Application Development and Automation 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: 
Read only

ALV Grid

Former Member
0 Likes
518

Hi,

How to display ALV grid by using classes , I know display only but my requirement is I want to display some fields input enable and some fields input disable plzz help me its urgent and give me the code if it is available.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
349

Hi Syamala,

This is my example question i think it is helpful for you..

Try this code

REPORT zcl_timesheet_approval MESSAGE-ID zcl_msg.

----


  • CLASS L_CL_EVENTS DEFINITION *

----


  • Class for inserting buttons on the toolbar *

----


CLASS l_cl_events DEFINITION.

PUBLIC SECTION.

METHODS:

toolbar FOR EVENT toolbar

OF cl_gui_alv_grid

IMPORTING e_object

e_interactive,

user_command FOR EVENT user_command

OF cl_gui_alv_grid

IMPORTING e_ucomm .

ENDCLASS. " L_CL_EVENTS DEFINITION

----


  • CLASS L_CL_EVENTS IMPLEMENTATION *

----


  • Implementation of class L_CL_EVENTS *

----


CLASS l_cl_events IMPLEMENTATION.

METHOD toolbar.

PERFORM event_toolbar USING e_object.

ENDMETHOD. " TOOLBAR

METHOD user_command.

PERFORM event_ucomm USING e_ucomm.

ENDMETHOD. " USER_COMMAND

ENDCLASS. " L_CL_EVENTS IMPLEMENTATION

  • Tables decalration..................................................

TABLES:

zcl_timesheet. " Employee master table

CONSTANTS:

c_boolean_yes(1) TYPE c " Boolean - yes

VALUE 'X',

c_approve_status(1) TYPE c " Approval status

VALUE 'A',

c_rej_status(1) TYPE c " Rejected status

VALUE 'R',

c_save_status(1) TYPE c " Save status

VALUE 'S',

c_fcode_approve(7) TYPE c " Function code - APPROVE

VALUE 'APPROVE',

c_fcode_rej(6) TYPE c " Function code - REJECT

VALUE 'REJECT',

c_fcode_back(4) TYPE c " Function code - BACK

VALUE 'BACK',

c_fcode_onli(4) TYPE c " Function code - EXECUTE

VALUE 'ONLI',

c_fcode_exit(4) TYPE c " Function code - EXIT

VALUE 'EXIT',

c_fcode_cancel(6) TYPE c " Function code - CANCEL

VALUE 'CANCEL',

c_zero(1) TYPE c " Constant value 0

VALUE '0',

c_alv_scr(7) TYPE c " GUI status : ALV screen

VALUE 'ALV_SCR'.

  • Type definition...................................................

----


  • Type definition of the structure to hold data from table *

  • zcl_timesheet. *

----


TYPES:

BEGIN OF type_s_time,

empid TYPE zcl_timesheet-empid,

" Employee ID

workdate TYPE zcl_timesheet-workdate,

" Date

groupid TYPE zcl_timesheet-groupid,

" Group ID

projectid TYPE zcl_timesheet-projectid,

" Project ID

projectname TYPE zcl_timesheet-projectname,

" Project name

objectid TYPE zcl_timesheet-objectid,

" Object ID

objectname TYPE zcl_timesheet-objectname,

" Object name

activityid TYPE zcl_timesheet-activityid,

" Activity ID

activityname TYPE zcl_timesheet-activityname,

" Activity name

timeworked TYPE zcl_timesheet-timeworked,

" Time spent on work

description TYPE zcl_timesheet-description,

" Description

taskstatus TYPE zcl_timesheet-taskstatus,

" Status of the proj

billstatus TYPE zcl_timesheet-billstatus,

" Billing status

appstatus TYPE zcl_timesheet-appstatus,

" Staus of the record

wstatus TYPE zcl_timesheet-wstatus,

" Working status

mngcomment TYPE zcl_timesheet-mngcomment,

" Managers comment

END OF type_s_time.

  • Field-string declarations...........................................

DATA:

  • Field-string to build fieldcat.

fs_fcat TYPE lvc_s_fcat,

  • Field-string for t_timesheet

fs_timesheet TYPE zcl_timesheet.

  • Working variables...................................................

DATA:

w_valid(1) TYPE c, " To get the flag from check_data

w_display(1) TYPE c, " Flag to display all records

ok_code TYPE syst-ucomm, " Function code on dialog screens

w_okcode TYPE syst-ucomm, " Temporary function code

w_first(1) TYPE c, " To place buttons for first time

w_submit(1) TYPE c, " Flag to display submitted records

w_empid TYPE zcl_emprecord-empid.

" Employee ID for GET parameter

  • Internal table declarations........................................

DATA:

  • Internal table to build fieldcat.

t_fcat TYPE lvc_t_fcat,

  • Internal table to display data.

t_time TYPE TABLE OF type_s_time,

  • Internal table to hold submitted data.

t_timesheet TYPE TABLE OF zcl_timesheet.

  • For ALV ...........................................................

DATA:

  • To create instance for cl_gui_custom_container

g_grid TYPE REF TO cl_gui_custom_container,

  • To create instance for cl_gui_alv_grid

g_alv TYPE REF TO cl_gui_alv_grid,

  • To create instance for l_cl_events

g_events TYPE REF TO l_cl_events,

  • To assign name for custom container

g_container TYPE scrfname VALUE 'CONTAINER',

  • To assign layout

g_fcatlayo TYPE lvc_s_layo.

  • Selection screen elements............................................

SELECTION-SCREEN BEGIN OF BLOCK blck WITH FRAME TITLE text-000.

SELECT-OPTIONS:

s_group FOR zcl_timesheet-groupid " Group ID

NO INTERVALS,

s_prjid FOR zcl_timesheet-projectid, " Project ID

