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: 

how to get an Unique id or something like an autoincrement ID

Former Member
0 Kudos
811

HI!

I am a SAP newbie! I want to create a database table with an unique id.

Does something like autoincrement exist?

Another Problem is that i don´t know which database will be used (sapdb, oracle, ....) so i can´t use oracle or sapDB spesific functions.

mfg markus

Message was edited by: Markus Buchner

1 ACCEPTED SOLUTION

nablan_umar
Advisor
Advisor
0 Kudos
440

You can use Number ranges for your unique key in your custom table. The good thing is it will be unique. The bad thing is you have to program it.

1. Create a custom number ranges using txn SNRO.

2. Whenever you create the record in this custom table, you need to use function module NUMBER_GET_NEXT to get the next unique number.

4 REPLIES 4

former_member183804
Active Contributor
0 Kudos
440

Hallo Markus,

Sap R/3 does not offer such a service by itself. I prefer to encapsulate of db accesses by a global class or function groups. If you need a unique key you may eigther:

  • use a GUID ( see Fuba GUID_CREATE )

  • some special logic for e.g. counters

while GUIDs guarantee uniqueness per see, they tend to be long (and no good style in sense of relational queries). Special keys might not be uniqueue on the other side. So you might need for the 2. approach the ENQUEUE technique (see ABAP online docu) to ensure this requirement along the R/3 system.

Kind Regards

Klaus

nablan_umar
Advisor
Advisor
0 Kudos
441

You can use Number ranges for your unique key in your custom table. The good thing is it will be unique. The bad thing is you have to program it.

1. Create a custom number ranges using txn SNRO.

2. Whenever you create the record in this custom table, you need to use function module NUMBER_GET_NEXT to get the next unique number.

0 Kudos
440

Hi

Nablan's proposition is the best way to provide a standard counter. However, you should be familiar to handle the procedure.

- <b>"Number Range"</b>s are objects for number assignments. To assign numbers, you need a corresponding number range object, a well maintained number range interval, and access to both of these things from within your application program (with the help of special function modules).

- Number range object maintenance is located in the development menu under other tools (transaction <b>SNRO</b>)

- There are standard capabilities that are included in number range feature

- Special functions that are used about number ranges are:

<b>NUMBER_GET_NEXT</b>: This FM is used in order to determine the next number(s) available.

<b>NUMBER_CHECK</b>: For checking external numbers to see if they lie within a number range interval that has been designated for external use.

<b>NUMBER_GET_INFO</b>: To get information about the individual number range intervals of number range objects (interval limits, current status, etc.)

You can find more information in the standard SAP course <b>"BC414 - Programming Database Updates"</b>.

*--Serdar

Former Member
0 Kudos
440

Use FM TRFC_GET_COUNTER.

It returns an upcounting number which is unique over all servers of a system.

The upper digits contain the number of seconds since 1970/01/01, the lower digits are used to guarantee uniqueness within the same second.