• 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.

     
  • 相关阅读:
    常见的Mysql十款高可用方案
    01 . OpenResty简介部署,优缺点,压测,适用场景及用Lua实现服务灰度发布
    08 . Jenkins之SpringCloud微服务+Vue+Docker持续集成
    TomcatAJP文件包含漏洞及线上修复漏洞
    Nginx升级加固SSL/TLS协议信息泄露漏洞(CVE-2016-2183)和HTTP服务器的缺省banner漏洞
    03 . Go开发一个日志平台之Elasticsearch使用及kafka消费消息发送到Elasticsearch
    关于本博客皮肤样式配置
    01 . etcd简介原理,应用场景及部署,简单使用
    Spring Cloud Config
    Spring Cloud Gateway
  • 原文地址:https://www.cnblogs.com/xiaomaohai/p/6157093.html
Copyright © 2020-2023  润新知