Search code examples
rpglerpg

How to encounter error UPDATE and DELETE without prior input WHEN want to update to SUBFILE in RPGLE


I'm having an error shown as in the picture below :

Error

If I enter blank option or wrong option, I will get the error as above

enter image description here

When this error occur, I cant Update, Delete and Refresh.

It happens when I want to update existing record and also when I put wrong option and blank option. When I debug, I realize that the error comes when want to UPDATE SUBFILE.

OSR     Begsr
        ReadC    SFL01
        DOW      *IN91 = *OFF
        
        Select
OPT     WhenEQ    2
        Exsr      UPDSR
OPT     WhenEQ    4
        Exsr      DLTSR             
OPT     WhenEQ    5
        Exsr      DSPSR
        Other
        Exsr      ERRSR
        EndSL

        Clear            OPT

        UPDATE    SFL01
        READC     SFL01

        Enddo
        Endsr

What should I do? Do I need to chain from logical file before UPDATE SUBFILE? Please help me. Thanks in advance


Solution

  • the indicator *in91 has to be specified as the EQ result indicator of the READC statement. Both READC statements. Or, replace the test for *in91 with a test of the built in %eof variable.

    c     OSR           Begsr                                               
    c                   ReadC     SFL01                                  91 
    c                   DOW       *IN91 = *OFF                              
    
    ** ------------------------- osr_eof -----------------------
    c     OSR_eof       Begsr                                   
    c                   ReadC     SFL01                         
    c                   DOW       %eof = '0'                    
                                                                
    c                   Select                                  
    c     OPT           WhenEQ    2                           
    c                   Exsr      UPDSR                         
    c     OPT           WhenEQ    4                           
    c                   Exsr      DLTSR                         
    c     OPT           WhenEQ    5                           
    c                   Exsr      DSPSR                         
    c                   Other                                   
    c                   Exsr      ERRSR                         
    c                   EndSL                                   
                                                                
    c                   Clear                   optn            
                                                                
    c                   UPDATE    SFL01                         
    c                   READC     SFL01                         
                                                                
    c                   Enddo