星期二, 10月 31, 2023

2001-04-10 如何於 RPG 中取得指定日期為星期幾 ?



如何於 RPG 中取得指定日期為星期幾 ?

File : QRPGLESRC
Member: DayOfWeekR
Type : RPGLE

     H  DFTACTGRP(*NO)

     D DateMDY         S               D   datfmt(*mdy)
     D DateAlpha       S              8    Inz
     D Output          S             50    Inz
      *
     D                 ds
     D TimeDate                      14  0
     D  Time60                        6  0 overlay(TimeDate:  1)
     D  Date80                        8  0 overlay(TimeDate:  7)
      *
     D DayofWeekA      S              9    DIM(7) CTDATA PERRCD(1)              
      *
     D Days            S             10I 0
     D DayofweekN      S             10I 0
     D datefmt         S             10    inz('MM/DD/YY')
      *
      * Feedback code data structure for CEE API
     D fc              DS
     D   sev                          5I 0
     D   msgno                        5I 0
     D   flags                        1
     D   facid                        3
     D   isi                         10I 0
      *
     C     *entry        Plist
     C                   Parm                    InputDate        10
      *
      *----------------------------------------------------*
      *  Get the current time                              *
      *----------------------------------------------------*
     C                   Time                    TimeDate
      *
     C     *usa          Move      Date80        DateMDY                        
     C                   Movel     DateMDY       DateAlpha                      
     c                   Eval      Output = 'Today is ' + DateAlpha
     C     Output        DSPLY

      * Convert Date to Lilian Format
     C                   CallB(D)  'CEEDAYS'
     C                   parm                    DateAlpha
     C                   parm                    datefmt
     C                   parm                    Days
     C                   parm                    fc
     C                   Eval      Output = 'Today"s Lilian date is ' +
     C                                      %trim(%editc(Days : 'Z'))
     C     Output        DSPLY
      *
      * Calculate Day of Week from Lilian Date
     C                   CallB     'CEEDYWK'
     C                   parm                    Days
     C                   parm                    DayOfweekN
      *
      * For the day of week, 1 indicates Sunday, 2 indicates Monday, ...,
      * 7 indicates Saturday.
     C                   Eval      Output = 'Today is ' +
     C                                       DayofWeekA(DayofWeekN)
     C     Output        DSPLY
      *
      * Caculate Inputdate
     c                   Eval      Output = 'InputDate is ' + InputDate
     C     Output        DSPLY

      * Convert Date to Lilian Format
     C                   CallB(D)  'CEEDAYS'
     C                   parm                    InputDate
     C                   parm      'MM/DD/YYYY'  datefmt
     C                   parm                    Days
     C                   parm                    fc
     C                   Eval      Output = 'InputDate Lilian date is ' +
     C                                      %trim(%editc(Days : 'Z'))
     C     Output        DSPLY
      *
      * Calculate Day of Week from Lilian Date
     C                   CallB     'CEEDYWK'
     C                   parm                    Days
     C                   parm                    DayOfweekN
      *
      * For the day of week, 1 indicates Sunday, 2 indicates Monday, ...,
      * 7 indicates Saturday.
     C                   Eval      Output = 'Inputdate Falls in ' +
     C                                       DayofWeekA(DayofWeekN)
     C     Output        DSPLY
      *
     C                   Eval      *InLR    = *On
**
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
      


參考資訊

1. Convert Date to Lilian Format (CEEDAYS) API
http://publib.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/qb3amm03/4.4

2. Calculate Day of Week from Lilian Date (CEEDYWK) API
http://publib.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/qb3amm03/4.3

3. Usage: CRTBNDRPG dftactgrp(*no)

4. Example : CALL DAYOFWEEKR '03/10/2001' 

沒有留言: