It would be useful to be able to validate data in a subroutine the same way that SB+ does in a field.

The long way is to use the execute routine:

CALL SB.PROCESS("V:CUSTOMER.ID.VAL")
IF RTN.FLAG NE 0 THEN

...error code...
END

Or for a quicker method you can use the routine SB.VALIDATE to do this.

VALUE = 1234567
VALIDATE.TXT = "F:FILE.NAME,DESCRIPTION,Y{}"
CALL SB.VALIDATE(VALIDATE.TXT)
IF RTN.FLAG NE 0 THEN

...error code...
END

Where:

  • VALUE – The value to validate.
  • VALIDATE.TXT param – The validation to perform. The empty string error message {} stops an error being displayed to the user.
  • RTN.FLAG – 0 if validated else 1 if an error.

This becomes most useful when you have a standardized validation process which you may want to use in your own code:

VALUE = 1234567
VALIDATE.TXT = "C:CUSTOMER.ID.VAL"
CALL SB.VALIDATE(VALIDATE.TXT)
IF RTN.FLAG NE 0 THEN

...error code...
END

Which method to use? Calling the SB.PROCESS routine is going to work as it is a documented option. The SB.VALIDATE routine does not seem to be documented, so it could change or disappear over time…

Be weary though, if the validation process has an error message, it will be displayed.