previous

Importing Membership Transactions

Automating upload of Membership Transactions

The purpose of this topic is to describe the process of setting up and maintaining an automated service to upload membership transaction records into the system.

Skills Required

  1. Basic Knowledge of dos commands and batch commands. These can also be referred in windows help.
  2. Basic knowledge of Oracle SQL loader. See Oracle Documentation for reference if required.
  3. Knowledge of setting up task in windows.

Components of the Process

There are 3 main Components of the process:

  1. Automated Service: The object of this service is to kick off the process at regular intervals. Although it can be configured in any desired way or program or script client requires but here we are just using windows (windows 2000) schedule task. It is an easy to setup and require no programming skills. It executes a batch (.bat) file which does the work.
  2. Oracle Sql Loader: Oracle Sql loader is a command line utility by Oracle with which a flat file can be uploaded into Oracle database. In this setup the command to evoke this utility is stored in a batch (.bat) file. By setting up the batch file correctly one can execute this command by automated service. The control file (.ctl) is configured to put data into a temporary table in the OPERA database.
  3. Oracle Package: A package in the database picks up the records uploaded in the temporary table and processes them. This package is also executed by a batch file using the Sql Plus utility.

Software Required

  1. Windows operating in which schedule task can be set up. For the steps below, we have used Windows 2000 as the operating system.
  2. Oracle 9i database client. This installs Oracle Sql Loader and Sql Plus utilities along with other required software to connect to the Oracle database. It is highly recommended not to use the sqlldr80.exe utility.

Steps to setup the process

Step A:

Unzip the file. It should create the following directory (folder) structure.

Note: The drive letter may be different.

Directory

Purpose

D:\mem_trx_upload

Root directory under which all the folders are organized.

D:\mem_trx_upload\badbox

This folder should contain files with extension .bad. These files are generated by Oracle Sql Loader for the records which it was not able to upload into database. Typically there should not be any files in this folder but incase there are some files then someone need to look into it why they failed.

D:\mem_trx_upload\code

This folder contains the required code like the batch file and control file and .sql file required for the operation. It also contains an output file called outrun.txt which contains output of the scripts run.

D:\mem_trx_upload\doc

This folder contains the documents.

D:\mem_trx_upload\inbox

This folder is where the user needs to copy the files which they want to upload.

D:\mem_trx_upload\logbox

This folder will contain the log files (.log) generated by Oracle Sql Loader. These logs will tell how many records were uploaded, how many failed and why.

D:\mem_trx_upload\outbox

After a file is uploaded, it will be moved in this folder from the inbox folder.

Step B:

Setup a Control file. A control file determines what will be uploaded from the flat file and in what format it will be uploaded, etc.

A sample control file (located in folder D:\mem_trx_upload\code\mem_trx_upload.ctl) is provided. You can edit this file to suite your requirements or create a new one in order to match the file format.

options(skip=1)

LOAD DATA

APPEND

INTO TABLE IMP_MEMTRX_TEMP

FIELDS TERMINATED BY "|" OPTIONALLY ENCLOSED BY '"'

TRAILING NULLCOLS

(

EXT_RESORT

,BATCH_ID

,SEQ_NO

,PMS_RESV_NO

,BEGIN_DATE

,MEMBERSHIP_TYPE

,MEMBERSHIP_CARD_NO

,TOTAL_BASE_POINTS

,TOTAL_BONUS_POINTS

,TOTAL_MISC_POINTS

,MEMBERSHIP_TRX_ID

,MEMBERSHIP_TRX_DATE

,IMPORT_DATE

,IMPORT_STATUS

,INTERFACE_ID

,RECORD_TYPE

,POINTS_CALCULATED_YN

,ADJUSTMENT_YN

,BILLING_GROUP

,BASE_BILLING_GROUP

,BONUS_BILLING_GROUP

)

CHAR

INTEGER EXTERNAL

INTEGER EXTERNAL

CHAR

DATE (8) 'YYYYMMDD'

CHAR

CHAR

INTEGER EXTERNAL

INTEGER EXTERNAL

INTEGER EXTERNAL

CONSTANT ""

CONSTANT ""

SYSDATE

CONSTANT "NEW"

CONSTANT "OXI-OPMS"

CONSTANT "OT"

CONSTANT "Y"

CONSTANT "Y"

CHAR

CHAR

CHAR

Note:

  1. The structure of control file should not be changed except position of the fields. All the fields in the control files are mandatory for processing membership transactions. Change the Interface id column.
  2. Batch id is not auto generated, so it is required in data file.

Step C:

Setup a Batch file. The batch file executes commands and invokes various utilities like Oracle Sql Loader and Sql Plus.

