Skip to content

Instantly share code, notes, and snippets.

@palanisamym14
Created September 22, 2021 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save palanisamym14/3e9526f4536efd99baa8a92631eab08b to your computer and use it in GitHub Desktop.
Save palanisamym14/3e9526f4536efd99baa8a92631eab08b to your computer and use it in GitHub Desktop.
IDENTIFICATION DIVISION.
PROGRAM-ID. LetterSearch.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 LetterTable.
02 LetterValues.
03 FILLER PIC X(13)
VALUE "ABCDCEFGHIJLM".
03 FILLER PIC X(13)
VALUE "NOPQRSTUVWXYZ".
02 FILLER REDEFINES LetterValues.
03 Letter PIC X OCCURS 26 TIMES
INDEXED BY LetterIdx.
01 LetterIn PIC X.
01 LetterPos PIC 99.
01 PrnPos PIC Z9.
PROCEDURE DIVISION.
Begin.
DISPLAY "Enter the letter please - "
WITH NO ADVANCING
ACCEPT LetterIn
SET LetterIdx LetterPos TO 1
SEARCH Letter VARYING LetterPos
AT END DISPLAY "Letter " LetterIn " not found!"
WHEN Letter(LetterIdx) = LetterIn
MOVE LetterPos TO PrnPos
DISPLAY LetterIn, " is in position ", PrnPos
END-SEARCH
STOP RUN.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment