Chapter Contents |
Previous |
Next |
SAS/SHARE User's Guide |
You can use SAS Component Language (SCL) with SAS/SHARE software to access data through a SAS/SHARE server. SCL has the ability to read and update SAS tables that are used concurrently by other clients or SCL applications. For complete information about SCL, see SAS Component Language: Reference.
A concurrent SCL application opens one SAS data table for update while other SAS operations (possibly in different SAS sessions) have the same data table open for update. These other opens for update can be done by other invocations of the first SCL application, by a different SAS application or SCL application, or even by a user who uses the FSEDIT or FSVIEW procedure on the table.
This section describes the following issues that you should consider when writing an SCL application that updates data concurrently:
Finally, see Appendix 4, "SAS Component Language Application," for an application that uses SAS tables that contain inventory and ordering information for each product in a store. The purpose of the application is to automate a system that develops orders and maintains the inventory list while sales representatives simultaneously write orders for products.
Locking Rows in SAS Tables |
When a SAS table is opened for update, only one row can be locked at a time. When a SAS table is opened for update more than one time in the same SAS session or in different SAS sessions (through a server), a different row can be locked by each of the opens. For example, if two users are running an SCL application that calls the OPEN function to open a SAS table for update, row 7 can be locked under one of the opens while row 10 is locked under the other.
Implications of Row Locking in SCL |
Row locking is a key consideration in concurrent SCL programming. After a lock on a row is released, your application can no longer be sure of the values that are contained in that row; another user might have already modified the values. Any data modifications that you make that are based on the old values may damage the data integrity of the system.
Therefore, you must never assume that the data values in a given row will not change in a shared table, even though only a very brief amount of time has elapsed between consecutive reads and locks of the row.
Row locking can give a programmer an important advantage. While an SCL application has a row locked, no other SAS operation (especially in another SAS session) can alter or delete that row. When each row in a SAS table can represent a specific instance of a resource that the application must govern, row locking provides a resource-specific, protected period of time in which the application can safely test and modify the state of the resource.
An example of a specific-resource instance is information about one of your customers or the number of items of a specific type that is currently in inventory. The sample SCL application in the appendix in this book applies locks to its inventory table to maintain the proper inventory count for each item, even if several sales representatives are simultaneously writing orders for those items.
Programming with the FSEDIT and the FSBROWSE Procedures |
The INIT section is especially useful to applications that read and update shared data. The initial values of the columns in a row (as presently stored in the SAS table) can be preserved in SCL columns. Preservation of initial values in SCL columns is important for applications that update auxiliary tables that are based on the PROC FSEDIT user's modification or on the creation of a row in the primary table (that is, the table that is specified in the DATA= option in the PROC FSEDIT statement.) (footnote 1) These SCL applications typically need to perform the following tasks:
Programming with the Data Table and Data Form Classes |
Like the FSEDIT procedure, the Data Table and the Data Form objects give the SCL programmer a number of labeled sections for structuring the order in which events will take place for each row in the table. These sections, which include INIT, MAIN, and TERM, operate in the same way as explained in Programming with the FSEDIT and the FSBROWSE Procedures.
If multiple instances of the Data Table or the Data Form objects are displayed within a single SAS/AF FRAME entry, the objects share data, then the model SCL for each data table or data form runs separately and the application developer must keep in mind whether a previous object has a lock on a row that the current object attempts to read or update. In addition, the frame SCL may also be operating on the shared data and timing within the frame could be critical. For more information about when SCL labels are run, see "Controlling Execution in the SCL" and "Summary of SCL Label Running" in the Data Set Data Model class under SAS/AF Component Reference in online help.
Locating and Fetching Control Rows |
gotrec=locatec(data-set-id,var-num,search-string, sort-order); if (gotrec<=0) then do; /* Handle observation not found */ end; else if (sysrc()=%sysrc(_swnoupd)) then do; /* Handle observation locked */ end;
Note: The LOCATEC and LOCATEN functions cannot perform
binary searches on compressed tables, SAS data views, or SAS data files with
deleted observations.
If the WHERE clause does not find the requested observation, the FETCH function returns a -1 return code indicating that the end of the table has been reached. If the WHERE clause is cleared by issuing a null WHERE function call, the next FETCH call that the application issues fetches the first observation in the table. The FETCH call, not the WHERE clause, locks the observation (if possible). Note that the WHERE function returns a harmless warning, %SYSRC(_SWWREP), when the WHERE clause is replaced.
Unlocking an Observation |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.