• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 653
  • Last Modified:

Programmer

Using a subfile where users can add and delete data on the subfile screen.  When they delete a record everything works fine.  When I try to add a record, after the subfile is initialized with SFLCLR the subfile load blows up with "an attempt to write a duplicate record" error. In some other posts I saw the SFLCLR clears the subfile but not the display, but cannot stop the error from happeneing. I can put my code out there if necessary.  I am a fairly experienced programmer in RPG but have never encountered this problem before,  I have wrote subfiles before. Hope you an help.
0
nmvfd18
Asked:
nmvfd18
  • 10
  • 9
  • 5
  • +1
2 Solutions
 
Gary PattersonVP Technology / Senior Consultant Commented:
Sure, post the code, and a dump from when the programs fails.

- Gary Patterson
0
 
nmvfd18Author Commented:
Here is the DDS:        

R SFL01                     SFL          
**                                   SFLNXTCHG    
           ZMAORD         1A  B 10  4            
           ZMZIP1         5A  B 10 18            
 26                                  DSPATR(RI)  
           ZMCITY        15A  O 10 34            
           ZMSTAT         2A  O 10 64            

         R CTL01                     SFLCTL(SFL01)              
                                     SFLPAG(0009)              
                                     SFLSIZ(0010)              
                                     CF06(06 'Add Record')      
                                     CA12(12 'Return')          
N33                                  ROLLUP(28 'roll more data')
                                     RTNCSRLOC(&RECNAM &FLDNAM)
                                     OVERLAY                    
 32                                  SFLDSP                    
 31                                  SFLDSPCTL                  
 33                                  SFLEND(*MORE)              
