× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: list members
  • From: Glenn Holmer <gholmer@xxxxxxxxxxxxxx>
  • Date: Thu, 01 Mar 2001 14:24:00 -0600
  • Organization: Weyco Group, Inc.

Jerrold_Bisera@countrywide.com wrote:
> 
> Glenn,
> 
> Could you post the source code?  Thanks.

I've attached it, it's probably a little big for the list.

> 
> "James H. H. Lampert" wrote:
> >
> > Glenn Holmer wrote:
> > > > How do you list the members in a file?
> > >
> > > Thanks, but what I'm looking for is how to do it in Java... :)
> > > Should I run one of those CL commands and examine the output, or
> > > is there a simpler way using Toolbox classes?
> >
> > Dear Mr. Holmer:
> >
> > There's an OPM system API for that. I haven't called it from Java, but I
> > have from C and RPG. If you can call an OPM API, and retrieve the
> > results from a *USRSPC, you've got it.
> 
> Yup, it's QUSLMBR (and QUSRTVUS to read the contents of the user space).
> IBM support turned me on to this today, it's done using PCML to directly
> call an OS/400 API from a Java program.  *Extremely* cool.
> 
> If anybody wants to see the source code for the test program I wrote,
> just ask.

-- 
____________________________________________________________
Glenn Holmer                          gholmer@weycogroup.com
Programmer/Analyst                       phone: 414.908.1809
Weyco Group, Inc.                          fax: 414.908.1601
/**************************************************************************
  ListMembers.java -- list members in an AS/400 file by directly calling
  OS/400 APIs with PCML.  See also ListMembers.pcml.
 **************************************************************************/

import com.ibm.as400.access.*;
import com.ibm.as400.data.*;
import java.util.*;

/**
 * A program that retrieves a list of the members in an AS/400 file.
 * Uses PCML to make direct OS/400 API calls.
 * @author Glenn Holmer &copy;Weyco Group, Inc. 2001
 */
public class ListMembers {
  ProgramCallDocument pcml;
  
  /**
   * Constructor.  Does everything.
   */
  public ListMembers() {
    AS400 weyco400;
    Object o;
    int ListOffset = 0, ListEntries = 0, i, j;
    Vector MemberNames;
    Enumeration enum;

    System.out.println("\nListMembers.java -- lists members in file "
                     + "SHADOW/RMIMETHODS using PCML.\n"); 
    
    // connect to AS/400 and create PCML object
    try {    
      System.out.println("connecting to office AS/400...");
      weyco400 = new AS400("weyco400", "java", "java");
      System.out.println("creating PCML object...");
      pcml = new ProgramCallDocument(weyco400, "ListMembers");
    } catch (PcmlException pe) {
      System.out.println(pe.getLocalizedMessage());
      pe.printStackTrace();
      System.out.println("Your pathetic attempt at PCML died horribly.");
      System.exit(1);
    }
      
    // call OS/400 API to get list of file members
    System.out.println("calling QUSLMBR from OS/400...");
    if (!callPCML("quslmbr")) {
      System.exit(1);
    }      
  
    // retrieve output from above (contained in user space object)
    System.out.println("retrieving user space data...");
    try {
      System.out.println("step 1: get offset to list data");
      pcml.setValue("qusrtvus1.StartPos", new Integer(125));
      if (!callPCML("qusrtvus1")) {
        System.exit(1);
      } else {      
        o = pcml.getValue("qusrtvus1.Receiver");
        ListOffset = ((Integer)o).intValue();
        System.out.println("list offset is " + ListOffset);
      }
      
      System.out.println("step 2: get number of list entries");
      pcml.setValue("qusrtvus1.StartPos", new Integer(133));
      if (!callPCML("qusrtvus1")) {
        System.exit(1);
      } else {      
        o = pcml.getValue("qusrtvus1.Receiver");
        ListEntries = ((Integer)o).intValue();
        System.out.println("number of list entries is " + ListEntries);
      }
      
      // We know from the API docs that the length of an entry in 
      // format MBRL0100 is 10, so we can save ourselves a third call
      // and go straight to getting the member list:      
      System.out.println("step 3: get member names into Vector");
      MemberNames = new Vector();
      for (i = ListOffset, j = 0; j < ListEntries; i += 10, j++) {
        pcml.setValue("qusrtvus2.StartPos", new Integer(i));
        if (!callPCML("qusrtvus2")) {
          System.exit(1);
        } else {
          o = pcml.getValue("qusrtvus2.Receiver");
          MemberNames.addElement(o);
        }
      }
      for (enum = MemberNames.elements(); enum.hasMoreElements(); ) {
        System.out.println("member: " + (String)enum.nextElement());
      }
    } catch (PcmlException pe) {
      System.out.println(pe.getLocalizedMessage());
      pe.printStackTrace();
      System.out.println("Your pathetic attempt at PCML died horribly.");
      System.exit(1);
    }
    
    System.exit(0);
  }
  
