Issue with Dynamic Table Access for Copying MOLGA Content Between Tables

Hi @ALL,

I’m currently developing a report to copy MOLGA content from one MOLGA to another. I’ve implemented dynamic table access for this, but it’s unable to retrieve the table data. I’ll share the program below, and any assistance would be greatly appreciated.

 

TYPESBEGIN OF ty_tbl_list,
         tabname TYPE tabname,
       END OF ty_tbl_list.

DATAlt_tables TYPE TABLE OF ty_tbl_list,
      ls_table  TYPE ty_tbl_list,
      lv_src_ctry TYPE land1 VALUE ’06’” France
      lv_tgt_ctry TYPE land1 VALUE ‘MA’” Morocco.

FIELD-SYMBOLS<lt_src_data> TYPE STANDARD TABLE,
               <lt_tgt_data> TYPE STANDARD TABLE,
               <ls_data>     TYPE any,
               <fs_country>  TYPE any,
               <fs_table>    TYPE STANDARD TABLE.

START-OF-SELECTION.

  CLEAR lt_tables.
  CLEAR ls_table.

  ” Manually populating the internal table
  ls_tabletabname ‘V_T52D1’.
  APPEND ls_table TO lt_tables.

  LOOP AT lt_tables INTO ls_table.
    PERFORM copy_tbl_content USING ls_tabletabname lv_src_ctry lv_tgt_ctry.
  ENDLOOP.

FORM copy_tbl_content USING pv_tabname TYPE tabname
                              pv_src_ctry TYPE land1
                              pv_tgt_ctry TYPE land1.

ASSIGN (pv_tabnameTO <fs_table>.
IF sysubrc <> 0.
  WRITE‘Table’pv_tabname‘not found’.
  RETURN.
ENDIF.

  ” Select data from source country
  SELECT FROM (pv_tabnameINTO TABLE <lt_src_data> WHERE country pv_src_ctry.

  IF <lt_src_data> IS INITIAL.
    WRITE‘No data found in table’pv_tabname‘for country’pv_src_ctry.
    RETURN.
  ENDIF.

  ” Loop through the selected data and prepare it for insertion
  LOOP AT <lt_src_data> ASSIGNING <ls_data>.

    ” Dynamically assign the ‘country’ field within the structure
    ASSIGN COMPONENT ‘COUNTRY’ OF STRUCTURE <ls_data> TO <fs_country>.

    IF sysubrc 0.
      <fs_country> pv_tgt_ctry.
      APPEND <ls_data> TO <lt_tgt_data>.
    ELSE.
      WRITE‘Field COUNTRY not found in table’pv_tabname.
      EXIT.
    ENDIF.

  ENDLOOP.

  ” Insert data into target country
  MODIFY (pv_tabnameFROM TABLE <lt_tgt_data>.

  IF sysubrc 0.
    WRITE‘Data copied successfully to table’pv_tabname‘for country’pv_tgt_ctry.
  ELSE.
    WRITE‘Failed to copy data to table’pv_tabname‘for country’pv_tgt_ctry.
  ENDIF.
ENDFORM.

 

Scroll to Top