s_empid FOR zcl_timesheet-empid, " Employee ID

s_date FOR zcl_timesheet-workdate. " Date

SELECTION-SCREEN END OF BLOCK blck.

SELECTION-SCREEN BEGIN OF BLOCK blck1 WITH FRAME TITLE text-015.

PARAMETERS:

p_app RADIOBUTTON GROUP g1 USER-COMMAND app ,

" To approve timesheet

p_disp RADIOBUTTON GROUP g1. " To display timesheet

SELECTION-SCREEN END OF BLOCK blck1.

----


  • AT SELECTION-SCREEN EVENT *

----


AT SELECTION-SCREEN.

  • To perform user actions on the selection screen

PERFORM user_command.

----


  • MODULE STATUS_0100 OUTPUT *

----


  • This module will create the objects for the instance and display *

  • the records *

----


MODULE status_0100 OUTPUT.

SET PF-STATUS c_alv_scr.

PERFORM set_titlebar USING w_display.

  • If program executed in foreground.

IF sy-batch IS INITIAL.

  • If g_grid is empty.

IF g_grid IS INITIAL.

  • To create object for instance grid

CREATE OBJECT g_grid

EXPORTING

container_name = g_container.

  • To create object for object grid

CREATE OBJECT g_alv

EXPORTING

i_parent = g_grid.

ELSE.

CALL METHOD g_alv->refresh_table_display.

ENDIF. " IF G_GRID IS INITIAL

ENDIF. " IF SY-BATCH IS INITIAL

REFRESH t_fcat.

  • If w_display eq 'X' .

IF w_display EQ c_boolean_yes.

  • To display all records except saved data

PERFORM display_allrecords.

ENDIF. " IF W_FLAG EQ C_BOOLEAN_YES

IF w_submit EQ c_boolean_yes.

  • To display submitted records

PERFORM submitted_records.

ENDIF. " IF W_SUBMIT EQ C_BOOLEAN_YES

ENDMODULE. " STATUS_0100 OUTPUT

----


  • MODULE USER_COMMAND_0100 INPUT *

----


  • To perform user actions in the screen 100 *

----


MODULE user_command_0100 INPUT.

  • To update the data in the ALV grid

PERFORM check_changed_data.

w_okcode = ok_code.

CLEAR ok_code.

CASE w_okcode.

WHEN c_fcode_back.

LEAVE TO SCREEN 0.

WHEN c_fcode_exit OR c_fcode_cancel.

LEAVE PROGRAM.

ENDCASE. " CASE W_OKCODE

ENDMODULE. " USER_COMMAND_0100

----


  • FORM GET_DATA *

----


  • To get the submitted data from zcl_timesheet *

----


  • No parameters are passsed to this subroutine *

----


FORM get_data .

SELECT *

FROM zcl_timesheet

INTO TABLE t_timesheet

WHERE empid IN s_empid

AND workdate IN s_date

AND groupid IN s_group

AND projectid IN s_prjid

AND appstatus EQ c_boolean_yes.

IF sy-subrc NE 0.

MESSAGE e000 .

ELSE.

CALL SCREEN 100.

ENDIF. " IF SY-SUBRC NE 0

ENDFORM. " GET_DATA

----


  • FORM BUILD_FCAT *

----


  • To build the field catalog giving managers comment in editable mode *

----


  • -->PR_Tabname type lvc_tname *

  • -->PR_Fieldname type lvc_fname *

  • -->PR_Coltext type lvc_txtcol *

  • -->PR_Colpos type lvc_colpos *

----


FORM build_fcat USING pr_tabname TYPE lvc_tname

pr_fieldname TYPE lvc_fname

pr_coltext TYPE lvc_txtcol

pr_colpos TYPE lvc_colpos.

CLEAR fs_fcat.

fs_fcat-tabname = pr_tabname.

fs_fcat-fieldname = pr_fieldname.

fs_fcat-coltext = pr_coltext.

fs_fcat-col_pos = pr_colpos.

IF fs_fcat-fieldname EQ 'MNGCOMMENT'.

fs_fcat-edit = c_boolean_yes.

fs_fcat-lowercase = c_boolean_yes.

fs_fcat-dd_outlen = 60.

ELSE.

fs_fcat-edit = space.

ENDIF. " IF FS_FCAT-FIELDNAME...

APPEND fs_fcat TO t_fcat.

ENDFORM. " BUILD_FCAT

----


  • FORM BUILD_FCATD *

----


  • To build fieldcatalog in the display mode *

----


  • -->pr_Tabname type lvc_tname *

  • -->pr_Fieldname type lvc_fname *

  • -->pr_Coltext type lvc_txtcol *

  • -->pr_Colpos type lvc_colpos *

----


FORM build_fcatd USING pr_tabname TYPE lvc_tname

pr_fieldname TYPE lvc_fname

pr_coltext TYPE lvc_txtcol

pr_colpos TYPE lvc_colpos .

CLEAR fs_fcat.

fs_fcat-tabname = pr_tabname.

fs_fcat-fieldname = pr_fieldname.

fs_fcat-coltext = pr_coltext.

fs_fcat-col_pos = pr_colpos.

fs_fcat-edit = space.

APPEND fs_fcat TO t_fcat.

ENDFORM. " BUILD_FCATD

----


  • FORM ALV_DISPLAY *

----


  • To display data in ALV *

----


  • --> pr_table type standard table *

  • --> pr_fcat type lvc_t_fcat *

----


FORM alv_display USING pr_table TYPE STANDARD TABLE

pr_fcat TYPE lvc_t_fcat .

  • Local data declaration....

DATA: lt_exclude TYPE ui_functions.

  • To exclude buttons on the ALV grid

PERFORM exclude_tb_functions CHANGING lt_exclude.

  • To display ALV

