     **
     **  Program . . : CBX277
     **  Description : Calculate Hash Value - CPP
     **  Author  . . : Carsten Flensburg
     **
     **
     **
     **  Compile options required:
     **    CrtRpgMod   Module( CBX277 )
     **                DbgView( *LIST )
     **
     **    CrtPgm      Pgm( CBX277 )
     **                Module( CBX277 )
     **                BndSrvPgm( CBX277S )
     **                ActGrp( *NEW )
     **
     **
     **-- Header specifications:  --------------------------------------------**
     H Option( *SrcStmt )  BndDir( 'QC2LE' )

     **-- API error data structure:
     D ERRC0100        Ds                  Qualified
     D  BytPrv                       10i 0 Inz( %Size( ERRC0100 ))
     D  BytAvl                       10i 0
     D  MsgId                         7a
     D                                1a
     D  MsgDta                      512a

     **-- Global variables:
     D HashVal         s           1024a   Varying
     D OutStr          s           1024a   Varying
     D Blanks          s             52a

     **-- Calculate hash value:
     D ClcHashVal      Pr           256a   Varying
     D  PxCalcStr                 65535a   Varying  Const
     D  PxHashAlg                    10i 0          Const
     **-- Convert hex nibbles to character:
     D CvtHexChr       Pr           128a   Varying
     D  PxHexStr                    256a   Varying  Const
     **-- Convert character to hex nibbles:
     D CvtChrHex       Pr           256a   Varying
     D  PxHexStr                    128a   Varying  Const

     **-- Display long text:
     D DspLngTxt       Pr                  ExtPgm( 'QUILNGTX' )
     D  LngTxt                    32767a   Const  Options( *VarSize )
     D  LngTxtLen                    10i 0 Const
     D  MsgId                         7a   Const
     D  MsgF                         20a   Const
     D  Error                     32767a   Const  Options( *VarSize )
     **-- Send program message:
     D SndPgmMsg       Pr                  ExtPgm( 'QMHSNDPM' )
     D  MsgId                         7a   Const
     D  MsgFq                        20a   Const
     D  MsgDta                      512a   Const  Options( *VarSize )
     D  MsgDtaLen                    10i 0 Const
     D  MsgTyp                       10a   Const
     D  CalStkE                      10a   Const  Options( *VarSize )
     D  CalStkCtr                    10i 0 Const
     D  MsgKey                        4a
     D  Error                       512a          Options( *VarSize )
     D  CalStkElen                   10i 0 Const  Options( *NoPass )
     D  CalStkEq                     20a   Const  Options( *NoPass )
     D  DspWait                      10i 0 Const  Options( *NoPass )
     D  CalStkEtyp                   20a   Const  Options( *NoPass )
     D  CcsId                        10i 0 Const  Options( *NoPass )
     **-- Display message window:
     D DspMsgWdw       Pr
     D  PxMsgStr                   1024a   Const  Varying
     **-- Send completion message:
     D SndCmpMsg       Pr            10i 0
     D  PxMsgDta                    512a   Const  Varying

     **-- Parameters:
     D CBX277          Pr
     D  PxCalcStr                  5000a   Varying
     D  PxHashAlg                    10i 0
     **
     D CBX277          Pi
     D  PxCalcStr                  5000a   Varying
     D  PxHashAlg                    10i 0

      /Free

        HashVal = ClcHashVal( PxCalcStr: PxHashAlg );

        OutStr  = CvtChrHex( HashVal );

        DspMsgWdw ( 'Input  . . . : ' + PxCalcStr + Blanks +
                    'Hash value . : ' + OutStr );

        SndCmpMsg( 'Hash value calculation completed.' );

        *InLr = *On;
        Return;

      /End-Free

     **-- Display message window:
     P DspMsgWdw       B
     D                 Pi
     D  PxMsgStr                   1024a   Const  Varying

      /Free

        DspLngTxt( PxMsgStr: %Len( PxMsgStr ): *Blanks: *Blanks: ERRC0100 );

      /End-Free

     P DspMsgWdw       E
     **-- Send completion message:
     P SndCmpMsg       B
     D                 Pi            10i 0
     D  PxMsgDta                    512a   Const  Varying

     D MsgKey          s              4a

      /Free

        SndPgmMsg( 'CPF9897'
                 : 'QCPFMSG   *LIBL'
                 : PxMsgDta
                 : %Len( PxMsgDta )
                 : '*COMP'
                 : '*PGMBDY'
                 : 1
                 : MsgKey
                 : ERRC0100
                 );

        If  ERRC0100.BytAvl > *Zero;
          Return  -1;

        Else;
          Return  0;

        EndIf;

      /End-Free

     P SndCmpMsg       E
