The preprocessor ANSWER statement can be used only in a preprocessor procedure that does not have the RETURNS attribute.
The ANSWER statement produces text and/or invokes other preprocessor procedures. The answered text replaces the invocation of the preprocessor procedure in the source text. You can use any number of ANSWER statements in a preprocessor procedure.
Abbreviations: ANS for ANSWER, COL for COLUMN, MAR for MARGINS
If it is an expression, the expression evaluation occurs in the usual manner and the result is converted to a single character string.
If SCAN or RESCAN is in effect, the character string is scanned for replacements and preprocessor procedure invocations. This replacement is done within the scope of the preprocessor procedure and not in the scope into which the answered text is returned. The answered text is then inserted into the source at the point of the preprocessor invocation. After the text is returned into the source, it is not scanned for any replacement activity.
Replacement activity in the string follows the same rules as those for source text scanning and replacement. See Example.
The values specified for exp5 must be within the range returned by the MACLMAR (left margin) and MACRMAR (right margin) built-in functions.
If you do not specify the MARGINS option for an ANSWER statement, the default value is MARGINS(MACLMAR,MACRMAR); if you specify the MARGINS option with no operands, the default value is MARGINS(MACCOL,MACRMAR).
You must not use both the RETURN statement with an expression and the ANSWER statement within the same preprocessor procedure.
%dcl (Expression, Single_string) entry;
%dcl (Deactivated_macro, Statement_function) entry;
%dcl Deactivated_variable character;
%deact Deactivated_variable, Deactivated_macro;
%Deactivated_variable = '** value of deactivated variable **';
%Deactivated_macro: procedure returns( character );
return( '** value of deactivated macro **' );
%end;
%Statement_function: procedure( key1 ) stmt returns( fixed );
dcl key1 fixed;
return( key1 + key1 );
%end;
%Expression: procedure;
ANS( Counter ) skip;
ANS( Deactivated_macro ) skip;
ANS( Deactivated_variable ) skip;
/* The following is invalid: */
/* ANS( Statement_function Key1(7);); */
%end;
%Single_string: procedure;
ANS( 'Counter' ) skip;
ANS( 'Deactivated_macro' ) skip;
ANS( 'Deactivated_variable' ) skip;
ANS( 'Statement_function Key1( 7 );' ) skip;
%end;
Expression /* Generates: */
/* 00001 */
/* ** value of deactivated macro ** */
/* ** value of deactivated variable ** */
Single_string /* Generates: */
/* Counter */
/* Deactivated_macro */
/* Deactivated_variable */
/* 14 */