ibm-information-center/dist/eclipse/plugins/i5OS.ic.rbam6_5.4.0.1/datearith.htm

98 lines
6.6 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="Example: Perform date arithmetic" />
<meta name="abstract" content="This program illustrates how to write a CL program that adds or subtracts a given number of days for the current system date." />
<meta name="description" content="This program illustrates how to write a CL program that adds or subtracts a given number of days for the current system date." />
<meta name="DC.subject" content="retrieving, program attribute, attribute, timing out" />
<meta name="keywords" content="retrieving, program attribute, attribute, timing out" />
<meta name="DC.Relation" scheme="URI" content="sampl.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="datearith" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Example: Perform date arithmetic</title>
</head>
<body id="datearith"><a name="datearith"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example: Perform date arithmetic</h1>
<div><p>This program illustrates how to write a CL program that adds or
subtracts a given number of days for the current system date.</p>
<div class="section"><div class="note"><span class="notetitle">Note:</span> Read the <a href="codedisclaimer.htm">Code license and disclaimer information</a> for important
legal information.</div>
<pre>/* Calculate new date from current system date. Pass negative */
/* number to subtract, positive number to add */
/* */
/* The first parameter is a character 8 date in YYYYMMDD format */
/* or the special value *CURRENT */
/* */
/* The second parameter is a decimal value for the number of days */
/* to adjust the first parameter by */
/* */
/* Test cases: CALL CALCDATE (*CURRENT -5) */
/* CALL CALCDATE (*CURRENT 5) */
/* CALL CALCDATE ('20030225' -90) */
/* CALL CALCDATE ('30020228' 90) */
/* */
/* There is no error handling in this sample, so make sure the */
/* input dates are valid (that is, no 20031325). The valid date */
/* date range is Oct 14 1582 to Dec 31 9999 */
/* */
PGM PARM(&amp;curdate &amp;DAYSTOCHG)
DCL VAR(&amp;CURDATE) TYPE(*CHAR) LEN(8)
DCL VAR(&amp;DAYSTOCHG) TYPE(*DEC) LEN(15 5)
DCL VAR(&amp;DATETIME) TYPE(*CHAR) LEN(17)
DCL VAR(&amp;DATE) TYPE(*CHAR) LEN(8)
DCL VAR(&amp;LILDATEINT) TYPE(*CHAR) LEN(4)
DCL VAR(&amp;LILDATEDEC) TYPE(*DEC) LEN(10 0)
DCL VAR(&amp;ERRCOD) TYPE(*CHAR) LEN(4) +
VALUE(X'00000000')
DCL VAR(&amp;MSG) TYPE(*CHAR) LEN(50)
IF COND(&amp;CURDATE = '*CURRENT') THEN(DO)
CALL PGM(QWCCVTDT) PARM('*CURRENT' ' ' '*YYMD' +
&amp;DATETIME &amp;ERRCOD) /* Get current system +
date and time in YYYYMMDD */
CHGVAR VAR(&amp;DATE) VALUE(%SST(&amp;DATETIME 1 8)) /* Get +
just the date portion */
ENDDO
ELSE CMD(CHGVAR VAR(&amp;DATE) VALUE(&amp;CURDATE)) /* +
Use the date provided */
CALLPRC PRC(CEEDAYS) PARM(&amp;DATE 'YYYYMMDD' +
&amp;LILDATEINT *OMIT) /* Get Lilian date for +
current date */
CHGVAR VAR(&amp;LILDATEDEC) VALUE(%BIN(&amp;LILDATEINT)) /* +
Get Lilian date in decimal format */
CHGVAR VAR(&amp;LILDATEDEC) VALUE(&amp;LILDATEDEC + +
&amp;DAYSTOCHG) /* Adjust specified number +
of days */
CHGVAR VAR(%BIN(&amp;LILDATEINT)) VALUE(&amp;LILDATEDEC) /* +
Get Lilian date in integer format */
CALLPRC PRC(CEEDATE) PARM(&amp;LILDATEINT 'YYYYMMDD' +
&amp;DATE *OMIT) /* Return calculated date in +
YYYYMMDD format */
CHGVAR VAR(&amp;MSG) VALUE('The new date is ' *CAT &amp;DATE)
SNDPGMMSG MSG(&amp;MSG) TOPGMQ(*EXT)
ENDPGM </pre>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="sampl.htm" title="These sample programs demonstrate the flexibility, simplicity, and versatility of CL programs.">Examples: CL programs and procedures</a></div>
</div>
</div>
</body>
</html>