Application Development and Automation 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: 
Read only

Issue with duplicates

Former Member
0 Likes
1,166

Hi,

If material document, material document item, po no and po item are same and quantatity is zero then delete the entire rows. I am deleting the rows when they are duplicates and quantity is zero. But the problem is when the quantity is in integers, I have to substract the quantity.

Regards

Kalpana

10 REPLIES 10
Read only

Former Member
0 Likes
1,119

You are talking in perspective of internal table OR database table.

If this is in database table then you have to fetch data in internal table first, otherwise you can directly apply below logic for internal table:

1. Loop at internal table into WA1.
     1.1. read same table with same material document, material document item, po no and po item in WA2.

     1.2 if entry found then check if WA1-QUANTITY = WA2-QUANTITY.

            1.2.1 if yes then delete entries from internal table.

                     else WA1-QUANTITY = WA1-QUANTITY - WA2-QUANTITY.

                              modify internal table by WA1.

ENDLOOP.

Hope this will work for you. else please copy your code, I will modify that accordingly.

Read only

Former Member
0 Likes
1,119

Please find attached file for your reference.

The problem is with the rows displaying in yellow color.

Regards

kalpana

Read only

0 Likes
1,119

please make your requirement more clearer,

If you are trying to consolidate the records based on quantity, Use COLLECT statement.

Loop ur <int table>

    collect <wa> to <output int tab>

endloop.

Read only

0 Likes
1,119

Hi,

From your Internal Table Convert Integer value to Quantity.

Then Proceed to delete the duplicates.

1. Before deleting Sort ITAB by material document, material document item, po no and po item.

2. delete itab where quantity = 0.

3. Now use the COLLECT statement to sum the quantity.

       loop at itab.

               collect itab to it_final.

          endloop.

Regards,

S.Chandrakumar



Read only

0 Likes
1,119

Hi,

The attached document is '.txt' file having no color coding. Please explain your req. with example.

BR.

Read only

Former Member
0 Likes
1,119

hi Kalpana,

in your case, you should not use delete adjacent duplicates from itab. write your process code like this:

data: gwa_itab like line of gt_itab,

        gwa_trd   like line of gt_itab.

loop at gt_itab into gwa_itab.

   if gwa_itab-no = gwa_trd-no and gwa_itab-item = gwa_trd-item and gwa_itab-quantity = 0.

        delete itab index sy-tabix.

   endif.

   move-corresponding gwa_itab to gwa_trd.

endloop.

if it works, let me know, thanks.

regards,

Archer

Read only

Former Member
0 Likes
1,119

You can also use control break statement.

define one internal table with these five fields and use AT NEW statement.

Here you can sum your quantity field.

Read only

Former Member
0 Likes
1,119

Hi Kalpana,

Please use collect statement. It will group po numbers, items, and sum up quantity.

Kindly ellaborate your issue if further assistance required.

Best rRgards,

Abirami

Read only

Former Member
0 Likes
1,119

Hi Kalpana.

Could you please tell us ur  requirements clearly and u can give ur cod ehere so we can modify the same code to substract for Int Value.

Thanks

Tarak

Read only

0 Likes
1,119

My requirement is

if buzid = 'W' and

          if mdocn = mdocit = ebeln = ebelp

          add a qantity(menge1)

          if menge1 is zero then delete  other wise show that record

I am deleting the rows when they are duplicates and quantity is zero. But the problem is when the quantity is integer value, I have to substract the quantity.

Here is my piece of code:

