SAP DESCRIBE FIELD ABAP Statements



Get Example source ABAP code based on a different SAP table
  


• DESCRIBE FIELD ABAP Statement

DESCRIBE FIELD
Short Reference

ABAP_SYNTAX
DESCRIBE FIELD dobj
$[TYPE typ $[COMPONENTS com$]$]
$[LENGTH ilen IN ${BYTE$|CHARACTER$} MODE$]
$[DECIMALS dec$]
$[OUTPUT-LENGTH olen$]
$[HELP-ID hlp$]
$[EDIT MASK mask$].

ABAP Addition
1 ... TYPE typ $[COMPONENTS com$]
2 ... LENGTH ilen IN ${BYTE$|CHARACTER$} MODE
3 ... DECIMALS dec
4 ... OUTPUT-LENGTH olen
5 ... HELP-ID hlp
6 ... EDIT MASK mask

What does it do?
This statement determines some properties of the data object dobj and assigns them to the specified target fields. The following can be specified as target fields of each addition:
Existing variables to which the return value can be converted.
Inline declarations DATA(var) or FINAL(var).
The different additions make it possible to determine the data type and the number of components for structures, the length used in the memory, the number of decimal places, the output length, the name of the data type for a reference to a data element in the ABAP Dictionary, and any conversion routines.



Latest notes:

Field symbols or formal parameters can be specified in procedures for dobj to determine the properties of the data object they represent when the statement is executed.
The statement DESCRIBE is mainly suitable for determining the properties of data objects of elementary data types. When DESCRIBE is used for structures or data objects of deep data types like strings, internal tables, or reference variables, only elementary properties can be determined. Additional information, for example, the static or dynamic type of a reference variable cannot be determined using DESCRIBE. For this kind of information, the type description classes of runtime type services ( RTTS) should be used. These enable all data object properties of all data types to be determined.
ABAP_HINT_END
• TYPE DESCRIBE FIELD
• COMPONENTS DESCRIBE FIELD

ABAP Addition

What does it do?
Determines the data type of the data object dobj. The return value is a single character ID. In an inline declaration for typ, a variable of the type c with length 1 is declared. The following tables list the assignment of return values for all possible data types. The ID is case-sensitive.
The type description classes of Runtime Type Services (RTTS) use constants with values that correspond to the internal, character-like IDs for all possible data types. These constants are defined in class CL_ABAP_TYPEDESCR and are listed in column RTTS constant . Numeric Data TypeIDRTTS constant
bbTYPEKIND_INT1
ssTYPEKIND_INT2
iITYPEKIND_INT
int88TYPEKIND_INT8
pPTYPEKIND_PACKED
decfloat16aTYPEKIND_DECFLOAT16
decfloat34eTYPEKIND_DECFLOAT34
fFTYPEKIND_FLOAT
Character-Like Data TypeIDRTTS constant
cCTYPEKIND_CHAR
nNTYPEKIND_NUM
stringgTYPEKIND_STRING
Byte-Like Data TypeIDRTTS constant
xXTYPEKIND_HEX
xstringyTYPEKIND_XSTRING
Date, Time, Time Stamp TypeIDRTTS constant
dDTYPEKIND_DATE
tTTYPEKIND_TIME
utclongpTYPEKIND_UTCLONG
Enumerated TypeIDRTTS constant
Enumerated typekTYPEKIND_ENUM
Reference TypeIDRTTS constant
Data referencelTYPEKIND_DREF
Object referencerTYPEKIND_OREF
Complex TypeIDRTTS constant
Flat structureuTYPEKIND_STRUCT1
Deep structurevTYPEKIND_STRUCT2
Internal tablehTYPEKIND_TABLE
The addition COMPONENTS determines the number of direct components of the data object dobj. The return value is of type i. For an inline declaration, a variable of type i is declared. If the data object dobj is not a structure, the value 0 is returned. If dobj is a nested structure, only the components of the highest hierarchy level are counted.



Latest notes:

If DESCRIBE FIELD is applied directly to a static box, its data type according to the above table is returned and not the internal ID j for the boxed component.
ABAP_HINT_END



Example ABAP Coding

For the deep nested structure struc1, the type ID v and three components are determined. For the flat structure struc2, the type ID u and two components are determined.
ABEXA 00219
ABAP_EXAMPLE_END
• LENGTH DESCRIBE FIELD
• IN BYTE MODE DESCRIBE FIELD
• IN CHARACTER MODE DESCRIBE FIELD

ABAP Addition

What does it do?
Determines the length used directly by the data object dobj in the memory in bytes or characters depending on the addition MODE. The return value is of type i. For an inline declaration, a variable of type i is declared.
The variant with the addition IN BYTE MODE determines the length of the data object dobj in bytes. The variant with the addition IN CHARACTER MODE determines the length of the data object dobj in characters. When using IN CHARACTER MODE, the data type of dobj must be flat and character-like. For deep data types, only IN BYTE MODE can be specified and the length of the references involved (eight bytes for each reference) is always determined.



