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

COBOLDB2 program - Help needed


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
beepravin

New User


Joined: 29 Sep 2008
Posts: 4
Location: Chennai

PostPosted: Thu Mar 12, 2009 2:53 pm
Reply with quote

Hi ,

As per my requirment, I have to read the records from the table and after some process, I have to update the values in the same table. So, in this case, how I have to declare the cursor?

Ex - The table "CONTRACT" will have 2 fields 'Policy' and the 'premium' fileds. The program will read the record and after some process it will update the 'premium' filed with new values for particular 'policy'.

So Could anybody provide any help??

Regards,
Praveen
Back to top
View user's profile Send private message
murugan_mf

Active User


Joined: 31 Jan 2008
Posts: 148
Location: Chennai, India

PostPosted: Thu Mar 12, 2009 4:58 pm
Reply with quote

Praveen,

The cursor declaration should be as

I am assuming policy field as a primary key.

Code:
Declare contract_csr cursor  for
Select
   policy
  ,premium
From
   contract
For update of premium


After fetching each row from the cursor and processing, do an update on
premium field based on policy.
Back to top
View user's profile Send private message
beepravin

New User


Joined: 29 Sep 2008
Posts: 4
Location: Chennai

PostPosted: Fri Mar 13, 2009 10:58 am
Reply with quote

Many Thanks Murugan :-)

Regards,
Praveen.
Back to top
View user's profile Send private message
rajesh_mbt

New User


Joined: 27 Mar 2006
Posts: 97
Location: India

PostPosted: Fri Mar 13, 2009 11:33 am
Reply with quote

Hi Murugan,
I am not clear with the
Code:
For Update Of premimum...

Can you bit explain the difference between with and without using For update in the cursor?
Back to top
View user's profile Send private message
srikanthkailasam

New User


Joined: 13 Nov 2006
Posts: 24
Location: Bengalooru

PostPosted: Fri Mar 13, 2009 11:58 pm
Reply with quote

Hi Rajesh,

FOR UPDATE lets you to update only the field that is mentioned. This helps in preventing any unwanted/unintentional updates.

Please correct me if I am wrong.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Sat Mar 14, 2009 3:19 am
Reply with quote

From the DB2 Vsn8 Appl Prog & Sql Guide,
2.2.1.1 Step 1: Declare the cursor

Quote:

DB2 must do more processing when you use the FOR UPDATE clause without a column list than when you use the FOR UPDATE clause with a column list.

Therefore, if you intend to update only a few columns of a table, your program can run more efficiently if you include a column list.

The precompiler options NOFOR and STDSQL affect the use of the FOR UPDATE clause in static SQL statements. For information about these options, see Table 59 in topic 5.1.1.1.6.

If you do not specify the FOR UPDATE clause in a DECLARE CURSOR statement, and you do not specify the STDSQL(YES) option or the NOFOR precompiler options, you receive an error if you execute a positioned UPDATE statement.


in short,
you need the FOR UPDATE clause in a cursor definition to differentiate
between a READ-ONLY cursor
and one that is to be used to UPDATE a column(s).

If you are not going to update all columns selected,
it is more efficient to list the columns to be updated.
Back to top
View user's profile Send private message
rajesh_mbt

New User


Joined: 27 Mar 2006
Posts: 97
Location: India

PostPosted: Mon Mar 16, 2009 12:22 pm
Reply with quote

Great!!! I leant one of the way of DB2 fine tunning icon_smile.gif
Thanks a lot Dick and Srikanth
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Using API Gateway from CICS program CICS 0
No new posts DB2 Event passed to the Application P... DB2 1
No new posts How to pass the PARM value to my targ... COBOL Programming 8
No new posts REXX code to expand copybook in a cob... CLIST & REXX 2
No new posts EZT program to build a flat file with... All Other Mainframe Topics 9
Search our Forums:

Back to Top