04-18-2006 11:54 AM
Hi all,
At the runtime I need to find the number of column of a internal table . For example for finding the number of rows we will be using DESCRIBE TABLE ...... like that do we have any statemnt.
regards
paul
04-18-2006 12:00 PM
Hi paul,
1. GET_COMPONENT_LIST
use this FM
2. not only the column number,
u will get all column details.
column name,
data type
length .
3. eg. (just copy paste in new program)
REPORT abc.
DATA : cmp LIKE TABLE OF rstrucinfo WITH HEADER LINE.
DATA : pa0001 LIKE TABLE OF pa0001 WITH HEADER LINE.
CALL FUNCTION 'GET_COMPONENT_LIST'
EXPORTING
program = sy-repid
fieldname = 'PA0001'
TABLES
components = cmp.
LOOP AT cmp.
WRITE 😕 cmp-compname , cmp-TYPE , cmp-olen.
ENDLOOP.
regards,
amit m.
04-18-2006 11:59 AM
Hi Paul
Number of columns in Internal Tables are fixed and doesnt and cant vary while execution so, that you know when you create internal table.
In case of extracts you have different number of columns for different type of records/lines.
Thanks
04-18-2006 12:00 PM
Hi paul,
1. GET_COMPONENT_LIST
use this FM
2. not only the column number,
u will get all column details.
column name,
data type
length .
3. eg. (just copy paste in new program)
REPORT abc.
DATA : cmp LIKE TABLE OF rstrucinfo WITH HEADER LINE.
DATA : pa0001 LIKE TABLE OF pa0001 WITH HEADER LINE.
CALL FUNCTION 'GET_COMPONENT_LIST'
EXPORTING
program = sy-repid
fieldname = 'PA0001'
TABLES
components = cmp.
LOOP AT cmp.
WRITE 😕 cmp-compname , cmp-TYPE , cmp-olen.
ENDLOOP.
regards,
amit m.
04-18-2006 12:02 PM
Hi Paul,
The number of columns will be static and i think there wil not be any syntax to get the same.
REgards,
Ravi
04-18-2006 12:09 PM
Hello,
DATA: IT_COMP LIKE RSTRUCINFO OCCURS 0 WITH HEADER LINE.
data: P_tab LIKE DD03L-TABNAME. "Internal table
CALL 'AB_STRUC_INFO'
ID 'PROGRAM' FIELD SY-CPROG
ID 'STRUCNAME' FIELD P_ITAB
ID 'STRUCINFO' FIELD IT_COMP-SYS.
Table IT_COMP will give you a list of all fields of Internal table.
describe table it_comp lines sy-index. will give you number of fields of internal table.
Regards,
Naimesh
04-18-2006 12:12 PM
Hi,
you can find the number of columns and their order using
the <b>'REUSE_ALV_FIELDCATALOG_MERGE'</b>
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = sy-repid
I_INTERNAL_TABNAME = 'ITAB'
I_INCLNAME = sy-repid
changing
ct_fieldcat = IT_FIELDCAT
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3
.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif
now describe your fieldcat . and find no of columns.
and their order also..
Regards
vijay
03-15-2012 1:22 PM
I always use the classes below.
CL_ABAP_CLASSDESCR
CL_ABAP_COMPLEXDESCR
CL_ABAP_DATADESCR
CL_ABAP_ELEMDESCR
CL_ABAP_INTFDESCR
CL_ABAP_OBJECTDESCR
CL_ABAP_REFDESCR
CL_ABAP_STRUCTDESCR
CL_ABAP_TABLEDESCR
CL_ABAP_TYPEDESCR
Good luck!
Best regards, Sander Pol
03-15-2012 1:47 PM
The SYST (sy-) variable seems to be SCOL (look at content of SYST in debug after your describe statement). However, one needs to consider that .include's are apparently counted as a column.
03-16-2012 3:06 AM
Hi,
Try this simple way of counting columns of your internal table
DATA: w_count LIKE sy-tabix.
FIELD-SYMBOLS: <fs>.
DATA: BEGIN OF itab OCCURS 0,
text1 TYPE c,
text2 TYPE c,
text3 TYPE c,
num1 TYPE n,
num2 TYPE n,
num3 TYPE n,
END OF itab.
CLEAR w_count.
DO.
ADD 1 TO w_count.
ASSIGN COMPONENT w_count OF STRUCTURE itab TO <fs>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
ENDDO.
SUBTRACT 1 FROM w_count.
WRITE: w_count.
Regards,
Jake
03-16-2012 4:52 AM
Hi,
assign the structure to a field symbol and use assign-components ... press F1 help on assign components...
if sy-index = 1.
ASSIGN COMPONENT sy-index OF STRUCTURE <fs_record> TO <fs_comp>.
IF sy-subrc <> 0.
count = count + 1.
ENDIF.
endif.
Otherwise use the below code,
DO.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE GWA_ITAB TO <FS>.
IF SY-SUBRC = 0.
CONTINUE.
ELSE.
G_COLNUMBER = SY-INDEX.
EXIT.
ENDIF.
ENDDO.
Now G_COLNUMBER - 1 , will be the no of column.
Regards,
Arun