INTOUCH® 4GL
A Guide to the INTOUCH Language


Previous Contents Index

DESCRIPTION:

WHEN EXCEPTION USE begins the protected block of code and specifies the HANDLER routine to use. handl_name is the name of the handler routine. The handler name must meet the specifications for variable names. The protected block is everything between the WHEN EXCEPTION USE and the END WHEN statements. If an exception occurs in this block of code, INTOUCH calls the handler specified. If the handler does not exist, an error is generated.

HANDLER begins the handler routine. Everything between the HANDLER and the END HANDLER constitutes the handler routine. END HANDLER returns control to the statement following the END WHEN. When the handler is called, this block of code is executed. In the example above, INTOUCH would normally return an exception when it tried to divide 25.00 by 0. The exception handler FIX_AVERAGE intercepts this exception and sets AVERAGE equal to 0.

The handler routine can occur before or after the protected block. For example:


        10  HANDLER fix_average 
              average = 0               <--- handler routine 
              CONTINUE 
            END HANDLER 
 
        20  INPUT 'Enter total sales amount': tsales 
            INPUT 'Enter number of sales': nsales 
            WHEN EXCEPTION USE fix_average 
              average = tsales/nsales 
            END WHEN 
        30  PRINT 'The average is'; average 
        40  END 

One of the advantages of WHEN EXCEPTION USE is that the same handler routine can be called by any number of WHEN EXCEPTION USE statements. For example:


        10  WHEN EXCEPTION USE numbers 
              INPUT 'How old are you': age      <--- first protected block 
            END WHEN 
 
        20  INPUT 'Your name, please': name$ 
 
        30  WHEN EXCEPTION USE numbers 
              INPUT 'Your birthdate': birth     <--- second protected block 
            END WHEN 
 
        40  PRINT name$; ' was born on'; birth 
 
        50  HANDLER numbers 
              PRINT 'Enter numbers only, please.'    <--- handler routine 
              RETRY 
            END HANDLER 
        60  END 

12.4 HANDLER Routine Actions

12.4.1 RETRY

FORMAT:


        USE 
          --- 
          ---  RETRY 
          --- 
        END WHEN 
 
           or 
        
        HANDLER handl_name 
          --- 
          ---  RETRY 
          --- 
        END HANDLER 

EXAMPLE:


        10  INPUT 'Your name, please': name$ 
        20  WHEN EXCEPTION IN 
              INPUT 'How old are you': age 
            USE 
              PRINT 'Not a valid age' 
              RETRY 
            END WHEN 
        30  PRINT 
            PRINT name$; ' is'; age 
        40  END 
 
        RNH 
        Your name, please? Tester 
        How old are you? 3x 
        Not a valid age 
        How old are you? 35 
 
        Tester is 35 

PURPOSE:

Use RETRY after an exception to re-execute the statement that generated the exception.

DESCRIPTION:

RETRY can only be used in a HANDLER routine. RETRY causes INTOUCH to leave the handler and re-execute the statement that generated an exception.

12.4.2 CONTINUE

FORMAT:


        USE 
          --- 
          ---  CONTINUE 
          --- 
        END WHEN 
 
           or 
 
        HANDLER handl_name 
          --- 
          ---  CONTINUE 
          --- 
        END HANDLER 

EXAMPLE:


        10  INPUT 'Enter total sales amount': tsales 
            INPUT 'Enter number of sales': nsales 
        20  WHEN EXCEPTION USE fix_average 
              average = tsales / nsales 
            END WHEN 
        30  PRINT 'The average is:'; average 
 
        40  HANDLER fix_average 
              average = 0 
              CONTINUE 
            END HANDLER 
        50  END 
 
        RNH 
        Enter total sales amount? 18.00 
        Enter number of sales? 0 
        The average is: 0 

PURPOSE

Use CONTINUE to continue normal program execution at the statement following the one that generated the exception.

DESCRIPTION:

CONTINUE causes INTOUCH to exit the exception handler and continue program execution at the first statement following the statement which generated the exception. CONTINUE can only be used in a HANDLER routine.

12.4.3 RESUME

FORMAT:


        USE 
          --- 
          ---  RESUME target 
          --- 
        END WHEN 
 
           or 
 
        HANDLER handl_name 
          --- 
          ---  RESUME target 
          --- 
        END HANDLER 

EXAMPLE:


        10  INPUT 'Enter total sales amount': tsales 
            INPUT 'Enter number of sales': nsales 
        20  WHEN EXCEPTION USE fix_average 
              average = tsales / nsales 
            END WHEN 
        30  PRINT 'The average is:'; average 
 
        40  HANDLER fix_average 
              average = 0 
              PRINT 'Invalid numbers.  Try again.' 
              RESUME 10 
            END HANDLER 
        50  END 
 
        RNH 
        Enter total sales amount? 75.00 
        Enter number of sales? 0 
        Invalid numbers.  Try again. 
        Enter total sales amount? 75.00 
        Enter number of sales? 3 
        The average is: 25 

PURPOSE:

Use RESUME to resume normal program execution at the statement label that you specify.

DESCRIPTION:

RESUME causes INTOUCH to exit the exception handler and resume program execution at the target line specified. The target can be a line number or a label.

RESUME can only be used in a handler routine.

12.4.4 EXIT HANDLER

FORMAT:


        USE 
          --- 
          ---  EXIT HANDLER 
          --- 
        END WHEN 
 
           or 
 
        HANDLER handl_name 
          --- 
          ---  EXIT HANDLER 
          --- 
        END HANDLER 

EXAMPLE:


        10  WHEN EXCEPTION USE mistake 
              INPUT 'Enter your age': age 
            END WHEN 
            PRINT 'You are'; age; 'years old' 
 
        20  HANDLER mistake 
              PRINT 'Oops...' 
              DELAY 2 
              EXIT HANDLER 
            END HANDLER 
        30  END 
 
        RNH 
        Enter your age? 3x 
        Oops... 
        Non-numeric input when number expected at 10.1 
        Enter your age? 35 
        You are 35 years old 

PURPOSE:

Use EXIT HANDLER to exit a handler routine and pass the exception up to the next level of exception handling.

DESCRIPTION:

EXIT HANDLER exits the current HANDLER routine. If the current handler is nested within another handler, INTOUCH jumps to the outside handler and executes the code for that handler. If there is no other exception handler, control returns to the INTOUCH system. INTOUCH prints the exception message and takes whatever action it normally would.

EXIT HANDLER can only be used within an exception handler.


Chapter 13
Calling Routines Written In Other Languages

You can call routines written in other languages and run them from an INTOUCH program.

Callable routines are stored in libraries. The LIBRARY statement tells INTOUCH what library a routine is located in. You must use the LIBRARY statement to specify where routines are located before you call them in your program.

The CALL statement calls routines and executes them. You can call any routine in a shared OpenVMS library and execute it. The CALL and LIBRARY statements make your programs more powerful, more versatile, and give you more programming options.

13.1 LIBRARY

FORMAT:


        LIBRARY 'libr_name' 

EXAMPLE:


        10  LIBRARY 'BASRTL' 
        20  PRINT 'Waiting 5 seconds...' 
        30  CALL BAS$SLEEP(5% BY VALUE) 
        40  END 
 
        RNH 
        Waiting 5 seconds... 

DESCRIPTION:

You can use the LIBRARY statement to specify the libraries you will use in your program.

The LIBRARY statement specifies libraries from which you CALL routines. The routines can be written in any OpenVMS language that supports the standard calling interface (FORTRAN, BASIC, COBOL, etc.).

libr_name is the file specification of a library. The library can be one of the OpenVMS supplied libraries, or a user-defined library. You must name a library with the LIBRARY statement before you call a routine from it. The library name must be a string constant in quotes.

To create libraries for INTOUCH, you can refer to Appendix E, Creating Libraries for Use with INTOUCH.

13.2 CALL

FORMAT:


        CALL routine_name(arg [BY pass_mech], arg...) 

EXAMPLE:


        10  LIBRARY 'BASRTL' 
        20  PRINT 'Waiting 5 seconds...' 
        30  CALL BAS$SLEEP(5% BY VALUE) 
        40  END 
 
        RNH 
        Waiting 5 seconds... 

DESCRIPTION:

You can use the CALL statement to call and execute library routines. You can use these routines to perform procedures rather than writing the code yourself.

The library to which the routine belongs must have been specified in a LIBRARY statement.

routine_name is the name of the routine you are calling. Some routines take arguments. arg is an argument you are passing to or getting from the routine. If more than one argument is passed, separate the arguments with commas:


        CALL routine_name(arg, arg, arg...) 

13.2.1 Optional Arguments

Some routines have optional arguments--arguments which can be used, but do not have to be used. To pass an optional argument, include it in the appropriate place in the argument list. If you do not want to pass an optional argument, specify that no argument is to be used by typing two commas side by side at the appropriate place in the argument list.

For example, the routine LIB$GET_INPUT gets a record of ASCII text. Its argument list contains two optional arguments:


        LIB$GET_INPUT(get-str.wt.dx [,prompt-str.rt.dx [,out-len.wwu.r]]) 
                         |                 |                  | 
            string variable the      a prompt string        length of the 
            input is assigned to                           string variable 

To input a line without using a prompt string, your CALL statement would have the following format:


        CALL routine_name(str_var,,num_var) 

The double commas tell INTOUCH that the optional variable prompt-str is not used. For example:


        10  LIBRARY 'LIBRTL' 
            BUF$ = REPEAT$(' ', 200) 
            CALL LIB$GET_INPUT(BUF$, , OUT_LEN%) 
            PRINT 'You typed: ';BUF$[1:OUT_LEN%] 
        20  END 

13.2.2 Passing Mechanisms

pass_mech refers to the mechanism by which values are passed to the routine. The default passing mechanism for reals and integers is by reference. The default passing mechanism for strings is by descriptor. Here is an explanation of the passing mechanisms available:
BY REF By reference. This is the default passing mechanism for real and integer data. Arguments passed by reference can be changed by the routine they are passed to.
BY VALUE By value. Arguments passed by value cannot be changed by the routine they are passed to.
BY DESC By descriptor. This is the default passing mechanism for strings. By descriptor causes INTOUCH to use the argument's descriptor when passing the argument. Arguments passed by descriptor can be changed by the routine they are passed to.

The system functions _REAL and _INTEGER can be used in conjunction with the library statements. These functions return resulting data associated with the CALL. (See Section A.1, System Functions for more information.)


Chapter 14
Data Structure Statements

This chapter explains the INTOUCH data structure statements. One of the major features of INTOUCH is its ability to perform database operations as part of the language. The data structure statements allow you to manipulate data structures in your own programs.

List of Data Structure Statements:

14.1 General Information

INTOUCH's data management system stores data file information in structures. (Chapter 16, Creating Structures, Field Definitions with SETUP tells how structures are created.) A structure file contains the following information:

In INTOUCH, you address the structure file and not the dataset directly.

An INTOUCH structure is made up of records and fields. A structure looks something like this:


                                       FIELDS 
 
                           /              |                \
                          /               |                 \
                         /                |                  \
                        /                 |                   \
                       /                  |                    \
 
      R          Client         Last name                  First name 
      E          Number                                  
      C       +---------+---------------------------+-------------------+ 
      O _____ |8|0|5|4|3|C|a|s|s| | | | | | | | | | |C|a|t|h|y| | | | | | 
      R _____ |8|0|5|4|2|B|r|o|c|k| | | | | | | | | |B|u|d| | | | | | | | 
      D       | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 
      S 
                                     positions 

In the above example, the records are the horizontal lines of information. In the CLIENT structure above, there is a record for each customer.

Each record consists of fields. For example, the customer records alone might contain a field for the customer's ID number, last name, first name, address, phone number, company name, etc. Each of these pieces of data is stored in its own field--the name field, address field, phone number field, etc.. The fields appear as columns in the diagram above.

To reference a field, you indicate the structure and the field you want. The field name is enclosed in parentheses.


        struc_name(field_name) 

struc_name is the name associated with the structure. field_name is the name of a field in the structure. INTOUCH searches for the field specified in the current record and reads its contents.


        10  OPEN STRUCTURE cl: NAME 'tti_run:client' 
        20  EXTRACT STRUCTURE cl: KEY ID = '80522' 
              PRINT cl(last), cl(first) ! Print last and first 
                                        ! fields from the CL structure 
            END EXTRACT 
            CLOSE STRUCTURE cl 
        30  END 
 
        RNH 
        Errant             Earl 

The remainder of this chapter describes the data structure statements and how to use them.

14.2 OPEN STRUCTURE

FORMAT:


        OPEN STRUCTURE struc_name: NAME 'struc_filename' 
          [, ACCESS INPUT | OUTIN] [, LOCK] [, DATAFILE filename] 
          [, OPTIMIZE OFF] 

EXAMPLE:


        10  OPEN STRUCTURE cl: NAME 'tti_run:client', & 
              ACCESS INPUT, LOCK    
        20  EXTRACT STRUCTURE cl 
              INCLUDE cl(state) = 'CA' 
              EXCLUDE cl(phone)[1:3] = '619' 
              SORT ASCENDING BY cl(last) 
            END EXTRACT 
        30  PRINT 'List of California clients by last name' 
            FOR EACH cl 
              PRINT cl(first); ' '; cl(last), cl(phone) 
            NEXT cl 
        40  CLOSE STRUCTURE cl 
        50  END 
 
        RNH 
        List of California clients by last name 
        Dale Derringer      (818) 223-9014 
        Earl Errant         (408) 844-7676 

DESCRIPTION:

The OPEN STRUCTURE statement is used to open a data structure. The structure must be open in order to reference data in the structure (i.e. change field data, add or delete records). struc_name is a name (i.e. nickname) you assign to the structure. You use this name to refer to the structure within the program. The structure name must be unique within the program or program system. If the structure name is associated with another open structure, an exception is generated. The structure name must meet the requirements for variable names.

After the keyword NAME, is the file specification of the structure file being opened. (See Chapter 16, Creating Structures, Field Definitions with SETUP for information on legal structure file names.) The file specification can be any valid string expression.

The ACCESS option tells INTOUCH whether to open the structure for input (reading field data) or for input and output (reading, changing and adding field data). ACCESS input is the default open mode for structures, meaning, that if no ACCESS option is provided, INTOUCH opens the structure for INPUT.

When INTOUCH executes the OPEN statement, it searches for the structure file specified. INTOUCH opens the structure and assigns it the structure name. If the structure file does not exist, an exception is generated.

14.2.1 ACCESS Option

The ACCESS option determines how you can access the structure.

The access options are:

14.2.2 LOCK Option

The LOCK option causes INTOUCH to lock the structure from write access by others. As long as the structure is open, the structure cannot be modified by others. This can speed up INTOUCH's structure statements (EXTRACTs especially). The particular effect depends on the file management system being used.

14.2.3 DATAFILE Option

The DATAFILE option overrides the default datafile as specified by the structure.

FORMAT:


        DATAFILE file_spec 

file_spec is the file specification of the data file you want to open. The file_spec can be any string expression.

14.3 CLOSE STRUCTURE struc_name

FORMAT:


        CLOSE STRUCTURE struc_name 

EXAMPLE:


        10  OPEN STRUCTURE cl: NAME 'tti_run:client' 
        20  EXTRACT STRUCTURE cl 
              INCLUDE cl(state) = 'CA' 
              EXCLUDE cl(phone)[1:3] = '619' 
              SORT ASCENDING BY cl(last) 
            END EXTRACT 
        30  PRINT 'List of California Clients' 
            FOR EACH cl 
              PRINT cl(first); ' '; cl(last), cl(phone) 
            NEXT cl 
        40  CLOSE STRUCTURE cl 
        50  END 
 
        RNH 
        List of California Clients 
        Dale Derringer      (818) 223-9014 
        Earl Errant         (408) 844-7676 


Previous Next Contents Index