Making a SIMPLE ALV, but Currency and Price is tricky

388 views Asked by At

I have created a simple ALV report and here I want to display Display Total and Subtotal for Currency/Price. However, it is very tricky as it does not add the price and only the currency of the last two in the grid.. The currency field has data type CURR and the price field has data type INT4.

Here is the code for my ALV:

    TYPE-POOLS: slis.  " SLIS contains all the ALV data types
    DATA: it_shelters TYPE TABLE OF zdb311shelters,
      it_fieldcat  TYPE slis_t_fieldcat_alv,
      wa_fieldcat  TYPE slis_fieldcat_alv,
    "These data types are used to define sorting criteria
      g_repid      TYPE sy-repid.

    START-OF-SELECTION.
   g_repid = sy-repid.

    "Collect data from the database
   SELECT * FROM zdb311shelters INTO TABLE it_shelters.

    "Build field catalog. We define the structure of the ALV grid, specifying the columns (fields) we   want to display and their descriptions in the field catalog

    wa_fieldcat-fieldname  = 'SHELTERID'.
    wa_fieldcat-seltext_m  = 'Shelter ID'.
    APPEND wa_fieldcat TO it_fieldcat.
    CLEAR wa_fieldcat.

    wa_fieldcat-fieldname  = 'SHELTER_NAME'.    " Fieldname in the data table
    wa_fieldcat-seltext_m  = 'Shelter Name'.   " Column description in the output
    APPEND wa_fieldcat TO it_fieldcat.
    CLEAR wa_fieldcat.

    wa_fieldcat-fieldname  = 'AVAILABILITY'.
    wa_fieldcat-seltext_m  = 'Availability'.
    APPEND wa_fieldcat TO it_fieldcat.
    CLEAR wa_fieldcat.

    wa_fieldcat-fieldname  = 'PRICE'.
    wa_fieldcat-seltext_m  = 'Price'.
    wa_fieldcat-do_sum     = 'X'.
    wa_fieldcat-cfieldname = 'CURRENCY'.
    APPEND wa_fieldcat TO it_fieldcat.
    CLEAR wa_fieldcat.

    wa_fieldcat-fieldname  = 'CURRENCY'.
    wa_fieldcat-seltext_m  = 'Currency'.
    APPEND wa_fieldcat TO it_fieldcat.
    CLEAR wa_fieldcat.
  
    wa_fieldcat-fieldname  = 'CAPACITY'.
    wa_fieldcat-seltext_m  = 'Capacity'.
    APPEND wa_fieldcat TO it_fieldcat.
    CLEAR wa_fieldcat.


    "Pass data and field catalog to ALV function module to display ALV list
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = g_repid
      it_fieldcat   = it_fieldcat
    TABLES
      t_outtab      = it_shelters
    EXCEPTIONS
      program_error = 1
      OTHERS        = 2.

And this is how I have inserted data:

" Populate work area for ZDB311SHELTERS
wa_zdb311shelters-mandt = '003'.
wa_zdb311shelters-shelterid = 654.
wa_zdb311shelters-shelter_name = 'CAVE'.
wa_zdb311shelters-price = 1000.
wa_zdb311shelters-currency = 'NOK'.
wa_zdb311shelters-availability = 'Yes'.
wa_zdb311shelters-capacity = 2.

" Insert into ZDB311SHELTERS
INSERT INTO zdb311shelters VALUES wa_zdb311shelters.


" Populate work area for ZDB311SHELTERS
wa_zdb311shelters-mandt = '002'.
wa_zdb311shelters-shelterid = 544.
wa_zdb311shelters-shelter_name = 'FIRE'.
wa_zdb311shelters-price = 2000.
wa_zdb311shelters-currency = 'NOK'.
wa_zdb311shelters-availability = 'Yes'.
wa_zdb311shelters-capacity = 4.

" Insert into ZDB311SHELTERS
INSERT INTO zdb311shelters VALUES wa_zdb311shelters.

" Populate work area for ZDB311SHELTERS
wa_zdb311shelters-mandt = '001'.
wa_zdb311shelters-shelterid = 344.
wa_zdb311shelters-shelter_name = 'CAPOW'.
wa_zdb311shelters-price = 215.
wa_zdb311shelters-currency = 'USD'.
wa_zdb311shelters-availability = 'No'.
wa_zdb311shelters-capacity = 3.

" Insert into ZDB311SHELTERS
INSERT INTO zdb311shelters VALUES wa_zdb311shelters.

" Populate work area for ZDB311SHELTERS
wa_zdb311shelters-mandt = '001'.
wa_zdb311shelters-shelterid = 500.
wa_zdb311shelters-shelter_name = 'RAIN'.
wa_zdb311shelters-price = 150.
wa_zdb311shelters-currency = 'USD'.
wa_zdb311shelters-availability = 'Yes'.
wa_zdb311shelters-capacity = 4.


" Insert into ZDB311SHELTERS
INSERT INTO zdb311shelters VALUES wa_zdb311shelters.

" Populate work area for ZDB311SHELTERS
wa_zdb311shelters-mandt = '000'.
wa_zdb311shelters-shelterid = 444.
wa_zdb311shelters-shelter_name = 'EARTH'.
wa_zdb311shelters-price = 2600.
wa_zdb311shelters-currency = 'SEK'.
wa_zdb311shelters-availability = 'Yes'.
wa_zdb311shelters-capacity = 5.

" Insert into ZDB311SHELTERS
INSERT INTO zdb311shelters VALUES wa_zdb311shelters.

Why is it being displayed like that? enter image description here

1

There are 1 answers

0
Xavier Salomone On

things to keep in mind:

  • In ALV use DDIC types for prices, It's easier than defining it in the field catalog (ex: it_shelters-price is CURR?) see DMBTR or NETWR on SE11.

  • or, in fieldcat references to a DDIC CURR (any should work), like:

wa_fieldcat-ref_fieldname = 'DMBTR'.
wa_fieldcat-ref_tabname   = 'BSEG'.