Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
COBOLDB2 program - Help needed

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: COBOLDB2 program - Help needed
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    Post subject:
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    Post subject: Reply to: COBOLDB2 program - Help needed
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: 95
Location: India

PostPosted: Fri Mar 13, 2009 11:33 am    Post subject:
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    Post subject:
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: 6968
Location: porcelain throne

PostPosted: Sat Mar 14, 2009 3:19 am    Post subject:
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: 95
Location: India

PostPosted: Mon Mar 16, 2009 12:22 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts How to write Rexx program to size and... sreejeshcs CLIST & REXX 14 Thu Oct 12, 2017 7:26 am
No new posts Accessing CICS tran with map from JCL... navdeepaggarwal CICS 5 Tue Oct 03, 2017 6:15 pm
No new posts Writing a file using online program grvtomar PL/I & Assembler 3 Fri Jun 30, 2017 1:06 pm
No new posts pre-compiler for program in an HFS Pedro DB2 0 Fri Jun 23, 2017 11:13 pm
No new posts Compiling program in endeavor for tra... RALAKKAL Compuware & Other Tools 4 Mon Jun 05, 2017 8:27 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us