SheerPower® 4GL
A Guide to the SheerPower Language


Previous Contents Index

DESCRIPTION:

The FIELD option allows you to get information about a specific field in a structure. struc_name is the name of the structure. field_expr is the field you are inquiring about. item specifies what type of information you are asking. The information is stored in the variable specified.

The following sections provide more information on what you can use for field_expr and on the various field items.

For more information:

The ITEM information is created when the SETUP routine is used to define the field. You can refer to Chapter 16, Database Setup for information on defining fields.

15.8.1.1 FIELD Expressions

The field_expr used in the ASK STRUCTURE FIELD: item statement can be either a constant or a string or numeric expression.

A string constant can be used to specify the field name. To use a string constant, just enter the field name, without quotes. SheerPower will then use the string constant as the field name:


        ASK STRUCTURE sheerpower:samples\CLIENT, FIELD LAST: DESCRIPTION A$ 
                                        / 
                  the field is specified by its field name 

You can also specify a field name with an expression. To use an expression, precede the expression with a pound sign (#). The pound sign tells SheerPower that the following characters are an expression, not the field name. If a pound sign is not included SheerPower will interpret the characters as a field name.


        ASK STRUCTURE CL, FIELD #FIELDNAME$: DESCRIPTION A$ 
                                    / 
          the field is specified by the value of the variable FIELDNAME$ 
 
 
        ASK STRUCTURE CL, FIELD #FIELDNUM: DESCRIPTION A$ 
                                    / 
          the field is specified by the value of the variable FIELDNUM 

EXAMPLE:

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

Example 15-26 Field expressions in ASK STRUCTURE FIELD

  open structure cl: name 'sheerpower:samples\client' 
  do
  clear
  print at 1, 1:; 
    ask_fields 
    if  _back or _exit  then exit do
    show_data 
  loop
  close structure 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 structure 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 structure 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 STRUCTURE struc_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 structure and/or field, the letter can be in the range of A thru Z. SheerPower defaults to N when the structure is created and fields are defined.

Example 15-27 ACCESS - field definition item

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

15.8.1.3 Item: APPLICATION


        ASK STRUCTURE struc_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 structure cl : name 'sheerpower:samples\client' 
  ask structure cl, field id: application str$ 
  print str$ 
  end
 
 
REPORTING_ID 

15.8.1.4 Item: ATTRIBUTES


        ASK STRUCTURE struc_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 STRUCTURE struc_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 structure cl: name 'sheerpower:samples\client' 
  ask structure cl, field id: changeable z 
  ask structure cl, field city: changeable z1 
  print z 
  print z1 
  close structure cl 
  end
 
 
0 
1 

15.8.1.6 Item: DATATYPE


        ASK STRUCTURE struc_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 STRUCTURE struc_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 STRUCTURE struc_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 STRUCTURE struc_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 STRUCTURE struc_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 STRUCTURE struc_name, FIELD field_expr: LENGTH num_var 

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


Previous Next Contents Index