To answer your question: COBOL accept numeric data however you define it.
So for “text data” (as long as it isn’t UTF-16 or another multibyte encoded file)
PIC 99 (which says “two digits in the default
USAGE DISPLAY – so one byte per digit) is perfectly fine.
As with every other language: “never trust input data” is something I can recommend. For example: someone could run this program with a file that was saved with an
UTF-8 encoded character in the name and then it “looks” right but the code has an unexpected shift in its data. For COBOL things like
FUNCTION TEST-NUMVAL(inp) [ignores spaces and allows decimal-point] or
IS NUMERIC (strict class test) can be useful.
Using data-check you could for example also skip empty lines or leading/trailing extra data (temporary rulers, headline, summary, …).
For the actual problem:
It looks like you feed the program with a “common” text file, but you actually did not specify this so your COBOL implementation uses the default
SEQUENTIAL. Because of the missing check of the input data you did not spot this directly.
To align expectations and code:
SELECT STUDENT-IN ASSIGN TO "C:\STUD-IN.DAT" ORGANIZATION IS LINE SEQUENTIAL. SELECT STUDENT-OUT ASSIGN TO "C:\STUD-OUT.DAT" ORGANIZATION IS LINE SEQUENTIAL.
CLICK HERE to find out more related problems solutions.