IBM AS/400 Sample Service Program, Part, Source for Service Program CvtToHex, CEEDOD1, CEEDOD2

Models: AS/400

1 489
Download 489 pages 47.95 Kb
Page 120
Image 120

Sample Service Program

 

*-----------------------------------------------------------------

 

 

 

*

 

* Use the operational descriptors to determine the length￿s of

*

 

* the parameters that were passed.

 

 

*

 

*-----------------------------------------------------------------

 

 

 

*

C

 

CALLP

CEEDOD(1

 

: DescType : DataType :

C

 

 

DescInfo1 : DescInfo2: Inlen

:

C

 

 

*OMIT)

 

 

 

C

 

CALLP

CEEDOD(2

 

: DescType : DataType :

C

 

 

DescInfo1 : DescInfo2: HexLen

:

C

 

 

*OMIT)

 

 

 

 

*-----------------------------------------------------------------

 

 

 

*

 

* Determine the length to handle (minimum of the input leng￿th

*

 

* and half of the hex length)

 

 

 

*

 

*-----------------------------------------------------------------

 

 

 

*

C

 

IF

InLen > HexLen / 2

 

C

 

EVAL

InLen = HexLen / 2

 

C

 

ENDIF

 

 

 

 

 

*-----------------------------------------------------------------

 

 

 

*

 

* For each character in the input string, convert to a 2-byte￿

*

 

* hexadecimal representation (for example, '5'

--> 'F5')

*

 

*-----------------------------------------------------------------

 

 

 

*

C

 

EVAL

HexPos = 1

 

 

 

C

 

DO

InLen

Pos

 

 

C

 

EVAL

InChar = %SUBST(InString : Pos :1)

 

C

 

EXSR

GetHex

 

 

 

C

 

EVAL

%SUBST(HexString : HexPos : 2) = HexDs

C

 

EVAL

HexPos = HexPos + 2

 

C

 

ENDDO

 

 

 

 

 

*-----------------------------------------------------------------

 

 

 

*

 

* Done; return to caller.

 

 

 

*

 

*-----------------------------------------------------------------

 

 

 

*

C

 

RETURN

 

 

 

 

 

*=================================================================*

 

* GetHex - subroutine to convert 'InChar' to 'HexDs'

*

 

*

 

 

 

 

*

 

* Use division by 16 to separate the two hexadecimal digits￿.

*

 

* The quotient is the first digit, the remainder is the seco￿nd.

*

 

*=================================================================*

C

GetHex

BEGSR

 

 

 

 

C

 

EVAL

IntChar = InChar

 

 

C

IntNum

DIV

16

X1

5 0

 

C

 

MVR

 

X2

5 0

 

 

*-----------------------------------------------------------------

 

 

 

*

 

* Use the hexadecimal digit (plus 1) to substring the list of￿

*

 

* hexadecimal characters '012

...CDEF'.

 

 

*

 

*-----------------------------------------------------------------

 

 

 

*

C

 

EVAL

HexC1 = %SUBST(HexDigits:X1+1:1)

 

C

 

EVAL

HexC2 = %SUBST(HexDigits:X2+1:1)

 

C

 

ENDSR

 

 

 

 

 

 

 

 

 

Figure

42 (Part 2

of 2).

Source for Service Program CvtToHex

 

96 ILE RPG for AS/400 Programmer's Guide

Page 120
Image 120
IBM Sample Service Program, Part, Source for Service Program CvtToHex, ILE RPG for AS/400 Programmers Guide, CEEDOD1