INTOUCH® 4GL
Application Development Guide


Previous Contents Index

5.3 Checking for _BACK and _EXIT

You can determine if a user has backed up or exited in an INTOUCH application by checking the _BACK and _EXIT internal variables.

Example


        1   program application_5_3 
        10  clear 
        20  do 
              print 
              input 'What is the current month': answer$ 
              if  _back or _exit  then  exit do 
              print 
              input 'What is the current year': answer$ 
              if  _back  then  repeat do 
              if  _exit  then  exit do 
            loop 
        30  print 
            print 'The End' 
        40  end 



 
What is the current month? May 
 
What is the current year? \
 
What is the current month? June 
 
What is the current year? exit 
 
The End 
 

5.4 Changing Key Values

When you are in INTOUCH, you can change any of the current keystroke concepts and values to other concepts and values. For example, you could change the "A" key to the value of "1" or to no value at all. You could also change "A" to the ASCII value CHR$(127) and the concept of "DEL".

Before you change any of the key values, you normally save the keyboard map. The keyboard map is a collection of the current keystroke concepts and values. The ASK/SET WINDOW: KEYMAP statements are used to save and restore keyboard maps.

Note

Changes to the keyboard map are only effective while in the INTOUCH environment.

Example

This example shows how to change key values and concepts. The values of some characters and digits are changed and then the original values are restored. The _IGNORE internal variable can be used to give keys no value at all.


        1   program application_5_4 
        10  clear 
            print at 1,1:; 
        20  input 'What is your Name': answer$ 
            input 'What is your Social Security No': answer$ 
            print 
        30  set window keystroke 'a,e,i,o,u,y': value '*' 
            set window keystroke '0,2,4,6,8': value '_ignore' 
            set window keystroke 'q': value '_exit' 
        40  message 'a,e,i,o,u,y are changed to "*", 0,2,4,6,8 will be ignored' 
            line input 'What is your Name': answer$ 
            line input 'What is your Social Security No': answer$ 
            message 'The value of the "Q" key has been changed to EXIT' 
            line input 'Press the "Q" key': answer$ 
            print 
        50  ask window: keymap save_map$ 
            set window: keymap '' 
            message 'The changed key values have been saved and the original ' & 
                         + 'values restored' 
            line input 'What is your Name': answer$ 
            line input 'What is your Social Security No': answer$ 
            line input 'Press the "Q" key and the "Return" key': answer$ 
        60  set window: keymap save_map$ 
            message 'The "CHANGED" key values have been restored' 
            print 
            line input 'What is your Name': answer$ 
            line input 'What is your Social Security No': answer$ 
            line input 'Press the "Q" key': answer$ 
        70  set window: keymap '' 
            message 'The original key values have been restored' 
        80  end 



What is your Name? sandy 
What is your Social Security No? 123456789 
 
What is your Name? s*nd* 
What is your Social Security No? 13579 
Press the "Q" key? EXIT 
 
What is your Name? sandy 
What is your Social Security No? 123456789 
Press the "Q" key and the "Return" key? q 
 
What is your Name? s*nd* 
What is your Social Security No? 13579 
Press the "Q" key? EXIT 
 
 
 
 
                   The original key values have been restored 

5.5 Supported Keys, Keystroke Combinations

INTOUCH supports several keystroke combinations, which bear special meaning and are valuable when creating applications around user input.


Chapter 6
Working with INTOUCH Data Structures

INTOUCH STRUCTURES are made up of records and fields. Each record consists of one or more fields. The INTOUCH data structure statements allow you to manipulate data stored in the fields from within your programs.

An INTOUCH structure file has the extension, STR (file_name.STR), and contains:

6.1 Creating Structures

INTOUCH structures are easy to create. At the INTOUCH prompt, type the words CALL SETUP.



  INTOUCH 
 
  CALL SETUP 

This will put you into the INTOUCH SETUP routine where you can create structures and define fields. You can also modify existing structures and fields. You will be asked for:

The SETUP routine then allows you to:

Note

You can refer to the "SETUP" chapter in the INTOUCH - A Guide to the Language manual for detail information on structures and fields.

6.2 Opening and Closing Structures

Structures can be opened and closed. Depending on the access mode, structure records can be read, written out, changed and deleted.

The OPEN STRUCTURE statement opens a structure and the CLOSE STRUCTURE statement closes a structure. CLOSE ALL will close any open structures and any other open files.

The OPEN STRUCTURE statement has several options (i.e. lock, datafile, etc.). You can refer to the INTOUCH - Guide to the Language manual for more information on OPEN and other structure statements.


        open structure catalog: name 'catalog', access outin 
 
        open structure cust: name 'user:[tester]customer', access output 
 
        open structure cl: name 'tti_run:client' 
                       |             |              | 
                 structure name      |              | 
                            file specification      | 
                                              access mode

structure name is the name you will use in your application to refer to fields in the structure. This name can be the same as the file specification or a shortened version (i.e. nickname). It is best to use a name that relates to the file specification as opposed to using file_1, file_2, etc. so you can easily identify the file throughout your application.

file specification is the actual name of the data file. This name can include the device and directory or logical which tells where the data file is located.

access mode tells how the data file will be used. The access modes are INPUT, OUTPUT and OUTIN. If no access is specified, the default is INPUT.

6.3 Referencing Structure Data

After you have created your structure and defined the fields, you can reference the field data in the structure using structure references.

To reference a field, you indicate the structure name and the expression of the field whose contents you want to access.


                struc_name(field_expr) 

struc_name is the name associated with the structure. field_expr is the name of a field in the structure. When you reference a field, INTOUCH searches the current record for the field and reads its contents. Some examples of structure references are:


                CL(PHONE)          CATALOG(PART_NUM) 

The field_expr can be either a string or numeric expression.

You can use a string constant to specify the field name. If you give the field name as a string constant, you need not enclose it in quotes. INTOUCH will use the string constant as the field name:


                      PRINT CL(LAST) 
                                / 
           the field is specified by its field name

