Try OpenEdge Now
skip to main content
ABL Reference
ABL Syntax Reference : SET statement
 

SET statement

Requests input, and then puts the data in the screen buffer frame and in the specified fields or variables. The SET statement is a combination of these statements:
*PROMPT-FOR — Prompts the user for data and puts that data into the screen buffer
*ASSIGN — Moves data from the screen buffer to the record buffer
Note: Does not apply to SpeedScript programming.

Data movement

Syntax

SET
  [ STREAM stream| STREAM-HANDLE handle]
  [ UNLESS-HIDDEN ]
  [
    {  field [view-as-phrase] [format-phrase] }
         [ WHEN expression ]
      | TEXT ( field [format-phrase] ... )
      | field = expression
      | constant [ AT n | TO n ]
      | ^
      | SPACE [ ( n ) ]
      | SKIP [ ( n ) ]
  ]...
  [ GO-ON ( key-label... ) ]
  [ frame-phrase ]
  [ editing-phrase ]
  [ NO-ERROR ]
SET [ STREAM stream | STREAM-HANDLE handle ][ UNLESS-HIDDEN ]
       record [ EXCEPT field ...] [ frame-phrase ]
    [ NO-ERROR ]
STREAM stream
Specifies the name of a stream. If you do not name a stream, the AVM uses the unnamed stream. See the DEFINE STREAM statement reference entry and the chapter on alternate I/O sources in OpenEdge Development: Programming Interfaces for more information on streams.
STREAM-HANDLE handle
Specifies the handle to a stream. If handle it is not a valid handle to a stream, the AVM generates a run-time error. Note that stream handles are not valid for the unnamed streams. See the chapter on alternate I/O sources in OpenEdge Development: Programming Interfaces for more information on streams and stream handles.
UNLESS-HIDDEN
Restricts SET to fields whose HIDDEN attribute is FALSE.
field
Represents the name of the field or variable whose value you want to store in the screen buffer and in the field or variable.
In the case of array fields, array elements with constant subscripts are treated as any other field. Array fields with no subscripts are expanded as though you typed in the implicit elements. See the DISPLAY statement reference entry for information on how the AVM handles array fields with expressions as subscripts.
view-as-phrase
Specifies the widget used to represent the field. For more information on view-as-phrase, see the VIEW-AS phrase reference entry.
format-phrase
Specifies one or more frame attributes for a field, variable, or expression. For more information on format-phrase, see the Format phrase reference entry.
WHEN expression
Sets the field only when expression has a value of TRUE. An expression is a field name, variable name, or expression whose value is logical.
TEXT
Defines a group of character fields or variables (including array elements) to use automatic word wrap. The TEXT option works with character fields only. When you insert data in the middle of a TEXT field, the AVM wraps data that follows into the next TEXT field, if necessary. If you delete data from the middle of a TEXT field, the AVM wraps data that follows into the empty area. If you enter more characters than the format for the field allows, the AVM discards the extra characters. The character fields must be in the x(n) format.
A blank in the first column of a line marks the beginning of a paragraph. Lines within a paragraph are treated as a group and will not wrap into other paragraphs.
The following table lists the keys you can use within a TEXT field, and their actions.
Table 61. Key actions in a TEXT field
Key
Action
APPEND-LINE
Combines the line the cursor is in with the next line.
BACK-TAB
Moves the cursor to the previous TEXT field.
BREAK-LINE
Breaks the current line into two lines beginning with the character the cursor is on.
BACKSPACE
Moves the cursor one position to the left and deletes the character at that position. If the cursor is at the beginning of a line, BACKSPACE moves the cursor to the end of the previous line.
CLEAR
Clears the current field and all fields in the TEXT group that follow.
DELETE-LINE
Deletes the line the cursor is in.
NEW-LINE
Inserts a blank line below the line the cursor is in.
RECALL
Clears fields in the TEXT group and returns initial data values for the group.
RETURN
In overstrike mode, moves to the next field in the TEXT group on the screen. In insert mode, the line breaks at the cursor and the cursor is positioned at the beginning of the new line.
TAB
Moves to the field after the TEXT group on the screen. If there is no other field, the cursor moves to the beginning of the TEXT group.
In this procedure, the s-com, or Order Comments field is a TEXT field. Run the procedure and enter text in the field to see how the TEXT option works.
r-text.p
DEFINE VARIABLE s-com AS CHARACTER NO-UNDO FORMAT "x(40)" EXTENT 5.

FORM "Shipped :" Order.ShipDate AT 13 SKIP
 "Misc Info :" Order.Instructions AT 13 SKIP(1)
 "Order Comments :" s-com AT 1
 WITH FRAME o-com CENTERED NO-LABELS TITLE "Shipping Information".

FOR EACH Customer NO-LOCK, EACH Order OF Customer:
 DISPLAY Customer.CustNum Customer.Name Order.OrderNum
   Order.OrderDate Order.PromiseDate WITH FRAME order-hdr CENTERED.
 UPDATE Order.ShipDate Order.Instructions TEXT(s-com)
