Přidáme ikonku

Vhodné doplnění ALV reportu pomocí ikonky pomáhá uživateli v rychlé orientaci ve výstupu dat. Není to nic náročného, ale je nutno ošetřit, kdy se má jaká ikonka zobrazit. V našem případě je to, když materiál obsahuje v kmeni dat cenu.

1.Rozšířená definice použitých tabulek

tables: marc, makt, mbew, mara, icon.

2.Definice sloupce pro ikonku

data: begin of report occurs 0,
matnr like marc-matnr,
werks like marc-werks,
ekgrp like marc-ekgrp,
dispo like marc-dispo,
dismm like marc-dismm,
maktx like makt-maktx,
bklas like mbew-bklas,
verpr like mbew-verpr,
stprs like mbew-stprs,
peinh like mbew-peinh,
mtart like mara-mtart,
meins like mara-meins,
light(4), END OF report.

3.Stanovení podmínky pro zobrazení ikonky

*doplneni ikonky kdyz nalezena cena
if report-verpr gt 0.
select single * from icon where
name eq 'ICON_CHECKED'.
report-light = icon-id.
endif.
append report.
clear report.
                   


Pokud je splněna podmínka a materiál má v kmeni dat uvedeou cenu, zobrazí se ve sloupci LIGHT zelená ikonka. Můžete vybrat libovolnou z tabulky ICON.
Vhodné je vytvořit také nadpis nového sloupce ve formu KATALOG.

WHEN 'LIGHT'. "definuje se text hlavicky sloupce
MOVE:
'L' TO gt_fieldcat_wa-ddictxt,
text-100 TO gt_fieldcat_wa-seltext_l,
* text-100 TO gt_fieldcat_wa-reptext_ddic.
* 'X' TO gt_fieldcat_wa-fix_column.
* SPACE TO gt_fieldcat_wa-key.
'10' TO gt_fieldcat_wa-outputlen.
                             


Text-100 založíte pokliknutím na něj myší…editir Vás provede založením textu.

Celý kod programu

REPORT ZREPORT. 
tables: marc, makt, mbew, mara, icon. 
 
data: begin of report occurs 0,
matnr like marc-matnr,
werks like marc-werks,
ekgrp like marc-ekgrp,
dispo like marc-dispo,
dismm like marc-dismm,
maktx like makt-maktx,
bklas like mbew-bklas,
verpr like mbew-verpr,
stprs like mbew-stprs,
peinh like mbew-peinh,
mtart like mara-mtart,
meins like mara-meins,
light(4),
END OF report.
***************ALV***************************************
TYPE-POOLS: slis.
DATA: gt_fieldcat_wa TYPE slis_fieldcat_alv.
DATA: gt_fieldcat TYPE slis_t_fieldcat_alv.
DATA: ls_fieldcat TYPE slis_fieldcat_alv.
*data int_fcat type SLIS_T_FIELDCAT_ALV.
* field to store report name
DATA g_repid LIKE sy-repid.
* field to check table length
DATA i_lines LIKE sy-tabix.
DATA: gs_layout TYPE slis_layout_alv,
g_exit_caused_by_caller,
gs_exit_caused_by_user TYPE slis_exit_by_user.
*************ALV****************************************
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-010.
parameters: pwerks like marc-werks memory id wrk obligatory.
SELECT-OPTIONS: pmatnr for marc-matnr.
SELECTION-SCREEN END OF BLOCK b1. 
 
START-OF-SELECTION. 
 
select * from marc where
matnr in pmatnr and
werks eq pwerks.
MOVE-CORRESPONDING marc to report. 
 
*vyber z tabulky makt
select single * from makt where
matnr eq report-matnr and
spras eq 'C'.
if sy-subrc eq 0. "byl nalezen zaznam v makt
report-maktx = makt-maktx.
endif. 
 
*vyber z tabulky mbew
select single * from mbew where
matnr eq report-matnr and
bwkey eq pwerks.
if sy-subrc eq 0.
report-bklas = mbew-bklas.
report-verpr = mbew-verpr.
report-stprs = mbew-stprs.
report-peinh = mbew-peinh.
endif. 
 
*vyber z tabulky mara
select single * from mara where
matnr eq report-matnr.
if sy-subrc eq 0.
report-mtart = mara-mtart.
report-meins = mara-meins.
endif. 
 
*doplneni ikonky kdyz nalezena cena
if report-verpr gt 0.
select single * from icon where
name eq 'ICON_CHECKED'.
report-light = icon-id.
endif. 
 
append report.
clear report.
endselect. 
 
****************** A L V ************************************
* Store report name
g_repid = sy-repid.
* Create Fieldcatalogue from internal table
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = g_repid
i_internal_tabname = 'REPORT' "capital letters!
"tabulka pro vystup ALV
i_inclname = g_repid
CHANGING
ct_fieldcat = gt_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3. 
 
IF sy-subrc <> 0.
WRITE: /
'Returncode',
sy-subrc,
'from FUNCTION REUSE_ALV_FIELDCATALOG_MERGE'.
ENDIF. 
 
PERFORM katalog.
DATA g_status TYPE slis_formname .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_BACKGROUND_ID = 'ALV_BACKGROUND'
* i_buffer_active = 'X'
i_callback_program = g_repid
* I_STRUCTURE_NAME = 'SFLIGHT'
it_fieldcat = gt_fieldcat[]
* IS_LAYOUT = GS_LAYOUT
* I_CALLBACK_PF_STATUS_SET = G_STATUS
i_save = 'A' "G_SAVE
* IS_VARIANT = GS_VARIANT
* IT_EVENTS = GT_EVENTS[]
* I_SCREEN_START_COLUMN = 0 "Use coordinates for
* I_SCREEN_START_LINE = 0 "display as dialog box
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER = G_EXIT_CAUSED_BY_CALLER
* ES_EXIT_CAUSED_BY_USER = GS_EXIT_CAUSED_BY_USER
TABLES
t_outtab = report "tabulka pro zobrazeni ALV
EXCEPTIONS
program_error = 1
OTHERS = 2. 
 
IF sy-subrc <> 0.
WRITE: /
'Returncode',
sy-subrc,
'from FUNCTION REUSE_ALV_GRID_DISPLAY'.
ENDIF. 
 
*************KATALOG***************************
FORM katalog.
*
LOOP AT gt_fieldcat INTO gt_fieldcat_wa.
CASE gt_fieldcat_wa-fieldname.
WHEN 'LIGHT'. "definuje se text hlavicky alv dle pole
MOVE:
'L' TO gt_fieldcat_wa-ddictxt,
text-100 TO gt_fieldcat_wa-seltext_l,
* text-100 TO gt_fieldcat_wa-reptext_ddic.
* 'X' TO gt_fieldcat_wa-fix_column.
* SPACE TO gt_fieldcat_wa-key.
'10' TO gt_fieldcat_wa-outputlen. 
 
ENDCASE.
MODIFY gt_fieldcat FROM gt_fieldcat_wa.
ENDLOOP.
ENDFORM. " katalog

Napsat komentář

Vaše emailová adresa nebude zveřejněna. Vyžadované informace jsou označeny *

*

„Proti hluposti se bojovat musí, ale vyhrát se nedá!“ Jan Werich