04-17-2018 8:33 AM
Hi all,
I was updating tcode to add two more field to filter. The code shows below run fine but I got a syntax check warning says condition for the key field "MJAHR" does not test for equality. Bit strange I didn't use that field. Could anyone please give me a hand to explain why this happened?
Thanks a lot!
Regards,
Lynn
Clear lv_mseg_lgort.
Select single lgort Into lv_mseg_lgort
From mseg
Where mblnr = ls_output-refbn and
zeile = ls_output-refbz.
If sy-subrc = 0.
ls_output-lgort = lv_mseg_lgort.
Else.
ls_output-lgort = ''.
Endif.
"Syntax check warning
This warning is only displayed in SLIN
In "SELECT SINGLE ...", the WHERE condition for the key field "MJAHR" does not
test for equality. Therefore, the single record in question is possibly not
unique.
Internal Message Code: MESSAGE GSB"
04-17-2018 10:07 AM
It's telling you that technically it's possible to have multiple entries with the same MBLNR in the database, each belonging to a different MJAHR. Combined with SELECT SINGLE, it's telling you that you're just going to get a random result if this is the case.
Only if you add MJAHR, you're guaranteed to get exactly the record you want.
04-17-2018 9:59 AM
Lynn,
Use MJAHR also in the where clause.That will satisfy the primary key requirement and at the same time result will be consistent.
K.Kiran.
04-17-2018 10:07 AM
It's telling you that technically it's possible to have multiple entries with the same MBLNR in the database, each belonging to a different MJAHR. Combined with SELECT SINGLE, it's telling you that you're just going to get a random result if this is the case.
Only if you add MJAHR, you're guaranteed to get exactly the record you want.
04-18-2018 1:24 AM
Thank you for your reply.
The system suggest use #EC but shows "Unknown column name "#EC" " .
Is there anything like this #etc I can use rather than add MJAHR ?
Cheers,
Lynn
04-18-2018 7:14 AM
Hi Lynn,
#EC.. comments are pseudocomments, special comments to provide additional info to the compiler. They are deprecated, but the checks still show them. Most have been replaced by pragmas
Here it presumably suggests #EC WARN_OK which tells the check to suppress the warning because you know what you're doing. The equivalent statement with a pragma would be:
select single blah from tab where foo = bar ##warn_ok.
But it's still best practice to supply the full key if possible, it's better for performance too.
Regards,
Mike
04-18-2018 7:27 AM
#EC should be entered as an inline comment.
Select single lgort Into lv_mseg_lgort " #EC ...
From mseg
Where mblnr = ls_output-refbn and
zeile = ls_output-refbz.
BUT you should figure out how you can use MJAHR. Otherwise you could end up selecting
MJAHR = 2018 MBLNR = 123456789012 ZEILE = 1
instead of
MJAHR = 2017 MBLNR = 123456789012 ZEILE = 1
You should only suppress these warnings where you know that they don't apply. You should also comment why they don't apply.
Remember the goal is not have ATC/SLIN give your program a clean bill of health, with no warnings or errors, the goal is to have error free code. ATC/SLIN is warning you of a potentially serious error - i.e. you'll select the wrong record, because you're not using MJAHR.
04-18-2018 7:28 AM
07-12-2018 7:01 AM
Thanks Matthew you were right I should figure out the why.
Cheers,
lyn
04-17-2018 11:12 AM
Hi Lynn,
Select single is usually to get the unique row from table , i.e to pass the complete key.
when key is partially , Extended check will show an error as it might pick up random row .
You can get the more information at
https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/abapselect_single.htm
To solve the problem , You can either pass the complete key in where clause or you can use select upto 1 rows
04-18-2018 1:23 AM
Hi Himanshu,
Thank you for your reply. The problem is the key MJAHR value are different in somehow in the tables. The system suggest use #EC but shows "Unknown column name "#EC" " .
Is there anything like this #etc I can use ?
Thanks
Lynn
04-18-2018 4:40 AM
can you please show the code that you have used to for #EC and also the Extendend check screenshot showing which #EC to be used.
04-18-2018 7:29 AM
04-18-2018 3:56 AM
04-18-2018 7:47 AM
https://blogs.sap.com/2015/03/11/selecting-one-line-from-an-database-table/
"The syntax documents the semantics of your statement in the program and the extended program check warns you, if you do not specify the full key."