Skip to Content
avatar image
Former Member

SAP PI 7.4 IDoc to Flat File - Group Flat File Output

Hi Everyone,

I've an issue with my IDoc to Flat File scenario. I would appreciate any advice you could give on this.

I have mapped IDoc SHPORD|DELVRY06 to produce a fixed length flat file output. The IDoc's are collected in SAP and sent out to PI. We are appending all the IDocs sent out to one flat file.

For every IDoc line segment E1EDL24 we need one line in the flat file output. This works fine.  (E1EDL24 ->removeContexts>Record)

The problem I have is grouping the lines in the flat file. Currently the output comes out like:-

<Transaction><Key><Material> <Quantity>

AB809MAT1 20

AB813PRD1 15

AB809MAT1 20

AB814PRD2 12

AB813PRD1 15

AB999ITM1  10

AB809MAT1 25


But the requirement is to have the output group (rolled up) by <Transaction><Key><Material> <Quantity> as follows:-


AB809MAT1 65

AB813PRD1 30

AB814PRD2 12

AB999ITM1  10


Do i need to perform another mapping step ?  Or is there I way I can achieve this within the existing mapping ? I've searched around but for some reason can't seem to find this scenario. Any help would be greatly appreciated.


Thanks for your time.

JE


Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    avatar image
    Former Member
    Oct 29, 2015 at 07:05 PM

    Hi Sritharan,


    Thanks for your time.


    Still not working. I'll describe a bit further. I've mapped the IDoc fine - so now I'm going to use another message mapping to format the flat file output.


    The Message type looks like this:

    <Record>

    --<Transaction>

    --<Key>

    --<Material>

    --<Quantity>


    In order to group the output my mapping looks like this.  I've concatenated Transaction,Key and Material to give me a KeyValue since we want a new record when this changes.


    To sum the quantity for every record I need to formatByExample when mapping Quantity right ?


    <Record>KeyValue-> removeContexts->sort->SplitValue(ValueChange)->collapseContexts-> <Record>

    <Transaction>                                       ---->      <Transaction>

    <Key>                                                      --->       <Key>

    <Material>                                               ---->     <Material>

    <Quantity>

        Quantity->removeContexts-> formatbyExample->UDF(Add)-><Quantity>

    KeyValue-> removeContexts->sort->SplitValue(ValueChange) ->                                                      


    This doesn't work. The problem is relating the KeyValue and the Quantity - the Quantity doesnt stay with the Keyvalue.


    I've attached screenshots below. Input show's 4 records and Output Shows 3 records which correct since we want to group where the KeyValue is the same (duplicated)  however the Quantities are not in the right context.


    My output should be:


    AB

    813

    PRD1

    15


    AB

    809

    MAT1

    45


    AB

    999

    ITM1

    10


    Thanks for your support.


    JE


    IMG1-InputValues.PNGIMG2-OutputValues.PNG



    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Raghuraman S

      Thanks Sritharan,

      I have tried with sortByKey but i cannot see a way to make it work.

      The problem is with the other fields in the Record - i can't link them to the KeyValue (which I'm using to create one idoc per KeyValue so duplicates are not created)

      So linking AB809MAT1 to the following:-

      AB

      809

      MAT1

      20

      etc.

      isn't looking possible for me at this stage. I will try looking into UDF maybe.

      Thanks for your help

  • Oct 29, 2015 at 01:58 PM

    Hello Joel,

    Requirment is little bit confusing.

    You wish to collect the line items for a particular idoc.?

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 02, 2015 at 11:23 AM

    Hi all,

    I've resolved this issue. I was not using the sort by key function correctly - Once I resolved the mapping and used the UDF (to add values in a context) from Sritharan my solution is now working perfectly. The solution is pretty straight forward once I got my thinking correct.

    I would like to thank everyone for taking the time to help me here; particularly Sritharan for his effort in doing his utmost to help out.

    So based on the above and for the record the correct mapping is as follows:

    1. First I create a normal mapping from IDoc to Message Type MT_FILE (Mapping 1)
    2. I then created another mapping to group Step 1 with the input (coming from Step 1) and the output being the same Message Type
    3. SortKey = Concat <Transaction> + <Key> + <Material>
    4. Record node mapping to group duplicate values together into one record

    1. Sub Nodes (all fields under Record are mapped the same - here my example for Qty)

    Thanks

    JE


    Add comment
    10|10000 characters needed characters exceeded