1,435 pts.
 Problem with the READ from PF in RPGLE
Hi ! Im trying to read a physical file from my RPGLE program. That physical file having many fileds. AGCDE is the one of the filed there. The AGCDE data is from 001 to 700. But i just added it randomly. Now im having a problem with READ in RPGLE.. When i call the program its reading the Physical file from the first when its comes to AGCDE 168,then its directly going to the 300. Its not reading the AGCDE between these two values which is added newer. Help to me to find out the problem...

Software/Hardware used:
ASKED: January 18, 2013  6:47 AM

Answer Wiki:
Your problem is the "agcde chain m1ama00" instruction. That is changing the pointer in the file that you are looping through. We also do not know what your subroutine is doing. 
Last Wiki Answer Submitted:  January 18, 2013  12:40 pm  by  CharlieBrowne   32,785 pts.
All Answer Wiki Contributors:  CharlieBrowne   32,785 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 
This is my code..

*loval        Setll        m1ama00                
              Read      m1ama00                
              Exsr       print_head             
              Dow       not %eof(m1ama00)      
              if        %eof(m1ama00)          
              Leave                            
              Endif                            
              move      agcde         cde_agt  
agcde         chain     m1ama00                
              eval       o_agcde = agcde       
              Exsr      Load_data             
              Read     m1ama00               
              Enddo
 1,435 pts.

 

What order are you reading the file in? You don’t show enough of your program to show us the order. And you haven’t told us how ordering is defined for the file. The code that you show is okay, but we have no way to know if it’s appropriate. — Tom

 107,735 pts.

 

Code looks weak but I can not determine specifications.
Please explain what you are trying to do.
Please explain the key on mlama00
Please show the F spec.

 44,070 pts.

 
This is my load_data subroutine .. 

move      *date         tstdate           8          
Eval      yr_t = %subst(tstdate:5:4)                 
move      yr_t          yr_n                         
Eval      t_yr1 =  yr_t                              
Eval      t_yr  = %char(yr_n - 1)                    
do        noofyr        in                           
Eval      txt_1 = '07'+ T_YR + ',' + '08' + T_YR +','
          + '09' + T_YR + ',' + '10' + T_YR + ','    
          + '11' + T_YR + ',' + '12' + T_YR + ','    
          + '01' + T_YR1 + ',' + '02' + T_YR1+ ','   
          + '03' + T_YR1 + ',' + '04' + T_YR1+ ','   
          + '03' + T_YR1 + ',' + '04' + T_YR1+ ','    
          + '05' + T_YR1 + ',' + '06' + T_YR1         
                                                      
eval      qrystr = 'SELECT AGCDE,  SUM(PRMAMT)  + '   
          + ' SUM(ADLPRM) - SUM(RFPREM) FROM FA5TH00 '
          + ' WHERE '                                 
          + 'PCMNTH IN('+%trim(txt_1) +' )' + ' AND ' 
          + ' AGCDE = ' + cde_agt                     
endsr
 1,435 pts.

 

Wonderful but doesn’t help .. atleast not yet.Why do you read and chain from the same file and then read again??? Phil

 44,070 pts.

 

The load_data subroutine is only useful to show that it doesn’t affect the order of records. It still doesn’t show anything about how the file is ordered. It doesn’t include the F-spec. It doesn’t include the file description. And it certainly doesn’t tell us why you have a CHAIN to the same file right in the middle of a READ loop. That is what causes your problem, but we still can’t tell what the programming should be doing because we don’t know any definitions. — Tom

 107,735 pts.

 
Hi Phil and Tom .
Thats my poor coding. 
Simply i want to read m1ama00 file from the beginning to end and execute the subroutine for the each AGCDE.. 
How can i do that..  If u specify the code it would be helpful to me.. 

Thanks 
Surey
 1,435 pts.

 
This would help you i Guess.. 
This is the run_qry subroutine its executed from Load_Data Subroutine.. 


     run_qry       BegSr            
/EXEC SQL                           
+ PREPARE S1 FROM :QRYSTR1          
/END-EXEC                           
*                                   
/EXEC SQL                           
+ DECLARE C1 CURSOR WITH HOLD FOR S1
/END-EXEC                           
*                                   
/EXEC SQL                           
+ OPEN C1                           
/END-EXEC                           
/EXEC SQL                           
+ FETCH NEXT FROM C1 INTO :agent_prm
/END-EXEC                           
/EXEC SQL                                        
+ FETCH NEXT FROM C1 INTO :agent_prm             
/END-EXEC                                                   
* 
/EXEC SQL                                        
+ CLOSE C1                                       
/END-EXEC                                        
                   EndSr                         
 1,435 pts.

 

You still haven’t shown the F-spec for m1ama00, and you haven’t shown the key information for the file from the file description. And you still haven’t explained why the CHAIN statement is in your READ loop.
 
But if you want to know how to read the file in sequence, the best guess is to delete that CHAIN statement from the program. The program will probably work better without it. It doesn’t seem to have a purpose, and it looks like it interferes with your sequencing.
 
Tom

 107,735 pts.

 

F-spec for file m1ama00.  And is m1ama00 keyed on AgCDE????” its reading the Physical file from the first when its comes to AGCDE 168,then its directly going to the 300″  So we’ve been focusing on the file m1ama00 and how you are getting data from it.  But perhaps it’s processing the data in the correct order but failing to report some rows because of the design of your downstream processes. So how do you know that the rows are being accessed from mlama00 out of order? 

 44,070 pts.

 
Hi 
This is my F specification.. everything is fine here i hope..
m1ama00   if   e           k disk

anyway i just changed my code as follows.

                   Dow       not %eof(m1ama00)     
                   if        %eof(m1ama00)         
                   Leave                           
                   Endif                           
                   move      agcde         cde_agt 
agcde         chain     m1ama00               
                   eval      o_agnme = %trim(agnme)
                   eval      o_agcde = agcde       
                   Exsr      Load_data             
                   eval      agcde = agcde + 001   
                    if        agcde = 713           
                   leave                           
                   endif                           

Now its showing the 169,170,171 etc.. 
But a new problem has arise. That is its showing right agnme upto 168. But from 169 to 299 its repeating the same name of 168.. from 300 onwards its showing the specific agnme which is correct.. 

Chain should hold all the fields of that specific row.. Am i right ? 

Tom, as you told, i just removed the CHAIN and its didn't worked . that's why i tried this.. 


Surey
 1,435 pts.

 

That segment of code doesn’t make sense. It has the start of a DO-loop but doesn’t show the ENDDO. The loop is conditioned on %EOF(m1ama00), but the CHAIN is the only statement shown that can set %EOF(m1ama00).
 
You did show the F-spec, so now we know that the program is accessing m1ama00 by key and not by RRN. That was the first thing we needed. But we still don’t see the key definition from the file description.
 
We also still have no idea why you keep putting the CHAIN in there. It has no purpose. It will either just read the same record that the program already has or it will read a different record. If it reads the same record, then it has no purpose. And if it reads a different record, then it will mess up the sequence of records that you read.
 
Take it out and leave it out, or explain why you have it there.
 
Also explain why you have no error indicators on the CHAIN and it also has no (E) extender. How do you expect to find out that it can’t find a record?
 
Yes, the CHAIN can have all fields from the record. But you already have all the fields when you READ. Why try to get all the fields twice?
 
Finally, you keep saying that values are wrong. How do you know they are wrong? Are you running in debug and watching memory? You don’t show any output statements in the program, so we can’t tell what you look at when you say that values are wrong.
 
Beyond those, earlier you showed the run_qry subroutine. You said it was called from Load_data, but your code doesn’t show that Load_data calls it. And run_qry creates a cursor and FETCHes two rows, but Load_data runs every time you go through your DO_loop. Why would you want a cursor? Why don’t you just SELECT the two records one at a time without a cursor? It is very inefficient to create a cursor every time. Why are you FETCHing two rows?
 
Your SELECT doesn’t have an ORDER BY clause, so you can’t expect to get two rows from the file that are next to each other. The second row that you FETCH could be any other row in the file.
 
So, get rid of the CHAIN or explain its purpose. And show us the key definition for m1ama00. And explain what you mean when you say values are wrong. I am guessing that you have a report or a screen that shows some values, but I have no idea how a value is copied from a file record to output so you can see it.
 
Tom

 107,735 pts.

 

code window will not work for me!!Here is about what we might have expectedWhy doesn’t this do what you want?Is mlama00 keyed on agcde?Are there repeating values of agcde in the table? Setll mlama00Read  mlama00Dow not %eof(mlama00) and agcde <= 713Move agcde   cde_agteval o_agnme = %trim(agnme)eval o_agcde = agcdeExsr load_dataRead mlama00enddo 

 44,070 pts.

 

Here is about what we might have expected
Why doesn’t this do what you want?
Is mlama00 keyed on agcde?
Are there repeating values of agcde in the table?

Setll mlama00
Read mlama00
Dow not %eof(mlama00) and agcde <= 713
Move agcde cde_agt
eval o_agnme = %trim(agnme)
eval o_agcde = agcde
Exsr load_data
Read mlama00
enddo

 44,070 pts.