CALL METHOD g_alv->set_table_for_first_display

EXPORTING

i_default = space

is_layout = g_fcatlayo

it_toolbar_excluding = lt_exclude

CHANGING

it_outtab = pr_table[]

it_fieldcatalog = pr_fcat[].

ENDFORM. " ALV_DISPLAY

----


  • FORM EVENT_TOOLBAR *

----


  • Setting toolbar in the alv grid *

----


  • -->E_OBJECT TYPE REF TO CL_ALV_EVENT_TOOLBAR_SET *

----


FORM event_toolbar USING e_object

TYPE REF TO cl_alv_event_toolbar_set.

  • Local declaration for the button.

DATA: ls_toolbar TYPE stb_button.

  • To add Approve button

ls_toolbar-function = c_fcode_approve.

ls_toolbar-butn_type = c_zero.

ls_toolbar-text = text-001.

APPEND ls_toolbar TO e_object->mt_toolbar.

  • To add Reject button

CLEAR ls_toolbar.

ls_toolbar-function = c_fcode_rej.

ls_toolbar-butn_type = c_zero.

ls_toolbar-text = text-013.

APPEND ls_toolbar TO e_object->mt_toolbar.

ENDFORM. " EVENT_TOOLBAR

----


  • FORM EXCLUDE_TB_FUNCTIONS *

----


  • To exclude buttons from ALV grid *

----


  • <--> PR_EXCLUDE TYPE UI_FUNCTIONS *

----


FORM exclude_tb_functions CHANGING pr_exclude TYPE ui_functions.

  • Local data declaration...

DATA ls_exclude TYPE ui_func.

  • To remove the buttons on the ALV grid.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.

APPEND ls_exclude TO pr_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.

APPEND ls_exclude TO pr_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.

APPEND ls_exclude TO pr_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.

APPEND ls_exclude TO pr_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.

APPEND ls_exclude TO pr_exclude.

ENDFORM. " EXCLUDE_TB_FUNCTIONS

----


  • FORM EVENT_UCOMM *

----


  • After Input in the ALV grid,if user select record and press *

  • approve or reject then the record will get updated *

----


  • --> PR_ucomm type sy-ucomm *

----


FORM event_ucomm USING pr_ucomm LIKE sy-ucomm.

CASE pr_ucomm.

  • If e_ucomm contains 'APP' i.e.function code for Approve button

WHEN c_fcode_approve. " To approve selected record

PERFORM app_timesheet USING c_approve_status.

  • If e_ucomm contains 'REJ' i.e. function code for Reject

WHEN c_fcode_rej. " To reject selected record

PERFORM app_timesheet USING c_rej_status.

ENDCASE. " CASE E_UCOMM

ENDFORM. " EVENT_UCOMM

----


  • FORM APP_TIMESHEET *

----


  • To get the selected records and update the records in database *

----


  • --> pr_status type char01 *

----


FORM app_timesheet USING pr_status TYPE char01 .

  • Local data declaration......

DATA:

lt_marked_rows TYPE lvc_t_roid, " Table to get rowid

l_fs_marked_row LIKE LINE OF lt_marked_rows.

" Field-string for lt_marked_rows

  • To get all the selected rows in the table lt_marked_rows

CALL METHOD g_alv->get_selected_rows

IMPORTING

et_row_no = lt_marked_rows.

  • Reading each row id and updating the database.

LOOP AT lt_marked_rows INTO l_fs_marked_row.

  • Reading the table t_timesheet with rowid

READ TABLE t_timesheet INTO fs_timesheet INDEX

l_fs_marked_row-row_id.

  • If record is there in the table.

IF sy-subrc EQ 0.

CLEAR fs_timesheet-appstatus.

GET PARAMETER ID 'ZEMPID' FIELD w_empid.

  • Changing the appstatus.

fs_timesheet-appstatus = pr_status.

fs_timesheet-approvedby = w_empid.

  • Updating the database table.

UPDATE zcl_timesheet FROM fs_timesheet.

IF sy-subrc EQ 0.

DELETE t_timesheet INDEX l_fs_marked_row-row_id.

PERFORM refresh_table USING pr_status.

ENDIF. " IF SY-SUBRC EQ 0.

ENDIF. " IF SY-SUBRC EQ 0

ENDLOOP. " LOOP AT LT_MARKED_ROWS...

ENDFORM. " APP_TIMESHEET

----


  • FORM CHECK_CHANGED_DATA *

----


  • To change the data *

----


  • No parameters are passsed to this subroutine *

----


FORM check_changed_data .

  • To change the data.

CALL METHOD g_alv->check_changed_data.

ENDFORM. " CHECK_CHANGED_DATA

----


  • FORM DISPLAY_ALL *

----


  • To display all the records *

----


  • No parameters are passsed to this subroutine *

----


FORM display_all .

SELECT empid " Employee ID

workdate " Workdate

groupid " Groupid

projectid " Project ID

projectname " Project name

objectid " Object ID

objectname " Object name

activityid " Activity ID

activityname " Activity name

timeworked " Time worked

description " Description

taskstatus " Task status

billstatus " Bill status

appstatus " Approved status

wstatus " Working status

mngcomment " Manager comment

FROM zcl_timesheet

INTO TABLE t_time

WHERE empid IN s_empid

AND workdate IN s_date

AND groupid IN s_group

AND projectid IN s_prjid

AND appstatus NE c_save_status.

IF sy-subrc NE 0.

MESSAGE e000.

ELSE.

CALL SCREEN 100.

ENDIF. " IF SY-SUBRC NE 0

ENDFORM. " DISPLAY_ALL

----


  • FORM REFFRESH_TABLE *

----


  • To refresh output table and issue message according p_status *

----


  • -->PR_STATUS TYPE CHAR01 *

