|Home • Trainings • Quiz • Tips • Tutorials • Functional • Cert Q's • Interview Q's • Jobs • Testimonials • Advertise • Contact Us|
Does RFC function modules work only once in a loop?
By Sarves Sombhatla, Yash Technologies
Sometimes, when we are trying to transfer the data from one
SAP system to another SAP system by looping the RFC function module, only the
data which is looped first will be uploaded and the remaining data will not be
The reason why this happens is when we establish a connection
from one system to another SAP system using an RFC, the global data of the
function group remains, as the connection remains active the global data will
not be cleared, to clear the global data we should close the connection and
re-establish it. By doing this the global data will be freed and we can continue
upload the data completely from one system to another by looping the RFC
To have a clear insight about this topic, check the below
Consider there are 2 SAP systems
In ABC we have a database table and we want to upload the
data from system XYZ to ABC.
In the first sap
1. Create a table (ZRFC_TABLE) with 2 fields
create an RFC function module to upload the data into the table through another
parameter: ITAB type ZRFC_TABLE which is created above.
flag variable in the Global data of the function module.
source code of the function module write the code to update the database table.
function module and activate it.
to another SAP system (XYZ) from where we need to send data to the database
table in the other SAP system (ABC).
report program with the following code.
TYPES: BEGIN OF type_table, mandt TYPE mandt, id TYPE numc2, name TYPE char20, END OF type_table. DATA: itab TYPE TABLE OF type_table, fs TYPE type_table. DATA: id TYPE numc2 VALUE '4'.
DO 5 TIMES. fs-id = id + 1. fs-name = 'Name'. APPEND fs TO itab. id = fs-id. ENDDO.
LOOP AT itab INTO fs. CALL FUNCTION 'ZRFC' DESTINATION 'ABC' EXPORTING itab = fs. ENDLOOP.
In the above report we have not used
RFC_CONNECTION_CLOSE function module. So if we try with the above code the flag
variable which has been declared in the global data of the function module will
be set to ‘X’ and the second time loop will not update the database as the
flag is not cleared.
REPORT ZRFC_REPORT. TYPES: BEGIN OF type_table, mandt TYPE mandt, id TYPE numc2, name TYPE char20, END OF type_table. DATA: itab TYPE TABLE OF type_table, fs TYPE type_table. DATA: id TYPE numc2 VALUE '40'.
DO 5 TIMES. fs-id = id + 1. fs-name = 'sarves'. APPEND fs TO itab. id = fs-id. ENDDO.
LOOP AT itab INTO fs. CALL FUNCTION 'YH1317_RFC' DESTINATION 'R3XCLNT100' EXPORTING itab = fs.
CALL FUNCTION 'RFC_CONNECTION_CLOSE' EXPORTING destination = 'R3XCLNT100' * TASKNAME = * EXCEPTIONS * DESTINATION_NOT_OPEN = 1 * OTHERS = 2 . IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.
When we use the RFC_CONNECTION_CLOSE
function module then the connection will be closed and the global data flag will
This will allow you to update the database
table with complete records.
In the same way when we try to upload data using a standard BAPI/RFC, it is a good practice to close the connection and rebuild it as the global data of the function group will be cleared and we can upload error free data into the SAP system.
Please send us your feedback/suggestions at webmaster@SAPTechnical.COM
©2006-2007 SAPTechnical.COM. All rights reserved.
product names are trademarks of their respective companies. SAPTechnical.COM
is in no way affiliated with SAP AG.
Graphic Design by Round the Bend Wizards