* _______ _______ _______ _______ _______ _______ ______ _______ _______ ______ _______ * | _ | _ | _ | | | _ | || _ | _ | _ | | _ | * | |_| | |_| | |_| | _ | | |_| | _ | |_| | |_| | | || | |_| | * | | | | |_| | | | | | | | | |_||_| | * | | _ || | ___| _| | |_| | | _ || __ | | * | _ | |_| | _ | | | |_| _ | | _ | |_| | | | | _ | * |__| |__|_______|__| |__|___| |_______|__| |__|______||__| |__|_______|___| |_|__| |__| * www.abapcadabra.com * *------------------------------------------------------------------------------------------- * program : ZABAPCADABRA_TABLETRANSPORTER * title : Move table definition (including domain and element) +content * functional area : Cross modules * environment : 4.7 * program Function : This report can download a table with data element and domain * definition and contents into a flat file, and upload it agian * in another system. * Documentation : Search for "table transporter" on AbapcadabrA.com * Previous version : This is the initial version * Developer name : Wim Maasdam * Development date : 12/12/2014 * Version : 0.1 *--------------------------------------------------------------------- * Change list: * Date Description * 12/12/2014 Initial release * 24/03/2017 Added download function (for ease of use) *--------------------------------------------------------------------- report ZABAPCADABRA_TABLETRANSPORTER no standard page heading line-size 650. type-pools: vrm, abap. tables: sscrfields,dd02l, dd03l. "Selection screen purpose only *--------------------------------------------------------------------- * C L A S S D E F I N I T I O N *--------------------------------------------------------------------- *---------------------------------------------------------------------- * CLASS lcl_utility DEFINITION *---------------------------------------------------------------------- class lcl_utility definition. public section. class-data: gt_bdcdata type standard table of bdcdata, gt_bdcmsgcoll type standard table of bdcmsgcoll. class-methods: f4_presentation_file importing title type any changing filepath type any, set_bdc importing screen type boolean p1 type any p2 type any, list_messages. endclass. "lcl_f4_processing DEFINITION *---------------------------------------------------------------------- * CLASS lcl_downloader DEFINITION *---------------------------------------------------------------------- class lcl_downloader definition. public section. types: ty_tab512_tt type standard table of tab512, ty_char780_tt type standard table of char780. class-data: gv_quote type c length 1, gt_table_content type ty_char780_tt. class-methods: selection importing tabname type dd02l-tabname with_content type boolean, read_content importing query_table type dd02l-tabname exporting data type ty_char780_tt, save_file importing filename type string. endclass. "lcl_downloader DEFINITION *---------------------------------------------------------------------- * CLASS lcl_uploader DEFINITION *---------------------------------------------------------------------- class lcl_uploader definition. public section. types: begin of ty_domain, domname type dd01l-domname, ddtext type dd01t-ddtext, datatype type dd01l-datatype, leng type dd01l-leng, decimals type dd01l-decimals, outputlen type dd01l-outputlen, convexit type dd01l-convexit, lowercase type dd01l-lowercase, entitytab type dd01l-entitytab, end of ty_domain, begin of ty_domain_value, domname type dd07t-domname, valpos type dd07l-valpos, domvalue_l type dd07l-domvalue_l, ddtext type dd07t-ddtext, end of ty_domain_value, begin of ty_dataelement, rollname type dd04l-rollname, ddtext type dd04t-ddtext, domname type dd04l-domname, datatype type dd04l-datatype, leng type dd04l-leng, scrtext_s type dd04t-scrtext_s, scrtext_m type dd04t-scrtext_m, scrtext_l type dd04t-scrtext_l, reptext type dd04t-reptext, end of ty_dataelement, begin of ty_tablefield, position type dd03l-position, fieldname type dd03l-fieldname, keyflag type dd03l-keyflag, mandatory type dd03l-mandatory, rollname type dd03l-rollname, checktable type dd03l-checktable, end of ty_tablefield, begin of ty_table, tabname type dd02l-tabname, contflag type dd02l-contflag, mainflag type dd02l-mainflag, tabart type dd09l-tabart, tabkat type dd09l-tabkat, ddtext type dd02t-ddtext, end of ty_table. class-data: * CONTNT; semi-colon delimited list of columns (up to 512 characters in total) gt_domains type table of ty_domain, gt_domain_value type table of ty_domain_value, gt_dataelement type table of ty_dataelement, gt_tablefield type table of ty_tablefield, gw_table type ty_table, gt_table_content type standard table of char780, gv_bdc_version type c length 20, gv_mode type c length 1 value 'N'. class-methods: read_file importing filename type any, check_version, process_domains, process_dataelements, process_table, process_table_contents. endclass. "lcl_downloader DEFINITION define add_bdc. lcl_utility=>set_bdc( screen = &1 p1 = &2 p2 = &3 ). end-of-definition. *--------------------------------------------------------------------- * S E L E C T I O N - S C R E E N *--------------------------------------------------------------------- selection-screen begin of line. parameters: pa_down as checkbox default space. selection-screen comment 5(26) lbl_01 for field pa_down. parameters: pa_table type dd02l-tabname. selection-screen: position 66. parameters: pa_wcont AS CHECKBOX default abap_true. selection-screen comment 68(12) lbl_01b for field pa_wcont. selection-screen end of line. selection-screen begin of line. selection-screen comment 5(26) lbl_02 for field pa_dfile. parameters: pa_dfile type string lower case. selection-screen end of line. selection-screen begin of line. selection-screen comment 5(26) lbl_03 for field pa_langu. parameters: pa_langu type sy-langu default sy-langu. selection-screen end of line. SELECTION-SCREEN skip. selection-screen begin of line. parameters: pa_up as checkbox default space. selection-screen comment 5(26) lbl_04 for field pa_ufile. parameters: pa_ufile type c length 100 lower case. selection-screen end of line. selection-screen begin of line. selection-screen comment 5(26) lbl_05 for field pa_devcl. parameters: pa_devcl type devclass default 'Z001'. selection-screen end of line. selection-screen begin of line. selection-screen comment 5(26) lbl_06 for field pa_task. parameters: pa_task type trkorr. selection-screen end of line. selection-screen begin of line. selection-screen comment 5(26) lbl_07 for field pa_mode. parameters: pa_mode type c length 1 default 'N'. selection-screen end of line. selection-SCREEN SKIP. selection-SCREEN BEGIN OF LINE. SELECTION-SCREEN PUSHBUTTON (70) lbl_abca USER-COMMAND ABAPCADABRA VISIBLE LENGTH 5. selection-SCREEN END OF LINE. at selection-screen on value-request for pa_dfile. lcl_utility=>f4_presentation_file( exporting title = 'Choose file to download to' changing filepath = pa_dfile ). at selection-screen on value-request for pa_ufile. lcl_utility=>f4_presentation_file( exporting title = 'Choose file to upload from' changing filepath = pa_ufile ). AT SELECTION-SCREEN. CASE sscrfields-ucomm. WHEN 'ABAPCADABRA'. CALL FUNCTION 'CALL_BROWSER' EXPORTING URL = 'http://abapcadabra.com/index.php/cookies/485-table-transporter' EXCEPTIONS OTHERS = 0. ENDCASE. *--------------------------------------------------------------------- * C L A S S I M P L E M E N T A T I O N *--------------------------------------------------------------------- class lcl_utility implementation. method f4_presentation_file. data: lv_title type c length 60, lv_filepath type c length 120, lt_files type standard table of sdokpath, lw_file type sdokpath. lv_title = title. lv_filepath = filepath. CALL FUNCTION 'TMP_GUI_FILE_OPEN_DIALOG' EXPORTING window_title = lv_title default_filename = lv_filepath TABLES file_table = lt_files EXCEPTIONS others = 4. if sy-subrc <> 0. message 'Front end file open error' type 'E'. else. read table lt_files index 1 into lw_file. filepath = lw_file-pathname. endif. endmethod. "f4_presentation_file method set_bdc. data: lw_bdcdata type bdcdata. clear lw_bdcdata. lw_bdcdata-dynbegin = screen. if screen eq 'X'. lw_bdcdata-program = p1. lw_bdcdata-dynpro = p2. else. lw_bdcdata-fnam = p1. lw_bdcdata-fval = p2. endif. append lw_bdcdata to gt_bdcdata. endmethod. "f4_server_file method list_messages. data: lw_msg type bdcmsgcoll, lw_msgtext type c length 90, lv_msgnr type sy-msgno. loop at gt_bdcmsgcoll into lw_msg. lv_msgnr = lw_msg-msgnr. message id lw_msg-msgid type 'I' number lv_msgnr into lw_msgtext with lw_msg-msgv1 lw_msg-msgv2 lw_msg-msgv3 lw_msg-msgv4. write: /6 lw_msg-msgtyp, lw_msgtext. endloop. * Opbouwen verbinding met & is mislukt endmethod. "list_messages endclass. "lcl_f4_processing IMPLEMENTATION *----------------------------------------------------------------------* * CLASS lcl_downloader IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* class lcl_downloader implementation. method selection. data: lt_dd01l type standard table of dd01l, "Domains lw_dd01l type dd01l, lt_dd01t type standard table of dd01t, "Domains lw_dd01t type dd01t, lt_dd07l type standard table of dd07l, "R/3-DD: waarden van de domains lw_dd07l type dd07l, lt_dd07t type standard table of dd07t, "R/3-DD: omschrijving bij domain values lw_dd07t type dd07t, lt_dd04l type standard table of dd04l, "Gegevenselementen lw_dd04l type dd04l, lt_dd04t type standard table of dd04t, "Gegevenselementen - tekst lw_dd04t type dd04t, lw_dd02l type dd02l, "SAP-tabellen lw_dd02t type dd02t, lw_dd09l type dd09l, "DD: technische instellingen van tabellen lt_dd03l type standard table of dd03l, "Tabelvelden lw_dd03l type dd03l, lv_outputline type c length 1000, lt_table_content type ty_char780_tt, lw_table_content type char780. if tabname is initial. message 'Please supply a table name' type 'S'. exit. endif. select single * from dd02l into lw_dd02l where tabname = tabname and as4local = 'A' and as4vers = 0000 and tabclass = 'TRANSP'. if sy-subrc <> 0. message 'Table not suitable (TABCLASS=TRANSP)' type 'S'. exit. endif. select single * from dd02t into lw_dd02t where tabname = tabname and ddlanguage = pa_langu and as4local = 'A' and as4vers = 0000. select single * from dd09l into lw_dd09l where tabname = tabname and as4local = 'A' and as4vers = 0000. select * from dd03l into table lt_dd03l where tabname = tabname order by position. if sy-subrc <> 0. message 'Table has no fields' type 'S'. exit. endif. select * from dd04l into table lt_dd04l for all entries in lt_dd03l where rollname = lt_dd03l-rollname and rollname like 'Z%' and as4local = 'A' and as4vers = 0000. if not lt_dd04l[] is initial. select * from dd04t into table lt_dd04t for all entries in lt_dd04l where rollname = lt_dd04l-rollname and ddlanguage = pa_langu and as4local = 'A' and as4vers = 0000. select * from dd01l into table lt_dd01l for all entries in lt_dd04l where domname = lt_dd04l-domname and domname like 'Z%' and as4local = 'A' and as4vers = 0000. if not lt_dd01l[] is initial. select * from dd01t into table lt_dd01t for all entries in lt_dd01l where domname = lt_dd01l-domname and ddlanguage = pa_langu and as4local = 'A' and as4vers = 0000. select * from dd07l into table lt_dd07l for all entries in lt_dd01l where domname = lt_dd01l-domname and as4local = 'A' and as4vers = 0000. sort lt_dd07l by domname valpos. select * from dd07t into table lt_dd07t for all entries in lt_dd01l where domname = lt_dd01l-domname and ddlanguage = pa_langu and as4local = 'A' and as4vers = 0000. sort lt_dd07t by domname valpos. endif. endif. clear gt_table_content[]. * Compose the interface-output, which will be in the following format: * DOMAIN;DD01L-DOMNAME;DD01T-DDTEXT;DD01L-DATATYPE;DD01L-LENG;DD01L-DECIMALS;DD01L-OUTPUTLEN;DD01L-CONVEXIT;DD01L-LOWERCASE;DD01L-ENTITYTAB * DOMVAL;DD07T-DOMNAME;DD07T-VALPOS;DD07L-DOMVALUE_L;DD07T-DDTEXT * DATAEL;DD04L-ROLLNAME;DD04D-DATATYPE;DD04D-LENG;DD04T-DDTEXT;DD04L-DOMNAME;DD04T-SCRTEXT_S;DD04T-SCRTEXT_M;DD04T-SCRTEXT_L;DD04T-REPTEXT * TTABLE;DD02L-TABNAME;DD02L-CONTFLAG;DD02L-MAINFLAG;DD09L-TABART;DD09L-TABKAT;DD02T-DDTEXT * TABFLD;DD03L-POSITION;DD03L-FIELDNAME;DD03L-KEYFLAG;DD03L-MANDATORY;DD03L-ROLLNAME;DD03L-CHECKTABLE; * CONTNT; semi-colon delimited list of columns (up to 512 characters in total) loop at lt_dd01l into lw_dd01l. "<= Domains and domain values read table lt_dd01t into lw_dd01t with key domname = lw_dd01l-domname. if sy-subrc <> 0. clear lw_dd01t. endif. concatenate 'DOMAIN' lw_dd01l-domname lw_dd01t-ddtext lw_dd01l-datatype lw_dd01l-leng lw_dd01l-decimals lw_dd01l-outputlen lw_dd01l-convexit lw_dd01l-lowercase lw_dd01l-entitytab into lv_outputline separated by ';'. append lv_outputline to gt_table_content. loop at lt_dd07l into lw_dd07l where domname = lw_dd01l-domname. read table lt_dd07t into lw_dd07t with key domname = lw_dd01l-domname valpos = lw_dd07l-valpos. concatenate 'DOMVAL' lw_dd07t-domname lw_dd07l-valpos lw_dd07l-domvalue_l lw_dd07t-ddtext into lv_outputline separated by ';'. append lv_outputline to gt_table_content. endloop. endloop. loop at lt_dd04l into lw_dd04l. "<= Data elements (and texts) read table lt_dd04t into lw_dd04t with key rollname = lw_dd04l-rollname. if sy-subrc <> 0. clear lw_dd04t. endif. concatenate 'DATAEL' lw_dd04l-rollname lw_dd04t-ddtext lw_dd04l-domname lw_dd04l-datatype lw_dd04l-leng lw_dd04t-scrtext_s lw_dd04t-scrtext_m lw_dd04t-scrtext_l lw_dd04t-reptext into lv_outputline separated by ';'. append lv_outputline to gt_table_content. endloop. concatenate 'TTABLE' lw_dd02l-tabname lw_dd02l-contflag lw_dd02l-mainflag lw_dd09l-tabart lw_dd09l-tabkat lw_dd02t-ddtext into lv_outputline separated by ';'. append lv_outputline to gt_table_content. loop at lt_dd03l into lw_dd03l. "<= Table fields concatenate 'TABFLD' lw_dd03l-position lw_dd03l-fieldname lw_dd03l-keyflag lw_dd03l-mandatory lw_dd03l-rollname lw_dd03l-checktable into lv_outputline separated by ';'. append lv_outputline to gt_table_content. endloop. * Table content if with_content = abap_true. read_content( exporting query_table = tabname importing data = lt_table_content ). loop at lt_table_content into lw_table_content. concatenate 'CONTNT' lw_table_content into lv_outputline separated by ';'. append lv_outputline to gt_table_content. endloop. endif. endmethod. "selection method read_content. data: lt_options type standard table of rfc_db_opt, lt_fields type standard table of rfc_db_fld, lw_field type rfc_db_fld, lv_query_table type ddobjname, lt_data type ty_tab512_tt, lt_dfies type standard table of dfies, lw_dfies type dfies, lv_line_cursor type i, lv_headerline_flds type string, lv_headerline_desc type string, lv_limited_fields type boolean. * The RFC_READ_TABLE functio module has a limitation to the record-width of * a single table, being 512 characters. If more data needs to be passed, * a more selective field choice should be applied. The coding below will * ensure that no more than .5k data is selected and that the field names for * these fields are listed: lv_query_table = query_table. CALL FUNCTION 'DDIF_FIELDINFO_GET' EXPORTING tabname = lv_query_table TABLES dfies_tab = lt_dfies EXCEPTIONS others = 0. * Prepare field header and footer gv_quote = '"'. * Prepare field selection, only allowing up to 512 characters to be filled: clear: lt_fields[], lv_line_cursor, lv_headerline_flds, lv_headerline_desc, lv_limited_fields. loop at lt_dfies into lw_dfies. add lw_dfies-outputlen to lv_line_cursor. add 1 to lv_line_cursor. "The delimiter if lv_line_cursor > 512. lv_limited_fields = abap_true. exit. endif. lw_field-fieldname = lw_dfies-fieldname. append lw_field to lt_fields. * Header line: concatenate lv_headerline_flds ';' gv_quote lw_dfies-fieldname gv_quote into lv_headerline_flds. concatenate lv_headerline_desc ';' gv_quote lw_dfies-scrtext_m gv_quote into lv_headerline_desc. endloop. if lv_limited_fields = abap_true. message 'Table content: not all fields are processed' type 'S'. endif. clear lt_options[]. "<= All data is selected, without selection options CALL FUNCTION 'RFC_READ_TABLE' EXPORTING query_table = query_table delimiter = ';' TABLES options = lt_options fields = lt_fields data = lt_data EXCEPTIONS table_not_available = 1 table_without_data = 2 option_not_valid = 3 field_not_valid = 4 not_authorized = 5 data_buffer_exceeded = 6 others = 7. if sy-subrc <> 0. message id sy-msgid type 'S' number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. endif. * Actual content is added - line by line append lines of lt_data to data. endmethod. "read_table method save_file. CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING FILENAME = filename TABLES DATA_TAB = gt_table_content EXCEPTIONS OTHERS = 4. IF SY-SUBRC <> 0. MESSAGE ID sy-msgid TYPE 'W' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ELSE. message 'File saved' type 'S'. ENDIF. endmethod. endclass. "lcl_downloader IMPLEMENTATION *---------------------------------------------------------------------- * CLASS lcl_uploader IMPLEMENTATION *---------------------------------------------------------------------- class lcl_uploader implementation. method read_file. data: lt_source_file type standard table of char780, lw_source_file type char780, lv_filename type string, lv_linetype type c length 10 ##NEEDED, lw_domain type ty_domain, lw_domain_value type ty_domain_value, lw_dataelement type ty_dataelement, lw_tablefield type ty_tablefield. lv_filename = filename. CALL FUNCTION 'GUI_UPLOAD' EXPORTING filename = lv_filename TABLES data_tab = lt_source_file EXCEPTIONS others = 4. if sy-subrc <> 0. clear: lt_source_file[]. endif. * Interpret the content of the file - and populate the required data: loop at lt_source_file into lw_source_file. case lw_source_file(6). * DOMAIN;DD01L-DOMNAME;DD01T-DDTEXT;DD01L-DATATYPE;DD01L-LENG;DD01L-DECIMALS;DD01L-OUTPUTLEN;DD01L-CONVEXIT;DD01L-LOWERCASE;DD01L-ENTITYTAB when 'DOMAIN'. split lw_source_file at ';' into lv_linetype lw_domain-domname lw_domain-ddtext lw_domain-datatype lw_domain-leng lw_domain-decimals lw_domain-outputlen lw_domain-convexit lw_domain-lowercase lw_domain-entitytab. append lw_domain to gt_domains. * DOMVAL;DD07T-DOMNAME;DD07T-VALPOS;DD07L-DOMVALUE_L;DD07T-DDTEXT when 'DOMVAL'. split lw_source_file at ';' into lv_linetype lw_domain_value-domname lw_domain_value-valpos lw_domain_value-domvalue_l lw_domain_value-ddtext. append lw_domain_value to gt_domain_value. * DATAEL;DD04L-ROLLNAME;DD04T-DDTEXT;DD04L-DOMNAME;DD04L-DATATYPE;DD04L-LENG;DD04T-SCRTEXT_S;DD04T-SCRTEXT_M;DD04T-SCRTEXT_L;DD04T-REPTEXT when 'DATAEL'. split lw_source_file at ';' into lv_linetype lw_dataelement-rollname lw_dataelement-ddtext lw_dataelement-domname lw_dataelement-datatype lw_dataelement-leng lw_dataelement-scrtext_s lw_dataelement-scrtext_m lw_dataelement-scrtext_l lw_dataelement-reptext. append lw_dataelement to gt_dataelement. * TABFLD;DD03L-POSITION;DD03L-FIELDNAME;DD03L-KEYFLAG;DD03L-MANDATORY;DD03L-ROLLNAME;DD03L-CHECKTABLE; when 'TABFLD'. split lw_source_file at ';' into lv_linetype lw_tablefield-position lw_tablefield-fieldname lw_tablefield-keyflag lw_tablefield-mandatory lw_tablefield-rollname lw_tablefield-checktable. append lw_tablefield to gt_tablefield. * TTABLE;DD02L-TABNAME;DD02L-CONTFLAG;DD02L-MAINFLAG;DD09L-TABART;DD09L-TABKAT;DD02T-DDTEXT when 'TTABLE'. split lw_source_file at ';' into lv_linetype gw_table-tabname gw_table-contflag gw_table-mainflag gw_table-tabart gw_table-tabkat gw_table-ddtext. when 'CONTNT'. append lw_source_file to gt_table_content. endcase. endloop. endmethod. "read_file method check_version. data: lw_bdcmsgcoll type bdcmsgcoll. * The SE11 transaction has undergone a face-lift causing screen name changes in different version. * This method determines which version of BDC session should be used. clear lcl_utility=>gt_bdcdata. add_bdc: 'X' 'SAPMSRD0' '0102', ' ' 'RSRD1-TBMA' 'X', ' ' 'RSRD1-TBMA_VAL' 'ZABAPCADABRAZ', ' ' 'BDC_OKCODE' '=SHOW', 'X' 'SAPMSRD0' '0102'. call transaction 'SE11' using lcl_utility=>gt_bdcdata mode 'N' messages into lcl_utility=>gt_bdcmsgcoll. read table lcl_utility=>gt_bdcmsgcoll into lw_bdcmsgcoll index 1. if lw_bdcmsgcoll-tcode = 'SE11_OLD' and lw_bdcmsgcoll-msgv1 = 'ZABAPCADABRAZ'. gv_bdc_version = 'SAPMSRD0'. else. gv_bdc_version = 'SAPLSD_ENTRY'. endif. endmethod. "check_version method process_domains. data: lw_domain type ty_domain, lw_domain_value type ty_domain_value. loop at gt_domains into lw_domain. * Check whether the domain is available / or not: select domname from dd01l into lw_domain-domname up to 1 rows where domname = lw_domain-domname. endselect. if sy-subrc = 0. write: / 'Domain', lw_domain-domname, 'already available'. else. * Set up a BDC recording to create te Domain clear: lcl_utility=>gt_bdcdata, lcl_utility=>gt_bdcmsgcoll. case gv_bdc_version. when 'SAPMSRD0'. * Not supported when 'SAPLSD_ENTRY'. add_bdc: 'X' 'SAPLSD_ENTRY' '1000', ' ' 'RSRD1-DOMA' 'X', ' ' 'BDC_OKCODE' '=CHANGE_RADIO', 'X' 'SAPLSD_ENTRY' '1000', ' ' 'RSRD1-DOMA' 'X', ' ' 'RSRD1-DOMA_VAL' lw_domain-domname, ' ' 'BDC_OKCODE' '=WB_CREATE', 'X' 'SAPLSD11' '1200', ' ' 'BDC_SUBSCR' 'SAPLSD11 1201TS_SCREEN', ' ' 'DD01D-DDTEXT' lw_domain-ddtext, ' ' 'DD01D-DATATYPE' lw_domain-datatype, ' ' 'DD01D-LENG' lw_domain-leng, ' ' 'DD01D-DECIMALS' lw_domain-decimals, ' ' 'DD01D-OUTPUTLEN' lw_domain-outputlen, ' ' 'DD01D-LOWERCASE' lw_domain-lowercase, ' ' 'BDC_OKCODE' '/ETAB2', 'X' 'SAPLSD11' '1200', ' ' 'BDC_SUBSCR' 'SAPLSD11 1203TS_SCREEN', ' ' 'DD01D-ENTITYTAB' lw_domain-entitytab. * Sequence processing: in reverse order: sort gt_domain_value by domname valpos descending. loop at gt_domain_value into lw_domain_value where domname = lw_domain-domname. add_bdc: ' ' 'BDC_OKCODE' '=WB_LINE_INSERT', 'X' 'SAPLSD11' '1200', ' ' 'DD07D-DOMVALUE(01)' lw_domain_value-domvalue_l, ' ' 'DD07D-DDTEXT(01)' lw_domain_value-ddtext. endloop. add_bdc: ' ' 'BDC_OKCODE' '=WB_SAVE', 'X' 'SAPLSTRD' '0100', ' ' 'KO007-L_DEVCLASS' pa_devcl, ' ' 'BDC_OKCODE' '=ADD', 'X' 'SAPLSTRD' '0300', ' ' 'KO008-TRKORR' pa_task, ' ' 'BDC_OKCODE' '=LOCK', 'X' 'SAPLSD11' '1200'. endcase. call transaction 'SE11' using lcl_utility=>gt_bdcdata mode gv_mode messages into lcl_utility=>gt_bdcmsgcoll. write: / 'Create domain', lw_domain-domname. lcl_utility=>list_messages( ). clear: lcl_utility=>gt_bdcdata, lcl_utility=>gt_bdcmsgcoll. case gv_bdc_version. when 'SAPMSRD0'. when 'SAPLSD_ENTRY'. add_bdc: 'X' 'SAPLSD_ENTRY' '1000', ' ' 'RSRD1-DOMA' 'X', ' ' 'BDC_OKCODE' '=CHANGE_RADIO', 'X' 'SAPLSD_ENTRY' '1000', ' ' 'RSRD1-DOMA' 'X', ' ' 'RSRD1-DOMA_VAL' lw_domain-domname, ' ' 'BDC_OKCODE' '=WB_EDIT', 'X' 'SAPLSD11' '1200', ' ' 'BDC_OKCODE' '=WB_ACTIVATE', 'X' 'SAPLSD11' '1200'. endcase. call transaction 'SE11' using lcl_utility=>gt_bdcdata mode gv_mode messages into lcl_utility=>gt_bdcmsgcoll. write: / 'Activate domain', lw_domain-domname. lcl_utility=>list_messages( ). endif. endloop. endmethod. "process_domains method process_dataelements. data: lw_dataelement type ty_dataelement. loop at gt_dataelement into lw_dataelement. * Check whether the dataset is available / or not: select rollname from dd04l into lw_dataelement-rollname up to 1 rows where rollname = lw_dataelement-rollname. endselect. if sy-subrc = 0. write: / 'Dataelement', lw_dataelement-rollname, 'already available'. else. clear: lcl_utility=>gt_bdcdata, lcl_utility=>gt_bdcmsgcoll. case gv_bdc_version. when 'SAPMSRD0'. add_bdc: 'X' 'SAPMSRD0' '0102', ' ' 'RSRD1-DDTYPE' 'X', ' ' 'RSRD1-DDTYPE_VAL' lw_dataelement-rollname, ' ' 'BDC_OKCODE' '=ADD', 'X' 'SAPLSED1' '0100', ' ' 'D_100-DTEL' 'X', "<= Data element (type) ' ' 'BDC_OKCODE' '=GOON', 'X' 'SAPLSD51' '1000', ' ' 'DD04D-DDTEXT' lw_dataelement-ddtext. if not lw_dataelement-domname is initial. add_bdc: ' ' 'RADIO-DOMAIN' 'X', ' ' 'RADIO-DIRECT' ' ', ' ' 'DD04D-DOMNAME' lw_dataelement-domname. else. add_bdc: ' ' 'RADIO-DOMAIN' ' ', ' ' 'RADIO-DIRECT' 'X', ' ' 'BDC_OKCODE' '=CHANGE_CHECKBOX', 'X' 'SAPLSD51' '1000', ' ' 'DD04D-DATATYPE' lw_dataelement-datatype, ' ' 'DD04D-LENG' lw_dataelement-leng. endif. add_bdc: ' ' 'BDC_OKCODE' '=TEXT', 'X' 'SAPLSD51' '1000', ' ' 'DD04D-SCRTEXT_S' lw_dataelement-scrtext_s, ' ' 'DD04D-SCRTEXT_M' lw_dataelement-scrtext_m, ' ' 'DD04D-SCRTEXT_L' lw_dataelement-scrtext_l, ' ' 'DD04D-REPTEXT' lw_dataelement-reptext, ' ' 'BDC_OKCODE' '=WB_SAVE', 'X' 'SAPLSTRD' '0100', ' ' 'KO007-L_DEVCLASS' pa_devcl, ' ' 'BDC_OKCODE' '=ADD', 'X' 'SAPLSTRD' '0300', ' ' 'KO008-TRKORR' pa_task, ' ' 'BDC_OKCODE' '=LOCK', 'X' 'SAPLSD11' '1200'. when 'SAPLSD_ENTRY'. * Set up a BDC recording to create te data element add_bdc: 'X' 'SAPLSD_ENTRY' '1000', ' ' 'RSRD1-DDTYPE' 'X', ' ' 'RSRD1-DDTYPE_VAL' lw_dataelement-rollname, ' ' 'BDC_OKCODE' '=CHANGE_RADIO', 'X' 'SAPLSD_ENTRY' '1000', ' ' 'BDC_OKCODE' '=WB_CREATE', 'X' 'SAPLSED1' '0100', ' ' 'D_100-DTEL' 'X', "<= Data element (type) ' ' 'BDC_OKCODE' '=GOON', 'X' 'SAPLSD51' '1000', ' ' 'DD04D-DDTEXT' lw_dataelement-ddtext. if not lw_dataelement-domname is initial. add_bdc: ' ' 'RADIO-DOMAIN' 'X', ' ' 'RADIO-DIRECT' ' ', ' ' 'DD04D-DOMNAME' lw_dataelement-domname. else. add_bdc: ' ' 'RADIO-DOMAIN' ' ', ' ' 'RADIO-DIRECT' 'X', 'X' 'SAPLSD51' '1000', ' ' 'DD04D-DATATYPE' lw_dataelement-datatype, ' ' 'DD04D-LENG' lw_dataelement-leng. endif. add_bdc: ' ' 'BDC_OKCODE' '=TEXT', 'X' 'SAPLSD51' '1000', ' ' 'DD04D-SCRTEXT_S' lw_dataelement-scrtext_s, ' ' 'DD04D-SCRTEXT_M' lw_dataelement-scrtext_m, ' ' 'DD04D-SCRTEXT_L' lw_dataelement-scrtext_l, ' ' 'DD04D-REPTEXT' lw_dataelement-reptext, ' ' 'BDC_OKCODE' '=WB_SAVE', 'X' 'SAPLSTRD' '0100', ' ' 'KO007-L_DEVCLASS' pa_devcl, ' ' 'BDC_OKCODE' '=ADD', 'X' 'SAPLSTRD' '0300', ' ' 'KO008-TRKORR' pa_task, ' ' 'BDC_OKCODE' '=LOCK', 'X' 'SAPLSD11' '1200'. endcase. call transaction 'SE11' using lcl_utility=>gt_bdcdata mode gv_mode messages into lcl_utility=>gt_bdcmsgcoll. write: / 'Creation of data element', lw_dataelement-rollname. lcl_utility=>list_messages( ). clear: lcl_utility=>gt_bdcdata, lcl_utility=>gt_bdcmsgcoll. case gv_bdc_version. when 'SAPMSRD0'. add_bdc: 'X' 'SAPMSRD0' '0102', ' ' 'RSRD1-DDTYPE' 'X', ' ' 'RSRD1-DDTYPE_VAL' lw_dataelement-rollname, ' ' 'BDC_OKCODE' '=EDIT', 'X' 'SAPLSD51' '1000', ' ' 'BDC_OKCODE' '=WB_ACTIVATE', 'X' 'SAPLSD51' '1000'. when 'SAPLSD_ENTRY'. add_bdc: 'X' 'SAPLSD_ENTRY' '1000', ' ' 'RSRD1-DDTYPE' 'X', ' ' 'RSRD1-DDTYPE_VAL' lw_dataelement-rollname, ' ' 'BDC_OKCODE' '=CHANGE_RADIO', 'X' 'SAPLSD_ENTRY' '1000', ' ' 'BDC_OKCODE' '=WB_EDIT', 'X' 'SAPLSD51' '1000', ' ' 'BDC_OKCODE' '=WB_ACTIVATE', 'X' 'SAPLSD51' '1000'. endcase. call transaction 'SE11' using lcl_utility=>gt_bdcdata mode gv_mode messages into lcl_utility=>gt_bdcmsgcoll. write: / 'Activation of data element', lw_dataelement-rollname. lcl_utility=>list_messages( ). endif. endloop. endmethod. "process_dataelements method process_table. data: lw_tablefield type ty_tablefield. select tabname from dd02l into gw_table-tabname up to 1 rows where tabname = gw_table-tabname. endselect. if sy-subrc = 0. write: / 'Table', gw_table-tabname, 'already available'. else. clear: lcl_utility=>gt_bdcdata, lcl_utility=>gt_bdcmsgcoll. case gv_bdc_version. when 'SAPMSRD0'. when 'SAPLSD_ENTRY'. add_bdc: 'X' 'SAPLSD_ENTRY' '1000', ' ' 'RSRD1-TBMA' 'X', ' ' 'RSRD1-TBMA_VAL' gw_table-tabname, ' ' 'BDC_OKCODE' '=CHANGE_RADIO', 'X' 'SAPLSD_ENTRY' '1000', ' ' 'BDC_OKCODE' '=WB_CREATE', 'X' 'SAPLSD41' '2200', ' ' 'BDC_SUBSCR' 'SAPLSD41 2202TS_SCREEN', ' ' 'DD02D-DDTEXT' gw_table-ddtext, ' ' 'DD02D-CONTFLAG' gw_table-contflag, ' ' 'DD02D-MAINFLAG' gw_table-mainflag, ' ' 'BDC_OKCODE' '=CHANGE_MAINTFLAG', 'X' 'SAPLSD41' '2200', ' ' 'BDC_SUBSCR' 'SAPLSD41 2202TS_SCREEN', ' ' 'BDC_OKCODE' '=DEF', 'X' 'SAPLSD41' '2200'. * Start filling fields here... which is done in reverse order, new fields are inserted at * the top: sort gt_tablefield by position descending. loop at gt_tablefield into lw_tablefield. add_bdc: ' ' 'BDC_SUBSCR' 'SAPLSD41 2202TS_SCREEN', ' ' 'BDC_CURSOR' 'DD03D-ROLLNAME(01)', ' ' 'BDC_OKCODE' '=WB_LINE_INSERT', 'X' 'SAPLSD41' '2200', ' ' 'BDC_SUBSCR' 'SAPLSD41 2202TS_SCREEN', ' ' 'DD03D-FIELDNAME(01)' lw_tablefield-fieldname, ' ' 'DD03P-KEYFLAG(01)' lw_tablefield-keyflag, ' ' 'DD03P-NOTNULL(01)' lw_tablefield-mandatory, ' ' 'DD03D-ROLLNAME(01)' lw_tablefield-rollname, ' ' 'BDC_OKCODE' '/00', 'X' 'SAPLSD41' '2200'. endloop. * Save the table - which finalizes the first part add_bdc: ' ' 'BDC_OKCODE' '=WB_SAVE', 'X' 'SAPLSTRD' '0100', ' ' 'KO007-L_DEVCLASS' pa_devcl, ' ' 'BDC_OKCODE' '=ADD', 'X' 'SAPLSD41' '2200'. endcase. call transaction 'SE11' using lcl_utility=>gt_bdcdata mode gv_mode messages into lcl_utility=>gt_bdcmsgcoll. write: / 'Create table', gw_table-tabname. lcl_utility=>list_messages( ). * Now set the technical settings clear: lcl_utility=>gt_bdcdata, lcl_utility=>gt_bdcmsgcoll. case gv_bdc_version. when 'SAPMSRD0'. * Not supported when 'SAPLSD_ENTRY'. add_bdc: 'X' 'SAPLSD_ENTRY' '1000', ' ' 'RSRD1-TBMA' 'X', ' ' 'RSRD1-TBMA_VAL' gw_table-tabname, ' ' 'BDC_OKCODE' '=WB_EDIT', 'X' 'SAPLSD41' '2200', ' ' 'BDC_OKCODE' '=SE13', 'X' 'SAPMSEDS' '0050', ' ' 'DD09V-TABART' gw_table-tabart, ' ' 'DD09V-TABKAT' gw_table-tabkat, ' ' 'BDC_OKCODE' '=SICH', 'X' 'SAPLSD41' '2200'. endcase. call transaction 'SE11' using lcl_utility=>gt_bdcdata mode gv_mode messages into lcl_utility=>gt_bdcmsgcoll. write: / 'Table', gw_table-tabname, 'can be activated'. lcl_utility=>list_messages( ). endif. endmethod. "process_table method process_table_contents. data: lw_dd02l type dd02l, lw_table_content type char780, lw_buffer type char780, lt_fieldvalues type standard table of char80, lv_fieldvalue type char80, lv_fieldname type c length 40, lw_tablefield type ty_tablefield, lv_tabix type sy-tabix. field-symbols: type any, type any. check not gt_table_content[] is initial. * To be ok with loading data into a table, the table itself needs to be * active: select * from dd02l into lw_dd02l up to 1 rows where tabname = gw_table-tabname. endselect. if sy-subrc <> 0 or lw_dd02l-as4local <> 'A'. write: / 'Table contents: table', gw_table-tabname, 'is not available or not active'. else. * Check the content that should be placed on the table: write: / 'Table contents:'. assign lw_buffer to casting type (gw_table-tabname). * Line-by-line processing loop at gt_table_content into lw_table_content. split lw_table_content at ';' into table lt_fieldvalues. clear . sort gt_tablefield by position. loop at gt_tablefield into lw_tablefield. concatenate '-' lw_tablefield-fieldname into lv_fieldname. assign (lv_fieldname) to . if sy-subrc = 0. lv_tabix = lw_tablefield-position + 1. "To cater for the CONTNT indicator read table lt_fieldvalues index lv_tabix into lv_fieldvalue. if sy-subrc = 0. move lv_fieldvalue to . endif. endif. * MANDT content is set to the current MANDT: if lw_tablefield-fieldname = 'MANDT'. move sy-mandt to . endif. endloop. * Now modify the line on the transparent table: modify (gw_table-tabname) from . write: / . endloop. endif. endmethod. "process_table_contents endclass. "lcl_uploader IMPLEMENTATION *--------------------------------------------------------------------- * I N I T I A L I Z A T I O N *--------------------------------------------------------------------- initialization. * All texts for this report have been set up as hard-coded texts (no use * of the report text-pool). Reason: easy copying of report source code. lbl_01 = 'Download table'. lbl_01b = 'With content'. lbl_02 = 'Download to (file)'. lbl_03 = 'Language'. lbl_04 = 'Upload from (file)'. lbl_05 = 'Development class'. lbl_06 = 'Change request'. lbl_07 = 'BDC session mode'. lbl_abca = '@N5\QMore on AbapcadabrA.com@'. *--------------------------------------------------------------------- * S T A R T - O F - S E L E C T I O N *--------------------------------------------------------------------- start-of-selection. * Produce a report with information of domains, data elements, table * header information, table fields and field content if pa_down = abap_true. lcl_downloader=>selection( tabname = pa_table with_content = pa_wcont ). lcl_downloader=>save_file( pa_dfile ). elseif pa_up = abap_true. lcl_uploader=>read_file( pa_ufile ). lcl_uploader=>check_version( ). lcl_uploader=>gv_mode = pa_mode. lcl_uploader=>process_domains( ). lcl_uploader=>process_dataelements( ). lcl_uploader=>process_table( ). lcl_uploader=>process_table_contents( ). endif.