You are on page 1of 14

Useful Coding

1) How to bounce Apache in 11i and R12
In 11i:
cd $COMMON_TOP/admin/scripts
ls –l
cd SID stop start
For R12 :
cd $COMMON_TOP/admin/scripts
ls –l stop // Bounce Apache stop //Bounce OC4J start start
2) How to call a concurrent program
String progAppl = "AR";
String progName = "TEST"; //Request Set Name
Vector test = new Vector();
ConcurrentRequest cr = new ConcurrentRequest(pConncection);
int reqId = cr.submitRequest(progAppl, progName,desc,null, false, test);
3) How to call Dialog page
String name = "Description";
MessageToken[] tokens = { new MessageToken("DESC",name) };
OAException confirmMessage = new

getParameter(SOURCE_PARAM). "inputTest"). LOV_TEXT. webBean. null. 4) How to capture LOV results returned from LOV in coding if(pagecontext. lovInput.get("<LovFieldName>"). new Integer(20001)).equals(lovInputSourceId)) { Hashtable lovResults = pageContext.isLovEvent() { String lovInputSourceId = pageContext.jsp? page=/sapient/oracle/apps/pa/projupdate/webui/sapeEAProjectUpdatePG&re tainAM=Y". if ("<LovItemId>".setAttributeValue(REGION_CODE. 0).redirectToDialogPage(dialogPage). lovInput.jsp? page=/sapient/oracle/apps/pa/projupdate/webui/ProjectListPG"). // Specify the LOV region definition.addIndexedChild(lovInput). } } } 5) How to create LOV programmatically (OAMessageLovInputBean)createWebBean(pageContext."OA.null."OA. pageContext.OADialogPage dialogPage = new OADialogPage(OAException.getLovResultsFromSession (lovInputSourceId).confirmMessage. if(lovResults!=null) { String value =(String)lovResults. . // Specify the application id of the base page. // Specify the path to the base page. lovInput.WARNING.setAttributeValue(REGION_APPLICATION_ID. "/oracle/apps/dem/webui/Basic").setLovRegion("/oracle/apps/fnd/framework/toolbox/tutorial/webui/ Employee sLovRN".

// base page item "Empname".. The leftmost tab should be added first. 8. 6.addLovRelations(pageContext.Remember to specify Prompt values for each tab submenu.entry.ap. 10) How to open a pop window through javascript.oie. "inputTest". pageContext. 4. lovInput." 5. "start now before query. 6) How to create HTML Tabs on pages. 7. "inputTest". Create a menu of type "Home Page. In the page specify the name of the Home Menu in application menu property. // direction LOV_REQUIRED_NO). Create a menu of type "HTML Tab" for each tab you want to display. for example). // direction LOV_REQUIRED_NO). Add your "Home Page" menu to your responsibility menu. Add the tab menus in your desired display sequence from left to right. 3. .accounting. 9) How to enable debugging.// Validation should be enabled for LOVs unless it's essential for the field to allow // a partial value (in a "Search" region. Make sure your user has access to this responsibility before you try to test the menu. // lov item LOV_CRITERIA. lovInput. Create a function for each page that you want to display.writeDiagnostics("oracle. 1).setUnvalidated(false). // Note that you must call this method after you add the messageLovInput item // to the web bean hierarchy. 1.webui. // Configure the LOV mappings.E xpenseAllocationsPageCO".".apps. Add the tab submenus to the "Home Page" menu. // lov item LOV_RESULT.addLovRelations(pageContext. // base page item "Empname".. 2. Do not specify any Prompt values. These values display as the tab text. Add each function to its corresponding tab menu. lovInput.

jsp? page=/sapient/oracle/apps/pa/clientupdate/webui/sapeEAClientListPG'}.Remember define it as global table type and not inside package specification.if(in put==false){void(0). .Do you wish to continue?'). because in that case our jdbc code would not be to find this object type.col3 Number).Remember define it as global object type and not inside package specification.}. 2)Define table of object u have defined above which u need to use in ur pl/sql procedure of some pkg.col2 Date. 1)Define Object with the same structure as your table of records u need to use in ur pl/sql procedureof some pkg.location='OA.Take a simple button: on destination url call javascript as javascript:input=confirm('Your Changes will be lost. because in that case our jdbc code would not be to find this object type. / ************************************************************* *****************/ /*The Script used to create Object type in this example is as follows:*******/ / ************************************************************* *****************/ create or replace type rectype as object(col1 varchar2(10). / ************************************************************* *****************/ /*The Script used to create table of Object type is as follows:*******/ / ************************************************************* *****************/ create or replace type rectab as table of rectype.if(input==true){window. 11) How to pass table of records to java.

col1. iorec(i). end as follows:*******/ / ************************************************************* *****************/ create or replace package body ioStructArray as procedure testproc(iorec in rectab.orec out rectab) is begin /*see how to loop and assign values*/ for i in 1.col1 := orec(i). end testproc.. end ioStructArray.iorec.3)Defining package specification and procedure definition / ************************************************************* ********************/ /*The Script used to create package specification in this eg. / 5)Getting connection object in JDBC Code : . end loop.col2 := orec(i).is as follows:*******/ / ************************************************************* *****************/ create or replace package ioStructArray as procedure testproc(iorec in rectab.orec out rectab).col2. / 4)Defining package body and procedure / ************************************************************* ********************/ /*The Script used to create package specification in this eg.count loop iorec(i).

driver.Here is the Code: //imports import oracle.getJdbcConnection().getConnection ("jdbc:oracle:oci8:@S692815. import oracle.apps.server. OracleConnection conn = (OracleConnection)oadbtransactionimpl. consider a simple scenario where we have a XXVO in AM and I have to pass all VO rows data to the pl/sql procedure we just created and then receieve a table of data back and then based on it values do something in AM. //Defining variables //oracle.jdbc.fnd.driver.apps.getJdbcConnection().OADBTransaction. 6)If writing in AM in OAF page.sql.WORLD". Public void arryToPLSQL() { //Getting Db connection OADBTransactionImpl oadbtransactionimpl = (OADBTransactionImpl)getOADBTransaction(). code to get connection: OADBTransactionImpl oadbtransactionimpl = (OADBTransactionImpl)getOADBTransaction().registerDriver(new oracle.framework. OracleConnection conn = (OracleConnection)oadbtransactionimpl.jdbc.fnd.sql. 7)Lets. import oracle.driver. import oracle. . "scott".*.framework. // Connect to the database Connection conn=DriverManager.server. "tiger").ARRAY we will use as out parameter from the package //and will store pl/sql table ARRAY message_display = null.OracleConnection.OADBTransactionImpl.OracleCallableStatement.jdbc. import oracle.OracleDriver()).//Getting db connection in a jdbc DriverManager.

row = (XXVORowImpl)XXVO. } catch (Exception e) { throw OAException.first().wrapperException(e). voRowStruct = StructDescriptor. try { //initializing object types in java. StructDescriptor voRowStruct = null.conn). populateObjectArraylist(row. } . //Oracle callable statement used to execute procedure OracleCallableStatement cStmt=null.arow).createDescriptor("RECTYPE".conn). //ArrayDescriptor >> Use to describe pl/sql table //as Array of objects in java ArrayDescriptor arrydesc = null. } for(XXVORowImpl row = (XXVORowImpl)XXVO. //Input array to pl/sql procedure ARRAY p_message_list = null. row!=null.//ArrayList to store object of type struct ArrayList arow= new ArrayList(). arrydesc = { //We have made this method to create struct arraylist // from which we will make ARRAY //the reason being in java ARRAY length cannot be dynamic //see the method defination below. //StructDescriptor >> use to describe pl/sql object //type in java.createDescriptor("RECTAB".

registerOutParameter(2. System. //You can typecast back these objects to java object type .i{ obRows[i]=(STRUCT)arow. for(int i=0.get(i).out.sql. i++) { oracle.datum array //which will typecast the object types Datum[] arrMessage = message_display. cStmt.out.length. i < arrMessage.size()].setArray(1.execute().getAttributes().conn. //getting Array back message_display = cStmt.ARRAY.//make array from arraylist STRUCT [] obRows= new STRUCT[arow.println("a [0 ] >>attribute1=" + a[0]). System. System. //Getting sql data types in oracle.getOracleArray()."RECTAB").testproc(:1.sql. cStmt.prepareCall("{CALL ioStructArray. Object[] a = os.println("a [2 ] >>attribute3=" + a[2]).println("a [1 ] >>attribute2=" + a[1]).obRows).getARRAY(2).p_message_list). cStmt. } catch (Exception e) { throw OAException.sql.out. } //jdbc code to execute pl/sql procedure try { cStmt =(OracleCallableStatement)conn. //getting data and printing it for (int i = 0. } try { p_message_list = new ARRAY(arrydesc.OracleTypes.wrapperException(e).STRUCT os = (oracle.:2)}").STRUCT)arrMessage[i].

String attr1 = null. } catch (Exception e) { } . conn. arow. attribMessage). } } /*Our custom method which will populate arraylist with struct object type */ public void populateObjectArraylist( XXVORowImpl row. try { STRUCT loadedStructTime = new STRUCT(voRowStruct.att2 and attr 3 //Putting values in object array attribMessage[0]=attr1.StructDescriptor voRowStruct . attribMessage[2]=attr3. Date attr2 = null. Number attr3 = null. attribMessage[1]=attr2. //Get value from Vo row and put in attr1.add(loadedStructTime).} } catch (Exception e1) { throw OAException.wrapperException(e1). ArrayList arow) { Object[] attribMessage = new Object[3].

insNarvaroCs. :13. try { insNarvaroCs. getCommentText()).PLSQL_INDEX_TABLE stmt.setNUMBER(13. :20. :16.setregisteroutparameter(1.setString(4. getProjectId()). OADBTransaction trans = getOADBTransaction(). :7.setString(7. getTaskId()). getHoursTuesday()). : 4.OracleTypes. insNarvaroCs."." + ":11. getDateMonday()). :14. String insStmnt = "BEGIN " + "xxotl_handle_timestore. :19.setNUMBER(11. :5.setString(5. insNarvaroCs. insNarvaroCs.setDATE(10. :9. OracleCallableStatement insNarvaroCs = (OracleCallableStatement)trans. :22). getHoursWednesday()). insNarvaroCs. insNarvaroCs.setString(1.PLSQL_INDEX_TABLE). :3. :6. getDateWednesday()). .setDATE(8. ArrayList al = new ArrayList(). 1). insNarvaroCs. :2.setNUMBER(2.setString(3. :12. getExpenditureType()). insNarvaroCs.setString(6.setNUMBER(9. getTcCommentText()).createCallableStatement(insStmnt. :17.setDATE(12. "SUBMIT"). getHoursMonday()). :15. ====================================================== ====================== protected void insertRow() { String OutError = "". insNarvaroCs. getPersonId()). :18. :8. :21. getDateTuesday()). :10.create_narvaro_timecard(:1.} ====================================================== ===================== However for using pl/sql tables you can use OracleTypes. insNarvaroCs. insNarvaroCs. " + "END. insNarvaroCs.

println("Column:" + a[0] + " Value:" + a[1]). getDateFriday()).ARRAY.setDATE(16.STRUCT os = (oracle. } insNarvaroCs. insNarvaroCs.sql. getDateThursday()). for (int i = 0.wrapperException(sqle). al. getDateSaturday()).setNUMBER(17.setDATE(18.checkErrors(trans).setNUMBER(19.checkErrors as per PLSQL API standards OAExceptionUtils.sql. i++) { oracle.setNUMBER(21. } if (OutError != null) { OAException. ARRAY arrayError = insNarvaroCs.length. getDateSunday()). getHoursSaturday()). insNarvaroCs.raiseBundledOAException(al).close(). getHoursSunday()).ERROR)). OracleTypes. insNarvaroCs. // OAExceptionUtils. getHoursThursday()). insNarvaroCs.execute(). } catch(SQLException sqle){ try { insNarvaroCs. getHoursFriday()).getOracleArray(). i < arr.add(new OAException(OutError.getAttributes(). . Datum[] arr = arrayError.insNarvaroCs. insNarvaroCs.} throw OAException.setNUMBER(15. "XXOTL_ERROR_MESSAGE_TBL"). //System. insNarvaroCs.setDATE(14. OAException. insNarvaroCs.STRUCT)arr[i].getARRAY(22).close().out. OutError = (String)a[1].registerOutParameter(22. } catch (Exception e) {. insNarvaroCs. Object[] a = os. insNarvaroCs.setDATE(20.

OABodyBean. OAGlobalButtonBarBean buttons = (OAGlobalButtonBarBean)page.put("Add".forwardimmediately to currentpage(map.fnd. Ø Code for Setting Initial Focus on a field (in process request) import oracle.get("Add"). buttons.} } 12) How to redirect to the same page and change properties.apps. String addEvent = map.webui.setRendered(false). map. . pagecontext. Y).equals(addEvent )) { /// editable } else { ////editable } 13 Some other code snippets. } in processrequest hashmap map = new hashmap(). if("Yes".framework. true.beans.getparameter("AddBtn") != null) { hashmap map = new hashmap(). Ø Code for Disabling Global Buttons (in process request) OAPageLayoutBean page = (OAPageLayoutBean)pageContext. if(pagecontext. page.prepareForRendering(pageContext).getGlobalButtons().getPageLayoutBean(). "Yes").

setLockingMode(oadbTransaction. // SelectVersion is the id of the lov item in the page if(messagelovinputbeanPerson != null) { Hashtable params = new Hashtable().setAttributeValue(OAWebBeanConstants.true. Ø Handling Browser Back Button (In Process Request) if (!pageContext. .… OABodyBean oabean = (OABodyBean)pageContext. whose action should happen after enter key press messagelovinputbeanPerson.put(”Go“. //Go is the name of the button. oabean.true)).isBackNavigationFired(false)) { TransactionUnitHelper.ON_ KEY_PRESS_ATTR.setInitialFocusId(”ProjectType1?).findIndexedChildRecursive(”SelectVe rsion“).setWrap(SOFT_WRAP).startTransactionUnit(pageContext.LOCK_NONE).params . “true”). oadbTransaction. params.”DefaultFormName”. } Ø Code for releasing lock on a database transaction (in AMImpl) OADBTransaction oadbTransaction = getOADBTransaction().new OABoundValueEnterOnKeyPress(pageContext. // All your processRequest logic should be inside this IF loop. Ø Code for wrapping text in read-only text area (in Process Request) textBean. (in process request) OAMessageLovInputBean messagelovinputbean = (OAMessageLovInputBean)webBean. “xxxxxxxxxxTxn”).getRootWebBean(). Ø Code for Handling enter key press after entering a value in the text box.

endTransactionUnit(pageContext. “xxxxxxxxxxxxxxxTxn”). pageContext. } } (In Process Form Request. before redirecting to a different page or before form submission) TransactionUnitHelper.isTransactionUnitInProgress(pageContext.} else { if (!TransactionUnitHelper. “xxxxxxxxxxxTxn”. .redirectToDialogPage(dialogPage). true)) { OADialogPage dialogPage = new OADialogPage(STATE_LOSS_ERROR).