CHR: PROC (INT) RETURNS (CHAR(1)); DCL INT FIXED BINARY, STRING CHAR(1); UNSPEC(STRING)=UNSPEC(INT); RETURN(STRING); END; ASCII: PROC (STRING) RETURNS (FIXED BIN); DCL STRING CHAR (*); DCL C CHAR(1), X FIXED BIN; C=SUBSTR(STRING,1,1); UNSPEC(X)=UNSPEC(C); RETURN(X); END; LEFT: PROC (STRING,COUNT) RETURNS (CHAR(255) VARYING); DCL LENGTH BUILTIN; DCL STRING CHAR(*), COUNT FIXED BIN; IF COUNT<1 | COUNT>LENGTH(STRING) THEN RETURN(''); ELSE RETURN(SUBSTR(STRING,1,COUNT) ); END; RIGHT: PROC (STRING,START) RETURNS (CHAR(255) VARYING); DCL LENGTH BUILTIN; DCL STRING CHAR(*), START FIXED BIN; IF START<1|START>LENGTH(STRING) THEN RETURN(''); ELSE RETURN(SUBSTR(STRING,START)); END; POS: PROC(STRING,SUB,START) RETURNS(FIXED); DCL (LENGTH,INDEX) BUILTIN; DCL (STRING,SUB) CHAR(*); DCL START FIXED; DCL N FIXED; IF START<1 | START>LENGTH(STRING) THEN N=0; ELSE DO; N=INDEX(SUBSTR(STRING,START),SUB); IF N>0 THEN N=N+START-1; END; RETURN(N); END; INSTR: PROC(START,STRING,SUB) RETURNS(FIXED); DCL (LENGTH,INDEX) BUILTIN; DCL START FIXED; DCL (STRING,SUB) CHAR(*); DCL N FIXED; IF START<1 | START>LENGTH(STRING) THEN N=0; ELSE DO; N=INDEX(SUBSTR(STRING,START),SUB); IF N>0 THEN N=N+START-1; END; RETURN(N); END; SEG: PROC(STRING,START,END) RETURNS(CHAR(255) VARYING); DCL (LENGTH,INDEX) BUILTIN; DCL STRING CHAR(*), (START,END) FIXED BIN; IF START<1 | START>LENGTH(STRING) | ENDLENGTH(STRING) THEN RETURN(SUBSTR(STRING,START)); ELSE RETURN(SUBSTR(STRING,START,END-START+1)); END;