Dynamic table copy

Dynamic table copy

Use this tip to make a dynamic table copy from a production system to a test system.

The solution consists of two programs -- a function-module named z_bcsag_tablecopy_remote and a report named zbcsag_tablecopy. In the report you can specify the name of the table to be copied and the destination, which is used to get the connection to the productive system.

In order to get it to work on your system, you first have to create the two programs in your test system. Then you have to create two objects -- zchar45 and zchar1000 -- with SE11. Click DATA-TYPE, then button create, and chose TABLE-TYPE / Built-in TYPE / DATA-TYPE CHAR / No. of Characters 45 and 1000.

Then transport the function-module into your productive system. After this you must create a destination to your production system. That's all!


FUNCTION z_bcsag_tablecopy_remote.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"  IMPORTING
*"     VALUE(QUELL_TAB_NAME) LIKE  DD02L-TABNAME
*"     VALUE(TAB_CONDITION) TYPE  ZCHAR45
*"  EXPORTING
*"     VALUE(TAB_RESULT) TYPE  ZCHAR1000
*"  EXCEPTIONS
*"      ERROR
*"----------------------------------------------------------------------

  SELECT * FROM (quell_tab_name) INTO TABLE tab_result
                                 WHERE (tab_condition).
ENDFUNCTION.



REPORT zbcsag_tablecopy LINE-SIZE 132
                        NO STANDARD PAGE HEADING.
*"----------------------------------------------------------------------
*" Report to copy a table from another system.
*"----------------------------------------------------------------------

SELECTION-SCREEN BEGIN OF BLOCK outer_block WITH FRAME.

PARAMETERS: tabelle  LIKE dd02l-tabname OBLIGATORY,   "Tabellenname
            rfc_dest LIKE rfcdes-rfcdest,             "Destination
            simu     TYPE tst_on DEFAULT 'X'.         "Simulation

SELECTION-SCREEN BEGIN OF BLOCK cond_block WITH FRAME TITLE text-001.
PARAMETERS: cond1(45),                                "Where-Klausel 1
            cond2(45),                                "Where-Klausel 2
            cond3(45),                                "Where-Klausel 3
            cond4(45),                                "Where-Klausel 4
            cond5(45).                                "Where-Klausel 5
SELECTION-SCREEN END OF BLOCK cond_block.

SELECTION-SCREEN END OF BLOCK outer_block.

DATA: it_condition TYPE zchar45.
DATA: it_tab TYPE zchar1000.
DATA: wa_it_tab(1000).

DATA: d_ref TYPE REF TO data.

FIELD-SYMBOLS: <cond> TYPE c,
               <copytab> TYPE ANY.

DATA: feldname(5),
      i TYPE n,
      count_commit TYPE i.

TABLES: tddat.


* Prüfung auf Berechtigung
SELECT SINGLE * FROM tddat WHERE tabname = tabelle.
AUTHORITY-CHECK OBJECT 'S_TABU_DIS'
    ID 'DICBERCLS' FIELD tddat-cclass
    ID 'ACTVT' FIELD '02'.
if sy-subrc < > 0.
  MESSAGE ID 'ZS-ALLG' TYPE 'E' NUMBER 000
           WITH 'Tabellenberechtigung fehlt!!!' .
endif.

* Kopiert werden darf nur in Testsysteme!!!!!!
IF sy-sysid(1) < > 'C'.
  MESSAGE ID 'ZS-ALLG' TYPE 'E' NUMBER 000
           WITH 'Report nur im Testsystem verwenden!!' .
ENDIF.


* Tabelle für Where-Bedingung zusammenbauen REFRESH it_condition.
DO 5 TIMES.
  i = sy-index.
  CONCATENATE 'cond' i INTO feldname.
  ASSIGN (feldname) TO <cond>.
  IF NOT ( <cond> IS INITIAL ).
    INSERT <cond> INTO TABLE it_condition.
  ENDIF.
ENDDO.

* Daten aus dem Remote-System holen über RFC-Destination CALL FUNCTION 'Z_BCSAG_TABLECOPY_REMOTE' DESTINATION rfc_dest
  EXPORTING
    quell_tab_name  = tabelle            "Name der Tabelle
    tab_condition   = it_condition       "Where-Bedingung
  IMPORTING
    tab_result      = it_tab             "Result-Set
  EXCEPTIONS
    error                = 1
    OTHERS               = 2.

* Programmabbruch wenn remote-lesen nicht funktioniert hat.
IF sy-subrc < > 0.
  IF simu = 'X'.
    WRITE: /'Returncode: ', sy-subrc.
  ELSE.
    MESSAGE ID 'ZS-ALLG' TYPE 'A' NUMBER 000
            WITH 'Lesefehler in Funktionsbaustein' .
  ENDIF.
ENDIF.


* Datenreferenz auf Struktur der gewünschten Tabelle erstellen CREATE DATA d_ref TYPE (tabelle).
ASSIGN d_ref->*

    Requires Free Membership to View

    When you register, you will start receiving targeted emails from my award-winning team of editorial writers. Our goal is to keep you informed on the hottest topics and biggest challenges faced by SAP professionals today.

    Hannah Smalltree, Editorial Director

    By submitting your registration information to SearchSAP.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchSAP.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

TO <copytab>. * Result-Set satzweise im lokalen System wegschreiben. LOOP AT it_tab INTO <copytab>. * Bei Simulation Sätze nur ausgeben. WRITE: / <copytab>(70). IF simu NE 'X'. INSERT INTO (tabelle) VALUES . IF sy-subrc NE 0 . UPDATE (tabelle) FROM . ENDIF . ADD 1 TO count_commit . IF count_commit = '1000' . COMMIT WORK . count_commit = 0 . ENDIF. ENDIF. ENDLOOP. *----------------------------------------------------------------------* TOP-OF-PAGE. *----------------------------------------------------------------------* WRITE: sy-datum DD/MM/YYYY, 43 'Tabellen zw. Systemen kopieren', 'System:', sy-sysid, 123 'Seite:', (3) sy-pagno NO-SIGN. ULINE. WRITE: / 'Kopierte Sätze aus Tabelle ', tabelle. ULINE.

This was first published in January 2006

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.

    Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.