Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
7 REPLIES 7

MarcoK
Explorer

Hi,

the keyword here is RTTI

 

DATA(lr_tabledescr) = CAST cl_abap_tabledescr( cl_abap_typedescr=>describe_by_data( lt_analok ) ).
DATA(lr_structdescr) = CAST cl_abap_structdescr( lr_tabledescr->get_table_line_type( ) ).
data(lt_col_names) = VALUE FIELDNAME_TAB( for ls in lr_structdescr->components ( ls-name ) ).
cl_demo_output=>write_data( lt_col_names ).
cl_demo_output=>display( ).

 

Edit: replaced lt_test with lt_analok

0 Kudos

thank you very much but can you edit this code according to the code I gave me above?
I want the column headers of the lt_analok table.
I am new to abap so sorry.
I would appreciate your help. 🙂

That would've been a nice little exercise (to find the place to change the coding to use lt_analok), but nonetheless I've edited the code. 😉

0 Kudos

DATA(lr_tabledescr) = CAST cl_abap_tabledescr( cl_abap_typedescr=>describe_by_data( lt_analok ) ).
DATA(lr_structdescr) = CAST cl_abap_structdescr( lr_tabledescr->get_table_line_type( ) ).

DATA(sutun_basliklari) = VALUE fieldname_tab( FOR ls IN lr_structdescr->components ( ls-name ) ).
DATA(sutun_type) = VALUE fieldname_tab( FOR ls IN lr_structdescr->components ( ls-type_kind ) ).

DATA index TYPE i.
index = 1.
LOOP AT sutun_basliklari INTO DATA(ls_st).
  WRITE: / index,   ' ' ,  ls_st, ' ', sutun_type[ index ] .  .
  index = index + 1.
ENDLOOP.

cl_demo_output=>display( ).

Hello, it's me again 🙂 I have one more question, I was able to print the column headers and types, but I couldn't get the output of the length parameter, can you help me? I leave the final version of the code below.  

 

SELECT lifnr, surbel, tedbf, eysbel, degkul, degtar, degsaa, iso_9001, iso_9001_t,
      iatf_16949, iatf_16949_t, surbel_t, iso_14001, iso_14001_t, iso_45001,
      iso_45001_t, iso_27001, iso_27001_t, iso_50001, iso_50001_t, iso_genel, iso_genel_t
          FROM zbtmm_t_0001 WHERE  (  ( iso_genel_t >= '20230101'  AND iso_genel_t <= '20250101' ) OR
              ( iso_50001_t  >= '20230101'  AND iso_50001_t  <= '20250101' ) OR
              ( iso_27001_t  >= '20230101'  AND iso_27001_t  <= '20250101' ) OR
              ( iso_45001_t  >= '20230101'  AND iso_45001_t  <= '20250101' ) OR
              ( iso_14001_t  >= '20230101'  AND iso_14001_t  <= '20250101' ) OR
              ( surbel_t     >= '20230101' AND surbel_t     <= '20250101' ) OR
              ( iatf_16949_t >= '20230101'  AND iatf_16949_t <= '20250101' ) OR
              ( iso_9001_t   >= '20230101'  AND iso_9001_t   <= '20250101' ) ) INTO TABLE (lt_analok).

DATA(lr_tabledescr) = CAST cl_abap_tabledescr( cl_abap_typedescr=>describe_by_data( lt_analok ) ).
DATA(lr_structdescr) = CAST cl_abap_structdescr( lr_tabledescr->get_table_line_type( ) ).

DATA(sutun_basliklari) = VALUE fieldname_tab( FOR ls IN lr_structdescr->components ( ls-name ) ).
DATA(sutun_type) = VALUE fieldname_tab( FOR ls IN lr_structdescr->components ( ls-type_kind ) ).

DATA index TYPE i.
index = 1.
LOOP AT sutun_basliklari INTO DATA(ls_st).
  WRITE: / index,   ' ' ,  ls_st, ' ', sutun_type[ index ] .  .
  index = index + 1.
ENDLOOP.

cl_demo_output=>display( ).

 

0 Kudos

This time just a few comments from me:

even if it works here, fieldname_tab is not the correct type for sutun_type,
take a look at the documentation of sy-tabix,
you can find the field length also in  lr_structdescr->components,
it looks like that there's no need for sutun_basliklari and sutun_type. Just use lr_structdescr->components in your loop
If you don't use cl_demo_output=>write_data, you don't need cl_demo_output=>display( )  here.

 

0 Kudos

Yes, I examined it after I asked you. Since it is a table, it is enough to return in the loop. thank you again.

LOOP AT sutun_basliklari INTO DATA(ls_st).

  WRITE: / index, ' ', ls_st, ' ', sutun_type[ index ], ' Length: ', lr_structdescr->components[ index ]-length.
  index = index + 1.

ENDLOOP.