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

logic

Former Member
0 Likes
705

Hi experts

I have orderno itemno and qty in table , I need to find out the

average qty for all itemno for particular orderno.

example

orderno itemno qty avg

001--


10
5
----2

001--


20
5
----

002--


10
10
----7.5

002--


20--


5

I need to extract data from the table and do the cal

pls give me the logic to do this

karthik

5 REPLIES 5
Read only

Former Member
0 Likes
688

Try Using COLLECT ...which will sum up the QTY and average.

Get the data into a internal table with a where condition on the ordno

and then COLLECT the avg and ordqty.

Regards,

Reema.

Read only

Pawan_Kesari
Active Contributor
0 Likes
688

SELECT orderno itemno AVG( qty )
INTO (v_orderno v_itemno v_avg)
FROM table_name
GROUP BY orderno itemno .
  WRITE : / v_orderno , v_itemno , v_avg .
ENDSELECT .

Read only

former_member194669
Active Contributor
0 Likes
688

Hi,

Check this


sort itab by orderno.
loop at itab.
  at end of orderno.
     move 'Y' to v_flg.
  endat.
  v_qty = v_qty + itab-qty.
  v_lin = v_lin + 1.
  if v_flg eq 'Y'.
     itab-avg = v_qty / v_lin.
     clear : v_flg, v_lin, v_qty.
     modify itab index sy-tabix.
  endif.
endloop.


aRs

Read only

Former Member
0 Likes
688

TRY below statement.

SELECT AVG( BRGEW ) INTO BRGEW

FROM VBAP

WHERE VBELN = P_VBELN

GROUP BY VBELN.

ADD BRGEW TO ITAB-BRGEW.

APPEND BRGEW.

ENDSELECT.

Read only

Former Member
0 Likes
688

Hi Karthik,

Here is the logic.

REPORT ztestprg.

TABLES : vbak,vbap.

DATA : BEGIN OF t_tab,

vbeln LIKE vbak-vbeln,

posnr LIKE vbap-posnr,

zmeng LIKE vbap-zmeng,

avg LIKE vbap-zmeng,

END OF t_tab.

DATA : i_tab LIKE STANDARD TABLE OF t_tab WITH HEADER LINE,

i_final LIKE STANDARD TABLE OF t_tab WITH HEADER LINE.

SELECT-OPTIONS : s_vbeln FOR vbak-vbeln.

DATA : v_total LIKE vbap-zmeng,

v_lineitems TYPE i,

lv_tabix TYPE sy-tabix.

START-OF-SELECTION.

SELECT vbak~vbeln

vbap~posnr

vbap~kwmeng

FROM vbak

JOIN vbap

ON vbakvbeln = vbapvbeln

INTO TABLE i_tab

WHERE vbak~vbeln IN s_vbeln.

SORT i_tab BY vbeln posnr.

i_final[] = i_tab[].

LOOP AT i_final.

lv_tabix = sy-tabix.

AT NEW vbeln.

CLEAR : v_lineitems,v_total.

LOOP AT i_tab WHERE vbeln = i_final-vbeln.

v_lineitems = v_lineitems + 1.

v_total = v_total + i_tab-zmeng.

ENDLOOP.

ENDAT.

i_final-avg = v_total / v_lineitems.

MODIFY i_final INDEX lv_tabix.

ENDLOOP.

LOOP AT i_final.

WRITE 😕 i_final-vbeln,

i_final-posnr,

i_final-zmeng,

i_final-avg.

ENDLOOP.

Thanks

Mahesh