11-14-2007 1:47 PM
Hi OO-Gurus,
I use an implementation of BADI ME_PROCESS_REQ_CUST to fill and handle user-defined fields in the MM-Purchase-Requisition, method IF_EX_ME_PROCESS_REQ_CUST~OPEN.
There I use a reference variable which refers to an interface (type ref to IF_PURCHASE_REQUISITION_ITEM) to access the item-object. My problem is that I need to have access to the class-attribute my_state. The corresponding class lcl_req_item is defined locally (LMEREQF01). So I cant use a reference variable with reference to this class (so widening cast using the interface-reference is not possible) .. Does anyone know a trick how to access the class-attribute anyway?
-
Coding:
data: l_item_list TYPE MMPUR_REQUISITION_ITEMS,
l_item TYPE MMPUR_REQUISITION_ITEM,
l_item_akt TYPE mereq_item,
l_item_ref TYPE ref to IF_PURCHASE_REQUISITION_ITEM.
l_item_list = im_header->get_items().
loop at l_item_list into l_item.
l_item_akt = l_item-item->get_data( ).
l_item_ref = l_item-item.
endloop.
-
(Debugging the code, I manage by doubleclicking the fieldcontent of l_item_ref (e.g ) to show the content of the class-attribute my_state. This works only if the field Interface in the Debugger is empty because then I see the attributes of the class. If the field Interface is filled with IF_PURCHASE_REQUISITION_ITEM, there arent any attributes shown.)
Thanks in advance for your kind help!!
Nicole
11-14-2007 11:30 PM
Hello Nicole
The following sample coding shows you how to solve your problem. Please do not ask me how I came across this solution.
However, if you are studying it carefully you may stumble across a most beautiful property of field-symbols as I did.
METHOD if_ex_me_process_req_cust~open.
DATA: l_item_list TYPE mmpur_requisition_items,
l_item TYPE mmpur_requisition_item,
l_item_akt TYPE mereq_item,
l_item_ref TYPE REF TO if_purchase_requisition_item.
DATA:
ld_attr TYPE string,
lo_obj TYPE REF TO object.
FIELD-SYMBOLS:
<lo_lcl> TYPE ANY,
<ls_item> TYPE mereq_item,
<ls_itemx> TYPE mereq_itemx.
l_item_list = im_header->get_items( ).
LOOP AT l_item_list INTO l_item.
l_item_akt = l_item-item->get_data( ).
l_item_ref = l_item-item.
lo_obj ?= l_item-item. " casting to root object !!!!!
ld_attr = 'MY_STATE'.
ASSIGN lo_obj->(ld_attr) TO <lo_lcl>.
ld_attr = 'MY_STATE->ITEM'.
ASSIGN lo_obj->(ld_attr) TO <ls_item>.
" ASSIGN l_item_ref->(ld_attr) TO <ls_item>. " does not work...
*
ld_attr = 'MY_STATE->ITEMX'.
ASSIGN lo_obj->(ld_attr) TO <ls_itemx>.
ENDLOOP.
" NOTE: data definition of local class lcl_req_item_state (fg MEREQ)
** DATA: item TYPE mereq_item,
** itemx TYPE mereq_itemx,
** header TYPE REF TO lcl_req_header,
** ref_item TYPE REF TO lcl_req_item,
** acct_container TYPE REF TO lcl_acct_container,
** source TYPE REF TO cl_source_of_supply_mm,
** release_state TYPE REF TO cl_release_state_mm,
** text_manager TYPE REF TO lcl_text_manager,
** bom TYPE REF TO lcl_bom,
** funds_mgt_active TYPE mmpur_bool VALUE mmpur_no,
** aktyp TYPE aktyp,
** no_auth TYPE mmpur_bool VALUE mmpur_no,
** release_op type mmpur_bool value mmpur_no,
** persistent TYPE mmpur_bool VALUE mmpur_no,
** checked TYPE mmpur_bool VALUE mmpur_no,
** manual_configuration TYPE mmpur_bool,
** input_buffer_changed TYPE mmpur_bool VALUE mmpur_no,
** changed TYPE mmpur_bool,
** broken_rules TYPE lty_mask,
** referenced_rules TYPE lty_mask,
** chp_changes TYPE mmchp_chp_list,
** dcm_manager TYPE REF TO if_revision_manager_dcm,
** "DCM Retrofit
** rel_state_after_release TYPE REF TO cl_release_state_mm,
** "DCM Retrofit
** chdoc_container TYPE REF TO lcl_chdoc_container,
** "DCM Retrofit
** service_changed TYPE mmpur_bool,
** "DCM Retrofit
** determinants TYPE lty_item_determinants.
ENDMETHOD.
Regards
Uwe
11-14-2007 11:30 PM
Hello Nicole
The following sample coding shows you how to solve your problem. Please do not ask me how I came across this solution.
However, if you are studying it carefully you may stumble across a most beautiful property of field-symbols as I did.
METHOD if_ex_me_process_req_cust~open.
DATA: l_item_list TYPE mmpur_requisition_items,
l_item TYPE mmpur_requisition_item,
l_item_akt TYPE mereq_item,
l_item_ref TYPE REF TO if_purchase_requisition_item.
DATA:
ld_attr TYPE string,
lo_obj TYPE REF TO object.
FIELD-SYMBOLS:
<lo_lcl> TYPE ANY,
<ls_item> TYPE mereq_item,
<ls_itemx> TYPE mereq_itemx.
l_item_list = im_header->get_items( ).
LOOP AT l_item_list INTO l_item.
l_item_akt = l_item-item->get_data( ).
l_item_ref = l_item-item.
lo_obj ?= l_item-item. " casting to root object !!!!!
ld_attr = 'MY_STATE'.
ASSIGN lo_obj->(ld_attr) TO <lo_lcl>.
ld_attr = 'MY_STATE->ITEM'.
ASSIGN lo_obj->(ld_attr) TO <ls_item>.
" ASSIGN l_item_ref->(ld_attr) TO <ls_item>. " does not work...
*
ld_attr = 'MY_STATE->ITEMX'.
ASSIGN lo_obj->(ld_attr) TO <ls_itemx>.
ENDLOOP.
" NOTE: data definition of local class lcl_req_item_state (fg MEREQ)
** DATA: item TYPE mereq_item,
** itemx TYPE mereq_itemx,
** header TYPE REF TO lcl_req_header,
** ref_item TYPE REF TO lcl_req_item,
** acct_container TYPE REF TO lcl_acct_container,
** source TYPE REF TO cl_source_of_supply_mm,
** release_state TYPE REF TO cl_release_state_mm,
** text_manager TYPE REF TO lcl_text_manager,
** bom TYPE REF TO lcl_bom,
** funds_mgt_active TYPE mmpur_bool VALUE mmpur_no,
** aktyp TYPE aktyp,
** no_auth TYPE mmpur_bool VALUE mmpur_no,
** release_op type mmpur_bool value mmpur_no,
** persistent TYPE mmpur_bool VALUE mmpur_no,
** checked TYPE mmpur_bool VALUE mmpur_no,
** manual_configuration TYPE mmpur_bool,
** input_buffer_changed TYPE mmpur_bool VALUE mmpur_no,
** changed TYPE mmpur_bool,
** broken_rules TYPE lty_mask,
** referenced_rules TYPE lty_mask,
** chp_changes TYPE mmchp_chp_list,
** dcm_manager TYPE REF TO if_revision_manager_dcm,
** "DCM Retrofit
** rel_state_after_release TYPE REF TO cl_release_state_mm,
** "DCM Retrofit
** chdoc_container TYPE REF TO lcl_chdoc_container,
** "DCM Retrofit
** service_changed TYPE mmpur_bool,
** "DCM Retrofit
** determinants TYPE lty_item_determinants.
ENDMETHOD.
Regards
Uwe
11-16-2007 8:07 AM
Dear Uwe,
thank you sooooooo much for this solution. It works perfect, you saved my life
If I could I would reward 1000 points!
Thanks und ein herzliches grüezi in die Schweiz!
Nicole
11-15-2007 5:29 AM
Hi
Accessing Attributes and method
Instance methods are called using CALL METHOD <reference>-><instance_method>.
Static methods (also referred to as class methods) are called using CALL METHOD <classname>=><class_method>.
If you are calling a static method from within the class, you can omit the class name.
You access static attributes using <classname>=><class_attribute>
You access instance attributes using <instance>-><instance_attribute>
=> and -> are the component selectors
11-16-2007 8:19 AM
Hello Nicole
I am glad that I could have helped you.
I assume that this solution reveals a general principle (if not, Klaus Ziegler will revise me...):
<i><b>All public class attributes correspond to a public memory area which can be accessed using field-symbols.</b></i>
It would be interesting to investigate why it did not work using the L_ITEM_REF variable. However, it was too late in the evening to spend more time in the SDN...
Regards
Uwe
12-13-2007 9:28 PM
Hello Nicole
If you require some more tricks using field-symbols have a look at the links provided in the snippet
<a href="https://wiki.sdn.sap.com/wiki/display/ABAP/AccessingtheInacessible-LocalClasseswithinGlobalClasses">Accessing the Inacessible - Local Classes within Global Classes</a>
Regards,
Uwe
03-07-2008 5:10 PM
Hi Uwe and Nicoli,
I am having one question about this and so re-opening the thread.
I am having almost same requirement and your solution is working fine for me in case when I am changing existing PR but I am facing one issure regarding this.
When I create the PR using ME51N, it calls the same BAdi ME_PROCESS_REQ_CUST , my code is like this:
lv_attr = 'MY_STATE->RELEASE_STATE->MY_INDICATOR'.
assign lo_obj->(lv_attr) to <lo_ref>.
now in case of PR creation MY_STATE->RELEASE_STATE is initial and thus there is no attribute MY_INDICATOR, thus next line
assign lo_obj->(lv_attr) to <lo_ref>.
giving me short dump GETWA_NOT_ASSIGNED as field symbol cannt be assigned .
In addition to this I would like to add one more thing that I am getting short dump
when I am re-assigning <lo_ref> to ay variable like this
l_release = <lo_ref> and here I am getting error as <lo_ref> is not pointing to any thing.
any idea to do this? I have already tried TRY-CATCH but its not working and I cannt check lo_obj->(lv_attr) to initial as it is syntax error.
Your thoughts are really appreciated.
Thanks in advance
Cheers
Jai
Edited by: Jai S on Mar 7, 2008 6:23 PM
Edited by: Jai S on Mar 7, 2008 6:24 PM
03-07-2008 5:48 PM
Hi Guys,
Issue has been resolved, I could have checked subrc.
Thanks any ways
Cheers
Jai