PDA

View Full Version : Hex mit RPG ?



agutknecht
29-04-08, 12:34
Hallo zusammen,
Ich hatte mit RPGIII noch nie was mit Hex gemacht und habe folgendes Problem:

Mein RPG Programm liest eine Zahl aus einer Datei, z.B. '2008' und diese sollte ich als Hexwert-Parameter in ein CL weitergeben.

Kann mir jemand ein Beispiel geben ?

Tausendfachen Dank
A.Gutknecht

kuempi von stein
29-04-08, 15:08
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.


.....DName+++++++++++EUDS.......Length+TDc.Functio ns++++++++++++++++++
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+++++++R esult++++++++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 (http://www.rpgiv.com/rpgnews/index.html) page.

entnommen von Frequently Asked Questions (http://www.rpgiv.com/kb/index.html)

kuempi

agutknecht
02-05-08, 12:34
Besten Dank für das Beispiel.
Gruess
A.Gutknecht