Skip to Content

Hi Everyone, with this post… I want to Share with you a Program that can create and fill tables Z, taken the structure and records of the original Table…

You can transfer all information of standard table to other Z table.

This program maybe is usefull if you need to execute a backup the information of the standard table to the Z table.

Here is the program code.

REPORT  zz_test_cl.

TYPE-POOLS: rs.

PARAMETER: source TYPE ddobjname OBLIGATORY,

           target TYPE ddobjname OBLIGATORY DEFAULT ‘Z’.

DATA: gv_state   TYPE ddgotstate,

      gv_s_dd02v     TYPE dd02v,

      gv_s_dd09l     TYPE dd09l,

      git_dd03p     TYPE dd03p OCCURS 0,

      gv_key         TYPE string,

      gv_rc          TYPE sysubrc,

      gv_langu TYPE rs_bool,

      go_ref_exception   TYPE REF TO cx_root,

      gv_text_exception   TYPE string,

      g_ref_itab TYPE REF TO data,

      g_ref_wa TYPE REF TO data.

FIELD-SYMBOLS:

      <l_s_dd03p>   TYPE dd03p,

      <fs_itab> TYPE ANY TABLE,

      <fs_wa> TYPE ANY.

AT SELECTION-SCREEN.

  IF target(1) <> ‘Z’ AND

    target(1) <> ‘Y’.

    MESSAGE e208(00) WITH ‘Nombre Tabla destino debe comenzar con Z o Y’.

  ENDIF.

START-OF-SELECTION.

*read model table (header and technical settings)

  CALL FUNCTION ‘DDIF_TABL_GET’

    EXPORTING

      name          = source

      state         = ‘A’

      langu         = sylangu

    IMPORTING

      gotstate      = gv_state

      dd02v_wa      = gv_s_dd02v

      dd09l_wa      = gv_s_dd09l

    TABLES

      dd03p_tab     = git_dd03p

    EXCEPTIONS

      illegal_input = 1

      OTHERS        = 2.

  IF     sysubrc    <> 0 OR gv_state <> ‘A’.

    MESSAGE i208(00) WITH ‘Tabla origen no existe o esta inactiva’.

    EXIT.

  ENDIF.

*adjust header

  gv_s_dd02vtabname   = target.

  gv_s_dd02vddtext    = target.

  gv_s_dd02vas4user   = syuname.

  gv_s_dd02vas4date   = sydatum.

  gv_s_dd02vas4time   = syuzeit.

*adjust technical settings

  gv_s_dd09ltabname   = target.

  gv_s_dd09las4user   = syuname.

  gv_s_dd09las4date   = sydatum.

  gv_s_dd09las4time   = syuzeit.

*adjust tablnm

  LOOP AT git_dd03p  ASSIGNING <l_s_dd03p>.

    <l_s_dd03p>tabname = target.

  ENDLOOP.

*create table

  CALL FUNCTION ‘DDIF_TABL_PUT’

    EXPORTING

      name              = target

      dd02v_wa          = gv_s_dd02v

      dd09l_wa          = gv_s_dd09l

    TABLES

      dd03p_tab         = git_dd03p

    EXCEPTIONS

      tabl_not_found    = 1

      name_inconsistent = 2

      tabl_inconsistent = 3

      put_failure       = 4

      put_refused       = 5

      OTHERS            = 6.

  IF sysubrc = 0.

    CALL FUNCTION ‘DDIF_TABL_ACTIVATE’

      EXPORTING

        name        = target

        auth_chk    = rs_c_false

        prid        = 2

      IMPORTING

        rc          = gv_rc

      EXCEPTIONS

        not_found   = 1

        put_failure = 2

        OTHERS      = 3.

    IF sysubrc = 0.

      CREATE DATA g_ref_itab TYPE STANDARD TABLE OF (source)

      WITH NON-UNIQUE DEFAULT KEY.

      ASSIGN g_ref_itab->* TO <fs_itab>.

      SELECT * FROM (source)

      INTO TABLE <fs_itab>.

      IF sysubrc = 0.

        TRY.

            INSERT (target) FROM TABLE <fs_itab>.

            IF sysubrc = 0.

              COMMIT WORK.

              MESSAGE i208(00) WITH ‘Se creo tabla destino y se copio informacion’.

            ENDIF.

          CATCH cx_sy_open_sql_db INTO go_ref_exception.

            gv_text_exception = go_ref_exception->get_text( ).

            MESSAGE e208(00) WITH gv_text_exception .

        ENDTRY.

      ENDIF.

    ENDIF.

  ENDIF.

Good Luck

Best Regards,

Wilmer Figueroa

Senior ABAP Consultant

To report this post you need to login first.

2 Comments

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

Leave a Reply