**************************************************************    
      **************************************************************    
      *            MAIN PROGRAM SIMPLE                                
      **************************************************************    
      **************************************************************    
       IDENTIFICATION DIVISION.                                         
       PROGRAM-ID.    SIMPLE.                                         
      **************************************************************    
      *                                                            *    
      *  DEMO A NESTED PROGRAM THAT RETURNS A VALUE                *    
      *  WHICH IS THE DISTANCE BETWEEN TWO POINTS                  *    
      *  THE DISTANCE PROGRAM IS PASSED 5 PARMS                    *    
      *  X1 - THE FIRST POINT X-COORDINATE                         *    
      *  Y1 - THE FIRST POINT Y-COORDINATE                         *    
      *  X2 - THE SECOND POINT X-COORDINATE                        *    
      *  Y2 - THE SECOND POINT Y-COORDINATE                        *    
      *  RES - THE RESULT IS PASSED BACK AS A SIDE-EFFECT          *    
      *  NOT A FUNCTION, BUT THE SIDE-EFFECT HAS A SIMILAR EFFECT  *    
      *                                                            * 
      ************************************************************** 
                                                                     
       DATA DIVISION.                                                
                                                                     
       WORKING-STORAGE SECTION.                                      
      * SOME DATA POINTS - X AND Y COORDINATES                       
       01 X1        PIC S9(4)V99 PACKED-DECIMAL VALUE 0.0.           
       01 Y1        PIC S9(4)V99 PACKED-DECIMAL VALUE 0.0.           
       01 X2        PIC S9(4)V99 PACKED-DECIMAL VALUE 3.0.           
       01 Y2        PIC S9(4)V99 PACKED-DECIMAL VALUE 4.0.           
       01 RES       PIC S9(4)V99 PACKED-DECIMAL.                     
       01 RESE      PIC  Z(4).99.                                    
       01 X1E       PIC -Z(4).99.                                    
       01 X2E       PIC -Z(4).99.                                    
       01 Y1E       PIC -Z(4).99.                                    
       01 Y2E       PIC -Z(4).99.                                    
       01 X11       PIC S9(4)V99 PACKED-DECIMAL VALUE 22.52.          
       01 Y11       PIC S9(4)V99 PACKED-DECIMAL VALUE 12.88.          
       01 X22       PIC S9(4)V99 PACKED-DECIMAL VALUE 10.33.          
       01 Y22       PIC S9(4)V99 PACKED-DECIMAL VALUE 40.83.          
                                                                      
       PROCEDURE DIVISION.                                            
       010-MAIN.                                                      
           MOVE X1 TO X1E                                             
           MOVE X2 TO X2E                                             
           MOVE Y1 TO Y1E                                             
           MOVE Y2 TO Y2E                                             
           CALL 'DISTANCE' USING X1, Y1, X2, Y2, RES                  
           MOVE  RES TO RESE                                          
           DISPLAY "DISTANCE FROM (" X1E "," Y1E ") TO (" X2E "," Y2E 
                   ") = " RESE                                        
           MOVE X11 TO X1E                                            
           MOVE X22 TO X2E                                            
           MOVE Y11 TO Y1E                                              
           MOVE Y22 TO Y2E                                              
           CALL 'DISTANCE' USING X11, Y11, X22, Y22, RES                
           MOVE  RES TO RESE                                            
           DISPLAY "DISTANCE FROM (" X1E "," Y1E ") TO (" X2E "," Y2E   
                   ") = " RESE                                          
           GOBACK                                                       
           .                                                            
      **************************************************************    
      *            SUBPROGRAM DISTANCE                                  
      **************************************************************    
       IDENTIFICATION DIVISION.                                         
       PROGRAM-ID.    DISTANCE.                                         
      **************************************************************    
      *                                                            *    
      *  THE DISTANCE PROGRAM COMPUTES THE DISTANCE BETWEEN TWO    *    
      *  TWO POINTS IN THE PLANE                                   *    
      *  THE DISTANCE PROGRAM IS PASSED 5 PARMS                    *    
      *  A1 - THE FIRST POINT X-COORDINATE                         *    
      *  B1 - THE FIRST POINT Y-COORDINATE                         *    
      *  A2 - THE SECOND POINT X-COORDINATE                        *    
      *  B2 - THE SECOND POINT Y-COORDINATE                        *    
      *  RESULT - THE RESULT IS PASSED BACK AS A SIDE-EFFECT       *    
      *                                                            *    
      **************************************************************    
       DATA DIVISION.                                                   
                                                                        
       WORKING-STORAGE SECTION.                                         
       LINKAGE SECTION.                                                 
       01 A1        PIC S9(4)V99 PACKED-DECIMAL VALUE 22.52.            
       01 B1        PIC S9(4)V99 PACKED-DECIMAL VALUE 12.88.            
       01 A2        PIC S9(4)V99 PACKED-DECIMAL VALUE 10.33.            
       01 B2        PIC S9(4)V99 PACKED-DECIMAL VALUE 40.83.            
       01 RESULT    PIC S9(4)V99 PACKED-DECIMAL VALUE 40.83.            
                                                                        
       PROCEDURE DIVISION USING A1, B1, A2, B2, RESULT.                 
       START-DISTANCE.                                                  
           COMPUTE  RESULT = (((A2 - A1) ** 2) + ((B2 - B1) ** 2)) ** .5
           .                                                            
       END PROGRAM DISTANCE.                                            
      **************************************************************    
       END PROGRAM SIMPLE.                                            
      **************************************************************