WITH FRAME o-com.
 s-com = "".
END.
field = expression
Indicates that the value of field is determined by evaluating the expression rather than having it entered on the screen or from a file. An assignment statement is embedded within the SET statement.
constant AT n
A constant value that you want to display in the frame. The n is the column in which you want to start the display.
constant TO n
A constant value that you want to display in the frame. The n is the column in which you want to end the display.
^
Tells the AVM to ignore an input field when input is being read from a file. Thus, the following statement reads a line from an input file and ignores that line:
SET ^
This is an efficient way to skip over lines.
SPACE [ ( n ) ]
Identifies the number (n) of blank spaces to insert after the expression on the display. The n can be 0. If the number of spaces you specify is more than the spaces left on the current line of the frame, the AVM starts a new line and discards any extra spaces. If you do not use this option or do not use n, the AVM inserts one space between items in the frame.
SKIP [ ( n ) ]
Identifies the number (n) of blank lines to be inserted after the expression is displayed. The n can be 0. If you do not use this option, a line is not skipped between expressions only if they do not fit on one line. If you use the SKIP option, but do not specify n, or if n is 0, a new line is started unless it is already at the beginning of a new line.
GO-ON ( keylabel . . . )
Tells the AVM to take the GO action when the user presses any of the keys listed. The keys you list are used in addition to keys that perform the GO action by default or because of ON statements. When you list a key label in the GO-ON option, you use the keyboard label of that key. For example, if you want the AVM to take the GO action when the user presses F1, you use the statement GO-ON(F1). If you list more than one key, separate them with spaces, not commas, as in GO-ON( F1RETURN ).
frame-phrase
Specifies the overall layout and processing properties of a frame. For more information on frame-phrase, see the Frame phrase reference entry.
editing-phrase
Supported only for backward compatibility.
Identifies processing to take place as each keystroke is entered. This is the syntax for the editing-phrase:
[ label: ] EDITING: statement... END.
For more information on editing-phrase, see the EDITING phrase reference entry.
record
Represents the name of a record buffer. All of the fields in the record, except those with the data type RECID and ROWID, are processed exactly as if you set each individually. The record you name must contain at least one field.
To use SET with a record in a table defined for multiple databases, you must qualify the record's table name with the database name. See the Record phrase reference entry for more information.
NO-ERROR
Suppresses ABL errors or error messages that would otherwise occur and diverts them to the ERROR-STATUS system handle. If an error occurs, the action of the statement is not done and execution continues with the next statement. If the statement fails, any persistent side-effects of the statement are backed out. If the statement includes an expression that contains other executable elements, like methods, the work performed by these elements may or may not be done, depending on the order the AVM resolves the expression elements and the occurrence of the error.
To check for errors after a statement that uses the NO-ERROR option:
*Check the ERROR-STATUS:ERROR attribute to see if the AVM raised the ERROR condition.
*Check if the ERROR-STATUS:NUM-MESSAGES attribute is greater than zero to see if the AVM generated error messages. ABL handle methods used in a block without a CATCH end block treat errors as warnings and do not raise ERROR, do not set the ERROR-STATUS:ERROR attribute, but do add messages to the ERROR-STATUS system handle. Therefore, this test is the better test for code using handle methods without CATCH end blocks. ABL handle methods used in a block with a CATCH end block raise ERROR and add messages to the error object generated by the AVM. In this case, the AVM does not update the ERROR-STATUS system handle.
*Use ERROR-STATUS:GET-MESSAGE( message-num ) to retrieve a particular message, where message-num is 1 for the first message.
If the statement does not include the NO-ERROR option, you can use a CATCH end block to handle errors raised by the statement.
Some other important usage notes on the NO-ERROR option:
*NO-ERROR does not suppress errors that raise the STOP or QUIT condition.
*A CATCH statement, which introduces a CATCH end block, is analogous to a NO-ERROR option in that it also suppresses errors, but it does so for an entire block of code. It is different in that the error messages are contained in a class-based error object (generated by the AVM or explicitly thrown), as opposed to the ERROR-STATUS system handle. Also, if errors raised in the block are not handled by a compatible CATCH block, ON ERROR phrase, or UNDO statement, then the error is not suppressed, but handled with the default error processing for that block type.
*When a statement contains the NO-ERROR option and resides in a block with a CATCH end block, the NO-ERROR option takes precedence over the CATCH block. That is, an error raised on the statement with the NO-ERROR option will not be handled by a compatible CATCH end block. The error is redirected to the ERROR-STATUS system handle as normal.
*If an error object is thrown to a statement that includes the NO-ERROR option, then the information and messages in the error object will be used to set the ERROR-STATUS system handle. This interoperability feature is important for those integrating code that uses the traditional NO-ERROR technique with the newer, structured error handling that features error objects and CATCH end blocks.
EXCEPT field
Affects all fields except those fields listed in the EXCEPT phrase.

Examples

