Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How does a primary key work?

Former Member
0 Kudos

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.

6 REPLIES 6

Former Member
0 Kudos

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

Former Member
0 Kudos

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!

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

0 Kudos

Hi,

Primary keys are unique fields which cannot contain any duplicate values. In the tables, the records are searched based on primary key values.

raymond_giuseppi
Active Contributor
0 Kudos

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