The CVTHEX command converts a field's contents to a hex string.

 For example, if  you pass in a  value of 'ABC', you would  receive back
 'C1C2C3'.  Decimal fields are also supported.

 There  are some application  functions where a  hex value is  needed or
 desirable.   One of  the places that a  hex value is  required in CL is
 on the  OVRDBF  command  POSITION  parameter when  dealing  with  keyed

 The CVTHEX  command allows the conversion  of one key value  at a time,
 but  makes it convenient  to create the  value that will  be needed for
 the OVRDBF POSITION parameter.

 Because the command returns  a variable, it can  only be executed in  a
 CL program.

 To convert from hex, see the CVTFRMHEX tool.

 Binary values

 Binary values are to  be represented in their hex  value.  For example,
 1000  in decimal  is X'03E8'.   CVTHEX would  produce a value  of 03E8.
 There is no real  difference between B=Binary  and A=Character for  the
 TYPE parameter.

 Command parameters                                    *CMD

    VALUE         A 128 byte  character field which is to  be translated
                  to  a  hex  equivalent.     The  value  must  be  left

    LEN           A  5 digit  0 decimal  field which  defines the length
                  of the  field to be  translated.   If a numeric  field
                  is  to  be translated,  the  length  of  the field  in
                  digits should be specified.

    TYPE          A  1 byte character field to  define the type of field
                  to be translated.   The entry values  are the same  as
                  are used in DSPFFD output.  The valid entries are:

                       A = Character
                       B = Binary
                       S = Zoned
                       P = Packed

    HEX           A 256  byte character field containing  the translated

    HEXPOS        A  3  digit  0  decimal  field  containing  the  start
                  position  within  the  return  parameter  HEX.    This
                  allows for multiple  fields to be concatenated  into a
                  single  string.    The  field  is updated  during  the
                  program  and  is returned  to be  a value  one greater
                  than  the  last  position  used.    Therefore,  it  is
                  already  set  to  be  used  again  for  another  field

 Command processing program interface

 A  command interface  is provided,  but the command  processing program
 can also be called  directly.  The following  is the parameter list  to
 be provided:

           VALUE    *CHAR    LEN(128)
           LEN      *DEC     LEN(5 0)
           TYPE     *CHAR    LEN(1)
           HEX      *CHAR    LEN(256)
           HEXPOS   *DEC     LEN(3 0)


 The following examples  show how you would specify the  fields and what
 the return values would be:

                Field 1     Field 2     Field 3    Field 4   Field 5
                -------     -------     -------    -------   -------

     VALUE       ABC          0123        123        0123       0033
     LEN          5            4           3           4         4
     TYPE         A            S           P           P         B
     HEX      C1C2C34040    F0F1F2F3     123F        00123F    0021

 A character  field does not have to contain  enough bytes to convert to
 match the length of the field, but a numeric field does.

 Note that in the case of a  even digit packed field, an extra digit  is
 placed in front of the field.

 Assume you have the  following key values which you want  to convert to
 corresponding hex values for use on the OVRDBF POSITION parameter:

                Field 1     Field 2
                -------     -------

     Type        Char       Packed
     Len          5           3
     Value       BBB         010

 The value of the HEX field after two uses of CVTHEX would be:


 This hex  value is not  the only value  needed for the  OVRDBF POSITION
 parameter,  but  it  is  normally  the  most  difficult  to  work with.
 Assume you  want  to process  a  file TESTKEY  which  has the  two  key
 fields  previously  described and  a  format  name  of TESTKEYR.    The
 following example shows how the CVTHEX command would be used:

              CHGVAR     &HEXPOS 1
              CVTHEX     VALUE(BBB) LEN(5) TYPE(A) HEX(&HEX) +
              CVTHEX     VALUE(009) LEN(3) TYPE(P) HEX(&HEX) +
              CHGVAR     &CMD ('OVRDBF FILE(TESTKEY) +
                           POSITION(*KEYAE' *BCAT '2' *BCAT +
                           'TESTKEYR' *BCAT 'X' *CAT '''' *CAT +
                           &HEX *TCAT '''' *CAT ')')
              CALL       QCMDEXC (&CMD 500)


 The command can only be used in a CL program:




 None, the tool is ready to use.

 Objects used by the tool

    Object        Type       Attribute      Src member     Src file
    ------        -----      ---------      ----------     -----------

    CVTHEX        *CMD                      TAACLPB        QATTCMD
    TAACLPBR      *PGM          RPG         TAACLPBR       QATTRPG

Added to TAA Productivity Tools April 1, 1995

Home Page

Last modified on March 10, 2014 © 1995, 2014 - TAA Tools, Inc.