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

INTERNAL TABLE

Former Member
0 Likes
710

Hi friends

I have two questions

1)

I have my final internal table as below

CORPID MATNR QTY ADDRID

123 10 1 101

123 20 2 101

123 10 5 101

123 10 5 102

123 20 5 102

123 30 8 102

123 20 5 102

so now i want to add the QTY when the CORPID, ADDRID AND MATNR are same so from the above table i need to have

CORPID MATNR QTY ADDRID

123 10 6 101

123 20 2 101

123 10 5 102

123 20 10 102

123 30 8 102

2)

Based on this modified internal table i need to create sales orders

Based on the CORPID and ADDRID i have to create one sales order so from the modified table i have to create two sales.

can any one help me out in this logic

7 REPLIES 7
Read only

Former Member
0 Likes
676

Hi satya,

try to collect into the internal table.

regards, Dieter

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
676

You should define another internal able and COLLECT into it.

data: begin of itab_c occurs 0,
        CORPID type ......  ,
        MATNR  type ......  ,
        ADDRID type ......  ,
        QTY      type ......  ,
        end of itab_c.


loop at itab.

  clear itab_c.
  move-corresponding itab to itab_c.
  collect itab_c.

endloop.

Regards,

RIch Heilman

Read only

Former Member
0 Likes
676
1.  change ur internal table order of fields to
            
          CORPID
          ADDRID
          MATNR
          QTY
     
       sort itab by CORPID ADDRID MATNR QTY 
        delete adjacent duplicates from itab comparing CORPID ADDRID MATNR.

          loop at itab.
             at end of matnr.
                SUM.                
             endat.
           endloop.

 2.   loop at itab.
        at end of ADDRID.
           *create one sales order
        endat.
    endat.

Message was edited by:

Chandrasekhar Jagarlamudi

Read only

Former Member
0 Likes
676

u need to use collect statement...here CORPID / MATNR / ADDRID should be char fields & QTY needs to be quantity field.

loop at itab.

collect itab.

endloop.

so, itab will have....

123 10 6 101

123 20 2 101

123 10 5 102

123 20 10 102

123 30 8 102

now write a BDC to create sales order using VA01 with condition as

sort itab by CORPID ADDRID.

loop at itab.

at new ADDRID.

fill header details.

endat.

fill item details.

at end of ADDRID.

save the order.

endat.

clear header data.

endloop.

Read only

Former Member
0 Likes
676

Hi Satya,

you can use COLLECT statement inside the LOOP to get the output.

For ex:

Loop at itab.

itab1-CORPID = itab-CORPID.

itab1-MATNR = itab-MATNR.

itab1-QTY = itab-QTY

itab1-ADDRID = itab-ADDRID.

Collect itab1.

Endloop.

regards,

Madhumitha

Read only

0 Likes
676

here iam not using QTY as quantity type

Read only

0 Likes
676

Hi,

If QTY is of type N, P or F, you can definitely use the Collect statement.

Otherwise rearrange the itab internal table strucutre to have QTY field as the last one...

then loop at itab and use

keep adding itab-qty to a temp variable.

at new fld1 fld2 fld3.

move-corresponding itab to itab1.

wa_qty = wa_qty+itab-qty.

on change of itab-qty.

itab1-qty = wa_qty.

append itab1.

clear: itab1,wa_qty.

endon.

Regards

Subramanian