Showing posts with label COBOL. Show all posts
Showing posts with label COBOL. Show all posts

Wednesday, November 28, 2012

Declare numeric field with More than 18 Digits in Cobol

Have you ever wondered about the 18digits maximum limit of Numerical variable declaration (PIC 9(18) ) in Cobol?

Well you can override it in Enterprise Cool, or in other words if Language environment (a.k.a LE) is available at your shop. The Language environment is introduced back in 2000 by IBM, which is a common application layer for many Programming languages. The LE has a lot of cool features which I’ll be covering future posts. So keep coming back.

Here is a sample program for Numeric field declaration with more than 18 digits. The Compiler directive (CBL) is that really turning the ship around.
This compiler-directing statement selectively suppresses output or causes output to be produced. The keywords *CONTROL and *CBL are synonymous.

The Program logic is simple its just move a 31 digit number to the number 1 variable, then add it with itself and display it.
If you Don’t have mainframe access to try it out, visit my post on getting a free mainframe id, it really helps.  http://mainframegeek.me/2012/11/23/free-mainframe-id-to-practice/ . It’s a raw mainframe so you won’t be getting handy compile JCL on this mainframe, let me know if you need one, I can help you.







 CBL ARITH(EXTEND)
IDENTIFICATION DIVISION.
PROGRAM-ID. COB18DIG.
AUTHOR.     SHIBU.T.
*
DATA DIVISION.
WORKING-STORAGE SECTION.
77  WS-NUM1                      PIC 9(31).
*
PROCEDURE DIVISION.
A0000100-MAIN-PARA.
MOVE 1234567890123456789012345678901
TO WS-NUM1.
DISPLAY 'WS-NUM1 BEFORE ADDITION: ' WS-NUM1.
ADD WS-NUM1                 TO WS-NUM1.
DISPLAY 'WS-NUM1 AFTER ADDITION: ' WS-NUM1.
STOP RUN.

 

The compile and run JCL will complete with return-code 000, here is the output I got in my machine.

image

Does my Program, post helped you? Comment, rate or like my facebook page (top right corner of this page) and click on the adds listed below. It really help me to make this website alive.

-Cheers, Shibu

Saturday, October 29, 2011

Programming a CICS-DPL-COBOL application & setting up the region.

DPL (Distributed Program Link) enables a Local CICS program to issue a EXEC CICS LINK to a program in the remote CICS region which return control to the calling program. DPL provides the below advantages for a CICS application.

  1. It allows a non OS390/zOS application to use DL/I, SQL, BDAM and VSAM files owned by a zOS/os390 system.
  2. Allows CICS programmer to use LU 6.2 link Protocol without knowing the protocol.
Restrictions of DPL.

You cannot use the below CICS services on the remote application.

  1. You cannot issue any terminal control commands. e.g. SEND, RECEIVE.
  2. No BMS commands.
  3. No security commands like SIGNON or SIGNOFF.

If you are receiving any abends on the remote application and it didn’t handle the abend by itself then, abend code will returned to the Main program.

Defining and installing CICS entries.

Assume that you have a Mainframe connectivity like below.

image

Here I have 2 TSO sessions, 8 CICS regions, 2 IMS, 1 CICSPlex/SM and few Session manager setups and Misce sessions.

I am using the CICSA and CICSB regions, I.e my Main program is in CICSA and it then calling the program on CICSB using a COMMAREA, second program will write the message passed in commarea into a VSAM file, set a message onto COMMAREA and returns into CICSA region.

Before you are getting started with your program, make sure that MRO/ISC is configured in your Mainframe, you can contact you system Admin or follow my instructions below.

  1. Go to your CICS region batch job in spool.
  2. Open the JESYSMSG and Check for ISC and IRCSTRT init parms are setup to YES.
  3. IF the above initparms are not setup to YES then you need to ask your sysadmin to set this up before you continue with DPL program.
Usually SYSADMIN do the below steps to setup ISC or IRCSTRT.
  1. Bring down CICS region using master console or Perform SHUTDOWN using CEMT.
  2. Find SIP parameter for the region.
  3. Go to SYSIN PDS of the Installed CICS TS.
  4. Find the DFH$SIP<SIP PARM> member and add the ISC and IRCSTRT parms.
  5. Restart CICS region.

You can also issue a CEMT I IRC to check whether IRC is setup for the region.

image

Steps to create CICS table entries for a DPL program.

  1. Define and Install the main program on LOCAL CICS region as usual.
  2. Define and install Mirror Entries of remote CICS transaction and program on LOCAL CIS region. Set the remote Attributes (Remote System as the 4 digit remote CICS region ID, and program name) You can see the remote system ID on SYSID field once you issue a CEMT/CEDA command (See below screenshots).
  3. Go to Remote CICS region and define and Install only remote Program and Transaction.
  4. Compile CICS programs and move Load module to the respective libraries of local and Remote CICS regions.
  5. Perform New copy for the Local program on Local CICS region and Remote program on remote region.
  6. Invoke the Local CICS program using the defined Transaction on Local CICS region.
DPL Sample program

Main program.

IDENTIFICATION DIVISION.
PROGRAM-ID. CDPL01A.
AUTHOR.     SHIBU.T.
*
DATA DIVISION.
WORKING-STORAGE SECTION.
77  WS-MSG-1                    PIC X(100).
77  WS-MSG-LEN                  PIC S9(4) COMP.
*
01  WS-COMMAREA.
     02  WS-RECID                PIC X(10).
     02  WS-MSG                  PIC X(40).
     02  WS-PROG-ID              PIC X(08).
LINKAGE SECTION.
01  DFHCOMMAREA.
     02  LS-COMMAREA.
         03  LS-RECID            PIC X(10).
         03  LS-MSG              PIC X(40).
         03  LS-PROG-ID          PIC X(08).
PROCEDURE DIVISION.
A0001-MAIN-PARA.
     MOVE SPACES                 TO WS-COMMAREA WS-MSG-1.
     IF EIBCALEN = 0 THEN
        PERFORM A00150-INITIALIZE
     ELSE
        PERFORM A00200-LINK
     END-IF.

*
A00150-INITIALIZE.
     MOVE 'PROGRAM ON CICSAOR1 REGION'
                                 TO WS-MSG.
     MOVE '1000000123'           TO WS-RECID.
     MOVE 'CDPL01A'              TO WS-PROG-ID.
     MOVE 'WS-MSG BEFORE DPL: '  TO WS-MSG-1(1:20).
     MOVE WS-MSG                 TO WS-MSG-1(21:26).
     MOVE '* PROGRAM-ID: '       TO WS-MSG-1(47:14).
     MOVE WS-PROG-ID             TO WS-MSG-1(61:08).
     EXEC CICS SEND TEXT
         FROM(WS-MSG-1)
         ERASE
     END-EXEC.
     EXEC CICS RETURN
         TRANSID('AA05')
         COMMAREA(WS-COMMAREA)
     END-EXEC.

*
A00200-LINK.
     MOVE LS-COMMAREA            TO WS-COMMAREA.
     EXEC CICS LINK
         PROGRAM('CDPL01B')
         COMMAREA(WS-COMMAREA)
     END-EXEC.

     MOVE SPACES                 TO WS-MSG-1.
     MOVE 'WS-MSG AFTER  DPL: '  TO WS-MSG-1(1:20).
     MOVE WS-MSG                 TO WS-MSG-1(21:26).
     MOVE '* PROGRAM-ID: '       TO WS-MSG-1(47:14).
     MOVE WS-PROG-ID             TO WS-MSG-1(61:08).
     EXEC CICS SEND TEXT
         FROM(WS-MSG-1)
         ERASE
     END-EXEC.
     EXEC CICS RETURN
     END-EXEC.

Sub Program on Remote region.

IDENTIFICATION DIVISION.
PROGRAM-ID. CDPL01B.
AUTHOR.     SHIBU.T.
*
DATA DIVISION.
WORKING-STORAGE SECTION.
77  WS-MSG-1                    PIC X(100).
77  WS-MSG-LEN                  PIC S9(4) COMP.
01  WS-FILE-DT.
     02  WS-DAT.
         03  WS-KEY              PIC X(10).
         03  WS-DAT1             PIC X(40) VALUE SPACES.
         03                      PIC X(60) VALUE SPACES.
