DBCS Function Handling

Some built-in functions can handle DBCS. The functions that deal with word delimiting and length determining conform with the following rules under OPTIONS EXMODE:

  1. Counting characters--Logical character lengths are used when counting the length of a string (that is, 1 byte for one SBCS logical character, 2 bytes for one DBCS logical character). In EBCDIC, SO and SI are considered to be transparent, and are not counted, for every string operation.
  2. Character extraction from a string--Characters are extracted from a string on a logical character basis. In EBCDIC, leading SO and trailing SI are not considered as part of one DBCS character. For instance, .A and .B are extracted from <.A.B>, and SO and SI are added to each DBCS character when they are finally preserved as completed DBCS characters. When multiple characters are consecutively extracted from a string, SO and SI that are between characters are also extracted. For example, .A><.B is extracted from <.A><.B>, and when the string is finally used as a completed string, the SO prefixes it and the SI suffixes it to give <.A><.B>.

    Here are some EBCDIC examples:

    S1 = 'abc<>def'
    
    SUBSTR(S1,3,1)      ->    'c'
    SUBSTR(S1,4,1)      ->    'd'
    SUBSTR(S1,3,2)      ->    'c<>d'
    
    S2 = '<><.A.B><>'
    
    SUBSTR(S2,1,1)      ->    '<.A>'
    SUBSTR(S2,2,1)      ->    '<.B>'
    SUBSTR(S2,1,2)      ->    '<.A.B>'
    SUBSTR(S2,1,3,'x')  ->    '<.A.B><>x'
    
    S3 = 'abc<><.A.B>'
    
    SUBSTR(S3,3,1)      ->    'c'
    SUBSTR(S3,4,1)      ->    '<.A>'
    SUBSTR(S3,3,2)      ->    'c<><.A>'
    DELSTR(S3,3,1)      ->    'ab<><.A.B>'
    DELSTR(S3,4,1)      ->    'abc<><.B>'
    DELSTR(S3,3,2)      ->    'ab<.B>'
  3. Character concatenation--String concatenation can only be done with valid mixed strings. In EBCDIC, adjacent SI and SO (or SO and SI) that are a result of string concatenation are removed. Even during implicit concatenation as in the DELSTR function, unnecessary SO and SI are removed.
  4. Character comparison--Valid mixed strings are used when comparing strings on a character basis. A DBCS character is always considered greater than an SBCS one if they are compared. In all but the strict comparisons, SBCS blanks, DBCS blanks, and leading and trailing contiguous SO and SI (or SI and SO) in EBCDIC are removed. SBCS blanks may be added if the lengths are not identical.

    In EBCDIC, contiguous SO and SI (or SI and SO) between nonblank characters are also removed for comparison.

    Note:
    The strict comparison operators do not cause syntax errors even if you specify mixed strings that are not valid.

    In EBCDIC:

          '<.A>' = '<.A. >'     ->    1     /* true  */
      '<><><.A>' = '<.A><><>'   ->    1     /* true  */
      '<>  <.A>' = '<.A>'       ->    1     /* true  */
    '<.A><><.B>' = '<.A.B>'     ->    1     /* true  */
           'abc' < 'ab<. >'     ->    0     /* false */
  5. Word extraction from a string--"Word" means that characters in a string are delimited by an SBCS or a DBCS blank.

    In EBCDIC, leading and trailing contiguous SO and SI (or SI and SO) are also removed when words are separated in a string, but contiguous SO and SI (or SI and SO) in a word are not removed or separated for word operations. Leading and trailing contiguous SO and SI (or SI and SO) of a word are not removed if they are among words that are extracted at the same time.

    In EBCDIC:

    W1 = '<><. .A. . .B><.C. .D><>'
    
    SUBWORD(W1,1,1)      ->    '<.A>'
    SUBWORD(W1,1,2)      ->    '<.A. . .B><.C>'
    SUBWORD(W1,3,1)      ->    '<.D>'
    SUBWORD(W1,3)        ->    '<.D>'
    
    W2 = '<.A. .B><.C><> <.D>'
    
    SUBWORD(W2,2,1)      ->    '<.B><.C>'
    SUBWORD(W2,2,2)      ->    '<.B><.C><> <.D>'

Built-in Function Examples

Examples for built-in functions, those that support DBCS and follow the rules defined, are given in this section. For full function descriptions and the syntax diagrams, refer to Functions.

ABBREV

In EBCDIC:

ABBREV('<.A.B.C>','<.A.B>')     ->    1
ABBREV('<.A.B.C>','<.A.C>')     ->    0
ABBREV('<.A><.B.C>','<.A.B>')   ->    1
ABBREV('aa<>bbccdd','aabbcc')   ->    1

Applying the character comparison and character extraction from a string rules.

COMPARE

In EBCDIC:

COMPARE('<.A.B.C>','<.A.B><.C>')     ->   0
COMPARE('<.A.B.C>','<.A.B.D>')       ->   3
COMPARE('ab<>cde','abcdx')           ->   5
COMPARE('<.A><>','<.A>','<. >')      ->   0

Applying the character concatenation for padding, character extraction from a string, and character comparison rules.

COPIES

In EBCDIC:

COPIES('<.A.B>',2)       ->   '<.A.B.A.B>'
COPIES('<.A><.B>',2)     ->   '<.A><.B.A><.B>'
COPIES('<.A.B><>',2)     ->   '<.A.B><.A.B><>'

Applying the character concatenation rule.

DATATYPE

DATATYPE('<.A.B>')       ->   'CHAR'
DATATYPE('<.A.B>','D')   ->   1
DATATYPE('<.A.B>','C')   ->   1
DATATYPE('a<.A.B>b','D') ->   0
DATATYPE('a<.A.B>b','C') ->   1
DATATYPE('abcde','C')    ->   0
DATATYPE('<.A.B','C')    ->   0
DATATYPE('<.A.B>','S')   ->   1      /* if ETMODE is on */

Note: If string is not a valid mixed string and C or D is specified as type, 0 is returned.

FIND

FIND('<.A. .B.C> abc','<.B.C> abc')    ->   2
FIND('<.A. .B><.C> abc','<.B.C> abc')  ->   2
FIND('<.A. . .B> abc','<.A> <.B>')     ->   1

Applying the word extraction from a string and character comparison rules.

INDEX, POS, and LASTPOS

INDEX('<.A><.B><><.C.D.E>','<.D.E>')    ->   4
POS('<.A>','<.A><.B><><.A.D.E>')        ->   1
LASTPOS('<.A>','<.A><.B><><.A.D.E>')    ->   3

Applying the character extraction from a string and character comparison rules.

INSERT and OVERLAY

In EBCDIC:

INSERT('a','b<><.A.B>',1)             -> 'ba<><.A.B>'
INSERT('<.A.B>','<.C.D><>',2)         -> '<.C.D.A.B><>'
INSERT('<.A.B>','<.C.D><><.E>',2)     -> '<.C.D.A.B><><.E>'
INSERT('<.A.B>','<.C.D><>',3,,'<.E>') -> '<.C.D><.E.A.B>'

OVERLAY('<.A.B>','<.C.D><>',2)          -> '<.C.A.B>'
OVERLAY('<.A.B>','<.C.D><><.E>',2)      -> '<.C.A.B>'
OVERLAY('<.A.B>','<.C.D><><.E>',3)      -> '<.C.D><><.A.B>'
OVERLAY('<.A.B>','<.C.D><>',4,,'<.E>')  -> '<.C.D><.E.A.B>'
OVERLAY('<.A>','<.C.D><.E>',2)          -> '<.C.A><.E>'

Applying the character extraction from a string and character comparison rules.

JUSTIFY

JUSTIFY('<><. .A. . .B><.C. .D>',10,'p')
                   ->   '<.A>ppp<.B><.C>ppp<.D>'
JUSTIFY('<><. .A. . .B><.C. .D>',11,'p')
                   ->   '<.A>pppp<.B><.C>ppp<.D>'
JUSTIFY('<><. .A. . .B><.C. .D>',10,'<.P>')
                   ->   '<.A.P.P.P.B><.C.P.P.P.D>'
JUSTIFY('<><.X. .A. . .B><.C. .D>',11,'<.P>')
                   ->   '<.X.P.P.A.P.P.B><.C.P.P.D>'

Applying the character concatenation for padding and character extraction from a string rules.

LEFT, RIGHT, and CENTER

In EBCDIC:

LEFT('<.A.B.C.D.E>',4)     ->   '<.A.B.C.D>'
LEFT('a<>',2)              ->   'a<> '
LEFT('<.A>',2,'*')         ->   '<.A>*'
RIGHT('<.A.B.C.D.E>',4)    ->   '<.B.C.D.E>'
RIGHT('a<>',2)             ->   ' a'
CENTER('<.A.B>',10,'<.E>') ->   '<.E.E.E.E.A.B.E.E.E.E>'
CENTER('<.A.B>',11,'<.E>') ->   '<.E.E.E.E.A.B.E.E.E.E.E>'
CENTER('<.A.B>',10,'e')    ->   'eeee<.A.B>eeee'

Applying the character concatenation for padding and character extraction from a string rules.

LENGTH

In EBCDIC:

LENGTH('<.A.B><.C.D><>')      ->   4

Applying the counting characters rule.

REVERSE

In EBCDIC:

REVERSE('<.A.B><.C.D><>')      ->   '<><.D.C><.B.A>'

Applying the character extraction from a string and character concatenation rules.

