How to: |
The CTRAN function translates a character within a character string to another character based on its decimal value. This function is especially useful for changing replacement characters to unavailable characters, or to characters that are difficult to input or unavailable on your keyboard. It can also be used for inputting characters that are difficult to enter when responding to a Dialogue Manager -PROMPT command, such as a comma or apostrophe. It eliminates the need to enclose entries in single quotation marks.
To use CTRAN, you must know the decimal equivalent of the characters in internal machine representation. Note that the coding chart for conversion is platform dependent, hence your platform and configuration option determines whether ASCII, EBCDIC, or Unicode coding is used. Printable EBCDIC or ASCII characters and their decimal equivalents are listed in Character Chart for ASCII and EBCDIC.
In Unicode configurations, this function uses values in the range:
CTRAN(length, source_string, decimal, decvalue, output)
where:
Integer
Is the number of characters in the source string, or a field that contains the length.
Alphanumeric
Is the character string to be translated enclosed in single quotation marks, or the field or variable that contains the character string.
Integer
Is the ASCII or EBCDIC decimal value of the character to be translated.
Integer
Is the ASCII or EBCDIC decimal value of the character to be used as a substitute for decimal.
Alphanumeric
Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks.
CTRAN translates the spaces in ADDRESS_LN3 (ASCII decimal value 32) to underscores (ASCII decimal value 95), and stores the result in ALT_ADDR:
TABLE FILE EMPLOYEE
PRINT ADDRESS_LN3 AND COMPUTE
ALT_ADDR/A20 = CTRAN(20, ADDRESS_LN3, 32, 95, ALT_ADDR);
BY EMP_ID
WHERE TYPE EQ 'HSM';
END
The output is:
EMP_ID ADDRESS_LN3 ALT_ADDR ------ ----------- -------- 117593129 RUTHERFORD NJ 07073 RUTHERFORD_NJ_07073_ 119265415 NEW YORK NY 10039 NEW_YORK_NY_10039___ 119329144 FREEPORT NY 11520 FREEPORT_NY_11520___ 123764317 NEW YORK NY 10001 NEW_YORK_NY_10001___ 126724188 FREEPORT NY 11520 FREEPORT_NY_11520___ 451123478 ROSELAND NJ 07068 ROSELAND_NJ_07068___ 543729165 JERSEY CITY NJ 07300 JERSEY_CITY_NJ_07300 818692173 FLUSHING NY 11354 FLUSHING_NY_11354
CTRAN translates the spaces in ADDRESS_LN3 (EBCDIC decimal value 64) to underscores (EBCDIC decimal value 109) and stores the result in ALT_ADDR:
TABLE FILE EMPLOYEE
PRINT ADDRESS_LN3 AND COMPUTE
ALT_ADDR/A20 = CTRAN(20, ADDRESS_LN3, 64, 109, ALT_ADDR);
BY EMP_ID
WHERE TYPE EQ 'HSM'
END
The output is:
EMP_ID ADDRESS_LN3 ALT_ADDR ------ ----------- -------- 117593129 RUTHERFORD NJ 07073 RUTHERFORD_NJ_07073_ 119265415 NEW YORK NY 10039 NEW_YORK_NY_10039___ 119329144 FREEPORT NY 11520 FREEPORT_NY_11520___ 123764317 NEW YORK NY 10001 NEW_YORK_NY_10001___ 126724188 FREEPORT NY 11520 FREEPORT_NY_11520___ 451123478 ROSELAND NJ 07068 ROSELAND_NJ_07068___ 543729165 JERSEY CITY NJ 07300 JERSEY_CITY_NJ_07300 818692173 FLUSHING NY 11354 FLUSHING_NY_11354___
This MODIFY request enables you to enter the names of new employees containing the accented letter È, as in the name Adèle Molière. The equivalent EBCDIC decimal value for “an asterisk is 92, for an È, 159.
If you are using the Hot Screen facility, some characters cannot be displayed. If Hot Screen does not support the character you need, disable Hot Screen with SET SCREEN=OFF and issue the RETYPE command. If your terminal can display the character, the character appears. The display of special characters depends upon your software and hardware; not all special characters may display.
The request is:
MODIFY FILE EMPLOYEE CRTFORM "***** NEW EMPLOYEE ENTRY SCREEN *****" " " "ENTER EMPLOYEE'S ID: <EMP_ID" " " "ENTER EMPLOYEE'S FIRST AND LAST NAME" "SUBSTITUTE *'S FOR ALL ACCENTED E CHARACTERS" " " "FIRST_NAME: <FIRST_NAME LAST_NAME: <LAST_NAME" " " "ENTER THE DEPARTMENT ASSIGNMENT: <DEPARTMENT" MATCH EMP_ID ON MATCH REJECT ON NOMATCH COMPUTE FIRST_NAME/A10 = CTRAN(10, FIRST_NAME, 92, 159, 'A10'); LAST_NAME/A15 = CTRAN(15, LAST_NAME, 92, 159, 'A15'); ON NOMATCH TYPE "FIRST_NAME: <FIRST_NAME LAST_NAME:<LAST_NAME" ON NOMATCH INCLUDE DATA END
A sample execution follows:
***** NEW EMPLOYEE ENTRY SCREEN ***** ENTER EMPLOYEE'S ID: 999888777 ENTER EMPLOYEE'S FIRST AND LAST NAME SUBSTITUTE *'S FOR ALL ACCENTED E CHARACTERS FIRST_NAME: AD*LE LAST_NAME: MOLI*RE ENTER THE DEPARTMENT ASSIGNMENT: SALES
The request processes as:
EMPLOYEE ID: 999888777
FIRST_NAME: AD*LE
LAST_NAME: MOLI*RE
DEPARTMENT: SALES
***** NEW EMPLOYEE ENTRY SCREEN ***** ENTER EMPLOYEE'S ID: ENTER EMPLOYEE'S FIRST AND LAST NAME SUBSTITUTE *'S FOR ALL ACCENTED E CHARACTERS FIRST_NAME: LAST_NAME: ENTER THE DEPARTMENT ASSIGNMENT: FIRST_NAME: ADÈLE LAST_NAME: MOLIÈRE
This MODIFY request adds records of new employees to the EMPLOYEE data source. The PROMPT command prompts you for data one field at a time. CTRAN enables you to enter commas in names without having to enclose the names in single quotation marks. Instead of typing the comma, you type a semicolon, which is converted by CTRAN into a comma. The equivalent EBCDIC decimal value for a semicolon is 94; for a comma, 107.
The request is:
MODIFY FILE EMPLOYEE
PROMPT EMP_ID LAST_NAME FIRST_NAME DEPARTMENT
MATCH EMP_ID
ON MATCH REJECT
ON NOMATCH COMPUTE
LAST_NAME/A15 = CTRAN(15, LAST_NAME, 94, 107, 'A15');
ON NOMATCH INCLUDE
DATA
A sample execution follows:
> EMPLOYEEFOCUS A ON 04/19/96 AT 16.07.29 DATA FOR TRANSACTION 1 EMP_ID = 224466880 LAST_NAME = BRADLEY; JR. FIRST_NAME = JOHN DEPARTMENT = MIS DATA FOR TRANSACTION 2 EMP_ID = end TRANSACTIONS: TOTAL = 1 ACCEPTED= 1 REJECTED= 0 SEGMENTS: INPUT = 1 UPDATED = 0 DELETED = 0 >
The request processes as:
EMP_ID: 224466880
LAST_NAME: BRADLEY; JR.
FIRST_NAME: JOHN
DEPARTMENT: MIS
TABLE FILE EMPLOYEE PRINT EMP_ID LAST_NAME FIRST_NAME DEPARTMENT IF EMP_ID IS 224466880 END
The output is:
EMP_ID LAST_NAME FIRST_NAME DEPARTMENT ------ --------- ---------- ---------- 224466880 BRADLEY, JR. JOHN MIS
Information Builders |