07-13-2012 10:27 PM
Hello everyone.
I understand Oracle PL/SQL and Transact SQL, I'm starting to learn ABAP but I would like to know how does a primary key work in a table dictionary, I mean, how to create a sequence (Oracle) or Identity (SQL Server), is this necesary? I've been searching in google but I notice everybody just declare a column as a Primary Key and nothing else.
Thank you in advance.
07-14-2012 1:10 PM
Hi ,
If I am getting your question properly , then follwing info will be usefull for you.
As we create sequence in Oracle there is a same concept in Abap data dictionary i.e NUMBER RANGES.
It is often necessary to directly access individual records in a data structure. This is done using unique keys. Number ranges are used to assign numbers to individual database records for a commercial object, to complete the key. Such numbers are e.g. order numbers or material master numbers.
These numbers provide, apart from unique identification of a data record, the possibility of encoding differentiating information for an object. One could tell from the number e.g., to which material type a material belongs.
The R/3 number range management also monitors the number status, so that numbers which have already been issued are not re-issued.
All dialogs, database accesses or other activities which are necessary for the maintenance of number range objects and number ranges and number allocation in user developments, can be performed using SAP function modules.
For detail information access link below and see Number ranges section in that.
http://help.sap.com/saphelp_47x200/helpdata/EN/2a/f9ff44493111d182b70000e829fbfe/frameset.htm
Thanks
Santosh
08-02-2012 1:24 PM
Hi,
In simple words, primary keys are fields that are unique. it is very much necessary, it helps in uniquely identifying every record in a table (i.e., process them in specific sequence)
For example.. Social Security Number can be a primary key, as you know, two person cannot have same Social Security Number.<It is Unique>
In case you want to fetch a particular person's record with his name, it wud be difficult as there could be more than one having same name. in tat case, if you kno the primary key of that table, in our case- which is the social security number. it would be easy to process or access the exactly needed record.
Hope this helps!
08-02-2012 2:57 PM
Hi Ivan,
As more simply,
if you need to enter the mark of your class student( student name : ivan,james,martin,james )in a table
ivan 20 40 50
james 40 50 60
martin 60 70 80
james 40 60 70
if you want to fetch james mark how come in above since we have 2 james ?????? so that we will insert a registration number as other column like
001 ivan 20 40 50
002 james 40 50 60
003 martin 60 70 80
004 james 40 60 70
hope you understand
08-02-2012 8:52 PM
Hello everyone.
I'm a little bit shamed because my question was not enough explanatory, I mean:
how does a primary key work in ABAP?
is it needed when I create a Transparent - Pooled table?
what about identity (in SQL Server) or sequence (in Oracle)? (this questions was answered in the second post)
Should I use NUMBER RANGES?
how long should be this range?
should I use NUMBER_GET_NEXT instead of use NUMBER RANGES?
how does this work in an internal table?
Thank you all for your answers.
08-13-2012 7:36 PM
Hi,
Primary keys are unique fields which cannot contain any duplicate values. In the tables, the records are searched based on primary key values.
08-14-2012 7:18 AM
Primary key are defined in SQL as an UNIQUE constraint with NOT NULL columns.
Only one set of primary keys is allowed on one table.
There are ABAP tools to create unique set of keys :
- Number ranges (Function group SNR3 with FMs like NUMBER_GET_NEXT)
- UUIDs (Class CL_SYSTEM_UUID)
Regards,
Raymond