‎2008 Dec 08 2:44 PM
Hi Gurus,
I have an issue while working with dynamic obj.actually the scenario is, am implementing one BADI for this object input parameter is ip_object which is type OBJECT (not specific to any class), at runtime class will be assigned this object, here my question is how can i use (attributes and methods) that object in development.
Ex: A class /SCA/CL_SVDELIVERY is having protected attribute MPO_DLV_REF (MPO_DLV_REF type reff to a structure /SCMB/DM_DELVRY_STR).
I am trying to access the above attribute (MPO_DLV_REF) in a BADI /SCMB/BOL_VALFRMWRK method VALIDATE, this VALIDATE method is importing IP_OBJECT which is Type Ref to OBJECT.
When i try to access like this: IP_OBJECT ->MPO_DLV_REF-> (some field name in /SCMB/DM_DELVRY_STR) it is giving error.(Error:MPO_DLV_REF is unknown)
‎2008 Dec 08 3:13 PM
Hi Venu,
Down-cast it into a more specific object ref variable and access its attribute...
DATA lo_object TYPE REF TO /SCA/CL_SVDELIVERY.
lo_object ?= IP_OBJECT.now u can access this lo_object->MPO_DLV_REF attribute..
OR
Code like the below example...
*----------------------------------------------------------------------*
* CLASS c1 DEFINITION *
*----------------------------------------------------------------------*
CLASS c1 DEFINITION.
PUBLIC SECTION.
DATA ls_makt TYPE makt.
METHODS constructor.
ENDCLASS. "c1 DEFINITION
*----------------------------------------------------------------------*
* CLASS c1 IMPLEMENTATION *
*----------------------------------------------------------------------*
CLASS c1 IMPLEMENTATION.
METHOD constructor.
SELECT SINGLE * FROM makt INTO ls_makt WHERE spras EQ sy-langu.
ENDMETHOD. "constructor
ENDCLASS. "
DATA attribute_name TYPE char40 VALUE 'LS_MAKT' .
DATA generic_obj TYPE REF TO object.
FIELD-SYMBOLS : <attribute>,
<field>.
START-OF-SELECTION.
CREATE OBJECT generic_obj TYPE c1.
ASSIGN generic_obj->(attribute_name) TO <attribute>.
ASSIGN COMPONENT 'MAKTX' OF STRUCTURE <attribute> TO <field>.
WRITE <field>. " ls_makt-maktxHowever in both cases u can access only its public attributes....
Cheers,
Jose.
‎2008 Dec 10 9:55 AM
Hi Jose,
Thanks for your fast response,it is working fine for public attributes,but how to access protected attributes.....
‎2008 Dec 10 10:09 AM
Hi Venu,
Visibility ( public/protected/private ) is a property of a class... and i don't think it is not possible to view/use a protected component of a class outside it ( exception sub-class/friend )........: (
Cheers,
Jose