简体   繁体   中英

How to create two compound foreign keys in ABAP

I got three tables. user tag and user_tag . The primary of user is iduser + client , the one of tag is idtag + client . Now I want to create foreign keys for the table user_tag for those two primary keys without having client twice in there.

How can I do that? How is it displayed in the Entry help/check (there is only one origin for the input available, and client has two origins)?

Here the example:

client|idtag     client|iduser
-------------    -------------
  1   |  1         1   |  3   
  1   |  2         1   |  4  
  2   |  1         2   |  3    

Possible values for my new table:

client|idtag|iduser
--------------------
  1   |  1  |  3
  1   |  1  |  4    
  1   |  2  |  3 
  1   |  2  |  4  
  2   |  1  |  3    

Now in my checktable I want to have checked my keys are in that table. If I do not check the client, I would have more possibilities I do not want (not consistent):

client|idtag|iduser
--------------------
  2   |  1  |  4    
  2   |  2  |  3 
  2   |  2  |  4  

Just think about the CLIENT (or MANDT ) like of something that is implicit and like it did not exist and simply define your foreign key as IDTAG, IDUSER as if you were doing that for a database like MySQL or Postgres.

I do not know what your requirements are but there is always a possibility to define transparent tables in SAP to be not client dependent but this is rather unlikely for application data and is rather used for cross-client configuration.

Just to explain it from another perspective: When you login in SAP your login is client specific.

When you write a select like

SELECT * FROM USER.
...
ENDSELECT.

you get only entries with the actual client. The system restrict the selection explicit on the actual client.

If you want a client independent selection you must use the addition CLIENT SPECIFIC in your select statement.

In other words: Under normal circumstances there is no mixture of data from different clients. So there is also no problem if your user_tag has only one client key.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM