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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Acceptance to Printout. 2

Status
Not open for further replies.

scurf

Programmer
Feb 5, 2002
19
GB
Good evening chaps and chapesses,

I need to code a program that will read a file from disk called "SALES-FILE.DAT" , the data is already in ascending order of TYPE-CODE and pre-validated and will eventually be sent to the printer.. I am having my usual problem of drawing a structure chart, I have this so far.

______________ SALES PROGRAM_________________
| | |
INITIAL UPDATE PROCESS CLOSE
____PROCESS______ UNTIL END OF FILE FILES
| | |
OPEN READ PRINT
SALES SALES HEADINGS

1) Should my update process be on a separate chart?

The main process required is to Read the field TYPE-CODE of the incoming DATA which is either a "1" or a "2", I need to code a control break when the TYPE-CODE changes from 1 to 2,.
If 1 is read then the field UNIT-PRICE (pic 9(3)v1) needs to be multiplied by the field WEIGHT, When 2 is read then the field UNIT-PRICE needs to be multiplied by the field QUANTITY.

This is only a small part of the program requirement, any help on the structure chart would be great, I am sure that I can code most of the other requirements of the program, but any help would be greatly appreciated.

Cheers all

GAZ

 
Hi Scurf,

From what I can see, you only print the headings. You're not one of those "environmentalist whakos", are you? :)

The following:

IF W-TYPE-CODE = 1 THEN
MOVE “POTATOES” TO W-VEG-TYPE ELSE
IF W-TYPE-CODE = 2 THEN
MOVE “TURNIPS” TO W-VEG-TYPE ELSE
IF W-TYPE-CODE = 3 THEN
MOVE “PEAS” TO W-VEG-TYPE ELSE
IF W-TYPE-CODE = 4 THEN
MOVE “CARROTS” TO W-VEG-TYPE ELSE
IF W-TYPE-CODE = 5 THEN
MOVE “SPROUTS” TO W-VEG-TYPE ELSE
MOVE “ TINNED VEG” TO W-VEG-TYPE
END-IF
END-IF
END-IF
END-IF
END-IF

May be better written as:
Code:
EVALUATE W-TYPE-CODE
WHEN 1
     MOVE “POTATOES”    TO W-VEG-TYPE 
WHEN 2
     MOVE “TURNIPS”     TO W-VEG-TYPE
WHEN 3
     MOVE “PEAS”        TO W-VEG-TYPE
WHEN 4
     MOVE “CARROTS”     TO W-VEG-TYPE
WHEN 5
     MOVE “SPROUTS”     TO W-VEG-TYPE
WHEN OTHER
     MOVE “ TINNED VEG” TO W-VEG-TYPE
END-EVALUATE
Still looking, Jack.

P.S. to get your code to align properly, type this:

*
Code:
*
your code goes here
*
* but don't key in the "*"s. I had to do that to fool the TGML editor.
 
Looks like it wasn't fooled. :~/ Again:

[*code*]
your code goes here
[*/code*] but don't code the "*"s.
 
I shall dispose of the IFS and use evaluate, it looks alot better, No I am not an evironmentalist, I am just trying my best to learn a new skill so that I can move on from my current job as a Benefit Fraud Investigator, I only put the *'s in as I was told to do so when applying comments to code. But fair enough, you are the proffessionals. Jack when you say "That I only print the headings", is this because my coding is crap and the program Ive coded does not meet the specification. I sometimes feel that my coding gets a bit long and I seem to include too many datanames..
I must get a compiler, unfortunately it would take about 2 years to download one on my dinosaur!!!!...

Thanks

Garry
sausages@scurfield.fsnet.co.uk
 
Hi Garry,

Oh, boy, I think we have a failure to communicate:

1) When I said you wrote only the headings, I meant that you never printed the detail lines or the control break lines. If you ran your pgm as it is now written, it would print the headings repeatedly and nothing else.

2) That lead to my attempt at the "environmentalist" joke. You see, if you only print the headings and not the detail, you save a LOT of paper. Therefore a LOT of trees. Get it? OK, so it's not that funny.

3) I'm guessing at this one, but the "*" comment you made in your reply must be in response to my P.S. I meant you should not type the "*" when you use the [*code*]/[*/code*] TGML tags. I had to use them to fool the editor, else they wouldn't show up in the post. It had nothing to do with your use of comments in the code. That is encouraged. Click on the "Preview Post" button and scroll down to the bottom of the page. You will see a Note that discusses how to use these tags.

4) Smile when you say "dinosaur" pardner.

Regards, Jack.
 
Sorry Jack, I must not have had my humour hat on yesterday......Thanks for the tip, I will reveiw the coding and try to clean it up...........

Cheers again, Garry...
 
Hello again, Hello, (In the woirds of Niel Diamond...Ignore my attempt at humour... I have had a look again at my code and made some minor adjustments, have I solved the problem with continuous printing of headers????

[*code*]

IDENTIFICATION DIVISION.
PROGRAM I-D. EXAM3.

*THIS PROGRAM WILL ACCEPT DATA FROM THE DISK FILE “SALESFILE.DAT” AND READ IT INTO THE *SALES-FILE. THE PROGRAM WILL CARRY OUT CALCULATIONS ON CERTAIN ELEMENTS OF DATA *AND PERFORM CONTROL BREAKS, THE OUTPUT IS A PRINTED REPORT.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT SALES-FILE ASSIGN TO “SALESFILE.DAT”
ORGANIZATION SEQUENTIAL.
SELECT PRINT-FILE
ASSIGN TO PRINTER.

DATA DIVISION.
FILE SECTION.
FD SALES-FILE.
01 SALES-RECORDS.
03 REF-NUMBER PIC X(6).
03 TYPE-CODE PIC 9.
03 WEIGHT PIC 9(4).
03 QUANTITY PIC 9(4).
03 CALC-METHOD PIC 9.
03 UNIT-BUY-PRICE PIC 9(3)V9.
03 UNIT-SALE-PRICE PIC 9(3)V9.

FD PRINT-FILE.
01 PRINT-REC PIC X(140).

WORKING-STORAGE SECTION.

01 END-FILE-FLAG PIC X VALUE “N”.
88 SALES-EOF VALUE “Y”.
01 W-TYPE-CODE PIC 9.
01 W-BUY-VALUE PIC 9(4)V99.
01 W-SALE-VALUE PIC 9(4)V99.
01 W-TOTAL-BUY-VALUE PIC 9(5)V99.
01 W-TOTAL-SALE-VALUE PIC 9(5)V99.
01 W-PROFIT PIC S9(5)V99.
01 W-GRAND-BUY-VALUE PIC 9(6)V99.
01 W-GRAND-SALE-VALUE PIC 9(6)V99.
01 W-GRAND-PROFIT PIC S9(6)V99.
01 W-BUY-CUMILATIVE-TOTAL PIC 9(4)V99 VALUE 0.
01 W-SALE-CUMILATIVE-TOTAL PIC 9(4)V99 VALUE 0.
01 W-CUMILATIVE-PROFIT PIC S9(6)V99 VALUE 0.
01 W-SALES-VALUE-FOR-ALL-SALES PIC 9(4)V99 VALUE 0.
01 W-BUY-VALUE-FOR-ALL-BUY PIC 9(4)V99 VALUE 0.


01 W-PRINT-HEADING.
03 PIC X(15) VALUE SPACES.
03 PIC X(49) VALUE “MR GREENS (WHOLESALER) - DAILY SALES
REPORT”.
03 PIC X(5) VALUE SPACES.

01 W-DATE
03 W-DATE-DAY PIC 99.
03 PIC X VALUE “/”.
03 W-DATE-MONTH PIC 99.
03 PIC X VALUE “/”.
03 W-DATE-YEAR PIC 99.
03 PIC X(18) VALUE SPACES.

03 PIC X(4) VALUE “PAGE”.
03 PIC X VALUE SPACES.
03 W-PAGE-NUMBER PIC ZZ9 VALUE 1.

01 W-PRINT-SUBHEADING.
03 PIC X(54) VALUE SPACES.
03 PIC X(22) VALUE “BUYING”.
03 PIC X(18) VALUE “SALE”.
03 PIC X(13) VALUE “PROFIT”.

01 W-PRINT-SUBHEADING1.
03 PIC X(10) VALUE SPACES.
03 PIC X(11) VALUE “REFERENCE”.
03 PIC X(2) VALUE “TYPE”.
03 PIC X(3) VALUE “WEIGHT”.
03 PIC X(3) VALUE “QTY”.
03 PIC X(2) VALUE “CALC”.
03 PIC X(4) VALUE “PRICE”.
03 PIC X(4) VALUE “VALUE”.
03 PIC X(7) VALUE “PRICE”.
03 PIC X(5) VALUE “VALUE”.

01 W-PRINT-SUBHEADINGS2.
03 PIC X(15) VALUE SPACES.
03 PIC X(14) VALUE “NO”.
03 PIC X(11) VALUE “KILOS”.
03 PIC X(9) VALUE “METH”.
03 PIC X(7) VALUE “P”.
03 PIC X(8) VALUE “£”.
03 PIC X(12) VALUE “P”.
03 PIC X(8) VALUE “£”.

01 W-DETAIL-LINE.
03 PIC X(12) VALUE SPACES.
03 W-OUT-REF-NO PIC X.
03 PIC X(4) VALUE SPACES.
03 W-OUT-TYPE PIC X.
03 ` PIC X(6) VALUE SPACES.
03 W-OUT-WEIGHT PIC 9(4).
03 PIC X(3) VALUE SPACES.
03 W-OUT-QUANTITY PIC 9(4).
03 PIC X(4) VALUE SPACES.
03 W-OUT-CALC-METHOD PIC 9.
03 PIC X(4) VALUE SPACES.
03 W-OUT-BUY-PRICE PIC 9(3)V9.
03 PIC X(5) VALUE SPACES.
03 W-OUT-BUY-VALUE PIC 9(4)V99.
03 PIC X(7) VALUE SPACES.
03 W-OUT-SALE-PRICE PIC 9(4)V99.
03 PIC X(5) VALUE SPACES.
03 W-OUT-SALE-VALUE PIC 9(4)V99.

*THE NEXT PARAGRAPH WILL DEFINE THE SUB-TOTALS WHEN A CONTROL BREAK IS REACHED, IE. *WHEN THE TYPE-CODE CHANGES.

01 W-DETAIL-LINE-SUB-TOTALS.
03 PIC X(22) VALUE SPACES.
03 W-OUT-TYPE PIC X.
03 PIC X(2) VALUE “TOTALS”.

03 W-VEG-TYPE PIC X(10).
03 PIC X(57) VALUE SPACES.
03 W-OUT-TOTAL-BUY PIC 9(5)V99.
03 PIC X(14) VALUE SPACES.
03 W-OUT-TOTAL-SALE PIC 9(5)V99.
03 PIC X(6) VALUE SPACES.
03 W-OUT-PROFIT PIC S9(5)V99.

01 W-GRAND-TOTALS.
03 PIC X(25) VALUE SPACES.
03 PIC X(31) VALUE “GRAND TOTALS”.
03 PIC X(18) VALUE SPACES.
03 W-GRAND-BUY-VALUE PIC 9(6)V99.
03 PIC X(13) VALUE SPACES.
03 W-GRAND-SALE-VALUE PIC 9(6)V99.
03 PIC X(8) VALUE SPACES.
03 W-GRAND-TOTAL-PROFIT PIC S9(6)V99.

PROCEDURE DIVISION.

OPEN INPUT SALES-FILE
OUTPUT PRINT-FILE
PERFORM NEW-HEADINGS-1
PERFORM RESET-CUMILATIVE-TOTALS
PERFORM INITIAL-PROCESS
PERFORM CONTROL-BREAK
PERFORM GRAND-TOTALS
PERFORM CLOSE-FILES
STOP RUN.

* MORE PROCESSES

NEW-HEADINGS-1.
WRITE PRINT-REC FROM W-PRINT-HEADING AFTER PAGE
MOVE DATE TO W-DATE
WRITE PRINT-REC FROM W-PRINT-SUBHEADING
WRITE PRINT-REC FROM W-PRINT-SUBHEADING1
WRITE PRINT-REC FROM W-PRINT-SUBHEADING2

INITIAL-PROCESS.

READ SALES-FILE
AT END MOVE “Y” TO END-FILE-FLAG
END-READ
MOVE TYPE-CODE TO W-TYPE-CODE
PERFORM UNTIL SALES-EOF
MOVE REF-NUMBER TO W-OUT-REF-NO
MOVE TYPE-CODE TO W-OUT-TYPE
MOVE WEIGHT TO W-OUT-WEIGHT
MOVE QUANTITY TO W-OUT-QUANTITY
MOVE CALC-METHOD TO W-OUT-CALC-METHOD
MOVE UNIT-BUY-PRICE TO W-OUT-BUY-PRICE

*USE TYPE-CODE AS THE CONTROL BREAK, TYPE-ODE CORRESPONDS TO THE VEGETABLES SOLD, *WHEN THE TYPE CODE CHANGES THIS INDICATED THE CHANGE IN THE VEGETABLE TYP SOLD.

PERFORM CALCULATION UNTIL TYPE-CODE NOT = W-TYPE-CODE
PERFORM CONTROL-BREAK.

*CALCULATE THE TOTALS IN THE DETAIL LINE, IF THE CALCULATION METHOD IS “1” THEN THE BUY *VALUE AND SALE VALUE ARE CALCULATED BY MULTIPLYING BY THE WEIGHT BY THE UNIT BUY *PRICE AND UNIT SALE PRICE..IF THE METHOD IS “2” THEN THEY ARE MULTIPLIED BY THE QUANTITY.
*A CUMILATIVE FIELD IS ALSO KEPT IN WORKING STORAGE TO KEEP A CUMILATIVE VALUE OF THE *BUY VALUES AND SALE VALUES WHICH NEED TO BE USED TO DISPLAY THE TOTALS WHEN THE *CONTROL BREAK IS REACHED.


CALCULATION.
IF CALC-METH = 1 THEN
COMPUTE W-OUT-BUY-VALUE = UNIT-BUY-PRICE * WEIGHT AND
COMPUTE W-OUT-SALE-VALUE = UNIT-SALE-PRICE * WEIGHT
ELSE
COMPUTE W-OUT-BUY-PRICE = UNIT-BUY-PRICE * QUANTITY AND
COMPUTE W-OUT-SALE-PRICE = UNIT-SALE-PRICE * QUANTITY

COMPUTE W-BUY-CUMILATIVE-TOTAL = W-BUY-CUMILATIVE-TOTAL + W-OUT-BUY-PRICE
COMPUTE W-SALE-CUMILATIVE-TOTAL = W-SALE-CUMILATIVE-TOTAL + W-OUT-SALE-PRICE.
COMPUTE W-OUT-PROFIT = W-SALE-CUMILATIVE-TOTAL - W-BUY-CUMILATIVE-TOTAL

COMPUTE W-SALES-VALUE-FOR-ALL-SALES = W-SALES-VALUE-FOR-ALL-SALES + W-SALE-CUMILATIVE-TOTAL
COMPUTE W-BUY-VALUE-FOR-ALL-BUY = W-BUY-VALUE-FOR-ALL-BUY + W-BUY-CUMILATIVE-TOTAL
COMPUTE W-GRAND-VALUE-PROFIT = W-GRAND-VALUE-PROFIT + W-CUMILATIVE-PROFIT

END-IF
CONTROL-BREAK.
MOVE W-TYPE-CODE TO W-OUT-TYPE
EVALUATE W-TYPE-CODE
WHEN 1
MOVE “POTATOES” TO W-VEG-TYPE
WHEN 2
MOVE “TURNIPS” TO W-VEG-TYPE
WHEN 3
MOVE “PEAS” TO W-VEG-TYPE
WHEN 4
MOVE “CARROTS” TO W-VEG-TYPE
WHEN 5
MOVE “SPROUTS” TO W-VEG-TYPE
WHEN OTHER
MOVE “ TINNED VEG” TO W-VEG-TYPE
END-EVALUATE


MOVE W-BUY-CUMILATIVE-TOTAL TO W-OUT-TOTAL-BUY
MOVE W-SALE-CUMILATIVE-TOTAL TO W-OUT-TOTAL-SALE
COMPUTE W-OUT-PROFIT = W-OUT-TOTAL-SALE - W-OUT-TOTAL-BUY

*RESET THE SUB TOTAL VALUES FOR THE NEXT CONTROL BREAK

RESET-CUMILATIVE-TOTALS.

MOVE 0 TO W-BUY-CUMILATIVE-TOTAL
MOVE 0 TO W-SALE-CUMILATIVE-TOTAL
MOVE 0 TO W-CUMILATIVE PROFIT

*MOVE FIGURES TO THE GRAND VALUE ONCE THE FILE REACHES THE END.
GRAND-TOTALS.

AT SALES-EOF
MOVE W-SALES-VALUE-FOR-ALL-SALES TO W-GRAND-SALE-VALUE
MOVE W-BUY-VALUE-FOR-ALL-BUY TO W-GRAND-BUY-VALUE
MOVE W-GRAND-VALUE-PROFIT TO W-GRAND-TOTAL-PROFIT

CLOSE-FILES.

[*/code*]

Fingers crossed.....

Cheers

Garry
sausages@scurfield.fsnet.co.uk




 
Hi Garry,

I’m not sure if you’re understanding the function of a PERFORM stmt or you don‘t see the error in the logic. If you look at the code in INITIAL-PROCESS you’ll see that you read a rec, then later you code:

PERFORM CALCULATION UNTIL TYPE-CODE NOT = W-TYPE-CODE

If the type-codes are already not = when you attempt to execute that perform, it won't execute. If they are =, the pgm will loop, because neither of the type codes will change. I guess you're expecting the types to change as a result of the read, but the read never occurs.

It may help you to think of the loops that come into play in the pgm. For example:

To process the file, you must process all the veggie types in it; to process a veggie type, you must process all the detail recs associated w/it. So, you’ve got 2 loops, one inside the other. Sound familiar? :)

Don’t get bogged down w/the details initially. Just block out the main processing functions and their relationships. Feel comfortable w/that 1st. Some pseudo code:
Code:
mainline.   
    perf read ip-rec 
    if ip-eof show error and stop
    perf proc-veggie-types until ip-eof
    end it
    .
proc-veggie-types.
    reset  veggie break sw
    move the veggie type stuff to the op-rec
     (it'll be gone after the perf if you don't)
    perf cum-veggie-types-tots until veggie-is-fini
    perf control-break
    . 
cum-veggie-types-tots.
    accum the stuff 
    perf read-ip-rec
    .
read-ip-rec.
    move ip-veggie-type to prev-veggie-type
    read ip-rec at end 
     set eof-sw, move hi-vals to ip-veggie-type
    perf chk-for-veggie-break
    .
chk-for-veggie-break.
    if ip-veggie-type not = prev-veggie-type        
       set veggie-is-fini to true
    .
I added more detail than is necessary for a 1st cut, but as you get used to the process, you’ll find more to add.

Regards, Jack.

P.S. I see you used the [*code*], the next time don’t include the *s and it’ll work.
 
Hey Garry,

Haven't heard from you in a while. Hope I didn't inadvertantly insult you again. How is the project going?

Regards, Jack.
 
Hello Jack,

I never get insulted, anyway, the program is being rested for a week or to whilst I carry out more important duties...ie Decorating, I will get back if or when I need furtherr assistance....

Cheers Pal

Garry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top