FORM data_retrival.
  SELECT bukrs fstag saknr INTO CORRESPONDING FIELDS OF  TABLE it_skb1 FROM skb1  WHERE fstag = 'G045' AND bukrs = '1000'."bukrs IN ('1000','2000','3000','4000','8000').
  IF  it_skb1[] IS NOT INITIAL.
    LOOP AT it_skb1.
      it_bsis-bukrs = it_skb1-bukrs.
      SELECT bukrs  belnr gjahr hkont budat blart buzid buzei shkzg xref3 wrbtr dmbtr waers  INTO CORRESPONDING FIELDS OF  TABLE it_bsis FROM bsis
      WHERE  bukrs =  it_skb1-bukrs AND hkont = it_skb1-saknr AND blart IN ('WE','RE','KP') AND buzid IN ('F','W').
      IF it_bsis[] IS NOT INITIAL.
        SELECT bukrs belnr awkey INTO CORRESPONDING FIELDS OF TABLE it_bkpf FROM bkpf FOR ALL ENTRIES IN it_bsis WHERE bukrs = it_bsis-bukrs AND belnr = it_bsis-belnr.
        SELECT ebeln ebelp belnr  gjahr bukrs buzei INTO CORRESPONDING FIELDS OF TABLE it_bseg FROM bseg FOR ALL ENTRIES IN it_bsis
        WHERE bukrs = it_bsis-bukrs  AND belnr = it_bsis-belnr AND  gjahr =  it_bsis-gjahr AND buzei  = it_bsis-buzei.
        SORT it_bseg BY ebeln ebelp.
      ENDIF.
      IF  it_bseg[] IS NOT INITIAL.
        SELECT ebeln ebelp lifn2 parvw INTO CORRESPONDING FIELDS OF TABLE it_ekpa FROM ekpa  FOR ALL ENTRIES IN it_bseg
          WHERE ebeln = it_bseg-ebeln AND parvw = 'ZM'.
      ENDIF.
      IF it_ekpa[] IS  NOT INITIAL .
        SELECT lifnr name1 sortl adrnr INTO CORRESPONDING FIELDS OF TABLE  it_lfa1 FROM lfa1 FOR ALL ENTRIES IN it_ekpa WHERE lifnr = it_ekpa-lifn2.
      ENDIF.

      LOOP AT it_bsis.
        READ TABLE it_bkpf WITH  KEY bukrs = it_bsis-bukrs belnr = it_bsis-belnr.
        it_bsis-awkey  = it_bkpf-awkey.
        MODIFY it_bsis TRANSPORTING:awkey.
        CLEAR:it_bkpf.
      ENDLOOP.

      LOOP AT it_bsis.
        IF it_bsis-buzid EQ 'W'.
          it_bsis-mdocn  = it_bsis-xref3+4(10).
          it_bsis-mdocy  = it_bsis-xref3+0(4).
          it_bsis-mdocit = it_bsis-xref3+15(3).
          MODIFY it_bsis TRANSPORTING:mdocn,mdocy,mdocit.
        ELSEIF it_bsis-buzid EQ 'F'.
          it_bsis-mdocn  = it_bsis-awkey+0(10).
          it_bsis-mdocy  = it_bsis-awkey+10(4).
          MODIFY it_bsis TRANSPORTING:mdocn,mdocy,mdocit.
        ENDIF.
      ENDLOOP.

      LOOP AT it_bsis.
        IF it_bsis-blart EQ 'WE' OR it_bsis-blart EQ 'RE'.
          SELECT SINGLE menge meins matnr werks INTO (it_bsis-menge1,it_bsis-meins1,it_bsis-matnr1,it_bsis-werks1) FROM mseg WHERE mblnr = it_bsis-mdocn.
          MODIFY it_bsis TRANSPORTING:menge1,meins1,matnr1.
*          SELECT SINGLE maktx INTO it_bsis-maktx1 FROM zmt_mat_desc_api LEFT JOIN mseg ON zmt_mat_desc_api~matnr = mseg~matnr AND zmt_mat_desc_api~werks = mseg~werks.
          SELECT SINGLE maktx INTO it_bsis-maktx1 FROM zmt_mat_desc_api WHERE matnr = it_bsis-matnr1 AND werks = it_bsis-werks1.
          MODIFY it_bsis TRANSPORTING maktx1.
        ENDIF.
        IF it_bsis-matnr1 IS INITIAL.
          READ TABLE it_bseg WITH KEY bukrs = it_bsis-bukrs  belnr = it_bsis-belnr gjahr = it_bsis-gjahr buzei = it_bsis-buzei.
          it_bsis-ebeln = it_bseg-ebeln.
          it_bsis-ebelp = it_bseg-ebelp.
          MODIFY it_bsis TRANSPORTING:ebeln,ebelp.
