-3

I have an sqlrpg program which is supposed to generate warehouse locations, 8 positions, in a loop so that we will have rows, aisles,bins, as: but code is only producing the first row below, and is in a 'never ending loop. Now this below code is the entire, but perhaps you can see is it incrementing correctly? I am try to isolate as to where exactly this is not working. If you can alert me please what part is not incrementing towards the desired locations result:

AA01A01 
AA01A02 
AA01B01 
AA01B02 
AA01C01 
AA01C02 
AA01D01    



  H DFTACTGRP(*NO)                                                       
FLOCtest   O    E           K DISK    rename(LOCATION:REC1)            
F                                     prefix(w_)                       
D  @1Position     s              1                                     
D  @2Position     s              1                                     
D  @34Position    s              2                                     
D  @5Position     s              1                                     
D  @67Position    s              2                                     
D  @Location      s             10a                                    
D  @Location1     s              1a                                    
D  @Location2     s              1a                                    
D  @Location3     s              2a                                    
D  @Location4     s              1a                                    
D  @Location5     s              2a                                    
D w_STRSEL        s           1000a   inz(*blanks)                     
D w_STRSEL1       s           1000a   inz(*blanks)                     
D w_STRSEL2       s           1000a   inz(*blanks)                     
D w_STRSEL3       s           1000a   inz(*blanks)                     
D w_STRWHERE      s           1000a   inz(*blanks)                     
D w_STRSQL        s           1000a   inz(*blanks)                     
D intVal          s             10  0                                   
D   yesNo         s              1                                      
D w_APOS          c                   const(x'7D')                      
D getValue        PR            10A                                     
D   p_file                      10A   CONST                             
D getDetails      PR                                                    
D   p_field                     20A   CONST                             
D   p_file                      20A   CONST                             
C                   EXSR      MAINR                                     
C                   EXSR      EXITR                                     

C     MAINR         BEGSR                                               
C*                  EXSR      getValPos                                 
C                   EXSR      genValue                                  
C                   ENDSR                                               

C     getValPos     BEGSR                                               
 /free                                                                  
                 @1Position = getValue('POSITION1');               
                 @2Position = getValue('POSITION2');               
                 @34Position= getValue('POSITION34');           

                 @5Position = getValue('POSITION5');               
                 @67Position= getValue('POSITION67');              

 /end-free                                                              
C                   ENDSR                                               

C     upd67a        BEGSR                                               
 /free                                                                  
                    Exec SQL                                            
                 Update Position67 set SixSeven = 1                  
                 Where SixSevenPosition =: @Location5;             

 /end-free                                                              
C                   ENDSR                                               
C     upd67b        BEGSR                                               
 /free                                                                  

                      Exec SQL                                          
                Update Position67 set SixSeven = 0;           
 /end-free                                                              
C                   ENDSR                                               
C     upd5a         BEGSR                                               
 /free                                                                  
                    Exec SQL                                            
                Update Position5 set FifthFlag = 1            
                Where FIFTH00001 =: @Location4;             

 /end-free                                                              
C                   ENDSR                                               
C     upd5b         BEGSR                                               
 /free                                                                  

               Exec SQL                                      
               Update Position5 set FIFTHFLAG = 0;       

 /end-free                                                              

C                   ENDSR                                               
C     upd34a        BEGSR                                               
 /free                                                                  

                Exec SQL                                                
                Update Position34 set THIRD00002= 1                 
                Where THIRD00001 =: @Location3;                   

  /end-free                                                              
 C                   ENDSR                                               
 C     upd34b        BEGSR                                               
  /free                                                                  

                 Exec SQL                                                
                Update Position34 set THIRD00002= 0;                

  /end-free                                                              
 C                   ENDSR                                               
 C     upd2a         BEGSR                                               
  /free                                                                  

                  Exec SQL                                          
             Update Position2 set SECONDFLAG= 1             
             Where SECON00001 =: @Location2;                

  /end-free                                                              
C                   ENDSR                                               
C     upd2b         BEGSR                                               
 /free                                                                  

              Exec SQL                                             
              Update Position2 set SECONDFLAG= 0;              

 /end-free                                                              
C                   ENDSR                                               
C     del1a         BEGSR                                               
 /free                                                                  

              Exec SQL                                            
              delete from Position1                               
              Where FIRST00001 =:@Location1;                      

 /end-free                                                              
