The DESCRIBE keyword in ABAP Language is used to get what an object looks like. You can use this keyword statment to specify a lot of properties of a data object at runtime. The variant of DESCRIBE is listed below:
- DESCRIBE FIELD (Field properties)
- DESCRIBE TABLE (Properties of an interal table)
- DESCRIBE DISTANCE (Distance between of two fields)
- DESCRIBE LIST (Properties of lists in list buffer)
Do take care of one thing:
"The statement DESCRIBE is basically used to specify the properties of data objects of elementary data types. If DESCRIBE is used for structures or data objects of deeper data types like strings, internal tables, or reference variables, only elementary properties can be specified. Additional information, for example, the static or dynamic type of a reference variable cannot be determined by DESCRIBE. For this information, you must use the type classes of the Run Time Type Services(RTTS), which allow the specification all properties of data objects of all data types. Since the functions of the RTTS type classes comprise the complete functions of the DESCRIBE statement, the system classes can be used instead of the statement." By SAP Help
DESCRIBE FIELD dobj
[TYPE typ [COMPONENTS com]]
[LENGTH ilen IN {BYTE|CHARACTER} MODE]
[DECIMALS dec]
[OUTPUT-LENGTH olen]
[HELP-ID hlp]
[EDIT MASK mask].
- [TYPE typ [COMPONENTS com]] is used to specify the elementary type of a data object , you can get a one char identification. The addition tells you how many direct components are there in the data object.
- [LENGTH ilen IN {BYTE|CHARACTER} MODE] is used to specify how many characters(capacity, not actual chars number) in bytes or characters MODE are there in the data objects.
- [DECIMALS dec] The number of decimal places of the data object.
- [OUTPUT-LENGTH olen] is used to to specify the output length on the screen of a data object . For string, the result is always 0.
- [HELP-ID hlp] is used to specify the reference table and component of an elementary data ojbect. The result is a struc-comp like char string. You can spilt it into 2 data, and use ‘F4IF_FIELD_VALUE_REQUEST’ function to call f4 help screen.
- [EDIT MASK mask] is used to specify the edit mask of a data object. This can be used to write a number as time format.
DESCRIBE TABLE itab [KIND knd] [LINES lin] [OCCURS n].
- [KIND knd] is used to specify the table kind, which is one of T(Standard) S(Sorted) H(Hashed).
- [LINES lin] is used to specify the line count of an internal table.
- [OCCURS n] is used to specify the initial size of an internal table.
DESCRIBE DISTANCE BETWEEN dobj1 AND dobj2 INTO dst IN {BYTE|CHARACTER} MODE.
- This is used to specify the distance of two component’s start position in one structure in byte or character MODE.
DESCRIBE LIST DESCRIBE LIST { {NUMBER OF {LINES|PAGES} n}
| {LINE linno PAGE page}
| {PAGE pagno page_properties} }
[INDEX idx].
page_properties:
… [LINE-SIZE width]
[LINE-COUNT length]
[LINES lines]
[FIRST-LINE first_line]
[TOP-LINES top_lines]
[TITLE-LINES title_lines]
[HEAD-LINES header_lines]
[END-LINES footer_lines] … .
This statment is used to get the attributes of list buffer, these attributes can be defined on the top of a program.
Here is some demo code attached:
DESCRIBE FIELD
*————————————————————*
* Demo code for describe field statement by www.imlex.net *
*————————————————————*
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,
COMP3(10) TYPE P DECIMALS 2,
COMP4 TYPE SY-DATUM,
COMP5 TYPE S_FLTIME,
END OF STRUC1,
TYP1 TYPE C LENGTH 1,
COMP1 TYPE I,
TYP2 TYPE C LENGTH 1,
COMP2 TYPE I,
LEN1 TYPE I,
LEN2 TYPE I,
DECM TYPE I,
OUTL TYPE I,
HLPD(30) TYPE C,
MASK TYPE STRING.
DESCRIBE FIELD: STRUC1 TYPE TYP1 COMPONENTS COMP1,
STRUC1-STRUC2 TYPE TYP2 COMPONENTS COMP2.
DESCRIBE FIELD: STRUC1-COMP1 LENGTH LEN1 IN BYTE MODE,
STRUC1-COMP1 LENGTH LEN2 IN CHARACTER MODE.
DESCRIBE FIELD: STRUC1-COMP3 DECIMALS DECM,
STRUC1-COMP3 OUTPUT-LENGTH OUTL.
DESCRIBE FIELD: STRUC1-COMP4 HELP-ID HLPD,
STRUC1-COMP5 EDIT MASK MASK.
*————————————————————*
* End of demo code for describe field statement. *
*————————————————————*
DESCRIBE TABLE & DESCRIBE DISTANCE
*————————————————————*
* Demo code for describe table statement by www.imlex.net *
*————————————————————*
TYPES: BEGIN OF X_ITAB,
FIELD1 TYPE I,
FIELD2(6) TYPE C,
FIELD3(10) TYPE P DECIMALS 2,
END OF X_ITAB.
DATA: T_ITAB TYPE STANDARD TABLE OF X_ITAB INITIAL SIZE 20 WITH HEADER LINE.
DATA: KND TYPE C,
LINE TYPE I,
ONN TYPE I,
DIS1 TYPE I,
DIS2 TYPE I.
DESCRIBE TABLE T_ITAB KIND KND LINES LINE OCCURS ONN.
DESCRIBE DISTANCE BETWEEN:
T_ITAB-FIELD1 AND T_ITAB-FIELD3 INTO DIS1 IN BYTE MODE,
T_ITAB-FIELD1 AND T_ITAB-FIELD3 INTO DIS2 IN CHARACTER MODE.
*NOTES: You can only use describe distance statment on a structure
* or table header line. A type or a no header table doesn’t work.
*————————————————————*
* End of demo code for describe table statement. *
*————————————————————*
DESCRIBE LIST