Skip to Content

The need for this approach :

  • File content conversion on the receiver side is mostly used for data with a header and item level (and some cases sub-item) data hierarchy. The limitation faced here is that content conversion can be used only with XML structures that have a single hierarchy level.
  • This weblog is aimed at putting forth a scalable solution for this limitation. Lots of approaches using XML tools etc have already been suggested. This one aims to do it within the standard XI development tools.

Sample Scenario with Multiple Levels of data for a flat File:   

Let us consider a case in the below shown structure is the data format in the target side.

 image

And the required file is of the format shown below.

image 

The general approach here is that level 1 can be viewed as header and Fields in that level are the header fields and Level 2 is item and so on. The requirement is that we would have to show the header fields in one line and then its corresponding items in each of the following lines with the corresponding sublevels following the items. Basically a running list of header and its items, subitems and then the next header and so on.

This cannot be directly achieved as the file content conversion will not allow us to use more than one level in its content conversion. The following steps need to be done in order to be able to convert this structure into a flat file.

Step 1:

            Whatever the target structure is create another data type as a copy of this structure and add another field of type string in the end and at just one level below the root node as shown below for the example we are discussing.

image

Note that this data type contains all the fields as required and then one field labelled “Result” in the end and just one level below the route node.

The above type will act as the intermediate structure. Declare another structure with just a node and an element within it as shown below. This shall be the final structure that would be used for the Content Conversion.

image 

Step 2:

Creating a message mapping between the actual target structure shown and the intermediate structure (with the extra field in the end) shown above.

image The

This mapping requires declaration of 2 global variables as shown below.

image

Except the first field in each level, map the others to constants, meaning field 2 till field “n”  in each level must be mapped to constants, for the first field in each level map them to the source as shown in the below example for level 1.

image

image

 image

The source field 1 and field 2 are from level 1 and the target field 1 is also from level 1. The user defined function “gen_flt1” would contain the following code.

image

The following needs to be noted about this Function

  • It is a simple user defined function and hence accepts a string and returns a string
  • The number of parameters it accepts will be equal to the number of fields in each level. If Level 1 has 4 fields, then all the four fields will be taken as input parameters and then the string “res” would be concatenation of all the four fields separated by space.
  • This function would append the records to the global array declared earlier. It exploits the fact that simple mapping functions are executed in the order of the XML and hence we can capture the same order required for the file.

Repeat the same procedure for all the levels. The same function can be re used if the number of fields in each level are the same, else use the same logic and create new function for every level.

After completing the mapping for all the levels, the mapping for the last field “Result” is done as shown below.

image

Note that the result field does not map to any source fields, instead it is mapped to another user defined function “Populate_Result” . This function would contain the below shown code.

image

The following needs to be noted about this Function

  • It is a context function and does not take any input parameters
  • The function reads the Global Array populated earlier and creates new instances of the field “Result” in the target

Once the mapping is completed, check is as shown below to get the desired result.

image

Step 3:

Create another mapping between the target structure above and the final structure if the flat file.

image

The mapping only involves 2 simple steps shown below

image

image

This would ensure that the number of result segments is transferred into “Data” nodes with in the target as shown below

image

Step 4:

Create an interface mapping with the between the source and target interfaces and the mapping created in step2 and step3 would be used together as shown below

image

The mapping can be checked as shown below.

image

The Target structure thus achieved is same as the one recommended to be used in file content conversion and hence the Content Conversion is now direct. Even though the target has “n” number of fields in each line, since they are concatenated, the field list in the conversion parameters would contain just one field “Result”.

Summary:
  • The Underlying logic is that that number of “Result” elements in the intermediate mapping must be the number of lines in the flat file and in the same order
  • Each level needs to be mapped once to be added to the Global Array.
  • The number of parameters that the function takes is equal to the number of fields in each level and concatenation must happen likewise.
Advantages:

This logic can be used to convert any hierarchical structure with any number of levels and elements in each level to a flat file by using the standard development tools in XI. The logic also takes care of differences in occurrence between each of sub levels that usually complicate the mapping since Node Functions would have to be used. The content conversion which is very complex to handle even with one hierarchy would now be simple as all the data is in just one field. Any of the separators can be used and file can be generated as fixed length also. Newer fields added to the target data also can be accommodated in the mapping. File Formats with variable alignment based on the hierarchy as shown below can also be achieved, but just concatenating more tab spaces in the UDF “Generate_Flt1”.

