****************************************
      * Program name: position.cbl
      * This program demonstrate the use
      * of the POSITION command.
      *
      * Copyright 2000 Deskware, Inc.
      ****************************************                                                             
      * Syntax: POSITION  AT RECORD 
      *
      * Syntax: POSITION  RELATIVE OFFSET 
      *
       1  filename_var   PIC X(n) VALUE `datafile.txt`.
       1  bytes_num      PIC 99 VALUE 50.
       FD filename_var RECORD IS bytes_num BYTES.

       1  record_variable.
        5 order_nbr     PIC 99999.
        5 data_var      PIC X(45).

       1  key_val       PIC 99999 VALUE 24331.

       OPEN filename_var FOR READING.

       POSITION filename_var AT RECORD key_val.
       READ filename_var INTO record_variable.
       IF order_nbr = key_val
          DISPLAY `For order number ` & order_nbr & `, data = ` & data_var
       ELSE
          DISPLAY `Problem with order_nbr values in data file; check file.`
       END-IF.

       POSITION filename_var RELATIVE OFFSET -2.
       READ filename_var INTO record_variable.
       IF order_nbr = (key_val-1)
          DISPLAY `For order number ` & order_nbr & `, data = ` & data_var
       ELSE
          DISPLAY `Problem with order_nbr values in data file; check file.`
       END-IF.
       CLOSE filename_var.
       STOP RUN.