Application Development 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: 

ALV_GRID OO: delete the empty lines

Former Member
0 Kudos

Hi all,

I have an edit ALV_GRID OO and I need to delete the empty lines (in case the

add a new line without introducing any data).

Since I'm new on ALV OO, please could you give an example?

I thank you in advance.

Paolo.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi ,


PROGRAM zdynfieldcat.
class zcltest definition deferred. "For field symbol reference.
 
* The ultimate ALV program
 
* this program demos the following
* 1) Build Dynamic ITAB with fields NOT defined in DDIC
* 2) Build Dynamic FieldCat. Table structure is obtained *via
* the new RTTI functionality
* 3) Add the CELL colour table as a deep structure to our dynamic table
* so we can colour individual cells.
* 4) Inherit a class so protected attributes
* of class cl_gui_alv_grid
* can be accessed
* 5) Add events so we can can program functionality when * the user presses 
* the ENTER key,
* or selects an action from the toolbar.
* 6) Display one line of a grid from our dynamic table with some cells coloured.
* 6) Set the Grid editable.
* 7) if user enters data then colou
* cells of entered data.
* 😎 show contents of new table 
* after all data has been entered.
 
* To use program copy the source and
* Create a blank screen 100 with a
* custom container called CCONTAINER1.
* with the screen logic shown below
* As we are using EVENTS we actually
* don't need a PAI module so it
* doesn't contain any code.
 
*PROCESS BEFORE OUTPUT.
* MODULE STATUS_0100.
*
*PROCESS AFTER INPUT.
* MODULE USER_COMMAND_0100
*

 
* Define field symbols as these can't be defined in classes
 
field-symbols: <dyn_table> type standard table,
<g2> type ref to zcltest,
<g1> type ref to cl_gui_custom_container,
<data_changed> type ref to cl_alv_changed_data_protocol,
<actual_tab> type standard table,
<outtab> type table,
<fs1> type ANY,
<FS2> TYPE TABLE,
<fs3> type table,
<fs4> type table,
<fs5> type table,
<wa_dyn_table> TYPE ANY,
<w_field1> type any,
<w_field2> type any,
<w_field3> type any,
<w_field4> type any,
<w_field5> type any,
<t_colours> type any,
<t_clrs> type line of lvc_t_scol,
<t_cellcolors> TYPE lvc_t_scol,
<t_cellcolors1> type lvc_t_scol.
 
 
class zcltest definition inheriting from cl_gui_alv_grid.
 
public section.
 
types: g4 type ref to cl_gui_custom_container.
types: g3 type ref to cl_alv_changed_data_protocol.
data: i_parent type g4,
lr_rtti_struc TYPE REF TO cl_abap_structdescr, "RTTI
zog like line of lr_rtti_struc->components. "RTTI
types: struc like zog.
types: struc1 type table of struc.
 
methods:
constructor
importing i_parent type g4,
disp_tab
importing p_er_data_changed type g3,
 
create_dynamic_fcat
importing zogt type struc1
exporting it_fldcat type lvc_t_fcat.
Protected section.
 
private section.
data: stab type ref to data,
wa_it_fldcat type lvc_s_fcat,
c_index type sy-index,
lt_good_cells type lvc_t_modi,
ls_good type lvc_s_modi,
ls_good_cells type lvc_s_modi,
et_good_cells type LVC_T_MODI,
e_row type i,
e_value type c,
e_col type i,
es_row_id type lvc_s_row,
es_col_id type lvc_s_col,
es_row_no type LVC_S_ROID,
wa_cellcolors TYPE LINE OF lvc_t_scol,
wa_modified_cells type line of LVC_T_MODI,
es_layout type LVC_S_LAYO.
 
endclass.
 
class zcltest implementation.
METHOD constructor.
 
CALL METHOD super->constructor
EXPORTING
i_appl_events = 'X'
i_parent = i_parent.
 
endmethod.
 
method disp_tab.
* mt_outtab is the data table held 
* as a protected attribute
* in class cl_gui_alv_grid.
assign me->mt_outtab->* TO <outtab>. "Original data
assign p_er_data_changed->mp_mod_rows TO <FS1>.
stab = p_er_data_changed->mp_mod_rows.
assign p_er_data_changed->mt_inserted_rows to <fs3>.
assign p_er_data_changed->mt_deleted_rows to <fs4>.
assign p_er_data_changed->mt_mod_cells to <fs5>.
assign stab->* TO <fs2>.
 
[code] 
* some functions --chose what you want
 
* This method gets the last (or current cell)
call method me->get_current_cell
importing e_row = e_row
e_value = e_value
e_col = e_col
es_row_id = es_row_id
es_col_id = es_col_id
es_row_no = es_row_no.
 
* For an example let's change the colour
* of any data entered including
* inserted rows.
*
* Proceed as follows
*
 
* read table <fs5> which gives us the
* row number and field name of
* the modified cell(s) including inserted rows
*
* For deleted rows we don't have to do anything
*
* Update the cell's colour characteristic table
 
* remember we added a colour table
* to the dynamic data table we built
* note that it's a DEEP structure.
 
* On REFRESH the alv will look at the
* updated colour table for the cells.
* we don't actually have to modify the data table but just the colour
* table
 
* recapping
 
* 1) Create your Field catalog WITHOUT 
* the colour table for the ALV grid display
* 2) Add the colour table to a 2nd field catalog
* which you use to build the actual data
* dynamic table
* 3) add the name of the colour table to the layout
* (struct_grid_lset-ctab_fname 
* = 'T_CELLCOLORS')
 
* Refresh Grid and new cell colours will work
 
 
* now let's change the colour of the selected cells.
 
ASSIGN COMPONENT 'T_CELLCOLORS'
OF STRUCTURE <wa_dyn_table> TO <t_cellcolors1>.
loop at <fs5> into wa_modified_cells.
 
 
read table <dyn_table> into <wa_dyn_table> index wa_modified_cells-row_id.
case sy-subrc.
when 0.
read table <t_cellcolors1> into wa_cellcolors
with key fname = wa_modified_cells-fieldname.
if sy-subrc = 0.
if not wa_modified_cells-value is initial.
wa_cellcolors-fname = wa_modified_cells-fieldname.
 
wa_cellcolors-color-col = '5'.
MODIFY <t_cellcolors1> from wa_cellcolors .
endif.
else.
if not wa_modified_cells-value is initial.
wa_cellcolors-fname = wa_modified_cells-fieldname.
 
wa_cellcolors-color-col = '5'.
append wa_cellcolors to <t_cellcolors1>.
endif.
endif.
 
when others.
loop at <fs2> into <wa_dyn_table>.
append <wa_dyn_table> to <dyn_table>.
endloop.
read table <dyn_table> into <wa_dyn_table> index wa_modified_cells-row_id.
clear wa_cellcolors.
if not wa_modified_cells-value is initial.
 
wa_cellcolors-fname = wa_modified_cells-fieldname.
 
wa_cellcolors-color-col = 5.
append wa_cellcolors to <t_cellcolors1>.
endif.
endcase.
 
 
MODIFY <dyn_table> FROM <wa_dyn_table> index wa_modified_cells-row_id.
 
 
endloop.
 
 
endmethod.
 
method create_dynamic_fcat.
loop at zogt into zog.
c_index = c_index + 1.
clear wa_it_fldcat.
 
wa_it_fldcat-fieldname = zog-name .
wa_it_fldcat-datatype = zog-type_kind.
wa_it_fldcat-inttype = zog-type_kind.
wa_it_fldcat-intlen = zog-length.
wa_it_fldcat-decimals = zog-decimals.
wa_it_fldcat-coltext = zog-name.
wa_it_fldcat-lowercase = 'X'.
append wa_it_fldcat to it_fldcat .
endloop.
endmethod. "create_dynamic_fcat
 
endclass. "zcltest IMPLEMENTATION
 
class lcl_grid_event_receiver definition.
 
public section.
data: data_c type ref to cl_alv_changed_data_protocol.
 
methods:
handle_data_changed
for event data_changed of zcltest
importing er_data_changed,
 
handle_data_changed_finished
for event data_changed_finished of zcltest
importing E_MODIFIED
ET_GOOD_CELLS,
 
 
toolbar
for event toolbar of zcltest
importing e_object
e_interactive,
 
user_command
for event user_command of zcltest
importing e_ucomm.
 
endclass.
 
 
class lcl_grid_event_receiver implementation.
method handle_data_changed.
 
call method <g2>->disp_tab
EXPORTING
p_er_data_changed = er_data_changed.
 
endmethod. "handle_data_changed
 
 
 
method handle_data_changed_finished.
 
* at this point our data dynamic table
* <dyn_table> now contains the actual updated values from
* the grid including the cell color info create in the on data changed
* event method call AND IN THE CORRECT ORDER.
* use this method to update say SAP data bases or other
* data from the GRID entered data.
*
* Data entry validation can be done here as well.
*
* Enter your own code here.
.
endmethod.
 
method toolbar.
 
 
data : ls_toolbar type stb_button.
clear ls_toolbar.
<b>move 0 to ls_toolbar-butn_type.
<b>move 'EDIT' to ls_toolbar-function.
move space to ls_toolbar-disabled.
move 'Edit' to ls_toolbar-text.</b>
move icon_change_text to ls_toolbar-icon.
move 'Click2Edit' to ls_toolbar-quickinfo.
append ls_toolbar to e_object->mt_toolbar.</b>
 
clear ls_toolbar.
move 0 to ls_toolbar-butn_type.
move 'UPDA' to ls_toolbar-function.
move space to ls_toolbar-disabled.
move 'Update' to ls_toolbar-text.
move icon_system_save to ls_toolbar-icon.
move 'Click2Update' to ls_toolbar-quickinfo.
append ls_toolbar to e_object->mt_toolbar.
 
clear ls_toolbar.
move 0 to ls_toolbar-butn_type.
move 'EXIT' to ls_toolbar-function.
move space to ls_toolbar-disabled.
move 'Exit' to ls_toolbar-text.
move icon_system_end to ls_toolbar-icon.
move 'Click2Exit' to ls_toolbar-quickinfo.
append ls_toolbar to e_object->mt_toolbar.
 
 
endmethod. "toolbar
 
method user_command.
 
case e_ucomm .
when 'EDIT'. "From Tool bar
perform set_input.
perform refresh_disp.
 
when 'UPDA'. "From Tool bar
perform refresh_disp.
 
when 'EXIT'. "From Tool bar
leave program.
 
endcase.
 
endmethod. "user_command
endclass. "lcl_grid_event_receiver IMPLEMENTATION
 
 
* program data
*
include <icon>.
* define any old internal structure NOT in DDIC
types: begin of s_elements,
anyfield1(20) type c,
anyfield2(20) type c,
anyfield3(20) type c,
anyfield4(20) type c,
anyfield5(11) type n,
end of s_elements.
 
data: wa_element type s_elements,
wa_cellcolors TYPE LINE OF lvc_t_scol,
 
wa_data type s_elements,
wa_dyn_table TYPE REF TO data.
 
 
* Note new RTTI functionality allows field detail retrieval
* at runtime for dynamic tables.
data:
grid1 type ref to zcltest,
grid_handler type ref to lcl_grid_event_receiver,
c_dec2 type s_elements-anyfield5,
wa_it_fldcat type lvc_s_fcat,
it_fldcat type lvc_t_fcat,
it_fldcat1 type lvc_t_fcat,
lr_rtti_struc TYPE REF TO cl_abap_structdescr, "RTTI
lt_comp TYPE cl_abap_structdescr=>component_table,"RTTI
ls_comp LIKE LINE OF lt_comp, "RTTI
zog like line of lr_rtti_struc->components, "RTTI
struct_grid_lset type lvc_s_layo,
l_valid type c,
new_table type ref to data.
types: struc like zog,
col_tab type lvc_t_scol.
 
 
data: zogt type table of struc,
grid_container1 type ref to cl_gui_custom_container,
g_event_receiver type ref to lcl_grid_event_receiver,
ok_code like sy-ucomm,
t_colours type table of col_tab,
i4 type int4.
 
start-of-selection.
call screen 100.
module status_0100 output.
 
if grid_container1 is initial.
 
create object grid_container1
exporting
container_name = 'CCONTAINER1'.
assign grid_container1 to <g1>.
create object grid1
exporting i_parent = grid_container1.
 
* we need reference to this instance so we can use
* Methods etc of zcltest class and alv (superclass)
* in our event receiver class.
 
assign grid1 to <g2>.
create object grid_handler.
 
* set handler for events
 
set handler:
grid_handler->user_command for grid1,
grid_handler->toolbar for grid1,
grid_handler->handle_data_changed_finished for grid1.
perform register_enter_event. "For ENTER key press
 
 
* Get the Internal table structure
lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( wa_data ).
 
* Build field catalog just use basic data here
* colour specific columns as well
zogt[] = lr_rtti_struc->components.
 
call method grid1->create_dynamic_fcat
EXPORTING
zogt = zogt
IMPORTING
it_fldcat = it_fldcat.
* Save field cat without cell info deep structure for Grid
it_fldcat1[] = it_fldcat.
* now add deep structure for cell colour to field catalog
* for dynamic table creation
assign t_colours to <t_colours>.
wa_it_fldcat-fieldname = 'T_CELLCOLORS'.
wa_it_fldcat-ref_field = 'COLTAB'.
wa_it_fldcat-ref_table = 'CALENDAR_TYPE'.
* use this table as it has a DDIC built in ref structure for cell colour info
 
APPEND wa_it_fldcat TO it_fldcat1.
* Create dynamic internal table and assign to field symbol.
* Use dynamic field catalog just built.
 
call method cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fldcat1
IMPORTING
ep_table = new_table.
 
perform populate_dynamic_itab.
perform init_grid.
i4 = 0.
call method grid1->set_ready_for_input
EXPORTING
i_ready_for_input = i4.
endif.
.
perform refresh_disp.
 
endmodule. "status_0100 OUTPUT
 
module user_command_0100 input.
*
*PAI not needed in OO ALV anymore as User Commands are handled as events
*in method user_command.
*
*we can also get control if the Data entered and the ENTER is pressed by
*raising an event.
* Control then returns to method handle_data_changed.
endmodule. "user_command_0100 INPUT
 
form populate_dynamic_itab.
* load up a line of the dynamic table
c_dec2 = c_dec2 + 11.
assign new_table->* to <dyn_table>.
 
create data wa_dyn_table like line of <dyn_table>.
assign wa_dyn_table->* to <wa_dyn_table>.
 
assign component 'ANYFIELD1' of structure <wa_dyn_table> to <w_field1>
.
<w_field1> = 'Tabbies'.
assign component 'ANYFIELD2' of structure <wa_dyn_table> to
<w_field2>.
<w_field2> = 'Ger Shepards'.
assign component 'ANYFIELD3' of structure <wa_dyn_table> to <w_field3>.
<w_field3> = 'White Mice'.
 
assign component 'ANYFIELD4' of structure <wa_dyn_table> to <w_field4>.
<w_field4> = 'Any old Text'.
 
assign component 'ANYFIELD5' of structure <wa_dyn_table> to <w_field5>.
<w_field5> = c_dec2..
APPEND <wa_dyn_table> TO <dyn_table>.
 
 
loop at <dyn_table> into <wa_dyn_table>.
clear wa_cellcolors.
 
ASSIGN COMPONENT 'T_CELLCOLORS'
OF STRUCTURE <wa_dyn_table> TO <t_cellcolors>.
wa_cellcolors-fname = 'ANYFIELD2'.
wa_cellcolors-color-col = '1'.
APPEND wa_cellcolors TO <t_cellcolors>.
clear wa_cellcolors.
wa_cellcolors-fname = 'ANYFIELD3'.
wa_cellcolors-color-col = '2'.
APPEND wa_cellcolors TO <t_cellcolors>.
 
clear wa_cellcolors.
 
wa_cellcolors-fname = 'ANYFIELD4'.
 
wa_cellcolors-color-col = '6'.
APPEND wa_cellcolors TO <t_cellcolors>.
MODIFY <dyn_table> FROM <wa_dyn_table>.
 
 
endloop.
endform. "populate_dynamic_itab
form exit_program.
 
call method grid_container1->free.
call method cl_gui_cfw=>flush.
leave program.
 
endform. "exit_program
 
form refresh_disp.
 
call method grid1->refresh_table_display.
 
endform. "refresh_disp
 
form set_input.
i4 = 1.
call method grid1->set_ready_for_input
EXPORTING
i_ready_for_input = i4.
 
endform. "set_input
form switch_input.
if i4 = 1.
i4 = 0.
else.
i4 = 1.
endif.
call method grid1->set_ready_for_input
EXPORTING
i_ready_for_input = i4.
endform. "switch_input
form init_grid.
 
* Enabling the grid to edit mode,
* Set ALV controls for cell coloring table.
 
struct_grid_lset-edit = 'X'. "To enable editing in ALV
struct_grid_lset-grid_title = 'Jimbos Test'.
struct_grid_lset-ctab_fname = 'T_CELLCOLORS'.
* struct_grid_lset-sel_mode = 'D'.
 
call method grid1->set_table_for_first_display
EXPORTING
is_layout = struct_grid_lset
CHANGING
it_outtab = <dyn_table>
it_fieldcatalog = it_fldcat.
endform. "init_grid
form register_enter_event.
call method grid1->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter.
* Instantiate the event or it won't work.
create object g_event_receiver.
set handler g_event_receiver->handle_data_changed for grid1.
 
endform. "register_enter_event

<b>Or good another eg oops</b>

REPORT ZTEST1234_ALV_TOP MESSAGE-ID ZZ .

DATA: G_GRID TYPE REF TO CL_GUI_ALV_GRID.

DATA: L_VALID TYPE C,

V_FLAG,

V_DATA_CHANGE,

V_ROW TYPE LVC_S_ROW,

V_COLUMN TYPE LVC_S_COL,

V_ROW_NUM TYPE LVC_S_ROID.

"The Below Definitions Must.....

DATA:

  • Reference to document

DG_DYNDOC_ID TYPE REF TO CL_DD_DOCUMENT,

  • Reference to split container

DG_SPLITTER TYPE REF TO CL_GUI_SPLITTER_CONTAINER,

  • Reference to grid container

