cancel
Showing results for 
Search instead for 
Did you mean: 

how to write this

Former Member
0 Kudos
49

hi, I want to write

select single * from...

select single * from...

If one of above mentioned can be reached, then have following steps...

thx, kitty

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi kitty

select single * from...

value = sy-subrc.

select single * from....

value1 = sy-subrc.

...

...

if value = 0 or value1 = 0 .....

<your select statemnt>

endif.

regards

kishore

Former Member
0 Kudos

Hi, I have below coding

select single * from vbfa where vbeln = vbrp-vgbel

and posnn = vbrp-vgpos

and vbtyp_n = vbrp-vgtyp.

select single * from vbfa where vbelv = vbrp-vgbel

and posnv = vbrp-vgpos

and vbtyp_v = vbrp-vgtyp.

if sy-subrc = 0.

select single bstkd from vbkd into z_ponr where vbeln = vbfa-vbelv

and posnr = '000000'.

now if both select can fetch data, it will only select one bstkd, I want to select two.

thx kitty

former_member188685
Active Contributor
0 Kudos
select single * from vbfa where vbeln = vbrp-vgbel
and posnn = vbrp-vgpos
and vbtyp_n = vbrp-vgtyp.
if sy-subrc = 0.
select single bstkd from vbkd into <b>z_ponr</b> where vbeln = vbfa-vbelv
and posnr = '000000'.
endif.
select single * from vbfa where vbelv = vbrp-vgbel
and posnv = vbrp-vgpos
and vbtyp_v = vbrp-vgtyp.
if sy-subrc = 0.
select single bstkd from vbkd into<b> z_ponr1</b> where vbeln = vbfa-vbelv
and posnr = '000000'.
endif.

now it will get both...

Regards

Vijay

Former Member
0 Kudos

Hi again,

1. u will have to use

another variable(structure)

See BOLD

2.

<b> data : myvbfa like vbfa.</b>

select single * from vbfa where vbeln = vbrp-vgbel

and posnn = vbrp-vgpos

and vbtyp_n = vbrp-vgtyp.

select single * from vbfa

<b>into myvbfa</b>

where vbelv = vbrp-vgbel

and posnv = vbrp-vgpos

and vbtyp_v = vbrp-vgtyp.

if sy-subrc = 0.

select single bstkd from vbkd into z_ponr

where ( vbeln = vbfa-vbelv <b>or vbeln = myvbfa-vbelv )</b>

and posnr = '000000'.

regards,

amit m.

former_member188685
Active Contributor
0 Kudos

Hi ,

if you use two structure in that case also you will get only one BSTKD, since here it is <b>select single</b> and <b>or</b> condition. so you will get one record. but if you select directly after the first select and second select into two variable you will get two BSTKD values. see my reply.

Regards

Vijay

Former Member
0 Kudos

THANKS A LOT!

IT WORKS NOW.

have a nice day!

kitty

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

Refer Tcode abapdocu -> Open Sql-> Read Data.

Refer this link:

http://www.sap-img.com/abap/difference-between-select-single-and-select-upto-one-rows.htm

Regards,

Gayathri

Former Member
0 Kudos

Hi Kitty,

You can code like this.

data: v_flg_go type c.

select single * from table1 where <conditions>

if sy-subrc = 0.

v_flg_go = 'X'.

endif.

if v_flg_go is initial.

select single * from table2 where <conditions>

if sy-subrc = 0.

v_flg_go = 'X'.

endif.

endif.

if v_flg_go = 'X'.

<i>further processing code</i>

endif.

Regards,

Raj

former_member188685
Active Contributor
0 Kudos

Hi,

select single * 
       from MARA 
       into x_mara
 where matnr = p_matnr.
if sy-subrc = 0.
select single * marc into x_marc where <condn>

if sy-subrc = 0.

endif.
endif.

please make your requirement clear

regards

Vijay

Former Member
0 Kudos

HI kiity

what is your requirement?

select single * from table will fetch the first record from the database.

regards

kishore

Former Member
0 Kudos

Hi Kirshore,

I will have two select single * from table, sometimes may first fetch data, sometimes may second fetch data, or may likely both can fetch data, if one of three happened, I will fetch another data. I don't know how to write.

thx a lot kitty

Former Member
0 Kudos

Hi kitty,

1. u can use this kind of logic.

2. data : sub1 type sy-subrc,

sub2 type sy-subrc,

sub3 type sy-subrc.

select singel *

sub1 = sy-subrc.

select singel *

sub2 = sy-subrc.

select singel *

sub3 = sy-subrc.

*----


if sub1 = 0 or sub2 = 0 or sub3 = 0.

select * from .....................

endif.

regards,

amit m.

suresh_datti
Active Contributor
0 Kudos

Hi Kitty,

You can check the sy-subrc after each select & set a flag to true if either of the return codes is 0. You can then go for the other data fetch if the flag is true.

Regards,

Suresh Datti