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 single problem

Former Member
0 Likes
1,364

Hi,

I have a problem with a select single statement:

select single * from PA0001 where pernr = wa-pernr.
if sy-subrc <> 0.
  do something
endif.

I always get the syntax error "A target error must be declared either explicity with an INTO clause or implicity with a TABLES statement."

Does anybody have an idea what the problem is?

Thanks and regards,

Martin

1 ACCEPTED SOLUTION
Read only

former_member194669
Active Contributor
0 Likes
1,168

Try this way


Tables : PA0001.
select single * from PA0001 where pernr = wa-pernr.
if sy-subrc  0.
  do something
endif.

7 REPLIES 7
Read only

former_member194669
Active Contributor
0 Likes
1,169

Try this way


Tables : PA0001.
select single * from PA0001 where pernr = wa-pernr.
if sy-subrc  0.
  do something
endif.

Read only

0 Likes
1,168

Hi Martin,

When you try to use any select statement there should be a into clause in case if your using tables declaration it would consider the table as a workarea by default and will not throw a synatx error.

Try the below logic.

Report zxyz_123.

tables: pa0001.

select single * from pa0001 where pernr = '000156784'.

if sy-subrc = 0.

endif.

cheers,

Devendran

Read only

Former Member
0 Likes
1,168

Hi ,

define work area for PA0001 with keyword Tables.

In select statement use 'INTO PA0001'.

then you can use work area PA0001 "to perform someting".

Try below code.

Tables: PA0001.

data: wa_pernr TYPE PA0001-PERNR.

parameters: p_pernr.

wa_pernr = p_pernr.

select single * from PA0001 INTO PA0001 where pernr = wa_pernr.

if sy-subrc = 0.

do something ( here you can use work are fields as per your requirement e.g. PA0001-PERNR, PA0001-SUBTY).

endif.

Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
1,168

Hi Martin Fischer,

To fetch records from DB and perform some action on it, first you need to move the records either in an internal table(for more than one records) or in a work area(for a single record.)

Use this code:-


REPORT  zxy_abc.

*--------------------Type Declaration----------------------*
TYPES : BEGIN OF it, 
        pernr TYPE pa0001-pernr,
        subty TYPE pa0001-subty,
        objps TYPE pa0001-objps,
        END OF it.
*--------------------Data Declaration----------------------*
DATA : wa_pa0001 TYPE it. "Work Area for type it
*--------------------Query---------------------------------*
START-OF-SELECTION.

SELECT SINGLE * FROM pa0001
INTO wa_pa0001
WHERE pernr = wa_pa0001-pernr.

IF sy-subrc EQ 0.
*code
*use these fields by wa_pa0001-pernr and so on..
ENDIF.

Hope this solves your problem.

Thanks & Regards.

Tarun Gambhir.

Read only

Former Member
0 Likes
1,168

Hi Martin,

Use the below query.


Tables: PA0001.
data: wa_pa0001 type pa0001.

select single * into wa_pa0001 from PA0001 where pernr = wa-pernr.
if sy-subrc  0.
  do something
endif.

Thanks,

Chidanand

Read only

Former Member
0 Likes
1,168

Hello,

Select Query is correct ;

check out with wa-pernr. Is it wa_pernr or wa-pernr. ?

Else try to use the into clause as :

SELECT SINGLE * FROM pa0001

into wrk_area

WHERE pernr = wa_pernr.

Thanks.

Read only

Former Member
0 Likes
1,168

Either use explicit work area using into clause or use the TABLES command to decalre implicit work area..