Attributes of SAP ABAP Data Objects can be determined at Runtime. The following attributes can be determined at runtime.
FIELD LENGTH
DATA TYPE
OUTPUT LENGTH
DECIMAL PLACES
CONVERSION ROUTINE
DISTANCE BETWEEN TWO FIELDS
HELP TEXT ID
DATA TYPE
OUTPUT LENGTH
DECIMAL PLACES
CONVERSION ROUTINE
DISTANCE BETWEEN TWO FIELDS
HELP TEXT ID
The statement used for determining the attributes of a field is DESCRIBE. We have seen earlier how we can use DESCRIBE to find attributes of a internal Table. See the post on Internal Table Basics.
Please find below the Syntax used to determine the attributes of SAP ABAP Data Objects at runtime.
DESCRIBE FIELD <field> [LENGTH <l>] [TYPE <t> [COMPONENTS <n>]]
[OUTPUT-LENGTH <o>] [DECIMALS <d>]
[EDIT MASK <m>] [HELP-ID <h>].
[OUTPUT-LENGTH <o>] [DECIMALS <d>]
[EDIT MASK <m>] [HELP-ID <h>].
Finding the Data Type at runtime.
Syntax
DESCRIBE FIELD <field> TYPE <t>.
Once the above statement is executed the type of the field <field> is obtained in the variable <t>.
Example.
REPORT ZEX_ATTRIBUTES .
Data: d_intiger type i,
d_float type f,
d_packed type p,
d_character type c,
d_date type d,
d_numc type n,
d_time type t,
d_hexa type x,
d_type type c.
DESCRIBE FIELD d_intiger type d_type.
Write:/ 'd_intiger', d_type.
DESCRIBE FIELD d_float type d_type.
Write:/ 'd_float', d_type.
DESCRIBE FIELD d_packed type d_type.
Write:/ 'd_packed', d_type.
DESCRIBE FIELD d_character type d_type.
Write:/ 'd_character', d_type.
DESCRIBE FIELD d_date type d_type.
Write:/ 'd_date', d_type.
DESCRIBE FIELD d_numc type d_type.
Write:/ 'd_numc', d_type.
DESCRIBE FIELD d_time type d_type.
Write:/ 'd_time', d_type.
DESCRIBE FIELD d_hexa type d_type.
Write:/ 'd_hexa', d_type.
Data: d_intiger type i,
d_float type f,
d_packed type p,
d_character type c,
d_date type d,
d_numc type n,
d_time type t,
d_hexa type x,
d_type type c.
DESCRIBE FIELD d_intiger type d_type.
Write:/ 'd_intiger', d_type.
DESCRIBE FIELD d_float type d_type.
Write:/ 'd_float', d_type.
DESCRIBE FIELD d_packed type d_type.
Write:/ 'd_packed', d_type.
DESCRIBE FIELD d_character type d_type.
Write:/ 'd_character', d_type.
DESCRIBE FIELD d_date type d_type.
Write:/ 'd_date', d_type.
DESCRIBE FIELD d_numc type d_type.
Write:/ 'd_numc', d_type.
DESCRIBE FIELD d_time type d_type.
Write:/ 'd_time', d_type.
DESCRIBE FIELD d_hexa type d_type.
Write:/ 'd_hexa', d_type.
Finding Attributes of a field
d_intiger I
d_float F
d_packed P
d_character C
d_date D
d_numc N
d_time T
d_hexa X
d_intiger I
d_float F
d_packed P
d_character C
d_date D
d_numc N
d_time T
d_hexa X
Finding the Length at Runtime.
Syntax
DESCRIBE FIELD <field> LENGTH <l>.
The length of the filed <field> is obtained in <l>.
Example.
REPORT ZEX_ATTRIBUTES1 .
Data: d_char(8) type c,
d_len type i.
move 'TEXT' to d_char.
DESCRIBE FIELD d_char LENGTH d_len.
Write:/ d_char, 'Length', d_len.
d_len type i.
move 'TEXT' to d_char.
DESCRIBE FIELD d_char LENGTH d_len.
Write:/ d_char, 'Length', d_len.
Finding the attributes length
TEXT Length 8
TEXT Length 8
Finding the Conversion Routine at Runtime.
Syntax
DESCRIBE FIELD <f> EDIT MASK <m>.
We have seen earlier how a CONVERSION ROUTINE works in SAP. We will now see an example of finding out the conversion routine at runtime. As we have seen earlier the Domain AUART has a conversion routine AUART. We will now determine this by using the example given below.
REPORT ZEX_ATTRIBUTES_CONVERSIONR .
data: d_ord like vbak-auart,
d_mask(10).
DESCRIBE FIELD d_ord EDIT MASK d_mask.
Write:/ d_mask.
d_mask(10).
DESCRIBE FIELD d_ord EDIT MASK d_mask.
Write:/ d_mask.
The output of this program is as follows.
Finding the conversion Routine
==AUART
==AUART
You can also use field symbols if you do not know a certain data type at runtime. As an SAP ABAP Developer for 10 years, I always recommend my team to use field symbols wherever possible.
ReplyDelete