Skip to Content
-3

How to write number of columns of internal table?

Hi, alll,

I have a task.

To display number of columns of internal table. Can you help me how to do that?

Some smart function?

I know how to display number of lines.

describe table name_table lines num_lines.

write num_lines.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Aug 11, 2017 at 02:31 PM
    Add comment
    10|10000 characters needed characters exceeded

  • Aug 11, 2017 at 09:53 PM
    -1

    Depending on your needs maybe one of this option is also useful

    **********************************************************************
    * Static DDIC Table with details
    DATA: lt_dfies_but000     TYPE TABLE OF dfies.
    
    CALL FUNCTION 'DDIF_FIELDINFO_GET'
      EXPORTING
        tabname   = 'BUT000' "<== Table
      TABLES
        dfies_tab = lt_dfies_but000
      EXCEPTIONS
        OTHERS    = 1.
    
    DATA(lv_but000_field_no) = lines( lt_dfies_but000 ).
    
    **********************************************************************
    * Static DDIC Structure with details
    DATA: lt_dfies_eew_but000 TYPE TABLE OF dfies.
    
    CALL FUNCTION 'DDIF_FIELDINFO_GET'
      EXPORTING
        tabname   = 'INCL_EEW_BUT000' "<== Structure
      TABLES
        dfies_tab = lt_dfies_eew_but000
      EXCEPTIONS
        OTHERS    = 1.
    
    DATA(lv_eew_but000_field_no) = lines( lt_dfies_eew_but000 ).
    
    **********************************************************************
    * Some Dynamic Structure - just count
    DATA: ls_adrc             TYPE adrc.
    DATA: lv_index                TYPE i.
    
    FIELD-SYMBOLS: <lv_any_field> TYPE any.
    
    DO.
      lv_index = lv_index + 1.
      ASSIGN COMPONENT lv_index OF STRUCTURE ls_adrc TO <lv_any_field>.
      IF sy-subrc <> 0.
        EXIT. "DO
      ENDIF.
    ENDDO.
    
    DATA(lv_adrc_field_no) = lv_index - 1.
    
    Add comment
    10|10000 characters needed characters exceeded

    • you need to use the structure <wa_table>

      The number of columns will be in lv_adrc_field_no

      ...
      DO.
        lv_index = lv_index + 1.
        ASSIGN COMPONENT lv_index OF STRUCTURE <wa_table> TO <lv_any_field>. "USE <wa_table>
        IF sy-subrc <> 0.
          EXIT. "DO
        ENDIF.
      ENDDO.
      
      DATA(lv_adrc_field_no) = lv_index - 1.
      
      write: / 'lines: ',lin_table, 'columns:', lv_adrc_field_no. "USE lv_adrc_field_no
      
  • avatar image
    Former Member
    Aug 13, 2017 at 08:21 AM
    -1
    *SY-TABIX CONTAINS INTERNAL TABLE INDEX NO   
    
    DATA: COUNT LIKE SY-TABIX. 
    FIELD-SYMBOLS: <FS>.
    
    Data:BEGIN OF ITAB OCCURS 0 ,
         NAME(10) TYPE C, 
         AGE TYPE I,
         SAL TYPE I,
    END OF ITAB. 
    
     CLEAR COUNT.
         
    
          DO.
              ADD 1 TO COUNT.
              ASSIGN COMPONENT COUNT OF STRUCTURE ITAB TO <FS> . 
            IF SY-SUBRC <> 0. 
                EXIT.
            ENDIF.
          ENDDO.
    
         SUBTRACT 1 FROM COUNT.  
         WRITE: 'NO OF COLUMNS:',COUNT.
    Add comment
    10|10000 characters needed characters exceeded