2014 Jun 25 5:02 PM
Hello,
There is a need in my function module where I need to take the help of a transaction wherein I would require the values of an internal table ( which is populated somewhere in the transaction program ) to be passed back to my function module where I intend to use these values to populate in a structure and to do some other mumbo jumbo with it.
So, I did the following:
EXPORT internaltable TO MEMORY ID c_memory.
SUBMIT ZTRANSACTIONPROGRAM
WITH w_param1 EQ '1000'
WITH w_param2 EQ iw_something
AND RETURN.
IMPORT internaltable FROM MEMORY ID c_memory.
Could you help me figure out how I need to code this requirement of mine in the transaction program? Is this doable? Please provide how I would need to code this out in the transaction program.
Would appreciate suggestions and alternatives to this approach.
Thanks & Regards,
Alice.
2014 Jun 26 4:39 AM
Hello Jörg Wulf and Always Leaner & all,
I have tried using that approach of exporting the memory id from the transaction program. But, it still shows me the same behavior.
What it still does now:
When I debug the code, it goes to the transaction program and in one swift moment comes straight back to my FM ( without filling the internal table obviously )
What I learnt from poking around here and there:
Is there any other way to access the transaction program's internal contents?
2014 Jun 25 5:30 PM
Hi Alice,
i have some dificulties to get your requirement right, so here is what i understood so far:
You call a custom program via submit.
The submit is executed in a custom FM.
the called program collects some data, which you want to use in your FM afterwards.
If this is correct so far, there are several options for achieving it.
Hope that helps:
Best regards - Jörg
2014 Jun 25 5:49 PM
Yes, Jörg. You have got the requirement right.
I would like to use the METHOD - 2 of what you have given above.
Could you please guide me on how I need to code for the 'export' where the table is being populated?
This is exactly what I am looking for.
Thanks!
2014 Jun 25 5:57 PM
I just reread your post and seemingly i missed the point
You already have lined out a valuable aproach.
For the decision, whether your program is called by your FM, you could do either of:
Once you're certain, that the calling was from your FM, you can export your table after populating and you can, if there's nothing more to be done, exit the program after that. The AND RETURN statement will assure, that you continue code-execution just where you left in your FM.
than you just have to import from memory and that's it.
BR -Jörg
2014 Jun 25 5:34 PM
Hello Alice,
Please try with the below code.
Data : IT_TABS TYPE TABLE OF abaplist.
SUBMIT ZTRANSACTIONPROGRAM WITH w_param1 EQ '1000'
WITH w_param2 EQ iw_something
EXPORTING LIST TO MEMORY AND RETURN.
IF SY-SUBRC = 0.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = IT_TABS "Table will be having all internal table details
EXCEPTIONS
not_found = 1
OTHERS = 2.
ENDIF.
Thanks
2014 Jun 25 5:38 PM
Hi,
You can also try with below code after your submit system.
DATA: it_itab(20) VALUE '(ZTRANSACTIONPROGRAM)ITAB[]'.
FIELD-SYMBOLS: <f_ITAB> TYPE TABLE
ASSIGNit_itab TO <f_ITAB>.
2014 Jun 25 5:53 PM
Hi 'Always Leaner',
I get where you are trying to go here. This is on the same lines of what I was thinking.
Yes, the import works fine in my FM but the internal table is empty.
I am looking for a little guidance where I can appropriately place my "export" code in the transaction program where my internal table(which I need) is being populated.
Basically, I would want that piece of code to do this:
"I could insert some code which basically says " Hey! If my calling program is "this"(my FM) -> only then copy this particular internal table at this line ( I would want to insert the code at the place where I would need a data transfer) to the memory id. " Plus, I would want this internal table to be exported so I can import it back to my FM and use it. And, may be an EXIT statement after that? So, I would not want the whole of the transaction program to execute. "
2014 Jun 25 5:57 PM
Hello Alice,
you can use sy-repid variable in ZTRANSACTIONPROGRAM).
For Example code like below
If sy-repid = 'ZCALLINGPROGRAM'
*After internal table is filled in ZTRANSACTIONPROGRAM)
Export IT_tab to memory 'ZABC'.
EXIT.
ENDIF.
Import this internal table in zcallingprogram.
Thanks
2014 Jun 25 6:26 PM
Hi again,
you can achieve what you required, by means of export and import to/from memory.
i would suggest however, that you reconsider the general design of both your FM and your program.
Have you thought of the possibility to reuse the same portion of code in both of your contexts, providing the respective caller with the content of the table?
This would be a clean aproach, you wouldn't have to bother with "who's calling" and exit, but just use a class or FM instead, whenever you are in need of that particular way of providing your content.
.
Maybe not for your actual problem but for future tasks, it is benefitial to break your code down, modulize it and use it the easy way.
BR - Jörg
2014 Jun 26 4:20 AM
Thank you. Please check the reply I have posted to the original discussion thread.
Thanks!
2014 Jun 26 4:41 AM
Thank you. Please check the reply I have posted to the original discussion thread.
Re-use - Sadly, I think this is the only option left
2014 Jun 26 4:39 AM
Hello Jörg Wulf and Always Leaner & all,
I have tried using that approach of exporting the memory id from the transaction program. But, it still shows me the same behavior.
What it still does now:
When I debug the code, it goes to the transaction program and in one swift moment comes straight back to my FM ( without filling the internal table obviously )
What I learnt from poking around here and there:
Is there any other way to access the transaction program's internal contents?
2014 Jun 26 5:44 AM
Hello Alice,
The SUBMIT statement can be used for Executable programs. Please find the below HELP from SAP
http://help.sap.com/abapdocu_70/en/ABAPSUBMIT.htm
I still feel export and import statement can be used.
Please follow below approach .
1 ) Export a flag to memory in FM
2)set parameter ids for the ztransaction in FM
3) Call ztransaction and skip first screen.
4)Import flag to memory of FM
5)If flag eq ex, export IT_tab of ztransaction to memory.
free memory id of flag and exit ztransaction
6) Import It_tab from memory into FM
Please let me know if it helps you.
Thanks
2014 Jun 26 8:22 AM
Hi Alice,
thanks for your clarification.
Apparently, your program is of Type M(odulepool) and not 1.
This is the reason for your unseccesful trials. Aou cannot execute a modulepool via submit.
Try CALL TRANSACTION ... instead.
BR - Jörg
2014 Jun 26 5:59 AM
Hi Alice D' Souza,
please use below code.
SUBMIT ZTRANSACTIONPROGRAM
WITH w_param1 EQ '1000'
WITH w_param2 EQ iw_something
EXPORTING LIST TO MEMORY
AND RETURN.
* Structure get the data from memory in ascii format....................
DATA: lt_list TYPE abaplist OCCURS 0 WITH HEADER LINE.
* Structure get the data from memory....................................
DATA: lt_txtlines(1024) TYPE c OCCURS 0 WITH HEADER LINE.
CLEAR : lt_list,lt_reportlines.
REFRESH : lt_list[],lt_reportlines[].
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = lt_list
EXCEPTIONS
not_found = 1
OTHERS = 2.
CHECK sy-subrc = 0.
CALL FUNCTION 'LIST_TO_ASCI'
TABLES
listobject = lt_list
listasci = lt_txtlines
EXCEPTIONS
empty_list = 1
list_index_invalid = 2
OTHERS = 3.
CHECK sy-subrc = 0.
lt_reportlines[] = lt_txtlines[].
CALL FUNCTION 'LIST_FREE_MEMORY'.
Regards,
Venkat.
2014 Jun 26 6:00 AM
Hi Alice,
Have you debugged the called program(your report), and checked wheather your required code is getting executed. As i think the lines of code which fills the internal table are not getting executed.
Rest is correct you export the data to memory from called program(your report) and import it in calling program(your FM).
2014 Jun 26 6:27 AM
Try this code:
1] code for function module:
data: isel type table of rsparams.
data: xsel type rsparams.
data s_matnr type matnr.
loop at it_matnr into s_matnr. "Select option
xsel-selname = 'S_MAT'.
xsel-kind = 'S'.
xsel-sign = 'I'.
xsel-option = 'EQ'.
xsel-low = s_matnr.
append xsel to isel.
clear: xsel, s_matnr.
endloop.
xsel-selname = 'PB_IND'."Radio button
xsel-kind = 'S'.
xsel-sign = 'I'.
xsel-option = 'EQ'.
xsel-low = 'X'.
append xsel to isel.
clear xsel.
xsel-selname = 'DIADATE'. "Parameters
xsel-kind = 'S'.
xsel-sign = 'I'.
xsel-option = 'EQ'.
xsel-low = sy-datum.
append xsel to isel.
clear xsel.
submit zgk_test_program
with selection-table isel
and return.
import t_display to it_display1 from memory id 't_display'.
free memory id 't_display'.
append lines of it_display1 to it_display.
2] code for program:zgk_test_program
export t_display to memory id 't_display'. "t_display is internal table
leave program.
2014 Jun 26 8:43 AM
1. create two separate FM's(set_output and get_output) in your calling FM's function group and declare global internal table to set and get the output data of your transaction for the given input.
Get_output should pass the data from the global internal table and set_output should set the values.
2. Use call transaction using for calling your transaction.
3. Modify the called transaction and write code to call the FM to set the data through set_output into global internal table declared in step 1.
4. call the get_output fm and hence you have the output of your called transaction.
2014 Jun 26 10:55 AM
Hi Alice,
if it is ZPROGRAM (customized) you can place the IMPORT in end of the Program
Eg.
SUBMIT zreport with p_param1 = 'value'
with p_param2 = 'value' and return.
Export ITAB to memory Id ''TEST. " (Inside zprogram)
Import ITAB to ITAB2 from memory id 'TEST'. " ( inside function Module)
2014 Jun 26 1:09 PM
Hi Alice,
you have to use export statement in your submit program from which you want to collect the data
and after executing the submit and return statement add import from memory id code.
2014 Jun 29 6:27 AM