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: 

How to find the number of columns in an internal table DYNAMICALLY ?

Former Member
0 Kudos
1,594

Hi,

How to find the number of columns in an internal table DYNAMICALLY ?

Thanks and Regards,

saleem.

5 REPLIES 5

naimesh_patel
Active Contributor
0 Kudos
162

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

former_member181962
Active Contributor
0 Kudos
162

See this:

former_member188685
Active Contributor
0 Kudos
162

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

0 Kudos
162

Hi Vijay,

Thanks for your suitable answer.

Former Member
0 Kudos
162

Saleem,

Use the function GET_COMPONENT_LIST and pass the work area / header line of the table. It will return a table with the column details, DESCRIBE the table to find the no. of lines and that will the no. of columns.

Regards,

Ravi

Note - Please mark the helpful answers and close the thread.