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

Update a DB2 Table Row


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Vishwamurthy

New User


Joined: 11 Mar 2008
Posts: 57
Location: India

PostPosted: Wed Jun 03, 2009 5:12 pm
Reply with quote

Hi all,
I would like to update a DB2 table row using a query similar to this..
Code:

UPDATE <TABLE>
SET <Column-1> = <Host Variable-1>
WHERE <Column-2> = <Host Variable-2>

How do I do that in a REXX Program?

Thanks in advance
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Wed Jun 03, 2009 5:31 pm
Reply with quote

IBM website - redbooks

Find and read

Squeezing the most out of dynamic SQl with DB2 for z/OS and OS/390

Has a whole chapter on SQL with REXX
Back to top
View user's profile Send private message
Vishwamurthy

New User


Joined: 11 Mar 2008
Posts: 57
Location: India

PostPosted: Wed Jun 03, 2009 5:35 pm
Reply with quote

Thank you.. That would be of great help.

Would be appreciated if I get a piece of code to go ahead faster icon_smile.gif.
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Wed Jun 03, 2009 5:37 pm
Reply with quote

Quote:
Would be appreciated if I get a piece of code to go ahead faster

Well, once the funds have cleared, 750 per day or part there of - code will be delivered.

DO NOT ask for code without at least showing what you have coded yourself and what the errors are. Asking for code like that is downright lazy !!!!!
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Jun 03, 2009 6:10 pm
Reply with quote

DB2 for z/OS and OS/390 : Squeezing the Most Out of Dynamic SQL

DB2 for z/OS Stored Procedures: Through the CALL and Beyond

DB2 9 for z/OS Stored Procedures: Through the CALL and Beyond

All have chapters on REXX, with examples that you can cut&paste "to go ahead faster ".
Back to top
View user's profile Send private message
Pedro

Global Moderator


Joined: 01 Sep 2006
Posts: 2547
Location: Silicon Valley

PostPosted: Wed Jun 03, 2009 7:49 pm
Reply with quote

Quote:
Would be appreciated if I get a piece of code to go ahead faster

This will get you started:
Code:
/* rexx */
/* add  your logic here */
Back to top
View user's profile Send private message
Vishwamurthy

New User


Joined: 11 Mar 2008
Posts: 57
Location: India

PostPosted: Thu Jun 04, 2009 7:45 pm
Reply with quote

Thanks expat!
The Redbook DB2 for z/OS and OS/390 : Squeezing the Most Out of Dynamic SQL has it all icon_smile.gif

My
Code:

/* REXX */                 
ADDRESS TSO "SUBCOM DSNREXX"
SQLSTMT = "UPDATE AGENT SET ADDRESS = ? WHERE AGENTID = ?"
SAY 'ENTER YOUR ID'                                       
PULL AGENTIDA
SAY 'ENTER YOUR NEW ADDRESS'
PULL ADDA                                       
ADDRESS DSNREXX                                           
"CONNECT DSN1"                                           
"EXECSQL DECLARE C1 CURSOR FOR S1"                       
"EXECSQL PREPARE S1 FROM :SQLSTMT"                       
"EXECSQL EXECUTE S1 USING :ADDA, :AGENTIDA"               
IF SQLCODE = 0 THEN                                       
   SAY 'UPDATE SUCCESSFUL'
ELSE                                                 
   DO                                                 
      SAY 'UPDATE OPERATION FAILED. ERROR DETAILS ARE'
      SAY 'SQLCODE' SQLCODE 'AND SQLSTATE' SQLSTATE   
   END                                               
"DISCONNECT DSN1"
 


I am sorry for asking for the code before trying anything..
I am now happy I know Dynamic SQL (I have read that 290 page book and only then started coding).
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Thu Jun 04, 2009 8:01 pm
Reply with quote

Great to see that you have done it.

Don't forget the SQLCA parts which will get any error messages and codes.
Back to top
View user's profile Send private message
Pedro

Global Moderator


Joined: 01 Sep 2006
Posts: 2547
Location: Silicon Valley

PostPosted: Thu Jun 04, 2009 10:46 pm
Reply with quote

Quote:
I have read that 290 page book and only then started coding

Impressive. I usually only read the page that I need. Knowing which manual to use is 99 percent of the battle. When I need more, I read more of it.
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 -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts Load new table with Old unload - DB2 DB2 6
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Check data with Exception Table DB2 0
No new posts Dynamically pass table name to a sele... DB2 2
Search our Forums:

Back to Top