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

Issue with Do Loop.


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
santosh_g

New User


Joined: 14 Aug 2011
Posts: 24
Location: india

PostPosted: Tue May 12, 2015 9:24 am
Reply with quote

Hi There,

I am having issue with do loop (going infinite loop). Below is my code:

Code:

Do i = 1 to TempLoop by 1                                           
   Select                                                           
      When i = 020 then call Build_SYSUT1   
      When i = 026 then call Build_FIELDS   
      When i = 099 then call Build_PUT       
      Otherwise do                                                   
         j = j+1                                                   
         Jclx.j = Stmt                                   
      End                                                           
   End                                                               
End                                                                 


/*******************/
Build_SYSUT1:                                             
 trace r                                                   
 Stmt = ''                                                 
 End_fl = 'N'                                             
                                                           
 Stmt = '//SYSUT1 DD DSN='||DSN.BCCYYMM||',DISP=SHR'       
 j = j+1                                                   
 Jclx.j = Stmt                                             
           

                                               
 Do forever                                               
    ccyy = substr(BCCYYMM,1,4)                             
    mm   = substr(BCCYYMM,5,2)                             
    mm   = mm + 1                                         
    If mm < 10 then mm = '0'||mm                           
                                                           
    BCCYYMM = ccyy||mm                                     
                                                           

    If mm > 12 then do                                               
       mm   = 01                                                     
       ccyy = ccyy + 01                                             
       BCCYYMM = ccyy||mm                                           
    End                                                             
                                                                     
    If BCCYYMM <<= ECCYYMM then do                                   
       Stmt = '//       DD DSN='||DSN.BCCYYMM||',DISP=SHR  '
       j = j+1                                                       
       Jclx.j = Stmt                                                 
    End                                                             
    Else leave                                                       
 End                                                                 
                                                                                               
                             
Return                       
         


When i = 20, Build_SYSUT1 is called. Upon return, the value of i is not incrementing and is always 20. Due to this, Build_SYSUT1 is called again (infinite loop).

Can anyone pls tell me where I am going wrong with DO loop.

Should I manually increment "i" in the program.

I even tried with Do/While, but same result.

Best Regards,
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Tue May 12, 2015 11:22 am
Reply with quote

it does... it does...
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


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

PostPosted: Tue May 12, 2015 2:25 pm
Reply with quote

Works for me. Taking the relevant code from your snippet:
Code:
temploop = 100; j = 0
Do i = 1 to TempLoop by 1

   Select

      When i = 020 then call Build_SYSUT1
      When i = 026 then call Build_FIELDS
      When i = 099 then call Build_PUT
      Otherwise do

         Say 'In Otherwise: i = 'i
         j = j+1
         stmt = 'jcl_'||i
         Jclx.j = Stmt

      End

   End

End
Exit
Build_SYSUT1:
   Say 'In BUILD_SYSUT1: i = 'i
Return
Build_FIELDS:
   Say 'In BUILD_FIELDS: i = 'i
Return
Build_PUT:
   Say 'In BUILD_PUT   : i = 'i
Return


Running this produces the expected output. Maybe there is something that you are not showing us that is relevant?
Back to top
View user's profile Send private message
santosh_g

New User


Joined: 14 Aug 2011
Posts: 24
Location: india

PostPosted: Tue May 12, 2015 8:44 pm
Reply with quote

Nic Clouston wrote:
Works for me. Taking the relevant code from your snippet:
Code:
temploop = 100; j = 0
Do i = 1 to TempLoop by 1

   Select

      When i = 020 then call Build_SYSUT1
      When i = 026 then call Build_FIELDS
      When i = 099 then call Build_PUT
      Otherwise do

         Say 'In Otherwise: i = 'i
         j = j+1
         stmt = 'jcl_'||i
         Jclx.j = Stmt

      End

   End

End
Exit
Build_SYSUT1:
   Say 'In BUILD_SYSUT1: i = 'i
Return
Build_FIELDS:
   Say 'In BUILD_FIELDS: i = 'i
Return
Build_PUT:
   Say 'In BUILD_PUT   : i = 'i
Return


Running this produces the expected output. Maybe there is something that you are not showing us that is relevant?


The code snippet is as is.

Create_jcl is below and Build_SYSUT1 as shown in OP.
I included trace r and the value of i is always 20.


Code:

Create_jcl:                                                             
                                                                       
  ADDRESS TSO                                                           
  "EXECIO * DISKR TEMPLATE (STEM Template. FINIS"                       
  If rc /= 0 Then                                                       
    Call Pgm_fail 0001 rc 'Unable to read TEMPLATE file!'               
                                                                       
  TempLoop = Template.0                                                 
                                                                       
  If TempLoop = 0 Then                                                 
     do                                                                 
        Say '*********************************************************'
        Say 'Nothing would be processed.....                          '
        Say '*********************************************************'
        Exit normal_rc                                                 
     end                                                               
                                                                   
   j = 0                                                           
                                                                   
   Jobname = User||'L'                                             
   Do forever                                                       
      x = length(Jobname)                                           
      If x < 8 then Jobname = Jobname||' '                         
      Else leave                                                   
   End                                                             
                                                                   
   
   Jcard = '//'||Jobname||Stmt                                     
   j = j+1                                                         
   Jclx.j = Jcard 
   j = j+1                                                 
   Jclx.j = Jcard2 
   j = j+1                                                 
   Jclx.j = Jcard3                         
                                                         

   Do i = 1 to TempLoop by 1                                           
      Select                                                           
         When i = 020 then call Build_SYSUT1    /* Line# 020 Template */
         When i = 026 then call Build_FIELDS    /* Line# 026 Template */
         When i = 097 then call Build_ACTSEL2   /* Line# 100 Template */
         When i = 102 then call Build_SECSEL    /* Line# 109 Template */
         When i = 607 then call Build_PUT       /* Line# 681 Template */
         Otherwise do                                                   
            j = j+1                                                     
            Jclx.j = Template.i                                         
         End                                                           
      End                                                               
   End                                                                 
   Jclx.0 = j                                                           
                                                                       
Return
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Tue May 12, 2015 9:36 pm
Reply with quote

do You realise that instead of ...

Code:
   
Jobname = User||'L' 
Do forever                                                       
      x = length(Jobname)                                           
      If x < 8 then Jobname = Jobname||' '                         
      Else leave                                                   
   End         


You could have used ...
Code:
jobname = left(user"L", 8)



and that when dealing with stems
instead of having the index hanging around
it is better to ...

Code:
<index> = <stemname>.0 + 1
<stemname>.<index> = <whatever expression You like>
<stemname>.0 = <index>


just one line of coding
but it saves You the hassle of keeping track of the value of the stem index al over the script

and running

Code:
       user="donald"

  TempLoop = 30


   j = 0

   Jobname = User||'L'
   Do forever
      x = length(Jobname)
      If x < 8 then Jobname = Jobname||' '
      Else leave
   End


   Jcard = '//'||Jobname||Stmt
   j = j+1
   Jclx.j = Jcard
   /*
   j = j+1
   Jclx.j = Jcard2
   j = j+1
   Jclx.j = Jcard3
    */

   Do i = 1 to TempLoop by 1
      Select
         When i = 20 then call Build_SYSUT1    /* Line# 020 Template */
         When i = 26 then call Build_FIELDS    /* Line# 026 Template */

         Otherwise do
            j = j+1
            Jclx.j = "Template."i
         End
      End
   End
   Jclx.0 = j

     do i = 1 to jclx.0
        say i jclx.i
    end

    exit

      Build_SYSUT1:
      j =j+1
   jclx.j = 'In BUILD_SYSUT1: i = 'i
Return
Build_FIELDS:
j =j+1
   jclx.j = 'In BUILD_FIELDS: i = 'i
Return


gives

Code:
1 //donaldL STMT
2 Template.1
3 Template.2
4 Template.3
5 Template.4
6 Template.5
7 Template.6
8 Template.7
9 Template.8
10 Template.9
11 Template.10
12 Template.11
13 Template.12
14 Template.13
15 Template.14
16 Template.15
17 Template.16
18 Template.17
19 Template.18
20 Template.19
21 In BUILD_SYSUT1: i = 20
22 Template.21
23 Template.22
24 Template.23
25 Template.24
26 Template.25
27 In BUILD_FIELDS: i = 26
28 Template.27
29 Template.28
30 Template.29
31 Template.30
Back to top
View user's profile Send private message
santosh_g

New User


Joined: 14 Aug 2011
Posts: 24
Location: india

PostPosted: Wed May 13, 2015 8:22 am
Reply with quote

Thank you enrico and Nic for your help.

The code worked. There was no issue with Do loop. I messed up the index in the program.


Best Regards,
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 -> CLIST & REXX

 


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 Issue after ISPF copy to Linklist Lib... TSO/ISPF 1
No new posts Facing ABM3 issue! CICS 3
No new posts Panvalet - 9 Character name - Issue c... CA Products 6
Search our Forums:

Back to Top