Date Difference
 Elapsed Number of Days
http://www.simotime.com
When technology complements business    Copyright © 1987-2010  SimoTime Enterprises  All Rights Reserved
  Table of Contents Version 10.03.20 
  Introduction
 
  Programming Objectives
  Programming Input and Output
  Programming Requirements
  Programming Overview
  The Call Interface
  Sample CMD Members for Net Express
 
  CMD to Run the Demonstration Program
  CMD to Create a DATEDAYS File
  Sample JCL for OS/390 or Mainframe Express
 
  Run the Demonstration Program
  Create a DATEDIFF File
  The Demonstration Program
  The Difference-in-Days Program
  The Date Validation Program
  Summary
 
  Software Agreement and Disclaimer
  Downloads and Links to Similar Pages
  Comments or Suggestions
  About SimoTime

Introduction
(Next) (Previous) (Table-of-Contents)

This suite of programs provides an example of a techniques that may be used to calculate the number-of-days difference between two gregorian dates in the ccyymmdd format. Allowances have been made for leap years with the four-year and four-hundred-year cycles. Three COBOL programs are provided. The first program is a demonstration program that reads a file containing "DATEDIFF" records and calls the second COBOL program that calculates the number-of-days difference between the two dates. The third program does the date validation, formatting and conversion. The COBOL programs are written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370. A JCL member is provided to run the job as an MVS batch job on an IBM mainframe or as a project with Micro Focus Mainframe Express (MFE) running on a PC with Windows. This program may serve as a tutorial for new programmers and as a reference for experienced programmers. Additional information is provided in the Downloads and Links to Similar Pages section of this document.

Programming Objectives
(Next) (Previous) (Table-of-Contents)

The following is a list of the functions provided in this example.

1. Accept two Gregorian dates as input.
2. Validate the month for 1-12 and create text string (i.e. month 7 is July).
3. Determine if the year is a leap year.
4. Vaildate the day for 1-30, 1-31, 1-28 or 1-29 based on month and leap year.
5. Calculate the differnce between two dates in number of days.

Programming Input and Output
(Next) (Previous) (Table-of-Contents)

The following is an example of the contents of the input or date-diff file (SYSUT1).

DATEDIFF 19420124       19430522
DATEDIFF 20000401       20011225
DATEDIFF 20001315       20001689
DATEDIFF 2001/01/01     20010105
DATEDIFF 1999-01-32     1999-02-30
DATEDIFF 1999-02/15     2000-02/15
DATEDIFF 19420124       20011109
DATEDIFF 14920101       20010201

The following is an example of the output file (SYSUT2) based on the preceding date-diff file .

* CBLDAYC1 Date Processing Examples           v2.0.00   http://www.simotime.com
* CBLDAYC1 (C) Copyright 2002   SimoTime Enterprises, LLC   All Rights Reserved
* CBLDAYC1 ********************************************************************
* CBLDAYC1 DATEDIFF 19420124       19430522
* CBLDAYC1 Difference in days..... 0000483
* CBLDAYC1 ********************************************************************
* CBLDAYC1 DATEDIFF 20000401       20011225
* CBLDAYC1 Difference in days..... 0000633
* CBLDAYC1 ********************************************************************
* CBLDAYC1 DATEDIFF 20001315       20001689
* SIMODATE NOK for Date Value, MM not 1 through 12...
* SIMODATE Program is ABENDING...
* CBLDAYC1 NOK for Date Value, MM not 1 through 12...
* CBLDAYC1 ********************************************************************
* CBLDAYC1 DATEDIFF 2001/01/01     20010105
* CBLDAYC1 Difference in days..... 0000004
* CBLDAYC1 ********************************************************************
* CBLDAYC1 DATEDIFF 1999-01-32     1999-02-30
* SIMODATE NOK for Day Value, DD not within month range...
* SIMODATE Program is ABENDING...
* CBLDAYC1 NOK for Day Value, DD not within month range...
* CBLDAYC1 ********************************************************************
* CBLDAYC1 DATEDIFF 1999-02/15     2000-02/15
* CBLDAYC1 Difference in days..... 0000365
* CBLDAYC1 ********************************************************************
* CBLDAYC1 DATEDIFF 1995/03/15     1996/03/15
* CBLDAYC1 Difference in days..... 0000366
* CBLDAYC1 ********************************************************************
* CBLDAYC1 DATEDIFF 19420124       20011109
* CBLDAYC1 Difference in days..... 0021838
* CBLDAYC1 ********************************************************************
* CBLDAYC1 DATEDIFF 14920101       20010201
* CBLDAYC1 Difference in days..... 0185942
* CBLDAYC1 ********************************************************************
* CBLDAYC1 DATEDIFF 19951230       19960102
* CBLDAYC1 Difference in days..... 0000003
* CBLDAYC1 ********************************************************************
* CBLDAYC1 DATEDIFF 20031230       20040301
* CBLDAYC1 Difference in days..... 0000062
* CBLDAYC1 SYSUT1 line count is 0000011
* CBLDAYC1 is Complete...
* CBLBITC1 Thank you for using this sample by SimoTime Enterprises, LLC
* CBLBITC1 Please send comments or suggestions to helpdesk@simotime.com

Programming Requirements
(Next) (Previous) (Table-of-Contents)

This suite of samples programs will run on the following platforms.

1. Executes on Windows/2000, Windows/NT and Windows/XP using Micro Focus Net Express and the CMD file provided.
2. May be ported to run on the UNIX platforms supported by Micro Focus COBOL.
3. Executes on a mainframe with MVS or Windows/2000, Windows/NT and Windows/XP using Micro Focus Mainframe Express and the JCL file provided.

Programming Overview
(Next) (Previous) (Table-of-Contents)

The following diagram is an overview of how the demonstration program fits into the example. The demonstration program will read the date difference file (SYSUT1) that contains two differnt dates in each record, call the date routines and write the resulting deffierence in days to the output file (SYSUT2).

               
Entry Point
OS390 or MFE
     
Entry Point
Net Express
  Entry Points  
 
     
 
     
CBLDAYJ1
jcl
     
CBLDAYE1
cmd
  Start the date processing example  
 
     
 
     
IEFBR14
cmd
     
If Exist
stmt
  Delete previously created Date Info file  
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
SYSUT1
qsam
     
     
     
CBLDAYC1
cobol
     
     
     
SYSUT2
qsam
  Read the date difference file (SYSUT1), call the date routine and write the results to the output file (SYSUT2).  
   
 
     
     
     
CBLDAYC2
cobol
  Calculate difference in days..  
   
 
 
 
     
   
 
 
SIMODATE
cobol
  Validate, format and convert the date.  
   
EOJ
      End-of-Job  
               

The Call Interface
(Next) (Previous) (Table-of-Contents)

The following is the syntax for calling the date routine (CBLDAYC2.CBL).

        call 'CBLDAYC2' using DDF-PASS-AREA

The callable date routine will accept a gregorian date and provide a data structure in the following format. A copy file (CBLDAYB1.CPY) is provided with the following fields defined.

      *****************************************************************
      *          Data structure for calling CBLDAYC2 Routine          *
      *****************************************************************
      *         Copyright (C) 1987-2010 SimoTime Enterprises          *
      *                     All Rights Reserved                       *
      *****************************************************************
      *              Provided by SimoTime Enterprises                 *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************
       01  DDF-PASS-AREA.
           05  DDF-REQUEST             pic X(8).
           05  DDF-RESPONSE            pic 9(4).
           05  DDF-MESSAGE-TEXT        pic X(68).
           05  DDF-GREGORIAN-DATE-1    pic X(10).
           05  DDF-GREGORIAN-DATE-2    pic X(10).
           05  DDF-DIFFERENCE-IN-DAYS  pic 9(7).
           05  DDF-JULIAN-DATE-1       pic 9(7).
           05  DDF-JULIAN-DATE-1-VALUE redefines DDF-JULIAN-DATE-1.
               10  DDF-JULIAN-CCYY-1   pic 9(4).
               10  DDF-JULIAN-DAY-1    pic 9(3).
           05  DDF-DAYS-REMAINING-1    pic 9(3).
           05  DDF-JULIAN-DATE-2       pic 9(7).
           05  DDF-JULIAN-DATE-2-VALUE redefines DDF-JULIAN-DATE-2.
               10  DDF-JULIAN-CCYY-2   pic 9(4).
               10  DDF-JULIAN-DAY-2    pic 9(3).
           05  DDF-DAYS-REMAINING-2    pic 9(3).

The following table is an overview of the data strings used in the pass area.

