Sunteți pe pagina 1din 18

Overview:

This document explains the procedure & step-by-step approach for populating the legacy data
available in the form of flat files into Oracle Applications database tables. It also explains the steps
to be followed while uploading the file.

W H I T E PA P E R : P O P U L AT I N G C U S T O M O r a c l e
A p p l i c a t i o n s D a tab a s e Ta b l e F r o m D a ta F i l e s
Introduction: It would not be proper for the end users to use the ftp
A large number of business establishments are now interface for uploading files. Hence a web-based
increasingly moving from existing file based legacy interface is developed which allows the files to be
systems to Oracle Applications. In the process they uploaded. A shell script is developed which
need to transfer the data existing in the form of files automatically picks up the files and populates the
into the staging tables of the database. The data files database tables. This shell script is registered in
might be located in the client machines at different Oracle Application and run as a concurrent program.
locations.
Thus the data files have to be brought to oracle Steps To Be Followed For Installation:
application server from the Host. The data must now
01. JSP Registration –The JSP page has to be
be loaded into the staging tables of the database.
registered with Oracle Applications as a
From a security point of view, only registered users
function.
must be allowed to upload files on the application
02. Shell Script Registration: The shell script
server.
has to be registered with Oracle Application
as a concurrent program and scheduled to
Solution Area – A Case Study run at regular intervals.
Either of the following two methods can be 03. Set Up: The directory into which the files
followed: - are data files are downloaded should be the
1) The end user might ftp the data files into a same as the directory from which the shell
specified directory on the server. A shell script picks up the data files. To achieve
script need to be initiated (or scheduled at this result, a configuration file exists which
regular intervals) that will populate the holds the path of the common directory
database. where the files are to be uploaded. Thus in
2) The end user uploads the data file using a the configuration file, set the values of the
web-based interface. The data file is put in a directory, allowed extension of files to be
predefined directory. A shell script picks up uploaded and the type of files to be
the data files regularly and populates the uploaded. The configuration file is in
database tables. “keyword=value” form.

Consulting | eCommerce | Mobile Computing | New Technologies | Interactive Technologies


Enterprise Resource Planning | Supply Chain Management | Customer Relationship Management | Enterprise Application Integration
Business Intelligence | Knowledge Management
04. Directory Structure: The following users to read write and execute this
directory structure is required. A main directory as show below: -
directory as set in configuration file should chmod 777 Downloaded/
have the following subdirectories
Software:
a. Control: Place the control file here
b. Archives: Can be cleaned up from Oracle Applications running on Unix Platform.
time to time
c. BadFiles: The bad files generated Solution:
by the shell script are moved to this
After making the above setups we need to make sure
directory.
that the control file is syntactically correct and loads
d. Log: The log files generated by the
data into the appropriate tables of the database. Any
script are moved to this directory
of the error or log files generated are moved into the
e. Downloaded: This is the directory
appropriate bad and log directories.
where the files that are brought by
JSP script are placed. Therefore
change its permissions to allow all

Neha Gupta is an associate of Tata Consultancy Services Ltd. She can be reached at neh.gupta@tcs.com.

© 2006, Tata Consultancy Services Ltd.

Consulting | eCommerce | Mobile Computing | New Technologies | Interactive Technologies


Enterprise Resource Planning | Supply Chain Management | Customer Relationship Management | Enterprise Application Integration
Business Intelligence | Knowledge Management
Steps To Link JSP (HTML) Pages To Oracle Apps Form Menu

NB: (Any .html file need to be converted to .jsp file because through this method only jsp files
can be linked)

Let the file name be X.JSP.


1. Move X.JSP to the environment variable $OA_HTML which in my system is the local
directory
/u02/apps/viscomn/html

2. Go to the Application Developer Responsibility and create a function with some name
like FILE_UPLOAD
a. Go to the Property tab and set the
Type field = “SSWA jsp function”
Function type = “JSP”.
Maintenance Mode Support= “none”
Context Dependence= “Responsibility”.
b. In the Web HTML tab set HTML Call to name (relative path from $OA_HTML) of
the “jsp” page.
c. Save

3. Now attach the Function to the appropriate menu in the usual way.
Note: If the name of the file is incorrect or the file does not have the proper .jsp extension
the menu item may not be displayed.

Consulting | eCommerce | Mobile Computing | New Technologies | Interactive Technologies


Enterprise Resource Planning | Supply Chain Management | Customer Relationship Management | Enterprise Application Integration
Business Intelligence | Knowledge Management
Steps For Running File Upload

1. Copy the file load.conf to /etc/


2. Set the variables in load.conf as per requirement
3. In the directory mentioned in load.conf, create the following directories
a. Downloaded
b. Control
c. Archives
d. Log
e. BadFiles
4. Move the control file for sql loader to the Control directory.
5. Link the file “form.jsp” to any responsibility as mentioned above. Load the associated file
“LoadDataFile.jsp” into the same directory as form.jsp.
6. Register the Shell Script “populate.sh” as a concurrent program and schedule it to run
periodically.
The database will be populated.

Consulting | eCommerce | Mobile Computing | New Technologies | Interactive Technologies


Enterprise Resource Planning | Supply Chain Management | Customer Relationship Management | Enterprise Application Integration
Business Intelligence | Knowledge Management
Customization

In LoadDataFile.jsp

This is the file that actually does the transfer of the file from the client system to the server. The file is uploaded
to the directory mentioned in the variable DESTINATION_FOLDER. Change this variable to the appropriate folder
from where the shell script picks up the data files.

The variable REQ_EXT should be set to the extension of the file to be uploaded. It can be set to empty quotes “”
if file of any extension is to be allowed to upload.

Default Values:
DESTINATION_FOLDER = “/u02/apps/viscomn/html/mohan/Downloaded/"
REQ_EXT = “.dat”

In populate.sh

The following Variable has to be set.


Set the value of MAIN_DIRECTORY to some existing Directory or better create one for it.
The Description of the variables used is given below
MAIN_DIR
CONTROL_FILE : This is the path of the control file used by sql loader.
DATA_FILES_DIR: This is the directory where all the data files will be kept.
ARCHIVE_DIR: The files that have been processed by sqlloader are moved to this directory with a time stamp
appended to it.
LOG_DIR: The log files generated by sql loader are put into this directory.
BAD_DIR: The bad files generated by sql loader are put into this directory.

If you follow the following steps only the Variable MAIN_DIR has to be changed.

Thus create a new directory (say xyz) for populating the database and set its path in the variable MAIN_DIR.
Create the following sub directories in xyz
Control: Place the control file here
Archives: Can be cleaned up from time to time
BadFiles: The bad files generated by sql loader are moved to this place.
Log: The log files generated by sql loader are moved to this directory
Downloaded: This is the directory where the files that are brought by LoadDataFile.jsp are placed. Thus, change
its permissions to allow all users to read write and execute this directory as show below:

[applmgr@APPSTRAINING mohan]$ chmod 777 Downloaded/


Please note that the complete path of directory DOWNLOADED should be the value of the variable
DESTINATION_FOLDER in the file LoadDataFile.jsp

Consulting | eCommerce | Mobile Computing | New Technologies | Interactive Technologies


Enterprise Resource Planning | Supply Chain Management | Customer Relationship Management | Enterprise Application Integration
Business Intelligence | Knowledge Management
Screenshots

Figure 1: Creating a menu for file upload

Consulting | eCommerce | Mobile Computing | New Technologies | Interactive Technologies


Enterprise Resource Planning | Supply Chain Management | Customer Relationship Management | Enterprise Application Integration
Business Intelligence | Knowledge Management
Figure 2: Creating a function for the file upload

Consulting | eCommerce | Mobile Computing | New Technologies | Interactive Technologies


Enterprise Resource Planning | Supply Chain Management | Customer Relationship Management | Enterprise Application Integration
Business Intelligence | Knowledge Management
Figure 3: Setting the properties of the function for file upload

Consulting | eCommerce | Mobile Computing | New Technologies | Interactive Technologies


Enterprise Resource Planning | Supply Chain Management | Customer Relationship Management | Enterprise Application Integration
Business Intelligence | Knowledge Management
Figure 4: Setting the .jsp to be called by the function for file
upload

Consulting | eCommerce | Mobile Computing | New Technologies | Interactive Technologies


Enterprise Resource Planning | Supply Chain Management | Customer Relationship Management | Enterprise Application Integration
Business Intelligence | Knowledge Management
Figure 5: Form for file upload in the web browser

Consulting | eCommerce | Mobile Computing | New Technologies | Interactive Technologies


Enterprise Resource Planning | Supply Chain Management | Customer Relationship Management | Enterprise Application Integration
Business Intelligence | Knowledge Management
Figure 6: Output screen on successful file upload

Consulting | eCommerce | Mobile Computing | New Technologies | Interactive Technologies


Enterprise Resource Planning | Supply Chain Management | Customer Relationship Management | Enterprise Application Integration
Business Intelligence | Knowledge Management
Figure 7: Unix Server screen for set ups for file upload

Consulting | eCommerce | Mobile Computing | New Technologies | Interactive Technologies


Enterprise Resource Planning | Supply Chain Management | Customer Relationship Management | Enterprise Application Integration
Business Intelligence | Knowledge Management
Populate.sh
#!/bin/bash

MAIN_DIR=/u02/apps/viscomn/html/mohan
CONTROL_FILE=$MAIN_DIR/Control/trans.ctl
#Control file path name and remains fixed through out.
DATA_FILES_DIR=$MAIN_DIR/Downloaded
#Data files are downloaded here before populating transactions.
ARCHIVE_DIR=$MAIN_DIR/Archives
#Data files are moved here after populating transactions.
LOG_DIR=$MAIN_DIR/Log
#Log files created by sqlldr are kept hin this directory.
BAD_DIR=$MAIN_DIR/BadFiles
#Bad files generated by sqlldr are put here.

cd $DATA_FILES_DIR
echo `pwd`
for file in *.dat
do
BASENAME=`echo $file | cut -d'.' -f1`
DATE=`date +%F`
DATAFILE=${DATA_FILES_DIR}/${BASENAME}.dat
ARCHIVEFILE=${ARCHIVE_DIR}/$DATE-${BASENAME}.dat
LOGFILE=${LOG_DIR}/$DATE-${BASENAME}.log
BADFILE=${BAD_DIR}/$DATE-${BASENAME}.bad
echo Data File:$DATAFILE
echo Archive File:$ARCHIVEFILE
echo Log File:$LOGFILE
echo Bad File:$BADFILE

echo `/u02/apps/visora/8.0.6/bin/sqlldr apps/apps@vis control=$CONTROL_FILE


data=$DATAFILE bad=$BADFILE log=$LOGFILE`

if [ $? = 0 ]
then
echo "$? Sqlldr successful"
else
echo "$? sqlldr failed"
fi
#mv $DATAFILE $ARCHIVEFILE
done #End of for.
#The above for loop gets each of the data files kept in the server
#directory and populates transactions using them. After populating
#the transactions, it moves each of the data files to the archive
#directory.

Consulting | eCommerce | Mobile Computing | New Technologies | Interactive Technologies


