In order to develop a ABAP Proxy first we need to have a Proxy Configured in the transaction SPROXY, this is to be done by PI or XI consultant, as a ABAPer you are not concerned with this.
The Proxy configured in SPROXY will look like.
By Clicking on the structure we can also see the structure of the Proxy, which is in tree structure.
In this case, proxy have 4 structured to be filled with data and then trigger the proxy to PI.
In order to create the proxy from the namespace given, we need to do following
1.Right click on the Message interface(outbound) and click on create
2.After clicking on create it will ask for Transport Request no, prefix, proxy class and other details, that we need to give in order to create the proxy and then activate.
3.We need to create a simple report program using SE38 .
4.We need to create a structure that will refer to the proxy structure. We need to populate this in order to send our data.
g_t_header TYPE zintercompany_data _send .
5.Various data declalarions required for Proxy sending and PDF attachment sending are.
attch_protocol TYPE REF TO if_wsprotocol_attachments,
g_attachment TYPE REF TO if_ai_attachment,
g_attachments TYPE prx_attach, "Internal table for attachment
g_attach_xstring TYPE xstring, "variable of xstring type.
g_spool_id TYPE tsp01-rqident,
g_pripar TYPE pri_params,
g_arcpar TYPE arc_params,
g_pdfspoolid TYPE tsp01-rqident, "SPOOL ID
g_jobname TYPE tbtcjob-jobname, "Jobname parameter for SPOOL
g_jobcount TYPE tbtcjob-jobcount, "Jobcount Paramater for SPOOL
g_string TYPE string, "To convert 132 character data into 255 character data.
*Reference variables exception class
lo_sys_exception TYPE REF TO cx_ai_system_fault,
*Object declaration for Proxy Class
obj_invoice1 TYPE REF TO “Proxy class name”.
* creating proxy object
CREATE OBJECT obj_invoice1.
6.If some amount field is involved, we can use FM CONVERSION_EXIT_CUNIT_OUTPUT to put –ve sign on the left side.
7.Update the main structure with the data required, if some substructures are there, then also finally we need to fill the main structure we only, that will be passed while triggering the proxy.
g_t_header-invoice_details-invoice_line_item[] = g_t_tab_det[].
g_t_header-invoice_properties = wa_inv_pro.
8.Get all the data required for PDF into a internal table.
9.In order to send the PDF into the proxy we need to get all the data in a “Xstring” type variable. To do so first we need to create a SPOOL of the data in our internal table.
10.Use FM 'GET_PRINT_PARAMETERS', if some special format is required. Start the TRY-CATCH Block. To create SPOOL :
NEW-PAGE PRINT ON
PARAMETERS g_pripar
ARCHIVE PARAMETERS g_arcpar
NO DIALOG.
“Write your data that need to be printed , with the format required for PDF. Whatever written here will be converted into SPOOL.
g_spool_id = sy-spono.
NEW-PAGE PRINT OFF.
11.We need to convert this SPOOL into PDF format using FM 'CONVERT_ABAPSPOOLJOB_2_PDF'
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = g_spool_id " SPOOL ID
no_dialog = ' '
IMPORTING
pdf_bytecount = g_size_bytes
pdf_spoolid = g_pdfspoolid
btc_jobname = g_jobname
btc_jobcount = g_jobcount
TABLES
pdf = g_table " All the data will be in this Data table
12.Converting the 132 character data to 255 character data
CLEAR g_string.
LOOP AT g_table INTO wa_table.
TRANSLATE wa_table USING ' |'.
CONCATENATE g_string wa_table INTO g_string.
ENDLOOP.
TRANSLATE g_string USING '| '.
DO.
wa_buf = g_string.
APPEND wa_buf TO g_t_buf.
SHIFT g_string BY 255 PLACES.
IF g_string IS INITIAL.
EXIT.
ENDIF.
ENDDO.
13.Appending 255 character data in one variable.
IF g_t_buf[] IS NOT INITIAL.
LOOP AT g_t_buf INTO wa_buf.
CONCATENATE
g_output
wa_buf
INTO g_output.
ENDLOOP.
14.Convert the Binary String to XSTRING
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = g_output
IMPORTING
buffer = g_outputx
15.Concatenating attach_xstring with the data field.We need to send this field to Proxy.
CONCATENATE g_attach_xstring g_outputx INTO g_attach_xstring IN BYTE MODE.
16.Below is the code required to send the proxy.
TRY-CATCH
* Get attachment protocol
TRY.
attch_protocol ?= obj_invoice1->get_protocol( if_wsprotocol=>attachments ).
g_attachment = attch_protocol->get_attachment_from_binary(
data = g_attach_xstring
type = if_ai_attachment=>c_mimetype_pdf
name = 'PDF Attachment' ). " Name of PDF to be uploaded
APPEND g_attachment TO g_attachments.
attch_protocol->set_attachments( g_attachments ).
*Sending Proxy fields to XI through EXECUTE ASYNCHRONOUS Method.
CALL METHOD obj_invoice1->execute_asynchronous
EXPORTING
output = g_t_header.
CATCH cx_ai_system_fault INTO lo_sys_exception.
COMMIT WORK.
ENDTRY.
CATCH cx_ai_system_fault INTO lo_sys_exception.
ENDTRY.
17.Other Exception Handling can be done as per the requirement. Using the “SXMB_MONI” TCode we can check whether the proxy has been sent successfully or not.
No comments:
Post a Comment