qRFC is very useful way to call program many times chronologically. I've checked how to program and process types.
Strong points
Strong points of qRFC are as follows.
- Process asynchronously
- Process chronologically
- When an error occurs, stop the queue and succeeding processes
The simplest program to use qRFC
The following program generates outbound queue. It's very simple!
Report YSIMPEST_QRFC
* Set an outbound queue name
CALL FUNCTION 'TRFC_SET_QUEUE_NAME'
EXPORTING
qname = 'YTEST01'
EXCEPTIONS
invalid_queue_name = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE e001(00) WITH 'TRFC_SET_QUEUE_NAME error'.
ENDIF.
* Call RFC module as qRFC
CALL FUNCTION 'RFC_PING'
IN BACKGROUND TASK
AS SEPARATE UNIT.
COMMIT WORK.
IF sy-subrc <> 0.
MESSAGE e001(00) WITH 'Commit error with return code:' sy-subrc.
ENDIF.
3 ways to use qRFC
There are 3 ways to use qRFC. See the below picture.
Please see help portal page "qRFC Communication Model."
Type A: Outbound queue only
The following program uses outbound queue only.
REPORT YQRFC_OUTBOUND.
* Number of queues to be created
PARAMETERS p_queue TYPE i DEFAULT 1000.
START-OF-SELECTION.
DO p_queue TIMES.
* Set queue name
CALL FUNCTION 'TRFC_SET_QUEUE_NAME'
EXPORTING
qname = 'YTEST01'
EXCEPTIONS
invalid_queue_name = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE e001(00) WITH 'Function TRFC_SET_QUEUE_NAME error'.
ENDIF.
* call as qRFC
CALL FUNCTION 'RFC_PING'
IN BACKGROUND TASK
AS SEPARATE UNIT.
ENDDO.
* Commit is necessary
COMMIT WORK.
IF sy-subrc <> 0.
MESSAGE e001(00) WITH 'Commit error with sy-subrc:' sy-subrc.
ENDIF.
Type B: Inbound queue only, Type C :Outbound and nbound queue
The below program generates only inbound queue or both outbound and inbound queue. When rfc destination is 'NONE' or omitted, it's type B.
REPORT YQRFC_INBOUND.
PARAMETERS:
p_num TYPE i DEFAULT 100,
p_in TYPE trfcqnam DEFAULT 'YTEST01_IN',
p_out TYPE trfcqnam DEFAULT 'YTEST01_OUT',
p_rfc TYPE rfcdest DEFAULT 'NONE'.
START-OF-SELECTION.
DO p_num TIMES.
CALL FUNCTION 'TRFC_SET_QIN_PROPERTIES'
EXPORTING
qout_name = p_out
qin_name = p_in
EXCEPTIONS
invalid_queue_name = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE e001(00) WITH 'TRFC_SET_QIN_PROPERTIES error'.
ENDIF.
CALL FUNCTION 'RFC_PING'
IN BACKGROUND TASK
DESTINATION p_rfc
AS SEPARATE UNIT.
ENDDO.
COMMIT WORK.
IF sy-subrc <> 0.
MESSAGE e001(00) WITH 'Commit error with return code:' sy-subrc.
ENDIF.
As for type C, outbound queue is deleted when inbound queue is completely generated. The outbound queue's lifespan is not up to if inbound queue is finished or not.