Skip to Content
Former Member

Report !!!!

Hi gurus,

I have a problem !!!!

I am working on a report...where I need to get the document number from table BKPF and then I need to get the line item data from table BSEG such as gross amount and Net amount, then I need to sum up the gross amount and net amount of one header and need to display it. ...

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 yoy please tell me how can I take care of this....

Any help will really be appreciated !!!! actually I am trying to learn!!!

Thanks,

Rajeev !!!!

Add a comment
10|10000 characters needed characters exceeded

5 Answers

• Best Answer
Former Member
Posted on Jan 10, 2008 at 03:26 AM

Hi Rajeev,

Have you written some code.

If you are stuck up at some place then let us know so that we can help you.

Regards,

Atish

Add a comment
10|10000 characters needed characters exceeded
• Former Member Former Member

Hi Rajeev,

I guess following code wouuld help you.

1.select from the reuired tables.

2. sort on keys which in this case would be document nuber.

3.Loop at tab1.

Loop at tab2 where docnum = tab1-docnum.

do the calculation.

endloop.

Pass on the value n document number to tab3.

append and clear .

endloop.

Display the tab3

Do eward if found useful

Regards,

Rajashree

• Former Member
Posted on Jan 10, 2008 at 04:14 AM

hi rajeev,

i will give a simple example,

data : begin of it,

f1 value 'A',

f2 value 1, u can take any values and append them

f3 value 2,

end of it.

sort it by f1.

loop at it.

at new f1.

sum.

write:/ 'total',it-f1,it-f3.

endloop.

free it.

in ur problem give some if condition so that it checks with 123 and sums up the values...

pls reward points if helpful,

shylaja

Add a comment
10|10000 characters needed characters exceeded
• Former Member

Hi guys,

I have tried and wrote the following code, can you please have a look at it and please let me know if I ned to make some changes.

&----

*& Report ZFI_PAYMENT *

*& *

&----

*& *

*& *

&----

REPORT ZFI_PAYMENT .

data : v_nebtr(15).

data: begin of it_bkpf occurs 0,

belnr like bkpf-belnr,

end of it_bkpf.

data: begin of it_bseg occurs 0,

belnr like bseg-belnr,

nebtr like bseg-nebtr,

end of it_bseg.

data : begin of it_fin occurs 0,

belnr like bseg-belnr,

nebtr like bseg-nebtr,

end of it_fin.

select belnr into table it_bkpf

from bkpf

where blart eq 'SA'.

select belnr into table it_bseg

from bseg

where belnr eq it_bkpf-belnr.

loop at it_bkpf.

read table it_bseg with key belnr = it_bkpf-belnr.

if sy-subrc eq 0.

ADD it_bseg-nebtr to v_nebtr.

else.

move it_bseg-nebtr to it_fin-nebtr.

move it_bseg-belnr to it_fin-belnr.

append it_fin.

clear it_fin.

endif.

it_bseg-nebtr = v_nebtr.

endloop.

Thanks,

Rajeev !!!

• Former Member
Posted on Jan 10, 2008 at 04:12 AM

Hi Rajeev,

I will send a sample code 4 u. ok.i only thing u did is u have to change the table name and internal table fileds according to ur requirement.I dont have enough time to develop the code ok.refer the below that is helpful to u.

code:

&----

*& Report YSALESORDER_ALV_SUBTOTALS *

*& *

&----

*& DEVELOPER : KIRAN KUMAR.G *

*& PURPOSE : DISPLAYING SUBTOTALS FOR A PARTICULAR SALES DOC NO *

*& CREATION DT: 26/11/2007 *

*& REQUEST : ERPK900035 *

&----

REPORT ysalesorder_alv_subtotals.

----

• Type Pools

----

TYPE-POOLS:slis.

----

• Tables

----

TABLES: vbak, "Sales Document: Header Data

vbap. "Sales Document: Item Data

----

• Global Structures

