Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ARFC : How to define the return subroutine ?

Former Member
0 Likes
1,091

Hi,

In an ARFC how we will define a return subroutine?

call function 'Z_RFC_EXEC'
       starting new task g_task_name
       destination in group us_srvgrp
       performing <b>task_return</b> on end of task

do we have to define the subroutine task_return in the main program ? if so how to build it ?

Could we put an ARFC inside an OPEN CURSOR and CLOSE CURSOR ?

rgds,

abhilash

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
985

Hi abhilash,

1 do we have to define the subroutine task_return in the main program ? if so how to build it ?

Yes, in your se38 program itself.

in this manner.

<b>FORM task_return USING TASKNAME</b>

2. This code may help u (just copy paste_

3.

report abc.

DATA: INFO LIKE RFCSI,

  • Result of the RFC_SYSTEM_INFO function

MSG(80) VALUE SPACE,

  • Exception handling

RET_SUBRC like SY-SUBRC.

  • SY-SUBRC handling

CALL FUNCTION 'RFC_SYSTEM_INFO'

STARTING NEW TASK 'INFO'

PERFORMING RETURN_INFO ON END OF TASK

EXCEPTIONS

COMMUNICATION_FAILURE = 1 MESSAGE MSG

SYSTEM_FAILURE = 2 MESSAGE MSG.

IF SY-SUBRC = 0.

WRITE: 'Wait for response'.

ELSE.

WRITE MSG.

ENDIF.

...

AT USER-COMMAND.

  • Return from the form routine RETURN_INFO using SET USER-COMMAND

IF SY-UCOMM = 'OKCD'.

IF RET_SUBRC = 0.

WRITE: 'Destination =', INFO-RFCDEST.

ELSE.

WRITE MSG.

ENDIF.

ENDIF.

...

*----


*

*----


FORM RETURN_INFO USING TASKNAME.

RECEIVE RESULTS FROM FUNCTION 'RFC_SYSTEM_INFO'

IMPORTING RFCSI_EXPORT = INFO

EXCEPTIONS

COMMUNICATION_FAILURE = 1 MESSAGE MSG

SYSTEM_FAILURE = 2 MESSAGE MSG.

RET_SUBRC = SY-SUBRC. "Setn RET_SUBRC

SET USER-COMMAND 'OKCD'. "Set OK_CODE

ENDFORM. "RETURN_INFO

regards,

amit m.

8 REPLIES 8
Read only

Former Member
0 Likes
986

Hi abhilash,

1 do we have to define the subroutine task_return in the main program ? if so how to build it ?

Yes, in your se38 program itself.

in this manner.

<b>FORM task_return USING TASKNAME</b>

2. This code may help u (just copy paste_

3.

report abc.

DATA: INFO LIKE RFCSI,

  • Result of the RFC_SYSTEM_INFO function

MSG(80) VALUE SPACE,

  • Exception handling

RET_SUBRC like SY-SUBRC.

  • SY-SUBRC handling

CALL FUNCTION 'RFC_SYSTEM_INFO'

STARTING NEW TASK 'INFO'

PERFORMING RETURN_INFO ON END OF TASK

EXCEPTIONS

COMMUNICATION_FAILURE = 1 MESSAGE MSG

SYSTEM_FAILURE = 2 MESSAGE MSG.

IF SY-SUBRC = 0.

WRITE: 'Wait for response'.

ELSE.

WRITE MSG.

ENDIF.

...

AT USER-COMMAND.

  • Return from the form routine RETURN_INFO using SET USER-COMMAND

IF SY-UCOMM = 'OKCD'.

IF RET_SUBRC = 0.

WRITE: 'Destination =', INFO-RFCDEST.

ELSE.

WRITE MSG.

ENDIF.

ENDIF.

...

*----


*

*----


FORM RETURN_INFO USING TASKNAME.

RECEIVE RESULTS FROM FUNCTION 'RFC_SYSTEM_INFO'

IMPORTING RFCSI_EXPORT = INFO

EXCEPTIONS

COMMUNICATION_FAILURE = 1 MESSAGE MSG

SYSTEM_FAILURE = 2 MESSAGE MSG.

RET_SUBRC = SY-SUBRC. "Setn RET_SUBRC

SET USER-COMMAND 'OKCD'. "Set OK_CODE

ENDFORM. "RETURN_INFO

regards,

amit m.

Read only

0 Likes
985

hi amit,

Thanks..

i am making a function module to an ARFC.I have to import an Itab from FM.

So where in the form task_return should i mention the Itab.?

How can we get the internal table in the program ?

regards,

abhilash

Read only

0 Likes
985

Hi again,

Simple.

(We have to just take care in callback FORM )

1. First of all declare a blank internal table,

which u will pass to the FM.

2. Suppose :

a) your TASK_RETURN is the call back form name

b) T001 is the TABLES which is returned

