25.02.2013 Views

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

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Writing</strong> <strong>$Functions</strong> <strong>with</strong> <strong>Your</strong> <strong>Own</strong> <strong>Error</strong> <strong>Messages</strong><br />

A Newsletter Excerpt for Model 204 Users<br />

April 2009<br />

USE OF AND ACCESS TO PRODUCTS AND FEATURES ARE IN ACCORDANCE WITH THE TERMS AND<br />

CONDITIONS OF THE USER’S SOFTWARE LICENSE. THE PRESENTATION OF MATERIAL HEREIN DOES NOT, IN<br />

ANY MANNER, MODIFY SUCH TERMS AND CONDITIONS.<br />

<strong>Writing</strong> <strong>$Functions</strong> <strong>with</strong> <strong>Your</strong> <strong>Own</strong> <strong>Error</strong> <strong>Messages</strong><br />

By James Damon<br />

In the February 2009 issue of <strong>Rocket</strong> M204, I showed you how to write your own<br />

$function in IBM Assembly Language, assemble that $function in the FUNU control section,<br />

and link-edit FUNU into the Model 204 nucleus using ONLINE or BATCH204 load<br />

modules. Once that is done, you can call your $function from User Language to perform<br />

special processing. The example I provided, $INSCHAR, however, was incomplete. It<br />

had no error detection or error reporting facilities to indicate to the user that an input<br />

value to the $function was incorrect. In this article I will show you how to add your own<br />

error messages to the MSGU control section, then assemble and link-edit that control<br />

section into the Model 204 nucleus.<br />

MSGU Control Section<br />

As <strong>with</strong> the source listing for the FUNU control section, the MSGU control section is also<br />

found in MACLIB, which is distributed <strong>with</strong> each release on the Model 204 installation<br />

tape. It is probably named something like M204.rlse.MACLIB, where rlse=V710, V610 or<br />

V510. I will not reprint the entire source listing for MSGU here, just the part that involves<br />

defining user error messages:<br />

ESTRT USER=YES,PREFIX=USER<br />

* REPLACE THIS DUMMY MESSAGE WITH ONE OR MORE USER MESSAGES<br />

EDEF 1,0000,I,,,'DUMMY MESSAGE' **********<br />

For the $INSCHAR function, I’ve added the following two error messages (in blue):<br />

ESTRT USER=YES,PREFIX=USER<br />

* REPLACE THIS DUMMY MESSAGE WITH ONE OR MORE USER MES-<br />

SAGES EDEF 1,0000,I,,,’String length must equal 10 bytes’<br />

EDEF 2,0000,I,,,’String must be numeric 0-9’<br />

<strong>Rocket</strong> M204 April 2009 1 of 4


<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


<strong>Writing</strong> <strong>$Functions</strong> <strong>with</strong> <strong>Your</strong> <strong>Own</strong> <strong>Error</strong> <strong>Messages</strong><br />

INSRET LEAVESTR Return the new string or null<br />

INSDEFC DC C'_' Default character for insert<br />

$INSNUM TRT BUF1(0),KAJUNK TRT to detect non-numeric data<br />

$INSMVC MVC BUF1+8(0),7(R1) Remainder of ARG1 starting column 7<br />

LTORG<br />

EJECT<br />

Assemble and Link-Edit Both FUNU and MSGU<br />

After you have updated the FUNU and MSGU source listings in the Model 204 macro<br />

library, M204.rlse.MACLIB, you can use the FUNUASM and MSGUASM jobs in the<br />

JCLLIB dataset to reassemble those control sections and place the new object decks in<br />

M204.rlse.OBJLIB. Remember, however, that you must set these options to ‘Y’ in<br />

INSPARMS during the installation process, or the FUNUASM and MSGUASM jobs will<br />

not be created:<br />

FUNC-USER=Y ** Enable USER-WRITTEN functions<br />

MSG-USER=Y ** Enable USER-WRITTEN messages<br />

Following successful assembly, the M204RLNK or similar job can be used to link those<br />

two control sections from M204.rlse.OBJLIB into the ONLINE and BATCH204 load<br />

modules.<br />

Testing $INSCHAR<br />

The following examples show the results <strong>with</strong> the error checking code and the new error<br />

messages assembled into MSGU. In the first example the procedure supplies the<br />

telephone number to $INSCHAR as a literal.<br />

BEGIN<br />

PRINT $INSCHAR('7814666601','.')<br />

END<br />

INCLUDE 0<br />

781.466.6601<br />

<strong>Rocket</strong> M204 April 2009<br />

3 of 4


<strong>Writing</strong> <strong>$Functions</strong> <strong>with</strong> <strong>Your</strong> <strong>Own</strong> <strong>Error</strong> <strong>Messages</strong><br />

In this next example the procedure retrieves three telephone numbers from three<br />

different records in a Model 204 database and passes them to $INSCHAR from the field<br />

TELNO.<br />

BEGIN<br />

FR WHERE TELNO IS LIKE *<br />

PRINT<br />

PRINT TELNO<br />

PRINT $INSCHAR(TELNO,'-')<br />

END<br />

INCLUDE 0<br />

800755422<br />

*** USER.0001: String length must equal 10 bytes<br />

3037868%62<br />

*** USER.0002: String must be numeric 0-9<br />

8005551212<br />

800-555-1212<br />

MSGCTL Command for User <strong>Messages</strong><br />

The MSGCTL command can be used to change the default action taken when a userdefined<br />

message is issued just as it can be used to change that action for Model 204<br />

defined messages. If you need a CCASNAP to be generated when one of your error<br />

messages is issued, you may want to use the MSGCTL command like this:<br />

MSGCTL USER.0001 SNAPPDL<br />

See the description of the MSGCTL command in the Model 204 Parameter and<br />

Command Reference for further details.<br />

Summary<br />

Without error checking we really did not have a useful $function. Now that we have<br />

added the appropriate error messages and error checking code, we have a complete<br />

$function. It inserts a separator into a character string of numbers and it also can detect<br />

and report errors in that string.<br />

<strong>Rocket</strong> M204 April 2009<br />

© 2009 <strong>Rocket</strong> M204<br />

77 Fourth Avenue, Waltham, MA 02451<br />

4 of 4

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!