Application Development and Automation 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: 
Read only

Find sum

Former Member
0 Likes
1,427

Hi,

Have written the select query as

SELECT lifnr gjahr belnr buzei bldat zfbdt zbd1t dmbe2 shkzg

INTO TABLE gt_bsik

FROM bsik FOR ALL ENTRIES IN gt_lfb1

WHERE bukrs EQ p_bukrs

AND lifnr EQ gt_lfb1-lifnr

AND umsks EQ space

AND umskz EQ space

AND augbl EQ space

AND zfbdt LE p_nedat.

next i have to find the sum of buzei field.How to do this.Please help

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,298

Hi Hema,

You can use keyword SUM for your requirement, as explained above.

Here is an alternative approach:

DATA: w_sum type i.

w_sum = 0.

LOOP AT gt_bsik INTO wa_bsik.

w_sum = w_sum + wa_bsik-buzei.

ENDLOOP.

WRITE:/ w_sum.

Hope this will help.

Regards,

Nitin

Hi,

Have written the select query as

SELECT lifnr gjahr belnr buzei bldat zfbdt zbd1t dmbe2 shkzg

INTO TABLE gt_bsik

FROM bsik FOR ALL ENTRIES IN gt_lfb1

WHERE bukrs EQ p_bukrs

AND lifnr EQ gt_lfb1-lifnr

AND umsks EQ space

AND umskz EQ space

AND augbl EQ space

AND zfbdt LE p_nedat.

next i have to find the sum of buzei field.How to do this.Please help

8 REPLIES 8
Read only

Former Member
0 Likes
1,298

you can use control break statements.

at end of buzei.

sum.

endat.

hope this helps.

Read only

Former Member
0 Likes
1,298

Hi.

Here is s sample code. make it change according to ur need

TYPES: BEGIN OF t_for_all,
  matnr LIKE mbew-matnr,
  bwkey LIKE mbew-bwkey,
END OF t_for_all.
 
TYPES: BEGIN OF t_mbew,
  bwkey LIKE mbew-bwkey,
  matnr LIKE mbew-matnr,
  salk3 TYPE p,
END OF t_mbew.
 
DATA: it1_mbew TYPE STANDARD TABLE OF t_mbew WITH HEADER LINE,
      it2_mbew TYPE STANDARD TABLE OF t_mbew WITH HEADER LINE,
      it_for_all TYPE STANDARD TABLE OF t_for_all,
      wa_it_for_all TYPE t_for_all.
 
wa_it_for_all-matnr = '000000002001000111'.
APPEND wa_it_for_all TO it_for_all.
wa_it_for_all-matnr = '000000000000000042'.
APPEND wa_it_for_all TO it_for_all.
CLEAR: wa_it_for_all.
wa_it_for_all-bwkey = '3000'.
APPEND wa_it_for_all TO it_for_all.
 
SELECT matnr bwkey bwtar salk3 FROM mbew
  INTO CORRESPONDING FIELDS OF it1_mbew
  FOR ALL ENTRIES IN it_for_all
  WHERE matnr = it_for_all-matnr.
  COLLECT it1_mbew INTO it1_mbew. " Use Collect in this way it will solve out your problem
ENDSELECT.
 
 
SELECT bwkey bwtar salk3 FROM mbew
  INTO CORRESPONDING FIELDS OF it2_mbew
  FOR ALL ENTRIES IN it_for_all
  WHERE bwkey = it_for_all-bwkey
    AND salk3 NE '0.00'.
  COLLECT it2_mbew INTO it2_mbew. " Use Collect in this way it will solve out your problem
ENDSELECT.

U just view the select and in select view the collect statement and make it change according to ur table

Read only

Former Member
0 Likes
1,298

Hi,

Check using Aggregate functions..

SELECT lifnr gjahr belnr bldat zfbdt zbd1t dmbe2 shkzg
SUM ( buzei )
INTO TABLE gt_bsik
FROM bsik FOR ALL ENTRIES IN gt_lfb1
WHERE bukrs EQ p_bukrs
AND lifnr EQ gt_lfb1-lifnr
AND umsks EQ space
AND umskz EQ space
AND augbl EQ space
AND zfbdt LE p_nedat.

OR

Loop the gt_bsik and find the sum of buzei.

Read only

0 Likes
1,298

Hi,

I tried the aggregate function sum(buzei) but its displaying error message as "Unknown column name "SUM". not determined until runtime, you cannot specify a field list",

How to correct it

Read only

Former Member
0 Likes
1,299

Hi Hema,

You can use keyword SUM for your requirement, as explained above.

Here is an alternative approach:

DATA: w_sum type i.

w_sum = 0.

LOOP AT gt_bsik INTO wa_bsik.

w_sum = w_sum + wa_bsik-buzei.

ENDLOOP.

WRITE:/ w_sum.

Hope this will help.

Regards,

Nitin

Read only

Former Member
0 Likes
1,298

DATA : begin of itab OCCURS 0,

pernr like pa0000-pernr,

END OF itab.

DATA : begin of itab1 OCCURS 0,

pernr like pa0000-pernr,

END OF itab1.

select pernr from pa0000 into table itab where pernr lt '10'.

clear itab.

loop at itab.

itab1-pernr = itab1-pernr + itab-pernr.

endloop.

loop at itab1.

write: itab1-pernr .

endloop.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,298

>

> next i have to find the sum of buzei field.How to do this.Please help

Hello Hema,

I think you got the requirement wrong. BUZEI is the line item number of an a/c'ing doc. I think its wrong to aggregate BUZEI.

Please clarify what exactly do you want?

BR,

Suhas

Read only

Former Member
0 Likes
1,298

you could just write a piece of code to loop the table and sum the values in the column.

data wa like line of gt_lfb1.

data s type i value 0.

Loop at gt_lfb1 into wa.

s = s + wa-buzei.

endloop.

in the end, the variable s should give u the sum.

hope it helps.