My physical file is STUDENT i am trying to get the particular record using scroll cursor but i am unable to get the values. pls correct it
A UNIQUE
A R STUREC
A STUNUM 10P
A STUNAME 10A
A STUAGE 5P
A K STUNUM
Dnumber s 10p 0
Dname s 10a
Dage s 5p 0
C z-add 555 number
c/exec sql
c+ declare c1 scroll cursor for select stunum, stuname, stuage from student
c/end-exec
c/exec sql
c+ open c1
c/end-exec
c start tag
c/exec sql
c+ fetch relative :number from c1 into :name, :age
c/end-exec
C number dsply
C name dsply
C age dsply
c sqlcod ifeq 100
C goto end
C else
C goto start
C endif
C end tag
c/exec sql
c+ close c1
c/end-exec
c eval *inlr=*on
Software/Hardware used:
ASKED:
December 5, 2012 1:16 AM
We can’t correct because we don’t know what is wrong. There’s no information on what is in the file nor what happens when anything runs. The code doesn’t check for any SQL conditions or errors, so we don’t know the result of any SQL statement. — Tom
if I am reading correctly, you are also setting number to 555 by a z-add and then fetching that from the cursor. Are there 555 (or more) records in STUDENT file?
This is my STUDENT file data, pls check it and correct it.STUNUM STUNAME STUAGE 111 siva 25 222 charan 18 333 kumar 20 444 satish 20 555 kiran 25 666 prasad 19 777 madhu 26 888 naga 25 999 venkat 24 123 bala 20 456 raja 22 789 ravi 23 100 siva 26
C z-add 555 number
c+ fetch relative :number
As BigKat said. This is asking the system to fetch the 555 row from the cursor. I think you want the 5th row not the 555th row. But relative depends on where your cursor is currently positioned.
Hi Phil,I changed z-add 555 number to z-add 5 number, but i not able get the correct result. pls correct my code.Dnumber s 10p 0 Dname s 10a Dage s 5p 0 C z-add 5 number c/exec sql c+ declare c1 scroll cursor for select stunum, stuname, stuage from studentc/end-exec c/exec sql c+ open c1 c/end-exec c start tag c/exec sql c+ fetch relative :number from c1 into :name, :age c/end-exec C number dsply C name dsply C age dsply c sqlcod ifeq 100C goto end C else C goto start C endif C end tag c/exec sql c+ close c1 c/end-exec c eval *inlr=*on
select stunum, stuname, stuage
c+ fetch relative :number from c1 into :name, :age
Three fields are selected so the Into must provide host fields for the three in the selected order. Perhaps there are other issues. Check the SQLCODE after each sql statement .. it will tell you more than I can.
Phil
Well, of course I would never use a goto
but when you go back to start
you were on record 5 soe it will fetch record 10 —
In Query you have selected three fields but you are moving only 2 host variables