This is a test message to test the length of the message box.
Login
ABAP obsolete add
Created by Software-Heroes

ABAP Obsolete - Add

791

In today's article, we'll look at the obsolete language element Add, how the replacement looks like and what we like or dislike about it.



The language element of today's article is mainly found in many old programs in the system and should therefore not cause you too much headache. It comes in a very simple form to add a value to a variable ...


" old element
ADD 1 TO ld_num.

" new element
ld_num = ld_num   1.

... and in the more complex version that we want to discuss today.

 

Preparation

As a preparation, we take the example from the documentation of the object (more in the link at the end of the article) and create a structure that we fill. The example of the SAP documentation makes it easier to describe, but we first define the types, then create the variables and fill them.


" Types
TYPES:
  tv_num TYPE p LENGTH 8 DECIMALS 0,

  BEGIN OF ts_numbers,
    one   TYPE tv_num,
    two   TYPE tv_num,
    three TYPE tv_num,
    four  TYPE tv_num,
    five  TYPE tv_num,
  END OF ts_numbers.

" Variables
DATA:
  ls_numbers TYPE ts_numbers,
  ld_sum     TYPE i.
FIELD-SYMBOLS:
  < ld_num > TYPE tv_num.

" Initial values
ls_numbers = VALUE #( one = 10 two = 20 three = 30 four = 40 five = 50 ).

In the example from the official documentation, the fields that follow each other and have the same type are added together. In the OO context, however, this type of definition is no longer possible and also prohibited. The documentation also refers to a similar function with which we can achieve the same effect.

 

Execution

Unlike the original command, you have to do some more programming and coding to add. Although this contradicts the idea of the commands introduced so far, but it does make the function much clearer.

We loop the structure as often as defined in p_cnt. We start with the first element and add up all the values.


DO p_cnt TIMES.
  DATA(ld_idx) = sy-index - 1.

  ASSIGN ls_numbers-one INCREMENT ld_idx TO < ld_num > RANGE ls_numbers.
  IF sy-subrc = 0.
    ld_sum = ld_sum   < ld_num >.
  ENDIF.
ENDDO.

 

The Assign starts with the field "one" and index 0 from the range of the structure. We also want to include the first field in our addition and should not increase the index here.

 

Conclusion

Not every new language element is necessarily easier, to create the source code, but the new language elements make it easier for foreign developers to understand. In any case, with our little tip, you are well prepared if you should replace such a construct in an old program.

 

Source:
ABAP Documentation Add-Until


Included topics:
ObsoleteAdd
Comments (0)



And further ...

Are you satisfied with the content of the article? We post new content in the ABAP area every Friday and irregularly in all other areas. Take a look at our tools and apps, we provide them free of charge.


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 - Ranges and Headers

Category - ABAP

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.

06/12/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