‎2012 Nov 02 7:22 AM
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.
***********************************************************************************************************
‎2012 Nov 02 7:28 AM
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
‎2012 Nov 02 7:50 AM
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
‎2012 Nov 02 12:58 PM
‎2012 Nov 02 8:11 AM
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.
‎2012 Nov 02 12:58 PM
‎2012 Nov 02 8:31 AM
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'.
‎2012 Nov 02 12:57 PM
‎2012 Nov 02 8:44 AM
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
‎2012 Nov 02 12:57 PM