Data types example usage

You can use the AS400DataType classes with ProgramCall to supply data for program parameters and to interpret the data returned in program parameters.
Note: Read the Code example disclaimer for important legal information.

Example: Using AS400DataType classes with ProgramCall

The following example shows how to use AS400DataType classes by using ProgramCall to call the system API, QUSRMBRD "Retrieve Member Description". The QUSRMBRD API retrieves the description of a specific member in a database file. The tables following the example list the required QUSRMBRD parameters and the types of information that the example retrieves.

     // 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 server data
     AS400Bin4 bin4 = new AS400Bin4();

     // We need a separate AS400Text object for each parameter with a
     // different length because 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 server data.

     // For the output parameter we need only specify how many bytes will
     // be returned
     parms[0] = new ProgramParameter(135);
     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 server data.
     byte[] receiverVar = parms[0].getOutputData();


  // We need this to convert the time and date data
     AS400Text char13Converter = new AS400Text(13);

  // We need this to convert the text description data
     AS400Text char50Converter = new AS400Text(50);

     // 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);

The following table lists the required parameters for the QUSRMBRD API as used in the preceding example.

QUSRMBRD parameter Input or output 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:
  • MBRD0100
  • MBRD0200
  • MBRD0300
The following example specifies MBRD0100.
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 following table lists the type of information that the example retrieves (based on format MBRD0100, as specified in the preceding example):

Information retrieved 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)