cancel
Showing results for 
Search instead for 
Did you mean: 

Create Dynamic Field

Former Member
0 Kudos

Hi,

I have a requirement for File to proxy scenario.

Sample File structure -

Name,Address,Salary,EmpID,Additional

ABC,KOL,10000,1234,ETC

PQR,BLR,20000,0987,ETC

Here fields are not fixed in the file means its not always fixed that Name will be the 1st field in the file ; it can be last one also.

Due to this I have created the Data Type in the Sender side like that -

Record

   Input

Here, I am inserting all the field of the file in the single field Input. I am separating the fields in an UDF in the Message mapping.

Now the problem is that some other fields can appear  in the file also but no of fields will always be 5. The file can be like that also

Address,Salary,EmpID,Additional,Tax

KOL,10000,1234,ETC,2%

BLR,20000,0987,ETC,3%

Now my question is -

Is it possible to create field in the target side dynamically means if 'Address' field comes in the field then I want to create a field in the target side with the name 'Address' .

If possible then how?

Accepted Solutions (0)

Answers (3)

Answers (3)

Muniyappan
Active Contributor
0 Kudos

Hi Apu,

you can follow this below link to achieve this by directly writing java mapping in ESR.

http://scn.sap.com/community/pi-and-soa-middleware/blog/2013/03/13/write-java-mapping-directly-in-

esr

you can use the blow code  in the function tab of message mapping for attributes and methods.

sample code


public void transform(TransformationInput in, TransformationOutput out)

  throws StreamTransformationException {

  try {

                      String targetxml ="";

                      String line = "";

                      int counter = 0;

                      String[] xmltag = new String[5]; // allocate as per numbe of columns

                      String[] data = new String [5];

                      StringBuffer sb = new StringBuffer();

                      InputStream ins = in.getInputPayload().getInputStream();

   BufferedReader br = new BufferedReader( new InputStreamReader(ins));

  sb = sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");

  sb = sb.append("<ns0:Emp xmlns:ns0=\"www.google.com\">");

  while((line=br.readLine()) != null )

                                {

                                                if(counter==0)

                                                                {

                                                                        xmltag = line.split(",");

                                                                }

                                       

                                                else

                                                                {

                                                                       data = line.split(",");

                                                                        sb = sb.append("<Record>");

                                                                        for(int i= 0;i<data.length;i++)   

                                                                                {

                                                                                        sb = sb.append("<");

                                                                                        sb = sb.append(xmltag[i]);

                                                                                        sb = sb.append(">");

                                                                                        sb = sb.append(data[i]);

                                                                                        sb = sb.append("</");

                                                                                        sb = sb.append(xmltag[i]);

                                                                                        sb = sb.append(">");

                                                                                       

                                                                                }

                                                                       

                                                                        sb = sb.append("</Record>");

                                                                }

                                                       

                                        ++counter;

                                       

                                }

                                br.close();

  sb = sb.append("</ns0:Emp>");

  targetxml =sb.toString();

  out.getOutputPayload().getOutputStream().write(targetxml.getBytes());

} catch (Exception e)    {   throw new StreamTransformationException(e.getMessage());   }

}

Mapping results

you can manipulate the code as per your requirement.

Regards,

Muniyappan.

Former Member
0 Kudos

Hi Apu,

You can use XSLT or Java mapping to dynamically populate a node. Blog by Sunil sounds goods using message mapping UDF.

Regards,

Pranav.

Harish
Active Contributor
0 Kudos

Hi Apu,

you can create dynamic target node in target structure, please refer the below blog for more detail

regards,

Harish