Application Development and Automation 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: 
Read only

Composite Primary Key

Former Member
0 Likes
4,447

Hello Experts,

I am good and expect the same from you guys..

<b>Kindly let me know the tables in sap which are using composite primary key..</b>

Thanks and Regards

Santosh

7 REPLIES 7
Read only

Former Member
0 Likes
1,791

Can you explain a bit further?

There is no concept called composite primary key sap afaik.

REgards,

Ravi

Read only

0 Likes
1,791

Hi Ravi,

To day i have attended an interview..

Interviewer asked me what the composite primary key.. I replied if a key is consists more than one field then it is called as composite primary key..

Then he asked me can u giv me some examples of tables which are having composite primary keys??

<b>I would like to know the tables which are using composite primary keys</b>

Thanks and Regards

Read only

0 Likes
1,791

Hi there. If that is what you consider a composite primary key, then the infotype tables (PA0001, etc.) would be a good example of tables with this type of key. Their keys include the fields of PERNR, BEGDA, and ENDDA, among other fields. I hope this helps.

- April King

Read only

0 Likes
1,791

well, there are lots...EKPO, VBAP, LFB1, KNB1, STKO, STPO, etc...

Read only

Former Member
0 Likes
1,791

Hai,

There are many tables in SAP with composite key as below.

SPFLI,SFLIGHT,SBOOK,KNA1,VBAK,VBAP etc...

If you want all the tables:

You can follow the below logic:

DATA:

BEGIN OF FS_TABLES,

TABNAME TYPE DD02L-TABNAME,

END OF FS_TABLES.

DATA:

T_TABLES LIKE STANDARD TABLE OF FS_TABLES,

T_FINAL LIKE STANDARD TABLE OF FS_TABLES.

SELECT TABNAME

FROM DD02L

INTO TABLE T_TABLES.

LOOP AT T_TABLES INTO FS_TABLES.

FOR EACH TABLE COUNT THE NO OF KEYS.

(DD03L CONTAINS THE FIELD NAME,TABLE NAME,KEYFLAG = 'X'X IF IT IS A KEY FLAG)

IF KEYS GT 1.

IT IS A TABLE WITH COMPOSITE PRIMARY KEY(STORE IN FINAL ITAB->T_FINAL )

T_FINAL-TABNAME = TABNAME.

APPEND FS_FINAL TO T_FINAL.

ENDIF.

ENDLOOP.

All the tables that you want will be in T_FINAL internal table.

Hope you grt all the tables.

<b>Reward points if it helps you.</b>

Regds,

Rama chary.Pammi

Read only

Former Member
0 Likes
1,791

Hi,

Actually composite primary key comes in to the picture when one key is not able to serve as a primary key for the table. In that case 2 key fields clubt to gether act as a primary key for the table..

like EKPO, VBAP, LFB1, KNB1

Do reward points if it helps .

Thx,

sofia

Read only

Former Member
0 Likes
1,791

Hi Santosh....

In SAP almost all the tables are having the composite primary key. Because in a client dependent table the primary key a combination of MANDT and Other fields..

I will give you some examples..

tables with out composite primary key : T000.

tables with composite primary key : MARA, MARC, VBAK, VBAP.........

Let me know if u have any more doubt....

Reward points if useful......

Suresh......