Integer increment

Sometimes ABAP drives me crazy for very simple tasks like incrementing an integer in a loop ...

Here is my attempt:

METHOD test.

  DATA lv_id TYPE integer.

  lv_id = 1.

  LOOP AT x ASSIGNING <y>.
    lv_id = lv_id+1.
  ENDLOOP.

ENDMETHOD.

As a result, an error message appears. Field type "I" does not allow access to subfields.

+5
source share
5 answers

Do you mean:

ADD 1 to lv_id.

By the way, when you iterate over an internal table, SY-TABIX has a loop counter.

+12
source

You yourself answered the question, but to make things a little clearer:

variable + 1 

is an arithmetic expression - add 1 to the value of the variable.

variable+1

- operation of shifting a character variable. For example, if the variable contains ABC, variable+1- BC.

NUMC. , variable = '4711', variable + 1 4712, variable+1 - '711' ( ).

, , , .

+17

Wow, I get it. These are spaces f ****** ...

lv_id = lv_id + 1

works...

+5
source

Plain

DATA: gv_inc type I.

put this statement in a loop

gv_inc = gv_inc + 1.

+1
source

If you are going to increase each cycle of the cycle, you can directly get the size of the table.

describe table x lines data(lv_id). "Out side of the loop.
0
source

All Articles