DG_PARENT_GRID TYPE REF TO CL_GUI_CONTAINER,

  • Reference to html container

DG_HTML_CNTRL TYPE REF TO CL_GUI_HTML_VIEWER,

  • Reference to html container

DG_PARENT_HTML TYPE REF TO CL_GUI_CONTAINER.

"up to here

----


  • CLASS lcl_event_handler DEFINITION

----


CLASS LCL_EVENT_HANDLER DEFINITION .

PUBLIC SECTION .

METHODS:

**Hot spot Handler

HANDLE_HOTSPOT_CLICK FOR EVENT HOTSPOT_CLICK OF CL_GUI_ALV_GRID

IMPORTING E_ROW_ID E_COLUMN_ID ES_ROW_NO,

**Double Click Handler

HANDLE_DOUBLE_CLICK FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID

IMPORTING E_ROW E_COLUMN ES_ROW_NO,

TOP_OF_PAGE FOR EVENT TOP_OF_PAGE "event handler

OF CL_GUI_ALV_GRID

IMPORTING E_DYNDOC_ID.

ENDCLASS. "lcl_event_handler DEFINITION

----


  • CLASS lcl_event_handler IMPLEMENTATION

----


CLASS LCL_EVENT_HANDLER IMPLEMENTATION.

*Handle Hotspot Click

METHOD HANDLE_HOTSPOT_CLICK .

CLEAR: V_ROW,V_COLUMN,V_ROW_NUM.

V_ROW = E_ROW_ID.

V_COLUMN = E_COLUMN_ID.

V_ROW_NUM = ES_ROW_NO.

MESSAGE I000 WITH V_ROW 'clicked'.

ENDMETHOD. "lcl_event_handler

*Handle Double Click

METHOD HANDLE_DOUBLE_CLICK.

ENDMETHOD. "handle_double_click

METHOD TOP_OF_PAGE. "implementation

  • Top-of-page event

PERFORM EVENT_TOP_OF_PAGE USING DG_DYNDOC_ID.

ENDMETHOD. "top_of_page

ENDCLASS. "LCL_EVENT_HANDLER IMPLEMENTATION

&----


*& Global Definitions

&----


DATA: G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,"Container1

G_HANDLER TYPE REF TO LCL_EVENT_HANDLER. "handler

DATA: OK_CODE LIKE SY-UCOMM,

SAVE_OK LIKE SY-UCOMM,

G_CONTAINER1 TYPE SCRFNAME VALUE 'TEST',

GS_LAYOUT TYPE LVC_S_LAYO.

*- Fieldcatalog for First and second Report

DATA: IT_FIELDCAT TYPE LVC_T_FCAT,

X_FIELDCAT TYPE LVC_S_FCAT,

LS_VARI TYPE DISVARIANT.

parameters: p_matnr like mara-matnr.

*----


  • START-OF_SELECTION

*----


START-OF-SELECTION.

DATA:BEGIN OF ITAB OCCURS 0,

VBELN LIKE LIKP-VBELN,

POSNR LIKE LIPS-POSNR,

CELLCOLOR TYPE LVC_T_SCOL, "required for color

DROP(10),

END OF ITAB.

SELECT VBELN

POSNR

FROM LIPS

UP TO 20 ROWS

INTO CORRESPONDING FIELDS OF TABLE ITAB.

END-OF-SELECTION.

IF NOT ITAB[] IS INITIAL.

CALL SCREEN 100.

ELSE.

MESSAGE I002 WITH 'NO DATA FOR THE SELECTION'(004).

ENDIF.

&----


*& Form CREATE_AND_INIT_ALV

&----


  • text

----


FORM CREATE_AND_INIT_ALV .

DATA: LT_EXCLUDE TYPE UI_FUNCTIONS.

"attention.....from here

"split your container here...into two parts

"create the container

CREATE OBJECT G_CUSTOM_CONTAINER

EXPORTING CONTAINER_NAME = G_CONTAINER1.

"this is for top of page

  • Create TOP-Document

CREATE OBJECT DG_DYNDOC_ID

EXPORTING STYLE = 'ALV_GRID'.

  • Create Splitter for custom_container

CREATE OBJECT DG_SPLITTER

EXPORTING PARENT = G_CUSTOM_CONTAINER

ROWS = 2

COLUMNS = 1.

  • Split the custom_container to two containers and move the reference

  • to receiving containers g_parent_html and g_parent_grid

"i am allocating the space for grid and top of page

CALL METHOD DG_SPLITTER->GET_CONTAINER

EXPORTING

ROW = 1

COLUMN = 1

RECEIVING

CONTAINER = DG_PARENT_HTML.

CALL METHOD DG_SPLITTER->GET_CONTAINER

EXPORTING

ROW = 2

COLUMN = 1

RECEIVING

CONTAINER = DG_PARENT_GRID.

"you can set the height of it

  • Set height for g_parent_html

CALL METHOD DG_SPLITTER->SET_ROW_HEIGHT

EXPORTING

ID = 1

HEIGHT = 5.

"from here as usual..you need to specify parent as splitter part

"which we alloted for grid

CREATE OBJECT G_GRID

EXPORTING I_PARENT = DG_PARENT_GRID.

  • Set a titlebar for the grid control

CLEAR GS_LAYOUT.

GS_LAYOUT-GRID_TITLE = TEXT-003.

GS_LAYOUT-ZEBRA = SPACE.

GS_LAYOUT-CWIDTH_OPT = 'X'.

GS_LAYOUT-NO_ROWMARK = 'X'.

GS_LAYOUT-CTAB_FNAME = 'CELLCOLOR'.

CALL METHOD G_GRID->REGISTER_EDIT_EVENT

EXPORTING

I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_ENTER.

CREATE OBJECT G_HANDLER.

SET HANDLER G_HANDLER->HANDLE_DOUBLE_CLICK FOR G_GRID.

SET HANDLER G_HANDLER->HANDLE_HOTSPOT_CLICK FOR G_GRID.

SET HANDLER G_HANDLER->TOP_OF_PAGE FOR G_GRID.

DATA: LS_CELLCOLOR TYPE LVC_S_SCOL. "required for color

DATA: L_INDEX TYPE SY-TABIX.

"Here i am changing the color of line 1,5,10...

"so you can change the color of font conditionally

LOOP AT ITAB.

L_INDEX = SY-TABIX.

IF L_INDEX = 1 OR L_INDEX = 5 OR L_INDEX = 10.

LS_CELLCOLOR-FNAME = 'VBELN'.

LS_CELLCOLOR-COLOR-COL = '6'.

LS_CELLCOLOR-COLOR-INT = '0'.

LS_CELLCOLOR-COLOR-INV = '1'.

APPEND LS_CELLCOLOR TO ITAB-CELLCOLOR.

MODIFY ITAB INDEX L_INDEX TRANSPORTING CELLCOLOR.

LS_CELLCOLOR-FNAME = 'POSNR'.

LS_CELLCOLOR-COLOR-COL = '6'.

LS_CELLCOLOR-COLOR-INT = '0'.

LS_CELLCOLOR-COLOR-INV = '1'.

APPEND LS_CELLCOLOR TO ITAB-CELLCOLOR.

MODIFY ITAB INDEX L_INDEX TRANSPORTING CELLCOLOR.

ENDIF.

ENDLOOP.

  • setting focus for created grid control

CALL METHOD CL_GUI_CONTROL=>SET_FOCUS

EXPORTING

CONTROL = G_GRID.

  • Build fieldcat and set editable for date and reason code

  • edit enabled. Assign a handle for the dropdown listbox.

PERFORM BUILD_FIELDCAT.

PERFORM SET_DRDN_TABLE.

  • Optionally restrict generic functions to 'change only'.

  • (The user shall not be able to add new lines).

PERFORM EXCLUDE_TB_FUNCTIONS CHANGING LT_EXCLUDE.

**Vaiant to save the layout

LS_VARI-REPORT = SY-REPID.

LS_VARI-HANDLE = SPACE.

LS_VARI-LOG_GROUP = SPACE.

LS_VARI-USERNAME = SPACE.

LS_VARI-VARIANT = SPACE.

LS_VARI-TEXT = SPACE.

LS_VARI-DEPENDVARS = SPACE.

**Calling the Method for ALV output

CALL METHOD G_GRID->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

IT_TOOLBAR_EXCLUDING = LT_EXCLUDE

IS_VARIANT = LS_VARI

IS_LAYOUT = GS_LAYOUT

I_SAVE = 'A'

CHANGING

IT_FIELDCATALOG = IT_FIELDCAT

IT_OUTTAB = ITAB[].

"do these..{

  • Initializing document

CALL METHOD DG_DYNDOC_ID->INITIALIZE_DOCUMENT.

  • Processing events

CALL METHOD G_GRID->LIST_PROCESSING_EVENTS

EXPORTING

I_EVENT_NAME = 'TOP_OF_PAGE'

I_DYNDOC_ID = DG_DYNDOC_ID.

"end }

  • Set editable cells to ready for input initially

CALL METHOD G_GRID->SET_READY_FOR_INPUT

EXPORTING

I_READY_FOR_INPUT = 1.

