Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert Char to Numeric in Free form

Status
Not open for further replies.

loonybin

Programmer
Dec 12, 2002
38
US
Hi.

I just want to convert MOVE CHAR NUM on free format. Could someone please help.

Thanks in advance.
 
CustomerN = %Int(Customer@);

The parameter is not valid on %INT. It only takes numeric. Please let me know of a way to convert char to numeric in free form. thanks.

 
loonybin,

What version of OS/400 are you running? I just tried it on my box and it worked. We are running V5R2.

MdnghtPgmr
 
%INT and %INTH only convert characters to numbers at V5R2 and above. For V5R1 (which I am on) and below, you can use this service program, which was written by Barbara Morris of IBM. I use it, and it works great.

One correction I had to make: add the EXPORT keyword to the procedure's definition begin.


De mortuis nihil nisi bonum.

 
loonybin, try this.
Code:
D ConvertDollar   PR             8S 2
D   InValue                     11    Value
                            .
                            .
                            .
//=========================================================
//  SUBPROCEDURE:  ConvertDollar
//       PURPOSE:  Convert character to dollar value
//
//  DATE          CHANGED BY          REASON
//
//=========================================================
P ConvertDollar   B
//---------------------------------------------------------D ConvertDollar   PI             8S 2
D   CharValue                   11    Value
D
D NegativeAmt     S               N   Inz(*Off)
D CharDollar      Ds
D  DollarAmt                     8S 2
//--------------------------------------------------------- /Free

  If %Scan('-':CharValue) > 0;
    NegativeAmt = *On;
    EvalR CharValue = %TrimR(%Replace('':CharValue:
                             %Scan('-':CharValue):1));
  Else;
    NegativeAmt = *Off;
  EndIf;
  DoW %Scan(',':CharValue) > 0;
    EvalR CharValue = %TrimR(%Replace('':CharValue:
                         %Scan(',':CharValue):1));
  EndDo;
  EvalR CharValue = %TrimR(%Replace('':CharValue:
          %Scan('.':CharValue);1));
  EvalR CharDollar = CharValue;
  If NegativeAmt;
    DollarAmt = DollarAmt * -1;
  EndIf;
  Return DollarAmt;

 /End-Free
 //--------------------------------------------------------P ConvertDollar   E
 //========================================================
The above procedure converts a dollar amount from a char value and converts it back into a signed numeric value. The actual conversion takes place EvalR CharDollar = CharValue.

RedMage1967
IBM Certifed - RPG IV Progammer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top