|
But be aware, if your character field contains only *Blanks, the built-in-functions %INT() and %DEC() will not return *Zeros, but fail. Birgitta -----Ursprungliche Nachricht----- Von: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx]Im Auftrag von Scott Klement Gesendet: Montag, 14. Februar 2005 20:44 An: RPG programming on the AS400 / iSeries Betreff: Re: TESTN > c evalr pay_type_test = paytyp > c testn pay_type_test 99 > c if *in99 > c eval sctax# = %int(paytyp) > c else > c eval msgdata = 'Invalid Transaction Type TESTN is designed to validate a numeric field before using MOVE or a data structure to convert it to a number. TESTN considers many letters to be "valid numbers" because they'd fit in the negative sign zone of a zoned decimal field. Trouble is -- you're not converting it to a zoned decimal field using MOVE. You're converting it to an INTEGER field using %INT()!! Instead of using TESTN, use MONITOR. It's designed for exactly what you're trying to do: c monitor c eval sctax# = %int(paytyp) c on-error c eval msgdata = 'Invalid Transaction Type' c endmon Some people will tell you to use %check(), but IMHO this is incorrect. For example, consider the string ' -1234'. This is a completely valid number for interpretation by %int() but it won't work if you validate it with %check('0123456789':myvar) because it contains both blanks and the negative sign. If you used %check('0123456790- ':myvar), then it would think that strings like '-------' or '- - - -' are valid numbers! So, use MONITOR. If you expect a TON of errors, use %check() first to weed a lot of them out before using MONITOR, but still use MONITOR... Good luck! -- This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/mailman/listinfo/rpg400-l or email: RPG400-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/rpg400-l.
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.