Field Name Description
DDF-REQUEST This is an eight character data string and should contain the following in upper case.
DATEDIFF This keyword causes the date-difference program (CBLDAYC2) to calculate the difference-in-days between the primary and secondary date.
This calling program must provide one of the above as a request. Otherwise, a non-zero return code will be set in the following result field. This data string is not changed by the conversion routine.
DDF-RESPONSE This is a four byte binary data string and is used by the calculation program to pass a return code. If the calcualtion request is successful the value in this data string will be zero.
DDF-MESSAGE-TEXT If a non-zero response occurs this field will contain a short message.
DDF-GREGORIAN-DATE-1

This is the primary input date field in gregorian format that will be used by the calculation program. If the gregorian date does not pass the editing process a message will be posted in the DDF-MESSAGE-TEXT field and a non-zero value of 16 will be placed in the DDF-RESPONSE field. SimoDATE is somewhat flexible in accepting and reformatting a gregorian date. For example, the following are acceptable and will be reformatted.

ccyymmdd   This is the preferred format.
ccyy-mm-dd    Special characters may be used as separators.
ccyy-m-d   Single digit month and day values are acceptable when separators are used.
ccyy/m/dd   A mixing of single digit usage is accepted.
DDF-GREGORIAN-DATE-2

This is the secondary input date field in gregorian format that will be used by the calculation program. If the gregorian date does not pass the editing process a message will be posted in the DDF-MESSAGE-TEXT field and a non-zero value of 16 will be placed in the DDF-RESPONSE field. SimoDATE is somewhat flexible in accepting and reformatting a gregorian date. For example, the following are acceptable and will be reformatted.

ccyymmdd   This is the preferred format.
ccyy-mm-dd    Special characters may be used as separators.
ccyy-m-d   Single digit month and day values are acceptable when separators are used.
ccyy/m/dd   A mixing of single digit usage is accepted.
DDF-DIFFERENCE-IN-DAYS This field contains the number-of-days difference between the primary and secondary dates. The contents of this field is provided by the calculation program.
DDF-JULIAN-DATE-1 This field contains the julian date for the primary gregorian date. The contents of this field is provided by the calculation program.
DDF-DAYS-REMAINING-1 This field is used for the number-of-days remaining in the year specified as the primary date. The contents of this field is provided by the calculation program.
DDF-JULIAN-DATE-2 This field contains the julian date for the secondary gregorian date. The contents of this field is provided by the calculation program.
DDF-DAYS-REMAINING-2 This field is used for the number-of-days remaining in the year specified as the secondary date. The contents of this field is provided by the calculation program.

Sample CMD File
(Next) (Previous) (Table-of-Contents)

This sample suite of programs has two CMD members. The first CMD member will execute the demonstration program. The second CMD member will create a Date Difference file.

Sample CMD, Run the Demonstration Program
(Next) (Previous) (Table-of-Contents)

The following is the CMD required to run the demonstration program on a Personal Computer with Micro Focus Net Express.

@echo OFF
rem  * *******************************************************************
rem  *                   This program is provided by:                    *
rem  *                    SimoTime Enterprises, LLC                      *
rem  *           (C) Copyright 1987-2010 All Rights Reserved             *
rem  *                                                                   *
rem  *             Web Site URL:   http://www.simotime.com               *
rem  *                   e-mail:   helpdesk@simotime.com                 *
rem  * *******************************************************************
rem  *
rem  * Text   - Read a file of Date Records, calculate differences.
rem  * Author - SimoTime Enterprises
rem  * Date   - January 24, 1996
rem  *
rem  * The job will read an 80-byte file that contains two dates per record
rem  * record. The job will then calculate the difference between the two
rem  * dates by number of days...
rem  *
rem  * This set of programs will run on a Personal Computer with Windows
rem  * and Micro Focus Net Express.
rem  *
rem  *                     ************
rem  *                     * CblDayE1 *
rem  *                     ********cmd*
rem  *                          *
rem  *                     ************
rem  *                     * If Exist *
rem  *                     *******stmt*
rem  *                          *
rem  *    ************     ************     ************
rem  *    *  SYSUT1  *-----* CBLDATC1 *-----*  SYSUT2  *
rem  *    ********dat*     ********cbl*     ********dat*
rem  *                          *   *
rem  *                          *   *       ************
rem  *                          *   *-call--* SIMODATE *
rem  *                          *           ********cbl*
rem  *                          *
rem  *                     ************
rem  *                     *   EOJ    *
rem  *                     ************
rem  *
rem  * *******************************************************************
rem  * Step   1   Delete any previously created file...
rem  *
     set syslog=d:\simoNXE4\AN01\datawrk1\SYSLOGT1.TXT
rem  *
     SimoEXEC NOTE *******************************************************CblDayE1
     SimoEXEC NOTE Starting JobName CblDayE1
:DeleteQSAM
     SimoEXEC NOTE Identify JobStep DeleteQSAM
     set SYSUT1=d:\SimoNXE4\AN01\DataAsc1\DATEDIFF.TXT
     set SYSUT2=d:\SimoNXE4\AN01\DataWrk1\DATEDAYS.TXT
     if exist %SYSUT2% del %SYSUT2%
rem  *
rem  * *******************************************************************
rem  * Step   2   Edit input, create a new output file...
rem  *
:ExecuteDateDifferenceRoutine
     SimoEXEC NOTE Identify JobStep ExecuteDateDifferenceRoutine
     SimoEXEC EXEC CBLDAYC1
     SimoEXEC NOTE Finished JobName CblDayE1
pause

Sample CMD, Create a Date Card File
(Next) (Previous) (Table-of-Contents)

The following is the CMD that may be used to create a date-difference file.

@echo OFF
rem  * *******************************************************************
rem  *                   This program is provided by:                    *
rem  *                    SimoTime Enterprises, LLC                      *
rem  *           (C) Copyright 1987-2010 All Rights Reserved             *
rem  *                                                                   *
rem  *             Web Site URL:   http://www.simotime.com               *
rem  *                   e-mail:   helpdesk@simotime.com                 *
rem  * *******************************************************************
rem  *
rem  * Text   - Create a Sequential Data Set on disk using ECHO function.
rem  * Author - SimoTime Enterprises
rem  * Date   = January 24, 1996
rem  *
rem  * The first job step (DeleteQSAM) will delete any previously created
rem  * file. The second job step (CreateQSAM) will create a new file.
rem  *
rem  * This set of programs will run on a Personal Computer with Windows
rem  * and Micro Focus Net Express.
rem  *
     SimoEXEC NOTE  *******************************************************CblDayE2
     SimoEXEC NOTE  Starting JobName CblDayE2
     set syslog=d:\simoNXE4\AN01\datawrk1\SYSLOGT1.TXT
rem  *
rem  * *******************************************************************
rem  * Step   1 of 2  Delete previously created QSAM file...
rem  *
:DeleteQSAM
     SimoEXEC NOTE  Identify JobStep DeleteQSAM
     set SYSUT1=d:\SimoNXE4\AN01\DataAsc1\DATEDIFF.TXT
     if exist %SYSUT1% del %SYSUT1%
rem  *
rem  * *******************************************************************
rem  * Step   2 of 2  Create and populate a new QSAM file...
rem  *
:CreateQSAM
     SimoEXEC NOTE  Identify JobStep CreateQSAM
rem  *....1....:....2....:....3....:....4....:....5....:....6....:....7....:....8
echo DATEDIFF 19420124       19430522      >%SYSUT1%
echo DATEDIFF 20000401       20011225     >>%SYSUT1%
echo DATEDIFF 20001315       20001689     >>%SYSUT1%
echo DATEDIFF 2001/01/01     20010105     >>%SYSUT1%
echo DATEDIFF 1999-01-32     1999-02-30   >>%SYSUT1%
echo DATEDIFF 1999-02/15     2000-02/15   >>%SYSUT1%
echo DATEDIFF 1995/03/15     1996/03/15   >>%SYSUT1%
echo DATEDIFF 19420124       20011109     >>%SYSUT1%
echo DATEDIFF 14920101       20010201     >>%SYSUT1%
echo DATEDIFF 19951230       19960102     >>%SYSUT1%
echo DATEDIFF 20031230       20040301     >>%SYSUT1%
     SimoEXEC NOTE  Finished JobName CblDayE2
pause

Sample JCL
(Next) (Previous) (Table-of-Contents)

This sample suite of programs has two JCL members. The first JCL member will execute the demonstration program. The second JCL member will create a DATE-DIFF file.

Sample JCL, Run the Demonstration Program
(Next) (Previous) (Table-of-Contents)

The following is the JCL required to run the demonstration program on the mainframe or with Micro Focus Mainframe Express.

