cancel
Showing results for 
Search instead for 
Did you mean: 

How to read Flat File and send to mulitple fields

former_member350687
Participant
0 Kudos

Hi All,

I am trying to read a flat file which is seperated by "|" in to once Recoed set and then split it to different fields.

Can you help me by giving UDF to read this strucure.

Below are the deatils.

Source File:

1173|2524457A|07/27/2013|USD|UNILEVER HPC EXECUTIVE MATTERS Unilever/HPC Executive Matters|500.00|2611=1000010045|=12107001|=|500.00|

1173|1038246A|08/08/2013|USD|IOS Litigation|1000.00|2611=1000010045|=12107001|=|500.00|2611=1000010200|=12107002|=|250.00|2611=1000010100|=12107006|=|250.00|

Accepted Solutions (0)

Answers (6)

Answers (6)

Former Member
0 Kudos

HI Mahi,

Try this code, will read the particular string in complete line by giving the N`th position of the '|' symbol.

public String StrPosition(String var1, int N, Container container) throws StreamTransformationException{

int count=0;
String str="";
N = N - 1;
for(int i=0;i<var1.length();i++)
{
if(var1.charAt(i)=='|')       count++;
if(count==N)
{
    if(var1.charAt(i)!='|')
    str=str+var1.charAt(i);
     }
if(count==(N+1))
break;
}

return str+"";

}

Thanks,

Dhileep.

Former Member
0 Kudos

Hi Mahi,

I assume you have a specific delimiter and a line separator (may be 'nl'). You can use FCC to incorporate your requirement.

If you have identified keyfields in your structure, you can post your fields accordingly in the header & line structure.

However, what do you mean by set of charater. Could you please elaborate on this?

Regards,

Akshay

Former Member
0 Kudos

Hi Mahi,

It is suggested to use File content conversion for splitting records based on delimiter.

If there is no control record to be mentioned for Header and Line Item, I suggest you to use FCC to split fields into single hierarchy structure and then map fields to Header, Line_Item node based on some condition.

Are you looking to add any specific condition for splitting at mapping step.

Regards,

Pranav

Former Member
0 Kudos

Hi Mahi,

Import your flat file using the below function module.

Sample code:

CALL FUNCTION 'GUI_UPLOAD'

       EXPORTING

         filename                = ls_filename     "your file name

         filetype                = 'ASC'

         has_field_separator     = lc_x

         read_by_line            = lc_x

       TABLES

         data_tab                = gt_filedata.      "internal table built with the fields you need

     

Loop your internal table 'gt_filedata' and split by '|'.

ex.

split gt_filedata at '|' into (your work area)


Try this. It will help you.


Regards,

Swadini Sujanaranjan

Former Member
0 Kudos

Hi Mahi,

You mean to say you are reading a | separated file line by line and then in mapping you want to split the fields using your own logic ?

can u explain how do want to split in mapping ,so that i can help you on this.

Regards

Venkat

former_member350687
Participant
0 Kudos

Hi Venkat,

Yes

former_member184720
Active Contributor
0 Kudos

Hi Mahi - Why don't you handle it in the content conversion? But for some reason if you would like to handle in the mapping then refer to below screenshots.

former_member350687
Participant
0 Kudos

Hi Hareesh,

Above logic is working only for one charater, it is reading only one character.

But my input contains set of character.

Input: 1173|2524457A|07/27/2013|USD|HPC EXECUTIVE MATTERS /HPC Executive Matters|500.00|2611=1000010045|=12107001|=|500.00|

Please help me on above issue.

Thanks & Regards,

Madhavi.G

former_member184720
Active Contributor
0 Kudos

Hi Madhavi - What do you mean by one char? it works for the whole set

Did you test?

You have to change the constant value for each field..

0,1,2 etc..

Bhargavakrishna
Active Contributor
0 Kudos