Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Syntax Check warning

Former Member
0 Likes
6,057

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"

1 ACCEPTED SOLUTION
Read only

pokrakam
Active Contributor
4,095

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.

13 REPLIES 13
Read only

kiran_k8
Active Contributor
0 Likes
4,095

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.

Read only

pokrakam
Active Contributor
4,096

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.

Read only

Former Member
0 Likes
4,095
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

Read only

pokrakam
Active Contributor
0 Likes
4,095

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

Read only

matt
Active Contributor
4,095

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

Read only

Former Member
0 Likes
4,095

Thanks a lot Mike!!

Solved problem 🙂

Read only

Former Member
0 Likes
4,095

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

Cheers,

lyn

Read only

former_member564522
Active Participant
4,095

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

Read only

0 Likes
4,095

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

Read only

0 Likes
4,095

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.

Read only

0 Likes
4,095

Hi Himanshu,

The problem is solved thank you for your help 🙂

Read only

Former Member
0 Likes
4,095

Thanks Kiran the problem is solved 🙂

Read only

retired_member
Product and Topic Expert
Product and Topic Expert
0 Likes
4,095

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