|
Actually, before Vini gave me the atoi function which I wound up
using I did it in RPG like this:
Eval TempString = '00000000000' + %Trim(TestInvOrCtr)
Eval Position = %Scan(' ': TempString)
Eval InvoiceStr = %SubSt(TempString: Position - 11: 11)
And InvoiceStr is a member of a Data Structure that is overlaying
InvoiceNo. Works fine, but the atoi works much better, IMO.
By the time I am trying to do this I have already determined that my
string only contains numbers and spaces by doing a Check.
Doing it this way, if someone put in a string such as '123 456 ' the
program wouldn't bomb with a decimal data error, but would translate
the number as 123.
Looking at your code I am not quite sure what it is doing, to be
honest. I will have to research the difference between Check and
CheckR(E) and also your use of the SUBST op code. I try to use
Eval where ever possible, so use the %SubSt expression rather than
the op code. Also, difference between Move and Move(p).
Regards,
Jim Langston
"Anthony C. Paul" wrote:
> Jim:
>
> 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
+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.