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

internal table

Former Member
0 Likes
944

Hello ,

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

regds

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
910

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
Read only

Former Member
0 Likes
910

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

Read only

Former Member
0 Likes
910

hiiiii

u can use SY-COLNO for this requirement

it works

thanks

Read only

Former Member
0 Likes
910

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

Read only

Former Member
0 Likes
911

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

Read only

0 Likes
910

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.

Read only

0 Likes
910

Hi there,

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

thanks

Read only

0 Likes
910

Some code perhaps?

How is your structure defined? Etc.

Read only

0 Likes
910

thats my table

DATA: BEGIN OF gt_data OCCURS 0,

line(100), " | separated

END OF gt_data.

thanks

Read only

0 Likes
910

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