Previous Page | Next Page

Using the RFC Macros and Macro Variables

%CALLRFC



Calls a specified RFC-enabled function module
Type: autocall macro
See also:

Using the R/3 BAPI Connector: Logon Window

RFC_LOGON_INFO


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

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:

  • 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 (a complex parameter that contains fields).

IMPORTING

passes field values or structures from the specified function module back to SAS. The IMPORTING parameters are defined as follows:

  • p1=var1 ... pn=varn

    The p1 ... pn parameters are export parameters 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. The INTABLES parameters are defined as follows:

  • p1=dataset1 ... pn=datasetn

    The SAS data sets are converted into internal tables and are passed to the specified function module.

    Note:   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.  [cautionend]

OUTTABLES

specifies references to output SAS data sets. The OUTTABLES parameters are defined as follows:

  • p1=dataset1 ... pn=datasetn

    Internal tables 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.

Note:   The alternate logon variable must be defined before the function call is submitted.  [cautionend]

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.)  [cautionend]


Using

The following macro variables are used with the %CALLRFC macro:


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.

Previous Page | Next Page | Top of Page