Sie sind auf Seite 1von 3

11/10/2016

StepbyStepguidetodevelopOutboundABAPProxywithPDFattachment.ABAPDevelopmentSCNWiki
GettingStarted

CommunityWIKI

SAPCommunity

Welcome,Guest

Login

Store

Register

ABAPDevelopment

StepbyStepguidetodevelopOutboundABAPProxywithPDFattachment.
CreatedbyAjayN.Kumar,lastmodifiedonJul04,2011

InordertodevelopaABAPProxyfirstweneedtohaveaProxyConfiguredinSPROXYtCode,thisistobedonebyXIperson,asaABAPeryouarenotconcernedwiththis.WeneedtoActivatethis
Proxyconfigured.AlthoughProxydemandsalittlemorecodethanIDoc'sbutustillitsabetteroptiontochoose.

Author:Ajaykumar
Company:Larsen&ToubroInfotech
Createdon:22June,2011
Author(s)Bio
AjayKumarisaSAPConsultantwithL&TInfotech.

TheProxyconfiguredinSPROXYwilllooklike.

ByClickingonthestructurewecanalsoseethestructureoftheProxy,whichisintreestructure.

Inthiscase,proxyhave4structuredtobefilledwithdataandthentriggertheproxytoPI.

Inordertocreatetheproxyfromthenamespacegiven,weneedtodofollowing
1.RightclickontheMessageinterface(outbound)andclickoncreate.#AfterclickingoncreateitwillaskforTransportRequestno,prefix,proxyclassandotherdetails,thatweneedtogiveinorder
tocreatetheproxyandthenactivate.
2.WeneedtocreateasimplereportprogramusingSE38
3.Weneedtocreateastructurethatwillrefertotheproxystructure.Weneedtopopulatethisinordertosendourdata.
g_t_headerTYPEzintercompany_data_send

https://wiki.scn.sap.com/wiki/pages/viewpage.action?pageId=240189709

1/3

11/10/2016

StepbyStepguidetodevelopOutboundABAPProxywithPDFattachment.ABAPDevelopmentSCNWiki

4.VariousdatadeclalarionsrequiredforProxysendingandPDFattachmentsendingare.
attch_protocolTYPEREFTOif_wsprotocol_attachments,
g_attachmentTYPEREFTOif_ai_attachment,
g_attachmentsTYPEprx_attach,"Internaltableforattachment
g_attach_xstringTYPExstring,"variableofxstringtype.
g_spool_idTYPEtsp01rqident,
g_priparTYPEpri_params,
g_arcparTYPEarc_params,
g_pdfspoolidTYPEtsp01rqident,"SPOOLID
g_jobnameTYPEtbtcjobjobname,"JobnameparameterforSPOOL
g_jobcountTYPEtbtcjobjobcount,"JobcountParamaterforSPOOL
g_stringTYPEstring,"Toconvert132characterdatainto255characterdata.
*Referencevariablesexceptionclass
lo_sys_exceptionTYPEREFTOcx_ai_system_fault,
*ObjectdeclarationforProxyClass
obj_invoice1TYPEREFTOProxyclassname.
*creatingproxyobject
CREATEOBJECTobj_invoice1.
5.Ifsomeamountfieldisinvolved,wecanuseFMCONVERSION_EXIT_CUNIT_OUTPUTtoputvesignontheleftside.#Updatethemainstructurewiththedatarequired,ifsomesubstructures
arethere,thenalsofinallyweneedtofillthemainstructureweonly,thatwillbepassedwhiletriggeringtheproxy.
g_t_headerinvoice_detailsinvoice_line_item[]=g_t_tab_det[].
g_t_headerinvoice_properties=wa_inv_pro.
6.GetallthedatarequiredforPDFintoainternaltable.
7.InordertosendthePDFintotheproxyweneedtogetallthedatainaXstringtypevariable.TodosofirstweneedtocreateaSPOOLofthedatainourinternaltable.
8.UseFM'GET_PRINT_PARAMETERS',ifsomespecialformatisrequired.StarttheTRYCATCHBlock.TocreateSPOOL:
NEWPAGEPRINTON
PARAMETERSg_pripar
ARCHIVEPARAMETERSg_arcpar
NODIALOG.
Writeyourdatathatneedtobeprinted,withtheformatrequiredforPDF.WhateverwrittenherewillbeconvertedintoSPOOL.
g_spool_id=syspono.
NEWPAGEPRINTOFF.
Elsethanthisthestepsrequiredare:
1.ConverttheSPOOLintoPDFformat.
2.Convertingthe132characterdatato255characterdata.
3.Append255characterdatainonevariable.
4.ConverttheBinaryStringtoXSTRING,andconcatenateitwithdatafield,whichwillbesenttoproxy.

