Focal Point
[SOLVED] DB2 Table Updates

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/738108433

January 07, 2010, 08:21 AM
ktnj
[SOLVED] DB2 Table Updates
Hello all,

I would like to use mainframe batch Focus to update a DB2 table as follows:
1. Read a flat file record
2. If the record (key) exists on the DB2 table
then update the DB2 row.
3. If the record (key) does not, insert it.

Can anyone provide the pseudo-code for this logic??

Thanks to all,
Ken
Focus 7.2.5 Z/OS IBM mainframe

This message has been edited. Last edited by: Kerry,


January 07, 2010, 10:02 AM
GinnyJakes
Please download a mainframe FOCUS manual and read up on MODIFY.


Ginny
---------------------------------
Prod: WF 7.7.01 Dev: WF 7.6.9-11
Admin, MRE,self-service; adapters: Teradata, DB2, Oracle, SQL Server, Essbase, ESRI, FlexEnable, Google
January 07, 2010, 01:00 PM
BlueZone
You could do the insert part with SQL passthrough too.

  
(..initial processing to read flat file and assign values to amper vars...)
-INSERT_LOOP to be processed as many times are needed
SQL DB2
INSERT statement using above amper vars
 ;
TABLE
END
-RUN
-SET &SQL_ERROR1 = &RETCODE;                                            
-TYPE SQL ERROR1: &SQL_ERROR1                                         
-IF (&SQL_ERROR1.EVAL EQ '0' OR &SQL_ERROR1.EVAL EQ -803) GOTO LBL_NXT1;
(else do ERROR processing here)
-LBL_NXT1
(continue processing after sucessful insert)
-INSERT_LOOP_END



The -803 check takes care of the duplicate condition and treats it as successful operation.
All other errors should be handled appropriately.

Sandeep Mamidenna


-------------------------------------------------------------------------------------------------
Blue Cross & Blue Shield of MS
WF.76-10 on (WS2003 + WebSphere) / EDA on z/OS + DB2 + MS-SQL
MRE, BID, Dev. Studio, Self-Service apps & a dash of fun !! Music
January 07, 2010, 01:31 PM
Maintain Wizard
You could easily do this in Maintain:

MAINTAIN FILE file1 AND file2
FOR ALL NEXT file1.keyfields into stk
FOR ALL REVISE file2.non-key fieldlist from stk
END

Just make sure that you allocate file1 and that the fields in both file are the same.

Mark
January 07, 2010, 03:01 PM
Tony A
... and also that you have a maintain licence?

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
January 19, 2010, 06:58 AM
ktnj
Those solution worked fine.
Sorry it took me so long to reply.
I was out of the office for several days.

Thanks again!


January 19, 2010, 10:06 AM
Francis Mariani
You used all of them?


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server