Clear leading zeros

450 pts.
Tags:
iseries v5r4
RPG
RPG IV
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

Answer Wiki

Thanks. We'll let you know when a new response is added.

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, …?

Discuss This Question: 14  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • NeilD
    Hi CharlieBrown, In my RPGIV program I need to remove the leading zeros prior to inserting the field into another file. Neil.
    450 pointsBadges:
    report
  • Birdieking
    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 pointsBadges:
    report
  • CharlieBrowne
    Try this when populating the field OUTPUTFIELD = %editC(INPUTFIELD:'X');
    41,380 pointsBadges:
    report
  • TomLiotta
    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
    125,585 pointsBadges:
    report
  • NeilD
    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.
    450 pointsBadges:
    report
  • Sloopy
    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 pointsBadges:
    report
  • Sloopy
    Oh - forgot. You need to use the opcode EVALR, which will right-adjust the result. EVALR trimmed = %triml( myField : ’0 ’)
    2,195 pointsBadges:
    report
  • NullFields
    In COBOL you can use the INSPECT verb with the REPLACE LEADING ZEROES option.
    880 pointsBadges:
    report
  • BigKat
    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'
    
    8,200 pointsBadges:
    report
  • BigKat
    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! :)
    8,200 pointsBadges:
    report
  • NeilD
    EVALR trimmed = %triml( myField : ’0 ’) Brilliant, thanks for everyones help. Neil.
    450 pointsBadges:
    report
  • Sloopy
    Kat, who do think made the phone call?
    2,195 pointsBadges:
    report
  • BigKat
    Darn you Sloopy, distracting me with a phone call :) I'll beat you next time (or maybe the one after that or...)
    8,200 pointsBadges:
    report
  • susan2029

    Hi BigKat


    very thank you for your code snippet.....for suppressing leading zeros.It quickly helped me :)

    thanks a lot

    10 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following