Skip to Content
-3

How to write number of columns of internal table?

Aug 11, 2017 at 12:53 PM

118

avatar image

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.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Fabian Lupa Aug 11, 2017 at 02:31 PM
2
Share
10 |10000 characters needed characters left characters exceeded
Domi Bigl 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.
Show 2 Share
10 |10000 characters needed characters left characters exceeded

code below:

the number of columns is still 1! Why do that? :-(



*&---------------------------------------------------------------------*

*& Report  Z_DB_TABLE_COL

*&

*&---------------------------------------------------------------------*

*&

*&

*&---------------------------------------------------------------------*

REPORT Z_DB_TABLE_COL.



PARAMETERS: p_table LIKE dd03l-tabname. " vložení názvu tabulky s možností filtrace



FIELD-SYMBOLS:

  <fs_table> TYPE table, " zavedení symbolů pro název tabulky

  <wa_table> TYPE any,

  <fs>.

DATA: xtable TYPE REF TO data, " tohle dává zprávu překladači, že data objektového typu budou definované za běhu

lin_table type i,

col_table TYPE i.





CREATE DATA xtable TYPE TABLE OF (p_table)." vytváření dat XTABLE za běhu

ASSIGN xtable->* TO <fs_table>. " před použitím symbolu pole loop, musí být přiřazeno

SELECT * FROM (p_table) INTO TABLE <fs_table> ORDER BY PRIMARY KEY. " výběr DB tabulky a přeházení dat do interní tabulky

LOOP AT <fs_table> ASSIGNING <wa_table>. " smyčka pro čtení tabulky

*  write: / <wa_table>.

ENDLOOP.





DESCRIBE TABLE <fs_table> LINES lin_table.

DATA: lv_index                TYPE i.



FIELD-SYMBOLS: <lv_any_field> TYPE any.



DO.

  lv_index = lv_index + 1.

  ASSIGN COMPONENT lv_index OF STRUCTURE <fs_table> TO <lv_any_field>.

  IF sy-subrc <> 0.

    EXIT. "DO

  ENDIF.

ENDDO.



DATA(lv_adrc_field_no) = lv_index - 1.



write: / 'lines: ',lin_table, 'columns:', <lv_any_field>.
0

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

0
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.
Share
10 |10000 characters needed characters left characters exceeded