INTRODUCTION
After attending the job, details of the work is captured in the PDF document .This PDF forms will be available in external system. SAP PI will pick the PDF forms from external system and trigger the ABAP server proxy with PDF attachment. Data in the PDF attachment should be posted in SAP ECC.
STEPS TO READ THE DATA IN PDF ATTACHMENT OF PROXY
1. In the method of a provider class (of proxy) get the server proxy context into a variable LO_SERVER_CONTEXT (type referring to IF_WS_SERVER_CONTEXT) by calling the method CL_PROXY_ACCESS=>GET_SERVER_CONTEXT.
2. Get the attachments protocols from server context using method LO_SERVER_CONTEXT->GET_PROTOCOL (IF_WSPROTOCOL=>ATTACHMENTS) into LO_ATTACHMENTS (of type referring to IF_WSPROTOCOL_ATTACHMENTS).
3. Read all the available attachments into internal table LT_ATTACH (of type PRX_ATTACH) by calling the method GET_ATTACHMENTS. LO_ATTACHMENTS->GET_ATTACHMENTS ( ).
4. Read data in the attachment using method GET_BINARY_DATA which will be in XSTRING format. LO_ATTACHMENT is the object of type referring to IF_AI_ATTACHMENT. LV_PDF_DATA is of type XSTRING.
Pseudo code:
LOOP AT LT_ATTACH INTO LO_ATTACHMENT.
LV_PDF_DATA = LO_ATTACHMENT->GET_BINARY_DATA( ).
ENDLOOP.
5. To convert the XSTRING data to ADS specific XSTRING data, get FP reference by calling CL_FP=>GET_REFERENCE ( ) into LO_FP.
6. Using GET_REFERENCE method of class interface CL_FP and CREATE_PDF_OBJECT method, convert the XSTRING (LV_PDF_DATA) data to ADS Specific XSTRING Data (LV_XML_DATA).
Pseudo code:
DATA: LO_FP TYPE REF TO IF_FP, LO_PDFOBJ TYPE REF TO IF_FP_PDF_OBJECT, LO_CONVERTER TYPE REF TO CL_ABAP_CONV_IN_CE, LV_FORMXML TYPE STRING.
LO_FP = CL_FP=>GET_REFERENCE ( ).
TRY.
LO_PDFOBJ = LO_FP->CREATE_PDF_OBJECT (CONNECTION = ’ADS’).
LO_PDFOBJ->SET_DOCUMENT (EXPORTING PDFDATA = LV_PDF_DATA).
LO_PDFOBJ->SET_EXTRACTDATA ( ).
LO_PDFOBJ->EXECUTE ( ).
LO_PDFOBJ = LO_FP->CREATE_PDF_OBJECT (CONNECTION = ’ADS’).
LO_PDFOBJ->SET_DOCUMENT (EXPORTING PDFDATA = LV_PDF_DATA).
LO_PDFOBJ->SET_EXTRACTDATA ( ).
LO_PDFOBJ->EXECUTE ( ).
Catch exceptions.
ENTRY.
LO_PDFOBJ->GET_DATA( IMPORTING FORMDATA = LV_XML_DATA ). LO_CONVERTER = CL_ABAP_CONV_IN_CE=>CREATE( INPUT = LV_XML_DATA ).
LO_CONVERTER->READ( IMPORTING DATA = LV_FORMXML ).
LO_CONVERTER->READ( IMPORTING DATA = LV_FORMXML ).
7. Using IXML classes, read the exact node level data from XML data
DATA: LO_IXML TYPE REF TO IF_IXML,
LO_STREAMFACTORY TYPE REF TO IF_IXML_STREAM_FACTORY,
LO_ISTREAM TYPE REF TO IF_IXML_ISTREAM,
LO_PARSER TYPE REF TO IF_IXML_PARSER,
LO_STREAMFACTORY TYPE REF TO IF_IXML_STREAM_FACTORY,
LO_ISTREAM TYPE REF TO IF_IXML_ISTREAM,
LO_PARSER TYPE REF TO IF_IXML_PARSER,
LO_NODE TYPE REF TO IF_IXML_NODE, LO_DOCUMENT TYPE REF TO IF_IXML_DOCUMENT.
*--Get a reference to iXML object.
LO_IXML = CL_IXML=>CREATE( ).
LO_STREAMFACTORY = LO_IXML->CREATE_STREAM_FACTORY( ).
LO_ISTREAM = LO_STREAMFACTORY->CREATE_ISTREAM_STRING( LV_FORMXML ).
LO_IXML = CL_IXML=>CREATE( ).
LO_STREAMFACTORY = LO_IXML->CREATE_STREAM_FACTORY( ).
LO_ISTREAM = LO_STREAMFACTORY->CREATE_ISTREAM_STRING( LV_FORMXML ).
*-create an xml document class that will be used to process the xml
LO_DOCUMENT = LO_IXML->CREATE_DOCUMENT( ).
*--create the parser class
LO_PARSER = LO_IXML->CREATE_PARSER( STREAM_FACTORY = LO_STREAMFACTORY
ISTREAM = LO_ISTREAM
DOCUMENT = LO_DOCUMENT ).
*--parse the xml
LO_PARSER->PARSE( ).
LO_DOCUMENT = LO_IXML->CREATE_DOCUMENT( ).
*--create the parser class
LO_PARSER = LO_IXML->CREATE_PARSER( STREAM_FACTORY = LO_STREAMFACTORY
ISTREAM = LO_ISTREAM
DOCUMENT = LO_DOCUMENT ).
*--parse the xml
LO_PARSER->PARSE( ).
8. Use FIND_FROM_NAME method of interface IF_IXML_DOCUMENT to read the data in each field in PDF form.
LO_NODE = LO_DOCUMENT->FIND_FROM_NAME (NAME = “FIELD NAME”).
IF LO_NODE IS BOUND.
LV_FIELD_VALUE = LO_NODE->GET_VALUE ( ).
LV_FIELD_VALUE = LO_NODE->GET_VALUE ( ).
3. DEBUGGING ABAP SERVER PROXY WITH PDF ATTACHMENT.
1. Keep External breakpoints in the provider class of the proxy.
2. Keep the system debugging on.
3. Deregister the receiver queues in TCODE: ‘SXMB_ADM’.
4. Trigger the proxy from SAP PI. So that an XML message is created in SAP ECC.
Go to Tcode: SXMB_MONI, click execute button and find the queue name in corresponding XML message.
Select the XML message & click on the details button for checking the queue name.
5. Go to Tcode: SMQ2 and click execute
Double click on the queue name until you see the user as ‘the particular user with which proxy is triggered from SAP PI’.Select the queue & go to “EDIT” and select “Save LUW”.
6. Go to “SXMB_MONI”, select the XML message and click on the “Restart” button. Select “Retain” button. Click Refresh button, so that queue status is change to “Manual Restart” from “Scheduled”.
7. Go to “SMQ2”, double click on the queue.
Select the queue & go to EDIT and select “Debug LUW”.
ABAP Debugger is triggered. In this way you can debug the ABAP Proxy with PDF attachment. In Debugger you can view the PDF form data in different converted formats and check the field level data of the PDF attachment.
Note:
· After debugging, register the receiver queues (Which have been deregistered earlier) in TCODE: ‘SXMB_ADM’.
· The other way of debugging is to keep the system debugging on, keep the external breakpoints in proxy class with the user with which proxy is triggered from SAP PI & set that user to Dialog user in TCODE SU01.