Page 1 of 1

Split XML file into different files.

PostPosted: Wed Sep 06, 2017 1:38 am
by Surabhi
Hi all,

I have a requirement to split xml file into different files based on condition .
The HEADER and INFORMATION should be there in all files along with the condition.

Input file:-
<?xml version="1.0" encoding="UTF-8"?>
<TRANSACTION>
<HEADER>
<NAME>ALEX</NAME>
</HEADER>
<INFORMATION>
<LASTNAME>CRISTOPER</CRISTOPER>
</INFORMATION>
<RESIDENCE>
<PLACE>DENMARK</PLACE>
</RESIDENCE>
<NUMBER>
<LOCAL>123456789</LOCAL>
</NUMBER>
<TRANSACTION>

Expected Output:-
File1:-
condition:: (if 8,7,ch,eq,c'DENMARK')

<?xml version="1.0" encoding="UTF-8"?>
<TRANSACTION>
<HEADER>
<NAME>ALEX</NAME>
</HEADER>
<INFORMATION>
<LASTNAME>CRISTOPER</CRISTOPER>
</INFORMATION>
<RESIDENCE>
<PLACE>DENMARK</PLACE>
<RESIDENCE>

File2:-
condition:: (if 8,9,eq,ch,c'12346789')
<?xml version="1.0" encoding="UTF-8"?>
<TRANSACTION>
<HEADER>
<NAME>ALEX</NAME>
</HEADER>
<INFORMATION>
<LASTNAME>CRISTOPER</CRISTOPER>
</INFORMATION>
<NUMBER>
<LOCAL>123456789</LOCAL>
</NUMBER>

i have tried using WHEN=GROUP option:-
INREC IFTHEN=(WHEN=GROUP,
BEGIN=(8,7,CH,EQ,C'DENMARK'),PUSH=(81:8,7)),
IFTHEN=(WHEN=GROUP,
BEGIN=(8,9,CH,EQ,C'123456789'),PUSH=(81:8,9))
OPTION COPY

But not able to proceed further.
Can anyone please help me out with this.

Thanks.

Re: Split XML file into different files.

PostPosted: Wed Sep 06, 2017 8:01 pm
by Aki88
Hello,

Going by the requirement you've stated, logically it appears that you want the RESIDENCE (sic), NUMBER (sic) tag data to be written to two different datasets along with the rest of the tags.

This raises a curious question, your post states that you're testing for DENMARK (sic) and c'12346789', what if other values are received for these fields; where do you want them written?

Aside, quick solution would be to use OUTFIL coupled with IFTHEN; in IFTHEN, for one case OMIT the tags within the BEGIN/END range of RESIDENCE (sic), while in the other OMIT the range within NUMBER (sic); write rest of the data as-is - basically an OPTION COPY.

Re: Split XML file into different files.

PostPosted: Tue Sep 12, 2017 6:14 pm
by Surabhi
Hi Aki88,

Thank you for the response.
to answer your question, we would not receive any other values for these fields other than DENMARK (sic) and c'12346789'.

This solution works when we have only one <TRANSACTION> with all this information.
Any idea how to handle mutliple <TRANSACTION> in same XML file?

Thanks.

Re: Split XML file into different files.

PostPosted: Tue Sep 12, 2017 6:20 pm
by Aki88
Hello,

Surabhi wrote:...
This solution works when we have only one <TRANSACTION> with all this information.
Any idea how to handle mutliple <TRANSACTION> in same XML file? ...


Can you please show representational input and corresponding expected output for the above scenario?

Re: Split XML file into different files.

PostPosted: Tue Sep 12, 2017 8:57 pm
by Surabhi
Hello,
Thanks for the quick response.
We have got some additional requirements to this, so i think i better go with cobol code to handel everything rather than a sort.

Thank you so much for your inputs :)

Thanks.