//CBLDAYJ1 JOB SIMOTIME,CLASS=1,MSGCLASS=0,NOTIFY=CSIP1
//* *******************************************************************
//*                   This program is provided by:                    *
//*                    SimoTime Enterprises, LLC                      *
//*           (C) Copyright 1987-2010 All Rights Reserved             *
//*                                                                   *
//*             Web Site URL:   http://www.simotime.com               *
//*                   e-mail:   helpdesk@simotime.com                 *
//* *******************************************************************
//*
//* Text   - Read a file of Date Cards, calculate difference in days.
//* Author - SimoTime Enterprises
//* Date   - January 24, 1996
//*
//* The job will read an 80-byte file that contains DATEDIFF
//* requests. The job will also write a file containing the results
//* of the date-difference calculation.
//*
//* This set of programs will run on a mainframe under MVS or on a
//* Personal Computer with Windows and Micro Focus Mainframe Express.
//*
//*                     ************
//*                     * CBLDAYJ1 *
//*                     ********jcl*
//*                          *
//*                     ************
//*                     * IEFBR14  *
//*                     ************
//*                          *
//*    ************     ************     ************
//*    *  SYSUT1  *-----* CBLDAYC1 *-----*  SYSUT2  *
//*    ************     ************     ************
//*                          *
//*                     ************
//*                     *   EOJ    *
//*                     ************
//*
//* *******************************************************************
//* Step   1   Delete any previously created file...
//*
//QSAMDELT EXEC PGM=IEFBR14
//QSYSUT2  DD  DSN=SIMOTIME.DATA.DDIFOUT,DISP=(MOD,DELETE,DELETE),
//             STORCLAS=MFI,
//             SPACE=(TRK,5),
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=800,DSORG=PS)
//*
//* *******************************************************************
//* Step   2   Edit input, create a new output file...
//*
//EXECDAT1 EXEC PGM=CBLDAYC1
//STEPLIB  DD  DSN=SIMOTIME.DEMO.LOADLIB1,DISP=SHR
//SYSUT1   DD  DSN=SIMOTIME.DATA.DDIFIN,DISP=SHR
//SYSUT2   DD  DSN=SIMOTIME.DATA.DDIFOUT,
//             DISP=(NEW,CATLG,DELETE),
//             STORCLAS=MFI,
//             SPACE=(TRK,5),
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=800,DSORG=PS)
//

Sample JCL, Create a Date-Diff File
(Next) (Previous) (Table-of-Contents)

The following is the JCL that may be used to create a date-diff file.

