Application Development and Automation 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: 
Read only

Auto generate primary key ABAP

Former Member
0 Likes
1,773

I'm trying to make auto creation of primary keys. My code works when you don't leave the screen. But when you exit then go back to the screen, the primary key resets. Are there any other ways of doing this?

SELECT MAX( PUNUM ) FROM Z032_PURCHASE_DB 
     INTO CORRESPONDING FIELDS OF wa_PURCH.

      PO_NUM = wa_PURCH-PUNUM + 1.

I'm trying to make auto creation of primary keys. My code works when you don't leave the screen. But when you exit then go back to the screen, the primary key resets. Are there any other ways of doing this?

SELECT MAX( PUNUM ) FROM Z032_PURCHASE_DB 
     INTO CORRESPONDING FIELDS OF wa_PURCH.

      PO_NUM = wa_PURCH-PUNUM + 1.
2 REPLIES 2
Read only

Sandra_Rossi
Active Contributor
0 Likes
1,000

What does mean "primary key resets"? Your issue is not related to your code (just do a debug and you'll see your SELECT works as expected). I think it's only a problem in your screen logic. In fact, your whole question is unclear. Could you please reformulate?

Read only

nomssi
Active Contributor
1,000

I presume you are trying to create new entries in a custom table. Make sure you understand LUW and why you should encapsulate the database write/update in a update function module. Learn about number ranges (or here). cf. Transaction SNRO. You should call function module NUMBER_GET_NEXT in you update function module and not in the flow logic of a screen.

Hope this helps,

JNN