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 CharlieBrowne32,835 pts.
All Answer Wiki Contributors: CharlieBrowne32,835 pts.
If you live outside the United States, by submitting your email address you consent to having your personal data transferred to and processed in the United States.
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
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.
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'
Hi CharlieBrown,
In my RPGIV program I need to remove the leading zeros prior to inserting the field into another file.
Neil.
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
Try this when populating the field
OUTPUTFIELD = %editC(INPUTFIELD:’X');
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
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.
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
Oh – forgot. You need to use the opcode EVALR, which will right-adjust the result.
EVALR trimmed = %triml( myField : ’0 ’)
In COBOL you can use the INSPECT verb with the REPLACE LEADING ZEROES option.
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'whoops
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!
EVALR trimmed = %triml( myField : ’0 ’)
Brilliant, thanks for everyones help.
Neil.
Kat, who do think made the phone call?
Darn you Sloopy, distracting me with a phone call
I’ll beat you next time (or maybe the one after that or…)