ENDFORM. "CREATE_AND_INIT_ALV

&----


*& Form EXCLUDE_TB_FUNCTIONS

&----


  • text

----


  • -->PT_EXCLUDE text

----


FORM EXCLUDE_TB_FUNCTIONS CHANGING PT_EXCLUDE TYPE UI_FUNCTIONS.

  • Only allow to change data not to create new entries (exclude

  • generic functions).

DATA LS_EXCLUDE TYPE UI_FUNC.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_DELETE_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_APPEND_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_INSERT_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_MOVE_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_CUT.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE_NEW_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_UNDO.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

ENDFORM. " EXCLUDE_TB_FUNCTIONS

&----


*& Form build_fieldcat

&----


  • Fieldcatalog

----


FORM BUILD_FIELDCAT .

DATA: L_POS TYPE I.

L_POS = L_POS + 1.

X_FIELDCAT-SCRTEXT_M = 'Delivery'(024).

X_FIELDCAT-FIELDNAME = 'VBELN'.

X_FIELDCAT-TABNAME = 'IT_FINAL'.

X_FIELDCAT-COL_POS = L_POS.

X_FIELDCAT-NO_ZERO = 'X'.

X_FIELDCAT-OUTPUTLEN = '10'.

X_FIELDCAT-HOTSPOT = 'X'.

APPEND X_FIELDCAT TO IT_FIELDCAT.

CLEAR X_FIELDCAT.

L_POS = L_POS + 1.

X_FIELDCAT-SCRTEXT_M = 'Item'(025).

X_FIELDCAT-FIELDNAME = 'POSNR'.

X_FIELDCAT-TABNAME = 'IT_FINAL'.

X_FIELDCAT-COL_POS = L_POS.

X_FIELDCAT-OUTPUTLEN = '5'.

APPEND X_FIELDCAT TO IT_FIELDCAT.

CLEAR X_FIELDCAT.

L_POS = L_POS + 1.

X_FIELDCAT-SCRTEXT_M = 'Drop'(025).

X_FIELDCAT-FIELDNAME = 'DROP'.

X_FIELDCAT-TABNAME = 'IT_FINAL'.

X_FIELDCAT-COL_POS = L_POS.

X_FIELDCAT-OUTPUTLEN = '5'.

X_FIELDCAT-EDIT = 'X'.

X_FIELDCAT-DRDN_HNDL = '1'.

X_FIELDCAT-DRDN_ALIAS = 'X'.

APPEND X_FIELDCAT TO IT_FIELDCAT.

CLEAR X_FIELDCAT.

ENDFORM. " build_fieldcat

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


MODULE STATUS_0100 OUTPUT.

SET PF-STATUS 'MAIN100'.

SET TITLEBAR 'MAIN100'.

IF G_CUSTOM_CONTAINER IS INITIAL.

**Initializing the grid and calling the fm to Display the O/P

PERFORM CREATE_AND_INIT_ALV.

ENDIF.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


MODULE USER_COMMAND_0100 INPUT.

CASE SY-UCOMM.

WHEN 'BACK'.

LEAVE TO SCREEN 0.

ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT

&----


*& Form SET_DRDN_TABLE

&----


  • text

----


FORM SET_DRDN_TABLE.

DATA:LT_DRAL TYPE LVC_T_DRAL,

LS_DRAL TYPE LVC_S_DRAL.

LOOP AT ITAB .

  • First listbox (handle '1').

IF SY-INDEX = 1.

LS_DRAL-HANDLE = '1'.

LS_DRAL-VALUE = ' '.

LS_DRAL-INT_VALUE = ' '.

ELSE.

LS_DRAL-HANDLE = '1'.

LS_DRAL-VALUE = ITAB-POSNR.

LS_DRAL-INT_VALUE = ITAB-POSNR.

ENDIF.

APPEND LS_DRAL TO LT_DRAL.

ENDLOOP.

**Setting the Drop down table for Reason Code

CALL METHOD G_GRID->SET_DROP_DOWN_TABLE

EXPORTING

IT_DROP_DOWN_ALIAS = LT_DRAL.

ENDFORM. " set_drdn_table

&----


*& Form EVENT_TOP_OF_PAGE

&----


  • text

----


  • -->DG_DYNDOC_ID text

----


FORM EVENT_TOP_OF_PAGE USING DG_DYNDOC_ID TYPE REF TO CL_DD_DOCUMENT.

"this is more clear.....check it

"first add text, then pass it to comentry write fm

DATA : DL_TEXT(255) TYPE C. "Text

  • Populating header to top-of-page

CALL METHOD DG_DYNDOC_ID->ADD_TEXT

EXPORTING

TEXT = 'Test Report'

SAP_STYLE = CL_DD_AREA=>HEADING.

  • Add new-line

CALL METHOD DG_DYNDOC_ID->NEW_LINE.

CLEAR : DL_TEXT.

  • Move program ID

CONCATENATE 'Program Name :' SY-REPID

INTO DL_TEXT SEPARATED BY SPACE.

  • Add Program Name to Document

PERFORM ADD_TEXT USING DL_TEXT.

  • Add new-line

CALL METHOD DG_DYNDOC_ID->NEW_LINE.

CLEAR : DL_TEXT.

CONCATENATE 'MATNR :' P_MATNR

INTO DL_TEXT SEPARATED BY SPACE.

  • Add Parameter to Document

PERFORM ADD_TEXT USING DL_TEXT.

  • Add new-line

CALL METHOD DG_DYNDOC_ID->NEW_LINE.

CLEAR : DL_TEXT.

  • Move User ID

CONCATENATE 'User ID :' SY-UNAME INTO DL_TEXT SEPARATED BY SPACE

.

  • Add User ID to Document

PERFORM ADD_TEXT USING DL_TEXT.

  • Add new-line

CALL METHOD DG_DYNDOC_ID->NEW_LINE.

CLEAR : DL_TEXT.

  • Move Client

CONCATENATE 'Client :' SY-MANDT INTO DL_TEXT SEPARATED BY SPACE.

  • Add Client to Document

PERFORM ADD_TEXT USING DL_TEXT.

  • Add new-line

CALL METHOD DG_DYNDOC_ID->NEW_LINE.

CLEAR : DL_TEXT.

  • Move date

WRITE SY-DATUM TO DL_TEXT.

CONCATENATE 'Date :' DL_TEXT INTO DL_TEXT SEPARATED BY SPACE.

  • Add Date to Document

PERFORM ADD_TEXT USING DL_TEXT.

  • Add new-line

CALL METHOD DG_DYNDOC_ID->NEW_LINE.

CLEAR : DL_TEXT.

  • Move time

WRITE SY-UZEIT TO DL_TEXT.

CONCATENATE 'Time :' DL_TEXT INTO DL_TEXT SEPARATED BY SPACE.

  • Add Time to Document

PERFORM ADD_TEXT USING DL_TEXT.

  • Add new-line

CALL METHOD DG_DYNDOC_ID->NEW_LINE.

  • Populating data to html control

PERFORM HTML.

ENDFORM. " EVENT_TOP_OF_PAGE

&----


*& Form ADD_TEXT

&----


  • To add Text

----


FORM ADD_TEXT USING P_TEXT TYPE SDYDO_TEXT_ELEMENT.

  • Adding text

CALL METHOD DG_DYNDOC_ID->ADD_TEXT

EXPORTING

TEXT = P_TEXT

SAP_EMPHASIS = CL_DD_AREA=>HEADING.

ENDFORM. " ADD_TEXT

&----


*& Form HTML

&----


  • text

----


FORM HTML.

DATA : DL_LENGTH TYPE I, " Length

DL_BACKGROUND_ID TYPE SDYDO_KEY VALUE SPACE. " Background_id

  • Creating html control

IF DG_HTML_CNTRL IS INITIAL.

CREATE OBJECT DG_HTML_CNTRL

EXPORTING

PARENT = DG_PARENT_HTML.

ENDIF.

  • Reuse_alv_grid_commentary_set

CALL FUNCTION 'REUSE_ALV_GRID_COMMENTARY_SET'

EXPORTING

DOCUMENT = DG_DYNDOC_ID

BOTTOM = SPACE

IMPORTING

LENGTH = DL_LENGTH.

  • Get TOP->HTML_TABLE ready

CALL METHOD DG_DYNDOC_ID->MERGE_DOCUMENT.

  • Set wallpaper

CALL METHOD DG_DYNDOC_ID->SET_DOCUMENT_BACKGROUND

EXPORTING

PICTURE_ID = DL_BACKGROUND_ID.

  • Connect TOP document to HTML-Control

DG_DYNDOC_ID->HTML_CONTROL = DG_HTML_CNTRL.

  • Display TOP document

CALL METHOD DG_DYNDOC_ID->DISPLAY_DOCUMENT

EXPORTING

REUSE_CONTROL = 'X'

PARENT = DG_PARENT_HTML

EXCEPTIONS

HTML_DISPLAY_ERROR = 1.

IF SY-SUBRC NE 0.

MESSAGE I999 WITH 'Error in displaying top-of-page'(036).

ENDIF.

ENDFORM. " HTML[/code]

<b>reward pts if found usefull :)</b>

Regards

Sathish

3 REPLIES 3

