Quantcast

Data Migration System


Data Migration System


Presently for data migration in oracle apps, raw data is migrated from flat files to oracle apps. The flat file may be an excel sheet provided by the client or any other text file. The existing process is tedious, complicated and not really user friendly.
To overcome these problems I have tried to develop a tool. With the help of this tool data migration does not require maintenance of scripts and the user has an opportunity wherein he may mention the source of the flat file and the destination where it needs to be migrated. This tool is called as ‘Data Migration System’. It is unlike other migration tools which has monolithic design and requires much more technical intervention.

INTRODUCTION
      Background
Conversion and loading process in oracle apps
Includes:-
1)   Migrating raw data to staging table by registering concurrent programs.
2)   Validating the staging table data and loading to the interface tables.
3)  Calling Oracle open interface program to load interface table data to base table.
This migration process is quite cumbersome and stringent. The migration systems are available in the market as separate utilities or these features are embedded with some application program. The migration system could be thought of as a user friendly system that allows the transfer of raw data from any flat file to oracle apps without any dependency.
Rationale behind building such system is to explore the oracle application framework.
The framework design is to build part of service oriented architecture. The technology chosen is JAVA because of its wide acceptance and flexibility on server side and with the help of this technology the design may be easily implemented.

      Relevance            
   The idea of implementation of data migration system is derived from traditional migration process in oracle apps.     
  Unlike the other migration tools which require maintaining of comma separated files or text file and additional scripting for migration, the data migration system provides a way for user to specify the spreadsheet i.e. excel sheet to migrate the data to oracle apps tables.
   The migration system will not affect the working of existing migration process in apps however the user is allowed to specify the package and/or procedure in order to validate the data in table. Migration system follows the same procedure as conventional migration process in apps by reducing task of maintaining separate data file and writing of control file scripts to read raw data from the file.     

technical Overview:
The main goal of data migration system is to provide user interface to upload spreadsheet rather than doing the same through backend using linux utilities or through oracle apps custom concurrent program.
The migration system follows the same process of conversion and loading. It inherits some features of application desktop integrator. The data migration system is another utility tool for migration. Even a novice user may migrate data using its simple user interface. It mainly includes following processes.

Initial process:
The migration system is similar to the SQL loader with certain additional facilities. At initial stage, the user is supposed to ask for an instance. This could be test instance, UAT instance, DEV instance, CRP instance or production. User can easily switch to another instance if migration process in the earlier has completed successfully. After specifying the instance, user will be required to enter database credentials for the same. Once the credentials are validated then user will be asked to select/mention the table name. The specified table name would be considered as the destination for migration. If table mentioned does not exist in database then the migration system provides option to the user for creating the table.

Moving data from flat file to oracle staging table:
Here user will be asked to select the columns of the staging table. User may shuttle the required number of columns in trailing list. Skipper may be mentioned, if the user wants to skip certain rows from spreadsheet and specify the file to upload the data to staging table. Possible file types supported by migration system are dat(data file), xls(excel spreadsheet), csv(comma separated file), txt(text file). As of now the delimiter for the text file is considered as comma. Idly any valid delimiter character may be specified before uploading the txt/dat file. Comma separated file containing commas, single and double quotes will be successfully uploaded. Workbook containing multiple spreadsheets will also be successfully uploaded. For e.g. If there is a requirement of PO data migration and client has provided the data in 3 different excel sheets indicating header, lines and distributions information. User can mention staging table information and specify the file straightway to upload. If user has specified correct source and destination information then message will be populated indicating file has been uploaded, error log table is maintained for recording any error occurred during/after uploading. Advantage of this migration system is that there is no need of querying the database to ensure insertion in table as the migrated data in the table may be viewed in the same page after successful file upload.

Moving from staging to Interface table(S) OIT:
To validate staging table data, the migration system allows user to specify package and/or procedure to carry out the same. The specified package must exist in oracle apps. Here the Benefit of data migration system is reusability of existing package(s) like conventional migration process. No need of restructuring the existing package and/or procedure.

Finally to Oracle apps base table:
User will ask for Oracle open interface program. This functionality is alike webADI. User will specify the parameters needed for running concurrent program to move data from interface tables to apps base tables.


FLow diagram:




Architecture



BENEFITS:
Ø  Simple and efficient system for transferring data from flat file to oracle database.
Ø  No need of maintaining control file and CSV file.
Ø  No need of manually transfer data files to server location. (No need of running the FTP utility.)
Ø  No need of remembering huge commands.
Ø  Multiple spreadsheets under single workbook can be successfully uploaded.
Ø  Time saving process.
Ø  Directly mention excel file to copy data to oracle database.
Ø  Allows user to create tables dynamically.
Ø  On successful migration, it also has the facility of viewing uploaded data rather than querying the database.


REFERENCES:
Books:
1. Anil passi, Vladimir Ajvaz, Oracle E-Business suite development and  extensibility handbook
2. Data Migration in Oracle E-Business Suite – presentation by Accenture.
3. Conversions, Interfaces and Oracle Applications: Data Movement throughout the Oracle Applications Life Cycle
4. Oracle application framework – developer guide version 12.1.1
5. Oracle_ Applications Developer’s Guide
6. Austin Davis, Accelerate oracle configurator data migration for E-business suite R12

Sites:
  1. http://erpschools.com/articles/interfaces-and-conversions
  2. http://docs.oracle.com/cd/E23903_01/doc/doc.41/e21675/appmgr_overview.htm
  3. http://apps2fusion.com/at/50-pb/255-data-conversion-strategies-in-oracle-e-business-suite-implementation
  4. http://apps2fusion.com/at/pb/255-data-conversion-strategies-in-oracle-e-business-suite-implementation?showall=1
  5. oracle.anilpassi.com/oa-framework-tutorial-01.html
  6. oracle.anilpassi.com/oa-framework-tutorials-training-2.html
  7. mukx.blogspot.com/oa-framework

Screen shots:










Implement 3-level master detail hierarchy using table region in OA framework.


Implement 3-level master detail hierarchy using table region in OA framework.

