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: 

cl_abap_typedescr=>key skips type P fields

Former Member
0 Kudos

Hi,

LOOP AT l_ref->key in the code below skips TYPE P fields. Is this a bug? Is there a solution to this issue? Thanks.

REPORT ztest.

TYPES: BEGIN OF t_tab,
          charfld_01(1) TYPE c,
          quanfld_01 TYPE p,
          charfld_02(1) TYPE c,
          quanfld_02 TYPE p,
          charfld_03(1) TYPE c,
       END OF t_tab.

DATA lt_tab TYPE STANDARD TABLE OF t_tab.

DATA l_ref TYPE REF TO cl_abap_tabledescr.

FIELD-SYMBOLS <key_comp_wa> TYPE abap_keydescr.

START-OF-SELECTION.
  l_ref ?= cl_abap_typedescr=>describe_by_data( lt_tab ).

  LOOP AT l_ref->key ASSIGNING <key_comp_wa>.
    WRITE:/ <key_comp_wa>-name.
  ENDLOOP.

* end

William

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi

The attribute L_REF->KEY has the key fields only, and all CHAR fields are considerated as key fields for a internal table.

Max

2 REPLIES 2

Former Member
0 Kudos

Hi

The attribute L_REF->KEY has the key fields only, and all CHAR fields are considerated as key fields for a internal table.

Max

0 Kudos

Try this (class CL_ABAP_STRUCTDESCR instead of CL_ABAP_TABLEDESCR)

TYPES: BEGIN OF T_TAB,

           CHARFLD_01(1) TYPE C,

           QUANFLD_01 TYPE P,

           CHARFLD_02(1) TYPE C,

           QUANFLD_02 TYPE P,

           CHARFLD_03(1) TYPE C,

           CHARFLD_04 TYPE I,

        END OF T_TAB.

DATA LT_TAB TYPE STANDARD TABLE OF T_TAB WITH HEADER LINE.

DATA L_REF TYPE REF TO CL_ABAP_STRUCTDESCR.

FIELD-SYMBOLS: <KEY_COMP_WA> TYPE ABAP_COMPDESCR.

START-OF-SELECTION.

   L_REF ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( LT_TAB ).

   LOOP AT L_REF->COMPONENTS ASSIGNING <KEY_COMP_WA>.

     WRITE:/ <KEY_COMP_WA>-NAME.

   ENDLOOP.