ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Receiving collection object from java

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

  • Receiving collection object from java

    Hi

    Please help me out in receiving collection object from java stored procedure. The length of collection is not fixed. it depends on data in some other database.

    Regards
    Raj
    Regards
    Rajesh

  • #2
    Re: Receiving collection object from java

    Need a little more info to help you out on this one. What language is receiveing the collection object? What are you trying to do? A bit of code would help.
    Last edited by kpmac; September 7, 2006, 06:36 PM.
    Predictions are usually difficult, especially about the future. ~Yogi Berra

    Vertical Software Systems
    VSS.biz

    Comment


    • #3
      Re: Receiving collection object from java

      Originally posted by kpmac View Post
      Need a little more info to help you out on this one. What language is receiveing the collection object? What are you trying to do? A bit of code would help.
      In RPGLE only.

      * Call Java stored procedure
      C/EXEC SQL CALL DD1110JY(:id, :data)
      C/END-EXEC

      The input parameter is :id, output parameter to receive Collection object is :data

      Thanks & Regards
      Raj
      Regards
      Rajesh

      Comment


      • #4
        Re: Receiving collection object from java

        Hi Rajesh ....

        Since u r calling java program to receive collecion object, there must be a way how you are going to handle the received collection object in your SQLRPGLE code.

        So whats your plan after receving the collections object. Depending on that we can minimize the problem and will look for solution....
        Thanks,
        Giri

        Comment


        • #5
          Re: Receiving collection object from java

          The returned collection object contains Data. In the program just we need to print the data from the collection object
          Regards
          Rajesh

          Comment


          • #6
            Re: Receiving collection object from java

            OK, I think the easiest way to get the data into an rpg program is to create a bean that breaks your "collection data" into its objects. Then prototype the beans accessor methods to get at the specific "data".

            EXAMPLE
            PHP Code:

            package tools
            ;

            import java.util.ArrayList;
            import java.util.Collection;
            import java.util.Iterator;

            /**
             * @author KpMac
             *
             */
            public class Person {

                private 
            Iterator iterator null;

                private 
            String firstName;

                private 
            String lastName;

                public 
            Person() {
                
                }

                public 
            Person(String firstNameString lastName) {
                    
            this.firstName firstName;
                    
            this.lastName lastName;
                }

                public 
            String getFirstName() {
                    return 
            firstName;
                }

                public 
            String getLastName() {
                    return 
            lastName;
                }

                public 
            boolean hasNext() {
                    
            boolean hasPeople false;
                    
            Person person null;
                                            
                    if(
            iterator==null){
                       
            iterator People.getPeople().iterator();
                    }

                    if (
            iterator.hasNext()){
                        
            person = (Personiterator.next();
                        
            hasPeople true;
                        
            this.firstName person.getFirstName();
                        
            this.lastName person.getLastName();
                    }
                    return 
            hasPeople;
                }

                public static 
            void main(String[] kpmac) {
                    
            Person person = new Person();
                    while (
            person.hasNext()) {
                        
            System.out.println(person.getFirstName() + " "
                                
            person.getLastName());
                    }
                }

            }

            class 
            People {    
                public static 
            Collection getPeople() {
                    
            ArrayList people = new ArrayList();
                    
            people.add(new Person("Kp""Mac"));
                    
            people.add(new Person("Jamie""F"));
                    
            people.add(new Person("FaSt","OnE"));
                    return 
            people;

                }

            and here are the RPG Prototypes
            PHP Code:
             *-------------------------------------------------------------------*
             *                           
            Prototypes                              *
             *-------------------------------------------------------------------*
             *                                                                    
            D crtPerson       PR              O   EXTPROC(*JAVA:                  
            D                                     'tools.Person':*CONSTRUCTOR)    
            D getFirstName...                                                     
            D                 PR              O   EXTPROC(*JAVA:                  
            D                                            'tools.Person':          
            D                                             'getFirstName')         
            D                                     CLASS(*JAVA:'java.lang.String'
            D getLastName...                                                      
            D                 PR              O   EXTPROC(*JAVA:                  
            D                                            'tools.Person':          
            D hasNext...                                                           
            D                 PR              N   EXTPROC(*JAVA:                   
            D                                            'tools.Person':           
            D                                             'hasNext')               
             *                                                                     
             *  
            Convert EBCIDIC to java.lang.String                                
             
            *                                                                     
            D cvtString       PR              O   EXTPROC(*JAVA:                   
            D                                             'java.lang.String':      
            D                                             *CONSTRUCTOR)            
            D                                     CLASS(*JAVA:'java.lang.String')  
            D RPGBytes                    3000A   Const varying                    
            D
            *                                                                     
             * 
            Converts ASCII TO EBCIDIC                                           
            D RPGStr          PR         32767A   Varying                          
            D                                     EXTPROC
            (*JAVA:                   
            D                                             'java.lang.String':      
            D                                             'getBytes')                    
            *                                                                    
            *-------------------------------------------------------------------*
            *                          
            Stand Alone                              *
            *-------------------------------------------------------------------*
            *                                                                    
            D p               S               O   CLASS(*JAVA:'tools.Person')      
            D firstName       S             10A   Inz                              
            D lastName        S             10A   Inz                              
            D name            S             20A   Varying Inz                          
            *                                                                    
            *=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=*
            *                             
            Main                                  *
            *=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=*
            *                                                                    
            /
            Free                                                                
                                                                                 
              p 
            crtPerson() ;                                                  
                                                                                 
              
            DoW hasNext) ;       
                                                                      
                
            firstName RPGStrgetFirstName) ) ;             
                
            lastName RPGStrgetLastName) ) ;               
                
            name = %TrimfirstName) + ' '  + %TrimlastName ) ; 
                
            Dsply name ;                                          
                                                                      
              
            EndDo;                                                  
                                                                      
              *
            InLr = *On;                                            
              Return;                                                 
             /
            End-Free                                                            
             
            *=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=* 
            Last edited by kpmac; September 22, 2006, 02:01 PM.
            Predictions are usually difficult, especially about the future. ~Yogi Berra

            Vertical Software Systems
            VSS.biz

            Comment

            Working...
            X