----


FORM refresh_table USING pr_status TYPE char01.

  • To refresh output table.

CALL METHOD g_alv->refresh_table_display.

  • Depending upon pr_status message is given.

IF pr_status EQ c_approve_status.

MESSAGE s001.

ELSE.

MESSAGE s002.

ENDIF. " IF P_STATUS EQ C_APPROVE_STATUS

ENDFORM. " REFRESH_TABLE

----


  • FORM SET_TITLEBAR *

----


  • To set titlebar on the screen 100. *

----


  • -->PR_STATUS TYPE CHAR01 *

----


FORM set_titlebar USING pr_status TYPE char01.

  • If pr_status eq 'X'.

IF pr_status EQ c_boolean_yes.

SET TITLEBAR c_alv_scr WITH text-017.

ELSE.

SET TITLEBAR c_alv_scr WITH text-018.

ENDIF. " IF P_STATUS EQ C_BOOLEAN_YES

ENDFORM. " SET_TITLEBAR

----


  • FORM USER_COMMAND *

----


  • According to sy-ucomm the action is performed in the screen 100 *

----


  • No parameters are passsed to this subroutine *

----


FORM user_command .

CASE sy-ucomm.

  • If p_app is selected, submitted data will be displayed for approval

WHEN c_fcode_onli OR c_fcode_approve.

CLEAR sy-ucomm.

  • To display the submitted records.

IF p_app EQ c_boolean_yes.

w_submit = c_boolean_yes.

  • To get submitted records

PERFORM get_data.

ENDIF. " IF P_APP EQ C_BOOLEAN_YES

  • To display all records according to selection.

IF p_disp EQ c_boolean_yes.

w_display = c_boolean_yes.

  • To display

PERFORM display_all.

CLEAR w_display.

ENDIF. " IF P_DISP EQ C_BOOLEAN_YES

ENDCASE. " CASE SY-UCOMM

ENDFORM. " USER_COMMAND

----


  • FORM DISPLAY_ALLRECORDS *

----


  • To display all the records in the display mode *

----


  • No parameters are passsed to this subroutine *

----


FORM display_allrecords .

CLEAR w_display.

PERFORM build_fcatd USING 'T_TIME' 'WORKDATE' text-002 '1'.

PERFORM build_fcatd USING 'T_TIME' 'EMPID' text-009 '2'.

PERFORM build_fcatd USING 'T_TIME' 'PROJECTID' text-003 '3'.

PERFORM build_fcatd USING 'T_TIME' 'PROJECTNAME' text-004 '4'.

PERFORM build_fcatd USING 'T_TIME' 'OBJECTID' text-005 '5'.

PERFORM build_fcatd USING 'T_TIME' 'OBJECTNAME' text-006 '6'.

PERFORM build_fcatd USING 'T_TIME' 'ACTIVITYID' text-007 '7'.

PERFORM build_fcatd USING 'T_TIME' 'ACTIVITYNAME' text-008 '8'.

PERFORM build_fcatd USING 'T_TIME' 'TIMEWORKED' text-010 '9'.

PERFORM build_fcatd USING 'T_TIME' 'DESCRIPTION' text-011 '10'.

PERFORM build_fcatd USING 'T_TIME' 'APPSTATUS' text-012 '11'.

PERFORM build_fcatd USING 'T_TIME' 'BILLSTATUS' text-016 '12'.

PERFORM build_fcatd USING 'T_TIME' 'MNGCOMMENT' text-014 '13'.

PERFORM alv_display USING t_time t_fcat.

ENDFORM. " DISPLAY_ALLRECORDS

----


  • FORM SUBMITTED_RECORDS *

----


  • To display submitted records for the manager to approve *

----


  • No parameters are passsed to this subroutine *

----


FORM submitted_records .

CLEAR w_submit.

  • To create object for instance g_events

CREATE OBJECT g_events.

  • If w_first equal to space

IF w_first IS INITIAL.

SET HANDLER g_events->toolbar

FOR g_alv.

w_first = c_boolean_yes.

ENDIF. " IF W_FIRST IS INITIAL..

SET HANDLER g_events->user_command

FOR g_alv.

g_fcatlayo-sel_mode = c_approve_status.

REFRESH t_fcat.

PERFORM build_fcat USING 'T_TIMESHEET' 'WORKDATE' text-002 '1'.

PERFORM build_fcat USING 'T_TIMESHEET' 'EMPID' text-009 '2'.

PERFORM build_fcat USING 'T_TIMESHEET' 'PROJECTID' text-003 '3'.

PERFORM build_fcat USING 'T_TIMESHEET' 'PROJECTNAME' text-004 '4'.

PERFORM build_fcat USING 'T_TIMESHEET' 'OBJECTID' text-005 '5'.

PERFORM build_fcat USING 'T_TIMESHEET' 'OBJECTNAME' text-006 '6'.

PERFORM build_fcat USING 'T_TIMESHEET' 'ACTIVITYID' text-007 '7'.

PERFORM build_fcat USING 'T_TIMESHEET' 'ACTIVITYNAME' text-008 '8'.

PERFORM build_fcat USING 'T_TIMESHEET' 'TIMEWORKED' text-010 '9'.

PERFORM build_fcat USING 'T_TIMESHEET' 'DESCRIPTION' text-011 '10'.

PERFORM build_fcat USING 'T_TIMESHEET' 'APPSTATUS' text-012 '11'.

PERFORM build_fcat USING 'T_TIMESHEET' 'BILLSTATUS' text-016 '12'.

PERFORM build_fcat USING 'T_TIMESHEET' 'MNGCOMMENT' text-014 '13'.

PERFORM alv_display USING t_timesheet t_fcat.

ENDFORM. " SUBMITTED_RECORDS

Plzz reward if it is useful,

