ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Validate fields after pressing ENTER

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Validate fields after pressing ENTER

    I have a typical screen with about 10 fields. The first 4 fields need to be validated against some tables. Each field should chain to a file and if the chain is %FOUND then it should continue to the next field, but at the present it doesn't. I can do the typical CHECK keyword and validate against ranges, etc, but I need a bit more with these 4 fields.

    I need to enter a value, press enter, having the value chain against a table, return to the screen and not let me continue to enter more data until the field has valid data. If the data is invalid because the data was not found, I want to stay on the field until valid data is entered and validated against a table or F3 or F12 is entered to completely exit.

    Right now,I am entering data, pressing enter and putting in dummy data into the table if the user entered invalid data. This was fine for a bit until the amount of data grew too much.

    I tried "repainting" the screen after I pressed enter to return control to the program which validated and then "repainted" the screen again to show results; however, this started getting out of control and the code turned into a mess.

    I know this can be done, but how?

    Any advice is greatly appreciated.

  • #2
    Re: Validate fields after pressing ENTER

    Post the section of code you have and we'll take a look.
    "Time passes, but sometimes it beats the <crap> out of you as it goes."

    Comment


    • #3
      Re: Validate fields after pressing ENTER

      I think I would display a screen with the first 4 fields only, validate, then either re-display or display another screen overlaying with the other 6 fields. This way they can't enter any data in fields 5-10 until I have validated.

      Comment


      • #4
        Re: Validate fields after pressing ENTER

        Put the CHANGE(nn) keyword on the field with the CHECK(ER) (End of Record) to simulate the Enter key. When the user fills up the field or Field Exit is pressed, the CHECK(ER) acts as the Enter key. If the user entered something in the field it would switch on the change indicator. If the indicator is off or the field is blank the user didn't change or did erase the field and you can take appropriate action against the tables.
        Philippe

        Comment


        • #5
          Re: Validate fields after pressing ENTER

          Another option would be to check out this simple example on message subfiles...and gleen what you need



          jamie
          All my answers were extracted from the "Big Dummy's Guide to the As400"
          and I take no responsibility for any of them.

          www.code400.com

          Comment


          • #6
            Re: Validate fields after pressing ENTER

            Low tech solution, I use CL with a display file, and if ANY of my validations fails I set a &CHK variable to on, then if at the end the &CHK is on then do not proceed and retrurn to the display file displaying the last validation error found. It will do this until all validations are passed, at which time the enter key will prompt the user to "Press F6 to Submit".

            PHP Code:
                         PGM                                                               
                                                                                           
                         DCL        
            VAR(&CHK)    TYPE(*CHARLEN(1)                        
                         
            DCL        VAR(&UPS)    TYPE(*CHARLEN(10)                       
                         
            DCL        VAR(&JRLASPTYPE(*DEC)  LEN(2 0)                      
                         
            DCLF       FILE(ENVADDDF)                                         
                                                                                           
                                                                                           
            /* --------- Setup Variables etc ----------------------------------- */        
                         
            CRTDTAARA  DTAARA(QTEMP/ENVMNGTYPE(*CHARLEN(5VALUE('     '
                         
            MONMSG     MSGID(CPF0000)                                         
                         
            RTVDTAARA  DTAARA(ENVMNGRTNVAR(&ENV)                            
                         
            CHGVAR     VAR(&OWNER)   VALUE(' ')                         
                         
            CHGVAR     VAR(&ASSN)    VALUE(' ')                         
                         
            CHGVAR     VAR(&ENVASP)  VALUE(' ')                         
                         
            CHGVAR     VAR(&REL)     VALUE('I321')                      
                         
            CHGVAR     VAR(&PGMQ)    VALUE('ENVADDC1')                  
                         
            CHGVAR     VAR(&CRTLIB)  VALUE('N')                         
                         
            CHGVAR     VAR(&CRTAUT)  VALUE('N')                         
                         
            CHGVAR     VAR(&CHGAUT)  VALUE('N')                         
                         
            CHGVAR     VAR(&CRTNVM)  VALUE('N')                         
                         
            CHGVAR     VAR(&CHK)     VALUE('0')                         
                         
            RMVMSG     PGMQ(*SAME)   CLEAR(*ALL)                        
                                                                                     
            /* --------- Send and Receive to Display File ENVADDDF ------------- */  
             
            SNDRCVF:    SNDF       RCDFMT(FORMC1)                                   
                         
            MONMSG     MSGID(CPF0000EXEC(RCVMSG)                      
                         
            SNDRCVF    RCDFMT(FORMAT01)                                 
                         
            CHGVAR     VAR(&CHK)    VALUE('0')                          
                         
            RMVMSG     PGMQ(*SAME)  CLEAR(*ALL)                         
                                                                                     
            /* --------- If F3/F12 is pressed then cancel and exit. ------------ */  
                         
            IF         COND(&IN03THEN(GOTO CMDLBL(ENDPGM))            
                         IF         
            COND(&IN12THEN(GOTO CMDLBL(ENDPGM))            
                                                                                     
            /* --------- Validate the Parameters entered. ---------------------  */                
                                                                                                   
            /*           ALL                                                     */                
            /*           Validate that something is selected                     */                
                         
            IF         COND((&CRTLIB *NE 'Y') *AND (&CRTAUT *NE 'Y') +                
                                    *AND (&
            CHGAUT *NE 'Y') *AND (&CRTNVM *NE 'Y')) THEN(DO)        
                           
            SNDPGMMSG  MSG('At least one option must be selected Y.'TOPGMQ(*SAME
                           
            CHGVAR     VAR(&CHKVALUE('1')                                         
                         
            ENDDO                                                                     
                                                                                                   
            /*           Validate for all options.                               */                
            /*           Validate the Environment Name is not blank              */                
                         
            IF         COND(&ENV *EQ ' 'THEN(DO)                                    
                           
            SNDPGMMSG  MSG('Environment Name must be entered.'TOPGMQ(*SAME)       
                           
            CHGVAR     VAR(&CHKVALUE('1')                                         
                         
            ENDDO                                                                     
            /*           Environment cannot be GICMS or LICMS.                   */                
                         
            IF         COND((&ENV *EQ 'GICMS') *OR (&ENV *EQ 'LICMS')) THEN(DO)       
                           
            SNDPGMMSG  MSG('You cannot process the Add environment +                
                                      command over this environment'
            )                              
                           
            CHGVAR     VAR(&CHKVALUE('1')                                         
                         
            ENDDO                                                                     
                                                                                                   
            /*           CRTNVM CRTLIB                                           */                
                         
            IF         COND((&CRTNVM *EQ 'Y') *OR (&CRTLIB *EQ 'Y')) THEN(DO)  
              
            /*           Validate the Description is not blank                   */       
                           
            IF         COND(&ASSN *EQ ' 'THEN(DO)                          
                             
            SNDPGMMSG  MSG('Description must be entered'TOPGMQ(*SAME)    
                             
            CHGVAR     VAR(&CHKVALUE('1')                                
                           
            ENDDO                                                            
                         ENDDO                                                              
                                                                                            
            /*           CRTNVM                                                  */         
                         
            IF         COND(&CRTNVM *EQ 'Y'THEN(DO)                          
              
            /*           Validate the Release is not blank                       */       
                           
            IF         COND(&REL *EQ ' 'THEN(DO)                           
                             
            SNDPGMMSG  MSG('Release Number Must be entered'TOPGMQ(*SAME
                             
            CHGVAR     VAR(&CHKVALUE('1')                                
                           
            ENDDO                                                            
                         ENDDO                                                              
                                                                                            
            /*           CRTNVM CRTLIB                                           */         
                         
            IF         COND((&CRTNVM *EQ 'Y') *OR (&CRTLIB *EQ 'Y')) THEN(DO)  
              
            /*           Validate the ASP is not blank                           */       
                           
            IF         COND(&ENVASP *EQ ' 'THEN(DO)                        
                             
            SNDPGMMSG  MSG('Database ASP must be entered.'TOPGMQ(*SAME)  
                             
            CHGVAR     VAR(&CHKVALUE('1')                                
                           
            ENDDO                                                            
                         ENDDO                                                               
                                                                                             
            /*           CRTNVM CHGAUT                                           */          
                         
            IF         COND((&CRTNVM *EQ 'Y') *OR (&CHGAUT *EQ 'Y') +           
                                     *OR (&
            CRTAUT *EQ 'Y')) THEN(DO)                         
              
            /*           Validate the Owner is not blank                         */        
                           
            IF         COND(&OWNER *EQ ' 'THEN(DO)                          
                             
            SNDPGMMSG  MSG('Owners User ID cannot be blank.'TOPGMQ(*SAME
                             
            CHGVAR     VAR(&CHKVALUE('1')                                 
                           
            ENDDO                                                             
              
            /*           Validate the Owner exists                               */        
                           
            IF         COND(&OWNER *NE ' 'THEN(DO)                          
                             
            RTVUSRPRF  USRPRF(&OWNERSTATUS(&UPS)                          
                             
            MONMSG     MSGID(CPF2204EXEC(CHGVAR VAR(&UPS) +               
                                        
            VALUE('*NO_EXIST'))                                  
                             IF         
            COND(&UPS *NE '*ENABLED'THEN(DO)                   
                               
            SNDPGMMSG  MSG('Owners User ID does not exist, or +           
                                          is *DISABLED.'
            TOPGMQ(*SAME)                      
                               
            CHGVAR     VAR(&CHKVALUE('1')                               
                             
            ENDDO                                                           
                           ENDDO                                                             
                         ENDDO                                                               
            /*           ------------------------------------------------------- */          
                                                                                             
            /* --------- If any validation failed then go and try again. ------- */     
                         
            IF         COND(&CHK *EQ '1'THEN(GOTO CMDLBL(SNDRCVF))       
                                                                                        
            /* --------- If F6 is not pressed then prompt to press F6 ---------- */     
                         
            IF         COND(&IN06 *EQ '0'THEN(DO)                        
                           
            SNDPGMMSG  MSG('Press F6 to Add Environment'TOPGMQ(*SAME)  
                           GOTO       
            CMDLBL(SNDRCVF)                                   
                         
            ENDDO                                                          
                                                                                        
                                                                                        
            /* --------- If F6 is pressed then ask for F6 to confirm. ---------- */     
                         
            IF         COND(&IN06THEN(DO)                                
                           
            SNDRCVF    RCDFMT(CONFIRM)                                   
              
            /* --------- If F6 is confirmed then continue ---------------------- */   
                           
            IF         COND(&IN06THEN(DO)                              
                             
            CHGDTAARA  DTAARA(ENVMNGVALUE(&ENV)                      
                             
            CALL       PGM(ENVADDC2PARM(&ENV &ASSN &ENVASP &REL +    
                                        &
            OWNER &CRTLIB &CRTAUT &CHGAUT &CRTNVM)         
                           
            ENDDO                                                        
              
            /* --------- Else if no F6 to confirm then go back to display file.  */   
                           
            ELSE       CMD(GOTO CMDLBL(SNDRCVF))                         
                         
            ENDDO                                                          
            /* ----------------------------------------------------------------- */  
                                                                                      
                                                                                     
            /* --------- End of Program ---------------------------------------- */  
                                                                                     
            ENDPGM:                                                                  
                         
            ENDPGM 
            Could also be done in RPGLE directly, so the CHAIN can be used inside the same code for the validation steps, I use the CL as my entry point so I haven't coded an example in RPGLE yet.

            GC
            Greg Craill: "Life's hard - Get a helmet !!"

            Comment

            Working...
            X