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
A blog about IBM i (AS/400), MQ and other things developers or Admins need to know.
星期四, 11月 09, 2023
2015-09-17 Retrieve AS400 Network Interfaces with java( List Network Interfaces (QtocLstNetIfc) API format NIFC0100)
2015-07-02 Get AS400 Subsystem jobs with java( Open List of Jobs (QGYOLJOB) API format OLJB0300)
Get AS400 Subsystem jobs with java( Open List of Jobs (QGYOLJOB) API format OLJB0300)
(SubsystemJobOpenListTest.java, SubsystemJobListItem.java, SubsystemJobOpenList.java)
File : SubsystemJobListItem.java
///////////////////////////////////////////////////////////////////////////////
//
//
// Filename: SubsystemJobListItem.java
//
// Author : Vengoal Chang
//
// Date : 2015/07/01
//
//
///////////////////////////////////////////////////////////////////////////////
package com.vengoal.as400.list;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import com.ibm.as400.access.BinaryConverter;
public class SubsystemJobListItem {
public static final int ACTIVE_JOB_STATUS_FOR_JOBS_ENDING = 103; // Active job status for jobs ending
public static final int CURRENT_USER = 305; // Current user profile
public static final int CPU_TIME_USED_LARGE = 312; // Processing unit time used - total for the job
public static final int CPU_TIME_USED_FOR_DATABASE = 313; // Processing unit time used for database - total for the job (Deprecated)
public static final int ELAPSED_CPU_PERCENT_USED = 314; // Processing unit used - percent during the elapsed time (job)
public static final int ELAPSED_CPU_TIME_USED = 315; // Processing unit used - time during the elapsed time (job)
public static final int ELAPSED_CPU_PERCENT_USED_FOR_DATABASE = 316; // Processing unit used for database - percent during the elapsed time (job) (Deprecated)
public static final int ELAPSED_CPU_TIME_USED_FOR_DATABASE = 317; // Processing unit used for database - time during the elapsed time (job) (Deprecated)
public static final int DATE_ENTERED_SYSTEM = 402; // Date and time job entered system
public static final int ELAPSED_DISK_IO = 414; // Disk I/O count during the elapsed time (job)
public static final int DISK_IO = 415; // Disk I/O count - total for the job
public static final int ELAPSED_DISK_IO_ASYNCH = 416; // Disk I/O count during the elapsed time - asynchronous I/O (job)
public static final int ELAPSED_DISK_IO_SYNCH = 417; // Disk I/O count during the elapsed time - synchronous I/O (job)
public static final int CONTROLLED_END_REQUESTED = 502; // End status
public static final int FUNCTION_NAME = 601; // Function name
public static final int FUNCTION_TYPE = 602; // Function type
public static final int INTERNAL_JOB_IDENTIFIER = 902; // Internal job identifier
public static final int ELAPSED_INTERACTIVE_RESPONSE_TIME = 904; // Interactive response time - total during the elapsed time
public static final int ELAPSED_INTERACTIVE_TRANSACTIONS = 905; // Interactive transactions - count during the elapsed time
public static final int JOB_USER_IDENTITY = 1012; // Job user identity
public static final int JOB_END_REASON = 1014; // Job end reason
public static final int JOB_LOG_PENDING = 1015; // Job log pending
public static final int JOB_TYPE_ENHANCED = 1016; // Job type - enhanced
public static final int MEMORY_POOL = 1306; // Memory pool name
public static final int MESSAGE_REPLY = 1307; // Message reply
public static final int MESSAGE_KEY = 1308; // Message key, when active job waiting for a message
public static final int MESSAGE_QUEUE = 1309; // Message queue name - qualified, when active job waiting for a message
public static final int MESSAGE_QUEUE_ASP = 1310; // Message queue library ASP device name, when active job waiting for a message
public static final int ELAPSED_PAGE_FAULTS = 1609; // Page fault count during the elapsed time (job)
public static final int RUN_PRIORITY = 1802; // Run priority (job)
public static final int SUBSYSTEM = 1906; // Subsystem description name - qualified
public static final int SERVER_TYPE = 1911; // Server type
public static final int SPOOLED_FILE_ACTION = 1982; // Spooled file action
public static final int THREAD_COUNT = 2008; // Thread count
public static final int TEMP_STORAGE_USED_LARGE = 2009; // Temporary storage used, in megabytes(from V7R2)
private String jobName;
private String jobUser;
private String jobNumber;
private String status;
private String jobType;
private String jobSubtype;
private String currentUser; // key 305
private String functionName; // key 601
private String functionType; // key 602
private String messageReply; // key 1307
private byte[] messageKey; // key 1308
private String qualMessageQueue; // key 1309
private String qualSubsystem; // key 1906
private TreeMap keyValues = new TreeMap(); // key others
public SubsystemJobListItem(String jobName, String jobUser, String jobNumber,
String status, String jobType,String jobSubtype, String currentUser, String functionName,
String functionType,
String messageReply, byte[] messageKey, String qualMessageQueue, String qualSubsystem) {
this.jobName = jobName;
this.jobUser = jobUser;
this.jobNumber = jobNumber;
this.status = status;
this.jobType = jobType;
this.jobSubtype = jobSubtype;
this.currentUser = currentUser;
this.functionName = functionName;
this.functionType = functionType;
this.messageReply = messageReply;
this.messageKey = messageKey;
this.qualMessageQueue = qualMessageQueue;
this.qualSubsystem = qualSubsystem;
}
public Object getObject(int key){
return keyValues.get(key);
}
public void setKeyValues(TreeMap keyValues){
this.keyValues = keyValues;
}
public String getJobName() {
return jobName;
}
public String getJobUser() {
return jobUser;
}
public String getJobNumber() {
return jobNumber;
}
public String getStatus() {
return status;
}
public String getJobType() {
return jobType;
}
public String getJobSubtype() {
return jobSubtype;
}
public String getCurrentUser() {
return currentUser;
}
public String getFunctionName() {
return functionName;
}
public String getFunctionType() {
return functionType;
}
public String getMessageReply() {
return messageReply;
}
public byte[] getMessageKey() {
return messageKey;
}
public String getQualMessageQueue() {
return qualMessageQueue;
}
public String getQualSubsystem() {
return qualSubsystem;
}
public String toString(){
StringBuffer strBuf = new StringBuffer();
strBuf.append(jobName).append("/");
strBuf.append(jobUser).append("/");
strBuf.append(jobNumber).append(",");
strBuf.append(status).append(",");
strBuf.append(jobType).append(",");
strBuf.append(jobSubtype).append(",");
strBuf.append("305=" + currentUser).append(",");
strBuf.append("601=" + functionName).append(",");
strBuf.append("602=" + functionType).append(",");
strBuf.append("1307=" + messageReply).append(",");
strBuf.append("1308(MSGKEY 4 bytes hex string)=" + BinaryConverter.bytesToHexString(messageKey)).append(",");
strBuf.append("1309=" + qualMessageQueue).append(",");
strBuf.append("1906=" + qualSubsystem);
if(keyValues.size() > 0){
Set set = keyValues.entrySet();
Iterator i = set.iterator();
while(i.hasNext()) {
Map.Entry me = (Map.Entry)i.next();
strBuf.append("," + me.getKey() + "=" + me.getValue());
}
}
return strBuf.toString();
}
}
File : SubsystemJobOpenList.java
///////////////////////////////////////////////////////////////////////////////
//
//
// Filename: SubsystemJobOpenList.java
//
// Author : Vengoal Chang
//
// Date : 2015/07/01
//
//
///////////////////////////////////////////////////////////////////////////////
package com.vengoal.as400.list;
import java.io.IOException;
import java.util.TreeMap;
import com.ibm.as400.access.AS400;
import com.ibm.as400.access.AS400Exception;
import com.ibm.as400.access.AS400SecurityException;
import com.ibm.as400.access.AS400Text;
import com.ibm.as400.access.BinaryConverter;
import com.ibm.as400.access.CharConverter;
import com.ibm.as400.access.ErrorCodeParameter;
import com.ibm.as400.access.ErrorCompletingRequestException;
import com.ibm.as400.access.Job;
import com.ibm.as400.access.ObjectDoesNotExistException;
import com.ibm.as400.access.ProgramCall;
import com.ibm.as400.access.ProgramParameter;
import com.ibm.as400.access.Trace;
import com.ibm.as400.access.list.OpenList;
/**
* Represents a list of subsystem jobs on the system with Open List of Jobs (QGYOLJOB) API.
* By default, following keys retrieved:
* keys_[0] = 305;
* keys_[1] = 601;
* keys_[2] = 602;
* keys_[3] = 1307;
* keys_[4] = 1308;
* keys_[5] = 1309;
* keys_[6] = 1906;
*
* List of Keys Supported for Format OLJB0300 reference:
* http://www-01.ibm.com/support/knowledgecenter/ssw_ibm_i_72/apis/qgyoljob.htm?lang=en
*
*/
public class SubsystemJobOpenList extends OpenList {
private String subsystem_;
private Job[] subsystemJobs_;
// Sort keys.
private int currentSortKey_ = 1;
// Info saved between calls to load() and getJobs().
private int numKeysReturned_;
private int[] keyFieldsReturned_;
private char[] keyTypesReturned_;
private int[] keyLengthsReturned_;
private int[] keyOffsetsReturned_;
// Keys to pre-load.
private int currentKey_ = 7;
private int[] keys_ = new int[currentKey_];
public SubsystemJobOpenList(AS400 system, String subsystem) {
super(system);
this.subsystem_ = subsystem;
// Figure out Job information default return key fields
keys_[0] = 305;
keys_[1] = 601;
keys_[2] = 602;
keys_[3] = 1307;
keys_[4] = 1308;
keys_[5] = 1309;
keys_[6] = 1906;
}
public void addJobAttributeToRetrieve(int attribute){
if (currentKey_ >= keys_.length){
// Resize.
int[] temp = keys_;
keys_ = new int[temp.length * 2];
System.arraycopy(temp, 0, keys_, 0, temp.length);
}
keys_[currentKey_++] = attribute;
}
public Job[] getSubsystemJobs(){
return subsystemJobs_;
}
@Override
protected byte[] callOpenListAPI() throws AS400SecurityException,
ErrorCompletingRequestException, InterruptedException, IOException,
ObjectDoesNotExistException {
if (Trace.isTraceOn()) Trace.log(Trace.DIAGNOSTIC, "Opening spooled file list.");
int lengthOfReceiverVariableDefinitionInformation = 4 + 20 * currentKey_;
byte[] keyOfFieldsToBeReturned = new byte[4 * currentKey_];
for (int i = 0; i < currentKey_; ++i)
{
BinaryConverter.intToByteArray(keys_[i], keyOfFieldsToBeReturned, i * 4);
}
// Figure out our sort information
byte[] sortInformation = new byte[4 + currentSortKey_ * 12];
BinaryConverter.intToByteArray(currentSortKey_, sortInformation, 0);
int fieldStartingPosition = 1;
int fieldLength = 10;
short dataType = (short)4;
BinaryConverter.intToByteArray(fieldStartingPosition, sortInformation, 4 );
BinaryConverter.intToByteArray(fieldLength, sortInformation, 8);
BinaryConverter.shortToByteArray(dataType, sortInformation, 12);
// Sort order 0xF1 = ascending, 0xF2 = descending.
sortInformation[14] = (byte)0xF1;
// Figure out our selection criteria.
byte[] jobSelectionInformation = new byte[206];
// Generate text objects based on system CCSID.
CharConverter conv = new CharConverter(system_.getCcsid(), system_);
for (int i = 0; i < 26; ++i) jobSelectionInformation[i] = 0x40;
String selectionJobName_ = "*ALL";
String selectionUserName_= "*ALL";
String selectionJobNumber_= "*ALL";
String selectionJobType_= "*";
conv.stringToByteArray(selectionJobName_.toUpperCase(), jobSelectionInformation, 0);
conv.stringToByteArray(selectionUserName_.toUpperCase(), jobSelectionInformation, 10);
conv.stringToByteArray(selectionJobNumber_, jobSelectionInformation, 20);
conv.stringToByteArray(selectionJobType_, jobSelectionInformation, 26);
int offset = 195;
int numberOfSubsystem = 1;
BinaryConverter.intToByteArray(offset, jobSelectionInformation, 76);
BinaryConverter.intToByteArray(numberOfSubsystem, jobSelectionInformation, 80);
// Subsystem name
AS400Text subsystemText = new AS400Text(10, system_);
byte[] subSystemBytes = subsystemText.toBytes(subsystem_);
System.arraycopy(subSystemBytes, 0, jobSelectionInformation, offset, 10);
offset += 10;
// Setup program parameters.
ProgramParameter[] parameters = new ProgramParameter[]
{
// Receiver variable, output, char(*).
new ProgramParameter(0),
// Length of receiver variable, input, binary(4).
new ProgramParameter(new byte[] { 0x00, 0x00, 0x00, 0x00 } ),
// Format name, input, char(8), EBCDIC 'OLJB0300'.
new ProgramParameter(new byte[] { (byte)0xD6, (byte)0xD3, (byte)0xD1, (byte)0xC2, (byte)0xF0, (byte)0xF3, (byte)0xF0, (byte)0xF0 } ),
// Receiver variable definition information, output, char(*).
new ProgramParameter(lengthOfReceiverVariableDefinitionInformation),
// Length of receiver variable definition information, input, binary(4).
new ProgramParameter(BinaryConverter.intToByteArray(lengthOfReceiverVariableDefinitionInformation)),
// List information, output, char(80).
new ProgramParameter(80),
// Number of records to return, input, binary(4).
// Special value '-1' indicates that "all records are built synchronously in the list".
new ProgramParameter(new byte[] { (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF } ),
// Sort information, input, char(*).
new ProgramParameter(sortInformation),
// Job selection information, input, char(*).
new ProgramParameter(jobSelectionInformation),
// Size of job selection information, input, binary(4).
new ProgramParameter(BinaryConverter.intToByteArray(jobSelectionInformation.length)),
// Number of fields to return, input, binary(4).
new ProgramParameter(BinaryConverter.intToByteArray(currentKey_)),
// Key of fields to be returned, input, array(*) of binary(4).
new ProgramParameter(keyOfFieldsToBeReturned),
// Error code, I/0, char(*).
new ErrorCodeParameter(),
// Job selection format name, input, char(8), EBCDIC 'OLJS0200'.
new ProgramParameter(new byte[] { (byte)0xD6, (byte)0xD3, (byte)0xD1, (byte)0xE2, (byte)0xF0, (byte)0xF2, (byte)0xF0, (byte)0xF0 } )
};
// Call the program.
ProgramCall pc = new ProgramCall(system_, "/QSYS.LIB/QGY.LIB/QGYOLJOB.PGM", parameters);
if (!pc.run())
{
throw new AS400Exception(pc.getMessageList());
}
// Key information returned.
byte[] defInfo = parameters[3].getOutputData();
numKeysReturned_ = BinaryConverter.byteArrayToInt(defInfo, 0);
keyFieldsReturned_ = new int[numKeysReturned_];
keyTypesReturned_ = new char[numKeysReturned_];
keyLengthsReturned_ = new int[numKeysReturned_];
keyOffsetsReturned_ = new int[numKeysReturned_];
offset = 4;
for (int i = 0; i < numKeysReturned_; ++i)
{
keyFieldsReturned_[i] = BinaryConverter.byteArrayToInt(defInfo, offset + 4);
keyTypesReturned_[i] = conv.byteArrayToString(defInfo, offset + 8, 1).charAt(0); // 'C' or 'B'
keyLengthsReturned_[i] = BinaryConverter.byteArrayToInt(defInfo, offset + 12);
keyOffsetsReturned_[i] = BinaryConverter.byteArrayToInt(defInfo, offset + 16);
offset += 20;
}
// List information returned.
return parameters[5].getOutputData();
}
@Override
protected Object[] formatOutputData(byte[] data, int recordsReturned, int recordLength)
throws AS400SecurityException, ErrorCompletingRequestException,
InterruptedException, IOException, ObjectDoesNotExistException {
int number = recordsReturned; // request entire list
CharConverter conv = new CharConverter(system_.getCcsid(), system_);
SubsystemJobListItem[] listItems = new SubsystemJobListItem[number];
subsystemJobs_ = new Job[number];
String currentUser = null;
String functionName = null;
String functionType = null;
String messageReply = null;
byte[] messageKey = null;
String qualMessageQueue = null;
String qualSubsystem = null;
TreeMap keyValues = new TreeMap();
for (int i = 0, offset = 0; i < listItems.length; ++i, offset += recordLength)
{
String jobName = conv.byteArrayToString(data, offset, 10);
String jobUser = conv.byteArrayToString(data, offset + 10, 10);
String jobNumber = conv.byteArrayToString(data, offset + 20, 6);
String status = conv.byteArrayToString(data, offset + 26, 4);
String jobType = conv.byteArrayToString(data, offset + 30, 1);
String jobSubtype = conv.byteArrayToString(data, offset + 31, 1);
for (int j = 0; j < numKeysReturned_; ++j)
{
int keyOffset = keyOffsetsReturned_[j];
if (keyTypesReturned_[j] == 'C')
{
String value = conv.byteArrayToString(data, offset + keyOffset, keyLengthsReturned_[j]);
if(keyFieldsReturned_[j] == 305 ) currentUser = value;
if(keyFieldsReturned_[j] == 601 ) functionName = value;
if(keyFieldsReturned_[j] == 602 ) functionType = value;
if(keyFieldsReturned_[j] == 1307) messageReply = value;
if(keyFieldsReturned_[j] == 1309) qualMessageQueue = value;
if(keyFieldsReturned_[j] == 1906) qualSubsystem = value;
if(keyFieldsReturned_[j] == 1308)
{
byte[] msgKey = new byte[4];
System.arraycopy(data, offset + keyOffset, msgKey, 0, 4);
messageKey = msgKey;
}
if(j > 6){
if(keyFieldsReturned_[j] == 312 || keyFieldsReturned_[j] == 313 ||
keyFieldsReturned_[j] == 315 || keyFieldsReturned_[j] == 317 ||
keyFieldsReturned_[j] == 414 || keyFieldsReturned_[j] == 415 ||
keyFieldsReturned_[j] == 416 || keyFieldsReturned_[j] == 417 ||
keyFieldsReturned_[j] == 1609)
keyValues.put(keyFieldsReturned_[j], new Long(BinaryConverter.byteArrayToLong(data, offset + keyOffset))) ;
else
keyValues.put(keyFieldsReturned_[j], value) ;
}
}
else
{
if ((keyFieldsReturned_[j] == Job.TEMP_STORAGE_USED_LARGE))
keyValues.put(keyFieldsReturned_[j], new Long(BinaryConverter.byteArrayToUnsignedInt(data, offset + keyOffset))) ;
else
keyValues.put(keyFieldsReturned_[j], new Integer(BinaryConverter.byteArrayToInt(data, offset + keyOffset))) ;
}
}
listItems[i] = new SubsystemJobListItem(jobName, jobUser, jobNumber,
status, jobType,jobSubtype, currentUser, functionName, functionType,
messageReply, messageKey, qualMessageQueue, qualSubsystem);
subsystemJobs_[i] = new Job(this.getSystem(), jobName, jobUser, jobNumber);
listItems[i].setKeyValues(keyValues);
}
return listItems;
}
@Override
protected int getBestGuessReceiverSize(int number) {
return 300 * number;
}
}
File : SubsystemJobOpenListTest.java
//////////////////////////////////////////////////////////////////////////////
//
//
// Filename: SubsystemJobOpenListTest.java
//
// Author : Vengoal Chang
//
// Date : 2015/07/01
//
//
///////////////////////////////////////////////////////////////////////////////
package com.vengoal.as400.list;
import java.util.Enumeration;
import com.ibm.as400.access.AS400;
import com.ibm.as400.access.CallStackEntry;
import com.ibm.as400.access.Job;
import com.vengoal.as400.common.MessageUtil;
public class SubsystemJobOpenListTest {
public static void main(String[] args) {
AS400 as400 = new AS400("as400ip", "user", "pass");
String subsystem = "QBATCH";
SubsystemJobOpenList list = new SubsystemJobOpenList(as400, subsystem);
list.addJobAttributeToRetrieve(SubsystemJobListItem.MEMORY_POOL);
list.addJobAttributeToRetrieve(SubsystemJobListItem.RUN_PRIORITY);
list.addJobAttributeToRetrieve(SubsystemJobListItem.DATE_ENTERED_SYSTEM);
list.addJobAttributeToRetrieve(SubsystemJobListItem.JOB_LOG_PENDING);
list.addJobAttributeToRetrieve(SubsystemJobListItem.JOB_TYPE_ENHANCED);
list.addJobAttributeToRetrieve(SubsystemJobListItem.SPOOLED_FILE_ACTION);
list.addJobAttributeToRetrieve(SubsystemJobListItem.THREAD_COUNT);
list.addJobAttributeToRetrieve(SubsystemJobListItem.CPU_TIME_USED_LARGE);
list.addJobAttributeToRetrieve(SubsystemJobListItem.ELAPSED_CPU_PERCENT_USED);
list.addJobAttributeToRetrieve(SubsystemJobListItem.ELAPSED_CPU_TIME_USED);
list.addJobAttributeToRetrieve(SubsystemJobListItem.ELAPSED_PAGE_FAULTS);
list.addJobAttributeToRetrieve(SubsystemJobListItem.DISK_IO);
list.addJobAttributeToRetrieve(SubsystemJobListItem.ELAPSED_DISK_IO_ASYNCH);
list.addJobAttributeToRetrieve(SubsystemJobListItem.ELAPSED_DISK_IO_SYNCH);
try {
list.open();
Enumeration items = list.getItems();
while (items.hasMoreElements())
{
SubsystemJobListItem item = (SubsystemJobListItem)items.nextElement();
System.out.println(item);
if(item.getMessageReply().equalsIgnoreCase(Job.MESSAGE_REPLY_WAITING)){
System.out.println(MessageUtil.getErrMsgTxtWithAPI(as400, item.getMessageKey(), item.getQualMessageQueue()));
Job msgwJob = new Job(as400, item.getJobName(), item.getJobUser(), item.getJobNumber());
CallStackEntry[] callstackEntry = msgwJob.getCallStack(Job.INITIAL_THREAD);
System.out.println("job call stack as following:");
for(int i = 0; i< callstackEntry.length; ++i){
//System.out.println(callstackEntry[i].getProgramLibrary() + "/" + callstackEntry[i].getProgramName() + " " + callstackEntry[i].getProcedureName());
}
}
System.out.println("Spooled file action=" + item.getObject(SubsystemJobListItem.SPOOLED_FILE_ACTION));
System.out.println("====================================");
}
Job[] subsystemJobs = list.getSubsystemJobs();
if(subsystemJobs != null){
for(int i =0; i < subsystemJobs.length; ++i){
// do your work related job
System.out.println(subsystemJobs[i].getNumber() + "/" + subsystemJobs[i].getUser() + "/" + subsystemJobs[i].getName());
}
} else {
System.out.println("Subsystem " + subsystem + " is inactive or not exist");
}
list.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
參照: Open List of Jobs (QGYOLJOB) 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();
}
}
}
星期二, 11月 07, 2023
2005-11-21 如何於 RPG 中取得 Java JVM 相關系統資訊 ?
如何於 RPG 中取得 Java JVM 相關系統資訊 ?
此範例程式藉由呼叫 Java 的相關 API,列印 JVM 系統屬性
File : QRPGLESRC
Member: JAVASYSR
Type : RPGLE
Usage : CRTBNDRPG JAVASYSR
CALL JAVASYSR
相關 OS/400 設定參照程式說明
*********************************************************************
* *
* Get Java VM version System Properities *
* first check V5R2 5722SS1 PTF SI13932 *
* V5R1 5722SS1 PTF SI10069 *
* Then use following command specify run time JVM version: *
* *
* ADDENVVAR ENVVAR(QIBM_RPG_JAVA_PROPERTIES) *
* VALUE('-Djava.version=1.3;') *
* or *
* ADDENVVAR ENVVAR(QIBM_RPG_JAVA_PROPERTIES) *
* VALUE('-Djava.version=1.4;') *
* *
*********************************************************************
H DEBUG OPTION(*SRCSTMT:*NODEBUGIO)
H dftactgrp(*no) thread(*serialize) bnddir('QC2LE')
*********************************************************************
*s6* * Java String method
*********************************************************************
FQSYSPRT O F 132 PRINTER
D newString PR O EXTPROC(*JAVA:
D 'java.lang.String':
D *CONSTRUCTOR)
D Class(*JAVA:'java.lang.String')
D value 65535A CONST VARYING
D stringBytes PR 100A VARYING
D EXTPROC(*JAVA
D :'java.lang.String'
D :'getBytes')
D stringLength PR 10I 0
D EXTPROC(*JAVA
D :'java.lang.String'
D :'length')
* java.lang.trim() --------------------------------------------------
D trimString PR O ExtProc(*JAVA:'java.lang.String'
D :'trim')
D Class(*JAVA:'java.lang.String')
D newProp PR O ExtProc(*JAVA:'java.util.Properties'
D :*CONSTRUCTOR)
D Class(*JAVA:'java.util.Properties')
D prop O Class(*java:'java.util.Properties')
D getSysProp PR O ExtProc(*JAVA:'java.lang.System'
D :'getProperties')
D STATIC
D Class(*java:'java.util.Properties')
D propertyNames PR O ExtProc(*JAVA:'java.util.Properties'
D :'propertyNames')
D Class(*java:'java.util.Enumeration')
D getProperty PR O ExtProc(*JAVA:'java.util.Properties'
D :'getProperty')
D Class(*java:'java.lang.String')
D O Class(*java:'java.lang.String')
D hasMoreElts PR N
D ExtProc(*JAVA:
D 'java.util.Enumeration':
D 'hasMoreElements')
D nextElement PR O
D ExtProc(*JAVA:
D 'java.util.Enumeration':
D 'nextElement')
D Class(*java:
D 'java.lang.Object')
D objToString PR O
D ExtProc(*JAVA:
D 'java.lang.Object':
D 'toString')
D Class(*java:
D 'java.lang.String')
D
D obj S O Class(*java:'java.lang.Object')
D p_String S O Class(*java:'java.lang.String')
D p_Value S O Class(*java:'java.lang.String')
D properties S O Class(*java:'java.util.Properties')
D enumeration S O Class(*java:'java.util.Enumeration')
D pname S 35
D pvalue S 97
/free
properties = getSysProp();
enumeration = propertyNames(properties);
Except Header;
dow hasMoreElts(enumeration);
obj = nextElement(enumeration);
p_string = objToString(obj);
pname = stringBytes(p_string);
p_value = getProperty(properties : p_string);
pvalue = stringBytes(p_value);
Except Detail;
enddo;
// dump;
*InLr = *On;
/end-free
****************************************************************
OQSYSPRT E Header 1
O 50 'Java System Properties'
O E Detail 1
O pname 35
O pvalue 132
星期一, 11月 06, 2023
2004-12-31 如何於 RPG 中呼叫 Java method ?
如何於 RPG 中呼叫 Java method ?
File : QRPGLESRC
Member: JAVASYSR
Type : RPGLE
OS Usage: OS/400 V5R1 以後(含)
CRTBNDPGM JAVASYSR
CALL JAVASYSR 產生報表
WRKJOB option 4 即可檢視報表 QSYSPRT
*********************************************************************
* *
* Get Java VM version System Properities *
* first check V5R2 5722SS1 PTF SI13932 *
* V5R1 5722SS1 PTF SI10069 *
* Then use following command specify run time JVM version: *
* *
* ADDENVVAR ENVVAR(QIBM_RPG_JAVA_PROPERTIES) *
* VALUE('-Djava.version=1.3;') *
* or *
* ADDENVVAR ENVVAR(QIBM_RPG_JAVA_PROPERTIES) *
* VALUE('-Djava.version=1.4;') *
* *
*********************************************************************
H DEBUG OPTION(*SRCSTMT:*NODEBUGIO)
H dftactgrp(*no) thread(*serialize) bnddir('QC2LE')
*********************************************************************
*s6* * Java String method
*********************************************************************
FQSYSPRT O F 132 PRINTER
D newString PR O EXTPROC(*JAVA:
D 'java.lang.String':
D *CONSTRUCTOR)
D Class(*JAVA:'java.lang.String')
D value 65535A CONST VARYING
D stringBytes PR 100A VARYING
D EXTPROC(*JAVA
D :'java.lang.String'
D :'getBytes')
D stringLength PR 10I 0
D EXTPROC(*JAVA
D :'java.lang.String'
D :'length')
* java.lang.trim() --------------------------------------------------
D trimString PR O ExtProc(*JAVA:'java.lang.String'
D :'trim')
D Class(*JAVA:'java.lang.String')
D newProp PR O ExtProc(*JAVA:'java.util.Properties'
D :*CONSTRUCTOR)
D Class(*JAVA:'java.util.Properties')
D prop O Class(*java:'java.util.Properties')
D getSysProp PR O ExtProc(*JAVA:'java.lang.System'
D :'getProperties')
D STATIC
D Class(*java:'java.util.Properties')
D propertyNames PR O ExtProc(*JAVA:'java.util.Properties'
D :'propertyNames')
D Class(*java:'java.util.Enumeration')
D getProperty PR O ExtProc(*JAVA:'java.util.Properties'
D :'getProperty')
D Class(*java:'java.lang.String')
D O Class(*java:'java.lang.String')
D hasMoreElts PR N
D ExtProc(*JAVA:
D 'java.util.Enumeration':
D 'hasMoreElements')
D nextElement PR O
D ExtProc(*JAVA:
D 'java.util.Enumeration':
D 'nextElement')
D Class(*java:
D 'java.lang.Object')
D objToString PR O
D ExtProc(*JAVA:
D 'java.lang.Object':
D 'toString')
D Class(*java:
D 'java.lang.String')
D
D obj S O Class(*java:'java.lang.Object')
D p_String S O Class(*java:'java.lang.String')
D p_Value S O Class(*java:'java.lang.String')
D properties S O Class(*java:'java.util.Properties')
D enumeration S O Class(*java:'java.util.Enumeration')
D pname S 35
D pvalue S 97
/free
properties = getSysProp();
enumeration = propertyNames(properties);
Except Header;
dow hasMoreElts(enumeration);
obj = nextElement(enumeration);
p_string = objToString(obj);
pname = stringBytes(p_string);
p_value = getProperty(properties : p_string);
pvalue = stringBytes(p_value);
Except Detail;
enddo;
// dump;
*InLr = *On;
/end-free
****************************************************************
OQSYSPRT E Header 1
O 50 'Java System Properties'
O E Detail 1
O pname 35
O pvalue 132
詳細資訊參照:WebSphere Development Studio ILE RPG Programmer's Guide
星期二, 10月 24, 2023
Domino Document
https://help.hcltechsw.com/domino/welcome/index.html
Domino 12.0.2 Designer
Developer View for IBM/Lotus Notes
WebSphere MQ Programming Using Base Classes for Java
(PDF) Integrate Domino and WebSphere MQ - DOKUMEN.TIPS
(PDF) Writing Java to build applications using IBM Lotus Domino Designer
Example: Working with sections in Java classes
This agent displays properties for all the sections in the Body item of the current document.
import lotus.domino.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
// (Your code goes here)
DocumentCollection dc = agentContext.getUnprocessedDocuments();
Document doc = dc.getFirstDocument();
RichTextItem body = (RichTextItem)doc.getFirstItem("Body");
RichTextNavigator rtnav = body.createNavigator();
if (rtnav.findFirstElement(RichTextItem.RTELEM_TYPE_SECTION)) {
do {
RichTextSection rtsection = (RichTextSection)rtnav.getElement();
System.out.println(
"Title = " + rtsection.getTitle());
System.out.println("\tBar color = " +
rtsection.getBarColor().getNotesColor());
System.out.println(
"\tIs expanded = " + rtsection.isExpanded());
System.out.println(
"\tTitle style font = " + rtsection.getTitleStyle().getFont());
} while (rtnav.findNextElement());
}
else
System.out.println("No sections in Body");
} catch(Exception e) {
e.printStackTrace();
}
}
}
星期四, 12月 09, 2010
訂閱:
文章 (Atom)