APIs by Example: Number Conversions with _CVTEFN and _LBCPYNV

Article ID: 17496

In Carsten Flensburg's October 2 APIs by Example, he left the use of the _CVTEFN and _LBCPYNV MI built-in functions to convert numeric fields to a form usable in a record buffer as an "exercise for the reader." In this installment, he offers two sample RPG ILE programs that show you how to use these two functions.

The _CVTEFN (Convert External Form to Numeric Value) function is used to remove display characters, such as currency signs, commas, and decimal points, from a string and convert the resulting number to various numeric formats. The sample program CBX903A shows how to convert the string -12.345.678,912 to packed and binary fields.

The _LBCPYNV (Late-bound Copy Numeric Value) function converts a number to various numeric formats. In the sample program CBX903B, the packed number -12345678.915 is converted into zoned-decimal format.

You can read more about these two MI functions in the "ILE C/C++ for iSeries MI Library Reference" manual at http://publib.boulder.ibm.com/iseries/v5r2/ic2924/books/c0924180.pdf. The manual is also listed under the "C and C++" topic in the iSeries DocFinder at http://www.iseriesnetwork.com/resources/isndocfinder/c.htm.

You can obtain the RPG IV sample program CBX903A and CBX903B at http://www.iseriesnetwork.com/noderesources/code/clubtechcode/ConvertNumbers.zip.

The above source code was written by Carsten Flensburg. For questions regarding this tip, contact Carsten at mailto:flensburg@novasol.dk.

ProVIP Sponsors

ProVIP Sponsors