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: 

use of DESCRIBE TABLE......... OCCURS n

Former Member
0 Kudos
1,452

Hi,

i want to know the use of DESCRIBE TABLE...........OCCURS n.

and its syntax to use.

regards,

Santosh

5 REPLIES 5

Former Member
0 Kudos
566

hi,

describe table is used to ge tthe number of records inn the table.

syntaxt:

data: lv_lines type i.

describe <itab> lines lv_lines.

Occurs 0 is used to declare table with header line.

data: begin of t_mara occurs 0,

matnr type matnr,

ernam type ernam,

end of t_mara.

0 Kudos
566

hi kasi raman, i am not asking the command OCCURS. i want to know the use of command OCCURS used with DESCRIBE

0 Kudos
566

Hi,

To find out the attributes of an internal table at runtime that were not available statically, use the statement:

DESCRIBE TABLE <itab> [LINES <l>] [OCCURS <n>] [KIND <k>].

If you use the LINES parameter, the number of filled lines is written to the variable <lin>. If you use the OCCURS parameter, the value of the INITIAL SIZE of the table is returned to the variable <n>. If you use the KIND parameter, the table type is returned to the variable <k>: ‘T’ for standard table, ‘S’ for sorted table, and ‘H’ for hashed table.

DATA: BEGIN OF LINE,

COL1 TYPE I,

COL2 TYPE I,

END OF LINE.

DATA ITAB LIKE HASHED TABLE OF LINE WITH UNIQUE KEY COL1

INITIAL SIZE 10.

DATA: LIN TYPE I,

INI TYPE I,

KND TYPE C.

DESCRIBE TABLE ITAB LINES LIN OCCURS INI KIND KND.

WRITE: / LIN, INI, KND.

DO 1000 TIMES.

LINE-COL1 = SY-INDEX.

LINE-COL2 = SY-INDEX ** 2.

INSERT LINE INTO TABLE ITAB.

ENDDO.

DESCRIBE TABLE ITAB LINES LIN OCCURS INI KIND KND.

WRITE: / LIN, INI, KND.

The output is:

0 10 H

1,000 10 H

Here, a hashed table ITAB is created and filled. The DESCRIBE TABLE statement is processed before and after the table is filled. The current number of lines changes, but the number of initial lines cannot change.

Regards

Former Member
0 Kudos
566

DESCRIBE TABLE itab.

Returns the attributes of the internal table itab. You must use at least one of the additions listed below:

1. ... LINES n

2. ... OCCURS n

3. ... KIND k

Places the number of filled lines of the table t in the field lin. The value returned to lin has type I.

DATA: N TYPE I,

ITAB TYPE TABLE OF I.

...

CLEAR ITAB.

APPEND 36 TO ITAB.

DESCRIBE TABLE ITAB LINES N.

Result: N contains the value 1.

OCCURS n

Effect

Passes the size of the OCCURS parameter from the table definition (as defined with DATA) to the variable n. The value returned to n has type I.

Example

DATA: N1 TYPE I,

N2 TYPE I,

ITAB1 TYPE TABLE OF I INITIAL SIZE 10,

ITAB2 TYPE I OCCURS 5.

DESCRIBE TABLE ITAB1 OCCURS N1.

DESCRIBE TABLE ITAB2 OCCURS N2.

Result: OCC contains the value 10 and N2 the value 5.

... KIND k

Effect

Writes the table type from itab to the variables n. The value returned to k is of type C. The constants SYDES_KIND-STANDARD, SYDES_KIND-SORTED and SYDES_KIND-HASHED are defined in the type group SYDES for the return values.

Example

Generic FORM routine any table type

TYPE-POOLS: SYDES.

...

FORM GENERIC_FORM USING ITAB TYPE ANY TABLE.

DATA: K TYPE C.

DESCRIBE TABLE ITAB KIND K.

CASE K.

WHEN SYDES_KIND-STANDARD.

...

WHEN SYDES_KIND-SORTED.

...

WHEN SYDES_KIND-HASHED.

...

ENDCASE.

ENDFORM.

Resard points if helpfull,

Regards,

Gopi.

Former Member
0 Kudos
566

Hi Sontosh Kumar,

This is kiran kumar.G.I will explain ur problem with example..

DESCRIBE:

Describe stmt is used to know how many records are there in ur internal table...

EX:

data: gv_lines type i.

describe table <Internal table name> lines gv_lines.

write:/ 'NUMBER OF RECORDS IN INTERNAL TABLE',gv_lines.

OCCURS 0:

This is used to declare internal table with header line.

when ever u have mention OCCURS 0 at that only BODY of the internal table is created,

EX:

data : begin of itab occurs 0,

vbeln like vbak-vbeln,

end of itab.

Award points if helpful.

Kiran Kumar.G

Have a Nice Day...