2012 Sep 06 11:24 AM
Hello,
I need to get all field names and values from type.
Structure can be like:
DATA: pit TYPE ZPPLP_pit8ar.
And Types defined as:
TYPES: BEGIN OF ZPPLP_row8ar,
zaliczka1 LIKE pc207-betrg,
zaliczka2 LIKE pc207-betrg,
zaliczka3 LIKE pc207-betrg,
zaliczka4 LIKE pc207-betrg,
zaliczka5 LIKE pc207-betrg,
zaliczka6 LIKE pc207-betrg,
zaliczka7 LIKE pc207-betrg,
zaliczka8 LIKE pc207-betrg,
zaliczka9 LIKE pc207-betrg,
zaliczka10 LIKE pc207-betrg,
zaliczka11 LIKE pc207-betrg,
zaliczka12 LIKE pc207-betrg,
zaliczka13 LIKE pc207-betrg,
sum LIKE pc207-betrg,
prowizja LIKE pc207-betrg,
end_sum LIKE pc207-betrg,
END OF ZPPLP_row8ar.
TYPES: BEGIN OF ZPPLP_pit8ar,
nip(13),
year(10),
from(10),
to(10),
row01 TYPE ZPPLP_row8ar,
row02 TYPE ZPPLP_row8ar,
row03 TYPE ZPPLP_row8ar,
row04 TYPE ZPPLP_row8ar,
row05 TYPE ZPPLP_row8ar,
row06 TYPE ZPPLP_row8ar,
row07 TYPE ZPPLP_row8ar,
row08 TYPE ZPPLP_row8ar,
row09 TYPE ZPPLP_row8ar,
row10 TYPE ZPPLP_row8ar,
row11 TYPE ZPPLP_row8ar,
row12 TYPE ZPPLP_row8ar,
description TYPE string.
TYPES: END OF ZPPLP_pit8ar.
I need to get all names and values from type pit.
For example:
nip | 7638472938
year | 2012
row01-zaliczka1 | 1501
row01-zaliczka2 | 1502
Is there any simple way to do this?
Thank you for helping in advance.
2012 Sep 06 1:43 PM
HI Mariusz,
If I understood your requirement correctly, here I have attached sample code.
You can achieve this by using the standard classes - CL_ABAP_TYPEDESCR and subclasses
for and by using Field-symbols as explained in the example program below.
REPORT ztest.
*type-pools ABAP.
TYPES: BEGIN OF zpplp_row8ar,
zaliczka1 LIKE pc207-betrg,
zaliczka2 LIKE pc207-betrg,
zaliczka3 LIKE pc207-betrg,
zaliczka4 LIKE pc207-betrg,
zaliczka5 LIKE pc207-betrg,
zaliczka6 LIKE pc207-betrg,
zaliczka7 LIKE pc207-betrg,
zaliczka8 LIKE pc207-betrg,
zaliczka9 LIKE pc207-betrg,
zaliczka10 LIKE pc207-betrg,
zaliczka11 LIKE pc207-betrg,
zaliczka12 LIKE pc207-betrg,
zaliczka13 LIKE pc207-betrg,
sum LIKE pc207-betrg,
prowizja LIKE pc207-betrg,
end_sum LIKE pc207-betrg,
END OF zpplp_row8ar.
TYPES: BEGIN OF zpplp_pit8ar,
nip(13),
year(10),
from(10),
to(10),
row01 TYPE zpplp_row8ar,
row02 TYPE zpplp_row8ar,
row03 TYPE zpplp_row8ar,
row04 TYPE zpplp_row8ar,
row05 TYPE zpplp_row8ar,
row06 TYPE zpplp_row8ar,
row07 TYPE zpplp_row8ar,
row08 TYPE zpplp_row8ar,
row09 TYPE zpplp_row8ar,
row10 TYPE zpplp_row8ar,
row11 TYPE zpplp_row8ar,
row12 TYPE zpplp_row8ar,
description TYPE string.
TYPES: END OF zpplp_pit8ar.
DATA: pit TYPE zpplp_pit8ar, pit_tab TYPE TABLE OF zpplp_pit8ar.
DATA: lt_fields TYPE abap_compdescr_tab, ls_fields type abap_compdescr .
field-symbols : <fs_data> type any.
DATA:
lo_tabledescr TYPE REF TO cl_abap_tabledescr.
DATA:
lo_structdescr TYPE REF TO cl_abap_structdescr.
lo_tabledescr ?= cl_abap_typedescr=>describe_by_data( p_data = pit_tab ).
lo_structdescr ?= lo_tabledescr->get_table_line_type( ).
lt_fields[] = lo_structdescr->components[].
LOOP AT pit_tab INTO pit.
LOOP AT lt_fields INTO ls_fields.
ASSIGN COMPONENT ls_fields-name OF STRUCTURE pit TO <fs_data>.
IF <fs_data> IS ASSIGNED.
WRITE: / ls_fields-name, sy-vline, <fs_data>.
UNASSIGN <fs_data>.
ENDIF.
ENDLOOP.
ENDLOOP.
2012 Sep 06 1:43 PM
HI Mariusz,
If I understood your requirement correctly, here I have attached sample code.
You can achieve this by using the standard classes - CL_ABAP_TYPEDESCR and subclasses
for and by using Field-symbols as explained in the example program below.
REPORT ztest.
*type-pools ABAP.
TYPES: BEGIN OF zpplp_row8ar,
zaliczka1 LIKE pc207-betrg,
zaliczka2 LIKE pc207-betrg,
zaliczka3 LIKE pc207-betrg,
zaliczka4 LIKE pc207-betrg,
zaliczka5 LIKE pc207-betrg,
zaliczka6 LIKE pc207-betrg,
zaliczka7 LIKE pc207-betrg,
zaliczka8 LIKE pc207-betrg,
zaliczka9 LIKE pc207-betrg,
zaliczka10 LIKE pc207-betrg,
zaliczka11 LIKE pc207-betrg,
zaliczka12 LIKE pc207-betrg,
zaliczka13 LIKE pc207-betrg,
sum LIKE pc207-betrg,
prowizja LIKE pc207-betrg,
end_sum LIKE pc207-betrg,
END OF zpplp_row8ar.
TYPES: BEGIN OF zpplp_pit8ar,
nip(13),
year(10),
from(10),
to(10),
row01 TYPE zpplp_row8ar,
row02 TYPE zpplp_row8ar,
row03 TYPE zpplp_row8ar,
row04 TYPE zpplp_row8ar,
row05 TYPE zpplp_row8ar,
row06 TYPE zpplp_row8ar,
row07 TYPE zpplp_row8ar,
row08 TYPE zpplp_row8ar,
row09 TYPE zpplp_row8ar,
row10 TYPE zpplp_row8ar,
row11 TYPE zpplp_row8ar,
row12 TYPE zpplp_row8ar,
description TYPE string.
TYPES: END OF zpplp_pit8ar.
DATA: pit TYPE zpplp_pit8ar, pit_tab TYPE TABLE OF zpplp_pit8ar.
DATA: lt_fields TYPE abap_compdescr_tab, ls_fields type abap_compdescr .
field-symbols : <fs_data> type any.
DATA:
lo_tabledescr TYPE REF TO cl_abap_tabledescr.
DATA:
lo_structdescr TYPE REF TO cl_abap_structdescr.
lo_tabledescr ?= cl_abap_typedescr=>describe_by_data( p_data = pit_tab ).
lo_structdescr ?= lo_tabledescr->get_table_line_type( ).
lt_fields[] = lo_structdescr->components[].
LOOP AT pit_tab INTO pit.
LOOP AT lt_fields INTO ls_fields.
ASSIGN COMPONENT ls_fields-name OF STRUCTURE pit TO <fs_data>.
IF <fs_data> IS ASSIGNED.
WRITE: / ls_fields-name, sy-vline, <fs_data>.
UNASSIGN <fs_data>.
ENDIF.
ENDLOOP.
ENDLOOP.