Link to home
Start Free TrialLog in
Avatar of kalyangkm
kalyangkmFlag for United States of America

asked on

Sort a file to segregate transaction sets and then create separate files for each transaction set using Java

Hi Folks,

I have an EDI file, which I need to sort and segregate the Transaction sets and transfer each transaction set into an FTP folder as a separate file. In the attachments I have "File A" which is the actual input file and "File B" shows format after the sort to show the individual transaction sets and finally 3 files "Output 1" , "Output 2" and "Output 3" which have to be extracted out of the File B and have to be sent to an FTP server. The idea is to directly extract the Output 1 , 2 and 3 from File A. I have shown the File B to depict what I meant by Transaction sets.

Each Transaction set consists of the following components in that order. Please check the file "File_A_components" which shows the highlighted components from the "File A" for reference.  I would need suggestion on how to generate Output 1, 2 and 3 separate files into an FTP server using Java. I am an amateur in JAVA. So please provide as detailed as possible.

Transaction Set components
Header
ST set
Trailer

Regards
Kalyan.
FILE-A.txt
FILE-B.txt
Output-1.txt
Output-2.txt
Output-3.txt
File_A_components.docx
Avatar of kalyangkm
kalyangkm
Flag of United States of America image

ASKER

Hi,

Could anyone please check into my question.

Regards
kalyan.
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Why don't you use a Java EDI api?
Hi Bill,

Thanks. I will give it a try and let you know the feedback.

Regards
Kalyan.
Hi CEHJ,

Java EDI API would be helpful, I just want to check if it will get me to the individual files that I am looking for or will it convert to XML?

Regards
kalyan.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Bill, it works. Just checking to see if you have any thoughts on how to approach the FTP part.
Thanks Jim, for the OO based approach. I don't need the code for now but I would need the approach on how to use the Apache FTP Client? As I am able to read through the contents but not getting any ideas on how to download the files to the server.
Avatar of Bill Prew
Bill Prew

Can you expand a bit on the requirements for the FTP part?  Do you have an FTP client on the computer where this java program will run?  And you need to send the output files to a remote server running FTP server?  Can all the files in a particular folder be sent, or do you have to send then one by one, by individual names?  What folder do they need to go in on the remote server?  And any other details...
@Bill,
    I will be deploying my code into a middle ware tool and tweaking it a bit to suit the Java mapping API of that tool. From there I need to upload these output files into a remote FTP server within our client landscape (so, no complications on the security). And yes all the output files should be sent to one folder of the FTP server at the same time.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Jim,

Thanks, I will work on it. The only doubt I have before I start is what would be the local file name as the files are getting generated generated under the Project folder in Eclipse currently and in the real scenario when we deploy it in the server what would be the path to access these files.
Hi Bill,

Thanks, Sure, I will work myself. The only doubt I have before I start is what would be the local file name as the files are getting generated generated under the Project folder in Eclipse currently and in the real scenario when we deploy it in the server what would be the path to access these files.
In the production server, do you know the full path to the "file-a.txt" file (or whatever the real name is)?  If so then you can just include that in the java code above when reading that file.

As far as the output files generated by the java code above, you can certainly prepend the full path to the files created, and that can be whatever you want, or whatever the production server requirements dictate.

In either case, you'll need to know that location for the files, and can then reference it in the FTP xfer code.


»bp
Hi Bill,

In the server I will be sending the file to the java mapping using a file adapter and the java mapping uses AbstractTransformation Class to read the input.  

Going back to the code you have given for FTP upload, I used and successfully modified it to upload the files by looping. PFA is the code "ftpFileUpload.txt".

Now I have the original splitting java map "sortingMultiEDIrecords.txt" (PFA), provided by you which generates the files and  also the "ftpFileUpload.txt" file.

Now my task is to use the Java mapping class mentioned earlier to generate the files using your code. I have tried to first generate the files using the following blog, PFA is the code I have created for that "Test_Java_Map.txt" unfortunately the only way to debug this is if you have the middleware tool I have. See if you can help in modifying the code. If not its fine.

https://blogs.sap.com/2015/02/08/how-to-create-java-mapping-in-sap-pi-po/
Useful blog for reading the input and output streams: https://gist.github.com/SriniBlog/113039b6f0433bee19ae

I would be interested in locking some time with you to work on this. But looks like Free Lance option has been removed in experts exchange. Please let me know incase there is any other option.
ftpFileUpload.txt
sortingMultiEDIrecords.txt
Test_Java_Map.txt
Link to the Jar files for AbstractTrasnformation Class

https://www.dropbox.com/s/2k2igg30x87a9oa/com.sap.xi.mapping.tool.lib_api.zip?dl=0
hi Bill,
I think it’s not fair to ask you what I have asked. I just needed an idea. I am planning to put a trace by putting println and see in the logs. but I just still not sure if I can directly FTP upload the Buffer reader content. not sure if I have to convert it to Byte code.
hi Bill, is there a possibility to directly FTP upload the files after splitting instead of writing it to a folder and then FTPing it? I can close this question and open a new one, I would appreciate if you can give your inputs
Honestly, I'm not sure.  I haven't worked much with the ftpclient class.  I see that the storeFile() method can take data from a stream and send it to the server to be stored in a named file.  But I'm not sure how that would be done using the streams that we are writing the data to from the first script I did.  Perhaps a new question with some more experienced java eyes looking at it...


»bp