Re: Code Clarity - Comments Invited
- From: docdwarf@xxxxxxxxx ()
- Date: Mon, 11 Dec 2006 18:34:44 +0000 (UTC)
In article <4phjn294rb5et2vq9o06kn5o6v31s4t028@xxxxxxx>,
Ron <ron@xxxxxxxxxxxxx> wrote:
docdwarf@xxxxxxxxx () wrote:
I'm interested in observations from the less-experienced programmers here;
perhaps The Oldsters might allow them their say before jumping in with the
usual chorus of 'Oh, that's obvious' and 'Why didn't you...?'.
It's been over a full day since the posting. Has that been
enough holding back?
Well, the weekend has now passed, at least in this part of the world and
using the calendar with which many folks are familiar... so it seems time
to roll onwards.
--snip of the program code--
The question is... what condition has been found?
Looks like you're checking that you have a left-justified
string with no embedded spaces.
This is my intention, yes.
A completely blank string
will also pass this test. A string that completely fills
the data area is a bad thing. The reference modifier
in the second inspect statement will point to one byte beyond
the end of the data area. Looks like in that case, it's
one of those "results are unpredictable" categories that
depends on compiler implementation.
Exactly the case... so now it is time for a bit of context.
The code is part of a Big-Time Kerflooie program... and, of course, in
order to understand the Kerflooie it might be best to know what goes on
when things run normally.
Every two weeks four feeder-systems send us files detailing the Time and
Attendance data for employees... so many regular hours worked, so much
overtime, this many sick leave hours taken, that many unexcused absences,
et and cetera. These records are then edited and reformatted (using
matched data from the Employee Master File) into output which is then sent
to another system for the cutting of paychecks (or creating of
direct-deposit transmissions).
Someone said 'All right... what happens if there is a Catastrophic event,
fire, flood, bomb, earthquake or the like, and we are unable to transmit
the T&A data to you... can you do something to generate check-cutting
data?' Someone in a corner office said 'Sure, no problem, just give us the
Social Security Numbers of the employees involved'... and the situation
then rolled downhill until it landed in my lap.
I looked at the Employee Master File (an indexed file, VSAM KSDS); in
addition to the employee's Social Security Number there is an Organisation
number (a PIC X(07), not the X(50) in my example) - the 'department' to
which an employee is assigned - and the default work-schedule for the last
time an employee had a work-schedule entered (in a table, 9(2)V99, OCCURS
14, with each occurrence containing the number of hours to be worked on a
given day). (Pay is processed every other week) I said 'If you can tell
me the list of SSNs that need to be paid or give me a list of
Organisations which need to be paid I can read through the Master and
generate output for at least the 'regular schedule'... things like leave
and overtime and the like will have to be dealt with later but at least
everyone will get a 'normal' check.'
That was fine... until some months (about 16) later someone in another
corner office said 'Well, there are primary and subordinate Organisations;
Org FYA has sub-Orgs FYA1, FYA2, FYA31, etc. Rather than giving you a
list of all the subordinate Orgs is there some way you can generate pay
based only on the primary?'
(Oh... did I mention that in the event of Catastrophe the list of
SSNs/Orgs would be fed to the program in a file that will be entered by
hand in a TSO Edit session? No online edits, just a bunch of... stuff.)
So... I already had a program which would read the file of To Be Paid into
a WORKING-STORAGE table and based on a JCL PARM would direct processing to
deal with SSN input or Org input. SSN input was the easier since the
Employee Master has an SSN key; for Org input I would process the Master
sequentially... read a rec, SEARCH the WS table, match/not match and so
on. Now I had to change things to deal with partials.
First... another PARM, for Org processing there'd be a 'P' for that, 88'd
to . Then the table-load routine would get changed... and here's where
the editing began. After the table is loaded (up to 5,000 entries) if Org
processing is requested I make a pass through it in the following manner:
(now the code is cut-n-pasted... pardon the caps, it is the Shop Style)
* *
*** CANCEL RUN IF BAD RECS - ORGS W/ LEADING OR EMBEDDED SPACE
* *
PERFORM VARYING SUB02 FROM 1 BY 1
UNTIL SUB02 > ORG-CTR
IF WS-ORG (SUB02)(1:1) = SPACES OR LOW-VALUES
DISPLAY ' ***********************************'
DISPLAY ' *** PROGRAM EMERGPAY ERROR ********'
DISPLAY ' *** INPUT ORG ' WS-ORG (SUB02)
' HAS *********'
DISPLAY ' *** LEADING SPACE(S) **************'
DISPLAY ' *** PROGRAM ABORTING *************'
DISPLAY ' ***********************************'
MOVE 888 TO RETURN-CODE
PERFORM 9999-EOJ
END-IF
MOVE 0 TO SPACE-TALLY, CHAR-TALLY
INSPECT WS-ORG (SUB02) TALLYING CHAR-TALLY
FOR CHARACTERS BEFORE INITIAL SPACE
IF CHAR-TALLY < LENGTH OF WS-ORG (SUB02)
INSPECT WS-ORG (SUB02)((CHAR-TALLY + 1):)
TALLYING SPACE-TALLY FOR ALL SPACES
IF LENGTH OF WS-ORG (SUB02) =
(CHAR-TALLY + SPACE-TALLY)
CONTINUE
ELSE
DISPLAY ' **********************************'
DISPLAY ' *** PROGRAM EMERGPAY ERROR *******'
DISPLAY ' *** INPUT ORG ' WS-ORG (SUB02)
' HAS ********'
DISPLAY ' *** EMBEDDED SPACE(S) ************'
DISPLAY ' *** PROGRAM ABORTING ************'
DISPLAY ' **********************************'
MOVE 889 TO RETURN-CODE
PERFORM 9999-EOJ
END-IF
END-IF
END-PERFORM.
.... and this code, I believe, would deal with an all-space entry and not
bother with the second INSPECT for spaces in the event of a
completely-filled Org.
Finally...
5100-ORG-PROCESS.
*
*** INPUT FILE CONSISTS OF ORGANIZATION NUMBERS. READ EMPMAST
*** SEQUENTIALLY AND CREATE RECS FOR ALL SSNS FOR ORG.
*
*
READ EMPFILE NEXT INTO MER-RECORD
AT END
SET NO-MORE-EMP TO TRUE
NOT AT END
MOVE EMP-SSN TO WS-RESTART-SSN
*
*** DEFAULT TO USING LENGTH OF ENTIRE FIELD (EXACT MATCH)
*
MOVE LENGTH OF WS-ORG (1) TO TALLY
*
PERFORM VARYING SUB02 FROM 1 BY 1
UNTIL SUB02 > ORG-CTR
*
*** FOR PARTIAL PROCESSING MATCH ON PARTIAL FIELD
*
IF PROCESS-PARTIAL-ORGS
MOVE 0 TO TALLY
INSPECT WS-ORG (SUB02) TALLYING TALLY
FOR CHARACTERS BEFORE INITIAL SPACE
END-IF
*
IF EMP-ORG(1:TALLY) = WS-ORG (SUB02)(1:TALLY)
PERFORM 5300-CREATE-OUTPUT
END-IF
END-PERFORM
END-READ.
Now... I understand full well that when there's a Catastrophic Failure a
company would be ill-advised to let the more junior personnel deal with
the processing for such an emergency... but I thought I'd seek the
comments of such folks, just to have a few more sets of eyes.
Please be so kind as to pardon my wordiness and kludgy code, and thanks to
all for their patience and participation.
DD
.
- Follow-Ups:
- Re: Code Clarity - Comments Invited
- From: Oliver Wong
- Re: Code Clarity - Comments Invited
- References:
- Prev by Date: Re: Code Clarity - Comments Invited
- Next by Date: IBM and COBOL SEARCH ALL
- Previous by thread: Re: Code Clarity - Comments Invited
- Next by thread: Re: Code Clarity - Comments Invited
- Index(es):
Relevant Pages
|