Link to home
Start Free TrialLog in
Avatar of kingasa
kingasa

asked on

AS/400 ToolBox - com.ibm.as400.access.AS400 class

Hello

In a java program I'm trying to create an AS400 object using the toolBox class's.
In my program I have a java.sql.Connection Object to my AS/400.

making an instance of the AS400 class will open a socket to my AS/400 computer.
the thing is that I already have a Connection to my AS/400.

so my Q is how can I use my current Conection instance to the AS/400 when I'm creating the AS400 instance, because I don't want to create one more socket.


    ASA.
Avatar of bhagawatula
bhagawatula

Hi,
From your question I understand that, u have been through the following ways
of establishing a connection to a 400.

Method 1:
                AS400 as400 = new AS400(System, User, Password);

Method 2:
                java.sql.Connection connection =
DriverManager.getConnection("jdbc:as400://" + System, User, Password);


The  question is that, where exactly you are being forced to use the AS400
Class, so that a second socket connection will be established. Can u please explain the requirement.

Is it something like, you want to run an RPG Program(batch) or access
Message Queue etc.,

e.g. In case, if you want to call an RPG Program or any batch command in the
AS400, you have to use only the AS400 class i guess.

Here, I have given a wrapper for Program Call, which basically accepts the
authority, library name, Program Name to be called. Constructors are
overloaded, one for with parameters and without parameters.

Create a sepatate program as follows.Have this as an separate program.


import com.ibm.as400.access.*;

class pgmCall {
      boolean parm;
      String Lib,Pgm;
      AS400 sys;
      ProgramParameter[] Pgmparm;
      public pgmCall(AS400 System,String Library, String Program)
            {
            sys=System;
            Lib=Library;
            Pgm=Program;
            parm=false;
            pgmOpen();
            }
      public pgmCall(AS400 System,String Library, String
Program,ProgramParameter[] Pparm)
            {
            sys=System;
            Lib=Library;
            Pgm=Program;
            Pgmparm=Pparm;
            parm=true;
            pgmOpen();
            }

      void pgmOpen()
      {
      try {
            QSYSObjectPathName pPath = new
QSYSObjectPathName(Lib,Pgm,"PGM");
            ProgramCall pgm = new ProgramCall(sys);
            if(parm)
                  pgm.setProgram(pPath.getPath(),Pgmparm);
            else
                  pgm.setProgram(pPath.getPath());

            System.out.println("Pgm.run() to be run");

               if (pgm.run()!=true)
               {
            System.out.println("Pgm.run() not true");
               }
            else
             {
             }
            System.out.println("Pgm.run() over");
          }
          catch(AS400SecurityException ee)
            {
        System.out.println("pgmCall :"+ ee);
        System.exit(0);
            }

      catch (Exception e)
            {
        System.out.println(e);
        System.exit(0);
            }

    }

public      ProgramParameter[] returnParam()
      {
            return Pgmparm;
      }
}





In any Program, whereever you want to call a Program, you can just code the
following way.



public class RPT extends HttpServlet
{

      AS400 as400;
      pgmCall DAILYSTAT;
 
        try
        {
            DAILYSTAT      = new pgmCall(as400,"TURBO","DAILY_STAT");
/*
as400 is the connection
TURBO is the library name
DAILY_STAT is the Program Name
*/
        }
      catch(Exception Exception2)
            {
            }

}

If the above, does not meet your questions please explain me clearly about
your requirement so that i can try to answer your question precisely.









Hi,
I am submitting mu comment as answer as I did not get any responce from you .

From your question I understand that, u have been through the following ways
of establishing a connection to a 400.

Method 1:
                AS400 as400 = new AS400(System, User, Password);

Method 2:
                java.sql.Connection connection =
DriverManager.getConnection("jdbc:as400://" + System, User, Password);


The  question is that, where exactly you are being forced to use the AS400
Class, so that a second socket connection will be established. Can u please explain the requirement.

Is it something like, you want to run an RPG Program(batch) or access
Message Queue etc.,

e.g. In case, if you want to call an RPG Program or any batch command in the
AS400, you have to use only the AS400 class i guess.

Here, I have given a wrapper for Program Call, which basically accepts the
authority, library name, Program Name to be called. Constructors are
overloaded, one for with parameters and without parameters.

Create a sepatate program as follows.Have this as an separate program.


import com.ibm.as400.access.*;

class pgmCall {
boolean parm;
String Lib,Pgm;
AS400 sys;
ProgramParameter[] Pgmparm;
public pgmCall(AS400 System,String Library, String Program)
{
sys=System;
Lib=Library;
Pgm=Program;
parm=false;
pgmOpen();
}
public pgmCall(AS400 System,String Library, String
Program,ProgramParameter[] Pparm)
{
sys=System;
Lib=Library;
Pgm=Program;
Pgmparm=Pparm;
parm=true;
pgmOpen();
}

void pgmOpen()
{
try {
QSYSObjectPathName pPath = new
QSYSObjectPathName(Lib,Pgm,"PGM");
ProgramCall pgm = new ProgramCall(sys);
if(parm)
pgm.setProgram(pPath.getPath(),Pgmparm);
else
pgm.setProgram(pPath.getPath());

System.out.println("Pgm.run() to be run");

         if (pgm.run()!=true)
         {
System.out.println("Pgm.run() not true");
         }
else
{
}
System.out.println("Pgm.run() over");
     }
     catch(AS400SecurityException ee)
       {
        System.out.println("pgmCall :"+ ee);
        System.exit(0);
       }

catch (Exception e)
       {
        System.out.println(e);
        System.exit(0);
       }

    }

public ProgramParameter[] returnParam()
{
return Pgmparm;
}
}





In any Program, whereever you want to call a Program, you can just code the
following way.



public class RPT extends HttpServlet
{

AS400 as400;
pgmCall DAILYSTAT;
 
        try
        {
DAILYSTAT      = new pgmCall(as400,"TURBO","DAILY_STAT");
/*
as400 is the connection
TURBO is the library name
DAILY_STAT is the Program Name
*/
        }
catch(Exception Exception2)
{
}

}

If the above, does not meet your questions please explain me clearly about
your requirement so that i can try to answer your question precisely.




 
Avatar of kingasa

ASKER

bhagawatula ,

All I want to do is excute the CLRPFM command on the AS/400 using the CommandCall class from the ToolBox.




    ASA.  

bhagawatula changed the proposed answer to a comment
ASKER CERTIFIED SOLUTION
Avatar of bhagawatula
bhagawatula

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kingasa

ASKER

Answer accepted