2006 Feb 28 1:27 AM
Hello experts,
I am currently trying to figure out a certain code because when I debug it it does not loop through all the records. For example, on the selection screen I put in PO number 4540000027 up to 4540000051. So when I debug it PO numbers 4540000050 and 4540000051 does not go through the loop so when the report output shows these 2 PO's doesnt have PO amount which they get in ekpo-netwr. I checked ekpo and they have both have values. This also happens when I try to show all PO and some of the PO in the report doesnt have an amount which when I check on the table, they have an amount. The field which holds the values of a certain PO is t_amount-netwr.I have pasted below the code which I am currently modifying. Help would really be appreciated. Thanks guys and take care!
LOOP AT t_account.
*AVH
on change of t_account-ebeln.
CLEAR v_netwr.
SELECT SINGLE netwr FROM ekpo INTO v_netwr
WHERE ebeln = t_account-ebeln
AND ebelp = t_account-po_item.
t_amount-netwr = v_netwr.
ENDON.
DELETE it_dtl WHERE ebeln = t_account-ebeln
AND psphi IS initial.
DELETE t_ekpo WHERE ebeln = t_account-ebeln
AND ebelp = t_account-po_item.
DELETE t_pohistory WHERE ebeln = t_account-ebeln
AND po_item = t_account-po_item.
t_proj-ebelp = t_account-po_item.
SELECT SINGLE psphi FROM prps INTO t_proj-psphi
WHERE posid = t_account-wbs_elem_e.
CHECK sy-subrc = 0.
LOOP AT t_pohistory WHERE po_item = t_account-po_item
AND ebeln = t_account-ebeln.
t_amount-ebeln = t_account-ebeln.
t_amount-psphi = t_proj-psphi.
AT NEW po_item.
CLEAR v_netwr.
SELECT SINGLE netwr FROM ekpo INTO v_netwr
WHERE ebeln = t_account-ebeln
AND ebelp = t_account-po_item.
t_amount-netwr = v_netwr.
ENDAT.
on change of t_account-ebeln.
CLEAR v_netwr.
SELECT SINGLE netwr FROM ekpo INTO v_netwr
WHERE ebeln = t_account-ebeln
AND ebelp = t_account-po_item.
t_amount-netwr = v_netwr.
ENDON.
ON CHANGE OF t_pohistory-po_item.
CLEAR v_netwr.
SELECT SINGLE netwr FROM ekpo INTO v_netwr
WHERE ebeln = t_account-ebeln
AND ebelp = t_account-po_item.
t_amount-netwr = v_netwr.
ENDON.
IF v_ebeln IS INITIAL AND v_ebelp IS INITIAL.
CLEAR v_netwr.
SELECT SINGLE netwr FROM ekpo INTO v_netwr
WHERE ebeln = t_account-ebeln
AND ebelp = t_account-po_item.
t_amount-netwr = v_netwr.
v_ebeln = t_account-ebeln.
v_ebelp = t_account-po_item.
ELSEIF v_ebeln <> t_account-ebeln AND
v_ebelp <> t_account-po_item.
CLEAR v_netwr.
SELECT SINGLE netwr FROM ekpo INTO v_netwr
WHERE ebeln = t_account-ebeln
AND ebelp = t_account-po_item.
t_amount-netwr = v_netwr.
v_ebeln = t_account-ebeln.
v_ebelp = t_account-po_item.
ELSEIF v_ebeln = t_account-ebeln AND
v_ebelp <> t_account-po_item.
CLEAR v_netwr.
SELECT SINGLE netwr FROM ekpo INTO v_netwr
WHERE ebeln = t_account-ebeln
AND ebelp = t_account-po_item.
t_amount-netwr = v_netwr.
v_ebeln = t_account-ebeln.
v_ebelp = t_account-po_item.
elseif v_netwr is initial or t_amount-netwr is initial.
CLEAR v_netwr.
SELECT SINGLE netwr FROM ekpo INTO v_netwr
WHERE ebeln = t_account-ebeln
AND ebelp = t_account-po_item.
t_amount-netwr = v_netwr.
v_ebeln = t_account-ebeln.
v_ebelp = t_account-po_item.
ENDIF.
2006 Feb 28 1:35 AM
Hi,
I guess you have not posted complete code.
First question - why don't you use Control Break statements instead of ON CHANGE.
Second question - for second loop (T_POHISTORY), already you are having condition of po item and po no, then why do you have ON CHANGE again?
2006 Feb 28 1:35 AM
Hi,
I guess you have not posted complete code.
First question - why don't you use Control Break statements instead of ON CHANGE.
Second question - for second loop (T_POHISTORY), already you are having condition of po item and po no, then why do you have ON CHANGE again?
2006 Feb 28 1:38 AM
Hi viyalab
Does the internal table t_account have this PO's.?
did you sort the internal table?
<b>No need of ON change in the loop at t_pohistory becoz it will loop only for one ebeln and ebelp which is your where condition</b>
regards
kishore
Message was edited by: Harikishore Sreenivasulu
2006 Feb 28 1:52 AM
Hi
You should NOT use Control Breaks inside a LOOP that is opened with a WHERE clause. It will not give you the correct results. You will have to change the second loop in your code.
Regards,
Suresh Datti
2006 Feb 28 1:56 AM
Yes, I have sorted t_account and t_pohistory by ebeln. I have pasted again the code. Hope you could help me guys. Again, the problem is for example I put in PO number
450000027 up to 450000051 in the selection screen only 450000029 up to 450000051 is shown but the PO amount of 450000050 and 450000051 is not shown .
FORM process_with_budat.
DELETE t_pohistory WHERE hist_type <> 'A'
AND hist_type <> 'E'
AND hist_type <> 'Q'.
sort t_account by ebeln.
sort t_pohistory by ebeln.
LOOP AT t_account.
*AVH
on change of t_account-ebeln.
CLEAR v_netwr.
SELECT SINGLE netwr FROM ekpo INTO v_netwr
WHERE ebeln = t_account-ebeln
AND ebelp = t_account-po_item.
t_amount-netwr = v_netwr.
endon.
DELETE it_dtl WHERE ebeln = t_account-ebeln
AND psphi IS initial.
DELETE t_ekpo WHERE ebeln = t_account-ebeln
AND ebelp = t_account-po_item.
DELETE t_pohistory WHERE ebeln = t_account-ebeln
AND po_item = t_account-po_item.
t_proj-ebelp = t_account-po_item.
SELECT SINGLE psphi FROM prps INTO t_proj-psphi
WHERE posid = t_account-wbs_elem_e.
CHECK sy-subrc = 0.
LOOP AT t_pohistory WHERE po_item = t_account-po_item
AND ebeln = t_account-ebeln.
t_amount-ebeln = t_account-ebeln.
t_amount-psphi = t_proj-psphi.
on change of t_account-ebeln.
CLEAR v_netwr.
SELECT SINGLE netwr FROM ekpo INTO v_netwr
WHERE ebeln = t_account-ebeln
AND ebelp = t_account-po_item.
t_amount-netwr = v_netwr.
ENDON.
ON CHANGE OF t_pohistory-po_item.
CLEAR v_netwr.
SELECT SINGLE netwr FROM ekpo INTO v_netwr
WHERE ebeln = t_account-ebeln
AND ebelp = t_account-po_item.
t_amount-netwr = v_netwr.
ENDON.
IF v_ebeln IS INITIAL AND v_ebelp IS INITIAL.
CLEAR v_netwr.
SELECT SINGLE netwr FROM ekpo INTO v_netwr
WHERE ebeln = t_account-ebeln
AND ebelp = t_account-po_item.
t_amount-netwr = v_netwr.
v_ebeln = t_account-ebeln.
v_ebelp = t_account-po_item.
ELSEIF v_ebeln <> t_account-ebeln AND
v_ebelp <> t_account-po_item.
CLEAR v_netwr.
SELECT SINGLE netwr FROM ekpo INTO v_netwr
WHERE ebeln = t_account-ebeln
AND ebelp = t_account-po_item.
t_amount-netwr = v_netwr.
v_ebeln = t_account-ebeln.
v_ebelp = t_account-po_item.
ELSEIF v_ebeln = t_account-ebeln AND
v_ebelp <> t_account-po_item.
CLEAR v_netwr.
SELECT SINGLE netwr FROM ekpo INTO v_netwr
WHERE ebeln = t_account-ebeln
AND ebelp = t_account-po_item.
t_amount-netwr = v_netwr.
v_ebeln = t_account-ebeln.
v_ebelp = t_account-po_item.
ENDIF.
CHECK NOT t_amount-psphi IS INITIAL.
if t_pohistory-pstng_date LE pa_augdt.
IF t_pohistory-pstng_date IN so_augdt.
IF t_pohistory-db_cr_ind = 'H'.
t_pohistory-val_loccur = - t_pohistory-val_loccur.
t_pohistory-val_forcur = - t_pohistory-val_forcur.
t_pohistory-cl_val_loc = - t_pohistory-cl_val_loc.
ENDIF.
IF t_pohistory-hist_type = 'A'.
IF t_pohistory-currency <> 'PHP'.
t_amount-dpamt = t_amount-dpamt + t_pohistory-val_forcur.
ELSE.
t_amount-dpamt = t_amount-dpamt + t_pohistory-val_loccur.
ENDIF.
ELSEIF t_pohistory-hist_type = 'E'.
IF t_pohistory-currency <> 'PHP'.
t_amount-gramt = t_amount-gramt + t_pohistory-val_forcur.
ELSE.
t_amount-gramt = t_amount-gramt + t_pohistory-val_loccur.
ENDIF.
ELSEIF t_pohistory-hist_type = 'Q'.
IF t_pohistory-currency <> 'PHP'.
t_amount-iramt = t_amount-iramt + t_pohistory-val_forcur.
ELSE.
t_amount-iramt = t_amount-iramt + t_pohistory-val_loccur.
ENDIF.
ENDIF.
IF t_pohistory-currency <> 'PHP'.
IF t_pohistory-val_loccur = 0 OR
t_pohistory-val_forcur = 0.
t_amount-tramt = t_amount-iramt.
t_amount-tramt = t_amount-dpamt.
ELSE.
t_amount-tramt = t_amount-iramt.
t_amount-tramt = ( t_pohistory-cl_val_loc /
( t_pohistory-val_loccur /
t_pohistory-val_forcur ) ) +
t_amount-dpamt.
ENDIF.
ELSE.
t_amount-tramt = t_amount-iramt.
t_amount-tramt = t_pohistory-cl_val_loc + t_amount-dpamt.
ENDIF.
IF NOT t_pohistory-cl_val_loc IS INITIAL.
CONCATENATE t_pohistory-mat_doc t_pohistory-doc_year
INTO bkpf-awkey.
SELECT SINGLE * FROM bkpf
WHERE awkey = bkpf-awkey.
*AVH - removed wrbtr and dmbtr from selection
SELECT augdt augbl shkzg FROM bsak
INTO (bsak-augdt,bsak-augbl,bsak-shkzg)
WHERE bukrs = bkpf-bukrs
AND gjahr = bkpf-gjahr
AND belnr = bkpf-belnr.
*AVH
if not bsak-augbl is initial.
select belnr gjahr from bsak
into (bsak-belnr, bsak-gjahr)
where bukrs = bkpf-bukrs
and belnr = bkpf-belnr
and gjahr = bkpf-gjahr.
select awkey from bkpf
into v_bkpf_aw
where bukrs = 'GLOB'
and belnr = bsak-belnr
and gjahr = bsak-gjahr.
w_len = strlen( v_bkpf_aw ).
w_off = w_len - 4.
v_awkey_1 = v_bkpf_aw+0(10).
v_awkey_2 = v_bkpf_aw+w_off(4).
select single dmbtr wrbtr from ekbe
into (ekbe-dmbtr, ekbe-wrbtr)
where belnr = v_awkey_1
and gjahr = v_awkey_2.
*AVH - Changed all bsak-wrbtr to ekbe-wrbtr and dmbtr to ekbe-dmbtr.
IF bsak-shkzg = 'H'.
ekbe-dmbtr = - ekbe-dmbtr.
ekbe-wrbtr = - ekbe-wrbtr.
ENDIF.
IF t_pohistory-currency <> 'PHP'.
IF bsak-augdt GT pa_augdt.
IF bsak-augdt IN so_augdt.
t_amount-tramt = t_amount-tramt + ekbe-wrbtr.
ENDIF.
ELSE.
IF bsak-augdt GT pa_augdt.
IF bsak-augdt IN so_augdt.
t_amount-tramt = t_amount-tramt + ekbe-dmbtr.
ENDIF.
ENDIF.
endselect.
endselect.
endselect.
endif.
ENDSELECT.
ENDIF.
IF t_account-distr_perc <> 0.
t_amount-dpamt = ( t_account-distr_perc *
t_amount-dpamt ) / 100.
t_amount-gramt = ( t_account-distr_perc *
t_amount-gramt ) / 100.
t_amount-iramt = ( t_account-distr_perc *
t_amount-iramt ) / 100.
t_amount-tramt = ( t_account-distr_perc *
t_amount-tramt ) / 100.
ENDIF.
ENDIF.
IF t_amount-tramt < 0.
t_amount-tramt = 0.
ENDIF.
t_amount-tramt = t_amount-iramt.
t_amount-blamt = t_amount-netwr - t_amount-tramt.
COLLECT t_amount. CLEAR t_amount.
APPEND t_proj.
ENDLOOP.
IF sy-subrc <> 0.
CLEAR v_netwr.
SELECT SINGLE netwr FROM ekpo INTO v_netwr
WHERE ebeln = t_account-ebeln
AND ebelp = t_account-po_item.
t_amount-ebeln = t_account-ebeln.
t_amount-psphi = t_proj-psphi.
t_amount-tramt = t_amount-iramt.
t_amount-blamt = t_amount-netwr - t_amount-tramt.
COLLECT t_amount. CLEAR t_amount.
APPEND t_proj.
ENDIF.
ENDLOOP.
*part 2
CHECK NOT t_ekpo[] IS INITIAL.
LOOP AT t_ekpo.
LOOP AT t_pohistory WHERE po_item = t_ekpo-ebelp
AND ebeln = t_ekpo-ebeln.
t_amount-ebeln = t_ekpo-ebeln.
ON CHANGE OF t_pohistory-po_item.
CLEAR v_netwr.
SELECT SINGLE netwr FROM ekpo INTO v_netwr
WHERE ebeln = t_ekpo-ebeln
AND ebelp = t_ekpo-ebelp.
t_amount-netwr = v_netwr.
ENDON.
IF t_pohistory-pstng_date LE pa_augdt.
IF t_pohistory-pstng_date IN so_augdt.
IF t_pohistory-db_cr_ind = 'H'.
t_pohistory-val_loccur = - t_pohistory-val_loccur.
t_pohistory-val_forcur = - t_pohistory-val_forcur.
t_pohistory-cl_val_loc = - t_pohistory-cl_val_loc.
ENDIF.
IF t_pohistory-hist_type = 'A'.
IF t_pohistory-currency <> 'PHP'.
t_amount-dpamt = t_amount-dpamt + t_pohistory-val_forcur.
ELSE.
t_amount-dpamt = t_amount-dpamt + t_pohistory-val_loccur.
ENDIF.
ELSEIF t_pohistory-hist_type = 'E'.
IF t_pohistory-currency <> 'PHP'.
t_amount-gramt = t_amount-gramt + t_pohistory-val_forcur.
ELSE.
t_amount-gramt = t_amount-gramt + t_pohistory-val_loccur.
ENDIF.
ELSEIF t_pohistory-hist_type = 'Q'.
IF t_pohistory-currency <> 'PHP'.
t_amount-iramt = t_amount-iramt + t_pohistory-val_forcur.
ELSE.
t_amount-iramt = t_amount-iramt + t_pohistory-val_loccur.
ENDIF.
ENDIF.
IF t_pohistory-currency <> 'PHP'.
IF t_pohistory-val_loccur = 0 OR
t_pohistory-val_forcur = 0.
t_amount-tramt = t_amount-iramt.
t_amount-tramt = t_amount-dpamt.
ELSE.
t_amount-tramt = t_amount-iramt.
t_amount-tramt = ( t_pohistory-cl_val_loc /
( t_pohistory-val_loccur /
t_pohistory-val_forcur ) ) +
t_amount-dpamt.
ENDIF.
ELSE.
t_amount-tramt = t_amount-iramt.
t_amount-tramt = t_pohistory-cl_val_loc + t_amount-dpamt.
ENDIF.
IF NOT t_pohistory-cl_val_loc IS INITIAL.
CONCATENATE t_pohistory-mat_doc t_pohistory-doc_year
INTO bkpf-awkey.
SELECT SINGLE * FROM bkpf
WHERE awkey = bkpf-awkey.
SELECT augdt augbl shkzg FROM bsak
INTO (bsak-augdt,bsak-augbl,bsak-shkzg)
WHERE bukrs = bkpf-bukrs
AND gjahr = bkpf-gjahr
AND belnr = bkpf-belnr.
*AVH - removed wrbtr from selection/start of insertion
if not bsak-augbl is initial.
select belnr gjahr from bsak
into (bsak-belnr, bsak-gjahr)
where bukrs = bkpf-bukrs
and belnr = bkpf-belnr
and gjahr = bkpf-gjahr.
select awkey from bkpf
into v_bkpf_aw
where bukrs = 'GLOB'
and belnr = bsak-belnr
and gjahr = bsak-gjahr.
w_len = strlen( v_bkpf_aw ).
w_off = w_len - 4.
v_awkey_1 = v_bkpf_aw+0(10).
v_awkey_2 = v_bkpf_aw+w_off(4).
select dmbtr wrbtr from ekbe
into (ekbe-dmbtr, ekbe-wrbtr)
where belnr = v_awkey_1
and gjahr = v_awkey_2.
*AVH - Changed all bsak-wrbtr to ekbe-wrbtr and dmbtr to ekbe-dmbtr.
IF bsak-shkzg = 'H'.
bsak-dmbtr = - ekbe-dmbtr. "bsak
ekbe-wrbtr = - ekbe-wrbtr. "bsak
ENDIF.
IF t_pohistory-currency <> 'PHP'.
IF bsak-augdt GT pa_augdt.
IF bsak-augdt IN so_augdt.
t_amount-tramt = t_amount-tramt + ekbe-wrbtr. "bsak
ENDIF.
ELSE.
IF bsak-augdt GT pa_augdt.
IF bsak-augdt IN so_augdt.
t_amount-tramt = t_amount-tramt + ekbe-dmbtr. "bsak
ENDIF.
ENDIF.
ENDSELECT.
endselect.
endselect.
endselect.
endif.
endselect.
ENDIF.
ENDIF.
IF t_amount-tramt < 0.
t_amount-tramt = 0.
ENDIF.
t_amount-tramt = t_amount-iramt.
t_amount-blamt = t_amount-netwr - t_amount-tramt.
COLLECT t_amount. CLEAR t_amount.
ENDLOOP.
IF sy-subrc <> 0.
CLEAR v_netwr.
SELECT SINGLE netwr FROM ekpo INTO v_netwr
WHERE ebeln = t_ekpo-ebeln
AND ebelp = t_ekpo-ebelp.
t_amount-ebeln = t_ekpo-ebeln.
t_amount-netwr = v_netwr.
t_amount-blamt = t_amount-netwr - t_amount-tramt.
COLLECT t_amount. CLEAR t_amount.
ENDIF.
ENDLOOP.
ENDFORM. " process_with_budat
2006 Feb 28 2:11 AM
Hi,
In intial block you are already populating V_NETWR, then why this repeats again?
on change of t_account-ebeln.
CLEAR v_netwr.
SELECT SINGLE netwr FROM ekpo INTO v_netwr
WHERE ebeln = t_account-ebeln
AND ebelp = t_account-po_item.
t_amount-netwr = v_netwr.
ENDON.
ON CHANGE OF t_pohistory-po_item.
CLEAR v_netwr.
SELECT SINGLE netwr FROM ekpo INTO v_netwr
WHERE ebeln = t_account-ebeln
AND ebelp = t_account-po_item.
t_amount-netwr = v_netwr.
ENDON.
You are getting data from BSAK based upon BKPF but this select is commented so the data will not get populated correctly.
Also avoid usage of SELECT - ENDSELECT. This will affect the performance.
Try first analysing this code and then start replacing it with simple ABAP code.