Application Development 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: 

Superfluous Statements: Select statement has an empty body.

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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

8 REPLIES 8

Former Member
0 Kudos

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

0 Kudos

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

0 Kudos

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?

matt
Active Contributor
0 Kudos
 
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

0 Kudos

thanks Naren and Matt, the question is solved.

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

ThomasZloch
Active Contributor
0 Kudos

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