TAA Tools
CVTFRMHEX      CONVERT FROM HEX VALUE                 TAACLPR

The CVTFRMHEX command allows  you to convert a variable  containing hex
data  to a  byte variable.   A  return location  and the  first invalid
value may be optionally returned.

CL  supports  the ability  to convert  a constant  (e.g.   X'F1')  to a
variable, but does not support the conversion from a variable.

A typical command would be:

       CVTFRMHEX     HEX(&HEX) RTNVAL(&RTNVAL) LEN(10)

This would specify  that the first 10  characters of the &HEX  variable
should be converted to  the first 5 bytes in &RTNVAL.   If the value in
&HEX was 'F1C1F2C2F3', the value in &RTNVAL would be '1A2B3'.

The  value to be  converted must  contain valid hex  values (0-9, A-F).
The LEN  value must be  a positive  even number.   If  you are  dealing
with variable length  data, you must ensure  that the LEN value  is set
correctly as trailing blanks will be considered invalid.

The RPG  program which performs the conversion  can be called directly.
See the  TAACLPRC source  in  QATTCL for  instructions and  the  return
code settings.

CVTFRMHEX  executes slowly  (array  processing and  bit  testing).   It
should  not  be used  if  a  large number  of  characters  needs to  be
converted.

If  an invalid hex value  (such as X'M3')exists, CPF9898  is sent as an
escape message  unless the ERRLOC  parameter is  specified.  If  ERRLOC
is specified, it  will contain 0 if valid hex values  exist and if not,
it  will contain the location of the  first position of the invalid hex
value.

To convert to hex, see the CVTHEX tool.

Command parameters                                    *CMD
------------------

   HEX           A variable or  constant up to 256  bytes in length  to
                 be  converted.   The data  should  be left  justified.
                 Only  the bytes defined  by the LEN  parameter will be
                 converted.   If trailing  blanks exist,  they will  be
                 considered an  error if the  LEN value  specifies that
                 they be converted.

   RTNVAL        The  return variable.   It must  be declared  as *CHAR
                 LEN(128)   and  the  converted   value  will  be  left
                 adjusted.

   LEN           The  length  of  the  value  to  be  converted.    The
                 default  is 2  meaning that  the first  two characters
                 of  the HEX parameter  will be converted.   It must be
                 a positive even number.

                 For  example,   to  convert   X'F1F2F3F4'  you   would
                 specify LEN(8).

   ERRLOC        The error location  if an invalid value  such as X'M3'
                 exists.   This is an optional  return variable that if
                 used must be specified as *DEC LEN(3 0).

                 If a  variable is  not specified  and an  invalid  hex
                 value exists,  CPF9898 is sent  as an  escape message.

                 If  a variable  is specified,  0  will be  returned if
                 all  valid hex values exist.   If an invalid hex value
                 exists, the  first position  of the  invalid value  is
                 returned and the command completes normally.

   ERRVALUE      The  error  hex  value  if  it exists.    This  is  an
                 optional  return  variable  that if  used  must  be be
                 specified as *CHAR LEN(2).

                 If ERRLOC is 0, ERRVALUE will contain blanks.

                 If  ERRLOC  is  not  0,  ERRVALUE  will   contain  the
                 invalid hex value.

Restrictions
-------------

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

Prerequisites
-------------

The following TAA Tools must be on your system:

         SNDESCMSG     Send escape message

Implementation
--------------

None, the tool is ready to use.

Objects used by the tool
------------------------

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

   CVTFRMHEX     *CMD                       TAACLPR       QATTCMD
   TAACLPRC      *PGM           CLP         TAACLPRC      QATTCL
   TAACLPRR      *PGM           RPG         TAACLPRR      QATTRPG
					

Added to TAA Productivity tools April 1, 1995


Home Page Up to Top