Home > Archive > Cobol > March 2004 > IF... (imperative) Not Necessarily So
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
IF... (imperative) Not Necessarily So
|
|
| docdwarf@panix.com 2004-03-26, 10:59 pm |
|
Learn something new every day, it seems... and so I post it here to show
everyone how little I actually know.
(note - all compiler references are to IBM mainframe software)
I was taught the syntax of IF (condition) [THEN] (imperative statement)...
and the compiler enforced this fairly well; even the venerable IKFCBL00
would throw a condition code of 12 on
IF FLD1 = ZEROES.
.... and this holds for the IBM Enterprise COBOL for z/OS and OS/390 3.2.0
which I presently use at work; it returns
IGYPS2079-S Expected a verb or "NEXT SENTENCE", but found ". ".
This syntax holds true for those who employ scope-delimiters, as well, as
IF FLD1 = ZEROES
END-IF
.... with or without a period (full stop) following the END-IF generates
IGYPS2079-S Expected a verb or "NEXT SENTENCE", but found "END-IF".
.... as, some might argue, Well It Should Be.
However... I was given a chunk of code to modify, the scenario being that
they no longer wanted records with zeroes in a couple of fields. At first
I was told that if the second field was zeroes the sign-indicator (a
separate alpha field preceding the numeric field... no SIGN LEADING
SEPARATE CHARACTER here!) should be blanked out since the indicator was
initialised to '+' in another section. The output records were stored in
a WORKING STORAGE table and the code started out as:
PERFORM 9798-WRITE-DETREC THRU 9798-EX
VARYING SUB03 FROM 1 BY 1
UNTIL SUB03 > 14.
....
9798-WRITE-DETREC.
*
WRITE OUT-REC FROM WK-REC (SUB03).
ADD 1 TO OUT-COUNT.
*
9798-EX.
EXIT.
So... I coded the following:
9798-WRITE-DETREC.
*
IF (WK-FLD1 (SUB03) = ZEROES)
IF (WK-FLD2 (SUB03) = ZEROES)
GO TO 9798-EX
END-IF
MOVE SPACES TO WK-FLD2-SIGN (SUB03)
END-IF.
*
WRITE OUT-REC FROM WK-REC (SUB03).
ADD 1 TO OUT-COUNT.
*
9798-EX.
EXIT.
.... and ran the job and submitted the test-results for examination. I
then received the classic 'I know that's what we told you but it's not
what we want...'; seems that they wanted the second '+' back again because
it made it easier to eyeball the unformatted data... but I've been burned
by 'Take it out... put it back... now take it out again' before so I
changed a single character to make it:
9798-WRITE-DETREC.
*
IF (WK-FLD1 (SUB03) = ZEROES)
IF (WK-FLD2 (SUB03) = ZEROES)
GO TO 9798-EX
END-IF
* MOVE SPACES TO WK-FLD2-SIGN (SUB03)
END-IF.
*
WRITE OUT-REC FROM WK-REC (SUB03).
ADD 1 TO OUT-COUNT.
*
9798-EX.
EXIT.
Now... as I read the above the the GO TO is predicated upon a second-level
conditional... but there is *nothing* predicated on the first.
And yet... it compiles and runs and does just what I want.
DD
| |
| William M. Klein 2004-03-26, 10:59 pm |
| Your nested IF ... END-IF *is* an imperative statement (scope terminated
conditional statement) and as such THAT is the "action" taken by your outermost
IF. This is just the same as:
IF A = "A"
Add 1 to X
On size error
Display "here"
End-Add
End-If
or (using another scope terminated conditional)
IF A = "A"
Evaluate X
When "Y"
Display "HERE"
End-Evaluate
End-IF
--
Bill Klein
wmklein <at> ix.netcom.com
<docdwarf@panix.com> wrote in message news:c27n36$h00$1@panix5.panix.com...
>
> Learn something new every day, it seems... and so I post it here to show
> everyone how little I actually know.
>
> (note - all compiler references are to IBM mainframe software)
>
> I was taught the syntax of IF (condition) [THEN] (imperative statement)...
> and the compiler enforced this fairly well; even the venerable IKFCBL00
> would throw a condition code of 12 on
>
> IF FLD1 = ZEROES.
>
> ... and this holds for the IBM Enterprise COBOL for z/OS and OS/390 3.2.0
> which I presently use at work; it returns
>
> IGYPS2079-S Expected a verb or "NEXT SENTENCE", but found ". ".
>
> This syntax holds true for those who employ scope-delimiters, as well, as
>
> IF FLD1 = ZEROES
> END-IF
>
> ... with or without a period (full stop) following the END-IF generates
>
> IGYPS2079-S Expected a verb or "NEXT SENTENCE", but found "END-IF".
>
> ... as, some might argue, Well It Should Be.
>
> However... I was given a chunk of code to modify, the scenario being that
> they no longer wanted records with zeroes in a couple of fields. At first
> I was told that if the second field was zeroes the sign-indicator (a
> separate alpha field preceding the numeric field... no SIGN LEADING
> SEPARATE CHARACTER here!) should be blanked out since the indicator was
> initialised to '+' in another section. The output records were stored in
> a WORKING STORAGE table and the code started out as:
>
> PERFORM 9798-WRITE-DETREC THRU 9798-EX
> VARYING SUB03 FROM 1 BY 1
> UNTIL SUB03 > 14.
> ...
>
> 9798-WRITE-DETREC.
> *
> WRITE OUT-REC FROM WK-REC (SUB03).
> ADD 1 TO OUT-COUNT.
> *
> 9798-EX.
> EXIT.
>
> So... I coded the following:
>
> 9798-WRITE-DETREC.
> *
> IF (WK-FLD1 (SUB03) = ZEROES)
> IF (WK-FLD2 (SUB03) = ZEROES)
> GO TO 9798-EX
> END-IF
> MOVE SPACES TO WK-FLD2-SIGN (SUB03)
> END-IF.
> *
> WRITE OUT-REC FROM WK-REC (SUB03).
> ADD 1 TO OUT-COUNT.
> *
> 9798-EX.
> EXIT.
>
> ... and ran the job and submitted the test-results for examination. I
> then received the classic 'I know that's what we told you but it's not
> what we want...'; seems that they wanted the second '+' back again because
> it made it easier to eyeball the unformatted data... but I've been burned
> by 'Take it out... put it back... now take it out again' before so I
> changed a single character to make it:
>
> 9798-WRITE-DETREC.
> *
> IF (WK-FLD1 (SUB03) = ZEROES)
> IF (WK-FLD2 (SUB03) = ZEROES)
> GO TO 9798-EX
> END-IF
> * MOVE SPACES TO WK-FLD2-SIGN (SUB03)
> END-IF.
> *
> WRITE OUT-REC FROM WK-REC (SUB03).
> ADD 1 TO OUT-COUNT.
> *
> 9798-EX.
> EXIT.
>
> Now... as I read the above the the GO TO is predicated upon a second-level
> conditional... but there is *nothing* predicated on the first.
>
> And yet... it compiles and runs and does just what I want.
>
> DD
| |
| docdwarf@panix.com 2004-03-26, 10:59 pm |
| In article <dAK1c.19044$yZ1.7876@newsread2.news.pas.earthlink.net>,
William M. Klein <wmklein@nospam.netcom.com> wrote:
>Your nested IF ... END-IF *is* an imperative statement (scope terminated
>conditional statement) and as such THAT is the "action" taken by your outermost
>IF.
I know that an inner IF is predicated by the outer, Mr Klein... what I
find unusual is that the inner IF has no associated imperative. It is as
though I wrote:
IF COND-1
IF COND-2
END-IF
DISPLAY 'COND-1'
END-IF
> This is just the same as:
>
> IF A = "A"
> Add 1 to X
> On size error
> Display "here"
> End-Add
> End-If
Not as I read it... my code is analagous to
If A = 'A'
Add 1 to X
On size error
End-Add
End-If
>
>or (using another scope terminated conditional)
>
> IF A = "A"
> Evaluate X
> When "Y"
> Display "HERE"
> End-Evaluate
>End-IF
Likewise, no... in my code the 'MOVE SPACES' is commented out (sorry for
not having made that more clear) so in this case it would be:
If A = 'A'
Evaluate X
When 'Y'
End-Evaluate
End-If
DD
><docdwarf@panix.com> wrote in message news:c27n36$h00$1@panix5.panix.com...
>
>
| |
| Howard Brazee 2004-03-26, 10:59 pm |
|
On 4-Mar-2004, docdwarf@panix.com wrote:
> IF (WK-FLD1 (SUB03) = ZEROES)
> IF (WK-FLD2 (SUB03) = ZEROES)
> GO TO 9798-EX
> END-IF
> * MOVE SPACES TO WK-FLD2-SIGN (SUB03)
> END-IF.
> *
> WRITE OUT-REC FROM WK-REC (SUB03).
> ADD 1 TO OUT-COUNT.
> *
> 9798-EX.
> EXIT.
>
> Now... as I read the above the the GO TO is predicated upon a second-level
> conditional... but there is *nothing* predicated on the first.
>
> And yet... it compiles and runs and does just what I want.
I really don't understand your post. The internal IF statement is predicated
by the external IF statement.
Am I missing something from your question? What I'm getting is very basic -
which is not the type of question I would expect from you.
| |
| William M. Klein 2004-03-26, 10:59 pm |
| In
IF (WK-FLD1 (SUB03) = ZEROES)
IF (WK-FLD2 (SUB03) = ZEROES)
GO TO 9798-EX
END-IF
> * MOVE SPACES TO WK-FLD2-SIGN (SUB03)
END-IF.
Why don't you think your
GO TO 9798-EX
is a "perfectly" valid is an "associated imperative" for the innermost IF?
What am I missing?
--
Bill Klein
wmklein <at> ix.netcom.com
<docdwarf@panix.com> wrote in message news:c27tc7$2dk$1@panix5.panix.com...
> In article <dAK1c.19044$yZ1.7876@newsread2.news.pas.earthlink.net>,
> William M. Klein <wmklein@nospam.netcom.com> wrote:
outermost[color=darkred]
>
> I know that an inner IF is predicated by the outer, Mr Klein... what I
> find unusual is that the inner IF has no associated imperative. It is as
> though I wrote:
>
> IF COND-1
> IF COND-2
> END-IF
> DISPLAY 'COND-1'
> END-IF
>
>
> Not as I read it... my code is analagous to
>
> If A = 'A'
> Add 1 to X
> On size error
> End-Add
> End-If
>
>
> Likewise, no... in my code the 'MOVE SPACES' is commented out (sorry for
> not having made that more clear) so in this case it would be:
>
> If A = 'A'
> Evaluate X
> When 'Y'
> End-Evaluate
> End-If
>
> DD
>
>
>
| |
| Howard Brazee 2004-03-26, 10:59 pm |
|
On 4-Mar-2004, docdwarf@panix.com wrote:
> I know that an inner IF is predicated by the outer, Mr Klein... what I
> find unusual is that the inner IF has no associated imperative. It is as
> though I wrote:
>
> IF COND-1
> IF COND-2
> END-IF
> DISPLAY 'COND-1'
> END-IF
How so? I see the inner IF has GO TO 9798-EX as its associated imperative.
[color=darkred]
| |
| docdwarf@panix.com 2004-03-26, 10:59 pm |
| In article <c27tse$8ig$1@peabody.colorado.edu>,
Howard Brazee <howard@brazee.net> wrote:
>
>On 4-Mar-2004, docdwarf@panix.com wrote:
>
>
>How so? I see the inner IF has GO TO 9798-EX as its associated imperative.
My error and apologies to all... this is correct, I misremembered my own
posting.
DD
| |
| docdwarf@panix.com 2004-03-26, 10:59 pm |
| In article <F_K1c.19074$yZ1.18995@newsread2.news.pas.earthlink.net>,
William M. Klein <wmklein@nospam.netcom.com> wrote:
>In
>
> IF (WK-FLD1 (SUB03) = ZEROES)
> IF (WK-FLD2 (SUB03) = ZEROES)
> GO TO 9798-EX
> END-IF
> END-IF.
>
>
>Why don't you think your
>
> GO TO 9798-EX
>
>is a "perfectly" valid is an "associated imperative" for the innermost IF?
>What am I missing?
As noted in my posting to Mr Brazee... my error and apologies, I
misremembered my own posting.
DD
| |
| docdwarf@panix.com 2004-03-26, 10:59 pm |
| In article <c27tod$86m$1@peabody.colorado.edu>,
Howard Brazee <howard@brazee.net> wrote:
>
>On 4-Mar-2004, docdwarf@panix.com wrote:
>
>
>I really don't understand your post. The internal IF statement is predicated
>by the external IF statement.
This is what Mr Klein pointed out... and in my confusion over these
newfangled scope delimiters - barely twenty years old, they are! - I did
not notice that what caught my eye was the equivalent of
IF COND-1
IF COND-2
(imperative).
>
>Am I missing something from your question? What I'm getting is very basic -
>which is not the type of question I would expect from you.
Quite obviously *I* was missing something... but this is a reason to have
others look over one's work.
Thanks much!
DD
| |
| Howard Brazee 2004-03-26, 10:59 pm |
|
On 4-Mar-2004, docdwarf@panix.com wrote:
> Quite obviously *I* was missing something... but this is a reason to have
> others look over one's work.
It's amazing what I've overlooked missing what should have been no-brainers.
| |
| docdwarf@panix.com 2004-03-26, 10:59 pm |
| In article <c282q7$ojc$1@peabody.colorado.edu>,
Howard Brazee <howard@brazee.net> wrote:
>
>On 4-Mar-2004, docdwarf@panix.com wrote:
>
>
>It's amazing what I've overlooked missing what should have been no-brainers.
I recall reading, somelace, that the most common sounds a programmer makes
is a sort of strangled groan of frustration followed by a laugh... a kind
of 'gaaaAHHHHH... ha ha ha ha ha!
DD
| |
|
| docdwarf@panix.com wrote:
> 9798-WRITE-DETREC.
> *
> IF (WK-FLD1 (SUB03) = ZEROES)
> IF (WK-FLD2 (SUB03) = ZEROES)
> GO TO 9798-EX
> END-IF
> * MOVE SPACES TO WK-FLD2-SIGN (SUB03)
> END-IF.
> *
> WRITE OUT-REC FROM WK-REC (SUB03).
> ADD 1 TO OUT-COUNT.
> *
> 9798-EX.
> EXIT.
>
> Now... as I read the above the the GO TO is predicated upon a second-level
> conditional... but there is *nothing* predicated on the first.
>
> And yet... it compiles and runs and does just what I want.
Nothing wrong with that at all... There is at lease -one- imperative
within that. You could have just as easily said
IF (WK-FLD1 (SUB03) = ZEROES)
AND (WK-FLD2 (SUB03) = ZEROES)
GO TO 9798-EX
END-IF.
I've seen that many times in code at my job... People add conditions,
and don't stop to think that they could "And" them together. It looks
something like
IF EQPP-TYPE = 'A'
IF EQPP-SRD (1:1) = 'X'
IF SRD-MDS = ' F0119011'
MOVE 58 TO REJCDE
GO TO TRANS-END.
Technically, there are no imperatives on the first 2, but as you've
seen, it works. :)
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
~ / \ / ~ Live from Montgomery, AL! ~
~ / \/ o ~ ~
~ / /\ - | ~ LXi0007@Netscape.net ~
~ _____ / \ | ~ http://www.knology.net/~mopsmom/daniel ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~ I do not read e-mail at the above address ~
~ Please see website if you wish to contact me privately ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|