Former Member
0 Kudos

Hi,

See following code :

http://www.sap-basis-abap.com/sapabap01.htm

Reward points if helpful

Regards.

Srikanta Gope

Former Member
0 Kudos

Hi ,


PROGRAM zdynfieldcat.
class zcltest definition deferred. "For field symbol reference.
 
* The ultimate ALV program
 
* this program demos the following
* 1) Build Dynamic ITAB with fields NOT defined in DDIC
* 2) Build Dynamic FieldCat. Table structure is obtained *via
* the new RTTI functionality
* 3) Add the CELL colour table as a deep structure to our dynamic table
* so we can colour individual cells.
* 4) Inherit a class so protected attributes
* of class cl_gui_alv_grid
* can be accessed
* 5) Add events so we can can program functionality when * the user presses 
* the ENTER key,
* or selects an action from the toolbar.
* 6) Display one line of a grid from our dynamic table with some cells coloured.
* 6) Set the Grid editable.
* 7) if user enters data then colou
* cells of entered data.
* 😎 show contents of new table 
* after all data has been entered.
 
* To use program copy the source and
* Create a blank screen 100 with a
* custom container called CCONTAINER1.
* with the screen logic shown below
* As we are using EVENTS we actually
* don't need a PAI module so it
* doesn't contain any code.
 
*PROCESS BEFORE OUTPUT.
* MODULE STATUS_0100.
*
*PROCESS AFTER INPUT.
* MODULE USER_COMMAND_0100
*

 
* Define field symbols as these can't be defined in classes
 
field-symbols: <dyn_table> type standard table,
<g2> type ref to zcltest,
<g1> type ref to cl_gui_custom_container,
<data_changed> type ref to cl_alv_changed_data_protocol,
<actual_tab> type standard table,
<outtab> type table,
<fs1> type ANY,
<FS2> TYPE TABLE,
<fs3> type table,
<fs4> type table,
<fs5> type table,
<wa_dyn_table> TYPE ANY,
<w_field1> type any,
<w_field2> type any,
<w_field3> type any,
<w_field4> type any,
<w_field5> type any,
<t_colours> type any,
<t_clrs> type line of lvc_t_scol,
<t_cellcolors> TYPE lvc_t_scol,
<t_cellcolors1> type lvc_t_scol.
 
 
class zcltest definition inheriting from cl_gui_alv_grid.
 
public section.
 
types: g4 type ref to cl_gui_custom_container.
types: g3 type ref to cl_alv_changed_data_protocol.
data: i_parent type g4,
lr_rtti_struc TYPE REF TO cl_abap_structdescr, "RTTI
zog like line of lr_rtti_struc->components. "RTTI
types: struc like zog.
types: struc1 type table of struc.
 
methods:
constructor
importing i_parent type g4,
disp_tab
importing p_er_data_changed type g3,
 
create_dynamic_fcat
importing zogt type struc1
exporting it_fldcat type lvc_t_fcat.
Protected section.
 
private section.
data: stab type ref to data,
wa_it_fldcat type lvc_s_fcat,
c_index type sy-index,
lt_good_cells type lvc_t_modi,
ls_good type lvc_s_modi,
ls_good_cells type lvc_s_modi,
et_good_cells type LVC_T_MODI,
e_row type i,
e_value type c,
e_col type i,
es_row_id type lvc_s_row,
es_col_id type lvc_s_col,
es_row_no type LVC_S_ROID,
wa_cellcolors TYPE LINE OF lvc_t_scol,
wa_modified_cells type line of LVC_T_MODI,
es_layout type LVC_S_LAYO.
 
endclass.
 
class zcltest implementation.
METHOD constructor.
 
CALL METHOD super->constructor
EXPORTING
i_appl_events = 'X'
i_parent = i_parent.
 
endmethod.
 
method disp_tab.
* mt_outtab is the data table held 
* as a protected attribute
* in class cl_gui_alv_grid.
assign me->mt_outtab->* TO <outtab>. "Original data
assign p_er_data_changed->mp_mod_rows TO <FS1>.
stab = p_er_data_changed->mp_mod_rows.
assign p_er_data_changed->mt_inserted_rows to <fs3>.
assign p_er_data_changed->mt_deleted_rows to <fs4>.
assign p_er_data_changed->mt_mod_cells to <fs5>.
assign stab->* TO <fs2>.
 
[code] 
* some functions --chose what you want
 
* This method gets the last (or current cell)
call method me->get_current_cell
importing e_row = e_row
e_value = e_value
e_col = e_col
es_row_id = es_row_id
es_col_id = es_col_id
es_row_no = es_row_no.
 
* For an example let's change the colour
* of any data entered including
* inserted rows.
*
* Proceed as follows
*
 
* read table <fs5> which gives us the
* row number and field name of
* the modified cell(s) including inserted rows
*
* For deleted rows we don't have to do anything
*
* Update the cell's colour characteristic table
 
* remember we added a colour table
* to the dynamic data table we built
* note that it's a DEEP structure.
 
* On REFRESH the alv will look at the
* updated colour table for the cells.
* we don't actually have to modify the data table but just the colour
* table
 
* recapping
 
* 1) Create your Field catalog WITHOUT 
* the colour table for the ALV grid display
* 2) Add the colour table to a 2nd field catalog
* which you use to build the actual data
* dynamic table
* 3) add the name of the colour table to the layout
* (struct_grid_lset-ctab_fname 
* = 'T_CELLCOLORS')
 
* Refresh Grid and new cell colours will work
 
 
* now let's change the colour of the selected cells.
 
ASSIGN COMPONENT 'T_CELLCOLORS'
OF STRUCTURE <wa_dyn_table> TO <t_cellcolors1>.
loop at <fs5> into wa_modified_cells.
 
 
read table <dyn_table> into <wa_dyn_table> index wa_modified_cells-row_id.
case sy-subrc.
when 0.
read table <t_cellcolors1> into wa_cellcolors
with key fname = wa_modified_cells-fieldname.
if sy-subrc = 0.
if not wa_modified_cells-value is initial.
wa_cellcolors-fname = wa_modified_cells-fieldname.
 
wa_cellcolors-color-col = '5'.
MODIFY <t_cellcolors1> from wa_cellcolors .
endif.
else.
if not wa_modified_cells-value is initial.
wa_cellcolors-fname = wa_modified_cells-fieldname.
 
wa_cellcolors-color-col = '5'.
append wa_cellcolors to <t_cellcolors1>.
endif.
endif.
 
when others.
loop at <fs2> into <wa_dyn_table>.
append <wa_dyn_table> to <dyn_table>.
endloop.
read table <dyn_table> into <wa_dyn_table> index wa_modified_cells-row_id.
clear wa_cellcolors.
if not wa_modified_cells-value is initial.
 
wa_cellcolors-fname = wa_modified_cells-fieldname.
 
wa_cellcolors-color-col = 5.
append wa_cellcolors to <t_cellcolors1>.
endif.
endcase.
 
 
MODIFY <dyn_table> FROM <wa_dyn_table> index wa_modified_cells-row_id.
 
 
endloop.
 
 
endmethod.
 
method create_dynamic_fcat.
loop at zogt into zog.
c_index = c_index + 1.
clear wa_it_fldcat.
 
wa_it_fldcat-fieldname = zog-name .
wa_it_fldcat-datatype = zog-type_kind.
wa_it_fldcat-inttype = zog-type_kind.
wa_it_fldcat-intlen = zog-length.
wa_it_fldcat-decimals = zog-decimals.
wa_it_fldcat-coltext = zog-name.
wa_it_fldcat-lowercase = 'X'.
append wa_it_fldcat to it_fldcat .
endloop.
endmethod. "create_dynamic_fcat
 
endclass. "zcltest IMPLEMENTATION
 
class lcl_grid_event_receiver definition.
 
public section.
data: data_c type ref to cl_alv_changed_data_protocol.
 
methods:
handle_data_changed
for event data_changed of zcltest
importing er_data_changed,
 
handle_data_changed_finished
for event data_changed_finished of zcltest
importing E_MODIFIED
ET_GOOD_CELLS,
 
 
toolbar
for event toolbar of zcltest
importing e_object
e_interactive,
 
user_command
for event user_command of zcltest
importing e_ucomm.
 
endclass.
 
 
class lcl_grid_event_receiver implementation.
method handle_data_changed.
 
call method <g2>->disp_tab
EXPORTING
p_er_data_changed = er_data_changed.
 
endmethod. "handle_data_changed
 
 
 
method handle_data_changed_finished.
 
* at this point our data dynamic table
* <dyn_table> now contains the actual updated values from
* the grid including the cell color info create in the on data changed
* event method call AND IN THE CORRECT ORDER.
* use this method to update say SAP data bases or other
* data from the GRID entered data.
*
* Data entry validation can be done here as well.
*
* Enter your own code here.
.
endmethod.
 
method toolbar.
 
 
data : ls_toolbar type stb_button.
clear ls_toolbar.
<b>move 0 to ls_toolbar-butn_type.
<b>move 'EDIT' to ls_toolbar-function.
move space to ls_toolbar-disabled.
move 'Edit' to ls_toolbar-text.</b>
move icon_change_text to ls_toolbar-icon.
move 'Click2Edit' to ls_toolbar-quickinfo.
append ls_toolbar to e_object->mt_toolbar.</b>
 
