Jul 22, 2016

Java Transformation

Scenario 1:

We are having data from source as below

ENTHDR|1|3.0
ENCHDR|HCH||C-LAB|||||MEDITECH_10HCH|||XXXXXXXX|4.0
PERSON|||||||||||||||||0||||XXXXXXXXX||||||||||||||
ENCNTR||||||||||||0||||||||0|||||||||||||||||||||||||||||0||||||||||||||||0||||||||||||||0|0|||||

need to load the above unstructured data into different tables like ENTHDR,ENCHDR, PERSON and ENCNTR. For that we used java transformation


Step1: set the src 
file properties to tab delimited so that the whole row treated as a single column

Step 2: Use java transformation to split the data based on '|' symbol




sample java code:
String[] str=REC.split("\\|"); 
//for(String retval: REC.split("\\|"))
//for(int i=0; i
if (str.length>0) {o_FIELD_1 = str[0]; }
if (str.length>1) {o_FIELD_2 = str[1]; }
if (str.length>2) {o_FIELD_3 = str[2]; }
if (str.length>3) {o_FIELD_4 = str[3]; }
if (str.length>4) {o_FIELD_5 = str[4]; }
if (str.length>5) {o_FIELD_6 = str[5]; }
if (str.length>6) {o_FIELD_7 = str[6]; }
if (str.length>7) {o_FIELD_8 = str[7]; }
if (str.length>8) {o_FIELD_9 = str[8]; }
o_REC_TYPE=REC_TYPE;
generateRow();

Then after use router and load the data into respective fields based on rec_type (ENCHDR,PERSON...etc)

Note to get the REC_TYPE i used the following function SUBSTR(Data,1,INSTR(Data,'|',1,1)-1)


No comments:

Post a Comment