‎2007 Jan 04 6:26 AM
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.
‎2007 Jan 04 6:28 AM
Hi,
change the code as below by adding an else condition.
IF SY-SUBRC = 0.
myvariable = PJIDENT. 'Primary Key
ELSE.
CLEAR: myvariable.
ENDIF.
‎2007 Jan 04 6:28 AM
Hi,
change the code as below by adding an else condition.
IF SY-SUBRC = 0.
myvariable = PJIDENT. 'Primary Key
ELSE.
CLEAR: myvariable.
ENDIF.
‎2007 Jan 04 6:43 AM
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
‎2007 Jan 04 6:34 AM
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
‎2007 Jan 04 6:42 AM
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?
‎2007 Jan 04 6:53 AM
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
‎2007 Jan 04 7:02 AM
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.
???
‎2007 Jan 04 7:05 AM
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.
‎2007 Jan 04 7:11 AM
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
‎2007 Jan 04 8:33 AM
‎2007 Jan 04 8:53 AM
‎2007 Jan 04 8:59 AM
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
‎2007 Jan 04 9:05 AM
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