Copy SAP Table Programmatically Using ABAP

To copy a SAP table use function module RS_DD_COPY_OBJ. To activate the copied table use the function module RS_DD_ACTIVATE.

CONSTANTS: c_type TYPE ddeutype VALUE 'T'.

DATA: g_ok TYPE c.

PARAMETERS : p_source TYPE ddobjname,
             p_target TYPE ddobjname.

*Copy DDIC Table
CALL FUNCTION 'RS_DD_COPY_OBJ'
  EXPORTING
    source_name        = p_source
    target_name        = p_target
    objtype            = c_type
  EXCEPTIONS
    not_executed       = 1
    permission_failure = 2
    OTHERS             = 3.
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
  WRITE:/ 'Table Copied Successfully'.

*Activate the copied table
  CALL FUNCTION 'RS_DD_ACTIVATE'
    EXPORTING
      objname = p_target
      objtype = c_type
    IMPORTING
      ok      = g_ok.
ENDIF.

In the selection screen enter Source table and Target table.

copy-sap-table-programatically-1

Output

copy-sap-table-programatically-2

Now go to ABAP Dictionary (SE11) and check the new table created.

copy-sap-table-programatically-3


3 Comments

Leave a Reply

Your email address will not be published.


*