Thursday, October 31, 2013

Calling the Procedure in OAF


Calling the Procedure in OAF


Now we r going to learn about how to call the procedures in oaf page.

First Create the work space and project.

Create the AM.

Create the page and attach the AM.

Create one new region in the page of style messageComponentLayout.

Create two items of style messageTextInput and data type number.

Create one submit button.

The structure of the page looks like as follows.





Now we have to create one package and package body to call that in OAF page.

//Package Specification
//Addition of two numbers.

CREATE OR REPLACE PACKAGE APPS.proc_in_oaf AUTHID CURRENT_USER
IS
PROCEDURE addition
(   item1            IN      NUMBER, 
    item2            IN      NUMBER, 
    addition    OUT  NUMBER
);
END proc_in_oaf;


//Package Body
CREATE OR REPLACE PACKAGE BODY APPS.proc_in_oaf
IS
PROCEDURE addition 
(   item1          IN    NUMBER,
             item2          IN    NUMBER,
               addition  OUT NUMBER
)
IS

BEGIN

 addition  := item1 + item2;

END addition;

END proc_in_oaf;


After creating the procedure,

Create the method in the AMImpl.java file for calling the and executing the procedure.

        public String AddNumber(String item1,String item2)
    { OADBTransaction oadbtransaction = (OADBTransaction)getTransaction();
      OADBTransactionImpl oadbtransactionimpl = (OADBTransactionImpl)getTransaction();
     String retValues;
    StringBuffer str = "Begin proc_in_oaf.addition(:1,:2,:3); End;";
     
     OracleCallableStatement oraclecallablestatement =
      (OracleCallableStatement)oadbtransaction.createCallableStatement(str.toString(), 1);
     try{
      oraclecallablestatement.setFloat(1,  Float.parseFloat(item1)  );
      oraclecallablestatement.setFloat(2,  Float.parseFloat(item2) );
      oraclecallablestatement.registerOutParameter(3, Types.VARCHAR);
      oraclecallablestatement.execute();
                       
      retValues = oraclecallablestatement.getString(3);
     }
     catch(Exception e)
     {
      throw OAException.wrapperException(e);
     }
     return retValues;
    }



Next create one controller in the page .

And call the method in the processFormRequest.




//FOR Copy Paste

  public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processFormRequest(pageContext, webBean);
   
     
          OAApplicationModule am = pageContext.getApplicationModule(webBean);
               
           if (pageContext.getParameter("item3") != null)         
           {           
                Serializable[] parameters1 = { pageContext.getParameter("item1"),
                                        pageContext.getParameter("item2"),
                                                                           };
                              
            String retVals1 = (String)am.invokeMethod("AddNumber", parameters1);
            String message = "Sum:  " + retVals1;                    
            throw new OAException(message, OAException.INFORMATION);

         
          }

      }


This completes the project.

Run the page to see the output.




After click on ADD button it will give the addition of two numbers.



1 comment:

  1. Hi Patil, thanks for the article and I have one question here. Can you please tell me the difference between OADBTransaction and OADBTransactionImpl?

    ReplyDelete