RPGLE - Determine day of the week - subprocedure
* Prototype for subprocedure
D DayOfWeek PR 1 0
D InputDate D Datfmt(*ISO)
* Days of the week name table - note ield names are required
D NameData DS
D 9 Inz('Monday')
D 9 Inz('Tuesday')
D 9 Inz('Wednesday')
D 9 Inz('Thursday')
D 9 Inz('Friday')
D 9 Inz('Saturday')
D 9 Inz('Sunday')
* Define the array as an overlay of the DS name
D Name 9 Dim(7) Overlay(NameData)
D DayName S 9
D WorkDate S D DatFmt(*ISO)
* Program input parameter
C *Entry PList
C Parm WorkDate
* Using DayofWeek, initialize DayName with table Name 5
C Eval DayName = Name(DayOfWeek(WorkDate))
* displaying result
C DayName Dsply
* Terminate Program
C Eval *InLR = *On
* SubProcedure: DayOfWeek (Day of the Week)
* The subprocedure accepts a valid date (format *ISO) and returns
* a number (1 digit) representing the day of the week
* (Monday = 1, ... , Sunday = 7) 2
P DayOfWeek B
* procedure interface definition 3
D DayOfWeek PI 1 0
D WorkDate D
D AnySunday C D'1999-06-13'
D WorkNum S 7 0
D WorkDay S 1 0
C WorkDate Subdur AnySunday WorkNum:*D
C WorkNum Div 7 WorkNum
C Mvr WorkDay
* Returning result to the calling procedure
C If WorkDay < 1
C Return WorkDay + 7
C Else
C Return WorkDay
C Endif
* Procedure definition end marker 2
P E
* Prototype for subprocedure
D DayOfWeek PR 1 0
D InputDate D Datfmt(*ISO)
* Days of the week name table - note ield names are required
D NameData DS
D 9 Inz('Monday')
D 9 Inz('Tuesday')
D 9 Inz('Wednesday')
D 9 Inz('Thursday')
D 9 Inz('Friday')
D 9 Inz('Saturday')
D 9 Inz('Sunday')
* Define the array as an overlay of the DS name
D Name 9 Dim(7) Overlay(NameData)
D DayName S 9
D WorkDate S D DatFmt(*ISO)
* Program input parameter
C *Entry PList
C Parm WorkDate
* Using DayofWeek, initialize DayName with table Name 5
C Eval DayName = Name(DayOfWeek(WorkDate))
* displaying result
C DayName Dsply
* Terminate Program
C Eval *InLR = *On
* SubProcedure: DayOfWeek (Day of the Week)
* The subprocedure accepts a valid date (format *ISO) and returns
* a number (1 digit) representing the day of the week
* (Monday = 1, ... , Sunday = 7) 2
P DayOfWeek B
* procedure interface definition 3
D DayOfWeek PI 1 0
D WorkDate D
D AnySunday C D'1999-06-13'
D WorkNum S 7 0
D WorkDay S 1 0
C WorkDate Subdur AnySunday WorkNum:*D
C WorkNum Div 7 WorkNum
C Mvr WorkDay
* Returning result to the calling procedure
C If WorkDay < 1
C Return WorkDay + 7
C Else
C Return WorkDay
C Endif
* Procedure definition end marker 2
P E
No comments:
Post a Comment