Return to the RPG Tips
Convert a String to Numeric
I would: 1. Scan (from right) the string for non-blanks, getting the length of the string. 2. Use that length to define a variable length field 3. Move the string into the variable length field 4. Move the variable length field into a numeric field You should be able to compile this & step through it so see how it works. +++++++++++++++++++ d input_field s 10 d fld_variable s 10a varying d numeric_fld s 10 0 * c move '1234 ' input_field c ' ' CHECKR(E) input_field Num 2 0 c eval %len(fld_variable) = Num c Num SUBST input_field:1 fld_variable c move(p) fld_variable numeric_fld * c seton lr OR Try the atof() procedure available in the binding directory QC2LE. the prototype for it goes like this: dc2f pr 8f extproc('atof') dstring * value options(*string) c eval int=c2f(%trim(amount1)) In the above example amount1 is the character field to be converted. While compiling don't forget to add the QC2LE binding directory entry
[report a broken link by clicking here]