Chapter Contents |
Previous |
Next |
SAS/ACCESS Interface to CA-IDMS Software: Reference |
An INPUT statement reads from the file specified by the most recently executed INFILE statement. If the INFILE statement is a CA-IDMS INFILE statement, the INPUT statement issues a CA-IDMS function call as formatted by variables specified in the INFILE statement.
There are no special options for the CA-IDMS INPUT statement as there are for the CA-IDMS INFILE statement. The form of the CA-IDMS INPUT statement is the same as that of the standard INPUT statement:
INPUT <specification-1 > <...specification-n > <@|@@ >; |
For example, suppose you issue an OBTAIN function call for the EMPLOYEE record. The CA-IDMS INPUT statement might be coded as follows:
input @1 employee_id 4.0 @5 firstname $char10. @15 lastname $char15. @30 street $char20. @50 city $char15. @65 state $char2. @67 zip $char9. @76 phone 10.0 @86 status $char2. @88 ssnumber $char9. @97 startdate 8.0 @105 termdate 8.0 @113 birthdate 8.0;
When this CA-IDMS INPUT statement executes, the DATA step interface generates and submits a function call from the options you entered on the CA-IDMS INFILE statement. If the FUNC= variable specified in the INFILE statement is assigned a value of GET or OBTAIN, an EMPLOYEE record is retrieved and placed in the input buffer. Data for the variables specified in the CA-IDMS INPUT statement are then moved from the input buffer to SAS variables in the program data vector.
Depending on which options you specify in the CA-IDMS INFILE statement and which form of the CA-IDMS INPUT statement you use, the INPUT statement will do one of the following:
input;
),
then the previously held record is released. See Holding Records in the Input Buffer for more information.
Although the syntax of the CA-IDMS INPUT statement and the standard INPUT statement are the same, your use of the CA-IDMS INPUT statement is often different. Suggested uses of the CA-IDMS INPUT statement are described in the following sections.
Using the Null INPUT Statement |
input;
A null INPUT statement serves three purposes:
input @;
or
input var1 var2 var3 @;
, a null INPUT statement releases
the previously held record. See Holding Records in the Input Buffer
for information.
Holding Records in the Input Buffer |
Assuming the FUNC= variable in your INFILE statement specifies GET or OBTAIN, the following INPUT statement submits a function call to the database, retrieves a record from the database, places it in the input buffer, and places a hold on the buffer:
input @;
The next INPUT statement that is executed does not issue another function call and does not place a new record in the input buffer. Instead, the second INPUT statement uses the data placed in the input buffer by the first INPUT statement.
If your INPUT statement also specifies variable names, then that statement issues a function call to the database, retrieves a record, places the record into the input buffer, and moves data values for the named variables into the program data vector:
input ssnumber $char11. @;
The SAS System holds the record in the input buffer for use with the next INPUT statement.
If you have used an INPUT statement with a trailing @ or @@, and you now want to release the record from the input buffer, use a null INPUT statement as described in Using the Null INPUT Statement.
Checking Call Status Codes |
Summary of _ERROR_ Values shows the _ERROR_ values and their meaning.
Value of _ERROR_ | Possible Corresponding Status Codes | Description |
---|---|---|
0 | CA-IDMS 0000 | Function call executed successfully |
1 | All CA-IDMS status codes except 0000 | CA-IDMS error code returned. Contents of the input buffer and the program data vector are printed in the SAS log with the next INPUT statement or when control returns to the beginning of the DATA step, whichever comes first. |
SAS status 9999 | Program cannot perform function call from options specified. |
Refer to your CA-IDMS documentation for explanations
of CA-IDMS error status codes.
For example, suppose you are writing a program that accesses all the DEPARTMENT and EMPLOYEE records from all the DEPT-EMPLOYEE set occurrences. When an end-of-set condition (CA-IDMS status code 0307) occurs on the EMPLOYEE record, _ERROR_ is set to 1; however, you do not consider the end-of-set condition to be an error. Instead, you want your application to obtain the next owner record or DEPARTMENT record from the next DEPT-EMPLOYEE set occurrence.
If a status code sets _ERROR_ but you do not consider
the condition to be an error, you should reset _ERROR_ to 0 before executing
another INPUT statement or returning to the beginning of the DATA step. Otherwise,
the contents of the input buffer and program data vector are printed on the
SAS log. See in Example: Traversing a Set
for an example of how to reset _ERROR_ to 0.
When you need to issue a retrieval call but you want to check either _ERROR_ or ERRSTAT= values before moving data to SAS variables, use a CA-IDMS INPUT statement with no variables specified, but with a trailing @, to issue the call:
input @;
Because no variables are specified, no data are moved to the program data vector. The statement contains a trailing @, so the record remains in the input buffer, and your application can check the values in _ERROR_ and/or ERRSTAT= before determining what action to take. For more information, see Holding Records in the Input Buffer.
For example, suppose you have specified ERRSTAT=ERR and FUNC=FUNC1 on your INFILE statement, and you have assigned FUNC1= 'GET' or 'OBTAIN'. You can use the following code to check the error status before moving data:
[1] input @; [2] if (err ne '0000' and err ne '0307') then go to staterr; [3] if err eq '0307' then do; [4] _error_ = 0; /* No more DEPT records so STOP */ stop; end; [5] input @1 department_id 4.0 @5 department_name $char45. @50 department_head 4.0;
The INPUT statement retrieves a record from the database and places a hold on the input buffer but does not move data to the program data vector. | |
A SAS IF statement checks to see if ERR is not equal to 0000 or 0307. If not, the program branches to the STATERR routine, which issues an error message and stops the DATA step. | |
If the INPUT statement encountered the end-of-set, then the _ERROR_ variable is reset to 0 () to prevent the contents of the input buffer and program data vector from being printed on the SAS log, and the DATA step stops. | |
If the first INPUT statement () was successful, then the second INPUT statement moves the data from the record being held in the input buffer to the program data vector and releases the hold. |
Handling End of File |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.