星期三, 11月 08, 2023

2011-08-12 如何將 DTS 格式的時間 與 格式為 YYYYMMDD HHMISS sss 時間互為轉換?(MI MATTOD and Convert Date and Time Format QWCCVTDT API )


如何將 DTS 格式的時間 與 格式為 YYYYMMDD HHMISS sss 時間互為轉換?(MI MATTOD and Convert Date and Time Format QWCCVTDT API )

系統時間 DTS 格式常出現在 Journal 或 系統函數中,有時就有需要將 DTS 格式轉換為可讀取格式,
指令 CVSDTS(Convert DTS to Date/Time),CVTTODTS((Convert Date/Time DTS) 如下:


File  : QCLSRC

Member: CVTDTS

Type  : CLP

Usage : CRTCLPGM CVTDTS


/*  ===============================================================  */
/*  = Command CVTDTS     CPP                                      =  */
/*  = Program....... CvtDts                                       =  */
/*  = Description... Convert DTS to Date/Time                     =  */
/*  ===============================================================  */
/*  = Date  : 2011/07/28                                          =  */
/*  = Author: Vengoal Chang                                       =  */
/*  ===============================================================  */

     Pgm      ( &Dts                   +
                &RtnDate               +
                &RtnTime               +
                &RtnMillsec            +
              )

/*-- Parameters:  ---------------------------------------------------*/
     Dcl        &Dts         *Char     8
     Dcl        &RtnDate     *Char     8
     Dcl        &RtnTime     *Char     6
     Dcl        &RtnMillSec  *Char     3
     Dcl        &OutDatTim   *Char    20

/*-- Global error monitoring:  --------------------------------------*/
     MonMsg     MCH3601
     MonMsg     CPF0000      *N        GoTo Error

     Call       QWCCVTDT    ( '*DTS'             +
                              &Dts               +
                              '*YYMD'            +
                              &OutDatTim         +
                              x'00000000'        +
                            )

     ChgVar &RtnDate    %SST(&OutDatTim 1 8)
     ChgVar &RtnTime    %SST(&OutDatTim 9 6)
     ChgVar &RtnMillSec %SST(&OutDatTim 15 3)

 Return:
     Return

/*-- Error processor ------------------------------------------------*/
Error:
     Call      QMHMOVPM    ( '    '                   +
                             '*DIAG'                  +
                             x'00000001'              +
                             '*PGMBDY   '             +
                             x'00000001'              +
                             x'0000000800000000'      +
                           )

     Call      QMHRSNEM    ( '    '                   +
                             x'0000000800000000'      +
                           )
 EndPgm:
     EndPgm


File  : QCLSRC

Member: CVTTODTS

Type  : CLP

Usage : CRTCLPGM CVTTODTS


/*  ===============================================================  */
/*  = Command CVTTODTS   CPP                                      =  */
/*  = Program....... CvtToDts                                     =  */
/*  = Description... Convert Date/Time to DTS                     =  */
/*  ===============================================================  */
/*  = Date  : 2011/07/28                                          =  */
/*  = Author: Vengoal Chang                                       =  */
/*  ===============================================================  */

     Pgm      ( &Date                  +
                &Time                  +
                &Millsec               +
                &RtnDts                +
              )

/*-- Parameters:  ---------------------------------------------------*/
     Dcl        &Date        *Char     8
     Dcl        &Time        *Char     6
     Dcl        &MillSec     *Char     3
     Dcl        &RtnDts      *Char     8
     Dcl        &InpDatTim   *Char    20

/*-- Global error monitoring:  --------------------------------------*/
     MonMsg     CPF0000      *N        GoTo Error

     ChgVar %SST(&InpDatTim 1 8)  &Date
     ChgVar %SST(&InpDatTim 9 6)  &Time
     ChgVar %SST(&InpDatTim 15 3) &MillSec
     ChgVar %SST(&InpDatTim 18 3) '000'

     Call       QWCCVTDT    ( '*YYMD'            +
                              &InpDatTim         +
                              '*DTS'             +
                              &RtnDts            +
                              x'00000000'        +
                            )

 Return:
     Return

/*-- Error processor ------------------------------------------------*/
Error:
     Call      QMHMOVPM    ( '    '                   +
                             '*DIAG'                  +
                             x'00000001'              +
                             '*PGMBDY   '             +
                             x'00000001'              +
                             x'0000000800000000'      +
                           )

     Call      QMHRSNEM    ( '    '                   +
                             x'0000000800000000'      +
                           )
 EndPgm:
     EndPgm


File  : QCMDSRC

Member: CVTDTS

Type  : CMD

Usage : CRTCMD  CMD(CVTDTS) PGM(CVTDTS) ALLOW(*IPGM *BPGM)


/*  ===============================================================  */
/*  = Command....... CVTDTS                                       =  */
/*  = CPP........... CVTDTS     CLP                               =  */
/*  = Description... Convert DTS to date/time                     =  */
/*  =                                                             =  */
/*  = Compile options:                                            =  */
/*  =                                                             =  */
/*  = CrtCmd      Cmd( CVTDTS )                                   =  */
/*  =             Pgm( CVTDTS )                                   =  */
/*  =             SrcMbr( CVTDTS  )                               =  */
/*  =             Allow(                                          =  */
/*  =                   *IREXX                                    =  */
/*  =                   *BREXX                                    =  */
/*  =                   *BPGM                                     =  */
/*  =                   *IPGM                                     =  */
/*  =                  )                                          =  */
/*  ===============================================================  */
/*  = Date  : 2011/07/14                                          =  */
/*  = Author: Vengoal Chang                                       =  */
/*  ===============================================================  */
             Cmd        Prompt( 'Convert DTS to Date/Time'   )

             Parm       DTS         *Char         8        +
                        Min( 1 )                           +
                        Expr( *YES )                       +
                        Prompt( 'DTS' )

             Parm       RTNDATE     *Char         8        +
                        RTNVAL(*YES)                       +
                        Prompt( 'Return date format YYYYMMDD(8)')

             Parm       RTNTIME     *Char         6        +
                        RTNVAL(*YES)                       +
                        Prompt( 'Return time format HHMMSS  (6)')

             Parm       RTNMILLSEC  *Char         3        +
                        RTNVAL(*YES)                       +
                        Prompt( 'Return millsec format sss  (3)')
                        

File  : QCMDSRC

Member: CVTTODTS

Type  : CMD

Usage : CRTCMD  CMD(CVTTODTS) PGM(CVTTODTS) ALLOW(*IPGM *BPGM)


/*  ===============================================================  */
/*  = Command....... CVTTODTS                                     =  */
/*  = CPP........... CVTTODTS   CLP                               =  */
/*  = Description... Convert date/time to DTS                     =  */
/*  =                                                             =  */
/*  = Compile options:                                            =  */
/*  =                                                             =  */
/*  = CrtCmd      Cmd( CVTTODTS )                                 =  */
/*  =             Pgm( CVTTODTS )                                 =  */
/*  =             SrcMbr( CVTTODTS )                              =  */
/*  =             Allow(                                          =  */
/*  =                   *IREXX                                    =  */
/*  =                   *BREXX                                    =  */
/*  =                   *BPGM                                     =  */
/*  =                   *IPGM                                     =  */
/*  =                  )                                          =  */
/*  ===============================================================  */
/*  = Date  : 2011/07/14                                          =  */
/*  = Author: Vengoal Chang                                       =  */
/*  ===============================================================  */
             Cmd        Prompt( 'Convert Date/time to DTS' )


             Parm       DATE        *Char         8        +
                        Min( 1 )                           +
                        Expr( *YES )                       +
                        Prompt( 'The date format YYYYMMDD')

             Parm       TIME        *Char         6        +
                        Min( 1 )                           +
                        Expr( *YES )                       +
                        Prompt( 'The time format HHMMSS')

             Parm       MILLSEC     *Char         3        +
                        Dft( 000 )                         +
                        Range('000' '999')                 +
                        Expr( *YES )                       +
                        Prompt( 'The millsec format sss')

             Parm       DTS         *Char         8        +
                        RTNVAL(*YES)                       +
                        Prompt( 'CL var for DTS           (8)')


File  : QCLSRC

Member: CVTDTST

Type  : CCL

Usage : CRTCLPGM CVTDTST

        CALL CVTDTST

PGM

/*-- Parameters:  ---------------------------------------------------*/
     Dcl        &Dts         *Char     8
     Dcl        &Dts2        *Char     8
     Dcl        &RtnDate     *Char     8
     Dcl        &RtnTime     *Char     6
     Dcl        &RtnMillSec  *Char     3
     Dcl        &RtnDate2    *Char     8
     Dcl        &RtnTime2    *Char     6
     Dcl        &RtnMillSe2  *Char     3
     Dcl        &RtnDts      *Char     8
     Dcl        &RtnDts2     *Char     8

             callprc    'mattod' parm(&DTS)

             CVTDTS     DTS(&DTS) RTNDATE(&RTNDATE) +
                          RTNTIME(&RTNTIME) RTNMILLSEC(&RTNMILLSEC)
             CVTTODTS   DATE(&RTNDATE) TIME(&RTNTIME) +
                          MILLSEC(&RTNMILLSEC) DTS(&RTNDTS)

             CVTDTS     DTS(&RTNDTS) RTNDATE(&RTNDATE2) +
                          RTNTIME(&RTNTIME2) RTNMILLSEC(&RTNMILLSE2)
             CVTTODTS   DATE(&RTNDATE2) TIME(&RTNTIME2) +
                          MILLSEC(&RTNMILLSE2) DTS(&RTNDTS2)

             DMPCLPGM
             
             DSPSPLF    FILE(QPPGMDMP) SPLNBR(*LAST)

ENDPGM


Convert Date and Time Format (QWCCVTDT) API





沒有留言: