10-03-2008 11:33 AM
Hello ,
How to count number of columns in internal table...any ideas?
regds
10-03-2008 12:11 PM
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
10-03-2008 11:36 AM
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
10-03-2008 11:38 AM
10-03-2008 11:40 AM
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
10-03-2008 12:11 PM
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
10-03-2008 12:18 PM
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.
10-03-2008 12:28 PM
Hi there,
ive tried it ..but all iam getting is 1..do i have to do anythin else?
thanks
10-03-2008 12:29 PM
10-03-2008 12:35 PM
thats my table
DATA: BEGIN OF gt_data OCCURS 0,
line(100), " | separated
END OF gt_data.
thanks
10-03-2008 12:38 PM
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