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

COBOL Infinite loops


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

New User


Joined: 24 Jul 2024
Posts: 4
Location: India

PostPosted: Tue Mar 11, 2025 1:27 pm
Reply with quote

Wrote a Cobol code where i am copying some specific fields with variable length from 2 files having same data, one flat and one ksds, the data from flat file is the parent record and ksds has child records to form a chain (chain can be of multiple child records), though the code is working fine with the test data, ran into a infinity loop issue when i found that a few of the parent's child data is the parent data again (i.e., A (parent) -- B (Child) -- A (parent)), this is causing the code to run in loops for a long time. Is there any way to avoid reading that record? Please suggest something

To help understand the chain:
What is required,
aa -- bb -- cc -- 0
aa -- bb -- 0
aa -- bb -- cc -- dd -- 0 (till a specific field that i need has zeroes or spaces as value)

What i am stuck at some record, and need to avoid this
aa -- bb -- aa -- bb -- aa -- bb -- aa....... and so on i a infinite loop
Back to top
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1207
Location: Dublin, Ireland

PostPosted: Tue Mar 11, 2025 5:19 pm
Reply with quote

Your description is unclear and you've missed out clairvoyant day.

You don't explain how the relationship between 'parent' and 'child' is determined between the flat file and the ksds or how a 'child' becomes a 'parent', nor have you shown any of the code that you claim "is working fine with the test data".

Garry
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2191
Location: USA

PostPosted: Tue Mar 11, 2025 7:34 pm
Reply with quote

07wickedwizard wrote:
Wrote a Cobol code where i ...


If you already HAVE wrote a code, then please, present it here (using the Code tags/button).

If you are only GOING to write a code, then please, provide a clear description of your requirements, and of the algorithm in your mind, for anybody to be able to understand your needs.
Back to top
View user's profile Send private message
07wickedwizard

New User


Joined: 24 Jul 2024
Posts: 4
Location: India

PostPosted: Wed Mar 12, 2025 11:29 am
Reply with quote

sergeyken wrote:
07wickedwizard wrote:
Wrote a Cobol code where i ...


If you already HAVE wrote a code, then please, present it here...


This is the current code
:
R0100-READ-L2BS-FLATFILE SECTION.
*---------------------------------
IF WS-FLAT-IO-OK
READ FLAT
AT END
SET WS-FLAT-EOF TO TRUE
NOT AT END
IF (RCBS-OLD-ACCT = SPACES OR
RCBS-OLD-ACCT = ZEROES)
SET WS-READ-REC-NO TO TRUE
CONTINUE
ELSE
IF (RCBS-OLD-ACCT NOT = SPACES OR
RCBS-OLD-ACCT NOT = ZEROES)
ADD 1 TO WS-CTR
ADD 1 TO WS1-CTR
SET WS-READ-REC-NO TO TRUE
MOVE RCBS-KEY-ACCT TO WS-L2BS-KEY-ACCT(WS-CTR)
MOVE RCBS-KEY-ORG TO WS-L2BS-KEY-ORG
MOVE RCBS-INT-STATUS TO
WS-L2BS-INT-STATUS(WS-CTR)
MOVE RCBS-DATE-LAST-STAT-CHG TO
WS-LAST-STAT-CHG(WS-CTR)
MOVE RCBS-OLD-ORG TO WS-OLD-ORG
MOVE RCBS-OLD-ACCT TO WS-OLD-ACCT
WS1-OLD-ACCT(WS1-CTR)
WS1-OLD-ACCT-IN(WS1-CTR)
PERFORM C2100-READ-L2BS-KSDS
END-IF
END-IF
END-READ
END-IF
IF NOT WS-FLAT-IO-OK
STRING 'ERROR' WS-FLAT-STATUS
' ERROR IN READING THE FLAT FILE'
DELIMITED BY SIZE INTO WS-ERR-TX
END-STRING
END-IF
.
R0100-EXIT.
EXIT.
****************************************************************
* THIS SECTION WILL READ THE KSDS FILE *
****************************************************************
C2100-READ-L2BS-KSDS SECTION.
*-----------------------------
MOVE WS-OLD-ORG TO L2BS-KEY-ORG
MOVE WS-OLD-ACCT TO L2BS-KEY-ACCT
IF NOT WS-KSDS-IO-OK
STRING 'ERROR ' WS-KSDS-STATUS
' ERROR IN READING THE L2BS FILE'
DELIMITED BY SIZE INTO WS-ERR-TX
END-STRING
END-IF
IF WS-KSDS-IO-OK
READ KSDS KEY IS L2BS-KEY
IF (L2BS-OLD-ACCT = SPACES OR
L2BS-OLD-ACCT = ZEROES)
ADD 1 TO WS-CTR
ADD 1 TO WS1-CTR
MOVE L2BS-KEY-ACCT TO WS-L2BS-KEY-ACCT(WS-CTR)
MOVE L2BS-OLD-ACCT TO WS-OLD-ACCT
WS1-OLD-ACCT(WS1-CTR)
MOVE L2BS-OLD-ORG TO WS-OLD-ORG
MOVE L2BS-INT-STATUS TO
WS-L2BS-INT-STATUS(WS-CTR)
MOVE L2BS-DATE-LAST-STAT-CHG TO
WS-LAST-STAT-CHG(WS-CTR)
SET WS-READ-REC-YES TO TRUE
PERFORM W2000-WRITE-DETAIL-RECORD
ELSE
MOVE L2BS-KEY-ORG TO WS-OLD-ORG
ADD 1 TO WS-CTR
ADD 1 TO WS1-CTR
MOVE L2BS-KEY-ACCT TO WS-L2BS-KEY-ACCT(WS-CTR)
MOVE L2BS-OLD-ACCT TO WS-OLD-ACCT
MOVE L2BS-INT-STATUS TO
WS-L2BS-INT-STATUS(WS-CTR)
MOVE L2BS-DATE-LAST-STAT-CHG TO
WS-LAST-STAT-CHG(WS-CTR)
SET WS-READ-REC-NO TO TRUE
GO TO C2100-READ-L2BS-KSDS
END-IF
* END-READ
END-IF
.
C2100-EXIT.
EXIT.
Back to top
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1207
Location: Dublin, Ireland