//CBLDAYJ2 JOB SIMOTIME,CLASS=1,MSGCLASS=0,NOTIFY=CSIP1
//* *******************************************************************
//*                   This program is provided by:                    *
//*                    SimoTime Enterprises, LLC                      *
//*           (C) Copyright 1987-2010 All Rights Reserved             *
//*                                                                   *
//*             Web Site URL:   http://www.simotime.com               *
//*                   e-mail:   helpdesk@simotime.com                 *
//* *******************************************************************
//*
//* Text   - Create a Sequential Data Set on disk using IEBGENER.
//* Author - SimoTime Enterprises
//* Date   - January 24, 1996
//*
//* The first job step (DELTQSAM) will delete any previously created
//* file. The second job step (CRTQNAME) will create a new file.
//*
//* This set of programs will run on a mainframe under MVS or on a
//* Personal Computer with Windows and Micro Focus Mainframe Express.
//*
//* *******************************************************************
//* Step   1   Delete any previously created file...
//*
//QSAMDELT EXEC PGM=IEFBR14
//SYSUT2   DD  DSN=SIMOTIME.DATA.DDIFIN,DISP=(MOD,DELETE,DELETE),
//             STORCLAS=MFI,
//             SPACE=(TRK,5),
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=800,DSORG=PS)
//*
//* *******************************************************************
//* Step   2   Create and populate a new QSAM file...
//*
//QCRTDIN1 EXEC PGM=IEBGENER
//SYSPRINT DD  SYSOUT=*
//SYSIN    DD  DUMMY
//* :....1....:....2....:....3....:....4....:....5....:....6....:....7....:....8
//SYSUT1   DD  *
DATEDIFF 19420124       19430522
DATEDIFF 20000401       20011225
DATEDIFF 20001315       20001689
DATEDIFF 2001/01/01     20010105
DATEDIFF 1999-01-32     1999-02-30
DATEDIFF 1999-02/15     2000-02/15
DATEDIFF 1995/03/15     1996/03/15
DATEDIFF 19420124       20011109
DATEDIFF 14920101       20010201
DATEDIFF 19951230       19960102
DATEDIFF 20031230       20040301
/*
//SYSUT2   DD  DSN=SIMOTIME.DATA.DDIFIN,
//             DISP=(NEW,CATLG,DELETE),
//             STORCLAS=MFI,
//             SPACE=(TRK,5),
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=800,DSORG=PS)
//

The Demonstration Program
(Next) (Previous) (Table-of-Contents)

The demonstration program will read the date difference file (SYSUT1), call the date routines and write the results to the output file (SYSUT2). The following is the source code listing for the demonstration program.

       IDENTIFICATION DIVISION.
       PROGRAM-ID.    CBLDAYC1.
       AUTHOR.        SIMOTIME ENTERPRISES.
      *****************************************************************
      * Copyright (C) 1987-2010 SimoTime Enterprises, LLC.            *
      *                                                               *
      * All rights reserved.  Unpublished, all rights reserved under  *
      * copyright law and international treaty.  Use of a copyright   *
      * notice is precautionary only does not imply publication or    *
      * disclosure.  This software contains confidential information  *
      * and trade secrets of SimoTime Enterprises, LLC. No part of    *
      * this program or publication may be reproduced, transmitted,   *
      * transcribed, stored in a retrieval system, or translated into *
      * any language or computer language, in any form or by any      *
      * means, electronic, mechanical, magnetic, optical, chemical,   *
      * manual or otherwise, without the prior written permission of: *
      *                                                               *
      * SimoTime Enterprises                                          *
      * 15 Carnoustie Drive                                           *
      * Novato, CA 94949-5849                                         *
      * 415.883.6565                                                  *
      *                                                               *
      * RESTRICTED RIGHTS LEGEND                                      *
      * Use, duplication, or disclosure by the Government is subject  *
      * to restrictions as set forth in subparagraph (c)(1)(ii) of    *
      * the Rights in Technical Data and Computer Software clause at  *
      * DFARS 52.227-7013 or subparagraphs (c)(1) and (2) of          *
      * Commercial  Computer Software - Restricted Rights  at 48      *
      * CFR 52.227-19, as applicable.  Contact SimoTime Enterprises,  *
      * 15 Carnoustie Drive, Novato, CA 94949-5849.                   *
      *                                                               *
      *****************************************************************
      *      This program is provided by SimoTime Enterprises         *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *                                                               *
      *****************************************************************
      *
      *****************************************************************
      * Source Member: CBLDAYC1.CBL
      * Copy Files:    CBLDAYB1.CPY
      * Calls to:      CBLDAYC2
      *                SIMODATE       via CBLDAYC2
      *****************************************************************
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT SYSUT1-FILE  ASSIGN to       SYSUT1
                  ORGANIZATION is SEQUENTIAL
                  ACCESS MODE  is SEQUENTIAL
                  FILE STATUS  is SYSUT1-STATUS.
           SELECT SYSUT2-FILE  ASSIGN to       SYSUT2
                  ORGANIZATION is SEQUENTIAL
                  ACCESS MODE  is SEQUENTIAL
                  FILE STATUS  is SYSUT2-STATUS.
      *
      *****************************************************************
       DATA DIVISION.
       FILE SECTION.
       FD  SYSUT1-FILE
           BLOCK CONTAINS 00800 CHARACTERS
           DATA RECORD    is SYSUT1-RECORD
           .
       01  SYSUT1-RECORD.
           05  SYSUT1-DATA-01.
               10  SYSUT1-KEYWORD  pic X(0008).
               10  SYSUT1-BLANK    pic X.
               10  SYSUT1-G1       pic X(10).
               10  filler          pic X(5).
               10  SYSUT1-G2       pic X(10).
               10  filler          pic X(46).
      *
       FD  SYSUT2-FILE
           BLOCK CONTAINS 00800 CHARACTERS
           DATA RECORD    is SYSUT2-RECORD
           .
       01  SYSUT2-RECORD.
           05  SYSUT2-DATA-01  pic X(00080).
      *
       WORKING-STORAGE SECTION.
       01  SIM-TITLE.
           05  T1 pic X(11) value '* CBLDAYC1 '.
           05  T2 pic X(34) value 'Difference Between Two Dates      '.
           05  T3 pic X(10) value ' v2.0.00  '.
           05  T4 pic X(24) value ' http://www.simotime.com'.
       01  SIM-COPYRIGHT.
           05  C1 pic X(11) value '* CBLDAYC1 '.
           05  C2 pic X(20) value 'Copyright 1987-2010 '.
           05  C3 pic X(28) value '  SimoTime Enterprises, LLC '.
           05  C4 pic X(20) value ' All Rights Reserved'.
      *
       01  SIM-THANKS-01.
           05  C1 pic X(11) value '* CBLDAYC1 '.
           05  C2 pic X(32) value 'Thank you for using this sample '.
           05  C3 pic X(32) value 'by SimoTime Enterprises, LLC    '.
           05  C4 pic X(04) value '    '.

       01  SIM-THANKS-02.
           05  C1 pic X(11) value '* CBLDAYC1 '.
           05  C2 pic X(32) value 'Please send comments or suggesti'.
           05  C3 pic X(32) value 'ons to helpdesk@simotime.com    '.
           05  C4 pic X(04) value '    '.
      *
       01  MESSAGE-BUFFER.
           05  MESSAGE-HEADER      pic X(11)   value '* CBLDAYC1 '.
           05  MESSAGE-TEXT.
               10  MESSAGE-TEXT-1  pic X(68)   value SPACES.
               10  MESSAGE-TEXT-2  pic X(188)  value SPACES.
      *
       01  SYSUT1-STATUS.
           05  SYSUT1-STATUS-L     pic X.
           05  SYSUT1-STATUS-R     pic X.
       01  SYSUT1-EOF              pic X       value 'N'.
       01  SYSUT1-OPEN-FLAG        pic X       value 'C'.
      *
       01  SYSUT2-STATUS.
           05  SYSUT2-STATUS-L     pic X.
           05  SYSUT2-STATUS-R     pic X.
       01  SYSUT2-EOF              pic X       value 'N'.
       01  SYSUT2-OPEN-FLAG        pic X       value 'C'.
      *
       01  IO-STATUS.
           05  IO-STAT1            pic X.
           05  IO-STAT2            pic X.
       01  TWO-BYTES.
           05  TWO-BYTES-LEFT      pic X.
           05  TWO-BYTES-RIGHT     pic X.
       01  TWO-BYTES-BINARY        redefines TWO-BYTES pic 9(4) comp.
      *
       01  APPL-RESULT             pic S9(9)   comp.
           88  APPL-AOK            value 0.
           88  APPL-EOF            value 16.
      *
       01  SYSUT1-TOTAL.
           05  filler      pic X(21)   value 'SYSUT1 line count is '.
           05  SYSUT1-LOC  pic 9(7)    value 0.
      *
      *****************************************************************
      * The following copy file of the pass area for calling SIMODATE,
      * the date editing routine.
      *****************************************************************
      *
       COPY CBLDAYB1.
      *
      *****************************************************************
       PROCEDURE DIVISION.
           perform Z-POST-COPYRIGHT
           perform SYSUT1-OPEN
           perform SYSUT2-OPEN
      *
           perform until SYSUT1-STATUS not = '00'
               perform SYSUT1-READ
               if  SYSUT1-STATUS = '00'
                   add 1 to SYSUT1-LOC
                   perform DATE-DIFFERENCE-CALCULATION
                   if  DDF-RESPONSE = 0
                       perform DATE-FUNCTION-DISPLAY
                   else
                       move DDF-MESSAGE-TEXT to MESSAGE-TEXT
                       perform Z-DISPLAY-CONSOLE-MESSAGE
                       move DDF-MESSAGE-TEXT to SYSUT2-DATA-01
                       perform SYSUT2-WRITE
                   end-if
               end-if
           end-perform
      *
           move SYSUT1-TOTAL to MESSAGE-TEXT
           perform Z-DISPLAY-CONSOLE-MESSAGE
      *
           if  APPL-EOF
               move 'is Complete...' to MESSAGE-TEXT
           else
               move 'is ABENDING...' to MESSAGE-TEXT
           end-if
           perform Z-DISPLAY-CONSOLE-MESSAGE
      *
           perform SYSUT2-CLOSE
           perform SYSUT1-CLOSE
           perform Z-THANK-YOU.
           GOBACK.
      *
      *****************************************************************
      * The following routines are in alphabetical sequence..         *
      *****************************************************************
      *
      *****************************************************************
       DATE-FUNCTION-DISPLAY.
           move 'Difference in days..... ' to MESSAGE-TEXT
           move DDF-DIFFERENCE-IN-DAYS     to MESSAGE-TEXT(25:7)
           move MESSAGE-TEXT               to SYSUT2-DATA-01
           perform Z-DISPLAY-CONSOLE-MESSAGE
           perform SYSUT2-WRITE
           exit.
      *
      *****************************************************************
       DATE-DIFFERENCE-CALCULATION.
           move all '*' to MESSAGE-TEXT-1
           perform Z-DISPLAY-CONSOLE-MESSAGE
           move all '*' to SYSUT2-DATA-01
           perform SYSUT2-WRITE

           move SYSUT1-DATA-01 to MESSAGE-TEXT
           perform Z-DISPLAY-CONSOLE-MESSAGE
           move SYSUT1-DATA-01 to SYSUT2-DATA-01
           perform SYSUT2-WRITE

           move 'DATEDIFF'           to DDF-REQUEST
           move SYSUT1-G1            to DDF-GREGORIAN-DATE-1
           move SYSUT1-G2            to DDF-GREGORIAN-DATE-2
           call 'CBLDAYC2' using DDF-PASS-AREA

           exit.
      *
      *****************************************************************
      * I/O ROUTINES FOR SYSUT1...                                    *
      *****************************************************************
       SYSUT1-CLOSE.
           add 8 to ZERO giving APPL-RESULT.
           close SYSUT1-FILE
           if  SYSUT1-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
           else
               add 12 to ZERO giving APPL-RESULT
           end-if
           if  APPL-AOK
               CONTINUE
           else
               move 'SYSUT1-Failure-CLOSE...' to MESSAGE-TEXT
               perform Z-DISPLAY-CONSOLE-MESSAGE
               move SYSUT1-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.
      *---------------------------------------------------------------*
       SYSUT1-READ.
           read SYSUT1-FILE
           if  SYSUT1-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
           else
               if  SYSUT1-STATUS = '10'
                   add 16 to ZERO giving APPL-RESULT
               else
                   add 12 to ZERO giving APPL-RESULT
               end-if
           end-if
           if  APPL-AOK
               CONTINUE
           else
               if  APPL-EOF
                   move 'Y' to SYSUT1-EOF
               else
                   move 'SYSUT1-Failure-GET...' to MESSAGE-TEXT
                   perform Z-DISPLAY-CONSOLE-MESSAGE
                   move SYSUT1-STATUS to IO-STATUS
                   perform Z-DISPLAY-IO-STATUS
                   perform Z-ABEND-PROGRAM
               end-if
           end-if
           exit.
      *---------------------------------------------------------------*
       SYSUT1-OPEN.
           add 8 to ZERO giving APPL-RESULT.
           open input SYSUT1-FILE
           if  SYSUT1-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
               move 'O' to SYSUT1-OPEN-FLAG
           else
               add 12 to ZERO giving APPL-RESULT
           end-if
           if  APPL-AOK
               CONTINUE
           else
               move 'SYSUT1-Failure-OPEN...' to MESSAGE-TEXT
               perform Z-DISPLAY-CONSOLE-MESSAGE
               move SYSUT1-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.
      *
      *****************************************************************
      * I/O ROUTINES FOR SYSUT2...                                    *
      *****************************************************************
       SYSUT2-WRITE.
           if  SYSUT2-OPEN-FLAG = 'C'
               perform SYSUT2-OPEN
           end-if
           write SYSUT2-RECORD
           if  SYSUT2-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
           else
               if  SYSUT2-STATUS = '10'
                   add 16 to ZERO giving APPL-RESULT
               else
                   add 12 to ZERO giving APPL-RESULT
               end-if
           end-if.
           if  APPL-AOK
               CONTINUE
           else
               move 'SYSUT2-Failure-WRITE...' to MESSAGE-TEXT
               perform Z-DISPLAY-CONSOLE-MESSAGE
               move SYSUT2-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.
      *---------------------------------------------------------------*
       SYSUT2-OPEN.
           add 8 to ZERO giving APPL-RESULT.
           open output SYSUT2-FILE
           if  SYSUT2-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
               move 'O' to SYSUT2-OPEN-FLAG
           else
               add 12 to ZERO giving APPL-RESULT
           end-if
           if  APPL-AOK
               CONTINUE
           else
               move 'SYSUT2-Failure-OPEN...' to MESSAGE-TEXT
               perform Z-DISPLAY-CONSOLE-MESSAGE
               move SYSUT2-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.
      *---------------------------------------------------------------*
       SYSUT2-CLOSE.
           add 8 to ZERO giving APPL-RESULT.
           close SYSUT2-FILE
           if  SYSUT2-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
               move 'C' to SYSUT2-OPEN-FLAG
           else
               add 12 to ZERO giving APPL-RESULT
           end-if
           if  APPL-AOK
               CONTINUE
           else
               move 'SYSUT2-Failure-CLOSE...' to MESSAGE-TEXT
               perform Z-DISPLAY-CONSOLE-MESSAGE
               move SYSUT2-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.
      *
      *****************************************************************
      * The following Z-Routines perform administrative tasks         *
      * for this program.                                             *
      *****************************************************************
      *
      *****************************************************************
      * ABEND the program, post a message to the console and issue    *
      * a STOP RUN.                                                   *
      *****************************************************************
       Z-ABEND-PROGRAM.
           if  MESSAGE-TEXT not = SPACES
               perform Z-DISPLAY-CONSOLE-MESSAGE
           end-if
           move 'PROGRAM-IS-ABENDING...'  to MESSAGE-TEXT
           perform Z-DISPLAY-CONSOLE-MESSAGE
           add 12 to ZERO giving RETURN-CODE
           STOP RUN
           exit.
      *
      *****************************************************************
      * Display CONSOLE messages...                                   *
      *****************************************************************
       Z-DISPLAY-CONSOLE-MESSAGE.
           if MESSAGE-TEXT-2 = SPACES
               display MESSAGE-BUFFER(1:79) upon console
           else
               display MESSAGE-BUFFER upon console
           end-if
           move all SPACES to MESSAGE-TEXT
           exit.
      *
      *****************************************************************
      * Display the file status bytes. This routine will display as   *
      * two digits if the full two byte file status is numeric. If    *
      * second byte is non-numeric then it will be treated as a       *
      * binary number.                                                *
      *****************************************************************
       Z-DISPLAY-IO-STATUS.
           if  IO-STATUS not NUMERIC
           or  IO-STAT1    = '9'
               subtract TWO-BYTES-BINARY from TWO-BYTES-BINARY
               move IO-STAT2 to TWO-BYTES-RIGHT
               display '* CBLDAYC1 File-Status-' IO-STAT1 '/'
                       TWO-BYTES-BINARY upon console
           else
               display '* CBLDAYC1 File-Status-' IO-STATUS upon console
           end-if
           exit.
      *
      *****************************************************************
       Z-POST-COPYRIGHT.
           display SIM-TITLE     upon console
           display SIM-COPYRIGHT upon console
           exit.
      *
      *****************************************************************
       Z-THANK-YOU.
           display SIM-THANKS-01 upon console
           display SIM-THANKS-02 upon console
           exit.
      *****************************************************************
      *      This example is provided by SimoTime Enterprises         *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************

The Difference-in-Days Program
(Next) (Previous) (Table-of-Contents)

The following is the source code listing for the program that calculates the difference-in-days between two dates.

       IDENTIFICATION DIVISION.
       PROGRAM-ID.    CBLDAYC2.
       AUTHOR.        SIMOTIME ENTERPRISES.
      *****************************************************************
      * Copyright (C) 1987-2010 SimoTime Enterprises, LLC.            *
      *                                                               *
      * All rights reserved.  Unpublished, all rights reserved under  *
      * copyright law and international treaty.  Use of a copyright   *
      * notice is precautionary only does not imply publication or    *
      * disclosure.  This software contains confidential information  *
      * and trade secrets of SimoTime Enterprises, LLC. No part of    *
      * this program or publication may be reproduced, transmitted,   *
      * transcribed, stored in a retrieval system, or translated into *
      * any language or computer language, in any form or by any      *
      * means, electronic, mechanical, magnetic, optical, chemical,   *
      * manual or otherwise, without the prior written permission of: *
      *                                                               *
      * SimoTime Enterprises                                          *
      * 15 Carnoustie Drive                                           *
      * Novato, CA 94949-5849                                         *
      * 415.883.6565                                                  *
      *                                                               *
      * RESTRICTED RIGHTS LEGEND                                      *
      * Use, duplication, or disclosure by the Government is subject  *
      * to restrictions as set forth in subparagraph (c)(1)(ii) of    *
      * the Rights in Technical Data and Computer Software clause at  *
      * DFARS 52.227-7013 or subparagraphs (c)(1) and (2) of          *
      * Commercial  Computer Software - Restricted Rights  at 48      *
      * CFR 52.227-19, as applicable.  Contact SimoTime Enterprises,  *
      * 15 Carnoustie Drive, Novato, CA 94949-5849.                   *
      *                                                               *
      *****************************************************************
      *      This program is provided by SimoTime Enterprises         *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *                                                               *
      *****************************************************************
      *
      *****************************************************************
      * Source Member: CBLDAYC2.CBL
      * Copy Files:    PASSDATE.CPY
      * Calls to:      SIMODATE
      *****************************************************************
      *
       DATA DIVISION.
      *
       WORKING-STORAGE SECTION.
       01  SIM-TITLE.
           05  T1 pic X(11) value '* CBLDAYC2 '.
           05  T2 pic X(34) value 'Calculate Date Differences in Days'.
           05  T3 pic X(10) value ' v2.0.00  '.
           05  T4 pic X(24) value ' http://www.simotime.com'.
       01  SIM-COPYRIGHT.
           05  C1 pic X(11) value '* CBLDAYC2 '.
           05  C2 pic X(20) value 'Copyright 1987-2010 '.
           05  C3 pic X(28) value '  SimoTime Enterprises, LLC '.
           05  C4 pic X(20) value ' All Rights Reserved'.
      *
       01  MESSAGE-BUFFER.
           05  MESSAGE-HEADER      pic X(11)   value '* CBLDAYC2 '.
           05  MESSAGE-TEXT.
               10  MESSAGE-TEXT-1  pic X(68)   value SPACES.
               10  MESSAGE-TEXT-2  pic X(188)  value SPACES.
      *
       01  APPL-RESULT             pic S9(9)   comp.
           88  APPL-AOK            value 0.
           88  APPL-EOF            value 16.
      *
       01  DIFF-OF-YEARS           pic 9(4)    value 0.
       01  DIFF-OF-DAYS            pic 9(7)    value 0.
       01  MULTIPLE-YEARS          pic 9(7)    value 0.
       01  NUMBER-OF-LEAP-YEARS    pic 9(7)    value 0.
       01  HOLD-REMAINDER-1        pic 9(7)    value 0.
       01  HOLD-REMAINDER-2        pic 9(7)    value 0.
       01  REGISTER-7-0            pic 9(7)    value 0.
      *
      *****************************************************************
      * The following copy file of the pass area for calling CBLDAYB1,
      * the date difference routine.
      *****************************************************************
      *
       COPY PASSDATE.
      *
       LINKAGE SECTION.
      *****************************************************************
      * The following copy file of the pass area for calling CBLDAYB1,
      * the date difference routine.
      *****************************************************************
      *
       COPY CBLDAYB1.
      *
      *****************************************************************
       PROCEDURE DIVISION using DDF-PASS-AREA.
      *
           initialize DDF-JULIAN-DATE-1
           initialize DDF-JULIAN-DATE-2
           initialize DDF-DIFFERENCE-IN-DAYS
      *
           perform DATE-DIFF-1-EDIT
      *
           if  DDF-RESPONSE = 0
               perform DATE-DIFF-2-EDIT
           end-if
      *
           if  DDF-RESPONSE = 0
               if  DDF-JULIAN-DATE-1 > DDF-JULIAN-DATE-2
                   add 20 to ZERO giving DDF-RESPONSE
                   move 'The primary date is > secondary date'
                     to DDF-MESSAGE-TEXT
               end-if
           end-if
      *
           if  DDF-RESPONSE = 0
               perform DATE-DIFF-CALCULATION
           end-if
      *
           GOBACK.
      *
      *****************************************************************
      * The following routines are in alphabetical sequence..         *
      *****************************************************************
      *
      *****************************************************************
       DATE-DIFF-1-EDIT.
           move DDF-GREGORIAN-DATE-1 to STD-GREGORIAN-4-EDIT
           perform DATE-FUNCTION-EDIT
           add STD-RESPONSE to ZERO giving DDF-RESPONSE
           if  STD-RESPONSE = 0
               move SPACES to DDF-MESSAGE-TEXT
               move STD-JULIAN-DATE to DDF-JULIAN-DATE-1
               move STD-DAYS-REMAINING to DDF-DAYS-REMAINING-1
           else
               move STD-MESSAGE-TEXT to DDF-MESSAGE-TEXT
           end-if
           exit.

      *****************************************************************
       DATE-DIFF-2-EDIT.
           move DDF-GREGORIAN-DATE-2 to STD-GREGORIAN-4-EDIT
           perform DATE-FUNCTION-EDIT
           add STD-RESPONSE to ZERO giving DDF-RESPONSE
           if  STD-RESPONSE = 0
               move SPACES to DDF-MESSAGE-TEXT
               move STD-JULIAN-DATE to DDF-JULIAN-DATE-2
               move STD-DAYS-REMAINING to DDF-DAYS-REMAINING-2
           else
               move STD-MESSAGE-TEXT to DDF-MESSAGE-TEXT
           end-if

           exit.
      *
      *****************************************************************
       DATE-DIFF-CALCULATION.
      *>   Calculate difference of years...
           subtract DDF-JULIAN-CCYY-1 from DDF-JULIAN-CCYY-2
             giving DIFF-OF-YEARS
      *>   Calculate difference of days...
           subtract DIFF-OF-DAYS from DIFF-OF-DAYS
           if  DIFF-OF-YEARS = 0
               subtract DDF-JULIAN-DAY-1 from DDF-JULIAN-DAY-2
                 giving DIFF-OF-DAYS
           else
               add DDF-DAYS-REMAINING-1 to DIFF-OF-DAYS
               add DDF-JULIAN-DAY-2     to DIFF-OF-DAYS
           end-if
      *>   Calculate for multiple years ignoring leap years
           if  DIFF-OF-YEARS > 1
               subtract 1 from DIFF-OF-YEARS giving MULTIPLE-YEARS
               multiply 365 by MULTIPLE-YEARS giving REGISTER-7-0
               add REGISTER-7-0 to DIFF-OF-DAYS
           end-if
      *>   Adjust difference of days for leap-year cycle...
           if  DIFF-OF-YEARS > 1
               perform DATE-DIFF-CALCULATION-LEAP
               add NUMBER-OF-LEAP-YEARS to DIFF-OF-DAYS
           end-if

           add DIFF-OF-DAYS to ZERO giving DDF-DIFFERENCE-IN-DAYS
           exit.
      *
      *****************************************************************
       DATE-DIFF-CALCULATION-LEAP.
      *>   Calculate years to next leap year...
           divide DDF-JULIAN-CCYY-1 by 4 giving MULTIPLE-YEARS
                  remainder HOLD-REMAINDER-1
      *>   Calculate number of years between primary and secondary...
           subtract 1 from DIFF-OF-YEARS giving MULTIPLE-YEARS
           add HOLD-REMAINDER-1 to MULTIPLE-YEARS
           divide MULTIPLE-YEARS by 4 giving NUMBER-OF-LEAP-YEARS
      *>   Adjust difference of days for 400-year leap-year cycle...
           perform DATE-DIFF-CALCULATION-LEAP-400
           exit.
      *
      *****************************************************************
       DATE-DIFF-CALCULATION-LEAP-400.
      *>   Calculate years to next leap year 400 exception...
           divide DDF-JULIAN-CCYY-1 by 400 giving MULTIPLE-YEARS
                  remainder HOLD-REMAINDER-2
      *>   Calculate number of years between primary and secondary...
           subtract 1 from DIFF-OF-YEARS giving MULTIPLE-YEARS
           add HOLD-REMAINDER-2 to MULTIPLE-YEARS
           divide MULTIPLE-YEARS by 400 giving REGISTER-7-0
           subtract REGISTER-7-0 from NUMBER-OF-LEAP-YEARS
      *>   Adjust difference of days for 4-year leap-year cycle...
           exit.
      *
      *****************************************************************
       DATE-FUNCTION-EDIT.
           move 'EDITDATE'           to STD-REQUEST
           move '-'                  to STD-DATE-EDIT-BYTE
           call 'SIMODATE' using STD-SIMODATE
           exit.
      *
      *****************************************************************
      * The following Z-Routines perform administrative tasks         *
      * for this program.                                             *
      *****************************************************************
      *
      *****************************************************************
      * ABEND the program, post a message to the console and issue    *
      * a STOP RUN.                                                   *
      *****************************************************************
       Z-ABEND-PROGRAM.
           if  MESSAGE-TEXT not = SPACES
               perform Z-DISPLAY-CONSOLE-MESSAGE
           end-if
           move 'PROGRAM-IS-ABENDING...'  to MESSAGE-TEXT
           perform Z-DISPLAY-CONSOLE-MESSAGE
           add 12 to ZERO giving RETURN-CODE
           STOP RUN
           exit.
      *
      *****************************************************************
      * Display CONSOLE messages...                                   *
      *****************************************************************
       Z-DISPLAY-CONSOLE-MESSAGE.
           if MESSAGE-TEXT-2 = SPACES
               display MESSAGE-BUFFER(1:79) upon console
           else
               display MESSAGE-BUFFER upon console
           end-if
           move all SPACES to MESSAGE-TEXT
           exit.
      *
      *****************************************************************
       Z-POST-COPYRIGHT.
           display SIM-TITLE     upon console
           display SIM-COPYRIGHT upon console
           exit.
      *****************************************************************
      *      This example is provided by SimoTime Enterprises         *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************

The Date Validation Program
(Next) (Previous) (Table-of-Contents)

The following is the source code listing for the date validation, formatting and conversion routine.

       IDENTIFICATION DIVISION.
       PROGRAM-ID.    SIMODATE.
       AUTHOR.        SIMOTIME ENTERPRISES.
      *****************************************************************
      * Copyright (C) 1987-2010 SimoTime Enterprises, LLC.            *
      *                                                               *
      * All rights reserved.  Unpublished, all rights reserved under  *
      * copyright law and international treaty.  Use of a copyright   *
      * notice is precautionary only does not imply publication or    *
      * disclosure.  This software contains confidential information  *
      * and trade secrets of SimoTime Enterprises, LLC. No part of    *
      * this program or publication may be reproduced, transmitted,   *
      * transcribed, stored in a retrieval system, or translated into *
      * any language or computer language, in any form or by any      *
      * means, electronic, mechanical, magnetic, optical, chemical,   *
      * manual or otherwise, without the prior written permission of: *
      *                                                               *
      * SimoTime Enterprises                                          *
      * 15 Carnoustie Drive                                           *
      * Novato, CA 94949-5849                                         *
      * 415.883.6565                                                  *
      *                                                               *
      * RESTRICTED RIGHTS LEGEND                                      *
      * Use, duplication, or disclosure by the Government is subject  *
      * to restrictions as set forth in subparagraph (c)(1)(ii) of    *
      * the Rights in Technical Data and Computer Software clause at  *
      * DFARS 52.227-7013 or subparagraphs (c)(1) and (2) of          *
      * Commercial  Computer Software - Restricted Rights  at 48      *
      * CFR 52.227-19, as applicable.  Contact SimoTime Enterprises,  *
      * 15 Carnoustie Drive, Novato, CA 94949-5849.                   *
      *                                                               *
      *****************************************************************
      *      This program is provided by SimoTime Enterprises         *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *                                                               *
      *****************************************************************
      *
      *****************************************************************
      * Source Member: SIMODATE.CBL
      * Copy Files:    PASSDATE.CPY
      *****************************************************************
      *
      * SIMODATE - edits and formats a gregorian date ccyymmdd. It also
      * provides additional information such as:
      *
      * 1. Identify leap year
      * 2. Provide a Julian Date
      * 3. Provide a text date - for example, January 1, 2001
      * 4. Provide days-in-month
      * and more...
      *
      * CALLING PROTOCOL
      * ----------------
      *    call 'SIMODATE' using STD-SIMODATE
      *
      *    01  STD-SIMODATE.
      *        05  STD-REQUEST             pic X(8).
      *        05  STD-RESPONSE            pic 9(4).
      *        05  STD-MESSAGE-TEXT        pic X(68).
      *        05  STD-GREGORIAN-4-EDIT    pic X(10).
      *        05  STD-EDITED-INFO.
      *            10  STD-DEBUG-INFO      pic X(8).
      *            10  STD-LEAP-YEAR-YN    pic X.
      *            10  STD-MONTH-VERBAGE   pic X(10).
      *            10  STD-MM-DAYS         pic 99.
      *            10  STD-GREGORIAN-DATE  pic 9(8).
      *            10  STD-JULIAN-DATE     pic 9(7).
      *            10  STD-JULIAN-VALUE    redefines STD-JULIAN-DATE.
      *                15  STD-JULIAN-CCYY pic 9(4).
      *                15  STD-JULIAN-DAY  pic 9(3).
      *            10  STD-DAYS-REMAINING  pic 9(3).
      *            10  STD-DATE-VERBAGE    pic X(18).
      *            10  STD-DATE-EDIT-BYTE  pic X.
      *            10  STD-DATE-EDITED     pic X(10).
      *
      *****************************************************************
      *
      * MAINTENANCE
      * -----------
      * 1997/02/27 Simmons, Created program.
      *
      *****************************************************************
      *
       DATA DIVISION.
       WORKING-STORAGE SECTION.
      *
      *****************************************************************
      *    Data-structure for Title and Copyright...
      *****************************************************************
       01  SIM-TITLE.
           05  T1 pic X(11) value '* SIMODATE '.
           05  T2 pic X(34) value 'Process a Date Request            '.
           05  T3 pic X(10) value ' v1.1.01  '.
           05  T4 pic X(24) value ' http://www.simotime.com'.
       01  SIM-COPYRIGHT.
           05  C1 pic X(11) value '* SIMODATE '.
           05  C2 pic X(20) value 'Copyright 1987-2010 '.
           05  C3 pic X(28) value '  SimoTime Enterprises, LLC '.
           05  C4 pic X(20) value ' All Rights Reserved'.

      *****************************************************************
       01  FIRST-TIME              pic X       value 'Y'.

       01  IX-1                    pic 999     value 0.
       01  IX-2                    pic 999     value 0.
       01  WORK-N-7                pic 9(7)    value 0.

       01  DATE-WORK-ALPHA.
           05  DATE-WORK-A-CCYY    pic X(4)    value SPACES.
           05  DATE-WORK-A-MM      pic X(2)    value SPACES.
           05  DATE-WORK-A-DD      pic X(2)    value SPACES.

       01  DATE-WORK-NUMERIC.
           05  DATE-WORK-N-CCYY    pic 9(4)    value 0.
           05  DATE-WORK-N-MM      pic 9(2)    value 0.
           05  DATE-WORK-N-DD      pic 9(2)    value 0.

       01  MONTH-TABLE-DATA.
           05  filler              pic X(10)   value 'January   '.
           05  filler              pic X(10)   value 'February  '.
           05  filler              pic X(10)   value 'March     '.
           05  filler              pic X(10)   value 'April     '.
           05  filler              pic X(10)   value 'May       '.
           05  filler              pic X(10)   value 'June      '.
           05  filler              pic X(10)   value 'July      '.
           05  filler              pic X(10)   value 'August    '.
           05  filler              pic X(10)   value 'September '.
           05  filler              pic X(10)   value 'October   '.
           05  filler              pic X(10)   value 'November  '.
           05  filler              pic X(10)   value 'December  '.
           05  filler              pic 99      value 31.
           05  filler              pic 99      value 28.
           05  filler              pic 99      value 31.
           05  filler              pic 99      value 30.
           05  filler              pic 99      value 31.
           05  filler              pic 99      value 30.
           05  filler              pic 99      value 31.
           05  filler              pic 99      value 31.
           05  filler              pic 99      value 30.
           05  filler              pic 99      value 31.
           05  filler              pic 99      value 30.
           05  filler              pic 99      value 31.
       01  MONTH-TABLE             redefines MONTH-TABLE-DATA.
           05  MONTH-VERBAGE       pic X(10)   occurs 12 times.
           05  MONTH-COUNT-OF-DAYS pic 99      occurs 12 times.

       01  JULIAN-DATE.
           05  JULIAN-CCYY         pic 9(4)    value 0.
           05  JULIAN-DDD          pic 9(3)    value 0.

       01  DATE-VERBAGE            pic X(18)   value SPACES.

      *****************************************************************
       01  MESSAGE-BUFFER.
           05  MESSAGE-HEADER      pic X(11)   value '* SIMODATE '.
           05  MESSAGE-TEXT        pic X(68).

      *****************************************************************
       LINKAGE SECTION.
       COPY PASSDATE.

      *****************************************************************
      * Mainline processing routine...
      *****************************************************************
       PROCEDURE DIVISION using STD-SIMODATE.

           add 20 to ZERO giving STD-RESPONSE
           move SPACES to STD-MESSAGE-TEXT

           if  FIRST-TIME not = 'N'
               if  STD-DEBUG-INFO = 'DEBUG   '
               or  STD-DEBUG-INFO = 'TRACE   '
                   perform Z-POST-COPYRIGHT
               end-if
               move 'N' to FIRST-TIME
           end-if

           evaluate STD-REQUEST
               when 'EDITDATE' perform EDIT-DATE-FUNCTION
               when OTHER      add 16 to ZERO giving RETURN-CODE
                               move '0016' to STD-RESPONSE
           end-evaluate

           if  STD-RESPONSE = 20
           and STD-MESSAGE-TEXT = SPACES
               subtract STD-RESPONSE from STD-RESPONSE
           end-if

           GOBACK.

      *****************************************************************
      * The following routines are in alphabetical order...           *
      *****************************************************************
      *
      *****************************************************************
      *>   This routine will accept dates in the following formats
      *>     ccyymmdd
      *>     ccyy/mm/dd
      *>     ccyy-mm-dd
      *>     ccyy.mm.dd
      *****************************************************************
       EDIT-DATE-FUNCTION.
           move SPACES to DATE-WORK-ALPHA
           add 1 to ZERO giving IX-2
           move STD-GREGORIAN-4-EDIT to DATE-WORK-A-CCYY
           if  DATE-WORK-A-CCYY not NUMERIC
               move 'NOK for Date Value, CCYY not numeric value...'
                 to MESSAGE-TEXT
               perform Z-POST-ABEND
           else
               add 4 to IX-2
           end-if
      *>   --------------------------------------------------------
      *>   Possible non-numeric separator between CCYY and MM
           if  STD-GREGORIAN-4-EDIT(IX-2:1) not NUMERIC
               add 1 to IX-2
           end-if
           move STD-GREGORIAN-4-EDIT(IX-2:2) to DATE-WORK-A-MM
           if  DATE-WORK-A-MM not NUMERIC
               move DATE-WORK-A-MM(1:1) to DATE-WORK-A-MM(2:1)
               move ZERO                to DATE-WORK-A-MM(1:1)
               add 1 to IX-2
           else
               add 2 to IX-2
           end-if
      *>   --------------------------------------------------------
      *>   Possible non-numeric separator between MM and DD
           if  STD-GREGORIAN-4-EDIT(IX-2:1) not NUMERIC
               add 1 to IX-2
           end-if
           move STD-GREGORIAN-4-EDIT(IX-2:2) to DATE-WORK-A-DD
           if  DATE-WORK-A-DD not NUMERIC
               move DATE-WORK-A-DD(1:1) to DATE-WORK-A-DD(2:1)
               move ZERO                to DATE-WORK-A-DD(1:1)
           end-if
           if  DATE-WORK-A-MM not NUMERIC
               move 'NOK for Date Value, MM not numeric value...'
                 to MESSAGE-TEXT
               perform Z-POST-ABEND
           end-if
           if  DATE-WORK-A-DD not NUMERIC
               move 'NOK for Date Value, DD not numeric value...'
                 to MESSAGE-TEXT
               perform Z-POST-ABEND
           end-if
           move 'WIP for Date Function...' to MESSAGE-TEXT
           perform Z-POST-CONDITIONAL-TRACE
           move DATE-WORK-ALPHA to DATE-WORK-NUMERIC
      *>   ------------------------------------------------------------
      *>   Determine if a leap year, it is not true that every fourth
      *>   year is a leap year.
      *>
      *>   if  YYYY is divisible by 4 it is a possible leap year and
      *>       additional checking is required.
      *>
      *>   if  YYYY is divisible by 100 and not divisible by 400
      *>       then it is not a leap year.
      *>
      *>   In other words the 100th year increments are not leap
      *>   years with the exception that every 400th year increment
      *>   is a leap year.
      *>
           move 'N' to STD-LEAP-YEAR-YN
           add 28 to ZERO giving MONTH-COUNT-OF-DAYS(2)
           move 'WIP for Date, not a Leap Year...' to MESSAGE-TEXT
           divide DATE-WORK-N-CCYY by 4 giving WORK-N-7
           multiply 4 by WORK-N-7
           if  WORK-N-7 = DATE-WORK-N-CCYY
               divide DATE-WORK-N-CCYY by 100 giving WORK-N-7
               multiply 100 by WORK-N-7
               if  WORK-N-7  = DATE-WORK-N-CCYY
                   divide DATE-WORK-N-CCYY by 400 giving WORK-N-7
                   multiply 400 by WORK-N-7
                   if  WORK-N-7 = DATE-WORK-N-CCYY
                       move 'Y' to STD-LEAP-YEAR-YN
                   end-if
               else
                   move 'Y' to STD-LEAP-YEAR-YN
               end-if
               if  STD-LEAP-YEAR-YN = 'Y'
                   move 'Y' to STD-LEAP-YEAR-YN
                   add 29 to ZERO giving MONTH-COUNT-OF-DAYS(2)
                   move 'WIP for Date, it is a Leap Year...'
                     to MESSAGE-TEXT
               end-if
           end-if
           perform Z-POST-CONDITIONAL-TRACE
      *>   ------------------------------------------------------------
      *>   Test for a valid month...
           if  DATE-WORK-N-MM > 0
           and DATE-WORK-N-MM < 13
               move 'WIP for Date, month is ?????????' to MESSAGE-TEXT
               move MONTH-VERBAGE(DATE-WORK-N-MM)
                 to MESSAGE-TEXT(24:10)
               perform Z-POST-CONDITIONAL-TRACE
               move MONTH-VERBAGE(DATE-WORK-N-MM)
                 to MESSAGE-TEXT(24:10)
               move MONTH-VERBAGE(DATE-WORK-N-MM) to STD-MONTH-VERBAGE
           else
               move 'NOK for Date Value, MM not 1 through 12...'
                 to MESSAGE-TEXT
               perform Z-POST-ABEND

           end-if
      *>   ------------------------------------------------------------
      *>   Test for a valid day...
           if  DATE-WORK-N-DD > 0
           and DATE-WORK-N-DD < MONTH-COUNT-OF-DAYS(DATE-WORK-N-MM) + 1
               move 'WIP for Date, month has ?? days' to MESSAGE-TEXT
               move MONTH-COUNT-OF-DAYS(DATE-WORK-N-MM)
                 to MESSAGE-TEXT(25:2)
               perform Z-POST-CONDITIONAL-TRACE
           else
               move 'NOK for Day Value, DD not within month range...'
                 to MESSAGE-TEXT
               perform Z-POST-ABEND
           end-if
           move MONTH-COUNT-OF-DAYS(DATE-WORK-N-MM)
             to STD-MM-DAYS

      *>   ------------------------------------------------------------
      *>   Create text version of the date. This is a sixteen character
      *>   field (DATE-VERBAGE) that is left-justified in the following
      *>   format...      month dd, ccyy
           move 'WIP for Date, ' to MESSAGE-TEXT
           move MONTH-VERBAGE(DATE-WORK-N-MM) to DATE-VERBAGE
           subtract IX-2 from IX-2
           inspect DATE-VERBAGE tallying IX-2
                   for CHARACTERS before SPACE
           add 2 to IX-2
           if  DATE-WORK-A-DD(1:1) = '0'
               move DATE-WORK-A-DD(2:1) to DATE-VERBAGE(IX-2:1)
               add 1 to IX-2
           else
               move DATE-WORK-A-DD to DATE-VERBAGE(IX-2:2)
               add 2 to IX-2
           end-if
           move ', ' to DATE-VERBAGE(IX-2:2)
           add 2 to IX-2
           move DATE-WORK-N-CCYY to DATE-VERBAGE(IX-2:4)

           move DATE-VERBAGE to MESSAGE-TEXT(15:18)
           perform Z-POST-CONDITIONAL-TRACE

           move DATE-VERBAGE to STD-DATE-VERBAGE

      *>   ------------------------------------------------------------
      *>   Create numeric date for display or print...
           move DATE-WORK-A-CCYY   to STD-DATE-EDITED
           move STD-DATE-EDIT-BYTE to STD-DATE-EDITED(5:1)
           move DATE-WORK-A-MM     to STD-DATE-EDITED(6:2)
           move STD-DATE-EDIT-BYTE to STD-DATE-EDITED(8:1)
           move DATE-WORK-A-DD     to STD-DATE-EDITED(9:2)
           move DATE-WORK-NUMERIC  to STD-GREGORIAN-DATE

      *>   ------------------------------------------------------------
      *>   Determine Julian Date...
           move 'WIP for Date, Julian is CCYYDDD' to MESSAGE-TEXT
           move DATE-WORK-N-CCYY to JULIAN-CCYY
           add DATE-WORK-N-DD to ZERO giving JULIAN-DDD
           add 1 to ZERO giving IX-2
           perform until IX-2 = DATE-WORK-N-MM
                      or IX-2 > 12
               add MONTH-COUNT-OF-DAYS(IX-2) to JULIAN-DDD
               add 1 to IX-2
           end-perform
           move JULIAN-DATE to MESSAGE-TEXT(25:7)
           perform Z-POST-CONDITIONAL-TRACE
           move JULIAN-DATE to STD-JULIAN-DATE

      *>   ------------------------------------------------------------
      *>   Calculate remaining days in the year...
           if  STD-LEAP-YEAR-YN = 'Y'
               subtract STD-JULIAN-DAY from 366
                 giving STD-DAYS-REMAINING
           else
               subtract STD-JULIAN-DAY from 365
                 giving STD-DAYS-REMAINING
           end-if

      *>   ------------------------------------------------------------
      *>   Determine AOK for Date Message...
           move 'AOK for Date Function...' to MESSAGE-TEXT
           perform Z-POST-CONDITIONAL-TRACE
           exit.

      *****************************************************************
      *    Display Copyright or Program Message...
      *    ------------------------------------------------------------
       Z-POST-ABEND.
           if  MESSAGE-TEXT not = SPACES
               move MESSAGE-TEXT to STD-MESSAGE-TEXT
               perform Z-POST-MESSAGE
           end-if
           move 'Program is ABENDING...' to MESSAGE-TEXT
           perform Z-POST-MESSAGE
           add 16 to ZERO giving STD-RESPONSE
           GOBACK
           exit.

       Z-POST-COPYRIGHT.
           display SIM-TITLE     upon console
           display SIM-COPYRIGHT upon console
           exit.

       Z-POST-MESSAGE.
           display MESSAGE-BUFFER upon console
           move SPACES to MESSAGE-TEXT
           exit.

       Z-POST-CONDITIONAL-TRACE.
           if  STD-DEBUG-INFO = 'DEBUG   '
           or  STD-DEBUG-INFO = 'TRACE   '
               display MESSAGE-BUFFER upon console
           end-if
           move SPACES to MESSAGE-TEXT
           exit.

Summary
(Next) (Previous) (Table-of-Contents)

The purpose of this document is to assist as a tutorial for new programmers or as a quick reference for experienced programmers. This suite of programs provides an example of a techniques that may be used to calculate the number-of-days difference between two gregorian dates in the ccyymmdd format. Allowances have been made for leap years with the four-year and four-hundred-year cycles.

Software Agreement and Disclaimer
(Next) (Previous) (Table-of-Contents)

Permission to use, copy, modify and distribute this software for any non-commercial purpose and without fee is hereby granted, provided the SimoTime copyright notice appear on all copies of the software. The SimoTime name or Logo may not be used in any advertising or publicity pertaining to the use of the software without the written permission of SimoTime Enterprises.

Permission to use, copy, modify and distribute this software for any commercial purpose requires a fee to be paid to Simotime Enterprises. Once the fee is received by SimoTime the latest version of the software will be delivered and a license will be granted for use within an enterprise, provided the SimoTime copyright notice appear on all copies of the software. The SimoTime name or Logo may not be used in any advertising or publicity pertaining to the use of the software without the written permission of SimoTime Enterprises.

SimoTime Enterprises makes no warranty or representations about the suitability of the software for any purpose. It is provided "AS IS" without any express or implied warranty, including the implied warranties of merchantability, fitness for a particular purpose and non-infringement. SimoTime Enterprises shall not be liable for any direct, indirect, special or consequential damages resulting from the loss of use, data or projects, whether in an action of contract or tort, arising out of or in connection with the use or performance of this software.

If you have any questions, suggestions or comments please call or send an e-mail to: helpdesk@simotime.com

Downloads and Links to Similar Pages
(Next) (Previous) (Table-of-Contents)

You may download this example at http://www.simotime.com/sim4dzip.htm#COBOLDateDifference or view the complete list of SimoTime Examples at http://www.simotime.com/sim4dzip.htm .

Note: You must be attached to the Internet to download a Z-Pack or view the list.

Check out   The Date Processing  for editing, validating, formatting and converting dates.

Check out   The COBOL Connection  in the SimoTime Library for more examples of mainframe COBOL techniques and sample code.

Check out   The JCL Connection  in the SimoTime Library for more mainframe JCL examples.

Check out   The SimoTime Library   for a wide range of topics for Programmers, Project Managers and Software Developers.

To review all the information available on this site start at   The SimoTime Home Page  .

The   Download Zipped Examples   may be used to download this example or other examples.

For more information about Micro Focus Mainframe Express refer to   http://www.microfocus.com  .

Comments or Suggestions
(Next) (Previous) (Table-of-Contents)

If you have any questions, suggestions or comments please call or send an e-mail to: helpdesk@simotime.com

About SimoTime Enterprises
(Next) (Previous) (Table-of-Contents)

Founded in 1987, SimoTime Enterprises is a privately owned company. We specialize in the creation and deployment of business applications using new or existing technologies and services. We have a team of individuals that understand the broad range of technologies being used in today's environments. This includes the smallest thin client using the Internet and the very large mainframe systems. There is more to making the Internet work for your company's business than just having a nice looking WEB site. It is about combining the latest technologies and existing technologies with practical business experience. It's about the business of doing business and looking good in the process. Quite often, to reach larger markets or provide a higher level of service to existing customers it requires the newer Internet technologies to work in a complementary manner with existing corporate mainframe systems. Whether you want to use the Internet to expand into new market segments or as a delivery vehicle for existing business functions simply give us a call or check the web site at http://www.simotime.com


Return-to-Top
Copyright © 1987-2010  SimoTime Enterprises  All Rights Reserved
When technology complements business
http://www.simotime.com