Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Help with counter id SAP ABAP

0 Kudos
266

I need to increase ID users everytime when i will write into database but i dont know how to do it.

3 REPLIES 3

cdprasanna
Active Participant
0 Kudos
144

Hi,

Best is to use snro .

If you are not interested in snro then fetch latest userid from DB table and then increment by one and save the next record.

GK817
Active Contributor
0 Kudos
144

Hi,

In your code, you are increasing the counter after appending the value to LT_USER. Move 'gv_a = gv_a + 1' code line to 2 lines above, before you assign gv_a to ls_user-user_id.

Else, get the latest record from DB and increment and then put it to DB as suggested by Prasanna above.

GK

former_member1716
Active Contributor
0 Kudos
144

Hello Floso Klim,

You Can follow the below Code:

ls_user-first_name = meno.
ls_user-last_name  = priez.
ls_user-school     = school.

SELECT MAX( user_id )
INTO @DATA(ls_latest_user)
FROM z04_users.

IF sy-subrc EQ 0.
  ls_user-user_id = ls_latest_user + 1.
ELSE.
  ls_user-user_id = 1.
ENDIF.

APPEND ls_user TO lt_user.

MODIFY z04_users FROM lt_user.