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 subtotal TEXT not appearing.

Former Member
0 Kudos

Hi Gurus,

I created an ALV. I would like to enter some text in front of the sub-total lines.

Somehow it doesn't work! I'm on release 4.6.

I also tested standard sap program BCALV_TEST_GRID_EVENTS where you can tick a checkbox to trigger the event for subtotal text. But here it also does not work! Is this a release bug?

Can someone confirm BCALV_TEST_GRID_EVENTS is working on another release?

7 REPLIES 7

Former Member
0 Kudos

HI,

USE THIS FOR TEXT

TOTALS-SUBTOTALS_TEXT = 'X'.

IN 'SORT' OF FM.

0 Kudos

Hi,

I tried that.. But let me ask you: Do you see subtotal texts when running BCALV_TEST_GRID_EVENTS ?? (Don't forget to tick the subtotal text checkbox) I ask you because this is not working here either.

former_member188685
Active Contributor
0 Kudos

For Grid it is not working that example. If you want to check the same use the below code and see how it works

REPORT ztest_alv_text .
TYPE-POOLS : slis.

TYPES : BEGIN OF itab_t,
ebeln LIKE ekpo-ebeln,
lifnr LIKE ekko-lifnr,
ekorg LIKE ekko-ekorg,
ekgrp LIKE ekko-ekgrp,
werks LIKE ekpo-werks,
ebelp LIKE ekpo-ebelp,
matnr LIKE ekpo-matnr,
menge LIKE ekpo-menge,
netpr LIKE ekpo-netpr,
d, "Dummy field to fire the Subtotal text event
END OF itab_t.

DATA: itab TYPE TABLE OF itab_t.
DATA: tab TYPE itab_t.
DATA : itab1 LIKE eket OCCURS 0 WITH HEADER LINE.

DATA: t_fcat TYPE slis_t_fieldcat_alv,
it_sort TYPE slis_t_sortinfo_alv,
t_events TYPE slis_t_event,
listhead TYPE slis_t_listheader,
ls_layout TYPE slis_layout_alv.

START-OF-SELECTION.

  SELECT a~ebeln
  a~lifnr
  a~ekorg
  a~ekgrp
  b~werks
  b~ebelp
  b~matnr
  b~menge
  b~netpr
  UP TO 100 ROWS
  INTO CORRESPONDING FIELDS OF TABLE itab
  FROM ekko AS a INNER JOIN ekpo AS b
  ON a~ebeln = b~ebeln.

END-OF-SELECTION.

  PERFORM fill_fcat USING t_fcat.

  PERFORM fill_event USING t_events.

  PERFORM fill_layout.
  PERFORM display.

*&---------------------------------------------------------------------*
*&      Form  fill_fcat
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_T_FCAT   text
*----------------------------------------------------------------------*
FORM fill_fcat USING p_t_fcat TYPE slis_t_fieldcat_alv.

  DATA : lfcat TYPE slis_fieldcat_alv,

  colpos TYPE i VALUE '0'.

  DATA : ls_sort TYPE slis_sortinfo_alv.

  colpos = colpos + 1.
  lfcat-col_pos = colpos.
  lfcat-fieldname = 'EBELN'.
  lfcat-tabname = 'ITAB'.
  lfcat-ref_fieldname = 'EBELN'.
  lfcat-ref_tabname = 'EKKO'.
  lfcat-hotspot = 'X'.
  APPEND lfcat TO p_t_fcat.
  CLEAR lfcat.

  colpos = colpos + 1.
  lfcat-col_pos = colpos.
  lfcat-fieldname = 'LIFNR'.
  lfcat-tabname = 'ITAB'.
  lfcat-ref_fieldname = 'LIFNR'.
  lfcat-ref_tabname = 'EKKO'.
  APPEND lfcat TO p_t_fcat.
  CLEAR lfcat.

  colpos = colpos + 1.
  lfcat-col_pos = colpos.
  lfcat-fieldname = 'EKORG'.
  lfcat-tabname = 'ITAB'.
  lfcat-ref_fieldname = 'EKORG'.
  lfcat-ref_tabname = 'EKKO'.
  APPEND lfcat TO p_t_fcat.
  CLEAR lfcat.

  colpos = colpos + 1.
  lfcat-col_pos = colpos.
  lfcat-fieldname = 'EKGRP'.
  lfcat-tabname = 'ITAB'.
  lfcat-ref_fieldname = 'EKGRP'.
  lfcat-ref_tabname = 'EKKO'.
  APPEND lfcat TO p_t_fcat.
  CLEAR lfcat.

  colpos = colpos + 1.
  lfcat-col_pos = colpos.
  lfcat-fieldname = 'WERKS'.
  lfcat-tabname = 'ITAB'.
  lfcat-ref_fieldname = 'WERKS'.
  lfcat-ref_tabname = 'EKPO'.
  APPEND lfcat TO p_t_fcat.
  CLEAR lfcat.

  colpos = colpos + 1.
  lfcat-col_pos = colpos.
  lfcat-fieldname = 'EBELP'.
  lfcat-tabname = 'ITAB'.
  lfcat-ref_fieldname = 'EBELP'.
  lfcat-ref_tabname = 'EKPO'.
  APPEND lfcat TO p_t_fcat.
  CLEAR lfcat.

  colpos = colpos + 1.
  lfcat-col_pos = colpos.
  lfcat-fieldname = 'MATNR'.
  lfcat-tabname = 'ITAB'.
  lfcat-ref_fieldname = 'MATNR'.
  lfcat-ref_tabname = 'EKPO'.
  APPEND lfcat TO p_t_fcat.
  CLEAR lfcat.

  colpos = colpos + 1.
  lfcat-col_pos = colpos.
  lfcat-fieldname = 'MENGE'.
  lfcat-tabname = 'ITAB'.
  lfcat-ref_fieldname = 'MENGE'.
  lfcat-ref_tabname = 'EKPO'.
  lfcat-do_sum = 'X'.
  APPEND lfcat TO p_t_fcat.
  CLEAR lfcat.

  colpos = colpos + 1.
  lfcat-col_pos = colpos.
  lfcat-fieldname = 'NETPR'.
  lfcat-tabname = 'ITAB'.
  lfcat-ref_fieldname = 'NETPR'.
  lfcat-ref_tabname = 'EKPO'.
  lfcat-do_sum = 'X'.
  APPEND lfcat TO p_t_fcat.
  CLEAR lfcat.


  colpos = colpos + 1.
  lfcat-col_pos = colpos.
  lfcat-fieldname = 'D'.
  lfcat-tabname = 'ITAB'.
  lfcat-ref_fieldname = 'EBELN'.
  lfcat-ref_tabname = 'EKKO'.
  lfcat-no_out = 'X'.
  APPEND lfcat TO p_t_fcat.
  CLEAR lfcat.

  ls_sort-spos = 1.
  ls_sort-fieldname = 'EBELN'.
  ls_sort-tabname = 'ITAB'.
  ls_sort-up = 'X'.
  ls_sort-group = 'UL'.


  APPEND ls_sort TO it_sort.
  CLEAR ls_sort.

  ls_sort-spos = 2.
  ls_sort-fieldname = 'D'.
  ls_sort-tabname = 'ITAB'.
  ls_sort-up = 'X'.
  ls_sort-group = 'UL'.
  ls_sort-subtot = 'X'.

  APPEND ls_sort TO it_sort.
ENDFORM. " fill_fcat

*&---------------------------------------------------------------------*
*&      Form  fill_event
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_T_EVENTS text
*----------------------------------------------------------------------*
FORM fill_event USING p_t_events TYPE slis_t_event.

  DATA : ls_event TYPE slis_alv_event.

  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
      i_list_type     = 0
    IMPORTING
      et_events       = p_t_events
    EXCEPTIONS
      list_type_wrong = 1
      OTHERS          = 2.
  IF sy-subrc NE 0.

  ENDIF.

  READ TABLE p_t_events WITH KEY name = slis_ev_top_of_page
  INTO ls_event.
  IF sy-subrc = 0.
    MOVE 'TOP_OF_PAGE' TO ls_event-form.
    APPEND ls_event TO p_t_events.
  ENDIF.

  READ TABLE p_t_events WITH KEY name = slis_ev_subtotal_text
  INTO ls_event.
  IF sy-subrc = 0.
    MOVE 'SUBTOTAL' TO ls_event-form.
    APPEND ls_event TO p_t_events.
  ENDIF.

ENDFORM. " FILL_EVENT

*&---------------------------------------------------------------------*
*&      Form  subtotal
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->I_LISTHEAD text
*      -->I_SUBTOTAL text
*----------------------------------------------------------------------*
FORM subtotal USING i_listhead STRUCTURE tab
i_subtotal TYPE slis_subtot_text.
*criteria type slis_fieldname,
  DATA: keyword LIKE dd03p-reptext,
  criteria_text(255) TYPE c,
  max_len LIKE dd03p-outputlen,
  display_text_for_subtotal(255) TYPE c.

  IF i_subtotal-criteria = 'D'.
    i_subtotal-display_text_for_subtotal = 'Test Subtotal text'.
    "here you need to do some calculations and assing the data
    "back to total line
  ENDIF.

ENDFORM.                    "SUBTOTAL

*&---------------------------------------------------------------------*
*&      Form  top_of_page
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM top_of_page.

  DATA : s_listhead TYPE slis_listheader.

  CLEAR s_listhead.
  s_listhead-typ = 'H'.
  s_listhead-info = 'SIMPLE REPORT'.
  APPEND s_listhead TO listhead.

  s_listhead-typ = 'S'.
  s_listhead-key = 'EBELN'.
  s_listhead-info = 'ALV'.
  APPEND s_listhead TO listhead.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = listhead
      i_logo             = 'ENJOYSAP_LOGO'.
ENDFORM. "TOP_OF_PAGE

*&---------------------------------------------------------------------*
*&      Form  fill_layout
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM fill_layout .

  ls_layout-zebra = 'X'.
  ls_layout-detail_popup = 'X'.
  ls_layout-key_hotspot = 'X'.
  ls_layout-window_titlebar = 'Test Title'.
  ls_layout-totals_text = 'GRAND TOTAL'.
  ls_layout-subtotals_text = 'SUB'.

ENDFORM. " fill_layout

*&---------------------------------------------------------------------*
*&      Form  display
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM display .

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = sy-repid
      it_sort            = it_sort[]
      it_events          = t_events
      it_fieldcat        = t_fcat
    TABLES
      t_outtab           = itab
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.
  IF sy-subrc NE 0.

  ENDIF.
ENDFORM. " display

Former Member
0 Kudos

hi Vijay Babu Dudla

I copied your program, and tested it. In your program I see:

FORM fill_layout .
 
  ls_layout-zebra = 'X'.
  ls_layout-detail_popup = 'X'.
  ls_layout-key_hotspot = 'X'.
  ls_layout-window_titlebar = 'Test Title'.
  ls_layout-totals_text = 'GRAND TOTAL'.
  ls_layout-subtotals_text = 'SUB'.
 
ENDFORM. " fill_layout

But in the ALV on screen I don't see those *grand total or sub texts*? What am I missing here?

0 Kudos

Hi,

Please check if you have passed the LAYOUT work area to the FM REUSE_ALV_.....

Regards,

Kunjal

0 Kudos
FORM fill_layout .
 
  ls_layout-zebra = 'X'.
  ls_layout-detail_popup = 'X'.
  ls_layout-key_hotspot = 'X'.
  ls_layout-window_titlebar = 'Test Title'.
  ls_layout-totals_text = 'GRAND TOTAL'.  
  ls_layout-subtotals_text = 'SUB'.  "This is not working 
"We have to print subtotal text only from the subtotal_text event
"and also Grandtotal text also not working
"this is working only incase of ALV_LIST function.
"if you observe the above code it is getting the subtotal text
"from the subtotal_text event
 
ENDFORM. " fill_layout

0 Kudos

>

>

FORM fill_layout .
  IF i_subtotal-criteria = 'D'.
    i_subtotal-display_text_for_subtotal = 'Test Subtotal text'.
    "here you need to do some calculations and assing the data
    "back to total line
  ENDIF.

So, If it's the event that triggers the text, then why don't I see this Test Subtotal text? I guess it's so easy I don't see it! Hehehehe...