DESCRIBE - Supply the Attributes of a Field

Variants:

1. DESCRIBE FIELD f.

2. DESCRIBE FIELD f INTO td.

Effect

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).

Note

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.

Variant 1

DESCRIBE FIELD f.


Extras:

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

Addition 1

... LENGTH len

Effect

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.

Example

DATA: FLD(8),
      LEN TYPE I.
DESCRIBE FIELD FLD LENGTH LEN IN CHARACTER MODE.

Result: LEN contains the value 8.

Addition 2

... IN CHARACTER MODE

Effect

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.

Addition 3

... IN BYTE MODE

Effect

This addition can only be used in combination with the addition LENGTH. The length of the field f is determined in bytes.

Addition 4

... TYPE type

Effect

The data type of f is placed in the field type.

Example

DATA: FLD(8) TYPE N,
      F_TYPE.
DESCRIBE FIELD FLD TYPE F_TYPE.

Result: F_TYPE contains the value 'N'.

Note

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:

b
1 byte integer without sign
g
String (STRING): Character string of variable length
h
Internal table
l
Data reference (REF TO DATA)
r
Object reference
s
2 byte integer with sign
u
Structure without internal table
v
Structure containing at least one internal table
y
X string (XSTRING): Byte sequence of variable length

For compatibility reasons, ... TYPE type returns type C for structures, not u or v.

Addition 5

... TYPE type COMPONENTS n

Effect

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.

Example

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.

Addition 6

... OUTPUT-LENGTH len

Effect

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.

Example

DATA: FLD(4) TYPE P,
      O_LEN  TYPE I.
DESCRIBE FIELD FLD OUTPUT-LENGTH O_LEN.

Result: O_LEN has the value 8.

Addition 7

... DECIMALS n

Effect

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.

Example

DATA: FLD(8) TYPE P DECIMALS 2,
      DEC    TYPE I.
DESCRIBE FIELD FLD DECIMALS DEC.

Result: DEC has the value 2.

Addition 8

... EDIT MASK mask

Effect

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.

Example

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".

Addition 9

... HELP-ID hlp

Effect

The help ID (F1 help) belonging to field f is placed in the field hlp. The result field hlp must have type C.

Note

You can only find a help ID if the type of f has an explicit LIKE reference to a field in the ABAP Dictionary.

Example

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.

Variant 2

DESCRIBE FIELD f INTO td.

Note

This statement is for internal use only.

Incompatible changes or further developments may occur at any time without warning or notice.

Effect

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:

IDX_NAME
Component name
IDX_USER_TYPE
Name of a user-defined type, that is, a type defined using a TYPES statement. Derived types (... TYPE A-B) and structures from the &ABAP Dictionary do not count as user-defined types.
CONTEXT
Only for user-defined types: The context in which the type is defined. Possible values are defined in the constants SYDES_CONTEXT in type group SYDES. Only use these constants for comparisons. The following type contexts are recognized:

SYDES_CONTEXT-PROGRAM: Global type in a program
SYDES_CONTEXT-FORM: Local type in a FORM
SYDES_CONTEXT-FUNCTION: Local type in a FUNCTION
SYDES_CONTEXT-METHOD: METHOD-lokaler Typ
IDX_CONTEXT_NAME
Only for user-defined types:
In a local context: The name of the FORM or FUNCTION in which the type is defined. The name of the associated program is the first entry in the name table.
In a global context: The name of the program in which the type is defined.
IDX_EDIT_MASK
Conversion routine from the ABAP Dictionary corresponding to the EDIT MASK addition in the DESCRIBE statement.
IDX_HELP_ID
Help ID for fields with a reference to the ABAP Dictionary
LENGTH
Internal length, corresponding to the LENGTH addition in the DESCRIBE statement.
OUTPUT_LENGTH
Output length, corresponding to the OUTPUT-LENGTH addition in the DESCRIBE statement.
DECIMALS
Number of decimal places, corresponding to the DECIMALS addition in the DESCRIBE statement.
TYPE
ABAP type, corresponding to the TYPE addition in the DESCRIBE statement.
TABLE_KIND
For the components that represent an internal table, contains the table type . The system returns the same values as the DESCRIBE TABLE itab KIND k variant. For components that do not represent a table, the return code is set to SYDES_KIND-UNDEFINED (see also type group SYDES).

Example

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


Additional help

Determining the Attributes of Data Objects