03-18-2009 2:54 PM
I do an extented check for a program, at part Superfluous Statements i saw some messages that say 'Select statement has an empty body', for example these select statements:
SELECT ddtext INTO dd07t-ddtext
FROM dd07t
WHERE domname LIKE 'CO_WRTTP'
AND ddlanguage = 'EN'
AND valpos = p_valu.
SELECT post1 INTO w_post1
FROM proj WHERE pspid = w_project.
ENDSELECT.
SELECT posnr
INTO w_posnr
FROM impr
WHERE posid = st_linerec-imposid
AND gjahr >= p_year.
ENDSELECT.
These select statements have a body obviously but why it says they have an empty body? and how to fix it? Thanks.
03-18-2009 2:56 PM
Hi,
You are not doing anything within the SELECT ...ENDSELECT..block..
To fix it use UP TO 1 ROWS.
SELECT post1 INTO w_post1
UP TO 1 ROWS " New code
FROM proj WHERE pspid = w_project.
ENDSELECT.
SELECT posnr
INTO w_posnr
UP TO 1 ROWS " New code
FROM impr
WHERE posid = st_linerec-imposid
AND gjahr >= p_year.
ENDSELECT.
Thanks
Naren
03-18-2009 2:56 PM
Hi,
You are not doing anything within the SELECT ...ENDSELECT..block..
To fix it use UP TO 1 ROWS.
SELECT post1 INTO w_post1
UP TO 1 ROWS " New code
FROM proj WHERE pspid = w_project.
ENDSELECT.
SELECT posnr
INTO w_posnr
UP TO 1 ROWS " New code
FROM impr
WHERE posid = st_linerec-imposid
AND gjahr >= p_year.
ENDSELECT.
Thanks
Naren
03-18-2009 3:04 PM
Hello Naren,
I was also thinking on the same lines. But did a bit of coding & checked in my case the below coding doesnot give any SLIN messages.
DATA:
V_BWKEY TYPE BWKEY,
V_BUKRS TYPE BUKRS.
DATA:
BEGIN OF ITAB OCCURS 0,
BWKEY TYPE BWKEY,
END OF ITAB.
SELECT BWKEY INTO V_BWKEY
FROM T001K
WHERE BUKRS = V_BUKRS.
ENDSELECT.
Can you please clarify?
@OP: Can you please share a bit more of your code, may that can help.
BR,
Suhas
03-18-2009 3:10 PM
Thanks Naren, it's good now. But can you explain why adding UP TO 1 ROWS make a difference while the old code without it still run normally?
03-18-2009 4:05 PM
SELECT post1 INTO w_post1
FROM proj WHERE pspid = w_project.
ENDSELECT.
If the table PROJ had several entries where PSPID was the same as W_PROJECT, then you'd end up fetching all those records from the database. Which would be an unnecessary action, because w_post1 would only contain the value you last fetched.
SELECT... UP TO 1 ROWS returns just the first record that matches then leaves the loop.
You could just as simply use:
SELECT SINGLE post1 INTO w_post1 FROM proj WHERE pspid = w_project.
matt
03-18-2009 4:09 PM
03-18-2009 3:01 PM
Hi Trangie,
Check the type declarations of dd07t-ddtext, w_post1, w_posnr.
w_post1, w_posnr must be declared as field strings and dd07t-ddtext must be a internal table.
Syntax of Select:
select <field-names>
into table <itab-name>
from <dbtab name>.
where <conditions>.
select <field-names>
into <field string name>
from <dbtab name>.
where <conditions>.
endselect.
Regards,
Swapna.
03-18-2009 4:03 PM
Hi Suhas Saha -> Actually I am getting an extended message for your code also.
Hi trangie -> If you use UP TO 1 rows it is actually selecting one record but in your first case...there possibly be more than record as it is not a key field of the table...eventhough actually the table will have only one row...
Hope this helps..
Thanks
Naren
03-18-2009 4:44 PM
I just want to point out (like Matt and Narendran) that
SELECT post1 INTO w_post1
FROM proj WHERE pspid = w_project.
ENDSELECT.
returns post1 for the last row found, whereas
SELECT post1 INTO w_post1
UP TO 1 ROWS
FROM proj WHERE pspid = w_project
ENDSELECT.
returns post1 for the first row found, which might cause a different behaviour during runtime.
Thomas