I am new to the forum, obviously (and in dire hehe) need of help regarding my COBOL program.
Been racking my brain over this and can't seem to figure out the issue.
My Program is below (left out opening and closing of files and few other unnecessary bits).
IDENTIFICATION DIVISION.
PROGRAM-ID. TBLE0503.
*Aim - Practicing using INDEX with tables
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT REC-PRICE-PART-FILE ASSIGN TO "REC-PRICE-PART.DAT"
FILE STATUS IS REC-PRICE-PART-FILE-STATUS
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD REC-PRICE-PART-FILE.
01 REC-PRICE-PART.
05 REC-ITEM-NUMBER PIC 9(3).
05 REC-PRICE PIC S99V99.
WORKING-STORAGE SECTION.
01 FILE-STATUS.
05 REC-PRICE-PART-FILE-STATUS PIC X(2).
01 PRICE-TABLE VALUE ZERO.
05 PRICE-GROUP OCCURS 16 TIMES
INDEXED BY PRICE-GRP-INDEX.
10 ITEM-NUMBER PIC 9(3).
10 ITEM-PRICE PIC 9(2)V9(3).
01 SWITCHES.
05 PRICE-TABLE-EOF-SWITCH PIC X VALUE 'N'.
88 PRICE-TABLE-EOF VALUE 'Y'.
01 WS-INPUT.
05 INP-ITEM-NUMBER PIC 9(3).
05 INP-ITEM-PRICE PIC 9(2)V9(3).
PROCEDURE DIVISION.
2000-MAIN-PROGRAM.
PERFORM 9100-OPEN-FILE
PERFORM 3500-LOAD-TABLE
PERFORM 9110-CLOSE-FILE
PERFORM 5000-MODIFY-TABLE
PERFORM 9000-STOP-PROGRAM
.
3500-LOAD-TABLE.
PERFORM 9200-READ-RECORD
PERFORM 3510-LOAD-LVL-1-TABLE
WITH TEST AFTER
VARYING PRICE-GRP-INDEX FROM 1 BY 1
UNTIL PRICE-GRP-INDEX = 16
OR PRICE-TABLE-EOF
.
3510-LOAD-LVL-1-TABLE.
IF NOT PRICE-TABLE-EOF
MOVE REC-ITEM-NUMBER TO ITEM-NUMBER (PRICE-GRP-INDEX)
MOVE REC-PRICE TO ITEM-PRICE (PRICE-GRP-INDEX)
END-IF
PERFORM 9200-READ-RECORD
.
5000-MODIFY-TABLE.
PERFORM
WITH TEST AFTER
UNTIL INP-ITEM-NUMBER = 999
DISPLAY 'Enter Item #' WITH NO ADVANCING
ACCEPT INP-ITEM-NUMBER
SET PRICE-GRP-INDEX TO 1
SEARCH PRICE-GROUP VARYING PRICE-GRP-INDEX
AT END
DISPLAY 'Nothing Found'
WHEN ITEM-NUMBER (PRICE-GRP-INDEX) = INP-ITEM-NUMBER
DISPLAY 'Current Price ' ITEM-PRICE (PRICE-GRP-INDEX)
DISPLAY 'Enter New Price'
ACCEPT INP-ITEM-PRICE
SET ITEM-PRICE (PRICE-GRP-INDEX) TO INP-ITEM-PRICE
DISPLAY 'New Price ' ITEM-PRICE (PRICE-GRP-INDEX)
END-SEARCH
END-PERFORM
.
The program is reading data in from a simple file that contains:
1011250
1075000
1110770
1580555
1616250
After that I am searching through the table and updating the item price if the user input matches an item number in the table.
Below is the program running:
Enter Item #101
Current Price 12.500
Enter New Price
.29
New Price 00.290 Expected
Enter Item #101
Current Price 00.290
Enter New Price
.293
New Price 00.293 Expected
Enter Item #101
Current Price 00.293
Enter New Price
22.23
New Price 22.230 Expected
Enter Item #101
Current Price 22.230
Enter New Price
23.236
New Price 23.230 UNEXPECTED - Why is the 6 truncated
Enter Item #101
Current Price 23.230
Enter New Price
3.236
New Price 03.236 EXPECTED - So it is correct only if I have 1 digit to the left of the decimal?
Enter Item #101
Current Price 03.236
Enter New Price
23.556
New Price 23.550 UNEXPECTED - Why is the 6 truncated
Enter Item #999
Nothing Found
So I can sort of see what is happening, I just don't understand why. I have defined my 'INP-ITEM-PRICE' data name to have enough storage for up to 99.999 I believe....
My Accept statement seems to be ignoring the last decimal value (if input a value > 9)?
Anyone got any idea where my understanding is incorrect? Or where my code is incorrect? But I believe it's not my code, but rather my understanding that is the issue here.
BTW, I am building/compiling on windows 10, but using Cygwin emulator thingy, and I am pretty sure I am using the COBOL-85 standard with the 1989 intrinsic functions added.
Thanks Guys, first post so I hope I've correctly posted.