Rational Developer for System z
Enterprise PL/I for z/OS, Version 3.8, Programming Guide

Macro preprocessor example

A simple example of the use of the preprocessor to produce a source deck is shown in Figure 4. According to the value assigned to the preprocessor variable USE, the source statements will represent either a subroutine (CITYSUB) or a function (CITYFUN).

The DSNAME used for SYSPUNCH specifies a source program library on which the preprocessor output will be placed. Normally compilation would continue and the preprocessor output would be compiled.

Figure 4. Using the macro preprocessor to produce a source deck
//OPT4#8  JOB
//STEP2 EXEC  IBMZC,PARM.PLI='MACRO,MDECK,NOCOMPILE,NOSYNTAX'
//PLI.SYSPUNCH DD  DSNAME=HPU8.NEWLIB(FUN),DISP=(NEW,CATLG),UNIT=SYSDA,
//          SPACE=(TRK,(1,1,1)),DCB=(RECFM=FB,LRECL=80,BLKSIZE=400)
//PLI.SYSIN  DD *
  /* GIVEN ZIP CODE, FINDS CITY                                       */
  %DCL USE CHAR;
  %USE = 'FUN'                  /* FOR SUBROUTINE, %USE = 'SUB' */ ;
  %IF USE = 'FUN' %THEN %DO;
  CITYFUN: PROC(ZIPIN) RETURNS(CHAR(16)) REORDER; /* FUNCTION         */
                        %END;
                  %ELSE %DO;
  CITYSUB: PROC(ZIPIN, CITYOUT) REORDER;     /* SUBROUTINE            */
    DCL CITYOUT CHAR(16);          /* CITY NAME                       */
                        %END;
    DCL (LBOUND, HBOUND) BUILTIN;
    DCL ZIPIN PIC '99999';        /* ZIP CODE                         */
    DCL 1 ZIP_CITY(7) STATIC,     /* ZIP CODE - CITY NAME TABLE       */
          2 ZIP PIC '99999' INIT(
                      95141, 95014, 95030,
                      95051, 95070, 95008,
                      0),           /* WILL NOT LOOK AT LAST ONE      */
          2 CITY CHAR(16) INIT(
                      'SAN JOSE', 'CUPERTINO', 'LOS GATOS',
                      'SANTA CLARA', 'SARATOGA', 'CAMPBELL',
                      'UNKNOWN CITY');  /* WILL NOT LOOK AT LAST ONE  */
    DCL I FIXED BIN(31);
    DO I = LBOUND(ZIP,1) TO             /* SEARCH FOR ZIP IN TABLE    */
           HBOUND(ZIP,1)-1              /* DON'T LOOK AT LAST ELEMENT */
           WHILE(ZIPIN ¬= ZIP(I));
    END;
  %IF USE = 'FUN' %THEN %DO;
    RETURN(CITY(I));                    /* RETURN CITY NAME           */
                        %END;
                  %ELSE %DO;
    CITYOUT=CITY(I);                    /* RETURN CITY NAME           */
                        %END;
  END;


Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)