Hello experts,
In a loop, I have the following stupid code, I'd like to merge the 2 lines "ADD 1 TO d" and "struc2-fldate = d" (I used a date, but my question is valid for numeric types too) :
DATA struc2 type sflight. DATA itab2 type table of sflight. DATA(d) = sy-datum. SELECT * FROM spfli INTO table @data(itab). LOOP AT itab INTO data(struc). move-corresponding struc to struc2.
ADD 1 TO d. struc2-fldate = d.
APPEND struc2 TO itab2. ENDLOOP.
The only solution I could find is to develop a method LCL_APP=>INC so that to do the following code:
struc2-fldate = lcl_app=>inc( CHANGING counter = d ).
The method is defined as follows:
CLASS lcl_app DEFINITION. PUBLIC SECTION. CLASS-METHODS inc CHANGING var TYPE any RETURNING VALUE(counter) TYPE decfloat34. ENDCLASS." CLASS lcl_app IMPLEMENTATION. METHOD inc. ADD 1 TO var. counter = var. ENDMETHOD." ENDCLASS."
Is there a simpler way?
Thanks!
The obstacles fort introducing such "a small function" in old ABAP are rather high (name clashes). I asked for those already but without success. 😔
We don't have replacement for i++ in ABAP so your way with the method seems to be only if you'd like to get rid of one line.
But maybe this is something for Dev team of SAP to add such small but useful function ?
I know using MACRO is kind of old style and should be avoided, but in such cases I wouldn't have problem to use it.
In my previous company with had a bunch of macros for our framework and actually it made life easier. That could be also an option.
Peter
Add a comment