Application Development and Automation 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: 
Read only

DESCRIBE TABLE stmt

Former Member
0 Likes
3,086

I have seen the following code:

data: lv_line type i.

Describe table itab lines lv_line.

read table itab into wa_itab index data: lv_line type i.

Could you plz tell me what is the use of DESCRIBE stmt and where we use it?

What value will be stored in lv_line variable? What would be its initial value?

Plz suggest!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,044

Hi,

( 1 ) DESCRIBE FIELD f. :Gets a particular attribute or allattributes of the field f.

( 2 ) DESCRIBE TABLE itab. :Gets the attributes of the internaltable itab.

You must use at least one of the additions listed below.

a))) LINES n : Places the numebr of filled lines of the table itab into the field n. The value returned to n has typeI.

Example

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.

b))) OCCURS n : Places the value of the OCCURS or INITIALSIZE parameter from the definition of itab (DATA) into the variable n. The value returned ton has the 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: n1 has the value 10, N2 has the value 5.

c))) KIND k : Places the table typeof itab into the field k. The value returned to k has the type C. The return value is one of the constantsSYDES_KIND-STANDARD, SYDES_KIND-SORTED, orSYDES_KIND-HASHED from the type group SYDES.

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.

( 3 ) DESCRIBE LIST NUMBER OF LINES lin.

- DESCRIBE LIST NUMBER OF PAGES n.

- DESCRIBE LIST LINE lin PAGE pag.

- DESCRIBE LIST PAGE pag.

effect: Returns the attributes of a list. All variants have theaddition ... INDEX idx allowing you to determine the attributesof a particular list level (SY-LSIND = 0,1,2,3,... ).

Regards,

Priyanka.

8 REPLIES 8
Read only

piyush_mathur
Active Participant
0 Likes
2,044

HI Santo,

Describe table will show the property of internal table.

Describe table itab lines lv_line.

This code will return the no of lines in internal table in variable lv_line.

PLease refer below documentation for further information :

DESCRIBE TABLE

Syntax

DESCRIBE TABLE itab [KIND knd] [LINES lin] [OCCURS n].

Extras:

1. ... KIND knd

2. ... LINES lin

3. ... OCCURS n

Effect

This statement determines some properties of the internal table itab and assigns them to the specified variables. The various additions enable you to determine the table type, the number of currently filled rows and the initial memory requirement.

In addition, the system fields sy-tfill and sy-tleng are filled with the current number of table rows and the length of a table row in bytes.

Notes

For detailed information about an internal table, you should use the methods of RTTS of the DESCRIBE TABLE statement.

Without the specification of an addition, the statement DESCRIBE TABLE only sets the system fields sy-tfill and sy-tleng.

Addition 1

... KIND knd

Effect

The table type of the internal table itab is determined and a corresponding one-digit identification is assigned to the data object knd. A character-type data type is expected for the data object. The identifications are "T" for standard tables, "S" for sorted tables and "H" for hashed tables. These values are also defined as constants sydes_kind-standard, sydes_kind-sorted, and sydes_kind-hashed in the type group SYDES.

Addition 2

... LINES lin

Effect

The current number of table rows of the internal table itab is determined and is assigned to the data object lin.The data type i is expected for the data object.

Note

As of release 6.10, the current number of rows of an internal table can also be determined using the in-built function lines.

Addition 3

... OCCURS n

Effect

The initial memory requirement defined during the creation of the internal table with the addition INITIAL SIZE or the obsolete addition OCCURS is determined and assigned to the data object n. The data type i is expected for the data object.

Example

Descending sorting of a generically typed internal table in a subprogram. Since sorted tables cannot be sorted in a descending order, the table type is checked to avoid an exception that cannot be handled.

TYPE-POOLS sydes.

...

FORM sort_descending CHANGING itab TYPE ANY TABLE.

DATA tabkind(1) TYPE c.

DESCRIBE TABLE itab KIND tabkind.

IF tabkind = sydes_kind-standard OR

tabkind = sydes_kind-hashed.

SORT itab DESCENDING.

ELSEIF tabkind = sydes_kind-sorted.

MESSAGE '...' TYPE 'E'.

ELSE.

MESSAGE '...' TYPE 'E'.

ENDIF.

ENDFORM.

Thanks

Piyush

rewards points, if helpfull

Read only

Former Member
0 Likes
2,044

Hi

Hope it will help you.

Reward if help.

You may sometimes need to find out the attributes of a data object at runtime that were not statically available. For example, you may need to find out the type of a generic interface parameter in a subroutine. To do this, you would use the statement:

DESCRIBE FIELD <f> [LENGTH <l>] [TYPE <t> [COMPONENTS <n>]]

[OUTPUT-LENGTH <o>] [DECIMALS <d>]

[EDIT MASK <m>] [HELP-ID <h>].

The attributes of the data object <f> specified by the parameters of the statement are written to the variables following the parameters. You can use any number of the additions in the same statement.

DESCRIBE FIELD DISTANCE BETWEEN <f1> AND <f 2> INTO <d>.

This statement returns the distance between the data objects <f1> and <f 2>.

Read only

Former Member
0 Likes
2,044

HI,

DESCRIBE table will returns the value of number of lines existing in the internal table. The initial value is zero.

Rgds,

Bujji

Read only

Former Member
0 Likes
2,044

Hi,

DESCRIBE TABLE itab LINES lv_line.

This statements counts no. of records exist in itab internal table. The count will be placed in lv_line.

You can also write

DESCRIBE TABLE itab. (without LINES)

To get the no. of records exists in itab use system field.

SY-TFILL.

Read only

Former Member
0 Likes
2,044

Thx

Read only

Former Member
0 Likes
2,045

Hi,

( 1 ) DESCRIBE FIELD f. :Gets a particular attribute or allattributes of the field f.

( 2 ) DESCRIBE TABLE itab. :Gets the attributes of the internaltable itab.

You must use at least one of the additions listed below.

a))) LINES n : Places the numebr of filled lines of the table itab into the field n. The value returned to n has typeI.

Example

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.

b))) OCCURS n : Places the value of the OCCURS or INITIALSIZE parameter from the definition of itab (DATA) into the variable n. The value returned ton has the 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: n1 has the value 10, N2 has the value 5.

c))) KIND k : Places the table typeof itab into the field k. The value returned to k has the type C. The return value is one of the constantsSYDES_KIND-STANDARD, SYDES_KIND-SORTED, orSYDES_KIND-HASHED from the type group SYDES.

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.

( 3 ) DESCRIBE LIST NUMBER OF LINES lin.

- DESCRIBE LIST NUMBER OF PAGES n.

- DESCRIBE LIST LINE lin PAGE pag.

- DESCRIBE LIST PAGE pag.

effect: Returns the attributes of a list. All variants have theaddition ... INDEX idx allowing you to determine the attributesof a particular list level (SY-LSIND = 0,1,2,3,... ).

Regards,

Priyanka.

Read only

Former Member
0 Likes
2,044

Hi Santo,

Mainly Describe is used to find the total number of rows avilable in internal tabel, mainly this statement is used in module pool, in tablecontrol.

For example your internal table contain100 records, if you want to view 100 records in table control you will use this Describe statement

TABLE CONTROL NAME = TAB.

DESCRIBE TABLE <ITAB> LINES LV_LINE.

TAB-LINES = LV_LINE.

Read only

Former Member
0 Likes
2,044

HI ,

DESCRIBE:

DESCRIBE statement will returns the value of number of lines existing in the internal table.

INITIAL VALUE :

The initial value is zero.

thanks

satheesh