ABAP Keyword Documentation → ABAP - Reference → Processing Internal Data → Attributes of Data Objects → DESCRIBE
DESCRIBE FIELD
Other versions: 7.31 | 7.40 | 7.54
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].
Extras
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
Effect
This statement determines several properties of the data object dobj
and
assigns them to the specified variables. The various additions enable you 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 ABAP Dictionary, and a possible conversion routine.
Notes
-
You can specify field symbols or formal parameters in
procedures for
dobj
to determine the properties of the data object they represent when the statement is executed. -
The statement
DESCRIBE
is used to determine the properties of data objects of elementary data types. WhenDESCRIBE
is used for structures or data objects of deep data types like strings, internal tables, or reference variables, you can only determine elementary properties. Further details, for example, the static or dynamic type of a reference variable cannot be determined usingDESCRIBE
. For this kind of information, you can use the type classes of Run Time Type Services (RTTS). They enable you to determine all properties of data objects of all data types.
Addition 1
... TYPE typ [COMPONENTS com]
Effect
Determines the data type of the data object dobj
and assigns a corresponding
one-digit ID to the data object typ
, which expects a character-likedata type.
The following tables list the assignment of return codes for all possible data types. The ID is case-sensitive.
Numeric Data Type | ID |
---|---|
b |
b |
s |
s |
i |
I |
p |
P |
decfloat16 |
a |
decfloat34 |
e |
f |
F |
Character-Like Data Type | ID |
---|---|
c |
c (exception, refer to note below) |
string |
g |
n |
N |
d |
D |
t |
T |
Byte-Like Data Type | ID |
---|---|
x |
X |
xstring |
y |
Reference Type | ID |
---|---|
Data reference | l |
Object reference | r |
Complex Type | ID |
---|---|
Flat structure | u (exception, refer to note below) |
Deep structure | v (exception, refer to note below) |
Internal table | h |
The addition COMPONENTS
assigns the number of direct components of the data
object dobj
to the data object com
. com
expects the data type i
. 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.
Notes
-
If you do not use the addition
COMPONENTS
, the additionTYPE
in non-Unicode programs returns the value "C" instead of "u" or "v" for any structures. -
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.
Example
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.
DATA: BEGIN OF struc1,
comp1 TYPE c LENGTH 1,
comp2 TYPE string,
BEGIN OF struc2,
comp1 TYPE c LENGTH 1,
comp2 TYPE i,
END OF struc2,
END OF struc1,
typ1 TYPE c LENGTH 1,
comp1 TYPE i,
typ2 TYPE c LENGTH 1,
comp2 TYPE i.
DESCRIBE FIELD: struc1 TYPE typ1 COMPONENTS comp1,
struc1-struc2 TYPE typ2 COMPONENTS comp2.
Addition 2
... LENGTH ilen IN {BYTE|CHARACTER} MODE
Effect
The length directly used by the data object dobj
in the memory is determined
in bytes or characters depending on the addition MODE
and is assigned to
the data object ilen
. ilen
expects the data type i
.
You must specify the addition MODE
in
Unicode programs. 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, you can only
specify IN BYTE MODE
. This always determines the length of the references involved (8 bytes for each reference).
In non-Unicode programs,
LENGTH
can be used without the addition MODE
. In this case, the addition IN BYTE MODE
is used implicitly.
Note
For data objects with a fixed length, the length is determined that is specified when the data object is created. To determine the used length of character-like data objects without counting the trailing spaces, you can use the
predefined function strlen
.
Example
Calculation of bytes required for the represenation of one character. The result is greater than 1 in multi-byte systems.
DATA: text TYPE c LENGTH 1,
blen TYPE i,
clen TYPE i,
bytes TYPE i.
DESCRIBE FIELD text LENGTH blen IN BYTE MODE.
DESCRIBE FIELD text LENGTH clen IN CHARACTER MODE.
bytes = blen / clen.
Addition 3
... DECIMALS dec
Effect
The number of decimalplaces
of the data object dobj
is determined and assigned to the data object dec
. dec
expects the data type i
.
Note
Only data objects of the data type p
can have decimal places. Therefore, the result in dec
can be different from 0 only for these data objects.
Addition 4
... OUTPUT-LENGTH olen
Effect
For data objects with a fixed length, the output length required for
screen layouts of the data object
dobj
is determined and assigned to the data object olen
.
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
.
Notes
- Normally, the required output length is specified adequately by the entry in the table for predefined output lengths. This is not the case when 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.
-
When the output length defined in a screen of a
screen field with the
identical name of
dobj
is shorter than the required output length, an exception that cannot be handled is triggered in the case of overflows. 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 provided 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
orxstrlen
.
Example
For date1
, the output length 8 associated with the type d
is determined. For date2
, the output length 10 defined in the domain SYDATS is determined.
DATA: date1 TYPE d,
date2 TYPE sy-datum,
olen1 TYPE i,
olen2 TYPE i.
DESCRIBE FIELD date1 OUTPUT-LENGTH olen1.
DESCRIBE FIELD date2 OUTPUT-LENGTH olen2.
Addition 5
... HELP-ID hlp
Effect
If the data type of the data object dobj
is determined by a data element
in ABAP Dictionary, the name of the data type is assigned to the field hlp
.
It is the name that was used after the addition TYPE
when defining the data
object dobj
. If the data object does not refer to a data object in ABAP Dictionary,
hlp
is initialized. hlp
expects a character-like data object.
If a field symbol is specified for dobj
, a data object is assigned to this
field symbol using the statement ASSIGN COMPONENT
, and the data object refers
to a component of a structure in ABAP Dictionary. The complete name of the structure component is returned.
Note
The addition is called HELP-ID
because the name of the data type in
hlp can be used for the display of the field help or input help assigned in ABAP Dictionary.
Example
After DESCRIBE FIELD
, hlp
contains the value "SPFLI-CARRID".
Since an input help is assigned to this component in ABAP Dictionary, the input help can be displayed
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 display the field help using the function module HELP_OBJECT_SHOW.
DATA: carrid TYPE spfli-carrid,
hlp TYPE string,
struc TYPE dfies-tabname,
comp TYPE dfies-fieldname.
DESCRIBE FIELD carrid HELP-ID hlp.
SPLIT hlp AT '-' INTO struc comp.
CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'
EXPORTING
tabname = struc
fieldname = comp
EXCEPTIONS
field_not_found = 1
no_help_for_field = 2
inconsistent_help = 3
no_values_found = 4
OTHERS = 5.
Addition 6
... EDIT MASK mask
Effect
If a conversion routine is assigned to the data object dobj
by referring
to a domain in ABAP Dictionary, two equals signs "==" precede the name of the conversion routine and
the result is assigned to the data object mask
. If no conversion routine
is assigned to the data object, mask
is initialized. mask
expects a character-like data object.
Note
If a data object mask
meets these requirements, you can use it directly in
the addition USING EDIT MASK
of the statement WRITE
to call the conversion routine.
Example
Since the data element S_FLTIME is associated with the conversion routine
SDURA by the domain S_DURA, msk
contains the value "==SDURA" after
DESCRIBE FIELD and the statement WRITE
returns the value "5:33" after the conversion from seconds to minutes.
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.