Page 1 of 1

XML FILE SORTING

PostPosted: Sun Apr 19, 2020 12:27 am
by RAVIPRAD29
Hi all,

I have a requirement to split xml file into 2 files based on condition ( 'ID' FIELD)
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>
<ID>11111
<TRANSACTION>

<TRANSACTION>
<HEADER>
<NAME>BEN</NAME>
</HEADER>
<ID>22222
<TRANSACTION>

<TRANSACTION>
<HEADER>
<NAME>JOHN</NAME>
</HEADER>
<ID>11111
<TRANSACTION>

<TRANSACTION>
<HEADER>
<NAME>MARK</NAME>
</HEADER>
<ID>22222
<TRANSACTION>


Expected Output:-
File1:-
condition:: (if 5,5,ch,eq,c'11111')

<?xml version="1.0" encoding="UTF-8"?>
<TRANSACTION>
<HEADER>
<NAME>ALEX</NAME>
</HEADER>
<ID>11111
<TRANSACTION>


<TRANSACTION>
<HEADER>
<NAME>JOHN</NAME>
</HEADER>
<ID>11111
<TRANSACTION>

File2:-
condition:: condition:: (if 5,5,ch,eq,c'22222')
<?xml version="1.0" encoding="UTF-8"?>

<TRANSACTION>
<HEADER>
<NAME>BEN</NAME>
</HEADER>
<ID>22222
<TRANSACTION>


<TRANSACTION>
<HEADER>
<NAME>MARK</NAME>
</HEADER>
<ID>22222
<TRANSACTION>

Re: XML FILE SORTING

PostPosted: Sun Apr 19, 2020 3:00 am
by NicC
Please use the code tags when posting data as well as code.

Have you investigated this document?
http://www.ibm.com/support/pages/smart-dfsort-tricks

Re: XML FILE SORTING

PostPosted: Sun Apr 19, 2020 6:39 pm
by RAVIPRAD29
Thanks fot the reply NicC.

I am basically looking for solution to split XML based on key Column ('ID' FIELD) with DFSORT

I tried with below sort card ,but I am not getting the desire result

//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,13,CH,EQ,C'<TRANSACTION>'),
END=(1,14,CH,EQ,C'</TRANSACTION>'),PUSH=(601:ID=8))
OUTFILE FNAMES=OUT01,BUILD=(1,600),INCLUDE=(5,5,CH,EQ,C'11111')

I am just getting just 1 line instead of entire group as indiacted belwo

<ID>11111
<ID>11111

Can you please let me know on these since this bit urgent requirement.

Re: XML FILE SORTING

PostPosted: Sun Apr 19, 2020 7:54 pm
by NicC
It is not urgent if you are posting on a forum where questions are answered by volunteers if and when they feel like it. And they are less likely to feel like it if you say 'urgent', or similar, and ignore requests to present your code and data correctly - using the code tags (see the "POST REPLY" button).
Have you studied that document - it has many ways to split a dataset?

Re: XML FILE SORTING

PostPosted: Sun Apr 19, 2020 9:41 pm
by sergeyken
RAVIPRAD29 wrote:Thanks fot the reply NicC.

I am basically looking for solution to split XML based on key Column ('ID' FIELD) with DFSORT

I tried with below sort card ,but I am not getting the desire result

//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,13,CH,EQ,C'<TRANSACTION>'),
END=(1,14,CH,EQ,C'</TRANSACTION>'),PUSH=(601:ID=8))
OUTFILE FNAMES=OUT01,BUILD=(1,600),INCLUDE=(5,5,CH,EQ,C'11111')

I am just getting just 1 line instead of entire group as indiacted belwo

<ID>11111
<ID>11111

Can you please let me know on these since this bit urgent requirement.


RTFM, RTFM, RTFM, and RTFM. And next: RTFM, RTFM, RTFM and RTFM again.

One hint: SORT is not good tools for such task. It can be used exactly as a hammer could be used to hammer screws, and bolts.

Re: XML FILE SORTING

PostPosted: Sun Apr 19, 2020 10:36 pm
by RAVIPRAD29
Hi NicC,

Thanks for your timely and valuable input and since many of my colleagues told me that XML sorting in DFSORT is complicated compared to COBOL and PL1 sorting. So i am trying out different options to find a solution for the complicated process and hence was looking out fot valuable inputs from xperienced and versatile professionals like you and sorry for maybe sounding impatient in trying to find a solution.

Also I have adeed the code tags for my query as below and also to SORT code now , and apologies for not adding it earlier since I am new to this forum and was not aware of these options.

I have a requirement to split xml file into 2 files based on condition ( 'ID' FIELD)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>
<ID>11111
</TRANSACTION>

<TRANSACTION>
<HEADER>
<NAME>BEN</NAME>
</HEADER>
<ID>22222
</TRANSACTION>

<TRANSACTION>
<HEADER>
<NAME>JOHN</NAME>
</HEADER>
<ID>11111
</TRANSACTION>

<TRANSACTION>
<HEADER>
<NAME>MARK</NAME>
</HEADER>
<ID>22222
</TRANSACTION>


Expected Output:-
File1:-
condition:: (if 5,5,ch,eq,c'11111')

<?xml version="1.0" encoding="UTF-8"?>
<TRANSACTION>
<HEADER>
<NAME>ALEX</NAME>
</HEADER>
<ID>11111
</TRANSACTION>


<TRANSACTION>
<HEADER>
<NAME>JOHN</NAME>
</HEADER>
<ID>11111
</TRANSACTION>

File2:-
condition:: condition:: (if 5,5,ch,eq,c'22222')
<?xml version="1.0" encoding="UTF-8"?>

<TRANSACTION>
<HEADER>
<NAME>BEN</NAME>
</HEADER>
<ID>22222
</TRANSACTION>


<TRANSACTION>
<HEADER>
<NAME>MARK</NAME>
</HEADER>
<ID>22222
</TRANSACTION>
 


i have gone through the document which you referred me following which i was
able to get a partial result with the below SORT card and just need your input
once again if this needs to be rectified or corrected.

 

//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,13,CH,EQ,C'<TRANSACTION>'),
END=(1,14,CH,EQ,C'</TRANSACTION>'),PUSH=(601:ID=8))
OUTFILE FNAMES=OUT01,BUILD=(1,600),INCLUDE=(5,5,CH,EQ,C'11111')

 


'
I am just getting just 1 line instead of entire group as indiacted below

<ID>11111
<ID>11111