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: 

internal table

Former Member
0 Kudos

Hello ,

How to count number of columns in internal table...any ideas?

regds

1 ACCEPTED SOLUTION

Former Member
0 Kudos

thanks for your replies..wotever i do all iam getting is 9 which is number of entries in the table...but iam looking for number of columns...any more ideas?

thanks

9 REPLIES 9

Former Member
0 Kudos

Hi,

Try the following

data: gs_t001 type t001.

data: go_struct type ref to cl_abap_structdescr,
      gt_comp   type abap_component_tab,
      gs_comp   type abap_componentdescr.

start-of-selection.

  go_struct ?= cl_abap_typedescr=>describe_by_data( gs_t001 ).
  gt_comp = go_struct->get_components( ).
describe table gt_comp lines sy-tfill.

write: / sy-tfill.

Darren

Former Member
0 Kudos

hiiiii

u can use SY-COLNO for this requirement

it works

thanks

Former Member
0 Kudos

And if you don't have the class cl_abap_typedescr, try something like this:

data: lv_count type i.

field-symbols: <field> type any.

do.
  assign component sy-index of structure YOUR_ITAB_STRUCTURE to <field>.
  if sy-subrc eq 0.
    lv_count = sy-index - 1.
  else.
    exit.
  endif.

enddo.

Edited by: Maen Anachronos on Oct 3, 2008 12:44 PM

Former Member
0 Kudos

thanks for your replies..wotever i do all iam getting is 9 which is number of entries in the table...but iam looking for number of columns...any more ideas?

thanks

0 Kudos

You haven't tried it the right way.

Does your internal table use a workarea? If so, look at my example and try that one. In no way that will return the number of entries in your internal table.

0 Kudos

Hi there,

ive tried it ..but all iam getting is 1..do i have to do anythin else?

thanks

0 Kudos

Some code perhaps?

How is your structure defined? Etc.

0 Kudos

thats my table

DATA: BEGIN OF gt_data OCCURS 0,

line(100), " | separated

END OF gt_data.

thanks

0 Kudos

What i was afraid of.. your structure only has 1 column. Hence, your result equals 1.

edit:

Apparently, you have a '|' separated string in there.

Read a line from your internal table into a workarea.

Use SPLIT workarea TABLE lt_temp AT '|'

And then count the number of lines in lt_temp.

I assume all lines in your intenal table have the same structure, e.g. the same number of separated values.

Edited by: Maen Anachronos on Oct 3, 2008 1:46 PM