<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: ABAP help with deeply nested items. in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-help-with-deeply-nested-items/m-p/2649283#M610573</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i would create a new itab like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HL = Higher Level&lt;/P&gt;&lt;P&gt;SO = Sales Order&lt;/P&gt;&lt;P&gt;IT = Item&lt;/P&gt;&lt;P&gt;SUM = Summed values&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HL    SO   IT   SUM&lt;/P&gt;&lt;P&gt;1020 1025 20  ___&lt;/P&gt;&lt;P&gt;1020 1023 10  ___&lt;/P&gt;&lt;P&gt;1020 1022 50  ___&lt;/P&gt;&lt;P&gt;1020 1021 10  ___&lt;/P&gt;&lt;P&gt;1010 1020 20  ___&lt;/P&gt;&lt;P&gt;1010 1015 20  ___&lt;/P&gt;&lt;P&gt;1010 1011 10  ___&lt;/P&gt;&lt;P&gt;1000 1010 20  ___&lt;/P&gt;&lt;P&gt;0000 1000 30  ___&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;basically, swap columns 1 &amp;amp; 2, reverse sort it and add a new SUM column.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;loop at itab.
  v_tabix = sy-tabix.  " &amp;lt;- keep track of your current line.

  at end of col1.
    sum.
    read table itab into work_area index sy-tabix.
    work_area-sum = itab-sum.
    modify itab index v_tabix from work_area transporting sum. 
  endat.

endloop.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;all this code is theoretical, probably wouldn't pass a syntax check and doesn't make the best use of work areas/field symbols, but it's a good start.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;reward points if helpful.&lt;/P&gt;&lt;P&gt;rp.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 13 Aug 2007 19:18:21 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-08-13T19:18:21Z</dc:date>
    <item>
      <title>ABAP help with deeply nested items.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-help-with-deeply-nested-items/m-p/2649282#M610572</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Gurus,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We have a requirement whence we need to sum up the key figures from one transformation layer going to the next.  The challenge is, its a deeply nested structure. something like :&lt;/P&gt;&lt;P&gt;SalesOrderItem     Higher Level Item         KeyFig   &lt;/P&gt;&lt;P&gt;1000                     0000                          30&lt;/P&gt;&lt;P&gt;1010                     1000                          20&lt;/P&gt;&lt;P&gt;1011                     1010                          10&lt;/P&gt;&lt;P&gt;1015                     1010                          20&lt;/P&gt;&lt;P&gt;1020                     1010                          20&lt;/P&gt;&lt;P&gt;1021                     1020                          10&lt;/P&gt;&lt;P&gt;1022                     1020                          50&lt;/P&gt;&lt;P&gt;1023                     1020                          10&lt;/P&gt;&lt;P&gt;1025                     1020                          20&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So now, in the next layer we will be rolling it upto the 1000 , 2000...levels- in this example 1000 level only.&lt;/P&gt;&lt;P&gt;The round figure items(1010, 1020.....) are the individual kmats and the summation happens like this: &lt;/P&gt;&lt;P&gt;1. Items 1021, 1022, 1023 and 1025 roll up to 1020; sum = 90.&lt;/P&gt;&lt;P&gt;2. Now when 1020 rolls up to its higher level item which is 1010, the sum that rolls up from 1020 should be 90 + 20.&lt;/P&gt;&lt;P&gt;3. Ultimately when all items roll up to item 1000, the total sum will be 190.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can someone please help me write this logic in ABAP?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;Chris&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Aug 2007 17:16:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-help-with-deeply-nested-items/m-p/2649282#M610572</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-08-13T17:16:56Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP help with deeply nested items.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-help-with-deeply-nested-items/m-p/2649283#M610573</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i would create a new itab like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HL = Higher Level&lt;/P&gt;&lt;P&gt;SO = Sales Order&lt;/P&gt;&lt;P&gt;IT = Item&lt;/P&gt;&lt;P&gt;SUM = Summed values&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HL    SO   IT   SUM&lt;/P&gt;&lt;P&gt;1020 1025 20  ___&lt;/P&gt;&lt;P&gt;1020 1023 10  ___&lt;/P&gt;&lt;P&gt;1020 1022 50  ___&lt;/P&gt;&lt;P&gt;1020 1021 10  ___&lt;/P&gt;&lt;P&gt;1010 1020 20  ___&lt;/P&gt;&lt;P&gt;1010 1015 20  ___&lt;/P&gt;&lt;P&gt;1010 1011 10  ___&lt;/P&gt;&lt;P&gt;1000 1010 20  ___&lt;/P&gt;&lt;P&gt;0000 1000 30  ___&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;basically, swap columns 1 &amp;amp; 2, reverse sort it and add a new SUM column.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;loop at itab.
  v_tabix = sy-tabix.  " &amp;lt;- keep track of your current line.

  at end of col1.
    sum.
    read table itab into work_area index sy-tabix.
    work_area-sum = itab-sum.
    modify itab index v_tabix from work_area transporting sum. 
  endat.

endloop.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;all this code is theoretical, probably wouldn't pass a syntax check and doesn't make the best use of work areas/field symbols, but it's a good start.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;reward points if helpful.&lt;/P&gt;&lt;P&gt;rp.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Aug 2007 19:18:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-help-with-deeply-nested-items/m-p/2649283#M610573</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-08-13T19:18:21Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP help with deeply nested items.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-help-with-deeply-nested-items/m-p/2649284#M610574</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;EDIT: the read statement in the loop is incorrect.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;loop at itab.
  v_tabix = sy-tabix.  " &amp;lt;- keep track of your current line.
 
  at end of col1.
    sum.
    read table itab into work_area with key SO = itab-HL.
