Performing Batch Operations

Overview

You can use batch operations to automate processes. For example, you can use them for overnight operations or to simplify connections for end users.
Use this command open the connection for a batch operation:
%r3connb(profile=profile-name,
libref=SAS-libref, function=OPEN);
profile-name
specifies the name of the profile to use to save the information in the Logon to R/3 window.
SAS-libref
specifies the SAS library where the profile was saved. If you do not specify this parameter, the profile is sought in the WORK, SASUSER, and R3LIB SAS libraries, in that order.
function=OPEN
opens the connection.
Use this command to close the connection:
%r3connb(profile=profile-name,
libref=SAS-libref,
function=CLOSE);
or
%r3connb(id=connection-id,
function=CLOSE); 
profile-name
specifies the name of the profile to use to save the information in the Logon to R/3 window.
SAS-libref
specifies the SAS library where the profile was saved. If you do not specify this parameter is not specified, the profile is sought in the WORK, SASUSER, and R3LIB SAS libraries, in that order.
function=CLOSE
disconnects from the SAP system.
connection_id
specifies the connection ID.

Source Parameter

Previous versions of SAS/ACCESS Interface to R/3 included a source parameter in the batch connection. For backward compatibility, the source parameter that is described below is still supported, although its use is not recommended.
Submit this command in SAS to set up the connection for batch:
%r3connb (source = libref.catalog.entry.SOURCE );
If you are using batch mode, submit this command in SAS to disconnect before exiting:
%r3connb (source = libref.catalog.entry.SOURCE, function = close);

Passwords

In batch processing, all parameters to log on to an SAP system are generally stored in permanent SAS catalog entries. If you do not want to store all parameters—particularly, user ID, password, and client—use the following SAS code to prompt the user for this information. In this scenario, you must enter all other connection information—the function module name, the gateway host, or the gateway service—in the Application Setup window when you create the SAS DATA step view.
/*----------------------------------------------------*/
/* This SAS program demonstrates how to prompt a user */
/* for the SAP user ID, password, client, and         */
/* language information.                              */
/* The remote processing is enclosed in comments.     */
/*----------------------------------------------------*/

*--- reset password ---*;
   %let pwd=;

*--- set the message text ---*;
   %let message=Please enter the SAP logon parameter;

*--- prompt the user for the parameters ---*;
   %macro secure;
   %global usr pwd cli lng;
   %window R3 columns=80 rows=15
     #2  @5 message 50 protect=yes
     #4  @5 "User    : " usr 10 required=yes
     #6  @5 "Password: " pwd 10 display=no required=yes
     #8  @5 "Client   : " cli 3 required=yes
     #10 @5 "Language : " lng 1 required=yes;
   %display R3;
   %mend secure;

   %secure;

/* === for remote processing =======================  */

*--- macro to pass macro variables to ---*;
*--- a remote SAS session ---*;
   %macro syslput(macvar,macval,remote=);
   %let str=%str(rsubmit &remote ;);
   %nrstr(%let) %str(&macvar = &macval ; endrsubmit;);
   &str ;
   %mend syslput;

*--- pass macro variables to the remote SAS session ---*;
   %syslput(usr,&usr);
   %syslput(pwd,&pwd);
   %syslput(cli,&cli);
   %syslput(lng,&lng);

*--- submit the code to the remote SAS session ---*;
   rsubmit;

=== end of remote processing =========================== */

*--- a temporary catalog entry for the connection ---*;
*--- parameters ---*;
   %let source=work.r3conn.conn1.source;

*--- the connection id ---*;
*--- ATTENTION: This has to be the same connection ID ---*;
*--- as the one that was used to create the views.    ---*;
   %let cconn=conn1;

*--- the host/port where the SAS RFC Server program ---*;
*--- is running, used only in z/OS operating environment ---*;
   %let tcphost=cafe7.eur.sas.com;
   %let port=6999;

*--- set the host parameter ---*;
   %let hst=hostname;

*--- save the parameters to the temporary catalog ---*;
*--- entry ---*;
   proc display c=sapr3.sr3dbi.savconnb.scl;
   run;

*--- connect to the SAP system ---*;
   %r3connb(source=&source);

*--- use the Data Step view you have created with the ---*;
*--- SAS/ACCESS Interface to R/3 ---*;

*--- close the connection to the SAP system ---*;
   %r3connb(source=&source, function=close);

/* === for remote processing
==================================
   endrsubmit;

=== end of remote processing

================================ */
*--- end of sample program ---*;