Skip to Content
author's profile photo Former Member
Former Member

regarding sub-total in alv

hi,

can any body provide me help regarding dis code as i want to add sub total feature in alv.plzzz help me as help will be definately rewarded.

dis is d code:-

REPORT ZTET2.

TABLES: ISEG,MARA.

TYPE-POOLS : SLIS.

DATA : DATE1(15) TYPE C,

DATE2(15) TYPE C,

TITLE(65) TYPE C,

DT(25) TYPE C.

DATA : ITEVENT TYPE SLIS_T_EVENT.

DATA: lv_sort TYPE slis_sortinfo_alv,

t_sort type slis_t_sortinfo_alv.

DATA : repid LIKE sy-repid.

DATA: BEGIN OF ITS1 OCCURS 0,

MATNR LIKE ISEG-MATNR,

ITEMID(6) TYPE C,

MEINS LIKE ISEG-MEINS,

MENGE LIKE ISEG-MENGE,

WRTZL LIKE ISEG-WRTZL,

BUCHM LIKE ISEG-BUCHM,

WRTBM LIKE ISEG-WRTBM,

WERKS LIKE ISEG-WERKS,

BUDAT LIKE ISEG-BUDAT,

ZLDAT LIKE ISEG-ZLDAT,

MTART LIKE MARA-MTART,

ITEMDESC LIKE MAKT-MAKTX,

DIFFQTY LIKE ISEG-BUCHM,

DIFFVALUE LIKE ISEG-WRTBM,

GRUND LIKE ISEG-GRUND,

GRTXT LIKE T157E-GRTXT,

BWART LIKE T157E-BWART,

REAS TYPE C LENGTH 15,

END OF ITS1.

data: t_heading type slis_t_listheader.

SELECTION-SCREEN BEGIN OF BLOCK PAR1 WITH FRAME TITLE TEXT-001.

PARAMETERS : PLANT LIKE ISEG-WERKS OBLIGATORY.

SELECT-OPTIONS : R_DATE FOR ISEG-BUDAT OBLIGATORY NO-EXTENSION,

M_TYPE FOR MARA-MTART,

IT_M FOR MARA-MATNR.

SELECTION-SCREEN END OF BLOCK par1.

CONCATENATE R_DATE-LOW6(2) '.' R_DATE-LOW4(2) '.' R_DATE-LOW+0(4) INTO DATE1.

CONCATENATE R_DATE-HIGH6(2) '.' R_DATE-HIGH4(2) '.' R_DATE-HIGH+0(4) INTO DATE2.

TOP-OF-PAGE.

PERFORM PG_HEADER.

START-OF-SELECTION.

SELECT AMATNR AMEINS AMENGE AWRTZL ABUCHM AWRTBM AWERKS ABUDAT AZLDAT BMTART AGRUND CBWART

FROM ISEG AS A INNER JOIN MARA AS B ON BMATNR = AMATNR

INNER JOIN MSEG AS C ON AMBLNR = CMBLNR

INTO CORRESPONDING FIELDS OF TABLE ITS1 WHERE BMATNR = AMATNR AND BMEINS = AMEINS AND AWERKS = PLANT AND ABUDAT IN R_DATE AND BMTART IN M_TYPE AND BMATNR IN IT_M.

SORT ITS1 BY MTART.

LOOP AT ITS1.

ITS1-ITEMID = ITS1-MATNR+12(6).

ITS1-DIFFQTY = ITS1-MENGE - ITS1-BUCHM.

ITS1-DIFFVALUE = ITS1-WRTZL - ITS1-WRTBM.

SELECT SINGLE MAKTX FROM MAKT INTO ITS1-ITEMDESC WHERE MATNR = ITS1-MATNR.

SELECT SINGLE GRTXT INTO ITS1-GRTXT FROM T157E WHERE GRUND = ITS1-GRUND AND SPRAS = 'E' AND BWART = ITS1-BWART.

MODIFY ITS1.

ENDLOOP.

PERFORM PRN_SMSTOCK_ALV.

FORM PG_HEADER.

WRITE : 'PHYSICAL INVENTORY AUDIT REPORT PLANT : ', PLANT.

ENDFORM.

form PRN_SMSTOCK_ALV .

data: w_title type lvc_title,

w_repid type syrepid,

w_comm type slis_formname,

w_status type slis_formname,

x_layout type slis_layout_alv,

t_event type slis_t_event,

t_fieldcat type slis_t_fieldcat_alv,

t_subtot TYPE slis_t_sortinfo_alv,

subtot LIKE LINE OF t_subtot.

refresh t_fieldcat.

refresh t_event.

refresh t_sort.

clear x_layout.

clear w_title.

