This is the RPG for the subfile program.
* Define the subfile and the variable that will hold record # (REC#)
FCUSD001 CF E WORKSTN
F SFILE(SFDATA:REC#)
FCUS IF E K DISK
*
C *IN03 DOWEQ *OFF
* Show screen for user to enter the salesperson's number
C EXFMT ENTSLS
C *IN03 IFEQ *OFF
* Clear the subfile
C EXSR CLRSF
* Load the subfile
C EXSR LODSF
* Show the command key footer and then the subfile SFCTL
C WRITE CMDKEYS
C EXFMT SFCTL
C ENDIF
C ENDDO
C MOVE *ON *INLR
C RETURN
*---------------------------------------------------------------------
C CLRSF BEGSR
* Clear the subfile by writing a SFCTL record with Indicator 50 Off
C MOVE *OFF *IN50
C WRITE SFCTL
C MOVE *ON *IN50
* Set the record number variable to zero
C MOVE *ZERO REC# 4 0
C ENDSR
*---------------------------------------------------------------------
C LODSF BEGSR
* Start reading the customer file for this salesperson
C SLSPER SETLL CUS 10
C *IN10 IFEQ *ON
C SLSPER READE CUS 95
C *IN95 DOWEQ *OFF
* For every customer found, add 1 to the record # of the subfile
* and write that record to the subfile data
C ADD 1 REC#
C WRITE SFDATA
C SLSPER READE CUS 95
C ENDDO
C ENDIF
* If subfile is empty, write a record that says "*NO RECORDS"
C REC# IFEQ *ZERO
C ADD 1 REC#
C CLEAR SFDATA
C MOVEL '*NO RECORDS*'CUSNAM
C WRITE SFDATA
C ENDIF
C ENDSR