----

DATA:gt_fieldcat TYPE slis_t_fieldcat_alv,

wa_fieldcat TYPE slis_fieldcat_alv,

gt_sortcat TYPE slis_t_sortinfo_alv,

wa_sortcat LIKE LINE OF gt_sortcat.

----

• Internal Table

----

DATA: BEGIN OF gt_salesorder OCCURS 0,

vbeln LIKE vbak-vbeln, " Sales Document Number

posnr LIKE vbap-posnr, " Sales Doc Item

netwr LIKE vbap-netwr, " Net Value

END OF gt_salesorder.

----

• SELECT OPTIONS

----

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

SELECT-OPTIONS: s_vbeln FOR vbak-vbeln. " Sales Document Number.

SELECTION-SCREEN END OF BLOCK b1.

----

• Initialization

----

INITIALIZATION.

PERFORM initialization.

----

• Start Of Selection

----

START-OF-SELECTION.

PERFORM field_catalog. "For Structure Creation

PERFORM fetch_data. "Get the Data From DB Table

PERFORM sorting USING gt_sortcat.

----

• End Of Selection

----

END-OF-SELECTION.

PERFORM display_data.

&----

*& Form initialization

&----

• text

----

• --> p1 text

• <-- p2 text

----

FORM initialization .

s_vbeln-sign = 'I'.

s_vbeln-option = 'BT'.

s_vbeln-low = '4969'.

s_vbeln-high = '5000'.

APPEND s_vbeln.

ENDFORM. " initialization

&----

*& Form field_catalog

&----

• text

----

• --> p1 text

• <-- p2 text

----

FORM field_catalog .

REFRESH : gt_fieldcat.

CLEAR : wa_fieldcat.

wa_fieldcat-col_pos = '1'. "Column Position

wa_fieldcat-tabname = 'IT_SALESORDER'. "Internal Table

wa_fieldcat-fieldname = 'VBELN'. "Field Name

wa_fieldcat-key = 'X'. "Blue Color

wa_fieldcat-seltext_m = 'Sales Doc No'. "Display Text In Screen

APPEND wa_fieldcat TO gt_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-col_pos = '2'. "Column Position

wa_fieldcat-tabname = 'IT_SALESORDER'. "Internal Table Name

wa_fieldcat-fieldname = 'POSNR'. "Field Name

wa_fieldcat-seltext_m = 'Sales Doc Item'."Display Text In Screen

APPEND wa_fieldcat TO gt_fieldcat.

CLEAR wa_fieldcat.

*SubTotal on the Field NETWR

wa_fieldcat-col_pos = '3'. "Column Position

wa_fieldcat-tabname = 'IT_SALESORDER'. "Internal Table

wa_fieldcat-fieldname = 'NETWR'. "Field Name

wa_fieldcat-do_sum = 'X'. "Sum

wa_fieldcat-seltext_m = 'Net Value'. "Display Text In Screen

APPEND wa_fieldcat TO gt_fieldcat.

CLEAR wa_fieldcat.

ENDFORM. " field_catalog

&----

*& Form sorting

&----

• text

----

• -->P_IT_SORTCAT text

----

FORM sorting USING p_it_sortcat TYPE slis_t_sortinfo_alv.

CLEAR wa_sortcat.

wa_sortcat-fieldname = 'VBELN'.

wa_sortcat-up ='X'.

wa_sortcat-subtot = 'X'.

APPEND wa_sortcat TO p_it_sortcat.

ENDFORM. " sorting

&----

*& Form display_data

&----

• text

----

• --> p1 text

• <-- p2 text

----

FORM display_data .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

• I_INTERFACE_CHECK = ' '

• I_BYPASSING_BUFFER = ' '

• I_BUFFER_ACTIVE = ' '

i_callback_program = sy-repid

• I_CALLBACK_PF_STATUS_SET = ' '

• I_CALLBACK_USER_COMMAND = ' '

