Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Sample DB2 multirow fetch and Multirow Insert program

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
apandey

New User


Joined: 31 Aug 2009
Posts: 73
Location: Mumbai

PostPosted: Thu Nov 03, 2011 4:06 pm    Post subject: Sample DB2 multirow fetch and Multirow Insert program
Reply with quote

HI All,

Can one pls provide a sample Cobol + DB2 (Multirow Fetch and multirow Insert) program.
Back to top
View user's profile Send private message

gylbharat

Active Member


Joined: 31 Jul 2009
Posts: 565
Location: Bangalore

PostPosted: Thu Nov 03, 2011 4:19 pm    Post subject:
Reply with quote

Take a look... This might help - http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=%2Fcom.ibm.db2.doc.relg%2Ffmlt.htm
Back to top
View user's profile Send private message
sushanth bobby

Senior Member


Joined: 29 Jul 2008
Posts: 1013
Location: India

PostPosted: Fri Nov 04, 2011 12:01 am    Post subject:
Reply with quote

Ashutosh,

Try it out!

Sample for Multi-Fetch
Code:
000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID.  DB2MULSE.
000300*AUTHOR.  SUSHANTH BOBBY.
000400*DATE-WRITTEN. NOVEMBER 2008.
000500*REMARKS.  A SAMPLE DB2 COBOL MULTI-ROW SELECT FETCH PROGRAM ***
000600
000700****************************************************************
000800*  THIS IS A SIMPLE COBOL-DB2 CURSOR PROGRAM.
000900*  THIS PROGRAM SELECT'S ALL THE ROW IN THE TABLE.
001000*  THERE IS NO INPUT TO THIS PROGRAM.
001100****************************************************************
001200 ENVIRONMENT DIVISION.
001300
001400 DATA DIVISION.
001500
001600****************************************************************
001700 WORKING-STORAGE SECTION.
001800****************************************************************
001900 01 WS-TEMP-VAR.
002000        05 END-OF-LOOP          PIC X(1).
002100        05 IO-COUNT             PIC 9(7).
002200        05 RECORD-COUNT         PIC 9(7).
002300        05 WS0-SALARY           PIC S9(7)V99.
002400        05 WS0-INCREMENT        PIC 9(3).
002500        05 I                    PIC 9(3).
002600        05 WS0-COMMM            PIC S9(7)V99 USAGE COMP-3.
002700        05 WS1-COMMM            PIC 9(7)V99.
002800        05 WS2-COMMM            PIC Z(7).99.
002810        05 INI-DUMP-TEST        PIC 9(7).
002900 01 LOOP                        PIC S9(3) USAGE COMP VALUE 20.
003000
003100 01 WS-TEMP-EMP-ARRAY.
003200         10 WS-EMPNO            PIC X(6) OCCURS 20 TIMES.
003300         10 FILLER              PIC X(1).
003400         10 WS-FIRSTNME OCCURS 20 TIMES.
003500            49 WS-FIRSTNME-LEN  PIC S9(4) USAGE COMP.
003600            49 WS-FIRSTNME-TEXT PIC X(12).
003700         10 WS-INDI      PIC S9(4) USAGE COMP OCCURS 20 TIMES.
003800      10 WS-COMMM     PIC S9(7)V99 USAGE COMP-3 OCCURS 20 TIMES.
003900     COPY DUMPT.
004000*    ***********************************************************
004100*    SQL CONTROL BLOCK
004200*    ***********************************************************
004300     EXEC SQL INCLUDE SQLCA    END-EXEC.
004400
004500*    ***********************************************************
004600*    SQL/DEFINITION OF EMPLOYEE
004700*    ***********************************************************
004800     EXEC SQL INCLUDE EMPLOYEE END-EXEC.
004900
005000*   ************************************************************
005100*    MULTI-ROW CURSOR FETCH DECLARATION
005200*   ************************************************************
005300*    ***********************************************************
006700 PROCEDURE DIVISION.
006800     INITIALIZE WS-TEMP-VAR
006900     INITIALIZE WS-TEMP-EMP-ARRAY
007000     EXEC SQL
007100          DECLARE ECURSOR CURSOR WITH ROWSET POSITIONING
007200          FOR
007300            SELECT EMPNO,FIRSTNME,COMM
007400            FROM EMPLOYEE
007500     END-EXEC.
007600*    ***********************************************************
007700*    OPENING ECURSOR
007800*    ***********************************************************
007900     EXEC SQL
008000       OPEN ECURSOR
008100     END-EXEC.
008110          DISPLAY 'AFTER OPEN SQLERRD(3) = 'SQLERRD(3).
008200
008300 0000-START-PROGRAM.
008400     EXEC SQL
008500       WHENEVER SQLERROR
008600       GOTO 9000-DB-ERROR
008700     END-EXEC.
008800
008900     EXEC SQL
009000       WHENEVER SQLWARNING
009100       CONTINUE
009200     END-EXEC.
009300
009400     EXEC SQL
009500       WHENEVER NOT FOUND
009600       CONTINUE
009700     END-EXEC.
009800
009900     PERFORM 0100-READ-PARA.
010000     EXEC SQL
010100       CLOSE ECURSOR
010200     END-EXEC.
010300     GO TO 1000-END-PROGRAM.
010400
010500 0100-READ-PARA.
010600        PERFORM UNTIL END-OF-LOOP = 'Y'
010700        INITIALIZE WS-TEMP-EMP-ARRAY
010800           EXEC SQL
010900             FETCH   NEXT ROWSET FROM ECURSOR FOR :LOOP ROWS
011000             INTO    :WS-EMPNO :WS-INDI ,:WS-FIRSTNME, :WS-COMMM
011100           END-EXEC
011400          DISPLAY 'SQLERRD(3) = 'SQLERRD(3)
011700          EVALUATE SQLCODE
011800            WHEN 0
011900              PERFORM 0200-READ-ARRAY
012000
012100            WHEN +100
012200              IF SQLERRD(3) > 0
012300                 MOVE SQLERRD(3) TO LOOP
012400                 PERFORM 0200-READ-ARRAY
012500              END-IF
012600              DISPLAY 'TOTAL NUMBER OF RECORDS = ' RECORD-COUNT
012700              DISPLAY 'TOTAL I/O STATUS = ' IO-COUNT
012800              MOVE 'Y' TO END-OF-LOOP
012900
013000            WHEN OTHER
013100              DISPLAY 'ERROR IN RETREVING DATA'
013200              DISPLAY 'SQLCODE = ' SQLCODE
013300
013400          END-EVALUATE
013500        END-PERFORM.
013600
013700 0200-READ-ARRAY.
013800      MOVE 1 TO I
013900      PERFORM LOOP TIMES
014000      MOVE WS-COMMM(I) TO WS1-COMMM
014100      MOVE WS1-COMMM TO WS2-COMMM
014200     DISPLAY WS-EMPNO(I)' 'WS-FIRSTNME(I)' 'WS-INDI(I)' 'WS2-COMMM
014300        ADD 1 TO I
014400        ADD 1 TO RECORD-COUNT
014500      END-PERFORM
014600      ADD 1 TO IO-COUNT.
014700
014800 1000-END-PROGRAM.
014900     GOBACK.
015000
015100 9000-DB-ERROR.
015200      GO TO 1000-END-PROGRAM.
015300


Thanks,
Sushanth
Back to top
View user's profile Send private message
apandey

New User


Joined: 31 Aug 2009
Posts: 73
Location: Mumbai

PostPosted: Fri Nov 04, 2011 12:33 pm    Post subject:
Reply with quote

Thanks Gylbharath and Sushanth.
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 -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts IMS T-Pipe queue counts in a COBOL Pr... Siva NKK Kothamasu IMS DB/DC 0 Tue May 09, 2017 6:31 pm
No new posts Need help in REXX CALL program Raje1002 CLIST & REXX 5 Wed Apr 19, 2017 11:18 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Executing OO COBOL program invoking J... Virendra Shambharkar COBOL Programming 2 Tue Jan 10, 2017 6:37 pm
No new posts Need Suggestion on COBOL program vickey_dw COBOL Programming 5 Thu Jan 05, 2017 10:55 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us