Transfer large volume of Data from one server to another in SAP

light111Transfer large volume of Data from one server to another in SAP


Sometimes we come to scenarios where we need to move large volume of data from one server to another. If number of records in source server is in thousands or lakhs then by using RFC we can send the data in destination server and update the relevant tables in one shot. But if the number of records are in crores then fetching this huge data will take much time and we might get dump for SELECT statement. To overcome this we can use Open Cursor Statement with select statement and extract records in packages, but Internal table is also having some limit to store the data at run time and here it will fail. If we call RFC in Open cursor – DO — ENDDO part then Calling a RFC triggers internal commit and Cursor will closed, in this case it wont fetch next package (FETCH NEXT CURSOR). We need to use statement ‘KEEPING LOGICAL UNIT OF WORK‘ while calling RFC to stop the internal commit as

CALL FUNCTION ‘Z_TABLE_UPDATE’ DESTINATION gv_rfcdest KEEPING LOGICAL UNIT OF WORK.


Sample Code- In Source Server:

REPORT  ztransfer.

* Types declaration for the fields that need to be pushed
TYPES BEGIN OF ty_zpushdata,
mblnr  TYPE mblnr,
mjahr  TYPE mjahr,
zeile TYPE mblpo,
bwart  TYPE bwart,
matnr  TYPE matnr,
werks  TYPE werks_d,
lgort  TYPE lgort_d,
END OF ty_zpushdata.

DATA gt_zpushdata           TYPE STANDARD TABLE OF ty_zpushdata,
             gv_records_transferred TYPE int4,  “No. of transferred records
             gv_rfcdest                TYPE ldapgatewrfcdest,
            gv_cursor                 TYPE cursor,
            fl_result                    TYPE flag,  “Success Flag
            gw_text                     TYPE char100.

FIELD-SYMBOLS <fs_zpushdata> TYPE ty_zpushdata.

* Input parameter to get Package Size
PARAMETERS p_pack TYPE int4 DEFAULT 50000 OBLIGATORY.

START-OF-SELECTION.

IF p_pack LT 50000.
MESSAGE s208(00WITH ‘Packge size can not be less than 50,000’ DISPLAY LIKE ‘E’.
LEAVE LIST-PROCESSING.
ENDIF.

REFRESH gt_zpushdata[].
CLEAR gv_cursor,
gv_records_transferred.

* Open Cursor to fetch records in Package
OPEN CURSOR WITH HOLD gv_cursor FOR
SELECT mblnr
                mjahr
                zeile
                bwart
                matnr
                werks
                 lgort
FROM zpushdata.
DO.
TRY.
FETCH NEXT CURSOR gv_cursor INTO TABLE gt_zpushdata
PACKAGE SIZE p_pack.
IF sysubrc NE 0.
CLOSE CURSOR gv_cursor.
CLEAR sysubrc.

EXIT.
ELSE.

UNASSIGN <fs_zpushdata>.
LOOP AT gt_zpushdata ASSIGNING <fs_zpushdata>.
*           Logic can be written here to change field values (Plant, SLoc.. etc)
ENDLOOP.
UNASSIGN <fs_zpushdata>.

ENDIF.

CLEAR fl_result.

*       Calling the RFC to push the Data
CALL FUNCTION ‘Z_TRANSFER’ DESTINATION gv_rfcdest KEEPING LOGICAL UNIT OF WORK
IMPORTING
e_success               fl_result
TABLES
t_zpushdata           gt_zpushdata
EXCEPTIONS
communication_failure MESSAGE gw_text
system_failure        MESSAGE gw_text
OTHERS                99.

IF sysubrc NE 0.
MESSAGE e208(00WITH gw_text.
RETURN.
ELSE.
*         Get the count for Success records
IF fl_result IS NOT INITIAL.
gv_records_transferred gv_records_transferred + linesgt_zpushdata ).
ENDIF.
ENDIF.

CATCH cx_root.

EXIT.

ENDTRY.

REFRESH gt_zpushdata[].

ENDDO.

MESSAGE s368(00WITH gv_records_transferred ‘Records have been transferred’.

In Destination Server:

Here we need to create RFC with Exporting parameter E_SUCCESS TYPE FLAG and Table Parameter T_ZPUSHDATA LIKE ZPUSHDATA.

In Source code of RFC:

IF t_zpushdata[] IS NOT INITIAL.
* Lock the Table 
CALL FUNCTION ‘ENQUEUE_E_TABLE’
EXPORTING
mode_rstable   ‘E’
tabname        ‘ZPUSHDATA’
EXCEPTIONS
foreign_lock   1
system_failure 2
OTHERS         3.
IF sysubrc IS INITIAL.

MODIFY zpushdata FROM TABLE t_zpushdata.
IF sysubrc IS INITIAL.
CALL FUNCTION ‘DB_COMMIT’.
e_success abap_true.
ENDIF.

CALL FUNCTION ‘DEQUEUE_E_TABLE’
EXPORTING
mode_rstable ‘E’
tabname      ‘ZPUSHDATA’.
ENDIF.
ENDIF.


 

2 comments

  1. Thanks a lot for this. I’m an SAP BW consultant with not much of ABAP exposure before, this will definitely help me especially when creating Function Module based BW Datasources. 🙂

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s