Hello,
I have to write a script to compare the sum of the amounts in a data file and the amount field value in an another file.
there is a table in which I have the list of source system name, source files and amount field names etc. Below is the data for a source system. "ABZ" has to be passed a parameter to the script.
PHP Code:
Query:
select Source_sys_name,Source_file_name,amount_field_names from source_sys_det where Source_sys_name='ABZ'
Result:
Source_sys_name,Source_file_name,amount_field_names
ABZ,SALES,sales_amount|cost_price|profit|Loss
(there are many source files for ABZ, but for an example I have mentioned only SALES here)
in the output above, in column 3, there are 4 fields - sales_amount|cost_price|profit|Loss which are amount field names. this means the source file ABZ_SALES has amount values in these 4 fields and we have to compare the amount values in a file with the source file ABZ_SALES available in a unix directory based on the field names in both the files.
Source file ABZ_SALES has 9 columns. the first line in the file is header and it is a pipe delimited file.
PHP Code:
cat ABZ_SALES:
sales_amount|cost_price|profit|Loss|state
10|12|13|30|ca
12|3|4|42|mn
Now, we have the list of amount fields names and the values of them in the source file, ABZ_SALES.
Below is the trigger file which will be sent everyday along with the source file mentioned above.
Below is the content of the trigger file for ABZ:
PHP Code:
cat ABZ_Trigger_file
SALES
sales_amount in total-22
cost_price in total-15
profit in total-17
loss in total-72
INVENTORY
a in total-200
b in total-108
c in total-1009
e in total-2007
d in total-120
f in total-304
In the file above, under SALES section, you can see the total for the individual amount fields. this amount should be compared with the amount in the ABZ_SALES file (for column sales_amount, as per ABZ_Trigger_file amount is 22 and in the ABZ_SALES file, sum the amount for the sales_amount field which is 10+12 and it is equal to 22 in the ABZ_Trigger_file file. If the amounts don't match, then it has to be written to a error_file and the comparison to proceed for other columns until all the column comparison are done until the loss column.
Similar to the source file SALES this comparison has to be done for INVENTORY also. and this has 2 amount fields, 3 weight fields and 1 unit field. like wise, a source system ABZ can contain multiple source files which is dynamic.
EMC source system has 5 files. and each of these files have amount fields, weight fields and unit fields in different locations and have to be compared and if the comparison fails, it has to be written to an error file else the script will complete successfully.
For INVENTORY:
PHP Code:
Query:
select Source_sys_name,Source_file_name,amount_field_names, from source_sys_det where Source_sys_name='ABZ' and
Source_file_name='INVENTORY'
Result:
Source_sys_name,Source_file_name,amount_field_names
ABZ,INVENTORY,a|b
thanks