Application Development and Automation 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: 
Read only

Problem with ALV DO_SUM

Former Member
0 Likes
1,150

Hello! Can someone please help me with this one?

I need to subtotal the amounts of my ALV report per vendor. The problem is, there are instances where the amounts are not being subtotalled, only an 'X' is being displayed. I've also double-checked my data, the amounts per vendor set all have the same currency.

I've also set the data types in the fieldcat to either 'CURR' or 'QUAN', but to no effect.

1 ACCEPTED SOLUTION
Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,111

You put the data type as CURR, but did you declare and fill a reference field for the CURRENCY?

Regards.

6 REPLIES 6
Read only

Former Member
0 Likes
1,111

hi Maple,

Refer to this sample program for totals and subtotals

REPORT ztest_alv_sub_totals .

TYPE-POOLS: slis.

DATA: BEGIN OF it_output OCCURS 0,
          var1(8) TYPE n,
          var2(10),
          var3 TYPE I,
      END OF it_output.

DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
       t_fieldcat TYPE slis_fieldcat_alv,
      it_sort TYPE slis_t_sortinfo_alv,
      t_sort TYPE slis_sortinfo_alv,
      v_repid LIKE sy-repid.

INITIALIZATION.
  v_repid = sy-repid.

START-OF-SELECTION.

  PERFORM get_data.
  PERFORM sort_fields.
  PERFORM fill_fieldcat.
  PERFORM list_display.

*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_data.

  it_output-var1 = 1000.
  it_output-var2 = 'anupama'.
  it_output-var3 = '10000'.
  APPEND it_output.
  CLEAR it_output.

  it_output-var1 = 1000.
  it_output-var2 = 'siddhu'.
  it_output-var3 = '20000'.
  APPEND it_output.
  CLEAR it_output.

  it_output-var1 = 1000.
  it_output-var2 = 'chinni'.
  it_output-var3 = '100000'.
  APPEND it_output.
  CLEAR it_output.

  it_output-var1 = 2000.
  it_output-var2 = 'chicchu'.
  it_output-var3 = '10000'.
  APPEND it_output.
  CLEAR it_output.

  it_output-var1 = 2000.
  it_output-var2 = 'candy'.
  it_output-var3 = '10000'.
  APPEND it_output.
  CLEAR it_output.

  it_output-var1 = 1000.
  it_output-var2 = 'anupama'.
  it_output-var3 = '10000'.
  APPEND it_output.
  CLEAR it_output.

  it_output-var1 = 4000.
  it_output-var2 = 'anupama'.
  it_output-var3 = '10000'.
  APPEND it_output.
  CLEAR it_output.


ENDFORM.                    " GET_DATA

*&---------------------------------------------------------------------*
*&      Form  fill_fieldcat
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM fill_fieldcat.
  PERFORM fill_fields USING: 'IT_OUTPUT' 'VAR1' 'Variable 1' ' ',
                             'IT_OUTPUT' 'VAR2' 'Variable 2' ' ',
                             'IT_OUTPUT' 'VAR3' 'Variable 3' 'X'.

ENDFORM.                    " fill_fieldcat

*&---------------------------------------------------------------------*
*&      Form  fill_fields
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_0146   text
*      -->P_0147   text
*      -->P_0148   text
*      -->P_0149   text
*----------------------------------------------------------------------*
FORM fill_fields USING    value(tabname) TYPE slis_tabname
                          value(fieldname) TYPE slis_fieldname
                          value(seltext_m) LIKE dd03p-scrtext_m
                          value(do_sum) TYPE c.
  t_fieldcat-tabname = tabname.
  t_fieldcat-fieldname = fieldname.
  t_fieldcat-seltext_m  = seltext_m.
  IF do_sum = 'X'.
    t_fieldcat-datatype = 'CURR'.
  ENDIF.
  t_fieldcat-do_sum = do_sum.
  APPEND t_fieldcat TO it_fieldcat.
  CLEAR t_fieldcat.
ENDFORM.                    " fill_fields

*&---------------------------------------------------------------------*
*&      Form  list_display
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM list_display.
  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
   EXPORTING
     i_callback_program             = v_repid
     it_fieldcat                    = it_fieldcat
     it_sort                        = it_sort[]
   TABLES
      t_outtab                       = it_output
   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.                    " list_display

*&---------------------------------------------------------------------*
*&      Form  sort_fields
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM sort_fields.
  t_sort-fieldname = 'VAR1'.
  t_sort-tabname = 'IT_OUTPUT'.
  t_sort-spos = 1.
  t_sort-up = 'X'.
  t_sort-subtot = 'X'.
  APPEND t_sort TO it_sort.
  CLEAR t_sort.

  t_sort-fieldname = 'VAR3'.
  t_sort-tabname = 'IT_OUTPUT'.
  t_sort-spos = 2.
  t_sort-up = 'X'.
  APPEND t_sort TO it_sort.
  CLEAR t_sort.

ENDFORM. 

Read only

Former Member
0 Likes
1,111

in field cat of amount

ifieldcat-do_sum = 'X'.

in sort info

wsortinfo-fieldname = 'LIFNR'.

wsortinfo-up = 'X'.

wsortinfo-group = 'UL'.

wsortinfo-subtot = 'X'.

append wsortinfo to isortinfo.

now pass that to alv list or grid in I_sort param..

regards

shiba dutta

Read only

Former Member
0 Likes
1,111

Thank you, but I have already tried your suggestions. I have tried setting the amount values in either 'QUAN' or 'CURR', and have set the sort category by vendor. Any other suggestions? Ü

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,112

You put the data type as CURR, but did you declare and fill a reference field for the CURRENCY?

Regards.

Read only

0 Likes
1,111

When filling your fieldcat, if you don't use a dictionary structure, you will have to link the unit/currency with the quantity/amount so :

(...)

fieldcat-fieldname = 'WRBTR'.

fieldcat-datatype = 'CURR'.

fieldcat-ref_fieldname = 'WAERS'.

append fieldcat.

(...)

fieldcat-fieldname = 'WAERS'.

fieldcat-datatype = 'CUCY'.

append fieldcat.

(...)

You can hide the unit field with

fieldcat-tech = 'X'.

Of course for your purpose WAERS shall be in the table

When amount is not zero, you will get an output like this 123,45

When amount is zero

- if currency/unit is space, you will get space

- if currency/unit is not space, you will get 0,00

so when no-data, clear (or dont fill) the unit, else fill unit/currency

A more: if you totalize such a field, you will get one total per unit/currency

Read only

0 Likes
1,111

Hi Raymond!

Thank you, your advice worked, although I used it in a different way.

I modified the reference table and field in my structure so that the amount field is linked to the corresponding currency field.

Thanks a lot!!