Built-in function examples for DBCS

Examples for built-in functions, those that support DBCS and follow the rules defined, are provided.

For full function descriptions and the syntax diagrams, refer to Functions.

The functions that deal with word delimiting and length determining conform with specific rules under OPTIONS EXMODE. See DBCS function handling for details.

ABBREV

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

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

COMPARE

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

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

COPIES

Applying the character concatenation rule.

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><>'

DATATYPE

Example of DATATYPE function

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 */

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

FIND

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

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

INDEX, POS, and LASTPOS

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

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

INSERT and OVERLAY

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

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>'

JUSTIFY

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

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>'

LEFT, RIGHT, and CENTER

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

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'

LENGTH

Applying the counting characters rule.

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

REVERSE

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

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

SPACE

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

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>'

STRIP

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

In EBCDIC:
STRIP('<><.A><.B><.A><>',,'<.A>')   ->  '<.B>'

SUBSTR and DELSTR

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

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><>'

SUBWORD and DELWORD

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

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>'

SYMBOL

Example of SYMBOL function

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

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

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'

VALUE

Example of VALUE function

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

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

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

WORD, WORDINDEX, and WORDLENGTH

Applying the word extraction from a string and, for WORDINDEX and WORDLENGTH, applying the counting characters rules.

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

WORDS

Applying the word extraction from a string rule.

In EBCDIC:
W = '<><. .A. . .B><.C. .D>'

WORDS(W)           ->    3

WORDPOS

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

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