2013 Jul 30 12:14 PM
Hi all,
I am developing a report for Bank Deposit. I have a following selection screen
SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME TITLE text-001.
PARAMETERS: p_cocd TYPE febko-bukrs OBLIGATORY.
SELECT-OPTIONS: s_hbkid FOR febko-hbkid,
s_hktid FOR febko-hktid,
s_emkey FOR febko-emkey OBLIGATORY,
s_euser FOR febko-euser OBLIGATORY,
s_azdat FOR febko-azdat OBLIGATORY.
SELECTION-SCREEN END OF BLOCK a.
and following data i am fetching from BKPF, FEBKO, FEBEP and FEBCL
SELECT bukrs
bktxt
budat
usnam
FROM bkpf INTO CORRESPONDING FIELDS OF TABLE it_bkpf
WHERE bukrs = p_cocd.
SORT it_bkpf BY bukrs.
DELETE ADJACENT DUPLICATES FROM it_bkpf COMPARING bktxt.
SELECT anwnd
kukey
emkey
azdat
bukrs
hbkid
hktid
euser
edate
FROM febko INTO CORRESPONDING FIELDS OF TABLE it_febko
FOR ALL ENTRIES IN it_bkpf
WHERE ( bukrs = it_bkpf-bukrs
AND anwnd = '0002'
AND emkey IN s_emkey
AND euser IN s_euser
AND azdat IN s_azdat )
AND ( hbkid IN s_hbkid
OR hktid IN s_hktid ).
IF it_febko[] IS NOT INITIAL.
SORT it_febko BY kukey.
DELETE ADJACENT DUPLICATES FROM it_febko COMPARING kukey.
SELECT kukey
esnum
budat
gsber
prctr
chect
gjahr
valut
vgman
kwbtr
nbbln
FROM febep INTO CORRESPONDING FIELDS OF TABLE it_febep
FOR ALL ENTRIES IN it_febko
WHERE kukey = it_febko-kukey.
ENDIF.
SORT it_febep BY kukey.
DELETE ADJACENT DUPLICATES FROM it_febep COMPARING kukey.
SELECT kukey
esnum
koart
agkon
FROM febcl INTO CORRESPONDING FIELDS OF TABLE it_febcl
FOR ALL ENTRIES IN it_febep
WHERE kukey = it_febep-kukey
AND koart = 'D'
AND esnum = it_febep-esnum.
Following is the loop...
DATA lv_text(25).
LOOP AT it_febko INTO wa_febko.
wa_final-emkey = wa_febko-emkey.
wa_final-azdat = wa_febko-azdat.
wa_final-bukrs = wa_febko-bukrs.
wa_final-hbkid = wa_febko-hbkid.
wa_final-hktid = wa_febko-hktid.
wa_final-euser = wa_febko-euser.
SORT it_febep BY kukey.
READ TABLE it_febep INTO wa_febep WITH KEY kukey = wa_febko-kukey BINARY SEARCH.
IF sy-subrc EQ 0.
wa_final-budat = wa_febep-budat.
wa_final-valut = wa_febep-valut.
wa_final-kwbtr = wa_febep-kwbtr.
wa_final-vgman = wa_febep-vgman.
wa_final-gsber = wa_febep-gsber.
wa_final-prctr = wa_febep-prctr.
wa_final-chect = wa_febep-chect.
CONCATENATE wa_febep-kukey wa_febep-esnum INTO lv_text.
SELECT SINGLE belnr
INTO wa_final-nbbln
FROM bkpf
WHERE bktxt = lv_text.
ENDIF.
SORT it_bkpf BY bktxt.
READ TABLE it_bkpf INTO wa_bkpf WITH KEY bktxt = lv_text BINARY SEARCH.
IF sy-subrc EQ 0.
wa_final-usnam = wa_bkpf-usnam.
ENDIF.
SORT it_febcl BY kukey.
READ TABLE it_febcl INTO wa_febcl WITH KEY kukey = wa_febep-kukey BINARY SEARCH.
IF sy-subrc EQ 0.
wa_final-agkon = wa_febcl-agkon.
ENDIF.
CLEAR lv_text.
APPEND wa_final TO it_final.
ENDLOOP.
My Problem is IT_FEBKO is fetching only one record even if there are 3 records for given date by user.
Any suggestion please.
Regards,
PS
2013 Jul 30 1:57 PM
Hi Everyone,
Problem solved.
" SORT it_febep BY kukey.
DELETE ADJACENT DUPLICATES FROM it_febep COMPARING kukey. "
was the flaw. Removed it for FEBEP contained line items with unique key KUKEY and i was sorting internal table by the same key when internal table contained DOC NO as well.
Thank you all for your generous help.
Regards,
PS
2013 Jul 30 12:25 PM
Purushottam,
1) Re-check the select statement conditions which fetches the data into IT_FEBKO.
Debugging helps you to understand the working of ABAP programs better. Make best use of it.
Regards.
2013 Jul 30 12:47 PM
Hi Arun,
I debugged it for almost coupe of hours it didnt work that is why i posted question here.
Thanks for your suggestion though .
Regards,
PS
2013 Jul 30 12:31 PM
Hi Purushottam,
Modify you select statement like this and debug..
SELECT anwnd
kukey
emkey
azdat
bukrs
hbkid
hktid
euser
edate
FROM febko INTO CORRESPONDING FIELDS OF TABLE it_febko
FOR ALL ENTRIES IN it_bkpf
WHERE bukrs = it_bkpf-bukrs
AND anwnd = '0002'
AND emkey IN s_emkey
AND euser IN s_euser
AND azdat IN s_azdat
AND hbkid IN s_hbkid
and hktid IN s_hktid .
2013 Jul 30 12:50 PM
Hi Ramesh,
I tried that way, it wont work. I know FEBKO is a header table and FEBEP is item table but what concerns me is even for multiple document number in BKPF it is FETCHING only one record. Select query with BKPF has some flaws.
Regards,
PS
2013 Jul 30 12:53 PM
Check Structure you declared and selected for it_bkpf
if possible all structures like that
SELECT bukrs
bktxt
budat
usnam
FROM bkpf INTO CORRESPONDING FIELDS OF TABLE it_bkpf
WHERE bukrs = p_cocd.
2013 Jul 30 12:54 PM
Hi,
Many time sequence also play important role in data fetching use all key fields after select statement OR try with * for checking purpose.
SELECT
ANWND
ABSND
AZIDT
EMKEY
kukey
azdat
bukrs
hbkid
hktid
euser
edate
Regards,
2013 Jul 30 1:00 PM
Hi,
Before using for all entries, always check if the table you are referring to has entries hence add this check before your select.
Add the brackets only if you have a condition " if this or that". Assuming that it should be HBKID OR HTKID, you can add brackets for that.
Also make the order of the fields in the Select Statement and in the where condition is the same as that in the database table. For ex: make sure ANWND comes first, KUKEY comes 2nd,etc same as the order in the database table FEBKO. Similarly ANWND should come first in the where condition...and so on. Let us know if you need any more details
IF IT_BKPF[] IS NOT INITIAL.
SELECT anwnd
kukey
emkey
azdat
bukrs
hbkid
hktid
euser
edate
FROM febko INTO CORRESPONDING FIELDS OF TABLE it_febko
FOR ALL ENTRIES IN it_bkpf
WHERE bukrs = it_bkpf-bukrs
AND anwnd = '0002'
AND emkey IN s_emkey
AND euser IN s_euser
AND azdat IN s_azdat
AND ( hbkid IN s_hbkid
OR hktid IN s_hktid ).
ENDIF.
2013 Jul 30 1:04 PM
Hi Purushottam,
Declare the interal table for FEBKO with all primary key fields from that table. This will solve your problem.
Regards,
Neelesh
2013 Jul 30 1:20 PM
hi Purushottam,
Your below query is failing
SELECT anwnd
kukey
emkey
azdat
bukrs
hbkid
hktid
euser
edate
FROM febko INTO CORRESPONDING FIELDS OF TABLE it_febko
FOR ALL ENTRIES IN it_bkpf
WHERE ( bukrs = it_bkpf-bukrs
AND anwnd = '0002'
AND emkey IN s_emkey
AND euser IN s_euser
AND azdat IN s_azdat )
AND ( hbkid IN s_hbkid
OR hktid IN s_hktid ).
I would request you to first check number of records in IT_BKPF. secondaly tally your condition in FEBKO table manually and check how many records are coming. Then fetch records from FEBKO based only on BKPF-BUKRS and ANWD as 0002. check how many records are fetched this time.
Next you filter the IT_FEBKO table based on select options (using delete ).
This process will help you understand the data that you are getting and probable flaw in code.
Please let me know if this helpw or still in doubt.
Regards,
DN.
2013 Jul 30 1:31 PM
Hi Purushottam,
Modify your select statement as below and Check.
If it_bkpf[] is not initial.
SELECT anwnd
kukey
emkey
azdat
bukrs
hbkid
hktid
euser
edate
FROM febko INTO CORRESPONDING FIELDS OF TABLE it_febko
FOR ALL ENTRIES IN it_bkpf
WHERE bukrs = it_bkpf-bukrs
AND anwnd = '0002'
AND emkey IN s_emkey
AND euser IN s_euser
AND azdat IN s_azdat
AND ( hbkid IN s_hbkid
OR hktid IN s_hktid ).
endif.
Also declare structures with required fields and use them for typing internal tables, (E.g : Don't use BKPF structure to type IT_BKPF, when you required only some of the fields from that table), So that you can avoid "corresponding fields into" statement.
2013 Jul 30 1:48 PM
Hi Purushottam,
The select query you are using does not have all keys for table FEBKO. You are using "for all entries" which will definitely not pick the duplicate entries.
Instead, use all the key fields
ANWND
ABSND
AZIDT
EMKEY
in your select query and then it should work fine.
2013 Jul 30 1:57 PM
Hi Everyone,
Problem solved.
" SORT it_febep BY kukey.
DELETE ADJACENT DUPLICATES FROM it_febep COMPARING kukey. "
was the flaw. Removed it for FEBEP contained line items with unique key KUKEY and i was sorting internal table by the same key when internal table contained DOC NO as well.
Thank you all for your generous help.
Regards,
PS