Latest notes:

For data objects with a fixed length, the length is determined that is specified when the data object is created. The built-in function strlen can be used to determine the occupied length of character-like data objects while ignoring the trailing blanks.
In structures, the alignment gaps are part of the length. This is particularly significant in the case of alignment gaps that can occur before the end of the structure.
With enumerated objects, the addition IN BYTE MODE must be specified and the length of the actual enumerated value is determined in the basic type.
ABAP_HINT_END



Example ABAP Coding

Calculation of the bytes required for the representation of one character. The result is greater than 1 in multibyte systems.
ABEXA 00220
ABAP_EXAMPLE_END



Example ABAP Coding

The result len of the following DESCRIBE statement is 9, not 10, due to a trailing alignment gap in struct.
ABEXA 00221
ABAP_EXAMPLE_END
• DECIMALS DESCRIBE FIELD

ABAP Addition

What does it do?
Determines the number of decimal places of the data object dobj. The return value is of type i. For an inline declaration, a variable of type i is declared.



Latest notes:

Only data objects of the data type p can have decimal places. Therefore, the result in dec can differ from 0 only for these data objects.
ABAP_HINT_END



Example ABAP Coding

The system recognizes 0 decimal places and then 4 decimal places.
ABEXA 00222
ABAP_EXAMPLE_END
• OUTPUT-LENGTH DESCRIBE FIELD

ABAP Addition

What does it do?
For data objects with a fixed length, the output length of the data object dobj required for screen layouts is determined. The return value is of type i. For an inline declaration, a variable of type i is declared.
Generally, this result corresponds to the predefined output length of the data object in accordance with its data type in the output in the list buffer. In strings, olen is always set to 0. olen expects the data type i.



Latest notes:

Normally, the required output length is determined sufficiently by the specification in the table for predefined output lengths, unless the data type of the data object is defined with a reference to ABAP Dictionary and an output length or a conversion routine is specified in the corresponding domain.
If the output length defined in a dynpro for a dynpro field with the same name as dobj is shorter than the required output length, an overflow raises an uncatchable exception. When passed to the list buffer, the outputs are truncated if the output length is shorter than the required output length.
When separators or templates are defined in the user master record for the output of a data type, they are only displayed if the defined output length is sufficient. The required length can be longer than the output length determined by OUTPUT-LENGTH.
The output length for strings can be determined using the functions strlen or xstrlen.
ABAP_HINT_END



Example ABAP Coding

For date1, the output length 8 linked with the type d is determined. For date2, the output length 10 defined in the domain SYDATS is determined.
ABEXA 00223
ABAP_EXAMPLE_END
• HELP-ID DESCRIBE FIELD

ABAP Addition

What does it do?
If the data type of the data object dobj is determined by a DDIC data element, the name of the data type is assigned that was used after the addition TYPE when defining the data object dobj. The return value is a string. In an inline declaration, a variable of the type string is declared.
If the data object does not refer to a data object in the ABAP Dictionary, hlp is initialized. hlp expects a character-like data object.
If a field symbol, to which a structure component is assigned using the statement ASSIGN COMPONENT, is specified for dobj, and if the structure component refers to a component of a DDIC structure, then the complete name of the structure component is returned.



Latest notes:

The addition is called HELP-ID because the name of the data type in hlp can be used to call the field help or input help assigned in the ABAP Dictionary.
ABAP_HINT_END



Example ABAP Coding

After DESCRIBE FIELD, hlp contains the value SPFLI-CARRID. Since an input help is assigned to this component in the ABAP Dictionary, the input help can be called using the function module F4IF_FIELD_VALUE_REQUEST. If the name s_carr_id is specified after TYPE when defining carrid, hlp contains the value S_CARR_ID and can be used, for example, to call the field help using the function module HELP_OBJECT_SHOW.
ABEXA 00224
ABAP_EXAMPLE_END



Example ABAP Coding

hlp also contains the value SPFLI-CARRID after DESCRIBE FIELD in this example.
ABEXA 00225
ABAP_EXAMPLE_END
• EDIT MASK DESCRIBE FIELD

ABAP Addition

What does it do?
If a conversion routine is assigned to the data object dobj by referring to a domain in the ABAP Dictionary, the name of the conversion routine is determined and prefixed with two equal signs ==. The return value is a string. In an inline declaration, a variable of the type string is declared. If no conversion routine is assigned to the data object, mask is initialized or remains initial.



Latest notes:

If a data object mask meets these requirements, it can be used directly in the addition USING EDIT MASK of the statement WRITE $[TO$] to call the conversion routine.
ABAP_HINT_END



Example ABAP Coding

Since the data element S_FLTIME in the ABAP Dictionary is linked with the conversion routine SDURA by the domain S_DURA, msk contains the value ==SDURA after DESCRIBE FIELD and the statement WRITE TO returns the value 5:33 after the conversion from seconds to minutes.
ABEXA 00226
ABAP_EXAMPLE_END

Return to menu