Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

how to loop within loop in cobol

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
sandeep.tikoo

New User


Joined: 07 Oct 2006
Posts: 6
Location: Bangalore

PostPosted: Mon Oct 09, 2006 7:01 pm    Post subject: how to loop within loop in cobol
Reply with quote

how to loop within loop in cobol
Back to top
View user's profile Send private message

DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Mon Oct 09, 2006 7:06 pm    Post subject: Re: how to loop within loop in cobol
Reply with quote

Please explain in more detail what you are trying to accomplish. There are many implementations of imbedded loops.

Dave
Back to top
View user's profile Send private message
sandeep.tikoo

New User


Joined: 07 Oct 2006
Posts: 6
Location: Bangalore

PostPosted: Mon Oct 09, 2006 7:11 pm    Post subject: Re: how to loop within loop in cobol
Reply with quote

actually all i want to do is make a multiplication table like
2*1=2 to 10*1=10,
where 2,1 must be variables like i,j i must be constant from 1 to 10 and then j should increase by 1 again i from 1 to 10 and j=2, to j should also go to 10...like this
Back to top
View user's profile Send private message
IQofaGerbil

Active User


Joined: 05 May 2006
Posts: 183
Location: Scotland

PostPosted: Mon Oct 09, 2006 8:12 pm    Post subject: Re: how to loop within loop in cobol
Reply with quote

Something like this?

Perform Para1 varying i from 1 by 1 until i > 10

Para1
perform Para2 varying j from 2 by 1 until j > 10

Para2

compute ans = j * i
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Mon Oct 09, 2006 8:21 pm    Post subject: Re: how to loop within loop in cobol
Reply with quote

sandeep.tikoo,

Here are a couple of ways to implement you loops with ?PERFORM? statements.

In format 1 you can vary both variables within the same perform, but I prefer format 2 using two perform statements. Here is why. Although COBOL allows for the varying of multiple variables within the same perform, and this is probably the answer that is being looked for in an academic setting, once you get to the real world of programming, you won?t be varying multiple variables very often. My feeling is, that, at 2 a.m., when your program abends in a production environment, and the on call person for production problems has never looked at your program before, is not the time to re-acquaint themselves with a format that is seldom used.


Code:

WORKING-STORAGE SECTION.                                           
                                                                   
01  I                           PIC S9(5)     COMP-3.             
01  J                           PIC S9(5)     COMP-3.             
01  RESULT                      PIC 9(5).                         
                                                                   
LINKAGE SECTION.                                                   
                                                                   
PROCEDURE DIVISION.                                               
                                                                   
PROGRAM-START.                                                     
                                                                   
    DISPLAY 'FORMAT 1'.                                           
                                                                   
    PERFORM COMPUTE-DISPLAY-RESULT THRU COMPUTE-DISPLAY-EXIT       
      VARYING I FROM 1 BY 1 UNTIL I > 10                           
      AFTER J FROM 1 BY 1 UNTIL J > 10.                           
                                                   
    DISPLAY 'FORMAT 2'.                                 
                                                       
    PERFORM                                             
      VARYING I FROM 1 BY 1 UNTIL I > 10               
        PERFORM                                         
          VARYING J FROM 1 BY 1 UNTIL J > 10           
            PERFORM COMPUTE-DISPLAY-RESULT             
                THRU COMPUTE-DISPLAY-EXIT               
        END-PERFORM                                     
    END-PERFORM.                                       
                                                       
    GOBACK.                                             
                                                       
COMPUTE-DISPLAY-RESULT.                                 
    COMPUTE RESULT = I * J.                             
    DISPLAY 'I = ' I ' J = ' J ' RESULT = ' RESULT.     
COMPUTE-DISPLAY-EXIT.                                   
    EXIT.                                               
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. Cobol GUI (like Editor) Kala Mainframe COBOL Programming 14 Wed May 10, 2017 12:30 pm
No new posts IMS T-Pipe queue counts in a COBOL Pr... Siva NKK Kothamasu IMS DB/DC 0 Tue May 09, 2017 6:31 pm
No new posts COBOL Code Parsers and Lineage Establ... balimanja COBOL Programming 2 Tue May 02, 2017 3:30 am
No new posts Cobol upgrade - source code missing f... gthmrj IBM Tools 1 Wed Apr 26, 2017 6:04 pm
No new posts COBOL Programming Sandpit? jodrisco COBOL Programming 6 Wed Apr 12, 2017 3:47 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us