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

Mandatory Fields on Editable ALV Grid

former_member125661
Contributor
0 Likes
4,331

Hi. I am using oops method to make an editable ALV grid.

How do I sent some columns for mandatory data entry?

Here are my declarations

gs_layout TYPE lvc_s_layo, "Layout declaration

go_grid TYPE REF TO cl_gui_alv_grid, "Grid

go_custom_container TYPE REF TO cl_gui_custom_container,"Container

go_fieldcat type lvc_t_fcat, "Field Catalog

Thanks,

Shareen

Hi. I am using oops method to make an editable ALV grid.

How do I sent some columns for mandatory data entry?

Here are my declarations

gs_layout TYPE lvc_s_layo, "Layout declaration

go_grid TYPE REF TO cl_gui_alv_grid, "Grid

go_custom_container TYPE REF TO cl_gui_custom_container,"Container

go_fieldcat type lvc_t_fcat, "Field Catalog

Thanks,

Shareen

6 REPLIES 6
Read only

Former Member
0 Likes
2,283

Excellent code/download how-to this site: An Easy Reference for ALV Grid Control by Serdar Simsekler.

Best!

Jim

Read only

Former Member
0 Likes
2,283

Any solutions as i am having the same requirement for my OOP ALV

Read only

Former Member
0 Likes
2,283

You can loop into that internal table displayed while SAVE or UPDATE and throw error or warnings.

Cheers

Kathir

Read only

ashok_kumar24116
Contributor
0 Likes
2,283

Hi Shareen Hegde ,

Try this program.

----


report zshail_alv_new .

tables: sflight.

type-pools: icon.

data: pt_sort type lvc_t_sort.

data: my_column type table of lvc_s_ceno with header line.

data: t_hype type LVC_T_HYPE.

class shail_event definition.

public section.

methods:

handle_toolbar for event toolbar of cl_gui_alv_grid

importing e_object e_interactive,

handle_user_command for event user_command of cl_gui_alv_grid importing

e_ucomm,

handle_contextmenu_request for event context_menu_request of

cl_gui_alv_grid importing e_object.

endclass.

class shail_event implementation.

method handle_toolbar.

perform handler_toolbar using e_object e_interactive.

endmethod.

method handle_user_command.

perform handler_user_command using e_ucomm.

endmethod.

method handle_contextmenu_request.

perform handler_contextmenu_request using e_object.

endmethod.

endclass.

data: go_container type ref to cl_gui_custom_container,

go_grid type ref to cl_gui_alv_grid,

field_catalog type lvc_t_fcat,

layout type lvc_s_layo.

data: begin of itab occurs 0.

include structure sflight.

data: end of itab.

data: obj type ref to shail_event.

data: button_exclude type ui_functions.

start-of-selection.

call screen 200.

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


module status_0100 output.

  • SET PF-STATUS 'xxxxxxxx'.

  • SET TITLEBAR 'xxx'.

if go_container is initial.

create object go_container

exporting

  • PARENT =

container_name = 'ALV_CONTAINER'

  • STYLE =

  • LIFETIME = lifetime_default

  • REPID =

  • DYNNR =

  • NO_AUTODEF_PROGID_DYNNR =

  • EXCEPTIONS

  • CNTL_ERROR = 1

  • CNTL_SYSTEM_ERROR = 2

  • CREATE_ERROR = 3

  • LIFETIME_ERROR = 4

  • LIFETIME_DYNPRO_DYNPRO_LINK = 5

  • others = 6

.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

create object go_grid

exporting

  • I_SHELLSTYLE = 0

  • I_LIFETIME =

i_parent = go_container

  • I_APPL_EVENTS = space

  • I_PARENTDBG =

  • I_APPLOGPARENT =

  • I_GRAPHICSPARENT =

  • I_USE_VARIANT_CLASS = SPACE

  • I_NAME =

  • EXCEPTIONS

  • ERROR_CNTL_CREATE = 1

  • ERROR_CNTL_INIT = 2

  • ERROR_CNTL_LINK = 3

  • ERROR_DP_CREATE = 4

  • others = 5

.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

create object obj.

set handler obj->handle_toolbar for go_grid.

set handler obj->handle_user_command for go_grid.

set handler obj->handle_contextmenu_request for go_grid.

select * from sflight into corresponding fields of table itab.

perform catalog_fill changing field_catalog.

perform layout_fill changing layout.

perform prepare_sort_table changing pt_sort.

call method go_grid->set_table_for_first_display

