Skip to Content
avatar image
-2
Former Member

Auto generate primary key ABAP

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.
Add comment
10|10000 characters needed 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?

  • Get RSS Feed

1 Answer

  • Nov 13, 2016 at 06:18 PM

    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

    Add comment
    10|10000 characters needed characters exceeded