*
01  WS-COMMAREA.
     02  WS-RECID                PIC X(10) VALUE SPACES.
     02  WS-MSG                  PIC X(40).
     02  WS-PROG-ID              PIC X(08).
LINKAGE SECTION.
01  DFHCOMMAREA.
     02  LS-COMMAREA.
         03  LS-RECID            PIC X(10).
         03  LS-MSG              PIC X(40).
         03  LS-PROG-ID          PIC X(08).
PROCEDURE DIVISION USING DFHCOMMAREA.
A0001-MAIN-PARA.
*    MOVE SPACES                 TO WS-COMMAREA WS-MSG-1.
     MOVE LS-RECID               TO WS-KEY.
     MOVE LS-MSG                 TO WS-DAT1.
     EXEC CICS WRITE
          DATASET('VFILE1')
          FROM(WS-DAT)
          LENGTH(LENGTH OF WS-DAT)
          RIDFLD(WS-KEY)
     END-EXEC.
     MOVE 'PROGRAM ON CICSAORB REGION'
                                 TO WS-MSG.
     MOVE 'CDPL01B'              TO WS-PROG-ID.
     MOVE WS-COMMAREA            TO LS-COMMAREA.
     EXEC CICS RETURN
     END-EXEC.

Compile aCICS programs and Move load modules to respective LOAD LIBS of CICS regions.

Please refer to http://mainframegeek.wordpress.com/2011/10/11/prepare-compile-define-install-execute-a-cics-cobol-program/ for more info on how to prepare compile a COBOL-CICS program, how to find LOAD LIB od CICS region and move the Load module.

Defining and Installing Resources to CICS.
On CICS REGION CICSA

Step 1 Create and Install Program entries for the Main program on CICSA, defining is similar to a normal CICS program.

clip_image002[12]

Step 2 Install the program.

clip_image002[32]

Step 3 Define Transaction Entry for Main program on CICSA, you need to mention main program name (CDPL01A) while defining Transaction entry.

clip_image002[8]

Step 4  Install the transaction.

clip_image002[10]

Step 5 Define Mirror Program.

clip_image002[14]

clip_image002[16]

clip_image002[18]

Step 6 Define and Install Mirror Transaction.

clip_image002[22]

clip_image002[24]

clip_image002[26]

on remote region

Step 7 Define, Install Program and Transaction entries .

image

clip_image002[6]

clip_image002[28]

clip_image002[30]

Step 9 Execute Program.

Issue AA05 on CICSA to execute program, do a cedf if you want to see what is exactly happening in the program. This is a pseudo-conversation program, it displays commarea content before links to the remote app. Press enter to issue LINK.

clip_image002[34]

clip_image002[36]

Control came back from Remote app, you can see the commarea contents which set up by remote app.

You can also open the file to ensure that Remote app is getitng COMMAREA conts correctly ( Remote app will write the commarea contents to VSAM file). Look for th last line, that is the message passed on commarea.

clip_image002[38]

Tuesday, September 13, 2011

DSNTIAR & DSNTIAC–SQLCA formatter for Batch & CICS

We must check for the SQLCODE before we issue commit on a table in DB2, handle the errors- Display description or whatever. handling/remembering reason for each and every sqlcode every time is a time pressing task always. There is DSNTIAR and DSNTIAC comes in picture. DSNTIAR and DSNTIAC are two assembler routine which helps to get a formatted version of SQLCA and the text message based on the sqlcode in the SQLCA.

DSNTIAR takes data from SQLCA formats and puts into a data area provided by the calling program. DSNTIAR will overwrite the contents of the data area before it moves the data.

DSTIAR expects the SQLCA in its original for, so before you call DSNTIAR/DSNTIAC make sure that you haven’t modified SQLCA.

Defining Message output Data name

Calling program must allocate output message data name and pass it,

make sure:

1. First 2 bytes are length – a pic s9(4) comp will be ideal for the purpose.

2.You must define enough space for the message in character type, data should be minimum of 10 lines of 72 bytes. A  PIC x(72)  occurs 10 times. will  be quite enough for the message.

e.g.

