顯示具有 JTOpen 標籤的文章。 顯示所有文章
顯示具有 JTOpen 標籤的文章。 顯示所有文章

星期四, 11月 09, 2023

2015-09-17 Retrieve AS400 Network Interfaces with java( List Network Interfaces (QtocLstNetIfc) API format NIFC0100)


Retrieve AS400 Network Interfaces with java( List Network Interfaces (QtocLstNetIfc) API format NIFC0100)
(RtvNetIfc.java)



File  : RtvNetIfc.java



/* ==================================================================*/
/*                                                                   */
/*  Program . . : RtvNetIfc.java                                     */
/*  Description : List Network Interfaces                            */
/*  Author  . . : Vengoal Chang                                      */
/*  Published . : AS400ePaper                                        */
/*  Date  . . . : September  17, 2015                                */
/*                                                                   */
/* ==================================================================*/

package com.free400.vengoal.as400api;

import com.ibm.as400.access.AS400;
import com.ibm.as400.access.AS400Bin4;
import com.ibm.as400.access.AS400Exception;
import com.ibm.as400.access.AS400Text;
import com.ibm.as400.access.ProgramParameter;
import com.ibm.as400.access.ServiceProgramCall;
import com.ibm.as400.access.SystemStatus;
import com.ibm.as400.access.UserSpace;

public class RtvNetIfc {

