Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Access to class-attribute by Interface-reference

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 can’t 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 aren’t any attributes shown.)

Thanks in advance for your kind help!!

Nicole

Former Member
Former Member replied

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

2 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question