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: 

Select Query

Former Member
0 Kudos
195

Hi all,

Program reads ESTMJ table to find the specification linked to the material. However, multiple specifications might be linked with the material. The specification number should be output to the file based upon the specification type. In order to output specification number, we check whether the specification type is REAL_SUB or ZPURCH_SUB

The select statements have been developed in this manner :

SELECT matnr bismt

INTO t_outtab FROM mara

WHERE lvorm IN s_lvorm

AND kzumw IN s_kzumw

AND mtart IN s_mtart .

*--- Retrieve 'RECNROOT' given the material number

CLEAR : w_recnroot.

SELECT SINGLE recnroot INTO w_recnroot

FROM estmj

WHERE matnr = t_outtab-matnr

AND delflg = space.

IF sy-subrc EQ 0.

*--- Retrieve the specification number

SELECT SINGLE subid INTO t_outtab-subid

FROM estrh

WHERE recnroot =

w_recnroot

AND delflg = space.

I changed the code for third query as in following manner :

SELECT SINGLE subid INTO t_outtab-subid

FROM estrh

WHERE recnroot = w_recnroot

AND ( subcat = 'REAL_SUB' or subcat =

'ZPURCH_SUB' )

AND delflg = space.

Can anyone suggest me whether what I have done is correct or wrong ?

Regards,

Varun.

Message was edited by: varun sonu

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
107

That last SELECT looks ok to me.



SELECT SINGLE subid INTO t_outtab-subid
FROM estrh
WHERE recnroot = w_recnroot
      AND ( subcat = 'REAL_SUB' 
         or subcat = 'ZPURCH_SUB' )
            AND delflg = space.

if sy-subrc <> 0.
* Then don't add to the file
Endif.



Regards,

Rich Heilman

3 REPLIES 3

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
108

That last SELECT looks ok to me.



SELECT SINGLE subid INTO t_outtab-subid
FROM estrh
WHERE recnroot = w_recnroot
      AND ( subcat = 'REAL_SUB' 
         or subcat = 'ZPURCH_SUB' )
            AND delflg = space.

if sy-subrc <> 0.
* Then don't add to the file
Endif.



Regards,

Rich Heilman

Former Member
0 Kudos
107

Hi Varun,

You can change the 3rd select like this & check.But your select looks good..

SELECT SINGLE subid INTO t_outtab-subid

FROM estrh

WHERE recnroot = w_recnroot

AND subcat in ('REAL_SUB' , 'ZPURCH_SUB')

AND delflg = space.

Former Member
0 Kudos
107

Hi Varun,

It seems good. but one suggestion, try to select the query based on RECN instead RECNROOT. Always it is better to retrieve query on Key values to increase performance and integrity purpose.

shylesh