‎2008 Sep 04 11:55 AM
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??
‎2008 Sep 04 1:47 PM
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?
‎2008 Sep 04 11:59 AM
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
‎2008 Sep 04 12:03 PM
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
‎2008 Sep 04 12:06 PM
With out writing the code it is not possible to do that functionality.
‎2008 Sep 04 12:14 PM
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.
‎2008 Sep 04 12:28 PM
‎2008 Sep 04 1:17 PM
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.
‎2008 Sep 04 1:47 PM
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?
‎2008 Sep 04 2:00 PM
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
‎2008 Sep 04 2:05 PM
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.
‎2008 Sep 04 2:51 PM
Hi...
Why can't you go foe client specific table i.e. MANDT as only key field.
--Naveen.I
‎2008 Sep 04 3:20 PM
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
‎2008 Sep 04 6:01 PM
‎2008 Sep 04 8:02 PM
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.
‎2008 Sep 05 5:15 AM
thanx, that sounds like a great option. I ll check it out and get back okies.
‎2008 Sep 05 5:59 AM
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