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: 

Deleting line item which has same batch and adding up their quantity in adobe output

Hamza_imran
Participant
0 Kudos

Hello gurus,

Need your help with the logic. i need to delete the line item which has the similar batch originating from similar or different sales order. i need to add up their quantity and just show them once accumulated. Stuck in this logic in the adobe form output. Any help would be more than appreciated.

Regards,

Hamza

1 ACCEPTED SOLUTION

Patrick_vN
Active Contributor

Hey,

if you check out the code below (which is a simplified version of what you posted), you'll quickly see it is rather meaningless:

IF ls_data-matnr EQ ls_data-matnr.
..
ENDIF

Why? Simply because you are comparing the variables with itself (it is like writing "IF a = a."). So first thing you would have to do is have the different line items in different structures (if you're sticking with this approach).

Or, forget about this approach and go for a statement like LOOP AT .. GROUP BY. If you group by the batch (and related fields) then all that rests to do is calculate the total quantity.

6 REPLIES 6

Hamza_imran
Participant
0 Kudos

i'm trying to write this code in the loop but it's not exactly doing what i want. Also, i need some clarity on how to delete/hide the row with the similar material and batch no.

         if ls_data-matnr eq ls_data-matnr and  ls_data-charg eq ls_data-charg.
  ls_data-fkimg = ls_data-fkimg + ls_data-fkimg.

  endif.

Patrick_vN
Active Contributor

Hey,

if you check out the code below (which is a simplified version of what you posted), you'll quickly see it is rather meaningless:

IF ls_data-matnr EQ ls_data-matnr.
..
ENDIF

Why? Simply because you are comparing the variables with itself (it is like writing "IF a = a."). So first thing you would have to do is have the different line items in different structures (if you're sticking with this approach).

Or, forget about this approach and go for a statement like LOOP AT .. GROUP BY. If you group by the batch (and related fields) then all that rests to do is calculate the total quantity.

0 Kudos

patrick.vannierop what about deleting the line item with the same batch?

0 Kudos

also can u please suggest how should i use LOOP AT .. GROUP BY in my current scenario?

Something like this?

LOOP AT [table_line_items] INTO grp
                      		GROUP BY ( key1 = grp-matnr key2 = grp-charg ).
*... prepare "grouped" item ...*

      	LOOP AT GROUP grp INTO member.
*...	  add member-fkimg to ...*
      	ENDLOOP.
*... add "grouped" item to [table_grouped_items] ...*
ENDLOOP.


*... replace contents of [table_line_items] with contents of [table_grouped_items]

To explain my pseudo-code, you need to define by what fields you want to group of course, the MATNR & CHARG are just an example.

Per group grp of (line items) you then:

  1. Prepare a new record - with the fields that this item (that "groups" the relevant items) needs to contain
  2. Loop at he grouped items and calculate the total
  3. Add the newly created record (with the data representing the group of line items) to a new table.

Once all the items/groups have been dealt with, replace the content of your line items table with the contents of the table containing the grouped items.

0 Kudos

Thanks for the help patrick!