|
I wrote a service program to do this for me
Setsign Prototype:
D SetSign PR
D InputNum 12S 2
D SignLoc 1A
D OutString 12A
SetSign:
*=================================================================*
* SetSign - Set the sign for a numeric to character conversion
*=================================================================*
H
*=================================================================*
* Parameters
* 1. Input: numeric value
* 2. Output: signed numeric string
*=================================================================*
D/copy qsrvsrc,setsignpr
*-----------------------------------------------------------------*
* Main entry parameters
* 1. Input: numeric value
* 2. Output: signed numeric string
*-----------------------------------------------------------------*
D SetSign PI
D InputNum 12S 2
D SignLoc 1A
D OutString 12A
D
*-----------------------------------------------------------------*
* Other fields used by the program
*-----------------------------------------------------------------*
D DS
D work1 11s 2
D work2 11a overlay(work1)
D Pos c ' '
D Neg c '-'
D Left c 'L'
D Right c 'R'
/free
work1 = %abs(InputNum);
// for Negative numbers
if InputNum < *zero;
// Sign on the Right
if SignLoc = Right;
OutString = work2 + Neg;
endif;
// Sign on the Left
if SignLoc = Left;
OutString = Neg + work2;
endif;
// Positive numbers
else;
// Sign on the Right
if SignLoc = Right;
OutString = work2 + Pos;
endif;
// Sign on the Left
if SignLoc = Left;
OutString = Pos + work2;
endif;
endif;
Return;
/end-free
Here is an example:
// Service Program SETSIGN must be specified at program creation time
// Prototype for SETSIGN service program
d/copy qrpglesrc,setsignpr
// Needed field Set to R for right, L for left
d signloc s 1a inz('R')
// Additional example fields
d NumberIn s 12s 2
D StringOut S 12A
// RPG Free source
/FREE
SetSign(NumberIn: signloc: StringOut);
/END-FREE
* ILE RPG source
c eval SETSIGN(NumberIn: signloc: StringOut)
Just another way to do it. Hope this helps. This code may not be
formatted properly in the post, I copied it directly from my source.
Gene Burns Programmer Analyst Haulers Insurance Company BSchwar@xxxxxxxx wrote:
Hello, I need to format a 7,2 numeric field (vlcontamt) to 7 alpha with leading zeros and a left hand minus sign. I've searched the archives and found references to the 'N' edit code, but that suppresses leading zeros. eval wrk11a = %editc(vlcontamt:'P') Results when running program is in debug mode: positive amount WRK11A = ' 61.10 ' negative amount WRK11A = ' -8.6710 ' I thought the "P" edit code was supposed to provide leading zeors? Thank You and happy 4th of July! Bob Schwartz Southeast Georgia Health System, Brunswick Campus email bschwar@xxxxxxxx
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.