‎2005 Nov 14 2:47 AM
Hi experts,
This is list of vendor line items code.
I want to display only KZ item with total amount.
So getting all the items and deleting which or not KZ items(excluding total amount of particular doc no.)
Can u tell me how to increase performance of this code.
I have commented * #################### like this.
There it is taking lot of time....
points guaranteed
cheers
kaki
REPORT Z1F_RFKEPL00 no standard page heading
line-size 140
line-count 65
message-id Z1.
TABLES: LFA1,t005t,bsak,bseg,t001,skat.
data: begin of t_bsak occurs 0,
bukrs like bsak-bukrs, "company code
lifnr like bsak-lifnr, "Vendor acc number
augdt like bsak-augdt, "Clearing date
AUGBL like bsak-AUGBL, "Clearing Document
GJAHR like bsak-GJAHR, "year
belnr like bsak-belnr, "Document number
BUZEI like bsak-BUZEI, "Line Item
budat like bsak-budat, "Posting Date in the Document
bldat like bsak-bldat, "Document date in document
blart like bsak-blart, "Document type
BSCHL like bsak-BSCHL, "Posting key
WAERS like bsak-WAERS, "Currency key
CPUDT like bsak-cpudt, "Accounting Document Entry Date
SHKZG like bsak-shkzg, "Debit/Credit Indicator
DMBTR like bsak-dmbtr, "Amount in local currency
WRBTR like bsak-wrbtr, "Amount in document currency
SGTXT like bsak-sgtxt, "Item Text
SAKNR LIKE bsak-saknr, "G/L Account Number
hkont like bsak-hkont, "General Ledger Account
SKFBT LIKE BSAK-SKFBT, "Amount Eligible for Cash Discount
KOSTL LIKE BSEG-KOSTL, "Cost center
ktopl like t001-ktopl, "chart of accounts
txt20 like skat-txt20, "Short test for the GL acc
name1 like lfa1-name1,
land1 like lfa1-land1,
landx like t005t-landx,
l_year like bsak-gjahr,
end of t_bsak.
data: begin of t_header occurs 0,
bukrs like bsak-bukrs,
belnr like bsak-belnr,
augbl like bsak-augbl,
gjahr like bsak-gjahr,
hkont like bseg-hkont,
lifnr like bsak-lifnr,
land1 like lfa1-land1,
name1 like lfa1-name1,
name2 like lfa1-name2,
name3 like lfa1-name3,
ort01 like lfa1-ort01,
pstlz like lfa1-pstlz,
landx like t005t-landx,
end of t_header.
data: begin of t_lfa1 occurs 0,
lifnr like lfa1-lifnr,
name1 like lfa1-name1,
land1 like lfa1-land1,
landx like t005t-landx,
end of t_lfa1.
data: begin of t_cal occurs 0,
debit like bsak-wrbtr,
credit like bsak-wrbtr,
balance like bsak-wrbtr,
end of t_cal.
data: t_bseg like t_bsak occurs 0 with header line.
data: t_data like t_bsak occurs 0 with header line.
selection-screen begin of block blk1 with frame title text-001.
select-options: s_lifnr for bsak-lifnr,
s_bukrs for bsak-bukrs.
selection-screen end of block blk1.
selection-screen begin of block blk2 with frame title text-002.
parameters s_budat like bsik-budat default sy-datum.
select-options: s_augdt for bsak-augdt.
selection-screen end of block blk2.
selection-screen begin of block blk3 with frame title text-003.
parameters: stand as checkbox default 'X',
park as checkbox.
selection-screen end of block blk3.
start-of-selection.
perform process_data.
top-of-page.
perform set_page_header.
&----
*& Form process_data
&----
text
----
form process_data.
data: line like t_bsak occurs 0 with header line.
data: l_wrbtr(10) type c.
data: l_debit type bsak-wrbtr,l_credit type bsak-wrbtr,
l_balance type bsak-wrbtr.
data: l_hkont(10) type n.
data: l_dtotal type bsak-wrbtr,l_ctotal type bsak-wrbtr,
l_fbalance type bsak-wrbtr.
data: t_tot like t_cal occurs 0 with header line.
Ranges R_BSTAT FOR BSAK-BSTAT.
R_BSTAT-SIGN = 'I'.
R_BSTAT-OPTION = 'EQ'.
IF stand = 'X' and park ne 'X'.
R_BSTAT-LOW = ' '.
APPEND R_BSTAT.
elseif stand ne 'X' and park eq 'X'.
R_BSTAT-LOW = 'V'.
APPEND R_BSTAT.
elseif stand eq 'X' and park eq 'X'.
R_BSTAT-LOW = ' '.
APPEND R_BSTAT.
R_BSTAT-LOW = 'V'.
APPEND R_BSTAT.
endif.
select BUKRS LIFNR AUGDT AUGBL GJAHR BELNR BUZEI BUDAT BLDAT
CPUDT WAERS BLART BSCHL SHKZG DMBTR WRBTR SGTXT HKONT SKFBT
from bsak
into corresponding fields of table t_bsak
where lifnr in s_lifnr and
BUKRS in s_bukrs and
budat le s_budat and " Open items
augdt in s_augdt and
bstat in R_BSTAT.
if sy-subrc ne 0.
message i016.
leave list-processing.
endif.
sort t_bsak by BUDAT.
loop at t_bsak.
t_bsak-l_year = t_bsak-budat(4).
modify t_bsak.
endloop.
CHECK NOT t_bsak[] IS INITIAL.
select BUKRS LIFNR AUGDT AUGBL GJAHR BELNR
SHKZG DMBTR WRBTR SGTXT SKFBT KOSTL BSCHL HKONT BUZEI
into corresponding fields of table t_bseg from bseg
FOR ALL ENTRIES IN t_bsak
where belnr = t_bsak-belnr and
gjahr = t_bsak-l_year and
bukrs = t_bsak-bukrs.
loop at t_bsak.
select single * from lfa1 where lifnr = t_bsak-lifnr.
move lfa1-lifnr to t_header-lifnr.
move lfa1-land1 to t_header-land1.
move lfa1-name1 to t_header-name1.
move lfa1-name2 to t_header-name2.
move lfa1-name3 to t_header-name3.
move lfa1-ort01 to t_header-ort01.
move lfa1-pstlz to t_header-pstlz.
move t_bsak-bukrs to t_header-bukrs.
append t_header.
clear t_header.
endloop.
to get vendor country
loop at t_header.
select single * from t005t where land1 = t_header-land1 and
SPRAS = 'E'.
move t005t-landx to t_header-landx.
if sy-subrc = 0.
modify t_header.
clear t_header.
endif.
endloop.
sort t_header.
delete adjacent duplicates from t_header.
loop at t_bsak.
loop at t_bseg where belnr = t_bsak-belnr and
bukrs = t_bsak-bukrs and
gjahr = t_bsak-gjahr.
l_hkont = t_bseg-hkont.
*To get chart of accounts
select single * from t001 where bukrs = t_bseg-bukrs.
move t001-ktopl to t_bseg-ktopl.
*To get short text for the chart of accounts
select single * from skat where ktopl = t_bseg-ktopl and
saknr = l_hkont and
spras = 'E'.
t_data-bukrs = t_bsak-bukrs.
t_data-lifnr = t_bsak-lifnr.
t_data-augdt = t_bseg-augdt.
t_data-AUGBL = t_bseg-AUGBL.
t_data-GJAHR = t_bseg-GJAHR.
t_data-belnr = t_bsak-belnr.
t_data-BUZEI = t_bseg-BUZEI.
t_data-budat = t_bsak-budat.
t_data-bldat = t_bsak-bldat.
t_data-blart = t_bsak-blart.
t_data-BSCHL = t_bseg-BSCHL.
t_data-WAERS = t_bsAK-WAERS.
t_data-CPUDT = t_bsak-cpudt.
t_data-SHKZG = t_bseg-shkzg.
t_data-DMBTR = t_bseg-dmbtr.
t_data-WRBTR = t_bseg-wrbtr.
t_data-SGTXT = t_bsak-sgtxt.
t_data-SAKNR = t_bseg-saknr.
t_data-hkont = t_bseg-hkont.
t_data-SKFBT = t_bseg-SKFBT.
t_data-KOSTL = t_bseg-KOSTL.
t_data-ktopl = t_bseg-ktopl.
t_data-txt20 = skat-txt20.
append t_data.
clear t_data.
endloop.
endloop.
####################
loop at t_bsak.
delete t_data where bschl = '50'.
endloop.
loop at t_bsak.
loop at t_data where augbl = t_bsak-augbl.
delete t_data where augbl eq t_bsak-augbl and
buzei ne '02' and
blart eq 'KZ'.
endloop.
endloop.
it is taking lot of time here
*Display----
*to display header
loop at t_header.
write:/1(6) t_header-bukrs color 2,
7(8) t_header-hkont color 2,
18(10) t_header-lifnr color 2.
write:/30(35) t_header-name1.
write:/30(35) t_header-name2.
write:/30(35) t_header-name3.
write:/30(20) t_header-ort01.
write:40(10) t_header-pstlz.
write:/30(20) t_header-landx.
uline.
loop at t_data where lifnr = t_header-lifnr
and hkont = t_header-hkont. "xxxxxxxxxx
loop at t_data where lifnr = t_header-lifnr.
l_wrbtr = t_data-wrbtr.
if t_data-shkzg = 'H'.
concatenate l_wrbtr '-' into l_wrbtr.
endif.
write:/15(11) t_data-BUDAT no-zero color 7,
26(5) t_data-BLART color 7,
30(12) t_data-belnr color 7,
42(16) t_data-BLDAT color 7,
58(5) t_data-buzei color 7,
63(12) t_data-BSCHL color 7,
75(9) t_data-AUGDT color 7,
84(35) t_data-AUGBL color 7,
119(7) t_data-WAERS color 7,
126(12) l_wrbtr color 7.
write:/55 t_data-sgtxt.
write:/60(10) t_data-kostl,
70(10) t_data-hkont,
80(20) t_data-txt20.
clear l_wrbtr.
endloop. " t_data.
uline.
write:/1(6) t_data-bukrs color 2,
7(8) t_data-hkont color 2,
18(10) t_data-lifnr color 2.
uline.
write:/1(6) t_data-bukrs color 2,
7(8) t_data-hkont color 2,
18(10) t_data-lifnr color 2,
105(5) t_data-waers color 2.
line[] = t_bsak[].
loop at line where lifnr = t_header-lifnr.
*for dedit
if line-shkzg = 'H'.
l_debit = l_debit + line-wrbtr.
endif.
*for credit
if line-shkzg = 'S'.
l_credit = l_credit + line-wrbtr.
endif.
endloop.
l_balance = l_debit - l_credit.
*for total debit & total credit
t_cal-debit = l_debit.
t_cal-credit = l_credit.
append t_cal.
clear t_cal.
write:115(15) l_debit color 3. write:135(1) 'D' color 3.
write:/115(15) l_credit color 3. write:135(1) 'C' color 3.
for balnce
write:/90(25) 'Bal.:' color 3.
write:115(15) l_balance color 3.
clear: l_debit,l_credit,l_balance.
uline.
endloop.
for totals
t_tot[] = t_cal[].
loop at t_cal into t_tot.
AT LAST.
SUM.
WRITE:115(15) t_tot-debit color 5.
WRITE:/115(15) t_tot-credit color 5.
write:/90(25) 'Bal.:' color 5.
l_fbalance = t_tot-debit - t_tot-credit.
write:115(15) l_fbalance color 5.
WRITE:1(130) t_tot-debit color 5. write:135(1) 'D' color 5.
WRITE:/1(130) t_tot-credit color 5. write:135(1) 'C' color 5.
write:/1(115) space color 5.
write: 90(25) 'Bal.:' color 5.
l_fbalance = t_tot-debit - t_tot-credit.
write:115(16) l_fbalance color 5.
ENDAT.
endloop.
endform. "process_data
&----
*& Form set_page_header
&----
text
----
FORM set_page_header.
write :1(15) 'Allocation' color col_heading,
15(10) 'Pstng' color col_heading,
25(5) 'Do' color col_heading,
30(10) 'Documnet' color col_heading,
40(10) 'Doc' color col_heading,
50(8) 'BusA' color col_heading,
58(5) 'LIm' color col_heading,
63(4) 'PK' color col_heading,
67(4) 'S' color col_heading,
71(4) 'P' color col_heading,
75(7) 'Clrg' color col_heading,
82(10) 'Clearing' color col_heading,
92(20) 'D/c discount Amnt' color col_heading,
112(5) 'Rsn' color col_heading,
117(2) 'G' color col_heading,
119(7) 'Curr-' color col_heading,
126(12) 'Amount in' color col_heading,
138(2) 'T' color col_heading.
write space.
write :1(15) 'number' color col_heading,
15(10) 'date' color col_heading,
25(5) 'ty' color col_heading,
30(10) 'number' color col_heading,
40(18) 'date' color col_heading,
58(5) '' color col_heading,
63(4) '' color col_heading,
67(4) 'I' color col_heading,
71(4) 'K' color col_heading,
75(7) 'date' color col_heading,
82(24) 'doc.no' color col_heading,
105(20) 'in LC' color col_heading,
112(5) 'code' color col_heading,
117(2) 'L' color col_heading,
119(7) 'ency' color col_heading,
126(12) 'doc.curr.' color col_heading,
138(2) 'X' color col_heading.
write space.
uline.
ENDFORM. " set_page_header
Message was edited by: Kaki R
‎2005 Nov 14 3:01 AM
I am not sure why you are looping at t_bsak so many times, but first let us focus on the piece of code you mentioned.
Here is your code
* ####################
loop at t_bsak.
delete t_data where bschl = '50'.
<b>*--why are you looping at t_bsak, if you just wanted
to delete t_data where bschl = '50'? You are not
using any field of t_bsak here!!! Comment out the loop--endloop statements here.</b>
endloop.
loop at t_bsak.
*************************
loop at t_data where augbl = t_bsak-augbl.
delete t_data where augbl eq t_bsak-augbl and
buzei ne '02' and
blart eq 'KZ'.
endloop.
**************************
<b>*-- change this code as follows
delete t_data where augbl eq t_bsak-augbl
and buzei ne '02'
and blart eq 'KZ'.</b>
endloop.
* it is taking lot of time here
‎2005 Nov 14 3:01 AM
I am not sure why you are looping at t_bsak so many times, but first let us focus on the piece of code you mentioned.
Here is your code
* ####################
loop at t_bsak.
delete t_data where bschl = '50'.
<b>*--why are you looping at t_bsak, if you just wanted
to delete t_data where bschl = '50'? You are not
using any field of t_bsak here!!! Comment out the loop--endloop statements here.</b>
endloop.
loop at t_bsak.
*************************
loop at t_data where augbl = t_bsak-augbl.
delete t_data where augbl eq t_bsak-augbl and
buzei ne '02' and
blart eq 'KZ'.
endloop.
**************************
<b>*-- change this code as follows
delete t_data where augbl eq t_bsak-augbl
and buzei ne '02'
and blart eq 'KZ'.</b>
endloop.
* it is taking lot of time here
‎2005 Nov 14 3:03 AM
So your code should look like this
delete t_data where bschl = '50'.
loop at t_bsak.
delete t_data where augbl eq t_bsak-augbl
and buzei ne '02'
and blart eq 'KZ'.
endloop.
‎2005 Nov 14 3:10 AM
‎2005 Nov 14 3:25 AM
See if this code, further improves it. I tried to remove lot of redundant loops. <b>Caution, I wrote this in notepad, so I may have missed a couple of lines, so check it thoroughly. This is just to give you an idea.</b>
select BUKRS LIFNR AUGDT AUGBL
GJAHR BELNR BUZEI BUDAT
BLDAT CPUDT WAERS BLART
BSCHL SHKZG DMBTR WRBTR
SGTXT HKONT SKFBT
from bsak
into corresponding fields of table t_bsak
where lifnr in s_lifnr
and BUKRS in s_bukrs
and budat le s_budat
and augdt in s_augdt
and bstat in R_BSTAT.
if sy-subrc ne 0.
message i016.
leave list-processing.
endif.
sort t_bsak by BUDAT.
loop at t_bsak.
t_bsak-l_year = t_bsak-budat(4).
select BUKRS LIFNR AUGDT AUGBL GJAHR BELNR
SHKZG DMBTR WRBTR SGTXT SKFBT KOSTL
BSCHL HKONT BUZEI
into corresponding fields of t_bseg
from bseg FOR ALL ENTRIES IN t_bsak
where belnr = t_bsak-belnr
and gjahr = t_bsak-l_year
and bukrs = t_bsak-bukrs.
*-- if BSCHL = 50, dont go further
check t_bseg-bschl <> '50'
and ( buzei eq '02' or
blart ne 'KZ' ).
l_hkont = t_bseg-hkont.
*-- To get chart of accounts
select single * from t001
where bukrs = t_bseg-bukrs.
move t001-ktopl to t_bseg-ktopl.
*-- To get short text for the chart of accounts
select single * from skat
where ktopl = t_bseg-ktopl
and saknr = l_hkont
and spras = 'E'.
t_data-bukrs = t_bsak-bukrs.
t_data-lifnr = t_bsak-lifnr.
t_data-augdt = t_bseg-augdt.
t_data-AUGBL = t_bseg-AUGBL.
t_data-GJAHR = t_bseg-GJAHR.
t_data-belnr = t_bsak-belnr.
t_data-BUZEI = t_bseg-BUZEI.
t_data-budat = t_bsak-budat.
t_data-bldat = t_bsak-bldat.
t_data-blart = t_bsak-blart.
t_data-BSCHL = t_bseg-BSCHL.
t_data-WAERS = t_bsAK-WAERS.
t_data-CPUDT = t_bsak-cpudt.
t_data-SHKZG = t_bseg-shkzg.
t_data-DMBTR = t_bseg-dmbtr.
t_data-WRBTR = t_bseg-wrbtr.
t_data-SGTXT = t_bsak-sgtxt.
t_data-SAKNR = t_bseg-saknr.
t_data-hkont = t_bseg-hkont.
t_data-SKFBT = t_bseg-SKFBT.
t_data-KOSTL = t_bseg-KOSTL.
t_data-ktopl = t_bseg-ktopl.
t_data-txt20 = skat-txt20.
append t_data.
clear t_data.
endselect. " BSEG select
select single * from lfa1 where lifnr = t_bsak-lifnr.
move lfa1-lifnr to t_header-lifnr.
move lfa1-land1 to t_header-land1.
move lfa1-name1 to t_header-name1.
move lfa1-name2 to t_header-name2.
move lfa1-name3 to t_header-name3.
move lfa1-ort01 to t_header-ort01.
move lfa1-pstlz to t_header-pstlz.
move t_bsak-bukrs to t_header-bukrs.
select single * from t005t
where land1 = t_header-land1
and SPRAS = 'E'.
move t005t-landx to t_header-landx.
append t_header.
clear t_header.
endloop.
sort t_header.
delete adjacent duplicates from t_header.