Another cool thing about QC2LE is that the ILE C/400 runtime includes the full set of open AS/400 MI instructions. That is the AS/400 assembly language can be called directly from RPG IV by prototyping their C/400 functions. For example, to call the Convert Characters to Hexadecimal Symbols MI instruction, you would call the 'cvthc' C runtime function. For example:
The following RPG IV code should compile on any version of OS/400 that includes RPG IV.
PHP-Code:
.....DName+++++++++++EUDS.......Length+TDc.Functions++++++++++++++++++
     
D szCharVal       S             20A   Inz('ABCDEFG')
     
D szHexVal        DS
     D   szHex1                            LIKE
(szCharVal)
     
D   szHex2                            LIKE(szCharVal)
     
D nCharLen        S              9B 0 
.....CSRn01..............OpCode(ex)Extended-factor2++++++++++++++++++
     **  if 
you want to avoid converting trailing blanks, use this stmt.
     
C     ' '           CheckR    szCharVal     nCharLen
     
**  or if you want to convert trailing blanks, use this stmt.
     
C                   Eval      nCharLen = %size(szCharVal) * 2   
.....CSRn01Factor1+++++++OpCode(ex)Factor2+++++++Result++++++++Len++DcHiLoEq
     
**  This converts '123' to 'F1F2F3'
     
C                   CALLB     'cvthc'
     
C                   Parm                    szHexVal
     C                   Parm                    szCharVal
     C                   Parm                    nCharLen
     
**  This converts 'F1F2F3' to '123'
     
C                   CALLB     'cvtch'
     
C                   Parm                    szCharVal
     C                   Parm                    szHexVal
     C                   Parm                    nCharLen 
Just a few things to remember when using the C runtime APIs.
  • The names are case-sensitive. That is 'cvthc' must be specified in lower case or it will not be found.
  • These functions are located in the OS/400 C-runtime library and must be bound using the QC2LE binding directory.
  • Parameters that require pass-by-value restrict the API to being called with newer releases of RPG IV, via procedure prototypes.
  • C functions that have return values cannot be called by RPG IV under OS/400 version 3, release 1.
  • Until you move to V3 R2 or, even better, V3 R7, the number of interfaces that can be accessed by RPG IV is limited. In fact, the HexToChar, CharToHex functions are about all that are useful.
  • Under later releases of RPG IV, procedure prototypes allow access to all of the C runtime functions. This includes those nice little date and time formatting functions, such as asctime.
For more details and examples of using procedure prototypes with the C runtime library, see the article on interfacing RPG IV with the C/400 language runtime library on the RPG Developer Network News page.
entnommen von Frequently Asked Questions

kuempi