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: 

ALV

Former Member
0 Kudos
121

HI,

i want to find subtotal for material wide for this field.

w_fieldcat-seltext_l = 'Material Stock Qnt'.

w_fieldcat-tabname = 'INT_OUTTAB'.

w_fieldcat-fieldname = 'LABST'.

w_fieldcat-do_sum = 'X'.

w_fieldcat-outputlen = '13'.

w_fieldcat-col_pos = '1'.

w_fieldcat-row_pos = '1'.

APPEND w_fieldcat TO i_fieldcat.

CLEAR w_fieldcat.

kishi.

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
101
w_fieldcat-seltext_l = 'Material Stock Qnt'.
w_fieldcat-tabname = 'INT_OUTTAB'.
w_fieldcat-fieldname = 'LABST'.
w_fieldcat-do_sum = 'X'.
w_fieldcat-datatype = 'QUAN'.     "<---Try Adding this
w_fieldcat-outputlen = '13'.
w_fieldcat-col_pos = '1'.
APPEND w_fieldcat TO i_fieldcat.
CLEAR w_fieldcat.

Regards,

Rich Heilman

11 REPLIES 11

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
102
w_fieldcat-seltext_l = 'Material Stock Qnt'.
w_fieldcat-tabname = 'INT_OUTTAB'.
w_fieldcat-fieldname = 'LABST'.
w_fieldcat-do_sum = 'X'.
w_fieldcat-datatype = 'QUAN'.     "<---Try Adding this
w_fieldcat-outputlen = '13'.
w_fieldcat-col_pos = '1'.
APPEND w_fieldcat TO i_fieldcat.
CLEAR w_fieldcat.

Regards,

Rich Heilman

0 Kudos
101

Hi Rich,

I am getting grandtotal of all the materials.

But here my req is to find the quantity based on material.

in REPORTS...we use like...

sort itab by matnr.

at new matnr.

sum.write/;//////

endloop.

like this is there any code available for ALV.

help me regarding this...

Vkr.

0 Kudos
101

Oh, sorry. I misunderstood. Here is a complete example.




report zrich_0004
       no standard page heading.

type-pools slis.

data: fieldcat type slis_t_fieldcat_alv.
data: sort     type slis_t_sortinfo_alv.

data: begin of imard occurs 0,
      matnr type mard-matnr,
      werks type mard-werks,
      lgort type mard-lgort,
      labst type mard-labst,
      end of imard.
* Selection Screen

start-of-selection.

  perform get_data.
  perform write_report.


************************************************************************
*  Get_Data
************************************************************************
form get_data.

  select * into corresponding fields of table imard
              from mard up to 100 rows.

endform.

************************************************************************
*  WRITE_REPORT
************************************************************************
form write_report.

  perform build_field_catalog.

  perform build_sort.

* CALL ABAP LIST VIEWER (ALV)
  call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
            it_sort     = sort
            it_fieldcat = fieldcat
       tables
            t_outtab    = imard.

endform.

************************************************************************
* BUILD_FIELD_CATALOG
************************************************************************
form build_field_catalog.

  data: fc_tmp type slis_fieldcat_alv .
  clear fieldcat. refresh fieldcat.

  clear fc_tmp.
  fc_tmp-reptext_ddic    = 'Material'.
  fc_tmp-fieldname  = 'MATNR'.
  fc_tmp-tabname   = 'IMARD'.
  fc_tmp-outputlen  = '18'.
  append fc_tmp to fieldcat.

  clear fc_tmp.
  fc_tmp-reptext_ddic    = 'Plant'.
  fc_tmp-fieldname  = 'WERKS'.
  fc_tmp-tabname   = 'IMARD'.
  fc_tmp-outputlen  = '4'.
  append fc_tmp to fieldcat.

clear fc_tmp.
  fc_tmp-reptext_ddic    = 'StLoc'.
  fc_tmp-fieldname  = 'LGORT'.
  fc_tmp-tabname   = 'IMARD'.
  fc_tmp-outputlen  = '4'.
  append fc_tmp to fieldcat.

clear fc_tmp.
  fc_tmp-reptext_ddic    = 'Qty'.
  fc_tmp-fieldname  = 'LABST'.
  fc_tmp-tabname   = 'IMARD'.
  fc_tmp-outputlen  = '15'.
  fc_tmp-do_sum     = 'X'.
  append fc_tmp to fieldcat.