N31                                  SFLCLR                    
 27                                  SFLMSG('Not a valid zip cod
           RECNAM        10A  H                                
           FLDNAM        10A  H                                
           SETRRN         4S 0H      SFLRCDNBR    

Here is the Rpg free code:

 begsr initsfl;      
  *in31 = *Off;      
  *In32 = *Off;      
  *In33 = *Off;      
  rrn1 = *zero;      
  rrn2 = *zero;      
  *In28 = *Off;      
  *In98 = *Off;      
  setrrn = *zeros;    
  LSTRRN1 = *zeros;  
  setrrn2 = *zeros;  
  LSTRRN2 = *zeros;  
  Write Ctl01;        
  Write Ctl02;        
  *in31 = *On;        
  rrn1 = 1;          
 
 begsr loadsfl;                  
 if zzone <> *blanks;            
 rrn1 = *zeros;                  
 setrrn = *zeros;                
 lstrrn1 = *zeros;              
 setll (zzone) opb803l1;        
 dow  rrn1 < 09;                
 reade (zzone) opb803l1;        
 end803 = %eof;                  
 if not %eof and zzone = zrzone;
 zmaord = *blanks;              
 zmzip1 = zrzipcode;            
 zmcity = *blanks;              
 zmstat = *blanks;              
 exsr verify_zip;                
 else;                          
 zmaord = *blanks;  
zmzip1 = *blanks
zmcity = *blanks
zmstat = *blanks
*in26 = *off;  
endif;          
rrn1 += 1;      
setrrn = rrn1;  
write sfl01;    
setrrn = rrn1;  
lstrrn1 = rrn1;
enddo;          
else;          
rrn1 = 1;      
setrrn = 1;    
lstrrn1 = 1;    
dow  rrn1 < 08;  
rrn1 += 1;      
if not %eof ;    
zmaord = *blanks;
zmzip1 = *blanks;
zmcity = *blanks;
zmstat = *blanks;
write sfl01;    
endif;          
enddo;          
endif;          
setrrn = rrn1;  
lstrrn1 = rrn1;  
if end803 = *on;
*in33 = *on;    
end803 = *off;  
endif;          
  *in32 = *on;
  endsr;        

   // Edit Data - USA                        
                                             
   begsr editdata;                            
   if zzone = svzone and zsrch = svsrch;      
    load = 'N';                              
   endif;                                    
   readc sfl01;                              
   dow not %EOF;                              
    if zmaord = 'D' or zmaord = 'd';          
     load = 'Y';                              
     chain (zmzip1) byzip;                    
     if zzone = zrzone and zmzip1 = zrzipcode;
      delete byzip;                          
     endif;                                  
    endif;                                    
    if zmaord = 'A' or zmaord = 'a';          
     load = 'Y';                              
     zrzone = zzone;                
     zrzipcode = zmzip1;            
     exsr verify_zip;              
     if *in26 = *off;              
      chain (zmzip1) byzip;        
      if %found and zzone = *blanks;
       *in91 = *on;                
      else;                        
       *in84 = *on;                
      endif;                        
     else;                          
      write byzip;                  
      *in85 = *on;                  
      lstrrn1 += 1;                
      setrrn = lstrrn1;            
      rrn1 = lstrrn1;              
     write sfl01;                  
    endif;                        
   endif;                          
  clear zmaord;                    
  if zmzip1 = *blanks;            
   *in26 = *off;                  
  endif;                          
  if *in26 = *on;                  
   *in27 = *on;                    
  endif;                          
  readc sfl01;                    
  enddo;                          
  if *in26 = *off and *in84 = *off;
   exsr initsfl;                  
   exsr loadsfl;                  
  endif;        
endsr;
0
 
nmvfd18Author Commented:
Program works fine with the subfile initialize and load of the subfile. If the user puts a 'D' to delete a record, program works fine and redisplays the data with the deleted subfile removed.  Its when a user tries to take an 'A' to add a record, that I get a Write a duplicate error message on SFL01. This occurs in the LOADSFL subroutine after the INITSFL subroutine is run. Again it appears that the SFLCLR is not clearing the SFL01 file. Any help you can provide would be great, this is very frustrating.
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
nmvfd18Author Commented:
I can provide the dump, but don't know what that would tell you, indicators 31 and 32 are on and the RRN1 field = 1. It is a lot of data to post, but if you still need it, just let me know.
0
 
tliottaCommented:
I see a number of issues with the code, but it's hard to tell if any of them relate; not enough of the program is shown. However, it's not clear what the exact problem is because [loadsfl] could possibly issue that error in two locations in the code. Which WRITE instruction is failing? I assume it's the first WRITE because you say "...the RRN1 field = 1", and it apparently never equals (1) for the other WRITE.

In the second DOW-loop in [loadsfl], why do you only WRITE to subfile records 2 through 8? In the first DOW-loop, you WRITE to subfile records 1 through 9.

Tom
0
 
nmvfd18Author Commented:
Tom:

The issue not whether I write subfile records 2 - 9 or 1 - 8, 3 people have looked at the code and tried to fix the problem multiple ways.  The program runs through the subroutine initsfl and loadsfl with no problem the first time.  The subfile is displayed on the screen and the user can either add or delete records. I they delete a record, the editdata, deletes the record from the file, i run through initsfl and loadsfl and the subfile is re-displayed with the record gone.  The problem occurs on the add, they add a record, which is verified to be valid, it is added to the file, and then i run through the initsfl and loadsfl and when it writes the first record in the subfile, I get the writing a duplicate record on the subfile. this occurs whether it is 1-9 or 2-8.  The problem appears that the subfile clear is not working or is not clearing the display, but I don't know why this should only happen when I am trying to add a record and not on the delete. Any help in this matter would be appreciated.
0
 
tliottaCommented:
Again, the problem is not clear. There are two WRITE statements in that subroutine. Which one fails?

The apparent oddity of which subfile RRNs are written is just one of a number of problems with the code. It seemed odd enough to have a purpose that might help explain the other things that are wrong or that simply seem odd with the code.

But the first question is still -- What fails?

Tom
0
 
nmvfd18Author Commented:
It is the first write that fails in loadsfl. The second write was added just to write blanks records.
0
 
Gary PattersonVP Technology / Senior Consultant Commented:
I've been an RPG programmer for over 20 years.  I've written hundreds of subfile programs and fixed many, many more.  

Tom knows his stuff, too.

There is almost zero chance that SFLCLR isn't working, or some other exotic problem.  

Odds are you have a simple logic error, and someplace you are not incrementing the SFLRRN properly, and ending up hitting the same record twice.  Or, you are actually getting a database error adding the record to a database file, and not realizing it.

But I can't tell, because you didn't provide a dump.

Most of the time just getting into debug and single-stepping though the program and checking the state of all your variable before critical operations will narrow it down in minutes.  You don't say if you've done this.  If not, you should.

Anway, if you need more help, please just provide the information we request.  We might've already gotten this fixed if we could see a dump.  

Before you do that, though, do yourself a favor and run this program under debug, and single-step though it from line one until the problem happens.  9 times out of ten, you'll see the problem (and it won't be "SLFCLR didn't work").  SLFCLR works.  Much more likely there is a logic bug and SLFCLR isn't getting hit, or you are just missing an increment in the sflrrn in some specific case.  

I do this for free, in my spare time, and nothing is more frustrating than carefully spelling out what you need to see in order to help someone with a problem, and then having the poster ignore or debate the need for the requests.

So, please do this:

1) Run under debug and single step through the ENTIRE PROGRAM, checking variable values to confirm they are what you are expecting.  You might want to pare your data down to a manageable size first so you don't have to load more than a few records.  9 times out of ten, in a few repeats of stepping through the program, you'll see the problem.

2) Please post the whole program, not just what you think is relevant.  For example, I want to see your F spec where the DSPF is declared.  Please don't post it inline - post a nicely formatted, indented copy as a text file attachment - either by downloading the source member as a text file, or by printing a listing and exporting the spooled file  via Navigator.  The easier you make it on us, the faster and better a response you'll get.  

Instructions are below.

http://www-01.ibm.com/support/docview.wss?uid=nas18e09d7cac393735686256d040050dbff

3) Finally, when the error occurs, dump the program and post a copy of the dump (in a text file attachment please).

4) Post the entire text of the error message, including the level 2 text (DSPJOBLOG, find the Duplicate record error, cursor on it, press F1).

Thanks!

- Gary Patterson
0
 
Gary PattersonVP Technology / Senior Consultant Commented:
If you are having problems and this is a new program, you might want to do yourself a favor and start with a good, working model subfile program.  

In his book, Subfiles in Free-Form RPG, Kevin Vandever has great sample code (that works).  The examples in this book and the previous fixed-format version have formed the basis of thousands and thousands of subfile programs that are running in production in shops all over the world.  

- Gary Patterson
0
 
nmvfd18Author Commented:
Sorry Gary and Tom.  I have stepped through the program in debug already, and I do not see the error.  I will do it again, just to be sure and also send you the program and the dump the way you asked.
0
 
Gary PattersonVP Technology / Senior Consultant Commented:
Thanks.  Glad to hear you've already tried stepping through in debug.  You know, it looks like this is a small, simple program.  I wouldn't mind loading a copy onto my test system and looking at it, as long as you can give me some data that doesn't have anything confidential in it.  

Here's how:

Create a lib called EELIB.

Create a source physical file in EE, and put a copy of the source for the program and any dependent objects (DDS for the dspf, dds for an PF and LF) into it.  Make a copy of any required pf containing test data (noting confidential, please!) into EE.  No need to put the compiled program or display file in there - I can just compile it.  If there are special compile instructions, make sure you include them.

Create a save file called EE in QGPL

SAVLIB the EELIB to the save file.

Download the savf using FTP to your PC (do a binary transfer!) and post it as an attachment here.  If it is too big, zip it first.

FTP myas400
(Log in)
>binary
>get /QSYS.QGPL/EE.SAVF c:\somefolderonyourpc\EE.SAVF
0
 
nmvfd18Author Commented:
Gary:  Did everything correct except when I do the get statement in the FTP i get the following:

200 POST subcommand request successful
550 Request rejected
Can I use iseries Navigator to bring the file to the pc?
0
 
Gary PattersonVP Technology / Senior Consultant Commented:
Looks like your system administrator is using an FTP exit program to secure FTP.  You may need to talk to your system admin in order to get rights to use FTP.

I always use FTP for this.  

Just tried using Navigator to drop a SAVF on my desktop but it didn't work.

- Gary
0
 
tliottaCommented:
GET /QSYS.LIB/QGPL.LIB/EE.SAVF...

Open in new window

Assuming NAMEFMT 1...

Or:
GET QGPL/SAVF...

Open in new window

Assuming NAMEFMT 0.

Tom
0
 
Gary PattersonVP Technology / Senior Consultant Commented:
@Tom:  Since AS/400 FTP server automatically switches to NAMEFMT 1 if the pathname starts with "/", I've decided to just avoid the whole NAMEFMT conversation altogether and stick to the IFS naming convention unless it is important to the conversation.  I just make sure to specify full paths.  

Never understood why we needed two path naming formats in the first place when the IFS format handles everything.
0
 
tliottaCommented:
@Gary:

Two name formats were needed during the earliest days after the TCP/IP Utilities became free of charge and the IFS was introduced. Too many scripts already existed for financial institutions, etc., and those earliest accounts weren't ones that could be irritated. Those early scripts all had only NAMEFMT 0 available.

But the IFS format still needs the .LIB qualifiers for QSYS and QGPL regardless of defaults. Defaulting is why I used "assuming" rather than adding the NAMEFMT directly in the script.

Tom
0
 
Gary PattersonVP Technology / Senior Consultant Commented:
@Tom:

I didn't realize until just now that there was a typo in my earlier PUT statement!  Thanks for spotting it and correcting it.

- Gary
0
 
nmvfd18Author Commented:
Still getting the same error as above. The file on the PC will have an extension of SAVF? Is that a legitimate file extension?
0
 
Gary PattersonVP Technology / Senior Consultant Commented:
Tom pointed out a problem with my PUT statement.  Corrected, it looks like this:

FTP myas400
(Log in)
>binary
>get /QSYS.LIB/QGPL/LIB/EE.SAVF c:\somefolderonyourpc\EE.SAVF

As far as you "extension" questions goes:

Windows file extensions are a convention, and are optional.  There is no "legitimate" or "not legitimate" (unless an extension uses illegal characters, perhaps and violates file naming rules, I suppose).  This is an AS/400 Save File, and since the AS/400 FTP server requires the SAVF extension on its side when using this name format, I tend to use the same extension on the PC file that is created.  But you don't have to.

If you want to use a different extension to use on the Windows side (or no extension at all if you prefer), feel free.  

That 500 error is often the result of a security issue.  It means that your security administrator has an FTP Exit Point program in place, and that program has decided to reject your FTP request.  Exit Point programs provide an extra layer of security for sensitive services like FTP.  If you get a 500 every time you try to use FTP, that is probably the cause, and you'll need to get help from a system administrator to use FTP.

- Gary Patterson
0
 
tliottaCommented:
The .SAVF extension is recognized by FTP servers running on AS/400s. It's not required on the PC, but the FTP server will do an automatic step or two for anyone needing to restore the savefile.

There's another typo. The path to your savefile should begin with /QSYS.LIB. The second node needs to be /QGPL.LIB. That second node in the example has a "/" where a "." needs to be.

Tom
0
 
Gary PattersonVP Technology / Senior Consultant Commented:
Tom:  Thanks again.  Pushing "submit" without giving it a good proofread, first.
0
 
nmvfd18Author Commented:
Gary & Tom:

I have solved the problem. I was writing a message to the display file before the cleat and load. Once I commented out the message, it program refreshed like I thought it would. Thank you for your help.
0
 
Gary PattersonVP Technology / Senior Consultant Commented:
Glad you got it fixed.
- Gary
0
 
daveslaterCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 10
  • 9
  • 5
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now