Hello,
I have a sequential file with records being fed to it via external card reader. Works very well. I want to do some statistics with the data, so I want to use the (very old) COBOL compiler delivered with TK4-. I struggle with the format for getting the number parsed in the correct way in pos. 18 - 25.
Format:
* 1 10 20 30 40 50
* +---+----+----+----+----+----+----+----+----+----+
* Jan 6 17:03:30 0003.10 4.8 166039
* Jan 6 17:08:05 -0002.20 3.5 9007
(I have changed the preparation script on Linux to always do a zero-fill, if this might have been the culprit. Not, it isn¡¯t. Issue stays the same.)
This is my current format description:
01 STATISTICS-INPILE-FORMAT.
02 MONTHNAME PIC A(3).
02 FILLER PIC X.
02 DAY-OF-MONTH PIC 9(2).
02 FILLER PIC X.
02 TIMESPEC.
03 T-HOUR PIC 9(2).
03 FILLER PIC X.
03 T-MINUTE PIC 9(2).
03 FILLER PIC X.
03 T-SECOND PIC 9(2).
03 FILLER PIC XX.
02 SCORE-TXT PIC X(8).
02 FILLER PIC X.
02 SCANTIME PIC 9(6)V9.
02 FILLER PIC X.
02 BYTES PIC 9(12).
02 FILLER PIC X(34).
When running the program, all fields filled correctly. For statistics, I want to do some calculations. To accomplish this, I defined:
WORKING-STORAGE SECTION.
77 SCORE PIC S9(6)V99.
Later, in the PROCEDURE DIVISION, I do a MOVE:
MOVE SCORE-TXT TO SCORE.
By reading IBM GC28-6396-6 (ANSI COBOL from 1976), I maybe should rewrite:
77 SCORE PIC S9(6)V99
SIGN IS LEADING.
A Compilation yields:
IKF1037I-E SIGN INVALID IN DATA DESCRIPTION. SKIPPING TO NEXT CLAUSE.
IKF1037I-E IS INVALID IN DATA DESCRIPTION. SKIPPING TO NEXT CLAUSE.
IKF1037I-E LEADING INVALID IN DATA DESCRIPTION. SKIPPING TO NEXT CLAUSE.
The only halfway applying external help also uses the SIGN clause.
If I leave out the complete SIGN clause, compilation is (again) successful. A ?DISPLAY¡° (to check if the fields are parsed correctly) in the read-loop yields the following:
20-Entry from Jan, 6, 15h 51m 25s:
has 94652 B, and took 3.6 s to scan.
Score is 005.800{
20-Entry from Jan, 6, 17h 06m 38s:
has 19885 B, and took 7.2 s to scan.
Score is 001.800{
20-Entry from Jan, 6, 17h 08m 05s:
has 9007 B, and took 3.5 s to scan.
Score is 002.200{
- Why are there three digits after the decimal point?
- What is that { after the rightmost digit? This mysterious ?sign overpunch¡° I¡¯ve been reading about?
- Note that this character stays the same, no matter if the input number is positive or negative.
As soon as I want to use this variable for any calculation, the program abends with a runtime error.
If I define the score variable slightly different, I surprisingly get the right numbers!
77 SCORE PIC 9(8).
20-Entry from Jan, 6, 15h 51m 25s:
has 94652 B, and took 3.6 s to scan.
Score is 0005.80
20-Entry from Jan, 6, 17h 06m 38s:
has 19885 B, and took 7.2 s to scan.
Score is -0001.80
20-Entry from Jan, 6, 17h 08m 05s:
has 9007 B, and took 3.5 s to scan.
Score is -0002.20
I still can¡¯t calculate with that variable.
Somewhere I¡¯ve read that sometimes the sign is at the *end* of a number in the US. So I changed my export to create records like this:
1 10 20 30 40 50
+---+----+----+----+----+----+----+----+----+----+
Jan 6 19:57:49 12.40- 3.3 51490
Jan 6 20:03:36 72.60+ 3.2 890
Field definition:
02 SCORE PIC S9(7)V99.
Output:
20-Entry from Jan, 6, 20h 34m 34s:
has 0 10340 B, and took 7 s to scan.
Score is 17.70
20-Entry from Jan, 6, 20h 38m 55s:
has 9 8 B, and took 9 s to scan.
Score is 52.00
No Sign, but garbled numbers (scan time, bytes). Is a sign only showing up when the output number is edited?
For a test, I¡¯m switching back to all definitions to be type X.
01 STATISTICS-INPILE-FORMAT.
02 MONTHNAME PIC A(3).
02 FILLER PIC X.
02 DAY-OF-MONTH PIC 9(2).
02 FILLER PIC X.
02 TIMESPEC.
03 T-HOUR PIC 9(2).
03 FILLER PIC X.
03 T-MINUTE PIC 9(2).
03 FILLER PIC X.
03 T-SECOND PIC 9(2).
03 FILLER PIC X.
02 SCORE-TXT PIC X(10).
02 FILLER PIC X.
02 SCANTIME PIC X(8).
02 FILLER PIC X.
02 BYTES PIC X(12).
02 FILLER PIC X(32).
and
WORKING-STORAGE SECTION.
77 SCORE PIC S9(6)V99 VALUE ZERO
USAGE IS DISPLAY.
Compiles well, move works, output is:
20-Entry from Jan, 6, 20h 27m 43s:
has 29245 B, and took 5.7 s to scan.
Score is 0.8000{
20-Entry from Jan, 6, 20h 34m 34s:
has 1034035 B, and took 7.0 s to scan.
Score is 17.7000{
20-Entry from Jan, 6, 20h 38m 55s:
has 838 B, and took 9.9 s to scan.
Score is 52.0000{
For whatever reason I now have four digits after the decimal point, and again the curly brace. Of course, I still can¡¯t do calculations with this number: Runtime Error.
In business (obviously the B in COBOL), negative values are common. But since the TK4- MVT compiler seems to even predate the document mentioned above, I¡¯m puzzled how to handle negative numbers.
May I ask kindly for a nudge in the right direction?
I have a complete JCL ready for uploading via external card reader into the HERC03 account, deleting possible leftovers from a previous run, and (re)creating all files as necessary, so potential helpers will have it more easy to actually help. Available on request.
Thank you.
:wq! PoC