Java Wrapper Example - mfx - 3.1

Syncsort™ MFX Programmers Guide

Product type
Software
Portfolio
Integrate
Product family
Syncsort™ Software
Product
Syncsort™ MFX > MFX
Version
3.1
Language
English
Content type
Programmer’s Guide
Product name
Syncsort™ MFX
Title
Syncsort™ MFX Programmers Guide
Topic type
How Do I
Copyright
2024
First publish date
2010
Last edition
2024-08-27
Last publish date
2024-08-27T08:14:56.318001

import com.ibm.jzos.*;                                                                              
import java.io.BufferedInputStream;                                                                 
import java.util.*;                                                                                 
import com.syncsort.zos.SyncSort;                                                                   
public class dfexec1                                                                                
{                                                                                                   
         public static void main(String   args) throws Exception {                                  
                 sort("<INPUT DSNAME>"); 
         }                                                                                          
         private static void sort(String inDs) throws Exception {                                   
                 int key = 20;                                                                      
                                                                                                    
                 SyncSort syncsort = new SyncSort();                                                
                 syncsort.addAllocation("alloc fi(SORTIN) da(" + inDs + ") reuse shr msg(2)");      
                 syncsort.setOutputStreamRecLen(80);                                                
                 syncsort.addControlStatement("SORT FIELDS=(1," + key + ",CH,A)");                  
                                                                                                    
                 long startTime = System.currentTimeMillis();                                       
                 syncsort.execute();                                                                
                 BufferedInputStream bis = new BufferedInputStream(syncsort.getChildStdoutStream());
                 byte   buffer = new byte 80 ;                        
                                        int bytesRead = 0;                                           
                                        while ((bytesRead = bis.read(buffer)) != -1) {               
                                                System.out.println(new String(buffer, 0, bytesRead));
                                        }                                                            
                 int rc =0;                                                                          
                 try {                                                                               
                         rc = syncsort.getReturnCode();                                              
                 } catch (RcException rce) {                                                         
                         System.out.println("Caught RcException: " + rce.getMessage());              
                         rc = -1;                                                                    
                 }                                                                                   
                if (rc != 0) {                                                                       
                        List stderrLines = syncsort.getStderrLines();                                
                        for (Iterator i=stderrLines.iterator(); i.hasNext(); ) {                     
                                System.err.println(i.next());                                        
                        }                                                                            
                }                                                                                    
        }                                                                                            
}