exporting

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE =

  • I_CONSISTENCY_CHECK =

  • I_STRUCTURE_NAME = 'SFLIGHT'

  • IS_VARIANT =

  • I_SAVE =

  • I_DEFAULT = 'X'

is_layout = layout

  • IS_PRINT =

  • IT_SPECIAL_GROUPS =

it_toolbar_excluding = button_exclude

IT_HYPERLINK = t_hype

  • IT_ALV_GRAPHICS =

  • IT_EXCEPT_QINFO =

changing

it_outtab = itab[]

it_fieldcatalog = field_catalog

it_sort = pt_sort

  • IT_FILTER =

  • EXCEPTIONS

  • INVALID_PARAMETER_COMBINATION = 1

  • PROGRAM_ERROR = 2

  • TOO_MANY_LINES = 3

  • others = 4

.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

else.

call method go_grid->refresh_table_display

  • EXPORTING

  • IS_STABLE =

  • I_SOFT_REFRESH =

  • EXCEPTIONS

  • FINISHED = 1

  • others = 2

.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

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 CATALOG_FILL

&----


  • text

----


  • <--P_FIELD_CATALOG text

----


form catalog_fill changing p_field_catalog.

data ls_fcat type lvc_s_fcat .

ls_fcat-fieldname = 'CARRID' .

ls_fcat-inttype = 'C' .

ls_fcat-outputlen = '20' .

ls_fcat-coltext = 'Carrier ID' .

ls_fcat-web_field = 'carrid_handle'.

ls_fcat-edit = 'X'.

*ls_fcat-emphasize = 'C310'. "needed for column coloring

append ls_fcat to field_catalog .

clear ls_fcat .

ls_fcat-fieldname = 'FLDATE' .

ls_fcat-ref_table = 'SFLIGHT' .

ls_fcat-ref_table = 'FLDATE' .

ls_fcat-outputlen = '20' .

ls_fcat-coltext = 'Flight Date' .

ls_fcat-web_field = 'fldate_handle'.

append ls_fcat to field_catalog .

clear ls_fcat .

ls_fcat-fieldname = 'PRICE' .

ls_fcat-ref_table = 'SFLIGHT' .

ls_fcat-ref_table = 'PRICE' .

ls_fcat-outputlen = '20' .

ls_fcat-coltext = 'Airfare' .

append ls_fcat to field_catalog .

clear ls_fcat .

ls_fcat-fieldname = 'SEATSMAX' .

ls_fcat-ref_table = 'SFLIGHT' .

ls_fcat-ref_table = 'SEATSMAX' .

ls_fcat-outputlen = '20' .

ls_fcat-coltext = 'Maximum seats' .

append ls_fcat to field_catalog .

endform. " CATALOG_FILL

&----


*& Form LAYOUT_FILL

&----


  • text

----


  • <--P_LAYOUT text

----


form layout_fill changing p_layout type lvc_s_layo.

p_layout-zebra = 'X' .

p_layout-grid_title = 'Flights' .

p_layout-smalltitle = 'X' .

p_layout-no_merging = 'X'.

*p_layout-sel_mode = 'A'.

*p_layout-info_fname = 'rowcolor'.

endform. " LAYOUT_FILL

&----


*& Form exclude_std_buttons

&----


  • text

----


  • <--P_BUTTON_EXCLUDE text

----


form exclude_std_buttons changing p_button_exclude type ui_functions.

  • the various buttons are details,sort asc,sort desc,find,set filter,

  • total, subtotal,

  • print,view,export,changelayout,display graphic, eu documentation

  • MC_FC_DETAIL,MC_FC_FIND,MC_FC_FILTER,MC_FC_GRAPHIC,MC_FC_SORT_ASC,

  • MC_FC_SORT_DSC,MC_FC_SUBTOT,MC_FC_SUM,MC_FC_PC_FILE,MC_FC_VIEWS

data: ls_exclude type ui_func.

ls_exclude = cl_gui_alv_grid=>mc_fc_detail.

append ls_exclude to p_button_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_find.

append ls_exclude to p_button_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_filter.

append ls_exclude to p_button_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_graph.

append ls_exclude to p_button_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_sort_asc.

append ls_exclude to p_button_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_sort_dsc.

append ls_exclude to p_button_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_subtot.

append ls_exclude to p_button_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_sum.

append ls_exclude to p_button_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_print.

append ls_exclude to p_button_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_views.

append ls_exclude to p_button_exclude.

endform. " exclude_std_buttons

&----


*& Form handle_toolbar

&----


  • text

----


  • -->P_E_OBJECT text

  • -->P_E_INTERACTIVE text

  • -->P_ENDMETHOD text

