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: 

Abap Object-oriented question

Former Member
0 Kudos

Hi Folks,

I'm currenty writing a user exit in SAP BW and in this user exit I would like to retrieve the value of a certain instance attribute but I don't manage to do this.

Let me explain you what I mean. At a certain point in some standard code a "create object query" statement occurs which declares a certain class. Via query->n_handle the value of an attribute can be derived in this standard program.

But... then the user exit is being called but I don't have access anymore to query->n_handle. The strange thing is I'm 100% sure the class can still be accessed as I tested in debugging node that I can view the class instance 3<\CLASS=CL_RSR_REQUEST> in debugging mode on the tabstrip table where you usually view internal tables. This instance was created in the standard program via "create object query". Why can't I access this anymore in the user exit while I can perfectly view the class in this user exit while in debugging mode. Can anyone give me a hint how to fetch the value from the attribute of 3<\CLASS=CL_RSR_REQUEST> as I need this badly.

Thanks in advance.

6 REPLIES 6

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

I assume that your exit is probably a Customer Function or a BADI.  Because of the scope of the interface into the object you are within, you no longer have visibility to the variable holding the pointer to the instance of your class. In other words, you can only see the variables that are exposed to your exit.

Now why can the debugger see the variable but you can't from the runtime? That has to do with the special way that the debugger actually references memory from any running program. Internally the debugger creates field symbols, referencing the program name and then the variable.  

I don't think this is officially released ABAP functionality, but you should be able to do the same in your program if you create a field name variable and structure the value as follows: (EXTERNAL_PROGRAM)EXTERNAL_VARIABLE.  Then assign this fieldname to a Field Symbol. You should then have a field symbol that points to a variable outside of your program area.

0 Kudos

Thanks for your time on answering my question Thomas.

Your assumption is right, we are talking about a Customer function. Your explantion on how the debugger works internally (field symbols referencing the program name and variable) is clear to me.

However I don't understand exactly how I could simulate the same thing in my customer exit  speaking in ABAP terms.

How do I need to create a field name variable and structure the value as follows : (EXTERNAL_PROGRAM)EXTERNAL_VARIABLE ?

Could you be so kind to give an example e.g. ? Thank you very much in advance.

With kind regards.

0 Kudos

No problem.  Take a look at the following code:

REPORT  yes_field_symbol .

DATA: fake_external_var(20) TYPE c VALUE 'I am External!'.

DATA: fieldname(100) TYPE c.

DATA: fieldname2(100) TYPE c.

MOVE '(YES_FIELD_SYMBOL)fake_external_var' TO fieldname.

MOVE 'fake_external_var' TO fieldname2.

FIELD-SYMBOLS: .

You can see here that I have assigned two different fieldnames to two different field symbols.  Both produce the same results. However the first fieldname contains the name of the program in brackets (). This just happens to be the name of the local program for simplicity of this example. However this could be any running program in your execution memory area. This is were you will use the name of the SAP program that declairs the variable that is holding the pointer to the object instance in want to work with.

Let me know if things are still foggy.

0 Kudos

I decided to make this example a little more interesting.  I changed the second field symbol to point to one of the kernel programs in the call stack (at least if you run this from the ABAP editor in Release 46C). I am now accessing a table size constant from the program SAPLSFES (which is actually the function group for FrontEnd Services). When you execute this you should see the value 1,024 write out for the second field symbol.

report  yes_field_symbol .

data: fake_external_var(20) type c value 'I am External!'.

data: fieldname(100) type c.

data: fieldname2(100) type c.

move '(YES_FIELD_SYMBOL)fake_external_var' to fieldname.

move '(SAPLSFES)c_dptablesize' to fieldname2.

field-symbols: .

0 Kudos

Hi Thomas,

Many thanks for your help. I managed to resolve my problem based on the logic in your sample program. This is a very interesting trick that I will definitely re-use again in the future.

Thx one more time!

Former Member
0 Kudos

Hi,

i tried to understand and reuse your posted ideas. Does i understand right this is a way to

save the reference to a class instance. why you dont use a data object wich type is ref to cl_class like:

data: r_ref type ref cl_class.

Wich version of WAS do you use, i use 6.20 and get errors by exectuing your reports.

Thank you for answering my question.