Sheerpower®
A Guide to the Sheerpower Language


Previous Contents Index

EXAMPLE:

This example shows how to access the actual field data using field expressions.

Example 15-26 Field Expressions in ASK TABLE FIELD

  open table cl: name 'sheerpower:samples\client' 
  do
  clear
  print at 1, 1:; 
    ask_fields 
    if  _back or _exit  then exit do
    show_data 
  loop
  close table cl 
  stop
 
  routine 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 table cl, field #field$: number z 
      if  z = 0  then
        message error: 'Illegal field: '; field$ 
      end if
    next f 
  loop while _error
  end routine
 
  routine show_data 
  print
  extract table cl 
    for f = 1 to elements(field_list$) 
      field$ = element$(field_list$, f) 
      print cl(#field$), 
    next f 
    print
  end extract
  delay
  end routine
  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 

15.8.1.2 Item: ACCESS


        ASK TABLE table_name, FIELD field_name: ACCESS str_var 

ACCESS retrieves the access (read and write) rules for the specified field. This information tells if the field can be read and written to. N is normal--meaning the field can be read and written to if the structure is also "N"ormal. Depending on whether security levels have been set on the table and/or field, the letter can be in the range of A thru Z. Sheerpower defaults to N when the table is created and fields are defined.

Example 15-27 ACCESS - Field Definition Item

  open table inv: name 'sheerpower:samples\invoice', access input
  ask table inv, field custnbr: access x$ 
  print x$ 
  close table inv 
  end
 
 
 
READ:N, WRITE:N 

15.8.1.3 Item: APPLICATION


        ASK TABLE table_name, FIELD field_expr: APPLICATION str_var 

APPLICATION returns a name of an application for the specified field in a string variable. This is optional information the user provides when the field is defined.

Example 15-28 APPLICATION - Field Definition Item

  open table cl : name 'sheerpower:samples\client' 
  ask table cl, field id: application str$ 
  print str$ 
  close table cl 
  end
 
 
REPORTING_ID 

15.8.1.4 Item: ATTRIBUTES


        ASK TABLE table_name, FIELD field_expr: ATTRIBUTES str_var 

ATTRIBUTES returns the Sheerpower field semantics (NUM - number, UC - upper-case, etc.) for the specified field in a string variable.

Refer to Section 16.3.1.9, Semantics for detailed information on field attributes.

15.8.1.5 Item: CHANGEABLE


        ASK TABLE table_name, FIELD field_expr: CHANGEABLE num_var 

CHANGEABLE returns a value of TRUE or FALSE. If the field specified by field_expr can be changed, the value is TRUE. If the field cannot be changed, the value is FALSE.

Example 15-29 CHANGEABLE - Field Definition Item

  open table cl: name 'sheerpower:samples\client' 
  ask table cl, field id: changeable z 
  ask table cl, field city: changeable z1 
  print z 
  print z1 
  close table cl 
  end
 
 
0 
1 

15.8.1.6 Item: DATATYPE


        ASK TABLE table_name, FIELD field_expr: DATATYPE str_var 

DATATYPE returns the field data type, such as CH (character), IN (integer), etc., in a string variable.

Refer to Section 16.3.1.4, Data Type for detailed information on field data types.

15.8.1.7 Item: DESCRIPTION


        ASK TABLE table_name, FIELD field_expr: DESCRIPTION str_var 

DESCRIPTION returns the description for the specified field in a string variable.

15.8.1.8 Item: HEADING


        ASK TABLE table_name, FIELD field_expr: HEADING str_var 

HEADING returns the report column heading for the specified field in a string variable. This is the heading that would appear in a Guided Query Language (GQS) report column.

15.8.1.9 Item: HELP


        ASK TABLE table_name, FIELD field_expr: HELP str_var 

HELP returns the help text for the specified field in a string variable.

15.8.1.10 Item: KEYED


        ASK TABLE table_name, FIELD field_expr: KEYED num_var 

KEYED returns a value of TRUE or FALSE in a numeric variable. If the specified field is a key field, the value is TRUE. Otherwise, the value is FALSE.

15.8.1.11 Item: LENGTH


        ASK TABLE table_name, FIELD field_expr: LENGTH num_var 

LENGTH returns the length of the specified field in a numeric variable.

15.8.1.12 Item: NAME


        ASK TABLE table_name, FIELD field_expr: NAME str_var 

NAME returns the name of the specified field in a string variable.

15.8.1.13 Item: NULL


        ASK TABLE table_name, FIELD field_name: NULL int_var 

If the specified field is NULL (i.e. contains no data), this statement returns TRUE. If the field is not NULL, the statement returns FALSE.

15.8.1.14 Item: NUMBER


        ASK TABLE table_name, FIELD field_expr: NUMBER num_var 

NUMBER returns the field number of the specified field in a numeric variable. Fields are numbered sequentially. If the field does not exist, Sheerpower returns a value of 0.

15.8.1.15 Item: OPTIMIZED


        ASK TABLE table_name, FIELD field_expr: OPTIMIZED num_var 

OPTIMIZED returns a value of TRUE or FALSE in a specified numeric variable. If the key field in field_expr is optimized, the value is TRUE. Otherwise, the value is FALSE.

Example 15-30 OPTIMIZED - Field Definition Item

  open table cl: name 'sheerpower:samples\client' 
  ask table cl, field id: optimized z 
  print z 
  close table cl 
  end
 
 
1 


Previous Next Contents Index