|
Jim wrote: >I have a field I am allowing my users to put in a string value >(container number, in the format XXXX999999) or a numeric >value (invoice number, 999999). I now have this variable that >contains one or the other, but in either case, it is left justified. > >So I either have: >'ABCD123456 ' >or >'1234 ' > >Now I'm kinda stumped. I can figure out if it is numeric or a >container number by using the Check opcode. But, once I >know it's numeric, just how do I convert this thing to a numeric >value? Every ILE RPG IV programmer has at their disposal every function in the C runtime library, including such useful functions as atol. Try compiling and running the following program: -------------- H dftactgrp(*no) bnddir('QC2LE') D num s 10i 0 D str s 20 inz('12345') D atol pr 10i 0 extproc('atol') D * value options(*string) C eval num = atol (str) C num dsply C eval *inlr = *on -------------- (It compiles on V4R4, but with a few obvious modifications should also run on V3R7.) Function atol expects as parameter a pointer to a null terminated string. The syntax "* value options(*string)" in the prototype will convert a string in RPG to a C-style null terminated string. You could also pass a pointer for that parameter, but then it's up to you to add in the null at the end of the string. Cheers! Hans Hans Boldt, ILE RPG Development, IBM Toronto Lab, boldt@ca.ibm.com +--- | 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-2024 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.