Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Generate IDs for different tables

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:


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.
  newid = nextID + 1.

Thank you for your ideas.

Former Member

Helpful Answer

Not what you were looking for? View more on this topic or Ask a question