C                   ENDSR                                               
C     writeLoc      BEGSR                                               

C                   eval      @Location = *blanks                       

C                   eval      @Location = @Location1 +                  
C                              @Location2 + @Location3 +                
C                              @LocatioN4 + @Location5                  
C                   eval      w_Location = @Location                    
C                   write     rec1                                      
C                   ENDSR                                               
C     genValue      BEGSR                                               
 /free                                                                  
           @1Position = getValue('POSITION1');      
           DOW       @1Position = '1';              
            w_STRSEL3 = ' order by FirstPosition';          

           getDetails('FirstPosition':'Position1');        
           @Location1 = %trim(@Location);           

           W_STRWHERE = ' where SECONDFLAG=0';      
           @2Position= getValue('POSITION2');       
           DOW       @2Position = '1';              
            w_STRSEL2 = ' where SecondFlag=0';    
            w_STRSEL3 = ' order by SecondPosition'; 
            getDetails('SecondPosition':'Position2'); 
            @Location2 = %trim(@Location);            
           W_STRWHERE = ' where THIRD00002=0';       
            @34Position=                             
            getValue('POSITION34');                   
            DOW  @34Position = '1';                  
             w_STRSEL2 = ' where ThirdFourthFlag=0'; 
          w_STRSEL3 = ' order by ThirdFourthPosition'; 

       getDetails('ThirdFourthPosition':'Position34'); 
        @Location3 = %trim(@Location);          
        W_STRWHERE = ' where FifthFlag= 0';        
        @5Position= getValue('POSITION5');          
        DOW       @5Position = '1';                 

      w_STRSEL2 = ' where FifthFlag=0';            
       w_STRSEL3 = ' order by FifthPosition';       
       getDetails('FifthPosition':'Position5');   
        @Location4 = %trim(@Location);           

        W_STRWHERE = ' where SixSeven = 0';    
        @67Position= getValue('POSITION67');  

        DOW       @67Position = '1';                        

       w_STRSEL2 = ' where SixSeven=0';                 
       w_STRSEL3 = ' order by SixSevenPosition';         

      getDetails('SixSevenPosition':'Position67');       
      @Location5 =  %trim(@Location);                    

 /end-free                                                              
C                   EXSR      writeLoc                                  
C                   EXSR      upd67a                                    
 /free                                                                  
        W_STRWHERE = ' where SixSeven = 0';                  
        @67Position= getValue('POSITION67');                 
 /end-free                                                              
C*                  ENDSR                                               
C                   ENDDO                                               
C                   EXSR      upd67b                                    
C                   EXSR      upd5a                                     
 /free                                                                  
     W_STRWHERE = ' where FifthFlag= 0';             

      @5Position= getValue('POSITION5');              
 /end-free                                                              
C                   ENDDO                                               
C                   EXSR      upd5b                                     
C                   EXSR      upd34a                                    
 /free                                                                  
      W_STRWHERE = ' where THIRD00002=0';                
      @34Position= getValue('POSITION34');               
 /end-free                                                              
C                   ENDDO                                               
C                   EXSR      upd34b                                    
C                   EXSR      upd2a                                     
 /free                                                                  
     W_STRWHERE = ' where SECONDFLAG=0';                 
     @2Position= getValue('POSITION2');                  
 /end-free                                                              
C                   ENDDO                                               
C                   EXSR      upd2b                                     
C                   EXSR      del1a                                     
 /free                                                                  
  W_STRWHERE = ' where FIRSTFLAG=0';                 
  @1Position= getValue('POSITION1');                 
 /end-free                                                              
C                   ENDDO                                               

C                   ENDSR                                               
C     EXITR         BEGSR                                               
C                   EVAL      *INLR = *ON                               
C                   ENDSR                                               
P getValue        b                                                     
D getValue        pi            10A                                     
D   p_file                      10A   CONST                             
D x_val1          s             10a                                     
D x_val2          s              9s 0                                   
 /free                                                                  
    yesNo = '0';                                  

   w_STRSEL = 'SELECT * FROM ' + p_file;           
   w_STRSQL = %trimr(w_STRSEL) + %trimr(W_STRWHERE); 
   Exec SQL PREPARE S1 FROM :w_STRSQL;               
   Exec SQL DECLARE C1 CURSOR FOR S1;                
   Exec SQL OPEN C1;                                

   Exec SQL Fetch C1 Into :x_val1, :x_val2;          
    if SQLCOD = 0;                                   
    yesNo = '1';                        
    endif;                                     
   Exec SQL CLOSE C1;                               
   return yesNo;                           
 /end-free                                                              
