Collect statement with index
Hi
can anyone give me some idea how to use collect statement with index
here in the below syntax i want to use collect instead of insert.
INSERT WA_ALVDISPLAY INTO IT_ALVDISPLAY index 3 .
thanks.
vivekk
hi
my scenario is like this
i need an yearly report of a examination held in a school based on month,each month they need report for girls and boys separately
the output format should be like this
month:marks( boys) marks( girls )
so i have created 3 internal tables suppose itab ,itab1,itab2.
itab1-month1
itab1-boy_sub1
itab1-boy_sub2
itab2-month2
itab2-girl_sub1
itab2-girl_sub2
itab -month1
itab -boy_sub1
itab -boy_sub2
itab -girl_sub1
itab -girl_sub2
first i am looping in itab1 and using COLLECT statement i am inserting data to itab (bez in a month more than one exam can happen)
i got boys mark in itab,then i need to put girls mark on the same row based on month
based on particular index i need to insert data, moreover i need to use COLLECT statement for getting the total of particular month
thanks
vivek
Similar Messages
-
Hi i have some problem with collect statement.
hi when i am using collect statement and whn ever any field is modified it is getting doubled and showing doubled value. may i knoe what would be problem.
Hai Kumar
Go through the following Collect Syntax
COLLECT
Basic form
COLLECT [wa INTO] itab.
Addition
... SORTED BY f
Effect
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.
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.
If the default key of an internal table processed with COLLECT is blank, all the values are added up in the first table line.
If you specify wa INTO , the entry to be processed is taken from the explicitly specified work area wa . If not, it comes from the header line of the internal table itab .
After COLLECT , the system field SY-TABIX contains the index of the - existing or new - table entry with default key fields which match those of the entry to be processed.
Notes
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.
If you process a table with COLLECT , you should also use COLLECT to fill it. Only by doing this can you guarantee that
the internal table will actually be unique or compressed, as described above and
COLLECT will run very efficiently.
If you use COLLECT with an explicitly specified work area, it must be compatible with the line type of the internal table.
Example
Compressed sales figures for each company
DATA: BEGIN OF COMPANIES OCCURS 10,
NAME(20),
SALES TYPE I,
END OF COMPANIES.
COMPANIES-NAME = 'Duck'. COMPANIES-SALES = 10.
COLLECT COMPANIES.
COMPANIES-NAME = 'Tiger'. COMPANIES-SALES = 20.
COLLECT COMPANIES.
COMPANIES-NAME = 'Duck'. COMPANIES-SALES = 30.
COLLECT COMPANIES.
The table COMPANIES now has the following appearance:
NAME SALES
Duck 40
Tiger 20
Addition
... SORTED BY f
Effect
COLLECT ... SORTED BY f is obsolete and should no longer be used. Use APPEND ... SORTED BY f which has the same meaning.
Note
Performance
The cost of a COLLECT in terms of performance increases with the width of the default key needed in the search for table entries and the number of numeric fields with values which have to be added up, if an entry is found in the internal table to match the default key fields.
If no such entry is found, the cost is reduced to that required to append a new entry to the end of the table.
A COLLECT statement used on a table which is 100 bytes wide and has a key which is 60 bytes wide and seven numeric fields is about approx. 50 msn (standardized microseconds).
Note
Runtime errors
COLLECT_OVERFLOW : Overflow in integer field when calculating totals.
COLLECT_OVERFLOW_TYPE_P : Overflow in type P field when calculating totals.
Thanks & regards
Sreenivasulu P -
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 -
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 -
What is syntax for inner join of Select statement with Secondary Index
Hi Genies,
Here i have created the Secondary index for table COEP and also used for select query but there is no improvement in runtime . taking same time for select query without index as well as with index. my code is
SELECT * INTO CORRESPONDING FIELDS OF TABLE ITAB_COEP FROM COEP AS A
INNER JOIN COBK AS B ON ( A~BELNR = B~BELNR AND A~KOKRS = B~KOKRS AND A~GJAHR = B~GJAHR )
WHERE A~OBJNR = OBJNR
AND A~GJAHR = CURRY
AND B~GJAHR = CURRY
AND A~RBEST = ''
AND A~BEKNZ = 'S'
AND B~BELNR NE WA_COBK-BELNR
AND B~AWREF_REV = ''
AND B~AWORG_REV = ''
AND B~KOKRS = WA_COIOB-KOKRS
AND B~BLDAT BETWEEN START_DATE AND END_DATE
AND B~BLART IN ('SA','KA','KR','AB') %_HINTS ORACLE 'INDEX("COEP" "COEP~ZBU")'.
index name is ZBU.
please any one let me know is there any syntax mistakes? but while checking and during the runtime it does'nt shows any error.
Regards,
Thangam.PHi Genies,
Here i have created the Secondary index for table COEP and also used for select query but there is no improvement in runtime . taking same time for select query without index as well as with index. my code is
SELECT * INTO CORRESPONDING FIELDS OF TABLE ITAB_COEP FROM COEP AS A
INNER JOIN COBK AS B ON ( A~BELNR = B~BELNR AND A~KOKRS = B~KOKRS AND A~GJAHR = B~GJAHR )
WHERE A~OBJNR = OBJNR
AND A~GJAHR = CURRY
AND B~GJAHR = CURRY
AND A~RBEST = ''
AND A~BEKNZ = 'S'
AND B~BELNR NE WA_COBK-BELNR
AND B~AWREF_REV = ''
AND B~AWORG_REV = ''
AND B~KOKRS = WA_COIOB-KOKRS
AND B~BLDAT BETWEEN START_DATE AND END_DATE
AND B~BLART IN ('SA','KA','KR','AB') %_HINTS ORACLE 'INDEX("COEP" "COEP~ZBU")'.
index name is ZBU.
please any one let me know is there any syntax mistakes? but while checking and during the runtime it does'nt shows any error.
Regards,
Thangam.P -
Replace the following open/fetch/close statements with a cursor FOR loop
Hi anyone could you please help me,
I would like to replace the following open/fetch/close statements with a cursor FOR loop.
Codes are:
CREATE OR REPLACE PROCEDURE COMOES.orchid_shipment_interface IS
-- get the com shipment header records
CURSOR c_com_shphdr ( p_dwn_end_dt DATE ) IS
SELECT custno client_id
, plheadno plheadno
, DECODE(carr_no,'FEDX',lading_no,'UPS',lading_no,carrier_pro_no) tracking_no
, carr_no||'/'||carr_method carrier_id
, plantid plant_id
, carr_no
, lading_no
, del_custaddr ship_to_id
, ol_type cfm_order_type
, del_custno
, shipterm freight_terms
, del_custattn attn_line
, custaddr
FROM com_plhead@com_pricing.world
WHERE status = '9'
AND (mod_dat) > p_dwn_end_dt;
-- get the com shipment address records
CURSOR c_com_shpadr (p_custaddr VARCHAR2) IS
SELECT name1 addr_name
, street1 addr_line1
, street2 addr_line2
, city city
, state state_cd
, zip zip
, country country_cd
, phone work_phone
, email email1
FROM com_address@com_pricing.world
WHERE addr_id = p_custaddr;
-- get the com shipment detail records
CURSOR c_com_shpdtl ( p_plheadno NUMBER) IS
SELECT pll.plheadno pllheadno
, pll.pllineno ord_line_no
, pll.ol_no erp_line_no
, pll.ol_segno
, pll.fg_id sku
, pll.qty_shipped ship_qty
, pll.ordno erp_ord_no
FROM com_plline@com_pricing.world pll
WHERE pll.plheadno = p_plheadno
AND NOT EXISTS (SELECT '1'
FROM com_pkg_int_interface@com_pricing.world cpi
WHERE pll.ordno = cpi.ordno
AND pll.ol_no = cpi.ol_no);
-- type declaration
-- type declaration of com table.
TYPE t_com_shphdr IS TABLE OF c_com_shphdr%ROWTYPE INDEX BY BINARY_INTEGER;
TYPE t_orchid_shphdr IS TABLE OF orchid_shipment_hdr_intf%ROWTYPE INDEX BY BINARY_INTEGER;
TYPE t_com_shpadr IS TABLE OF c_com_shpadr%ROWTYPE INDEX BY BINARY_INTEGER;
TYPE t_orchid_shpadr IS TABLE OF orchid_shipment_address_intf%ROWTYPE INDEX BY BINARY_INTEGER;
TYPE t_com_shpdtl IS TABLE OF c_com_shpdtl%ROWTYPE INDEX BY BINARY_INTEGER;
TYPE t_orchid_shpdtl IS TABLE OF orchid_shipment_dtl_intf%ROWTYPE INDEX BY BINARY_INTEGER;
lv_company_code com_customer.business_unit%TYPE;
lv_erp_ord_no com_plline.ordno%TYPE;
lv_actual_ship_date com_plline.confirm_date%TYPE;
lv_po_no com_oline.po_no%TYPE;
lv_ord_date com_oline.entrydate%TYPE;
lv_hdr_batch_ctrl_no download_batch_info.batch_ctrl_no%TYPE;
lv_adr_batch_ctrl_no download_batch_info.batch_ctrl_no%TYPE;
lv_dtl_batch_ctrl_no download_batch_info.batch_ctrl_no%TYPE;
lv_sku_desc com_salesitem.title%TYPE;
lv_ord_qty com_oldelseg.qty%TYPE;
lr_com_shphdr t_com_shphdr;
lr_orchid_shphdr t_orchid_shphdr;
lr_com_shpadr t_com_shpadr;
lr_orchid_shpadr t_orchid_shpadr;
lr_com_shpdtl t_com_shpdtl;
lr_orchid_shpdtl t_orchid_shpdtl;
-- variable declaration
ln_shphdr_seq NUMBER(10):= 0;
ln_shpadr_seg NUMBER(10):= 0;
ln_shpdtl_seq NUMBER(10):= 0;
cnt NUMBER(10):= 0;
cnt1 NUMBER(10):= 0;
ld_hdr_dwn_end_dt download_batch_info.download_end_tstamp%TYPE;
lc_hdr_dwn_status download_batch_info.dwn_status%TYPE;
ld_hdr_download_end_tstamp DATE;
ln_hdr_running_seq NUMBER(10) := 0;
ld_adr_dwn_end_dt download_batch_info.download_end_tstamp%TYPE;
lc_adr_dwn_status download_batch_info.dwn_status%TYPE;
ld_adr_download_end_tstamp DATE;
ln_adr_running_seg NUMBER(10) := 0;
ld_dtl_dwn_end_dt download_batch_info.download_end_tstamp%TYPE;
lc_dtl_dwn_status download_batch_info.dwn_status%TYPE;
ld_dtl_download_end_tstamp DATE;
ln_dtl_running_seq NUMBER(10) := 0;
BEGIN
-- get the batch control number details from batch information table for shipment header
BEGIN
SELECT batch_ctrl_no
, NVL(download_end_tstamp,TO_DATE('01/01/1980','MM/DD/YYYY'))
, dwn_status
INTO lv_hdr_batch_ctrl_no
, ld_hdr_dwn_end_dt
, lc_hdr_dwn_status
FROM comoes.download_batch_info
WHERE download_id = 'ORCHID_SHIPMENT_HDR_INTF';
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE (' No Data Found for ORCHID_SHIPMENT_HDR_INTF in Download Batch Info table...!!!');
RAISE;
WHEN TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE (' Too Many Rows found for ORCHID_SHIPMENT_HDR_INTF in Download Batch Info table...!!!');
RAISE;
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE (' Following error occured while getting batch control number for ORCHID_SHIPMENT_HDR_INTF in Download Batch Info table...!!!'||SQLERRM);
RAISE;
END;
-- get the batch control number details from batch information table for shipment address
BEGIN
SELECT batch_ctrl_no
, NVL(download_end_tstamp,TO_DATE('01/01/1980','MM/DD/YYYY'))
, dwn_status
INTO lv_adr_batch_ctrl_no
, ld_adr_dwn_end_dt
, lc_adr_dwn_status
FROM comoes.download_batch_info
WHERE download_id = 'ORCHID_SHIPMENT_ADDRESS_INTF';
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE (' No Data Found for ORCHID_SHIPMENT_ADDRESS_INTF in Download Batch Info table...!!!');
RAISE;
WHEN TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE (' Too Many Rows found for ORCHID_SHIPMENT_ADDRESS_INTF in Download Batch Info table...!!!');
RAISE;
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE (' Following error occured while getting batch control number for ORCHID_SHIPMENT_ADDRESS_INTF in Download Batch Info table...!!!'||SQLERRM);
RAISE;
END;
-- get the batch control number details from batch information table for shipment details
BEGIN
SELECT batch_ctrl_no
, NVL(download_end_tstamp,TO_DATE('01/01/1980','MM/DD/YYYY'))
, dwn_status
INTO lv_dtl_batch_ctrl_no
, ld_dtl_dwn_end_dt
, lc_dtl_dwn_status
FROM download_batch_info
WHERE download_id = 'ORCHID_SHIPMENT_DTL_INTF';
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE (' No Data Found for ORCHID_SHIPMENT_DTL_INTF in Download Batch Info table...!!!');
RAISE;
WHEN TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE (' Too Many Rows found for ORCHID_SHIPMENT_DTL_INTF in Download Batch Info table...!!!');
RAISE;
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE (' Following error occured while getting batch control number for ORCHID_SHIPMENT_DTL_INTF in Download Batch Info table...!!!'||SQLERRM);
RAISE;
END;
-- if previous run is not sucess then do nothing and return.
OPEN c_com_shphdr ( ld_hdr_dwn_end_dt ) ;
LOOP
-- delete the collection for every cycle
lr_com_shphdr.DELETE;
lr_orchid_shphdr.DELETE;
lr_com_shpadr.DELETE;
lr_orchid_shpadr.DELETE;
lr_com_shpdtl.DELETE;
lr_orchid_shpdtl.DELETE;
-- fetch the order header records to collection
FETCH c_com_shphdr BULK COLLECT INTO lr_com_shphdr LIMIT 500;
-- where there is no record in the collection the exit from the loop
EXIT WHEN lr_com_shphdr.COUNT = 0;
-- build your logic there to populate the data into order header collection.
FOR i IN 1..lr_com_shphdr.COUNT
LOOP
-- accumulate header running sequence number
ln_hdr_running_seq := ln_hdr_running_seq + 1;
ln_shphdr_seq := ln_hdr_running_seq;
-- Get the business unit for the customer from com_customer
BEGIN
SELECT business_unit
INTO lv_company_code
FROM com_customer@com_pricing.world
WHERE custno = lr_com_shphdr(i).del_custno;
EXCEPTION
WHEN OTHERS THEN
lv_company_code := NULL;
END;
-- Get the ordno, confirm_date from COM_PLLINE
BEGIN
SELECT ordno
, confirm_date
INTO lv_erp_ord_no
, lv_actual_ship_date
FROM com_plline@com_pricing.world cpl
WHERE cpl.plheadno = lr_com_shphdr(i).plheadno
AND ROWNUM = 1;
EXCEPTION
WHEN OTHERS THEN
lv_erp_ord_no := NULL;
lv_actual_ship_date := NULL;
END;
-- Get the po_no, Entry_date from COM_OLINE
BEGIN
SELECT po_no
, entrydate
INTO lv_po_no
, lv_ord_date
FROM com_oline@com_pricing.world col
WHERE col.ordno = lv_erp_ord_no
AND ROWNUM = 1;
EXCEPTION
WHEN OTHERS THEN
lv_po_no := NULL;
lv_ord_date := NULL;
END;
-- To assign the Bol Number from Lading Number
IF lr_com_shphdr(i).carr_no NOT IN ('FEDX','UPS') THEN
lr_orchid_shphdr(i).bol_no := lr_com_shphdr(i).lading_no;
ELSE
lr_orchid_shphdr(i).bol_no := NULL;
END IF;
-- For each order header get the Shipment Delivery Adderss
OPEN c_com_shpadr ( lr_com_shphdr(i).custaddr);
FETCH c_com_shpadr BULK COLLECT INTO lr_com_shpadr;
-- where there is no record in the collection the exit from the loop
EXIT WHEN lr_com_shpadr.COUNT = 0;
-- biuld your logic here to populate the del address collection.
FOR j IN 1..lr_com_shpadr.COUNT
LOOP
-- accumulate the loop count into temp variable, so that will through tell each set of order header.
cnt := cnt + 1;
-- accumolate the header running sequence number.
ln_adr_running_seg := ln_adr_running_seg + 1;
ln_shpadr_seg := ln_adr_running_seg;
-- move the order address data into collection.
lr_orchid_shpadr(cnt).client_id := lr_com_shphdr(i).del_custno;
lr_orchid_shpadr(cnt).ord_no := lr_com_shphdr(i).plheadno;
lr_orchid_shpadr(cnt).tracking_no := lr_com_shphdr(i).tracking_no;
lr_orchid_shpadr(cnt).addr_name := lr_com_shpadr(j).addr_name;
lr_orchid_shpadr(cnt).attn_line := lr_com_shphdr(i).attn_line;
lr_orchid_shpadr(cnt).addr_line1 := lr_com_shpadr(j).addr_line1;
lr_orchid_shpadr(cnt).addr_line2 := lr_com_shpadr(j).addr_line2;
lr_orchid_shpadr(cnt).addr_line3 := NULL;
lr_orchid_shpadr(cnt).addr_line4 := NULL;
lr_orchid_shpadr(cnt).addr_line5 := NULL;
lr_orchid_shpadr(cnt).city := lr_com_shpadr(j).city;
lr_orchid_shpadr(cnt).state_cd := lr_com_shpadr(j).state_cd;
lr_orchid_shpadr(cnt).zip := lr_com_shpadr(j).zip;
lr_orchid_shpadr(cnt).zip_ext := NULL;
lr_orchid_shpadr(cnt).country_cd := lr_com_shpadr(j).country_cd;
lr_orchid_shpadr(cnt).tax_geo_cd := NULL;
lr_orchid_shpadr(cnt).work_phone := lr_com_shpadr(j).work_phone;
lr_orchid_shpadr(cnt).email1 := lr_com_shpadr(j).email1;
lr_orchid_shpadr(cnt).cre_dat := SYSDATE;
lr_orchid_shpadr(cnt).cre_usr := USER;
lr_orchid_shpadr(cnt).batch_ctrl_no := lv_adr_batch_ctrl_no;
END LOOP;
CLOSE c_com_shpadr;
-- For each order header get the order detail/delivery segment data
OPEN c_com_shpdtl ( lr_com_shphdr(i).plheadno );
FETCH c_com_shpdtl BULK COLLECT INTO lr_com_shpdtl;
-- where there is no record in the collection the exit from the loop
EXIT WHEN lr_com_shpdtl.COUNT = 0;
-- build your logic here to populate the order detail collection
FOR k IN 1..lr_com_shpdtl.COUNT
LOOP
-- accumulate the loop count into a temp variable, so that will through till each set of Order Header.
cnt1 := cnt1 + 1;
-- accumulate header running sequence number
ln_dtl_running_seq := ln_dtl_running_seq + 1;
ln_shpdtl_seq := ln_dtl_running_seq;
-- Get Quantity for the delvery from delevery segment table.
BEGIN
SELECT NVL(Qty,0)
INTO lv_ord_qty
FROM com_oldelseg@com_pricing.world cds
WHERE cds.ordno = lr_com_shpdtl(k).erp_ord_no
AND cds.ol_no = lr_com_shpdtl(k).erp_line_no
AND cds.ol_segno = lr_com_shpdtl(k).ol_segno;
EXCEPTION
WHEN OTHERS THEN
lv_ord_qty := NULL;
END;
-- Get Title for the salesitem from the salesitem table.
BEGIN
SELECT Title
INTO lv_sku_desc
FROM com_salesitem@com_pricing.world cs
WHERE cs.fg_id = lr_com_shpdtl(k).sku;
EXCEPTION
WHEN OTHERS THEN
lv_sku_desc := NULL;
END;
-- move the Order detail data into collection
lr_orchid_shpdtl(cnt1).client_id := lr_com_shphdr(i).client_id;
lr_orchid_shpdtl(cnt1).ord_no := lr_com_shphdr(i).plheadno;
lr_orchid_shpdtl(cnt1).ord_line_no := lr_com_shpdtl(k).ord_line_no;
lr_orchid_shpdtl(cnt1).erp_line_no := lr_com_shpdtl(k).erp_line_no;
lr_orchid_shpdtl(cnt1).sku := lr_com_shpdtl(k).sku;
lr_orchid_shpdtl(cnt1).tracking_no := lr_com_shphdr(i).tracking_no;
lr_orchid_shpdtl(cnt1).container_no := NULL;
lr_orchid_shpdtl(cnt1).ord_qty := lv_ord_qty;
lr_orchid_shpdtl(cnt1).ship_qty := lr_com_shpdtl(k).ship_qty;
lr_orchid_shpdtl(cnt1).price_point := NULL;
lr_orchid_shpdtl(cnt1).pick_invoice_no := NULL;
lr_orchid_shpdtl(cnt1).cancel_qty := NULL;
lr_orchid_shpdtl(cnt1).bldg_id := NULL; --lr_com_shpdtl(k).bldg_id;
lr_orchid_shpdtl(cnt1).sku_company := NULL; --lr_com_shpdtl(k).sku_company;
lr_orchid_shpdtl(cnt1).sku_desc := lv_sku_desc;
lr_orchid_shpdtl(cnt1).icc_cd1 := NULL; --lr_com_shpdtl(k).icc_cd1;
lr_orchid_shpdtl(cnt1).erp_ord_no := lr_com_shpdtl(k).erp_ord_no;
lr_orchid_shpdtl(cnt1).cre_dat := SYSDATE;
lr_orchid_shpdtl(cnt1).cre_usr := USER;
lr_orchid_shpdtl(cnt1).batch_ctrl_no := lv_dtl_batch_ctrl_no;
END LOOP;
CLOSE c_com_shpdtl;
-- build the logic to populate Order Header
lr_orchid_shphdr(i).client_id := lr_com_shphdr(i).client_id;
lr_orchid_shphdr(i).ord_no := lr_com_shphdr(i).plheadno;
lr_orchid_shphdr(i).tracking_no := lr_com_shphdr(i).tracking_no;
lr_orchid_shphdr(i).container_no := NULL; -- container number is not maintained in COM
lr_orchid_shphdr(i).carrier_id := lr_com_shphdr(i).carrier_id;
lr_orchid_shphdr(i).plant_id := lr_com_shphdr(i).plant_id;
lr_orchid_shphdr(i).erp_ord_no := lv_erp_ord_no;
lr_orchid_shphdr(i).erp_ord_no2 := NULL;
lr_orchid_shphdr(i).po_no := lv_po_no;
lr_orchid_shphdr(i).ship_to_id := lr_com_shphdr(i).ship_to_id;
lr_orchid_shphdr(i).ship_to_addr_id := lr_com_shphdr(i).custaddr;
lr_orchid_shphdr(i).scac := NULL; --lr_com_shphdr(i).scac;
lr_orchid_shphdr(i).actual_ship_date := lv_actual_ship_date;
lr_orchid_shphdr(i).cfm_order_type := lr_com_shphdr(i).cfm_order_type;
lr_orchid_shphdr(i).company_code := lv_company_code;
lr_orchid_shphdr(i).no_of_order_lines := NULL; --lr_com_shphdr(i).no_of_order_lines;
lr_orchid_shphdr(i).pick_invoice_no := NULL;
lr_orchid_shphdr(i).ord_date := lv_ord_date;
lr_orchid_shphdr(i).orig_tender_date := NULL;
lr_orchid_shphdr(i).orig_delv_date := NULL;
lr_orchid_shphdr(i).delivery_flag := NULL;
lr_orchid_shphdr(i).delv_date_from := NULL;
lr_orchid_shphdr(i).delv_date_to := NULL;
lr_orchid_shphdr(i).orig_carr_cd := NULL;
lr_orchid_shphdr(i).routing_comment := NULL;
lr_orchid_shphdr(i).segment_type := NULL;
lr_orchid_shphdr(i).back_order_flag := NULL;
lr_orchid_shphdr(i).addr_override_flag := NULL;
lr_orchid_shphdr(i).fmx_assigned_carr := NULL;
lr_orchid_shphdr(i).fmx_assigned_ship_date := NULL;
lr_orchid_shphdr(i).fmx_assigned_delv_date := NULL;
lr_orchid_shphdr(i).freight_terms := lr_com_shphdr(i).freight_terms;
lr_orchid_shphdr(i).fmx_load_id := NULL;
lr_orchid_shphdr(i).asn_type := NULL;
lr_orchid_shphdr(i).icc_cd1 := NULL; --lr_com_shphdr(i).icc_cd1;
lr_orchid_shphdr(i).trans_type := NULL;
lr_orchid_shphdr(i).ref_no1 := NULL;
lr_orchid_shphdr(i).ref_no2 := NULL;
lr_orchid_shphdr(i).ref_no3 := NULL;
lr_orchid_shphdr(i).ref_no4 := NULL;
lr_orchid_shphdr(i).cre_dat := SYSDATE;
lr_orchid_shphdr(i).cre_usr := USER;
lr_orchid_shphdr(i).batch_ctrl_no := lv_hdr_batch_ctrl_no;
-- logic to get total boxes and weight.
BEGIN
SELECT SUM(no_cartons), SUM(weight)
INTO lr_orchid_shphdr(i).total_boxes
, lr_orchid_shphdr(i).weight
FROM com_plline@com_pricing.world pll
WHERE pll.plheadno = lr_com_shphdr(i).plheadno;
EXCEPTION
WHEN OTHERS THEN
lr_orchid_shphdr(i).total_boxes := NULL;
lr_orchid_shphdr(i).weight := NULL;
END;
END LOOP;
-- initialize the variables for next loop cycle.
cnt := 0;
cnt1 := 0;
-- populate the shipment header interface table.
FOR x IN 1..lr_orchid_shphdr.COUNT
LOOP
ld_hdr_download_end_tstamp := lr_orchid_shphdr(x).cre_dat;
INSERT INTO orchid_shipment_hdr_intf
(record_qualifier
,client_id
,ord_no
,tracking_no
,container_no
,bol_no
,carrier_id
,plant_id
,erp_ord_no
,erp_ord_no2
,po_no
,ship_to_id
,ship_to_addr_id
,scac
,actual_ship_date
,cfm_order_type
,company_code
,no_of_order_lines
,pick_invoice_no
,total_boxes
,weight
,ord_date
,orig_tender_date
,orig_delv_date
,delivery_flag
,delv_date_from
,delv_date_to
,orig_carr_cd
,routing_comment
,segment_type
,back_order_flag
,addr_override_flag
,fmx_assigned_carr
,fmx_assigned_ship_date
,fmx_assigned_delv_date
,freight_terms
,fmx_load_id
,asn_type
,upl_status
,icc_cd1
,trans_type
,ref_no1
,ref_no2
,ref_no3
,ref_no4
,cre_dat
,cre_usr
,batch_ctrl_no)
VALUES
( 10
,lr_orchid_shphdr(x).client_id
,lr_orchid_shphdr(x).ord_no
,lr_orchid_shphdr(x).tracking_no
,lr_orchid_shphdr(x).container_no
,lr_orchid_shphdr(x).bol_no
,lr_orchid_shphdr(x).carrier_id
,lr_orchid_shphdr(x).plant_id
,lr_orchid_shphdr(x).erp_ord_no
,lr_orchid_shphdr(x).erp_ord_no2
,lr_orchid_shphdr(x).po_no
,lr_orchid_shphdr(x).ship_to_id
,lr_orchid_shphdr(x).ship_to_addr_id
,lr_orchid_shphdr(x).scac
,lr_orchid_shphdr(x).actual_ship_date
,lr_orchid_shphdr(x).cfm_order_type
,lr_orchid_shphdr(x).company_code
,lr_orchid_shphdr(x).no_of_order_lines
,lr_orchid_shphdr(x).pick_invoice_no
,lr_orchid_shphdr(x).total_boxes
,lr_orchid_shphdr(x).weight
,lr_orchid_shphdr(x).ord_date
,lr_orchid_shphdr(x).orig_tender_date
,lr_orchid_shphdr(x).orig_delv_date
,lr_orchid_shphdr(x).delivery_flag
,lr_orchid_shphdr(x).delv_date_from
,lr_orchid_shphdr(x).delv_date_to
,lr_orchid_shphdr(x).orig_carr_cd
,lr_orchid_shphdr(x).routing_comment
,lr_orchid_shphdr(x).segment_type
,lr_orchid_shphdr(x).back_order_flag
,lr_orchid_shphdr(x).addr_override_flag
,lr_orchid_shphdr(x).fmx_assigned_carr
,lr_orchid_shphdr(x).fmx_assigned_ship_date
,lr_orchid_shphdr(x).fmx_assigned_delv_date
,lr_orchid_shphdr(x).freight_terms
,lr_orchid_shphdr(x).fmx_load_id
,lr_orchid_shphdr(x).asn_type
,00
,lr_orchid_shphdr(x).icc_cd1
,lr_orchid_shphdr(x).trans_type
,lr_orchid_shphdr(x).ref_no1
,lr_orchid_shphdr(x).ref_no2
,lr_orchid_shphdr(x).ref_no3
,lr_orchid_shphdr(x).ref_no4
,lr_orchid_shphdr(x).cre_dat
,lr_orchid_shphdr(x).cre_usr
,lr_orchid_shphdr(x).batch_ctrl_no);
END LOOP;
-- populate the shipment address interface table.
FOR y IN 1..lr_orchid_shpadr.COUNT
LOOP
ld_adr_download_end_tstamp := lr_orchid_shpadr(y).cre_dat;
INSERT INTO orchid_shipment_address_intf
( record_qualifier
, client_id
, ord_no
, tracking_no
, addr_name
, attn_line
, addr_line1
, addr_line2
, addr_line3
, addr_line4
, addr_line5
, city
, state_cd
, zip
, zip_ext
, country_cd
, tax_geo_cd
, work_phone
, email1
, cre_dat
, cre_usr
, batch_ctrl_no)
VALUES ( 14
, lr_orchid_shpadr(y).client_id
, lr_orchid_shpadr(y).ord_no
, lr_orchid_shpadr(y).tracking_no
, lr_orchid_shpadr(y).addr_name
, lr_orchid_shpadr(y).attn_line
, lr_orchid_shpadr(y).addr_line1
, lr_orchid_shpadr(y).addr_line2
, lr_orchid_shpadr(y).addr_line3
, lr_orchid_shpadr(y).addr_line4
, lr_orchid_shpadr(y).addr_line5
, lr_orchid_shpadr(y).city
, lr_orchid_shpadr(y).state_cd
, lr_orchid_shpadr(y).zip
, lr_orchid_shpadr(y).zip_ext
, lr_orchid_shpadr(y).country_cd
, lr_orchid_shpadr(y).tax_geo_cd
, lr_orchid_shpadr(y).work_phone
, lr_orchid_shpadr(y).email1
, lr_orchid_shpadr(y).cre_dat
, lr_orchid_shpadr(y).cre_usr
, lr_orchid_shpadr(y).batch_ctrl_no);
END LOOP;
-- populate the shipment detail interface table.
FOR z IN 1..lr_orchid_shpdtl.COUNT
LOOP
ld_dtl_download_end_tstamp := lr_orchid_shpdtl(z).cre_dat;
INSERT INTO orchid_shipment_dtl_intf
( record_qualifier
, client_id
, ord_no
, ord_line_no
, erp_line_no
, sku
, tracking_no
, container_no
, ord_qty
, ship_qty
, price_point
, pick_invoice_no
, cancel_qty
, bldg_id
, sku_company
, sku_desc
, icc_cd1
, erp_ord_no
, cre_dat
, cre_usr
, batch_ctrl_no)
VALUES ( 20
, lr_orchid_shpdtl(z).client_id
, lr_orchid_shpdtl(z).ord_no
, lr_orchid_shpdtl(z).ord_line_no
, lr_orchid_shpdtl(z).erp_line_no
, lr_orchid_shpdtl(z).sku
, lr_orchid_shpdtl(z).tracking_no
, lr_orchid_shpdtl(z).container_no
, lr_orchid_shpdtl(z).ord_qty
, lr_orchid_shpdtl(z).ship_qty
, lr_orchid_shpdtl(z).price_point
, lr_orchid_shpdtl(z).pick_invoice_no
, lr_orchid_shpdtl(z).cancel_qty
, lr_orchid_shpdtl(z).bldg_id
, lr_orchid_shpdtl(z).sku_company
, lr_orchid_shpdtl(z).sku_desc
, lr_orchid_shpdtl(z).icc_cd1
, lr_orchid_shpdtl(z).erp_ord_no
, lr_orchid_shpdtl(z).cre_dat
, lr_orchid_shpdtl(z).cre_usr
, lr_orchid_shpdtl(z).batch_ctrl_no);
END LOOP;
COMMIT;
END LOOP;
CLOSE c_com_shphdr;
-- set the status to success
UPDATE comoes.download_batch_info
SET batch_ctrl_no = orchid_plhead_btch_ctrl_seq.NEXTVAL
, dwn_status = '90'
, download_end_tstamp = NVL(ld_hdr_download_end_tstamp,SYSDATE)
WHERE download_id = 'ORCHID_SHIPMENT_HDR_INTF'
AND batch_ctrl_no = lv_hdr_batch_ctrl_no;
UPDATE comoes.download_batch_info
SET batch_ctrl_no = orchid_address_btch_ctrl_seq.NEXTVAL
, dwn_status = '90'
, download_end_tstamp = NVL(ld_hdr_download_end_tstamp,SYSDATE)
WHERE download_id = 'ORCHID_SHIPMENT_ADDRESS_INTF'
AND batch_ctrl_no = lv_adr_batch_ctrl_no;
UPDATE comoes.download_batch_info
SET batch_ctrl_no = orchid_plline_btch_ctrl_seq.NEXTVAL
, dwn_status = '90'
, download_end_tstamp = NVL(ld_dtl_download_end_tstamp,SYSDATE)
WHERE download_id = 'ORCHID_SHIPMENT_DTL_INTF'
AND batch_ctrl_no = lv_dtl_batch_ctrl_no;
-- Update the download status to success in the interface table.
-- Shipment Header
COMMIT;
EXCEPTION
WHEN OTHERS THEN
-- load is not sucess then set the status to fail
UPDATE comoes.download_batch_info
SET dwn_status = '99'
WHERE download_id = 'ORCHID_SHIPMENT_HDR_INTF'
AND batch_ctrl_no = lv_hdr_batch_ctrl_no;
UPDATE comoes.download_batch_info
SET dwn_status = '99'
WHERE download_id = 'ORCHID_SHIPMENT_ADDRESS_INTF'
AND batch_ctrl_no = lv_adr_batch_ctrl_no;
UPDATE comoes.download_batch_info
SET dwn_status = '99'
WHERE download_id = 'ORCHID_SHIPMENT_DTL_INTF'
AND batch_ctrl_no = lv_dtl_batch_ctrl_no;
COMMIT;
DBMS_OUTPUT.PUT_LINE('Following error occured while executing ORCHID_SHIPMENT_INTF procedure...!!!'||SQLERRM);
RAISE;
END orchid_shipment_interface;Edited by: BluShadow on 03-Aug-2011 13:28
added {noformat}{noformat} tags. Please read {message:id=9360002} to learn to do this yourself. &nbPlease read the Forum FAQ on how to ask a question, particularly how to format code
SQL and PL/SQL FAQ
SQL and PL/SQL FAQ
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE (' Following error occured while getting batch control number for ORCHID_SHIPMENT_HDR_INTF in Download Batch Info table...!!!'||SQLERRM);
RAISE;http://tkyte.blogspot.com/2008/01/why-do-people-do-this.html -
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. -
Report in which collect statement .
report in which collect statement is used and also its purpose.
COLLECT
Basic form
COLLECT [wa INTO] itab.
Addition
... SORTED BY f
Effect
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.
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.
If the default key of an internal table processed with COLLECT is blank, all the values are added up in the first table line.
If you specify wa INTO , the entry to be processed is taken from the explicitly specified work area wa . If not, it comes from the header line of the internal table itab .
After COLLECT , the system field SY-TABIX contains the index of the - existing or new - table entry with default key fields which match those of the entry to be processed.
Notes
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.
If you process a table with COLLECT , you should also use COLLECT to fill it. Only by doing this can you guarantee that
the internal table will actually be unique or compressed, as described above and
COLLECT will run very efficiently.
If you use COLLECT with an explicitly specified work area, it must be compatible with the line type of the internal table.
Example
Compressed sales figures for each company
DATA: BEGIN OF COMPANIES OCCURS 10,
NAME(20),
SALES TYPE I,
END OF COMPANIES.
COMPANIES-NAME = 'Duck'. COMPANIES-SALES = 10.
COLLECT COMPANIES.
COMPANIES-NAME = 'Tiger'. COMPANIES-SALES = 20.
COLLECT COMPANIES.
COMPANIES-NAME = 'Duck'. COMPANIES-SALES = 30.
COLLECT COMPANIES.
The table COMPANIES now has the following appearance:
NAME SALES
Duck 40
Tiger 20
Addition
... SORTED BY f
Effect
COLLECT ... SORTED BY f is obsolete and should no longer be used. Use APPEND ... SORTED BY f which has the same meaning.
Note
Performance
The cost of a COLLECT in terms of performance increases with the width of the default key needed in the search for table entries and the number of numeric fields with values which have to be added up, if an entry is found in the internal table to match the default key fields.
If no such entry is found, the cost is reduced to that required to append a new entry to the end of the table.
A COLLECT statement used on a table which is 100 bytes wide and has a key which is 60 bytes wide and seven numeric fields is about approx. 50 msn (standardized microseconds).
Note
Runtime errors
COLLECT_OVERFLOW : Overflow in integer field when calculating totals.
COLLECT_OVERFLOW_TYPE_P : Overflow in type P field when calculating totals. -
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. -
About Collect Statement.
hi experts,
i am genereating a report in FICO module. i have to fetch teh data from the field DMBTR (AMOUNT). it has both credits anddebits. i have to do calculations and should display the final balance in the report. each GL account number has different credits and debits. i have to display each account with the balance. if i am using collect statement it only making sum of eitehr debits or credits. i want both to be sum up. is tehre any other way to do the same..thnx in advance,
santosh.Syntax Diagram
COLLECT
Syntax
COLLECT wa INTO itab [result].
Effect
This statement inserts the contents of a work area wa either as single row into an internal table itab or adds the values of its numeric components to the corresponding values of existing rows with the same key. As of Release 6.10, you can use result to set a reference to the inserted or changed row in the form of a field symbol or data reference.
Prerequisite for the use of this statement is that wa is compatible with the row type of itab and all components that are not part of the table key must have a numeric data type (i, p, f).
In standard tables that are only filled using COLLECT, the entry is determined by a temporarily created hash administration. The workload is independent of the number of entries in the table. The hash administration is temporary and is generally invalidated when the table is accessed for changing. If further COLLECT statements are entered after an invalidation, a linear search of all table rows is performed. The workload for this search increases in a linear fashion in relation to the number of entries.
In sorted tables, the entry is determined using a binary search. The workload has a logarithmic relationship to the number of entries in the table.
In hashed tables, the entry is determined using the hash administration of the table and is always independent of the number of table entries.
If no line is found with an identical key, a row is inserted as described below, and filled with the content of wa:
In standard tables the line is appended.
In sorted tables, the new line is inserted in the sort sequence of the internal table according to its key values, and the table index of subsequent rows is increased by 1.
In hashed tables, the new row is inserted into the internal table by the hash administration, according to its key values.
If the internal table already contains one or more rows with an identical key, those values of the components of work area wa that are not part of the key, are added to the corresponding components of the uppermost existing row (in the case of index tables, this is the row with the lowest table index).
The COLLECT statement sets sy-tabix to the table index of the inserted or existing row, in the case of standard tables and sorted tables, and to the value 0 in the case of hashed tables.
Outside of classes, you can omit wa INTO if the internal table has an identically-named header line itab. The statement then implicitly uses the header line as the work area.
COLLECT should only be used if you want to create an internal table that is genuinely unique or compressed. In this case, COLLECT can greatly benefit performance. If uniqueness or compression are not required, or the uniqueness is guaranteed for other reasons, the INSERT statement should be used instead.
The use of COLLECT for standard tables is obsolete. COLLECT should primarily be used for hashed tables, as these have a unique table key and a stable hash administration.
If a standard table is filled using COLLECT, it should not be edited using any other statement with the exception of MODIFY. If the latter is used with the addition TRANSPORTING, you must ensure that no key fields are changed. This is the only way to guarantee that the table entries are always unique and compressed, and that the COLLECT statement functions correctly and benefits performance. The function module ABL_TABLE_HASH_STATE can be used to check whether a standard table is suitable for editing using COLLECT.
Example
Compressed insertion of data from the database table sflight into the internal table seats_tab. The rows in which the key components carrid and connid are identical are compressed by adding the number of occupied seats to the numeric component seatsocc.
DATA: BEGIN OF seats,
carrid TYPE sflight-carrid,
connid TYPE sflight-connid,
seatsocc TYPE sflight-seatsocc,
END OF seats.
DATA seats_tab LIKE HASHED TABLE OF seats
WITH UNIQUE KEY carrid connid.
SELECT carrid connid seatsocc
FROM sflight
INTO seats.
COLLECT seats INTO seats_tab.
ENDSELECT.
Exceptions
Catchable Exceptions
CX_SY_ARITHMETIC_OVERFLOW
Cause: Overflow in integer field during totals formation
Runtime Error: COLLECT_OVERFLOW
Cause: Overflow in type p field during totals formation
Runtime Error: COLLECT_OVERFLOW_TYPE_P
Non-Catchable Exceptions
Cause: COLLECT used for non-numeric fields
Runtime Error: TABLE_COLLECT_CHAR_IN_FUNCTION -
Issue while using Collect statement in program
Hi friend's,
i have some issue regarding Collect statement..
Issue is somthing like this,i have created a structure and internal table and work area with same type,
u can look in below code..i wann to collect 'enmng' f'ield value whose matnr,charg,mvt type ,aufnr,rsnum are same but rspos and lgort are differnt for this i need to collect 'ENMNG' field value can any one tel me what to do...it not collectng value instead of this it append entire row...
types: begin of ty_resb,
rsnum type resb-rsnum, "Resrvation Number
rspos type resb-rspos, "item position
xloek type resb-xloek, "Item Deleted if = 'X'
matnr type resb-matnr, "Material Number
lgort type resb-lgort, "Storage location 'REJT'
charg type resb-charg, "Batch No
enmng type resb-enmng, "Quantity withdrawn should be greater then '0'
enwrt type resb-enwrt, "Value Withdrawn
aufnr type resb-aufnr, "Order
bwart type resb-bwart, "Movement type
end of ty_resb.
data:tt_resb type table of ty_resb ,
tt_resb1 type table of ty_resb ,
tt_resb2 type standard table of ty_resb ,
**workarea.
ts_resb type ty_resb,
ts_resb2 type ty_resb,
ts_resb1 type ty_resb.
**move data to another internal table
tt_resb1[] = tt_resb[].
sort tt_resb by rsnum rspos matnr charg bwart lgort aufnr .
sort tt_resb1 by rsnum rspos matnr charg bwart lgort aufnr.
DELETE adjacent duplicates from tt_resb comparing rsnum rspos matnr charg bwart lgort aufnr .
DELETE adjacent duplicates from tt_resb1 comparing rsnum rspos matnr charg bwart lgort aufnr.
loop at tt_resb into ts_resb .
clear:ts_resb1,ts_resb2.
read table tt_resb1 into ts_resb1 with key rsnum = ts_resb-rsnum rspos = ts_resb-rspos matnr = ts_resb-matnr
charg = ts_resb-charg aufnr = ts_resb-aufnr binary search.
if ts_resb1-bwart = '261' .
move ts_resb1-aufnr to ts_resb2-aufnr.
move ts_resb1-matnr to ts_resb2-matnr.
move ts_resb1-charg to ts_resb2-charg.
move ts_resb1-bwart to ts_resb2-bwart.
move ts_resb1-enwrt to ts_resb2-enwrt.
move ts_resb1-lgort to ts_resb2-lgort.
move ts_resb1-enmng to ts_resb2-enmng.
collect ts_resb2 into tt_resb2.
endif.
clear ts_resb.
endloop.
Regard's,
shaikh khalid.Hi Shaikh,
I have added new declarations as highlighted below and new lines within your loop:
Execute your program in debug mode and see what happens to the internal tt_collect I added. The collect will sum the fields enmng for all entries that have same value on the fields matnr,charg,mvt type ,aufnr,rsnum.
Question from me: what do you want to do with the collected/Summed up entries?
types: begin of ty_resb,
rsnum type resb-rsnum, "Resrvation Number
rspos type resb-rspos, "item position
xloek type resb-xloek, "Item Deleted if = 'X'
matnr type resb-matnr, "Material Number
lgort type resb-lgort, "Storage location 'REJT'
charg type resb-charg, "Batch No
enmng type resb-enmng, "Quantity withdrawn should be greater then '0'
enwrt type resb-enwrt, "Value Withdrawn
aufnr type resb-aufnr, "Order
bwart type resb-bwart, "Movement type
end of ty_resb.
data:tt_resb type table of ty_resb ,
tt_resb1 type table of ty_resb ,
tt_resb2 type standard table of ty_resb ,
types: begin of ty_collect,
rsnum type resb-rsnum,
matnr type resb-matnr,
charg type resb-charg,
bwart type resb-bwart,
aufnr type resb-aufnr,
enmng type resb-enmng,
end of ty_collect.
data: tt_collect type table of ty_collect,
ts_collect type ty_collect.
**workarea.
ts_resb type ty_resb,
ts_resb2 type ty_resb,
ts_resb1 type ty_resb.
**move data to another internal table
tt_resb1[] = tt_resb[].
sort tt_resb by rsnum rspos matnr charg bwart lgort aufnr .
sort tt_resb1 by rsnum rspos matnr charg bwart lgort aufnr.
DELETE adjacent duplicates from tt_resb comparing rsnum rspos matnr charg bwart lgort aufnr .
DELETE adjacent duplicates from tt_resb1 comparing rsnum rspos matnr charg bwart lgort aufnr.
loop at tt_resb into ts_resb .
clear:ts_resb1,ts_resb2.
read table tt_resb1 into ts_resb1 with key rsnum = ts_resb-rsnum rspos = ts_resb-rspos matnr = ts_resb-matnr
charg = ts_resb-charg aufnr = ts_resb-aufnr binary search.
if ts_resb1-bwart = '261' .
move ts_resb1-aufnr to ts_resb2-aufnr.
move ts_resb1-matnr to ts_resb2-matnr.
move ts_resb1-charg to ts_resb2-charg.
move ts_resb1-bwart to ts_resb2-bwart.
move ts_resb1-enwrt to ts_resb2-enwrt.
move ts_resb1-lgort to ts_resb2-lgort.
move ts_resb1-enmng to ts_resb2-enmng.
collect ts_resb2 into tt_resb2.
move-corresponding ts_resb1 to ts_collect.
collect ts_collect into tt_collect
endif.
clear ts_resb.
clear ts_collect.
endloop. -
Hi,
i have requirement to get all unique entries from table .if i am getting duplicate record then i need to add qunatity field which i have define like rlbes-anfme.
my internal table is :
11 name1 23.00
22 name2 1,324.00
11 name1 10.00
I want output in this way
11 name1 33.00
22 name2 1,324.00
i tried to use collect statement but the problem is its not working on character type field.
if i use packed field then i am not able to upload my file because i am getting quantity filed 1,2344.00 this way.( instead of 1325.00)
please give me any solution.
thanks,
jackHi,
Try this..
Create another internal table which has the same structure of your internal table.
DATA: LT_COLLECT LIKE ITAB OCCURS 0 WITH HEADER LINE.
DATA: V_QUANTITY TYPE MENGE_D.
Sort the internal table.
SORT ITAB BY field1 field2. " Give the appropriate field names.
<b>* process the internal table which has the records.</b>
LOOP AT ITAB.
Sum up the quantity.
V_MENGE = V_MENGE + ITAB-ANFME. " Quantity field.
Move the first two fields.
LT_COLLECT-FIELD1 = ITAB-FIELD1.
LT_COLLECT-FIELD2 = ITAB-FIELD2.
At the end of the record..append the record.
AT END OF FIELD2. " Give the corresponding field name.
LT_COLLECT-ANFME = V_MENGE.
APPEND LT_COLLECT.
CLEAR: V_MENGE.
ENDAT.
ENDLOOP.
Thanks,
Naren -
Reg: Collect statement in internal table
Hi,
Can any one tell me wether we can use the collect statement in an internal table which has no header line
if it can be used can anyone please send me a sample snippet
Thanks In ADVANCE
Guhapriyan SubrahmanyamHi Guhapriyan,
I have used the collect statement in the way as shown..
DATA : BEGIN of I_ALLOCATIONS OCCURS 0,
PSPNR LIKE PRPS-PSPNR,
PSPID LIKE PROJ-PSPID,
PSPHI LIKE PRPS-PSPHI,
POST1 LIKE PROJ-POST1,
ZZLOB LIKE PROJ-ZZLOB,
WERKS LIKE PROJ-WERKS,
SOBID LIKE HRP1001-SOBID,
OBJID LIKE HRP1001-OBJID,
BEGDA LIKE HRP1001-BEGDA,
ENDDA LIKE HRP1001-ENDDA,
PROZT LIKE HRP1001-PROZT,
LOB LIKE HRP1000-STEXT,
TEMP TYPE P decimals 2,
TYPE(3),
ZROLE LIKE PA0001-ZROLE,
HOLID TYPE P decimals 2,
LEAVE TYPE P decimals 2,
DAYS TYPE P decimals 2,
END of I_ALLOCATIONS.
DATA: I_ALLOCATION LIKE I_ALLOCATIONS OCCURS 0 WITH HEADER LINE.
************Populate I_ALLOCATIONS **************
LOOP AT I_ALLOCATIONS.
COLLECT I_ALLOCATIONS INTO I_ALLOCATION.
ENDLOOP.
Actually i had requirement like u, but this one is rather simple...
Get the required data in an I_Table which dont require Header line..
Later on collect this particular I_Table in other I_Table1 with the Header Line...
Regards,
Abhishek -
Transactional replication very slow with indexes on Subscriber table
I have setup Transactional Replication for one of our databases where one table with about 5mln records is replicated to a Subsriber database. With every replication about 500-600.000 changed records are send to the Subscriber.
Since one month I see very strange behaviour when I add about 10 indexes to the Subscriber table. As soon as I have added the indexes replication speed becomes extremely slow (almost 3 hours for 600k records). As soon as I remove the indexes the replication
is again very fast, about 3 minutes for the same amount of records.
I've searched a lot on the internet to solve this issue but can't find any explaination for this strange behaviour after adding the indexes. As far as I know it doesn't have to be a problem to add indexes to a Subscriber table, and it hasn't been before on
another replication configuration we use.
Some information from the Replication Log:
With indexes on the Subscriber table
Total Run Time (ms) : 9589938 Total Work Time : 9586782
Total Num Trans : 3 Num Trans/Sec : 0.00
Total Num Cmds : 616245 Num Cmds/Sec : 64.28
Total Idle Time : 0
Writer Thread Stats
Total Number of Retries : 0
Time Spent on Exec : 9580752
Time Spent on Commits (ms): 2687 Commits/Sec : 0.00
Time to Apply Cmds (ms) : 9586782 Cmds/Sec : 64.28
Time Cmd Queue Empty (ms) : 5499 Empty Q Waits > 10ms: 172
Total Time Request Blk(ms): 5499
P2P Work Time (ms) : 0 P2P Cmds Skipped : 0
Reader Thread Stats
Calls to Retrieve Cmds : 2
Time to Retrieve Cmds (ms): 10378 Cmds/Sec : 59379.94
Time Cmd Queue Full (ms) : 9577919 Full Q Waits > 10ms : 6072
Without indexes on the Subscriber table
Total Run Time (ms) : 89282 Total Work Time : 88891
Total Num Trans : 3 Num Trans/Sec : 0.03
Total Num Cmds : 437324 Num Cmds/Sec : 4919.78
Total Idle Time : 0
Writer Thread Stats
Total Number of Retries : 0
Time Spent on Exec : 86298
Time Spent on Commits (ms): 282 Commits/Sec : 0.03
Time to Apply Cmds (ms) : 88891 Cmds/Sec : 4919.78
Time Cmd Queue Empty (ms) : 1827 Empty Q Waits > 10ms: 113
Total Time Request Blk(ms): 1827
P2P Work Time (ms) : 0 P2P Cmds Skipped : 0
Reader Thread Stats
Calls to Retrieve Cmds : 2
Time to Retrieve Cmds (ms): 2812 Cmds/Sec : 155520.63
Time Cmd Queue Full (ms) : 86032 Full Q Waits > 10ms : 4026
Can someone please help me with this issue? Any ideas?
PimHi Megens:
Insert statement might be slow with not only indexes and few others things too
0) SQL DB Blocking during inserts
1) If any insert triggers are existed
2) Constraints - if any
3) Index fragmentation
4) Page splits / fill factor
Without indexes inserts will be fast because, each time when new row going to insert to the table, SQL Server will do
1) it will check for the room, if no room page splits will happen and record will placed at right place
2) Once the record updated all the index should be update
3) all these extra update work will cause can make insert statement bit slow
Its better to have index maintenance jobs frequently to avoid fragmentation.
If every thing is clear on SQL Server Side, you need look up on DISK IO, N/W Latency between the servers and so on
Thanks,
Thanks, Satish Kumar. Please mark as this post as answered if my anser helps you to resolves your issue :) -
Hi friends i have doubt on collect statement.
i have some problem with matnr which is repeating no.of times. so i tried using collect and selected some of the fields to collect. Now i need to collect those collected elements in to internal table and need to display those fields in an ouput. for example.
loop at sumtab.
matnr type s886-matnr,
avg1 type p decimals 3,
total type p decimals 3,
endloop.
and now using loop i am collecting. these fields using my itab.
loop at itab.
move-corresponding itab to sumtab.
collect sumtab.
clear sumtab.
endloop.
***here itab contains no.of other fields like qty,stock etc.
so after here i am using ALV to display the itab.
my problem is how to make SUMTAB fields tobe moved in itab.Hi Kalyan,
The collect statement works like this . (ex)
data: begin of itab occurs 0,
name(10) type c,
value(4) type n,
end of itab.
itab-name = 'JACK'.
itab-value = 100.
append itab.
itab-name = 'PAT'.
itab-value = 200.
append itab.
itab-name = 'JACK'.
itab-value = 200.
append itab.
sort itab.
loop itab.
collect itab.
write: / itab-name, itab-value.
endloop.
<b>o/p:</b>
JACK 300
PAT 200
Maybe you are looking for
-
Boa tarde. Estamos implementando ECC e usando a solução disponibilizada pela SAP de trabalhar com o CTe como um mestre de serviço. As notas foram aplicadas e tudo esta funcionando (Contabilização da Folha/MIRO e escrituração), porém é preciso registr
-
I deleted my app world how do i get it back?
I deleted my app world how do i get it back
-
Problem with customer exit variable on date range
Hi All, I have customer exit variable on date range. In the selection screen it has to give the week range as a default (05/21/2009 to 05/27/2009). Earlier its working fine and from yesterday onwards it is not working properly. yesday onwards defaul
-
dear apple im gonna smash my iphone 4s!! what a rubbish! reception is totally awfull. Im on O2 UK and my reception goes from four to one too often. I thought you have sorted the antenna issues! how can I have full reception at one point, and then it
-
Java Slideshow via HTML Snippet?
I've created a basic slideshow in XatShow, when it outputs, it creates a folder with the following files; show1.html xatshowApplet.jar and 20 .jpg files (the images). I've copied the contents of the html file, and tried to paste them into the window