%CALLRFC Macro

Calls a specified RFC-enabled function module.
Type: autocall macro
Requirement: Function modules that are called using this macro must be RFC-enabled, synchronous, and have no user interaction.
See: RFC_LOGON_INFO, Using the R/3 BAPI Connector: Logon Window

Syntax

%CALLRFC
(<RFC-enabled function module name>
EXPORTING <parameter string> IMPORTING <parameter string>
INTABLES <parameter string> OUTTABLES <parameter string>
USING <parameter string>)

Optional Arguments

EXPORTING
passes field values or structures to the specified function module. The EXPORTING parameters are declared as import parameters in the function interface. Here is how they are defined.
  • p1=value1 ... pn=valuen
    These parameters are passed as field values to the specified function module.
  • p1.n1=value p1.n2=value2 ... pn.vn=valuen
    These parameters are passed as elements of a structured parameter, which is a complex parameter that contains fields.
IMPORTING
passes field values or structures from the specified function module back to SAS. Here is how they are defined.
  • p1=var1 ... pn=varn
    The p1 ... pn parameters are export parameters that are declared in the function interface.
    The var1 ... varn parameters are SAS macro variables that are used to pass the values from the SAP system back to SAS. The macro variables must be defined before the function call is submitted.
  • p1=dataset1 pn=datasetn
    Parameters that are written into a data set require a two-level data set name. Writing parameters into data sets can be useful for structured parameters.
INTABLES
passes references to input SAS data sets. Here is how they are defined.
  • p1=dataset1 ... pn=datasetn
    The SAS data sets are converted into internal tables and are passed to the specified function module. The variable names in the SAS data set must match the field names of the internal table as they are defined in the function interface.
OUTTABLES
specifies references to output SAS data sets. Here is how they are defined.
  • p1=dataset1 ... pn=datasetn
    Internal tables that are passed back to SAS from the specified function module are converted into SAS data sets.
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. The alternate logon variable must be defined before the function call is submitted.

Details

If an error occurs while the %CALLRFC macro is executing, the macro variables &SYSRC, &SYSERR, or both contain a nonzero value. (See Checking for Errors Using Macro Variables.) 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 Checking for Errors Using Function Module Parameters.)
Use the RFC_LOGON_INFO macro variable with the %CALLRFC macro. It 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 you can use the R/3 BAPI Connector window. This window automatically displays if you do not use the RFC_LOGON_INFO macro string when you submit your %CALLRFC macro statement. Below are the required connection parameters. If any required values are missing, you are prompted to provide the missing information.
  • CLIENT
  • USER
  • PASSWD (or PASSWDX)
  • LANG
The RFC_LOGON_INFO macro variable also requires some connection information. Here is how to define the connection parameters:
If you use...
Specify...
the saprfc.ini file
DEST value
a specific application server
ASHOST and SYSNR values
load-balancing
MSHOST, R3NAME, and GROUP values
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.

Examples

Example 1: Reading Data into a SAS Data Set

This example shows how to use the %CALLRFC macro to read data from an SAP R/3 system into a SAS data set. The %CALLRFC macro calls the RFC-enabled function module named RFC_SYSTEM_INFO and writes system information output to the WORK.RFCSI_EXPORT SAS data set.
%callrfc(RFC_SYSTEM_INFO
         IMPORTING RFCSI_EXPORT=WORK.RFCSI_EXPORT);

Example 2: Specifying Logon Parameters

This example shows how to use RFC_LOGON_INFO to specify logon parameters for the %CALLRFC macro. TestUser connects to a specific application server to read data from the R/3 system into a temporary SAS data set named WORK.RFCSI_EXPORT.
%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);

Example 3: Using SAS Dates

This example shows how to use SAS dates in the function call. 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. The macro variable is defined before the %CALLRFC macro is used.
%let MRETURN=;
%callrfc(BAPI_COSTCENTER_GETLIST
         EXPORTING CONTROLLINGAREA=1000
                    DATE=%sysfunc(date (), yymmddn8.)
         IMPORTING RETURN=MRETURN
         OUTTABLES COSTCENTER_LIST=WORK.COSTCENTER_LIST);

Example 4: Checking for Errors Using Macro Variables

This example shows how to use the &SYSRC and &SYSERR macro variables to check for errors that occur while the %CALLRFC macro executes. A new macro named %EXAMPLE4 is created. It uses the SAS macro variables &SYSRC and &SYSERR to check return codes from the %CALLRFC macro. It also generates an error message if errors occurred.
%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;

Example 5: Checking for Errors Using Function Module Parameters

This example shows how to use the parameters in the function module to check for errors that occurred while the %CALLRFC macro executes. A new macro named %EXAMPLE5 is created to retrieve a list of customers from the R/3 system. The range of customer numbers to retrieve is specified in the SAS data set WORK.IDRANGE. This data set is then used as the input table in the function call. Information for customers between customer number 0000000000 and 9999999999 is 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.
%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;