Skip to Content
This is a small series about some useful tools making consultant’s life a little easier dealing with Web AS ABAP. h3. Introduction Wouldn’t it be nice, if you can share database table content between different Web AS ABAP systems? I recently worked for a customer who installed a brand new empty ERP 6.0. When I looked at the shipped customizing of the units of measure, the whole data was complete messed up. (Important UoMs where missing, ISO codes were not set, not everything was translated.) Instead of manually correcting the data using transaction CUNI (which is quite old and not user friendly) I downloaded the data from a system where I new data were consistent and uploaded the relevant tables into the customers system. For this I have deleloped a small tool, I would like to share with you: *Usage cases can be:* ** Backing up data into a file, to restore it later, e.g. to repeat a demo ** Moving only selected data from productive to QAS or development system. h3. The Solution To download the data base tables into XML files use the following program: ************************************************************************ * SAP Deutschland * *———————————————————————- * Historie * ======== * Revisionen Name Firma Datum *———————————————————————- * Rev 01 Stephan Heinberg SAP Deutschland * Ersterstellung *———————————————————————- * Programmbeschreibung: *———————————————————————- * Download DB table content into XML files *———————————————————————- REPORT ZPL_MIG_R002 MESSAGE-ID bc_datamodel_service. *——————————————————————— * * Globale Daten *——————————————————————— * CONSTANTS: gc_file_extension TYPE string VALUE ‘XSAP’. DATA: gv_tabname LIKE dd02l-tabname. *——————————————————————— * * Selektionsbild *——————————————————————— * SELECTION-SCREEN BEGIN OF BLOCK s01 WITH FRAME. SELECT-OPTIONS gr_tabs FOR gv_tabname. PARAMETERS: p_path TYPE dxlpath OBLIGATORY DEFAULT ‘C:\temp’ “#EC NOTEXT . SELECTION-SCREEN END OF BLOCK s01. *======================================================================= * At Selection screen *======================================================================= AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. PERFORM get_path CHANGING p_path. *——————————————————————— * * Prüfungen Einstiegsscreen *——————————————————————— * AT SELECTION-SCREEN. *——————————————————————— * * Ausführung *——————————————————————— * START-OF-SELECTION. PERFORM format_path CHANGING p_path. PERFORM do_it USING p_path gr_tabs[]. *&——————————————————————– * *& Form get_filename *&——————————————————————– * * text *——————————————————————— * * –>CV_FILENAME text *——————————————————————— * FORM get_path CHANGING cv_path. DATA: lv_path_string TYPE string. lv_path_string = cv_path. CALL METHOD cl_gui_frontend_services=>directory_browse CHANGING selected_folder = lv_path_string EXCEPTIONS cntl_error = 1 error_no_gui = 2 not_supported_by_gui = 3. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. cv_path = lv_path_string. ENDFORM. “GET_FILENAME *&——————————————————————– * *& Form do_it *&——————————————————————– * * text *——————————————————————— * * –>P_P_PATH text * –>P_GR_TABS text *——————————————————————— * FORM do_it USING uv_path TYPE dxlpath ut_tabs TYPE table. DATA: lt_tab TYPE TABLE OF tabname, lv_table TYPE tabname . SELECT tabname FROM dd02l INTO TABLE lt_tab UP TO 50 ROWS WHERE tabname IN ut_tabs AND as4local = ‘A’ AND tabclass = ‘TRANSP’. IF sy-subrc <> 0. MESSAGE e555 WITH ‘No tables were found.'(001). ENDIF. PERFORM check_table_authority USING lt_tab. LOOP AT lt_tab INTO lv_table. PERFORM serialize USING lv_table uv_path. ENDLOOP. ENDFORM. ” do_it *&——————————————————————– * *& Form check_table_authority *&——————————————————————– * * text *——————————————————————— * * –>UT_TAB text *——————————————————————— * FORM check_table_authority USING ut_tab TYPE table. DATA: lv_table TYPE tabname . LOOP AT ut_tab INTO lv_table. CALL FUNCTION ‘VIEW_AUTHORITY_CHECK’ EXPORTING view_action = ‘S’ view_name = lv_table no_warning_for_clientindep = abap_false EXCEPTIONS invalid_action = 1 no_authority = 2 no_clientindependent_authority = 3 table_not_found = 4 no_linedependent_authority = 5. IF sy-subrc <> 0. MESSAGE e555 WITH ‘No authority to view table:'(002) lv_table. ENDIF. ENDLOOP. ENDFORM. “check_table_authority *&——————————————————————– * *& Form serialize *&——————————————————————– * * text *——————————————————————— * * –>P_LV_TABLE text * –>P_UV_PATH text *——————————————————————— * FORM serialize USING uv_table TYPE tabname uv_path TYPE dxlpath. TYPES: xmlline(1024) TYPE x. DATA: lt_xml TYPE TABLE OF xmlline, lr_data_table TYPE REF TO data, lv_filename TYPE string . FIELD-SYMBOLS: gui_download EXPORTING * BIN_FILESIZE = filename = lv_filename filetype = ‘BIN’ * APPEND = SPACE * WRITE_FIELD_SEPARATOR = SPACE * HEADER = ’00’ * TRUNC_TRAILING_BLANKS = SPACE * WRITE_LF = ‘X’ * COL_SELECT = SPACE * COL_SELECT_MASK = SPACE * DAT_MODE = SPACE confirm_overwrite = abap_true * NO_AUTH_CHECK = SPACE * CODEPAGE = SPACE * IGNORE_CERR = ABAP_TRUE * REPLACEMENT = ‘#’ * WRITE_BOM = SPACE * TRUNC_TRAILING_BLANKS_EOL = ‘X’ * WK1_N_FORMAT = SPACE * WK1_N_SIZE = SPACE * WK1_T_FORMAT = SPACE * WK1_T_SIZE = SPACE * IMPORTING * FILELENGTH = CHANGING data_tab = lt_xml EXCEPTIONS file_write_error = 1 no_batch = 2 gui_refuse_filetransfer = 3 invalid_type = 4 no_authority = 5 unknown_error = 6 header_not_allowed = 7 separator_not_allowed = 8 filesize_not_allowed = 9 header_too_long = 10 dp_error_create = 11 dp_error_send = 12 dp_error_write = 13 unknown_dp_error = 14 access_denied = 15 dp_out_of_memory = 16 disk_full = 17 dp_timeout = 18 file_not_found = 19 dataprovider_exception = 20 control_flush_error = 21 not_supported_by_gui = 22 error_no_gui = 23 . IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. WRITE: / ‘The DB table has been succesfully downloaded:'(003), uv_table. ENDFORM. ” serialize *&——————————————————————– * *& Form get_file_name *&——————————————————————– * * text *——————————————————————— * * –>P_LV_TABLE text * –>P_UV_PATH text * <–P_LV_FILENAME text *——————————————————————— * FORM get_file_name USING uv_table uv_path CHANGING cv_filename. CONCATENATE uv_path uv_table ‘.’ gc_file_extension INTO cv_filename. ENDFORM. ” get_file_name *&——————————————————————– * *& Form format_path *&——————————————————————– * * text *——————————————————————— * * <–P_P_PATH text *——————————————————————— * FORM format_path CHANGING cv_path TYPE dxlpath. DATA: lv_length TYPE i, lv_file_separator TYPE c . lv_length = STRLEN( cv_path ). CALL METHOD cl_gui_frontend_services=>get_file_separator CHANGING file_separator = lv_file_separator EXCEPTIONS cntl_error = 1 error_no_gui = 2 not_supported_by_gui = 3. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. lv_length = lv_length – 1. IF cv_path+lv_length(1) <> lv_file_separator. CONCATENATE cv_path lv_file_separator INTO cv_path. ENDIF. ENDFORM. ” format_path To upload the tables again, here’s the program:
To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

  1. Jürgen Mayer
    Hello Stephan,

    this looks nice and helpful but for all the dummies like me I think you should highlight the chapter ‘Warning’ in UPPERCASE BOLD RED letters.

    Regards
    Jürgen

    (0) 
    1. Stephan Heinberg Post author
      Hi Rich,
      I know this plug-in. It is still labeled alpha release. It would be nice to have one tool which does it all.
      The main reasons why I would not use the SAPlink plug-in for up-and-downloading table data is an architectural decision of SAPlink that I won’t agree with: SAPlink up-and-downloads their XML nuggets in text and not binary mode, and unfortunately there is no plain text! I had a few problems with SAPLink using non-Ascii7 characters, so I would not recommend using it for write DB table content, especially language tables.
      (0) 

Leave a Reply