1. Go to Tcode SE38. Provide a z-program name and click on create. Provide description and select executable program.
2. Activate the program and execute. Provide the legacy file in the given format. Below is the legacy file format for the connection object migration in our scenario.
REPORT ztest_emigall_conversion.
SELECTION-SCREEN BEGIN OF BLOCK grp2 WITH FRAME TITLE text-002.
PARAMETERS : p_file TYPE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN END OF BLOCK grp2.
CONSTANTS: gc_ext_xls TYPE string VALUE '*.xls',
gc_tab TYPE abap_char1 VALUE cl_abap_char_utilities=>horizontal_tab,
gc_fs_wa TYPE lvc_fname VALUE '<fs_wa>-'.
DATA: gt_op_data TYPE rsanm_file_table.
DATA: gt_excel_tab TYPE STANDARD TABLE OF alsmex_tabline,
gs_excel_tab TYPE alsmex_tabline,
gt_fieldcat TYPE lvc_t_fcat,
gs_fieldcat TYPE lvc_s_fcat,
gv_value TYPE string.
DATA: gt_dynpro TYPE REF TO data,
gs_dynpro TYPE REF TO data.
FIELD-SYMBOLS :
<fs_table> TYPE STANDARD TABLE,
<fs_wa> TYPE any,
<fs_current_field> TYPE any,
<fs_field_value> TYPE any.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
* F4 help for file path
PERFORM f4help.
START-OF-SELECTION.
* Upload the Excel File to an internal table
PERFORM upload_excel_to_itab.
IF gt_excel_tab IS NOT INITIAL.
* Build the Field Catalog for creating the Dynamic Internal Table.
PERFORM build_field_catalog.
* Create dynamic table from field catalog
PERFORM create_dynamic_itab_wa.
* Fill the Dynamic internal table with data
PERFORM fill_data.
* Create different performs for each migration objects
* Convert CO data into EMIGALL format
PERFORM convert_co_data.
* Write converted data file to PC
PERFORM write_op_file.
ENDIF.
*&---------------------------------------------------------------------*
*& Form F4HELP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f4help .
DATA: lt_filetable TYPE filetable,
lx_filetable TYPE file_table,
lv_return_code TYPE i,
lv_window_title TYPE string.
lv_window_title = text-003.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = lv_window_title
default_extension = gc_ext_xls
CHANGING
file_table = lt_filetable
rc = lv_return_code
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
READ TABLE lt_filetable INTO lx_filetable INDEX 1.
p_file = lx_filetable-filename.
ENDFORM. " F4HELP
*&---------------------------------------------------------------------*
*& Form UPLOAD_EXCEL_TO_ITAB
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM upload_excel_to_itab .
* create internal table with Excel values
* Attention: This function module belongs to application component FI-AA
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file
i_begin_col = '1'
i_begin_row = '1'
i_end_col = '200'
i_end_row = '5000'
TABLES
intern = gt_excel_tab
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
ENDFORM. " UPLOAD_EXCEL_TO_ITAB
*&---------------------------------------------------------------------*
*& Form BUILD_FIELD_CATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM build_field_catalog .
LOOP AT gt_excel_tab INTO gs_excel_tab WHERE row EQ '1' .
gs_fieldcat-fieldname = gs_excel_tab-value.
gs_fieldcat-coltext = gs_excel_tab-value.
gs_fieldcat-outputlen = 50.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
ENDLOOP.
ENDFORM. " BUILD_FIELD_CATALOG
*&---------------------------------------------------------------------*
*& Form CREATE_DYNAMIC_ITAB_WA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM create_dynamic_itab_wa .
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = gt_fieldcat
IMPORTING
ep_table = gt_dynpro
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
*Assign the Dynamic internal table reference to a Field Symbol and
*create a Work Area of its Line type.
IF sy-subrc EQ 0.
ASSIGN gt_dynpro->* TO <fs_table>.
CREATE DATA gs_dynpro LIKE LINE OF <fs_table>.
ASSIGN gs_dynpro->* TO <fs_wa>.
ENDIF.
ENDFORM. " CREATE_DYNAMIC_ITAB_WA
*&---------------------------------------------------------------------*
*& Form FILL_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fill_data .
LOOP AT gt_excel_tab INTO gs_excel_tab WHERE row NE '1' .
READ TABLE gt_fieldcat INTO gs_fieldcat INDEX gs_excel_tab-col.
CHECK sy-subrc EQ 0.
CONCATENATE gc_fs_wa gs_fieldcat-fieldname INTO gv_value.
ASSIGN (gv_value) TO <fs_current_field>.
IF <fs_current_field> IS ASSIGNED.
<fs_current_field> = gs_excel_tab-value.
ENDIF.
AT END OF row ##LOOP_AT_OK.
APPEND <fs_wa> TO <fs_table>.
CLEAR <fs_wa>.
ENDAT.
ENDLOOP.
ENDFORM. " FILL_DATA
*&---------------------------------------------------------------------*
*& Form CONVERT_CO_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM convert_co_data .
DATA: lw_op_data TYPE rsanm_file_line,
lv_legacykey TYPE emg_oldkey,
lv_pltxt TYPE pltxt,
lv_house_num1 TYPE ad_hsnm1,
lv_street TYPE ad_street.
LOOP AT <fs_table> ASSIGNING <fs_wa>.
ASSIGN COMPONENT 'LEGACYKEY' OF STRUCTURE <fs_wa> TO <fs_field_value>.
lv_legacykey = <fs_field_value>.
ASSIGN COMPONENT 'PLTXT' OF STRUCTURE <fs_wa> TO <fs_field_value>.
lv_pltxt = <fs_field_value>.
CONCATENATE lv_legacykey 'CO_EHA' lv_pltxt INTO lw_op_data SEPARATED BY gc_tab.
APPEND lw_op_data TO gt_op_data.
ASSIGN COMPONENT 'STREET' OF STRUCTURE <fs_wa> TO <fs_field_value>.
lv_street = <fs_field_value>.
ASSIGN COMPONENT 'HOUSE_NUM1' OF STRUCTURE <fs_wa> TO <fs_field_value>.
lv_house_num1 = <fs_field_value>.
CONCATENATE lv_legacykey 'CO_ADR' lv_street lv_house_num1 INTO lw_op_data SEPARATED BY gc_tab.
APPEND lw_op_data TO gt_op_data.
CONCATENATE lv_legacykey '&ENDE' INTO lw_op_data SEPARATED BY gc_tab.
APPEND lw_op_data TO gt_op_data.
ENDLOOP.
ENDFORM. " CONVERT_CO_DATA
*&---------------------------------------------------------------------*
*& Form WRITE_OP_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM write_op_file .
DATA: lv_filename TYPE string,
lv_path TYPE string,
lv_fullpath TYPE string.
CALL METHOD cl_gui_frontend_services=>file_save_dialog
CHANGING
filename = lv_filename
path = lv_path
fullpath = lv_fullpath.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = lv_fullpath
TABLES
data_tab = gt_op_data.
ENDFORM. " WRITE_OP_FILE
2. Activate the program and execute. Provide the legacy file in the given format. Below is the legacy file format for the connection object migration in our scenario.
Provide a file name and save the converted file in local drive. The converted file looks like this.
CO_10000005 CO_EHA Test Conn obj CO_10000005 CO_ADR Street1 H101 CO_10000005 &ENDE
No comments:
Post a Comment