Solved

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

Posted on 2000-03-19
6
944 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 1

Expert Comment

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

Accepted Solution

by:
bhagawatula earned 100 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Employees depend heavily on their PCs, and new threats like ransomware make it even more critical to protect their important data.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now