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

how to get return value from a program using 'submit' statement

ayyappan_venugopal2
Participant
0 Likes
43,462

Hi Gurus,

I am new to abap, trying to call a program within a function module through "SUBMIT" statement.

whats my question is , I am passing importing parameters 'a' and 'b' in the submit statement. I debugged it the values of 'a' and 'b' are correctly passing to calling program and it calculating the result  but i don't know how to get the result back to the calling function module.

Hereby attached the called program and calling fm code. please help me

****************************************************************************************************

FUNCTION ZTEST_GURU.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(A) TYPE  I
*"     REFERENCE(B) TYPE  I
*"  EXPORTING
*"     REFERENCE(C) TYPE  I
*"----------------------------------------------------------------------

submit ztest_guru with p_a = a
                   with p_b = b
                   and return.
   ENDFUNCTION.

**********************************************************************************************************

REPORT  ZTEST_GURU.

data: res type i.

*
parameters: p_a type i ,
                   p_b type i .

res = p_a + p_b.

***********************************************************************************************************

9 REPLIES 9
Read only

Sijin_Chandran
Active Contributor
0 Likes
17,398

Hi ,

U need to use RETURN option while calling SUBMIT for that.

Refer the below link and research about SUBMIT in detail.

http://help.sap.com/saphelp_nw70/helpdata/en/9f/dba51a35c111d1829f0000e829fbfe/content.htm

Read only

basarozgur_kahraman
Contributor
0 Likes
17,398

Hi Ayyappan,

Convert REPORT  ZTEST_GURU to function, if you can. Else, In REPORT  ZTEST_GURU add write statement after res calculation

REPORT  ZTEST_GURU.


data: res type i.


*

parameters: p_a type i ,

                   p_b type i .


res = p_a + p_b.

write res.


and change submit statement like

                   submit ztest_guru with p_a = a

                                                     with p_b = b

                    EXPORTING LIST TO MEMORY

                   and return.

After submit you can get RES value with function LIST_FROM_MEMORY

Example:

DATA list_tab TYPE TABLE OF abaplist.

SUBMIT report EXPORTING LIST TO MEMORY
              AND RETURN.

CALL FUNCTION 'LIST_FROM_MEMORY'
  TABLES
    listobject = list_tab
  EXCEPTIONS
    not_found  = 1
    OTHERS     = 2.

IF sy-subrc = 0.
  CALL FUNCTION 'WRITE_LIST'
    TABLES
      listobject = list_tab.
ENDIF.

Best Regards

Basar Ozgur

Read only

0 Likes
17,398

Thank you Basar..

Read only

Former Member
0 Likes
17,398

Hi,

If the output of the program that you are calling is a list then you can export it to memory and import from memory as the other friend said. But it is not possible to get a single value returned by that program. If the program you are calling is a z program then you can set parameter id of the value you want and get that value in your FM....

thanks,

Aswath.

Read only

0 Likes
17,398

Thank you Aswath.

Read only

Sijin_Chandran
Active Contributor
17,398

Hi Ayappan ,

You can use MEMORY ID technique for accomplishing your task.

EXPORT the value of variable res to a memory id by using the below command in ZTEST_GURU program.

eg: 

res = p_a + p_b.

EXPORT res TO MEMORY ID 'ZTEST'.

And after this IMPORT while calling SUBMIT command.

eg:

submit ztest_guru with p_a = a

                   with p_b = b

                   and return.

IMPORT res FROM MEMORY ID 'ZTEST'.




Read only

0 Likes
17,398

Thank you sijin

Read only

Former Member
0 Likes
17,398

Hi ayyappan,

The approach would depend on the called program i.e, list report or ALV report.

There are two three ways:

1) Using memory ID

2) Using spool

3) Using class CL_SALV_BS_RUNTIME_INFO

1) First you have to export the list to memory and later retrieve the list and then convert it into ASCII using function modules

2) First set up the print parameters of spool. Submit the report and store output in spool and then read the spool

3) First, set runtime information for the submit statement using cl_salv_bs_runtime_info=>set. Then Submit the program. Then get reference for ALV's data using cl_salv_bs_runtime_info=>get_data_ref. Then Assign this reference to a field symbol. This field symbol will now have all the values of the ALV output you need. Then clear runtime data cl_salv_bs_runtime_info=>clear_all( ).

Regards,

Prashant

Read only

0 Likes
17,398

Thank you prashant..