Control break statement not working

Question: hi all,

plzz help me if u can.

i am using control break statement "at end of field" its working properly..

see my code below.

*multiply unit price with balance on hand and save in separate field.
*concatenate matnr and plant in one field
  loop at i_file2.
    if i_file2-matnr = ' '.
    delete i_file2 index sy-tabix.
    continue.
    endif.
    clear: i_file2-mul_unit_pr, i_file2-mat_plt.
    i_file2-mul_unit_pr = i_file2-bal * i_file2-unit_pr.
    concatenate i_file2-matnr i_file2-plant into i_file2-mat_plt.
    modify i_file2 index sy-tabix transporting mul_unit_pr mat_plt.
  endloop.

  clear i_file2.
  sort i_file2 by mat_plt.

*sum multiplied unit prices.
  loop at i_file2.
    clear i_file2-total_unit_pr.
    at end of mat_plt.
      read table i_file2 index sy-tabix.
      sum.
      i_file2-total_unit_pr = i_file2-mul_unit_pr.
      modify i_file2 index sy-tabix transporting total_unit_pr.
    endat.
  endloop.

In i_file2-total_unit_pr the values are not getting added.

plzz help.

regards,
madhuri.

Answer:
Functioning of CONTROL-BREAK in LOOPs depends on the sequence of internal table fields too. "mat_plt" should be the first field in the internal table, and the table should be sorted on this field (which you have done already).

And, what type is field "total_unit_pr", because SUM would sum its contents too. The CLEAR you have used for this field would clear only the header line contents for this field. During SUM, it would hold summation of the rows which meet the AT...ENDAT criteria.

Rather than moving a value to this field, define a local field, and move the value to that local field within AT..ENDAT and move this local field's value back to "mul_unit_pr", and MODIFY is outside of AT..ENDAT event.

Still.. could not understand the business reason behind this.. but guess you know what you want to do.

Regards
Sudhir/Mohit

Answer:
How about this.

This assumes your table is defined


begin of i_file2 occurs 0,
  matnr like ......
  plant like .......
  ........
end of i_file2.


Then your code brecomes


  delete i_file2 where matnr = ' '.
  sort i_file 2 by matnr plant.
  loop at i_file 2.
    at end of plant.          " as it will break at change of matnr or plant
      sum.
      i_file2-total_unit_pr = i_file2-bal * i_file2-unit_pr.
      modify i_file2 index sy-tabix transporting total_unit_pr.
    endat.
  endloop.


Though for the life of me I can't see the point in this, you end up with a table, some records holding individual values others totals.

If you were after just the totals then you would need to write the values to a different table.

Why not give us your ideas behind the code and we can help wit a better solution.

Answer:
Hi all,

Thanks for ur reply....
i got the solution...i moved the i_file2-mat_plant field to first position and its working fine.

Actually my requirement was like this...

I need to upload a file from local into some internal table and needed to sum if a material and plant combination record occurs more than once like...

material3 plant2 10.00
material1 plant1 25.00
material1 plant1 50.00
material2 plant1 30.00

in this case i should sum at material1 plant1 ...so only i combined material and plant into one field and applied sum. previously i added this field at last in internal table..now i moved the position to first by declaring another internal table of same type i_file2.

Thanks and kind regards,
madhuri.
Copyright ?2007 - 2008 www.jt77.com