Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Logic Error?? Simple Program 2

Status
Not open for further replies.

NateUNI

MIS
Jan 3, 2002
132
US
Some how this program is not reading the 3rd record right, it is not assigning the right discount. The input file is this:
51347935 00511111
42309847 10021222
38901974 12532333
21564823 50043444
10024567 90054555
and the cobol code is here: btw i had a problem/question not to long ago, and i posted the question here, and got a response right away. Thanks alot for your time and kindness to this beginner!!

IDENTIFICATION DIVISION.
PROGRAM-ID. Project-2stubs.
AUTHOR. Nathan-Schile.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT ORDER-TRANSACTION-FILE ASSIGN TO
'C:\cobol\PRJ02-01.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT PRINT-FILE ASSIGN TO 'C:\cobol\output.txt'.
DATA DIVISION.
FILE SECTION.
FD ORDER-TRANSACTION-FILE
RECORD CONTAINS 17 CHARACTERS
DATA RECORD IS ORDER-TRANSACTION-RECORD.
01 ORDER-IN.
05 CUST-NO PIC X(8).
05 FILLER PIC X(1).
05 ORD-QTY PIC XXX.
05 ITEM-NUMBER.
10 ITEM-SERIES PIC X.
10 REST-NUMBERS PIC X(4).

FD PRINT-FILE
RECORD CONTAINS 132 CHARACTERS
DATA RECORD IS PRINT-LINE.
01 PRINT-LINE.
05 FILLER PIC X.
05 PRINT-NO PIC X(8).
05 FILLER PIC X(2).
05 PRINT-ITEM-NO PIC X(5).
05 FILLER PIC X(3).
05 PRINT-QTY PIC 9(3).
05 FILLER PIC X(7).
05 PRINT-DISCOUNT PIC 99.
05 FILLER PIC X(101).

WORKING-STORAGE SECTION.
01 END-OF-DATA-FLAG PIC X(3) VALUE SPACES.
01 HEADING-LINE.
05 FILLER PIC X.
05 CUSTOMER-NO PIC X(8) VALUE 'Customer'.
05 FILLER PIC XX.
05 ITEM PIC X(4) VALUE 'Item'.
05 FILLER PIC X(4).
05 QTY PIC X(3) VALUE 'Qty'.
05 FILLER PIC X(3).
05 DISCOUNT PIC X(8) VALUE 'Discount'.
01 DETAIL-LINE.
05 FILLER PIC XX.
05 NUM PIC X(6) VALUE 'Number'.
05 FILLER PIC XX.
05 NUM2 PIC X(6) VALUE 'Number'.
05 FILLER PIC X.
05 ORDERED PIC X(7) VALUE 'Ordered'.
05 FILLER PIC XX.
05 PERCENT PIC X(7) VALUE 'Percent'.

PROCEDURE DIVISION.
100-PREPARE-PROGRAMMER-REPORT.
OPEN INPUT ORDER-TRANSACTION-FILE
OUTPUT PRINT-FILE.
PERFORM 300-WRITE-HEADER
PERFORM 200-PROCESS-CUST-RECORDS
UNTIL END-OF-DATA-FLAG = 'YES'.
CLOSE ORDER-TRANSACTION-FILE
PRINT-FILE.
STOP RUN.

200-PROCESS-CUST-RECORDS.
READ ORDER-TRANSACTION-FILE
AT END
MOVE 'YES' TO END-OF-DATA-FLAG
NOT AT END
PERFORM 210-PROCESS-EACH-RECORD
END-READ.


210-PROCESS-EACH-RECORD.
IF ITEM-SERIES = '1' OR ITEM-SERIES = '2'
EVALUATE TRUE
WHEN ORD-QTY <= 100
MOVE '00' TO PRINT-DISCOUNT
MOVE CUST-NO TO PRINT-NO
MOVE ORD-QTY TO PRINT-QTY
MOVE ITEM-NUMBER TO PRINT-ITEM-NO
WRITE PRINT-LINE
WHEN ORD-QTY > 100 AND ORD-QTY <= 500
MOVE '10' TO PRINT-DISCOUNT
MOVE CUST-NO TO PRINT-NO
MOVE ORD-QTY TO PRINT-QTY
MOVE ITEM-NUMBER TO PRINT-ITEM-NO
WRITE PRINT-LINE
WHEN ORD-QTY > 500 AND ORD-QTY <= 999
MOVE '20' TO PRINT-DISCOUNT
MOVE CUST-NO TO PRINT-NO
MOVE ORD-QTY TO PRINT-QTY
MOVE ITEM-NUMBER TO PRINT-ITEM-NO
WRITE PRINT-LINE
END-EVALUATE
ELSE
IF ITEM-SERIES = '3' OR ITEM-SERIES = '4' OR ITEM-SERIES = '5'
EVALUATE TRUE
WHEN ORD-QTY <= 50
MOVE '00' TO PRINT-DISCOUNT
MOVE CUST-NO TO PRINT-NO
MOVE ORD-QTY TO PRINT-QTY
MOVE ITEM-NUMBER TO PRINT-ITEM-NO
WRITE PRINT-LINE
WHEN ORD-QTY > 50 AND ORD-QTY <= 100
MOVE '15' TO PRINT-DISCOUNT
MOVE CUST-NO TO PRINT-NO
MOVE ORD-QTY TO PRINT-QTY
MOVE ITEM-NUMBER TO PRINT-ITEM-NO
WRITE PRINT-LINE
WHEN ORD-QTY > 100 AND ORD-QTY <= 500
MOVE '20' TO PRINT-DISCOUNT
MOVE CUST-NO TO PRINT-NO
MOVE ORD-QTY TO PRINT-QTY
MOVE ITEM-NUMBER TO PRINT-ITEM-NO
WRITE PRINT-LINE
WHEN ORD-QTY > 500 AND ORD-QTY <=999
MOVE '25' TO PRINT-DISCOUNT
MOVE CUST-NO TO PRINT-NO
MOVE ORD-QTY TO PRINT-QTY
MOVE ITEM-NUMBER TO PRINT-ITEM-NO
WRITE PRINT-LINE
END-EVALUATE
END-IF.
300-WRITE-HEADER.
MOVE HEADING-LINE TO PRINT-LINE.
WRITE PRINT-LINE.
MOVE DETAIL-LINE TO PRINT-LINE.
WRITE PRINT-LINE.
MOVE SPACES TO PRINT-LINE.
 
What discount ARE you getting?
 
i am getting a discount of '00', Thanks
 
You wrote:

Some how this program is not reading the 3rd record right, it is not assigning the right discount. The input file is this:
51347935 00511111
42309847 10021222
38901974 12532333
21564823 50043444
10024567 90054555

And then you defined the file as:

FD ORDER-TRANSACTION-FILE
RECORD CONTAINS 17 CHARACTERS
DATA RECORD IS ORDER-TRANSACTION-RECORD.
01 ORDER-IN.
05 CUST-NO PIC X(8).
05 FILLER PIC X(1).
05 ORD-QTY PIC XXX.
05 ITEM-NUMBER.
10 ITEM-SERIES PIC X.
10 REST-NUMBERS PIC X(4).


My first question is: if each record contains 16 numbers; the first 8 bytes is the customer number, then a 1 byte filler, then 3 bytes for ORD-QTY, and 5 bytes for the item number. Each time, the 17th byte will either be low-values or spaces. Or else garbage if not properly initialized. Why are you defining a 17-byte field when the incoming records each contain 16 bytes?

Let me start here, and then we'll go forward.

Hope this helps, Nina Too
 
I declared it as a 17 byte field because that is how i was told to in class. I do not know how to declare it as a 16 byte field. How would I? is that the cause of my problem?
 
17 bytes is correct. the filler separates 2 blocks of 8 numbers, for a total of 17 positions.
------------------------------------

Oh, My! Does this bring back memories! I spent 2 days on the exact same problem in 1980!

You coded:
WHEN ORD-QTY <= 50
but ORD-QTY has PIC XXX!!!!!
You are testing for <= 50b, where b is a space! The trailing filler in an alphanumeric comparison is a space! And of course, 125 is less than 50b! So your discount is '00'!
All the other tests had 3 didgits, so the problem did not occur...
Change ORD-QTY to PIC 999.

Stephen J Spiro
Member, J4 COBOL Standards Committee
check it out at

stephenjspiro@mail.com
 
Stephen,

good one; missed that, too.

By the way, Nate, weren't you the one with the missing END-IF's? You solved that nicely! Just get out the last few bugs, and you ought to have a fine program.

Regards,
Ronald.
 
From Stepen Spiro:

17 bytes is correct. the filler separates 2 blocks of 8 numbers, for a total of 17 positions.

Oooops! Thanks.

And you got the correct way to solve this, too.

Nina Too
 
StephenJSpiro thanks so much for the help! I really appricate the time you guys take to help me. My teacher couldn't even find the problem. This is by far the best forum i have posted in. THANKS
 
.
FD ORDER-TRANSACTION-FILE
RECORD CONTAINS 17 CHARACTERS
DATA RECORD IS ORDER-TRANSACTION-RECORD.
01 ORDER-IN.

I believe your data record is clause is incorrect.
Try changing it to: DATA RECORD IS ORDER-IN.

Steve Millman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top