Introduction We use Database tables frequently for look-up in our ABAP logic. Maintaining records in table is a manual process by updating table record by record. Available program for such updates are static in nature. Following approach allow you to create a generic program from updating any database table. How To Use: • Go to TCODE SE38. • Create a program Z_FLATFILE_UPLOAD as shown Below • Copy Paste the below code *&———————————————————————* *& Z_FLATFILE_UPLOAD. *& TITLE: Program to upload a flat file from path provided *& CREATED BY: Jaya Tiwari *&———————————————————————* REPORT z_flatfile_upload. ![]() ![]() I am trying to update a transparent Table using Dynamic Table. But everytime i try to update it i recieve a dump stating Move to SRC to DEST. Data: itab type standard table of ZCUSTOM_TABLE. How to Update Database Table with an Dynamic Internal Table of type ANY TABLE. IT_FINAL: is the dynamic Internal Table (Data Type: TYPE TABLE) 2. *———————————————————————-* * data declarations *———————————————————————-* TYPES: BEGIN OF lty_ttab, rec TYPE STRING, END OF lty_ttab. DATA: lt_itab TYPE STANDARD TABLE OF lty_ttab WITH HEADER LINE. DATA: lv_file_str TYPE string, lv_column TYPE n LENGTH 4. *Dynamic Table and Work area FIELD-SYMBOLS: TYPE ANY TABLE,. DATA: lv_tabname TYPE dd02l – tabname. ” DataBase Table Name DATA: lt_tble TYPE REF TO data, lt_line TYPE REF TO data. “Structure for Reading Field Names of DataBase Table TYPES: BEGIN OF lty_dd03vv, tabname TYPE tabname, fieldname TYPE fieldname, position TYPE tabfdpos, END OF lty_dd03vv. “Internal Table and work area for Reading Field Names of DataBase Table DATA: lt_dd03vv TYPE STANDARD TABLE OF lty_dd03vv WITH HEADER LINE, lwa_dd03vv LIKE LINE OF lt_dd03vv. DATA: lv_fieldname TYPE fieldname, lv_counter ( 2 ) TYPE n VALUE 0. *———————————————————————-* * selection screen design *———————————————————————-* SELECTION-SCREEN BEGIN OF BLOCK bi WITH FRAME TITLE txt_t1. SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN COMMENT ( 25 ) txt_file. PARAMETERS: lp_file TYPE localfile. SELECTION-SCREEN END OF LINE. SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN COMMENT ( 25 ) txt_tabl. PARAMETERS: lp_tble LIKE lv_tabname. SELECTION-SCREEN END OF LINE. SELECTION-SCREEN SKIP 1. SELECTION-SCREEN BEGIN OF LINE. PARAMETERS: cb_hdr AS CHECKBOX DEFAULT ‘X’ MODIF ID m1. SELECTION-SCREEN COMMENT ( 70 ) txt_warn MODIF ID m1. Doctor who 1x01 ita download adobe reader. SELECTION-SCREEN END OF LINE. SELECTION-SCREEN END OF BLOCK bi. *———————————————————————-* * At selection screen for field *———————————————————————-* INITIALIZATION. ![]() Txt_file = ‘File Path ‘. Txt_t1 = ‘File Upload Details ‘. Txt_tabl = ‘Target table Name ‘. Txt_warn = ‘Ignore Header Line in file Uploading.’. *———————————————————————-* * Read File Path *———————————————————————-* AT SELECTION-SCREEN ON VALUE-REQUEST FOR lp_file. CALL FUNCTION ‘KD_GET_FILENAME_ON_F4’ EXPORTING static = ‘X’ CHANGING file_name = lp_file. *———————————————————————-* * Validation *———————————————————————-* AT SELECTION-SCREEN ON BLOCK bi. IF lp_tble IS INITIAL. MESSAGE ‘Target Table Name Cannot be Empty.’ TYPE ‘E’. *———————————————————————-* * Start of selection *———————————————————————-* START-OF-SELECTION. Lv_file_str = lp_file. *FM to read file content from path provided CALL FUNCTION ‘GUI_UPLOAD’ EXPORTING filename = lv_file_str TABLES data_tab = lt_itab EXCEPTIONS file_open_error = 1 file_read_error = 2 no_batch = 3 gui_refuse_filetransfer = 4 invalid_type = 5 no_authority = 6 unknown_error = 7 bad_data_format = 8 header_not_allowed = 9 separator_not_allowed = 10 header_too_long = 11 unknown_dp_error = 12 access_denied = 13 dp_out_of_memory = 14 disk_full = 15 dp_timeout = 16 OTHERS = 17. IF sy – subrc 0. MESSAGE ‘File could not be uploaded’ TYPE ‘E’. *———————————————————————-* * Dynamic Internal Table and Work Area creation *———————————————————————-* IF lp_tble IS NOT INITIAL. Lv_tabname = lp_tble. “Check If table exist in Data Dictionary and no of columns in table SELECT COUNT ( * ) FROM dd03vv INTO lv_counter WHERE tabname = lv_tabname AND as4local = ‘A’. Powerflasher fdt enterprise 3 5 0 1094 cracked windshield repair. IF sy – subrc = 0 AND lv_counter GT 0. “Dynamic Internal Table Defination CREATE DATA lt_tble TYPE TABLE OF ( lp_tble ). ASSIGN lt_tble -> * TO. A lighting colorful and bright edges can be applied to the text using this layer style. You may have seen this layer style being used in mobile games or ads promoting the jelly products. “Dynamic Work Area Defination CREATE DATA lt_line LIKE LINE OF. ASSIGN lt_line -> * TO. SELECT tabname fieldname position FROM dd03vv INTO TABLE lt_dd03vv WHERE tabname = lv_tabname AND as4local = ‘A’. Update Syntax In Sap AbapSORT lt_dd03vv BY position. *———————————————————————-* * Assign Data to Internal Table via Work Area *———————————————————————-* LOOP AT lt_itab. ” Ignore header Row if Checkbox is checked IF cb_hdr = ‘X’. “Read Field Name from Internal Table one by one DO lv_counter TIMES. READ TABLE lt_dd03vv INTO lwa_dd03vv WITH KEY position = sy – index BINARY SEARCH. Lv_fieldname = lwa_dd03vv – fieldname. “Assign Data to each field ASSIGN COMPONENT lv_fieldname OF STRUCTURE TO. “Insert row into Dynamic Internal table INSERT INTO TABLE. *———————————————————————-* ***——- Modify Database tabe with Internal table ——-*** * If record already exist it will be update, * else new entry will get created *———————————————————————-* MODIFY ( lp_tble ) FROM TABLE. IF sy – subrc = 0. WRITE: ‘Table ‘, lp_tble, ‘Successfully Updated’. MESSAGE ‘Table not found in Data Dictionary.’ TYPE ‘E’. *———————————————————————-* * End Of Program *———————————————————————-* • Save and Activate your code. • Execute Program,Following selection screen will appear.Provide file path and table name as input.Also uncheck check box if there is no header row. Ztest1 ztest2 ztest3 A DD ADADSADA B DD adadada C DD sccada D DD adadada E DD 12121313 F DD 12121 G DD • 445.67 H DD saas I DD rwrw J DD zsczczc K DD awaqswqw L DD qqqqqqqqqqqqqqqqqqqqqqqqqqq • Pass Inputs like shown in above snapshot and execute.On success following message will appear. • Check database table via TCODE SE16,It will display loaded records. • To Update Table Data change the Data in file and load again. *** For client specific tables value in column MANDT will automatically gets populated so no need to create a separate column in flat file for the same. This program only allows you to add new records or update ( based on key ) existing records in a table.Delete functionality is purposefully opted out, as this can accidentally affect important tables.However if someone want to add delete functionality in program, I would suggest to put some authorization constraint as who or which table can use the program to delete data.A custom table can be created to store authorized users or tables that can use deletion functionality and before deletion this table will be referred by program. Limitations • There is limitation of data length for internal table reading flat file of 262143 characters. • Program can be executed for one table at a time. Appendix: Loading a Flat file and placing at Application Server This program will allow you to load your flat file at specific path in application server. Here we are providing 3 static paths which can be configured once (Path exist in AL11- SAP Directory) and then can be used just by selecting specific radio button. If User want to use different path other than listed one,Other radio button will allow him to pass it manually. Program Output: Double Click on output screen to navigate through SAP Directory to see file output. Sample File Output Sample Code: *&—————————————————————————————–* *& Report: z_flatfile_load_al11 *& Title: Program will load a flat file and place it at application server *& at specified path *& Created BY: Jaya Tiwari *&—————————————————————————————–* REPORT z_flatfile_load_al11. *—————————————————————————————-* * data declarations *—————————————————————————————-* ” To Read CSV file data from user’s workstation TYPES: BEGIN OF lty_ttab, rec TYPE string, END OF lty_ttab. DATA: lt_itab TYPE STANDARD TABLE OF lty_ttab WITH HEADER LINE. DATA: lv_file_str TYPE string, “file Path lv_system TYPE c LENGTH 15, “system name lv_count TYPE n LENGTH 5. DATA: lv_counter ( 2 ) TYPE n VALUE 0, lv_tabname TYPE tabname.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |