ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

How to catch return value from paramter we pass from CL/CLE through Java in Qshell

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

  • How to catch return value from paramter we pass from CL/CLE through Java in Qshell

    Hello Java & AS/400 Expert..

    I make small application from CL called java with Qshell (QSH).
    java will accept 2 paramter which is passed from CL, and calculate it.
    example : CL passed 2 parameter , e.g &PARM1 ='2' and &PARM2='0' to Java , then java will process with formula : strResult=&PARM1 *100 ,
    my question , How CL catch strResult (java variable) and assign it value to &PARM2
    bellow I include snippet code both CL ana java code

    CL code (CALCULATE.CLP) :
    Code:
    PGM                                                                     
                 DCL        VAR(&PARM1) TYPE(*CHAR) LEN(1) VALUE('2')       
                 DCL        VAR(&PARM2) TYPE(*CHAR) LEN(5) VALUE('0')       
                 DCL        VAR(&JAVA) TYPE(*CHAR) LEN(255)                 
                                                                            
                 CHGVAR     VAR(&JAVA) VALUE('java example.Calculate ' +    
                              *CAT &PARM1 *CAT ' ' *CAT &PARM2)           
                                                                            
                                                                            
                 CHGCURDIR  DIR('/home/sh30')                               
                 CHKOBJ     OBJ(QTEMP/DIRLIST) OBJTYPE(*FILE)               
                 MONMSG     MSGID(CPF0000) EXEC(DO)                         
                                                                            
                 CRTPF QTEMP/DIRLIST RCDLEN(5000)                           
                 ENDDO                                                      
                                                                            
                 OVRDBF FILE(STDOUT) TOFILE(QTEMP/DIRLIST)                  
                 QSH        CMD(&JAVA)                                      
              DLTOVR FILE(STDOUT)   
    ENDPGM
    java Code (Calculate.java)

    Code:
    package example;
    
    /**
     * File name   : Calculate.java
     * @author wahyu komara
     *Created Date : Nov 26, 2010  
     */
    public class Calculate {
    	private int result;
    	public Calculate(String[] strArgs){
    		result=Integer.parseInt(strArgs[0]) *100;
    	}
    public int getResult() {
    		return result;
    	}
    	public void setResult(int result) {
    		this.result = result;
    	}
    public static void main(String args[]){
    	Calculate calculate=new Calculate(args);
    	args[1]=""+calculate.getResult();
    	System.out.println(args[1]);
    
    }
    }
    when I debug CL, the value of &PARM2 doesn't change yet....still remain '0 '

    any respond, and comment is highly appreciated


    Regards,


    Wahyu Komara

  • #2
    Re: How to catch return value from paramter we pass from CL/CLE through Java in Qshel

    The parameters to a Java method are always pass by value. If the parameter is an object then the value is the object reference which means you have the same object referenced twice, or more. In most cases if you pass an object in to a method and change it then the calling method will also see the change, since they both have references to the same object. In the case of the main method it is different because the caller of the main method is outside the scope of the program.

    Running the program from QShell like this could work if your program was self contained. If for instance you gave it a couple of strings and it then generated a PDF or XLS and writes it to a particular IFS location then that could work. If on the other hand you want to call the code like you would a service program in RPG then you need a different tact.

    You might like to have a read of these articles.

    Ben

    Comment


    • #3
      Re: How to catch return value from paramter we pass from CL/CLE through Java in Qshel

      Yes Ben, My program is intended to make PDF File from AS/400 Report Spool, after java convert the spool into PDF then sent to particular email.
      when the report creation is processed I need to get report PDF filename (available from java variable name) in order to display it in Screen DSPF,
      so user notes generated report name and suited with email delivered.

      I have read the link you gave, but I still confuse , may be I need more practice and explore
      Ok, thank you for your help..

      Comment


      • #4
        Re: How to catch return value from paramter we pass from CL/CLE through Java in Qshel

        The links show you how to hook into Java code from RPG without using the main method. You could create a class that has methods something like this:

        PHP Code:
        public class PDFGen
        {
        public 
        PDFGen()
        {
        // Use the constructor from your RPG program to create a PDFGen object
        }

        public 
        void setContent(String content)
        {
        // You can call methods to pass in content to your created PDFGen object
        }

        public 
        String getIFSLocation()
        {
        // And you can retrieve information by calling methods too!
        }

        Ben

        Comment

        Working...
        X