|
Editing Numbers in CL, Take Two
Hey, Ted:
I just read Cletus' tip on the editing of numbers in CL procedures, called Editing Numbers in CL. I will add these techniques to my tool kit. As always, thanks for the great stuff. Here's another method I've used to remove leading blanks from numbers in CL.
--Russ
Russ's method uses a message description that has a four-byte binary variable. Here's how it works. (This following code is mine, not his, so any mistakes are also mine.)
Let's use the example from the previous article. Variable &CustOrders contains the number of orders that have been added to a database file. Our job is to load the number of orders, without leading blanks, into the &AlphaNum variable.
First, a few variable declarations.
dcl &CustOrders *dec 10
dcl &AlphaNum *char 10
dcl &BinVar *char 4
Second, a message description that defines a four-byte binary variable.
CrtMsgf Msgf(Qtemp/TempMsg)
MonMsg MsgID(CPF2112)
AddMsgd MsgID(TMP1001) Msgf(QTEMP/TEMPMsg) Msg('&1') + Fmt((*BIN 4))
MonMsg MsgID(CPF2412)
The MONMSG message commands keep the CL procedure from erroring out during a rerun.
As before, variable &CustOrders has the number of orders. Convert the number of orders to binary format.
RtvMbrd File(ORDERS) NbrCurRcd(&CustOrders)
ChgVar Var(%BIN(&BinVar)) Value(&CustOrders)
Now, retrieve the message description into a CL variable. In the process, the system applies the number of orders to the message.
RtvMsg MsgID(TMP1001) Msgf(Qtemp/TempMsg) +
MsgDta(&BinVar) Msg(&AlphaNum)
At this point, &AlphaNum contains the number of records in the ORDERS file, left-adjusted.
Thanks to Russ for submitting this editing technique.
--Ted
RELATED STORY
Editing Numbers in CL
|