EDUCAÇÃO E TECNOLOGIA

improved example of how to add semantics to a SELECT

Dear community, my last blog was about how to add more semantics to a SELECT-statement. The solution presented at that time could still be improved. As a reminder, the solution from that time.

SELECT SINGLE spld AS printer, spdb AS output_immediately, spda AS delete_from_spool INTO @DATA(user_print_settings) FROM usr01 WHERE bname = @sy-uname.

In the solution above, it was already possible to see what information in the database table USR01 are important (printer settings). All without comment. The code tells the “story”.

Unfortunately, the solution didn’t make it clear what the meaning of database table USR01 is. This can be solved as follows. In addition, I’ve included a suggestion from Jacques Nomssi Nzali in the new solution: The user is now part of the USER_PRINT_SETTINGS structure – many thanks to him for his suggestion 🙂

 SELECT SINGLE user_master_data~bname AS user, user_master_data~spld AS printer, user_master_data~spdb AS output_immediately, user_master_data~spda AS delete_from_spool INTO @DATA(user_print_settings) FROM usr01 AS user_master_data WHERE bname = @sy-uname.

With this solution it’s now clear what role the database table USR01 plays. By the way, the following solution also works.

 SELECT SINGLE @sy-uname AS user, user_master_data~spld AS printer, user_master_data~spdb AS output_immediately, user_master_data~spda AS delete_from_spool INTO @DATA(user_print_settings) FROM usr01 AS user_master_data WHERE bname = @sy-uname.

Both approaches differ only from the data element in the “USER” column. In solution 1 the column is of data element “XUBNAME”, in solution 2 it’s “SYST_UNAME”.

Best regards, thanks for reading and please stay healthy

Michael