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: 

Combining Select Query

Former Member
0 Kudos

Hi All,

Please tell me how to combine the following 2 select queries:

SELECT SINGLE konda

FROM vbkd

INTO v_konda

WHERE vbeln EQ v_vbelv.

SELECT SINGLE traty

FROM vbkd

INTO wa_output-out_code

WHERE vbeln EQ v_vbelv

AND posnr EQ v_posnr.

in order to access VBKD table only once.(here wa_output is a work area)

Thanks,

Neethu.

7 REPLIES 7

former_member181962
Active Contributor
0 Kudos
SELECT SINGLE konda  traty
FROM vbkd 
INTO ( v_konda, wa_output-out_code )
WHERE vbeln EQ v_vbelv AND posnr EQ v_posnr.

0 Kudos

Hi,

But, for the first select query I dont need the condition posnr EQ v_posnr.

Please tell how to do this.

Thanks,

Neethu

0 Kudos

Hi,

Then its not possible... as both have different conditional records, so you will have to write two different queries ...

Tell me are you writing these two queries inside the loop..... or it gets executed only once...

if its once then you will have to write it separately...

if its in a loop then give the code will try to minimize hits to db table.

Regards,

Siddarth

0 Kudos

Hi,

I hope there is no other option for your requirement.

Because the requirements are having distinct meaning.

So you have to write two SELECT statements.

But you can try like the following:

SELECT SINGLE konda traty FROM vbkd

INTO ( v_konda, wa_output-out_code )

WHERE vbeln EQ v_vbelv AND posnr EQ v_posnr.

if sy-subrc ne 0.

SELECT SINGLE konda FROM vbkd

INTO v_konda WHERE vbeln EQ v_vbelv.

endif.

Thanks and Best Regards,

Suresh

Former Member
0 Kudos

HI,

Check this code..

SELECT SINGLE konda traty 
FROM vbkd 
INTO ( v_konda  ,  wa_output-out_code )
WHERE vbeln EQ v_vbelv 
AND posnr EQ v_posnr.

Former Member
0 Kudos

Hi Neethu,

Check this,

SELECT SINGLE vbelv posnr konda traty

FROM vbkd

INTO TABLE it_vbkd

WHERE vbeln EQ v_vbelv.

READ TABLE it_vbkd WITH KEY posnr EQ v_posnr.

Hope this information is help to you.

Regards,

José

0 Kudos

this may work....can you check with this...

SELECT SINGLE akonda btraty

FROM vbkd as a,vbkd as b

INTO ( v_konda, wa_output-out_code )

WHERE a~vbeln EQ v_vbelv

AND b~posnr EQ v_posnr.

AND avbeln = bvbeln