Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

CHARACTER-TO-INTEGER( ) Convert character to integer

&pagelevel(3)&pagelevel

Domain: Conversion functions

The CHARACTER-TO-INTEGER( ) function converts one character to a decimal number based on the characters EBCDIC code.

If the input string consists of several characters, then only the first character is converted.

All characters in a string can be converted in combination with the corresponding string function (e.g. SUBSTRING).

Format

CHARACTER-TO-INTEGER( )

CHAR-TO-INT( )

STRING = string_expression

Result type

INTEGER (<integer 0..255>)

Input parameters

STRING = string_expression
Designates the string whose first character is to be converted.
If “string_expression” designates a null string, an error message is output.

Result

Integer <integer 0..255>

Error message

SDP0417  SPECIFIED STRING EMPTY. FUNCTION NOT EXECUTED

Example 1: Converting a character

C = CHARACTER-TO-INTEGER(STRING = 'ABC')
/SHOW-VARIABLE C
C = 193 

In EBCDI code, the first character in the string (the A) is shown as X’C1’ in half-byte notation and as B’11000001’ in binary notation. This corresponds to the number 193 in the decimal system (= 128 + 64 + 1). CHARACTER-TO-INTEGER( ) thus converts the letter A to the number 193.

Example 2: Converting all characters in a string

/BEGIN-BLOCK
/   INT = 1
/   CSTRING = 'ABC'
/   SUBST: CONVSTRING = SUBSTRING(CSTRING, INT)
/   CODE = CHARACTER-TO-INTEGER(STRING = CONVSTRING)
/   SHOW-VARIABLE CODE
/   INT = INT+1
/   IF (INT < 4)
/      GOTO SUBST
/   END-IF
/END-BLOCK

SHOW-VARIABLE outputs the numbers 193, 194 and 195 consecutively in a loop.