Mahi.

Hi,

How to display ALV grid by using classes , I know display only but my requirement is I want to display some fields input enable and some fields input disable plzz help me its urgent and give me the code if it is available.

1 REPLY 1
Read only

Former Member
0 Likes
350

Hi Syamala,

This is my example question i think it is helpful for you..

Try this code

REPORT zcl_timesheet_approval MESSAGE-ID zcl_msg.

----


  • CLASS L_CL_EVENTS DEFINITION *

----


  • Class for inserting buttons on the toolbar *

----


CLASS l_cl_events DEFINITION.

PUBLIC SECTION.

METHODS:

toolbar FOR EVENT toolbar

OF cl_gui_alv_grid

IMPORTING e_object

e_interactive,

user_command FOR EVENT user_command

OF cl_gui_alv_grid

IMPORTING e_ucomm .

ENDCLASS. " L_CL_EVENTS DEFINITION

----


  • CLASS L_CL_EVENTS IMPLEMENTATION *

----


  • Implementation of class L_CL_EVENTS *

----


CLASS l_cl_events IMPLEMENTATION.

METHOD toolbar.

PERFORM event_toolbar USING e_object.

ENDMETHOD. " TOOLBAR

METHOD user_command.

PERFORM event_ucomm USING e_ucomm.

ENDMETHOD. " USER_COMMAND

ENDCLASS. " L_CL_EVENTS IMPLEMENTATION

  • Tables decalration..................................................

TABLES:

zcl_timesheet. " Employee master table

CONSTANTS:

c_boolean_yes(1) TYPE c " Boolean - yes

VALUE 'X',

c_approve_status(1) TYPE c " Approval status

VALUE 'A',

c_rej_status(1) TYPE c " Rejected status

VALUE 'R',

c_save_status(1) TYPE c " Save status

VALUE 'S',

c_fcode_approve(7) TYPE c " Function code - APPROVE

VALUE 'APPROVE',

c_fcode_rej(6) TYPE c " Function code - REJECT

VALUE 'REJECT',

c_fcode_back(4) TYPE c " Function code - BACK

VALUE 'BACK',

c_fcode_onli(4) TYPE c " Function code - EXECUTE

VALUE 'ONLI',

c_fcode_exit(4) TYPE c " Function code - EXIT

VALUE 'EXIT',

c_fcode_cancel(6) TYPE c " Function code - CANCEL

VALUE 'CANCEL',

c_zero(1) TYPE c " Constant value 0

VALUE '0',

c_alv_scr(7) TYPE c " GUI status : ALV screen

VALUE 'ALV_SCR'.

  • Type definition...................................................

----


  • Type definition of the structure to hold data from table *

  • zcl_timesheet. *

----


TYPES:

BEGIN OF type_s_time,

empid TYPE zcl_timesheet-empid,

" Employee ID

workdate TYPE zcl_timesheet-workdate,

" Date

groupid TYPE zcl_timesheet-groupid,

" Group ID

projectid TYPE zcl_timesheet-projectid,

" Project ID

projectname TYPE zcl_timesheet-projectname,

" Project name

objectid TYPE zcl_timesheet-objectid,

" Object ID

objectname TYPE zcl_timesheet-objectname,

" Object name

activityid TYPE zcl_timesheet-activityid,

" Activity ID

activityname TYPE zcl_timesheet-activityname,

" Activity name

timeworked TYPE zcl_timesheet-timeworked,

" Time spent on work

description TYPE zcl_timesheet-description,

" Description

taskstatus TYPE zcl_timesheet-taskstatus,

" Status of the proj

billstatus TYPE zcl_timesheet-billstatus,

" Billing status

appstatus TYPE zcl_timesheet-appstatus,

" Staus of the record

wstatus TYPE zcl_timesheet-wstatus,

" Working status

mngcomment TYPE zcl_timesheet-mngcomment,

" Managers comment

END OF type_s_time.

  • Field-string declarations...........................................

DATA:

  • Field-string to build fieldcat.

fs_fcat TYPE lvc_s_fcat,

  • Field-string for t_timesheet

fs_timesheet TYPE zcl_timesheet.

  • Working variables...................................................

DATA:

w_valid(1) TYPE c, " To get the flag from check_data

w_display(1) TYPE c, " Flag to display all records

ok_code TYPE syst-ucomm, " Function code on dialog screens

w_okcode TYPE syst-ucomm, " Temporary function code

w_first(1) TYPE c, " To place buttons for first time

w_submit(1) TYPE c, " Flag to display submitted records

w_empid TYPE zcl_emprecord-empid.

" Employee ID for GET parameter

  • Internal table declarations........................................

DATA:

  • Internal table to build fieldcat.

t_fcat TYPE lvc_t_fcat,

  • Internal table to display data.

t_time TYPE TABLE OF type_s_time,

  • Internal table to hold submitted data.

t_timesheet TYPE TABLE OF zcl_timesheet.

  • For ALV ...........................................................

DATA:

  • To create instance for cl_gui_custom_container

g_grid TYPE REF TO cl_gui_custom_container,

  • To create instance for cl_gui_alv_grid

g_alv TYPE REF TO cl_gui_alv_grid,

  • To create instance for l_cl_events

g_events TYPE REF TO l_cl_events,

  • To assign name for custom container

g_container TYPE scrfname VALUE 'CONTAINER',

  • To assign layout

g_fcatlayo TYPE lvc_s_layo.

  • Selection screen elements............................................

SELECTION-SCREEN BEGIN OF BLOCK blck WITH FRAME TITLE text-000.

SELECT-OPTIONS:

s_group FOR zcl_timesheet-groupid " Group ID

NO INTERVALS,

s_prjid FOR zcl_timesheet-projectid, " Project ID