	public static void main(String[] args)  {
		 final AS400Bin4 intConverter_ = new AS400Bin4();		

		// Change following as400ip, as400user, as400password as your system and user profile setting
		AS400 as400 = new AS400("as400ip", "as400user", "as400password");
		try {
			// The first parm is 20 characters, 10 chars of user space followed by 10 chars of library. 
			// Create a converter for 20 chars. AS400Text char20 = new AS400Text(20, system); 
			// The second parm is the format name (8 chars). Create a converter. 
			AS400Text char20 = new AS400Text(20, as400);
			AS400Text char8 = new AS400Text(8, as400);			

			// Create program parameters
			ProgramParameter[] parms = new ProgramParameter[3];
			UserSpace usrSpc = new UserSpace(as400, "/QSYS.LIB/QTEMP.LIB/MYSPACE.USRSPC");
			usrSpc.setMustUseProgramCall(true);
			usrSpc.create(10240, // The initial size is 10KB
					true, // Replace if the user space already exists
					" ", // No extended attribute
					(byte) 0x00, // The initial value is a null
					"Created by a Java program", // The description of the user
													// space
					"*USE");

			// First parm is qualified user space CHAR(20)
			// CHAR(0-9) is the user space name
			// CHAR(10-19) is the library name
			String qSpace = "MYSPACE   QTEMP     ";

			// First parm is the library qualified UserSpace
			parms[0] = new ProgramParameter(char20.toBytes(qSpace));
			parms[0].setParameterType(ProgramParameter.PASS_BY_REFERENCE);
			// Second parm is the format
			parms[1] = new ProgramParameter(char8.toBytes("NIFC0100"));
			parms[1].setParameterType(ProgramParameter.PASS_BY_REFERENCE);

			// Last parm is the error code. We pass an array of 0x00s so
			// messages are returned.
			byte[] bytes = new byte[32];
			parms[2] = new ProgramParameter(bytes, 32);
			parms[2].setParameterType(ProgramParameter.PASS_BY_REFERENCE);
			System.out.println("Retrieving network interface information for system "
					+ new SystemStatus(as400).getSystemName() + " ...");
			ServiceProgramCall sPGMCall = new ServiceProgramCall(as400, "/QSYS.LIB/QTOCNETSTS.SRVPGM", "QtocLstNetIfc",
					ServiceProgramCall.NO_RETURN_VALUE, parms);
			if (sPGMCall.run() != true) {
				throw new AS400Exception(sPGMCall.getMessageList());
			} else {
				byte[] header = new byte[140];
				usrSpc.read(header, 0);
				int list_Offset = intConverter_.toInt(header, 124);
				int list_Size = intConverter_.toInt(header, 128);
				int entry_count = intConverter_.toInt(header, 132);
				int entry_size = intConverter_.toInt(header, 136);

				int strPos = list_Offset;
				System.out.println("IP Address     " + " " + "NetWork Address" + " " + "Line Desc " + " " + "Status");
				System.out.println("===============" + " " + "===============" + " " + "==========" + " " + "======");
				for (int i = 0; i < entry_count; i++) {
					String ipAdr = usrSpc.read(strPos, 15);
					String netAdr = usrSpc.read(strPos + 20, 15);
					String netWork = usrSpc.read(strPos + 40, 10);
					String lineDesc = usrSpc.read(strPos + 50, 10);
					String ifc = usrSpc.read(strPos + 60, 10);
					byte[] ifcStatusBytes = new byte[4];
					usrSpc.read(ifcStatusBytes, strPos + 72);
					int ifcStatus = intConverter_.toInt(ifcStatusBytes);
					System.out.println(ipAdr + " " + netAdr + " " + lineDesc + " " + ifcStatus);
					strPos += entry_size;
				}

			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}


						
						


參照: List Network Interfaces (QtocLstNetIfc) API




2014-12-23 如何以 java 取得 data queue 的所有屬性?(Retreive data queue description with API QMHQRDQD)


如何以 java 取得 data queue 的所有屬性?(Retreive data queue description with API QMHQRDQD)

RtvDtaqD.java
     



/* ==================================================================*/
/*                                                                   */
/*  Program . . : RtvDtaqD.java                                      */
/*  Description : Retrieve data queue description                    */
/*  Author  . . : Vengoal Chang                                      */
/*  Published . : AS400ePaper                                        */
/*  Date  . . . : December 23, 2014                                  */
/*                                                                   */
/* ==================================================================*/

package com.free400.vengoal.as400api;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import com.ibm.as400.access.AS400;
import com.ibm.as400.access.AS400Bin4;
import com.ibm.as400.access.AS400Exception;
import com.ibm.as400.access.AS400Text;
import com.ibm.as400.access.CharConverter;
import com.ibm.as400.access.DateTimeConverter;
import com.ibm.as400.access.ProgramCall;
import com.ibm.as400.access.ProgramParameter;
import com.ibm.as400.access.ServiceProgramCall;
import com.ibm.as400.access.Trace;

public class RtvDtaqD {
	private static final int PAD_LIMIT = 8192;
	private static final AS400Bin4 intConverter_ = new AS400Bin4();
	public static Calendar cal = Calendar.getInstance();
	public static DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");

private static ProgramParameter[] buildProgramParameters(AS400 as400, String dtaqname, String dtaqlib) throws Exception {
		
		ProgramParameter[] parameterList = new ProgramParameter[4];
		parameterList[0] = new ProgramParameter(120);
		
		parameterList[1] = new ProgramParameter(intConverter_.toBytes(120));		
			
		AS400Text text8 = new AS400Text(8, as400);
		parameterList[2] = new ProgramParameter(text8.toBytes("RDQD0100"));	
		
		AS400Text text20 = new AS400Text(20, as400);
		byte[] dtaqNameLibBytes = text20.toBytes(padRight(dtaqname, 10) + padRight(dtaqlib, 10));
		parameterList[3] = new ProgramParameter(dtaqNameLibBytes);
				
		return parameterList;			
	}

	private static void rtvDtaqDesc(AS400 as400, String dtaqname, String dtaqlib){
		try{
			CharConverter charConverter = new CharConverter(as400.getCcsid(), as400);
			ProgramParameter[] parameters = buildProgramParameters(as400, dtaqname, dtaqlib);
			ProgramCall  rtvDtaqPgmDCall = new ProgramCall(as400, "/QSYS.LIB/QMHQRDQD.PGM", parameters);
			//Trace.setTraceAllOn(true);
			//Trace.setTraceOn(true);
			if (rtvDtaqPgmDCall.run() != true) {
				throw new AS400Exception(rtvDtaqPgmDCall.getMessageList());
			} else {
				byte[] rcvVar = parameters[0].getOutputData();
				int maxentlen = intConverter_.toInt(rcvVar, 8);
				System.out.println("Maximum entry length: " + maxentlen );
				
				int keylen = intConverter_.toInt(rcvVar, 12);
				System.out.println("Key length: " + keylen );
				
				String sequence = charConverter.byteArrayToString(rcvVar, 16, 1);
				System.out.println("Sequence: " + sequence );
				
				String senderid = charConverter.byteArrayToString(rcvVar, 17, 1); 
				System.out.println("Include sender ID: " + senderid );
				
				String forceindicator = charConverter.byteArrayToString(rcvVar, 18, 1);
				System.out.println("Force indicator: " + forceindicator );
				
				String text = charConverter.byteArrayToString(rcvVar, 19, 50);
				System.out.println("Text: " + text );
				
				String typeOfDq = charConverter.byteArrayToString(rcvVar, 69, 1);
				System.out.println("Type of data queue: " + typeOfDq );
				
				String autoReclaim = charConverter.byteArrayToString(rcvVar, 70, 1);
				System.out.println("Automatic Reclaim: " + autoReclaim );
				
				String eforceDqLck = charConverter.byteArrayToString(rcvVar, 71, 1);
				System.out.println("Enforce data queue locks: " + eforceDqLck );
				
				int nbrOfMsg = intConverter_.toInt(rcvVar, 72);
				System.out.println("Number of messages: " + nbrOfMsg );
				
				int nbrOfMsgAlc = intConverter_.toInt(rcvVar, 76);
				System.out.println("Number of entries currently allocated: " + nbrOfMsgAlc );			
				
				String dqname = charConverter.byteArrayToString(rcvVar, 80, 10);
				System.out.println("Data queue name used: " +dqname );
				
				String dqlib = charConverter.byteArrayToString(rcvVar, 90, 10);
				System.out.println("Data queue library used: " + dqlib );
				
				int maxNbrOfEntAlw = intConverter_.toInt(rcvVar, 100);
				System.out.println("Maximum number of entries allowed: " + maxNbrOfEntAlw );	
				
				int inlNbrOfEnt = intConverter_.toInt(rcvVar, 104);
				System.out.println("Initial number of entries: " + inlNbrOfEnt );
				
				int maxNbrOfEntSpc = intConverter_.toInt(rcvVar, 108);
				System.out.println("Maximum number of entries specified: " + maxNbrOfEntSpc );
				
				DateTimeConverter dtc = new DateTimeConverter(as400);
				// System current date and time
		        byte[] systemDtsByte = new byte[8];
		        System.arraycopy(rcvVar, 112, systemDtsByte, 0, 8);
		        Date sysDate = dtc.convert(systemDtsByte, "*DTS");
		        String systemTimeStr=null;
		        if (sysDate != null){
		        	cal.setTime(sysDate);
		        	systemTimeStr = df.format(cal.getTime());
		        }
		        System.out.println("Last reclaim date and time: " + systemTimeStr );

			}
			
			} catch(Exception e){
				e.printStackTrace();
			}
	}

	public static String padRight(String s, int n) {
		return String.format("%1$-" + n + "s", s);
	}

	public static void main(String[] args)  {		
		AS400 as400 = new AS400("as400ip", "user", "password");
		rtvDtaqDesc(as400,  "DTAQ", "QGPL");
	}

}







參照: Retrieve Data Queue Description (QMHQRDQD) API




2014-05-23 2014-05-12 如何於 java 環境中透過取得系統名稱?(RtvNetA.java)


如何於 java 環境中透過取得系統名稱?(RtvNetA.java)

RtvNetA.java -- Retrieve Network Attributes 

於 CLP 中可執行 RTVNETA SYSNAME(&SYSNAME),於 java 需要呼叫 API QWCRNETA 來完成。


RtvNetA.java        



/* ==================================================================*/
/*                                                                   */
/*  Program . . : RtvNetA.java                                       */
/*  Description : Retrieve Network Attributes                        */
/*  Author  . . : Vengoal Chang                                      */
/*  Published . : AS400ePaper                                        */
/*  Date  . . . : May 23, 2014                                       */
/*                                                                   */
/* ==================================================================*/

package com.free400.vengoal.as400api;

import com.ibm.as400.access.AS400;
import com.ibm.as400.access.AS400Bin4;
import com.ibm.as400.access.AS400Exception;
import com.ibm.as400.access.AS400Text;
import com.ibm.as400.access.CharConverter;
import com.ibm.as400.access.ErrorCodeParameter;
import com.ibm.as400.access.ProgramCall;
import com.ibm.as400.access.ProgramParameter;

public class RtvNetA {
	
	private AS400 as400;
	private final AS400Bin4 intConverter_ = new AS400Bin4();
	
	public static final String NETATR_ALRBCKFP = "ALRBCKFP";
	public static final String NETATR_ALRCTLD = "ALRCTLD";
	public static final String NETATR_ALRDFTFP = "ALRDFTFP";
	public static final String NETATR_ALRFTR = "ALRFTR";
	public static final String NETATR_ALRHLDCNT = "ALRHLDCNT";
	public static final String NETATR_ALRLOGSTS = "ALRLOGSTS";
	public static final String NETATR_ALRPRIFP = "ALRPRIFP";
	public static final String NETATR_ALRRQSFP = "ALRRQSFP";
	public static final String NETATR_ALRSTS = "ALRSTS";
	public static final String NETATR_ALWADDCLU = "ALWADDCLU";
	public static final String NETATR_ALWANYNET = "ALWANYNET";
	public static final String NETATR_ALWHPRTWR = "ALWHPRTWR";
	public static final String NETATR_ALWVRTAPPN = "ALWVRTAPPN";
	public static final String NETATR_VRTAUTODEV = "VRTAUTODEV";
	public static final String NETATR_DDMACC = "DDMACC";
	public static final String NETATR_DFTCNNLST = "DFTCNNLST";
	public static final String NETATR_DFTMODE = "DFTMODE";
	public static final String NETATR_DFTNETTYPE = "DFTNETTYPE";
	public static final String NETATR_DTACPR = "DTACPR";
	public static final String NETATR_DTACPRINM = "DTACPRINM";
	public static final String NETATR_HPRPTHTMR = "HPRPTHTMR";
	public static final String NETATR_JOBACN = "JOBACN";
	public static final String NETATR_LCLCPNAME = "LCLCPNAME";
	public static final String NETATR_LCLLOCNAME = "LCLLOCNAME";
	public static final String NETATR_LCLNETID = "LCLNETID";
	public static final String NETATR_MAXINTSSN = "MAXINTSSN";
	public static final String NETATR_MAXHOP = "MAXHOP";
	public static final String NETATR_MDMCNTRYID = "MDMCNTRYID";
	public static final String NETATR_MSGQ = "MSGQ";
	public static final String NETATR_NETSERVER = "NETSERVER";
	public static final String NETATR_NODETYPE = "NODETYPE";
	public static final String NETATR_NWSDOMAIN = "NWSDOMAIN";
	public static final String NETATR_OUTQ = "OUTQ";
	public static final String NETATR_PNDSYSNAME = "PNDSYSNAME";
	public static final String NETATR_PCSACC = "PCSACC";
	public static final String NETATR_RAR = "RAR";
	public static final String NETATR_SYSNAME = "SYSNAME";
	
	public RtvNetA(AS400 as400){
		this.as400 = as400;
	}
	
	public String getNetAtr(String attribute) throws Exception{
		String[] atrs = new String[1];
		atrs[0] = attribute;
		String[] rtnAtrs =  getNetAtr(atrs);
		return rtnAtrs[0];
	}
	
	public String[] getNetAtr(String[] attributes)	throws Exception {
		final CharConverter charConverter = new CharConverter(as400.getCcsid(), as400);
		String[] rtnStr = new String[attributes.length];		
		
		ProgramParameter[] parameters = buildProgramParameters(attributes);
		ProgramCall rtvNetAtr = new ProgramCall(as400, "/QSYS.LIB/QWCRNETA.PGM", parameters);

		if (rtvNetAtr.run() != true) {
			throw new AS400Exception(rtvNetAtr.getMessageList());
		} else {
			byte[] rcvVar = parameters[0].getOutputData();
			Integer nbrOfAtrRtn = (Integer) intConverter_.toObject(rcvVar, 0);
			int offsetOfNetAtrInfoTable = 0;
			int offset;
			String netAtr, typeOfData, infoStatus;
			int lenOfData;
			Object atrValue = null;
			for (int i = 0; i < nbrOfAtrRtn; i++) {
				offsetOfNetAtrInfoTable += 4;
				offset =  intConverter_.toInt(rcvVar, offsetOfNetAtrInfoTable);
				netAtr =  charConverter.byteArrayToString(rcvVar, offset, 10);
				offset += 10;
				typeOfData =  charConverter.byteArrayToString(rcvVar, offset, 1);
				offset += 1;
				infoStatus =  charConverter.byteArrayToString(rcvVar, offset, 1);
				offset += 1;
				lenOfData = intConverter_.toInt(rcvVar, offset);
				offset += 4;
				if (typeOfData.equalsIgnoreCase("C")) {
					atrValue = charConverter.byteArrayToString(rcvVar, offset,	lenOfData).trim();
					rtnStr[i] = (String) atrValue;
				} else if (typeOfData.equalsIgnoreCase("B")) {
					atrValue = intConverter_.toInt(rcvVar, offset);
					rtnStr[i] = Integer.toString((Integer) atrValue);
				}
				// System.out.println(netAtr + "=" + atrValue);
			}
		}
		return rtnStr;
	}
	
	private ProgramParameter[] buildProgramParameters(String[] attributes) {
		
		ProgramParameter[] parameterList = new ProgramParameter[5];
		parameterList[0] = new ProgramParameter(2048);
		parameterList[1] = new ProgramParameter(intConverter_.toBytes(2048));
		parameterList[2] = new ProgramParameter(intConverter_.toBytes(attributes.length));
		
		AS400Text text10 = new AS400Text(10, as400);
		byte[] atrNameBytes = new byte[attributes.length * 10];
		int atrNameOffset = 0;
		for (int i = 0; i < attributes.length; i++) {
			byte[] atrName = text10.toBytes(attributes[i]);
			System.arraycopy(atrName, 0, atrNameBytes, atrNameOffset, 10);
			atrNameOffset += 10;
		}
		
		parameterList[3] = new ProgramParameter(atrNameBytes);
		parameterList[4] = new ErrorCodeParameter();
		
		return parameterList;			
	}

	public static void main(String[] args) {
		
		try {
			AS400 as400 = new AS400("AS400IP", "USER", "PASS");
			RtvNetA rtvNetA = new RtvNetA(as400);
			String[] atrName = { RtvNetA.NETATR_SYSNAME };
			String[] rtnValues = rtvNetA.getNetAtr(atrName);
			for (int i = 0; i < rtnValues.length; i++) {
				System.out.println(atrName[i] + "=" + rtnValues[i]);
			}

			atrName[0] = RtvNetA.NETATR_MAXINTSSN;
			rtnValues = rtvNetA.getNetAtr(atrName);
			for (int i = 0; i < rtnValues.length; i++) {
				System.out.println(atrName[i] + "=" + rtnValues[i]);
			}

			String[] atrName2 = { RtvNetA.NETATR_DDMACC, RtvNetA.NETATR_MAXHOP };
			rtnValues = rtvNetA.getNetAtr(atrName2);
			for (int i = 0; i < rtnValues.length; i++) {
				System.out.println(atrName2[i] + "=" + rtnValues[i]);
			}
			
			System.out.println(NETATR_LCLNETID+ "=" + rtvNetA.getNetAtr(NETATR_LCLNETID));
			as400.disconnectAllServices();
			System.exit(0);
		} catch (Exception excp) {
			excp.printStackTrace();
		}
	}
}





2014-05-12 如何於 java 環境中透過 QTEMP library 取得執行指令所輸出的報表內容?(AS400CommandOutput.java)


2014-05-12 如何於 java 環境中透過 QTEMP library 取得執行指令所輸出的報表內容?
AS400CommandOutput.java -- AS400 command output spooled file to TEXT file within QTEMP 

Many CLP to get command spooled output to QTEMP outfile in CLP, but when the CLP call by Java command server, 
could not get the QTEMP file. 

The AS400CommandOutput will run your command output to spooled and use CPYSPLF command to copy spooled to 
QTEMP outfile and read all record to TEXT file within QTEMP use AS400File.runCommand() method. 





AS400CommandOutput.java
        



    package com.free400.vengoal;
     
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.Enumeration;
     
    import com.ibm.as400.access.AS400;
    import com.ibm.as400.access.AS400Exception;
    import com.ibm.as400.access.AS400File;
    import com.ibm.as400.access.AS400FileRecordDescription;
    import com.ibm.as400.access.AS400Message;
    import com.ibm.as400.access.CommandCall;
    import com.ibm.as400.access.Job;
    import com.ibm.as400.access.QSYSObjectPathName;
    import com.ibm.as400.access.Record;
    import com.ibm.as400.access.RecordFormat;
    import com.ibm.as400.access.SequentialFile;
    import com.ibm.as400.access.SpooledFile;
    import com.ibm.as400.access.SpooledFileList;
     
    public class AS400CommandOutput {
        
        private static final String FILE_SEPARATOR_PROP = "file.separator";
        public static java.text.SimpleDateFormat datetimeFmt = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        private AS400 as400;
        private CommandCall commandCall;
        private SequentialFile seqfile;
        private String lastSplfName=null, lastSplfJob=null, lastSplfUsr=null, lastSplfJobNbr=null;
        private int lastSplfNbr=0;
        private String file;
        private String commandJobNbr;
        private String ddmJobNbr;
        private File toFile = null;
        private PrintWriter writer_;
        private FileOutputStream os;
        private boolean fileOpened = false;
     
        public AS400CommandOutput(AS400 as400){
            this.as400 = as400;
            this.commandCall = new CommandCall(this.as400);
        }
        
        public AS400CommandOutput(AS400 as400, File toFile){
            this.as400 = as400;
            this.toFile = toFile;
            this.commandCall = new CommandCall(this.as400);
        }
        
        public AS400 getSystem(){
            return as400;
        }    
     
        public String getCommandJobNbr(){
            String cmdJobNbr = null;
            try {
                as400.connectService(AS400.COMMAND);
                Job[] as400Jobs = as400.getJobs(AS400.COMMAND);
                for(int i=0; i < as400Jobs.length; i++){
                    cmdJobNbr = as400Jobs[i].getNumber();
                    System.out.println("Linking to AS400 job: " + as400Jobs[i].getNumber() + "/" + as400Jobs[i].getUser() + "/" + as400Jobs[i].getName());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }        
            return cmdJobNbr;
        }
        
        public String getDDMJobNbr(){
            String ddmJobNbr = null;
            try {
                as400.connectService(AS400.RECORDACCESS);
                Job[] as400Jobs = as400.getJobs(AS400.RECORDACCESS);
                for(int i=0; i < as400Jobs.length; i++){
                    ddmJobNbr = as400Jobs[i].getNumber();
                    System.out.println("Linking to AS400 job: " + as400Jobs[i].getNumber() + "/" + as400Jobs[i].getUser() + "/" + as400Jobs[i].getName());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }        
            return ddmJobNbr;
        }
        
        public void getLastSplfInfo(String selectSplfName, boolean deleteSplf) throws Exception{
            String splfName, splfJob, splfUsr, splfJobNbr, splfDate,splfTime;
            int splfNbr; 
            String lastSplfDateTime=" ";
            String splfDateTime;     
        
            SpooledFileList splfList = new SpooledFileList( as400 );
            // set filters, all users, on all queues
            splfList.setUserFilter(as400.getUserId());
            splfList.setQueueFilter("/QSYS.LIB/%ALL%.LIB/%ALL%.OUTQ");
            // open list, openSynchronously() returns when the list is completed.
            splfList.openSynchronously();
            Enumeration enumer = splfList.getObjects();            
            while( enumer.hasMoreElements() )
            {
                SpooledFile splf = (SpooledFile)enumer.nextElement();
                if ( splf != null )
                {
                    // output this spooled file's name
                    splfName = splf.getStringAttribute(SpooledFile.ATTR_SPOOLFILE);
                    splfJob = splf.getStringAttribute(SpooledFile.ATTR_JOBNAME);
                    splfUsr = splf.getStringAttribute(SpooledFile.ATTR_JOBUSER);
                    splfJobNbr =  splf.getStringAttribute(SpooledFile.ATTR_JOBNUMBER);
                    splfDate =  splf.getStringAttribute(SpooledFile.ATTR_DATE);
                    splfTime =  splf.getStringAttribute(SpooledFile.ATTR_TIME);
                    splfNbr = splf.getIntegerAttribute(SpooledFile.ATTR_SPLFNUM);
                    splfDateTime = splfDate + splfTime;
                    //System.out.println("splfDate:" + splfDate + " splfTime:" + splfTime + " job:" + splfJobNbr + "/"+ splfUsr + "/" + splfJob +  " spooled file = " + splfName + " splfNbr=" + splfNbr);
                    if(splfName.equalsIgnoreCase(selectSplfName) && splfJob.equalsIgnoreCase("QPRTJOB")){
                        if (deleteSplf){
                            splf.delete();
                        } else if (splfDateTime.compareTo(lastSplfDateTime) > 0){
                            lastSplfDateTime = splfDateTime;
                            lastSplfName = splfName;
                            lastSplfJob  = splfJob;
                            lastSplfUsr  = splfUsr;                         
                            lastSplfJobNbr=splfJobNbr;
                            lastSplfNbr = splfNbr;
                        }
                    }
                }
                //System.out.println("last SPLFInfo: job " + lastSplfJobNbr + "/"+ lastSplfUsr + "/" + lastSplfJob + " lastSplfName:" + lastSplfName + " lastSplfNbr:" + lastSplfNbr);
            }
            // clean up after we are done with the list
            splfList.close();
        }
        
        public void cpysplfWithQtemp(String splfName, boolean deleteTempFile) throws Exception{
            if(seqfile == null){
                seqfile = new SequentialFile();
                seqfile.setSystem(as400);
                seqfile.setPath("/QSYS.LIB/QGPL.LIB/QDDSSRC.FILE"); // for run following command use;
            }
     
            if(ddmJobNbr == null)
                ddmJobNbr = getDDMJobNbr();        
     
            file = splfName.substring(0, 4) + ddmJobNbr;        
            
            getLastSplfInfo(splfName, false);
            CPYSPLF(seqfile, lastSplfName, lastSplfJob, lastSplfUsr, lastSplfJobNbr, lastSplfNbr, true, "QTEMP", file, "M000000000", 201);
            seqfile.setPath(new QSYSObjectPathName("QTEMP", file, "M000000000", "MBR").getPath());
            setRecordFormat();
            if(toFile == null)
                readAll();
            else
                readAll(toFile);
            getLastSplfInfo(splfName, true);
        }
        
        public void readAll(){
            readAll(null);
        }
        
        public void readAll(File toFile){
            try {
                seqfile.open(AS400File.READ_ONLY, 100, AS400File.COMMIT_LOCK_LEVEL_NONE);
                Record dataRcd = seqfile.readNext();
                while (dataRcd != null) {
                    if(toFile == null)
                        onRecord(dataRcd);
                    else
                        onRecord(toFile, dataRcd);
                    dataRcd = seqfile.readNext();
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    seqfile.close();
                    if(fileOpened){
                        writer_.close();
                        os.close();
                        fileOpened = false;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        
        public void onRecord(Record record) {
            System.out.println(getClass() + ":" + record);        
        }
        
        public void onRecord(File file, Record record) throws IOException{
            if(!fileOpened){
                os = new FileOutputStream(file, file.exists());
                writer_ = new PrintWriter(os, true);
                fileOpened = true;
            }
             writer_.println(record);
             writer_.flush();    
        }
        
        public void setRecordFormat() throws Exception{
            AS400FileRecordDescription recordDescription = new AS400FileRecordDescription(as400, seqfile.getPath());
            RecordFormat[] formats = recordDescription.retrieveRecordFormat();
            RecordFormat recordFormat = formats[0];
            seqfile.setRecordFormat(recordFormat);
        }
        
        public void CPYSPLF(SequentialFile seqFile, String splfName, String splfJob, String splfUsr, String splfJobNbr, int splfNbr , boolean includeIGCData, String toLibrary, String toFile, String toMbr, int toFileRecordLength){
     
            String cmdCRTPF = "CRTPF FILE(" 
                    + toLibrary.toUpperCase().trim()  
                    + "/" 
                    + toFile.toUpperCase().trim()  
                    + ") RCDLEN(" 
                    + toFileRecordLength 
                    + ") MBR(" 
                    + toMbr.toUpperCase().trim() 
                    + ") MAXMBRS(*NOMAX) SIZE(*NOMAX)";
            
            String cmdCPYSPLF = "CPYSPLF FILE(" 
                    + splfName
                    + ") TOFILE(" 
                    + toLibrary.toUpperCase().trim() 
                    + "/" 
                    + toFile.toUpperCase().trim() 
                    + ") JOB("
                    + splfJobNbr 
                    + "/" 
                    + splfUsr 
                    + "/" 
                    + splfJob
                    + ") SPLNBR(" 
                    + splfNbr 
                    + ") MBROPT(*REPLACE)";
            try {
                if(!chkObjExist(seqFile, toLibrary, toFile, "*FILE"))
                    seqFile.runCommand(cmdCRTPF);    
     
                AS400Message[] messagelist = seqFile.runCommand(cmdCPYSPLF);
                for (int i = 0; i < messagelist.length; i++) {
                    if (messagelist[i].getID() != null){                    
                        if(messagelist[i].getID().equalsIgnoreCase("CPF3485")){
                            System.out.println(cmdCPYSPLF +" Command successful"); 
                        } else
                            System.out.println(messagelist[i].getID() + " " + messagelist[i].getText());
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        
        public boolean chkObjExist(SequentialFile seqFile, String objLib, String objName, String objType) throws Exception {
            boolean objectExist = true;
            String cmdChkObj;
            cmdChkObj = "CHKOBJ OBJ(" + objLib + "/" + objName + ") OBJTYPE(" + objType + ")";
            AS400Message[] messagelist = seqFile.runCommand(cmdChkObj);
            for (int i = 0; i < messagelist.length; i++) {
                if (messagelist[i].getID() != null){
                    System.out.println(messagelist[i].getID() + " " + messagelist[i].getText());
                    if (messagelist[i].getID().equalsIgnoreCase("CPF9801")){
                        objectExist = false;
                    }
                }
            }
            return objectExist;
        }
        
        public boolean runCmd(String commandString) {        
            boolean success = false;
            try {
                // Run the command.
                if (success = commandCall.run(commandString)){
                    //System.out.println(commandString + " Command successful");
                }else{
                    System.out.println(commandString + " Command failed");
                    throw new AS400Exception(commandCall.getMessageList());
                }
            } catch (Exception e) {
                System.out.println("Command " + commandCall.getCommand() + " did not run");
                e.printStackTrace();
            }
            return success;
        }
        
        public static void main(String[] args) {
            try {
                AS400 as400 = new AS400("as400ip", "user", "userpass");
                AS400CommandOutput get400ACTJOB = new AS400CommandOutput(as400, new File("d:\\temp\\WRKACTJOB.TXT"));
                get400ACTJOB.runCmd("WRKACTJOB OUTPUT(*PRINT) RESET(*YES) SEQ(*CPUPCT)");
                Thread.sleep(5000);
                get400ACTJOB.runCmd("WRKACTJOB OUTPUT(*PRINT) SEQ(*CPUPCT)");
                get400ACTJOB.cpysplfWithQtemp("QPDSPAJB", true);
     
                get400ACTJOB.runCmd("WRKSYSSTS OUTPUT(*PRINT)");
                get400ACTJOB.cpysplfWithQtemp("QPDSPSTS", true);
     
            } catch (Exception e) {
                e.printStackTrace();
            }
        }    
    }