zoukankan      html  css  js  c++  java
  • ABAPC语言调用SAP的RFC的代码样例

    C语言代码
    #include <stdlib.h>
    #include <stdio.h>
    #include "sapnwrfc.h"

    RFC_RC SAP_API stfc_connection_impl(RFC_CONNECTION_HANDLE rfcHandle, RFC_FUNCTION_HANDLE funcHandle, RFC_ERROR_INFO* errorInfo){
     RFC_RC rc = RFC_OK;
     SAP_UC requtext[256], buf[256];

     rc = RfcGetString(funcHandle, cU("REQUTEXT"), requtext, 256, NULL, errorInfo);
     printfU(cU("Got request for STFC_CONNECTION./nREQUTEXT = %s/n/n"), requtext);
     sprintfU(buf, cU("STFC_CONNECTION called with REQUTEXT = %s"), requtext);
     rc = RfcSetString(funcHandle, cU("ECHOTEXT"), buf, strlenU(buf), errorInfo);

     return rc;
    }

    int mainU(int argc, SAP_UC** argv){
     RFC_RC rc = RFC_OK;
     RFC_CONNECTION_PARAMETER loginParams[1];
     RFC_ERROR_INFO errorInfo;
     RFC_CONNECTION_HANDLE connection;
     RFC_FUNCTION_DESC_HANDLE z_perform_callback, stfc_connection;
     RFC_FUNCTION_HANDLE functionContainer;
     SAP_UC data[256];

     loginParams[0].name = cU("dest"); loginParams[0].value = cU("SPJ");

     connection = RfcOpenConnection(loginParams, 1, &errorInfo);
     if (connection == NULL){
      printfU(cU("Error during logon: %s/n"), errorInfo.message);
      printfU(cU("Please check that the sapnwrfc.ini file is in the current/nworking directory and the logon parameters are ok./n"));
      return 1;
     }

     /* Note: In the following all error handling is omitted for simplicity. */
     z_perform_callback = RfcGetFunctionDesc(connection, cU("Z_PERFORM_CALLBACK"), &errorInfo);
     stfc_connection = RfcGetFunctionDesc(connection, cU("STFC_CONNECTION"), &errorInfo);

     // The stfc_connection_impl function will be called from R/3 during the RfcInvoke step below!
     rc = RfcInstallServerFunction(NULL, stfc_connection, stfc_connection_impl, &errorInfo);

     functionContainer = RfcCreateFunction(z_perform_callback, &errorInfo);

     rc = RfcSetString(functionContainer, cU("INPUT_DATA"), cU("Original Request"), 16, &errorInfo);
     rc = RfcInvoke(connection, functionContainer, &errorInfo);
     rc = RfcGetString(functionContainer, cU("OUTPUT_DATA"), data, 256, NULL, &errorInfo);

     RfcCloseConnection(connection, NULL);

     printfU(cU("Response from Z_PERFORM_CALLBACK: OUTPUT_DATA = %s/n"), data);
     return 0;

    ABAP代码
    FUNCTION z_perform_callback.
    *"----------------------------------------------------------------------
    *"*"Local interface:
    *"  IMPORTING
    *"     VALUE(INPUT_DATA) TYPE  CHAR255
    *"  EXPORTING
    *"     VALUE(OUTPUT_DATA) TYPE  CHAR255
    *"----------------------------------------------------------------------

      DATA: error_message(120),
            request LIKE sy-lisel,
            echo LIKE sy-lisel.

      CONCATENATE 'Z_PERFORM_CALLBACK called with INPUT_DATA =' input_data
        INTO request SEPARATED BY space.

      CALL FUNCTION 'STFC_CONNECTION' DESTINATION 'BACK'
        EXPORTING
          requtext       = request
        IMPORTING
          echotext       = echo
    *    RESPTEXT       =
        EXCEPTIONS
          system_failure = 1 MESSAGE error_message
          communication_failure = 2 MESSAGE error_message
                .

      IF sy-subrc NE 0.
        CONCATENATE 'Error during callback:' error_message INTO output_data
        SEPARATED BY space.
      ELSE.
        CONCATENATE 'Response from STFC_CONNECTION: ECHOTEXT =' echo INTO output_data
        SEPARATED BY space.
      ENDIF.

    ENDFUNCTION.

     
  • 相关阅读:
    openlayers6聚合图(附源码下载)
    arcgis api 4.x for js地图加载第三方矢量切片
    leaflet读取tif像素值的两种实现方式(附源码下载)
    openlayers6热力图(附源码下载)
    cesium 3dtiles模型单体化点击高亮效果
    leaflet聚合图功能(附源码下载)
    openlayers6绘制扇形(附源码下载)
    【 Windows 10】神州网信政府版官方镜像
    Windows10 解决“装了 .NET Framework 4.5.2/4.6.1/4.7.1等等任何版本 或版本更高的更新”问题
    App.config/Web.config 中特殊字符的处理
  • 原文地址:https://www.cnblogs.com/xiaomaohai/p/6157093.html
Copyright © 2011-2022 走看看