SPACE

In EBCDIC:

SPACE('a<.A.B. .C.D>',1)        ->  'a<.A.B> <.C.D>'
SPACE('a<.A><><. .C.D>',1,'x')  ->  'a<.A>x<.C.D>'
SPACE('a<.A><. .C.D>',1,'<.E>') ->  'a<.A.E.C.D>'

Applying the word extraction from a string and character concatenation rules.

STRIP

In EBCDIC:

STRIP('<><.A><.B><.A><>',,'<.A>')   ->  '<.B>'

Applying the character extraction from a string and character concatenation rules.

SUBSTR and DELSTR

In EBCDIC:

SUBSTR('<><.A><><.B><.C.D>',1,2)  ->  '<.A><><.B>'
DELSTR('<><.A><><.B><.C.D>',1,2)  ->  '<><.C.D>'
SUBSTR('<.A><><.B><.C.D>',2,2)    ->  '<.B><.C>'
DELSTR('<.A><><.B><.C.D>',2,2)    ->  '<.A><><.D>'
SUBSTR('<.A.B><>',1,2)            ->  '<.A.B>'
SUBSTR('<.A.B><>',1)              ->  '<.A.B><>'

Applying the character extraction from a string and character concatenation rules.

SUBWORD and DELWORD

In EBCDIC:

SUBWORD('<><. .A. . .B><.C. .D>',1,2) ->  '<.A. . .B><.C>'
DELWORD('<><. .A. . .B><.C. .D>',1,2) ->  '<><. .D>'
SUBWORD('<><.A. . .B><.C. .D>',1,2)   ->  '<.A. . .B><.C>'
DELWORD('<><.A. . .B><.C. .D>',1,2)   ->  '<><.D>'
SUBWORD('<.A. .B><.C><> <.D>',1,2)    ->  '<.A. .B><.C>'
DELWORD('<.A. .B><.C><> <.D>',1,2)    ->  '<.D>'

Applying the word extraction from a string and character concatenation rules.

SYMBOL

In EBCDIC:

Drop A.3  ;  <.A.B>=3      /* if ETMODE is on */

SYMBOL('<.A.B>')    ->    'VAR'
SYMBOL(<.A.B>)      ->    'LIT'  /* has tested "3" */
SYMBOL('a.<.A.B>')  ->    'LIT'  /* has tested A.3 */

TRANSLATE

In EBCDIC:

TRANSLATE('abcd','<.A.B.C>','abc')       ->  '<.A.B.C>d'
TRANSLATE('abcd','<><.A.B.C>','abc')     ->  '<.A.B.C>d'
TRANSLATE('abcd','<><.A.B.C>','ab<>c')   ->  '<.A.B.C>d'
TRANSLATE('a<>bcd','<><.A.B.C>','ab<>c') ->  '<.A.B.C>d'
TRANSLATE('a<>xcd','<><.A.B.C>','ab<>c') ->  '<.A>x<.C>d'

Applying the character extraction from a string, character comparison, and character concatenation rules.

VALUE

In EBCDIC:

Drop A3  ;  <.A.B>=3  ;  fred='<.A.B>'

VALUE('fred')       ->    '<.A.B>'  /* looks up FRED   */
VALUE(fred)         ->    '3'       /* looks up <.A.B> */
VALUE('a'<.A.B>)    ->    'A3'      /* if ETMODE is on */

VERIFY

In EBCDIC:

VERIFY('<><><.A.B><><.X>','<.B.A.C.D.E>')   ->  3

Applying the character extraction from a string and character comparison rules.

WORD, WORDINDEX, and WORDLENGTH

In EBCDIC:

W = '<><. .A. . .B><.C. .D>'

WORD(W,1)           ->    '<.A>'
WORDINDEX(W,1)      ->    2
WORDLENGTH(W,1)     ->    1

Y = '<><.A. . .B><.C. .D>'

WORD(Y,1)           ->    '<.A>'
WORDINDEX(Y,1)      ->    1
WORDLENGTH(Y,1)     ->    1

Z = '<.A  .B><.C> <.D>'

WORD(Z,2)           ->    '<.B><.C>'
WORDINDEX(Z,2)      ->    3
WORDLENGTH(Z,2)     ->    2

Applying the word extraction from a string and (for WORDINDEX and WORDLENGTH) counting characters rules.

WORDS

In EBCDIC:

W = '<><. .A. . .B><.C. .D>'

WORDS(W)           ->    3

Applying the word extraction from a string rule.

WORDPOS

In EBCDIC:

WORDPOS('<.B.C> abc','<.A. .B.C> abc')            ->   2
WORDPOS('<.A.B>','<.A.B. .A.B><. .B.C. .A.B>',3)  ->   4

Applying the word extraction from a string and character comparison rules.