Some programmers like to code validation logic into subroutines, and do not easily accept the LANSA approach of:

     request <<data>>
    begincheck
    <<validate>>
    endcheck

Unable to resist the urge to use a subroutine they soon change the program to be like this:

     dountil #errors = n
    request <<data>>
    execute validate
    enduntil
 
    subroutine validate
    begincheck
    <<validate>>
      if_error
      change #errors Y
      else
      change #errors N
      endif
    endcheck
    endroutine

and are surprised when the whole program aborts

The reason is that the ENDCHECK command, by default, returns control to the last display (if it can be found in same routine), otherwise it aborts the program.

In this subroutine the ENDCHECK command has no last display to return control to, so it aborts. If you must code validation routines, the best structure is probably something like the following:

     dountil #errors = 0
    request <<data>>
    execute validate
    enduntil
 
    subroutine validate
    change #errors 0
    begincheck keep_count(#errors)
    <<validate>>
    endcheck if_error(*next)
    endroutine
  • No labels