01  ERROR-MESSAGE.                                
        02  ERROR-LEN   PIC S9(4)  COMP VALUE +720.
        02  ERROR-TEXT  PIC X(72)  OCCURS 10 TIMES.

keep the length in another variable.

77  ERROR-TEXT-LEN      PIC S9(9)  COMP VALUE +72.

Once we executed a SQL statement, we are ready to issue a call to DSNTIAR,

CALL 'DSNTIAR' USING SQLCA ERROR-MESSAGE ERROR-TEXT-LEN

display the resultant message by displaying “ ERROR-TEXT() “ table.

Possible return codes for DSNTIAR/DSNTIAC
0 Successful execution.
4 More data available than could fit into the provided message area.
8 Error record length is not between 72 & 240
12 Message area is not large enough,  we need to provide more space needs to be defined and must be passed.
16 Error in message routine.

 

Sample program

IDENTIFICATION DIVISION.                                        
PROGRAM-ID. DBPGM01.                                            
AUTHOR    . SHIBU.T.                                            
*                                                                
DATA DIVISION.                                                  
WORKING-STORAGE SECTION.                                        
     EXEC SQL                                                    
         INCLUDE MYNAM                                           
     END-EXEC.                                                   
     EXEC SQL                                                    
         INCLUDE SQLCA                                           
     END-EXEC.                                                   
                                                                 
01  ERROR-MESSAGE.                                              
         02  ERROR-LEN   PIC S9(4)  COMP VALUE +720.             
         02  ERROR-TEXT  PIC X(72)  OCCURS 10 TIMES.             
77  ERROR-TEXT-LEN      PIC S9(9)  COMP VALUE +72.              
                                                                 
01  WS-TEMP-VAR.                                                
     05  TEMP                    PIC X(30).                      
     05  TEMP-MSG                PIC X(60).                      
     05  WS-IND                  PIC X VALUE 'Y'.                
01  WS-TBLE-DTA.                                                
     05  WS-SEQ                  PIC X(3).                       
     05  WS-SEQ-TMP              PIC X(3).                       
     05  WS-NAME                 PIC X(15).                      
                                                                 
77  WS-I                        PIC S9(4) COMP.                 
                                                                 
01  WS-SQLCODE                  PIC ------9.                    
*                                                                
PROCEDURE DIVISION.                                             
     PERFORM A00100-READ-PARA.                                   
                                                                 
Z00100-EXIT-PARA.                                               
     STOP RUN.                                                   
A00100-READ-PARA.                                               
     DISPLAY '         A00100-READ-PARA.           '             
     EXEC SQL                                                   
         DECLARE CURREAD1 CURSOR FOR                            
             SELECT NAME,SEQ FROM IBMGRP.MYNAM                  
     END-EXEC.                                                  
     EXEC SQL                                                   
        OPEN CURREAD1                                           
     END-EXEC.                                                  
     EVALUATE TRUE                                              
     WHEN SQLCODE = 0                                           
      PERFORM A00150-READ-PARA                                  
     WHEN SQLCODE > 0                                           
      DISPLAY 'FETCH WAS SUCCESS WITH A WARNING'                
      CALL 'DSNTIAR' USING SQLCA ERROR-MESSAGE ERROR-TEXT-LEN   
      PERFORM VARYING WS-I FROM 1 BY 1 UNTIL WS-I = 10          
        DISPLAY ERROR-TEXT(WS-I)                                
      END-PERFORM                                               
     WHEN OTHER                                                 
      CALL 'DSNTIAR' USING SQLCA ERROR-MESSAGE ERROR-TEXT-LEN   
      PERFORM VARYING WS-I FROM 1 BY 1 UNTIL WS-I = 10          
        DISPLAY ERROR-TEXT(WS-I)                                
      END-PERFORM                                               
      PERFORM Z00100-EXIT-PARA                                  
     END-EVALUATE.                                              
     MOVE SQLCODE             TO WS-SQLCODE.                    
     DISPLAY 'SQLCODE OPEN  ' WS-SQLCODE.                       
