cancel
Showing results for 
Search instead for 
Did you mean: 

File Content Conversion

former_member188791
Participant
0 Kudos

Hi Group,

Can any body help with the File content conversion in ID for the below example:

Source File

---------------

H,1844567891234,123456789,FF,ACK

M,1833444235678,345343434,0.51,0,51,0.51,0.51,0.51,,,,,

G,183344

4235677,123,0.51,0,51,0.51,,,,,,

R,1833444235679,123234,0.51,0,51,0.51,,

Output

-----------------

<Record>

<Type>M</Type>

<CID>1833444235678</CID>

<MID>345343434</MID>

<Type>0.51,0,51,0.51,0.51,0.51,,,,,</Type>

</Record>

<Record>

<Type>G</Type>

<CID>1833444235677</CID>

<MID>123</MID>

<Type>0.51,0,51,0.51,,,,,,</Type>

</Record>

<Record>

<Type>R</Type>

<CID>1833444235679</CID>

<MID>123234</MID>

<Type>0.51,0,51,0.51,,</Type>

</Record>

Accepted Solutions (0)

Answers (2)

Answers (2)

anupam_ghosh2
Active Contributor
0 Kudos

Hi Rajiv,

            When the number of entries in a line is too many, FCC becomes complex.

In such situation try very simple FCC convert file contents into XML row wise. Then you can have an java mapping/UDF to extract individual elements in target XML. Thus if your file is comming as

H,1844567891234,123456789,FF,ACK

M,1833444235678,345343434,0.51,0,51,0.51,0.51,0.51,,,,,

G,183344

4235677,123,0.51,0,51,0.51,,,,,,

R,1833444235679,123234,0.51,0,51,0.51,,

try converting it to something like this

<mt_src>

    <row>H,1844567891234,123456789,FF,ACK</row>

    <row>M,1833444235678,345343434,0.51,0,51,0.51,0.51,0.51,,,,,</row>

    <row>G,183344</row>

    <row>4235677,123,0.51,0,51,0.51,,,,,,<row>

     <row>R,1833444235679,123234,0.51,0,51,0.51,,<row>

</mt_src>

Now use java mapping/UDF to convert this structure to required target structure.

Regards

Anupam

former_member184681
Active Contributor
0 Kudos

Hi Anupam,

>>> When the number of entries in a line is too many, FCC becomes complex

I don't really agree that this is enough reason to give up FCC and go for Java mapping - which in fact would also be complex . This is what FCC was made for: so that you wouldn't have to use Java pre-mappings for flat file scenarios. Still, in certain cases (especially where FCC is not enough, since I agree its functionality is limited) reading a file line by line is a good (or the only feasible) idea.

Regards,

Greg

anupam_ghosh2
Active Contributor
0 Kudos

Hi Greg,

              Perhaps I could not make my point clear. If the target XML to which we are trying to map each line of the file, is complicated, and too many XML sub levels are present, then its better to go for java mapping. In thoses cases also, we need initial FCC so that there is an XML input to java mapping.

Its upto the programmer to decide on case to case basis. In the present case you wrote this

"Such conversion isn't really possible with FCC, because:"  thus that was my idea of cracking the problem. At the end of the day we have to come out with a solution. FCC should be the first option but instead of wasting lot of time in figuring it out we need to progress to meet the project deadline.

Regards

Anupam 

former_member184681
Active Contributor
0 Kudos

Agreed. It all depends on the circumstances and the developer himself .

former_member188791
Participant
0 Kudos

Hi Anupam,

Thank you for your reply,I agree with your approach writing in to simple row,but JAVA how we can separate these tags because here length is varying for CID and MID fields ,can you please suggest.

former_member184681
Active Contributor
0 Kudos

Dear Rajiv,

You can do this in two different ways:

1. If you know the maximum row length (300 characters here):

Recordset Structure = row,*

ignoreRecordsetName = true

row.fieldNames = row

row.fieldFixedLengths = 300

row.keepIncompleteFields = YES

row.endSeparator = 'nl'

2. Based on the endSeparator 'nl' and fieldSeparator 'nl':

Recordset Structure = row,*

ignoreRecordsetName = true

row.fieldNames = row

row.fieldSeparator = 'nl'

row.endSeparator = 'nl'

Regards,

Greg

anupam_ghosh2
Active Contributor
0 Kudos

Hi Rajiv,

               In java mapiing first obtain each row in a string. Say for example each row of string you obtain is String s="M,1833444235678,345343434,0.51,0,51,0.51,0.51,0.51,,,,,";

Now get each field of the string which is separeted by comma into an array of string, thus

String a[]=s.split(",");

thus you obtain this

a[0]="M",

a[1]="1833444235678"  //CID

a[2]="345343434" //MID

so on and so forth. Last few elements will have no values in them as per example string.

Each line of the file will have same number of commas.  Using DOM parser you can create a target XML and put these values in appropiate target.   In the sample data you showed one line as

G,183344

4235677,123,0.51,0,51,0.51,,,,,,

this should have come as 

G,183344,4235677,123,0.51,0,51,0.51,,,,,,

Lines should not come broken. This you have to ensure from sender side.( Else check if each line begins with an alpahabet such as H ,M ,G,R etc. If a line is not begining with an alphabet concatenate with previous line.)

About how to create the target XML structure using DOM Pls check my response to your thread

http://scn.sap.com/message/13409162

I have assumed you have fair amount of experience in programming with Java, thus this should not be difficult for you.

About FCC   Greg has already proposed a solution. Please try it out.

 

Regards

Anupam 

MichalKrawczyk
Active Contributor
0 Kudos

Hi,

>>>Can any body help

what have you tried already?

Regards,

Michal Krawczyk

former_member188791
Participant
0 Kudos

Hi Michal,

Here I am attaching FCC:

Recordset Structure         :Header,*Record,*

Record.fieldNames          :Type,CID,MID,Type1

Record.keyFiieldValue     : M

Record.fieldFixedLength  : 1,14,11,300

Record.fieldSeparator      :,

former_member184681
Active Contributor
0 Kudos

Hi Rajiv,

Such conversion isn't really possible with FCC, because:

1. You have multiple key field values for the same target node.

2. Field fixed lengths cannot be used, since for instance "MID" field value has variable length.

3. Field separator cannot be used either, because commas also appear in the last expected field.

However, you can try to get really close to your expected structure, with the following set of parameters (assuming that MID lengths are constant for each key field value):

Recordset Structure:     Header,*,RecordM,*,RecordG,*,RecordR,*

Key Field Name:     Type

RecordM.fieldNames:     Type,CID,MID,Type1

RecordM.keyFieldValue:     M

RecordM.fieldFixedLength:     1,13,9,300

RecordM.keepIncompleteFields:     YES

RecordG.fieldNames:     Type,CID,MID,Type1

RecordG.keyFieldValue:     G

RecordG.fieldFixedLength:     1,13,3,300

RecordG.keepIncompleteFields:     YES

RecordR.fieldNames:     Type,CID,MID,Type1

RecordR.keyFieldValue:     R

RecordR.fieldFixedLength:     1,13,6,300

RecordR.keepIncompleteFields:     YES

Regards,

Greg