ABAP 调用BAPI-实例
程序员文章站
2022-06-01 15:01:59
...
从本地系统调用BAPI
利用现有的BAPI读取特定航线的航班列表。
*&---------------------------------------------------------------------*
*& Report Z_BAPIDEMO
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_BAPIDEMO.
TABLES : bapisflist ,
BAPISFDETA.
PARAMETERS :
fromcoun type bapisfdeta-countryfr OBLIGATORY,
fromcity type bapisfdeta-cityfrom OBLIGATORY,
tocun TYPE bapisfdeta-countryto OBLIGATORY,
tocity TYPE bapisfdeta-cityto OBLIGATORY,
carrier TYPE bapisfdeta-carrid OBLIGATORY.
DATA: return TYPE bapiret2,
msg(80),
flightlist TYPE STANDARD TABLE OF bapisflist ,
ls_flightlist type bapisflist.
START-OF-SELECTION.
CALL FUNCTION 'BAPI_SFLIGHT_GETLIST'
EXPORTING
FROMCOUNTRYKEY = fromcoun
FROMCITY = fromcity
TOCOUNTRYKEY = tocun
TOCITY = tocity
AIRLINECARRIER = carrier
* AFTERNOON = ' '
* MAXREAD = 0
IMPORTING
RETURN = return
TABLES
FLIGHTLIST = flightlist
.
CASE sy-subrc.
WHEN 0.
IF return-type <> 's'.
WRITE : / return-message.
else.
PERFORM print_list.
ENDIF.
when 1 or 2.
WRITE : / msg.
when OTHERS.
WRITE : / 'Other error occurs.'.
ENDCASE.
*&---------------------------------------------------------------------*
*& Form PRINT_LIST
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM PRINT_LIST .
loop at flightlist into ls_flightlist.
write : / ls_flightlist-carrid,
ls_flightlist-connid,
ls_flightlist-fldate,
ls_flightlist-airpfrom,
ls_flightlist-deptime,
ls_flightlist-seatsmax,
ls_flightlist-seatsocc.
endloop.
ENDFORM.
如果数据库表有该相关信息则显示。
从远程系统调用BAPI
通过上面实例,即可实现BAPI功能模块的远程调用过程。该调用在逻辑系统DEST中运行功能模块。BAPI_SFLIGHT_GETLIST,并读取该系统中的航班列表,通过flightlist参数返回给本地系统处理并使用。
TCODE:SM51找到对应的RFC Connections 例:CQXCLNT100
*&---------------------------------------------------------------------*
*& Report Z_BAPIDEMO
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_BAPIDEMO.
TABLES : bapisflist ,
BAPISFDETA.
PARAMETERS :
fromcoun type bapisfdeta-countryfr OBLIGATORY,
fromcity type bapisfdeta-cityfrom OBLIGATORY,
tocun TYPE bapisfdeta-countryto OBLIGATORY,
tocity TYPE bapisfdeta-cityto OBLIGATORY,
carrier TYPE bapisfdeta-carrid OBLIGATORY.
DATA: return TYPE bapiret2,
msg(80),
flightlist TYPE STANDARD TABLE OF bapisflist ,
ls_flightlist type bapisflist.
START-OF-SELECTION.
CALL FUNCTION 'BAPI_SFLIGHT_GETLIST'
DESTINATION 'CQXCLNT100'
EXPORTING
FROMCOUNTRYKEY = fromcoun
FROMCITY = fromcity
TOCOUNTRYKEY = tocun
TOCITY = tocity
AIRLINECARRIER = carrier
* AFTERNOON = ' '
* MAXREAD = 0
IMPORTING
RETURN = return
TABLES
FLIGHTLIST = flightlist
.
CASE sy-subrc.
WHEN 0.
IF return-type <> 's'.
WRITE : / return-message.
else.
PERFORM print_list.
ENDIF.
when 1 or 2.
WRITE : / msg.
when OTHERS.
WRITE : / 'Other error occurs.'.
ENDCASE.
*&---------------------------------------------------------------------*
*& Form PRINT_LIST
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM PRINT_LIST .
loop at flightlist into ls_flightlist.
write : / ls_flightlist-carrid,
ls_flightlist-connid,
ls_flightlist-fldate,
ls_flightlist-airpfrom,
ls_flightlist-deptime,
ls_flightlist-seatsmax,
ls_flightlist-seatsocc.
endloop.
ENDFORM.
代码中将RFC Connection 名称填写到destination后实现远程系统的数据连接。
上一篇: vue-spa项目实现tab页