天天看点

webservice篇1 ABAP调用webservice

在ABAP中调用Webservice

一. 创建Webservice

    有两种方式创建webservice,一种是在se80中使用wizard生成,另一种是直接在se37中给予function生成,具体操作如下:

    1.se80中Create-->Enterprise Service/Web Service --> Web Servcie

      维护service名,选择一个poit type(type point为一个功能点:如,Bapi中的Method,FunctionGroup中的一个function,一个function或者Message Interface:XI)

    2.se37 Utility--> More Utility --> Create WebService -->From the Function Module

    在创建完成的时候可以选择立刻release,否则需要在wsconfig中进行release。

二 WSASMIN(WebService Administration)

     Tcode:wsadmin

    选中刚刚创建的Webservice ,可以有两种操作测试webservice

   1.点击Ctrl+F8 --> 进入WebService HomePage(可以预览webservice发送接收的数据)

    2.点击Ctrl+F1 --> 预览WSDL文档

三 在Wsconfig中设置Logon Data

    输入Service Definition , 并填写一个Variant,点击新建

   Create --> ICF Detail -->在Servcie列表中选择需要设置Logo Data的Service,双击,在logon data的tab页中设置logo data(设置了logon data的service在调用时就不会在弹出logon对话框)

    (tcode :SICF 可以直接进入Maintain Service)

四 在ABAP中调用Webservice

    1.创建Proxy

     se80 --> Create --> Enterprice Service --> Proxy

    在Proxy中指定wsdl连接

    2. 创建Logical Port (tcode:lpconfig)

    输入Logical Port,指定Proxy Class,点击新建。

    3.创建程序

      在se80中,将Proxy拖入到workbench中,自动生成代码框架,根据自己需求进行简单的修改,代码示例如下:

DATA: g_proxy TYPE REF TO zglco_zgl_flight .
TRY.
    CREATE OBJECT g_proxy
      EXPORTING logical_port_name = 'ZGLPORT_FLIGHT'
         .
  CATCH cx_ai_system_fault .
ENDTRY.

DATA: output TYPE zglflight_get_list_response .
DATA: input TYPE zglflight_get_list .

input-max_rows = 10 .
TRY.
    CALL METHOD g_proxy->flight_get_list
      EXPORTING
        input   = input
      IMPORTING
        output = output.
  CATCH cx_ai_system_fault .
  CATCH cx_ai_application_fault .
ENDTRY.
DATA : ls_sflight TYPE zglbapisfldat.
DATA : lt_sflight TYPE zglbapisfldat_tab .

lt_sflight = output-flight_list-item .

LOOP AT lt_sflight INTO ls_sflight .

  WRITE    : ls_sflight-airlineid , ls_sflight-airline ,
             ls_sflight-connectid , ls_sflight-flightdate ,
             ls_sflight-airportfr , ls_sflight-cityfrom ,
             ls_sflight-airportto , ls_sflight-cityto ,
             ls_sflight-deptime ,    ls_sflight-arrtime ,
             ls_sflight-arrdate ,    ls_sflight-price ,
             ls_sflight-curr ,       ls_sflight-curr_iso .
  ULINE .

ENDLOOP.      

详细步骤:

  1. SE80 创建企业服务

     ​​

    webservice篇1 ABAP调用webservice
webservice篇1 ABAP调用webservice
webservice篇1 ABAP调用webservice
webservice篇1 ABAP调用webservice

填入链接

webservice篇1 ABAP调用webservice