on 02-26-2015 11:14 AM
Hi Guys,
Can somebody please help me as I am facing very strange problem in Sender FCC.
I have a structure like this
MT_ABC
FILE_HEADER
RECORD_TYPE
FIELD1
FIELD2
VOUCHER_HEADER
RECORD_TYPE
FIELD1
FIELD2
VOUCHER_DETAIL
RECORD_TYPE
FIELD1
FIELD2
FCC Setting in Adapter
Document Name : MT_ABC
Document Namespace: http://abc.com
Document Offset:
Recordset Name: Records
Recordset Namespace:
Recordset Structure: FILE_HEADER,1,VOUCHER_HEADER,*,VOUCHER_DETAIL,*
Recordset Sequence: Ascending
Recordset per Message:
Key Field Name : KEY
key Filed Type: String (Case-Sensitive)
Details
FILE_HEADER.fieldNames : RECORD_TYPE,FIELD1, FIELD2 | |
FILE_HEADERfieldFixedLengths. : 1,2,12 |
FILE_HEADER.endSeparator : 'nl'
FILE_HEADER.keyFieldValue : A
FILE_HEADER.keyFieldInStructure : ignore
FILE_HEADER.processFieldNames : fromConfiguration
VOUCHER_HEADER.fieldNames : RECORD_TYPE,FIELD1, FIELD2
VOUCHER_HEADER.fieldFixedLengths : 1,2,9
VOUCHER_HEADER.endSeparator : 'nl'
VOUCHER_HEADER.keyFieldValue : B
VOUCHER_HEADER.keyFieldInStructure : ignore
VOUCHER_HEADER.processFieldNames : fromConfiguration
VOUCHER_DETAIL.fieldNames : RECORD_TYPE,FIELD1,FIELD2, |
VOUCHER_DETAIL.fieldFixedLengths : 1,2,2
VOUCHER_DETAIL.endSeparator : 'nl'
VOUCHER_DETAIL.keyFieldValue : D
VOUCHER_DETAIL.processFieldNames : fromConfiguration
BUT OUTPUT IS COMING LIKE THIS
<?xml version="1.0" encoding="utf-8"?>
<ns:MT_ABC xmlns:ns="http://abc.com">
<Recordset>
<FILE_HEADER>
<RECORD_TYPE>A</RECORD_TYPE>
<FIELD1>12</FIELD2>
<FIELD2>140506022407</FIELD2>
</FILE_HEADER>
<VOUCHER_HEADER>
<RECORD_TYPE>B</RECORD_TYPE>
<FIELD1>01</FIELD1>
<FIELD2>003417131</FIELD2>
</VOUCHER_HEADER>
<VOUCHER_DETAIL>
<RECORD_TYPE>D</RECORD_TYPE>
<FIELD1>03</FIELD1>
<FIELD2>01</FIELD2>
</Recordset>
<Recordset>
<VOUCHER_HEADER>
<VOUCHER_DETAIL>
</Recordset>
Can somebody please tell me why the structure is not generating like this.
MT_ABC
FILE_HEADER
RECORD_TYPE
FIELD1
FIELD2
VOUCHER_HEADER
RECORD_TYPE
FIELD1
FIELD2
VOUCHER_DETAIL
RECORD_TYPE
FIELD1
FIELD2
VOUCHER_HEADER
RECORD_TYPE
FIELD1
FIELD2
VOUCHER_DETAIL
RECORD_TYPE
FIELD1
FIELD2
Regards,
Asif
Hi Asif
As mentioned by Amit, your flat file represents has a nested structure, and that is not supported by standard FCC.
Besides Java Mapping, another alternative would be to use two step mapping, the first step being an XSLT to deepened the flat XML generated by FCC. I have written the following article about XSLT based approach recently.
Do note that there are prerequisite for this - for each parent-child relationship, there must be a corresponding field in both parent and child containing the same value.
Rgds
Eng Swee
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Eng,
Very nice blog's.
Unfortunately there is no relationship between parent and child not so I have to play around with context or else have to use UDF or JAVA Mapping but I really don't want to go that root until you tell me that there is no other option.
Source File
A811
B010034171
D030176131
D030276131
B010034171
D030176131
A911
B010034172
D030176133
D030276134
B010034175
D030176136
File_Header : A
Voucher_header : B
Voucher_detail:D
All the fields will come "n" number of times so it's bit tricky to generate the required output.
FILE_HEADER
FIELD1
FIELD2
VOUCHER_HEADER
FIELD1
FIELD2
VOUCHER_DETAIL
FIELD1
FIELD2
FILE_HEADER
FIELD1
FIELD2
VOUCHER_HEADER
FIELD1
FIELD2
VOUCHER_DETAIL
FIELD1
FIELD2
Hi Eng,
Can you please tell me if it is possible to generate multiple FILE_HEADER because I have tried with FCC and it is always generating one FILE_HEADER and not multiple so not sure if there is any limitation on FCC.
Recordset Structure: FILE_HEADER,*,VOUCHER_HEADER,*,VOUCHER_DETAIL,*
Input File
A811
B010034171
D030176131
D030276131
B010034171
D030176131
A911
B010034172
D030176133
D030276134
B010034175
D030176136
Output generated by FCC
<FILE_HEADER>
<VOUCHER_HEADER>
<VOUCHER_DETAIL>
<VOUCHER_DETAIL>
<VOUCHER_HEADER>
<VOUCHER_DETAIL>
<VOUCHER_HEADER>
<VOUCHER_DETAIL>
<VOUCHER_DETAIL>
<VOUCHER_HEADER>
<VOUCHER_DETAIL>
Kindly let me know if this is possible with FCC or not and if not then how to achieve this.
Many Thanks,
Asif
Hi Asif,
Yes, you can repeat the Header Records. For each A repeat your Record structure, in MM map the A field occurrence from Source to Target Record Node (it should have 0..Unbounded occurrence).
I would suggest you to split it in 2 Steps:
1. Do normal FCC to convert the Flat file to XML
2. Add XSLT / JM code to create Hierarchy between Voucher Header and corresponding Voucher Detail node, if required.
For FCC you can create the XML structure in same level / hierarchy as follows:
Record *
FILE_HEADER 1
RECORD_TYPE
FIELD1
FIELD2
VOUCHER_HEADER *
RECORD_TYPE
FIELD1
FIELD2
VOUCHER_DETAIL *
RECORD_TYPE
FIELD1
FIELD2
Set the Recordset Sequence to Variable instead of Ascending.
Converting Text Format in the Sender File/FTP Adapter to XML - Advanced Adapter Engine - SAP Library
With this setting first check if you are able to see the XML in correct format. Then as a next step go for adding Hierarchy.
Hope it helps.
Regards,
Azhar
Hi Asif,
If you use below content conversion.
You will get below XML:
You can use below mapping to get required output. (VOUCHER_DATA(you need to make return as XML)->mapVoucherDetails(UDF)->VOUCHER_DETAIL), remaining all the fields field to field mapping.
UDF execution type is "All values of queue"
public void mapVoucherDetail(String[] input, ResultList result, Container container)
throws StreamTransformationException {
try {
InputStream inputStream = new ByteArrayInputStream(input[0].getBytes());
Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream);
NodeList vouchers = document.getDocumentElement().getChildNodes();
int voucherHeaderCount = 0;
for (int i = 0; i < vouchers.getLength(); i++) {
Node voucher = vouchers.item(i);
if (voucher.getNodeType() == Node.ELEMENT_NODE) {
NodeList childNodes = voucher.getChildNodes();
for (int j = 0; j < childNodes.getLength(); j++) {
Node childNode = childNodes.item(j);
if (childNode.getNodeType() == Node.ELEMENT_NODE) {
if (childNode.getNodeName().equals("VOUCHER_HEADER")) {
voucherHeaderCount++;
Node sibling = childNode.getNextSibling();
while (!(sibling instanceof Element) && sibling != null) {
sibling = sibling.getNextSibling();
if (sibling != null && sibling.getNodeName().equals("VOUCHER_DETAIL")
&& voucherHeaderCount != 1) {
result.addContextChange();
}
}
} else if (childNode.getNodeName().equals("VOUCHER_DETAIL"))
result.addValue("true");
}
}
}
}
} catch (Exception e) {
throw new StreamTransformationException(e.getMessage());
}
}
You need to include these imports.
Output is below:
Regards,
Praveen.
Praveen,
I have never really had the need to use the "Return as XML" feature and as such never really explored potential use cases for it.
Your solution is really interesting and IMHO the mechanics behind how it works is deserving of a blog post - when you have the time for it .
Bravo Praveen. Really good one!
Rgds
Eng Swee
Manoj,
Since this thread is already answered and your inputs are not directly related to the original query, why not you start a discussion thread in this forum - make sure to uncheck the "mark this discussion as a question" so that it does not encourage those who are merely point hunting.
We can then have a proper conversation over there on that thread.
As a start you can possibly indicate what specifically you are trying to learn where SCN search have not helped you. You also probably should elaborate on what you mean by "trace an xml file" because I don't really understand that, as always if it can be backed by an example, it would be useful.
Rgds
Eng Swee
Hi Asif,
You can leave Recordset Name and Recordset Namespave blanks, i think you have set Recordset Name with the value Recordset.
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
FCC supports up to 3 level of hierarchical structure and in ur case it's more than 3....so either use java mapping and convert txt into required xml format OR adjust the input (which u are seeing currently) at mapping level - It will be little tricky but certainly possible.
Thanks
Amit Srivastava
Hi Amit,
Thanks for your input but I don't think my structure is more than 3 levels and even if I remove the File header then still I am getting the same output and not voucher_header and under that voucher_details and instead it comes like.
VOUCHER_HEADER
VOUCHER_DETAIL
VOUCHER_DETAIL
VOUCHER_HEADER
VOUCHER_DETAIL
so how to get the structure like this
VOUCHER_HEADER
VOUCHER_DETAIL
VOUCHER_DETAIL
VOUCHER_HEADER
VOUCHER_DETAIL
VOUCHER_DETAIL
Regards,
Asif
Hello,
In FCC, u cannot have a sub structure inside a node which contains elements inside it
So, if a text file consist of multiple rows then each row will be converted into a separate XML node while doing FCC in file sender adapter.
Check sap help u will see how the sender structure will look like after doing FCC in sender adapter. So, if u want to have a hierarchical structure then u have to do some tweaking s suggested above.
Thanks
Amit Srivastava
Thanks Amit
So what you are saying is that I cannot use sub structures for FCC and it will always be like that.
FILE_HEADER
VOUCHER_HEADER
VOUCHER_DETAIL
Output after FCC
<Recordset>
FILE_HEADER
VOUCHER_HEADER
VOUCHER_DETAIL
</Recordset>
<Recordset>
VOUCHER_HEADER
VOUCHER_DETAIL
VOUCHER_DETAIL
</Recordset>
and then use another mapping to transform the required output.
Thanks Amit
Will play around and see if I am able to generate the required output with mapping and without Module or JAVA mapping.
I have also noticed that even if I define FILE_HEADER , * it is still generating one header in the output instead of multiple so do you know how to get multiple header in the output.
EXAMPLE
<Recordset>
FILE_HEADER
VOUCHER_HEADER
VOUCHER_DETAIL
</Recordset>
<Recordset>
FILE_HEADER
VOUCHER_HEADER
VOUCHER_DETAIL
</Recorset>
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.