Solved

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

Posted on 2000-03-19
6
934 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Owning a franchise can be the dream of a lifetime. It provides a chance for economic growth. You can be as successful as you want.  To make your franchise successful, you need to market it successfully. Here are six of the best marketing strategies …
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 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

19 Experts available now in Live!

Get 1:1 Help Now