clear ls_toolbar.
move 0 to ls_toolbar-butn_type.
move 'UPDA' to ls_toolbar-function.
move space to ls_toolbar-disabled.
move 'Update' to ls_toolbar-text.
move icon_system_save to ls_toolbar-icon.
move 'Click2Update' to ls_toolbar-quickinfo.
append ls_toolbar to e_object->mt_toolbar.
 
clear ls_toolbar.
move 0 to ls_toolbar-butn_type.
move 'EXIT' to ls_toolbar-function.
move space to ls_toolbar-disabled.
move 'Exit' to ls_toolbar-text.
move icon_system_end to ls_toolbar-icon.
move 'Click2Exit' to ls_toolbar-quickinfo.
append ls_toolbar to e_object->mt_toolbar.
 
 
endmethod. "toolbar
 
method user_command.
 
case e_ucomm .
when 'EDIT'. "From Tool bar
perform set_input.
perform refresh_disp.
 
when 'UPDA'. "From Tool bar
perform refresh_disp.
 
when 'EXIT'. "From Tool bar
leave program.
 
endcase.
 
endmethod. "user_command
endclass. "lcl_grid_event_receiver IMPLEMENTATION
 
 
* program data
*
include <icon>.
* define any old internal structure NOT in DDIC
types: begin of s_elements,
anyfield1(20) type c,
anyfield2(20) type c,
anyfield3(20) type c,
anyfield4(20) type c,
anyfield5(11) type n,
end of s_elements.
 
data: wa_element type s_elements,
wa_cellcolors TYPE LINE OF lvc_t_scol,
 
wa_data type s_elements,
wa_dyn_table TYPE REF TO data.
 
 
* Note new RTTI functionality allows field detail retrieval
* at runtime for dynamic tables.
data:
grid1 type ref to zcltest,
grid_handler type ref to lcl_grid_event_receiver,
c_dec2 type s_elements-anyfield5,
wa_it_fldcat type lvc_s_fcat,
it_fldcat type lvc_t_fcat,
it_fldcat1 type lvc_t_fcat,
lr_rtti_struc TYPE REF TO cl_abap_structdescr, "RTTI
lt_comp TYPE cl_abap_structdescr=>component_table,"RTTI
ls_comp LIKE LINE OF lt_comp, "RTTI
zog like line of lr_rtti_struc->components, "RTTI
struct_grid_lset type lvc_s_layo,
l_valid type c,
new_table type ref to data.
types: struc like zog,
col_tab type lvc_t_scol.
 
 
data: zogt type table of struc,
grid_container1 type ref to cl_gui_custom_container,
g_event_receiver type ref to lcl_grid_event_receiver,
ok_code like sy-ucomm,
t_colours type table of col_tab,
i4 type int4.
 
start-of-selection.
call screen 100.
module status_0100 output.
 
if grid_container1 is initial.
 
create object grid_container1
exporting
container_name = 'CCONTAINER1'.
assign grid_container1 to <g1>.
create object grid1
exporting i_parent = grid_container1.
 
* we need reference to this instance so we can use
* Methods etc of zcltest class and alv (superclass)
* in our event receiver class.
 
assign grid1 to <g2>.
create object grid_handler.
 
* set handler for events
 
set handler:
grid_handler->user_command for grid1,
grid_handler->toolbar for grid1,
grid_handler->handle_data_changed_finished for grid1.
perform register_enter_event. "For ENTER key press
 
 
* Get the Internal table structure
lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( wa_data ).
 
* Build field catalog just use basic data here
* colour specific columns as well
zogt[] = lr_rtti_struc->components.
 
call method grid1->create_dynamic_fcat
EXPORTING
zogt = zogt
IMPORTING
it_fldcat = it_fldcat.
* Save field cat without cell info deep structure for Grid
it_fldcat1[] = it_fldcat.
* now add deep structure for cell colour to field catalog
* for dynamic table creation
assign t_colours to <t_colours>.
wa_it_fldcat-fieldname = 'T_CELLCOLORS'.
wa_it_fldcat-ref_field = 'COLTAB'.
wa_it_fldcat-ref_table = 'CALENDAR_TYPE'.
* use this table as it has a DDIC built in ref structure for cell colour info
 
APPEND wa_it_fldcat TO it_fldcat1.
* Create dynamic internal table and assign to field symbol.
* Use dynamic field catalog just built.
 
call method cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fldcat1
IMPORTING
ep_table = new_table.
 
perform populate_dynamic_itab.
perform init_grid.
i4 = 0.
call method grid1->set_ready_for_input
EXPORTING
i_ready_for_input = i4.
endif.
.
perform refresh_disp.
 
endmodule. "status_0100 OUTPUT
 
module user_command_0100 input.
*
*PAI not needed in OO ALV anymore as User Commands are handled as events
*in method user_command.
*
*we can also get control if the Data entered and the ENTER is pressed by
*raising an event.
* Control then returns to method handle_data_changed.
endmodule. "user_command_0100 INPUT
 
form populate_dynamic_itab.
* load up a line of the dynamic table
c_dec2 = c_dec2 + 11.
assign new_table->* to <dyn_table>.
 
create data wa_dyn_table like line of <dyn_table>.
assign wa_dyn_table->* to <wa_dyn_table>.
 
assign component 'ANYFIELD1' of structure <wa_dyn_table> to <w_field1>
.
<w_field1> = 'Tabbies'.
assign component 'ANYFIELD2' of structure <wa_dyn_table> to
<w_field2>.
<w_field2> = 'Ger Shepards'.
assign component 'ANYFIELD3' of structure <wa_dyn_table> to <w_field3>.
<w_field3> = 'White Mice'.
 
assign component 'ANYFIELD4' of structure <wa_dyn_table> to <w_field4>.
<w_field4> = 'Any old Text'.
 
assign component 'ANYFIELD5' of structure <wa_dyn_table> to <w_field5>.
<w_field5> = c_dec2..
APPEND <wa_dyn_table> TO <dyn_table>.
 
 
loop at <dyn_table> into <wa_dyn_table>.
clear wa_cellcolors.
 
ASSIGN COMPONENT 'T_CELLCOLORS'
OF STRUCTURE <wa_dyn_table> TO <t_cellcolors>.
wa_cellcolors-fname = 'ANYFIELD2'.
wa_cellcolors-color-col = '1'.
APPEND wa_cellcolors TO <t_cellcolors>.
clear wa_cellcolors.
wa_cellcolors-fname = 'ANYFIELD3'.
wa_cellcolors-color-col = '2'.
APPEND wa_cellcolors TO <t_cellcolors>.
 
clear wa_cellcolors.
 
wa_cellcolors-fname = 'ANYFIELD4'.
 
wa_cellcolors-color-col = '6'.
APPEND wa_cellcolors TO <t_cellcolors>.
MODIFY <dyn_table> FROM <wa_dyn_table>.
 
 
endloop.
endform. "populate_dynamic_itab
form exit_program.
 
call method grid_container1->free.
call method cl_gui_cfw=>flush.
leave program.
 
endform. "exit_program
 
form refresh_disp.
 
call method grid1->refresh_table_display.
 
endform. "refresh_disp
 
form set_input.
i4 = 1.
call method grid1->set_ready_for_input
EXPORTING
i_ready_for_input = i4.
 
endform. "set_input
form switch_input.
if i4 = 1.
i4 = 0.
else.
i4 = 1.
endif.
call method grid1->set_ready_for_input
EXPORTING
i_ready_for_input = i4.
endform. "switch_input
form init_grid.
 
* Enabling the grid to edit mode,
* Set ALV controls for cell coloring table.
 
struct_grid_lset-edit = 'X'. "To enable editing in ALV
struct_grid_lset-grid_title = 'Jimbos Test'.
struct_grid_lset-ctab_fname = 'T_CELLCOLORS'.
* struct_grid_lset-sel_mode = 'D'.
 
call method grid1->set_table_for_first_display
EXPORTING
is_layout = struct_grid_lset
CHANGING
it_outtab = <dyn_table>
it_fieldcatalog = it_fldcat.
endform. "init_grid
form register_enter_event.
call method grid1->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter.
* Instantiate the event or it won't work.
create object g_event_receiver.
set handler g_event_receiver->handle_data_changed for grid1.
 
endform. "register_enter_event

<b>Or good another eg oops</b>

REPORT ZTEST1234_ALV_TOP MESSAGE-ID ZZ .

DATA: G_GRID TYPE REF TO CL_GUI_ALV_GRID.

DATA: L_VALID TYPE C,

V_FLAG,

V_DATA_CHANGE,

V_ROW TYPE LVC_S_ROW,

V_COLUMN TYPE LVC_S_COL,

V_ROW_NUM TYPE LVC_S_ROID.

"The Below Definitions Must.....

DATA:

  • Reference to document

DG_DYNDOC_ID TYPE REF TO CL_DD_DOCUMENT,

  • Reference to split container

DG_SPLITTER TYPE REF TO CL_GUI_SPLITTER_CONTAINER,

  • Reference to grid container

