Trimming Leading Zeros

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Here's my method for trimming leading zeros from a character field in RPG (V2R1 or later). Let's say a character field with a length of 10, named CHRNUM, contains the value '002300450'. The TRMZRO subroutine in 8 will remove all leading zeros and return a value of ' 2300450'.

Here's my method for trimming leading zeros from a character field in RPG (V2R1 or later). Let's say a character field with a length of 10, named CHRNUM, contains the value '002300450'. The TRMZRO subroutine in Figure 8 will remove all leading zeros and return a value of ' 2300450'.

This technique eliminates the need for array processing and therefore is very efficient.

If you want to remove leading zeros from a character field that was originally a negative number, you will have to append a negative sign. This can easily be done by using the CAT operation.


Trimming Leading Zeros

Figure 8 RPG Code for Removing Leading Zeros from a Charact

 ... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 C CLEARWRK30 C MOVE CHRNUM WRK30 30 C EXSR TRMZRO C MOVE WRK30 CHRNUM C MOVEL*ON *INLR *=============================================================== C TRMZRO BEGSR *=============================================================== C WRK30 IFNE *ALL'0' C WRK30 ANDNE*BLANKS C ' ':'0' XLATEWRK30 WRK30 C '0' CHECKWRK30 Y 30 C '0':' ' XLATEWRK30 WRK30 C ' ':'0' XLATEWRK30:Y WRK30 C ELSE C MOVE *BLANKS WRK30 C ENDIF C ENDSR *=============================================================== 
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: