Solved

cobol control-break question

Posted on 2000-04-12
6
349 Views
Last Modified: 2011-09-20
I have a text file with6 fields
region            pic x 3
section           pic x 3
proj #            pic x 5
type               pic x 15
budget amt    pic 9(9)
actual amt      pic 9(9)

I have to create a report showing the following fields with thier proper
headings.  also I must show a variance (+, -) showing the difference
between budget and actual amts.     I am able to do this,  but at the bottom of the report I must show totals for sections, and totals for regions.
  When I attempt to do this I loose my calculated variance field.  I know
I am doing this program incorrectly and am going nowhere.  if it will
help I can e-mail my .txt file and my code.

thank you.
0
Comment
Question by:qsysopr
  • 3
  • 2
6 Comments
 
LVL 3

Expert Comment

by:arch_great
ID: 2711299
Keep 2 variables for Regiontot and Section tot (which will become 0 ,when the region changes.... )

Pseudo code (not in COBOL)

mregtot = 0
msectot = 0

AS long as !eof()
    mregion = region
    msection = section
   

    if section changes
        do control break (where U will print that section's total...
    endif    

    if region changes
            do control break (where U will print that region's total...
    endif

     Calculate variance for each detail....

-----------

In Control break  of section and region , reinitialise the respective totals to zero...
 
0
 
LVL 54

Accepted Solution

by:
nico5038 earned 50 total points
ID: 2713325
You are trying to write a so called "level" program.

The solution arch great proposes is nearly OK but (as often) forgets to take the EOF situation in consideration.

Main processing is:

define an actual and a saved key:

01 WA-KEY.
   03 WA-EOF      PIC X(01).
   03 WA-SECTION  PIC X(03).
   03 WA-REGION   PIC X(03).

01 WA-KEY-SECTION REDEFINES WA-KEY.
   03 FILLER      PIC X(04).

01 WS-KEY.
   03 WS-EOF      PIC X(01).
   03 WS-SECTION  PIC X(03).
   03 WS-REGION   PIC X(03).

01 WB-KEY-SECTION REDEFINES WB-KEY.
   03 FILLER      PIC X(04).

PROCEDURE DIVISION.

PERFORM INIT-ROUTINE

PERFORM MAIN-ROUTINE UNTIL WB-EOF = "1"

MAIN-ROUTINE
MAIN01:
   ' Test no total
   IF WA-KEY = WB-KEY
      PERFORM PRINT-DETAIL
      PERFORM READ-NEXT
      GOTO MAIN01
    END
    ' Test region total
    IF WA-KEY-SECTION = WB-KEY-SECTION
      PERFORM PRINT-REGION-TOTAL
      INIT region
      PERFORM PRINT-DETAIL
      PERFORM READ-NEXT
      GOTO MAIN01
    END
    ' Test section total
    IF WA-EOF = WB-EOF
      PERFORM PRINT-REGION-SECTION-TOTAL
      INIT section and region
      PERFORM PRINT-DETAIL
      PERFORM READ-NEXT
      GOTO MAIN01
    END
    ' Hereyou get when WA-EOF is set
    ' Just print the last totals and ready !
    PERFORM PRINT-REGION-SECTION-TOTAL
    MOVE WA-EOF TO WB-EOF
END MAIN

READ-NEXT
      COUNT region and section
      MOVE WB-KEY TO WA-KEY
      READ NEXT
      MOVE fields to WA
      SET WA-EOF WHEN EOF OCCURS
END READ-NEXT

INIT-ROUTINE
      SET COUNT region and section TO ZERO
      READ FIRST
      MOVE fields to WA
      MOVE WA-KEY TO WB-KEY
      SET WA-EOF WHEN EOF OCCURS
END INIT-ROUTINE
     
0
 
LVL 24

Expert Comment

by:SunBow
ID: 2739389
I swear I won't cobol, but I am also sure that if I did and init routine I would also run a cleanup routine at the end.

More than likely I would use Eof to process some totalling code, then leaf out to cleanup of files and such.

>       PERFORM PRINT-DETAIL
>       PERFORM READ-NEXT

yah, very nice and crisply done
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 54

Expert Comment

by:nico5038
ID: 2739684
Sunbow,

Using a 'switch-value' for EOF in a "sortwork-key" offers the advantage that even multiple files can be "levelled" automatically and that those files having EOF are automatically skipped for pocessing by the value of this EOF field!
0
 
LVL 54

Expert Comment

by:nico5038
ID: 2772434
How is the progress on the report ?
0
 
LVL 24

Expert Comment

by:SunBow
ID: 2834518
did it work?
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
matchUp  challenge 9 71
ClickOnce Install - Shortcut Question 3 58
Fibonacci challenge 11 82
Turning python script into an applet 12 37
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now