Skip to content

Instantly share code, notes, and snippets.

@zhjuncai
Last active March 19, 2024 03:39
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zhjuncai/6067997 to your computer and use it in GitHub Desktop.
Save zhjuncai/6067997 to your computer and use it in GitHub Desktop.
abap demo use of cl_abap_structdescr to get list of structure component definition
*&---------------------------------------------------------------------*
*& report z_demo_structdescr
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
report z_demo_structdescr.
data:
ls_trq_item type /scmtms/s_trq_item_k,
lr_trq_item type ref to /scmtms/s_trq_item_k,
lo_field_catalog type ref to cl_abap_structdescr,
lt_field_list type ddfields,
ls_field type line of ddfields,
lv_field_desc type string.
lo_field_catalog ?= cl_abap_structdescr=>describe_by_data( p_data = ls_trq_item ).
lt_field_list = lo_field_catalog->get_ddic_field_list( ).
read table lt_field_list into ls_field with key fieldname = 'key'.
if sy-subrc eq 0.
lv_field_desc = ls_field-fieldtext.
endif.
lo_field_catalog ?= cl_abap_structdescr=>describe_by_name( p_name = '/scmtms/s_trq_item_k' ).
check lo_field_catalog is bound.
free lt_field_list.
lt_field_list = lo_field_catalog->get_ddic_field_list( ).
create data lr_trq_item.
lo_field_catalog ?= cl_abap_structdescr=>describe_by_data_ref( p_data_ref = lr_trq_item ).
check lo_field_catalog is bound.
free lt_field_list.
lt_field_list = lo_field_catalog->get_ddic_field_list( ).
write / 'Done Test!'.
@ethantew
Copy link

ethantew commented Oct 2, 2021

Thank you, I found this is useful.

@bearmond1
Copy link

Line 21 will get you a dump

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment