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

Using SUBMIT in an ABAP program.

Former Member
0 Likes
79,020


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:

  • In my function module, I was able to create a structure which would hold the exact same stuff like the data of the internal table in the transaction program.
  • I then wrote the following SUBMIT code so it jumps to the transaction program to get the values I need.

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.

  • What is happening basically is :- When I debug the code, I find that the execution does go to the transaction program I want it to go. But, soon after it jumps back to the calling FM code. ( Is this because of the return statement I have added here?) And, the internal table which is imported is empty. No values whatsoever.

  • If I want it to go all the way to the line of code in the transaction program - exactly after which that internal table( which I need ) is getting populated - what would I have to do?
  • 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.

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
54,140

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:

  • "SUBMIT program" works only for Reports?! ( with events & selection screen ) Is this the reason why my transaction program ( which has PBO and PAI modules w/o events ) does not seem to work for this case? (Please let me know if this is the reason WHY ? )
  • Also I cannot use the " Call transaction XXXX " statement in my FM because I need only the populated internal table from the transaction program and nothing else.

Is there any other way to access the transaction program's internal contents?

20 REPLIES 20
Read only

jrg_wulf
Active Contributor
0 Likes
54,140

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.

  1. simple, but deprecated: use common area. define your table-structure in DDIC and use tables statement. Name it the same, both in called program and FM
    Don't use it though.
  2. using memory: the basic idea was ok, but you need to do the export when the table is populated. That would be in the called program. The import should be ok.
  3. create data with area handle: this is kind of the new edition of common area but with far better control of who can access and how. My favorite but needs a bit of practice.
    To get teh knack of it, there is a fine example in the F1 documentation of create data.

Hope that helps:

Best regards - Jörg

Read only

Former Member
0 Likes
54,140

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!

Read only

jrg_wulf
Active Contributor
0 Likes
54,140

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:

  1. add an optional parameter to the program, saying Hey it's me
  2. export a flag to memory and take the session id for memory-id
    call function 'TH_GET_SESSION_ID'
                  importing
                    session_id = memid
                    id_len     = lv_l.

    Thus you can ascertain, that it's not a leftover. Import it in the program
    and you'll know when to act.
  3. you cannot however evaluate sy-cprog or call stack, because it gets reset by submit.

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





Read only

Mohamed_Mukhtar
Active Contributor
0 Likes
54,140

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

Read only

0 Likes
54,140

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>.

Read only

0 Likes
54,140

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. "

Read only

0 Likes
54,140

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

Read only

0 Likes
54,140

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

Read only

0 Likes
54,140

Thank you. Please check the reply I have posted to the original discussion thread.

Thanks!

Read only

0 Likes
54,140

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

Read only

Former Member
0 Likes
54,141

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:

  • "SUBMIT program" works only for Reports?! ( with events & selection screen ) Is this the reason why my transaction program ( which has PBO and PAI modules w/o events ) does not seem to work for this case? (Please let me know if this is the reason WHY ? )
  • Also I cannot use the " Call transaction XXXX " statement in my FM because I need only the populated internal table from the transaction program and nothing else.

Is there any other way to access the transaction program's internal contents?

Read only

0 Likes
54,140

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

Read only

0 Likes
54,140

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

Read only

Former Member
0 Likes
54,140

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.

Read only

dani_mn
Active Contributor
0 Likes
54,140

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).

Read only

gireesh_kokate
Explorer
0 Likes
54,140

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.

Read only

former_member183073
Active Participant
0 Likes
54,140

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.

Read only

Former Member
0 Likes
54,140

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)

Read only

0 Likes
54,140

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.

Read only

Former Member
0 Likes
54,140

Thank you all ! It works now.