‎2011 Sep 08 5:35 AM
hi to all,
to the moderators : please try to do this and then take necessary action
such as moving to points free zone
i already posted this code but did not get the reply, So posting as new thread again.
in the below code if i enter the input parameters as
Fiscal Year : 2011
Posting Period :3
G/L Account : some number
Cost Center :28
then i am getting the exact output
where as if i enter
Fiscal Year : 2010
Posting Period :3
G/L Account : some number
Cost Center :28
then i am getting the output regardless of Posting Period i.e it is taking all 12 months (1-12)
REPORT ZTEMP1 no standard page heading.
types: begin of ty_bseg,
gjahr type gjahr, "fysical year
hkont type hkont, "gl account
KOSTL type KOSTL, "cost center
AUFNR type AUFNR, "order type
BUKRS TYPE BUKRS,
PSWBT TYPE PSWBT, "General ledger amount
WRBTR type WRBTR,
end of ty_bseg.
TYPES: BEGIN OF TY_BKPF,
GJAHR TYPE GJAHR,
MONAT TYPE MONAT,
BUKRS TYPE BUKRS,
BUDAT TYPE BUDAT,
END OF TY_BKPF.
DATA: IT_BSEG TYPE TABLE OF TY_BSEG,
WA_BSEG TYPE TY_BSEG,
IT_BKPF TYPE TABLE OF TY_BKPF,
WA_BKPF TYPE TY_BKPF.
PARAMETERS: S_GJAHR TYPE ty_bseg-gjahr default sy-datum+0(4).
PARAMETERS: S_MONAT type ty_BKPF-MONAT default sy-datum+4(2).
SELECT-OPTIONS: S_HKONT FOR WA_BSEG-HKONT obligatory .
SELECT-OPTIONS: s_kostl for wa_bseg-kostl .
START-OF-SELECTION.
perform actual.
perform pri_actual.
CLEAR WA_BSEG.
REFRESH IT_BSEG.
skip 3.
*&---------------------------------------------------------------------*
*& Form ACTUAL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM ACTUAL .
SELECT gjahr
hkont
KOSTL
AUFNR
BUKRS
PSWBT
WRBTR FROM BSEG
INTO TABLE IT_BSEG
WHERE GJAHR EQ S_GJAHR
AND HKONT IN S_HKONT
and kostl in s_kostl.
IF NOT it_bseg[] IS INITIAL.
SELECT GJAHR
MONAT
BUKRS
BUDAT FROM BKPF
INTO TABLE IT_BKPF
FOR ALL ENTRIES IN IT_BSEG
WHERE MONAT eq s_monat
AND GJAHR = it_BSEG-GJAHR
AND BUKRS = it_BSEG-BUKRS.
else.
message 'No data available for given inputs' type 'E'.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form PRI_ACTUAL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM PRI_ACTUAL .
sort it_bseg by kostl aufnr.
LOOP AT IT_BSEG INTO WA_BSEG.
at new hkont. " gl account number
write:1 sy-uline(58),
/1 sy-vline(1),
2 wa_bseg-HKONT COLOR 3.
endat.
at end of aufnr. "order type
sum.
write:58 sy-vline(1).
write:/1 sy-uline(58),
/1 sy-vline(1),
2 wa_bseg-aufnr color 1,
10 wa_bseg-pswbt,
58 sy-vline(1).
endat.
at end of kostl. "cost center
write:/1 sy-uline(58),
/1 sy-vline(1),
2 wa_bseg-kostl,
58 sy-vline(1).
endat.
at end of kostl.
sum.
write:25 wa_bseg-pswbt.
write:/1 sy-uline(58).
endat.
endloop.
clear wa_bseg.
ENDFORM. " PRI_ACTUAL
So kindly pelase suggest me .
thanks in advance,
ben2012.
Moderator message : Duplicate post locked. Continue with Original thread : [SELECT STATEMENT NOT WORKING|]
Edited by: Vinod Kumar on Sep 8, 2011 10:24 AM
‎2011 Sep 08 5:46 AM
Hi,
this code looks strange:
sort it_bseg by kostl aufnr.
LOOP AT IT_BSEG INTO WA_BSEG.
at new hkont. " gl account number
Shouldn't IT_BSEG be sorted by HKONT KOSTL AUFNR ?
AT NEW HKONT for an unsorted HKONT may lead to strange results!
Regards,
Klaus
‎2011 Sep 08 5:52 AM
Hi,
2 ways your Problem will resolve
1) First you have to get the data from BKPF table and proceed the BSEG table. Your looping only BSEG internal table.
Suppose you giving the input like below
Fiscal Year : 2010
Posting Period :3
G/L Account : some number
Cost Center :28
you first getting record in BSEG table so all data for Posting Period i.e it is taking all 12 months (1-12) will fetch.
So best way to write the code first you get the data from BKPF table and proceed the BSEG table.
2)
in your loop check the BKPF internal table like
sort it_bseg by kostl aufnr.
sort it_bkpf by BUKRS BELNR GJAHR.
LOOP AT IT_BSEG INTO WA_BSEG.
Read table it_bkpf into wa_bkpf with key BUKRS = wa_bseg-bukrs
BELNR = wa_bseg-belnr
GJAHR = = wa_bseg-gjahr Binary search.
If sy-subrc EQ 0.
"Proceed your code
Endif.
Endloop.
Regards,
Dhina..