s_empid FOR zcl_timesheet-empid, " Employee ID

s_date FOR zcl_timesheet-workdate. " Date

SELECTION-SCREEN END OF BLOCK blck.

SELECTION-SCREEN BEGIN OF BLOCK blck1 WITH FRAME TITLE text-015.

PARAMETERS:

p_app RADIOBUTTON GROUP g1 USER-COMMAND app ,

" To approve timesheet

p_disp RADIOBUTTON GROUP g1. " To display timesheet

SELECTION-SCREEN END OF BLOCK blck1.

----


  • AT SELECTION-SCREEN EVENT *

----


AT SELECTION-SCREEN.

  • To perform user actions on the selection screen

PERFORM user_command.

----


  • MODULE STATUS_0100 OUTPUT *

----


  • This module will create the objects for the instance and display *

  • the records *

----


MODULE status_0100 OUTPUT.

SET PF-STATUS c_alv_scr.

PERFORM set_titlebar USING w_display.

  • If program executed in foreground.

IF sy-batch IS INITIAL.

  • If g_grid is empty.

IF g_grid IS INITIAL.

  • To create object for instance grid

CREATE OBJECT g_grid

EXPORTING

container_name = g_container.

  • To create object for object grid

CREATE OBJECT g_alv

EXPORTING

i_parent = g_grid.

ELSE.

CALL METHOD g_alv->refresh_table_display.

ENDIF. " IF G_GRID IS INITIAL

ENDIF. " IF SY-BATCH IS INITIAL

REFRESH t_fcat.

  • If w_display eq 'X' .

IF w_display EQ c_boolean_yes.

  • To display all records except saved data

PERFORM display_allrecords.

ENDIF. " IF W_FLAG EQ C_BOOLEAN_YES

IF w_submit EQ c_boolean_yes.

  • To display submitted records

PERFORM submitted_records.

ENDIF. " IF W_SUBMIT EQ C_BOOLEAN_YES

ENDMODULE. " STATUS_0100 OUTPUT

----


  • MODULE USER_COMMAND_0100 INPUT *

----


  • To perform user actions in the screen 100 *

----


MODULE user_command_0100 INPUT.

  • To update the data in the ALV grid

PERFORM check_changed_data.

w_okcode = ok_code.

CLEAR ok_code.

CASE w_okcode.

WHEN c_fcode_back.

LEAVE TO SCREEN 0.

WHEN c_fcode_exit OR c_fcode_cancel.

LEAVE PROGRAM.

ENDCASE. " CASE W_OKCODE

ENDMODULE. " USER_COMMAND_0100

----


  • FORM GET_DATA *

----


  • To get the submitted data from zcl_timesheet *

----


  • No parameters are passsed to this subroutine *

----


FORM get_data .

SELECT *

FROM zcl_timesheet

INTO TABLE t_timesheet

WHERE empid IN s_empid

AND workdate IN s_date

AND groupid IN s_group

AND projectid IN s_prjid

AND appstatus EQ c_boolean_yes.

IF sy-subrc NE 0.

MESSAGE e000 .

ELSE.

CALL SCREEN 100.

ENDIF. " IF SY-SUBRC NE 0

ENDFORM. " GET_DATA

----


  • FORM BUILD_FCAT *

----


  • To build the field catalog giving managers comment in editable mode *

----


  • -->PR_Tabname type lvc_tname *

  • -->PR_Fieldname type lvc_fname *

  • -->PR_Coltext type lvc_txtcol *

  • -->PR_Colpos type lvc_colpos *

----


FORM build_fcat USING pr_tabname TYPE lvc_tname

pr_fieldname TYPE lvc_fname

pr_coltext TYPE lvc_txtcol

pr_colpos TYPE lvc_colpos.

CLEAR fs_fcat.

fs_fcat-tabname = pr_tabname.

fs_fcat-fieldname = pr_fieldname.

fs_fcat-coltext = pr_coltext.

fs_fcat-col_pos = pr_colpos.

IF fs_fcat-fieldname EQ 'MNGCOMMENT'.

fs_fcat-edit = c_boolean_yes.

fs_fcat-lowercase = c_boolean_yes.

fs_fcat-dd_outlen = 60.

ELSE.

fs_fcat-edit = space.

ENDIF. " IF FS_FCAT-FIELDNAME...

APPEND fs_fcat TO t_fcat.

ENDFORM. " BUILD_FCAT

----


  • FORM BUILD_FCATD *

----


  • To build fieldcatalog in the display mode *

----


  • -->pr_Tabname type lvc_tname *

  • -->pr_Fieldname type lvc_fname *

  • -->pr_Coltext type lvc_txtcol *

  • -->pr_Colpos type lvc_colpos *

----


FORM build_fcatd USING pr_tabname TYPE lvc_tname

pr_fieldname TYPE lvc_fname

pr_coltext TYPE lvc_txtcol

pr_colpos TYPE lvc_colpos .

CLEAR fs_fcat.

fs_fcat-tabname = pr_tabname.

fs_fcat-fieldname = pr_fieldname.

fs_fcat-coltext = pr_coltext.

fs_fcat-col_pos = pr_colpos.

fs_fcat-edit = space.

APPEND fs_fcat TO t_fcat.

ENDFORM. " BUILD_FCATD

----


  • FORM ALV_DISPLAY *

----


  • To display data in ALV *

----


  • --> pr_table type standard table *

  • --> pr_fcat type lvc_t_fcat *

----


FORM alv_display USING pr_table TYPE STANDARD TABLE

pr_fcat TYPE lvc_t_fcat .

  • Local data declaration....

DATA: lt_exclude TYPE ui_functions.

  • To exclude buttons on the ALV grid

PERFORM exclude_tb_functions CHANGING lt_exclude.

  • To display ALV