• I_CALLBACK_TOP_OF_PAGE = ' '

• I_CALLBACK_HTML_TOP_OF_PAGE = ' '

• I_CALLBACK_HTML_END_OF_LIST = ' '

• I_STRUCTURE_NAME =

• I_BACKGROUND_ID = ' '

• I_GRID_TITLE =

• I_GRID_SETTINGS =

• IS_LAYOUT =

it_fieldcat = gt_fieldcat

• IT_EXCLUDING =

• IT_SPECIAL_GROUPS =

it_sort = gt_sortcat

• IT_FILTER =

• IS_SEL_HIDE =

• I_DEFAULT = 'X'

• I_SAVE = ' '

• IS_VARIANT =

• IT_EVENTS =

• IT_EVENT_EXIT =

• IS_PRINT =

• IS_REPREP_ID =

• I_SCREEN_START_COLUMN = 0

• I_SCREEN_START_LINE = 0

• I_SCREEN_END_COLUMN = 0

• I_SCREEN_END_LINE = 0

• IT_ALV_GRAPHICS =

• IT_HYPERLINK =

• IT_ADD_FIELDCAT =

• IT_EXCEPT_QINFO =

• I_HTML_HEIGHT_TOP =

• I_HTML_HEIGHT_END =

• IMPORTING

• E_EXIT_CAUSED_BY_CALLER =

• ES_EXIT_CAUSED_BY_USER =

TABLES

t_outtab = gt_salesorder

EXCEPTIONS

program_error = 1

OTHERS = 2.

IF sy-subrc <> 0.

• MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

• WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " display_data

&----

*& Form fetch_data

&----

• text

----

• --> p1 text

• <-- p2 text

----

FORM fetch_data .

REFRESH : gt_salesorder.

CLEAR : gt_salesorder.

SELECT a~vbeln

posnr

b~netwr

FROM vbak AS a

INNER JOIN vbap AS b ON avbeln = bvbeln

INTO TABLE gt_salesorder

WHERE a~vbeln IN s_vbeln.

ENDFORM. " fetch_data

Award points if helpful.

Kiran Kumar.G.A

Have a Nice Day..

Add a comment
10|10000 characters needed characters exceeded
• Former Member
Posted on Jan 10, 2008 at 04:19 AM

Hi,

Can you tell me on which BSEG field u r calculating gross amount?

Add a comment
10|10000 characters needed characters exceeded
• Former Member
Posted on Jan 10, 2008 at 04:31 AM

Hi Rajeev,

Try this program !!!! Try to make it as per ur reqmnt ðŸ˜Š

TYPES: BEGIN OF company,

name(20) TYPE c,

sales TYPE i,

END OF company.

DATA: comp TYPE STANDARD TABLE OF company,

comptab TYPE HASHED TABLE OF company

WITH UNIQUE KEY name,

wa_comptab TYPE company,

wa_comp TYPE company.

wa_comp-name = '123'.

wa_comp-sales = 10.

APPEND wa_comp TO comp.

CLEAR wa_comp.

wa_comp-name = '321'.

wa_comp-sales = 20.

APPEND wa_comp TO comp.

CLEAR wa_comp.

wa_comp-name = '621'.

wa_comp-sales = 20.

APPEND wa_comp TO comp.

CLEAR wa_comp.

wa_comp-name = '123'.

wa_comp-sales = 30.

APPEND wa_comp TO comp.

CLEAR wa_comp.

wa_comp-name = '621'.

wa_comp-sales = 1.

APPEND wa_comp TO comp.

CLEAR wa_comp.

LOOP AT comp INTO wa_comptab.

COLLECT wa_comptab INTO comptab.

ENDLOOP.

LOOP AT comptab INTO wa_comptab.

WRITE:/ wa_comptab-name , wa_comptab-sales.

CLEAR: wa_comptab.

ENDLOOP.

regards

Avi..........

Add a comment
10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.