View previous topic :: View next topic
|
Author |
Message |
bbharathiraj Warnings : 1 New User
Joined: 26 Oct 2006 Posts: 50 Location: Chennai
|
|
|
|
Dear Friends,
Below question was raised by my collegue. I tried all the way with my COBOL knoweldge but couldn't find solution
Question:
How to generate the below report with out using IF/EVALUATE with input file contains 2 fileds 1) Salary 2) Employee number.
Code: |
Salary NO OF Employee TOTAL Employees
-------------------------------------------------------------------------
1000 10 10
2000 20 30
10000 30 70 |
Assume: Total record is 70 in input file
Is there any way in COBOL with out IF/EVALUATE |
|
Back to top |
|
|
Peter cobolskolan
Active User
Joined: 06 Feb 2012 Posts: 104 Location: Sweden
|
|
|
|
Are you sure your college is a programmer?
The basics in all programming languages are IFs and different types of EVALUATE. |
|
Back to top |
|
|
bbharathiraj Warnings : 1 New User
Joined: 26 Oct 2006 Posts: 50 Location: Chennai
|
|
|
|
Yes. He is working with me for last 6 years as developer |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Just hard-code the report lines and DISPLAY them.
Unless you can come up with a very, very good reason for the question, we don't do "if magic could happen" answers. |
|
Back to top |
|
|
don.leahy
Active Member
Joined: 06 Jul 2010 Posts: 765 Location: Whitby, ON, Canada
|
|
|
|
What is this, a bar bet? |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Thanks for that Don, I had been thing it was something real but stupid :-)
OK, search for the Cobol Report Writer manual. That'll do what your colleague has challenged you to with Cobol. Summing, totally, control-breaks etc, all you do is define that they need to be done and with what fields, and the "Report Writer" does the rest. |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
All I see is that a simple sort job would it for to get a report without IF / EVALUATE statements |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Pandora-Box wrote: |
All I see is that a simple sort job would it for to get a report without IF / EVALUATE statements |
great! but:
bbharathiraj wrote: |
Is there any way in COBOL with out IF/EVALUATE |
need to stay on subject.... |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
my mistake thanks for correction |
|
Back to top |
|
|
bbharathiraj Warnings : 1 New User
Joined: 26 Oct 2006 Posts: 50 Location: Chennai
|
|
|
|
I just want to share with COBOL experts is there any solution for this since I take this question seriously.
I will post the possible solution if I get it from questioner
I think, as Bill recommended, Cobol Report writer might be the solution |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
First, it is an extremely poor question -- probably should be in the homework or interview questions section of this forum, not in the COBOL section.
Second, your colleague obviously wants you to explore COBOL Report Writer, which would be the ONLY way in COBOL to generate the given output without explicit IF statements (Report Writer has implicit IF statements for control breaks).
Third, COBOL Report Writer is NOT part of COBOL -- IBM lists it as a separate product with its own order number (5798-DYR, 5798-DZX for Report Writer versus 5655-S71 for Enterprise COBOL V4.1). So unless a site orders (and pays for) the Report Writer, that functionality will not be present so at many sites what you want to do is not possible, period. |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Hi Why dont you try this logic
Prerequisite the input file is sorted based on Salary
Code: |
Open input
Open output report file
Write header
Read input file
Store salary in field ws-salary , ws-salary2
Perform until EOF is reached
Perform Until ws-salary not = ws-salary2
Add 1 to no of employees
Add 1 to Total-total employee
Read input-file
Store salary in field ws-salary
End-Perform
Write Salary , no of employees , total employees to report
reinitialize no of employees
move ws-salary to ws-salary2
End-Perform |
Experts correct me If I am wrong I just gave a shot never tested it |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Looks pretty good to me providing there is no "scope creep". If there becomes an increase in the number of different "salaries", somethng would be needed to print headers on the next page.
Well done
d |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Thanks Dick and yes agreed to your point on the fresh header for next page
just trying to improve myself through vicarious experiences |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
just trying to improve myself through vicarious experiences |
Do continue at this - it works very well
d |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Sure cant stop myself |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
I kind of like that too, pandora-box.
You would need to read another record :-)
You could even do the pagination with PERFORM UNTILs. If the test is true, the perform does not get done.
Going back to your own Sort suggestion, it is also not so bad. Do the report in Sort, then simply read/write in the Cobol program. Just a perform-until-end-of-file type of thing.
OK, wouldn't meet the input file requirement. So, to keep to the "spirit" of the Cobol-only and the input file, it might, I don't know, be possible to do the formatting of the report as a Cobol internal sort, then just do the printing.
So, although probably not the expected answer, though maybe it is, it is certainly not a bad answer to an odd question, pandora-box.
Oh, dear, it might also be easier than we are thinking.
How about, use the salary as a subscript? Normalise it first, add one. At end of file, empty table (PERFORM UNTIL for table PERFORM UNTIL for non-zero), turn the subscript back to a salary, do the running total. Pagination as above.
'Nuff now. |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Thanks Bill
I was pretty doubtful of adding another read then realised I might need it though couldnt edit my post that point of time .
Wish I get the moderating access one day so I could edit my post any point it time
I did understand the logic of yours. ..
Got to try it later point in time
Thanks about that |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Wish I get the moderating access one day so I could edit my post any point it time |
Maybe someday
As far as editing, i believe you can edit within 10 minutes (not positive, 'cause i don't have the time limit )
If it is longer than the time limit and you want something changed, post this in the topic and someone will be able to make the change for you. |
|
Back to top |
|
|
bbharathiraj Warnings : 1 New User
Joined: 26 Oct 2006 Posts: 50 Location: Chennai
|
|
|
|
Thanks Pandora!. its working |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Glad its working |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
Nice work, Pandora-Box |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Thanks Marso |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Pandora-Box,
though late, let me add my 'good job'!
worth much more than the question deserved. |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
I am striving hard for more such good jobs :-) Hope i would be consistent :-) |
|
Back to top |
|
|
|