DG_PARENT_GRID TYPE REF TO CL_GUI_CONTAINER,

  • Reference to html container

DG_HTML_CNTRL TYPE REF TO CL_GUI_HTML_VIEWER,

  • Reference to html container

DG_PARENT_HTML TYPE REF TO CL_GUI_CONTAINER.

"up to here

----


  • CLASS lcl_event_handler DEFINITION

----


CLASS LCL_EVENT_HANDLER DEFINITION .

PUBLIC SECTION .

METHODS:

**Hot spot Handler

HANDLE_HOTSPOT_CLICK FOR EVENT HOTSPOT_CLICK OF CL_GUI_ALV_GRID

IMPORTING E_ROW_ID E_COLUMN_ID ES_ROW_NO,

**Double Click Handler

HANDLE_DOUBLE_CLICK FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID

IMPORTING E_ROW E_COLUMN ES_ROW_NO,

TOP_OF_PAGE FOR EVENT TOP_OF_PAGE "event handler

OF CL_GUI_ALV_GRID

IMPORTING E_DYNDOC_ID.

ENDCLASS. "lcl_event_handler DEFINITION

----


  • CLASS lcl_event_handler IMPLEMENTATION

----


CLASS LCL_EVENT_HANDLER IMPLEMENTATION.

*Handle Hotspot Click

METHOD HANDLE_HOTSPOT_CLICK .

CLEAR: V_ROW,V_COLUMN,V_ROW_NUM.

V_ROW = E_ROW_ID.

V_COLUMN = E_COLUMN_ID.

V_ROW_NUM = ES_ROW_NO.

MESSAGE I000 WITH V_ROW 'clicked'.

ENDMETHOD. "lcl_event_handler

*Handle Double Click

METHOD HANDLE_DOUBLE_CLICK.

ENDMETHOD. "handle_double_click

METHOD TOP_OF_PAGE. "implementation

  • Top-of-page event

PERFORM EVENT_TOP_OF_PAGE USING DG_DYNDOC_ID.

ENDMETHOD. "top_of_page

ENDCLASS. "LCL_EVENT_HANDLER IMPLEMENTATION

&----


*& Global Definitions

&----


DATA: G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,"Container1

G_HANDLER TYPE REF TO LCL_EVENT_HANDLER. "handler

DATA: OK_CODE LIKE SY-UCOMM,

SAVE_OK LIKE SY-UCOMM,

G_CONTAINER1 TYPE SCRFNAME VALUE 'TEST',

GS_LAYOUT TYPE LVC_S_LAYO.

*- Fieldcatalog for First and second Report

DATA: IT_FIELDCAT TYPE LVC_T_FCAT,

X_FIELDCAT TYPE LVC_S_FCAT,

LS_VARI TYPE DISVARIANT.

parameters: p_matnr like mara-matnr.

*----


  • START-OF_SELECTION

*----


START-OF-SELECTION.

DATA:BEGIN OF ITAB OCCURS 0,

VBELN LIKE LIKP-VBELN,

POSNR LIKE LIPS-POSNR,

CELLCOLOR TYPE LVC_T_SCOL, "required for color

DROP(10),

END OF ITAB.

SELECT VBELN

POSNR

FROM LIPS

UP TO 20 ROWS

INTO CORRESPONDING FIELDS OF TABLE ITAB.

END-OF-SELECTION.

IF NOT ITAB[] IS INITIAL.

CALL SCREEN 100.

ELSE.

MESSAGE I002 WITH 'NO DATA FOR THE SELECTION'(004).

ENDIF.

&----


*& Form CREATE_AND_INIT_ALV

&----


  • text

----


FORM CREATE_AND_INIT_ALV .

DATA: LT_EXCLUDE TYPE UI_FUNCTIONS.

"attention.....from here

"split your container here...into two parts

"create the container

CREATE OBJECT G_CUSTOM_CONTAINER

EXPORTING CONTAINER_NAME = G_CONTAINER1.

"this is for top of page

  • Create TOP-Document

CREATE OBJECT DG_DYNDOC_ID

EXPORTING STYLE = 'ALV_GRID'.

  • Create Splitter for custom_container

CREATE OBJECT DG_SPLITTER

EXPORTING PARENT = G_CUSTOM_CONTAINER

ROWS = 2

COLUMNS = 1.

  • Split the custom_container to two containers and move the reference

  • to receiving containers g_parent_html and g_parent_grid

"i am allocating the space for grid and top of page

CALL METHOD DG_SPLITTER->GET_CONTAINER

EXPORTING

ROW = 1

COLUMN = 1

RECEIVING

CONTAINER = DG_PARENT_HTML.

CALL METHOD DG_SPLITTER->GET_CONTAINER

EXPORTING

ROW = 2

COLUMN = 1

RECEIVING

CONTAINER = DG_PARENT_GRID.

"you can set the height of it

  • Set height for g_parent_html

CALL METHOD DG_SPLITTER->SET_ROW_HEIGHT

EXPORTING

ID = 1

HEIGHT = 5.

"from here as usual..you need to specify parent as splitter part

"which we alloted for grid

CREATE OBJECT G_GRID

EXPORTING I_PARENT = DG_PARENT_GRID.

  • Set a titlebar for the grid control

CLEAR GS_LAYOUT.

GS_LAYOUT-GRID_TITLE = TEXT-003.

GS_LAYOUT-ZEBRA = SPACE.

GS_LAYOUT-CWIDTH_OPT = 'X'.

GS_LAYOUT-NO_ROWMARK = 'X'.

GS_LAYOUT-CTAB_FNAME = 'CELLCOLOR'.

CALL METHOD G_GRID->REGISTER_EDIT_EVENT

EXPORTING

I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_ENTER.

CREATE OBJECT G_HANDLER.

SET HANDLER G_HANDLER->HANDLE_DOUBLE_CLICK FOR G_GRID.

SET HANDLER G_HANDLER->HANDLE_HOTSPOT_CLICK FOR G_GRID.

SET HANDLER G_HANDLER->TOP_OF_PAGE FOR G_GRID.

DATA: LS_CELLCOLOR TYPE LVC_S_SCOL. "required for color

DATA: L_INDEX TYPE SY-TABIX.

"Here i am changing the color of line 1,5,10...

"so you can change the color of font conditionally

LOOP AT ITAB.

L_INDEX = SY-TABIX.

IF L_INDEX = 1 OR L_INDEX = 5 OR L_INDEX = 10.

LS_CELLCOLOR-FNAME = 'VBELN'.

LS_CELLCOLOR-COLOR-COL = '6'.

LS_CELLCOLOR-COLOR-INT = '0'.

LS_CELLCOLOR-COLOR-INV = '1'.

APPEND LS_CELLCOLOR TO ITAB-CELLCOLOR.

MODIFY ITAB INDEX L_INDEX TRANSPORTING CELLCOLOR.

LS_CELLCOLOR-FNAME = 'POSNR'.

LS_CELLCOLOR-COLOR-COL = '6'.

LS_CELLCOLOR-COLOR-INT = '0'.

LS_CELLCOLOR-COLOR-INV = '1'.

APPEND LS_CELLCOLOR TO ITAB-CELLCOLOR.

MODIFY ITAB INDEX L_INDEX TRANSPORTING CELLCOLOR.

ENDIF.

ENDLOOP.

  • setting focus for created grid control

CALL METHOD CL_GUI_CONTROL=>SET_FOCUS

EXPORTING

CONTROL = G_GRID.

  • Build fieldcat and set editable for date and reason code

  • edit enabled. Assign a handle for the dropdown listbox.

PERFORM BUILD_FIELDCAT.

PERFORM SET_DRDN_TABLE.

  • Optionally restrict generic functions to 'change only'.

  • (The user shall not be able to add new lines).

PERFORM EXCLUDE_TB_FUNCTIONS CHANGING LT_EXCLUDE.

**Vaiant to save the layout

LS_VARI-REPORT = SY-REPID.

LS_VARI-HANDLE = SPACE.

LS_VARI-LOG_GROUP = SPACE.

LS_VARI-USERNAME = SPACE.

LS_VARI-VARIANT = SPACE.

LS_VARI-TEXT = SPACE.

LS_VARI-DEPENDVARS = SPACE.

**Calling the Method for ALV output

CALL METHOD G_GRID->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

IT_TOOLBAR_EXCLUDING = LT_EXCLUDE

IS_VARIANT = LS_VARI

IS_LAYOUT = GS_LAYOUT

I_SAVE = 'A'

CHANGING

IT_FIELDCATALOG = IT_FIELDCAT

IT_OUTTAB = ITAB[].

"do these..{

  • Initializing document

CALL METHOD DG_DYNDOC_ID->INITIALIZE_DOCUMENT.

  • Processing events

CALL METHOD G_GRID->LIST_PROCESSING_EVENTS

EXPORTING

I_EVENT_NAME = 'TOP_OF_PAGE'

I_DYNDOC_ID = DG_DYNDOC_ID.

"end }

  • Set editable cells to ready for input initially

CALL METHOD G_GRID->SET_READY_FOR_INPUT

EXPORTING

I_READY_FOR_INPUT = 1.

ENDFORM. "CREATE_AND_INIT_ALV

&----


*& Form EXCLUDE_TB_FUNCTIONS

