Problem solve Get help with specific problems with your technologies, process and projects.

Dynamic table copy

Learn how to copy SAP information from a table in a production system to a table in a test system in this reader-submitted ABAP tip.

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->* 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 last published in January 2006

Dig Deeper on SAP ABAP

PRO+

Content

Find more PRO+ content and other member only offers, here.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchManufacturingERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchCRM

SearchContentManagement

SearchFinancialApplications

Close