Documente Academic
Documente Profesional
Documente Cultură
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.
Neha Gupta is an associate of Tata Consultancy Services Ltd. She can be reached at neh.gupta@tcs.com.
NB: (Any .html file need to be converted to .jsp file because through this method only jsp files
can be linked)
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.
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
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:
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
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.
}
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;
}
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 );
}
}
out.println("File " + lastFileName + " uploaded Successuflly"); <!File Upload complete!>
}catch(NullPointerException e){
String
sp=" ";
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());}
}
%>
<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 !>