perform set_fieldcat2 using:

1 'MTART' 'MTART' 'MARA' '15' space 'MATERIAL TYPE' space space space space space space space space SPACE t_fieldcat 'L' 'L',

2 'ITEMID' 'ITEMID' 'MARA' '7' space 'ITEM ID' space space space space space space space space SPACE t_fieldcat 'R' 'C',

3 'ITEMDESC' 'MAKTX' 'MAKT' '25' space 'MATERIAL DESCRIPTION' space space space space space space space space SPACE t_fieldcat 'L' 'C',

4 'MEINS' 'MEINS' 'MARA' '5' space 'UOM' space space space space space space space space SPACE t_fieldcat 'C' 'C',

5 'MENGE' 'MENGE' 'ISEG' '13' space 'ORG.INV.QTY' space space space space space space space space SPACE t_fieldcat 'R' 'C',

6 'WRTZL' 'WRTZL' 'ISEG' '13' space 'ORG.INV.VALUE' space space space space space space space space SPACE t_fieldcat 'R' 'C',

7 'BUCHM' 'BUCHM' 'ISEG' '13' space 'PHY.INV.QTY' space space space space space space space space SPACE t_fieldcat 'R' 'C',

8 'WRTBM' 'WRTBM' 'ISEG' '13' space 'PHY.INV.VALUE' space space space space space space space space SPACE t_fieldcat 'R' 'C',

9 'DIFFQTY' 'MENGE' 'ISEG' '13' space 'DIFF.INV.QTY' space space space space space space space space SPACE t_fieldcat 'R' 'C',

10 'DIFFVALUE' 'WRTZL' 'ISEG' '13' space 'DIFF.INV.VALUE' space space space space space space space space SPACE t_fieldcat SPACE 'P',

11 'BUDAT' 'BUDAT' 'ISEG' '18' space 'CORRECTED DATE' space space space space space space space space SPACE t_fieldcat 'C' 'C',

12 'GRTXT' 'GRTXT' 'ISEG' '18' space 'REASON' space space space space space space space space SPACE t_fieldcat 'L' 'L',

13 'REAS' 'REAS' 'ISEG' '18' space 'AUTH.BY' space space space space space space space space SPACE t_fieldcat 'C' 'C'.

x_layout-zebra = 'X'.

perform set_top_page_heading using t_heading t_event.

perform set_events using t_event.

perform get_subtotals.

w_status = ''.

w_repid = sy-repid.

  • w_comm = 'USER_COMMAND'.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_callback_program = w_repid

it_fieldcat = t_fieldcat

i_Callback_top_of_page = 'Top-of-page'

is_layout = x_layout

it_sort = t_sort

i_callback_pf_status_set = w_status

i_callback_user_command = w_comm

i_save = 'X'

it_events = t_event

i_grid_title = w_title

tables

t_outtab = ITS1

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.

FORM set_fieldcat2 USING

p_colpos p_fieldname p_ref_fieldname p_ref_tabname

p_outputlen p_noout

p_seltext_m p_seltext_l p_seltext_s p_reptext_ddic p_ddictxt

p_hotspot p_showasicon p_checkbox p_edit

p_dosum

  • p_subtot

t_fieldcat TYPE slis_t_fieldcat_alv

P_JUST

P_FTYPE.

DATA: wa_fieldcat TYPE slis_fieldcat_alv.

CLEAR wa_fieldcat.

  • General settings

wa_fieldcat-fieldname = p_fieldname.

wa_fieldcat-col_pos = p_colpos.

wa_fieldcat-no_out = p_noout.

wa_fieldcat-hotspot = p_hotspot.

wa_fieldcat-checkbox = p_checkbox.

wa_fieldcat-icon = p_showasicon.

wa_fieldcat-do_sum = p_dosum.

  • wa_fieldcat-t_subtot = p_subtot.

  • Set output length.

IF NOT p_outputlen IS INITIAL.

wa_fieldcat-outputlen = p_outputlen.

ENDIF.

  • Set text headers.

  • IF NOT p_seltext_m IS INITIAL.

wa_fieldcat-seltext_m = p_seltext_m.

  • ENDIF.

  • IF NOT p_seltext_l IS INITIAL.

wa_fieldcat-seltext_l = p_seltext_l.

  • ENDIF.

  • IF NOT p_seltext_s IS INITIAL.

wa_fieldcat-seltext_s = p_seltext_s.

  • ENDIF.

IF NOT p_reptext_ddic IS INITIAL.

wa_fieldcat-reptext_ddic = p_reptext_ddic.

ENDIF.

  • IF NOT p_ddictxt IS INITIAL.

wa_fieldcat-ddictxt = p_ddictxt.

  • ENDIF.