endform.

************************************************************************
*       FORM build_sort                                                *
************************************************************************
form build_sort.

  data: tmp_sort type line of slis_t_sortinfo_alv.

  clear sort. refresh sort.

  clear tmp_sort.
  tmp_sort-fieldname = 'MATNR'.
  tmp_sort-tabname   = 'IMARD'.
  tmp_sort-up        = 'X'.
  tmp_sort-subtot    = 'X'.
  append tmp_sort to sort.

endform.

Regards,

Rich Heilman

0 Kudos
101

Thanks rich.

0 Kudos
101

Hi Rich one more doubt,

can i give any sub heading like...

Available stock---

like this..

VKR.

0 Kudos
101

Do you mean on the subtotal Line??

Regards,

Rich Heilman

0 Kudos
101

HI rich,

exactly.

vkr.

0 Kudos
101

There is talk thru SDN that you can use the subtotal_text field in the layout parameter, but I have never seen anyone say that it actually works, nor have I ever got it to work, including today.

Regards,

Rich Heilman

Former Member
0 Kudos
101

HI,

see this code for sub-totals.

type-pools: slis.

data: g_repid like sy-repid,

gs_print type slis_print_alv,

gt_list_top_of_page type slis_t_listheader,

gt_events type slis_t_event,

gt_sort type slis_t_sortinfo_alv,

gs_layout type slis_layout_alv,

gt_fieldcat type slis_t_fieldcat_alv,

fieldcat_ln like line of gt_fieldcat,

col_pos type i.

data: begin of itab,

field1(5) type c,

field2(5) type c,

field3(5) type p decimals 2,

end of itab.

data: begin of itab1 occurs 0.

include structure itab.

data: end of itab1.

data: begin of itab_fieldcat occurs 0.

include structure itab.

data: end of itab_fieldcat.

  • Print Parameters

parameters:

p_print as checkbox default ' ', "PRINT IMMEDIATE

p_nosinf as checkbox default 'X', "NO SELECTION INFO

p_nocove as checkbox default ' ', "NO COVER PAGE

p_nonewp as checkbox default ' ', "NO NEW PAGE

p_nolinf as checkbox default 'X', "NO PRINT LIST INFO

p_reserv type i. "NO OF FOOTER LINE

initialization.

g_repid = sy-repid.

perform print_build using gs_print. "Print PARAMETERS

start-of-selection.

  • TEST DATA

move 'TEST1' to itab1-field1.

move 'TEST1' to itab1-field2.

move '10.00' to itab1-field3.

append itab1.

move 'TEST2' to itab1-field1.

move 'TEST2' to itab1-field2.

move '20.00' to itab1-field3.

append itab1.

do 50 times.

append itab1.

enddo.

end-of-selection.

perform build.

perform eventtab_build changing gt_events.

perform comment_build changing gt_list_top_of_page.

perform call_alv.

form build.

  • DATA FIELD CATALOG

  • Explain Field Description to ALV

data: fieldcat_in type slis_fieldcat_alv.

clear fieldcat_in.

fieldcat_ln-fieldname = 'FIELD1'.

fieldcat_ln-tabname = 'ITAB1'.

*FIELDCAT_LN-NO_OUT = 'X'. "FIELD NOT DISPLAY, CHOOSE FROM LAYOUT

fieldcat_ln-key = ' '. "SUBTOTAL KEY

fieldcat_ln-no_out = ' '.

fieldcat_ln-seltext_l = 'HEAD1'.

append fieldcat_ln to gt_fieldcat.

clear fieldcat_in.

fieldcat_ln-fieldname = 'FIELD2'.

fieldcat_ln-tabname = 'ITAB1'.

fieldcat_ln-no_out = 'X'.

fieldcat_ln-seltext_l = 'HEAD2'.

append fieldcat_ln to gt_fieldcat.

clear fieldcat_in.

fieldcat_ln-fieldname = 'FIELD3'.

fieldcat_ln-tabname = 'ITAB1'.

fieldcat_ln-ref_fieldname = 'MENGE'. "<- REF FIELD IN THE DICTIONNARY

fieldcat_ln-ref_tabname = 'MSEG'. "<- REF TABLE IN THE DICTIONNARY

fieldcat_ln-no_out = ' '.