*          CLEAR:it_bseg.
          SELECT SINGLE txz01 INTO it_bsis-maktx1 FROM ekpo WHERE ebeln = it_bsis-ebeln AND ebelp = it_bsis-ebelp."WHERE ebeln = it_bseg-ebeln ."AND matnr = it_bsis-mdocn.
          MODIFY it_bsis TRANSPORTING maktx1.
          CLEAR:it_bseg.
        ENDIF.

      LOOP AT it_bsis.
        READ TABLE it_skb1.
        it_bsis-saknr = it_skb1-saknr.
        MODIFY it_bsis TRANSPORTING saknr.
        CLEAR:it_skb1.
        READ TABLE it_ekpa WITH KEY ebeln = it_bseg-ebeln.
        it_bsis-lifn2 = it_ekpa-lifn2.
        MODIFY it_bsis TRANSPORTING lifn2.
        CLEAR:it_ekpa.
        READ TABLE it_lfa1 WITH KEY lifnr = it_bsis-lifn2.
        it_bsis-name1 = it_lfa1-name1.
        it_bsis-sortl = it_lfa1-sortl.
        it_bsis-adrnr = it_lfa1-adrnr.
        MODIFY it_bsis TRANSPORTING:name1,sortl,adrnr.
        CLEAR:it_lfa1.
        READ TABLE it_bseg WITH KEY bukrs = it_bsis-bukrs belnr = it_bsis-belnr gjahr = it_bsis-gjahr buzei = it_bsis-buzei.
        it_bsis-ebeln = it_bseg-ebeln.
        it_bsis-ebelp = it_bseg-ebelp.
        MODIFY it_bsis TRANSPORTING:ebeln,ebelp.
        CLEAR:it_bseg.
        IF it_bsis-buzid EQ 'W'.
          SELECT SINGLE lifnr ebeln INTO (it_bsis-lifnr1,it_bsis-ebeln1) FROM ekko WHERE ebeln = it_bsis-ebeln.
          MODIFY it_bsis TRANSPORTING:lifnr1,ebeln1.
          SELECT SINGLE name1 INTO it_bsis-name12 FROM lfa1 WHERE lifnr = it_bsis-lifnr1.
          MODIFY it_bsis TRANSPORTING name12.
        ELSEIF it_bsis-buzid EQ 'F'.
          SELECT SINGLE lifnr ebelp INTO (it_bsis-lifnr1,it_bsis-ebelp1) FROM bseg
            WHERE bukrs = it_bsis-bukrs  AND belnr = it_bsis-belnr AND  gjahr =  it_bsis-gjahr AND buzei  = it_bsis-buzei.
          MODIFY it_bsis TRANSPORTING:lifnr1.
          SELECT SINGLE name1 INTO it_bsis-name12 FROM lfa1 WHERE lifnr = it_bsis-lifnr1.
          MODIFY it_bsis TRANSPORTING name12.
        ENDIF.
        IF it_bsis-shkzg = 'S'.
          it_bsis-menge1 = it_bsis-menge1 * -1.
          MODIFY it_bsis TRANSPORTING menge1.
        ENDIF.
        IF it_bsis-shkzg = 'S'.
          it_bsis-wrbtr = it_bsis-wrbtr * -1.
          it_bsis-dmbtr = it_bsis-dmbtr * -1.
          MODIFY it_bsis TRANSPORTING:wrbtr,dmbtr.
        ENDIF.
        IF it_bsis-buzid = 'F'.
          SELECT SINGLE waers FROM bsis INTO it_bsis-waers WHERE waers = 'INR'.
          MODIFY it_bsis TRANSPORTING waers.
        ENDIF.
        IF it_bsis-buzid = 'W'.
          SORT it_bsis BY mdocn mdocit ebeln ebelp menge1.
          DELETE ADJACENT DUPLICATES FROM it_bsis COMPARING mdocn mdocit ebeln ebelp menge1.
        ENDIF.
      ENDLOOP.