cancel
Showing results for 
Search instead for 
Did you mean: 

Take two files from a folder and compress them into one zip file

Former Member
0 Kudos

Hi experts,

AS IS, without SAP ERP and SAP PI, my scenario extracts some data from a DB (a stored procedure) and writes two files that are, then, compressed into a zip file.

Now, the TO BE, with SAP ERP and SAP PI, my scenario will be ABAP PROXY -> PI -> and 2 FILE. Until now I have done the first part, so I have extracted the data from the ERP and I have sent it to SAP PI that writes to separates files into a folder (that we will call, to simplify, A.TXT and B.TXT).

I have tried to zip both into one zip file in two way:

- Using the AF_Modules/PayloadZipBean: but no way, this module can only zip every single file, with a 'bad name' inside every single zip file (Maindocument)

- Using some OS Commands: but I can't ... maybe I haven't found the right command ...

So, this is my goal:

- take two files from a folder and compress them into one zip file

- And, if it's possible, maintain the original names of each file into the zip file (not like Maindocument)

I think to be near the solution but maybe I lost some details that are importants to reach my goal, so I need your help

Thanks,

Antonello

Accepted Solutions (0)

Answers (6)

Answers (6)

swapna_patha
Explorer
0 Kudos

Hi Antonello, Did you got the solution for this, even i have same requirement. Please assist Regards, Swapna.

Former Member
0 Kudos

Hi,

I ad same issue and resolved it with os command in file channel.

I have created a .sh file on server and run it in os command

cd /usr/sap/folder zip batch.zip *.csv

Thanks

Shivi

sunil_singh13
Active Contributor
0 Kudos

Hi Antonello,

If we can make one file as an attachment and another as Main Payload then they can be zipped together as Single file. But it will be bit complex development.

Thanks,

Sunil Singh

Former Member
0 Kudos

Hi Sunil,

it could be complex, and maybe it cloud be done, but this is not the requirement of my partner

Thanks,

Antonello

Former Member
0 Kudos

Hi Antonello,

Have you got the solution? I have the same requirment.

Thanks

Shivi

former_member184681
Active Contributor
0 Kudos

Hi Antonello,

You can zip all payloads with PayloadZipBean using the following attribute:

zip.Mode     zipAll

Unfortunately, I think you can only set the name of the file created for the main payload:

zip.filenameKey     Content-Type: text/plain; name="expected_name.txt"

You can read more on this bean here:

http://help.sap.com/saphelp_nw04/helpdata/en/45/da9358a1772e97e10000000a155369/content.htm

Regards,

Greg

Former Member
0 Kudos

Hi Grzegorz,

did you have used before this Module? Because I had used it with the same parameters that you suggests me but the result is: one file zip for each file taken from the sender channel, so, in my scenario, two files zip, those are the screens of my files sequence:

Sender:

Receiver:



The folder with the 2 txt files, that are teaken from the sender channel, then the result zip files from the receiver channel.

Did I have mistake something?

Thanks,

Antonello

former_member184681
Active Contributor
0 Kudos

Dear Antonello,

Just one thing I forgot to ask before. These two files you already create - are they two separate payloads of one PI message, or two completely separate messages? The zipAll option zips all the payloads of one message (the first case). If you want to zip two separate messages, it might be more complicated. Personally, I would split it to two interfaces:

1. The scenario you already have, that creates two files based on the proxy call.

2. File-to-file pass-through scenario (with no mapping involved) that reads both files as one message (with two payloads) using the Additional Files option in sender file channel, and zips them to one zip archive.

Regards,

Greg

Former Member
0 Kudos

The way you suggest me seems to be right but in my case I have 2 files with 2 different names and in the Rules of this option there is one that says:

The way that the files to be transported are grouped together is defined by the file names. All file names must be identical except for a defined part (such as the suffix).

Mmmm ... maybe I can't do this with PI ?

Former Member
0 Kudos

Hi Antonello,

Have you configured the Additional Files table in sender channel? It would make that both the files picked in one messages. And then zipAll would work.

Hava a try.

Regards,

Kevin

former_member184681
Active Contributor
0 Kudos

Hi,

Just one more idea: I remember seeing a blog or Wiki on how to zip messages into a file in a Java mapping and then write the .zip file content in binary mode. This should be possible in your case, and moreover should comply to your requirement to set the file names accordingly. The only question that you didn't answer the previous time is, if you create both files based on one message? If yes, then I guess you've got your solution

Regards,

Greg

Former Member
0 Kudos

Hi Kevin,

I have tried what you are suggesting me (if you see just a little bit over your post ) but I use 2 different files with 2 different names, so i catch an error in sender channel because the names are not the same ... but maybe you are right and I mistake something ... this is the rule of the option:

The way that the files to be transported are grouped together is defined by the file names. All file names must be identical except for a defined part (such as the suffix).

This is the Sender channel configuration with the option Additional file/s:

this is the error on the channel after I start it:

Can you help me?

Thanks,

Antonello

Former Member
0 Kudos

Hi Greg,

why not? We can try ... but can you explain just a little bit more what you are saying me?

Now my scenario is like this:

- one outbound Service Interface -> the ABAP Proxy call Async

- two inbound Service Interface -> Clienti and Movimenti

- one multimapping -> Proxy to Clienti and Movimenti

and I create 2 files.

So, as you say me now, I have to collapse Clienti and Movimenti in one Service Interface and split them after with Java Mapping, and then zip them into one file? with the right names of txt files?

Antonello

former_member184681
Active Contributor
0 Kudos

Hi,

>>> So, as you say me now, I have to collapse Clienti and Movimenti in one Service Interface

Not really, using multimapping should be fine. Just use two consecutive message mappings in your operation mapping:

1. One that you are using so far, with two messages created.

2. Additional Java mapping that will read both payloads into some streams (files) and then zip them into one file.

I've found the doc, by the way: http://scn.sap.com/docs/DOC-3784.

Regards,

Greg

Former Member
0 Kudos

Hi Greg,

I will take a look at the document and I will say you if this could be the right way,

Thanks for now

Antonello

Former Member
0 Kudos

Hi Antonello,

if you have 2 files with the name clienti.txt and movimenti.txt. then pls have  a try to configure as below.

and add some other paramters as ur requirement.

Regards,

Kevin Song

Former Member
0 Kudos

Hi Kevin,

I tried in many ways but it doesn't work, the error is always the same:

format must be "originalNamePart"="additionalNamePart"

I think that to work it the names must be like: clienti.txt and clienti1.txt.

I need to find another way.

Thanks,

Antonello

Former Member
0 Kudos

Please go through the below link to zip the multiple files.I think it"ll helpful for you.

http://www.loni.ucla.edu/~esowell/edevel/people/eric/unixcmd.html

Thanks.

Former Member
0 Kudos

Hi manas,

my OS is Windows.

Thanks,

Antonello

rajasekhar_reddy14
Active Contributor
0 Kudos

Hi,

Why are you creating two different files? do you have any condition?

If no condition then you can collect messages and create as a one file (very much possible).

Best Regards,

Raj

Former Member
0 Kudos

Hi Raja,

why you are wearing two shoes? maybe you can wear only one! 🙂 What kind of question is this? I don't think is the right way to solve the technical problem. The scenario is this, and this will be, because the process, who will takes the files, needs two files to do its job.

Thanks,

Antonello