PostPosted: Wed Mar 12, 2025 1:34 pm
Reply with quote

When presenting code, please use the code tags so that it is readable. As it is, what is presented is incomplete and difficult to read. You don't show, for example, the definition of L2BS-KEY or explain precisely what the relationship between 'parent' and 'child' is.

Garry.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2191
Location: USA

PostPosted: Wed Mar 12, 2025 4:54 pm
Reply with quote

07wickedwizard wrote:
sergeyken wrote:
07wickedwizard wrote:
Wrote a Cobol code where i ...


If you already HAVE wrote a code, then please, present it here...


This is the current code
Code:
:
        R0100-READ-L2BS-FLATFILE SECTION.
      *---------------------------------
           IF WS-FLAT-IO-OK
             READ FLAT
                 AT END
                    SET WS-FLAT-EOF TO TRUE
                 NOT AT END
                  IF (RCBS-OLD-ACCT = SPACES OR
                      RCBS-OLD-ACCT = ZEROES)
                      SET WS-READ-REC-NO TO TRUE
                       CONTINUE
                  ELSE
                    IF (RCBS-OLD-ACCT NOT = SPACES OR
                        RCBS-OLD-ACCT NOT = ZEROES)
                      ADD 1 TO WS-CTR
                      ADD 1 TO WS1-CTR
                      SET WS-READ-REC-NO TO TRUE
                      MOVE RCBS-KEY-ACCT TO WS-L2BS-KEY-ACCT(WS-CTR)
                      MOVE RCBS-KEY-ORG TO WS-L2BS-KEY-ORG
                      MOVE RCBS-INT-STATUS TO
                                        WS-L2BS-INT-STATUS(WS-CTR)
                      MOVE RCBS-DATE-LAST-STAT-CHG TO
                                         WS-LAST-STAT-CHG(WS-CTR)
                      MOVE RCBS-OLD-ORG  TO WS-OLD-ORG
                      MOVE RCBS-OLD-ACCT TO WS-OLD-ACCT
                                            WS1-OLD-ACCT(WS1-CTR)
                                            WS1-OLD-ACCT-IN(WS1-CTR)
                      PERFORM C2100-READ-L2BS-KSDS
                     END-IF
                  END-IF
             END-READ
           END-IF
           IF NOT WS-FLAT-IO-OK
              STRING 'ERROR' WS-FLAT-STATUS
                     ' ERROR IN READING THE FLAT FILE'
              DELIMITED BY SIZE INTO WS-ERR-TX
              END-STRING
           END-IF
           .
       R0100-EXIT.
            EXIT.
      ****************************************************************
      *   THIS SECTION WILL READ THE KSDS FILE                       *
      ****************************************************************
       C2100-READ-L2BS-KSDS SECTION.
      *-----------------------------
           MOVE WS-OLD-ORG TO L2BS-KEY-ORG
           MOVE WS-OLD-ACCT TO L2BS-KEY-ACCT
           IF NOT WS-KSDS-IO-OK
              STRING 'ERROR ' WS-KSDS-STATUS
                     ' ERROR IN READING THE L2BS FILE'
              DELIMITED BY SIZE INTO WS-ERR-TX
              END-STRING
           END-IF
           IF WS-KSDS-IO-OK
              READ KSDS KEY IS L2BS-KEY
                IF (L2BS-OLD-ACCT = SPACES OR
                    L2BS-OLD-ACCT = ZEROES)
                  ADD 1 TO WS-CTR
                  ADD 1 TO WS1-CTR
                  MOVE L2BS-KEY-ACCT TO WS-L2BS-KEY-ACCT(WS-CTR)
                  MOVE L2BS-OLD-ACCT TO WS-OLD-ACCT
                                        WS1-OLD-ACCT(WS1-CTR)
                  MOVE L2BS-OLD-ORG TO WS-OLD-ORG
                  MOVE L2BS-INT-STATUS TO
                                      WS-L2BS-INT-STATUS(WS-CTR)
                  MOVE L2BS-DATE-LAST-STAT-CHG TO
                                      WS-LAST-STAT-CHG(WS-CTR)
                  SET WS-READ-REC-YES TO TRUE
                  PERFORM W2000-WRITE-DETAIL-RECORD
                ELSE
                  MOVE L2BS-KEY-ORG TO WS-OLD-ORG
                  ADD 1 TO WS-CTR
                  ADD 1 TO WS1-CTR
                  MOVE L2BS-KEY-ACCT TO WS-L2BS-KEY-ACCT(WS-CTR)
                  MOVE L2BS-OLD-ACCT TO WS-OLD-ACCT
                  MOVE L2BS-INT-STATUS TO
                                      WS-L2BS-INT-STATUS(WS-CTR)
                  MOVE L2BS-DATE-LAST-STAT-CHG TO
                                      WS-LAST-STAT-CHG(WS-CTR)
                  SET WS-READ-REC-NO TO TRUE
                  GO TO C2100-READ-L2BS-KSDS
                END-IF
      *       END-READ
           END-IF
           .
        C2100-EXIT.
             EXIT.


It is more important the programs to be understandable by a human, rather than runnable by a computer!

Whenever I see any GOTO-like statement in any code, I usually stop trying to understand it.

Did you ever try to TEST and DEBUG your code?
Did you hear about such MANDATORY steps in ANY software development?

What are the results of your testing?
What are the intermediate data produced?
Where is the trace of execution of your code?
E.t.c, e.t.c, e.t.c.
Back to top
View user's profile Send private message
Pedro

Global Moderator


Joined: 01 Sep 2006
Posts: 2609
Location: Silicon Valley

PostPosted: Thu Mar 13, 2025 6:57 am
Reply with quote

re: Whenever I see any GOTO-like statement in any code, I usually stop trying to understand it.

Agree. I have not written Cobol for many years, but I think that a section that calls itself (through GO TO) is sketchy. I think you intentionally made an infinite loop.

Perhaps use "PERFORM xyz UNTIL some condition" and in the section do the stuff that needs to be repeated and then make the condition true when you reach the end.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2191
Location: USA

PostPosted: Mon Mar 17, 2025 7:28 pm
Reply with quote

How it's going with testing and debugging, to get any information about the processing?
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 Problem moving a cobol program into E... COBOL Programming 3
No new posts COBOL sorting, with input GDG base COBOL Programming 7
No new posts Need help with ADABAS query (COBOL-AD... All Other Mainframe Topics 1
No new posts Replacing FILLER with FILLER<SeqNu... DFSORT/ICETOOL 2
No new posts Compile Sp Cobol base COBOL Programming 1
Search our Forums:

Back to Top