Enterprise Resource Planning | Supply Chain Management | Customer Relationship Management | Enterprise Application Integration
Business Intelligence | Knowledge Management
LoadDataFile.jsp
<%
final String configFile = "/etc/load.conf"; <!Setting path for configuration file!>
String dirPath="";
String fileType="";
String fileExt="";
try{ <!Reading from configuration file!>
String line = "";
BufferedReader conf = new BufferedReader(new FileReader(configFile));
while( (line=conf.readLine())!=null)
{
if(line.startsWith("#"))
continue;
else if(line.startsWith("Directory")) <!Getting Directory path from config file!>
dirPath=line;
else if(line.startsWith("File_Type"))
fileType=line; <!Getting file type from config file!>
else if(line.startsWith("Extension"))
fileExt=line; <!Getting file extension from config file!>

}
conf.close();
}catch(Exception e){ out.println(e.toString());}
dirPath=dirPath.substring("Directory=".length(),dirPath.lastIndexOf("/")+1);
fileType=fileType.substring("File_Type=".length(),fileType.length());
fileExt=fileExt.substring("Extension=".length(),fileExt.length());
final String DESTINATION_FOLDER = dirPath.substring(0,dirPath.lastIndexOf("/"))+"/Downloaded/";
<!Setting file path!>
String err = "";
String lastFileName = "";
String s2;
String code="";
String ext="";
String contentType = request.getContentType(); <!Setting content type!>
String boundary = "";
final int BOUNDARY_WORD_SIZE = "boundary=".length();
if(contentType == null || !contentType.startsWith("multipart/form-data")) {
err = "Ilegal ENCTYPE : must be multipart/form-data\n";
err += "ENCTYPE set = " + contentType;
}else{ <!Setting boundary size!>
boundary = contentType.substring(contentType.indexOf("boundary=") + BOUNDARY_WORD_SIZE);
boundary = "--" + boundary;
try { <!Parsing Input Stream from the data file!>
javax.servlet.ServletInputStream sis = request.getInputStream();
byte[] b = new byte[1024];
int x=0;
int state=0;
String name="",fileName="",contentType2="";
java.io.FileOutputStream buffer = null;
while((x=sis.readLine(b,0,1024))>-1) {
String s = new String(b,0,x);
if(s.startsWith(boundary)) {
state = 0;

Consulting | eCommerce | Mobile Computing | New Technologies | Interactive Technologies


Enterprise Resource Planning | Supply Chain Management | Customer Relationship Management | Enterprise Application Integration
Business Intelligence | Knowledge Management
name = null;
contentType2 = null;
fileName = null;

}
else if(s.startsWith("Content-Disposition") && state==0)
{
state = 1;
if(s.indexOf("filename=") == -1)
{
name = s.substring(s.indexOf("name=") + "name=".length(),s.length()-2);
}
else
{
name = s.substring(s.indexOf("name=") + "name=".length(),s.lastIndexOf(";"));
fileName = s.substring(s.indexOf("filename=") + "filename=".length(),s.length()-2);
if(fileName.equals("\"\""))
fileName = null;
else
{
String userAgent = request.getHeader("User-Agent");
String userSeparator="/"; // default
if (userAgent.indexOf("Windows")!=-1)
userSeparator="\\";
if (userAgent.indexOf("Linux")!=-1)
userSeparator="/";
fileName =
fileName.substring(fileName.lastIndexOf(userSeparator)+1,fileName.length()-1);
if(fileName.startsWith( "\""))
fileName = fileName.substring( 1);
}
}
name = name.substring(1,name.length()-1);
if (name.equals("uploadfile"))
{
if (buffer!=null)
buffer.close();
lastFileName = fileName;
if(fileName==null || code==null)
{
out.println("<b><br>Both the fileName and code have to be
mentioned</b>");
throw new java.lang.NullPointerException();
}
ext=fileName.substring(fileName.lastIndexOf("."));
if(fileExt.indexOf(ext.substring(1))==-1)
{
out.println("<b><br>Files of this Extension are not allowed</b>");
throw new java.lang.NullPointerException();
}
buffer = new
java.io.FileOutputStream(DESTINATION_FOLDER+fileName.substring(0,fileName.lastIndexOf(".")) +
code.substring(0,code.length()-2)+ext );
}

Consulting | eCommerce | Mobile Computing | New Technologies | Interactive Technologies


Enterprise Resource Planning | Supply Chain Management | Customer Relationship Management | Enterprise Application Integration
Business Intelligence | Knowledge Management
}
else if(s.startsWith("Content-Type") && state==1)
{
state = 2;
contentType2 = s.substring(s.indexOf(":")+2,s.length()-2);
if(fileType.indexOf(contentType2)==-1)
{
out.println("<br><b>Bad File Type: "+contentType2+" are not allowed</b>");
throw new NullPointerException();
}
}
else if(s.equals("\r\n") && state != 3)
{
state = 3;
}
else
{
if (name.equals("uploadfile"))
{
s2= new String(b,0,x);
buffer.write(b,0,x);
}
if (name.equals("code"))
{
code= new String(b,0,x);
}

}
out.println("File " + lastFileName + " uploaded Successuflly"); <!File Upload complete!>
}catch(NullPointerException e){
String
sp="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
out.println("<br>Please Note:<br>");
out.println("<br>"+sp+" 1. File Types Allowed: "+fileType);
out.println("<br>"+sp+" 2. File Extensions Allowed: "+fileExt);
}catch(Exception e){out.println("<br>Error: " + e.toString());}
}
%>

Consulting | eCommerce | Mobile Computing | New Technologies | Interactive Technologies


Enterprise Resource Planning | Supply Chain Management | Customer Relationship Management | Enterprise Application Integration
Business Intelligence | Knowledge Management
Load.conf
#This file has to be saved in "/etc/" directory
#Insert the path of the directory where the program is to run
Directory=/u02/apps/viscomn/html/mohan/
#The kind of files to be uploaded is controlled below. For normal text files the default values are good
enough.
File_Type=text/plain application/octet-stream
#Only files with the following extensions will be uploaded to the server
Extension=dat bad
#End of file

Consulting | eCommerce | Mobile Computing | New Technologies | Interactive Technologies


Enterprise Resource Planning | Supply Chain Management | Customer Relationship Management | Enterprise Application Integration
Business Intelligence | Knowledge Management
Form.jsp

<html>
<head>
</head>
<body>
<script>
<! Function to verify the code of the file and its selection for uploaded !>
function Verify(){
temp = document.forms['upform'].elements['code'].value;
if(temp==null || temp.length==0){
alert("Enter a Mcc Code before you uploading a file ");
return false;
}
temp = document.forms['upform'].elements['uploadfile'].value;
if(temp==null || temp.length==0){
alert("Enter a file name before you can upload it");
return false;
}
return true;
}
</script>
<! Settings for front end display for the upload form !>

<form method="post" action="LoadDataFile_v5.jsp" name="upform" enctype="multipart/form-data"


onsubmit="return Verify()">
<table width="60%" border="0" cellspacing="1" cellpadding="1" align="center" class="style1">
<tr>
<td align="left"><b>Enter the MCC Code of the Milk Center :</b></td>
</tr>
<tr>
<td>
<input type="text" name="code">
</td>
</tr>
<tr>
<td align="left"><b>Select a file to Upload :</b></td>
</tr>
<tr>
<td align="left">
<input type="file" name="uploadfile" size="50">
</td>
</tr>
<tr>
<td align="left">
<input type="hidden" name="todo" value="upload">
<input type="submit" name="Submit" value="Upload" >
<input type="reset" name="Reset" value="Reset ">
</td>
</tr>
</table>
</form>
</body>
</html>

Consulting | eCommerce | Mobile Computing | New Technologies | Interactive Technologies


Enterprise Resource Planning | Supply Chain Management | Customer Relationship Management | Enterprise Application Integration
Business Intelligence | Knowledge Management

S-ar putea să vă placă și