A00150-READ-PARA.                                              
     DISPLAY '****DATA FROM TABLE***'                           
     PERFORM UNTIL SQLCODE = 100                                
        EXEC SQL                                                
           FETCH CURREAD1 INTO :WS-NAME,:WS-SEQ                 
        END-EXEC                                                
        MOVE SQLCODE             TO WS-SQLCODE                  
        EVALUATE TRUE                                           
        WHEN SQLCODE = 0                                        
         MOVE SPACES TO TEMP-MSG                                
         STRING                                                 
         'NAME: ' DELIMITED BY SPACE ' ' DELIMITED BY SIZE      
         WS-NAME DELIMITED BY SPACE ',' DELIMITED BY SIZE       
         'SEQ#' DELIMITED BY SPACE ' ' DELIMITED BY SIZE        
         WS-SEQ DELIMITED BY SIZE INTO TEMP-MSG                 
         DISPLAY TEMP-MSG                                       
        WHEN  SQLCODE > 0                                       
         DISPLAY 'FETCH WAS SUCCESS WITH A WARNING'             
         CALL 'DSNTIAR' USING SQLCA ERROR-MESSAGE ERROR-TEXT-LEN
         PERFORM VARYING WS-I FROM 1 BY 1 UNTIL WS-I = 10       
         DISPLAY ERROR-TEXT(WS-I)                               
      END-PERFORM                                               
        WHEN OTHER                                              
         CALL 'DSNTIAR' USING SQLCA ERROR-MESSAGE ERROR-TEXT-LEN
         PERFORM VARYING WS-I FROM 1 BY 1 UNTIL WS-I = 10       
           DISPLAY ERROR-TEXT(WS-I)                             
         END-PERFORM                                            
         PERFORM Z00100-EXIT-PARA                               
        END-EVALUATE                                            
     END-PERFORM.                                               
     DISPLAY '****END OF TABLE DATA****'                        
     EXEC SQL                                                   
        CLOSE CURREAD1                                          
     END-EXEC.                                                  
     MOVE SQLCODE             TO WS-SQLCODE.                    
     DISPLAY 'SQLCODE CLOSE ' WS-SQLCODE.                       
     EXIT                                                       
     .                                                          

Compiling and link editing.

remember you must concatenate <HLQ>.SDSNLOAD of DB2 installed in your host mainframe to the STEPLIB of compile step, otherwise it will result in DSNTIAR module not found error while compiling. Read http://mainframegeek.wordpress.com/2011/05/12/steps-in-a-cobol-db2-program/ for the jcl for compile, link edit and exec ut the DB2 cobol program. Don’t forget to change the JCL as mentioned below.

e.g.

//DB2COBA JOB (12345678),MSGCLASS=H,REGION=4M,                        
//        MSGLEVEL=(1,1),CLASS=A,NOTIFY=&SYSUID                       
//*                                                                   
//JOBLIB    DD DSN=DSN910.DB9G.SDSNEXIT,DISP=SHR                      
//          DD DSN=DSN910.SDSNLOAD,DISP=SHR                           
//*****************************************************************   
//* SQL PREPROC AND COBOL COMPILATION:                                
//*****************************************************************   
//*-NB---SQL PREPROC NOW IS NOW DONE BY THE COBOL COMPILER:           
//*****************************************************************   
//COB     EXEC  PGM=IGYCRCTL,                                         
//            PARM=(SQL,LIB,NOTERM,NOSEQUENCE,LIB,XREF,DYN,'')        
//STEPLIB   DD DSN=IGY410.SIGYCOMP,DISP=SHR                           
//          DD DSN=DSN910.SDSNLOAD,DISP=SHR                           
//DBRMLIB   DD DSN=TSHRCI.PGMG.DBRM(DBPGM02),DISP=SHR                 
//SYSIN     DD DSN=TSHRCI.PGMG.COBOL1(DBPGM02),DISP=SHR               
//SYSLIB    DD DSN=TSHRCI.PGMG.COBOL1,DISP=SHR                        
//SYSLIN    DD DSN=&&LOADSET,DISP=(MOD,PASS),UNIT=SYSDA,              
//             SPACE=(800,(500,500))                                  
//SYSPRINT  DD SYSOUT=*                                               
//SYSUDUMP  DD SYSOUT=*                                               
//SYSUT1    DD SPACE=(800,(500,500),,,ROUND),UNIT=SYSDA               
//SYSUT2    DD SPACE=(800,(500,500),,,ROUND),UNIT=SYSDA               
//SYSUT3    DD SPACE=(800,(500,500),,,ROUND),UNIT=SYSDA               
//SYSUT4    DD SPACE=(800,(500,500),,,ROUND),UNIT=SYSDA               
//SYSUT5    DD SPACE=(800,(500,500),,,ROUND),UNIT=SYSDA               
//SYSUT6    DD SPACE=(800,(500,500),,,ROUND),UNIT=SYSDA               
//SYSUT7    DD SPACE=(800,(500,500),,,ROUND),UNIT=SYSDA               
//*****************************************************************
   

