|
Alan,
I covered that in a presentation I did at COMMON a few years ago.
Here's the source code:
P WeekDay B EXPORT
D WeekDay PI 32A
D InputDate D CONST DATFMT(*ISO)
D DS
D Days 70A INZ('Sunday +
D Monday +
D Tuesday +
D Wednesday +
D Thursday +
D Friday +
D Saturday')
D Day 10A Dim(7) Overlay(Days)
C TEST(E) InputDate
C If %ERROR
C Return 'Invalid Date'
C Endif
** Note: Date validation is done here to avoid -1 return value
C return Day(DayOfWeek(InputDate))
P WeekDay E
This is calling a slightly different GetDayOfWeek procedure. I called in
DayOfWeek so it'll have a different name from the one in the article.
The main difference is that this DAYOFWEEK procedure accepts a valid
date data-type as its input parameter whereas the article was concerned
with that strange CL date CYMD format.
Below is the modified DayOfWeek procedure.
P DayOfWeek B EXPORT
** Procedure interface for DayOfWeek function
D DayOfWeek PI 10I 0
D InputDate D CONST DATFMT(*ISO)
** Base date is based on calendar changed date
D BaseDate S D INZ(D'1582-10-14')
D nDayOfWeek S 10I 0
D nDays S 10I 0
C TEST(E) InputDate
C If %ERROR
C Return -1
C Endif
C InputDate SubDur BaseDate nDays:*DAYS
C CALLB 'CEEDYWK'
C Parm nDays
C Parm nDayofWeek
C return nDayOfWeek
P DayofWeek E
Bob Cozzi
www.rpgiv.com/seminars
-----Original Message-----
From: rpg400-l-admin@midrange.com [mailto:rpg400-l-admin@midrange.com]
On Behalf Of alan shore
Sent: Wednesday, August 21, 2002 9:35 AM
To: <"'rpg400-l@midrange.com'"
Subject: Dear all,
Dear all,
I came across an article by Robert Cozzi, Jr at
http://www.mcpressonline.com/mc/.5bfbb72f
titled "Moving to ILE CL" (and before anyone starts saying that I'm in
the wrong forum, this is an RPG question) I decided it was high time
for me to start delving into creating procedures, and binding and such.
Plus the end result of this article would give me the day of the week
for a particular date, which is something that I need for a project I'm
working on. So - killing 2 birds with one stone. Anyway, in the
article/procedures/programs, what is returned is a numeric value
representing the day of the week. What I want ot return is the actual
English representation. Monday, Tuesday etc. I attempted to implement
arrays, but ended up with not being able to create a module due to
compile errors. My question to the forum, how can arrays be implemented
in rpg procedures, if possible. I have included the RPG module that I
ended up with, and it should be apparent what array I am attempting to
implement. Much appreciated and thanks in advance.
*************** Beginning of data
*************************************
0001.00 H NOMAIN
0002.00
*----------------------------------------------------------------
0003.00 * GetWeekDay - Calculate the day of the week from a CL format
date 0004.00 * 0005.00
*----------------------------------------------------------------
0006.00 D GetWeekDay PR 10a
0007.00 D cymdDate 7A CONST
0008.00
0009.00 P GetWeekDay B Export
0010.00 * DAYOFWEEK
0011.00 D GetWeekDay PI 10A
0012.00 D cymdDate 7A CONST
0013.00 *
*
0014.00 D BaseDate S D DATFMT(*ISO)
INZ(D'1582-10-14')
0015.00 D Days S 10I 0
0016.00 D DayofWeek S 10I 0
0017.00 D DayofWeekAlpha S 1A
0018.00 D WeekDay S 10A
0019.00 D InputDate S D DATFMT(*ISO)
0020.00 *
0021.00
*----------------------------------------------------------------
0022.00 C *CYMD0 TEST(DE) cymdDate
0023.00 C If %ERROR
0024.00 C return 'Invalid '
0025.00 C endif
0026.00 C *CYMD0 MOVE cymdDate InputDate
0027.00 C InputDate Subdur BaseDate Days:*Days
0028.00 C CALLB 'CEEDYWK'
0029.00 C PARM Days
0030.00 C PARM DayofWeek
0031.00 C DayofWeek dsply
0032.00 C if DayofWeek=1
0033.00 C eval Weekday='Sunday '
0034.00 C else
0035.00 C if DayofWeek=2
0036.00 C eval Weekday='Monday '
0037.00 C else
0038.00 C if DayofWeek=3
0039.00 C eval Weekday='Tuesday '
0040.00 C else
0041.00 C if DayofWeek=4
0042.00 C eval Weekday='Wednesday'
0043.00 C else
0044.00 C if DayofWeek=5
0045.00 C eval Weekday='Thursday '
0046.00 C else
0047.00 C if DayofWeek=6
0048.00 C eval Weekday='Friday '
0049.00 C else
0050.00 C if DayofWeek=7
0051.00 C eval Weekday='Saturday '
0052.00 C else
0053.00 C eval WeekDay='Invalid '
0054.00 C endif
0055.00 C endif
0056.00 C endif
0057.00 C endif
0058.00 C endif
0059.00 C endif
0060.00 C endif
0061.00 C WeekDay dsply
0062.00 *
*
0063.00 C Return WeekDay
0064.00 P GetWeekDay E
_______________________________________________
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing
list To post a message email: RPG400-L@midrange.com To subscribe,
unsubscribe, or change list options,
visit: http://lists.midrange.com/cgi-bin/listinfo/rpg400-l
or email: RPG400-L-request@midrange.com
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.