COBOL Program Example ( Mainframes)

COBOL is an essential languages in Mainframes. If you have a basic idea about COBOL language and how it operates then you will be able to understand the below example properly. If you don’t know what are divisions in a COBOL program or how it’s basically written then you must read few initial chapters of any COBOL Book.This is a sample program for beginners. It has been tested on windows on a specific software.

Here is a sample program for COBOL Language in which a list of items and their related data is accepted from the user and after entering all the data it asks the users if he wants to continue or not. If yes, he will be able to enter all the information again else program will exit.

The below program has been successfully executed. If you don’t understand anything, comment.

Here is the program :

       IDENTIFICATION DIVISION.                                                
       PROGRAM-ID. PRG1.                                                     
                                                                               

       ENVIRONMENT DIVISION.                                                   
                                                                               
       DATA DIVISION.                                                          
       WORKING-STORAGE SECTION.                                                
       01  ITEM-REC.                                                           
           05 IT-ITEMNO.                                                       
              10 IT-CLASS        PIC X(2).                                     
                 88 88-VAL-CLASS VALUE ’10’ ’20’ ’30’ ’40’ ’50’ ’60’.          
              10 IT-SR-NO        PIC X(4).                                     
           05 IT-DESC            PIC X(25).                                    
           05 IT-MONOPBAL        PIC 9(6).                                     
           05 IT-RCPTQTY         PIC 9(6).                                     
           05 IT-DESPQTY         PIC 9(6).                                     
           05 IT-CLOBAL          PIC 9(6).                                     
           05 IT-RATE            PIC 9(5)V99.                                  
           05 IT-CLOVALUE        PIC 9(6).                                     
           05 IT-PROCMY          PIC 9(6).                                     
                                                                               
       01  W02-CHOICE            PIC X(01) VALUE SPACES.                       
           88 88-VALID-CHOICE    VALUE ‘Y’ ‘y’ ‘N’ ‘n’.                        
           88 88-CHOICE-NO       VALUE ‘N’ ‘n’.                                
                                                                               
       PROCEDURE DIVISION.                                                     
       0000-MAIN.                                                              
           PERFORM 1000-ACPT-DATA  THRU 1000-EXIT.                             
           PERFORM 2000-DISP-REC   THRU 2000-EXIT.                             
           PERFORM 3000-CHOICE-NO  THRU 3000-EXIT.                             
           STOP RUN.                                                           

       1000-ACPT-DATA.                                                         
           MOVE SPACES TO IT-CLASS.                                            
                                                                               
           DISPLAY ‘ENTER ITEM CLASS’                                          
           ACCEPT IT-CLASS.                                                    
                                                                               
           IF 88-VAL-CLASS                                                     
              NEXT SENTENCE                                                    
           ELSE                                                                
              PERFORM 1000-ACPT-DATA THRU 3000-EXIT                            
                            UNTIL 88-VAL-CLASS.                                
                                                                               
           DISPLAY ‘ENTER ITEM SERIAL NO’                                      
           ACCEPT IT-SR-NO.                                                    
                                                                               
           DISPLAY ‘ENTER ITEM DESCRIPTION’                                    
           ACCEPT IT-DESC.                                                     
                                                                               
           DISPLAY ‘ENTER ITEM MONTHLY BALANCE QUANTITY’                       
           ACCEPT IT-MONOPBAL.                                                 
                                                                               
           DISPLAY ‘ENTER ITEM MONTH RECIEPT QUANTITY’                         
           ACCEPT IT-RCPTQTY.                                                  
                                                                               
           DISPLAY ‘ENTER ITEM DISPATCH QUANTITY’                              
           ACCEPT IT-DESPQTY.                                                  
                                                                               
           DISPLAY ‘ENTER ITEM CLOSING BALANCE’                                
           ACCEPT IT-CLOBAL.                                                   
                                                                               
                                                                               
           DISPLAY ‘ENTER ITEM RATE’                                           
           ACCEPT IT-RATE.                                                     
                                                                               
           MULTIPLY IT-CLOBAL BY IT-RATE GIVING IT-CLOVALUE.                   
           DISPLAY ‘ITEM CLOSING VALUE’                                        
           DISPLAY IT-CLOVALUE.                                                
                                                                               
           DISPLAY ‘ENTER ITEM PROCESSING MONTH’                               
           ACCEPT IT-PROCMY.                                                   
       1000-EXIT.                                                              
           EXIT.                                                               
                                                                               
       2000-DISP-REC.                                                          
           DISPLAY ‘ITEM NO : ‘ WITH NO ADVANCING                              
           DISPLAY IT-ITEMNO.                                                  
           DISPLAY ‘ITEM DESCRIPTION : ‘ WITH NO ADVANCING                     
           DISPLAY IT-DESC.                                                    
           DISPLAY ‘ITEM MONTHLY BALANCE QUANTITY : ‘ WITH NO ADVANCING        
           DISPLAY IT-MONOPBAL.                                                
           DISPLAY ‘ITEM MONTH RECIEPT QUANTITY : ‘ WITH NO ADVANCING          
           DISPLAY IT-RCPTQTY.                                                 
           DISPLAY ‘ITEM DISPATCH QUANTITY : ‘ WITH NO ADVANCING               
           DISPLAY IT-DESPQTY.                                                 
           DISPLAY ‘ITEM CLOSING QUANTITY : ‘ WITH NO ADVANCING                
           DISPLAY IT-CLOBAL.                                                  
           DISPLAY ‘ITEM RATE : ‘ WITH NO ADVANCING                            
           DISPLAY IT-RATE.                                                    
           DISPLAY ‘ITEM CLOSING VALUE : ‘ WITH NO ADVANCING                   
           DISPLAY IT-CLOBAL.                                                  
           DISPLAY ‘PROCESSING MONTH : ‘ WITH NO ADVANCING                     
           DISPLAY IT-PROCMY.                                                  
       2000-EXIT.                                                              
           EXIT.                                                               

       3000-CHOICE-NO.                                                         
           DISPLAY ‘DO YOU WANT TO INPUT MORE(Y/N)?’.                          
           ACCEPT W02-CHOICE.                                                  
           PERFORM 1000-ACPT-DATA THRU 3000-EXIT                               
                              UNTIL 88-CHOICE-NO.                              
       3000-EXIT.                                                              
           EXIT.                                                               
           STOP RUN.                                                           

Add Comment