      PROGRAM INVEN
************************************************************************
* Program to read a part number during execution, access a record in   *
* a direct-access parts inventory file, and display this record.       *
* Identifiers used are:                                                *
*     RECLEN : a parameter specifying record length (parameter)        *
*     PARTNO : part number                                             *
*     FNAME  : name of the file                                        *
*     INFO   : a record in the file                                    *
*     BADNUM : 0 if valid part number, otherwise nonzero               *
*                                                                      *
* Input (keyboard): FNAME, PARTNO                                      *
* Input (file):     INFO                                               *
*                                                                      *
* Output (screen):  User prompts, INFO, or error message and PARTNO    *       
*                   for an invalid part number                         *
*                                                                      *
* Note:  The compiler used for this program requires that the          *
* end-of-line character in a file record be counted in determining     *
* the record length; therefore, RECLEN is set at 31.                   *
************************************************************************

      INTEGER PARTNO, RECLEN, BADNUM
      PARAMETER (RECLEN = 31)
      CHARACTER*20 FNAME, INFO*(RECLEN)

* Get the name of the file and open it for direct access

      PRINT *, 'ENTER NAME OF FILE'
      READ '(A)', FNAME
      OPEN (UNIT = 10, FILE = FNAME, STATUS = 'OLD',
     +      ACCESS = 'DIRECT', FORM = 'FORMATTED', RECL = RECLEN)

      PRINT *, 'ENTER PART NUMBER (0 TO STOP)'
      READ *, PARTNO

* While there are more part numbers to process do the following

 10   IF (PARTNO .NE. 0) THEN
          READ (10, '(A)', REC = PARTNO, IOSTAT = BADNUM) INFO
          IF (BADNUM .EQ. 0) THEN
              PRINT '(1X, ''PART'', I3, '': '', A)', PARTNO, INFO
          ELSE
              PRINT '(1X, ''INVALID PART NUMBER: '', I3)', PARTNO
          END IF
          PRINT *
          PRINT *, 'PART NUMBER?'
          READ *, PARTNO
      GO TO 10
      END IF

      CLOSE(10)
      END
