Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

how to Sum in a SAP Query

Former Member
0 Kudos

Folks,

I have given up....Really need some advice....

I need a report example: Order Number, Order Type, Order Date, Customer number, Net Price, Total order cost

I can get all I need from file VBAK, EXCEPT total order cost, which is at the line level (VBAP). Now I need to show one line per order and sum the cost field (VBAP/WAVWR)...

How can I accomplish this in SAP Query? IS this even possible?

3 REPLIES 3

Former Member
0 Kudos

Hi

For each order the query'll show as many rows as many items, so I believe you need to do a little program.

Max

Former Member
0 Kudos

Hi,

I am sure about SAP Query...

But check this program which might satisfy your requirement..

  • Declarations.

TYPE-POOLS: slis.

DATA: BEGIN OF wa_data,

vbeln LIKE vbak-vbeln,

auart LIKE vbak-auart,

audat LIKE vbak-audat,

kunnr LIKE vbak-kunnr,

netwr LIKE vbak-netwr,

wavwr LIKE vbap-wavwr,

waerk LIKE vbak-waerk,

posnr LIKE vbap-posnr,

END OF wa_data.

DATA: itab LIKE wa_data OCCURS 0 WITH HEADER LINE.

DATA: itab_final LIKE wa_data OCCURS 0 WITH HEADER LINE.

DATA: v_tabix TYPE sytabix.

DATA: t_fieldcat TYPE slis_t_fieldcat_alv.

  • Selection-screen.

PARAMETERS: p_erdat LIKE vbak-erdat OBLIGATORY.

START-OF-SELECTION.

  • Get the data

SELECT avbeln aauart

aaudat akunnr

anetwr bwavwr

awaerk bposnr

INTO TABLE itab

FROM vbak AS a INNER JOIN vbap AS b

ON avbeln = bvbeln

WHERE a~erdat = p_erdat.

IF sy-subrc <> 0.

MESSAGE s208(00) WITH 'No data found'.

LEAVE LIST-PROCESSING.

ENDIF.

SORT itab BY vbeln.

  • Sum the cost.

LOOP AT itab.

  • Store the tabix.

v_tabix = sy-tabix.

wa_data = itab.

AT END OF vbeln.

SUM.

  • modify the cost.

MOVE wa_data TO itab_final.

MOVE itab-wavwr TO itab_final-wavwr.

APPEND itab_final.

CLEAR itab_final.

ENDAT.

ENDLOOP.

  • SHow the report.

DATA: v_repid TYPE syrepid.

v_repid = sy-repid.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = v_repid

i_internal_tabname = 'WA_DATA'

i_inclname = v_repid

CHANGING

ct_fieldcat = t_fieldcat.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

i_callback_program = v_repid

it_fieldcat = t_fieldcat

TABLES

t_outtab = itab_final.

Thanks,

Naren

0 Kudos

I am not an ABAP developer/programmer, therefore cannot write the abap code as I don’t have access to the workbench. Is there another way to accomplish this?