This is a test message to test the length of the message box.
Login
ABAP Obsolete Ranges and Headers
Created by Software-Heroes

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.

Advertising

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.


Included topics:
ObsoleteRANGEOCCURSWITH HEADER LINE
Comments (0)
Advertising

ABAP - Naming conventions

Category - ABAP

How important is it nowadays to adhere to naming conventions or even to use naming conventions in the modern ABAP environment? We want to look at that in this article.

04/09/2021

ABAP - Use INSERT

Category - ABAP

APPEND already has a long history in ABAP, but this will play less and less of a role in the future. We'll show you why.

12/11/2020

ABAP Obsolete - Assignment and calculation

Category - ABAP

How does it actually work with the assignments and the calculation in ABAP? Here you will find out the current language constructs and what you should avoid.

06/26/2020

ABAP Obsolete - DESCRIBE

Category - ABAP

Again we have for you a most used ABAP term for which there is already a new alternative, this time not just one alternative.

11/15/2019

ABAP Obsolete - TYPE-POOL

Category - ABAP

Type pools are obsolete, but the use continues. How best to deal with it in the future, you will find out here today.

08/23/2019