提问人:Cecilie 提问时间:10/22/2023 最后编辑:Sandra RossiCecilie 更新时间:11/11/2023 访问量:53
制作一个简单的 ALV,但货币和价格很棘手
Making a SIMPLE ALV, but Currency and Price is tricky
问:
我创建了一个简单的 ALV 报告,在这里我想显示货币/价格的显示总计和小计。但是,这非常棘手,因为它不添加价格,而只添加网格中最后两个的货币。currency 字段具有数据类型,price 字段具有数据类型。CURR
INT4
这是我的 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.
这就是我插入数据的方式:
" 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.
为什么这样显示?
答:
0赞
Xavier Salomone
11/11/2023
#1
要记住的事项:
在 ALV 中,将 DDIC 类型用于价格,这比在字段目录中定义它更容易(例如:it_shelters-price 是 CURR?),请参阅 SE11 上的 DMBTR 或 NETWR。
或者,在 fieldcat 中对 DDIC CURR 的引用(任何都应该有效),例如:
wa_fieldcat-ref_fieldname = 'DMBTR'. wa_fieldcat-ref_tabname = 'BSEG'.
评论