cancel
Showing results for 
Search instead for 
Did you mean: 

SAP SDK: Fetching PDF from ERP into C4C as PDF attachment in EC

chandansb
Active Contributor
0 Kudos

Hello Experts,

Our requirement is to fetch the PDF document from SAP ERP into C4C as PDF attachment in Embed Component. We have referred this document on SCN to create the Web Service in ERP to convert the print spool into PDF on ERP and get the data into XSTRING format.

On C4C we have consumed the ERP Web Service into Custom BO and we are getting successful ping test as well as get the response with the XSTRING format. Now I want to know how will I create the PDF from this XSTRING. Below is my BO definition.


businessobject mycustomBO (


element data1 : LANGUAGEINDEPENDENT_MEDIUM_Text;

element data2 : LANGUAGEINDEPENDENT_MEDIUM_Text;

element data3 : LANGUAGEINDEPENDENT_MEDIUM_Text;

element CFlag : Indicator;

[DependentObject(AttachmentFolder)] node Attachment;


}

Kindly help me understand what need to done to achieve this requirement.

Thanks in Advance.

Regards,

Chandan

Accepted Solutions (1)

Accepted Solutions (1)

chandansb
Active Contributor

Hello Experts,

I am still stuck to understand how this can be achieved.

Any suggestions?

Regards,

Chandan

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Chandan,

As PDF is XML based with some raw contents, can't you use the built-in library function ToString()?

HTH,

   Horst

chandansb
Active Contributor
0 Kudos

Hello Horst,

Thanks for the reply. I have very less experience working on Cloud Application Studio, it would really be helpful if you elaborate on this. I will try it out once I get some idea.

Thanks,

Chandan

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Chandan,

At the top you mention a blog in which it is described how to fetch the spool.

This includes writing a function module (which is not possible in SDK.)

Question: Can this function module return the PDF as string or Base64?

This would it make easier to build up the PDF in the AttachmentDocument.

Bye,

   Horst

chandansb
Active Contributor
0 Kudos

Hello Horst,

I have built the FM similar to that mentioned in the blog in our SAP ECC system. This is now returning us XSTRING format. (I am getting this XSTRING format Output from SPOOL generated in ECC.)

I am now trying to understand how this XSTRING can be converted into the PDF in the attachment using Cloud SDK.

Thanks,

Chandan

sunil1101
Employee
Employee
0 Kudos

Hi Chandan

After consuming you are getting data in XSTRING format if possible first convert returning data into String then parse string to read your required fields elements and pass those value to our BO elements Once you are able to create BO instances as per PDF document then you can create a Form template on BO.

following the  below link

http://scn.sap.com/thread/3627237

Thanks

Sunil

chandansb
Active Contributor
0 Kudos

Hello Sunil,

Thanks for your reply.

But here we are directly trying to create a PDF from the output from ECC (which is XSTRING here) Moreover we are not using any template here. So I am right now trying to understand how this XSTRING value can be converted directly to PDF.

Thanks,

Chandan

sunil1101
Employee
Employee
0 Kudos

I chandan I dont think there is workarround which transfer xstring to pdf format data.

What I know is that we can create print form on top of BO.

check link in my previous reply.

chandansb
Active Contributor
0 Kudos

Hello Sunil,

Now I am getting not only XSTRING but also Base64 string format from ECC. I have changed my code to get the PDF from this base64 now. It is as below.

var ATTACHMENT_TYPE_DOCUMENT : DocumentTypeCode;

var documentName : LANGUAGEINDEPENDENT_Name;

var documentAlternativeName : LANGUAGEINDEPENDENT_Name;

var DocDesc : Description;

var DocBInary : BinaryObject.content;

ATTACHMENT_TYPE_DOCUMENT.content = "10001";

documentName = "ECCorder.pdf";

documentAlternativeName = "";

  1. DocDesc.content = "";

var scenario = "SalesOrderPDFScenario";

var requeecc : SalesOrder_WS.ZknkSalesOrder.Request;

var respons : SalesOrder_WS.ZknkSalesOrder.Response;

var SorderTable : SalesOrder_WS.ZknkSalesOrder.Request.SalesOrders.item;

requeecc.SalesOrders.item.Add(SorderTable);

requeecc.CustomerNumber = "";

requeecc.ISpool = "19855";

respons = SalesOrder_WS.ZknkSalesOrder(requeecc,"",scenario);

DocBInary = Binary.ParseFromString(respons.OB64string);

this.Pdfcontent.content = DocBInary;

this.Pdfcontent.mimeCode = "application/pdf";

//this.Pdfcontent.fileName = documentName;

//DocBInary.content = respons.OB64string;

this.Attachment.CreateFile(ATTACHMENT_TYPE_DOCUMENT, documentName, documentAlternativeName, DocDesc, this.Pdfcontent);

Yet I am not able to see any PDF getting generated under attachments. Kindly suggest if I can somehow rectify this to get the PDF from Base64.

Regards,

Chandan

Former Member
0 Kudos

Do you have a binary object right?

put directly an xstring in the binaryobject.content and then create the attachment.

For me it worked

foreach (var act in qryact_Result.Where(n => n.op_id == this.op_id)){

  if (!act.AttachmentFolder.IsSet()){

  AttFld = act.AttachmentFolder.Create();

  }else{

  AttFld = act.AttachmentFolder;

  }

  foreach (var attachment in this.AttachmentsList){

  docName = attachment.name;

  doctype.content = "10001";

  binar = attachment.binaryObject;

  AttFld.CreateFile(doctype, docName, docAltName, docDesc, binar);

  }

  break;

  }

chandansb
Active Contributor
0 Kudos

Hello Alessandro,

Thanks for replying.

Yes we have XSTRING content, per your suggestion I will check by using it directly. Once done I will update the thread accordingly.

Thanks a lot,

Chandan

chandansb
Active Contributor
0 Kudos

Hello Alessandro,

This has worked!!!    Thanks a lot Sir.

Closing the discussion marking your suggestion as Answered.

Cheers,

Chandan

Former Member
0 Kudos

Great!

Answers (0)