ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Looking for examples

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Looking for examples

    Hi I'm a seasoned AS400 developer that is looking to add java to allow running programs from a web browser. Looking for some simple examples that will get me started in the right direction.

    thanks in advance,

    Robert

  • #2
    Re: Looking for examples

    Not sure what you're asking for. Do you want examples of Java web front ends that execute RPG programs on the back end?
    "Time passes, but sometimes it beats the <crap> out of you as it goes."

    Comment


    • #3
      Re: Looking for examples

      Originally posted by littlepd View Post
      Not sure what you're asking for. Do you want examples of Java web front ends that execute RPG programs on the back end?

      Yes Please... basically I want to create a web based front end that will ask for a date and a company and then run a RPG program.

      thanks so much!!!

      Comment


      • #4
        Re: Looking for examples

        Why java? Do it in RPG. www.easy400.net/cgidev2/start
        "Time passes, but sometimes it beats the <crap> out of you as it goes."

        Comment


        • #5
          Re: Looking for examples

          Sounds like PCML could be the thing for you.


          It does have its limitations. I probably wouldn't recommend it for building an entire as400 backed website as it doesn't have any concept of state i.e. session. It could be useful though if you have a separate website that needs to occasionally call an as400 program.

          Another option would be to create a stored procedure on the as400 and call this using JDBC.
          Ben

          Comment


          • #6
            Re: Looking for examples

            Originally posted by BenThurley View Post
            Sounds like PCML could be the thing for you.


            It does have its limitations. I probably wouldn't recommend it for building an entire as400 backed website as it doesn't have any concept of state i.e. session. It could be useful though if you have a separate website that needs to occasionally call an as400 program.

            Another option would be to create a stored procedure on the as400 and call this using JDBC.

            Actually Ben the java tool kit was what got me started thinking that I wanted to use Java to do this. the majority of our software is web based but runs on the iseries... there are a few programs that I'm creating that are more "batch" driven but require a few prompts to be entered to run them. I thought instead of people having to log into green screen why not make them web based.

            This article I believe is what I was looking for. The IBM reference books just don't get it.

            thanks!

            Robert

            Comment


            • #7
              Re: Looking for examples

              Ben,

              any idea why this isn't working for me?

              I keep getting this error <<<<<Could not find the main class: callapgm. Program will exit.>>>>>

              here is my PCML
              PHP Code:
              <pcml version="1.0">
              <
              program name="VAPBIP1" path="/QSYS.lib/VLAWOBJ.lib/VAPBIP1.PGM">
              <
              data name="company" type="char" length="4"
              usage="input"/>
              <
              data name="from_date" type="char" length="10"
              usage="input"/>
              <
              data name="to_date" type="char" length="10"
              usage="input"/>
              </
              program>
              </
              pcml>

              here is my "Copied" Java

              import com
              .ibm.as400.data.ProgramCallDocument;
              import com.ibm.as400.data.PcmlException;
              import com.ibm.as400.access.AS400;
              import com.ibm.as400.access.AS400Message;
              import java.math.BigDecimal;

              public class 
              callapgm
              {
                  
              // instance variables - replace the example below with your own
                  
              private int x;

                  
              /**
                   * Constructor for objects of class callapgm
                   */
                  
              public callapgm()
                  {
                      
                  }

                  public static 
              void main(String argv[])
                 {

                     
              // Create and instantiate an AS/400 Object
                     // If you do not enter a user id or password, you will be prompted for each
                     // AS400 sys = new  AS400("url of iSeries", "user id", "password");
                     
              System.out.println("Connecting to iSeries...");
                     
              AS400 sys = new  AS400();

                     
              // Create Data Objects
                     
              ProgramCallDocument pcml;                // com.ibm.as400.data.ProgramCallDocument
                     
              BigDecimal sum = new BigDecimal("0");    // RPG program variable
                     
              String comment;                          // RPG program variable
                     
              boolean rc false;                      // Return code for program call
                     
              String msgIdmsgText;                   // Messages returned from AS/400

                     
              try
                     {

                          
              // Instantiate the Objects (assign the variables)
                          
              pcml = new ProgramCallDocument(sys"callpgm");
                          
              pcml.setValue("program.parameter1", new String("100"));
                          
              pcml.setValue("program.parameter2", new String("01-01-2011"));
                          
              pcml.setValue("program.parameter3", new String("01-31-2011"));

                          
              // Debug statement...Use to view outbound and inbound parms if you need it
                          //com.ibm.as400.data.PcmlMessageLog.setTraceEnabled(true);

                          // Call the Program
                          
              System.out.println("Calling the program...");
                          
              rc pcml.callProgram("program");

                          
              // If return code is false, get messages from the iSeries
                          
              if(rc == false)
                          {
                              
              // Retrieve list of AS/400 messages
                              
              AS400Message[] msgs pcml.getMessageList("program");

                              
              // Loop through all messages and write them to standard output
                              
              for (int m 0msgs.lengthm++)
                              {
                                  
              msgId msgs[m].getID();
                                  
              msgText msgs[m].getText();
                                  
              System.out.println("    " msgId " - " msgText);
                              }
                              
              System.out.println("Call to PROGRAM failed. See messages listed above");
                              
              System.exit(0);
                          }

                          
              // Return code was true, call to PROGRAM succeeded - woo-hoo!

                          
              else
                          {
                              
              // Process the returned Data
                            //  sum = (BigDecimal)  pcml.getValue("program.sum");
                            //  comment = (String)  pcml.getValue("program.comment");
              //
                //              System.out.print("5" + " + " + "5.25" + " = " + sum);
                  //            System.out.print("\n");
                    //          System.out.print(comment);
                      //        System.exit(0);
                          
              }
                     }

                     catch (
              PcmlException e)
                     {
                          
              System.out.println(e.getLocalizedMessage());
                          
              e.printStackTrace();
                          
              System.out.println("Call to PROGRAM failed");
                          
              System.exit(0);
                     }

                     
              // Disconnect from AS/400
                     
              sys.disconnectAllServices();

                  }
                  
                  

              Comment


              • #8
                Re: Looking for examples

                Code:
                try
                {
                
                // Instantiate the Objects (assign the variables)
                pcml = new ProgramCallDocument(sys, "[COLOR="darkred"]YourPCMLname[/COLOR]");
                pcml.setValue("[COLOR="darkred"]VAPBIP1[/COLOR].[COLOR="darkred"]company[/COLOR]", new String("100"));
                pcml.setValue("[COLOR="darkred"]VAPBIP1[/COLOR].[COLOR="darkred"]from_date[/COLOR]", new String("01-01-2011"));
                pcml.setValue("[COLOR="darkred"]VAPBIP1[/COLOR].[COLOR="darkred"]to_date[/COLOR]", new String("01-31-2011"));
                
                // Debug statement...Use to view outbound and inbound parms if you need it
                //com.ibm.as400.data.PcmlMessageLog.setTraceEnabled( true);
                
                // Call the Program
                System.out.println("Calling the program...");
                rc = pcml.callProgram("[COLOR="darkred"]VAPBIP1[/COLOR]");
                
                / If return code is false, get messages from the iSeries
                if(rc == false)
                {
                // Retrieve list of AS/400 messages
                AS400Message[] msgs = pcml.getMessageList("[COLOR="darkred"]VAPBIP1[/COLOR]");

                Comment


                • #9
                  Re: Looking for examples

                  That didn't work... same error as before.

                  Comment


                  • #10
                    Re: Looking for examples

                    seems this is classpath issue, what tool you used? WDSC? RAD?

                    Comment


                    • #11
                      Re: Looking for examples

                      the sdk from oracle that includes netbeans

                      Comment


                      • #12
                        Re: Looking for examples

                        what does class path mean? I have put my jar file is a directory where I can run some of the netbeans examples... looking at the examples I don't see any different in them versus my little program.

                        this is what I get when I try mine.

                        C:\Program Files\Java\jdk1.6.0_24\jre\lib\ext>java -jar callpgm.jar
                        Exception in thread "main" java.lang.NoClassDefFoundError: com/ibm/as400/data/Pc
                        mlException
                        Caused by: java.lang.ClassNotFoundException: com.ibm.as400.data.PcmlException
                        at java.net.URLClassLoader$1.run(Unknown Source)
                        at java.security.AccessController.doPrivileged(Native Method)
                        at java.net.URLClassLoader.findClass(Unknown Source)
                        at java.lang.ClassLoader.loadClass(Unknown Source)
                        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
                        at java.lang.ClassLoader.loadClass(Unknown Source)
                        Could not find the main class: callpgm.Callpgm. Program will exit.

                        Comment


                        • #13
                          Re: Looking for examples

                          You may be well beyond this point by now, but:

                          Service-enabling i5/OS applications by using PCML, 2-step process
                          "Time passes, but sometimes it beats the <crap> out of you as it goes."

                          Comment


                          • #14
                            Re: Looking for examples

                            The exception, "java.lang.ClassNotFoundException: com.ibm.as400.data.PcmlException",
                            indicates that the JAR file containing your 'PCML connection' isn't in your classpath.
                            since you are using netbeans,
                            right click on the project > Properties > Libraries > Compile tab > Add JAR/Folder button
                            add jt400.jar & OK

                            Before build a jar file, right click on your source file (in your case callpgm.java) > Run File

                            show the exceptions now...

                            PS: If you use the WDSC or RAD, you can generate program call bean automatically for the given PCML file.
                            Then, you only have to invoke the generated class, something like this..
                            PHP Code:
                            VAPBIP1 vap = new VAPBIP1();
                            vap.setCOMPANY("ABC");
                            vap.setFROM_DATE("2010-10-15");
                            vap.setTO_DATE("2011-04-15");
                            vap.invoke();
                            vap.disconnect(); 

                            Comment


                            • #15
                              Re: Looking for examples

                              Okay.... this was very helpful!

                              I've got it working now within Netbeans... pretty slick actually... I've been able to change it around a bit to make it work on different programs and do things so that I know it's actually working.


                              then I do a build... and try to run it just from a command window... doesn't work ????


                              Here is what I get.

                              C:\jt400\lib>java -jar add2numbers.jar
                              Exception in thread "main" java.lang.NoClassDefFoundError: com/ibm/as400/data/Pc
                              mlException
                              Caused by: java.lang.ClassNotFoundException: com.ibm.as400.data.PcmlException
                              at java.net.URLClassLoader$1.run(Unknown Source)
                              at java.security.AccessController.doPrivileged(Native Method)
                              at java.net.URLClassLoader.findClass(Unknown Source)
                              at java.lang.ClassLoader.loadClass(Unknown Source)
                              at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
                              at java.lang.ClassLoader.loadClass(Unknown Source)
                              Could not find the main class: add2numbers. Program will exit.

                              C:\jt400\lib>


                              any thoughts on this? I've tried moving things around to different directories....

                              here is what my classpath looks like.



                              C:\jt400\lib>echo %classpath%
                              C:\Program Files\Java\jdk1.6.0_24\jre\lib\ext;C:\jt400\lib

                              C:\jt400\lib>echo %path%
                              C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32 \WBEM;C:\WINDOWS\system32\Wind
                              owsPowerShell\v1.0;C:\Program Files\Intel\DMIX;C:\Program Files\NTRU Cryptosyste
                              ms\NTRU TCG Software Stack\bin\;C:\Program Files\Wave Systems Corp\Gemalto\Acces
                              s Client\v5\;C:\PROGRA~1\IBM\CLIENT~1;C:\PROGRA~1\IB M\CLIENT~1\Shared;C:\PROGRA~
                              1\IBM\CLIENT~1\Emulator;C:\jt400\lib;C:\Program Files\Java\jdk1.6.0_24\bin;

                              C:\jt400\lib>



                              Originally posted by dhanuxp View Post
                              The exception, "java.lang.ClassNotFoundException: com.ibm.as400.data.PcmlException",
                              indicates that the JAR file containing your 'PCML connection' isn't in your classpath.
                              since you are using netbeans,
                              right click on the project > Properties > Libraries > Compile tab > Add JAR/Folder button
                              add jt400.jar & OK

                              Before build a jar file, right click on your source file (in your case callpgm.java) > Run File

                              show the exceptions now...

                              PS: If you use the WDSC or RAD, you can generate program call bean automatically for the given PCML file.
                              Then, you only have to invoke the generated class, something like this..
                              PHP Code:
                              VAPBIP1 vap = new VAPBIP1();
                              vap.setCOMPANY("ABC");
                              vap.setFROM_DATE("2010-10-15");
                              vap.setTO_DATE("2011-04-15");
                              vap.invoke();
                              vap.disconnect(); 

                              Comment

                              Working...
                              X