cancel
Showing results for 
Search instead for 
Did you mean: 

How to log a pdf and csv file in CPI which is incoming

bikram_ray
Explorer
0 Kudos

I am building a scenario in cpi where csv and pdf files are coming to CPI and being sent to receiver.
before processing the files need to be logged in CPI in original format.
Can someone please help me?

@MortenWittrock can you help please?

Ryan-Crosby
Active Contributor
0 Kudos
A simple query for logging payload as an attachment in the forums would yield multiple results, but depending on volume and size you may want to think twice.

Accepted Solutions (0)

Answers (2)

Answers (2)

SunilPatel
Explorer
0 Kudos

You can use provided logging groovy script.

SunilPatel
Explorer
0 Kudos

There are many ways you can do it. However, I would like to explain about How I have done recently.
Pull or accept data from source system as Zip file. It contains Invoice csv file and PDF file both. It can contain one CSV files contains n numbers of Invoice records and their PDF files. If CSV file contains 100 invoice records, then 100 pdfs should be part of zip files.
Now let's move to details steps
1) once you have zip file, please apply-Base64 Encoder
2) save it one of the exchange property
3) Apply Base64 Decoder
4) Convert csv to xml
5) Apply iteration splitter and post the first invoice - I'm creating as an IDOC
During 5th steps - Once Invoice IDOC posted for same invoice number, use step2 property value and apply decoder and check PDF name. In this case Invoice posted - invoice number and pdf invoice name should be matched. You can use any combination of names; it is depending on invoice pdf file name. and apply SFTP same invoice to target system.
And so on.
Please let me know if you have any confusion with above steps.

SunilPatel
Explorer
0 Kudos

Sorry > I've not mentioned about logging. you can use groovy script before first step something like below

Set this property - isPayloadLogReq as true so it will save entire zip file.

 

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;


def Message log01(Message message) {processData("log01",message);}
def Message log02(Message message) {processData("log02",message);}
def Message log03(Message message) {processData("log03",message);}

def Message processData(String prefix, Message message) {
//Body
def body = message.getBody(java.lang.String) as String;
//Headers
def headers = message.getHeaders();
def loggingEnabled = "false" ;
loggingEnabled = headers.get("isPayloadLogReq")

if(null != loggingEnabled && loggingEnabled.equalsIgnoreCase("true"))
{
def messagelog =messageLogFactory.getMessageLog(message)
if (messagelog != null)
{
messagelog.addAttachmentAsString(prefix,body,"text/plain")

}

}
return message;
}

bikram_ray
Explorer
0 Kudos
Hi Sunil,
bikram_ray
Explorer
0 Kudos
for my case I don't have a zip file. Everyday pdf files are coming and that needs to be logged in CPI in original format