Application Development and Automation 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: 
Read only

select

Former Member
0 Likes
765

hi,

may i know if i just want to check if the entry is exist (not to get the data from database table), say ekko,

can i write as below? i must use select? i must have if statement to check sy-subrc?

select single * where ebeln = wa_pono and

ebelp = wa_poitem.

if sy-subrc = 0

perform found.

else.

perform not found.

endif.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
738

Yes, you must use select. But you can also minmize the data retreival by specifying a field.

data: wa_ebeln type ekko-ebeln.

clear wa_ebeln.
select single ebeln into wa_ebeln
         where ebeln = wa_pono and 
                   ebelp = wa_poitem.
if sy-subrc = 0
perform found.
else.
perform not found.
endif.

Regards,

Rich Heilman

7 REPLIES 7
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
739

Yes, you must use select. But you can also minmize the data retreival by specifying a field.

data: wa_ebeln type ekko-ebeln.

clear wa_ebeln.
select single ebeln into wa_ebeln
         where ebeln = wa_pono and 
                   ebelp = wa_poitem.
if sy-subrc = 0
perform found.
else.
perform not found.
endif.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
738

Hi Eliana,

You can also use the 'Select count(*)' variant which does not need you to retrieve any field.

Karthik

Read only

Former Member
0 Likes
738

Hi,

you can use the select *

select single

for ex:

TABLES SPFLI.

SELECT * FROM SPFLI

WHERE

CITYFROM = 'FRANKFURT' AND

CITYTO = 'NEW YORK'.

WRITE: / SPFLI-CARRID, SPFLI-CONNID.

ENDSELECT.

for ex:

TABLES SFLIGHT.

DATA SEATSFREE TYPE I.

SELECT SINGLE * FROM SFLIGHT

WHERE

CARRID = 'LH ' AND

CONNID = '0400' AND

FLDATE = '19950228'.

SEATSFREE = SFLIGHT-SEATSMAX - SFLIGHT-SEATSOCC.

WRITE: / SFLIGHT-CARRID, SFLIGHT-CONNID,

SFLIGHT-FLDATE, SEATSFREE.

you can use following return code in your program

SY-SUBRC = 0 At least one line was read.

SY_SUBRC = 4 No lines were read.

SY-SUBRC = 8 The search key was not fully qualified.

*******please reward points if the information is helpful to you*************

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
738

Hi,

In select statement, you need to specify the database table name.

data v_ebeln type ebeln.

select single ebeln into v_ebeln from <b>EKBE</b> where ebeln = wa_pono and

ebelp = wa_poitem.

if sy-subrc = 0

perform found.

else.

perform not found.

endif.

Read only

Former Member
0 Likes
738

hi

your query should have DB table name.

select single * from ekpo where ebeln = wa_pono and

ebelp = wa_poitem.

if sy-subrc = 0

perform found.

else.

perform not found.

endif.

reward if useful.

Read only

Former Member
0 Likes
738

Hi Elina,

Your view is correct but you should modify your coding.

select single * where ebeln = wa_pono and ebelp = wa_poitem.

if sy-subrc = 0

perform found.

else.

perform notfound.

endif.

form found.

Write: 'The record is found'.

endform.

form notfound.

Write: 'The record is not found'.

endform.

IF HELPFULL REWARD

Read only

Former Member
0 Likes
738

hi.

refer this code.

data: it_ebeln type ekko-ebeln.

clear it_ebeln.

select single ebeln into it_ebeln

where ebeln = it_ebeln-pono and

ebelp = it_ebeln-poitem.

if sy-subrc = 0

perform found.

else.

perform not found.

endif.

Reward all helpfull answers.

Regards.

Jay