Application Development and Automation 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: 
Read only

find internal table colman

Former Member
0 Likes
1,272

Hi,

there is why to now how much Colman i have in internal table?

Regards

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,219

Hi,

please take a look into the well documentated classes of the runtime type service (RTTS). The root class for this is CL_ABAP_TYPEDESCR.

For internal table the classes CL_ABAP_TABLEDESCR and CL_ABAP_STRUCTDESCR might be interesting for you.

[Determining the Attributes of Data Objects|http://help.sap.com/saphelp_nw70/helpdata/EN/fc/eb3145358411d1829f0000e829fbfe/frameset.htm]

Regards Rudi

hi,

i now that for table row number i use sy-TFILL

what i have to use to now table colman nubers

Regards

10 REPLIES 10
Read only

Former Member
0 Likes
1,219

Hi,

I'm not clear ur question..

Read only

0 Likes
1,219

hi,

i now that for table row number i use sy-TFILL

what i have to use to now table colman nubers

Regards

Read only

matt
Active Contributor
0 Likes
1,219

I think you're asking how to find the number of columns in an internal table.

Easy. Let's assume your table is call it_itab,

DATA: l_count TYPE i,
      lp_data TYPE REF TO DATA.

FIELD-SYMBOLS: <l_field> TYPE any,
              <ls_wa> TYPE any.

CREATE DATA lp_data LIKE LINE OF it_itab.
ASSIGN lp_data->* TO <ls_wa>.

l_count = 0.
DO.
  ADD 1 TO l_count.
  ASSIGN COMPONENT l_count OF STRUCTURE <ls_wa> TO <l_field>.
  IF sy-subrc IS NOT INITIAL.
    EXIT.
  ENDIF. 
ENDDO.

SUBTRACT 1 FROM l_count.

WRITE: / 'Number of columns', l_count.

Edited by: Matthew Billingham on Jul 17, 2008 10:03 AM

Better solution

Read only

Former Member
0 Likes
1,220

Hi,

please take a look into the well documentated classes of the runtime type service (RTTS). The root class for this is CL_ABAP_TYPEDESCR.

For internal table the classes CL_ABAP_TABLEDESCR and CL_ABAP_STRUCTDESCR might be interesting for you.

[Determining the Attributes of Data Objects|http://help.sap.com/saphelp_nw70/helpdata/EN/fc/eb3145358411d1829f0000e829fbfe/frameset.htm]

Regards Rudi

Read only

matt
Active Contributor
0 Likes
1,219

>

> Hi,

>

> please take a look into the well documentated classes of the runtime type service (RTTS). The root class for this is CL_ABAP_TYPEDESCR.

>

> For internal table the classes CL_ABAP_TABLEDESCR and CL_ABAP_STRUCTDESCR might be interesting for you.

>

> [Determining the Attributes of Data Objects|http://help.sap.com/saphelp_nw70/helpdata/EN/fc/eb3145358411d1829f0000e829fbfe/frameset.htm]

>

> Regards Rudi

Much better solution than mine!

Read only

0 Likes
1,219

hi Matthew Billingham ,

i not familiar with classes maybe u can give me e.g.

Regards

Read only

0 Likes
1,219

Hi,

see this example:


DATA gt_mara TYPE mara_tab.

DATA gx_struc TYPE REF TO cl_abap_structdescr.
DATA gx_table TYPE REF TO cl_abap_tabledescr.
DATA gv_lines TYPE i.
FIELD-SYMBOLS <gs_components> TYPE abap_compdescr.
FIELD-SYMBOLS <gv_field> TYPE ANY.

gx_table ?= cl_abap_typedescr=>describe_by_data( gt_mara ).
gx_struc ?= gx_table->get_table_line_type( ).
DESCRIBE TABLE gx_struc->components LINES gv_lines.

Regards Rudi

Read only

0 Likes
1,219

Try this code.

DATA : BEGIN OF it_mara OCCURS 0,

matnr LIKE mara-matnr,

ersda LIKE mara-ersda,

END OF it_mara.

DATA : p(5) TYPE c.

FIELD-SYMBOLS: <fs_record> TYPE ANY.

FIELD-SYMBOLS: <fs_comp> TYPE ANY.

IF it_mara IS NOT INITIAL.

ASSIGN it_mara TO <fs_record>.

DO.

ASSIGN COMPONENT sy-index OF STRUCTURE <fs_record> TO <fs_comp>.

IF sy-subrc EQ 0.

p = p + 1.

ELSE.

EXIT.

ENDIF.

ENDDO.

ENDIF.

WRITE : / p.

Read only

matt
Active Contributor
0 Likes
1,219

>

> hi Matthew Billingham ,

>

> i not familiar with classes maybe u can give me e.g.

>

> Regards

Follow Rudi's approach

Or - no classes with this one - haven't tried it, but it should work:

DATA: lp_data TYPE REF TO data.
FIELD-SYMBOLS: <ls_wa>.
DATA: l_count TYPE i,
      l_type  TYPE c.

CREATE DATA lp_data LIKE LINE OF itab.
ASSIGN lp_data->* TO <ls_wa>.

DESCRIBE FIELD <ls_wa> l_type COMPONENTS l_count.

Read the abap help on keywords DESCRIBE FIELD.

matt

Read only

matt
Active Contributor
0 Likes
1,219

>

> Try this code.

>

> DATA : BEGIN OF it_mara OCCURS 0,

> matnr LIKE mara-matnr,

> ersda LIKE mara-ersda,

> END OF it_mara.

>

> DATA : p(5) TYPE c.

> FIELD-SYMBOLS: <fs_record> TYPE ANY.

> FIELD-SYMBOLS: <fs_comp> TYPE ANY.

>

> IF it_mara IS NOT INITIAL.

> ASSIGN it_mara TO <fs_record>.

> DO.

> ASSIGN COMPONENT sy-index OF STRUCTURE <fs_record> TO <fs_comp>.

> IF sy-subrc EQ 0.

> p = p + 1.

> ELSE.

> EXIT.

> ENDIF.

> ENDDO.

> ENDIF.

> WRITE : / p.

Doesn't work if the table has no records in it.