Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
sandeep.tikoo

New User

Joined: 07 Oct 2006
Posts: 6
Location: Bangalore

 Posted: Mon Oct 09, 2006 7:01 pm    Post subject: how to loop within loop in cobol how to loop within loop in cobol

DavidatK

Active Member

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

 Posted: Mon Oct 09, 2006 7:06 pm    Post subject: Re: how to loop within loop in cobol Please explain in more detail what you are trying to accomplish. There are many implementations of imbedded loops. Dave
sandeep.tikoo

New User

Joined: 07 Oct 2006
Posts: 6
Location: Bangalore

 Posted: Mon Oct 09, 2006 7:11 pm    Post subject: Re: how to loop within loop in cobol 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
IQofaGerbil

Active User

Joined: 05 May 2006
Posts: 183
Location: Scotland

 Posted: Mon Oct 09, 2006 8:12 pm    Post subject: Re: how to loop within loop in cobol 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
DavidatK

Active Member

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

Posted: Mon Oct 09, 2006 8:21 pm    Post subject: Re: how to loop within loop in cobol

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.
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics Issue in suppressing leading zeros &a... Vijay_Sirisha COBOL Programming 21 Thu Jun 07, 2018 8:01 pm VBS to VB in COBOL and JCL srajendran2 COBOL Programming 12 Fri Jun 01, 2018 3:04 am Rexx code to find greater then symobl... Bharath Vikraman CLIST & REXX 8 Tue May 29, 2018 9:40 am How to convert 2 bytes into single by... pkmurali DB2 6 Fri May 25, 2018 1:41 pm SYSADATA - COBOL - Structure displace... ganasrinivasan COBOL Programming 3 Thu May 24, 2018 9:45 pm

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us