" check sy-subrc to make sure a higher level is found 
    work_area-sum = itab-sum.
    modify itab index v_tabix from work_area transporting sum. 
  endat.
 
endloop.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Aug 2007 19:47:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-help-with-deeply-nested-items/m-p/2649284#M610574</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-08-13T19:47:42Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP help with deeply nested items.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-help-with-deeply-nested-items/m-p/2649285#M610575</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you Robert for your earnest reply.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you do the sum at end of col1 after the sorting you suggested, we will have two distinct sums for 1020 and 1010. The problem with that is, 1020 has its own keyfigures which need to be added to the sum of which 1020 is a high level item for.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also,SO Item 1020 has a higher level item 1010, so  the combined sum so far has to be added to the sum for which 1010 is the higher level item.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;All help appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Aug 2007 21:05:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-help-with-deeply-nested-items/m-p/2649285#M610575</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-08-13T21:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP help with deeply nested items.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-help-with-deeply-nested-items/m-p/2649286#M610576</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Chris,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I really think this can be accomplished using that code example as a base.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Create your table so that it has more than 1 summation field so you can roll your lower level numbers to the higher level then add that to it's own value. then, move that to a 3rd field.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Otherwise, you could have a 2nd itab just to store the top level sales orders. They should be easy to find because those are in the Higher Level column of your itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Loop through those:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Loop at HL_itab.
  loop at SO_itab where HL = HL_itab-entry.
    add your values here and store somewhere
  endloop.
endloop.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Aug 2007 21:25:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-help-with-deeply-nested-items/m-p/2649286#M610576</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-08-13T21:25:32Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP help with deeply nested items.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-help-with-deeply-nested-items/m-p/2649287#M610577</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can try this, but please put it through more examples. Assumption is that your highest level item will have higher item number as 0000 and that they are always sorted in the way it is given in your example.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
DATA: BEGIN OF itab OCCURS 0,
        posnr(6) TYPE n,
        uposn(6) TYPE n,
        qty TYPE p DECIMALS 2.
DATA: END OF itab.

DATA: itab2 LIKE itab OCCURS 0 WITH HEADER LINE.
DATA: itab3 LIKE itab OCCURS 0 WITH HEADER LINE.

DATA: v_total TYPE p DECIMALS 2,
      v_posnr(6) TYPE n.

itab-posnr = '1000'.
itab-uposn = '0000'.
itab-qty   = 30.
APPEND itab.

itab-posnr = '1010'.
itab-uposn = '1000'.
itab-qty   = 20.
APPEND itab.

itab-posnr = '1011'.
itab-uposn = '1010'.
itab-qty   = 10.
APPEND itab.

itab-posnr = '1015'.
itab-uposn = '1010'.
itab-qty   = 20.
APPEND itab.

itab-posnr = '1020'.
itab-uposn = '1010'.
itab-qty   = 20.
APPEND itab.

itab-posnr = '1021'.
itab-uposn = '1020'.
itab-qty   = 10.
APPEND itab.

itab-posnr = '1022'.
itab-uposn = '1020'.
itab-qty   = 50.
APPEND itab.

itab-posnr = '1023'.
itab-uposn = '1020'.
itab-qty   = 10.
APPEND itab.

itab-posnr = '1025'.
itab-uposn = '1020'.
itab-qty   = 20.
APPEND itab.
itab2[] = itab[].
*-- assumption is that if UPOSN = 000000, then there is no higher level
*   item
LOOP AT itab WHERE uposn = '000000'.
  itab3-posnr = v_posnr = itab-posnr.
  DO.
    LOOP AT itab2 WHERE uposn = v_posnr.
      v_total = v_total + itab2-qty.
    ENDLOOP.
    IF sy-subrc &amp;lt;&amp;gt; 0.
      EXIT.
    ELSE.
      v_posnr = itab2-posnr.
    ENDIF.
*-- This item does not appear as a higher level item
  ENDDO.
  v_total = v_total + itab-qty.
  itab3-qty = v_total.
  APPEND itab3.
  CLEAR itab3.
ENDLOOP.

LOOP AT itab3.
  WRITE:/ itab3-posnr,
          itab3-qty.
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Aug 2007 21:33:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-help-with-deeply-nested-items/m-p/2649287#M610577</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-08-13T21:33:17Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP help with deeply nested items.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-help-with-deeply-nested-items/m-p/2649288#M610578</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you Robert, I ll build more upon your pseudo code. Points assigned for your help:)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Aug 2007 21:55:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-help-with-deeply-nested-items/m-p/2649288#M610578</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-08-13T21:55:56Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP help with deeply nested items.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-help-with-deeply-nested-items/m-p/2649289#M610579</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you Srinivas.&lt;/P&gt;&lt;P&gt; I ll try your code with more examples and let you know the outcome. It does make sense and seems it ll suffice.&lt;/P&gt;&lt;P&gt;Thanks a lot! points assigned for your timely help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Aug 2007 21:58:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-help-with-deeply-nested-items/m-p/2649289#M610579</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-08-13T21:58:56Z</dc:date>
    </item>
  </channel>
</rss>

