Monday, January 12, 2009

Another spell for the hacker book

The object oriented programming in APO uses in many cases the singleton pattern. An object static method (class method in standard object oriented talk) is used to obtain the object instance. If it is the first time the object is created and stored in a static attribute (class attribute). Then further calls to the method return the instance stored in the attribute. A practical result of this coding logic is that these objects become global structures of data because as long they were initialized at a given point of time, they are can be accessed at any later time just by calling the static method. For example, the object /SAPAPO/CL_ATPFIELD_BUF can be called in ATP user-exits to get the field catalog (some user-exits don’t have the field catalog available in the input parameters).

CALL METHOD /sapapo/cl_atpfield_buf=>get_atpfield
iv_ordid = lv_ordid
iv_delps = lv_delps
et_atpfield = lt_atpfield.

This works because the field catalog is stored in a static attribute of the object.

For global classes (like /SAPAPO/CL_ATPFIELD_BUF) this is very simple, but ABAP also allows the definition of local classes. For example, the main objects for the ATP calculation (LCL_REQUIREMENT_ATP, etc) are classes defined inside program /SAPAPO/SAPLATPT. I always wanted to have access to these objects inside user-exits (because it means having access to all ATP information). Something like this trick for global variables but able to access the objects.

After many failed attempts, this one works fine.

l_name(150) TYPE c,
l_tabtype(150) TYPE c,
ldr_reqref TYPE REF TO data.

<reqref_t> TYPE ANY TABLE.


CREATE DATA ldr_reqref TYPE (l_tabtype).
ASSIGN ldr_reqref->* TO <reqref_t> CASTING TYPE (l_tabtype).

CALL METHOD (l_name)=>get_instances
RECEIVING rt_reqref = <reqref_t>.

Now this pointer <reqref_t> is a pointer to a list of all LCL_REQUIREMENT_ATP object instances relevant for the current ATP check.

Labels: ,


Anonymous charan said... there any other way to find out the hidden BADI'S in R/# side.

6:58 AM  
Anonymous charan said...

in R/3 Side

6:59 AM  

Post a Comment

Links to this post:

Create a Link

<< Home