cancel
Showing results for 
Search instead for 
Did you mean: 

structure not populating correctly in FCC

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

engswee
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

engswee
Active Contributor
0 Kudos

Hi Asif

From the sample file content provided, I can't find a pattern to establish parent-child relationship too, so unfortunately the XSLT approach cannot be used.

I think Java Mapping as suggested by Amit would be the option to go with.

Rgds

Eng Swee

Former Member
0 Kudos

Thanks Eng,

I have found one blog which might solve my problem without the use of Java Mapping but with 2 UDF's.

engswee
Active Contributor
0 Kudos

Sure, feel free to try that out.

Former Member
0 Kudos

I have tried but no luck as it seems the only way to do this is JAVA but I am not comfortable with JAVA so wondering if somebody can please guide me.

Former Member
0 Kudos

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

azharshaikh
Active Contributor
0 Kudos

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

former_member182412
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

Thank you so much Praveen. You have solved my problem

I have tested the scenario and it's working like a charm!!!!

THANK YOU

former_member182412
Active Contributor
0 Kudos

Hi Asif,

I forgot to mention this mapping, please use below mapping for FILE_HEADER Node.

Regards,

Praveen.

engswee
Active Contributor
0 Kudos

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

RaghuVamseedhar
Active Contributor
0 Kudos

Appreciate your effort and innovative solution.

Your solution in was on similar lines. Inspired by this solution, I was able to successfully implement a tricky requirement (useOneAsMany failed me), last week.

I agree with , time for your first blog.

former_member182412
Active Contributor
0 Kudos

Thanks Eng and Raghu for your comments, i will definitely write the blog about this.

Former Member
0 Kudos

I will await for your blogs Praveen

Do you have any document or anything to learn more about JAVA mapping as I really need to learn but so far I couldn't find any good books or training material so if you have any please share it with me on muiqbal at hotmail dot co dot uk

engswee
Active Contributor
0 Kudos

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

Answers (1)

Answers (1)

iaki_vila
Active Contributor
0 Kudos

Hi Asif,

You can leave Recordset Name and Recordset Namespave blanks, i think you have set Recordset Name with the value Recordset.

Regards

Former Member
0 Kudos

Hi Inaki,

I have tried that but still not luck.

Any other suggestion as I have tried so many things but didn't get the required output.

Regards,

Asif

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

Former Member
0 Kudos

Yes, using FCC you cannot get that structure.

So if u comfortable with JM use that (I would have opted it, just to add make sure error handling is done properly in code) and if not then tweak ur mapping.

Former Member
0 Kudos

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>