Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MOVE from character to numeric

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
Hi
this is RPG question. So, I have field, for example 10 characters long field NBCHR = '420356 ' and I´d like to move it to numeric field NBNUM, also 10 long. Solution should be 420356, not 4203560000. Exists any way how to do it through keyword VARYING?
Thanks Martin
 
Thanks for breaking it out...

Now, I had the same problem. Unfortunatly, I never came up with a simple solution. You could maybe right justify then convert into a number. Mike Wills
IBM iSeries (AS/400) Programmer
[pc2]
 
Yes, simply define a field (let's use Varfield) as varying. Do the following:

Eval Varfield = %trim(NBCHR)
Move Varfield NBNUM


If there are any possibilities of non-numeric data getting into the NBCHR field, you may want to check VARFIELD before moving it to NBNUM.

K. Hood
 
O.K. but, how to work with VARFIELD in VARYING, you have to define the lenght of variable, but I´m looking for any variable lenght
 
serpa9x,

Define the field as the maximum length that you will need.

D NBCHR S 30 Varying


C Eval NBCHR = '1234'

In this example the length of NBCHR will be 4 after the Eval, not 30.

 
RPGIV soln, using external procedure atoi --
Compile with BNDDIR(qsys/qc2le)...

0001.00 DStrToNum pr 10i 0 extproc('atoi')
0002.00 D num 10a
0003.00 *
0003.01 C movel(p) *blanks CharString 10
0003.02 C z-add *zeros CvtNum 10 0
0004.00 C eval CharString = ' -153 '
0005.00 C eval CvtNum = StrToNum(CharString)
0006.00 *
0007.00 C eval *inlr = *on
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top