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

Dictionary..Autoincrementing field

lijisusan_mathews
Active Contributor
0 Likes
1,985

is there a way to add a field in a table, which is an auto incrementing field. ie. the value of that field should be populated automatically whenever i add a new line. and i need to set this field as the primary key of the table, so it has to autoincrement itself. is there way to do that in se11 itself at table level design, instead of writing code??

1 ACCEPTED SOLUTION
Read only

lijisusan_mathews
Active Contributor
0 Likes
1,932

isnt there a provision in ORACLE to add an auto incrementing primary key field. So is that provision unavailable in SAP system which uses ORACLE as the backend?

15 REPLIES 15
Read only

Former Member
0 Likes
1,932

No suzie, it is not possible to write a code in the table itself, but what you can do is always get the largest number available and add one to it whenever you insert new line.

Regards,

C.A

Read only

naveen_inuganti2
Active Contributor
0 Likes
1,932

Hi....

Get back with your exact reuirement.

What is the functionality of that field..

We can solve this in another way if you provide some extra information on this.

Thanks,

Naveen.I

Read only

Former Member
0 Likes
1,932

With out writing the code it is not possible to do that functionality.

Read only

Former Member
0 Likes
1,932

Hi Dude,

U can do that by using EXITS(user EXITS).

Find the exact ENHANCEMENT COMPONENT and write Ur Increment Code in That.

Hope this Helps U.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,932

Such a possibility does certainly not not exist (yet), otherwise why does everyone use number ranges and programming,

Regards

Read only

Former Member
0 Likes
1,932

Hi,

Go to the transaction SNRO and create a number range object.

Fine the enhance ment (User exit) when inserting records into the table and in that exit call the FM NUMBER_GET_NEXT to get automatic increment next number.

To create Number range Object:

See below procedure.

1. Go to transaction SNRO (Simple way to remember is SapNumberRangeObject).

2. Enter the number range object name and press CREATE.

3. Enter the description, Long text and Number Length domain and Warning %.

Warning% à Assume that an interval is defined from 1 to 1000. If you want to issue a warning at the number 900, enter 10 (%) here.

4. Press SAVE. You would get a prompt. Press YES and assign the object to a local class.

5. Now click on u201CNumber Rangesu201D button on the application toolbar.

6. Click on u201CChange Intervalsu201D.

7. Click on u201CInsert Intervalu201D.

8. Enter the values as shown below: Click u201CInsertu201D and then SAVE. The number range object is generated.

Testing the Number Range Object:

We can use the function module, NUMBER_GET_NEXT, to get the next number of any number range object.

Following is a test program to get the next available number of the object created above:

REPORT zsnro_test.

DATA:

NUMBER TYPE I.

CALL FUNCTION 'NUMBER_GET_NEXT'

EXPORTING

nr_range_nr = '01'

object = 'ZDEMO'

IMPORTING

NUMBER = NUMBER

EXCEPTIONS

INTERVAL_NOT_FOUND = 1

NUMBER_RANGE_NOT_INTERN = 2

OBJECT_NOT_FOUND = 3

QUANTITY_IS_0 = 4

QUANTITY_IS_NOT_1 = 5

INTERVAL_OVERFLOW = 6

BUFFER_OVERFLOW = 7

OTHERS = 8

.

IF sy-subrc 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Write 😕 'Next available number is: ', Number.

Hope this helps you.

Regards,

Rama.

Read only

lijisusan_mathews
Active Contributor
0 Likes
1,933

isnt there a provision in ORACLE to add an auto incrementing primary key field. So is that provision unavailable in SAP system which uses ORACLE as the backend?

Read only

0 Likes
1,932

Hi.. Suize...

Iam not sure about that ORACLE techniue, But we can do most of the things with ABAP...

But in your case.., it will be a long procedure and may effects others...,

See this.. solution...

1. Create TMG for table,

2. Goto that TMG screen's PAI event,

3. Enhance the code for SAVE button,

4. Also make the field as input not possible.

But i dont think you are having this reuirement reuires this much of time spending..,

Thanks,

Naveen.I

Read only

0 Likes
1,932

My exact requirement is:

I need to create a table in which all data that is processed during a transaction is to be stored, or rather 'logged'. So many or all fields can be repetitive. ie., i need a table without any key fields and that allows duplication.But in a table, i have to specify atleast 1 primary key. So 1 resort i thought of is to introduce a new field, say index in the DB, which will simply be a number ( like the serial number of latest record ) and add that record as the primary key. But users will not enter values into that field. If i have to insert values into that field using code, i will have to take the count of records, or any other logic that involves writing some query from this table. But this table contains crores of records. So if this logic is done for every new entry, performance issues can arise right. So i want to have a table level solution

i hope my requirement is clear.

Read only

0 Likes
1,932

Hi...

Why can't you go foe client specific table i.e. MANDT as only key field.

--Naveen.I

Read only

0 Likes
1,932

Your requirement is clear, but ABAP simply does not provide an option for this at table level. You must go with either number ranges (i.e. fm NUMBER_GET_NEXT) or with a SELECT MAX incrementing the key by 1 for new insertions. The latter is probably faster, but problems may arise if concurrent updations are done so you should have locking issues into account. While with the first option you ensure you'll get a unique key for each calling.

Edited by: Alejandro Bindi on Sep 4, 2008 11:27 AM

Read only

0 Likes
1,932

Create two key fields (and the client)

- MANDT first key, implicit

- key TYPE timestampl as second key

Then perform a

DO.
  GET TIME STAMP FIELD table-key.
  INSERT table.
  IF sy-subrc EQ 0.
    EXIT.
  ENDIF.
ENDDO.

Regards

Read only

0 Likes
1,932

Good alternative Raymond, i've missed that one. In theory however it could also present duplicated key problems when used simultaneously from different programs updating the same table. If that's not the case, i would go with this option.

Read only

0 Likes
1,932

thanx, that sounds like a great option. I ll check it out and get back okies.

Read only

Former Member
0 Likes
1,932

Hi,

I think your requirement is to mark the number of records......

However, auto increment of field in the Data Dictonary is not possible.....You will have to do the same in your code before you add the record to the database table.....

You can do the same using the Number Range object....

Regards,

Kunjal