IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

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


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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
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

Global Moderator


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

PostPosted: Thu Jul 18, 2013 3:00 pm
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
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

Global Moderator


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

PostPosted: Thu Jul 18, 2013 3:11 pm
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
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

Global Moderator


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

PostPosted: Thu Jul 18, 2013 3:41 pm
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
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
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
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

Global Moderator


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

PostPosted: Fri Jul 19, 2013 2:56 pm
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

Superior Member


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

PostPosted: Fri Jul 19, 2013 4:02 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Does anyone know rexx for VSE CLIST & REXX 3
No new posts TSO ALLOC In REXX Needs Improvement JCL & VSAM 3
No new posts REXX/CMS How to place command console... CLIST & REXX 4
No new posts Help needed in automation cics transa... CLIST & REXX 1
No new posts Reroute print output via REXX/SDSF TSO/ISPF 6
Search our Forums:

Back to Top