1. DESCRIBE
FIELD f.
2. DESCRIBE FIELD f INTO td.
Gets a particular attribute (variant 1) or all attributes of the field f.
If you use variant 1, you must also use at least one of the additions listed below.
If you
do not know the field whose attributes you want to get before runtime, you can assign the field to a
field symbol. (FIELD-SYMBOLS, ASSIGN).
You cannot apply the DESCRIBE statement to all ABAP
types. In connection with ABAP Objects, SAP has introduced an RTTI concept,
based on system classes, to determine type properties at runtime. This concept applies to all ABAP types
and thus also covers all the functions of the DESCRIBE FIELD statement.
DESCRIBE FIELD f.
1. ... LENGTH
len
2. ...
IN CHARACTER MODE
3. ...
IN BYTE MODE
4. ...
TYPE type
5. ...
TYPE type COMPONENTS n
6.
... OUTPUT-LENGTH len
7.
... DECIMALS n
8. ...
EDIT MASK mask
9. ... HELP-ID hlp
... LENGTH len
The internal length of field
f is placed in field len.
Note that if the field is of type
STRING or XSTRING,
the system returns the length of the string reference, which is always eight bytes, not the length
of relevant data object. The value written to len is of type I.
In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs. See DESCRIBE and Unicode. If you use the addition LENGTH, you must also use one of the two additions IN CHARACTER MODE or IN BYTE MODE in Unicode systems.
DATA: FLD(8),
LEN TYPE I.
DESCRIBE FIELD FLD LENGTH LEN IN CHARACTER MODE.
Result: LEN contains the value 8.
... IN CHARACTER MODE
This addition can only be used for character-type fields and in combination with the addition
LENGTH. The length of the field f is determined in characters.
... IN BYTE MODE
This addition can only be used in combination with the addition LENGTH.
The length of the field f is determined in bytes.
... TYPE type
The data type of f is placed in the field type.
DATA: FLD(8) TYPE N,
F_TYPE.
DESCRIBE FIELD FLD TYPE F_TYPE.
Result: F_TYPE contains the value 'N'.
Besides the elementary data types you can specify for
TYPES (C, N, and so on), there are further data types
that originate from Dictionary references or object generation. Each elementary type whose name is longer
than 1 character, has a short internal description. These data types, which are also returned by the
DESCRIBE statement, have the following type identification codes:
For compatibility reasons, ... TYPE type returns type C for structures, not u or v.
... TYPE type COMPONENTS n
The same as ... TYPE type, except that u or v is written
to type for structures, and the number of components in
the structure is written to
n. If f is
not a structure, n takes the value 0. The value returned in n has type I.
Recursive processing of the elements in an ABAP structure:
FORM TEST USING F.
DATA: TYP(1) TYPE C, N TYPE I.
FIELD-SYMBOLS: <F>.
DO.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE F TO <F>.
IF SY-SUBRC <> 0. EXIT. ENDIF.
DESCRIBE
FIELD <F> TYPE TYP COMPONENTS N.
IF N > 0. " Äquivalent hierzu
ist TYP = 'u' OR TYP = 'v'
PERFORM TEST USING <F>.
ELSE.
PERFORM DO_SOMETHING USING <F>.
ENDIF.
ENDDO.
ENDFORM.
... OUTPUT-LENGTH len
Returns the output length of
f to the variable len.
The output length is the length required for the field in a
WRITE statement. The maximum length of len
is therefore determined by the maximum length for a line of a list. For character strings, the system
returns the actual length in characters. For XSTRING type fields, it returns double the length in bytes.
For internal tables and structures containing internal tables, the value returned is 0, since they cannot
be displayed using the WRITE statement. The value returned
to len has type I.
In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs. Structures that are not purely character-type have the output length 0 in Unicode programs. See Determining the Length and Distance.
DATA: FLD(4) TYPE P,
O_LEN TYPE I.
DESCRIBE FIELD FLD OUTPUT-LENGTH O_LEN.
Result: O_LEN has the value 8.
... DECIMALS n
The number of decimal places for the field
f (in the DECIMALS
addition to the DATA statement, or defined in the ABAP
Dictionary) is entered in the variable n. The value returned
to n has the type I.
DATA: FLD(8) TYPE P DECIMALS 2,
DEC TYPE I.
DESCRIBE FIELD FLD DECIMALS DEC.
Result: DEC has the value 2.
... EDIT MASK mask
If the field f has a conversion routine in the ABAP Dictionary,
this is placed in the field
mask in the form "==conv".
"conv" stands for the name of the conversion routine;
for example, "
==ALPHA" for the conversion routine "ALPHA".
You can use the contents of
mask in this form in the USING
EDIT MASK mask addition of the WRITE statement.
Check whether the "Customer number" field in the table SBOOK has a conversion routine:
DATA SBOOK_WA TYPE SBOOK.
DATA: CONV_EXIT(10).
DESCRIBE FIELD SBOOK_WA-CUSTOMID EDIT MASK CONV_EXIT.
IF CONV_EXIT <> SPACE. ... ENDIF.
Result: CONV_EXIT contains the value "==ALPHA".
... HELP-ID hlp
The help ID (F1 help) belonging to field f is placed in
the field hlp. The result field hlp must have type C.
You can only find a help ID if the type of f has an explicit LIKE reference to a field in the ABAP Dictionary.
Find the help ID for various fields:
TYPES: MYTYPE LIKE SBOOK-CLASS.
DATA: F1 LIKE SBOOK-LUGGWEIGHT,
F2 TYPE MYTYPE,
F3
LIKE F1,
HLP(30) TYPE C,
NAME(30)
TYPE C VALUE 'SBOOK-ORDER_DATE'.
FIELD-SYMBOLS: <G1> TYPE ANY, <G2> TYPE ANY.
DESCRIBE
FIELD F1 HELP-ID HLP. WRITE: /(5) 'F1:', HLP.
DESCRIBE FIELD F2 HELP-ID HLP. WRITE: /(5) 'F2:',
HLP.
DESCRIBE FIELD F3 HELP-ID HLP. WRITE: /(5) 'F3:', HLP.
ASSIGN (NAME) TO <G1>.
DESCRIBE FIELD <G1> HELP-ID HLP. WRITE: /(5) '<G1>:', HLP.
ASSIGN F2 TO <G2>.
DESCRIBE FIELD <G2> HELP-ID HLP. WRITE: /(5) '<G2>:', HLP.
Result: The system displays the following help IDs:
F1: SBOOK-LUGGWEIGHT
F2: SBOOK-CLASS
F3:
SBOOK-LUGGWEIGHT
<G1>:
<G2>: SBOOK-CLASS
The help ID for field symbol <G1> is empty because it has no explicit LIKE reference to a Dictionary field.
DESCRIBE FIELD f INTO td.
This statement is for internal use only.
Incompatible changes or further developments may occur at any time without warning or notice.
The attributes of the field f, its components, subcomponents
and so on, are placed in the field td (type description).
td must have type SYDES_DESC,
defined in the type group SYDES.
You therefore need to declare type group SYDES in your
ABAP program using a TYPE-POOLS
statement.
The structure SYDES_DESC has two table
components, TYPES and NAMES:
As well as the tree structure information, the type description table (TYPES)
contains further information about the type of f or its
components. This includes all of the information obtained by the usual additions to
DESCRIBE FIELD. TYPES also contains the following additional columns:
Suppose the complex data type EMPLOYEE_STRUC is defined as follows:
PROGRAM DESCTEST.
TYPES: BEGIN OF NAME_STRUC,
FIRST(20) TYPE C,
LAST(20)
TYPE C,
END OF NAME_STRUC,
BEGIN OF ABSENCE_TIME_STRUC,
DAY TYPE
D,
FROM TYPE
T,
TO
TYPE T,
END OF ABSENCE_TIME_STRUC,
BEGIN OF EMPLOYEE_STRUC,
ID
LIKE SBOOK-CUSTOMID,
NAME
TYPE NAME_STRUC,
BEGIN OF ADDRESS,
STREET(30) TYPE C,
ZIPCODE(4) TYPE
N,
PLACE(30) TYPE C,
END OF ADDRESS,
SALARY_PER_MONTH(10) TYPE P DECIMALS
3,
ABSENT
TYPE STANDARD TABLE OF ABSENCE_TIME_STRUC
WITH NON-UNIQUE DEFAULT KEY,
PHONE TYPE
STANDARD TABLE OF PHONE_NUMBER
WITH NON-UNIQUE DEFAULT KEY,
END OF EMPLOYEE_STRUC.
By using the type group SYDES, you can determine the structure of type EMPLOYEE_STRUC as follows:
TYPE-POOLS: SYDES.
DATA: EMPLOYEE TYPE EMPLOYEE_STRUC,
TD TYPE SYDES_DESC.
DESCRIBE FIELD EMPLOYEE INTO TD.
The following table displays selected columns of the type description table
TD-TYPES. To make it easier to read, the column names of
the IDX_NAME, IDX_USER_TYPE
and IDX_EDIT_MASK columns have been abbreviated:
|FROM| TO |BACK|NAME|UTYP|EMSK|TYPE
----|----|----|----|----|----|----|----
1 | 2 | 7 | 0
| 0 | 2 | 0 | v
2 | 0 | 0
| 1 | 6 | 0 | 4 | N
3 | 8
| 9 | 1 | 7 | 5 | 0 | u
4
| 10 | 12 | 1 | 8 | 0 | 0 | u
5
| 0 | 0 | 1 | 9 | 0 | 0 | P
6 | 13 | 13 | 1 | 11 | 0 | 0 | h
7
| 17 | 17 | 1 | 12 | 0 | 0 | h
8 | 0
| 0 | 3 | 13 | 0 | 0 | C
9 | 0
| 0 | 3 | 14 | 0 | 0 | C
10 | 0
| 0 | 4 | 15 | 0 | 0 | C
11 | 0
| 0 | 4 | 16 | 0 | 0 | N
12 | 0
| 0 | 4 | 17 | 0 | 0 | C
13 | 14 | 16 | 6
| 0 | 18 | 0 | u
14 | 0 | 0 | 13 | 20 | 0
| 0 | D
15 | 0 | 0 | 13 | 21 | 0 | 0
| T
16 | 0 | 0 | 13 | 22 | 0 | 0 | T
17 | 0 | 0 | 7 | 0 | 0 | 0 | N
Note that the entries in lines 6 and 7 represent internal tables (ABAP type h).
For each internal table, there is always an entry for its line type (lines 13 and 17).
The
indexes in columns 5 and 7 cross-reference entries in the name table TD-NAMES.
For example, taking line 3, you would find the corresponding name in line 7 of
TD-NAMES, and the user type in line 5 (NAME_STRUC).
The name table TD-Names contains the following
entries. Note that the names
SALARY_PER_MONTH and ABSENCE_TIME_STRUC
are stored in two parts:
|CONTINUE|NAME
|CONTINUE|NAME
----|--------|-------------- ----|--------|--------------
1 | |DESCTEST 12
| |PHONE
2 | |EMPLOYEE_STRUC 13
| |FIRST
3 | |SBOOK-CUSTOMID 14
| |LAST
4 |
|==ALPHA 15 | |STREET
5 | |NAME_STRUC 16
| |ZIPCODE
6 |
|ID 17
| |PLACE
7 |
|NAME 18
| * |ABSENCE_TIME_ST
8 |
|ADDRESS 19
| |RUC
9 | * |SALARY_PER_MONT
20 | |DAY
10 |
|H
21 | |FROM
11 |
|ABSENT 22 | |TO
Determining the Attributes of Data Objects