The r-set.p procedure reads each Item record, displays the ItemNum and lets the user enter information for the ItemName, OnHand, Allocated, and Price fields. When you run this procedure, notice that it does not display existing values for the ItemName, OnHand, Allocated, and Price fields.
r-set.p
FOR EACH Item:
DISPLAY Item.ItemNum.
SET Item.ItemName Item.OnHand Item.Allocated Item.Price.
END.
On each iteration of the block, the FOR EACH statement reads a single record into the Item record buffer. The DISPLAY statement moves the ItemNum from the record buffer to the screen buffer where you can see it. The SET statement prompts for data, stores the data in screen buffers, and moves the data to the record buffer, overwriting whatever is already there. Therefore, even though the ItemName, OnHand, Allocated, and Price fields are put into the Item record buffer by the FOR EACH statement, you never see the values for those fields.
The r-set2.p procedure displays the CustNum, Name, and CreditLimit for a Customer and lets you change the CreditLimit field. The HELP option in the SET statement displays help information at the bottom of the screen when you are changing the CreditLimit. The VALIDATE option in the SET statement makes sure that the CreditLimit value is greater than 0. If it is not, VALIDATE displays the message "Invalid credit limit."
r-set2.p
FOR EACH Customer:
DISPLAY Customer.CustNum Customer.Name Customer.CreditLimit.
SET Customer.Name Customer.CreditLimit
VALIDATE(Customer.CreditLimit > 0, "Invalid credit limit.")
HELP "Enter a positive credit-limit.".
REPEAT:
CREATE Order.
Order.CustNum = Customer.CustNum.
SET Order.OrderNum Order.ShipDate VALIDATE(Order.ShipDate > TODAY,
"Ship date too early.").
END.
END.
After you modify CreditLimit, the procedure creates an Order for the Customer and assigns the Customer.CustNum value to the CustNum field in the Order record. The SET statement lets you enter information for the OrderNum and ShipDate fields. The VALIDATE option in the SET statement makes sure that the Ship Date is greater than TODAY.

Notes

*If any field is a field in a database record, the SET statement upgrades the record lock condition to EXCLUSIVE-LOCK before updating the record.
*If any field is part of a record retrieved with a field list, the SET statement rereads the complete record before updating it.
*SET does not move data into the field or variable if there is no data in the corresponding screen field. There is data in a screen field if a DISPLAY of the field was done or if you enter data into the field. If you set a field or variable that has not been DISPLAYed in the frame and key in blanks, then the field or variable is not changed because the screen field is changed only if the data differs from what was in the frame field.
*When ABL compiles a procedure, it designs all the frames used by that procedure. When you run the procedure, the SET statement puts data into those fields.
*In a SET statement, the AVM first prompts for all specified fields and then assigns the values of those fields, moving from left to right. During this left to right pass of the field list, the AVM processes embedded assignments (field = assignment) as it encounters them.
*If you are getting input from a device other than the terminal, and the number of characters read by the SET statement for a particular field or variable exceeds the display format for that field or variable, the AVM returns an error. However, if you are setting a logical field that has a format of y/n and the data file contains a value of YES or NO, the AVM converts that value to "y" or "n".
*If you type blanks into a field in which data has never been displayed, the ENTERED function returns FALSE and the SET or ASSIGN statement does not update the underlying field or variable. Also, if the AVM has marked a field as entered, and the SET statement prompts for the field again and you do not enter any data, the AVM no longer considers the field an entered field.
*If you use a single qualified identifier with the SET statement, the Compiler first interprets the reference as dbname.tablename. If the Compiler cannot resolve the reference as dbname.tablename, it tries to resolve it as tablename.fieldname.
When using SET to set fields, you must use table names that are different from field names to avoid ambiguous references. See the Record phrase reference entry for more information.
*The SET statement causes the ASSIGN and WRITE events to occur and fires all related database ASSIGN and WRITE triggers. The ASSIGN triggers execute before the WRITE triggers and after the field is actually updated. The WRITE triggers only execute if the ASSIGN triggers do not return an error. If an ASSIGN trigger fails (or executes a RETURN statement with the ERROR option), the SET statement is undone. This means that any changes to the database from that SET statement are backed out. If the SET statement occurs within a transaction, any changes to variables, worktable fields, and temp-table fields are also undone unless they are defined with the NO-UNDO option. Also, if a WRITE trigger fails (or executes a RETURN statement with the ERROR option), the SET statement is undone.
*In the context of the .NET blocking method, System.Windows.Forms.Application:Run( ), if you directly or indirectly execute the SET statement while displaying a non-modal ABL window, in certain contexts (such as within a user-defined function or non-VOID method) this statement execution raises the STOP condition. For more information on the .NET Application:Run( ), method, see the reference entry for the WAIT-FOR statement (.NET andABL).
Note: See OpenEdge Development: ABL Handbook for more information on database triggers.

See also

DEFINE STREAM statement, EDITING phrase, Format phrase, Frame phrase, PROMPT-FOR statement, Stream object handle, UPDATE statement