‎2007 Jul 11 11:34 AM
May not make sense ... but I'm trying to write code like this
if X
field-symbols: <ls_screenline> type Z
endif
if Y
field-symbols: <ls_screenline> type Y
endif
So basically I can create a field-symbol <ls_screenline> that has a different structure depending on a condition.
Background: I'm in a BSP application that passes in a table structure of ANY type. This table has lines that are either structure Z or Y. Structure Z and Y mostly have the same structure and field names. In the code I'm writing I'm only accessing the fields that are common to Z and Y. So it seems silly to write my code twice, once for Z and once for Y.
‎2007 Jul 11 11:42 AM
Hi,
Why dont you use the class CL_ABAP_TYPEDESCR and method DESCRIBE_BY_DATA to get the TYPE of the data that you receive.
Also if the fields that you want are anyway same you can use
ASSIGN COMPONENT comp_name OF STRUCTURE <> and deal with the fields you want to deal with.
With out knowing the datatype.
DATA: lr_rtti_struc TYPE REF TO cl_abap_structdescr.
lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data(<fs_data>).
Regards,
Sesh
‎2007 Jul 11 11:38 AM
Declare your field symbols as TYPE ANY and assign the value to it as per the condition.
FIELD-SYMBOLS: <fs_any> TYPE ANY.
if X
assign z to <fs_any>.
endif
if Y
assign y to <fs_any>.
endif
‎2007 Jul 11 11:42 AM
Hi,
Why dont you use the class CL_ABAP_TYPEDESCR and method DESCRIBE_BY_DATA to get the TYPE of the data that you receive.
Also if the fields that you want are anyway same you can use
ASSIGN COMPONENT comp_name OF STRUCTURE <> and deal with the fields you want to deal with.
With out knowing the datatype.
DATA: lr_rtti_struc TYPE REF TO cl_abap_structdescr.
lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data(<fs_data>).
Regards,
Sesh
‎2007 Jul 24 2:10 PM
assign component 'EXTERNAL_ID' of structure <ls_screenline_any> to <lv_cgpl_extid>.
Full code
CRMT_BSP_MKTPL_ TREE / BASIC DATA / BASIC_DATA_TPM
Data: lv_text1 type cgpl_text1.
field-symbols: <ls_screenLine_any> type any ,
<lv_cgpl_extid> type CGPL_EXTID,
<lv_cgpl_text1> type cgpl_text1.
if iv_screen_structure_name = 'CRMT_BSP_MKTPL_TREE' or
iv_screen_structure_name = 'CRMT_BSP_MKTPL_BASIC_DATA' OR
iv_screen_structure_name = 'CRMT_BSP_MKTPL_BASIC_DATA_TPM'.
assign et_screen_structure to <et_screen_structure>.
loop at <et_screen_structure> assigning <ls_screenline_any>.
assign component 'EXTERNAL_ID'
of structure <ls_screenline_any> to <lv_cgpl_extid>.
CALL FUNCTION 'Z_CRM_MKTPL_STOREREAD_MECHANIC'
EXPORTING
EXTID = <lv_cgpl_extid>
IMPORTING
TEXT1 = lv_text1.
if lv_text1 is not initial.
assign component 'TEXT1'
of structure <ls_screenline_any> to <lv_cgpl_text1>.
<lv_cgpl_text1> = lv_text1.
CLEAR: LV_TEXT1.
endif.
endloop.
endif.