fieldcat_ln-do_sum = 'X'. "SUM UPON DISPLAY

append fieldcat_ln to gt_fieldcat.

  • DATA SORTING AND SUBTOTAL

data: gs_sort type slis_sortinfo_alv.

clear gs_sort.

gs_sort-fieldname = 'FIELD1'.

gs_sort-spos = 1.

gs_sort-up = 'X'.

gs_sort-subtot = 'X'. "***CRUCIAL STATEMENT****

append gs_sort to gt_sort.

clear gs_sort.

gs_sort-fieldname = 'FIELD2'.

gs_sort-spos = 2.

gs_sort-up = 'X'.

*GS_SORT-SUBTOT = 'X'. **THIS SHOULD NOT BE UNCOMENTED*

append gs_sort to gt_sort.

endform.

form call_alv.

  • ABAP List Viewer

call function 'REUSE_ALV_LIST_DISPLAY'

exporting

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE = ' '

i_callback_program = g_repid

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

i_structure_name = 'ITAB1'

is_layout = gs_layout

it_fieldcat = gt_fieldcat[]

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

it_sort = gt_sort[]

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

it_events = gt_events[]

  • IT_EVENT_EXIT =

is_print = gs_print

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

tables

t_outtab = itab1

exceptions

program_error = 1

others = 2.

endform.

  • HEADER FORM

form eventtab_build changing lt_events type slis_t_event.

constants:

gc_formname_top_of_page type slis_formname value 'TOP_OF_PAGE'.

*GC_FORMNAME_END_OF_PAGE TYPE SLIS_FORMNAME VALUE 'END_OF_PAGE'.

data: ls_event type slis_alv_event.

call function 'REUSE_ALV_EVENTS_GET'

exporting

i_list_type = 0

importing

et_events = lt_events.

read table lt_events with key name = slis_ev_top_of_page

into ls_event.

if sy-subrc = 0.

move gc_formname_top_of_page to ls_event-form.

append ls_event to lt_events.

endif.

  • define END_OF_PAGE event

  • READ TABLE LT_EVENTS WITH KEY NAME = SLIS_EV_END_OF_PAGE

  • INTO LS_EVENT.

  • IF SY-SUBRC = 0.

  • MOVE GC_FORMNAME_END_OF_PAGE TO LS_EVENT-FORM.

  • APPEND LS_EVENT TO LT_EVENTS.

  • ENDIF.

endform.

form comment_build changing gt_top_of_page type slis_t_listheader.

data: gs_line type slis_listheader.

clear gs_line.

gs_line-typ = 'H'.

gs_line-info = 'HEADER 1'.

append gs_line to gt_top_of_page.

clear gs_line.

gs_line-typ = 'S'.

gs_line-key = 'STATUS 1'.

gs_line-info = 'INFO 1'.

append gs_line to gt_top_of_page.

gs_line-key = 'STATUS 2'.

gs_line-info = 'INFO 2'.

append gs_line to gt_top_of_page.

  • CLEAR GS_LINE.

  • GS_LINE-TYP = 'A'.

*

  • GS_LINE-INFO = 'ACTION'.

  • APPEND GS_LINE TO GT_TOP_OF_PAGE.

endform.

form top_of_page.

call function 'REUSE_ALV_COMMENTARY_WRITE'

exporting

it_list_commentary = gt_list_top_of_page.

write: sy-datum, 'Page No', sy-pagno left-justified.

endform.

form end_of_page.

write at (sy-linsz) sy-pagno centered.

endform.

  • PRINT SETTINGS

form print_build using ls_print type slis_print_alv.

ls_print-print = p_print. "PRINT IMMEDIATE

ls_print-no_print_selinfos = p_nosinf. "NO SELECTION INFO

ls_print-no_coverpage = p_nocove. "NO COVER PAGE

ls_print-no_new_page = p_nonewp.

ls_print-no_print_listinfos = p_nolinf. "NO PRINT LIST INFO

ls_print-reserve_lines = p_reserv.

endform.

rgds,

bharat.

Former Member
0 Kudos
101

http://help.sap.com/printdocu/core/Print46c/en/data/pdf/CAGTFLV/CAGTFLV.pdf

refer that pdf, it contains details abt subtotals.

regards,

srinivas

<b>*reward for useful answers*</b>