01-09-2008 11:46 PM
Hi all,
I have got a requirement where I need to prepare report, the report should look out for the document number in BKPF and then display the detail of that document number such as Gross amount, Net amount from other FI table.
So basically if a document has multiple line items then we need to add up all those line items.
My scenario is like this:
doc # item# Gross amount Net amount
123 1 12 10
123 2 12 9
123 3 13 11
124 1 15 13
So the output should be:
doc # Gross amount Net amount
123 37 30
124 15 13
So can you please tell me how to care of this.
Thanks,
Rajeev!!!!!!
01-10-2008 12:13 AM
hi,
try this code
*doc_tab1 is doc # item# gross amount net amount .
*doc_tab2 is doc # gross amount net amount
>FIELD-SYMBOLS <fs_doc> LIKE doc_tab2.
>LOOP AT doc_tab1.
> READ TABLE doc_tab2 ASSIGNING <fs_doc> WITH KEY doc = doc_tab1-doc.
> IF sy-subrc = 0.
> ADD doc_tab1-gross TO <fs_doc>-gross.
> ADD doc_tab1-net TO <fs_doc>-net.
> ELSE.
> MOVE doc_tab1-doc TO doc_tab2-doc.
> MOVE doc_tab1-gross TO doc_tab2-gross.
> MOVE doc_tab1-net TO doc_tab2-net.
> APPEND doc_tab2.
> CLEAR doc_tab2.
> ENDIF.
>ENDLOOP.
bye
Marco
01-10-2008 12:11 AM
Hi Rajeev,
Use COLLECT statement instead of APPEND to internal table.
or use Control break statements.
Like,
data: w_gr_amt like Gross amount,
w_nt_amt like Net amount.
loop at itab into wa_itab.
w_gr_amt = w_gr_amt + wa_itab-gross_amount.
w_nt_amt = w_nt_amt + wa_itab_net_Amount.
at end of doc #.
append doc# w_gr_amt w_nt_amt to another itab.
clear w_gr_amt w_nt_amt.
endloop.
It should work. if not only slight changes needed. Best way is using collect key word.
Regards,
Amal
01-10-2008 12:13 AM
hi,
try this code
*doc_tab1 is doc # item# gross amount net amount .
*doc_tab2 is doc # gross amount net amount
>FIELD-SYMBOLS <fs_doc> LIKE doc_tab2.
>LOOP AT doc_tab1.
> READ TABLE doc_tab2 ASSIGNING <fs_doc> WITH KEY doc = doc_tab1-doc.
> IF sy-subrc = 0.
> ADD doc_tab1-gross TO <fs_doc>-gross.
> ADD doc_tab1-net TO <fs_doc>-net.
> ELSE.
> MOVE doc_tab1-doc TO doc_tab2-doc.
> MOVE doc_tab1-gross TO doc_tab2-gross.
> MOVE doc_tab1-net TO doc_tab2-net.
> APPEND doc_tab2.
> CLEAR doc_tab2.
> ENDIF.
>ENDLOOP.
bye
Marco
01-10-2008 12:22 AM
Hi Marco,
Thanks for the reply, I don't want to use Field Symbol.
Will the following code work?
Loop at tab01.
read table tab02 with key doc eq tab01-doc.
if sy-subrc eq 0.
Add tab01-gross to v_gross.
Add tab01-net to v_net.
else.
move tab01-doc to tab02-doc.
move tab01-gross to tab02-gross.
move tab01-net to tab02-net.
append tab02.
clear tab02.
endif.
endloop.
and I have one more doubt How can I get the required data from BKPF and BSEG into the internal tables.
Thanks,
Rajeev !!!!
01-10-2008 12:39 AM
Rajeev,
As u r looping itab and appending for 2nd itab, u can use the pesudo code which i mention above.
And ur reading itab using doc# only . so u will get the same record. Obviously first record for that doc #.
Regards,
Amal
Edited by: Amal on Jan 10, 2008 12:39 AM
01-10-2008 12:48 AM
Thanks for the reply Amal....I got this point !!!
But now the only concern is I need to get the document number from table BKPF and then I have to look out for the line items for that document #, So I am not sure from which table I can get that information and also how can I retrieve the data from the table into my internal table.!!!
I really appreciate your help and will defintly reward you with you points!!!
Thanks,
Rajeev !!!!
01-10-2008 1:09 AM
U can get item details from BSEG. By using BUKRS, BELNR and GJAHR fields in where condition to link with BKPF.
just inside that loop use select to get records from BSEG and append all the records to another itab.
Regards,
Amal