Skip to Content
avatar image
Former Member

Find the number column of a internal table

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

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

9 Answers

  • Best Answer
    avatar image
    Former Member
    Apr 18, 2006 at 11:00 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 16, 2012 at 03: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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 18, 2006 at 10: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

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 18, 2006 at 11:02 AM

    Hi Paul,

    The number of columns will be static and i think there wil not be any syntax to get the same.

    REgards,

    Ravi

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 18, 2006 at 11:09 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 18, 2006 at 11:12 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 15, 2012 at 01: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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 15, 2012 at 01: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.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 16, 2012 at 04: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

    Add comment
    10|10000 characters needed characters exceeded