Collect statement help
Hi all,
need help on collect logic...I have a temporary table w_meg1 which has data
Month value
1 0.5
1 1
2 0.5
2 1
2 1.5
3 4
4 1
6 2
Here i need to add the data under month 1 and display as one single line.
i am getting this data for w_meg1 using the do loop..which is like this
LOOP AT t_coss.
DO 12 TIMES
VARYING w_meg
FROM t_coss-meg001 NEXT t_coss-meg002.
endloop.
i need the output like this
Month value
1 1.5
2 3
3 4
4 1
6 2
any ideas?
Moderator Message: Basic Question. Please search for available information before posting.
Edited by: kishan P on Nov 23, 2010 4:31 PM
Hi,
If the value 1 is not character field you need to create an new internal table with character field for that value.
Then pass that internal table to new internal table .
Data : itab3 is of type new internal table you created with Character field.
itab2[] = itab1[].
Then
Loop at itab2 into wa_itab2.
wa_itab3-value = wa_itab2-value.
wa_itab3-value1 = wa_itab2-value1.
collect wa_itab3 into itab3.
clear : wa_itab3,wa_itab2,
endloop.
Hope this might solve your Problem,
With Regards,
Sumodh.P
Similar Messages
-
Help with a COLLECT statement.
I had to make changes to some code and these changes required me to add some fields to an internal table. Below is what the table looked like before I made any changes:
DATA : BEGIN OF t_frgroup OCCURS 0,
BEGIN CHANGE 02/11/03
hazmat TYPE c,
END CHANGE 02/11/03
mfrgr LIKE lips-mfrgr,
brgew LIKE lips-brgew,
lfimg LIKE lips-lfimg,
qtypal LIKE w_nbr_palletsx,
qtypce LIKE w_nbr_palletsx,
vstel LIKE likp-vstel,
no_cnvrt TYPE c,
END OF t_frgroup.
This is what it looked like after I made the changes:
DATA : BEGIN OF t_frgroup OCCURS 0,
BEGIN CHANGE 02/11/03
hazmat TYPE c,
END CHANGE 02/11/03
mfrgr LIKE lips-mfrgr,
brgew LIKE lips-brgew,
lfimg LIKE lips-lfimg,
qtypal LIKE w_nbr_palletsx,
qtypce LIKE w_nbr_palletsx,
vstel LIKE likp-vstel,
no_cnvrt TYPE c,
matnr TYPE lips-matnr,
vbeln TYPE lips-vbeln,
posnr TYPE lips-posnr,
qty LIKE vblkp-lfimg,
vrkme LIKE lips-vrkme,
converted(1) TYPE c VALUE 'N',
END OF t_frgroup.
My issue is, after adding those fields, my collect statement no longer works:
LOOP AT t_lips.
MOVE-CORRESPONDING t_lips TO t_frgroup.
COLLECT t_frgroup.
ENDLOOP.
I need it to collect with the key being mfrgr. How can I do this? After adding the fields the collect statement now acts as an insert (I assume that matnr is now acting as the key) instead of collect.
Regards,
AaronHi Aaron,
1. Define the table keys while defining your internal table.
2. The order of the fields in the structure should be that the key fields come first , then the quantity fields and amount fields next.
3. Sort the table by the key fields before the loop.
The collect statment is creating news entries because If the system finds an entry with the key fields , the numeric fields that are not part of the table key are added to the sum total of the existing entries. If it does not find an entry, the system creates a new entry instead. Clearly the system is unable to find the existing entry because the key fields are not defined in your internal table or the fields are are out of order.
Hope this helps.
A simple example depicting this is as follows :
TYPES: BEGIN OF COMPANY,
NAME(20) TYPE C,
SALES TYPE I,
END OF COMPANY.
DATA: COMP TYPE COMPANY,
COMPTAB TYPE HASHED TABLE OF COMPANY
WITH UNIQUE KEY NAME.
COMP-NAME = 'Duck'. COMP-SALES = 10. COLLECT COMP INTO COMPTAB.
COMP-NAME = 'Tiger'. COMP-SALES = 20. COLLECT COMP INTO COMPTAB.
COMP-NAME = 'Duck'. COMP-SALES = 30. COLLECT COMP INTO COMPTAB.
regards,
Advait Gode.
Edited by: Advait Gode on Mar 28, 2008 3:50 PM -
How to use collect statement properly
In PBID table , i will get 4 rows for a material . I will get the corresponding values of bdzei from the same table . Now i will pass this bdzei into pbhi table. then i will get some 200 rows of data. I have to sum up the field plnmg , by grouping the laeda field of pbhi. In short, i need to know the sum of pbhi-plnmg for a particular pbhi-laeda . I know a way to do it. But i want to know how to use the COLLECT statement for this purpose. My output should contain oly 1 line for 1 material ..
PBID table
Matnr BDZEI
p4471 457
1002
2309
2493
PBHI table
BDZEI LAEDA PLNMG
1002 06.08.2004 0.000
1002 06.08.2004 83.000
457 07.08.2004 12.000
457 07.08.2004 24.000
Reqd O/p
MATNR LAEDA PLNMG
p4471 06.08.2004 83
p4471 07.08.2004 36
Hope u understood my situation .please help me out ...
Thanking you in advance ..
ShankarREPORT zppr_zpipr NO STANDARD PAGE HEADING LINE-SIZE 150 LINE-COUNT 63.
TABLES: pbid,
pbhi,
makt,
mseg,
mkpf.
DATA: BEGIN OF it_pbid OCCURS 0,
matnr LIKE pbid-matnr, " Material
status TYPE c LENGTH 4, " For distinguishing materials from pbid and pbim .. will contain space for PBID and 'PBIM' for PBIM
bdzei LIKE pbid-bdzei,
laeda LIKE pbhi-laeda,
end of it_pbid.
DATA: BEGIN OF it_pbim OCCURS 0,
matnr LIKE pbid-matnr, " Material
status TYPE c LENGTH 4, " For distinguishing materials from pbid and pbim .. will contain space for PBID and 'PBIM' for PBIM
bdzei LIKE pbim-bdzei,
laeda LIKE pbhi-laeda,
end of it_pbim.
DATA: BEGIN OF it_pbid_pbim OCCURS 0,
matnr LIKE pbid-matnr, " Material
laeda LIKE pbhi-laeda, " Reduction Date
dbmng LIKE pbhi-dbmng, " Planned quantity in the data base
plnmg LIKE pbhi-plnmg, " Planned quantity
status TYPE c LENGTH 4, " For distinguishing materials from pbid and pbim .. will contain space for PBID and 'PBIM' for PBIM
mblnr LIKE mseg-mblnr, " Material Doc Number
pbfnr LIKE pbid-pbdnr, " Plan Number
maktx LIKE makt-maktx, " Matl Desc
aenam LIKE pbhi-aenam, " User Changed
erfmg LIKE mseg-erfmg, " Qty Invoiced
budat LIKE mkpf-budat, " Invoice date
bdzei LIKE pbid-bdzei, " Independent requirements pointer
werks LIKE pbid-werks, " plant
pirrednqty TYPE i, " PIR Reduction Quantity = pbih-plnmg - pbih-dbmng
diff TYPE i, " Difference
slno TYPE i, " Sl No
END OF it_pbid_pbim.
DATA: BEGIN OF it_allrows OCCURS 0.
INCLUDE STRUCTURE it_pbid_pbim.
DATA: END OF it_allrows.
*DATA: BEGIN OF it_final OCCURS 0.
INCLUDE STRUCTURE it_pbid_pbim.
*DATA: END OF it_final.
DATA: BEGIN OF line,
matnr LIKE pbid-matnr, " Material
laeda LIKE pbhi-laeda, " Reduction Date
plnmg LIKE pbhi-plnmg, " Planned quantity
maktx LIKE makt-maktx, " Matl Desc
dbmng LIKE pbhi-dbmng, " Planned quantity in the data base
mblnr LIKE mseg-mblnr, " Material Doc Number
pbfnr LIKE pbid-pbdnr, " Plan Number
aenam LIKE pbhi-aenam, " User Changed
erfmg LIKE mseg-erfmg, " Qty Invoiced
budat LIKE mkpf-budat, " Invoice date
bdzei LIKE pbid-bdzei, " Independent requirements pointer
werks LIKE pbid-werks, " plant
pirrednqty TYPE i, " PIR Reduction Quantity = pbih-plnmg - pbih-dbmng
diff TYPE i, " Difference
slno TYPE i, " Sl No
status TYPE c LENGTH 4, " For distinguishing materials from pbid and pbim .. will contain space for PBID and 'PBIM' for PBIM
END OF line.
DATA Itfinal1 LIKE STANDARD TABLE
OF LINE
WITH DEFAULT KEY.
DATA ITfinal LIKE ITfinal1.
DATA: BEGIN OF it_dates OCCURS 0,
date TYPE sy-datum,
END OF it_dates.
DATA: l_slno TYPE i.
DATA: l_zebra TYPE c.
SELECT-OPTIONS:
s_werks FOR pbid-werks obligatory.
SELECT-OPTIONS:
s_matnr FOR pbid-matnr.
SELECT-OPTIONS:
s_pbdnr FOR pbid-pbdnr.
SELECT-OPTIONS:
s_laeda FOR pbhi-laeda obligatory.
parameter:
c_print type checkbox.
SELECT matnr bdzei FROM pbid INTO (it_pbid-matnr, it_pbid-bdzei) WHERE werks IN s_werks AND matnr IN s_matnr AND pbdnr IN s_pbdnr.
it_pbid-status = 'PBID'.
APPEND it_pbid.
move-corresponding it_pbid to it_pbid_pbim.
Append it_pbid_pbim.
ENDSELECT.
SELECT matnr bdzei FROM pbim INTO (it_pbim-matnr,it_pbim-bdzei) WHERE werks IN s_werks AND matnr IN s_matnr AND pbdnr IN s_pbdnr.
APPEND it_pbim.
Append it_pbid_pbim.
ENDSELECT.
*break-point.
START-OF-SELECTION.
LOOP AT s_laeda.
it_dates-date = s_laeda-low.
APPEND it_dates.
ENDLOOP.
DATA: l_startdate LIKE sy-datum.
IF s_laeda-high EQ space.
ELSE.
l_startdate = s_laeda-low + 1.
DO.
IF l_startdate <= s_laeda-high.
it_dates-date = l_startdate.
APPEND it_dates.
ELSE.
it_dates-date = sy-datum.
EXIT.
ENDIF.
l_startdate = l_startdate + 1.
ENDDO.
ENDIF.
*break-point.
LOOP AT it_pbim.
LOOP AT it_dates.
it_pbim-laeda = it_dates-date.
it_pbim-status = 'PBIM'.
MODIFY it_pbim TRANSPORTING laeda status.
MOVE-CORRESPONDING it_pbim TO it_pbid_pbim.
APPEND it_pbid_pbim.
ENDLOOP.
ENDLOOP.
break-point.
l_zebra = 'X'.
DATA: l_toterfmg LIKE mseg-erfmg.
DATA: l_erfmg LIKE mseg-erfmg.
data: l_totpir type i.
**************************************PBID*************************************
LOOP AT it_pbid.
move-corresponding it_pbid to it_pbid_pbim.
append it_pbid_pbim.
SELECT SINGLE maktx FROM makt INTO (it_pbid_pbim-maktx) WHERE matnr = it_pbid-matnr.
MODIFY table it_pbid_pbim TRANSPORTING maktx.
SELECT aenam laeda FROM pbhi INTO (it_pbid_pbim-aenam,it_pbid_pbim-laeda) WHERE bdzei = it_pbid-bdzei AND aenam = 'Abbau-'.
MODIFY TABLE it_pbid_pbim TRANSPORTING aenam laeda. " debug here
select single sum( dbmng ) sum( plnmg ) FROM pbhi INTO (it_pbid_pbim-dbmng,it_pbid_pbim-plnmg) WHERE bdzei = it_pbid-bdzei AND aenam = 'Abbau-' and laeda = it_pbid_pbim-laeda..
MODIFY TABLE it_pbid_pbim TRANSPORTING dbmng plnmg. " debug here
endselect.
it_pbid_pbim-pirrednqty = it_pbid_pbim-dbmng - it_pbid_pbim-plnmg.
MODIFY table it_pbid_pbim TRANSPORTING pirrednqty.
IF ( it_pbid_pbim-laeda IN s_laeda AND it_pbid_pbim-aenam EQ 'Abbau-' ).
MOVE-CORRESPONDING it_pbid_pbim TO it_allrows.
append it_allrows.
ELSEIF NOT it_pbid_pbim-laeda IN s_laeda.
delete it_pbid_pbim index sy-tabix. " debug here
ENDIF.
ENDSELECT.
ENDLOOP.
**************************************PBIM*************************************
LOOP AT it_pbim.
move-corresponding it_pbim to it_pbid_pbim.
append it_pbid_pbim.
SELECT SINGLE maktx FROM makt INTO (it_pbid_pbim-maktx) WHERE matnr = it_pbim-matnr.
MODIFY table it_pbid_pbim TRANSPORTING maktx.
SELECT aenam laeda FROM pbhi INTO (it_pbid_pbim-aenam,it_pbid_pbim-laeda) WHERE bdzei = it_pbim-bdzei AND aenam = 'Abbau-'.
MODIFY TABLE it_pbid_pbim TRANSPORTING aenam laeda. " debug here
select single sum( dbmng ) sum( plnmg ) FROM pbhi INTO (it_pbid_pbim-dbmng,it_pbid_pbim-plnmg) WHERE bdzei = it_pbim-bdzei AND aenam = 'Abbau-' and laeda = it_pbid_pbim-laeda..
MODIFY TABLE it_pbid_pbim TRANSPORTING dbmng plnmg. " debug here
it_pbid_pbim-pirrednqty = it_pbid_pbim-dbmng - it_pbid_pbim-plnmg.
MODIFY table it_pbid_pbim TRANSPORTING pirrednqty.
IF ( it_pbid_pbim-laeda IN s_laeda AND it_pbid_pbim-aenam EQ 'Abbau-' ).
MOVE-CORRESPONDING it_pbid_pbim TO it_allrows.
append it_allrows.
ELSEIF NOT it_pbid_pbim-laeda IN s_laeda.
delete it_pbid_pbim index sy-tabix. " debug here
ENDIF.
ENDSELECT.
ENDLOOP.
sort it_allrows by matnr laeda status.
**********************************ALL ROWS************************
loop at it_allrows.
line-matnr = it_allrows-matnr.
line-laeda = it_allrows-laeda.
line-plnmg = it_allrows-plnmg.
line-dbmng = it_allrows-dbmng.
line-mblnr = it_allrows-mblnr.
line-pbfnr = it_allrows-pbfnr.
line-maktx = it_allrows-maktx.
line-aenam = it_allrows-aenam.
line-erfmg = it_allrows-erfmg.
line-budat = it_allrows-budat.
line-bdzei = it_allrows-bdzei.
line-werks = it_allrows-werks.
line-pirrednqty = it_allrows-pirrednqty.
line-diff = it_allrows-diff.
line-slno = it_allrows-slno.
line-status = it_allrows-status.
collect line into itfinal1.
endloop.
loop at itfinal1 into line.
collect line into itfinal.
write: / line-matnr, line-plnmg, line-dbmng,line-laeda,line-status..
endloop.
skip 4.
loop at itfinal into line.
write: / line-matnr, line-plnmg, line-dbmng,line-laeda,line-status..
endloop.
break-point. -
Two collect statement from internal table
Dear Experts,
I want populate values to two internal tables from a internal table.
can i use two collect statement for different internal table from a single internal table.
advise please.
Thanks in advance.
R.Rajendranhi there....
well u can very well use this thing.....
use the two colect statements inside the loop which u will use to read the records of the input table.
hope it helps.
do reward if it does. -
Problem with Collect statement
Hi Experts,
I am facing a peculiar problem. Please go through the code below and it is not giving the aggregate of it_ekbe_642_pgi-menge for the same it_ekbe_642_pgi-ebeln and it_ekbe_642_pgi-ebelp.
LOOP AT it_ekbe_642_pgi.
it_ekbe_642_pgi_tot-ebeln = it_ekbe_642_pgi-ebeln.
it_ekbe_642_pgi_tot-ebelp = it_ekbe_642_pgi-ebelp.
it_ekbe_642_pgi_tot-budat = it_ekbe_642_pgi-budat.
it_ekbe_642_pgi_tot-xblnr = it_ekbe_642_pgi-xblnr.
it_ekbe_642_pgi_tot-menge = it_ekbe_642_pgi-menge.
COLLECT it_ekbe_642_pgi_tot.
ENDLOOP.
Please suggest.
Thanks....
Shibaji.Hi Shibaji Maitra ,
Since you are aggregating the it_ekbe_642_pgi-menge for the same it_ekbe_642_pgi-ebeln and it_ekbe_642_pgi-ebelp.
For using the Collect statement the order of the fields should be
in proper order i.e. all the char fields come up & then after that
all the numeric fields.Please check the sequence in your internal
table and also the fields type of menge field.
LOOP AT it_ekbe_642_pgi.
it_ekbe_642_pgi_tot-ebeln = it_ekbe_642_pgi-ebeln.
it_ekbe_642_pgi_tot-ebelp = it_ekbe_642_pgi-ebelp.
it_ekbe_642_pgi_tot-xblnr = it_ekbe_642_pgi-xblnr.
it_ekbe_642_pgi_tot-budat = it_ekbe_642_pgi-budat.
it_ekbe_642_pgi_tot-menge = it_ekbe_642_pgi-menge.
COLLECT it_ekbe_642_pgi_tot.
ENDLOOP.
Rewards points if helpful.
Regards
Manoj Kumar -
Internal Table Line Operations - Collect Statement
Hello Gurus,
I have an internal table with data in it. The fields of the internal table are
Location - Matnr - Qty - Flag.
Same material can be at different locations with different quantities. I need to get material and total quantity of the material in all the locations in a new internal table.
If the table (it_tab) contains -
Location - matnr - qty - flag
1200 abc 10 S
1201 abc 20 S
1205 abc 30 S
1207 abc 50 S
1200 xyz 20 S
1201 xyz 25 S
1300 xyz 22 S
From this table, I need to get the result int table (it_res) as below -
Matnr - qty
abc 110
xyz 67
110 = 102030+50
67 = 252220
My idea is we can use collect statement looping the it_tab table.
Please help me how to do this.
Regards,
BaluHi balu,
1. Simple
2. Create one another internal table STAB,
with only two fields
a) MATNR
b) QTY
3. Now,
4.
Loop at Itab.
Move-corresponding itab to STAB.
COLLECT STAB.
Endloop.
regards,
amit m. -
Collect Statement to group on character fields
Hi,
I am working on some specific requirements on a support project and found a bit scenario where there is a data in an internal table and displayed the group wise total. for which the collect statement is used.
loop at lt_matdata into lwa_matdata.
lwa_final-docno = lwa_matdata-docno.
lwa_final-matnr = lwa_matdata-matnr.
lwa_final-puqty = lwa_matdata-puqty.
lwa_final-amt = lwa_matdata-amount.
collect lwa_final into lt_final.
endloop.
now the problem is i need to add RATE also to the final table. if i add the field rate to the final it will display a sum. I tried to find something that helps me adding a field RATE. Please suggest a way where i can skip the sum in collect for the specific field.
one way is i can create an another internal table and make a read statement to display the data, but wanted to know if there is any other simple and suitable solution to this.
Thanks,
JanisarHi,
Run this code & get the idea for your program...
DATA: BEGIN OF line,
col1(3) TYPE c,
col2(2) TYPE n,
col3 TYPE i,
col4 type i,
END OF line.
DATA itab LIKE SORTED TABLE OF line
WITH NON-UNIQUE KEY col1 col2.
line-col1 = 'abc'. line-col2 = '12'. line-col3 = 3.
COLLECT line INTO itab.
line-col4 = 12.
modify itab from line index sy-tabix transporting col4.
WRITE / sy-tabix.
clear line.
line-col1 = 'def'. line-col2 = '34'. line-col3 = 5.
COLLECT line INTO itab.
line-col4 = 12.
modify itab from line index sy-tabix transporting col4.
WRITE / sy-tabix.
clear line.
line-col1 = 'abc'. line-col2 = '12'. line-col3 = 7.
COLLECT line INTO itab.
line-col4 = 12.
modify itab from line index sy-tabix transporting col4.
WRITE / sy-tabix.
clear line.
LOOP AT itab INTO line.
WRITE: / line-col1, line-col2, line-col3, line-col4.
ENDLOOP.
In your code you try this,
loop at lt_matdata into lwa_matdata.
lwa_final-docno = lwa_matdata-docno.
lwa_final-matnr = lwa_matdata-matnr.
lwa_final-puqty = lwa_matdata-puqty.
lwa_final-amt = lwa_matdata-amount.
collect lwa_final into lt_final.
* ADD THESE LINES
lwa_final-rate = lwa_matdata-rate.
modify it_final from lwa_final index sy-tabix transporting rate.
clear lwa_final.
endloop. -
Regarding collect statement - Production report
Dear Experts,
I've the following requirement
A ) I'm creating a ALV report from Z table where i want the summary of the qty across different processing type like CT , ST , WS & FG .
B ) For each processing types i want the total qty to be displayed in different columns.
C ) When i'm trying to execute , no data is displaying..
Piece of coding is as below.. Request help to clear the below issue..
REPORT ZPP_PRD_REPORT.
TABLES : ZPP_ACTUAL_PRD.
TYPES : BEGIN OF TY_ACTUAL_PRD,
KDAUF TYPE KDAUF,
KDPOS TYPE KDPOS,
WERKS TYPE WERKS_D,
PROCTYP TYPE ZDE_PP_PROCTYP,
AUFNR TYPE AUFNR,
MEINS TYPE MEINS,
END OF TY_ACTUAL_PRD.
TYPES : BEGIN OF TY_FINAL,
KDAUF TYPE KDAUF,
KDPOS TYPE KDPOS,
WERKS TYPE WERKS_D,
PROCTYP TYPE ZDE_PP_PROCTYP,
AUFNR TYPE AUFNR,
MEINS TYPE MEINS,
END OF TY_FINAL.
DATA : GT_ACTUAL_PRD TYPE TABLE OF TY_ACTUAL_PRD,
GS_ACTUAL_PRD TYPE TY_ACTUAL_PRD,
GT_ACTUAL_PRD_COLLECT TYPE TABLE OF TY_ACTUAL_PRD.
DATA : GT_FINAL TYPE TABLE OF TY_FINAL,
GS_FINAL TYPE TY_FINAL.
DATA : GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
GS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
DATA : GT_EVENTS TYPE SLIS_T_EVENT.
DATA : GD_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA : GS_REPID LIKE SY-REPID.
SELECT-OPTIONS : S_KDAUF FOR ZPP_ACTUAL_PRD-KDAUF,
S_KDPOS FOR ZPP_ACTUAL_PRD-KDPOS.
START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM POPULATE_DATA1.
*& Form GET_DATA
* text
* --> p1 text
* <-- p2 text
FORM GET_DATA .
SELECT
KDAUF
KDPOS
WERKS
PROCTYP
AUFNR
MEINS
FROM ZPP_ACTUAL_PRD INTO TABLE GT_ACTUAL_PRD WHERE KDAUF IN S_KDAUF AND
KDPOS IN S_KDPOS.
ENDFORM. " GET_DATA
*& Form POPULATE_DATA1
* text
* --> p1 text
* <-- p2 text
FORM POPULATE_DATA1 .
LOOP AT GT_ACTUAL_PRD INTO GS_ACTUAL_PRD.
GS_FINAL-KDAUF = GS_ACTUAL_PRD-KDAUF.
GS_FINAL-KDPOS = GS_ACTUAL_PRD-KDPOS.
GS_FINAL-WERKS = GS_ACTUAL_PRD-WERKS.
GS_FINAL-PROCTYP = GS_ACTUAL_PRD-PROCTYP.
GS_FINAL-AUFNR = GS_ACTUAL_PRD-AUFNR.
GS_FINAL-MEINS = GS_ACTUAL_PRD-MEINS.
COLLECT GS_ACTUAL_PRD INTO GT_ACTUAL_PRD_COLLECT.
ENDLOOP.
ENDFORM. " POPULATE_DATA1
*& Form BUILD_FIELDCATALOG
* text
* --> p1 text
* <-- p2 text
FORM BUILD_FIELDCATALOG .
GS_FIELDCAT-FIELDNAME = 'KDAUF'.
GS_FIELDCAT-SELTEXT_M = 'SALESORDER'.
GS_FIELDCAT-OUTPUTLEN = 10.
GS_FIELDCAT-DO_SUM = 'X'.
GS_FIELDCAT-NO_ZERO = 'X'.
APPEND GS_FIELDCAT TO GT_FIELDCAT.
CLEAR GS_FIELDCAT.
GS_FIELDCAT-FIELDNAME = 'KDPOS'.
GS_FIELDCAT-SELTEXT_M = 'SALESITEM'.
GS_FIELDCAT-OUTPUTLEN = 10.
GS_FIELDCAT-DO_SUM = 'X'.
GS_FIELDCAT-NO_ZERO = 'X'.
APPEND GS_FIELDCAT TO GT_FIELDCAT.
CLEAR GS_FIELDCAT.
GS_FIELDCAT-FIELDNAME = 'WERKS'.
GS_FIELDCAT-SELTEXT_M = 'PLANT'.
GS_FIELDCAT-OUTPUTLEN = 10.
GS_FIELDCAT-DO_SUM = 'X'.
GS_FIELDCAT-NO_ZERO = 'X'.
APPEND GS_FIELDCAT TO GT_FIELDCAT.
CLEAR GS_FIELDCAT.
GS_FIELDCAT-FIELDNAME = 'PROCTYP'.
GS_FIELDCAT-SELTEXT_M = 'TYPE'.
GS_FIELDCAT-OUTPUTLEN = 10.
GS_FIELDCAT-DO_SUM = 'X'.
GS_FIELDCAT-NO_ZERO = 'X'.
APPEND GS_FIELDCAT TO GT_FIELDCAT.
CLEAR GS_FIELDCAT.
GS_FIELDCAT-FIELDNAME = 'AUFNR'.
GS_FIELDCAT-SELTEXT_M = 'ORDER'.
GS_FIELDCAT-OUTPUTLEN = 10.
GS_FIELDCAT-DO_SUM = 'X'.
GS_FIELDCAT-NO_ZERO = 'X'.
APPEND GS_FIELDCAT TO GT_FIELDCAT.
CLEAR GS_FIELDCAT.
GS_FIELDCAT-FIELDNAME = 'MENGE'.
GS_FIELDCAT-SELTEXT_M = 'QTY'.
GS_FIELDCAT-OUTPUTLEN = 10.
GS_FIELDCAT-DO_SUM = 'X'.
GS_FIELDCAT-NO_ZERO = 'X'.
APPEND GS_FIELDCAT TO GT_FIELDCAT.
CLEAR GS_FIELDCAT.
ENDFORM. " BUILD_FIELDCATALOG
*& Form ALV_DISPLAY
* text
* --> p1 text
* <-- p2 text
FORM ALV_DISPLAY .
GS_REPID = SY-REPID.
IF GS_REPID IS NOT INITIAL.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = GS_REPID
IT_FIELDCAT = GT_FIELDCAT[]
IT_EVENTS = GT_EVENTS[]
I_SAVE = 'A'
I_DEFAULT = 'X'
TABLES
T_OUTTAB = GT_ACTUAL_PRD_COLLECT
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.
ENDFORM. " ALV_DISPLAY
Z Data base table looks as below..
Best rgds/thnks,
Srikanth.Hi Sankara ,
Collect statement is used to add all the numeric components to the corresponding values of all the existing rows in an internal table , with the same key . The data type can be I , P , F .
Please ensure that there is a comman value in all the rows .
check this out and let me know if any issues
Regards,
Kavitha -
Hello,
I have a header and an item table which contains customer records in the header table and line items in the item table . A Customer has many billing document and hence there are a lot line items with the same material.
I want to use the collect statement to group all the materials and have one line item for one type of material and want to sum all the quantities of those materials and the price of the material.
suggest the best solution for the particular scenario.
thank you.Hi Rahul,
You can consider using ABAP Tree Control feature if you are planning to use ABAP Dialog Programing. It will be very elegant and will provide you with a nice UI. Have a look at the demo codes for the functionality.
Use the Transaction DWDM to get all the control examples. You can get more examples in SLIS Package.
If you try using ABAP Web Dynpro , then also you can design it in the way you want.
Hope this will help.
Thanks,
Samantak. -
Hi All
I need to some help with Customer Collection statement , I need this field to display the DOC REF NO in column 2 and not BP REF NO.
Which field must I display in order to display the invoice number or credit note number related to a particular line on the statement lines.
Thanks
Bongani DlaminiHi Bongani Dlamini,
This PLD is one of the hard coded one. There is no option for you to customize it. You need to create your own report by a reporting tool instead.
Thanks,
Gordon -
Hi all,
i have the fallowing problem.
I'm trying to do a collect statement as fallow:
SORT i_tran BY cuenta ASCENDING.
LOOP AT i_tran.
AT NEW cuenta.
COLLECT i_tran INTO i_tran2.
APPEND i_tran2.
CLEAR i_tran.
CLEAR i_tran2.
ENDAT.
endloop.
where i_tran is a collect internal table and i_tran2 is another internal table.
when I execute the collect statement all the fields are fill with asterics and the field that Im interested in is set to zero.
another problem is that is not doing the collect per cuenta. (is doing it per record, ex. if cuenta 123 has three records it executes at the collect statement for each one of them.
this is the structure of i_tran:
* Registro de Transacciones
TYPES: BEGIN OF E_TRAN,
RECTYPE TYPE C, "Tipo Registro N
CCODE(15) TYPE C, "Id Empresa (RNC)
SEQNR(7) TYPE C, "Secuencia Header
SECTR(7) TYPE C, "Secuencia Transaccion
CUENTA(20) TYPE C, "Cuenta Suplidor
MONTRN TYPE I, "Montro Transaccion (13)
TIPCTA TYPE C, "Tipo de Cuenta
WAERS(3) TYPE C, "Moneda
CODBAN(8) TYPE C, "Banco Destino (No. Cuenta Banco)
DIGVER TYPE C, "Digito Verificacion
CODOPR(2) TYPE C, "Codigo Operacion
TIPIDN(2) TYPE C, "Tipo de Identificacion
IDENTF(15) TYPE C, "Identificacion
NOMBRE(35) TYPE C, "Nombre Beneficiario
REFERN(12) TYPE C, "Referencia
DESCRED(40) TYPE C, "Descripcion Estado Destino
FECVEN(4) TYPE C, "Fecha Vencimiento
FCONTC TYPE C, "Forma de Contacto
EMAIL(40) TYPE C, "E-mail Beneficiario
NUMFAX(12) TYPE C, "Numero de Fax
RESERV(2) TYPE C, "Reservado para uso futuro
NUMAUT(15) TYPE C, "Numero Autorizacion
CODRET(3) TYPE C, "Codigo Retorno Remoto
CODRZR(3) TYPE C, "Codigo Razon Remoto
CODRZI(3) TYPE C, "Codigo Razon Interno
PROCTR TYPE C, "Procesador Transaccion
STATS(2) TYPE C, "Status Transaccion
FILLER(52), "En blanco
END OF E_TRAN.
DATA: IT_TRAN TYPE E_TRAN.
DATA: I_TRAN TYPE STANDARD TABLE OF E_TRAN WITH HEADER LINE,
I_TRAN2 TYPE STANDARD TABLE OF E_TRAN WITH HEADER LINE.
if anyone can help me I'll appreciated.
thanks in advanced,
Gregorio.Hi Gergorio,
1. I think that the way you have used COLLECT
is incorrect.
(There is no need to use AT NEW for collect)
(only Loop, Collect will do the work)
2. U have said that :
tran is a collect internal table and i_tran2 is
another internal table.
3. Meaning, that,
i_trans2 has many records
tran is the SUMMARY table (to gather totals)
4. Now, on what base,
do u want to do summary ?
ie. What will be the key/main/criteria fields?
(all char fields of your internal table,
or some of them)
(If only some are required, then your logic won't work)
5. Moreover, we should have numeric/integer
fields in our internal table so that
summation is done automatically.
6. The simple logic is like this.
LOOP AT DETAILITAB.
COLLECT DETAILTAB INTO SUMMARYTAB.
ENDLOOP.
7. The above will take care of
all summations
(with respect to DISTINCT COMBAINATION
of ALL CHAR FIELDS)
8. If your criteria for summation is
less fields then some little more work
is required. If this is so, let me know.
I hope it helps.
Regards,
Amit M. -
Dynamic Query and Collect Statement.
Hi Gurus....
Please explain me how to write dynamic Query,,, Pl. give me with example.
Also would like to know basics of Collect statement and it's use..
Thanks
RiteshHi Ritesh,
COLLECT is used to create unique or compressed datsets. The key fields are the default key fields of the internal table itab . If all non-numeric fields are same in the internal table then it will add numeric fields and maintains a single entry
If you use only COLLECT to fill an internal table, COLLECT makes sure that the internal table does not contain two entries with the same default key fields.
Check this link to know about COLLECT statement
http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/collect.htm
Dynamic query can be built in SAP with the help of () values.
DATA:
V_TABNAME TYPE DDO2L-TABNAME,
V_CONDTION TYPE STRING.
V_TABNAME = 'MARA'.
V_CONDTION = 'MATNR LIKE 'S*'.
SELECT MATNR
FROM <b>(V_TABNAME)</b>
INTO TABLE ITAB
WHERE <b>(V_CONDTION)</b>.
Thanks,
Vinay -
hi everybody,
how to use collect statement to get the total amount paid to different vendor payments
data : begin of wa occurs 0,
bukrs type bsak-bukrs,
lifnr type bsak-lifnr,
land1 type lfa1-land1,
name1 like lfa1-name1,
dmbtr like bsak-dmbtr,
count type i value 0,
tot_vend type i,
vend type i.
data :end of wa.
data : itab like table of wa.
select distinct bukrs lifnr waers from bsak into
corresponding fields of wa
where bukrs in s_bukrs
and lifnr in s_lifnr
and bschl in s_bschl.
i want the total amount paid according to vendor i am using this way but i am not getting
loop at itab into wa.
wa-dmbtr = bsak-dmbtr.
collect wa-dmbtr into itab.
modify itab from wa transporting dmbtr.
i am unalbe to get it
can anybody help me regarding this if possible with example.
thanks in advance,
regards,
venu.Hi Venu,
types: BEGIN OF ty,
NAME(20),
SALES TYPE I,
END OF ty.
data : itab type standard table of ty,
itab1 type standard table of ty,
wa type ty,
wa1 type ty.
wa-NAME = 'Duck'. wa-SALES = 10.
append wa to itab.
wa-NAME = 'Tiger'. wa-SALES = 20.
append wa to itab.
wa-NAME = 'Duck'. wa-SALES = 30.
append wa to itab.
loop at itab into wa.
wa1 = wa.
collect wa1 into itab1.
endloop.
loop at itab1 into wa1.
write : / wa1-name , wa1-sales.
endloop.
COLLECT is used to create unique or compressed datsets. The key fields are the default key fields of the internal table itab .
If you use only COLLECT to fill an internal table, COLLECT makes sure that the internal table does not contain two entries with the same default key fields.
<b>If, besides its default key fields, the internal table contains number fields (see also ABAP/4 number types ), the contents of these number fields are added together if the internal table already contains an entry with the same key fields.</b>
If the default key of an internal table processed with COLLECT is blank, all the values are added up in the first table line.
In the program you mentioned yesterday,I am not able to get the logic since many lines are commented. -
Adding a field to existing collective search help
we tried to add a custom field to already existing collective search help
for this we tried to copy the search help exit "F4IF_SHLP_EXIT_VENDOR_EXP",
but we are unable to activate the copied function module since it's throwing a error that
a statement in one of the includes that was created by the system is inactive.
Thanks in advance,
RajHi Venkata,
Datasource Enhacement:
Please check : [Enhancing LO DataSource u2013 Step by Step|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b0af763b-066e-2910-a784-dc6731660f46]
after adding new field to datasource, need to populate using ABAP code in User Exit.
Adjust update and transfer rules of 0Customer and load data.
how can I add that field in 0SD_C03 cube.
--> In 0Customer infoobject, make Sales District as Navigational attribute and also activate as navigational in CUBE: 0SD_C03. Then it will be available for reporting for navigation, filtering.
Hope it Helps
Srini -
Collective search help in SRM 7.0
Hello all,
Does any body has an idea why the custom elementary search helps wont get displayed in SRM7.0 When we add for a collective search help.
For ex.. BBP_BUPA* SOURCE_OF SUPPLY is the standard collective search help where we added custom search helps to it,
While upgrading we try to implement the same in 7.0 also, But theya re not at all visible in the Drop down of Preferred supplier.
I tried to check web dynpro componenet WDR_F4_COLLECTIVE method in debug mode but was unable to trace it out,
Can any body help me how can i include them to standard collective search helps in web dynpro.
Thanks and Regards
geethaDear Poster,
As no response has been provided to the thread in some time I must assume the issue is resolved, if the question is still valid please create a new thread rephrasing the query and providing as much data as possible to promote response from the community.
Best Regards,
SDN SRM Moderation Team
Maybe you are looking for
-
Production orders not to be considered during MRP run
Dear SAPeers, i want to know how to ensure that open production orders are not considered during the MRP run. the following is the scenario. PIR for march after MRP run creates a planned order. this planned order is converted to production order. now
-
Is the SQL * Plus Worksheet included in the Oracle 10g Express Edition?
Hello All, I need to install Oracle 10g for a SQL class that I will be taking this year. I will be installing it in my laptop (Pentium 4, 1GB RAM). I was told by the Professor that I needed to have the SQL*Plus Worksheet. I would like to know which v
-
CMYK swatch problem- new documents
Hi When I open a new document in CMYK my swatches in swatch palette are showing as RGB. How do I get them back to CMYK? My colour mode is ticked as CMYK. I have rebooted and reset my workspace to my saved setting but it still doesnot default my swatc
-
Hi, I have done this using MS excel. In excel i plot a graph for the below values and i drew a trend line for that plot. from that i am able to find the order and equation of best fit. Is there any way to do this in Labview. Give me some examples
-
Keep getting kicked off safari
while being on the internet for a few minutes at a time it kicks me off and sends me to my home page. Is there anyway to fix this?