Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 11

IDENTIFICATION DIVISION. PROGRAM-ID. SIMODATE. AUTHOR. SIMOTIME ENTERPRISES. ***************************************************************** * Copyright (C) 1987-2012 SimoTime Enterprises.

* * * * All rights reserved. Unpublished, all rights reserved under * * copyright law and international treaty. Use of a copyright * * notice is precautionary only and does not imply publication * * or disclosure. * * * * 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 expressed 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 * * * * 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. * 2004/01/26 Simmons, Mike added the check for 4000th year * increments are not leap years. * ***************************************************************** * 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 ' v06.03.03'. 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-2012 '. 05 C3 pic X(28) value '--- SimoTime Enterprises ---'.

05

C4 pic X(20) value ' All Rights Reserved'.

***************************************************************** 01 FIRST-TIME pic X value 'Y'. 01 01 01 01 IX-1 IX-2 WORK-N-7 DATE-WORK-ALPHA. 05 DATE-WORK-A-CCYY 05 DATE-WORK-A-MM 05 DATE-WORK-A-DD DATE-WORK-NUMERIC. 05 DATE-WORK-N-CCYY 05 DATE-WORK-N-MM 05 DATE-WORK-N-DD MONTH-TABLE-DATA. 05 filler 05 filler 05 filler 05 filler 05 filler 05 filler 05 filler 05 filler 05 filler 05 filler 05 filler 05 filler 05 filler 05 filler 05 filler 05 filler 05 filler 05 filler 05 filler 05 filler 05 filler 05 filler 05 filler 05 filler MONTH-TABLE 05 MONTH-VERBAGE 05 MONTH-COUNT-OF-DAYS JULIAN-DATE. 05 JULIAN-CCYY 05 JULIAN-DDD DATE-VERBAGE pic 999 pic 999 pic 9(7) pic X(4) pic X(2) pic X(2) pic 9(4) pic 9(2) pic 9(2) value 0. value 0. value 0. value SPACES. value SPACES. value SPACES. value 0. value 0. value 0. '. '. '. '. '. '. '. '. '. '. '. '.

01

01

01

pic X(10) value 'January pic X(10) value 'February pic X(10) value 'March pic X(10) value 'April pic X(10) value 'May pic X(10) value 'June pic X(10) value 'July pic X(10) value 'August pic X(10) value 'September pic X(10) value 'October pic X(10) value 'November pic X(10) value 'December pic 99 value 31. pic 99 value 28. pic 99 value 31. pic 99 value 30. pic 99 value 31. pic 99 value 30. pic 99 value 31. pic 99 value 31. pic 99 value 30. pic 99 value 31. pic 99 value 30. pic 99 value 31. redefines MONTH-TABLE-DATA. pic X(10) occurs 12 times. pic 99 occurs 12 times. pic 9(4) pic 9(3) pic X(18) value 0. value 0. value SPACES.

01

01

***************************************************************** 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 CCYY is divisible by 4 it is a leap year except if divisible by 100 then it is not a leap year except if divisible by 400 then it is a leap year except if divisible by 4000 then it is not a leap year. 1600,2000, etc... are leap years 1700,1800,1900 are not leap years 4000,8000,etc... are not leap years In other words the 100th year increments are not leap years with the exception that every 400th year increment is a leap year except every 4000th year is not 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 divide DATE-WORK-N-CCYY by 4000 giving WORK-N-7 multiply 4000 by WORK-N-7 if WORK-N-7 not = DATE-WORK-N-CCYY move 'Y' to STD-LEAP-YEAR-YN end-if 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. 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. ***************************************************************** * 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 COBOL Copy File


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

The following (PASSDATE.CPY) is the COBOL copy file that may be used when calling SimoDATE.
***************************************************************** * Data Structure or Pass Area used for calling SIMODATE. * ***************************************************************** * Copyright (C) 1987-2012 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 * ***************************************************************** * STD-REQUEST - This is an eight character data string * and should contain the following in * upper case. * EDITDATE, This keyword causes the date * routine (SIMODATE) to validate the date * and provide and edited text string plus * a julian date and more. * The calling program must provide 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 date routine. * * STD-RESPONSE - This is a four byte binary data string * and is used by the conversion routine to * pass a return code. If the date request * is successful the value in this data * string will be zero. * * STD-MESSAGE-TEXT - If a non-zero response occurs this field * will contain a short message. * * STD-GREGORIAN-4-EDIT - This is the input date field in * gregorian format that will be validated. * If the gregorian date does not pass the

* editing process a message will be posted * in the STD-MESSAGE-TEXT field and a * non-zero value of 16 will be placed in * the STD-RESPONSE field. SimoDATE is * somewhat flexible in accepting and * reformatting a gregorian date. For * example, the following are acceptable * and will be reformatted into the * STD-GREGORIAN-4-EDIT field. * 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 * delimiter are used. * ccyy/m/dd A mixing of single digit * usage is accepted. * * STD-DEBUG-INFO - This data string provides additional * debugging capability. This may be * helpful if changes are made to the date * routine. * * STD-LEAP-YEAR-YN - This field is used to identify a leap * year. A "Y" indicates the input date is * a leap year. An "N" indicates the input * year is not a leap year. * * STD-MONTH-VERBAGE - This field is used for the text of the * input month. For example, 1=January, * 2=February, etc. * * STD-MM-DAYS - This field is used for the number of * days in the input month. * * STD-GREGORIAN-DATE - This field is used for the gregorian * date in ccyymmdd format (all numeric * values). * * STD-JULIAN-DATE - This field is used for the julian date * in ccyyddd format. * * STD-DAYS-REMAINING - The number of days remaining in the * year. * * STD-DATE-VERBAGE - This field is used for the date in text * format. For example, 19991225 will * produce a text string of * December 25, 1999. * * STD-DATE-EDIT-BYTE - This field contains the character that * will be used to edit and format the * gregorian date. For example, this field * may contain a space, a dash, a slash, * etc... and will be used as the delimiter * between the year, month and day. * * STD-DATE-EDITED - This field if for the edited date using * the delimiter character from the * preceding field. For example, 19991225 * will produce 1999/12/25 if the delimiter * character is a slash. *****************************************************************

* 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-14. 15 STD-DATE-DAY pic X(3). 15 STD-DATE-DAY-2 pic X. 15 STD-DATE-EDITED pic X(10). *** PASSDATE - End-of-Copy File - - - - - - - - - - - PASSDATE * ***************************************************************** * 01

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. In the world of programming there are many ways to solve a problem. This documents and the links to other documents are intended to provide a choice of alternatives.

Software Agreement and Disclaimer


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

Permission to use, copy, modify and distribute this software, documentation or training material for any purpose requires a fee to be paid to SimoTime Enterprises. Once the fee is received by SimoTime the latest version of the software, documentation or training material 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, documentation or learning material for any purpose. It is provided "AS IS" without any expressed or implied warranty, including the implied warranties of merchantability, fitness for a particular purpose and noninfringement. 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, documentation or training material.

You might also like