SCROL LOGIC IN DB2 NOT WORKING



IBM's flagship relational database management system

SCROL LOGIC IN DB2 NOT WORKING

Postby avvarycobol » Mon Mar 28, 2011 8:22 pm

THIS IS MY PROGRAM


IDENTIFICATION DIVISION.
PROGRAM-ID. SCROL.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT OUTFILE ASSIGN TO DD2.
DATA DIVISION.
FILE SECTION.
FD OUTFILE.
01 OUTRECORD.
05 ACCNO PIC 9(4).
05 ACCNAME PIC X(20).
05 FILLER PIC X(56).
WORKING-STORAGE SECTION.
EXEC SQL
INCLUDE SQLCA
END-EXEC.
EXEC SQL
INCLUDE TB1
END-EXEC.
EXEC SQL
DECLARE CUR1 SENSITIVE STATIC SCROLL CURSOR FOR
SELECT ACCNO, ACCNAME
FROM TB1

END-EXEC.
PROCEDURE DIVISION.
OPEN OUTPUT OUTFILE.
EXEC SQL
OPEN CUR1
END-EXEC.
EXEC SQL
FETCH CUR1 INTO :HACCNO, :HACCNAME
END-EXEC.
EXEC SQL
FETCH RELATIVE +2 FROM CUR1 INTO :HACCNO, :HACCNAME
END-EXEC.
MOVE HACCNO TO ACCNO.
MOVE HACCNAME TO ACCNAME.
WRITE OUTRECORD.
CLOSE OUTFILE.
EXEC SQL
CLOSE CUR1
END-EXEC.
IF SQLCODE = 00
DISPLAY 'SUCCESSFULLY WRITED TO FILE', SQLCODE
ELSE
DISPLAY 'FAILED AT WRITING', SQLCODE
DISPLAY 'ACCNO', ACCNO
DISPLAY 'ACCNAME', ACCNAME
END-IF.
STOP RUN.


AND MY TABLE IS


ACCNO ACCNAME
------ --------------------
1234 BILL CLINTON
2000 BARACK
3000 HILLARY
4000 GEORGE

Here my primary key is ACCNO

and writing out put to a file

i am getting 50J sql code.

what is the problem with my program.

am i doing right or any wrong in program.plz clarify.

with regards.
avvarycobol
 
Posts: 5
Joined: Mon Mar 07, 2011 5:28 pm
Has thanked: 0 time
Been thanked: 0 time

Re: SCROL LOGIC IN DB2 NOT WORKING

 

Re: SCROL LOGIC IN DB2 NOT WORKING

Postby Akatsukami » Mon Mar 28, 2011 9:01 pm

Obviously, since you're getting an SQL error code, you're doing something wrong.

Now, were you able and willing to read and understand this manual page, you'd know why you were getting that error code. Since your poor logic masks the error code from the statement that caused that, you'll have to re-write your program or apply far more effort and logic than you have so far to continue debugging.
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1056
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: SCROL LOGIC IN DB2 NOT WORKING

Postby alexm » Fri Apr 08, 2011 9:14 pm

avvarycobol,
there's plenty of information available that you may use to solve your problem. In the good old days, I had to go for walking-tours to grab a manual and have a look at it. Now with the internet available, it should not be a big deal to start an internet browser, and set some handy bookmarks for IBM related pages.

First, there's that nice link here that beams you to a table of contents of IBM software manuals. It covers a lot of stuff you're dealing with within a z/OS environment.

If you are asked to code programs, you'll need a link to the IBM library that covers your programming languages.

And if you should put some DB2 SQL statements into your program, you may have a look at the IBM library that describes your DB2 release - you may take this link as a starting point and scroll down to the 'manuals'. Very interesting for application programmers is the manual called 'Application Programming & SQL Guide', another manual you should bookmark is 'SQL Reference', and 'Messages'.

Apart from this, there are collections of redbooks and other technical resources available that may discuss in deep detail what you're interested in. Give it a try.

Suddently, one or two words regarding your program: it's always good practice to add some error handling code following all executable SQL statements in your program. If you would have done this, you'd have seen that the 'OPEN CUR1' returned an SQLCODE your program should not accept, and terminate. The way you have coded your program - without checking SQLCODEs - leads to your (misplaced) statement: scroll logic is not working...
EXEC SQL
   sql statement
END-EXEC
IF SQLCODE = 0
   ...
ELSE
   display error and diagnositc information
   terminate program
END-IF


Regards,
alexm
User avatar
alexm
 
Posts: 33
Joined: Wed Oct 13, 2010 6:40 pm
Has thanked: 0 time
Been thanked: 0 time


Return to DB2

 


  • Related topics
    Replies
    Views
    Last post