Output is wrong - cobol

Written my program but I cannot get the right output as needed
Below is my code and my input with the output.
Also does my procedure program make sense or should I revise it, it seems it makes sense but after looking at different books I'm not sure anymore.
FD INPUT-FILE.
01 INPUT-RECORD.
05 EXCUSE-NUMBER PIC 9(02).
88 VALID-EXCUSE VALUE 1 THRU 10.
05 FILLER PIC X(03).
05 NUMBER-TIMES-USED PIC 9(02).
05 FILLER PIC X(73).
FD REPORT-FILE.
01 REPORT-RECORD PIC X(80).
FD ERROR-FILE.
01 ERROR-RECORD PIC X(80).
WORKING-STORAGE SECTION.
******************************************************************
* DEFINES PROCESSINGVARIABLES AND OUTPUT LINES *
******************************************************************
01 WS-AREA.
05 WS-IF-STATUS PIC X(02).
05 WS-OF-STATUS PIC X(02).
05 WS-EF-STATUS PIC X(02).
05 WS-END-OF-FILE PIC X(01) VALUE "N".
88 AT-WS-END-OF-FILE VALUE "Y".
05 WS-INVALID-RECORD PIC X(01) VALUE "N".
05 WS-LINE-NUMBER PIC 9(03) VALUE 0.
05 WS-MOST-USED-EXCUSE PIC 9(02) VALUE 0.
05 WS-EXCUSE PIC 9(02) VALUE 0.
05 WS-EXCUSE-TOTAL PIC 9(04).
01 BLANK-LINE.
05 PIC X(80).
******************************************************************
* (THIS IS WHERE THE HEADING ON THE PRINT OUT SHEET GOES) *
******************************************************************
01 HEADING-LINE-1.
05 FILLER PIC X(14) VALUE SPACES.
05 FILLER PIC X(37)
VALUE "TEN MOST OUTRAGEOUS HOME-WORK EXCUSES".
01 HEADING-LINE-2.
05 FILLER PIC X(11).
05 FILLER PIC X(06) VALUE "RECORD".
05 FILLER PIC X(08).
05 FILLER PIC X(05) VALUE "IMAGE".
******************************************************************
* DETAIL-LINE COMMENTS. *
* on the detail line we are writing out the Data information *
* in particular, when we write out the line-number, error *
* excuse number, excuses used, and how many times used *
* Detail summary will be reported out *
* Stars will be Display underneath bad data. *
*****************************************************************
01 DETAIL-LINE.
05 FILLER PIC X(03).
05 DL-EXCUSE-NUMBER PIC 9(02).
05 FILLER PIC X(03).
05 DL-EXCUSE-USED PIC X(51).
05 FILLER PIC X(03).
05 DL-AMOUNT-USED PIC ZZ9.
01 DETAIL-LINE-ERROR-1.
05 FILLER PIC X(08) VALUE SPACES.
05 DLE-LINE-NUMBER PIC ZZ9.
05 FILLER PIC X(09) VALUE SPACES.
05 DLE-ERROR PIC X(16).
01 DETAIL-LINE-ERROR-2.
05 FILLER PIC X(20) VALUE SPACES.
05 DLE-EXCUSE-NUMBER PIC X(02) VALUE SPACES.
05 FILLER PIC X(03) VALUE SPACES.
05 DLE-EXCUSE PIC X(02) VALUE SPACES.
01 DETAIL-TOTAL.
05 FILLER PIC X(41) VALUE SPACES.
05 FILLER PIC X(20)
VALUE "TOTAL EXCUSES USED =".
05 DT-TOTAL PIC ZZZ9 VALUE ZERO.
01 DETAIL-TOTAL-MOST-USED.
05 FILLER PIC X(34) VALUE SPACES.
05 FILLER PIC X(27)
VALUE "EXCUSE USE THE MOST TIMES =".
05 DTMU-HIGH PIC ZZZ9.
******************************************************************
* This is where we hard code the excuses used with the table *
* from the input file. *
******************************************************************
01 TABLE-EXCUSES-1.
05 PIC X(51)
VALUE "JOHN CONVINCE ME TO CONVERT TO LINUX".
05 PIC X(51)
VALUE "BEACUSE OF SECURITY REASON I CAN'T CONFIRM NOR DENY".
05 PIC X(51)
VALUE "BECAUSE THE HOSPITAL DOESN'T HAVE WIFI'".
05 PIC X(51)
VALUE "AFTER INSTALLING LINUX MY SYSTEM CRASHED".
05 PIC X(51)
VALUE "WHAT WAS THE QUESTION AGAIN".
05 PIC X(51)
VALUE "ARE YOU SURE, I REMEBER TURNING IT IN".
05 PIC X(51)
VALUE "I'M INVOKING MY 5TH AMENDMENT RIGHT".
05 PIC X(51)
VALUE "LINUX MADE ME CRAZY I THREW MY COMPUTER".
05 PIC X(51)
VALUE "SOMEONE STOLED MY BACKPACK".
05 PIC X(51)
VALUE "BEACUSE OF SECURITY REASON I CAN'T CONFIRM NOR DENY".
01 TABLE-EXCUSES-2 REDEFINES TABLE-EXCUSES-1.
05 TEN-EXCUSES OCCURS 10 TIMES PIC X(51).
01 TABLE-EXCUSES-COUNTER.
05 TABLE-EXCUSES-COUNT OCCURS 10 TIMES PIC 9(03).
PROCEDURE DIVISION.
******************************************************************
* Finally - where the real work gets done *
* it is divided into paragraphs (or modules) generally called *
* from the main controlling module (here 1000-MAIN-CONTROL). *
* 1000-Main be the control module, *
* 2000-Initialize *
* 3000-Process *
* 4000-Finish *
******************************************************************
1000-MAIN.
OPEN INPUT INPUT-FILE
OUTPUT REPORT-FILE, ERROR-FILE
PERFORM 2000-INITIALIZE
PERFORM UNTIL AT-WS-END-OF-FILE
READ INPUT-FILE
AT END MOVE "Y" TO WS-END-OF-FILE
NOT AT END PERFORM 3000-PROCESS
END-READ
END-PERFORM
PERFORM 4000-FINISH
VARYING WS-EXCUSE
FROM 1 BY 1
UNTIL WS-EXCUSE > 10
MOVE WS-MOST-USED-EXCUSE TO DTMU-HIGH
MOVE WS-EXCUSE-TOTAL TO DT-TOTAL
WRITE REPORT-RECORD FROM BLANK-LINE
WRITE REPORT-RECORD FROM DETAIL-TOTAL
WRITE REPORT-RECORD FROM BLANK-LINE
WRITE REPORT-RECORD FROM DETAIL-TOTAL-MOST-USED.
CLOSE INPUT-FILE REPORT-FILE ERROR-FILE
STOP RUN.
2000-INITIALIZE.
INITIALIZE WS-EXCUSE
INITIALIZE TABLE-EXCUSES-COUNTER
WRITE ERROR-RECORD FROM HEADING-LINE-2
WRITE ERROR-RECORD FROM BLANK-LINE
WRITE REPORT-RECORD FROM HEADING-LINE-1
WRITE REPORT-RECORD FROM BLANK-LINE.
3000-PROCESS.
MOVE "N" TO WS-INVALID-RECORD
ADD 1 TO WS-LINE-NUMBER
IF NOT VALID-EXCUSE
MOVE INPUT-RECORD TO DLE-ERROR
MOVE WS-LINE-NUMBER TO DLE-LINE-NUMBER
MOVE "Y" TO WS-INVALID-RECORD
MOVE ALL "*" TO DLE-EXCUSE-NUMBER
END-IF.
IF WS-INVALID-RECORD = "N"
INSPECT EXCUSE-NUMBER REPLACING LEADING SPACES BY ZERO
IF EXCUSE-NUMBER IS NUMERIC
ADD EXCUSE-NUMBER TO TABLE-EXCUSES-COUNT(EXCUSE-NUMBER)
IF TABLE-EXCUSES-COUNT(EXCUSE-NUMBER) >
WS-MOST-USED-EXCUSE
MOVE TABLE-EXCUSES-COUNT(EXCUSE-NUMBER)
TO WS-MOST-USED-EXCUSE
END-IF
ADD NUMBER-TIMES-USED TO WS-EXCUSE-TOTAL
ELSE
MOVE "Y" TO WS-INVALID-RECORD
MOVE WS-LINE-NUMBER TO DLE-LINE-NUMBER
MOVE INPUT-RECORD TO DLE-ERROR
MOVE ALL "*" TO DLE-EXCUSE
END-IF
END-IF.
IF WS-INVALID-RECORD = "Y"
WRITE ERROR-RECORD FROM DETAIL-LINE-ERROR-1
WRITE ERROR-RECORD FROM DETAIL-LINE-ERROR-2
MOVE SPACES TO DETAIL-LINE-ERROR-1
MOVE SPACES TO DETAIL-LINE-ERROR-2
END-IF.
4000-FINISH.
MOVE WS-EXCUSE TO DL-EXCUSE-NUMBER
MOVE TEN-EXCUSES(WS-EXCUSE) TO DL-EXCUSE-USED
MOVE TABLE-EXCUSES-COUNT(WS-EXCUSE) TO DL-AMOUNT-USED
WRITE REPORT-RECORD FROM DETAIL-LINE
WRITE REPORT-RECORD FROM BLANK-LINE
MOVE SPACES TO DETAIL-LINE.
My output is as follow then follow by what it should be.
RECORD IMAGE
3 0r4000700 03
**
12 125999999 12
**
21 125000899 21
**
23 A01001111 23
**
Should be:
RECORD IMAGE
3 0r4000700 03
**
6 074000Q00 06
**
12 125999999 12
**
21 125000899 21
**
23 A01001111 23
**

You have two problems which is causing record number three to not appear with the correct error and record number six not to appear as an error at all.
I've indented your code to allow you to better see what is going on.
As usual, the compiler doesn't care, doesn't take note of indentation, so it is for humans. So do it. Indent. Often you'll see some of your own errors just by doing that.
IF NOT VALID-EXCUSE
MOVE INPUT-RECORD TO DLE-ERROR
MOVE WS-LINE-NUMBER TO DLE-LINE-NUMBER
MOVE "Y" TO WS-INVALID-RECORD
MOVE ALL "*" TO DLE-EXCUSE-NUMBER
END-IF
IF WS-INVALID-RECORD = "N"
INSPECT EXCUSE-NUMBER REPLACING LEADING SPACES BY ZERO
IF EXCUSE-NUMBER IS NUMERIC
ADD EXCUSE-NUMBER TO TABLE-EXCUSES-COUNT(EXCUSE-NUMBER)
IF TABLE-EXCUSES-COUNT(EXCUSE-NUMBER) >
WS-MOST-USED-EXCUSE
MOVE TABLE-EXCUSES-COUNT(EXCUSE-NUMBER)
TO WS-MOST-USED-EXCUSE
END-IF
ADD NUMBER-TIMES-USED TO WS-EXCUSE-TOTAL
ELSE
MOVE "Y" TO WS-INVALID-RECORD
MOVE WS-LINE-NUMBER TO DLE-LINE-NUMBER
MOVE INPUT-RECORD TO DLE-ERROR
MOVE ALL "*" TO DLE-EXCUSE
END-IF
END-IF
If we take record three first.
Your range-test on the 88 (good to use 88s, do it more) is this, in hexadecimal:
X'3031' through X'3130'.
This will work if the field is already known to be NUMERIC, but otherwise, since numbers appear before letters in ASCII, a whole slew of stuff you don't want gets treated as "valid". The value of 12 are rejected because they are large than 10 (X'3130'). Any letter, preceded by a zero, will be treated as valid, as will any control-code or any remaining value that happens to fit in the huge range of non-numeric values.
As Bruce Martin indicated, you need to know that the field is NUMERIC before applying that test.
IF EXCUSE-NUMBER NUMERIC
AND NOT VALID-EXCUSE
MOVE INPUT-RECORD TO DLE-ERROR
MOVE WS-LINE-NUMBER TO DLE-LINE-NUMBER
MOVE "Y" TO WS-INVALID-RECORD
MOVE ALL "*" TO DLE-EXCUSE-NUMBER
END-IF
That's become a little difficult for humans to read (the compiler doesn't mind). Bruce's suggestion for simplification (positive checks and CONTINUE with ELSE to catch the bad data) is a good one:
IF ( EXCUSE-NUMBER NUMERIC )
AND ( VALID-EXCUSE )
[all the good data goes here]
CONTINUE
ELSE
[leaving all the bad data here, ie both not numeric and
numeric but not in range]
MOVE INPUT-RECORD TO DLE-ERROR
MOVE WS-LINE-NUMBER TO DLE-LINE-NUMBER
MOVE "Y" TO WS-INVALID-RECORD
MOVE ALL "*" TO DLE-EXCUSE-NUMBER
END-IF
Note: You need the NUMERIC-plus-range when you are validating data. Once good data is in your system, range-checks will work "as expected" as there will be no intervening non-numeric data to spoil the plot.
You also get to do both types errors for EXCUSE-NUMBER at once, simplifying the following IF.
If you can have a leading blank in either field, you need to deal with that before any checking. You don't need to use INSPECT.
With a two-byte field just REDEFINES so you can give the entire field as alpha-numeric a name, and first byte a name. Put 88s on those with a value of space. If the 88 is true, set that to zero (whole field, or byte, two tests):
IF 88-level
MOVE ZERO TO name-you've-given
END-IF
So far, record three has been treated as valid. Now it gets into your nested-IF. It EXCUSE-NUMBER is not NUMERIC, so hits the ELSE, where you have coding for the second field, . Because you didn't indent, this was obscured.
Record three has been rejected "by accident".
In the nested-IF, you meant to check NUMBER-TIMES-USED for NUMERIC.
Which explains why record six does not appear as an error, because it's only fault is NUMBER-TIMES-USED not being NUMERIC, which your program currently doesn't notice.
You've also erroneously added EXCUSE-NUMBER instead of NUMBER-TIMES-USED.
IF WS-INVALID-RECORD = "N"
[stuff for leading space]
IF NUMBER-TIMES-USED IS NUMERIC
ADD NUMBER-TIMES-USED TO TABLE-EXCUSES-COUNT(EXCUSE-NUMBER)
IF TABLE-EXCUSES-COUNT(EXCUSE-NUMBER) >
WS-MOST-USED-EXCUSE
MOVE TABLE-EXCUSES-COUNT(EXCUSE-NUMBER)
TO WS-MOST-USED-EXCUSE
END-IF
ADD NUMBER-TIMES-USED TO WS-EXCUSE-TOTAL
ELSE
MOVE "Y" TO WS-INVALID-RECORD
MOVE WS-LINE-NUMBER TO DLE-LINE-NUMBER
MOVE INPUT-RECORD TO DLE-ERROR
MOVE ALL "*" TO DLE-EXCUSE
END-IF
END-IF
Be aware that the size of TABLE-EXCUSES-COUNT is greater than the size of WS-MOST-USED-EXCUSE. If you keep it like that, you will get unexpected behaviour when you have more than 99 of the same type of excuse.
Your nested-IF is a bit tortuous, and you have some repetition. Here's some simplification:
IF ( EXCUSE-NUMBER NUMERIC )
AND ( VALID-EXCUSE )
PERFORM CHECK-NUMBER-TIMES-USED
ELSE
PERFORM SET-STANDARD-REJECTION
MOVE ALL "*" TO DLE-EXCUSE-NUMBER
END-IF
...
CHECK-NUMBER-TIMES-USED.
IF 88-level-first-byte-space
MOVE ZERO TO name-you've-given-the-first-byte
END-IF
IF 88-level-field-space
MOVE ZERO TO field
END-IF
IF NUMBER-TIMES-USED IS NUMERIC
ADD NUMBER-TIMES-USED TO TABLE-EXCUSES-COUNT ( EXCUSE-NUMBER )
WS-EXCUSE-TOTAL
PERFORM CHECK-HIGHEST-EXCUSE-COUNT
ELSE
PERFORM SET-STANDARD-REJECTION
MOVE ALL "*" TO DLE-EXCUSE
END-IF
SET-STANDARD-REJECTION.
MOVE INPUT-RECORD TO DLE-ERROR
MOVE WS-LINE-NUMBER TO DLE-LINE-NUMBER
MOVE "Y" TO WS-INVALID-RECORD
.
CHECK-HIGHEST-EXCUSE-COUNT.
IF TABLE-EXCUSES-COUNT ( EXCUSE-NUMBER )
GREATER THAN WS-COUNT-OF-MOST-USED
MOVE TABLE-EXCUSES-COUNT ( EXCUSE-NUMBER )
TO WS-COUNT-OF-MOST-USED
MOVE EXCUSE-NUMBER TO WS-EXCUSE
END-IF
.
There's at least one more simplification when you get to the totals, but see how that goes.

VALID-EXCUSE may well be implemented as
EXCUSE-NUMBER >= '01' and EXCUSE-NUMBER < '12'
So in procedure 3000-PROCESS, I would try replacing
IF NOT VALID-EXCUSE
MOVE INPUT-RECORD TO DLE-ERROR
MOVE WS-LINE-NUMBER TO DLE-LINE-NUMBER
MOVE "Y" TO WS-INVALID-RECORD
MOVE ALL "*" TO DLE-EXCUSE-NUMBER
END-IF.
with
INSPECT EXCUSE-NUMBER REPLACING LEADING SPACES BY ZERO
IF EXCUSE-NUMBER is numeric
and VALID-EXCUSE
continue
else
MOVE INPUT-RECORD TO DLE-ERROR
MOVE WS-LINE-NUMBER TO DLE-LINE-NUMBER
MOVE "Y" TO WS-INVALID-RECORD
MOVE ALL "*" TO DLE-EXCUSE-NUMBER
END-IF
if not NUMBER-TIMES-USED is numeric
MOVE "Y" TO WS-INVALID-RECORD
MOVE WS-LINE-NUMBER TO DLE-LINE-NUMBER
MOVE INPUT-RECORD TO DLE-ERROR
MOVE ALL "*" TO DLE-EXCUSE
end-if
also remove the following:
ELSE
MOVE "Y" TO WS-INVALID-RECORD
MOVE WS-LINE-NUMBER TO DLE-LINE-NUMBER
MOVE INPUT-RECORD TO DLE-ERROR
MOVE ALL "*" TO DLE-EXCUSE
This code is in completely the wrong place.
There are other errors e.g.
ADD EXCUSE-NUMBER TO TABLE-EXCUSES-COUNT(EXCUSE-NUMBER)
should probably be
ADD 1 TO TABLE-EXCUSES-COUNT(EXCUSE-NUMBER)

Related

How do I fix duplication of fields in RPT file?

This program is to read in the SEQ file and take the data thru different validations, if it fails to comply with one of the validations the error message is moved to FIELD-NAME and FIELD-VALUE is the errored field.
After all data is processed all transaction are to be used to create the RPT file.
PROBLEM: When reviewing the RPT file, a weird issue is that ERROR FIELD NAME/ERROR FIELD VALUE keeps repeating the same error after entry is passed. I believe the problem is located in the 300, 310, 320, 330, 340, 350 sections.
Part number validation requirements Col. 01-05 must be a number, col 06 must be a capital, 07-08 must be a number in the range 01-68 or 78-99
Quantity validation requirements Leading spaces are allowed(can be all spaces), if not all spaces must be a number after leading spaces, zero value is allowed, value over 20,000 is an error
Date validation requirements month value must be 01-12, day value must be 01-31
Charge Number validation requirements cannot be blank, must be left justified(no leading spaces), and no more than one dash (hyphen) allowed
Initial validation requirements both must be letters (upper or lower case OK)
Transaction Code validation requirements must be REC, ISS, AJ+, or AJ-
If you run my attached program with the attached SEQ, your RPT will look like mine.
Below is the desired output. (pg 1)
SEQ:
11438A01 5000102667-X44 JBISS
12345A77 120103OK BY MIKELLREC
12789B02 14460606144-X22A AJ+
13168A02 31231722394 mkISS
13168A02 70102221-Q18 JBAJ-
2074B01 25 0532 OK BY JIMK RE
22109A04 20000325669-Y5Z DCISS
3077.B22 1000801144X MWAJ-
32149A01 10625567-X1 dcREC
39886B02 2000203517-AA JBAJ+
40442A2( 33 333-Q67 MKISS
43009B01 1440801899-23 MKISS
47890A02 30000422X-4-8 DCISS
49000B01 1000831901-Y6 MWAJ+
51111A011052X0905901-Y66 JBREC
52301A02 10228733876-X1 ABREC
55986b01 99990430A DCISS
57989A01 21130144X JBAJ+
57989A01 500831722394-XX MKISS
59901B0220300133X966-QQ22 MWREC
60022A01 400823 517-X1-33MWAJ+
66780B01 1000831722-YY BwREC
68999A01 21028123-Q88 MKISS
75312B01 500222966-32 BISS
77771A03 12780606 ABISS
78896B02 1000831123456-X13DCREC
80090B01 881$25983334-X25jbAJ
82432A05 420912722-X9 MWISS
83058C04 65000325Q1234 K*AJ+
85987D02 1061214Charge #32KBAJ-
87167B01 7000930144XX DCAJ+
91986 01 25072 900-23 MWISS
9576XA00 1001122j55 kbREC
96134B05 60214GOOD BSAJ-
98407C03254*00416Confirmed EHISS
Code:
IDENTIFICATION DIVISION.
PROGRAM-ID. INVTRAN.
* Tate
***************************************************************
* This program reads a fie of inventory transaction,
* validates the data, prints a report showing all transactions
* (with errors indicated), and writes a data file of
* all transactions without errors.
***************************************************************
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INVENTORY-TRANS-FILE-IN
ASSIGN TO 'INVTRAN.SEQ'
ORGANIZATION IS LINE SEQUENTIAL.
* SELECT INVENTORY-TRANS-FILE-OUT
* ASSIGN TO 'INVTRAN.OUT'
* ORGANIZATION IS LINE SEQUENTIAL.
SELECT INVENTORY-TRANS-FILE-OUT-2
ASSIGN TO 'INVTRAN.RPT'
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD INVENTORY-TRANS-FILE-IN.
01 INVENTORY-TRANS-RECORD-IN.
05 PART-NUMBER-IN.
10 PART-NUMERIC-1-IN PIC X(5).
10 PART-ALPHABETIC-IN PIC X.
10 PART-NUMERIC-2-IN PIC XX.
88 VALID-PART-NUMERIC-2 VALUE '01' THRU '68' '78' THRU '99'.
05 QUANTITY-IN.
10 QUANTITY-9-IN PIC 9(5).
05 DATE-IN.
10 MONTH-IN PIC XX.
88 VALID-MONTH-IN VALUE '01' THRU '12'.
10 DAY-IN PIC XX.
88 VALID-DAY-IN VALUE '01' THRU '31'.
05 CHARGE-NUMBER-IN PIC X(10).
05 INITIALS-IN.
10 INITIALS-1-IN PIC X.
10 INITIALS-2-IN PIC X.
05 TRANS-CODE-IN PIC X(3).
88 VALID-TRANS-CODE-IN VALUE 'REC' 'ISS' 'AJ+' 'AJ-'.
FD INVENTORY-TRANS-FILE-OUT-2.
01 INVENTORY-TRANS-RECORD-OUT-2 PIC X(80).
WORKING-STORAGE SECTION.
01 WS-FIRST-TIME-THRU PIC X(3) VALUE 'YES'.
01 LINES-PRINTED PIC 99 VALUE 99.
01 PAGE-NUMBER PIC 99 VALUE ZERO.
01 RECORDS-ERROR-SWITCH PIC X(3).
01 FIELD-ERROR-SWITCH PIC X(3).
01 WS-TOTAL PIC 99 VALUE ZERO.
01 WS-ERROR PIC 99 VALUE ZERO.
01 WS-GOOD PIC 99 VALUE ZERO.
01 WS-QUANTITY PIC 9(4) VALUE ZERO.
01 TOTAL-ERROR-COUNT PIC 9(3) VALUE ZERO.
01 TOTAL-GOOD-COUNT PIC 9(3) VALUE ZERO.
01 TOTAL-GOOD-QUANTITY PIC 9(5) VALUE ZERO.
01 WS-CURRENT-DATE-DATA.
05 WS-CURRENT-DATE.
10 RUN-YEAR PIC XX.
10 RUN-MONTH PIC XX.
10 RUN-DAY PIC XX.
01 HEADING-LINE-1.
05 PIC X(17) VALUE SPACES.
05 PIC X(35) VALUE 'INVENTORY TRANSACTIONS AUDIT TRAIL'.
05 PIC X(8) VALUE SPACES.
05 HL-1-DATE.
10 MONTH-1 PIC XX.
10 PIC X VALUE '/'.
10 DAY-1 PIC XX.
10 PIC X VALUE '/'.
10 YEAR-1 PIC XX.
05 PIC X(3) VALUE SPACES.
05 PIC X(5) VALUE 'PAGE'.
05 HL-1-PAGE-NUMBER PIC Z9.
01 HEADING-LINE-2.
05 PIC X(10) VALUE 'PART NO'.
05 PIC X(5) VALUE 'QUAN'.
05 PIC X(5) VALUE 'DATE'.
05 PIC X(11) VALUE 'CHARGE NO'.
05 PIC X(3) VALUE 'IN'.
05 PIC X(4) VALUE 'TRN'.
05 PIC X(3) VALUE SPACES.
05 PIC X(20) VALUE 'ERROR FIELD NAME'.
05 PIC X(17) VALUE 'ERROR FIELD VALUE'.
01 DETAIL-LINE.
05 PART-NUMBER PIC X(8).
05 PIC X VALUE SPACE.
05 QUANTITY PIC X(5).
05 PIC X VALUE SPACE.
05 DATE-X PIC X(4).
05 PIC X VALUE SPACE.
05 CHARGE-NUMBER PIC X(10).
05 PIC X VALUE SPACE.
05 INITIALS PIC XX.
05 PIC X VALUE SPACE.
05 TRANS-CODE PIC X(3).
05 PIC X(4) VALUE SPACES.
05 FIELD-NAME PIC X(18).
05 PIC XX VALUE SPACES.
05 FIELD-VALUE PIC X(10).
01 TRANSACTIONS.
05 PIC X(41) VALUE 'Total Transactions:'.
05 T-1 PIC 99.
01 ERROR-TRANSACTIONS.
05 PIC X(41) VALUE 'Total Error Transactions:'.
05 T-2 PIC 99.
01 GOOD-TRANSACTIONS.
05 PIC X(41) VALUE 'Total Good Transactions:'.
05 T-3 PIC 99.
01 QUANTITY-TOTAL.
05 PIC X(41) VALUE 'Good Transactions Quantity Total:'.
05 Q-4 PIC 9,999.
PROCEDURE DIVISION.
100-MAIN.
OPEN INPUT INVENTORY-TRANS-FILE-IN
OPEN OUTPUT INVENTORY-TRANS-FILE-OUT-2
ACCEPT WS-CURRENT-DATE FROM DATE
MOVE RUN-MONTH TO MONTH-1
MOVE RUN-DAY TO DAY-1
MOVE RUN-YEAR TO YEAR-1
PERFORM 150-WRITE-HEADINGS
PERFORM UNTIL RECORDS-ERROR-SWITCH = 'YES'
READ INVENTORY-TRANS-FILE-IN
AT END
PERFORM 500-TRANSACTIONS
PERFORM 510-ERROR-TRANSACTIONS
PERFORM 520-GOOD-TRANSACTIONS
PERFORM 530-QUANTITY
MOVE 'YES' TO RECORDS-ERROR-SWITCH
NOT AT END
PERFORM 200-PROCESS-ONE-RECORD
END-READ
END-PERFORM
CLOSE INVENTORY-TRANS-FILE-IN
CLOSE INVENTORY-TRANS-FILE-OUT-2
STOP RUN.
150-WRITE-HEADINGS.
ADD 1 TO PAGE-NUMBER
MOVE PAGE-NUMBER TO HL-1-PAGE-NUMBER
MOVE HEADING-LINE-1 TO INVENTORY-TRANS-RECORD-OUT-2
IF WS-FIRST-TIME-THRU = 'YES'
WRITE INVENTORY-TRANS-RECORD-OUT-2
MOVE 'NO' TO WS-FIRST-TIME-THRU
ELSE
WRITE INVENTORY-TRANS-RECORD-OUT-2 AFTER ADVANCING PAGE
END-IF
MOVE HEADING-LINE-2 TO INVENTORY-TRANS-RECORD-OUT-2
WRITE INVENTORY-TRANS-RECORD-OUT-2
MOVE 1 TO LINES-PRINTED.
200-PROCESS-ONE-RECORD.
IF LINES-PRINTED > 54
PERFORM 150-WRITE-HEADINGS
END-IF
MOVE 'NO' TO RECORDS-ERROR-SWITCH
PERFORM 300-VALIDATE-PART-NUMBER
PERFORM 310-VALIDATE-QUANTITY
PERFORM 320-VALIDATE-DATE
PERFORM 330-VALIDATE-CHARGE-NUMBER
PERFORM 340-VALIDATE-INITIALS
PERFORM 350-VALIDATE-TRANSACTION-CODE
MOVE PART-NUMBER-IN TO PART-NUMBER
MOVE QUANTITY-IN TO QUANTITY
MOVE DATE-IN TO DATE-X
MOVE CHARGE-NUMBER-IN TO CHARGE-NUMBER
MOVE INITIALS-IN TO INITIALS
MOVE TRANS-CODE-IN TO TRANS-CODE
IF RECORDS-ERROR-SWITCH = 'NO'
ADD 1 TO TOTAL-GOOD-COUNT
ADD 1 TO TOTAL-GOOD-QUANTITY
MOVE DETAIL-LINE TO INVENTORY-TRANS-RECORD-OUT-2
WRITE INVENTORY-TRANS-RECORD-OUT-2
ELSE
ADD 1 TO TOTAL-ERROR-COUNT
END-IF.
300-VALIDATE-PART-NUMBER.
IF NOT VALID-PART-NUMERIC-2
MOVE 'Part Number' TO FIELD-NAME
MOVE PART-NUMBER-IN TO FIELD-VALUE
END-IF.
310-VALIDATE-QUANTITY.
IF FUNCTION NUMVAL (QUANTITY-IN) IS GREATER THAN 20000
MOVE 'Quantity' TO FIELD-NAME
MOVE QUANTITY-IN TO FIELD-VALUE
END-IF.
320-VALIDATE-DATE.
IF NOT VALID-MONTH-IN
MOVE 'Date' TO FIELD-NAME
MOVE DATE-IN TO FIELD-VALUE
ELSE
IF NOT VALID-DAY-IN
MOVE 'Date' TO FIELD-NAME
MOVE DATE-IN TO FIELD-VALUE
END-IF
END-IF.
330-VALIDATE-CHARGE-NUMBER.
IF CHARGE-NUMBER-IN IS EQUAL TO ' '
MOVE 'Charge Number' TO FIELD-NAME
MOVE CHARGE-NUMBER-IN TO FIELD-VALUE
END-IF.
340-VALIDATE-INITIALS.
IF ((INITIALS-1-IN IS EQUAL TO ' ') OR (INITIALS-2-IN IS EQUAL TO ' '))
MOVE 'Initials' TO FIELD-NAME
MOVE INITIALS-IN TO FIELD-NAME
END-IF.
350-VALIDATE-TRANSACTION-CODE.
IF NOT VALID-TRANS-CODE-IN
MOVE 'Transaction Code' TO FIELD-NAME
MOVE TRANS-CODE-IN TO FIELD-VALUE
END-IF.
500-TRANSACTIONS.
MOVE WS-TOTAL TO TRANSACTIONS
MOVE T-1 TO INVENTORY-TRANS-RECORD-OUT-2
WRITE INVENTORY-TRANS-RECORD-OUT-2 AFTER ADVANCING 2 LINES.
510-ERROR-TRANSACTIONS.
MOVE WS-ERROR TO ERROR-TRANSACTIONS
MOVE T-2 TO INVENTORY-TRANS-RECORD-OUT-2
WRITE INVENTORY-TRANS-RECORD-OUT-2 AFTER ADVANCING 2 LINES.
520-GOOD-TRANSACTIONS.
MOVE WS-GOOD TO GOOD-TRANSACTIONS
MOVE T-3 TO INVENTORY-TRANS-RECORD-OUT-2
WRITE INVENTORY-TRANS-RECORD-OUT-2 AFTER ADVANCING 2 LINES.
530-QUANTITY.
MOVE WS-QUANTITY TO QUANTITY-TOTAL
MOVE Q-4 TO INVENTORY-TRANS-RECORD-OUT-2
WRITE INVENTORY-TRANS-RECORD-OUT-2 AFTER ADVANCING 2 LINES.
Please ask questions if you need more clarification.
Thank you.
The reason the content of FIELD-NAME and FIELD-VALUE are repeated is that nothing was done to change the content of those fields. At a minimum, it is necessary to move spaces into those fields after writing the report line. In 200-PROCESS-ONE-RECORD, insert a MOVE statement after writing the record, such as that shown below.
MOVE DETAIL-LINE TO INVENTORY-TRANS-RECORD-OUT-2
WRITE INVENTORY-TRANS-RECORD-OUT-2
MOVE SPACES TO FIELD-NAME FIELD-VALUE

How do I fix duplication?

This program is to read in the SEQ file and take the data thru different validations, if it fails to comply with one of the validations the error message is moved to FIELD-NAME.
After all data is processed all transaction are to be used to create the RPT file.
PROBLEM: When reviewing the RPT file, everything is duplicated except the Heading-Line-1. Another weird issue is that ERROR FIELD NAME/ERROR FIELD VALUE keeps repeating the same error after entry is passed.
If you run the code provided with the SEQ also provide you will see how the data currently prints. Attached below is a link to how the first page of data should look.
Desired Output file
SEQ:
11438A01 5000102667-X44 JBISS
12345A77 120103OK BY MIKELLREC
12789B02 14460606144-X22A AJ+
13168A02 31231722394 mkISS
13168A02 70102221-Q18 JBAJ-
2074B01 25 0532 OK BY JIMK RE
22109A04 20000325669-Y5Z DCISS
3077.B22 1000801144X MWAJ-
32149A01 10625567-X1 dcREC
39886B02 2000203517-AA JBAJ+
40442A2( 33 333-Q67 MKISS
43009B01 1440801899-23 MKISS
47890A02 30000422X-4-8 DCISS
49000B01 1000831901-Y6 MWAJ+
51111A011052X0905901-Y66 JBREC
52301A02 10228733876-X1 ABREC
55986b01 99990430A DCISS
57989A01 21130144X JBAJ+
57989A01 500831722394-XX MKISS
59901B0220300133X966-QQ22 MWREC
60022A01 400823 517-X1-33MWAJ+
66780B01 1000831722-YY BwREC
68999A01 21028123-Q88 MKISS
75312B01 500222966-32 BISS
77771A03 12780606 ABISS
78896B02 1000831123456-X13DCREC
80090B01 881$25983334-X25jbAJ
82432A05 420912722-X9 MWISS
83058C04 65000325Q1234 K*AJ+
85987D02 1061214Charge #32KBAJ-
87167B01 7000930144XX DCAJ+
91986 01 25072 900-23 MWISS
9576XA00 1001122j55 kbREC
96134B05 60214GOOD BSAJ-
98407C03254*00416Confirmed EHISS
Code:
IDENTIFICATION DIVISION.
PROGRAM-ID. INVTRAN.
* Tate
***************************************************************
* This program reads a fie of inventory transaction,
* validates the data, prints a report showing all transactions
* (with errors indicated), and writes a data file of
* all transactions without errors.
***************************************************************
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INVENTORY-TRANS-FILE-IN
ASSIGN TO 'INVTRAN.SEQ'
ORGANIZATION IS LINE SEQUENTIAL.
* SELECT INVENTORY-TRANS-FILE-OUT
* ASSIGN TO 'INVTRAN.OUT'
* ORGANIZATION IS LINE SEQUENTIAL.
SELECT INVENTORY-TRANS-FILE-OUT-2
ASSIGN TO 'INVTRAN.RPT'
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD INVENTORY-TRANS-FILE-IN.
01 INVENTORY-TRANS-RECORD-IN.
05 PART-NUMBER-IN.
10 PART-NUMERIC-1-IN PIC X(5).
10 PART-ALPHABETIC-IN PIC X.
10 PART-NUMERIC-2-IN PIC XX.
88 VALID-PART-NUMERIC-2 VALUE '01' THRU '68' '78' THRU '99'.
05 QUANTITY-IN.
10 QUANTITY-9-IN PIC 9(5).
05 DATE-IN.
10 MONTH-IN PIC XX.
88 VALID-MONTH-IN VALUE '01' THRU '12'.
10 DAY-IN PIC XX.
88 VALID-DAY-IN VALUE '01' THRU '31'.
05 CHARGE-NUMBER-IN PIC X(10).
05 INITIALS-IN.
10 INITIALS-1-IN PIC X.
10 INITIALS-2-IN PIC X.
05 TRANS-CODE-IN PIC X(3).
88 VALID-TRANS-CODE-IN VALUE 'REC' 'ISS' 'AJ+' 'AJ-'.
FD INVENTORY-TRANS-FILE-OUT-2.
01 INVENTORY-TRANS-RECORD-OUT-2 PIC X(80).
WORKING-STORAGE SECTION.
01 WS-FIRST-TIME-THRU PIC X(3) VALUE 'YES'.
01 LINES-PRINTED PIC 99 VALUE 99.
01 PAGE-NUMBER PIC 99 VALUE ZERO.
01 RECORDS-ERROR-SWITCH PIC X(3).
01 FIELD-ERROR-SWITCH PIC X(3).
01 WS-TOTAL PIC 99 VALUE ZERO.
01 WS-ERROR PIC 99 VALUE ZERO.
01 WS-GOOD PIC 99 VALUE ZERO.
01 WS-QUANTITY PIC 9V999 VALUE ZERO.
01 TOTAL-ERROR-COUNT PIC 9(3) VALUE ZERO.
01 TOTAL-GOOD-COUNT PIC 9(3) VALUE ZERO.
01 TOTAL-GOOD-QUANTITY PIC 9(5) VALUE ZERO.
01 WS-CURRENT-DATE-DATA.
05 WS-CURRENT-DATE.
10 RUN-YEAR PIC XX.
10 RUN-MONTH PIC XX.
10 RUN-DAY PIC XX.
01 HEADING-LINE-1.
05 PIC X(17) VALUE SPACES.
05 PIC X(35) VALUE 'INVENTORY TRANSACTIONS AUDIT TRAIL'.
05 PIC X(8) VALUE SPACES.
05 HL-1-DATE.
10 MONTH-1 PIC XX.
10 PIC X VALUE '/'.
10 DAY-1 PIC XX.
10 PIC X VALUE '/'.
10 YEAR-1 PIC XX.
05 PIC X(3) VALUE SPACES.
05 PIC X(5) VALUE 'PAGE'.
05 HL-1-PAGE-NUMBER PIC Z9.
01 HEADING-LINE-2.
05 PIC X(10) VALUE 'PART NO'.
05 PIC X(5) VALUE 'QUAN'.
05 PIC X(5) VALUE 'DATE'.
05 PIC X(11) VALUE 'CHARGE NO'.
05 PIC X(3) VALUE 'IN'.
05 PIC X(4) VALUE 'TRN'.
05 PIC X(3) VALUE SPACES.
05 PIC X(20) VALUE 'ERROR FIELD NAME'.
05 PIC X(17) VALUE 'ERROR FIELD VALUE'.
01 DETAIL-LINE.
05 PART-NUMBER PIC X(8).
05 PIC X VALUE SPACE.
05 QUANTITY PIC X(5).
05 PIC X VALUE SPACE.
05 DATE-X PIC X(4).
05 PIC X VALUE SPACE.
05 CHARGE-NUMBER PIC X(10).
05 PIC X VALUE SPACE.
05 INITIALS PIC XX.
05 PIC X VALUE SPACE.
05 TRANS-CODE PIC X(3).
05 PIC X(4) VALUE SPACES.
05 FIELD-NAME PIC X(18).
05 PIC XX VALUE SPACES.
05 FIELD-VALUE PIC X(10).
01 TRANSACTIONS.
05 PIC X(41) VALUE 'Total Transactions:'.
05 T-1 PIC 99.
01 ERROR-TRANSACTIONS.
05 PIC X(41) VALUE 'Total Error Transactions:'.
05 T-2 PIC 99.
01 GOOD-TRANSACTIONS.
05 PIC X(41) VALUE 'Total Good Transactions:'.
05 T-3 PIC 99.
01 QUANTITY-TOTAL.
05 PIC X(41) VALUE 'Good Transactions Quantity Total:'.
05 Q-4 PIC 9,999.
PROCEDURE DIVISION.
100-MAIN.
OPEN INPUT INVENTORY-TRANS-FILE-IN
OPEN OUTPUT INVENTORY-TRANS-FILE-OUT-2
ACCEPT WS-CURRENT-DATE FROM DATE
MOVE RUN-MONTH TO MONTH-1
MOVE RUN-DAY TO DAY-1
MOVE RUN-YEAR TO YEAR-1
PERFORM 150-WRITE-HEADINGS
PERFORM UNTIL RECORDS-ERROR-SWITCH = 'YES'
READ INVENTORY-TRANS-FILE-IN
AT END
PERFORM 500-TRANSACTIONS
PERFORM 510-ERROR-TRANSACTIONS
PERFORM 520-GOOD-TRANSACTIONS
PERFORM 530-QUANTITY
MOVE 'YES' TO RECORDS-ERROR-SWITCH
NOT AT END
PERFORM 200-PROCESS-ONE-RECORD
END-READ
END-PERFORM
CLOSE INVENTORY-TRANS-FILE-IN
CLOSE INVENTORY-TRANS-FILE-OUT-2
STOP RUN.
150-WRITE-HEADINGS.
ADD 1 TO PAGE-NUMBER
MOVE PAGE-NUMBER TO HL-1-PAGE-NUMBER
MOVE HEADING-LINE-1 TO INVENTORY-TRANS-RECORD-OUT-2
IF WS-FIRST-TIME-THRU = 'YES'
WRITE INVENTORY-TRANS-RECORD-OUT-2
MOVE 'NO' TO WS-FIRST-TIME-THRU
ELSE
WRITE INVENTORY-TRANS-RECORD-OUT-2 AFTER ADVANCING PAGE
END-IF
MOVE HEADING-LINE-2 TO INVENTORY-TRANS-RECORD-OUT-2
WRITE INVENTORY-TRANS-RECORD-OUT-2
MOVE 1 TO LINES-PRINTED.
200-PROCESS-ONE-RECORD.
IF LINES-PRINTED > 54
PERFORM 150-WRITE-HEADINGS
END-IF
MOVE 'NO' TO RECORDS-ERROR-SWITCH
PERFORM 300-VALIDATE-PART-NUMBER
PERFORM 310-VALIDATE-QUANTITY
PERFORM 320-VALIDATE-DATE
PERFORM 330-VALIDATE-CHARGE-NUMBER
PERFORM 340-VALIDATE-INITIALS
PERFORM 350-VALIDATE-TRANSACTION-CODE
MOVE PART-NUMBER-IN TO PART-NUMBER
MOVE QUANTITY-IN TO QUANTITY
MOVE DATE-IN TO DATE-X
MOVE CHARGE-NUMBER-IN TO CHARGE-NUMBER
MOVE INITIALS-IN TO INITIALS
MOVE TRANS-CODE-IN TO TRANS-CODE
IF RECORDS-ERROR-SWITCH = 'NO'
ADD 1 TO TOTAL-GOOD-COUNT
ADD 1 TO TOTAL-GOOD-QUANTITY
WRITE INVENTORY-TRANS-RECORD-OUT-2
MOVE DETAIL-LINE TO INVENTORY-TRANS-RECORD-OUT-2
WRITE INVENTORY-TRANS-RECORD-OUT-2
ELSE
ADD 1 TO TOTAL-ERROR-COUNT
END-IF.
300-VALIDATE-PART-NUMBER.
IF NOT VALID-PART-NUMERIC-2
MOVE 'Part Number' TO FIELD-NAME
MOVE PART-NUMBER-IN TO FIELD-VALUE
END-IF.
310-VALIDATE-QUANTITY.
IF QUANTITY-9-IN IS GREATER THAN '20,000'
MOVE 'Quantity' TO FIELD-NAME
MOVE QUANTITY-IN TO FIELD-VALUE
END-IF.
320-VALIDATE-DATE.
IF NOT VALID-MONTH-IN
MOVE 'Date' TO FIELD-NAME
MOVE DATE-IN TO FIELD-VALUE
ELSE
IF NOT VALID-DAY-IN
MOVE 'Date' TO FIELD-NAME
MOVE DATE-IN TO FIELD-VALUE
END-IF
END-IF.
330-VALIDATE-CHARGE-NUMBER.
IF CHARGE-NUMBER-IN IS EQUAL TO ''
MOVE 'Charge Number' TO FIELD-NAME
MOVE CHARGE-NUMBER-IN TO FIELD-VALUE
END-IF.
340-VALIDATE-INITIALS.
IF ((INITIALS-1-IN IS EQUAL TO '') OR (INITIALS-2-IN IS EQUAL TO ''))
MOVE 'Initials' TO FIELD-NAME
MOVE INITIALS-IN TO FIELD-NAME
END-IF.
350-VALIDATE-TRANSACTION-CODE.
IF NOT VALID-TRANS-CODE-IN
MOVE 'Transaction Code' TO FIELD-NAME
MOVE TRANS-CODE-IN TO FIELD-VALUE
END-IF.
500-TRANSACTIONS.
MOVE WS-TOTAL TO TRANSACTIONS
MOVE T-1 TO INVENTORY-TRANS-RECORD-OUT-2
WRITE INVENTORY-TRANS-RECORD-OUT-2 AFTER ADVANCING 2 LINES.
510-ERROR-TRANSACTIONS.
MOVE WS-ERROR TO ERROR-TRANSACTIONS
MOVE T-2 TO INVENTORY-TRANS-RECORD-OUT-2
WRITE INVENTORY-TRANS-RECORD-OUT-2 AFTER ADVANCING 2 LINES.
520-GOOD-TRANSACTIONS.
MOVE WS-GOOD TO GOOD-TRANSACTIONS
MOVE T-3 TO INVENTORY-TRANS-RECORD-OUT-2
WRITE INVENTORY-TRANS-RECORD-OUT-2 AFTER ADVANCING 2 LINES.
530-QUANTITY.
MOVE WS-QUANTITY TO QUANTITY-TOTAL
MOVE Q-4 TO INVENTORY-TRANS-RECORD-OUT-2
WRITE INVENTORY-TRANS-RECORD-OUT-2 AFTER ADVANCING 2 LINES.
If you have any questions please let me know.
The duplicate output occurs in the following code.
IF RECORDS-ERROR-SWITCH = 'NO'
ADD 1 TO TOTAL-GOOD-COUNT
ADD 1 TO TOTAL-GOOD-QUANTITY
WRITE INVENTORY-TRANS-RECORD-OUT-2
MOVE DETAIL-LINE TO INVENTORY-TRANS-RECORD-OUT-2
WRITE INVENTORY-TRANS-RECORD-OUT-2
The first WRITE statement prints a duplicate of the previous line. The second WRITE statement prints a new line, which is printed again on the next loop. Remove the first WRITE statement.
Other problems I noted are:
Invalid literals
330-VALIDATE-CHARGE-NUMBER.
IF CHARGE-NUMBER-IN IS EQUAL TO ''
340-VALIDATE-INITIALS.
IF ((INITIALS-1-IN IS EQUAL TO '') OR (INITIALS-2-IN IS EQUAL TO ''))
A zero-length literal is not permitted; thus, in each case, '' should be ' '.
Invalid numeric compare
310-VALIDATE-QUANTITY.
IF QUANTITY-9-IN IS GREATER THAN '20,000'
QUANTITY-9-IN is defined as PIC 9(5); however the data contains leading spaces and '20,000' is not valid for numeric comparisons. A proper numeric comparison could be:
IF FUNCTION NUMVAL (QUANTITY-IN) IS GREATER THAN 20000
These following were not investigated further than noted.
Print spacing does not match the desired output
There are no ADVANCING phrases for the lines written, thus only single-spacing is used.
Totals do not print correctly
WS-QUANTITY is defined as PIC 9V999. It should be 9999 or 9(4).
The data items for the totals are not being incremented.
The MOVE statements in the 500-, 510-, 520-, and 530- paragraphs overwrite fixed text.

Reformat data leaving numeric digits without separators

I have a field containing article-numbers (PIC X(25)).
Example article number: 12345-6789.
The problem is the "-", I need to delete the "-" and put together the 5 and 6, result example: 123456789
Using Micro Focus Net Express 5.1 running on a UNIX server. The position of the dash is not fixed.
Take this code for a spin.
Update: Good catch, Bill. I just wanted to give options, depending what the needs and demands truly were.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.
* ClassIncludeList and ClassExcludeList can now be referenced much like NUMERIC
CLASS ClassIncludeList IS '0123456789'
CLASS ClassExcludeList IS '-'
.
WORKING-STORAGE SECTION.
01 InputStringText PIC X(1000).
01 InputStringLength PIC 9(04) COMP.
01 OutputStringText PIC X(1000).
01 OutputStringLength PIC 9(04) COMP.
01 ByteSubscript PIC 9(04) COMP.
PROCEDURE DIVISION.
MOVE article-numbers TO InputStringText.
MOVE FUNCTION LENGTH(article-numbers) TO InputStringLength.
PERFORM IncludeCharacters.
* Use OutputStringText(OutputStringLength)
PERFORM ExcludeCharacters.
* Use OutputStringText(OutputStringLength)
IncludeCharacters.
MOVE SPACES TO OutputStringText
MOVE ZERO TO OutputStringLength
PERFORM
VARYING ByteSubscript FROM 1 BY 1
UNTIL ByteSubscript > InputStringLength
IF (InputStringText(ByteSubscript:1) IS ClassIncludeList)
ADD 1 TO OutputStringLength
MOVE InputStringText(ByteSubscript:1)
TO OutputStringText(OutputStringLength:1)
END-IF
END-PERFORM
.
ExcludeCharacters.
MOVE SPACES TO OutputStringText
MOVE ZERO TO OutputStringLength
PERFORM
VARYING ByteSubscript FROM 1 BY 1
UNTIL ByteSubscript > InputStringLength
IF (InputStringText(ByteSubscript:1) IS ClassExcludeList)
CONTINUE
ELSE
ADD 1 TO OutputStringLength
MOVE InputStringText(ByteSubscript:1)
TO OutputStringText(OutputStringLength:1)
END-IF
END-PERFORM
.
There's always UNSTRING and STRING if your Cobol supports them, and if there is a limit to how many 'parts' there are going to be in the text.
01 ARTICLE-NUMBER PIC X(25).
01 PARTS.
05 PART1 PIC X(25).
05 PART2 PIC X(25).
05 PART3 PIC X(25).
05 PART4 PIC X(25).
01 RESULT PIC X(25).
........
INITIALIZE PARTS, RESULT.
UNSTRING ARTICLE-NUMBER
DELIMITED BY '-'
INTO PART1, PART2, PART3, PART4
ON OVERFLOW
DISPLAY "Too many parts!!!"
END-UNSTRING.
STRING PART1, PART2, PART3, PART4
DELIMITED BY SPACE INTO RESULT.
Hope this helps.
The following should work on any modern COBOL:
01 INPUT-STRING PIC X(25).
01 OUTPUT-STRING PIC X(25).
01 IX PIC S9(8) COMP SYNC.
01 OX PIC S9(8) COMP SYNC.
...
MOVE +1 TO OX.
MOVE ALL ' ' TO OUTPUT-STRING.
PERFORM VARYING IX FROM 1 BY 1
UNTIL IX > 25
IF NOT INPUT-STRING(IX:1) = '-'
THEN
MOVE INPUT-STRING(IX:1) TO OUTPUT-STRING(OX:1)
ADD +1 TO OX
END-IF
END-PERFORM.

Occurs and Subscripts

I seem to have yet another problem dealing with COBOL. My teacher has assigned us with having to take a file of names and make it into two columns going 54 rows down. I thought this was going to be simple as I looked in the book as it was more or less using a new function to do what I had all ready been doing, but once I got home and put down my code it all went to heck. Th program I made, for some reason unknown to me, only writes one name in the first column of row one and the does the same ever 54 rows. I am obviously on the wrong track but in my mind it looks right. Here is what I got:
WORKING-STORAGE SECTION.
01 ARE-THERE-MORE-RECORDS PIC X(3) VALUE 'YES'.
01 REPORT-START PIC X VALUE 'Y'.
01 LINE-COUNT PIC 99 VALUE ZEROS.
01 PAGE-NUMBER PIC 99 VALUE ZEROS.
01 NAME-COUNT PIC 9(3) VALUE ZEROS.
01 WORK-AREA-1.
05 N-COLUMN-1 PIC 99 VALUE ZEROS.
01 WORK-AREA-2.
05 N-COLUMN-2 PIC 9(3) VALUE 54.
01 NAME-STORAGE.
05 NAME-STO OCCURS 108 TIMES PIC X(30).
01 WS-DATE.
05 RUN-YEAR PIC XX.
05 RUN-MONTH PIC XX.
05 RUN-DAY PIC XX.
01 HEADING-LINE-1.
05 PIC X(32) VALUE SPACES.
05 PIC X(16)
VALUE 'NAME LIST REPORT'.
05 PIC X(6) VALUE SPACES.
05 HL-1-DATE.
10 MONTH-2 PIC XX.
10 PIC X VALUE '/'.
10 DAY-2 PIC XX.
10 PIC X VALUE '/'.
10 YEAR-2 PIC XX.
05 PIC X(4) VALUE SPACES.
05 PAGE-1 PIC X(4) VALUE 'PAGE'.
05 PIC X(1) VALUE SPACES.
05 NUMBER-PAGE PIC Z9.
01 DETAIL-LINE.
05 BLANK-A-OUT PIC X(4) VALUE SPACES.
05 DL-COLUMN-1 PIC X(30).
05 BLANK-E-OUT PIC X(20) VALUE SPACES.
05 DL-COLUMN-2 PIC X(30).
PROCEDURE DIVISION.
100-MAIN.
OPEN INPUT NAMELIST-FILE-IN
OPEN OUTPUT NAMELIST-FILE-OUT
ACCEPT WS-DATE FROM DATE
MOVE RUN-MONTH TO MONTH-2
MOVE RUN-DAY TO DAY-2
MOVE RUN-YEAR TO YEAR-2
PERFORM 200-NEXT-PAGE
PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO '
READ NAMELIST-FILE-IN
AT END
MOVE 'NO ' TO ARE-THERE-MORE-RECORDS
NOT AT END
PERFORM 300-STORE-NAME
END-READ
END-PERFORM
CLOSE NAMELIST-FILE-IN
CLOSE NAMELIST-FILE-OUT
STOP RUN.
200-NEXT-PAGE.
ADD 1 TO PAGE-NUMBER
MOVE PAGE-NUMBER TO NUMBER-PAGE
MOVE HEADING-LINE-1 TO NAMELIST-RECORD-OUT
IF REPORT-START = 'N'
WRITE NAMELIST-RECORD-OUT
AFTER ADVANCING PAGE
ELSE
MOVE 'N' TO REPORT-START
WRITE NAMELIST-RECORD-OUT
AFTER ADVANCING 1 LINE
END-IF.
MOVE ZEROS TO LINE-COUNT.
300-STORE-NAME.
ADD 1 TO NAME-COUNT
MOVE NAME-IN TO NAME-STORAGE
IF NAME-COUNT > 54
PERFORM 400-PROCESS-FILE
END-IF.
400-PROCESS-FILE.
IF LINE-COUNT >= 52
PERFORM 200-NEXT-PAGE
END-IF
ADD 1 TO LINE-COUNT
ADD 1 TO N-COLUMN-1
ADD 1 TO N-COLUMN-2
MOVE NAME-STO (N-COLUMN-1) TO DL-COLUMN-1
MOVE NAME-STO (N-COLUMN-2) TO DL-COLUMN-2
MOVE DETAIL-LINE TO NAMELIST-RECORD-OUT
WRITE NAMELIST-RECORD-OUT
AFTER ADVANCING 1 LINE
IF N-COLUMN-2 = 108
MOVE 0 TO NAME-COUNT
MOVE 0 TO N-COLUMN-1
MOVE 54 TO N-COLUMN-2
END-IF.
This is not all I have to do, but until I figure this out I cannot continue.
I'm not familiar with this dialect of COBOL, but i thnk the problem is with:
MOVE NAME-IN TO NAME-STORAGE
I t should look like this:
MOVE NAME-IN TO NAME-STO OF NAME-STORAGE(NAME-COUNT)
Am i right am i wrong or am i just dreaming?

Having trouble with my lines in COBOL

I am having a little issue I cannot solve. My lines are showing up wrong on my output. For example I have a line that is suppose to show up like this:
123-45-6789 J S Doe Second Yr Programming 88 266 3.02
but instead is showing up like this:
123-45-6789 J S Doe Second Yr Programming 88 266
3.02
Anyone know how to fix this. I have never encountered this problem before.
Here are is the storage area for the lines
01 DETAIL-LINE.
05 DL-FIRST-NUM PIC X(3).
05 DL-DASH-1 PIC X VALUE '-'.
05 DL-SECOND-NUM PIC XX.
05 DL-DASH-2 PIC X VALUE '-'.
05 DL-THIRD-NUM PIC X(4).
05 BLANK-A-OUT PIC X(3) VALUE SPACES.
05 DL-FIRST-LETTER PIC X.
05 BLANK-B-OUT PIC X VALUE SPACES.
05 DL-SECOND-LETTER PIC X.
05 BLANK-C-OUT PIC X VALUE SPACES.
05 DL-LAST-NAME PIC X(9).
05 BLANK-D-OUT PIC X(2) VALUE SPACES.
05 DL-CLASS-STANDING PIC X(9).
05 BLANK-E-OUT PIC X(3) VALUE SPACES.
05 DL-MAJOR PIC X(13).
05 BLANK-F-OUT PIC X(3) VALUE SPACES.
05 DL-HOURS PIC ZZ9.
05 BLANK-G-OUT PIC X(5) VALUE SPACES.
05 DL-POINTS PIC ZZ9.
05 BLANK-H-OUT PIC X(4) VALUE SPACES.
05 DL-GPA PIC 9.99.
and here is the code to write it out
400-PROCESS-ONE-RECORD.
IF LINE-COUNT >= 52
PERFORM 600-NEXT-PAGE
END-IF
ADD 2 TO LINE-COUNT
MOVE SSN-IN TO SSN-BREAK
MOVE FIRST-NUM TO DL-FIRST-NUM
MOVE SECOND-NUM TO DL-SECOND-NUM
MOVE THIRD-NUM TO DL-THIRD-NUM
MOVE STUDENT-NAME-IN TO NAME-BREAK
MOVE FIRST-LETTER TO DL-FIRST-LETTER
MOVE SECOND-LETTER TO DL-SECOND-LETTER
MOVE LAST-NAME TO DL-LAST-NAME
IF CLASS-STANDING-IN = 0
MOVE 'HIGH SCHOOL' TO DL-CLASS-STANDING
END-IF
IF CLASS-STANDING-IN = 1
MOVE 'First Yr' TO DL-CLASS-STANDING
END-IF
IF CLASS-STANDING-IN = 2
MOVE 'Second Yr' TO DL-CLASS-STANDING
END-IF
IF CLASS-STANDING-IN = 3
MOVE 'PROGRAM 60' TO DL-CLASS-STANDING
END-IF
IF CLASS-STANDING-IN = ' ' OR 4
MOVE ' ' TO DL-CLASS-STANDING
END-IF
IF MAJOR-IN = 'NES'
MOVE 'Net Security' TO DL-MAJOR
END-IF
IF MAJOR-IN = 'NET'
MOVE 'Networking' TO DL-MAJOR
END-IF
IF MAJOR-IN = 'PGM'
MOVE 'Programming' TO DL-MAJOR
END-IF
IF MAJOR-IN = 'DIG'
MOVE 'Digital Media' TO DL-MAJOR
END-IF
IF MAJOR-IN = 'COR'
MOVE ' ' TO DL-MAJOR
END-IF
MOVE CREDIT-HOURS-IN TO DL-HOURS
IF MAJOR-IN = 'NES'
ADD 1 TO NES-TOTAL
END-IF
IF MAJOR-IN = 'NET'
ADD 1 TO NET-TOTAL
END-IF
IF MAJOR-IN = 'PGM'
ADD 1 TO PGM-TOTAL
END-IF
IF MAJOR-IN = 'DIG'
ADD 1 TO DIG-TOTAL
END-IF
MOVE CREDIT-POINTS-IN TO DL-POINTS
COMPUTE TOTAL-GPA ROUNDED
= CREDIT-POINTS-IN / CREDIT-HOURS-IN
IF MAJOR-IN = 'NES' AND TOTAL-GPA > '3.O'
ADD 1 TO NES-GPA
END-IF
IF MAJOR-IN = 'NET' AND TOTAL-GPA > '3.O'
ADD 1 TO NET-GPA
END-IF
IF MAJOR-IN = 'PGM' AND TOTAL-GPA > '3.O'
ADD 1 TO PGM-GPA
END-IF
IF MAJOR-IN = 'DIG' AND TOTAL-GPA > '3.O'
ADD 1 TO DIG-GPA
END-IF
MOVE TOTAL-GPA TO DL-GPA
MOVE DETAIL-LINE TO STUDENTS-RECORD-OUT
IF DL-CLASS-STANDING = 'First Yr' OR 'Second Yr' AND
GRAD-STAT-IN = ' ' OR 'X'
ADD CREDIT-POINTS-IN TO TOTAL-POINTS
ADD CREDIT-HOURS-IN TO TOTAL-HOURS
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 1 LINES
END-IF.
There are a couple of possible explanations for the line break.
The first explanation to eliminate is line wrapping caused by
whatever device you are displaying output on. Based on the DETAIL-LINE record
layout you have provided, the wrap occurs at column 72. Suspicious. Does your output device (eg. screen, or file) wrap lines at column 72
The next possible explanation involves some non-SPACE character, such as a line feed,
stored in BLANK-H-OUT. This may have happened through any number of programming goofs
elsewhere in the program. Unchecked out of bounds array/table references are often the
source of this sort of thing. Working this out will take some real debugging.
Are you writing to a 72 character wide file? My hunch is that your record is 3 characters too short.
Can you post your File Section?

Resources