Writing $Functions with Your Own Error Messages - Rocket Software
Writing $Functions with Your Own Error Messages - Rocket Software
Writing $Functions with Your Own Error Messages - Rocket Software
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>Writing</strong> <strong>$Functions</strong> <strong>with</strong> <strong>Your</strong> <strong>Own</strong> <strong>Error</strong> <strong>Messages</strong><br />
In the $INSCHAR source listing, I have added code to test the string argument to<br />
enforce those two rules:<br />
1) The argument must be exactly 10 bytes<br />
2) The argument must be numeric: digits 0-9<br />
The Modified $INSCHAR Code<br />
The blue lines of code below were added to implement error checking.<br />
**$INSCHAR Receives a numeric character string (ARG1) of length 10<br />
* and returns that character string <strong>with</strong> the single<br />
* character (ARG2) inserted in col 4 and col 7 of ARG1.<br />
* Col: 4 7<br />
* | |<br />
* v v<br />
* ARG1: 1234567890<br />
* ARG2: _ (DEFAULT)<br />
*<br />
* RETURN: 123_456_7890<br />
$INSCHAR ENTER<br />
MVC BUF2(1),INSDEFC Get default character for insert<br />
ARG 2,NOARG=INSDEF If ARG2 not provided, use default<br />
L R2,4(X1) Type of ARG - required for RTSTRL<br />
CCALL RTSTRL Call ReTurn STRing <strong>with</strong> Length<br />
* Returns A(ARG2)-1 in R1 and len in R2<br />
MVC BUF2(1),1(R1) Move ARG2 (char for insert) to BUF2<br />
INSDEF ARG 1,NOARG=INSDONE If ARG1 not provided, return null<br />
L R2,4(X1) Type of ARG - required for RTSTRL<br />
CCALL RTSTRL Returns A(ARG1)-1 in R1 and len in R2<br />
C R2,=F'10' Is length of ARG1 exactly 10 bytes?<br />
BNE INSERR1 No, issue error<br />
* Ensure ARG1 is numeric only<br />
MVC BUF1(10),1(R1) Move ARG1 to BUF1<br />
L X1,KAPFF A(KZFF) = 256 foxes<br />
MVC KAJUNK(256),0(X1) Setup table for Translate and Test<br />
MVC KAJUNK+C'0'(C'9'-C'0'+1),KA00 Get zeroes for numbers<br />
BCTR R2,0 Subtract one from length<br />
EX R2,$INSNUM TRT BUF1(0),KAJUNK<br />
IF BNZ If non-numeric character found<br />
ERROR 2,OPT=USER String must be numeric 0-9<br />
B INSDONE Set len of ret string to 0 and return<br />
IFEND<br />
LA R2,10 Get len back in R2<br />
MVC BUF1(20),KA00 Clear BUF1<br />
MVC BUF1(3),1(R1) Move 1st 3 chars of ARG1 to BUF1<br />
MVC BUF1+3(1),BUF2 Insert ARG2<br />
MVC BUF1+4(3),4(R1) Move next 3 chars of ARG1 to BUF1<br />
MVC BUF1+7(1),BUF2 Insert ARG2<br />
S R2,=F'6' Subtract (3+3) bytes from ARG1 length<br />
EX R2,$INSMVC Move rest of ARG1 to BUF1<br />
A R2,=F'8' Get new len of ARG1(6+2+rest of ARG1)<br />
LA R1,BUF1-1 Get A(BUF1) minus 1<br />
B INSRET<br />
INSERR1 ERROR 1,OPT=USER String length must be 10 bytes<br />
INSDONE SR R2,R2 No ARG1, set return string len to 0<br />
<strong>Rocket</strong> M204 April 2009<br />
2 of 4