Replace leading blanks with zeros in RPG

2505 pts.
Tags:
AS/400
RPG
I have a 3A field on my display file, when user enters ' 50' I want to chain the file with '050' since record in stored in file like that. How can I replace the leading blanks with zeros in this case?

Software/Hardware used:
AS400

Answer Wiki

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

Use the BIF %XLATE.

yourfield = %Xlate(‘  ‘ : ’0′);

Discuss This Question: 15  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
  • philpl1jb
    Beware .. the solution above will properaly translate ' 50' to 050 but will translate '50 ' to 500.
    50,465 pointsBadges:
    report
  • MDratwa
    How about a set of "IF" checking on pos 2 or 3 and moving to the correct position (with leading zeros).
    785 pointsBadges:
    report
  • MDratwa
    You can use the keying function of right adjust with zeros (change the screen).
    785 pointsBadges:
    report
  • Splat
    MDratwa, better to use an EVALR on the field prior to the %xlate, e.g.:Evalr yourfield = yourfield;Yourfield = %Xlate(‘  ‘ : ’0′);
    7,425 pointsBadges:
    report
  • philpl1jb
    if this were an issue I might make a line of code like this  ...     FixedVal  =  %substr( '000' +  %TRIM(ScreenVal) : %LEN('000' +  %TRIM(ScreenVal)) - 2 : 3)
    50,465 pointsBadges:
    report
  • ToddN2000
    Change the DDS and set the input field to CHECK(RZ) to right adjust zero fill.
    12,875 pointsBadges:
    report
  • TomLiotta
    Are the users deliberately typing a blank as the first character? Or does the display file currently shift the characters to the right? Is the input supposed to be three numeric digits? If so, why is it defined as 3A? The actual data characteristics should be explained first. -- Tom
    125,585 pointsBadges:
    report
  • RamvishakRamesh
    It is a field in display file for country code. So when user enters ' 50' or '50 ' it should be considered as '050'.
    2,505 pointsBadges:
    report
  • RamvishakRamesh
    CHECK(RZ) is not giving result as '050' if I enter ' 50'
    2,505 pointsBadges:
    report
  • TomLiotta
    If the user types the leading blank, then CHECK(RZ) can't do anything. You need to answer the earlier questions about your problem before anything will be helpful. -- Tom
    125,585 pointsBadges:
    report
  • RamvishakRamesh
    User deliberately types blanks. cannot change the country code to numeric as it is a standard being followed.
    2,505 pointsBadges:
    report
  • TomLiotta
    Since the standard seems to be wrong, you should change the standard. (Why would anyone want a standard with guaranteed built-in flaws?) But if you can't change the standard, you need to change blanks to zeros in your program code. -- Tom
    125,585 pointsBadges:
    report
  • TomLiotta
    So when user enters ‘ 50′ or ’50 ‘ it should be considered as ’050′.   Although CHECK(RZ) won't put zeros into the leading positions when a user types blanks, the value can be right-adjusted automatically for you. That's a slight help. However, if the country code is '050' and the user enters ' 50' or '50 ', then you can return an error. It's an incorrect country code.   But you can pass the trimmed value into the atoi() — Convert Character String to Integer API. The integer result will be (50). You can assign the result to a 3-digit zoned-decimal field and reference it as a character value to get '050'.   Tom
    125,585 pointsBadges:
    report
  • RamvishakRamesh
    I have done it this way, I didnt change the display file field from character to int, instead Eval      wCntry     = %Int(DspfFld)     Then moved wCntry to the Keyfield value to vaidate. So when user enters '  50', wCntry will have '050' itself
    2,505 pointsBadges:
    report
  • TomLiotta
    Yes, %INT() is probably a better way in RPG. It's more likely to be familiar. Good choice. -- Tom
    125,585 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