For this example we will call the system API, QUSRMBRD "Retrieve Member Description". This API retrieves the description of a specific member in a database file. The required parameters are shown in the table below.
QUSRMBRD Parameters | |||
Parameter | Input/Output/InputOutput | Type | Description |
---|---|---|---|
Receiver variable | Output | Char(*) | Character buffer which will contain the information retrieved. |
Length of receiver variable | Input | Bin(4) | Length of the character buffer provided for the receiver variable. |
Format name | Input | Char(8) | Format specifying the type of information to be retrieved. Must be one of:
|
Qualified database file name | Input | Char(20) | The qualified file name. This is the file name blank padded to 10 characters followed by the library name blank padded to 10 characters. Special values of *CURLIB and *LIBL are allowed for the library name. |
Database member name | Input | Char(10) | The name of the member blank padded to 10 characters. Special values of *FIRST and *LAST are allowed. |
Override processing | Input | Char(1) | Whether overrides are to be processed. 0 indicates that overrides are not to be processed. This is the value we will specify. |
The format of the retrieved information (based on format MBRD0100) is:
MBRD0100 Format Returned Information | |
Information | Type |
---|---|
Bytes returned | Bin(4) |
Bytes available | Bin(4) |
Database file name | Char(10) |
Database file library name | Char(10) |
Member name | Char(10) |
File attribute (type of file: PF, LF, DDMF) | Char(10) |
Source type (type of the source source member if this is a source file) | Char(10) |
Creation date and time | Char(13) |
Last source change date and time | Char(13) |
Member text description | Char(50) |
Source file (whether the file is a source file: 0=Data file, 1=Source file) | Char(1) |
And now, on to the example.
// Create a ProgramCall object. We will set the program name and parameter list later. ProgramCall qusrmbrd = new ProgramCall(new AS400()); // Create an empty program parameter list ProgramParameter[] parms = new ProgramParameter[6]; // Create AS400DataTypes to convert our input parameters from Java types to AS/400 data AS400Bin4 bin4 = new AS400Bin4(); // We need a separate AS400Text object for each parameter with a different length since the // AS400Text class requires the length to be specified. AS400Text char8Converter = new AS400Text(8) AS400Text char20Converter = new AS400Text(20); AS400Text char10Converter = new AS400Text(10); AS400Text char1Converter = new AS400Text(1); // Populate our parameter list; we use the AS400DataType objects to convert our Java // values to byte arrays containing AS/400 data. parms[0] = new ProgramParameter(135); // For the output parameter we need only specify how many // bytes will be returned. parms[1] = new ProgramParameter(bin4.toBytes(new Integer(135))); parms[2] = new ProgramParameter(char8Converter.toBytes("MBRD0100")); parms[3] = new ProgramParameter(char20Converter.toBytes("MYFILE MYLIB ")); parms[4] = new ProgramParameter(char10COnverter.toBytes("MYMEMBER ")); parms[5] = new ProgramParameter(char1Converter.toBytes("0")); // Set the program name and parameter list qusrmbrd.setProgram("/qsys.lib/qusrmbrd.pgm", parms); // Call the program try { qusrmbrd.run(); } catch(Exception e) { // Handle any exceptions } // Get the information retrieved. Note that this is raw AS/400 data. byte[] receiverVar = parms[0].getOutputData(); AS400Text char13Converter = new AS400Text(13); // We need this to convert the time and date data AS400Text char50Converter = new AS400Text(50); // We need this to convert the text description data // Create an AS400Structure to handle the returned information AS400DataType[] dataTypeArray = new AS400DataType[11]; dataTypeArray[0] = bin4; dataTypeArray[1] = bin4; dataTypeArray[2] = char10Converter; dataTypeArray[3] = char10Converter; dataTypeArray[4] = char10Converter; dataTypeArray[5] = char10Converter; dataTypeArray[6] = char10Converter; dataTypeArray[7] = char13Converter; dataTypeArray[8] = char13Converter; dataTypeArray[9] = char50Converter; dataTypeArray[10] = char1Converter; AS400Structure returnedDataConverter = new AS400Structure(dataTypeArray); // Convert the data returned to an array of Java Objects using our // returnedDataConverter Object[] qusrmbrdInfo = dataConverter.toObject(receiverVar, 0); // Get the number of bytes returned Integer bytesReturned = (Integer)qusrmbrdInfo[0]; Integer bytesAvailable = (Integer)qusrmbrdInfo[1]; if (bytesReturned.intValue() != 135) { System.out.println("Wrong amount of information returned."); System.exit(0); } String fileName = (String)qusrmbrdInfo[2]; String libName = (String)qusrmbrdInfo[3]; String mbrName = (String)qusrmbrdInfo[4]; String fileAttribute = (String)qusrmbrdInfo[5]; String sourceType = (String)qusrmbrdInfo[6]; String created = (String)qusrmbrdInfo[7]; String lastChanged = (String)qusrmbrdInfo[8]; String textDesc = (String)qusrmbrdInfo[9]; String isSourceFile = (String)qusrmbrdInfo[10]; // We will just output all the information to the screen System.out.println(fileName + " " + libName + " " + mbrName + " " + fileAttribute + sourceType + " " + created + " " + lastChanged + " " + textDesc + " " + isSourceFile);