Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member182412
Active Contributor

Introduction

Standard file content conversion supports one level of nested XML but many times we need more than one nested deep XML, We have many blogs in SCN that deals with this requirement. In this document i want to show by using standard file content conversion and message mapping.


Example Scenarios

Scenario 1

I took the example from this thread Re: Sender File content conversion , this is flat file to two level nested XML structure.


This below is sender flat file, sender message type structure and sender file FCC parameters.

File Content Conversion


InvoiceHeader.keyFieldValueH
InvoiceHeader.keyFieldNameLineIndicator
InvoiceHeader.fieldNamesLineIndicator,SupplierCode,InvoiceDate,Currency,Amount
InvoiceHeader.fieldSeparator;
InvoiceHeader.endSeparator'nl'
InvoiceDetail.keyFieldNameLineIndicator
InvoiceDetail.keyFieldValueD
InvoiceDetail.fieldNamesLineIndicator,LineType,CompanyCode,Costelement
InvoiceDetail.fieldSeparator;
InvoiceDetail.fieldSeparator'nl'
ControlHeader.keyFieldValueCH
ControlHeader.keyFieldNameLineIndicator
ControlHeader.fieldNamesControlIndicator,TotalLine,TotalAmt
ControlHeader.fieldSeparator;
ControlHeader.endSeparator'nl'
ControlData.keyFieldValueCD
ControlData.keyFieldNameLineIndicator
ControlData.fieldNamesControlIndicator,TotalLine,TotalAmt,Currency
ControlData.fieldSeparator;
ControlData.endSeparator'nl'

Output

The below is output of the mapping, you can find source is flat file structure according to file above, the output is nested three level deep XML as we expected.

Mapping

The mapping simple field to field mapping except for ControlHeader node and ControlData node, these two we just need to change the context to root node.

Scenario 2

I took this example from this thread structure not populating correctly in FCC, This example is flat structure to three level nested XML.

Input Data

The below is sender file, sender message structure and file content conversion.

File Content Conversion

FILE_HEADER.keyFieldValueA
FILE_HEADER.keyFieldNameKEY
FILE_HEADER.fieldNamesKEY,FIELD1,FIELD2
FILE_HEADER.fieldFixedLengths1,2,1
FILE_HEADER.endSeparator'nl'
VOUCHER_HEADER.keyFieldNameKEY
VOUCHER_HEADER.keyFieldValueB
VOUCHER_HEADER.fieldNamesKEY,FIELD1,FIELD2
VOUCHER_HEADER.fieldFixedLengths1,2,7
VOUCHER_HEADER.endSeparator'nl'
VOUCHER_DETAIL.keyFieldValueD
VOUCHER_DETAIL.keyFieldNameKEY
VOUCHER_DETAIL.fieldNamesKEY,FIELD1,FIELD2
VOUCHER_DETAIL.fieldFixedLengths1,2,7
VOUCHER_DETAIL.endSeparator'nl'

Output

The below is output of the mapping, you can find source is flat file structure according to file above, the output is nested three level deep XML as we expected.

Mapping

First level node you can directly map and change the context change to root node. The fields under first level node you can directly map

For all other child level nodes (Second level node and third level node) you can apply the below mapping.

For second level and third level node fields you can apply the below mapping.

User Defined Function

The below is the mapChildNode UDF which is used above, this is generic UDF we can use this in all similar requirement in future.


public void mapChildNode(int[] parentCount, int[] childCount, ResultList result, Container container)
  throws StreamTransformationException {
  int i = 0;
  for (; i < parentCount.length; i++) {
  if (childCount[i] > 0) {
  if (parentCount[i] > 0 && i != 0)
  result.addContextChange();
  for (int j = 0; j < childCount[i]; j++)
  result.addValue("");
  } else {
  if (i != 0)
  result.addContextChange();
  result.addSuppress();
  }
  }
  }








Similar documents in SCN

Flat file to deep XML - using an UDF

XSLT approach - Flat File to Deep XML

DeepFCCBean - Flat File to Deep XML

riyaz.sayyad/blog/2008/05/20/xipi-convert-flat-file-to-deeply-nested-xml-structures-using-only-graphical-mapping


Conclusion

We can do flat file to nested deep XML using standard file content conversion and message mapping using one generic user defined function.I hope this helps.

2 Comments
Labels in this area