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

Need Help Select Single

Former Member
0 Likes
1,051

I am making a query using sq02.

Select Single * from TSP02

where PJFINAHERR = 1.

<b>IF SY-SUBRC = 0.

myvariable = PJIDENT. 'Primary Key

ENDIF.

</b>

thats the short code.

but after testing the query it outputs multiple but same data.

it outputs:

13229

13229

13229

13229

13229

13229

13229

13229

13229

13229

and so on and so forth.

could you pls. advise?

Thank you in advance.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,019

Hi,

change the code as below by adding an else condition.

IF SY-SUBRC = 0.

myvariable = PJIDENT. 'Primary Key

ELSE.

CLEAR: myvariable.

ENDIF.

12 REPLIES 12
Read only

Former Member
0 Likes
1,020

Hi,

change the code as below by adding an else condition.

IF SY-SUBRC = 0.

myvariable = PJIDENT. 'Primary Key

ELSE.

CLEAR: myvariable.

ENDIF.

Read only

0 Likes
1,019

see demo code -

tables tsp02.

data myvariable like tsp02-pjident.

Select Single * from TSP02

where PJFINAHERR = 1.

IF SY-SUBRC = 0.

myvariable = tsp02-PJIDENT.

ENDIF.

write: myvariable.

or if u have a number of records in the table for condition 1 then code is -

tables tsp02.

data: begin of itab occurs 0,

include structure tsp02.

data end of itab.

Select * from TSP02 into table itab

where PJFINAHERR = 1.

loop at itab.

write:/ itab-PJIDENT.

endloop.

Reward points if helpfull

amit

Read only

Former Member
0 Likes
1,019

i think you are selecting that in a loop and appending your variable to itab here

PJFINAHERR field is getting only one condition i.e. 1 so it is selecting same row for loop pass.

just change the where condition.

regards

shiba dutta

Read only

Former Member
0 Likes
1,019

Thanks for the immediate replies.

Well, im used to Sql in vb or foxpro. not in abap.

Should the code select all rows having PJFINAHERR the value of 1?

Read only

Former Member
0 Likes
1,019

it is not taking all the values it is only taking the first row several times which meets the where condition so try to use differnt where condn for select single if you want to get different values.

better to use key fields in where condn...

regards

shiba dutta

Read only

Former Member
0 Likes
1,019

But it does not seem to output what i need.

What i need is to get all records from table TSP02 where the field PJFINAHERR = 1.

Should that be just

Select Single * from TSP02

Where PJFINAHERR = 1.

???

Read only

0 Likes
1,019

Use this code to fetch all the records with key field value 1,do not use select single..

see below code -

tables tsp02.

data: begin of itab occurs 0,

include structure tsp02.

data end of itab.

Select * from TSP02 into table itab

where PJFINAHERR = 1.

loop at itab.

write:/ itab-PJIDENT.

endloop.

Read only

0 Likes
1,019

Hi Gerard,

If you want all the records in the table where the value if PJFINAHERR = 1.

Then here is the code for it.

Data : it_1 type table of RSPOID. " Define the internal table

select PJIDENT 
  into table it_1
  from TSP02
  where PJFINAHERR = 1.

now your internal table it_1 will have the value of records where PJFINAHERR = 1.

Regadrs

Arun

Read only

Former Member
0 Likes
1,019

got it... but how could i output it in sq01?

Read only

0 Likes
1,019

Hi Gerard ,

I did not get what you want to do.

Regadrs

Arun

Read only

Former Member
0 Likes
1,019

Hi Arun,

Since the data i need is already in the internal table, i need to know how to display those data on screen. And since I'm using sq01. I could not use "write" can't I?

Regards,

-Vince

Read only

0 Likes
1,019

Hi Gerard ,

Here is the code which retrieves the value and displays it as output.


Data : it_1 type table of RSPOID, " Define the internal table
           v_one type RSPOID." Work Area

select PJIDENT  " Select Data
  into table it_1
  from TSP02
  where PJFINAHERR = 1  .

loop at it_1 into v_one .
 Write v_one.     " Print the data
endloop.

Regards

Arun

  • Assign Points if reply is helpful