After depth searching on various oracle forums, I came to know that multi-level hierarchy in advance table is not achievable by easy means. There could be at the most one detail region inside an advance table.  If the business requirement is to display records in master->detail->detail format then advance table won’t be effective. For e.g. If the requirement is to show item transaction details year wise and when user clicks on show-hide region against any record will navigate to the month wise details and when user clicks on show-hide region against any record will navigate to the day wise details such hierarchy is possible, The OA framework provides the table region to achieve the same functionality.

Procedure:
Create view object for corresponding master – detail – detail regions.

Define view link for 1st level of master-detail hierarchy.
Define view link for 2nd level of master-detail hierarchy.
Add transient attribute of type string to each master View object so as to display corresponding detail region and default it to N. Make this transient attribute as always updatable.  While developing I have attached one transient attribute “showFlag” to Master View object xxQcItemReceiptXsactionsYrlyVO. And “showFlag1” to master view object xxQcItemReceiptXsactionsMnthlyVO who is child of xxQcItemReceiptXsactionsYrlyVO.

Attaching view objects to AM. Select the appropriate view object and shuttle it to right side.
First shuttle the master VO then shuttle detail VO to right side then click on apply.

Create table region by selecting page region right click -> new ->region using wizard. 


After creating table select newly created table region right click -> new -> detail.

It will create detail region table.


Select detail region and attach new table region inside.



Set the properties for master – detail region. Specify view link instance name for master VO and specify detail view attribute name to show-hide detail region.


Specify view link instance for detail region and detail view attribute to display detail region inside it.

Specify view link instance for inner most detail region. 

Table region with 3 level of mater detail hierarchy.

Shuttle Control in OA Framework


Shuttle Control in OA Framework

While working on various business scenarios, we may come across multiple situations wherein we need to select specific values from the list and require moving to another list which will be considered as final list.  OA framework provides shuttle control to fulfill the same. For e.g.  In Jdeveloper, while attaching view object to the application module we need to select correct view object from view object definition list in left side panel and move it to right side panel/list so as to include view object definition into the  application module. Well, to achieve such operations Oracle application framework provides such option by means of shuttle control.  Shuttle Control allows user to move values from one list region to other.
Design:  Select page region and right click -> new region set region style property of this region to shuttle.  After setting region style you will get shuttle region with default leading list. You may provide trailing list to shuttle region by selecting shuttle region right click -> trailing list. By default leading and trailing lists will be empty.  You may add values into leading and trailing list by specifying view object instance and VO attribute.
Adding values into the shuttle control:  Shuttle Control may have leading and trailing list. There are 2 different ways to add values to Leading and/or trailing list in shuttle control.

1)      By using View Object: By specifying pick list view object instance, display attribute and value attribute for leading list will populate values fetched from VO. By default shuttle control have leading list.



2)      Manually adding static values.

There might be a scenario wherein you may need to add independent (Raw text) values without fetching from view objects to shuttle region’s lists.  OA framework provides function to add values dynamically to shuttle control’s leading and/or trailing list. For adding static values to shuttle’s leading and trailing list, OA framework provides standard function to achieve the same. However user needs to specify default picklist view instance, view display and value attribute for leading and trailing list.
Code manually adds static text/ values.
/* First to find shuttle region in your page */
OADefaultShuttleBean shuttle = (OADefaultShuttleBean)webBean.findChildRecursive("ShuttleBean");
shuttle.prepareForRendering(pageContext);

/* Let control of leading list in shuttle control */
OADefaultListBean leading =  (OADefaultListBean)shuttle.getLeading();
leading.setListCacheEnabled(false);

/* Here I am displaying list of table columns in leading list */
Serializable TabName[] = {TableName,UserId};
ArrayList ar = (ArrayList)am.invokeMethod("SetColums",TabName);
System.out.println("Last index of array :"+ar.size());

/*Cleaning leading list*/
leading.clearIndexedChildren();

for (int i = 0; i < ar.size(); i++ )
{
      System.out.println("Element from Array :"+ar.get(i).toString());
      leading.addOption(ar.get(i).toString());
 }
    
AM Method: setColums()
   public ArrayList SetColums(String TableName,String UserId)
   {
       System.out.println("-----Inside SetColums------");
       tableColsVOImpl vo = this.gettableColsVO1();
       ArrayList array = new ArrayList();
       String Where =" table_name = '"+TableName+"'";
      System.out.println("Where Clause :"+Where);
       String Query = "select * from all_tab_cols where table_name like '"+TableName+"'"+ " AND OWNER = '" + UserId + "'"+" ORDER BY INTERNAL_COLUMN_ID";
       vo.setQuery(Query);
       //vo.setWhereClause(null);
       //vo.setWhereClause(Where);
       vo.executeQuery();
       System.out.println("Query ::"+vo.getQuery());

     /* getting a row */
       OARow row = (OARow)vo.next();
       while (row != null)
       {
              /*finally adding to array */
array.add(row.getAttribute(2)); /*get column name*/
            System.out.println("Column we fetched is :"+row.getAttribute(2));
            row = (OARow)vo.next();
       }    
       return array;
   }

   


 In above example, the values in leading list will be set dynamically based on table name.
For more details please refer Jdev guide -> shuttle.

Read Comma separated file containing commas, single/ double quotes, line feed characters.


Read Comma separated file containing commas, single/ double quotes, line feed characters.

