Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to add fields in table

Former Member
0 Kudos

Hi All

here i have a question. How to add total Quantity (MENGE), amount in local currency (DMBTR) fields in MSEG table based on the condition when the vendor number (LIFNR),Document number(MBLNR),Material NUmber( MATNR) are same.

Thanks & regards

sreenu

3 REPLIES 3

Former Member
0 Kudos

Sreenivas,

You can loop at the table and calculate the totals manually. Whenever the data changes for Vendor, document, Material reset the total variables.

Regards,

Ravi

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

You can use the COLLECT statement. HEre you get all your records and then collect them into anther internal table, the collect will happen on the fields to the left of the first numeric, so it will collect on mblnr lifnr and matnr.



report zrich_0001.

data: begin of imseg occurs 0,
      mblnr type mseg-mblnr,
      lifnr type mseg-lifnr,
      matnr type mseg-matnr,
      menge type mseg-menge,
      dmbtr type mseg-dmbtr,
      end of imseg.

data: begin of ims occurs 0,
      mblnr type mseg-mblnr,
      lifnr type mseg-lifnr,
      matnr type mseg-matnr,
      menge type mseg-menge,
      dmbtr type mseg-dmbtr,
      end of ims.

select-options: s_mblnr for ims-mblnr.

select * into corresponding fields of table imseg
        from mseg
                 where mblnr in s_mblnr.


loop at imseg.
  clear ims.
  move-corresponding imseg to ims.
  collect ims.

endloop.






Regards,

Rich Heilman

Former Member
0 Kudos

That calculation will be wrong if you don't consider the 'Debit/Credit Indicator' or the field SHKZG. This will inform whether the quantity is taken out or added in to a particular location or just plain destroyed. A value of 'H' in this field indicates that it is added, and a value of 'S' indicates that it is removed.

You want this total at the break of document number besides others. Does this mean you have material documents that have multiple lines for that same material? Otherwise, adding material document to the break logic will not result in the totals that you think you need.