image

To report this post you need to login first.

7 Comments

You must be Logged on to comment or reply to a post.

    1. Karthik Narayan Kesavan Post author
      Thanks Deviprasad! Yeah the node function you mentioned is actually meant for this purpose. But with increasing hierarchy and difference in occurances the function gets more complicated, i had hence given up on that approach and chosen this.There are various methods to achieve flat structures, but i was thinking about a common solution to any type of structure as node function related solutions are very specific and are not applicable even if our strucuture is little different from ones stated in examples.
      (0) 
      1. Goradindla Sreerama Reddy
        Hi Karthik,

        In Step 2 i.e. Intermidate mapping . if you are havinf flat input then mapping into intermodate mapping i.e. Source strcuture is more diffcult for which we may need to use XLST or Java. can you put that in ur blog

        (0) 
      2. Harish Choudhary
        Hi Karthic,

        Will this scenario work in file to idoc scenario.
        Where I have the same file shown above in the source side and I need to trigger the idoc for each Level-2. And each Level-3 will be the item segment for the idoc.

        Please reply to me on my email : harish_jmk@hotmail.com

        Thanx in advance.

        Regards

        Harish

        (0) 
  1. Dev S
    Hi

    This is a really nice blog . However I have one question
    What if my structure is restricted till Level 2
    is that possible without Intermediate mapping?

    i.e the target structure that i have to produce for my file is :

    Dt_File
         Level1(o…unbounded) 
              Level2(1)
                  field1
                  field2
              Level2a(1)
                  field3
              Level2b(1)
                  field4

    where Level 2 ,2a and 2b are at the same level and Field 1 and field2  are under Level2 , field 3 is under Level2a dn field 4 is under Level 2b

    is that possible to use produce the same using Content conversion ???

    Thanks
    Dev

    (0) 
    1. Karthik Narayan Kesavan Post author
      Hi Dev,
             I think the primary issue with the reciever side content conversion is it supports only one level.
      Check this link.
      http://help.sap.com/saphelp_nw04/helpdata/en/d2/bab440c97f3716e10000000a155106/content.htm
      It says “The expected XML structure contains the structure as nodes filled with any number of elements without additional subnodes.”
      So in your example, all the fields must be under level1 without any additional subnodes..
      Hope this helps..
      Thanks,
      Karthik
      (0) 
  2. Neha R
    Hi Kartik

    What if the It is File to IDOC scenario and the Incoming file is FLAt like this

    HPOCKET11119880001216980000121516072010AA123456bbWM100012349800000619
    DPOCKET_TEST001 4012YAG1
    WZOA00000010000001
    WZOA00000020000002
    WZOB00000030000003
    IAAXX000001
    IAAXX000002
    C0000000000000000000100000000000000000001000000000000000000020000000000000000000300000000000000000004
    DPOCKET_TEST002 4012YAG1
    WZOA00000110000011
    WZOA00000220000022
    IAAXX000011
    IAAXX000022
    C0000000000000000001100000000000000000011000000000000000000220000000000000000003300000000000000000044
    T2

    and then i have to make a message structure like this using content conversion

              0 to 1

              – 0 to unbounded
         …………………
         …………………
         …………………

         – 0 to unbounded
         ……………..
            ……………..
         
              – 0 to unbounded
         ………………
         ……………..
         
         – 0 to unbounded
         ……………..
         ……………..
         
              0 to 1
    ………………….

    and then in the intermediate mapping – map it to the structure

              0 to 1

                   – 0 to unbounded
         …………………
         …………………
         …………………
              – 0 to unbounded
              ……………..
              ……………..
         
         
                   – 0 to unbounded
              ………………
              ……………..
         
         
              – 0 to unbounded
              ……………..
              ……………..
         
         

              0 to 1
    ………………….

    how to achieve this ??

    I really need ur help

    Regards
    Naina

    (0) 

Leave a Reply