A sample batch file (located in folder D:\mem_trx_upload\code\mem_trx_upload.bat) is provided. You can edit this file to suite your requirements or create a new one. In this file, you may wish to change values marked in bold.

The assumption is that the files are located on drive D: and File to upload have extension .lst.

You may also have to give path of sqlplus if required.

cd D:\mem_trx_upload\code

ren outrun.txt outrun2.bak

echo on

echo '############################## Process start #############################' >> outrun.txt

date /t >> outrun.txt

time /t >> outrun.txt

dir D:\mem_trx_upload\inbox\*.lst /b >> outrun.txt

for %%f in (D:\mem_trx_upload\inbox\*.lst) do D:\oracle\product\10.2.0\client_1\BIN\sqlldr sqlldr userid= v46orsdev/v46orsdev@rkv46ors data=%%f control= mem_trx_upload.ctl errors=50000 log=%%f.log >> outrun.txt

for %%a in (D:\mem_trx_upload\inbox\*.lst) do xcopy %%a D:\mem_trx_upload\outbox /y /f >> outrun.txt

for %%a in (D:\mem_trx_upload\inbox\*.bad) do xcopy %%a D:\mem_trx_upload\badbox /y /f >> outrun.txt

for %%a in (D:\mem_trx_upload\inbox\*.log) do xcopy %%a D:\mem_trx_upload\logbox /y /f >> outrun.txt

for %%a in (D:\mem_trx_upload\inbox\*.lst) do del %%a /q >> outrun.txt

for %%a in (D:\mem_trx_upload\inbox\*.bad) do del %%a /q >> outrun.txt

for %%a in (D:\mem_trx_upload\inbox\*.log) do del %%a /q >> outrun.txt

D:\10gDS\bin\sqlplusw.EXE [oracle user]/[oracle pass]@[oracle service]@runme.sql

type daily_rejects_results.LST >> outrun.txt

date /t >> outrun.txt

time /t >> outrun.txt

echo '############################## Process End ###############################' >> outrun.txt

type outrun2.bak >> outrun.txt

del outrun2.bak /q

del daily_rejects_results.LST /q

__________________________________________________________________

Now, change the D:\mem_trx_upload\code\runme.sql.

Make the following changes to the runme.sql SCRIPT

1) Update the initialization below before executing the script:

imp_data.set_user('SUPERVISOR', 'XXXXXXX', 'CRO');

2) Deleting old records which are uploaded till last week.

trunc(sysdate) - 7 change number of days accordingly.

Step D:

Setup a service. Here is an example how to set up a service in Windows 2000 operating system.

Go to Start>Settings>Control Panel>Schedule Tasks>Add Schedule Task and run the wizard to setup a task and make to execute the .bat file. The service can be enabled or disabled as per requirement.

importing_membership_transactions_1

importing_membership_transactions_2

importing_membership_transactions_3

importing_membership_transactions_4

importing_membership_transactions_5

importing_membership_transactions_6

importing_membership_transactions_7

Usage

On daily basis the user should copy the flat file to be uploaded into inbox folder. The file should have .lst extension (however this can be changed in the .bat file ) and each file should have a unique file name so as not to overwrite older files. The schedule task will pick up this file and upload it into the OPERA database. Then it will move the file to outbox folder.

Maintenance

From time to time depending on the usage (say weekly) someone needs to look into to check if all records are getting uploaded and processed ok. Runme.sql script located in folder code is set to delete records successfully uploaded after a week.

Following tasks will need to be done

  1. Look in folder badbox. If there are some files there then some records did not get uploaded. Open this file to see what records did not make it to the database. Possible reasons can be wrong record format, Wrong date format, Special characters appearing in the file etc.
  2. If there is a .bad file the look under logbox to open .log file with the same name to see what error came. If there is no .bad file and log is ok then you can either delete the log files or move it to some other place for backup.
  3. Open the outrun.txt to see how the scripts ran and what the status of various records uploaded batch wise is. You can take backup of outrun.txt file under code folder in some other place. Delete the outrun.txt when not required. A very big outrun.txt file will slow down the process. It is very important to keep this file as small as possible.
  4. If some records are showing the status of error (see outrun.txt) in the database then you need to look in the errors to fix the problem. Errors can be viewed in column import_msg. On sql prompt, run the following to view the errors:

    /******************************************************************/

    Set line 1000

    Set pages 999

    Col resort format a20

    Col seq_no format a20

    Col import_msg format a200

    Spool result

    select batch_id,

    seq_no,

    import_date,

    resort,

    membership_type,

    membership_card_no,

    import_msg

    from imp_memtrx_temp

    where import_status = 'ERROR'

    order by batch_id desc

    /

    Spool off

    /*****************************************************************/