Using the RFC Macros and Macro Variables |
Type: | autocall macro | ||
See also: |
|
Syntax | |
Details | |
Using | |
Example 1 | |
Example 2 | |
Example 3 | |
Example 4 | |
Example 5 |
Syntax |
%CALLRFC(<RFC-enabled function module name> EXPORTING <parameter string> IMPORTING <parameter string> INTABLES <parameter string> OUTTABLES <parameter string> USING <parameter string>) |
Details |
%CALLRFC is a SAS macro that allows you to call any RFC-enabled function module that you specify. Function modules that are called using this macro must
be RFC-enabled
be synchronous
have no user interaction
The parameters for %CALLRFC are as follows:
EXPORTING |
passes field values or structures to the specified function module. The EXPORTING parameters are declared as import parameters in the function interface and are defined as follows:
|
IMPORTING |
passes field values or structures from the specified function module back to SAS. The IMPORTING parameters are defined as follows:
|
INTABLES |
passes references to input SAS data sets. The INTABLES parameters are defined as follows:
|
OUTTABLES |
specifies references to output SAS data sets. The OUTTABLES parameters are defined as follows:
|
USING |
specifies alternate connection parameters when you log on to the SAP System. By default, the %CALLRFC macro uses the connection parameters that are defined in the RFC_LOGON_INFO variable. However, if you want to use an alternate set of connection parameters, create a variable that contains those parameters and reference that variable in the USING parameter. Note: The alternate logon variable must be defined before the function call is submitted. |
Note: If an error occurs while the %CALLRFC macro is executing, the macro variables &SYSRC and/or &SYSERR contain a nonzero value. (See Example 4.) The ABAP function module might also contain parameters to return error conditions to the calling program. These return codes can be written into a SAS macro variable and checked in the SAS program. (See Example 5.)
Using |
The following macro variables are used with the %CALLRFC macro:
RFC_LOGON_INFO
defines the R/3 BAPI connection parameters that are required to access the SAP System. You can specify these connection parameters by using the RFC_LOGON_INFO macro string or by using the R/3 BAPI Connector window, which is automatically displayed if you do not use the RFC_LOGON_INFO macro string when you submit your %CALLRFC macro statement. The following connection parameters are required:
CLIENT
USER
PASSWD (or PASSWDX)
LANG
Note: If any of the required values are missing, the user is prompted to provide the missing information.
The RFC_LOGON_INFO macro variable also requires some connection information. The connection parameters should be defined as follows:
If you use the saprfc.ini, specify the DEST value.
If you use a specific application server, specify the ASHOST and SYSNR values.
If you use Load Balancing, specify the MSHOST, R3NAME, and GROUP values.
Note: Load Balancing is available only if the CALLRFC executable has been linked using Release 4.0 or higher of the RFCSDK.
For more information about defining the RFC_LOGON_INFO variable, see RFC_LOGON_INFO. For more information about using the R/3 BAPI Connector window, see Using the R/3 BAPI Connector: Logon Window.
Example 1 |
The following example shows how to use the %CALLRFC macro to read data from an SAP R/3 system into a SAS data set:
%callrfc(RFC_SYSTEM_INFO IMPORTING RFCSI_EXPORT=WORK.RFCSI_EXPORT);
In this example, the %CALLRFC macro calls the RFC-enabled function module named RFC_SYSTEM_INFO and writes the system information output to the SAS data set WORK.RFCSI_EXPORT.
Example 2 |
The following example shows how to specify the logon parameters for the %CALLRFC macro using the RFC_LOGON_INFO:
%let RFC_LOGON_INFO CLIENT=010 USER=TestUser PASSWD=TestPwd LANG=E ASHOST=HostName SYSNR=02; %callrfc(RFC_SYSTEM_INFO IMPORTING RFCSI_EXPORT=WORK.RFCSI_EXPORT);
In this example, TestUser is connecting to a specific application server to read data from the R/3 system into a temporary SAS data set named WORK.RFCSI_EXPORT.
Example 3 |
The following example demonstrates how to use SAS dates in the function call:
%let MRETURN=; %callrfc(BAPI_COSTCENTER_GETLIST EXPORTING CONTROLLINGAREA=1000 DATE=%sysfunc(date (), yymmddn8.) IMPORTING RETURN=MRETURN OUTTABLES COSTCENTER_LIST=WORK.COSTCENTER_LIST);
In this example, the %CALLRFC macro is used to call the function module named BAPI_COSTCENTER_GETLIST. The function call reads the list of cost centers for controlling area 1000 for the current date and writes the output list into a temporary SAS data set named WORK.COSTCENTER_LIST. The return code of the function call is written to the SAS macro variable MRETURN. Note that the macro variable is defined before the %CALLRFC macro is used.
Example 4 |
The following example illustrates how to use the &SYSRC and &SYSERR macro variables to check for errors that occur while the %CALLRFC macro is executing:
%macro example4; %callrfc(INVALID_FUNCTION_CALL); %if %eval(&sysrc) ne 0 or %eval(&syserr) ne 0 %then %do; %put An error occurred while calling the function. %put sysrc=&sysrc syserr=&syserr; %end; %mend; %example4;
In this example, a new macro named %EXAMPLE4 is created. %EXAMPLE4 uses the SAS macro variables &SYSRC and &SYSERR to check return codes from the %CALLRFC macro. The new macro also generates an error message if errors occurred.
Example 5 |
The following example shows how to use the parameters in the function module to check for errors that occurred during the execution of the %CALLRFC macro:
%macro example5; %global bapi_return; /* create the input data set */ data WORK.IDRANGE; sign='I'; option='BT'; low='0000000000'; high='9999999999'; output; run; %callrfc(BAPI_CUSTOMER_GETLIST IMPORTING RETURN=BAPI_RETURN INTABLES IDRANGE=WORK.IDRANGE OUTTABLES ADDRESSDATA=WORK.ADDRESSES); %if %substr(&bapi_return,1,1)=E or %substr(&bapi_return,1,1)=W %then %do; %put An error occurred while calling the BAPI_CUSTOMER_GETLIST function.; %put bapi_return=&bapi_return; %end; %else %do; proc print data=WORK.ADDRESSEs; run; %end; %mend; %example5;
In this example, a new macro named %EXAMPLE5 is created to retrieve a list of customers from the R/3 system. The range of customer numbers to be retrieved is specified in the SAS data set WORK.IDRANGE. This data set is then used as the input table in the function call. The information for customers between customer number 0000000000 and 9999999999 will be read into the SAS data set WORK.ADDRESSES. The function parameters contain return codes and messages from the BAPI_CUSTOMER_GETLIST function. The structure of the return parameter is defined in the function interface. In this example, the first character in the return string contains the message type. E indicates an error message and W indicates a warning message.
Copyright © 2008 by SAS Institute Inc., Cary, NC, USA. All rights reserved.