Internet Communicatin Framework简单应用实例
SAP提供了ICF通过Internet与外部进行通讯,下面只是基本ABAP Object的一个错误的例子进行了修改,附代码如下:
?
1,SICF创建一个Server: z_http_service
?
2, SE24自定义一个类,并引入interface为IF_HTTP_EXTENSION,并声明如下数据类型:
? types:
??? BEGIN OF tline,
??????? datestr??????? TYPE c LENGTH 10,
??????? planetypestr?? TYPE c LENGTH 10,
??????? seatsfreestr?? TYPE c LENGTH 10,
????? END OF tline .
? types:
??? BEGIN OF tflight,
???????????? carrid??????? TYPE spfli-carrid,
???????????? connid??????? TYPE spfli-connid,
???????????? cityfrom????? TYPE spfli-cityfrom,
???????????? cityto??????? TYPE spfli-cityto,
???????????? valuestr????? TYPE char100,
???????????? table???????? TYPE STANDARD TABLE OF tline
??????????????????????????????? WITH NON-UNIQUE DEFAULT KEY,
?????????? END OF tflight .
METHOD if_http_extension~handle_request.
* wait up to 1 seconds.
? DATA: header_data? TYPE string,
??????? html_body??? TYPE string,
??????? fldate?????? TYPE sflight-fldate,
??????? planetype??? TYPE sflight-planetype,
??????? seatsocc???? TYPE sflight-seatsocc,
??????? seatsmax???? TYPE sflight-seatsmax,
??????? line???????? TYPE tline,
??????? flight?????? TYPE tflight.
*? header_data? =? server->request->get_header_field(
*????????????????? if_http_header_fields_sap=>query_string ).
*? FIND REGEX '(\D+)(\d+)' IN header_data
*?????? SUBMATCHES flight-carrid flight-connid.
? flight-carrid = server->request->get_form_field( 'P1' ).
? flight-connid = server->request->get_form_field( 'P2' ).
? SELECT SINGLE cityfrom cityto
???????? FROM spfli
???????? INTO? (flight-cityfrom, flight-cityto)
???????? WHERE carrid = flight-carrid AND
?????????????? connid = flight-connid .
? SELECT fldate planetype seatsocc seatsmax
???????? FROM sflight
???????? INTO (fldate, planetype, seatsocc, seatsmax)
???????? WHERE carrid = flight-carrid AND
?????????????? connid = flight-connid.
??? WRITE fldate????? TO line-datestr.
??? line-planetypestr = planetype.
??? line-seatsfreestr = seatsmax - seatsocc.
??? APPEND line TO flight-table.
? ENDSELECT.
? CALL TRANSFORMATION z_flight_to_html
?????????? SOURCE flight = flight
?????????? RESULT XML html_body.
? server->response->set_header_field(
??????????????????? name? = if_http_header_fields=>content_type
??????????????????? value = 'text/html'
? ).
? server->response->set_cdata( data = html_body ).
ENDMETHOD.
?
3,创建Simple Transformation(ST),代码如下:
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
? <tt:root name="FLIGHT"/>
? <tt:template>
??? <html>
????? <body>
??????? <h2>
????????? <tt:value ref=".FLIGHT.carrid"/>
????????? <text/>
????????? <tt:value ref=".FLIGHT.connid"/>
??????? </h2>
??????? <h3>
????????? <tt:value ref=".FLIGHT.cityfrom"/>
????????? <text>-</text>
????????? <tt:value ref=".FLIGHT.cityto"/>
??????? </h3>
??????? <table border="2">
????????? <tr>
??????????? <td>
????????????? <b>date</b>
??????????? </td>
??????????? <td>
????????????? <b>planetype</b>
??????????? </td>
??????????? <td>
????????????? <b>Availability</b>
??????????? </td>
????????? </tr>
????????? <tt:loop ref=".FLIGHT.table">
??????????? <tr>
????????????? <td>
??????????????? <tt:value ref="datestr"/>
????????????? </td>
????????????? <td>
??????????????? <tt:value ref="planetypestr"/>
????????????? </td>
????????????? <td>
??????????????? <tt:value ref="seatsfreestr"/>
????????????? </td>
??????????? </tr>
????????? </tt:loop>
??????? </table>
????? </body>
??? </html>
? </tt:template>
</tt:transform>
?
4,链接参数:
http://(sapserver):8000/z_http_service?sap-client=800&P1=AA&P2=0017
?
?
?
ST语法参考:
http://help.sap.com/saphelp_nw70/helpdata/en/e3/7d4719ca581441b6841f1054ff1326/frameset.htm