DESCRIBE FIELD

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

Additions:
1. ... LENGTH len
2. ... TYPE type
3. ... TYPE type COMPONENTS n
4. ... OUTPUT-LENGTH len
5. ... DECIMALS n
6. ... EDIT MASK mask
7. ... HELP-ID hlp

Effect

The internal length of field f is placed in field len. The value of len has type I.

Example

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

Result: LEN contains the value 8.

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

As well as the data types you can specify in the DATA statement (C, N and so on), there are further data types that originate from Dictionary references or object generation. These data types, which are also returned by the DESCRIBE statement, have the following type identification codes:

h Internal table

s 2 byte integer with sign

b 1 byte integer without sign

u Structure without internal table

v Structure containing at least one internal table

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

Effect

The same as ... TYPE type, but u or v is returned in type for structures, and the number of components in the structure is returned 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. " Equivalent is type = 'u' or type = 'v' 
	PERFORM TEST USING <F>. 
	ELSE. 
	PERFORM DO_SOMETHING USING <F>. 
	ENDIF. 
  ENDDO. 
ENDFORM.

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

Example

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

Result: O_LEN has the value 8.

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

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:

TABLES SBOOK. 
DATA: CONV_EXIT(10). 
DESCRIBE FIELD SBOOK-CUSTOMID EDIT MASK CONV_EXIT. 
IF CONV_EXIT <> SPACE. ... ENDIF.

Result: CONV_EXIT contains the value "==ALPHA".

Effect

The help ID (F1-Hilfe) 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.

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>, <G2>. 
 
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 following help IDs are output:

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.


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

PROGRAM : Global type in a program
FORM : Local type in a FORM
FUNCTION: Local type in a FUNCTION

IDX_CONTEXT_NAME Only for user-defined types:
In a local context: The name of the FORM or AB>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.

Example

Suppose the complex data type EMPLOYEE_STRUC is defined as follows:

PROGRAM DESCTEST. 
 
TABLES: SBOOK. 
 
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 ABSENCE_TIME_STRUC OCCURS 5, 
		 PHONE(20)			TYPE N OCCURS 3, 
	 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 thatthe 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