If you specify the field as an expression, you must precede the expression with a pound sign (#). The pound sign tells INTOUCH that the following characters are an expression, not the field name. If you do not include the pound sign, INTOUCH will interpret the characters as a field name.

Here are two examples:


                     PRINT CL(#FIELDNAME$) 
                                 / 
          the field is specified by the variable FIELDNAME$
 
 
                     PRINT CL(#FIELDNUM) 
                              / 
          the field is specified by the variable FIELDNUM

The following examples show how to open and close a structure and how to use field names and field expressions.

Example A

If you know what fields you want to process, you can reference the data by the field names.


        1   program application_6_1 
        10  clear 
            open structure cl: name 'tti_run:client' 
        20  extract structure cl 
              print cl(last), cl(first), cl(phone) 
            end extract 
        30  close structure cl 
        40  end 



  Smith               Sam                 (809) 555-8789 
  Kent                Keith               (619) 967-5021 
  Johnson             Paul                (619) 489-5551 
  Waters              Wayne               (619) 564-1231 
  Rodrigues           Homero              (   )    -   0 
  Donaldson           George              (   )    -   0 
  Errant              Earl                (408) 844-7676 
  Abott               Al                  (202) 566-9892 
  Brock               Bud                 (218) 555-4322 
  Cass                Cathy               (619) 743-8582 
  Porter              Pete                (619) 778-6709 
  Derringer           Dale                (818) 223-9014 
  Farmer              Fred                (305) 552-7872 

Example B

If you do not know what fields you want to process, you can reference the data using field expressions.


        1   program application_6_2 
        10  open structure cl: name 'tti_run:client' 
        20  do 
            clear 
            print at 1, 1:; 
              gosub ask_fields 
              if  _back  or  _exit  then  exit do 
              gosub show_data 
            loop 
            close structure cl 
            stop 
 
        30  ask_fields: 
            do 
              if  _error  then  set error off 
              print 'Field List:  '; & 
                      'ID, LAST, FIRST, MIDDLE, STREET, CITY, STATE, ZIP, PHONE' 
              print 
              line input 'Select fields to display': field_list$ 
              if  _back  or  _exit  then exit do 
              for f = 1 to elements(field_list$) 
                field$ = element$(field_list$, f) 
                ask structure cl, field #field$: number z 
                if  z = 0  then 
                  message error: 'Illegal field: '; field$ 
                end if 
              next f 
        40  loop while _error 
            return 
 
        50  show_data: 
            print 
            extract structure cl 
              for f = 1 to elements(field_list$) 
                field$ = element$(field_list$, f) 
                print cl(#field$), 
              next f 
              print 
        60  end extract 
            delay 
            return 
        70  end 



Field List:  ID, LAST, FIRST, MIDDLE, STREET, CITY, STATE, ZIP, PHONE 
 
Select fields to display? last,first,phone 
 
Smith               Sam                 (809) 555-8789 
Kent                Keith               (619) 967-5021 
Johnson             Paul                (619) 489-5551 
Waters              Wayne               (619) 564-1231 
Rodrigues           Homero              (   )    -   0 
Donaldson           George              (   )    -   0 
Errant              Earl                (408) 844-7676 
Abott               Al                  (202) 566-9892 
Brock               Bud                 (218) 555-4322 
Cass                Cathy               (619) 743-8582 
Porter              Pete                (619) 778-6709 
Derringer           Dale                (818) 223-9014 
Farmer              Fred                (305) 552-7872 
 
 
 
 
                        Press the RETURN key to continue 

6.4 Examples Using Structures

Once you have located a specific data record in the structure, you can perform the processing steps. Locating the record or records can sometimes be complicated. This section gives you examples of how to use INTOUCH to locate structure records in different situations.

Example 1 - Common Extract and Sort

This example shows a common way to extract and sort records.


        1   program application_6_3 
        10  clear 
            print at 1, 15: 'Selecting, extracting and sorting CLIENT records' 
            print 
        20  open structure cl: name 'tti_run:client' 
        30  extract structure cl 
              include cl(state) = 'CA' 
              exclude cl(phone)[1:3] = '619' 
              sort descending by cl(last) 
            end extract 
        40  for each cl 
              print cl(id); tab(12); cl(last); ' '; cl(first), cl(city); ' '; & 
                cl(state), cl(phone) 
            next cl 
        50  close structure cl 
        60  end 



 
              Selecting, extracting and sorting CLIENT records 
 
80522      Errant Earl                  Monterey CA         (408) 844-7676 
80561      Derringer Dale               Los Angeles CA      (818) 223-9014 
 

Example 2 - Using Input Parameters to Select Records

Often, the user will select what data they want to see on a report. This example shows how to use input parameters to select records.


        1   program application_6_4 
        10  clear 
            print at 1, 1:; 
        20  message 'Enter lst letter of last names to be selected ' & 
                + 'separated by commas' 
            line input 'Letters (A,B,C)': list$ 
            print 
        30  open structure cl: name 'tti_run:client' 
        40  extract structure cl 
              include match(list$, cl(last)[1:1]) > 0 
              sort ascending by cl(last) 
            end extract 
        50  for each cl 
              print cl(id); tab(12); cl(last); ' '; cl(first); ' '; & 
                cl(middle), cl(city); ' '; cl(state), cl(phone) 
            next cl 
        60  close structure cl 
        70  end 



 
Letters (A,B,C)? a,b,f,s,w 
 
80531      Abott Al A                   New York NY         (202) 566-9892 
80542      Brock Bud B                  Duluth MN           (218) 555-4322 
80573      Farmer Fred F                Miami FL            (305) 552-7872 
20000      Smith Sam S                  Seattle WA          (809) 555-8789 
32001      Waters Wayne W               San Diego CA        (619) 564-1231 
 

Example 3 - Sorting Fields not in the Main Structure

There are times when you want to list data in a specific order but the field that needs to be sorted is located in another structure. For example, you want to list the invoices from the INVOICE structure in customer name order. INVOICE contains a customer number but not the name. The name is only in the CUSTOMER structure. This example extracts INVOICE records which have an invoice amount greater than $11,000.00 and sorts the invoices by customer name. The SET STRUCTURE, FIELD: KEY statement uses the customer number to get the CUSTOMER file record so the name can be sorted. When this statement is used, the FIELD must be a key field.


        1   program application_6_5 
        10  clear 
            print at 1, 1:; 
        20  open structure inv: name 'tti_run:invoice' 
            open structure cust: name 'tti_run:customer' 
        30  extract structure inv 
              include inv(invamt) > 11000.00 
              set structure cust, field custnbr: key inv(custnbr) 
              sort by cust(name) 
            end extract 
        40  print 'Cust#'; tab(8); 'Customer Name'; tab(40); 'Inv#'; & 
                  tab(50); 'Inv Amount' 
            print 
        50  for each inv 
              set structure cust, field custnbr: key inv(custnbr) 
              if  _extracted = 0  then 
                cust_name$ = 'UNKNOWN' 
              else 
                cust_name$ = cust(name) 
              end if 
              print inv(custnbr); tab(8); cust_name$; tab(40); inv(invnbr); & 
                    tab(50); inv(invamt) 
            next inv 
        60  close all 
        70  end 



 
Cust#  Customer Name                   Inv#      Inv Amount 
 
12513  Alpha Products Inc              10376      12,453.00 
21670  Anywhere Travel Service         10301      28,712.00 
21670  Anywhere Travel Service         10348      13,168.00 
24424  Flower Power, Inc               10330      14,255.00 
24424  Flower Power, Inc               10347      12,737.00 
24424  Flower Power, Inc               10358      12,959.00 
20348  MicroNet Solutions              10341      13,143.00 
20348  MicroNet Solutions              10345      20,511.00 
20348  MicroNet Solutions              10355      18,163.00 
20348  MicroNet Solutions              10363      12,472.00 
21138  Peabody Plumbing                10395      11,165.00 
19279  Sky High Airlines               10384      12,150.00 
13727  Tumbleweeds Real Estate         10311      12,010.00 
 

Example 4 - Using Keys to Find Records

It is possible to locate specific records using record keys. You can use the PRIMARY key or ALTERNATE keys. The key can be the complete key or a partial key. These examples show two ways to retrieve records using partial keys.

This example extracts all records that start with the input partial customer number.


        1   program application_6_6 
        10  clear 
            print at 1, 1:; 
        20  open structure cust: name 'tti_run:customer' 
        30  do 
              message 'Enter the first part of the customer number' 
              input 'Customer number': cust_number$ 
              extract structure cust, field custnbr: partial key cust_number$ 
              end extract 
              if  _extracted = 0  then 
                message error: 'No numbers found starting with ' + cust_number$ 
                repeat do 
              else 
                exit do 
              end if 
            loop 
        40  print 
            for each cust 
              print cust(custnbr), cust(name) 
            next cust 
        50  close structure cust 
        60  end 



 
Customer number? 2 
 
20341               Loprice Drug Stores, Inc 
20348               MicroNet Solutions 
21138               Peabody Plumbing 
21670               Anywhere Travel Service 
24424               Flower Power, Inc 
 

This example uses the SET STRUCTURE statement. In this case, only the first record that matches the partial customer number is extracted.


        1   program application_6_7 
        10  clear 
            print at 1, 1:; 
        20  open structure cust: name 'tti_run:customer' 
        30  do 
              message 'Enter the first part of the customer number' 
              input 'Customer number': cust_number$ 
              set structure cust, field custnbr: partial key cust_number$ 
              if  _extracted = 0  then 
                message error: 'No number found starting with ' + cust_number$ 
                repeat do 
              end if 
              print 
              print cust(custnbr), cust(name) 
            end do 
        40  close structure cust 
        50  end 



 
Customer number? 2 
 
20341               Loprice Drug Stores, Inc 
 
 
 
 
 
                  Enter the first part of the customer number 
 


Previous Next Contents Index