Professional Documents
Culture Documents
ABAP-based HTTP Client For Messages To SAP XI PDF
ABAP-based HTTP Client For Messages To SAP XI PDF
Messages to SAP XI
Applies To:
SAP NW 04 – XI 3.0 and SAP R/3 4.6C and above
Summary
In the SAP Exchange Infrastructure (XI), the HTTP adapter is native to the Integration Server (IS). A sender
HTTP Adapter need not be configured in XI. HTTP messages can be sent to the native HTTP adapter of XI.
There is a browser-based tool already available for this purpose. This article describes an ABAP-based tool
for acting as the sender HTTP adapter.
Table of Contents
Applies To:........................................................................................................................................1
Summary ..........................................................................................................................................1
Introduction.......................................................................................................................................2
Runtime behavior..........................................................................................................................5
Program Constraints.....................................................................................................................6
Texts needed for the ABAP program for HTTP Client ...................................................................14
Author Bio.......................................................................................................................................15
Introduction
The HTTP adapter can be used for sending a payload to XI without SOAP envelope. It is native to the
Integration Server (IS) in XI. Consequently, there is no need to configure a sender HTTP Adapter in XI.
Browser-based tools are already available for sending HTTP messages to the native HTTP adapter of XI.
However, an ABAP-based tool can have certain advantages over the browser-based tool, if the sending
system is based on SAP. This article describes an ABAP-based tool for acting as the sender HTTP
adapter.
There may be valid business reasons for the SAP-based sending system to use a HTTP adapter, such
as:
Some advantages of using an ABAP-based HTTP Client as compared to the browser-based tool:
o Provision to integrate the application into the business events of the back-end ERP system
o In-line Text Editor that can be used for editing the Payload
o Can be enhanced to include logging the errors to a file and any custom validations on the
Payload contents and communication data
The reason for using this function module HTTP2_POST and not the Class CL_HTTP_CLIENT is that this
tool should be useful for older versions of SAP. The Class CL_HTTP_CLIENT has been undergoing
some revisions long after the function module HTTP2_POST became available. If needed, the code can
be modified to use the Class CL_HTTP_CLIENT instead.
Variants can be created and used as needed for each receiver. For example:
Field Description
Integration Server The XI Integration Server’s <Host>:<Port>
Host&Port
Quality of Service Allowed values:
o BE (Best Effort)
o EO (Exactly Once)
o EOIO (Exactly Once In Order)
Client SAP Client of the XI system
User User to access the XI system client
o Defaults to XIAPPLUER
o If different, the user should have the same roles as XIAPPLUER
Password Password for the user access to the XI system client
Language Logon language for the user access to XI system client, Defaults to DE
Party Sender Party, Optional
If the option ‘Insert Payload as Text’ is chosen, a Text editor appears as follows, where the payload can
be entered, edited or pasted.
Runtime behavior
When executed successfully, the results of the program run appear as in the following example. This
example uses an Asynchronous call (QoS = EO). For Synchronous calls (QoS = BE), the results will
be reported as in the internal table GT_RESPONSE_ENTITY_BODY.
When executed with errors, the results of the program run appear as in the following example. This
example uses an Asynchronous call (QoS = EO), with a wrong Sender Service, resulting in errors
during Receiver Determination in XI.
Program Constraints
o When uploading the payload from a file, the line width has a limit of 1024 characters. Any
characters in a line after position 1024 will be truncated.
o The password is not encrypted on the selection screen, for easier administration. If needed, code
can be modified to encrypt this.
*&---------------------------------------------------------------------*
report Z_HTTP_CLIENT_FOR_XI line-size 132 line-count 65.
*---------------------------------------------------------------------*
*Data declaration
*---------------------------------------------------------------------*
tables SSCRFIELDS.
*---------------------------------------------------------------------*
*Selection Screen
*---------------------------------------------------------------------*
*HTTP Client for sending a message to XI Sender HTTP Adapter
selection-screen begin of block HTTP_CLIENT with frame title TEXT-S01.
selection-screen skip 1.
*Header Parameters
selection-screen begin of block HEADER_INFO with frame title TEXT-S02.
parameters:
P_SRVHST(255) type C lower case obligatory,
" Integration Server URL with Host and Port
P_QOS(4) type C, " Quality of Service
*Logon information
P_CLIENT type MANDT obligatory, " Integration Server SAP Client
P_USER type SY-UNAME obligatory default 'XIAPPLUSER', " User
P_PASSWD(20) type C lower case obligatory, " Password
P_LANGU type SPRAS obligatory default 'DE'. " Logon language
*Sender information
selection-screen begin of block SENDER_INFO with frame title TEXT-S03.
parameters:
P_PARTY(60) type C lower
case, " Sender Party
P_SCHEME(120) type C lower
case, " Sender Scheme
P_AGENCY(120) type C lower
case, " Sender Agency
P_SERVIC(60) type C lower
case obligatory, " Sender Service
P_NMSPAC(60) type C lower
case obligatory,
" Sender Interface Namespace
P_INTERF(60) type C lower case obligatory. " Sender Interface
* Payload
selection-screen begin of block PAYLOAD with frame title TEXT-S04.
*---------------------------------------------------------------------*
at selection-screen.
*---------------------------------------------------------------------*
G_UCOMM = SY-UCOMM.
if G_UCOMM = 'PAYL'.
if P_PAYTXT = 'X'.
editor-call for GT_PAYLOAD title 'Payload Text'(001)
backup into GT_PAYLOAD.
clear: P_FILE.
endif.
endif.
*---------------------------------------------------------------------*
at selection-screen on value-request for P_FILE.
*---------------------------------------------------------------------*
perform FILENAME_HELP using P_FILE.
*---------------------------------------------------------------------*
at selection-screen output.
*---------------------------------------------------------------------*
if G_UCOMM = 'PAYL'.
if P_PAYTXT = 'X'.
loop at screen.
if SCREEN-GROUP1 = 'FIL'.
SCREEN-ACTIVE = '0'.
SCREEN-INVISIBLE = '1'.
modify screen.
endif.
endloop.
endif.
endif.
*---------------------------------------------------------------------*
start-of-selection.
*---------------------------------------------------------------------*
*If there is a file name, ignore the Payload uploaded as Text and read
*it from the file name.
if P_FILE is not initial.
clear GT_PAYLOAD.
* Upload the payload from file
perform PAYLOAD_FROM_FILE tables GT_STRING using P_APP P_FILE.
call function 'CONVERT_TABLE_TO_STRING'
exporting
I_TABLINE_LENGTH = 1024
importing
E_STRING = G_STR
tables
IT_TABLE = GT_STRING.
if GT_PAYLOAD is initial.
message I499(SY) with 'Payload is empty'(003).
stop.
endif.
'&sap-password=' P_PASSWD
'&sap-client=' P_CLIENT
'&sap-language=' P_LANGU
into G_QUERY.
GS_LINE-LINE = G_REQUEST_ENTITY_BODY_LENGTH.
shift GS_LINE-LINE left deleting leading SPACE.
concatenate 'content-length:' GS_LINE-LINE into
GS_LINE-LINE separated by SPACE.
append GS_LINE to GT_REQUEST_HEADERS.
if SY-SUBRC <> 0.
message id SY-MSGID type SY-MSGTY number SY-MSGNO
with SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
else.
write:/ 'Response from HTTP Post:'(004) color 1.
uline.
skip 1.
write:/ 'Status Code:'(005) color 1, 20 G_STATUS_CODE,
/ 'Status Text:'(006) color 1, 20 G_STATUS_TEXT.
uline.
*&---------------------------------------------------------------------*
*& Form PAYLOAD_FROM_FILE
*&---------------------------------------------------------------------*
* To upload the Payload from File into an internal table
*----------------------------------------------------------------------*
form PAYLOAD_FROM_FILE tables LT_PAYLOAD
using L_APP type ANY
L_FILENAME type RLGRAP-FILENAME.
if SY-SUBRC <> 0.
message I499(SY) with 'File upload failed'(009) L_FILENAME.
stop.
endif.
else.
message I499(SY) with 'File upload failed'(009) L_FILENAME.
stop.
endif.
endif.
endform. "PAYLOAD_FROM_FILE
*&---------------------------------------------------------------------*
*& Form FILENAME_HELP
*&---------------------------------------------------------------------*
* Search Help for File name
*----------------------------------------------------------------------*
form FILENAME_HELP using L_FILE type RLGRAP-FILENAME.
UNDEFIND_ERROR = 8
DOUBLE_CONVERSION = 9
STEPL_NOT_FOUND = 10
others = 11.
if SY-SUBRC <> 0.
message I499(SY) with 'Selection Screen could not be read'(010).
elseif not LT_FIELDLIST[] is initial.
read table LT_FIELDLIST into LS_FIELDLIST
with key FIELDNAME = 'P_APP'.
if SY-SUBRC = 0.
move LS_FIELDLIST-FIELDVALUE to L_APP.
endif.
read table LT_FIELDLIST into LS_FIELDLIST
with key FIELDNAME = 'P_FILE'.
if SY-SUBRC = 0.
move LS_FIELDLIST-FIELDVALUE to L_FILE.
endif.
endif.
L_PATH = L_FILE.
if SY-SUBRC <> 0.
message I499(SY) with 'No application server name defined'(012).
endif.
else.
L_FILE = L_PATH.
endif.
else.
L_FIELDNAME = 'P_FILE'.
call function 'F4_FILENAME'
exporting
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = L_FIELDNAME
importing
FILE_NAME = L_FILE.
endif.
Selection Texts
P_AGENCY Agency
P_APP File on Application Server
P_CLIENT Client
P_FILE Name of File
P_INTERF Interface
P_LANGU Language Key
P_LCL File on Local Computer
P_NMSPAC Interface Namespace
P_PARTY Party
P_PASSWD Password
P_PAYFIL Payload from File
P_PAYTXT Payload as Text
P_QOS Quality of Service
P_SCHEME Scheme
P_SERVIC Service
P_SRVHST Integration Server Host&Port
P_USER User
Text Elements
001 Payload Text
002 Enter a File Name
003 Payload is empty
004 Response from HTTP Post:
005 Status Code:
006 Status Text:
Author Bio
SAP will not be held liable for any damages caused by using or misusing the information, code or methods
suggested in this document, and anyone using these methods does so at his/her own risk.
SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of
this technical article or code sample, including any liability resulting from incompatibility between the content
within this document and the materials and services offered by SAP. You agree that you will not hold, or seek
to hold, SAP responsible or liable with respect to the content of this document.