cancel
Showing results for 
Search instead for 
Did you mean: 

Extract Field from file

Former Member
0 Kudos

Hai Experts,

I have a scenario in which i am collecting IDOCS(900-1000 number) in the form of a file (as given in Steffans Blog).

File adapter picks up this file and posts this file to target.

My requirement is to extract a field value from this file .This field value is unique for all the 900-1000 IDOCs collected(into the file).Before posting the file at target i have to add this field as a header to the file.

for eg:if all the IDOCs collected has a unique field called ACKKEY and has a value PET500, my target file should have the header field at top as

ACKKEY:PET500

followed by the contents of the field.

Should i write a user defined function for this?or is there any other way?

If i have to write any user defined function for this what is it to be(i dont know much about how to write java code)?

I will award points for sure

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

HI Anoop

If you can share how the header and items look like and what are the values you are expecting we can work on the UDF for the same..

Yes you can pass the value without using UDF also to the field which is not in header while mapping to target.

Thanks

Gaurav.

Former Member
0 Kudos

HI Gaurav/Bavesh

The target file should look like below

THE ACKKEY FOR CURRENT EMPLOYEE : PET500

EMPLOYEE ID FOR CURRENT EMPLOYEE :DET2098

DEPARTMENT VALUE FOR CURRENT EMPLOYEE :TP234

<?xml version="1.0" encoding "UTF-8"?>

<EMPLOYEE>

<ACKKEY>PET500</ACKKEY>

<EMPID>DET2098</EMPID>

<DEPTVALUE>TP234</DEPTVALUE>

<EMPNAME>RONALD</EMPNAME>

<CITY></CITY>

<DRUN></DRUN>

<PINCODE></PINCODE>

...............................

................................

</EMPLOYEE>

<EMPLOYEE>

<ACKKEY>PET500</ACKKEY>

<EMPID>DET2098</EMPID>

<DEPTVALUE>TP234</DEPTVALUE>

<EMPNAME></EMPNAME>

<CITY>LONDON</CITY>

<DRUN>TR5D</DRUN>

<PINCODE></PINCODE>

..................................

..................................

</EMPLOYEE>

and so on.

In First IDOC EMPNAME is present and in second there are values for CITY and DRUN

Thus each IDOC though contains all the segments will contain value for only a few segments in each of them.But there are fields like ACKKEY,EMPID,DEPTVALUE which is unique and repeats in each of the IDOC. These three fields clearly distinguishes one employee details from the other.This is my target file structure.Can i have a UDF for making such a file and steps to be followed.

Sorry for late reply.

Former Member
0 Kudos

HI Gaurav/Bavesh

The target file should look like below

THE ACKKEY FOR CURRENT EMPLOYEE : PET500

EMPLOYEE ID FOR CURRENT EMPLOYEE :DET2098

DEPARTMENT VALUE FOR CURRENT EMPLOYEE :TP234

<?xml version="1.0" encoding "UTF-8"?>

<EMPLOYEE>

<ACKKEY>PET500</ACKKEY>

<EMPID>DET2098</EMPID>

<DEPTVALUE>TP234</DEPTVALUE>

<EMPNAME>RONALD</EMPNAME>

<CITY></CITY>

<DRUN></DRUN>

<PINCODE></PINCODE>

...............................

................................

</EMPLOYEE>

<EMPLOYEE>

<ACKKEY>PET500</ACKKEY>

<EMPID>DET2098</EMPID>

<DEPTVALUE>TP234</DEPTVALUE>

<EMPNAME></EMPNAME>

<CITY>LONDON</CITY>

<DRUN>TR5D</DRUN>

<PINCODE></PINCODE>

..................................

..................................

</EMPLOYEE>

and so on.

In First IDOC EMPNAME is present and in second there are values for CITY and DRUN

Thus each IDOC though contains all the segments will contain value for only a few segments in each of them.But there are fields like ACKKEY,EMPID,DEPTVALUE which is unique and repeats in each of the IDOC. These three fields clearly distinguishes one employee details from the other.This is my target file structure.Can i have a UDF for making such a file and steps to be followed.

