Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Using REXX to fetch DB2 rows , but can not fetch all

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
chaoj

Active User


Joined: 03 Jun 2010
Posts: 103
Location: Dalian

PostPosted: Thu Jul 18, 2013 2:22 pm    Post subject: Using REXX to fetch DB2 rows , but can not fetch all
Reply with quote

Hello all

I wrote a REXX pgm to select DB2 table and make the records to a particular format , but for some tables , I can not fetch all rows cause the SQLCODE returns 100 and no more rows was fetched . Please help .


I use SQLCODE = 100 to judge the end of the table record .

but for some table , there's 600 records in the table , when fetch 245 records , the SQLCODE was 100 .

(some table is OK , some table is NG)

Code:

PARMSQL3 = "SELECT "TEMPCOL" FROM PK80U1."TBLNAME   
"EXECSQL DECLARE C3 CURSOR FOR S3"                   
"EXECSQL PREPARE S3 FROM :PARMSQL3"                 
"EXECSQL OPEN C3"                                   
DO FOREVER                                           
"EXECSQL FETCH C3 INTO :DBDATA1"                     
 IF SQLCODE = 100 THEN LEAVE                         
 OUTLINE1.1 = DBDATA1                               
 ADDRESS TSO "EXECIO 1 DISKW OUTDD1 (STEM OUTLINE1. "
END                                                 
"EXECSQL CLOSE C3"                                   
Back to top
View user's profile Send private message

chaoj

Active User


Joined: 03 Jun 2010
Posts: 103
Location: Dalian

PostPosted: Thu Jul 18, 2013 2:30 pm    Post subject:
Reply with quote

by the way , I printed the SQLERRD.1,SQLERRD.2 and SQLERRD.3

but for all tables (OK or NG) , the SQLERRD was the same

SQLERRD.1:-110
SQLERRD.2:0
SQLERRD.3:0
Back to top
View user's profile Send private message
Pandora-Box

Moderator


Joined: 07 Sep 2006
Posts: 1530
Location: Andromeda Galaxy

PostPosted: Thu Jul 18, 2013 3:00 pm    Post subject:
Reply with quote

Try something like this

Code:
J=1
DO UNTIL (SQLCODE ¬= 0)
ADDRESS DSNREXX "EXECSQL FETCH C3 INTO :DBDATA1"
  IF SQLCODE = 0 THEN DO
      OUTLINE1.J   = DBDATA1
  END
END
Back to top
View user's profile Send private message
chaoj

Active User


Joined: 03 Jun 2010
Posts: 103
Location: Dalian

PostPosted: Thu Jul 18, 2013 3:08 pm    Post subject:
Reply with quote

Pandora-Box wrote:
Try something like this

Code:
J=1
DO UNTIL (SQLCODE ¬= 0)
ADDRESS DSNREXX "EXECSQL FETCH C3 INTO :DBDATA1"
  IF SQLCODE = 0 THEN DO
      OUTLINE1.J   = DBDATA1
  END
END


Thanks Pandora , I tried the code , but the remainder records in the table still could not fetch cause the SQLCODE=100
Back to top
View user's profile Send private message
Pandora-Box

Moderator


Joined: 07 Sep 2006
Posts: 1530
Location: Andromeda Galaxy

PostPosted: Thu Jul 18, 2013 3:11 pm    Post subject:
Reply with quote

The code works perfect for me and it is tested

I would suggest you to double check on table data
Back to top
View user's profile Send private message
chaoj

Active User


Joined: 03 Jun 2010
Posts: 103
Location: Dalian

PostPosted: Thu Jul 18, 2013 3:13 pm    Post subject:
Reply with quote

Pandora-Box wrote:
The code works perfect for me and it is tested

I would suggest you to double check on table data


Thanks , some table is OK , and some table is not ,

maybe as you say , I should check the table , I wonder if there's problem with the index ??
Back to top
View user's profile Send private message
Pandora-Box

Moderator


Joined: 07 Sep 2006
Posts: 1530
Location: Andromeda Galaxy

PostPosted: Thu Jul 18, 2013 3:41 pm    Post subject:
Reply with quote

Opps I did a mistake in copy paste

Code:
J=1
DO UNTIL (SQLCODE ¬= 0)
ADDRESS DSNREXX "EXECSQL FETCH C3 INTO :DBDATA1"
  IF SQLCODE = 0 THEN DO
      OUTLINE1.J   = DBDATA1
      J=J+1
  END
END


After populating all to OUTLINE.J try to write that into output
Back to top
View user's profile Send private message
chaoj

Active User


Joined: 03 Jun 2010
Posts: 103
Location: Dalian

PostPosted: Fri Jul 19, 2013 6:41 am    Post subject:
Reply with quote

Pandora-Box wrote:
Opps I did a mistake in copy paste

Code:
J=1
DO UNTIL (SQLCODE ¬= 0)
ADDRESS DSNREXX "EXECSQL FETCH C3 INTO :DBDATA1"
  IF SQLCODE = 0 THEN DO
      OUTLINE1.J   = DBDATA1
      J=J+1
  END
END


After populating all to OUTLINE.J try to write that into output


The result was the same , when fetch 245 records , sqlcode was set to 100
, then loop ended , the remainder 355 records could not be fetched .....
Back to top
View user's profile Send private message
chaoj

Active User


Joined: 03 Jun 2010
Posts: 103
Location: Dalian

PostPosted: Fri Jul 19, 2013 7:17 am    Post subject:
Reply with quote

I run the REXX at the development environment and test environment , it OK ....... but at production environment , there's problem , any DB2 setup will affect the fetch ??
Back to top
View user's profile Send private message
chaoj

Active User


Joined: 03 Jun 2010
Posts: 103
Location: Dalian

PostPosted: Fri Jul 19, 2013 8:13 am    Post subject:
Reply with quote

I found the reason .....

the remainder 355 records is rubbish data , and no key with the mother table , it's OK , sorry for your time Pandora
Back to top
View user's profile Send private message
Pandora-Box

Moderator


Joined: 07 Sep 2006
Posts: 1530
Location: Andromeda Galaxy

PostPosted: Fri Jul 19, 2013 2:56 pm    Post subject:
Reply with quote

Glad to know you figured out ..

But there is nothing as such rubbish data may be we didnt think that frist place icon_smile.gif
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Fri Jul 19, 2013 4:02 pm    Post subject:
Reply with quote

chaoj wrote:
the remainder 355 records is rubbish data , and no key with the mother table , it's OK , sorry for your time Pandora
There is(are) parent/child relations I heard of - -since when "mother table(s)" are being talked about...icon_biggrin.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts REXX compiled via RXTCOMP sergeyken CLIST & REXX 7 Tue Feb 07, 2017 9:41 pm
This topic is locked: you cannot edit posts or make replies. DB2 query Using Recursion, Converting... smilewithashu2 DB2 3 Tue Jan 03, 2017 12:50 pm
This topic is locked: you cannot edit posts or make replies. Calling REXX code from ISPF panel sanchita dey TSO/ISPF 4 Mon Jan 02, 2017 5:13 pm
No new posts REXX DB2: Dynamic allocation of DB2.D... BHAS CLIST & REXX 3 Mon Dec 19, 2016 8:26 pm
No new posts find particular member name in PDS us... ravi243 CLIST & REXX 10 Mon Dec 19, 2016 6:44 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us