Scroll cursor example

225 pts.
Tags:
AS/400
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

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 8  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TomLiotta
    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
    125,585 pointsBadges:
    report
  • BigKat
    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?
    8,220 pointsBadges:
    report
  • gsivakkp86
    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  
    225 pointsBadges:
    report
  • philpl1jb
    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.  
    50,165 pointsBadges:
    report
  • gsivakkp86
    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                                           
    225 pointsBadges:
    report
  • philpl1jb
    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
    50,165 pointsBadges:
    report
  • philpl1jb
    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 --
    50,165 pointsBadges:
    report
  • harith
    In Query you have selected three fields but you are moving only 2 host variables
    170 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following