guster47
guster47

Reputation: 71

CICS statements in the body of an IF statement

Good afternoon, I am analyzing some legacy code in COBOL and have found this case specific case that I can't wrap my head around.

000610     IF EIBCALEN = 0                                              00061011
000700     EXEC CICS                                                    00070000
000800          SEND MAP('TCHM144')                                     00080007
001100     END-EXEC.                                                    00110000
001110     ELSE                                                         00111013
001111        IF EIBAID = DFHCLEAR OR DFHPF2 OR DFHPF3                  00111113
001112        EXEC CICS SEND FROM(WS-CHAR)                              00111213
001113                       LENGTH(LENGTH OF WS-CHAR)                  00111313
001114                       ERASE                                      00111413
001115                       END-EXEC.                                  00111513
001116        EXEC CICS RETURN END-EXEC.                                00111613
001120*         MAPONLY ERASE FREEKB                                    00112002
001200     EXEC CICS                                                    00120000
001300          RETURN TRANSID('TCE4')                                  00130000
001400     END-EXEC.                                                    00140000
001500     GOBACK.                                                      00150012

From what I recall having a period in the body of the IF statement closes the sentence up to the IF at the highest level but, in this case the END-EXEC contained in the IF's body is followed by a period which, following the above mentioned logic would close the sentence and the ELSE would not be referred to any IF. Am I correct or is there a specific case where this would work? Thank you.

Upvotes: 3

Views: 293

Answers (3)

Rick Smith
Rick Smith

Reputation: 4407

The entire EXEC statement through the ending separator period will be replaced by code. This is similar to what happens with COPY statements. In the following, both COPY statements copy text containing a simple add instruction with no separator periods. During preprocessing, the COPY statements are replaced with the text. The same occurs with EXEC statements. As long as the EXEC statement does not introduce any separator periods, the rules for COBOL concerning the ending of a sentence do not apply.

As @cschneid suggests, look at the listing to see what was done with that source code.

Following is an example with COPY statements. Notice that the separator periods have no effect on compilation.


Source:

   data division.
   working-storage section.
   1 a pic 9 value 0.
   1 b pic 9 value 0.
   procedure division.
   begin.
       display 'A: ' a
       display 'B: ' b
       if a = b
           copy a.
       else
           copy b.
       end-if
       display 'A: ' a
       display 'B: ' b
       stop run
       .

List:

     1 data division.
     2 working-storage section.
     3 1 a pic 9 value 0.
     4 1 b pic 9 value 0.
     5 procedure division.
     6 begin.
     7     display 'A: ' a
     8     display 'B: ' b
     9     if a = b
*   10         copy a.
    11         add 1 to a
    12     else
*   13         copy b.
    14         add 1 to b
    15     end-if
    16     display 'A: ' a
    17     display 'B: ' b
    18     stop run
    19     .

Output:

A: 0
B: 0
A: 1
B: 0

Upvotes: 4

cschneid
cschneid

Reputation: 10765

Look at the compile listing to be certain what was done with that particular version and release of the compiler and CICS translator at the time compilation was done.

The introduction of integrated translators made for some interesting edge cases.

Upvotes: 2

George
George

Reputation: 1

You are correct, the period terminates the IF and the code as written would not compile cleanly so I doubt this code as written is actually being used. =000033==> IGYPS2011-E An "ELSE" did not have a matching "IF". The "ELSE" was discarded.

Upvotes: -3

Related Questions