CALL METHOD g_alv->set_table_for_first_display

EXPORTING

i_default = space

is_layout = g_fcatlayo

it_toolbar_excluding = lt_exclude

CHANGING

it_outtab = pr_table[]

it_fieldcatalog = pr_fcat[].

ENDFORM. " ALV_DISPLAY

----


  • FORM EVENT_TOOLBAR *

----


  • Setting toolbar in the alv grid *

----


  • -->E_OBJECT TYPE REF TO CL_ALV_EVENT_TOOLBAR_SET *

----


FORM event_toolbar USING e_object

TYPE REF TO cl_alv_event_toolbar_set.

  • Local declaration for the button.

DATA: ls_toolbar TYPE stb_button.

  • To add Approve button

ls_toolbar-function = c_fcode_approve.

ls_toolbar-butn_type = c_zero.

ls_toolbar-text = text-001.

APPEND ls_toolbar TO e_object->mt_toolbar.

  • To add Reject button

CLEAR ls_toolbar.

ls_toolbar-function = c_fcode_rej.

ls_toolbar-butn_type = c_zero.

ls_toolbar-text = text-013.

APPEND ls_toolbar TO e_object->mt_toolbar.

ENDFORM. " EVENT_TOOLBAR

----


  • FORM EXCLUDE_TB_FUNCTIONS *

----


  • To exclude buttons from ALV grid *

----


  • <--> PR_EXCLUDE TYPE UI_FUNCTIONS *

----


FORM exclude_tb_functions CHANGING pr_exclude TYPE ui_functions.

  • Local data declaration...

DATA ls_exclude TYPE ui_func.

  • To remove the buttons on the ALV grid.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.

APPEND ls_exclude TO pr_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.

APPEND ls_exclude TO pr_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.

APPEND ls_exclude TO pr_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.

APPEND ls_exclude TO pr_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.

APPEND ls_exclude TO pr_exclude.

ENDFORM. " EXCLUDE_TB_FUNCTIONS

----


  • FORM EVENT_UCOMM *

----


  • After Input in the ALV grid,if user select record and press *

  • approve or reject then the record will get updated *

----


  • --> PR_ucomm type sy-ucomm *

----


FORM event_ucomm USING pr_ucomm LIKE sy-ucomm.

CASE pr_ucomm.

  • If e_ucomm contains 'APP' i.e.function code for Approve button

WHEN c_fcode_approve. " To approve selected record

PERFORM app_timesheet USING c_approve_status.

  • If e_ucomm contains 'REJ' i.e. function code for Reject

WHEN c_fcode_rej. " To reject selected record

PERFORM app_timesheet USING c_rej_status.

ENDCASE. " CASE E_UCOMM

ENDFORM. " EVENT_UCOMM

----


  • FORM APP_TIMESHEET *

----


  • To get the selected records and update the records in database *

----


  • --> pr_status type char01 *

----


FORM app_timesheet USING pr_status TYPE char01 .

  • Local data declaration......

DATA:

lt_marked_rows TYPE lvc_t_roid, " Table to get rowid

l_fs_marked_row LIKE LINE OF lt_marked_rows.

" Field-string for lt_marked_rows

  • To get all the selected rows in the table lt_marked_rows

CALL METHOD g_alv->get_selected_rows

IMPORTING

et_row_no = lt_marked_rows.

  • Reading each row id and updating the database.

LOOP AT lt_marked_rows INTO l_fs_marked_row.

  • Reading the table t_timesheet with rowid

READ TABLE t_timesheet INTO fs_timesheet INDEX

l_fs_marked_row-row_id.

  • If record is there in the table.

IF sy-subrc EQ 0.

CLEAR fs_timesheet-appstatus.

GET PARAMETER ID 'ZEMPID' FIELD w_empid.

  • Changing the appstatus.

fs_timesheet-appstatus = pr_status.

fs_timesheet-approvedby = w_empid.

  • Updating the database table.

UPDATE zcl_timesheet FROM fs_timesheet.

IF sy-subrc EQ 0.

DELETE t_timesheet INDEX l_fs_marked_row-row_id.

PERFORM refresh_table USING pr_status.

ENDIF. " IF SY-SUBRC EQ 0.

ENDIF. " IF SY-SUBRC EQ 0

ENDLOOP. " LOOP AT LT_MARKED_ROWS...

ENDFORM. " APP_TIMESHEET

----


  • FORM CHECK_CHANGED_DATA *

----


  • To change the data *

----


  • No parameters are passsed to this subroutine *

----


FORM check_changed_data .

  • To change the data.

CALL METHOD g_alv->check_changed_data.

ENDFORM. " CHECK_CHANGED_DATA

----


  • FORM DISPLAY_ALL *

----


  • To display all the records *

----


  • No parameters are passsed to this subroutine *

----


FORM display_all .

SELECT empid " Employee ID

workdate " Workdate

groupid " Groupid

projectid " Project ID

projectname " Project name

objectid " Object ID

objectname " Object name

activityid " Activity ID

activityname " Activity name

timeworked " Time worked

description " Description

taskstatus " Task status

billstatus " Bill status

appstatus " Approved status

wstatus " Working status

mngcomment " Manager comment

FROM zcl_timesheet

INTO TABLE t_time

WHERE empid IN s_empid

AND workdate IN s_date

AND groupid IN s_group

AND projectid IN s_prjid

AND appstatus NE c_save_status.

IF sy-subrc NE 0.

MESSAGE e000.

ELSE.

CALL SCREEN 100.

ENDIF. " IF SY-SUBRC NE 0

ENDFORM. " DISPLAY_ALL

----


  • FORM REFFRESH_TABLE *

----


  • To refresh output table and issue message according p_status *

----


  • -->PR_STATUS TYPE CHAR01 *

----


