Tuesday, July 22, 2025

🚦Practical Program - ALV Cell coloring, ALV Traffic light column, ALV Drop down column

REPORT Z930ALV7.

include z930alv7_vardec.

INCLUDE z930alv7_moddef.

INCLUDE z930alv7_subdef.

start-of-SELECTION.

call screen 100.

Include Program: containing variable declarations

(z930alv6_vardec)

data v_vbeln type vbak-vbeln.

SELECT-OPTIONS so_vbeln for v_vbeln DEFAULT '4980' to '5030'.

data : vbak_cont type ref to cl_gui_custom_container,

vbak_grid type ref to cl_gui_alv_grid.

data : t_fcat type lvc_t_fcat,

wa_fcat type lvc_s_fcat.

data wa_layo type lvc_s_layo.

types : begin of ty_vbak.

include type zcvbak.

types : netwr type vbak-netwr,

end of ty_vbak.

data : t_vbak type table of ty_vbak,

wa_vbak type ty_vbak.

types : begin of ty_final_vbak.

include type zcvbak.

types : netwr type vbak-netwr,

cellcolor type lvc_t_scol,

lights type c,

ordertype type string,

end of ty_final_vbak.

data : t_final_vbak type table of ty_final_vbak,

wa_final_vbak type ty_final_vbak.

data wa_cellcolor type lvc_s_scol.

Include Program: containing module definitions(Z930ALV7_MODDEF)

MODULE STATUS_0100 OUTPUT.

if vbak_cont is not bound.

SET PF-STATUS 'STATUS100'.

* link container with custom control

CREATE OBJECT VBAK_CONT

EXPORTING

CONTAINER_NAME = 'CUSTCTRL'.

* link alv grid with custom container

CREATE OBJECT VBAK_GRID

EXPORTING

I_PARENT = vbak_cont.

* get sales orders

perform getvbak.

if t_vbak is not INITIAL.

* generate field catalog for sales orders grid

perform fldcatvbak.

* generate layout

perform layoutvbak.

* prepare dropdown column values

perform dropdown_ordertype.

* display sales orders

perform displayvbak.

endif.

endif.

ENDMODULE. " STATUS_0100 OUTPUT

MODULE USER_COMMAND_0100 INPUT.

case sy-ucomm.

when 'BACK'.

leave program.

endcase.

ENDMODULE. " USER_COMMAND_0100 INPUT

Include Program: containing subroutine definitions

(Z930ALV7_MODDEF)

FORM GETVBAK .

select vbeln erdat erzet ernam netwr

from vbak

into table t_vbak

where vbeln in so_vbeln.

if sy-subrc eq 0.

clear wa_vbak.

loop at t_vbak into wa_vbak.

clear wa_final_vbak.

clear wa_cellcolor.

MOVE-CORRESPONDING wa_vbak to wa_final_vbak.

if wa_vbak-netwr < 10000.

wa_final_vbak-lights = '1'. "red

wa_cellcolor-fname = 'VBELN'.

wa_cellcolor-color-col = 5.

wa_cellcolor-color-int = 1.

wa_cellcolor-color-inv = 0.

append wa_cellcolor to wa_final_vbak-cellcolor.

elseif wa_vbak-netwr >= 10000 and wa_vbak-netwr < 40000.

wa_final_vbak-lights = '2'. "orange

wa_cellcolor-fname = 'VBELN'.

wa_cellcolor-color-col = 7.

wa_cellcolor-color-int = 1.

wa_cellcolor-color-inv = 0.

append wa_cellcolor to wa_final_vbak-cellcolor.

else.

wa_final_vbak-lights = '3'. "green

wa_cellcolor-fname = 'VBELN'.

wa_cellcolor-color-col = 3.

wa_cellcolor-color-int = 1.

wa_cellcolor-color-inv = 0.

append wa_cellcolor to wa_final_vbak-cellcolor.

endif.

append wa_final_vbak to t_final_vbak.

clear wa_vbak.

endloop.

endif.

ENDFORM. " GETVBAK

FORM FLDCATVBAK .

refresh t_fcat.

clear wa_fcat.

wa_fcat-fieldname = 'VBELN'.

wa_fcat-col_pos = 1.

wa_fcat-coltext = 'Sales Doc'.

wa_fcat-outputlen = 12.

append wa_fcat to t_fcat.

clear wa_fcat.

wa_fcat-fieldname = 'ERDAT'.

wa_fcat-col_pos = 2.

wa_fcat-coltext = 'Creation Date'.

wa_fcat-outputlen = 12.

append wa_fcat to t_fcat.

clear wa_fcat.

wa_fcat-fieldname = 'ERDAT'.

wa_fcat-col_pos = 3.

wa_fcat-coltext = 'Creation Time'.

wa_fcat-outputlen = 12.

append wa_fcat to t_fcat.

clear wa_fcat.

wa_fcat-fieldname = 'ERNAM'.

wa_fcat-col_pos = 4.

wa_fcat-coltext = 'Created By'.

wa_fcat-outputlen = 12.

append wa_fcat to t_fcat.

clear wa_fcat.

wa_fcat-fieldname = 'NETWR'.

wa_fcat-col_pos = 5.

wa_fcat-coltext = 'Net Value'.

wa_fcat-outputlen = 12.

append wa_fcat to t_fcat.

clear wa_fcat.

wa_fcat-fieldname = 'LIGHTS'.

wa_fcat-col_pos = 6.

wa_fcat-coltext = 'Status'.

wa_fcat-outputlen = 8.

append wa_fcat to t_fcat.

clear wa_fcat.

wa_fcat-fieldname = 'ORDERTYPE'.

wa_fcat-col_pos = 7.

wa_fcat-coltext = 'Order Type'.

wa_fcat-outputlen = 12.

wa_fcat-drdn_hndl = 50.

wa_fcat-edit = 'X'.

append wa_fcat to t_fcat.

ENDFORM. " FLDCATVBAK

FORM LAYOUTVBAK .

clear wa_layo.

wa_layo-grid_title = 'Sales Orders'.

wa_layo-ctab_fname = 'CELLCOLOR'. "for cell coloring

wa_layo-excp_fname = 'LIGHTS'. "for traffic lights

ENDFORM. " LAYOUTVBAK

FORM DISPLAYVBAK .

CALL METHOD VBAK_GRID->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

IS_LAYOUT = wa_layo

CHANGING

IT_OUTTAB = t_final_vbak

IT_FIELDCATALOG = t_fcat.

ENDFORM. " DISPLAYVBAK

FORM DROPDOWN_ORDERTYPE .

data : t_drop type lvc_t_drop,

wa_drop type lvc_s_drop.

clear wa_drop.

wa_drop-handle = 50.

wa_drop-value = 'High order'.

append wa_drop to t_drop.

clear wa_drop.

wa_drop-handle = 50.

wa_drop-value = 'Medium order'.

append wa_drop to t_drop.

clear wa_drop.

wa_drop-handle = 50.

wa_drop-value = 'Low order'.

append wa_drop to t_drop.

CALL METHOD VBAK_GRID->SET_DROP_DOWN_TABLE

EXPORTING

IT_DROP_DOWN = t_drop.

ENDFORM. " DROPDOWN_ORDERTYPE

Flow logic of screen 100:

PROCESS BEFORE OUTPUT.

MODULE STATUS_0100.

*

PROCESS AFTER INPUT.

MODULE USER_COMMAND_0100.



Layout of screen 100:



GUI status of screen 100:



No comments:

Post a Comment