Need help in moving Character field to numeric field in RPG.

70 pts.
Tags:
AS/400
AS/400 numeric fields
AS400 RPGLE
Need help in moving Character field to numeric field in RPG. I have a character field of lenght 10 in the file and its was left aligned. Now I'm reading the file and get this value and moving to a numeric field of 20 length. I'm facing a problem while moving since its was a left aligned i'm not able to move to numeric field. Its populating the field with value follwed by Zeros. I need Zero prefix to the field value.

Answer Wiki

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

RPG or RPGLE/RPG IV???
In RPGLE it might look something like this.
my20n = %dec(myChar:20:5) assumes m20n is 20, 5
but since myChar might not be a number you might put it in a monitor block.
Phil

Discuss This Question: 6  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
    In RPGLE fixed format that would be EVAL my20n = %dec(myChar:20:5) Phil
    49,950 pointsBadges:
    report
  • Kvrs80
    Hi Philp, Its RPG. I'm having the data as VAr1 - '1234 ' - Char field VAr2 - 000000000 - Numeric field When i moved C MOVE VAR1 VAR2 ==> VAR2 - 1234000000 Thx, KVr
    70 pointsBadges:
    report
  • philpl1jb
    Ohhh .. trip in the wayback machine "When a character field is moved into a numeric result field, the digit portion of each character is converted to its corresponding numeric character and then moved to the result field. Blanks are transferred as zeros" It sounds like you will need to rebuild the value as 0000001234 1. Move Var1 WRKVAR 10 2. Loop while position 10 of WARKVARAis a blank -- this might require a substr to get value in position 10. 2.1 add a leading zero '0' CAT WRKVAR WRkVAR finlly WRKVAR = 0000001234 3. then MOVE WARVAR Var2 Phil
    49,950 pointsBadges:
    report
  • TomLiotta
    Where are these values coming from? Why are you having character fields that need to be converted into numeric values? Depending on the process, there might be better things to do. Phil has the right answer for what you asked. I'm curious if there could have been other questions at a higher level that might change the circumstances. Tom
    125,585 pointsBadges:
    report
  • Kvrs80
    Hi Phil/Tom, Thanks for the solution. I will try this and let you guys know. Tom This value is 20 char length file field. There are some records with left aligned and i need to move to 20 numeric with leading zeros to another file as per the design. Thanks Kvr.
    70 pointsBadges:
    report
  • TomLiotta
    I understand that the values are in a character field in a file. But why are they put into a file as character values in the first place? Where does the file come from? Why doesn't it just have a numeric field? How are you getting the file? (Why would the field be 20 characters wide? That's a big field for numeric values.) A description of the general process would be helpful. For some kinds of files, it might be possible to do it without programming. For example, you might create a VIEW over the file so that the character column is converted to a numeric value with the DECIMAL() SQL function. 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