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 calculation- Urgent Pls help

Former Member
0 Kudos

Hi

I need to calculate alv items. Example

My alv display is

pos.date ord A/cno Doc cost cost cost total

16.06.07 123 45 VC 340 340

16.06.07 123 45 VC 230 230

16.06.07 123 45 VC 110 110

12.01.08 123 45 VC 340 340

if date, order,A/c no and doc.type is same it should display in one line.

i need to display this as

pos.date ord A/cno Doc cost cost cost total

16.06.07 123 45 VC 340 230 110 680

12.01.08 123 45 VC 340 340

1 ACCEPTED SOLUTION

venkat_o
Active Contributor
0 Kudos

Hi, Just build sort table of type slis_t_sortinfo, for the fields mentioned.

w_sort-fieldname = 'DATE'.
w_sort-tabname = 'ITAB'.
w_sort-up = 'X'.
append w_sort to i_sort.
clear w_sort.
Like that for all fields which u have mentioned. and pass this i_sort through REUSE_ALV_GRID_DISPLAY. It will display . Regards, Venkat.O

6 REPLIES 6

venkat_o
Active Contributor
0 Kudos

Hi, Just build sort table of type slis_t_sortinfo, for the fields mentioned.

w_sort-fieldname = 'DATE'.
w_sort-tabname = 'ITAB'.
w_sort-up = 'X'.
append w_sort to i_sort.
clear w_sort.
Like that for all fields which u have mentioned. and pass this i_sort through REUSE_ALV_GRID_DISPLAY. It will display . Regards, Venkat.O

Former Member
0 Kudos

hi venkat

Thanks for ur reply. type slis_t_sortinfo is unknown.

where i add this code? in fieldcatalog or some where? following is my field catalog.

pls help

Former Member
0 Kudos

you just declare one internal table like this...

data : w_sor type slis_sortinfo_alv,

data : t_sort type slis_t_sortinfo.

w_sort-fieldname = 'DATE'.

w_sort-tabname = 'ITAB'.

w_sort-up = 'X'.

append w_sort to t_sort.

clear w_sort.

pass this one to reuse_alv_grid_display FM.

u can find this slis_t_sortinfo in SLIS type pool.

venkat_o
Active Contributor
0 Kudos

Hi Kumar, Have a look at the sample program. I have mentioned regarding sort table declaration, how to build sort table and where to pass that function module ...


REPORT  zvenkat_notepas.
TYPES:
      BEGIN OF t_mard,
       werks TYPE mard-werks,
       lgort TYPE mard-lgort,
       matnr TYPE mard-matnr,
       insme TYPE mard-insme,
       einme TYPE mard-einme,
       speme TYPE mard-speme,
      END OF t_mard.
DATA:
      w_mard TYPE t_mard.
DATA:
      i_mard TYPE STANDARD TABLE OF t_mard.
*&---------------------------------------------------------------------*
*&      ALV Variables
*&---------------------------------------------------------------------*
TYPE-POOLS :slis.

DATA :i_field   TYPE slis_t_fieldcat_alv,
      w_field   LIKE LINE OF i_field,
      i_events  TYPE slis_t_event,
      w_events  LIKE LINE OF i_events,
      i_sort    TYPE slis_t_sortinfo_alv,       "Sort table declaration
      w_sort    LIKE LINE OF i_sort.            "Sort work area

*&---------------------------------------------------------------------*
*&      START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.

  PERFORM get_data_from_database .

*&---------------------------------------------------------------------*
*&      END-OF-SELECTION
*&---------------------------------------------------------------------*
END-OF-SELECTION.

  PERFORM build_fieldcatalog.
  PERFORM build_sort.                   "Building Sort table
  PERFORM display_data.
*&---------------------------------------------------------------------*
*&      Form  build_fieldcatalog
*&---------------------------------------------------------------------*
FORM build_fieldcatalog .
  CLEAR :
    w_field,
   i_field[].

  PERFORM build_fcat USING:
        'WERKS' 'I_MARD' 'WERKS',
        'LGORT' 'I_MARD' 'LGORT',
        'MATNR' 'I_MARD' 'MATNR',
        'INSME' 'I_MARD' 'INSME',
        'EINME' 'I_MARD' 'EINME',
        'SPEME' 'I_MARD' 'SPEME'.
ENDFORM.                    " build_fieldcatalog

*&---------------------------------------------------------------------*
*&      Form  display_data
*&---------------------------------------------------------------------*
FORM display_data .
  DATA :program LIKE sy-repid VALUE sy-repid.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program     = program
      i_callback_top_of_page = 'TOP_OF_PAGE'
      it_fieldcat            = i_field
      it_sort                = i_sort                      "Pass Sort table
    TABLES
      t_outtab               = i_mard.
  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.                    " display_data

*&---------------------------------------------------------------------*
*&      Form  get_data_from_database
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM get_data_from_database .
  CLEAR :i_mard,
         i_mard[].

  SELECT werks lgort matnr insme einme speme
  FROM mard
  INTO CORRESPONDING FIELDS OF TABLE i_mard
    UP TO 100 ROWS.


ENDFORM.                    " get_data_from_database

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

  DATA :
  i_header TYPE slis_t_listheader,
  w_header LIKE LINE OF i_header.

  DATA:l_date1 TYPE datum,
       l_date2 TYPE datum.

  w_header-typ = 'S'.
  w_header-info = sy-title.
  APPEND w_header TO i_header.
  CLEAR w_header.

  w_header-typ = 'H'.
  w_header-info = sy-repid.
  APPEND w_header TO i_header.
  CLEAR w_header.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = i_header
      i_logo             = 'ENJOYSAP_LOGO'.

ENDFORM.                    "top_of_page
*&---------------------------------------------------------------------*
*&      Form  BUILD_FCAT
*&---------------------------------------------------------------------*

FORM build_fcat  USING  l_field l_tab l_text.

  w_field-fieldname = l_field.
  w_field-tabname   = l_tab.
  w_field-seltext_m = l_text.
  APPEND w_field TO i_field.
  CLEAR w_field.

ENDFORM.                    " BUILD_FCAT
*&---------------------------------------------------------------------*
*&      Form  build_sort
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM build_sort .
  CLEAR :w_sort,i_sort.
  w_sort-fieldname = 'WERKS'.
  w_sort-tabname   = 'I_MARD'.
  w_sort-up = 'X'.
  APPEND w_sort TO i_sort.
  CLEAR  w_sort.

  w_sort-fieldname = 'LGORT'.
  w_sort-tabname   = 'I_MARD'.
  w_sort-up = 'X'.
  APPEND w_sort TO i_sort.
  CLEAR  w_sort.

ENDFORM.                    " build_sort
Regards, Venkat.O

Former Member
0 Kudos

hi kumar,

use the SUM statement.

have a look at the following table

f1 f2 f3

a 1 30

b 2 40

a 1 10

sort TABLE by f1 f2.

loop at table.

at new f3.

SUM.

endloop.

hope this idea is helpful...

srini..

Former Member
0 Kudos

Hi,

First you need to declare a type pool for that inorder to access the structures present in that type-pools..

Type-pools: slis.

data: I_SORT TYPE SLIS_T_SORTINFO_ALV,

W_SORT TYPE slis_sortinfo_alv.

W_SORT-fieldname = 'DATE'.

W_SORT-tabname = 'ITAB'.

W_SORT-up = 'X'.

APPEND W_SORT TO I_SORT.

Then you need to pass this I_SORT to your grid display.

I think it is useful for you.