7.48.2 ENDPRINT Examples

Example 1: Consider the 2 following RDML programs which ask a user to input an order number and then print the order line details:

    GROUP_BY  NAME(#ORDERDET) FIELDS(#ORDNUM #CUSTNUM #DATEDUE #ORDLIN #PRODUCT #QUANTITY #PRICE)

    REQUEST   FIELDS(#ORDNUM)

L1:  FETCH     FIELDS(#ORDERDET) FROM_FILE(ORDHDR) WITH_KEY(#ORDNUM) NOT_FOUND(L1) ISSUE_MSG(*YES)

    SELECT    FIELDS(#ORDERDET) FROM_FILE(ORDLIN) WITH_KEY(#ORDNUM)

    UPRINT    FIELDS(#ORDERDET)

    ENDSELECT

    GOTO      L1

and:

     GROUP_BY  NAME(#ORDERDET) FIELDS(#ORDNUM #CUSTNUM #DATEDUE #ORDLIN #PRODUCT #QUANTITY #PRICE)

     REQUEST   FIELDS(#ORDNUM)

L1:   FETCH     FIELDS(#ORDERDET) FROM_FILE(ORDHDR) WITH_KEY(#ORDNUM) NOT_FOUND(L1) ISSUE_MSG(*YES)

     SELECT    FIELDS(#ORDERDET) FROM_FILE(ORDLIN) WITH_KEY(#ORDNUM)

     UPRINT    FIELDS(#ORDERDET)

     ENDSELECT

     ENDPRINT

     GOTO      L1

Note that both programs are almost identical. They both request that an order number be input, retrieve the order header details and then print all associated order line details.

The difference is in the ENDPRINT command.

The first program waits until the user uses the EXIT or MENU function key on the REQUEST command before an ENDPRINT command is automatically executed as the function ends. Thus all the orders requested have been printed into one print / spool file.

In the second program an ENDPRINT is executed after each order has been printed. This causes the print / spool file to be closed. A new one will be automatically opened when the next UPRINT command (if any) is executed. Thus each order is placed into a separate print / spool file.