P getValue        E                                                     

P getDetails      b                                                     
D getDetails      pi                                                    
D   p_field                     20A   CONST                             
D   p_file                      20A   CONST                             

D x_val1          s             10a                                     
 /FREE                                                                  
    @Location = *blanks;                      
     w_STRSEL = 'SELECT ' + p_field;           
     w_STRSEL1= ' FROM ' + p_file;             
 w_STRSQL = %trimr(w_STRSEL) + %trimr(w_STRSEL1) + 

   %trimr(w_STRSEL2) + %trimr(w_STRSEL3);            
   Exec SQL PREPARE S1a FROM :w_STRSQL;           
   Exec SQL DECLARE C1a CURSOR FOR S1a;           
   Exec SQL OPEN C1a;                            
   Exec SQL Fetch C1a Into :x_val1;             

   if SQLCOD = 0;                                
   @Location = %trim(x_val1);                  
   endif;                                       

   Exec SQL CLOSE C1a;                         

   w_STRSEL  = *blanks;                       
   w_STRSEL1 = *blanks;                       
          w_STRSEL2 = *blanks;                       
                                 w_STRSEL3 = *blanks;                   
                                    w_STRSQL  = *blanks;                

 /end-free                                                              
P getDetails      E                                                     
  • 1
    First of all, `EXSR, BEGSR, ENDSR` are all compatible with free-format. Please do us all a favor and use the free-format versions instead of going inbetween fixed and free in the c-specs. Second, you seem to have chopped off the end of some many of your lines. Third, if you're generating values...why do you need SQL to read a table? – Charles Jan 07 '16 at 03:03
  • oh so no need for C specs for Exsr etc. I was not aware. – Ron Rontel Jan 07 '16 at 13:56
  • ABout the C' specs within the /free- when i remove that in the source the compiler objects. I think maybe because we are on OS 6.1? I formatted the code better now. – Ron Rontel Jan 07 '16 at 14:46
  • Where would you focus your debugging to see why its only writing the same record out and in a never ending loop? – Ron Rontel Jan 07 '16 at 14:54
  • `...is it incrementing correctly?` Incrementing **what** correctly? That is, you seem to be FETCHing from various tables or viewa; but you haven't shown us what the definitions are for those tables or views. We can see program code, but there's no way we can test it without a clue about their definitions. (Also, what is `LOCtest`?) And as @Charles asked, why are you using SQL (to do a task that violates fundamental RDBMS rules and is therefore probably inappropriate for SQL)? Also, what are examples of, say, the first three rows that would be FETCHed? – user2338816 Jan 13 '16 at 08:53
  • I was going to format this in a way that would make it more understandable, but gave up when I found that there is no way it will even compile. Subroutine `genValue` has 5 `DOW` loops that have no `enddo;` or maybe you aren't giving us the whole program. – jmarkmurphy Jan 17 '16 at 04:33

2 Answers2

0

I can't format the code properly in a comment,

 /end-free                                                              
C                   ENDSR                                               

C     upd67a        BEGSR                                               
 /free                                                                  

Could be this instead

  ENDSR; 

  BEGSR upd67a;

You can't put the C in position 6 when you are using free-format op-codes.

I can't reconcile what you say you want to do, generate warehouse locations, 8 positions, in a loop with the code you've provided. In particular, why do you need SQL at all let alone need to use SQL to read an external table?

Charles
  • 21,637
  • 1
  • 20
  • 44
  • I am using tables to control the limits of the loops we are doing. We need to create locations as AA01A01. we have position 1, 2, 34, 5, 67 all have outer limit, this outer limit in the tables – Ron Rontel Jan 07 '16 at 20:50
-1

Ron, i can see that your question can be quickly resolved by debugging and inspecting the values in your DOW condition. I think it's little harder for people to decipher lenghty codes above without seeing the data and actual SQL stmt. I have 2 suggestions, 1) when your job is running, do wrkjob, pick your pgm, one of the columns there show the running line# of your pgm, if you see specific line# that's taking longer it might be the line that loops, end your job thru another session, 2) perhaps post your actual SQL stmt, in your getvalue and getdetails procedure to give people idea of the SQL stmt, to see it better.