2015 Nov 10 8:51 AM
Hi Guru's
I will explain my program and please suggest where i need to put clear. Even, i used debugger, but not able to understand.
Selected the EKKO table (item table) with EBELN, and it's contain multiple line item (2 rows).
and i looped in this table (loop at IT! into WA), in this loop, selected the EKBE table with movement type 101 and EBELN.(used be SELECT END SECLECT) Hence, here also two line items has selected (checked data dictionary).
My question, two time EBLEN has passed in loop or one time EBELN has passed. Because, I need to collect the total line item value of PO and GRN.
According to my code, I am getting value as multiplied by two. Also please suggest where i need to use CLEAR.
Rgds,
Ganapathi Raman P
2015 Nov 10 9:15 AM
Hi Ganapathi,
Please go through the sample code.
READ TABLE IT_EKKO INTO WA_EKKO WITH KEY <condition>.
IF SY-SUBRC = 0.
WA_FINAL-EKGRP = WA_EKKO-EKGRP.
WA_FINAL-AEDAT = WA_EKKO-AEDAT.
WA_FINAL-ERNAM = WA_EKKO-ERNAM.
LOOP AT IT_EKPO INTO WA_EKPO WHERE EBELN = WA_EKKO-EBELN AND BUKRS = WA_EKKO-BUKRS.
WA_FINAL-BUKRS = WA_EKPO-BUKRS.
WA_FINAL-BEDNR = WA_EKPO-BEDNR.
WA_FINAL-EBELN = WA_EKPO-EBELN.
WA_FINAL-EBELP = WA_EKPO-EBELP.
WA_FINAL-STATU = WA_EKPO-STATU.
WA_FINAL-LOEKZ = WA_EKPO-LOEKZ.
WA_FINAL-MATNR = WA_EKPO-MATNR.
WA_FINAL-TXZ01 = WA_EKPO-TXZ01.
WA_FINAL-WERKS = WA_EKPO-WERKS.
WA_FINAL-LGORT = WA_EKPO-LGORT.
WA_FINAL-KTMNG = WA_EKPO-KTMNG.
WA_FINAL-MEINS = WA_EKPO-MEINS.
WA_FINAL-NETPR = WA_EKPO-NETPR.
WA_FINAL-BRTWR = WA_EKPO-BRTWR.
APPEND WA_FINAL TO IT_FINAL.
CLEAR: WA_EKPO.
ENDLOOP.
ENDIF.
CLEAR: WA_EKKO, WA_FINAL.
2015 Nov 10 9:29 AM
Just littlle modification on the above code,
CLEAR: WA_EKKO, WA_EKPO.
ENDLOOP.
ENDIF.
CLEAR: WA_FINAL.
2015 Nov 10 9:47 AM
Hi Monika,
Thanks for your reply..
This is my code,
select EBELN WERKS AEDAT from EKKO into IT1 where EBELN in SO_EBELN.
*two records has been selected
loop at IT1 into WA1
select EBELN MENGE BWART from EKBE into WA2 where EBELN = WA1-EBELN and BWART = 101
*two records has been selected
if sy-subrc = 0.
wa_collect-ebeln = wa1-ebeln.
wa_collect-netwr = wa1-netwr.
wa_collect-menge = wa3-menge.
end if.
collect wa_collect.
write : wa_collect-ebeln, wa_collect-netwr, wa_collect-menge.
endloop.
here, total values of netwr and menge has been multiplied by two. so, where i have to use clear.
please suggest me.
Rgds,
Ganapathi Raman P
2015 Nov 10 9:54 AM
Hi Ganapathi,
In EKBE select query include ebelp field in where condition or before loop sort internal table by ebeln, delete adjacent duplicates from internal table comparing ebeln.
Hope it helpful,
Regards,
Venkat.
2015 Nov 10 10:01 AM
Hi Ganapathi, i hav seen your code,
in ekko table , you will get only line ltem for particular EBELN. if 2 records has been selected means 2 different purchase doc u r giving.
In ekbe table , have chance to get more line items for particular EBELN. my code will help for u.
for performance wise, try to avoid select- endselect.
check with proper test data else will get different result.
Happy coding!!!.
Rgds,
Kannan
2015 Nov 10 10:10 AM
2015 Nov 10 10:14 AM
2015 Nov 10 11:24 AM
Hi kannan,
wrongly mentioned EKKO instead of EKPO.
I given only one purchase document number. in this contain, two line items.
As debugger says, IT1 have two records and after collect the values are multiplied by two.
checked with debugger, first line item record passing two times, so first line item value has doubled and it's collects second line item GRN value also and vice versa for (second line item).
If i use EKBE only, your coding works fine with no doubt !!!
Hence, Please suggest the solution for my method.
Rgds,
Ganapathi Raman P
2015 Nov 10 11:32 AM
Mounika code will help in that case. Please check that code also.
Rgds,
Kannan
2015 Nov 11 9:08 AM
Hi Venkat,
Including EBELP in where condition, for what i need to mention as condition ?
sort internal table by ebeln and delete adjacent duplicate comparing by ebeln. this is for EKBE ?
Here, there is no duplicate record found. becoze, in EKPO, two line items has found with values and EKBE, two line item found with GRN values.
Hence, i need to collect with value and total GRN's for the PO number. That's all.
Please confirm.
Rgds,
Ganapathi
2015 Nov 11 11:58 AM
Hi Ganapathi,
Usually purchase order contains sub items.
eg: 6000 10,
6000 20.
if you are not considering purchase order item then po number will be coming twice in ekpo internal table.
Kindly discuss with functional consultant regarding requirement.
if you never consider about purchase order item.
then you can sort the ekpo internal table with ebeln.
delete adjacent duplicates from internal table(ekpo) comparing ebeln. to avoid twice the po number.
Hope it helpful,
Regards,
Venkat.
2015 Nov 11 1:26 PM
Hi Venkat,
Thanks for your input.
My functional consultant has never considered about the purchase order item.
I can accept your 'delete adjacent duplicates' coding. But, my functional consultant required, to display the total values of PO , GRN Qty. If i used, delete adjacent duplicates , it will get first line item value only
Hence, I used collect statement to get the total value of all line items. Can you please suggest alternative method if possible or will modify in this coding.
Regards
Ganapathi
2015 Nov 11 4:05 PM
Hi Ganapathi,
Declare internal table with po no and amount field, fill the values to internal table with collect statement ( it_ekpo internal table).
pass the new internal table for ekbe select query.
Hope it helpful,
Regards,
Venkat.
2015 Nov 12 3:24 PM
You could try some
So I would suggest
SELECT ebeln werks aedat
ebelp menge netwr " new fields
FROM ekpo
INTO TABLE it1
WHERE ebeln IN so_ebeln.
LOOP AT it1 INTO wa1.
SELECT menge " other fields removed as already known!
FROM ekbe
INTO wa2
WHERE ebeln = wa1-ebeln AND ebelp = wa1-ebelp AND bwart = '101'.
IF sy-subrc = 0.
wa_collect-ebeln = wa1-ebeln.
wa_collect-netwr = wa1-netwr * ( wa3-menge / wa1-menge ). " add some check
wa_collect-menge = wa3-menge.
COLLECT wa_collect.
SUBTRACT wa_collect-netwr FROM wa1-netwr.
SUBTRACT wa_collect-menge FROM wa1-menge. " prevent rounding effect
ENDIF.
ENDSELECT.
ENDLOOP.
Now try to optimize with either some JOIN or only two SELECT (and without FOR ALL ENTRIES) and filling the final table only at last EBELN record. Also did you consider RM (102)
Regards,
Raymond
2015 Nov 14 8:38 AM
2015 Nov 10 9:43 AM
Hi Ganapathi,
What are the fields you getting in the selection screen? if you want fetch data from EKPO and EKBE table, please follow the below select query
select a~ebeln
a~ebelp
a~matnr
a~bwtar
a~menge
a~BMBTR into (corrosponding fields of table IT_EKBE)
from (ekbe AS a inner join ekko AS b ON a~ebeln = b~ebeln
where budat in S_BUDAT and a~BWART eq '101'.
note: what fields you are getting in the selection screen, you can add those fields in the where condition.
create one more internal table for EKBE like IT_EKBE1
use collect statement inside the loop,
loop at it_ekbe into wa_ekbe.
collect wa_ekbe to IT_EKBE1.
endloop.
Hope this solution will help for you.
Rgds,
kannan
2015 Nov 12 5:40 PM
Please check if the following code helps
types:begin of ty_temp,
ebeln type ebeln,
ebelp type ebelp,
werks type ewerk,
aedat type erdat,
netwr type bwert,
menge type menge_d,
bwtar type bwtar_d,
end of ty_temp,
begin of ty_collect,
ebeln type ebeln,
netwr type bwert,
menge type menge_d,
end of ty_collect.
data:
wa_collect type ty_collect,
it_collect type TABLE OF ty_collect,
it_temp type STANDARD TABLE OF ty_temp,
wa_temp type ty_temp.
SELECTION-SCREEN begin of block b1.
select-OPTIONS: so_ebeln for wa_temp-ebeln.
SELECTION-SCREEN end of block b1.
SELECT ekpo~ebeln ekpo~ebelp ekpo~werks ekpo~aedat ekpo~netwr
ekbe~menge ekbe~bwart into table it_temp
from ekpo inner JOIN ekbe on ekpo~ebeln = ekbe~ebeln
and ekpo~ebelp = ekbe~ebelp
where ekpo~ebeln in so_ebeln
and bwart = 101.
if sy-subrc is INITIAL.
loop at it_temp into wa_temp.
wa_collect-ebeln = wa_temp-ebeln.
wa_collect-netwr = wa_temp-netwr.
wa_collect-menge = wa_temp-menge.
collect wa_collect into it_collect.
endloop.
clear wa_collect.
endif.
loop at it_collect into wa_collect.
write : / wa_collect-ebeln, wa_collect-netwr, wa_collect-menge.
endloop.
2015 Nov 24 7:05 PM