Outputs.

image

Wednesday, August 17, 2011

CURSORS in DB2

When we are using the DB2 in our applications we can only have one row of data at a time. So what we will do if we don't know which row exactly we need?, what if we have more than 1 row to work with? well the answer is "CURSORS".

Cursor is used when more than one row are to be selected.  Cursors has mainly 4 control statements.

1. Declare.

A name will be assigned for particular SQL statement. The name should be unique in the scope of the program. there are no limits for the number of cursors which we can have in one application program. We can declare cursor in Working storage section or Procedure division.
E.g.
EXEC SQL                                 
    DECLARE CURREAD1 CURSOR FOR          
        SELECT NAME,SEQ FROM IBMGRP.MYNAM
END-EXEC.                                

2. Open.

This statement builds the resultant table.
E.g.
EXEC SQL       
   OPEN CURREAD1
END-EXEC.  

3. Fetch.


Fetch statement will returns data from the resultant table (One row at a time) and assigns values to the specified host variables.
E.g.
EXEC SQL                              
   FETCH CURREAD1 INTO :WS-NAME,:WS-SEQ
END-EXEC                              

4. Close

Empty all the resources used by the cursor.
E.g.
EXEC SQL        
   CLOSE CURREAD1
END-EXEC.       

All these control statements will throw specific SQLCODES.

Few Snippets.

Read table.

EXEC SQL                                
    DECLARE CURREAD1 CURSOR FOR         
        SELECT NAME,SEQ FROM IBMGRP.MYNAM
END-EXEC.
Open
EXEC SQL       
   OPEN CURREAD1
END-EXEC.  

PERFORM UNTIL SQLCODE = 100                         
   EXEC SQL                                         
      FETCH CURREAD1 INTO :WS-NAME,:WS-SEQ          
   END-EXEC                                         
   MOVE SQLCODE             TO WS-SQLCODE           
   DISPLAY 'SQLCODE FETCH ' WS-SQLCODE              
   IF SQLCODE = 0 THEN                              
    MOVE SPACES TO TEMP-MSG                         
    STRING                                          
    'NAME: ' DELIMITED BY SPACE ' ' DELIMITED BY SIZE
    WS-NAME DELIMITED BY SPACE ',' DELIMITED BY SIZE
    'SEQ#' DELIMITED BY SPACE ' ' DELIMITED BY SIZE 
    WS-SEQ DELIMITED BY SIZE INTO TEMP-MSG          
    DISPLAY TEMP-MSG                                
   END-IF                                           
END-PERFORM.

Fetch name and SEQ till we hit SQLCODE 100 and display the data.

Update Table

We need to mention FOR UPDATE OF and the field name in declare statement.

EXEC SQL                                
    DECLARE CURUPDT1 CURSOR FOR         
        SELECT NAME,SEQ FROM IBMGRP.MYNAM
        WHERE SEQ = :WS-SEQ             
        FOR UPDATE OF NAME              
END-EXEC.     
here I will be updating NAME field of MYNAM table                          
EXEC SQL                                
   OPEN CURUPDT1
END-EXEC.
MOVE '002'               TO WS-SEQ.       
EXEC SQL                                  
   FETCH CURUPDT1 INTO :WS-NAME,:WS-SEQ-TMP
END-EXEC                                       
EXEC SQL                                  
   UPDATE IBMGRP.MYNAM                    
   SET NAME = :WS-NAME                    
   WHERE CURRENT OF CURUPDT1                    
END-EXEC.   
"CURRENT OF CURUPDT1" statement will pick the current row to update.   
EXEC SQL                                  
   CLOSE CURUPDT1                         
