星期三, 11月 08, 2023

2009-01-10 如何判斷系統是否在限制(restricted state)狀態中?(Command RTVSYSSTE with API QWCRSSTS)


如何判斷系統是否在限制(restricted state)狀態中?(Command RTVSYSSTE with API QWCRSSTS)

有時候應用程式必須要在系統為限制(restricted state)狀態下才能執行,所以需要利用 API QWCRSSTS 判斷系統狀態
,防止應用程式在一般狀態下執行。

此指令 RTVSYSSTE 取得目前系統是否為限制狀態。
回傳值為 '1' 即為限制(restricted state)狀態
回傳值為 '0' 即為一般狀態狀態


File   : QCLSRC
Member : RTVSYSSTEC
Type   : CLP
Usage  : CRTCLPGM RTVSYSSTEC

/*  ===============================================================  */
/*  = Program....... RtvSysSteC                                   =  */
/*  = Description... Retrieve system state information            =  */
/*  ===============================================================  */

Pgm (&RstdState)

/*  ===============================================================  */
/*  = Declarations                                                =  */
/*  ===============================================================  */

  Dcl        &RstdState  *Char     (    1    )
/*  ===============================================================  */
/*  = Restricted state flag.                                      =  */
/*  = 0  System is not in restricted state.                       =  */
/*  = 1  System is in restricted state                            =  */
/*  ===============================================================  */
  Dcl        &RcvVar     *Char     (   68    )
  Dcl        &RcvVarLen  *Char     (    4    )
  Dcl        &Format     *Char     (    8    )
  Dcl        &Reset      *Char     (   10    )

  Dcl        &APIError   *Char     (  272    )
  Dcl        &BytesProv  *Char     (    4    )
  Dcl        &BytesAvail *Char     (    4    )
  Dcl        &MsgID      *Char     (    7    )
  Dcl        &MsgDta     *Char     (  256    )
  Dcl        &MsgF       *Char     (   10    )
  Dcl        &MsgFLib    *Char     (   10    )

/*  ===============================================================  */
/*  = Global error monitor                                        =  */
/*  ===============================================================  */

  MonMsg     ( CPF0000 MCH0000 ) Exec(                                +
    GoTo       Error                 )

/*  ===============================================================  */
/*  = Initialize variables                                        =  */
/*  ===============================================================  */

  ChgVar      &Format  ( 'SSTS0200' )
  ChgVar      &Reset   ( '*YES' )

  ChgVar      ( %Bin( &RcvVarLen ) )     ( 68 )
  ChgVar      ( %Bin( &BytesProv ) )     ( 272 )
  ChgVar      ( %Bin( &BytesAvail ) )    ( 0 )
  ChgVar      ( %Sst( &APIError 1 4 ) )  ( &BytesProv )
  ChgVar      ( %Sst( &APIError 5 4 ) )  ( &BytesAvail )

/*  ===============================================================  */
/*  = Retrieve system status information                          =  */
/*  ===============================================================  */

  Call       QWCRSSts                                                 +
                      (                                               +
                        &RcvVar                                       +
                        &RcvVarLen                                    +
                        &Format                                       +
                        &Reset                                        +
                        &APIError                                     +
                      )

/*  ---------------------------------------------------------------  */
/*  - Check for error and percolate if one exists                 -  */
/*  ---------------------------------------------------------------  */

  ChgVar      &BytesAvail  ( %Sst( &APIError 5 4 ) )

  If         ( %Bin( &BytesAvail ) *NE 0 )                            +
    Do
      ChgVar      &MsgID    ( %Sst( &APIError  9   7 ) )
      ChgVar      &MsgDta   ( %Sst( &APIError 17 256 ) )
      ChgVar      &MsgF     ( 'QCPFMSG' )
      ChgVar      &MsgFLib  ( 'QSYS' )
      GoTo        SndMsg
    EndDo

/*  ===============================================================  */
/*  = Extract system status information                           =  */
/*  ===============================================================  */

  ChgVar      &RstdState   ( %Sst( &RcvVar 31 1 ) )

/*  ===============================================================  */
/*  = Exit program                                                =  */
/*  ===============================================================  */

  Return

/*  ===============================================================  */
/*  = Error routine                                               =  */
/*  ===============================================================  */

Error:

  RcvMsg     MsgType( *Excp )                                         +
             MsgDta( &MsgDta )                                        +
             MsgID( &MsgID )                                          +
             MsgF( &MsgF )                                            +
             MsgFLib( &MsgFLib )

  MonMsg     ( CPF0000 MCH0000 )

SndMsg:

  SndPgmMsg  MsgID( &MsgID )                                          +
             MsgF( &MsgFLib/&MsgF )                                   +
             MsgDta( &MsgDta )                                        +
             MsgType( *Escape )

  MonMsg     ( CPF0000 MCH0000 )

/*  ===============================================================  */
/*  =  End of program                                             =  */
/*  ===============================================================  */

EndPgm



File   : QCMDSRC
Member : RTVSYSSTE
Type   : CMD
Usage  : CRTCMD CMD(RTVSYSSTE) PGM(lib/RTVSYSSTEC) ALLOW(*IPGM *BPGM)

/*  ===============================================================  */
/*  = Command....... RtvSysSte                                    =  */
/*  = CPP........... RtvSysSteC                                   =  */
/*  = Description... Retrieve System State                        =  */
/*  =                                                             =  */
/*  =                                                             =  */
/*  = CrtCmd      Cmd( RtvSysSte  )                               =  */
/*  =             Pgm( RtvSysSteC )                               =  */
/*  =             SrcFile( YourSourceFile )                       =  */
/*  =             Allow( *Ipgm *Bpgm )                            =  */
/*  ===============================================================  */
/*  = Date  : 2009/01/10                                          =  */
/*  = Author: Vengoal Chang                                       =  */
/*  ===============================================================  */

             Cmd        Prompt( 'Retrieve System State')

             Parm       Kwd( RstdState )                              +
                        Type( *Char    )                              +
                        RtnVal( *Yes )                                +
                        Len( 1 )                                      +
                        Prompt( 'Restricted state' )




File   : QCLSRC
Member : RTVSYSSTET
Type   : CLP
Usage  : CRTCLPGM RTVSYSSTET
         測試程式 CALL RTVSYSSTET

PGM
             DCL &RSTDSTATE *CHAR 1
             DCL &MSGDTA *CHAR 256

             RTVSYSSTE  RSTDSTATE(&RSTDSTATE)

/*  ===============================================================  */
/*  = Insert your code that uses the system status values         =  */
/*  ===============================================================  */

  If (&RstdState *EQ '1') +
     ChgVar &MsgDta 'Current system state is in restricted state'
  Else +
     ChgVar &MsgDta 'Current system state is not in restricted state'

  SndPgmMsg  MsgId(CPF9898) Msgf(QCPFMSG)                             +
             MsgDta(&MsgDta)
ENDPGM




沒有留言: