IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Infinite loop Issue in perform Until


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
shankarm

Active User


Joined: 17 May 2010
Posts: 175
Location: India

PostPosted: Wed Jul 31, 2013 7:53 pm
Reply with quote

Hello,

In the below code,
the value of D-CNTR is zero. The below code gets into indifinite loop, i dont understand why? Please help.

It should not go into the loop correct? since WS-CNTR (Value '1') is greater than D-CNTR ( valur '0')?

Code:

05 D-CNTR                           PIC 9(04) COMP.
05 WS-CNTR                          PIC 9(08) VALUE ZEROES.

PERFORM VARYING WS-CNTR FROM 1 BY 1 UNTIL
     WS-CNTR > D-CNTR                   
.
.
.
End-perform.
Back to top
View user's profile Send private message
Ed Goodman

Active Member


Joined: 08 Jun 2011
Posts: 556
Location: USA

PostPosted: Wed Jul 31, 2013 7:59 pm
Reply with quote

I agree that it SHOULD behave like you expect. That leaves the possibility that the value in D-CNTR really isn't zero.

Without trying it myself for fun, I can't even remember if the loop would execute even once.
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Wed Jul 31, 2013 8:06 pm
Reply with quote

Does it not depend on what the default is (WITH TEST BEFORE or AFTER). With AFTER it will execute once.
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Wed Jul 31, 2013 8:07 pm
Reply with quote

Regardless of the value in D-CNTR, it should not go to infinite loop.
Maximum value that can be stored in 9(4) COMP is 32767. It should loop for those many times and exit.

That leaves for one possibility. Are you manipulating the counters inside perform? Can you cut and paste your exact code?
Back to top
View user's profile Send private message
Ed Goodman

Active Member


Joined: 08 Jun 2011
Posts: 556
Location: USA

PostPosted: Wed Jul 31, 2013 8:10 pm
Reply with quote

I agree that it SHOULD behave like you expect. That leaves the possibility that the value in D-CNTR really isn't zero.

Without trying it myself for fun, I can't even remember if the loop would execute even once.

I would add a display on that D-CNTR field just to sure it's really zero.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Jul 31, 2013 8:15 pm
Reply with quote

Nic, yes, it does depend. Default is BEFORE, so should not execute even once if termination condition is satisfied.

agkshirsagar, how many times it should go through the loop will depending on the compiler option TRUNC. The field is unsigned, so the maximum if treated as COMP-5, that is, with TRUNC(BIN), is 65,535. If TRUNC(STD) or TRUNC(OPT) the maximum is 9999. However, for this purpose, the results should be the same - no loop.

shankarm, you do need to show the rest of your code inside the PERFORM. That is likely where the problem is. Other things are possible, but check the most likely first.
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Wed Jul 31, 2013 8:15 pm
Reply with quote

Hi,

I tested Code with what you have mentioned.

Its not going in loop for me

It will be great if show us whoile piece of code

How about displaying D-CNTR before loop starts?

Regards,
Chandan
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Jul 31, 2013 10:08 pm
Reply with quote

Hello,

Quote:
In the below code,
the value of D-CNTR is zero.
I don't think so . . .
The field is uninitialized and may contain anything . . .

Something else may be modifying WS-CNTR or D-CNTR causing the loop. . .
Back to top
View user's profile Send private message
shankarm

Active User


Joined: 17 May 2010
Posts: 175
Location: India

PostPosted: Wed Jul 31, 2013 10:39 pm
Reply with quote

Code:



PERFORM VARYING WS-CNTR FROM 1 BY 1 UNTIL             
     WS-CNTR > D-CNTR                                 
  MOVE 'N' TO RPT-FLAG                               
  MOVE SPACES                 TO SING-NME             
  MOVE HD-D-FILG-NME(WS-CNTR) TO SING-NME             
  MOVE +120                   TO SING-LENGTH         
  CALL 'TRDSNGLE'          USING SING-NME, SING-LENGTH
  MOVE SPACES                 TO WS-DEF-NME           
  MOVE SING-NME               TO WS-DEF-NME           
                                                     
  IF WS-CNTR <= D-CNTR                               
   PERFORM VARYING RPT-CNTR FROM 1 BY 1 UNTIL         
     RPT-CNTR = DEF-CNTR OR  RPT-FLAG = 'Y'           
     IF WS-DEF-NME EQUAL TO MSD-FILG-NME(RPT-CNTR)   
        MOVE 'Y' TO RPT-FLAG                         
     END-IF                                           
   END-PERFORM                                       
  END-IF                                             
                                                   
  IF RPT-FLAG EQUAL TO 'N'                         
     ADD 1 TO MDEF-CNTR                             
     MOVE WS-DEF-NME TO MSD-FILG-NME(MDEF-CNTR)     
     MOVE HD-D-STR-ADR(WS-CNTR)  TO                 
                   MSD-FILG-STR-ADR(MDEF-CNTR)     
     MOVE HD-D-CITY-NME(WS-CNTR) TO                 
                   MSD-FILG-CITY-NME(MDEF-CNTR)     
     MOVE HD-D-ST-NME(WS-CNTR)   TO                 
                   MSD-FILG-ST-NME(MDEF-CNTR)       
     MOVE HD-D-POST-CD(WS-CNTR)  TO                 
                   MSD-FILG-POST-CD(MDEF-CNTR)     
     MOVE WS-CAUSE-CD   TO MSU-CAUSE-CD(MDEF-CNTR) 
     MOVE WS-CAUSE-DESC TO MSU-CAUSE-DESC(MDEF-CNTR)
     IF DEF-CNTR <= 14                                     
       MOVE WS-DEF-NME             TO SD-FILG-NME(DEF-CNTR)
       MOVE HD-D-STR-ADR(WS-CNTR)  TO                     
                               SD-FILG-STR-ADR(DEF-CNTR)   
       MOVE HD-D-CITY-NME(WS-CNTR) TO                     
                               SD-FILG-CITY-NME(DEF-CNTR) 
       MOVE HD-D-ST-NME(WS-CNTR)   TO                     
                               SD-FILG-ST-NME(DEF-CNTR)   
       MOVE HD-D-POST-CD(WS-CNTR)  TO                     
                               SD-FILG-POST-CD(DEF-CNTR)   
       MOVE WS-CAUSE-CD   TO SU-CAUSE-CD(DEF-CNTR)         
       MOVE WS-CAUSE-DESC TO SU-CAUSE-DESC(DEF-CNTR)       
       ADD 1 TO DEF-CNTR                                   
     END-IF                                               
  ELSE                                                   
    MOVE WS-DEF-NME             TO  WS-ERR-VAL           
    MOVE SPACES                 TO  WS-FILING-LOC       
    MOVE WS-COMM-KEY            TO  WS-FILING-NUM       
    MOVE '10'                   TO  ERR-TYP             
    ADD   1                     TO  WS-COUNTF10, WS-SUM-F
    ADD   1                     TO  ERR-CNTR             
    MOVE '10'                   TO  WS-ERR-VALUE         
    MOVE SPACES                 TO  WS-INPUT             
    MOVE HD-D-FULLREC(WS-CNTR)  TO  WS-INPUT             
    WRITE ERROR-REC             FROM WS-ERROUT-REC       
    PERFORM 0460-FL-ERR-PARA THRU                       
            0460-FL-ERR-PARA-EXIT                       
  END-IF                                                 
END-PERFORM.                                             
0460-FL-ERR-PARA.                                               
                                                                 
    MOVE 'F'            TO WS-ERR-TYPE                           
    EVALUATE ERR-TYP                                             
      WHEN '8'  MOVE 'INVALID CAUSE OF ACTION ' TO  WS-ERR-MSG   
                MOVE WS-PNUM                    TO  WS-FILING-LOC
      WHEN '10' MOVE 'EXACT DUPLICATE         ' TO  WS-ERR-MSG   
                MOVE WS-PNUM                    TO  WS-FILING-LOC
      WHEN OTHER                                                 
            MOVE SPACES                         TO  WS-ERR-MSG   
    END-EVALUATE.                                               
    PERFORM 0490-SEARCH-ERR-TBL THRU                             
            0490-SEARCH-ERR-TBL-EXIT.                           
                                                                 
0460-FL-ERR-PARA-EXIT.                                           
     EXIT.         
Back to top
View user's profile Send private message
shankarm

Active User


Joined: 17 May 2010
Posts: 175
Location: India

PostPosted: Wed Jul 31, 2013 10:42 pm
Reply with quote

I gave display outside the loop for D-cntr and inside the loop for WS-CNTR

Output:
Code:

D-CNTR0000     
WS-CNTR00000001
WS-CNTR00000002
WS-CNTR00000003
WS-CNTR00000004
WS-CNTR00000005
WS-CNTR00000006
WS-CNTR00000007
WS-CNTR00000008
WS-CNTR00000009
WS-CNTR00000010
.
.
.
.
.
.

And gives a S0c4..
Back to top
View user's profile Send private message
shankarm

Active User


Joined: 17 May 2010
Posts: 175
Location: India

PostPosted: Wed Jul 31, 2013 10:43 pm
Reply with quote

TRDSNGLE is not editing D-cntr..
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Jul 31, 2013 11:07 pm
Reply with quote

You need to show the definitions, as what you have shown so far has "05" levels, and we need to see everything that is part of the 01(s) that those fields are part of.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Aug 01, 2013 12:10 am
Reply with quote

Code:
    PERFORM 0490-SEARCH-ERR-TBL THRU                             
            0490-SEARCH-ERR-TBL-EXIT.   


This we need to see.

Also show where you put the DISPLAYs?
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Aug 01, 2013 12:31 am
Reply with quote

It looks like you have compiler option TRUNC(STD) or TRUNC(OPT). Can you confirm which, please?

TRUNC(OPT) I'd guess. Can you

Code:
05  D-X REDEFINES D-CNTR PIC XX.


And

Code:
DISPLAY
        ">"
        D-X
        "<"

At the same time as your DISPLAY of D-CNTR.

Use SET HEX ON and paste the result of the new DISPLAY.

Is this some of the "old" code you support, or something you've written yourself?
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Thu Aug 01, 2013 7:16 pm
Reply with quote

Getting a S0C4 is not the same as infinite loop. Which one it is?
If you printed the value before the perform loop and D-CNTR was zero, it should have never entered in the loop.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Aug 01, 2013 8:02 pm
Reply with quote

agkshirsagar wrote:
Getting a S0C4 is not the same as infinite loop. Which one it is?
If you printed the value before the perform loop and D-CNTR was zero, it should have never entered in the loop.


Those two things are what make it interesting :-)
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1306
Location: Vilnius, Lithuania

PostPosted: Thu Aug 01, 2013 9:39 pm
Reply with quote

Load the program in Debug Tool (or Xpediter), add a breakpoint on any changes of key variables and run it.

Use the flucking tools that are made to debug code, don't waste time fluffing around on forums giving information in piecemeal snippets.
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 765
Location: Whitby, ON, Canada

PostPosted: Thu Aug 01, 2013 10:22 pm
Reply with quote

prino wrote:
Load the program in Debug Tool (or Xpediter), add a breakpoint on any changes of key variables and run it.

Use the flucking tools that are made to debug code, don't waste time fluffing around on forums giving information in piecemeal snippets.
I like to tell people "Don't waste time speculating on what the code might be doing, or what it ought to be doing. Find out what it is really doing".
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Aug 01, 2013 10:53 pm
Reply with quote

Already adding code has changed the symptoms (apparently).

Re-compiling it for debugging may cause it to "work" :-)

For anyone who wants to know what it is doing, it is getting into the PERFORM when - on the face of it - it shouldn't.

Given that, it becomes "easy", with al the information. Which we lack.

shankarm is not so hot on the "feedback" througjh past expeience. He perhaps already has his solution.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
This topic is locked: you cannot edit posts or make replies. REXX - Do - Not able to LOOP CLIST & REXX 10
No new posts Use of Perform Thru Exit COBOL Programming 6
No new posts Issue after ISPF copy to Linklist Lib... TSO/ISPF 1
No new posts Facing ABM3 issue! CICS 3
Search our Forums:

Back to Top