04-08-2010 5:01 PM
Hi SAP Community,
I have a issue relating to ID-generation.
I have different tables with their own primary keys/IDs e.g. zautopool-carID, zcitys-cityID..
Now, I want to write a (general) method which should generate simple IDs for all of my tables. They begin with 1 and they get incremented with 1 and so on.
So, what can you suggest me, which technology should I use, so that the ID generator is general (That means, it should be able to generate a carID, a cityID with the same code.)
I tried it this way:
Firstly I declared a Fieldsymbol <fsID>.
Then : ASSIGN ls_autopool-carid TO <fsID>
Then I wrote this method:
method GENERATE_ID.
data: lastid TYPE zmwa_id.
select count(*) <fsID> from zautopool into lastid. ### Here, I wanted to use <fsID> as a reference to ls_autopool-carid
endselect. ### My goal is that this Select-statement and the following ones can
### handle all IDs.
*Algorithm to increment LastID.
select carid
from zautopool
WHERE carid = (lastid + 1)
INTO nextID.
IF nextID = ' '.
newid = lastid + 1.
ELSE.
newid = nextID + 1.
ENDIF.
Thank you for your ideas.
04-08-2010 5:06 PM
Hi,
Better solution for your issue is generate the number range and assign the number range object to it. Everything system will take of it.
For more information about number range creation go through the below link.
http://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=50004015.
04-08-2010 5:06 PM
Hi,
Better solution for your issue is generate the number range and assign the number range object to it. Everything system will take of it.
For more information about number range creation go through the below link.
http://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=50004015.
04-08-2010 5:11 PM
Thanks but this is too much effort for a small programm.
I don't need any variable to hold the year, company or subobject etc...
Isn't there a simplier solution?
04-08-2010 5:17 PM
select * into table t_table from ztable.
describe t_table lines l_id.
l_id = l_id + 1.