&----


  • text

----


  • -->PT_EXCLUDE text

----


FORM EXCLUDE_TB_FUNCTIONS CHANGING PT_EXCLUDE TYPE UI_FUNCTIONS.

  • Only allow to change data not to create new entries (exclude

  • generic functions).

DATA LS_EXCLUDE TYPE UI_FUNC.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_DELETE_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_APPEND_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_INSERT_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_MOVE_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_CUT.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE_NEW_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_UNDO.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

ENDFORM. " EXCLUDE_TB_FUNCTIONS

&----


*& Form build_fieldcat

&----


  • Fieldcatalog

----


FORM BUILD_FIELDCAT .

DATA: L_POS TYPE I.

L_POS = L_POS + 1.

X_FIELDCAT-SCRTEXT_M = 'Delivery'(024).

X_FIELDCAT-FIELDNAME = 'VBELN'.

X_FIELDCAT-TABNAME = 'IT_FINAL'.

X_FIELDCAT-COL_POS = L_POS.

X_FIELDCAT-NO_ZERO = 'X'.

X_FIELDCAT-OUTPUTLEN = '10'.

X_FIELDCAT-HOTSPOT = 'X'.

APPEND X_FIELDCAT TO IT_FIELDCAT.

CLEAR X_FIELDCAT.

L_POS = L_POS + 1.

X_FIELDCAT-SCRTEXT_M = 'Item'(025).

X_FIELDCAT-FIELDNAME = 'POSNR'.

X_FIELDCAT-TABNAME = 'IT_FINAL'.

X_FIELDCAT-COL_POS = L_POS.

X_FIELDCAT-OUTPUTLEN = '5'.

APPEND X_FIELDCAT TO IT_FIELDCAT.

CLEAR X_FIELDCAT.

L_POS = L_POS + 1.

X_FIELDCAT-SCRTEXT_M = 'Drop'(025).

X_FIELDCAT-FIELDNAME = 'DROP'.

X_FIELDCAT-TABNAME = 'IT_FINAL'.

X_FIELDCAT-COL_POS = L_POS.

X_FIELDCAT-OUTPUTLEN = '5'.

X_FIELDCAT-EDIT = 'X'.

X_FIELDCAT-DRDN_HNDL = '1'.

X_FIELDCAT-DRDN_ALIAS = 'X'.

APPEND X_FIELDCAT TO IT_FIELDCAT.

CLEAR X_FIELDCAT.

ENDFORM. " build_fieldcat

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


MODULE STATUS_0100 OUTPUT.

SET PF-STATUS 'MAIN100'.

SET TITLEBAR 'MAIN100'.

IF G_CUSTOM_CONTAINER IS INITIAL.

**Initializing the grid and calling the fm to Display the O/P

PERFORM CREATE_AND_INIT_ALV.

ENDIF.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


MODULE USER_COMMAND_0100 INPUT.

CASE SY-UCOMM.

WHEN 'BACK'.

LEAVE TO SCREEN 0.

ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT

&----


*& Form SET_DRDN_TABLE

&----


  • text

----


FORM SET_DRDN_TABLE.

DATA:LT_DRAL TYPE LVC_T_DRAL,

LS_DRAL TYPE LVC_S_DRAL.

LOOP AT ITAB .

  • First listbox (handle '1').

IF SY-INDEX = 1.

LS_DRAL-HANDLE = '1'.

LS_DRAL-VALUE = ' '.

LS_DRAL-INT_VALUE = ' '.

ELSE.

LS_DRAL-HANDLE = '1'.

LS_DRAL-VALUE = ITAB-POSNR.

LS_DRAL-INT_VALUE = ITAB-POSNR.

ENDIF.

APPEND LS_DRAL TO LT_DRAL.

ENDLOOP.

**Setting the Drop down table for Reason Code

CALL METHOD G_GRID->SET_DROP_DOWN_TABLE

EXPORTING

IT_DROP_DOWN_ALIAS = LT_DRAL.

ENDFORM. " set_drdn_table

&----


*& Form EVENT_TOP_OF_PAGE

&----


  • text

----


  • -->DG_DYNDOC_ID text

----


FORM EVENT_TOP_OF_PAGE USING DG_DYNDOC_ID TYPE REF TO CL_DD_DOCUMENT.

"this is more clear.....check it

"first add text, then pass it to comentry write fm

DATA : DL_TEXT(255) TYPE C. "Text

  • Populating header to top-of-page

CALL METHOD DG_DYNDOC_ID->ADD_TEXT

EXPORTING

TEXT = 'Test Report'

SAP_STYLE = CL_DD_AREA=>HEADING.

  • Add new-line

CALL METHOD DG_DYNDOC_ID->NEW_LINE.

CLEAR : DL_TEXT.

  • Move program ID

CONCATENATE 'Program Name :' SY-REPID

INTO DL_TEXT SEPARATED BY SPACE.

  • Add Program Name to Document

PERFORM ADD_TEXT USING DL_TEXT.

  • Add new-line

CALL METHOD DG_DYNDOC_ID->NEW_LINE.

CLEAR : DL_TEXT.

CONCATENATE 'MATNR :' P_MATNR

INTO DL_TEXT SEPARATED BY SPACE.

  • Add Parameter to Document

PERFORM ADD_TEXT USING DL_TEXT.

  • Add new-line

CALL METHOD DG_DYNDOC_ID->NEW_LINE.

CLEAR : DL_TEXT.

  • Move User ID

CONCATENATE 'User ID :' SY-UNAME INTO DL_TEXT SEPARATED BY SPACE

.

  • Add User ID to Document

PERFORM ADD_TEXT USING DL_TEXT.

  • Add new-line

CALL METHOD DG_DYNDOC_ID->NEW_LINE.

CLEAR : DL_TEXT.

  • Move Client

CONCATENATE 'Client :' SY-MANDT INTO DL_TEXT SEPARATED BY SPACE.

  • Add Client to Document

PERFORM ADD_TEXT USING DL_TEXT.

  • Add new-line

CALL METHOD DG_DYNDOC_ID->NEW_LINE.

CLEAR : DL_TEXT.

  • Move date

WRITE SY-DATUM TO DL_TEXT.

CONCATENATE 'Date :' DL_TEXT INTO DL_TEXT SEPARATED BY SPACE.

  • Add Date to Document

PERFORM ADD_TEXT USING DL_TEXT.

  • Add new-line

CALL METHOD DG_DYNDOC_ID->NEW_LINE.

CLEAR : DL_TEXT.

  • Move time

WRITE SY-UZEIT TO DL_TEXT.

CONCATENATE 'Time :' DL_TEXT INTO DL_TEXT SEPARATED BY SPACE.

  • Add Time to Document

PERFORM ADD_TEXT USING DL_TEXT.

  • Add new-line

CALL METHOD DG_DYNDOC_ID->NEW_LINE.

  • Populating data to html control

PERFORM HTML.

ENDFORM. " EVENT_TOP_OF_PAGE

&----


*& Form ADD_TEXT

&----


  • To add Text

----


FORM ADD_TEXT USING P_TEXT TYPE SDYDO_TEXT_ELEMENT.

  • Adding text

CALL METHOD DG_DYNDOC_ID->ADD_TEXT

EXPORTING

TEXT = P_TEXT

SAP_EMPHASIS = CL_DD_AREA=>HEADING.

ENDFORM. " ADD_TEXT

&----


*& Form HTML

&----


  • text

----


FORM HTML.

DATA : DL_LENGTH TYPE I, " Length

DL_BACKGROUND_ID TYPE SDYDO_KEY VALUE SPACE. " Background_id

  • Creating html control

IF DG_HTML_CNTRL IS INITIAL.

CREATE OBJECT DG_HTML_CNTRL

EXPORTING

PARENT = DG_PARENT_HTML.

ENDIF.

  • Reuse_alv_grid_commentary_set

CALL FUNCTION 'REUSE_ALV_GRID_COMMENTARY_SET'

EXPORTING

DOCUMENT = DG_DYNDOC_ID

BOTTOM = SPACE

IMPORTING

LENGTH = DL_LENGTH.

  • Get TOP->HTML_TABLE ready

CALL METHOD DG_DYNDOC_ID->MERGE_DOCUMENT.

  • Set wallpaper

CALL METHOD DG_DYNDOC_ID->SET_DOCUMENT_BACKGROUND

EXPORTING

PICTURE_ID = DL_BACKGROUND_ID.

  • Connect TOP document to HTML-Control

DG_DYNDOC_ID->HTML_CONTROL = DG_HTML_CNTRL.

  • Display TOP document

CALL METHOD DG_DYNDOC_ID->DISPLAY_DOCUMENT

EXPORTING

REUSE_CONTROL = 'X'

PARENT = DG_PARENT_HTML

EXCEPTIONS

HTML_DISPLAY_ERROR = 1.

IF SY-SUBRC NE 0.

MESSAGE I999 WITH 'Error in displaying top-of-page'(036).

ENDIF.

ENDFORM. " HTML[/code]

<b>reward pts if found usefull :)</b>

Regards

Sathish

Former Member
0 Kudos

Hi,

See following code also:

Reward points if helpful

Regards.

Srikanta Gope