ANSWER[1]

Purpose

Invokes other preprocessor procedures, and/or produces text. Answered text replaces the invocation of the preprocessor procedure in the source text. The number of ANSWER statements you can use in a preprocessor procedure is unlimited.

Syntax

>>--ANSWER----------------------------------------------------------->  
           |+-(-exp1-)-+|  |+-PAGE---------------+|
                           |+-SKIP---------------+|
                                     |+-(-exp2-)-+| 
>-------------------------------------------------------------;-----><
  |+-COLUMN--(-exp3-)-+|  |+-MARGINS------------------------+|
                                    |+-(-exp4-------------)-+|
                                              |+-,-exp5-+|

Abbreviation for ANSWER: ANS

Parameters

expn
A character expression representing the ANSWER text, which can be either a single character string constant or a preprocessor expression of any complexity.
When expn is a character expression, its evaluation occurs in the usual manner, and the result is converted to a single character string.

If SCAN or RESCAN is set, the character string is scanned for preprocessor procedure invocations and replacements. The returned replacement is within the scope of the preprocessor procedure and not in the scope where the answered text is returned. Answered text is inserted into the source at the point of the preprocessor invocation. Once the text has been returned into the source, it is not scanned for any replacement activity.

String replacement activity follows the same rules as those for source text scanning and replacement.

PAGE
Places answer text on a new page of the output source by generating a %PAGE directive.
SKIP
Places answer text on a new line of the output source. The value provided for exp2 represents an arithmetic expression that specifies the number of lines to be skipped. When omitted, the default value of exp2 is 1.
COLUMN
Identifies the starting column in the source program line where the answer text is placed. The exp3 value represents the arithmetic expression for the column number of the source program line where the answer text starts.

Abbreviation: COL

MARGINS
Identifies the placement of output text within the output record. The exp4 value represents the arithmetic expression for the left margin for the output text. The exp5 value represents the arithmetic expression for the right margin for the output text.

exp5 specifies values that must be within the range returned by the MACLMAR (left margin) and MACRMAR (right margin) built-in functions.

If you omit this option, the default value is MARGINS(MACLMAR,MACRMAR); if you include this option with no operands, the default value is MARGINS(MACCOL,MACRMAR).

Abbreviation: MAR

Comments

Use this statement only in a preprocessor procedure that does not also use the RETURNS attribute.

Do not use both the RETURN statement with an expression, and the ANSWER statement within the same preprocessor procedure.

When an expression invokes a macro, and that macro does not return a value, the macro preprocessor assumes that a null string is returned.

Example

 %dcl Expression entry; 
 %Expression: procedure;
   dcl sn fixed; sn = 4;  
   ANS( "IF (X > 3) THEN") col(sn) skip; 
   ANS( "put skip list('x is greater than 3');") col(sn + 2) skip;  
   ANS( "PUT")              COL (SN) skip; 
   ANS( "SKIP")             COL (SN+6); 
   ANS( "LIST")             COL (SN+12); 
   ANS( "('Hello World');") COL (SN+18); 
  %end;  
  foo: proc() options(main);   
    dcl x fixed bin(31) init(4);  
 Expression      
  end;

Generates:

 FOO: PROC() OPTIONS(MAIN);     
   DCL X FIXED BIN(31) INIT(4); 

   IF (X > 3) THEN                                                           
     put skip list('x is greater than 3');
   PUT   SKIP  LIST  ('Hello World');     
 END;