Belowisthecoderequiredtocompletetheremainingpart.

$generalUtil.escapeXMLCharacters($body)
1.WeneedtoconvertthisSPOOLintoPDFformatusingFM'CONVERT_ABAPSPOOLJOB_2_PDF'
CALLFUNCTION'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid=g_spool_id"SPOOLID
no_dialog=''
IMPORTING
pdf_bytecount=g_size_bytes
pdf_spoolid=g_pdfspoolid
btc_jobname=g_jobname
btc_jobcount=g_jobcount
TABLES
pdf=g_table"AllthedatawillbeinthisDatatable

2.Convertingthe132characterdatato255characterdata
CLEARg_string.
LOOPATg_tableINTOwa_table.
TRANSLATEwa_tableUSING'|'.
CONCATENATEg_stringwa_tableINTOg_string.
ENDLOOP.

TRANSLATEg_stringUSING'|'.
DO.
wa_buf=g_string.
APPENDwa_bufTOg_t_buf.
SHIFTg_stringBY255PLACES.
IFg_stringISINITIAL.
EXIT.
ENDIF.
ENDDO.

3.Appending255characterdatainonevariable.
IFg_t_buf[]ISNOTINITIAL.
LOOPATg_t_bufINTOwa_buf.
CONCATENATE
g_output
wa_buf
INTOg_output.
ENDLOOP.

4.ConverttheBinaryStringtoXSTRING
CALLFUNCTION'SCMS_STRING_TO_XSTRING'

https://wiki.scn.sap.com/wiki/pages/viewpage.action?pageId=240189709

2/3

11/10/2016

StepbyStepguidetodevelopOutboundABAPProxywithPDFattachment.ABAPDevelopmentSCNWiki

EXPORTING
text=g_output
IMPORTING
buffer=g_outputx

5.Concatenatingattach_xstringwiththedatafield.WeneedtosendthisfieldtoProxy.
CONCATENATEg_attach_xstringg_outputxINTOg_attach_xstringINBYTEMODE.

6.Belowisthecoderequiredtosendtheproxy.
TRYCATCH
Getattachmentprotocol

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='PDFAttachment')."NameofPDFtobeuploaded

APPENDg_attachmentTOg_attachments.
attch_protocol>set_attachments(g_attachments).

*SendingProxyfieldstoXIthroughEXECUTEASYNCHRONOUSMethod.
CALLMETHODobj_invoice1>execute_asynchronous
EXPORTING
output=g_t_header.
CATCHcx_ai_system_faultINTOlo_sys_exception.
COMMITWORK.
ENDTRY.
CATCHcx_ai_system_faultINTOlo_sys_exception.
ENDTRY.

7.OtherExceptionHandlingcanbedoneaspertherequirement.UsingtheSXMB_MONITCodewecancheckwhethertheproxyhasbeensentsuccessfullyornot.

standard

template

document

paper

article

1Comment
AnilSupraj
HiAjay,

IamabletosendfilestoPI,correctlywhentheproxyisasynchronousoutbound.
ButIdonotfindanyfileswhenIuseasynchronousoutboundproxy.

Anil

ContactUs
Privacy

SAPHelpPortal
TermsofUse

LegalDisclosure

Copyright

https://wiki.scn.sap.com/wiki/pages/viewpage.action?pageId=240189709

FollowSCN

3/3