Skip to Content
-2

Auto generate primary key ABAP

Nov 12, 2016 at 10:08 PM

103

avatar image

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.
10 |10000 characters needed characters left characters exceeded

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?

0
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Jacques Nomssi Nov 13, 2016 at 06:18 PM
1

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

Share
10 |10000 characters needed characters left characters exceeded