Application Development 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: 

How do I get a variable, or object from ABAP STACK.

Martin_Kuma
Active Participant
38,670

Hey Gurus,

How do I get a variable, or object from ABAP STACK.

Example: I start my FM. I can see in the ABAP STACK the variable I need. I can see the object; I could use to get my variable. I need to use it in my FM; however I need to reference it in the run time. How do I do that?

Is there a method I can use for reading ABAP STACK?

Do I just use command: get reference of u2026?

Does anyone have an example code?

Basis version 7

Thanks in advance

Martin

1 ACCEPTED SOLUTION

former_member194669
Active Contributor
0 Kudos
11,339

Have you checked fm SYSTEM_CALLSTACK ?

You can find few threads in the forum related to this. please make a search in SYSTEM_CALLSTACK

9 REPLIES 9

former_member194669
Active Contributor
0 Kudos
11,340

Have you checked fm SYSTEM_CALLSTACK ?

You can find few threads in the forum related to this. please make a search in SYSTEM_CALLSTACK

RichHeilman
Developer Advocate
Developer Advocate
11,339

Ah, you mean you want to access a variable from another program in the call stack, yes? You can do this using field symbols, but please don't try to change a value while doing this, it could really screw things up.

this example, is using two programs, where the second is accessing variables of the first program. Basically just notice that we are using the program name and the variable name when assigning the field symbol.

report zrich_0006 .


tables: mara.

parameters: p_matnr type mara-matnr..

data: matnr type mara-matnr.
data: imarc type table of marc with header line.

matnr = p_matnr.
select * from marc into table imarc up to 10 rows
               where matnr = p_matnr.

perform in in program zrich_0007.


report zrich_0007 .

*---------------------------------------------------------------------*
*       FORM in                                                       *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
form in.

  data: field(50).
  data: xmarc type marc.

  field-symbols: <matnr>.
  field-symbols: <imarc> type marc_upl_tt.

* Assign an individual variable
  field = '(ZRICH_0006)matnr'.
  assign (field) to <matnr>.

* Assign an internal table
  field = '(ZRICH_0006)IMARC[]'.
  assign (field) to <imarc>.

* Write out your data
  write <matnr>.

  loop at <imarc> into xmarc.
    write: / xmarc-werks.
  endloop.

endform.

Regards,

Rich Heilman

0 Kudos
11,339

Rich,

I have question for you please.

if IN form is in a function group, then whether if we called


perform in in program zrich. " Function group main program

Whether it will work?

0 Kudos
11,339

I think it would since I have done something simular in the past. For example, there was a user exit, and of course the implementation was in an INCLUDE which was inside of a function module, I needed access to some variable at a higher level function call, so I used this same thing and pointed to the variable of the main program of the function group.

Regards,

Rich Heilman

0 Kudos
11,339

Hey Gurus

Thanks for the quick response.

I see I did not write everything. Sorry.

To explain my problem:

This is a BW object call InfoSpoke. The InfoSpoke collects data from BW and places them in a csv on the file system. There is no way to create the file name dynamically in the InfoSpoke self. You can assign a logical file, but for each InfoSpoke one u2013 and imagine I have 200+ of them. So I am trying to create the file name dynamically by a FM. The FM u2018justu2019 needs to find which InfoSpoke called the FM and return the name of it.

This FM, which I use is a customer exit for logical file /TX: FILE/.

During debug I found that right after the PAI module an object is created, which is used during the entire process of data retrieval and save.

Now I either reference the object self and then use one of the methods available, or I directly reference one of the variables.

But I do not know how to assign/reference the object/variable.

Rich, the assignment you are using. Well, you know that the ZRICH_0006 calls the ZRICH_0007 and thus can assign ZRICH_0006 variables in the ZRICH_0007. However I do not, as the program is generated at run time.

I need to define a variable/object, which will be known at run time. Then I need to assign the values in call stack to this variable/object.

aRs, the SYSTEM_CALLSTACK returns the list of methods, but I need the variable/object which is used in side these methods. The list of the used methods, does not help much.

Martin

0 Kudos
11,339

Martin,

I think you have 2 options

1. Try to use EXPORT/IMPORT

http://help.sap.com/saphelp_nw04/Helpdata/EN/fc/eb3bde358411d1829f0000e829fbfe/content.htm

2. Write the dynamic file name in a custom table with unique in the userexit and read it whenever you need using infospoke id.

( I will not suggest for second option)

0 Kudos
11,339

a®s,

How do I IMPORT from ABAP STACK, please?

Example:

I have the method: CL_RSB_... The method has a variable: lv_var.

I cannot add an EXPORT to ID 'XXX' to the method.

Thanks

Martin

0 Kudos
268

Thank you for the constructive and valuable instructions. Works well!

Martin_Kuma
Active Participant
0 Kudos
11,339

added implicit enhancement to a method