ABAP Obsolete - Ranges and Headers
Generate a decent range for an interface? Tables with or without header lines? We show you what is still possible and what you should rather be.
Table of contents
Today's article is about some statements that have to do with internal tables. That is why we have summarized the different variants in one article. You will still find these functions in many older SAP reports and functions, but you should not use them for yourself.
WITH HEADER LINE
Together with the table, the addition creates a header line that can be addressed under the same name. This saves the INTO addition for the loop, INSERT and some other statements, but for a transfer you must explicitly refer to the table by adding a "[]" at the end.
In the example, the loop and the transfer:
DATA:
lt_bkpf TYPE STANDARD TABLE OF bkpf WITH HEADER LINE.
LOOP AT lt_bkpf.
" Do Something
ENDLOOP.
lo_app->main( lt_bkpf[] ).
This way should no longer be used because the header line is not directly visible and could only confuse other developers in modern development who do not know the construct. To ensure that the table and structure are clearly separated from each other, a line is also explicitly declared. In the meantime, the inline declaration can also be used.
DATA:
lt_bkpf TYPE STANDARD TABLE OF bkpf.
LOOP AT lt_bkpf INTO DATA(ls_bkpf).
" Do Something
ENDLOOP.
lo_app->main( lt_bkpf ).
RANGES
Do you need a range for selection, as an interface parameter or for transfer in a data object? With the TYPE addition you can create a table of the type Range in the modern ABAP language. The table does not have a header line, as is the case with a table defined with RANGES.
RANGES:
lt_r_company_code FOR t001-bukrs.
DATA:
lt_r_company_code TYPE RANGE OF t001-bukrs.
If you want to convert the result of the selection directly into a range, you can also do this directly in the SELECT and inline declaration. To do this, create and set the fields for SIGN and OPTION in the statement, then adopt the result in LOW and HIGH. This is an easy, quick way and saves the conversion in an additional loop.
SELECT 'I' AS sign, 'EQ' AS option, bukrs AS low, bukrs AS high
FROM t001
INTO TABLE @DATA(lt_r_company_code).
OCCURS
The statement creates a table and allocates a number of lines in memory, even if it does not yet contain 10 lines, as mentioned in the example. This command should no longer be used because the definition does not show exactly what is being created. Neither the type of table is known nor a key has been defined. In our example, we also omitted the key for clarity.
DATA:
lt_bkpf LIKE t001 OCCURS 10.
DATA:
lt_bkpf TYPE STANDARD TABLE OF t001.
Conclusion
Even in the more modern OO context, many of the old commands for definition no longer work. We want to give you a few innovations in all areas for a clean programming style.