Chapter Contents |
Previous |
Next |
SAS/ACCESS Interface to IMS-DL/I Software |
A PUT statement writes information to the file specified by the most recently executed FILE statement. If the FILE statement is a DL/I FILE statement, the corresponding PUT statement issues a DL/I update call.
There are no special options for a DL/I PUT statement as there are for the DL/I INFILE and DL/I FILE statements. The form of the DL/I PUT statement is the same as that of the standard PUT statement:
PUT variable optional specifications;
For example, assume that you are issuing an insert call for the CUSTOMER segment of the ACCTDBD database. The following DL/I PUT statement (which looks just like a standard PUT statement) formats a CUSTOMER segment and issues the ISRT call:
put @1 ssnumber $char11. @12 custname $char40. @52 addr_line_1 $char30. @82 addr_line_2 $char30. @112 custcity $char28. @140 custstat $char2. @142 custland $char20. @162 custzip $char10. @172 h_phone $char12. @184 o_phone $char12.;Although the syntax of the DL/I PUT statement is identical to that of the standard PUT statement, your use of the DL/I PUT is often different. Segment format and suggested uses of the DL/I PUT statement are discussed in Using the DL/I PUT Statement.
Example 3: An Update Call |
data _null_; set mydata.customer; length ssa1 $9; infile acctsam dli call=func ssa=ssa1 status=st pcbno=4; file acctsam dli; func = 'ISRT'; ssa1 = 'CUSTOMER'; put @1 ssnumber $char11. @12 custname $char40. @52 addr_line_1 $char30. @82 addr_line_2 $char30. @112 custcity $char28. @140 custstat $char2. @142 custland $char20. @162 custzip $char10. @172 h_phone $char12. @184 o_phone $char12.; if st ¬= ' ' then if st = 'LB' or st = 'II' then _error_ = 0; else do; file log; put _all_; abort; end; run;To update ACCTDBD with new occurrences of the CUSTOMER segment type, this program issues qualified insert calls that add observations from MYDATA.CUSTOMER to the database. The DL/I INFILE statement defines ACCTSAM as the PSB. Options in the INFILE statement specify that
If the ISRT call is not successful, the status code
variable ST is set with the DL/I status code and the automatic variable _ERROR_
is set to 1. After the ISRT call, the status code variable ST is checked
for non-blanks. If the variable value is either
LB
or
II
,
which indicate that the segment occurrence already exists, the automatic variable
_ERROR_ is reset to 0 and processing continues. Otherwise, all values from
the program data vector are written to the SAS log, and the DATA step aborts.
Using the DL/I PUT Statement |
In order for a DL/I update call to be executed, the CALL= option must be specified in the DL/I INFILE statement. The value of the CALL= variable must be set to the appropriate update call before the DL/I PUT statement is executed. If CALL= is not specified, the call function defaults to GN and no update calls can be issued.
The update call issued by a DL/I PUT statement may or
may not be successful. DL/I returns various status codes that indicate whether
or not the update call was successful. It is always a good idea to check the
status code, but it is especially important in an update program. If you are
unfamiliar with DL/I status codes, consult your IBM documentation for descriptions.
Your SAS program can obtain the return code if the STATUS= option of the
INFILE statement is specified. The _ERROR_ and STATUS= variable checking guidelines
discussed in Using the DL/I INPUT Statement
are also applicable to DL/I PUT statements.
One way the buffer can be formatted is by specifying all fields and their locations. For example, this DL/I PUT statement formats the entire CUSTOMER segment of the ACCTDBD database:
put @1 ssnumber $char11. @12 custname $char40. @52 addr_line_1 $char30. @82 addr_line_2 $char30. @112 custcity $char28. @140 custstat $char2. @142 custland $char20. @162 custzip $char10. @172 h_phone $char12. @184 o_phone $char12.;
Another way to format the output buffer is with the _INFILE_ specification. If the current input source is a DL/I INFILE and the last DL/I INPUT statement retrieved the DL/I segment to be replaced, then the following DL/I PUT statement formats the output buffer with the contents of the retrieved segment and holds the segment in the output buffer until another DL/I PUT statement is executed:
put _infile_ @;
A subsequent DL/I PUT statement can modify the data
in the output buffer and execute the REPL call.(footnote 1) Example 4 illustrates this technique.
Notice that SSA1, a qualified SSA, is constructed by concatenating the SSA specification with the value of the SSN variable in the SAS data set. SSA1 is set to blanks after the GHU call because an SSA is not needed for the REPL call. (Since the program issues get calls with qualified SSAs, access is random.)
data _null_; set mydata.newaddr; length ssa1 $31; infile acctsam dli ssa=ssa1 call=func status=st pcbno=4; ssa1 = 'CUSTOMER(SSNUMBER =' || ssn || ')'; func = 'GHU '; input; if st = ' ' then do; func = 'REPL'; ssa1 = ' '; file acctsam dli; put _infile_ @; put @52 newaddr1 $char30. @82 newaddr2 $char30. @112 newcity $char28. @140 newstate $char2. @162 newzip $char10.; if st ¬= ' ' then link abendit; end; else if st = 'GE' then _error_ = 0; else link abendit; return; abendit: file log; put _all_; abort; run;
Alternatively, the two DL/I PUT statements can be combined into one without the trailing @ sign. For example:
data _null_; set mydata.newaddr; length ssa1 $31; infile acctsam dli ssa=ssa1 call=func status=st pcbno=4; ssa1 = 'CUSTOMER(SSNUMBER ='||ssn||')'; func = 'GHU '; input; if st = ' ' then do; func = 'REPL'; ssa1 = ' '; file acctsam dli; put @1 _infile_ @52 newaddr1 $char30. @82 newaddr2 $char30. @112 newcity $char28. @140 newstate $char2. @162 newzip $char10.; if st ¬= ' ' then link abendit; end; else if st = 'GE' then _error_ = 0; else link abendit; return; abendit: file log; put _all_; abort; run;
put _infile_;
Example 5: Issuing DLET Calls
demonstrates this technique.
The following example deletes all WIRETRAN segments with a transaction date of 03/31/95:
data _null_; length ssa1 $30; retain db 'WIRETRN ' ; infile acctsam dli call=func dbname=db ssa=ssa1 status=st; func = 'GHN '; ssa1 = 'WIRETRAN(WIREDATE =03/31/95) '; input; if st = ' ' then do; file acctsam dli; func = 'DLET'; ssa1 = ' '; put _infile_; if st ¬= ' ' then link abendit; end; else if st = 'GB' then do; _error_ = 0; stop; end; else link abendit; return; abendit: file log; put _all_; abort; run;
Note: A check for a status code of
GB
is required in this DATA step because it uses a qualified SSA and
random access processing. In example 5, the DATA step does not set the end-of-file
condition, and the source logic must check for it to stop the DATA step normally.
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.