2

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  
inetphantom
  • 2,498
  • 4
  • 38
  • 61
  • Not sure if I fully grasp what you mean but client has only one origin which is the current client your program is executed on so there is no need to have it twice. This is not a field you'd normally set manually. – andrecito Sep 18 '15 at 07:48
  • @andreas so I it is without doing anything avoided that I could add a key not available under the specific client? – inetphantom Sep 18 '15 at 08:22
  • Why do you want to avoid having the client in two foreign keys in the fist place? It belongs there to enforce referential integrity in a multi-client environment. – vwegert Sep 18 '15 at 08:57
  • @vwegert I want to have him in both tables. I add an example uf my understanding of the situation. – inetphantom Sep 18 '15 at 10:08
  • Then what exactly is your problem? Just build the tables as shown above. – vwegert Sep 18 '15 at 11:43

2 Answers2

1

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.

Jagger
  • 10,350
  • 9
  • 51
  • 93
  • So the environment checks for me that I do not have those cases as shown in my added example and I can just ignore it? – inetphantom Sep 18 '15 at 10:27
  • I am not sure but you mean by "environment checks". In SAP even if you define check table the foreign keys are not propagated to the database anyway. So if in the client 1 you do the following insert `DATA: ls_rel TYPE zrel. zrel-idtag = 1. zrel-iduser = 5. INSERT zrel FROM ls_rel.` where the user with number 5 does not exist in the user table, you will not receive any exception at all and the record will be inserted into the database anyway and it has nothing to do with the client in such a case. Try it by ys! You have to take care of consistency checks by yourself on the app server level. – Jagger Sep 18 '15 at 11:21
1

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.

knut
  • 27,320
  • 6
  • 84
  • 112