%label:[label:]... PROCEDURE[(ident[,ident]...)] [STATEMENT]RETURNS(CHARACTER|FIXED|BIT);
Abbreviation(s): %PROC for %PROCEDURE.
%DECLARE (A,B,C) CHARACTER; %ACTIVATE CAT; %A = 'AAA'; %B = 'BBB'; %C = 'CCC'; RES_STRING_3 = CAT(A,B,C); RES_STRING_2 = CAT (A,B); RES_STRING_1 = CAT(A); %CAT: PROCEDURE(X,Y,Z) RETURNS(CHAR); DECLARE (X,Y,Z) CHAR; DECLARE S CHAR; IF PARMSET(Z) THEN S = ''''||X||Y||Z||''''; ELSE IF PARMSET(Y) THEN S = ''''||X||Y||''''; ELSE S = ''''||X||''''; RETURN(S); %END CAT;
The text generated by this example would be as follows:
RES_STRING_3 = 'AAABBBCCC'; RES_STRING_2 = 'AAABBB'; RES_STRING_1 = 'AAA';
This example also shows how to generate a character string constant using the preprocessor. To do so, use four successive apostrophes, followed by the concatenation symbol, followed by the expression for the desired character string constant, followed by another concatenation symbol, followed by four more apostrophes.
Description
The %PROCEDURE statement is used in conjunction with a %END statement to delimit a preprocessor procedure. Such a preprocessor procedure is an internal function procedure that can be executed only by the preprocessor.
The STATEMENT option is ignored in this version of Open PL/I. One of the attributes, CHARACTER, FIXED, or BIT, must be specified in the RETURNS attribute list to indicate the type of value returned by the function procedure. There can be no default.
The preprocessor statements ASSIGNMENT, DECLARE, DO, GOTO, IF, NULL, RETURN, and NOTE can be used within a preprocessor procedure. Inside the preprocessor procedure the % symbols are omitted.