FORM refresh_table USING pr_status TYPE char01.

  • To refresh output table.

CALL METHOD g_alv->refresh_table_display.

  • Depending upon pr_status message is given.

IF pr_status EQ c_approve_status.

MESSAGE s001.

ELSE.

MESSAGE s002.

ENDIF. " IF P_STATUS EQ C_APPROVE_STATUS

ENDFORM. " REFRESH_TABLE

----


  • FORM SET_TITLEBAR *

----


  • To set titlebar on the screen 100. *

----


  • -->PR_STATUS TYPE CHAR01 *

----


FORM set_titlebar USING pr_status TYPE char01.

  • If pr_status eq 'X'.

IF pr_status EQ c_boolean_yes.

SET TITLEBAR c_alv_scr WITH text-017.

ELSE.

SET TITLEBAR c_alv_scr WITH text-018.

ENDIF. " IF P_STATUS EQ C_BOOLEAN_YES

ENDFORM. " SET_TITLEBAR

----


  • FORM USER_COMMAND *

----


  • According to sy-ucomm the action is performed in the screen 100 *

----


  • No parameters are passsed to this subroutine *

----


FORM user_command .

CASE sy-ucomm.

  • If p_app is selected, submitted data will be displayed for approval

WHEN c_fcode_onli OR c_fcode_approve.

CLEAR sy-ucomm.

  • To display the submitted records.

IF p_app EQ c_boolean_yes.

w_submit = c_boolean_yes.

  • To get submitted records

PERFORM get_data.

ENDIF. " IF P_APP EQ C_BOOLEAN_YES

  • To display all records according to selection.

IF p_disp EQ c_boolean_yes.

w_display = c_boolean_yes.

  • To display

PERFORM display_all.

CLEAR w_display.

ENDIF. " IF P_DISP EQ C_BOOLEAN_YES

ENDCASE. " CASE SY-UCOMM

ENDFORM. " USER_COMMAND

----


  • FORM DISPLAY_ALLRECORDS *

----


  • To display all the records in the display mode *

----


  • No parameters are passsed to this subroutine *

----


FORM display_allrecords .

CLEAR w_display.

PERFORM build_fcatd USING 'T_TIME' 'WORKDATE' text-002 '1'.

PERFORM build_fcatd USING 'T_TIME' 'EMPID' text-009 '2'.

PERFORM build_fcatd USING 'T_TIME' 'PROJECTID' text-003 '3'.

PERFORM build_fcatd USING 'T_TIME' 'PROJECTNAME' text-004 '4'.

PERFORM build_fcatd USING 'T_TIME' 'OBJECTID' text-005 '5'.

PERFORM build_fcatd USING 'T_TIME' 'OBJECTNAME' text-006 '6'.

PERFORM build_fcatd USING 'T_TIME' 'ACTIVITYID' text-007 '7'.

PERFORM build_fcatd USING 'T_TIME' 'ACTIVITYNAME' text-008 '8'.

PERFORM build_fcatd USING 'T_TIME' 'TIMEWORKED' text-010 '9'.

PERFORM build_fcatd USING 'T_TIME' 'DESCRIPTION' text-011 '10'.

PERFORM build_fcatd USING 'T_TIME' 'APPSTATUS' text-012 '11'.

PERFORM build_fcatd USING 'T_TIME' 'BILLSTATUS' text-016 '12'.

PERFORM build_fcatd USING 'T_TIME' 'MNGCOMMENT' text-014 '13'.

PERFORM alv_display USING t_time t_fcat.

ENDFORM. " DISPLAY_ALLRECORDS

----


  • FORM SUBMITTED_RECORDS *

----


  • To display submitted records for the manager to approve *

----


  • No parameters are passsed to this subroutine *

----


FORM submitted_records .

CLEAR w_submit.

  • To create object for instance g_events

CREATE OBJECT g_events.

  • If w_first equal to space

IF w_first IS INITIAL.

SET HANDLER g_events->toolbar

FOR g_alv.

w_first = c_boolean_yes.

ENDIF. " IF W_FIRST IS INITIAL..

SET HANDLER g_events->user_command

FOR g_alv.

g_fcatlayo-sel_mode = c_approve_status.

REFRESH t_fcat.

PERFORM build_fcat USING 'T_TIMESHEET' 'WORKDATE' text-002 '1'.

PERFORM build_fcat USING 'T_TIMESHEET' 'EMPID' text-009 '2'.

PERFORM build_fcat USING 'T_TIMESHEET' 'PROJECTID' text-003 '3'.

PERFORM build_fcat USING 'T_TIMESHEET' 'PROJECTNAME' text-004 '4'.

PERFORM build_fcat USING 'T_TIMESHEET' 'OBJECTID' text-005 '5'.

PERFORM build_fcat USING 'T_TIMESHEET' 'OBJECTNAME' text-006 '6'.

PERFORM build_fcat USING 'T_TIMESHEET' 'ACTIVITYID' text-007 '7'.

PERFORM build_fcat USING 'T_TIMESHEET' 'ACTIVITYNAME' text-008 '8'.

PERFORM build_fcat USING 'T_TIMESHEET' 'TIMEWORKED' text-010 '9'.

PERFORM build_fcat USING 'T_TIMESHEET' 'DESCRIPTION' text-011 '10'.

PERFORM build_fcat USING 'T_TIMESHEET' 'APPSTATUS' text-012 '11'.

PERFORM build_fcat USING 'T_TIMESHEET' 'BILLSTATUS' text-016 '12'.

PERFORM build_fcat USING 'T_TIMESHEET' 'MNGCOMMENT' text-014 '13'.

PERFORM alv_display USING t_timesheet t_fcat.

ENDFORM. " SUBMITTED_RECORDS

Plzz reward if it is useful,

Mahi.