‎2010 Nov 16 2:54 PM
Hi,
I have 2 internal tables, the first table which has quantity, week(WKYYYY format) matnr werks.
2nd internal table also has the same structure , now i want a flag in 2nd internal table when collect statement happens.
Eg. 1223 abc 10 112010
1223 abc 20 122010
1224 xyz 10 122011
now my 2nd internal table should have a flag like this
1223 abc 30 122010 X
1224 xyz 10 122010 this should not have X set
like this...
Loop at internal table 1.
collect into internal table 2.
endloop.
‎2010 Nov 16 4:25 PM
Hi...
That's something that could be useful for you....
DATA: BEGIN OF tab1 OCCURS 0,
key(4) TYPE c,
matnr TYPE mara-matnr,
qty TYPE i,
END OF tab1,
BEGIN OF tab2 OCCURS 0,
key(4) TYPE c,
matnr TYPE mara-matnr,
qty TYPE i,
flag TYPE c,
END OF tab2.
REFRESH: tab1, tab2.
tab1-key = '1223'.
tab1-matnr = 'TEST1'.
tab1-qty = 10.
APPEND tab1.
CLEAR tab1.
tab1-key = '1223'.
tab1-matnr = 'TEST1'.
tab1-qty = 20.
APPEND tab1.
CLEAR tab1.
tab1-key = '1224'.
tab1-matnr = 'TEST2'.
tab1-qty = 15.
APPEND tab1.
CLEAR tab1.
tab1-key = '1225'.
tab1-matnr = 'TEST3'.
tab1-qty = 34.
APPEND tab1.
CLEAR tab1.
tab1-key = '1225'.
tab1-matnr = 'TEST3'.
tab1-qty = 28.
APPEND tab1.
CLEAR tab1.
tab1-key = '1226'.
tab1-matnr = 'TEST4'.
tab1-qty = 2.
APPEND tab1.
DATA: currkey(4) TYPE c.
LOOP AT tab1.
CLEAR tab2.
READ TABLE tab2 WITH KEY currkey.
IF sy-subrc EQ 0 AND
tab1-key EQ currkey.
tab2-flag = 'X'.
MODIFY tab2 FROM tab2 INDEX sy-tabix.
ENDIF.
MOVE-CORRESPONDING tab1 TO tab2.
IF tab1-key NE currkey.
currkey = tab1-key.
CLEAR tab2-flag.
APPEND tab2.
ELSE.
COLLECT tab2.
ENDIF.
ENDLOOP.
‎2010 Nov 16 2:58 PM
Collect statement will not work for this scenario. You have to find some other logic like reading, adding and modifying.
‎2010 Nov 16 3:38 PM
Hi
This cannot be done Simultaneously using Collect statement since the 2 table Structures are different and collect will not work.
‎2010 Nov 16 4:25 PM
Hi...
That's something that could be useful for you....
DATA: BEGIN OF tab1 OCCURS 0,
key(4) TYPE c,
matnr TYPE mara-matnr,
qty TYPE i,
END OF tab1,
BEGIN OF tab2 OCCURS 0,
key(4) TYPE c,
matnr TYPE mara-matnr,
qty TYPE i,
flag TYPE c,
END OF tab2.
REFRESH: tab1, tab2.
tab1-key = '1223'.
tab1-matnr = 'TEST1'.
tab1-qty = 10.
APPEND tab1.
CLEAR tab1.
tab1-key = '1223'.
tab1-matnr = 'TEST1'.
tab1-qty = 20.
APPEND tab1.
CLEAR tab1.
tab1-key = '1224'.
tab1-matnr = 'TEST2'.
tab1-qty = 15.
APPEND tab1.
CLEAR tab1.
tab1-key = '1225'.
tab1-matnr = 'TEST3'.
tab1-qty = 34.
APPEND tab1.
CLEAR tab1.
tab1-key = '1225'.
tab1-matnr = 'TEST3'.
tab1-qty = 28.
APPEND tab1.
CLEAR tab1.
tab1-key = '1226'.
tab1-matnr = 'TEST4'.
tab1-qty = 2.
APPEND tab1.
DATA: currkey(4) TYPE c.
LOOP AT tab1.
CLEAR tab2.
READ TABLE tab2 WITH KEY currkey.
IF sy-subrc EQ 0 AND
tab1-key EQ currkey.
tab2-flag = 'X'.
MODIFY tab2 FROM tab2 INDEX sy-tabix.
ENDIF.
MOVE-CORRESPONDING tab1 TO tab2.
IF tab1-key NE currkey.
currkey = tab1-key.
CLEAR tab2-flag.
APPEND tab2.
ELSE.
COLLECT tab2.
ENDIF.
ENDLOOP.
‎2010 Nov 16 5:00 PM
Hi,
Try this code
data : begin of it1,
fld1,
fld2(10),
fld3(10),
fld4 type i,
end of it1.
data : begin of it2,
fld1,
fld2(10),
fld3(10),
fld4 type i,
fld5,
end of it1.
data : wa2 like it2.
sort it1 by fld1 fld2 fld3.
loop at it1.
wa2 = it1.
count = count + 1.
at end of fld3.
sum.
wa2-fld4 = it1-fld4.
if count gt 1.
wa2-fld5 = 'X'.
endif.
clear count.
append wa2 to it2.
clear wa2.
endat.
endloop.
Thanks,
Anmol Bhat.
Edited by: anmol112 on Nov 16, 2010 3:48 PM
‎2010 Nov 16 8:03 PM
Firstly, the first two rows will not be collected into one row because 4th field values are different.
The solution to your question is, instead of adding a flag column to the second itab, add a number column and set 1 for that column in the loop. After all the collection is complete, you should interpret any number greater than 1 as 'X'.
‎2010 Nov 16 8:53 PM
‎2010 Nov 17 5:50 AM
Try this:
DESCRIBE TABLE a LINES index.
COLLECT wa2 INTO itab2.
DESCRIBE TABLE a LINES index1.
IF index = index1.
collect = 'X'.
ELSEIF index LT index1 AND collect = 'X'.
CLEAR collect.
wa2-flag = 'X'.
MODIFY itab2 FROM wa2 INDEX index TRANSPORTING flag.
CLEAR wa2-flag.
ENDIF.
‎2010 Nov 19 3:16 PM
Hi,
<< Moderator message - Cut and paste response from various sources removed. Plagiarism is not allowed in SCN >>
Edited by: chandrasek on Nov 19, 2010 4:20 PM
Edited by: Rob Burbank on Nov 19, 2010 10:41 AM
‎2010 Nov 19 3:36 PM
>
> Hi,
>
> COLLECT can create unique or compressed datasets and should be used precisely for this purpose. If uniqueness or
>
> compression are unimportant, or two values with identical default key field values could not possibly occur in your particular
>
> task, you should use APPEND instead. However, for a unique or compressed dataset which is also efficient, COLLECT is the
>
> statement to use.
>
> Edited by: chandrasek on Nov 19, 2010 4:20 PM
ow... naughty naughty... i'm pretty sure you didn't write that piece yourself.