Skip to Content
0
Former Member
Mar 27, 2010 at 09:54 AM

To sum quantity

18 Views

Hi All,

I want to calculate the Sum of Quantity for a particular Material in ALV report.

Below is the code of my partial Program. Pls help me out.

FORM build_fldcat .

DATA:

lit_fieldcat TYPE slis_t_fieldcat_alv,

lwa_fieldcat TYPE slis_fieldcat_alv,

lv_cnt TYPE i.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = 'ZPPREP_QM_REGISTER'

i_internal_tabname = 'GIT_OUTPUT'

i_bypassing_buffer = gc_x

CHANGING

ct_fieldcat = lit_fieldcat

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

IF sy-subrc <> 0.

MESSAGE s398(00) WITH 'Error in ALV display' space space space.

STOP.

ENDIF.

CLEAR lv_cnt.

LOOP AT lit_fieldcat INTO lwa_fieldcat.

CLEAR gwa_it_fldcat.

MOVE-CORRESPONDING lwa_fieldcat TO gwa_it_fldcat.

gwa_it_fldcat-key = space.

lv_cnt = lv_cnt + 1.

gwa_it_fldcat-col_pos = lv_cnt.

CASE lwa_fieldcat-fieldname.

WHEN 'MATNR'.

gwa_it_fldcat-no_zero = gc_x.

gwa_it_fldcat-key = gc_x.

WHEN 'MENGE'.

gwa_it_fldcat-coltext = 'Qty./Mat doc'.

gwa_it_fldcat-no_zero = gc_x.

  • gwa_it_fldcat-do_sum = gc_x.

gwa_it_fldcat-ref_field = lwa_fieldcat-ref_fieldname.

gwa_it_fldcat-ref_table = lwa_fieldcat-ref_tabname.

gwa_it_fldcat-scrtext_l = lwa_fieldcat-seltext_l.

gwa_it_fldcat-scrtext_m = lwa_fieldcat-seltext_m.

gwa_it_fldcat-scrtext_s = lwa_fieldcat-seltext_s.

  • gwa_it_fldcat-do_sum = lwa_fieldcat-do_sum. "For Sum of Quantity

APPEND gwa_it_fldcat TO git_fldcat.

  • collect gwa_it_fldcat INTO git_fldcat.

endloop.

&----


*

*& Form OUTPUT_TABLE

&----


DATA:

lv_fld TYPE i,

lv_atnam TYPE cabn-atnam,

lit_batch TYPE TABLE OF clbatch,

lwa_batch TYPE clbatch.

sort git_mseg by matnr. " Added by NKU

LOOP AT git_mseg INTO gwa_mseg.

READ TABLE git_mchb INTO gwa_mchb WITH KEY matnr = gwa_mseg-matnr

werks = gwa_mseg-werks

lgort = gwa_mseg-lgort

charg = gwa_mseg-charg

BINARY SEARCH.

IF sy-subrc NE 0.

CONTINUe.

endif.

***Materail No

lv_fld = lv_fld + 1.

ASSIGN COMPONENT lv_fld OF STRUCTURE <gfs_line> TO <gfs_field>.

<gfs_field> = gwa_mseg-matnr.

***Quantity

lv_fld = lv_fld + 1.

ASSIGN COMPONENT lv_fld OF STRUCTURE <gfs_line> TO <gfs_field>.

<gfs_field> = gwa_mseg-menge.

lv_fld = lv_fld + 1.

ASSIGN COMPONENT lv_fld OF STRUCTURE <gfs_line> TO <gfs_field>.

<gfs_field> = gwa_mseg-meins.

***End of Quantity