You need to redefine the char field either in W/S or where it is defined in the input file. If you redefine a char field to numeric you should do a numeric test on the field before using it as numeric, otherwise your may abend with a S0C7. Yea, that's the hard way to do it above... This is one of the most common Easytrieve questions I encounter in the field. There is a macro that is shipped from CA called ALHPACON. You send it an alpha field and it returns a numeric. %ALHPACON ALPHA-FIELD NUMERIC-FIELD Ask your systems programmer to look for the shipped macros if it is not in your maclib.
IF WS-AGE NUMERIC DISPLAY "NUMERIC" ELSE DISPLAY "NOT NUMERIC' END-IF
There are a couple of different ways to convert upper case characters to lower case in easytrieve. One is to use the INSPECT/CONVERTING command.
You can't convert the data type of any variable.
your wish
no
IF WS-AGE NUMERIC DISPLAY "NUMERIC" ELSE DISPLAY "NOT NUMERIC' END-IF
There are a couple of different ways to convert upper case characters to lower case in easytrieve. One is to use the INSPECT/CONVERTING command.
You can't convert the data type of any variable.
numeric value for monthly income
Character.toString('c')
(CXXX)
your wish
no
convert alphanumeric to numeric data definitions required convert-this w 5 a convert-this-num convert-this 5 n 0 convert-this-byte convert-this 1 a occurs 5 index ctb-x this-packed w 3 p 0 error-flag 1 1 a procedure is error-flag = 'x' ctb-x = 0 do-while ctb-c < 5 case convert-this-byte value numeric error-flag = error-flag *or any other null action value ' ' convert-this-byte = '0' * if there are valid characters that need to be converted - test for them and convert them, in my day it was spaces to the left convert to zero blindly otherwiese error-flag = 'y' end-case ctb-x = ctb-x + 1 end-do if error-flag = 'y' *define an error routine and execute it else this-packed = convert-this-num * move the field to the resulting packed field "this-packed" end-if
The char data type is a single 16-bit, unsigned Unicode character. It ranges from 0 to 65,535. They are not integral data type like int, short etc. i.e. the char data type can't hold the numeric values. The syntax of declaring a char type variable is shown as:char caps = 'c';
Formally, you cannot do this. A char containing a character value has a different bit configuration than an int. Attempting to convert between the two is non-portable. However, in the ASCII character set, the character '0' has the value 48, or 0x30. If you subtract 48 from the char you will get the int value, but only if the char was one of the digits '0' through '9'. It is better to use the library routines to convert, such as atoi and sscanf, because they will give you predictable, portable results.
Although character data types such as char are intrinsically numeric, whenever you print a char you automatically print the symbol associated with the character code (the char's value), never the code. In order to print the code you must cast the character to a numeric data type, such as int. char c = 'A'; // ASCII value 65 decimal (0x41) std::cout << static_cast<int>(c); // puts the value 65 on std::cout