09-24-2008 1:39 PM
Hello Guru,
I'm building a function builder that should transform any structure- or table-field to its corresponding component in the internal table.
e.g.
BAPI_MARA_GA-MATERIAL should be transformed in MATNR.
My priority is concentrated by BAPI_MATERIAL_GETALL.
I should MAP all the structure or table fields to their corresponding internal element.
e.g.
BAPI_MARA_GA should be mapped to MARA
BAPI_MARA_GA-MATERIAL should be mapped to MATNR.
Thanks for your help.
Regards,
Kais
09-24-2008 2:05 PM
HI,
Try to use the class CL_ABAP_STRUCTDESCR and its methods.
Take a look at the example below :
REPORT z_assign_comp.
*& Dynamic Programming ! Usign Structure Descriptior Class. *
DATA: BEGIN OF line OCCURS 0,
col1 TYPE i,
col2(10) TYPE c,
col3 TYPE i,
END OF line.
FIELD-SYMBOLS : <fs> TYPE ANY.
FIELD-SYMBOLS : <itab_line> TYPE ANY.
DATA : BEGIN OF t_comp OCCURS 0,
comp(5) TYPE c,
END OF t_comp.
DATA : l_struc TYPE REF TO cl_abap_structdescr.
DATA : l_typedesc TYPE REF TO cl_abap_typedescr.
DATA : lt_comp TYPE abap_compdescr_tab,
w_comp LIKE LINE OF lt_comp.
line-col1 = 11.line-col2 = 'SAP'.line-col3 = 33.
APPEND line.
line-col1 = 44.line-col2 = 'P.I.'.line-col3 = 66.
APPEND line.
ASSIGN line TO <itab_line>.
*Call the static method of the structure descriptor describe_by_data
CALL METHOD cl_abap_structdescr=>describe_by_data
EXPORTING
p_data = <itab_line>
RECEIVING
p_descr_ref = l_typedesc.
*The method returns a reference of a type descriptor class therefore we
*need to Cast the type descriptor to a more specific class i.e
*Structure Descriptor.
l_struc ?= l_typedesc.
*Use the Attribute COMPONENTS of the structure Descriptor class to get
*the field names of the structure
lt_comp = l_struc->components.
LOOP AT line.
WRITE 😕 'Row : ', sy-tabix.
LOOP AT lt_comp INTO w_comp.
* Using the ASSIGN component ,assigns a data object to a field symbol.
ASSIGN COMPONENT w_comp-name OF STRUCTURE line TO <fs>.
WRITE 😕 w_comp-name, ' ', <fs>.
ENDLOOP.
ENDLOOP.
This might be a pointer to your requirement.
regards,
Advait
09-24-2008 2:05 PM
HI,
Try to use the class CL_ABAP_STRUCTDESCR and its methods.
Take a look at the example below :
REPORT z_assign_comp.
*& Dynamic Programming ! Usign Structure Descriptior Class. *
DATA: BEGIN OF line OCCURS 0,
col1 TYPE i,
col2(10) TYPE c,
col3 TYPE i,
END OF line.
FIELD-SYMBOLS : <fs> TYPE ANY.
FIELD-SYMBOLS : <itab_line> TYPE ANY.
DATA : BEGIN OF t_comp OCCURS 0,
comp(5) TYPE c,
END OF t_comp.
DATA : l_struc TYPE REF TO cl_abap_structdescr.
DATA : l_typedesc TYPE REF TO cl_abap_typedescr.
DATA : lt_comp TYPE abap_compdescr_tab,
w_comp LIKE LINE OF lt_comp.
line-col1 = 11.line-col2 = 'SAP'.line-col3 = 33.
APPEND line.
line-col1 = 44.line-col2 = 'P.I.'.line-col3 = 66.
APPEND line.
ASSIGN line TO <itab_line>.
*Call the static method of the structure descriptor describe_by_data
CALL METHOD cl_abap_structdescr=>describe_by_data
EXPORTING
p_data = <itab_line>
RECEIVING
p_descr_ref = l_typedesc.
*The method returns a reference of a type descriptor class therefore we
*need to Cast the type descriptor to a more specific class i.e
*Structure Descriptor.
l_struc ?= l_typedesc.
*Use the Attribute COMPONENTS of the structure Descriptor class to get
*the field names of the structure
lt_comp = l_struc->components.
LOOP AT line.
WRITE 😕 'Row : ', sy-tabix.
LOOP AT lt_comp INTO w_comp.
* Using the ASSIGN component ,assigns a data object to a field symbol.
ASSIGN COMPONENT w_comp-name OF STRUCTURE line TO <fs>.
WRITE 😕 w_comp-name, ' ', <fs>.
ENDLOOP.
ENDLOOP.
This might be a pointer to your requirement.
regards,
Advait