Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2000-03-19
6
Medium Priority
?
984 Views
Last Modified: 2010-05-18
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.
0
Comment
Question by:kingasa
  • 4
  • 2
6 Comments
 
LVL 1

Expert Comment

by:bhagawatula
ID: 2650635
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.








0
 
LVL 1

Expert Comment

by:bhagawatula
ID: 2655899

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.




 
0
 

Author Comment

by:kingasa
ID: 2657897
bhagawatula ,

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




    ASA.  

0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 1

Expert Comment

by:bhagawatula
ID: 2662533
bhagawatula changed the proposed answer to a comment
0
 
LVL 1

Accepted Solution

by:
bhagawatula earned 400 total points
ID: 2662538
import com.ibm.as400.access.*;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;

public class CMDCALLEXAMPLE extends HttpServlet
{

    AS400 as400;
    cmdCall Clrpfm;

    public CMDCALLEEXAMPLE()
    {
    }

    public void init(ServletConfig servletconfig)
        throws ServletException
    {
        super.init(servletconfig);
    }


    public void service(HttpServletRequest httpservletrequest,
HttpServletResponse httpservletresponse)
    {
        PrintWriter printwriter = null;
        HttpSession httpsession = null;
        Connection connection = null;
        ResultSet resultset = null;

        try
        {
            httpsession = httpservletrequest.getSession(true);
            httpservletresponse.setContentType("text/html");
            printwriter = httpservletresponse.getWriter();
            as400 = (AS400)httpsession.getValue("as400");
            connection = (Connection)httpsession.getValue("Connection");
        }
        catch(Exception Exception1)
        {
            printwriter.println("Session Object Retrieval Exception :" +
Exception1);
            printwriter.close();
            return;
        }

    public void CheckMandatoryEntry(String Opt)
    {

    try {
        Clrpfm = new cmdCall(as400,"CLRPFM LIBRARY/FILENAME");
        System.out.println("Batch Command Run Successfully");
            }
        catch(Exception Exception4)
        {
        System.out.println("Command Run Exception "+ Exception4);
        }
    }

}


---------------------------------------
Source Code for cmdCall
======================

import com.ibm.as400.access.*;

class cmdCall {

    String Str;
    AS400 sys;
    public cmdCall(AS400 System,String cmdStr) {
        sys=System;
        Str=cmdStr;
        pgmOpen();
        }

    void pgmOpen()  {
    try {
        CommandCall cmd=new CommandCall(sys);
        System.out.println(Str);
        cmd.run(Str);
            }
        catch(AS400SecurityException ee) {
            System.out.println("cmdCall :"+ ee);
            System.exit(0);
             }
    catch (Exception e)         {
            System.out.println("cmdCall1 :"+ e);
            System.exit(0);
            }
    }
}


0
 

Author Comment

by:kingasa
ID: 3487934
Answer accepted
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Steps to fix error: “Couldn’t mount the database that you specified. Specified database: HU-DB; Error code: An Active Manager operation fail”
Aerodynamic noise is the cause of the majority of the noise produced by helicopters. The inordinate amount of noise helicopters produce is a major problem in the both a military and civilian setting. To remedy this problem the use of an aerogel coat…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question