While working in iSupplier implementation, we need to upload comma separated file containing ASN data provided by the client into database. While using comma separated file, user had restrictions not to put comma or any special characters in the file. But what if user needs to upload his address information into database. Address may contain commas and/or special characters. Below is the code that reads CSV file containing commas, special characters/quotes and inserts filtered data into database.

 /*************************************************************************************************************
  *
  *     Reading Data from comma separated file, this code will filter the data from comma separated
  *     file and then insert that data into table.
  *    
  *
  * **********************************************************************************************************/

  public String readCSVFile(String filePath, String TableName, String ColumnList,String skipperValue,String UserId)
  {
        String LS = System.getProperty("line.separator");
        String fileContent = null;
        String ErrorCount = null;
        int skipper = Integer.parseInt(skipperValue);
        String Contentwoquotes = "";
        int beginIndex = 0,endIndex = 0,i = 0;
        String splitString = "";
        String BufferData = "";     
        int charFound;
        int countNull = 1;
        String quoteString = "";
        int trackQuotes = 0;
        String q2string = "";
       
        try
        {
               FileReader fr = new FileReader(filePath);
               BufferedReader reader = new BufferedReader(fr);
               String line;
               int rowNumber = 0;
              
               
               while( skipper != 0 )
               {
                    reader.readLine();
                    skipper--;
               }
              
               while ((line = reader.readLine()) != null)
               {
                   fileContent = line;
                   BufferData = "";
                   q2string = "";
                   quoteString = "";
                   Contentwoquotes = "";
                   countNull = 0;
                   splitString = "";
                   int quoteTracker = 0;
                  
                   while(line.indexOf(",") > -1 )
                   {
                      endIndex = line.indexOf(",");
                      
                      if (line.charAt(0) == '"')
                      {
                           i = 0;
                           quoteTracker = 0;
                           splitString = "";
                      
                           while ( i < line.length() )
                           {  
                                  if (line.charAt(i) == '"' )
                                  {
                                       if (trackQuotes == 1 )
                                       {
                                           q2string = q2string + line.charAt(i); 
//                                           System.out.println("Quote String  At  ::"+q2string);
//                                           System.out.println("Counter :"+trackQuotes);
                                           i++;
                                           trackQuotes = 0;
                                       }
                                       else
                                       {                                             
                                           trackQuotes++;
                                           quoteTracker = 0;
//                                           System.out.println("Track Quotes ::"+trackQuotes);
                                           i++;
                                       }
                                           
                                  }
                                  else if ("'".equals(line.substring(i,i+1)))
                                  {
                                      q2string = q2string + line.charAt(i) + "'" ;
//                                      System.out.println("Quote String  At  ::"+q2string);
//                                      System.out.println("Counter :"+trackQuotes);
                                      i++;
                                      trackQuotes = 0;
                                     
                                  }
                                  else
                                  {
                                          if (line.charAt(i) == ','&& trackQuotes == 1)
                                          {
                                              charFound = checkASCII(q2string);
                                              quoteTracker = 1;
                                              if (charFound == 1)
                                              {
                                                  BufferData = BufferData + "'" +q2string + "',";       
                                                  Contentwoquotes = Contentwoquotes + q2string + "        ";
                                              }
                                              else
                                              {
                                                  BufferData = BufferData + q2string; 
                                                  Contentwoquotes = Contentwoquotes + q2string + "        ";
                                              }
//                                              q2string = "";
//                                              System.out.println("Line Data ::"+line);   
//                                              System.out.println("Value of I ::"+i);
//                                              System.out.println("Counter :"+trackQuotes);
//                                              System.out.println("Line Length ::"+line.length());
//                                              line = line.substring(i+1);
//                                              System.out.println("Remaining line ::"+line);   
                                             
//                                                if ("".equalsIgnoreCase(line))
//                                                    BufferData = BufferData + "'',";

                                              i = 0 ;
                                              break;
                                          }
                                          else
                                          {
                                              if (line.charAt(i) == ',')
                                              {
                                                  endIndex = line.indexOf(",");
//                                                  System.out.println("End index ::"+endIndex);
                                                  if (endIndex == 0 && quoteTracker != 0)
                                                  {
                                                      q2string =  q2string + "'',";
                                                  }
                                                  else
                                                      q2string =  q2string + line.charAt(i);
                                                      
                                              }
                                              else
                                              {
                                                  q2string = q2string + line.charAt(i);
//                                                  System.out.println("Quote String  At  ::"+q2string);
//                                                  System.out.println("Counter :"+trackQuotes);
//                                                  System.out.println("Value of I ::"+i);
//                                                  System.out.println("Line length ::"+line.length());
//                                                    trackQuotes++;
                                              }   
                                              i++;
                                          }   
                                          trackQuotes = 0;
                                         
                                          /*
                                          if (line.charAt(i) == ','&& trackQuotes == 1)
                                          {
                                              splitString = q2string;
                                              q2string = "";
                                          }  
                                          else
                                          {
                                             q2string = q2string + line.charAt(i);
                                             System.out.println("Quote String  At  ::"+q2string);
                                             System.out.println("Counter :"+trackQuotes);
                                          }*/
                                     
                                  }

                                 
                                  if(i == line.length() && trackQuotes == 0 && i != 0  && quoteTracker == 0)
                                  {
                                     i = 0;
                                     line = reader.readLine();
//                                     System.out.println("Line data......"+line);
                                     if (line == null )
                                        break;
                                  }   
                                 
                           }
                          
                           splitString = splitString + q2string;
//                           System.out.println("splitString ::"+splitString);
//                             Contentwoquotes = Contentwoquotes + splitString + "        ";
                           endIndex = line.indexOf(",");
//                           System.out.println("Buffer Data ::"+BufferData);
//                           System.out.println("End Index   ::"+endIndex);
                          
                           if (endIndex != -1 && endIndex != 0 )
                           {
                               if (line != null)
                               {
                                  line = line.substring(i+2);
                                  endIndex = line.indexOf(",");
                               }  
                           }
                           else
                           {
                               line = line.substring(i);    
                           }
//                             System.out.println("Remaining Line Data "+line);
                      }
                      else
                      {
                           endIndex = line.indexOf(",");
                           splitString = line.substring(beginIndex,endIndex);                             
                           i = 0;
                           quoteString  = "";
                           trackQuotes = 0;
//                             System.out.println("Split String catched :: "+splitString);
                          
                           if ((splitString.indexOf("'")!= -1 ))
                           {
                                  while ( i < splitString.length() )
                                  {  
                                         if ("'".equals(splitString.substring(i,i+1)))
                                         {
                                             quoteString = quoteString + splitString.charAt(i) + "'" ;
//                                               System.out.println("Quote String  At  ::"+quoteString);
                                             i++;
                                             //trackQuotes = 0;
                                            
                                         }
                                         else
                                         {
                                             quoteString = quoteString + splitString.charAt(i);
//                                               System.out.println("Quote String  At  ::"+quoteString);
                                             i++;
                                             //trackQuotes = 0;
                                         }
                                  }
                                  splitString = quoteString;

                                  /*BufferData = BufferData + "'" +quoteString + "',"; */
                           }
                           else
                           {
                               if (line != null)
                               {
                                   if (endIndex != 0 )
                                   {
                                        charFound = checkASCII(splitString);
                                        if (charFound == 1)
                                        {
                                            BufferData = BufferData + "'" + splitString + "',";       
                                        }
                                        else
                                        {
                                            BufferData = BufferData + splitString + ","; 
                                        }
                                   }
                                   else
                                   {
                                     // If string has null value
                                       if(endIndex != -1)
                                       { 
                                           countNull++;
        //                                 System.out.println("Null Counter ::"+countNull);
                                           BufferData = BufferData + "'',";
                                       }  
                                   }
                               }
                               else
                               {
                                   charFound = checkASCII(splitString);
                                   if (charFound == 1)
                                   {
                                       BufferData = BufferData + "'" + splitString + "'";       
                                   }
                                   else
                                   {
                                       BufferData = BufferData + splitString; 
                                   }
                               }   
                           }
                          
                           Contentwoquotes = Contentwoquotes + splitString + "        ";
                          
                           if(line.length() > endIndex)
                              line = line.substring(endIndex+1);
                       
                      }

                   }
               
//                   System.out.println("Content w/o quotes ::"+Contentwoquotes);
//                   System.out.println("Line with quotes  ::"+BufferData);
//                   System.out.println("Line Data ::"+line);
//                   System.out.println("Begin Index ::"+beginIndex);
//                   System.out.println("End Index   ::"+endIndex);
                
                    if (line == null )
                       break;
               
                    /** Locating last field in the line */
                   
                     if (line != null )
                     {
                             if ("".equalsIgnoreCase(line))
                                  countNull++;
                             int isQuoteFinished = 0;
                             int charFlag = 0;
                             int flag = 0;
                             /** Checking at end of the Line */
//                             System.out.println("Line length ::"+fileContent.length());
//                             System.out.println("Null Counter ::"+countNull);
                             int contentlength = fileContent.length() + 1;
//                             System.out.println("Now outside the loop........");
                             if (countNull != contentlength)
                             {
                                     if ("".equalsIgnoreCase(line))
                                         BufferData = BufferData + "''";  
                                        
                                     else if (line.charAt(0) == '"')
                                     {
                                         q2string = "";
                                         i = 0;
                //                         System.out.println("Double quotes at 0th index.");
                                         while ( i < line.length() )
                                         {  
                                                if (line.charAt(i) == '"' )
                                                {
                                                     if (trackQuotes == 1 )
                                                     {
                                                         q2string = q2string + line.charAt(i); 
//                                                         System.out.println("Quote String  At  ::"+q2string);
//                                                         System.out.println("Counter :"+trackQuotes);
                                                         i++;
                                                         trackQuotes = 0;
                                                     }
                                                     else
                                                     {
                                                         trackQuotes++;
                                                         isQuoteFinished = 0;
                                                         i++;
                                                     }
                                                     charFlag = 0;    
                                                }
                                                else if ("'".equals(line.substring(i,i+1)))
                                                {
                                                    q2string = q2string + line.charAt(i) + "'" ;
//                                                    System.out.println("Quote String  At  ::"+q2string);
//                                                    System.out.println("Counter :"+trackQuotes);
                                                    i++;
                                                    charFlag = 0;
                                                    trackQuotes = 0;
                                                }
                                                else
                                                {
                                                    if (line.charAt(i) == ','&& trackQuotes == 1)
                                                    {
                                                        charFound = checkASCII(q2string);
                                                        isQuoteFinished = 1;
                                                        if (charFound == 1)
                                                        {
                                                            BufferData = BufferData + "'" +q2string + "',";       
                                                            Contentwoquotes = Contentwoquotes + q2string + "        ";
                                                        }
                                                        else
                                                        {
                                                            BufferData = BufferData + q2string + ","; 
                                                            Contentwoquotes = Contentwoquotes + q2string + "        ";
                                                        }
                                                       
                                                        q2string = "";
//                                                        System.out.println("Line Data ::"+line);   
//                                                        System.out.println("Value of I ::"+i);
//                                                        System.out.println("Counter :"+trackQuotes);
//                                                        System.out.println("Line Length ::"+line.length());
                                                        line = line.substring(i+1);
//                                                        System.out.println("Remaining line ::"+line);   
                                                        if ("".equalsIgnoreCase(line))
                                                            BufferData = BufferData + "''"; 
                                                        i = 0;
                                                    }
                                                    else
                                                    {
                                                        if (line.charAt(i) == ',')
                                                        {
                                                            endIndex = line.indexOf(",");
//                                                            System.out.println("End index ::"+endIndex);
//                                                            System.out.println("Char Flag ::"+charFlag);
                                                            if (endIndex == 0 && isQuoteFinished != 0 && charFlag != 1 )
                                                            {
                                                                flag = 1;
                                                                q2string =  q2string + "'',";
                                                            }
                                                            else {
                                                                q2string =  q2string + line.charAt(i);
//                                                                System.out.println("Char Flag ::"+charFlag);
                                                                charFlag = 0;
                                                            }
                                                               
                                                        }
                                                        else
                                                        {   
                                                            q2string = q2string + line.charAt(i);
                                                            charFlag = 1;
//                                                            System.out.println("Quote String  At  ::"+q2string);
//                                                            System.out.println("Counter :"+trackQuotes);
                                                            trackQuotes++;
                                                        }   
                                                        i++;
                                                           
                                                    }   
                                                    trackQuotes = 0;
                                                }
                                               
//                                               System.out.println("Counter Value revs :"+trackQuotes);
                                               if(i == line.length() && trackQuotes == 0 && i != 0 && isQuoteFinished == 0 )
                                               {
                                                   i = 0;
                                                   line = reader.readLine();
                                                   /* New line Comes */
                                                   if (line == null )
                                                      break;
                                               } 
                                             
//                                               System.out.println("Buffer Data ::"+BufferData);
                                         }  // end of while ( i < line.length() )
                                         
                                        
                                       
                                         if (flag == 1)
                                             line = line.substring(i-1);
                                         
//                                         System.out.println("Remaining Line Data ::"+line);
//                                         System.out.println("String ::"+q2string);
                                        
                                         
                                        
                                         if (",".equalsIgnoreCase(line))
                                         {
                                             BufferData = BufferData + q2string + "''"; 
                                         }   
                                         else
                                         {
                                             charFound = checkASCII(q2string);
                                             if (charFound == 1 )
                                             {
                                                 BufferData = BufferData + "'" + q2string + "'";       
                                             }
                                             else
                                             {
                                                 BufferData = BufferData + q2string; 
                                             }
                                             
                                         }   
                                        Contentwoquotes = Contentwoquotes + q2string + "        ";
                //                  
                                     } // end of if (line.charAt(0) == '"')
                                     else
                                     {
                                         i = 0;
                                         quoteString = "";
                                         if ((line.indexOf("'")!= -1 ))
                                         {
//                                                System.out.println("String having quotes.......");
                                                while ( i < line.length() )
                                                {  
                                                       if ("'".equals(line.substring(i,i+1)))
                                                       {
                                                           quoteString = quoteString + line.charAt(i) + "'" ;
//                                                           System.out.println("Quote String  At  ::"+quoteString);
                                                           i++;
                                                       }
                                                       else
                                                       {
                                                           quoteString = quoteString + line.charAt(i);
//                                                           System.out.println("Quote String  At  ::"+quoteString);
                                                           i++;
                                                       }
                                                }
                                                Contentwoquotes = Contentwoquotes + quoteString + "         ";
                                                BufferData = BufferData + "'" +quoteString + "'";
                                         } // end of if ((line.indexOf("'")!= -1 ))
                                         else
                                         {
                                             charFound = checkASCII(line);
                                             if (charFound == 1){
                                                     BufferData = BufferData + "'"+ line + "'";
                                             }
                                             else{
                                                     BufferData = BufferData + line;
                                             }
                                             Contentwoquotes = Contentwoquotes + line  + "         ";
                                         } // end of nested else
                                     } // end of main else
                                    

                                       
//                                     System.out.println("Line length ::"+line.length());
                //                   System.out.println("line.charAt(beginIndex) ::"+line.charAt(beginIndex));
                //                   System.out.println("line.lastIndexOf('\"')::"+line.lastIndexOf('"'));
//                                     System.out.println("Content w/o quotes ::"+Contentwoquotes);
//                                     System.out.println("Line with quotes  ::"+BufferData);
//                                     System.out.println("Line Data ::"+line);
                //                   System.out.println("Begin Index ::"+beginIndex);
                //                   System.out.println("End Index   ::"+endIndex);
               
                                     insertIntoTable(BufferData,TableName,ColumnList,Contentwoquotes,UserId,rowNumber);  
                                    
                                     if (line == null )
                                        break;
                                   
                             }
                           
                     }
                     else {
                                insertIntoTable(BufferData,TableName,ColumnList,Contentwoquotes,UserId,rowNumber);  
                     }
                    
               } // end of while ((line = reader.readLine()) != null)       
                   

              rowNumber++;
                
        }
        catch (IOException e) {
            e.printStackTrace();
        }

/**********************************************************************
               Below method inserts line into table.
**********************************************************************/
  public void insertIntoTable(String RowData,String TableName, String ColumnList, String Contentwoquotes,String UserId, int rowNumber)
  {
      OADBTransactionImpl oadbtransactionimpl = (OADBTransactionImpl)getDBTransaction();
      int beginIndex = 0,endIndex = RowData.indexOf(","),i = 0;
      String splitString = "";
      String Line = RowData;
      String BufferData = "";      
      int charFound;
      String InsertStmt;
      ArrayList Value = new ArrayList();
      CallableStatement oraclecallablestatement;

      try
      {
          oraclecallablestatement = oadbtransactionimpl.createCallableStatement(insertstmt, -1);               
          oraclecallablestatement.execute();
          System.out.println("Insert Command Executed Successfully.");
          oraclecallablestatement.close();
      }
      catch (SQLException e)
      {
          
          String insertintoErrorTabHead = "INSERT INTO XXKOP.STGGING_ERROR_DTLS(ERROR_MSG,COLUMNNAME) " +      " Values('"+e.getMessage().substring(e.getMessage().indexOf("")+1)+"','"+Contentwoquotes+"')";

          try
          {
                oraclecallablestatement = oadbtransactionimpl.createCallableStatement(insertintoErrorTabHead, -1);
                oraclecallablestatement.execute();
                oraclecallablestatement.close();
          }
          catch (SQLException exp)
          {
                throw new OAException(e.getMessage() + "   " + insertstmt,OAException.ERROR);
          } 
     
      }
  }
  

Search on Master-detail table in OAF

Search on Master-detail table in OAF

Hello friends,

Oracle application framework provides me another opportunity to work on and to get more acquainted with. So here I am eager to share another short article on OAF.  Just finished a project on OAF and came across various fact and findings about the framework.
You guys may have come across master – detail relationship in OAF and ‘how-to’ behind that as well.  I have recently read articles on how to insert a row into child table. Well this article is quite a different one.
While developing an application, there might be a requirement wherein we need to work on master detail relationship.  In my case, the requirement was to develop the search page having result table including master and detail table records.  The user may enter any search criteria that may fall under master table and/or detail table. Depending upon the search performed by the user, the master and detail table records must be populated.
For e.g. consider employee and department table.  We have to develop a search page which populates department details along with employee details based on search criteria.
(1) If user searches for department no 10 then the result table should display the department no 10 along with employees who works under the same.

Hide
Dept No
Department
Location
(-)
10
Accounting
New york

Empno
Name
Job
Mgr
Hiredate
 Salary
Commission
7934
Millar
Clerk
7782
23-Jan-82
 30000

7839
King
President

17-Nov-81
15000000


(2) If user searches for employee number 7839 then result table should display department in which employee 7839 works and that employee details only.

Hide
Dept No
Department
Location
(-)
10
Accounting
New york
   
Empno
Name
Job
Mgr
Hiredate
Salary
Commission
7839
King
President

17-Nov-81
15000000


To achieve such results in oaf in master detail search, we need to first execute master table VO so as to populate master and detail table records then we need to traverse to each record in detail table and ignore/ remove unwanted records.
Here is the java code to get results:

/* You may change the search criteria according to business requirement. */
public void showMasterDetail(OAPageContext pageContext, OAWebBean webBean, OAApplicationModule am) {
        // get a handle to inner table
        RowSet innerRowSet = null;
        OAAdvancedTableBean innerTable = (OAAdvancedTableBean)webBean.findChildRecursive("region12");
        int counter = 0;
        OARow row = null;
        int loginId = pageContext.getLoginId();
        String deptno = pageContext.getParameter("deptno");
        String dname = pageContext.getParameter("dname");
        String location = pageContext.getParameter("location");
        String empno = pageContext.getParameter("empno");
        String ename = pageContext.getParameter("ename");
        String job = pageContext.getParameter("job");
        String mgr = pageContext.getParameter("mgr");
        String hiredate = pageContext.getParameter("hiredate");
        String salary = pageContext.getParameter("salary");
        String HdrsearchQuery = null;
        Row lineRow = null;
        Row[] rowsInRange = {};
        OAViewObject  HdrsearchVo = (OAViewObject)am.findViewObject("xxDeptVO1") ;
        OAViewObject LinesearchVo = (OAViewObject)am.findViewObject("xxEmpVO1");
        pageContext.putSessionValue("retainAMValue","N");
//        processRequest(pageContext,webBean);
        if (!("N".equalsIgnoreCase(pageContext.getParameter("searchHdrLine")))) {
            if (deptno!= ""&& deptno!= null) {
                if ("".equalsIgnoreCase(HdrsearchQuery)) {
                    HdrsearchQuery =
                            HdrsearchQuery + " DEPTNO = "+ deptno;
                } else {
                    HdrsearchQuery =
                            HdrsearchQuery + " AND DEPTNO = "+ deptno;
                }
            }
            if (dname!= ""&& dname!= null) {
                if ("".equalsIgnoreCase(HdrsearchQuery)) {
                    HdrsearchQuery =
                            HdrsearchQuery + " UPPER(DNAME) LIKE UPPER('" + dname +  "')";
                } else {
                    HdrsearchQuery =
                            HdrsearchQuery + " AND UPPER(DNAME) LIKE UPPER('" + dname +  "')";
                }
            }

            if (location!= ""&& location!= null) {
                if ("".equalsIgnoreCase(HdrsearchQuery)) {
                    HdrsearchQuery =
                            HdrsearchQuery + " UPPER(LOCATION) LIKE UPPER('" + location + "')";
                } else {
                    HdrsearchQuery =
                            HdrsearchQuery + " AND UPPER(LOCATION) LIKE UPPER('" + location + "')";                }
            }

            if (empno!= ""&& empno!= null) {
                if ("".equalsIgnoreCase(LineSearchQuery)) {
                    LineSearchQuery =
                            LineSearchQuery + " EMPNO = "+empno;
                } else {
                    LineSearchQuery =
                            LineSearchQuery + " AND EMPNO = "+empno;
                }
            }

            if (ename!= ""&& ename!= null) {
                if ("".equalsIgnoreCase(LineSearchQuery)) {
                    LineSearchQuery =
                            LineSearchQuery + " UPPER(ENAME) LIKE UPPER('" + ename + "')";
                } else {
                    LineSearchQuery =
                            LineSearchQuery + " AND UPPER(ENAME) LIKE UPPER('" + ename + "')";
                }
            }

            if (hiredate!= ""&& hiredate!= null) {
                if ("".equalsIgnoreCase(LineSearchQuery)) {
                    LineSearchQuery =
                            LineSearchQuery + " HIREDATE ='" + hiredate +
                            "'";
                } else {
                    LineSearchQuery =
                            LineSearchQuery + " AND HIREDATE = '" + hiredate +
                            "'";
                }
            }

            if (job!= ""&& job!= null) {
                if ("".equalsIgnoreCase(LineSearchQuery)) {
                    LineSearchQuery =
                            LineSearchQuery + " UPPER(JOB) LIKE UPPER('" + job + "')";
                } else {
                    LineSearchQuery =
                            LineSearchQuery + " AND UPPER(JOB) LIKE UPPER('" + job + "')";
                }
            }
           
            if (mgr!= ""&& mgr!= null) {
                if ("".equalsIgnoreCase(LineSearchQuery)) {
                    LineSearchQuery =
                            LineSearchQuery + " MGR = " + mgr ;
               } else {
                    LineSearchQuery =
                            LineSearchQuery + " AND MGR = " + mgr ;
                }
            }

            if (salary!= ""&& salary!= null) {
                if ("".equalsIgnoreCase(LineSearchQuery)) {
                    LineSearchQuery =
                            LineSearchQuery + " SALARY = " +salary;
                } else {                         
                    LineSearchQuery =
                            LineSearchQuery + " AND SALARY = " +salary;
                }
            }

            System.out.println(" Header Set where clause Query is : " + HdrsearchQuery);
           
            if (!("".equalsIgnoreCase(LineSearchQuery))) {
                if (LinesearchVo != null)
                {
                    LinesearchVo.setWhereClause(null);
                    LinesearchVo.setWhereClause(LineSearchQuery);
                    LinesearchVo.executeQuery();
                    String lstOfdepts = "";
                    lineRow = LinesearchVo.first();
                    if (lineRow != null) {
                       while(lineRow != null )
                       {
                          lstOfdepts = lstOfdepts + lineRow.getAttribute("deptNo").toString() + ",";
                          lineRow = LinesearchVo.next();
                       }
                       if (!("".equalsIgnoreCase(lstOfHdrIds)))
                       {
                           lstOfdepts =  lstOfdepts.substring(0,lstOfHdrIds.length()-1);
                           if ("".equalsIgnoreCase(HdrsearchQuery)) {
                              HdrsearchQuery = HdrsearchQuery + “ DEPTNO IN ("+lstOfdepts +")";
                           } else {
                              HdrsearchQuery = HdrsearchQuery + " AND DEPTNO IN ("+lstOfdepts +")";
                           }
                       }   
                    }
                    else
                    {
                         if ("".equalsIgnoreCase(HdrsearchQuery)) {
                           HdrsearchQuery = HdrsearchQuery + "  DEPTNO IS NULL ";
                         }
                         else {
                            HdrsearchQuery = HdrsearchQuery + " AND DEPTNO IS NULL ";
                        }
                    }
                }   
            } else {
                LinesearchVo.setWhereClause(null);
                LinesearchVo.clearCache();
                LinesearchVo.executeQuery();
            }
           
            if (!("".equalsIgnoreCase(HdrsearchQuery))) {                
//               HdrsearchVo.setWhereClause(null);
//               HdrsearchVo.clearCache();
//               HdrsearchVo.setWhereClause(HdrsearchQuery);
//               HdrsearchVo.executeQuery();
                 HashMap hmap = new HashMap();
                 hmap.put("HdrwhereClauseQ", HdrsearchQuery);
                 hmap.put("LinewhereClauseQ", LineSearchQuery);
                 hmap.put("ToPage","CurrPage");

/*Once search parameter for department i.e. master gets initialize master view object and refresh the page to reflect the changes in master detail hierarchy */

pageContext.forwardImmediatelyToCurrentPage(hmap,false,null);
            } else {
                HdrsearchVo.setWhereClause(null);
                HdrsearchVo.clearCache();
                HdrsearchVo.executeQuery();
            }
        }
        else {
           /* When Master View object is initialized with search criteria
            Here is time to initialize detail VO. */                       
            HdrsearchQuery = pageContext.getParameter("HdrwhereClauseQ");
            LineSearchQuery = pageContext.getParameter("LinewhereClauseQ");
        }
       
        if (!("".equalsIgnoreCase(LineSearchQuery))) {
             int chkFlag = 0;
//             innerTable.clearCache(pageContext);
//             innerTable.setAttributeValue(OAWebBeanConstants.CLEAR_CACHE_ATTR,Boolean.TRUE); 
   /* If user has entered one of the search criteria from detail table then  
      we need to remove unwanted records from detail table once master table 
      is initialized. One way to get handle of detail table is use of enumerator       */             
             LinesearchVo.setWhereClause(LineSearchQuery);
             LinesearchVo.executeQuery();
            // create an enumerator.
            OAInnerDataObjectEnumerator enum1 = new OAInnerDataObjectEnumerator(pageContext, innerTable);
            while (enum1.hasMoreElements())
            {
                innerRowSet = (RowSet)enum1.nextElement();
                // get all rows.
                rowsInRange = innerRowSet.getAllRowsInRange();
                System.out.println(" Inner Table Fetched Row Count :" +innerRowSet.getFetchedRowCount());

            /* Here we go to traverse each record in detail table returned after initialization of master VO */ 

                for (int i = 0; i < rowsInRange.length; i++ )
                {
                    String empnofrmquery = rowsInRange[i].getAttribute("EmpNo").toString();
                    String enamefrmquery = rowsInRange[i].getAttribute("Ename").toString();
                    String jobfrmquery = rowsInRange[i].getAttribute("Job").toString();
                    chkFlag = 0;
                    if (grrNumber != ""&& grrNumber != null) {
                        if (!(empnofrmquery.equalsIgnoreCase(empno))) {
                            lineRow = LinesearchVo.first();
                            while(lineRow != null) {
                                if(!(empno.equalsIgnoreCase(lineRow.getAttribute("EmpNo").toString()))) {
                                    chkFlag = 1;
                                }
                                else {
                                    chkFlag = 0;
                                    break;
                                }
                                lineRow = LinesearchVo.next();
                            }
                        }
                    }
                    if (enamefrmquery!= ""&& enamefrmquery!= null) {
                        if (!(enamefrmquery.equalsIgnoreCase(ename))) {
                             lineRow = LinesearchVo.first();
                             while(lineRow != null) {
                                 if(!(ename.equalsIgnoreCase(lineRow.getAttribute("Ename").toString()))) {
                                     chkFlag = 1;
                                 }
                                 else {
                                     chkFlag = 0;
                                     break;
                                 }
                                 lineRow = LinesearchVo.next();
                             }
                        }
                       
                    }
                   
                    if (jobfrmquery!= ""&& jobfrmquery!= null) {
                        if (!(jobfrmquery.equalsIgnoreCase(job))){
                            lineRow = LinesearchVo.first();
                            while(lineRow != null) {
                                if(!(jobfrmquery.equalsIgnoreCase(lineRow.getAttribute("Job").toString()))) {
                                    chkFlag = 1;
                                }
                                else {
                                    chkFlag = 0;
                                    break;
                                }
                                lineRow = LinesearchVo.next();
                            }
                        }
                    }
                  /*Remove the rows that does not fit in search criteria */ 
if (chkFlag == 1) {
                        rowsInRange[i].remove();
                    }
                }
            }
                         
        }
        else {
            if (!("".equalsIgnoreCase(HdrsearchQuery))) {
                HdrsearchVo.setWhereClause(null);
                HdrsearchVo.clearCache();
                HdrsearchVo.setWhereClause(HdrsearchQuery);
                HdrsearchVo.executeQuery();
            }
            else {
                HashMap hmap = new HashMap();
                hmap.put("HdrwhereClauseQ",null);
                hmap.put("LinewhereClauseQ",null);
                hmap.put("ToPage",null);
                pageContext.forwardImmediatelyToCurrentPage(hmap,false,null);   
            }
//              
        }
    }

In Process request attach the following code
    /**
     * Layout and page setup logic for a region.
     * @param pageContext the current OA page context
     * @param webBean the web bean corresponding to the region
     */
    public void processRequest(OAPageContext pageContext, OAWebBean webBean) {
        super.processRequest(pageContext, webBean);
        OAApplicationModule am = pageContext.getApplicationModule(webBean);
        if (pageContext.getSessionValue("retainAMValue") != null ) {
            System.out.println("Retain AM Value 
::"+pageContext.getSessionValue("retainAMValue").toString());

   if(!("Y".equalsIgnoreCase(pageContext.getSessionValue("retainAMValue").toString()))) {
                am.invokeMethod("rollbackTxn");
                if (pageContext.getParameter("HdrwhereClauseQ") != ""  &&  pageContext.getParameter("HdrwhereClauseQ")  != null)
                whereClause = pageContext.getParameter("HdrwhereClauseQ");
                /* Refresh the page with master VO */    
                Serializable param[] = {whereClause};
                am.invokeMethod("initHdrSearchVO",param);
                
                if ("CurrPage".equalsIgnoreCase(page)) {
                     /* Once master VO is initialized then invoke procedure 
                        to initialize detail VO */  
                     pageContext.putParameter("searchHdrLine","N");
                     showMasterDetail (pageContext,webBean,am);
                     System.out.println("Page Status :"+page);
                }
            }
            else {
                Serializable param[] = {whereClause};
                am.invokeMethod("initHdrSearchVO",param);
            }
        }
        else {
            Serializable param[] = {whereClause};
            am.invokeMethod("initHdrSearchVO",param);
        }
     
    }
  In process form request handle the event
    /**
     * Layout and page setup logic for a region.
     * @param pageContext the current OA page context
     * @param webBean the web bean corresponding to the region
     */
   public void processFormRequest(OAPageContext pageContext, OAWebBean webBean) {
        super.processFormRequest(pageContext, webBean);
      /*Check search button pressed */      
      if(pageContext.getParameter(“SearchBtn”) != null )
      {
         /*Populate header and detail table*/
          showMasterDetail(pageContext, webBean, am);
      }
  }

/*******************************************************************************
Note:  initHdrSearchVO is master view object holding department details
And LinesearchVo is detail view object holding employee details. You may change the naming conventions according to standards. Here I have put deptno, department and location as search criteria from master table and empno and name and job from detail table.
*******************************************************************************/

Cheers !!!!

  

Quality Cost and Delivery - Oracle Purchasing


Hello Friends,

This is another blog, sharing with you guys more informative and quite useful for you hopefully. :)

Well this is one feature we have discovered while working in oracle purchasing. 
Just finish of one implementation and got chance to share this nice concept with you. 

First of all, I would like to thank my friends Kedar Deshpande and Amit Agarwal - Oracle apps experts who are the thought worker of this concept. 

To begin with 
This topic is about identifying best supplier based on 3 factors (Quality, cost and Delivery)

Concept

Supplier Quality Cost and Delivery (Acronym SQCD or QCD). Functionality is to identify best supplier based its transaction history on 3 factors

1)   How Cost effective material provided,
2)  How was Quality of a material on basis of material rejection ratio during GRN. If collection plan is attached to material then based on material specifications provided by supplier; Material is inspected during GRN and accepted by organization.
3)   And Material Delivered on specified need by date including date tolerance. 