c) T001 is also the name of the internal table

3.

FORM RETURN_INFO USING TASKNAME.

<b> RECEIVE RESULTS FROM FUNCTION 'ZAM_FM02'

TABLES T001 = T001.</b>

ENDFORM.

regards,

amit m.

Read only

Former Member
0 Likes
985

Hi again,

1. Taking your same requirement,

2. suppose

a) a new FM which simply populates and returns TABLES T001 (company master)

b) the FM Name is ZAM_FM02

3. After creating the above FM,

just copy paste the code below.

(in the break-point, u will be able

to see the records in T001 internal table)

4.

report abc.

*----


data : t001 like table of t001 with header line.

DATA: INFO LIKE RFCSI,

MSG(80) VALUE SPACE,

RET_SUBRC like SY-SUBRC.

CALL FUNCTION 'ZAM_FM02'

STARTING NEW TASK 'INFO'

PERFORMING RETURN_INFO ON END OF TASK

TABLES

T001 = t001

EXCEPTIONS

COMMUNICATION_FAILURE = 1 MESSAGE MSG

SYSTEM_FAILURE = 2 MESSAGE MSG.

*----


IF SY-SUBRC = 0.

WRITE: 'Wait for response'.

ELSE.

WRITE MSG.

ENDIF.

*----


*

*----


FORM RETURN_INFO USING TASKNAME.

BREAK-POINT.

RECEIVE RESULTS FROM FUNCTION 'ZAM_FM02'

TABLES T001 = T001.

BREAK-POINT. "<----


HERE

ENDFORM. "RETURN_INFO

regards,

amit m.

Read only

0 Likes
985

hi amit,

here is my FM

 CALL FUNCTION 'ORDER_CHANGE_FOR_ACTIVITY'
            STARTING NEW TASK taskname
            PERFORMING return_info ON END OF TASK
       EXPORTING
         flg_lkz                    = set_loek
         flg_lvm                    = set_loev
*        INTERVALL                  = ' '
         selid                      = selid
         testrun                    = pa_testl
         init_tables                = 'X'
         maxnumber                  = pa_wpoc
         called_as_rfc              = 'X'
         export_msg_to_memory       = ' '
        TABLES
          caufv_tab                 = gt_caufv
          table_of_messages         = mess_tab
       EXCEPTIONS
         nothing_to_do              = 1
         wrong_selid                = 2
         OTHERS                     = 3
                .

and my form is

FORM return_info USING taskname.

RECEIVE RESULTS FROM FUNCTION 'ORDER_CHANGE_FOR_ACTIVITY'
       TABLES
          table_of_messages = mess_tab.		

ENDFORM.                    "RETURN_INFO

in this case program gets hanged at the end of the FM

what went wrong ?

regards

abhilash

Read only

0 Likes
985

Hi again,

1. are u able to execute this FM,

normally,

(ie. without any extension of new task)

2. The FM logic might be slow. just check out .

regards,

amit m.

Read only

0 Likes
985

hi amit,

i can run this FM normally. even in aRFC mode also it was runnig, but soon i added the

PERFORMING return_info ON END OF TASK

and the corresponding Subroutine, it is getting hanged until i stop the transaction.

regds

abhilash

Read only

0 Likes
985

Use wait until...statement after the arfc function call to keep the program waiting for the return_info to get executed.

Regards

Sridhar