END-EXEC.
  
Delete Record

Like cursor for updating a record we need to mention FOR UPDATE OF in cursor declaration statement.
    

EXEC SQL                                
    DECLARE CURDELT1 CURSOR FOR         
        SELECT NAME,SEQ FROM IBMGRP.MYNAM
        WHERE SEQ = :WS-SEQ             
        FOR UPDATE OF NAME              
END-EXEC.                               
EXEC SQL                                
   OPEN CURDELT1                        
END-EXEC.                                                              
EXEC SQL                                  
   FETCH CURDELT1 INTO :WS-NAME,:WS-SEQ-TMP
END-EXEC                                  
EXEC SQL                   
   DELETE FROM IBMGRP.MYNAM
   WHERE SEQ = :WS-SEQ     
END-EXEC.                  
EXEC SQL             
   CLOSE CURDELT1    
END-EXEC.
  

Sample DB2-COBOL-CURSOR Code
Please refer http://mainframegeek.wordpress.com/2011/05/12/steps-in-a-cobol-db2-program to get JCL for compiling and executing DB2-COBOL-CURSOR program

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
       IDENTIFICATION DIVISION.                           
       PROGRAM-ID. DBPGM01.                               
       AUTHOR    . SHIBU.T.                               
      *                                                   
       DATA DIVISION.                                     
       WORKING-STORAGE SECTION.                           
           EXEC SQL                                       
               INCLUDE MYNAM                              
           END-EXEC.                                      
           EXEC SQL                                       
               INCLUDE SQLCA                              
           END-EXEC.                                      
       01  WS-TEMP-VAR.                                   
           05  TEMP                    PIC X(30).         
           05  TEMP-MSG                PIC X(60).            
       01  WS-TBLE-DTA.                                   
           05  WS-SEQ                  PIC X(3).          
           05  WS-SEQ-TMP              PIC X(3).          
           05  WS-NAME                 PIC X(15).         
       01  WS-SQLCODE                  PIC ------9.       
      *                                                   
       PROCEDURE DIVISION.                                
           PERFORM A00100-READ-PARA.                      
           PERFORM A00200-UPDATE-PARA.                    
           PERFORM A00100-READ-PARA.                      
           PERFORM A00400-INSERT-PARA.                    
           PERFORM A00100-READ-PARA.                      
           PERFORM A00300-DELETE-PARA.                    
           PERFORM A00100-READ-PARA.                      
           STOP RUN.                                      
       A00100-READ-PARA.                                  
           DISPLAY '         A00100-READ-PARA.           '
           EXEC SQL                                       
               DECLARE CURREAD1 CURSOR FOR                      
                   SELECT NAME,SEQ FROM IBMGRP.MYNAM            
           END-EXEC.                                            
           EXEC SQL                                             
              OPEN CURREAD1                                     
           END-EXEC.                                            
           MOVE SQLCODE             TO WS-SQLCODE.              
           DISPLAY 'SQLCODE OPEN  ' WS-SQLCODE.                 
           DISPLAY '****DATA FROM TABLE***'                     
           PERFORM UNTIL SQLCODE = 100                          
              EXEC SQL                                          
                 FETCH CURREAD1 INTO :WS-NAME,:WS-SEQ           
              END-EXEC                                          
              MOVE SQLCODE             TO WS-SQLCODE            
              DISPLAY 'SQLCODE FETCH ' WS-SQLCODE               
              IF SQLCODE = 0 THEN                               
               MOVE SPACES TO TEMP-MSG                          
               STRING                                           
               'NAME: ' DELIMITED BY SPACE ' ' DELIMITED BY SIZE
               WS-NAME DELIMITED BY SPACE ',' DELIMITED BY SIZE 
               'SEQ#' DELIMITED BY SPACE ' ' DELIMITED BY SIZE  
               WS-SEQ DELIMITED BY SIZE INTO TEMP-MSG           
               DISPLAY TEMP-MSG                                 
              END-IF                                            
           END-PERFORM.                                         
           DISPLAY '****END OF TABLE DATA****'                  
           EXEC SQL                                             
              CLOSE CURREAD1                                    
           END-EXEC.                                            
           MOVE SQLCODE             TO WS-SQLCODE.              
           DISPLAY 'SQLCODE CLOSE ' WS-SQLCODE.                 
      *                                                         
       A00200-UPDATE-PARA.                                      
           DISPLAY '         A00200-UPDATE-PARA.         '      
           EXEC SQL                                             
               DECLARE CURUPDT1 CURSOR FOR                      
                   SELECT NAME,SEQ FROM IBMGRP.MYNAM            
                   WHERE SEQ = :WS-SEQ                      
                   FOR UPDATE OF NAME                       
           END-EXEC.                                        
           EXEC SQL                                         
              OPEN CURUPDT1                                 
           END-EXEC.                                        
           MOVE SQLCODE             TO WS-SQLCODE.          
           DISPLAY 'SQLCODE OPEN  ' WS-SQLCODE.             
           MOVE '002'               TO WS-SEQ.              
           EXEC SQL                                         
              FETCH CURUPDT1 INTO :WS-NAME,:WS-SEQ-TMP      
           END-EXEC                                         
           MOVE SQLCODE             TO WS-SQLCODE.          
           DISPLAY 'SQLCODE FETCH ' WS-SQLCODE.             
           MOVE 'SHYAM-KUMAR'       TO WS-NAME.             
           EXEC SQL                                         
              UPDATE IBMGRP.MYNAM                           
              SET NAME = :WS-NAME                           
              WHERE SEQ = :WS-SEQ                           
           END-EXEC.                                        
           MOVE SQLCODE             TO WS-SQLCODE.          
           DISPLAY 'SQLCODE UPDT  ' WS-SQLCODE.             
           EXEC SQL                                         
              CLOSE CURUPDT1                                
           END-EXEC.                                        
           MOVE SQLCODE             TO WS-SQLCODE.          
           DISPLAY 'SQLCODE CLOSE ' WS-SQLCODE.             
           EXIT.                                            
      *                                                     
       A00400-INSERT-PARA.                                  
           DISPLAY '         A00400-INSERT-PARA.         '  
           MOVE 'TEMP-NAME'         TO WS-NAME.             
           MOVE 007                 TO WS-SEQ.              
           EXEC SQL                                         
               INSERT INTO IBMGRP.MYNAM                     
               VALUES ( :WS-SEQ,:WS-NAME)                   
           END-EXEC.                                      
           MOVE SQLCODE             TO WS-SQLCODE.        
           DISPLAY 'SQLCODE INSRT ' WS-SQLCODE.           
           EXIT.                                          
      *                                                   
       A00300-DELETE-PARA.                                
           DISPLAY '         A00300-DELETE-PARA.         '
           EXEC SQL                                       
               DECLARE CURDELT1 CURSOR FOR                
                   SELECT NAME,SEQ FROM IBMGRP.MYNAM      
                   WHERE SEQ = :WS-SEQ                    
                   FOR UPDATE OF NAME                     
           END-EXEC.                                      
           EXEC SQL                                       
              OPEN CURDELT1                               
           END-EXEC.                                      
           MOVE SQLCODE             TO WS-SQLCODE.        
           DISPLAY 'SQLCODE OPEN  ' WS-SQLCODE.           
           MOVE '007'               TO WS-SEQ.            
           EXEC SQL                                       
              FETCH CURDELT1 INTO :WS-NAME,:WS-SEQ-TMP    
           END-EXEC                                       
           MOVE SQLCODE             TO WS-SQLCODE.        
           DISPLAY 'SQLCODE FETCH ' WS-SQLCODE.           
           EXEC SQL                                       
              DELETE FROM IBMGRP.MYNAM                    
              WHERE SEQ = :WS-SEQ                         
           END-EXEC.                                      
           MOVE SQLCODE             TO WS-SQLCODE.        
           DISPLAY 'SQLCODE DELT  ' WS-SQLCODE.           
           EXEC SQL                                       
              CLOSE CURDELT1                              
           END-EXEC.                                      
           MOVE SQLCODE             TO WS-SQLCODE.        
           DISPLAY 'SQLCODE CLOSE ' WS-SQLCODE.           
           EXIT.

Screen Shots

image

image

image

Please tryout the code yourself and let me know if you have any concerns.