380 pts.
 Clear leading zeros
I have a 10A character field which hold a numeric value. Problem is that it contains leading zeros. How can I remove them?

Many thanks.

 



Software/Hardware used:
V5R4 iSeries
ASKED: October 29, 2009  9:08 AM
UPDATED: November 3, 2009  12:56 PM

Answer Wiki:
Do you want to remove them in the file when a record is added or updated. Or do you want to remove them when you extract the data for a report or insertion into another file? In either case mentioned aboove, what process is used to do that function? An RPG program, SQL, CPYF, ...?
Last Wiki Answer Submitted:  October 29, 2009  2:56 pm  by  CharlieBrowne   32,835 pts.
All Answer Wiki Contributors:  CharlieBrowne   32,835 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Hi CharlieBrown,

In my RPGIV program I need to remove the leading zeros prior to inserting the field into another file.

Neil.

 380 pts.

 

I checked my RPG IV and ILE manuals and came up with the same answer. Insert a line of free form code and use the %CHAR Built-in function. If you set
CHAR10 = %CHAR(POINTS)
the result would be ’234 ‘

Below is IBM’s example.
D points S 10i 0 INZ(234)
/FREE
//—————————————————-
// Use %CHAR to convert a number to character format:
//—————————————————-
result = ’You have ’ + %char(points) + ’ points.’;
// result = ’You have 234 points.’
// /END-FREE

 10 pts.

 

Try this when populating the field
OUTPUTFIELD = %editC(INPUTFIELD:’X');

 32,835 pts.

 

I need to remove the leading zeros prior to inserting the field into another file.

What data type is the column in “another file”? If it’s also CHAR(10), do you want left-or right-justified?

Tom

 108,055 pts.

 

What data type is the column in “another file”? If it’s also CHAR(10), do you want left-or right-justified?

Tom

Hi,

Both fields are 10A and I need it right justified.

Neil.

 380 pts.

 

You have a number in a character field, and want the leading zeros removed.

So, use this:

trimmed = %triml( myField : ’0 ’)

The second parameter contains a zero and a blank. The Trim Left BIF will trim BOTH those values off the LEFT side of the value, and place the result in the field TRIMMED.

Regards,

Sloopy

 2,195 pts.

 

Oh – forgot. You need to use the opcode EVALR, which will right-adjust the result.

EVALR trimmed = %triml( myField : ’0 ’)

 2,195 pts.

 

In COBOL you can use the INSPECT verb with the REPLACE LEADING ZEROES option.

 880 pts.

 
d field1          s             10a   inz('0000098030')      
d field2          s             10a                          
c                   evalr     field2 = %triml(field1:'0')    
c                   eval      *inlr = *on                    
c                   dump(a)                                  

FIELD1                CHAR(10)             '0000098030'
FIELD2                CHAR(10)             '     98030'
 7,185 pts.

 

whoops :D

Guess Sloopy beat me in with the answer while I got tied up on a phone call!

Darn work getting in the way of things! :)

 7,185 pts.

 

EVALR trimmed = %triml( myField : ’0 ’)

Brilliant, thanks for everyones help.

Neil.

 380 pts.

 

Kat, who do think made the phone call?

 2,195 pts.

 

Darn you Sloopy, distracting me with a phone call :)

I’ll beat you next time (or maybe the one after that or…)

 7,185 pts.