cancel
Showing results for 
Search instead for 
Did you mean: 

Module in PI

Former Member
0 Kudos

Dear All

I have a CSV file as input where I have to validate the header and footer using a Java module. I have a limitation that I cannot convert the incoming CSV file into xml before validating.

Can anyone tell me what approach should I take in the module to attain the functionality?

Is there anyway that I can use the file handling in the Module code?

Regards

Sourabh

Accepted Solutions (1)

Accepted Solutions (1)

former_member187339
Active Contributor
0 Kudos

Hi Sourabh,

>>Can anyone tell me what approach should I take in the module to attain the functionality?

Module can be used but what are you validating here? May be an example of csv and the condition will be helpful for us to know the problem

Regards

Suraj

Former Member
0 Kudos

Suraj

We are validating the header and footer in the csv file which looks like

"A00",1,"AR4","20090407","125334",859525

"N68","MAM",2102175432,"REM","20090407","20090423","AM","NN3","8AD","Y","Y","","CR","XX"

"N68","MAM",2102175431,"EXC","20090407","20090427","AM","DL15","0BA","Y","Y","","CR","ET"

"Z99",55

Where first line is the header and last line the footer and rest is data. The codition is only that all fields should be present in the header and footer.

former_member187339
Active Contributor
0 Kudos

Hi Sourabh,

what I understood is you need 6 values in header and they should match with "A00",1,"AR4","20090407","125334",859525 respectively...

also the last two value shoudl be "Z99",55 ...so your module shoudl do the following..

1. It will have the entire file as input.. So till it encounter a newline it has the header...

2. Read and compare the values if found satisfactory, then only check trailer..

3. then go to end of input and read the last two values or values before a newline.. and then compare with the required one.. if they are there then the file is valid... elase raise exception and fail it in channel...

4. In file sender channel, after your module call the Plain2XML function and make the XML structure. This will be called only when the first module (created by you) is a success...

If you want to know on how to create a module or raise exception in module, search sdn you will find lot of documents

Regards

Suraj

Former Member
0 Kudos

1. It will have the entire file as input.. So till it encounter a newline it has the header...

How to take the file as input and then identify the new line character as this calls for file handling and needs the input stream to be converted to fileinputstream, the we are not able to do in moudule

Thanks for your help

former_member187339
Active Contributor
0 Kudos

Hi Sourabh,

Can you paste the section of code which you are using to read from file and get the content here...

Also check this: https://help.sap.com/javadocs/pi/SP3/xpi/index.html

for getting a input stream from the input payload you need the following imports to be done


import com.sap.aii.af.mp.module.*;
import com.sap.aii.af.ra.ms.api.*;
import com.sap.aii.mapping.*;

And this code piece to be included


Message msg = (Message) inputModuleData.getPrincipalData();
TextPayload payload = msg.getDocument();
InputStream iscontent = payload.getContent();

Regards

Suraj

Answers (0)