TAA Tools

The Move Character  to Decimal command  allows for the  situation where
a packed  decimal value (e.g.   X'010F') is in a  CL character variable
and  you  want  to  treat it  as  a  decimal value.    For  the inverse
function, see MOVDECCHR.

In  most  cases  there  is   no  need  for  MOVCHRDEC  as   you  should
consistently  specify  parameter  definitions  to avoid  this  type  of

However,  there are cases where  the MOVCHRDEC command  is needed.  For
example, when dealing  with a command  list of sub-lists  where one  or
more of  the elements is numeric,  extracting from the value  passed by
command  definition can only  be done to  a character field.   You need
the MOVCHRDEC command to treat the element properly.

For example, assume you have a  command which uses a list of  sub-lists
where each  sub  list allows  the entry  of "Code  ID" and  "Quantity".
The command definition would be coded as follows:

             PARM       KWD(LIST) TYPE(LIST1) MIN(1) MAX(50) +
                          PROMPT('List of entries:')
 LIST1:      ELEM       TYPE(*CHAR) LEN(5) +
                          PROMPT('Code ID:')
             ELEM      TYPE(*DEC) LEN(3 0) +

The length  of the sub-list  passed from command definition  will be 7.
The  first 5 are  the Code ID and  the next two are  a packed value for
Quantity.   You  must  use  the  substring capability  to  extract  the
Quantity  value  and  therefore  can   only  move  it  to  a  character
variable.   To work with the  data, you want it  in a decimal variable.

The MOVCHRDEC command requires  the character field to  be in a  LEN(8)
variable.   So you  must normally move  the value  first.   The typical
commands would then be:

     CHGVAR       &WORK2 %SST(&SUBLIST 6 2) /* Extract from sub list */
     CHGVAR       &WORK8 &WORK2             /* Move to 8 byte var    */
     MOVCHRDEC    DECOUT(&DEC) CHRINP(&CHAR) /* Move to decimal var  */

The  returned decimal  value must be  coded as  LEN(15 0).   The CHRINP
must be coded as LEN(8).

Note that you left adjust the value in the CHRINP variable.

The CHGVAR  command can  be  used to  convert  data from  character  to
decimal.    For  example,  if  you  have   a  character  value  of  123
(X'F1F2F3') using  CHGVAR to a DEC(5 0) variable  will convert the data
to X'00123F'.

Unlike  the CHGVAR  command, MOVCHRDEC does  not convert  the data, but
rather moves  the bytes to  a decimal  variable.  The  same bytes  will
appear  in  the  decimal   variable  (see  next  discussion  for  right

You  should  left  adjust the  value  into the  CHRINP  variable.   For
example, assume  that  in the  previous  example  the 2  byte  Quantity
variable  contained X'050F'.   To  use MOVCHRDEC,  the CHRINP  variable
must  be LEN(8).   You can  use CHGVAR  to move  the value to  a LEN(8)
variable in  which case  the bytes  are properly  aligned and  the  new
variable will  contain the  value X'050F404040404040'.   When you  then
use  MOVCHRDEC, the  command  will scan  the character  value  from the
right  for  the first  non-blank character  and  right adjust  into the
numeric field.   The DECOUT variable will  contain X'000000000000050F'.

An error  will occur if  the field to  be moved does not  contain valid
packed data.

Command parameters                                    *CMD

   DECOUT        The  decimal variable to contain the  result.  It must
                 be specified as LEN(15 0).

   CHRINP        The character  variable  to  be  moved.   It  must  be
                 specified  as  LEN(8).    The   value  placed  in  the
                 variable must be left adjusted.




The following TAA Tools must be on your system:

        SNDESCMSG      Send escape message


None, the tool is ready to use.

Objects used by the tool

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

   MOVCHRDEC     *CMD                      TAACLPJ        QATTCMD
   TAACLPJC      *PGM          CLP         TAACLPJC       QATTCL
   TAACLPJR      *PGM          RPG         TAACLPJR       QATTRPG

Added to TAA Productivity tools April 1, 1995

Home Page Up to Top