Along with these, we can also include how much maximum Credit limitwith no of days provided by Supplier.
This will help buyer to have deal with effective supplier(s) and based on that supplier ranking will be decided and accordingly sourcing rule/assignment will be created and/or updated.   
This would be useful for auto sourced orders where supplier will be referenced from sourcing rule. Currently sourcing rule is manually maintained by buyer. Even if certain supplier agreement is over then buyer needs to manually disable sourcing assignment.

Before placing PO/agreement with supplier buyer has to consider these factors which is very well possible with the help of SQCD.

Scope includes based on cost, quality and delivery transactions against supplier(s), to show best supplier for particular item and decide supplier rankings and material distribution (i.e. Allocation %) and give facility to buyer to create/update the sourcing rule/ assignment based on supplier suggestion matrix populated as SQCD result.

EBS Gap

In Standard Oracle Applications, the Sourcing rules/assignments more over deciding best supplier is managed manually by the buyer. 

Even if certain supplier agreement is over then buyer needs to manually disable sourcing assignment.

Before placing PO/agreement with supplier buyer has to consider QCD factors which is very well possible with the help of SQCD.

Impacts to Processes

With this customization in place, Buyer can able to decide good vendor amongst list.
When Buyer raises sourcing RFQ, requesting for particular item distributes to suppliers and suppliers then responds with quotation incl. cost. Here buyer only gets visibility of current RFQ and its quotation but does not aware of RFQs/PO/BPAs raised earlier for the same material and supplier.

