Skip to Content
-3

Syntax Check warning

Apr 17 at 07:33 AM

132

avatar image
 

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"

10 |10000 characters needed characters left characters exceeded

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.

0

Thanks Kiran the problem is solved :)

0
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Mike Pokraka Apr 17 at 09:07 AM
2

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.

Show 5 Share
10 |10000 characters needed characters left characters exceeded
Morning Mike,

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

0

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

0

#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.

1
Matthew Billingham

Thanks Matthew you were right I should figure out the why.

Cheers,

lyn

0

Thanks a lot Mike!!

Solved problem :)

0
Himanshu Gupta
Apr 17 at 10:12 AM
1

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

Show 3 Share
10 |10000 characters needed characters left characters exceeded

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

0

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.

0
Himanshu Gupta

Hi Himanshu,

The problem is solved thank you for your help :)

0
Horst Keller
Apr 18 at 06:47 AM
0

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."

Share
10 |10000 characters needed characters left characters exceeded