ABAP DESCRIBE FIELD/TABLE Usage .

There are three types of DESCRIBE statements. Let’s briefly describe the usage of DESCRIBE FIELD:
Properties of an Internal Table 1. DESCRIBE TABLE ...
Field Properties 2. DESCRIBE FIELD ...
Distance Between Two Fields 3. DESCRIBE DISTANCE ...


(1): DESCRIBE TABLE

语法:DESCRIBE TABLE itab   [KIND knd]  [LINES lin]  [OCCURS n]

Function: judge some attributes of the internal table itab and assign them to the specified variables. Different options enable you to determine the table type, the current number of field rows and the memory size required for initialization.

In addition, the system fields sy-tfill and sy-tleng hold the current number of table rows and the length of the table rows in bytes.

Note:

For more detailed information about the internal table, use the RTTS method instead of the statement describe table.

Without specifying an additional item, the statement describe table only sets the values ​​of the system fields sy-tfill and sy-tleng.

1.······CHILD knd

Determine the table type of the internal table itab, and assign a corresponding character identifier to the data object knd of the character data type. When marked as T, it represents a standard table, when it is marked as S, it represents a sorted table, and when it is marked as H, it represents a hash table.

These values ​​are also defined in the type group SYDES as constants sydes_kind-standed, sydes_kind-sorted, sydes_kind-hashed.

Example: Sort a general internal table in descending order in a subroutine. Because sorted tables cannot be sorted in descending order, table type checking is performed to avoid unhandled exceptions.
              TYPE-POOLS sydes.
          ...
           FORM sort_descending CHANGINGitab TYPE ANY TABLE.
             DATA tabkind(1) TYPE c.
             DESCRIBE TABLE itab KIND tabkind.
             IF tabkind = sydes_kind-standard OR
                tabkind= sydes_kind-hashed.
                SORTitab DESCENDING.
             ELSEIF tabkind = sydes_kind- sorted.
                MESSAGE'...' TYPE 'E'.
             ELSE.
                MESSAGE'...' TYPE 'E'.
             ENDIF.
           ENDFORM.

2.·····LINES lin

DESCRIBE TABLE lt_mat LINES lv_cont. 

This line means to calculate the number of rows in the internal table lt_mat, and put the number of rows into the variable lv_cont.

lv_cont is a data object of type I.

Note:

In version 6.10, the current number of internal table rows can also be determined with the built-in function lines.

3.·····OCCURS n

Determine the initial memory size required by the inner table during the creation of the inner table with the option initial size or the old-fashioned option ocurs, and assign the value to the data object n, where n is a data object of type I.

(2) DESCRIBE  FIELD

Function: Describe the attributes of an Elementary data, that is to say, you can know the type, length, decimal point, output length and other information of a certain data through this statement. The syntax is as follows.
DESCRIBE FIELD dobj
   [TYPE typ [COMPONENTS com]]
   [LENGTH ilen IN { BYTE | CHARACTER } MODE]
   [DECIMALS dec]
   [OUTPUT-LENGTH olen]
   [HELP-ID hlp]
   [EDIT MASK mask].
1. ... TYPE typ [COMPONENTS com]
DESCRIBE FIELD data1 TYPE typ1 COMPONENTS com1.
The result of the operation is that the type of data1 is stored in the variable typ1, and com1 stores several sub-elements in data1.
2. ... LENGTH ilen IN { BYTE | CHARACTER } MODE
DESCRIBE FIELD data1 LENGTH ilen IN BYTE CHARACTER MODE.
The result of the operation is that the length defined by data1 is stored in ilen.
3. ... DECIMALS dec
DESCRIBE FIELD data1 DECIMALS dec.
The result of the operation is that if data1 is a decimal, dec stores the number of digits after the decimal point.
4. ... OUTPUT-LENGTH olen
DESCRIBE FIELD data1 OUTPUT-LENGTH olen.
The result of the operation is that the output length of data1 is stored in olen.
5. ... HELP-ID hlp
DESCRIBE FIELD carry HELP-ID hlp.
If data1 is determined by the data element in ABAP Dictionary, the data type of data1 will be stored in hlp.
6. ... EDIT MASK mask
DATA: time TYPE s_fltime,
       seconds TYPE i,
       msk TYPE string.
DESCRIBE FIELD time EDIT MASK msk.
seconds = 333.
WRITE seconds USING EDIT MASK msk
. —————
Copyright statement: This article is an original article of CSDN blogger "Mengbi Shenghua 111", following the CC 4.0 BY-SA copyright agreement, please attach the original source link and this statement for reprinting.
Original link: https://blog.csdn.net/Victor9279/article/details/53007568

Guess you like

Origin blog.csdn.net/qq_53645728/article/details/129753556