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: 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.