If the process needs to serially execute the FMs in the target system, then QRFC is the option. All the function modules that are assigned as a member with a counter number to the QUEUE are executed one after another. The below post shows how this can be achieved. This shows a flight code creation and then updating it in the target system. So we want to serialize the process, first the creation would happen and then only update not update first and then creation.
------------------------------------------------------------------------------------------------------------------------------------------------
Step1. Target System: Create a RFC enabled function module..
Step2. Target System: Import parameter.
Step3. Target System: Source code. This FM creates (Insert) a new flight code.
Step4. Target System: Creates one more FM.
Step5. Target System: import parameter.
Step6. Target System: Source code which updates an existing flight code.
Step7. Target System: Create the last FM for the test purpose.
Step8. Target System: Import parameter.
Step9. Target System: Sourced code which deletes one flight code.
Step10. Target System: current record status in table.
Step11. Calling System: We will use this RFC destination created in Tcode- SM59 for our test purpose. OD a connection test.
Step12. Calling System: The connection is successful.
Step13. Calling System: Here is the program which prepares a Queue with a particular name and calls each RFC function modules.
Here for the demo purpose. We will call two RFC FMs in sequential order. One which creates a flight code and then one more RFC FM which updates the flight code. As we want to use qRFC technique, then before calling each CREATE & UPDATE RFC FM , we have to call the FM 'TRFC_SET_QUEUE_NAME' before calling create or update FM.
---------------------------------------------------------------------------------------------------------------------------------------------
REPORT zqrfc_flight_test.
TYPES: BEGIN OF ty_res,
dest TYPE rfcdest,
tid TYPE arfctid,
xcall TYPE i,
END OF ty_res.
SELECTION-SCREEN: BEGIN OF BLOCK b1.
PARAMETERS : carr TYPE scarr-carrid,
cr AS CHECKBOX, " create
up AS CHECKBOX, "update
dl AS CHECKBOX. "delete
SELECTION-SCREEN: END OF BLOCK b1.
DATA : ls TYPE scarr,
lt_res TYPE TABLE OF ty_res,
ls_res TYPE ty_res,
indx TYPE i.
ls-carrid = carr.
IF cr = 'X'.
CALL FUNCTION 'TRFC_SET_QUEUE_NAME' " sett the queue name by calling FM
EXPORTING
qname = 'DEV_TED_QUEUE_FLIGHT' " queue name
EXCEPTIONS
invalid_queue_name = 1
OTHERS = 2.
IF sy-subrc <> 0.
EXIT.
ENDIF.
CALL FUNCTION 'ZRFC_CREATE_AIRLINE_CODE'
IN BACKGROUND TASK AS SEPARATE UNIT " qRFC counter 1
DESTINATION 'QRFC_DEST_TEST'
EXPORTING
ls = ls.
CALL FUNCTION 'ID_OF_BACKGROUNDTASK' " call the FM which will gibe the TID
EXPORTING
dest = 'QRFC_DEST_TEST' " rfc destination name
IMPORTING
tid = ls_res-tid.
ls_res-dest = 'QRFC_DEST_TEST'.
indx = indx + 1.
ls_res-xcall = indx.
APPEND ls_res TO lt_res.
CLEAR ls_res.
ENDIF.
IF up = 'X'.
CALL FUNCTION 'TRFC_SET_QUEUE_NAME' " sett the queue name by calling FM
EXPORTING
qname = 'DEV_TED_QUEUE_FLIGHT'
EXCEPTIONS
invalid_queue_name = 1
OTHERS = 2.
IF sy-subrc <> 0.
EXIT.
ENDIF.
LS-CARRNAME = 'NEW CARRNAME'. " SENDING CARRNAME FIELD AS UPDATE
CALL FUNCTION 'ZRFC_UPDATE_AIRLINE_CODE'
IN BACKGROUND TASK AS SEPARATE UNIT " qRFC counter 2
DESTINATION 'QRFC_DEST_TEST'
EXPORTING
ls = ls.
CALL FUNCTION 'ID_OF_BACKGROUNDTASK'
EXPORTING
dest = 'QRFC_DEST_TEST'
IMPORTING
tid = ls_res-tid.
ls_res-dest = 'QRFC_DEST_TEST'.
indx = indx + 1.
ls_res-xcall = indx.
APPEND ls_res TO lt_res.
CLEAR ls_res.
ENDIF.
IF dl = 'X'.
CALL FUNCTION 'TRFC_SET_QUEUE_NAME' " sett the queue name by calling FM
EXPORTING
qname = 'DEV_TED_QUEUE_FLIGHT'
EXCEPTIONS
invalid_queue_name = 1
OTHERS = 2.
IF sy-subrc <> 0.
EXIT.
ENDIF.
CALL FUNCTION 'ZRFC_DELETE_AIRLINE_CODE'
IN BACKGROUND TASK AS SEPARATE UNIT " " qRFC counter 3
DESTINATION 'QRFC_DEST_TEST'
EXPORTING
ls = ls.
CALL FUNCTION 'ID_OF_BACKGROUNDTASK'
EXPORTING
dest = 'QRFC_DEST_TEST'
IMPORTING
tid = ls_res-tid.
ls_res-dest = 'QRFC_DEST_TEST'.
indx = indx + 1.
ls_res-xcall = indx.
APPEND ls_res TO lt_res.
CLEAR ls_res.
ENDIF.
COMMIT WORK. " triggers the outbound queue by the scheduler
LOOP AT lt_res INTO ls_res.
WRITE : / ls_res-dest, ls_res-tid, ls_res-xcall.
ENDLOOP.
--------------------------------------------------------------------------------------------------------------------------------------------
Step14. Calling System: Go to tcode- SMQ1 which shows the outbound queues.
Step15. Calling System: execute.
Step16. Calling System: Currently there is no queue waiting.
Step17. Calling System: Go to Tcode- SMQS which is the qRFC scheduler.
Step18. Calling System: Let's register our RFC destination here which is used in our program. Click on the registration button.
Step19. Calling System: Form the pop up, with F4 option select our RFC destination.
Step20. Calling System: Here is our rfc destination and continue.
Step21. Calling System: So here our rfc destination is added to the outbound scheduler. Check that type is R. Which means the RFC destination is registered. When any call happens from the program with this RFC destination, if its type - R then the system automatically start processing it.
Step22. Calling System: Select our rfc destination by checking the check box from the left side and click on deregistration button.
Step23. Calling System: Continue.
Step24. Calling System: So the type - U now, which means any call made by using this RFC destination, the system/the scheduler will not process those automatically unless until the type is R.
Actually we don't need to register any RFC destination in SMQS transaction. When ever any call is made from program by using qRFC concept with a rfc destination and when the subsequent commit work statement is executed in the program, then automatically the RFC destination is added to this transaction with type R and the scheduler starts processing it. For our demo process we need to understand how exactly it works, for that reason we registered the RFC destination and make as type U from R. later we will make it as R to execute our queue fMs.
Step25. Calling System: Execute the above report. Provide a flight code- ( carr field ) and choose CR ( create) and UP( update) check box and execute it. Make sure that the debug point is set in the report program also to under stand the process. Step 13 tells where to set debug point. Also set debug point in RFC FMs in the target system.
Step26. Calling System: The debugger is triggered here. we are at line 45. when qRFC FM is called, in the background it creates a transaction ID number which is temporarily stored in the table. This can be retrieved by using the FM ID_OF_BACKGROUNDTASK and passing the rfc destination name to it. Here we just need to display it.
Step27. Calling System: Continue the execution in the debugger with F5 or F6 button. as we have selected the update check box also, it exeucutes this option.
Step28. Calling System: we are the point where the two qRFC are called ( create and update). but the commit work statement has not been triggered yet. double click on LT_RES internal table in the debugger to see its contents.
Step29. Calling System: Here we have two entries with the transaction id for both the qRFC calls. Go back (F3).
Step30. Calling System: press F6 to complete commit work statement execution.
Step31. Calling System: So here we are. Now we have to check what has happened in the system by the execution of commit work statement.
Step32. Calling System: go to tcode- SMQ1 . previously in our check there was no records now we have one record. it displays the queue name and rfc destination name. in the QUEUE Information section, no of queue is 1 and inside that queue there are two FM calls one for create and one for update.
Step33. Calling System: Double click on the queue name and it will show the two RFC FM names which will be called in sequence.
Step35. Calling System: Go to tcode- SMQS the outbound scheduler. From here also we can move to the Tcode- SMQ1 as well. Select our destination by selecting the check box from the left side and click on the QRFC Monitor button.
Step36. Calling System: So here we are again what we observed in SMQ1 tcode. Go back.
Step37. Calling System: Now we have to make ourRFC destination mode as R so that the scheduler starts executing the queue. Select the check box from left side for the RFC destination and click on registration button. Here mark some thing , the scheduler status is inactive as nothing is there to process and also our RFC destination line status is inactive. Select our destination by selecting the check from from the left side and click on registration button.
Step38. Calling System: Continue.
Step39. Calling System: So the type is R now and notice the scheduler status is starting from Inactive. Now the scheduler starts executing the FMs that line in this queue. If the debug point has been set in the target RFC FMs that would have been triggered.
Step40. Target System: So here the debugger is. Hold here the debugger don't press F8.
Step41. Calling System: check the tcode- SMQ1 and here the status is running and also there are 2 entries out of which first is executing.
Step42. Calling System: Go to tcode- SMQS and scheduler status is waiting and also our destination status is waiting with action conn 1.
Step43. Target System: Go to the debugger and press F8. So the first create FM finished its execution.
Step44. Target System: So again the scheduler starts executing the second FM in the queue. Hold the debugger here don't press f8.
Step45. Target System: Check the table entries. So one record has been creates with id ZZ.
Step46. Calling System: Go to Tcode- SMQ1 and check the status and entries. Out of 1 entries first entry has already been executed and the second is running.
Step47. Calling System: Go to Tcode- SMQS and check the status as well.
Step48. Target System: Go to the debugger and press F8 to finish the execution.
Step49. Target System: check in the table. OS it has been properly updated with carrname field.
Step50. Calling System: Goto tocde- SMQ1 and refresh it.
Step51. Calling System: there would be no more queues with our destination.
Step52. Calling System: check tcode- SMQS and the scheduler status is inactive and our rfc destination line status is also inactive.
------------------------------------------------------------------------------------------------------------------------------------------------
Step1. Target System: Create a RFC enabled function module..
Step2. Target System: Import parameter.
Step3. Target System: Source code. This FM creates (Insert) a new flight code.
Step4. Target System: Creates one more FM.
Step5. Target System: import parameter.
Step6. Target System: Source code which updates an existing flight code.
Step7. Target System: Create the last FM for the test purpose.
Step8. Target System: Import parameter.
Step9. Target System: Sourced code which deletes one flight code.
Step10. Target System: current record status in table.
Step11. Calling System: We will use this RFC destination created in Tcode- SM59 for our test purpose. OD a connection test.
Step12. Calling System: The connection is successful.
Step13. Calling System: Here is the program which prepares a Queue with a particular name and calls each RFC function modules.
Here for the demo purpose. We will call two RFC FMs in sequential order. One which creates a flight code and then one more RFC FM which updates the flight code. As we want to use qRFC technique, then before calling each CREATE & UPDATE RFC FM , we have to call the FM 'TRFC_SET_QUEUE_NAME' before calling create or update FM.
---------------------------------------------------------------------------------------------------------------------------------------------
REPORT zqrfc_flight_test.
TYPES: BEGIN OF ty_res,
dest TYPE rfcdest,
tid TYPE arfctid,
xcall TYPE i,
END OF ty_res.
SELECTION-SCREEN: BEGIN OF BLOCK b1.
PARAMETERS : carr TYPE scarr-carrid,
cr AS CHECKBOX, " create
up AS CHECKBOX, "update
dl AS CHECKBOX. "delete
SELECTION-SCREEN: END OF BLOCK b1.
DATA : ls TYPE scarr,
lt_res TYPE TABLE OF ty_res,
ls_res TYPE ty_res,
indx TYPE i.
ls-carrid = carr.
IF cr = 'X'.
CALL FUNCTION 'TRFC_SET_QUEUE_NAME' " sett the queue name by calling FM
EXPORTING
qname = 'DEV_TED_QUEUE_FLIGHT' " queue name
EXCEPTIONS
invalid_queue_name = 1
OTHERS = 2.
IF sy-subrc <> 0.
EXIT.
ENDIF.
CALL FUNCTION 'ZRFC_CREATE_AIRLINE_CODE'
IN BACKGROUND TASK AS SEPARATE UNIT " qRFC counter 1
DESTINATION 'QRFC_DEST_TEST'
EXPORTING
ls = ls.
CALL FUNCTION 'ID_OF_BACKGROUNDTASK' " call the FM which will gibe the TID
EXPORTING
dest = 'QRFC_DEST_TEST' " rfc destination name
IMPORTING
tid = ls_res-tid.
ls_res-dest = 'QRFC_DEST_TEST'.
indx = indx + 1.
ls_res-xcall = indx.
APPEND ls_res TO lt_res.
CLEAR ls_res.
ENDIF.
IF up = 'X'.
CALL FUNCTION 'TRFC_SET_QUEUE_NAME' " sett the queue name by calling FM
EXPORTING
qname = 'DEV_TED_QUEUE_FLIGHT'
EXCEPTIONS
invalid_queue_name = 1
OTHERS = 2.
IF sy-subrc <> 0.
EXIT.
ENDIF.
LS-CARRNAME = 'NEW CARRNAME'. " SENDING CARRNAME FIELD AS UPDATE
CALL FUNCTION 'ZRFC_UPDATE_AIRLINE_CODE'
IN BACKGROUND TASK AS SEPARATE UNIT " qRFC counter 2
DESTINATION 'QRFC_DEST_TEST'
EXPORTING
ls = ls.
CALL FUNCTION 'ID_OF_BACKGROUNDTASK'
EXPORTING
dest = 'QRFC_DEST_TEST'
IMPORTING
tid = ls_res-tid.
ls_res-dest = 'QRFC_DEST_TEST'.
indx = indx + 1.
ls_res-xcall = indx.
APPEND ls_res TO lt_res.
CLEAR ls_res.
ENDIF.
IF dl = 'X'.
CALL FUNCTION 'TRFC_SET_QUEUE_NAME' " sett the queue name by calling FM
EXPORTING
qname = 'DEV_TED_QUEUE_FLIGHT'
EXCEPTIONS
invalid_queue_name = 1
OTHERS = 2.
IF sy-subrc <> 0.
EXIT.
ENDIF.
CALL FUNCTION 'ZRFC_DELETE_AIRLINE_CODE'
IN BACKGROUND TASK AS SEPARATE UNIT " " qRFC counter 3
DESTINATION 'QRFC_DEST_TEST'
EXPORTING
ls = ls.
CALL FUNCTION 'ID_OF_BACKGROUNDTASK'
EXPORTING
dest = 'QRFC_DEST_TEST'
IMPORTING
tid = ls_res-tid.
ls_res-dest = 'QRFC_DEST_TEST'.
indx = indx + 1.
ls_res-xcall = indx.
APPEND ls_res TO lt_res.
CLEAR ls_res.
ENDIF.
COMMIT WORK. " triggers the outbound queue by the scheduler
LOOP AT lt_res INTO ls_res.
WRITE : / ls_res-dest, ls_res-tid, ls_res-xcall.
ENDLOOP.
Step14. Calling System: Go to tcode- SMQ1 which shows the outbound queues.
Step15. Calling System: execute.
Step16. Calling System: Currently there is no queue waiting.
Step17. Calling System: Go to Tcode- SMQS which is the qRFC scheduler.
Step18. Calling System: Let's register our RFC destination here which is used in our program. Click on the registration button.
Step19. Calling System: Form the pop up, with F4 option select our RFC destination.
Step20. Calling System: Here is our rfc destination and continue.
Step21. Calling System: So here our rfc destination is added to the outbound scheduler. Check that type is R. Which means the RFC destination is registered. When any call happens from the program with this RFC destination, if its type - R then the system automatically start processing it.
Step22. Calling System: Select our rfc destination by checking the check box from the left side and click on deregistration button.
Step23. Calling System: Continue.
Step24. Calling System: So the type - U now, which means any call made by using this RFC destination, the system/the scheduler will not process those automatically unless until the type is R.
Actually we don't need to register any RFC destination in SMQS transaction. When ever any call is made from program by using qRFC concept with a rfc destination and when the subsequent commit work statement is executed in the program, then automatically the RFC destination is added to this transaction with type R and the scheduler starts processing it. For our demo process we need to understand how exactly it works, for that reason we registered the RFC destination and make as type U from R. later we will make it as R to execute our queue fMs.
Step25. Calling System: Execute the above report. Provide a flight code- ( carr field ) and choose CR ( create) and UP( update) check box and execute it. Make sure that the debug point is set in the report program also to under stand the process. Step 13 tells where to set debug point. Also set debug point in RFC FMs in the target system.
Step26. Calling System: The debugger is triggered here. we are at line 45. when qRFC FM is called, in the background it creates a transaction ID number which is temporarily stored in the table. This can be retrieved by using the FM ID_OF_BACKGROUNDTASK and passing the rfc destination name to it. Here we just need to display it.
Step27. Calling System: Continue the execution in the debugger with F5 or F6 button. as we have selected the update check box also, it exeucutes this option.
Step28. Calling System: we are the point where the two qRFC are called ( create and update). but the commit work statement has not been triggered yet. double click on LT_RES internal table in the debugger to see its contents.
Step29. Calling System: Here we have two entries with the transaction id for both the qRFC calls. Go back (F3).
Step30. Calling System: press F6 to complete commit work statement execution.
Step31. Calling System: So here we are. Now we have to check what has happened in the system by the execution of commit work statement.
Step32. Calling System: go to tcode- SMQ1 . previously in our check there was no records now we have one record. it displays the queue name and rfc destination name. in the QUEUE Information section, no of queue is 1 and inside that queue there are two FM calls one for create and one for update.
Step33. Calling System: Double click on the queue name and it will show the two RFC FM names which will be called in sequence.
Step35. Calling System: Go to tcode- SMQS the outbound scheduler. From here also we can move to the Tcode- SMQ1 as well. Select our destination by selecting the check box from the left side and click on the QRFC Monitor button.
Step36. Calling System: So here we are again what we observed in SMQ1 tcode. Go back.
Step37. Calling System: Now we have to make ourRFC destination mode as R so that the scheduler starts executing the queue. Select the check box from left side for the RFC destination and click on registration button. Here mark some thing , the scheduler status is inactive as nothing is there to process and also our RFC destination line status is inactive. Select our destination by selecting the check from from the left side and click on registration button.
Step38. Calling System: Continue.
Step39. Calling System: So the type is R now and notice the scheduler status is starting from Inactive. Now the scheduler starts executing the FMs that line in this queue. If the debug point has been set in the target RFC FMs that would have been triggered.
Step40. Target System: So here the debugger is. Hold here the debugger don't press F8.
Step41. Calling System: check the tcode- SMQ1 and here the status is running and also there are 2 entries out of which first is executing.
Step42. Calling System: Go to tcode- SMQS and scheduler status is waiting and also our destination status is waiting with action conn 1.
Step43. Target System: Go to the debugger and press F8. So the first create FM finished its execution.
Step44. Target System: So again the scheduler starts executing the second FM in the queue. Hold the debugger here don't press f8.
Step45. Target System: Check the table entries. So one record has been creates with id ZZ.
Step46. Calling System: Go to Tcode- SMQ1 and check the status and entries. Out of 1 entries first entry has already been executed and the second is running.
Step47. Calling System: Go to Tcode- SMQS and check the status as well.
Step48. Target System: Go to the debugger and press F8 to finish the execution.
Step49. Target System: check in the table. OS it has been properly updated with carrname field.
Step50. Calling System: Goto tocde- SMQ1 and refresh it.
Step51. Calling System: there would be no more queues with our destination.
Step52. Calling System: check tcode- SMQS and the scheduler status is inactive and our rfc destination line status is also inactive.
No comments:
Post a Comment