Sorry for late reply.

Former Member
0 Kudos

Can you give the like of blog you followed and secondly you want before each IDOC followed by it's contents you should add one header line. E.g.

ACKKEY:PET500

followed by the contents of the field.

ACKKEY:PET555

followed by the contents of the field.

ACKKEY:MAT999

followed by the contents of the field.

*

*

*

and so on....

OR there will be only one header line in the target file.

Former Member
0 Kudos

Hai Sarvesh,

Thanks for Your reply.I followed the Blog:

Actually in my scenario this ACKKEY would be the key field(that is it will have a unique value say PET500).All the 900-1000 IDDOCs that will be created will have the value PET500 in the ACKKEY field.

There will be multiple header line in the target field,but it is similar(ie all the 900-1000 IDOC will have 3 fields(amongst 26 fields) each containing unique value which would make up the three header line.

for eg:

ACKKEY:PET500

EMPID:DET2098

DEPTVAL:TP234

this would make up my header followed by the whole file taken up from source.I think i have made it clear.

If i get the process of creating one header line the other two can be created in similar way i guess.

Former Member
0 Kudos

Hi,

Thanks for good expl... So where are you facing the problem in doing so.

If you are doing message mapping then at target structure you can add the header line and use the IF condition to check if the source ACKKEY field contains PET500 then map ACKKEY:PET500 to your target field. Similarly do the same for other fields too..

I think you are not doing any mapping, you just wnat to add these header values at the top of source file and then with the help of Sender File adapter you want to pickup the file and want to send to target system.

Plz focus on it..

Regards,

Sarvesh

Former Member
0 Kudos

Hi sarvesh,

As you said

you just wnat to add these header values at the top of source file and then with the help of Sender File adapter you want to pickup the file and want to send to target system.

If i can do so it is the best method but I am just a beginner on XI and that is why i went for the other approach of using a user defined function. if you could tell me how i can do it it will be of great help for me.

ie If I want to add these header values at top of source file and then with help of sender file adapter i want to pick up the file and want to send to target system,What i should do?

Former Member
0 Kudos

HI Anoop

Yes you can workout with a small java code like

Pass ACCKEY value into UDF

String str ="";

str = "ACCKEY:"+ACCKEY;

return str;

and map it to target header field.

this will return ACCKEY:PET500 to the header field.

Thanks

Gaurav

Edited by: Gaurav Bhargava on Sep 30, 2008 11:56 AM

Former Member
0 Kudos

Hai Gaurav,

I dont know much about creating and use of user defined function.I am studying that for the purpose of my interface for first time.I would appreciate your hepl if you could help me out with the whole of user defined function for this particular purpose

I have one more doubt.The target field also has a field called ACKKEY to which i have to map ACKKEY in the source field besides using it for Header field.Can i pass the Source ACKKEY value to both userdefined function and Target ACKKEY value.If so how?

former_member238007
Contributor
0 Kudos

Anoop,

There will be no problem , you can map it any number of fields.

just click the target and source use the mapping funciton or an userdefined function its enough.. if it is an just moving a value u can directly map it..

and w.r.t user defined is concerned we need the complete fields which u are using at the source side and to which i need to map at the target side.

regards,

Kishore

Former Member
0 Kudos

Hi Kishore,

As i said above the source and target are having the three fields(which i have mentioned above as ACKKEY,EMPID,DEPTVAL) as unique fields and these have to appear as the header also.

Mapping for these unique fields should be as shown below

Source Target

ie ACKKEY---->ACKKEY

EMPID------->EMPID

DEPTVAL------>DEPTVAL

please proide me the user defined function for the same.I also want to know what all classes i should import.So can you please make the user defined function as exact as possible?

bhavesh_kantilal
Active Contributor
0 Kudos

Use Standard function COPYVALUE if the field occurs just once.

if it occurs multiple times in both the source and the target side, then it is a straight mapping.

Regards

Bhavesh