SQCD will help buyer to have deal with effective supplier(s) and based on that supplier ranking will be decided and suggestion will be given to buyer that includes list of suppliers with current material distribution, suggested material distribution (calculated), Probable Ranking and accordingly buyer will have option to create/update sourcing rule.  

Business Rules

This function will capture existing material transactions; along with suppliers and its material delivery ratio for given need by date.
Based on inputs, SQCD function will give suggestion distribution matrix then buyer will decide to go with that suggestion or will update required material distribution manually in sourcing rule/assignment 

·   Input to SQCD function will be
§  Inventory Organization
§  Item
§  Date range - Date from:
                                               Date To:
§  Delivery weightage (%)
§  Quality weightage (%)
§  Cost weightage (%)
·     Total of QCD parameters should be equals to 100%

·      Function will look for received quantity, rejected quantity, return quantity, correction quantity, accepted quantity for each material shipment from PO/releases.

·      Calculate total and actual correction quantity, total and actual acceptance quantity, total and actual delivery quantity 

·      Calculate QCD values.

Delivery_Performance = (100 *(delivery_receive_qty/ord_qty) * Delivery_Weightage)/100

Quality_Acceptance = (100 - (100*(reject_qty/receive_qty))* Quality_Weightage)/100

Price_Effectiveness = (100 - (100*(avg_price/total_avg_price))* Price_Weightage)/100

Composite_Score = Delivery_Performance + Quality_Acceptance      + Price_Effectiveness

·         Supplier ranking will be decided based on composite score
·         Function outputs below material distribution matrix

§  Current Distribution       (Already existing distribution in Sourcing rule)
§  Suggested Distribution (Distribution suggested by the SQCD form)

§  Required Distribution     (The buyer can manually change the distribution)