----


form handler_toolbar using p_e_object type ref to

cl_alv_event_toolbar_set

p_e_interactive .

data: ls_toolbar type stb_button.

clear ls_toolbar.

move 'PER' to ls_toolbar-function. "#EC NOTEXT

move icon_display_text to ls_toolbar-icon.

move 'Test Info'(201) to ls_toolbar-quickinfo.

move 'Test Info'(201) to ls_toolbar-text.

move ' ' to ls_toolbar-disabled. "#EC NOTEXT

append ls_toolbar to p_e_object->mt_toolbar.

endform. " handle_toolbar

&----


*& Form handle_user_command

&----


  • text

----


  • -->P_E_UCOMM text

----


form handler_user_command using p_e_ucomm.

case p_e_ucomm.

when 'PER'.

perform selected_columns.

when 'CREA'.

message i001(zmess).

endcase.

endform. " handle_user_command

&----


*& Form prepare_sort_table

&----


  • text

----


  • <--P_PT_SORT text

----


form prepare_sort_table changing p_pt_sort type lvc_t_sort.

data: ls_sort type lvc_s_sort.

ls_sort-spos = '1'.

ls_sort-fieldname = 'FLDATE'.

ls_sort-up = space.

ls_sort-down = 'X'.

append ls_sort to p_pt_sort.

endform. " prepare_sort_table

&----


*& Form handler_contextmenu_request

&----


  • text

----


  • -->P_E_OBJECT text

----


form handler_contextmenu_request using p_e_object type ref to

cl_ctmenu.

*

*CALL METHOD p_e_object->hide_functions

  • EXPORTING

  • fcodes = LT_FCODES

  • .

CALL METHOD p_e_object->clear

.

*break-point.

*

*

*

CALL METHOD p_e_object->add_function

EXPORTING

fcode = 'CREA'

text = 'Add Function'

  • ICON =

  • FTYPE =

  • DISABLED =

  • HIDDEN =

  • CHECKED =

  • ACCELERATOR =

.

*

endform. " handler_contextmenu_request

&----


*& Form selected_columns

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form selected_columns.

CALL METHOD go_grid->get_selected_cells_id

IMPORTING

ET_CELLS = my_column[]

.

loop at my_column.

    • this will specify the id of the selected cell

message i001(zmess) with my_column-row_id.

message i002(zmess) with my_column-col_id.

endloop.

endform. " selected_columns

&----


*& Form display_values

&----


  • text

----


  • -->P_ROW_ID text

*----


&----


*& Form prepare_hyp_tab

&----


  • text

----


  • <--P_T_HYPE text

----


form prepare_hyp_tab changing p_t_hype type lvc_t_hype.

endform. " prepare_hyp_tab

*

&----


*& Module STATUS_0200 OUTPUT

&----


  • text

----


module STATUS_0200 output.

  • SET PF-STATUS 'xxxxxxxx'.

  • SET TITLEBAR 'xxx'.

endmodule. " STATUS_0200 OUTPUT

&----


*& Module USER_COMMAND_0200 INPUT

&----


  • text

----


module USER_COMMAND_0200 input.

CASE SY-UCOMM.

WHEN 'NEXT'.

CALL SCREEN 100.

WHEN 'EXIT'.

LEAVE PROGRAM.

ENDCASE.

endmodule. " USER_COMMAND_0200 INPUT

----


Good Luck and REWARD ME for the same

Thanks

Ashok.N

Read only

Former Member
0 Likes
2,283

And exactly how does this make fields mandatory??!? No good just posting random code.

I get the feeling it isn't possible to set mandatory fields in an editable ALV. You'd have to manually check each entry.

Read only

Former Member
0 Likes
2,283

I had the same problem.
As

said , i looped into the internal table and checked whether mandatory fields are filled.
If not i exited from the loop and gave out a message.


DATA: VALID(1).

WHEN 'SAVE'.

        "Checking whether mandotary fields are filled

       VALID = 'X'.

       LOOP AT IT_ZFI_BS_REPORT INTO WA_ZFI_BS_REPORT.

         IF WA_ZFI_BS_REPORT-CO_CODE eq ''. "Checking the empty fileds

           VALID = ' '.

           EXIT.

         ENDIF.

       ENDLOOP.

       IF VALID eq 'X'.

               "Code for saving the Internal Table into the database

       ELSE.

        MESSAGE I001(00) WITH 'Please Fill All the Mandetory Fields'.

       ENDIF.

Best Regards,

Diren.