• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Indicate Negative Numbers with Parentheses

    January 11, 2006 Hey, Ted

    Thank you for a newsletter with information that is always interesting and useful. I enjoyed reading about your IIF function. Here is a function I wrote a few years back on V5R1. It returns a numeric value edited for displaying or printing that includes parenthesis when the value is negative. Our accountants prefer that negative numbers appear within parenthesis. The value returned contains two decimals, as this function is primarily used for monetary amounts.

    –Glenn T. Berg, programmer/analyst

    It was good of Glenn to share his EditParens function with the rest of us. I don’t blame the bean counters for wanting to see negative numbers in parentheses. Those trailing minus signs don’t stand out as well, and can get lost when numbers are displayed or printed close together. If a number is negative, EditParens places a floating opening parenthesis immediately before the first non-blank character of the edited result and follows the edited number with a closing parenthesis. If the number is not negative, the positions that the parentheses would fill are left blank.

    Here is the procedure prototype for the EditParens function. In my testing, I put it in member EditParens of source physical file PROTOTYPES.

    D* Prototype for Subprocedure EditParens     
    D EditParens      PR            42A   VARYING
    D    Val                        30P 2 VALUE
    

    Here’s the function itself.

    *-----------------------------------------------------------------------
    *  Subprocedure EditParens - Place Parentheses Around Negative Number   
    *-----------------------------------------------------------------------
    H nomain                                                                 
                                                                             
    D/copy prototypes,EditParens                                             
                                                                             
    P EditParens      B                   EXPORT                             
                                                                             
    D* Procedure Interface                                                   
    D EditParens      PI            42A   VARYING                            
    D  Val                          30P 2 VALUE                              
    D* Local Work fields                                                     
    D Lparen          C                   CONST('(')                         
    D Rparen          C                   CONST(')')                         
    D WRK             S             42A   VARYING                            
                                                                             
     *    Edited Value
     *   Note that the '1' edit code does not include a sign so we 
     *   don't have to calculate the absolute value when negative. 
    C                   If         Val >=0                         
    C                   Eval       WRK = %TrimL(%Editc(Val:'1')) + 
    C                              ' '                             
    C                   Else                                       
    C                   Eval       WRK = Lparen +                  
    C                              %TrimL(%Editc(Val:'1')) +       
    C                              RParen                          
    C                   End                                        
                                                                   
    C                   Return     WRK                             
    P                 E
    

    Here’s an example of how a calling routine might invoke EditParens. Numeric variables WXCUR and WXYTD are copied into edited variables WXCURO and WXYTDO.

    D WXYTD           s              9P 2                   
    D WXCUR           s              7P 2                   
    D WXYTDO          s             14A                     
    D WXCURO          s             11A                     
    
    D/copy prototypes,EditParens                            
                                                            
    C                   EvalR     WXYTDO = EditParens(WXYTD)
    C                   EvalR     WXCURO = EditParens(WXCUR)
    

    I will leave it to the reader to place the routine in an appropriate module or service program. This is a topic I dealt with in the January 4 edition of Four Hundred Guru.

    –Ted

    RELATED STORIES

    A Handy RPG FUNction

    Properly Placed Procedures

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    nuBridges:  Leading provider of secure FTP on the iSeries
    COMMON:  Join us at the Spring 2006 conference, March 26-30, in Minneapolis, Minnesota
    California Software:  Migrate iSeries apps to Windows, Linux, or Unix

    DataMirror Claims Top Benchmark for Data Replication Mainsoft, IBM to Convert .NET Code to Java on All eServers

    Leave a Reply Cancel reply

Volume 6, Number 2 -- January 11, 2006
THIS ISSUE SPONSORED BY:

ProData Computer Svcs
Advanced Systems Concepts
COMMON

Table of Contents

  • A FUNction to Align Text
  • Alternatives to Clear Physical File Member
  • Admin Alert: Six Simple Rules for OS/400 Group Profiles
  • Alternate SQL Row-Selection Criteria, Take 3
  • Indicate Negative Numbers with Parentheses
  • Admin Alert: Limiting *PUBLIC Access to i5/OS Objects, Part 2

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Public Preview For Watson Code Assistant for i Available Soon
  • COMMON Youth Movement Continues at POWERUp 2025
  • IBM Preserves Memory Investments Across Power10 And Power11
  • Eradani Uses AI For New EDI And API Service
  • Picking Apart IBM’s $150 Billion In US Manufacturing And R&D
  • FAX/400 And CICS For i Are Dead. What Will IBM Kill Next?
  • Fresche Overhauls X-Analysis With Web UI, AI Smarts
  • Is It Time To Add The Rust Programming Language To IBM i?
  • Is IBM Going To Raise Prices On Power10 Expert Care?
  • IBM i PTF Guide, Volume 27, Number 20

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle