Character Functions for DBCS Code Pages

In this section:

The following functions manipulate strings of DBCS and SBCS characters when your configuration uses a DBCS code page.


Top of page

x
DCTRAN: Translating A Single-Byte or Double-Byte Character to Another

How to:

The DCTRAN function translates a single-byte or double-byte character within a character string to another character based on its decimal value. To use DCTRAN, you need to know the decimal equivalent of the characters in internal machine representation.

To use DCTRAN, you need to know the decimal equivalent of the characters in internal machine representation.



x
Syntax: How to Translate a Single-Byte or Double-Byte Character to Another
DCTRAN(length, source_string, inhexchar, outhexchar, output_format)

where:

length

Double

Is the number of characters in the source_string field.

source_string

Alphanumeric

Is the character string to be translated.

decimal

Double

Is the ASCII or EBCDIC decimal value of the character to be translated.

decvalue

Double

Is the ASCII or EBCDIC decimal value of the character to be used as a substitute for inhexchar.

output_format

Alphanumeric

Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks.



Example: Using DCTRAN to Translate Double-Byte Characters

In the following:


Top of page

x
DEDIT: Extracting or Adding Characters

How to:

If your configuration uses a DBCS code page, you can use the DEDIT function to extract characters from or add characters to a string.

DEDIT works by comparing the characters in a mask to the characters in a source field. When it encounters a nine (9) in the mask, DEDIT copies the corresponding character from the source field to the new field. When it encounters a dollar sign ($) in the mask, DEDIT ignores the corresponding character in the source field. When it encounters any other character in the mask, DEDIT copies that character to the corresponding position in the new field.



x
Syntax: How to Extract or Add DBCS or SBCS Characters
DEDIT(inlength, source_string, mask_length, mask, outfield)

where:

inlength

Integer

Is the number of bytes in source_string. The string can have a mixture of DBCS and SBCS characters. Therefore, the number of bytes represents the maximum number of characters possible in the source string.

source_string

Alphanumeric

Is the string to edit enclosed in single quotation marks, or the field containing the string.

mask_length

Integer

Is the number of characters in mask.

mask

Alphanumeric

Is the string of mask characters.

Each nine (9) in the mask causes the corresponding character from the source field to be copied to the new field.

Each dollar sign ($) in the mask causes the corresponding character in the source field to be ignored.

Any other character in the mask is copied to the new field.

outfield

Alphanumeric

Is the field to which the result is returned, or the format of the output value enclosed in single quotation marks.



Example: Adding and Extracting DBCS Characters

The following example copies alternate characters from the source string to the new field, starting with the first character in the source string, and then adds several new characters at the end of the extracted string:

The following example copies alternate characters from the source string to the new field, starting with the second character in the source string, and then adds several new characters at the end of the extracted string:


Top of page

x
DSTRIP: Removing a Single-Byte or Double-Byte Character From a String

How to:

The DSTRIP function removes all occurrences of a specific single-byte or double-byte character from a string. The resulting character string has the same length as the original string but is padded on the right with spaces.



x
Syntax: How to Remove a Single-Byte or Double-Byte Character From a String
DSTRIP(length, source_string, char, output_format)

where:

length

Double

Is the number of characters in source_string and outfield.

source_string

Alphanumeric

Is the string from which the character will be removed.

char

Alphanumeric

Is the character to be removed from the string. If more than one character is provided, the left-most character will be used as the strip character.

Note: To remove single quotation marks, use two consecutive quotation marks. You must then enclose this character combination in single quotation marks.

output_format

Alphanumeric

Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks.



Example: Removing a Double-Byte Character From a String

In the following:


Top of page

x
DSUBSTR: Extracting a Substring

How to:

If your configuration uses a DBCS code page, you can use the DSUBSTR function to extract a substring based on its length and position in the parent string.



x
Syntax: How to Extract a Substring
DSUBSTR(inlength, parent, start, end, sublength, outfield)

where:

inlength

Integer

Is the length of the parent string in bytes, or a field that contains the length. The string can have a mixture of DBCS and SBCS characters. Therefore, the number of bytes represents the maximum number of characters possible in the parent string.

parent

Alphanumeric

Is the parent string enclosed in single quotation marks, or the field containing the parent string.

start

Integer

Is the starting position (in number of characters) of the substring in the parent string. If this argument is less than one or greater than end, the function returns spaces.

end

Integer

Is the ending position (in number of characters) of the substring. If this argument is less than start or greater than inlength, the function returns spaces.

sublength

Integer

Is the length of the substring in characters (normally end - start + 1). If sublength is longer than end - start +1, the substring is padded with trailing spaces. If it is shorter, the substring is truncated. This value should be the declared length of outfield. Only sublength characters will be processed.

outfield

Alphanumeric

Is the field to which the result is returned, or the format of the output value enclosed in single quotation marks.



Example: Extracting a Substring

The following example extracts the 3-character substring in positions 4 through 6 from a 15-byte string of characters:


Top of page

x
JPTRANS: Converting Japanese Specific Characters

How to:

Reference:

The JPTRANS function converts Japanese specific characters.



x
Syntax: How to Convert Japanese Specific Characters
JPTRANS ('type_of_conversion', length, source_string, 'output_format')

where:

type_of_conversion

Is one of the following options indicating the type of conversion you want to apply to Japanese specific characters. These are the single component input types:

Conversion Type

Description

'UPCASE'

Converts Zenkaku (Fullwidth) alphabets to Zenkaku uppercase.

'LOCASE' 

Converts Zenkaku alphabets to Zenkaku lowercase.

'HNZNALPHA'

Converts alphanumerics from Hankaku (Halfwidth) to Zenkaku.

'HNZNSIGN' 

Converts ASCII symbols from Hankaku to Zenkaku.

'HNZNKANA'

Converts Katakana from Hankaku to Zenkaku.

'HNZNSPACE' 

Converts space (blank) from Hankaku to Zenkaku.

'ZNHNALPHA'

Converts alphanumerics from Zenkaku to Hankaku.

'ZNHNSIGN' 

Converts ASCII symbols from Zenkaku to Hankaku.

'ZNHNKANA'

Converts Katakana from Zenkaku to Hankaku.

'ZNHNSPACE' 

Converts space from Zenkaku to Hankaku.

'HIRAKATA'

Converts Hiragana to Zenkaku Katakana.

'KATAHIRA'

Converts Zenkaku Katakana to Hiragana.

'930TO939' 

Converts codepage from 930 to 939.

'939TO930' 

Converts codepage from 939 to 930.

length

Integer

Is the number of characters in the source_string.

source_string

Alphanumeric

Is the string to convert.

output_format

Alphanumeric

Is the name of the field that contains the output, or the format enclosed in single quotation marks.



Example: Using the JPTRANS Function
JPTRANS('UPCASE', 20, Alpha_DBCS_Field, 'A20')

JPTRANS('LOCASE', 20, Alpha_DBCS_Field, 'A20')

JPTRANS('HNZNALPHA', 20, Alpha_SBCS_Field, 'A20')

JPTRANS('HNZNSIGN', 20, Symbol_SBCS_Field, 'A20')

JPTRANS('HNZNKANA', 20, Hankaku_Katakana_Field, 'A20')

JPTRANS('HNZNSPACE', 20, Hankaku_Katakana_Field, 'A20')

JPTRANS('ZNHNALPHA', 20, Alpha_DBCS_Field, 'A20')

JPTRANS('ZNHNSIGN', 20, Symbol_DBCS_Field, 'A20')

JPTRANS('ZNHNKANA', 20, Zenkaku_Katakana_Field, 'A20')

JPTRANS('ZNHNSPACE', 20, Zenkaku_Katakana_Field, 'A20')

JPTRANS('HIRAKATA', 20, Hiragana_Field, 'A20')

JPTRANS('KATAHIRA', 20, Zenkaku_Katakana_Field, 'A20')

In the following, codepoints 0x62 0x63 0x64 are converted to 0x81 0x82 0x83, respectively:

JPTRANS('930TO939', 20, CP930_Field, 'A20')

In the following, codepoints 0x59 0x62 0x63 are converted to 0x81 0x82 0x83, respectively:

JPTRANS('939TO930', 20, CP939_Field, 'A20')


x
Reference: Usage Notes for the JPTRANS Function

WebFOCUS