IF NOT P_JUST IS INITIAL.

WA_FIELDCAT-JUST = P_JUST.

ENDIF.

IF NOT p_edit IS INITIAL.

wa_fieldcat-Input = 'X'.

wa_fieldcat-edit = 'X'.

wa_fieldcat-do_sum = 'x'.

  • wa_fieldcat-checkbox = 'x'.

  • wa_fieldcat-hotspot = 'x'.

ENDIF.

APPEND wa_fieldcat TO t_fieldcat.

ENDFORM. "set_fieldcat2

form top_of_page.

call function 'REUSE_ALV_COMMENTARY_WRITE'

exporting

it_list_commentary = t_heading.

ENDFORM.

form set_top_page_heading using t_heading type slis_t_listheader

t_events type slis_t_event.

data: x_heading type slis_listheader,

x_event type line of slis_t_event.

  • Report title

clear t_heading[].

clear x_heading.

x_heading-typ = 'H'.

x_heading-info = 'PHYSICAL INVENTORY AUDIT REPORT'.

append x_heading to t_heading.

  • Plant Name

clear x_heading.

x_heading-typ = 'S'.

x_heading-key = 'PLANT : '.

x_heading-info = PLANT.

append x_heading to t_heading.

IF DATE2 = '00.00.0000'.

CONCATENATE DATE1 'to' DATE1 INTO DT SEPARATED BY SPACE.

ELSE.

CONCATENATE DATE1 'to' DATE2 INTO DT SEPARATED BY SPACE.

ENDIF.

X_heading-TYP = 'S'.

X_heading-key = 'PERIOD :'.

X_heading-INFO = DT.

APPEND x_heading TO t_heading.

  • Control Date

clear x_heading.

x_heading-typ = 'S'.

x_heading-key = 'CONTROL NO. :'.

x_heading-info = ' ASDFADDFAAS DATE : 11.04.2007'.

append x_heading to t_heading.

  • Top of page event

x_event-name = slis_ev_top_of_page.

x_event-form = 'TOP_OF_PAGE'.

append x_event to t_events.

endform.

ENDFORM.

form set_events using t_events type slis_t_event.

data: x_event type line of slis_t_event.

endform.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jan 30, 2008 at 04:17 AM

    Hi Ric,

    Check the below steps.

    Declare the internal table and work area.

    DATA: it_sort TYPE slis_t_sortinfo_alv,

    wa_sort TYPE slis_sortinfo_alv.

    Where you are populating the fieldcatalog add the below code there

    CLEAR wa_fieldcatalog.

    wa_fieldcatalog-do_sum = 'X'.

    MODIFY it_fieldcatalog

    FROM wa_fieldcatalog

    TRANSPORTING do_sum

    WHERE fieldname = 'LOSFX'. "Field which you will sum up.

    CLEAR wa_sort.

    wa_sort-spos = '1'.

    wa_sort-fieldname = 'MTART'. "Field on the basis of which you will calculate subtotal

    wa_sort-subtot = 'X'.

    wa_sort-up = 'X'.

    APPEND wa_sort TO it_sort.

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    i_callback_program = lz_repid

    i_callback_pf_status_set = 'PF_STATUS_SET'

    i_callback_user_command = 'USER_COMMAND'

    i_callback_top_of_page = 'TOP-OF-PAGE'

    is_layout = zs_layout

    it_fieldcat = it_fieldcatalog

    it_sort = it_sort " Pass the internal table populated above

    TABLES

    t_outtab = it_output

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Ric,

      I was going through your code.You have declared t_sort but you are just passing it you are not populating it populate it before passing it to FM REUSE_ALV_GRID_DISPLAY as below

      CLEAR wa_sort.

      wa_sort-spos = '1'.

      wa_sort-fieldname = 'MTART'.

      wa_sort-subtot = 'X'.

      wa_sort-up = 'X'.

      APPEND wa_sort TO it_sort.

      and where you are populating the fieldcatalog put a condition that if the field name is 'FIELD1'

      put this code

      CLEAR wa_fieldcatalog.

      wa_fieldcatalog-do_sum = 'X'.

      MODIFY it_fieldcatalog

      FROM wa_fieldcatalog

      TRANSPORTING do_sum

      WHERE fieldname = 'LOSFX'. "Field where you have to calculate the subtotal.

      Check my code thouroghly and try to implement it in your code you will get the desired result

  • Posted on Jan 30, 2008 at 04:28 AM

    Hi Ric,

    When you are creating the fieldcatalogue, for which ever field you want the sub total, make that as X. the field is do_sum. This needs to be made X.You have written space in the fieldcat.

    Thanks,

    Dishant

    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.