  /**
   * Call program described in PCML file.
   * @param  ProgramName The program name tag in the PCML file.  Note that
   *         this is not necessarily the actual program name.
   * @return A boolean value representing success/failure.
   */
  private boolean callPCML(String ProgramName) {
    boolean rc;
    AS400Message[] msgs;
    int i;
    
    try {
      rc = pcml.callProgram(ProgramName);
      if (rc == false) {
        System.out.println("oops, error messages should follow:");
        msgs = pcml.getMessageList(ProgramName);
        for (i = 0; i < msgs.length; i++) {
          System.out.println(msgs[i].getID() + ": " + msgs[i].getText());
        }
        return rc;
      }  
    } catch (PcmlException pe) {
      System.out.println(pe.getLocalizedMessage());
      pe.printStackTrace();
      System.out.println("Your pathetic attempt at PCML died horribly.");
      return false;
    }
    return true;
  }
  
  /**
   * Program entry point.
   */
  public static void main(String argv[]) {
    new ListMembers();
  }
}

<pcml version="1.0">

  <!-- PCML source for OS/400 API calls made from ListMembers.java -->
  
  <!-- First two calls to QUSRTVUS: first call gets offset to list,
       second gets number of entries. -->
  <program name="qusrtvus1" path="/QSYS.LIB/QUSRTVUS.PGM">
    <data name="UserSpace"  type="char" length="20" usage="input" 
          init="USLMBR    SHADOW"/>
    <data name="StartPos"   type="int"  length="4"  usage="input"/>
    <data name="Length"     type="int"  length="4"  usage="input"
          init="4"/>
    <data name="Receiver"   type="int"  length="4"  usage="output"/>
  </program>

  <!-- Third and subsequent calls to QUSRTVUS: get member names 
       in a loop. -->
  <program name="qusrtvus2" path="/QSYS.LIB/QUSRTVUS.PGM">
    <data name="UserSpace"  type="char" length="20" usage="input" 
          init="USLMBR    SHADOW"/>
    <data name="StartPos"   type="int"  length="4"  usage="input"/>
    <data name="Length"     type="int"  length="4"  usage="input"
          init="10"/>
    <data name="Receiver"   type="char" length="10" usage="output"/>
  </program>
  
  <!-- QUSLMBR returns output to a user space and does not need 
       a receiver: -->  
  <program name="quslmbr"   path="/QSYS.LIB/QUSLMBR.PGM">
    <data name="UserSpace"  type="char" length="20" usage="input" 
          init="USLMBR    SHADOW"/>
    <data name="Format"     type="char" length="8"  usage="input"
          init="MBRL0100"/>
    <data name="FileName"   type="char" length="20" usage="input"
          init="RMIMETHLOGSHADOW    "/>
    <data name="MemberName" type="char" length="10" usage="input"
          init="*ALL      "/>
    <data name="Override"   type="char" length="1"  usage="input"
          init="0"/>
  </program>
</pcml>


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.