ALV to set whether a cell can be edited according to the criteria

Source: Internet
Author: User
*&---------------------------------*
*& Z_TEST_ZS13
*&
*&---------------------------------*
*&
*&
*&---------------------------------*

The Z_TEST_ZS13.

*&---------------------------------*
*& Zdemo_alvgrid_edit *
*& *
*&---------------------------------*
*& *
*& Example of a simple ALV Grid
*& ..... *........ *..... *....
*& *
*& the basic ALV grid, enhanced to display specific fields as *
*& editable depending on field value *
*&---------------------------------*

Tables:ekko.

Type-pools:slis. "ALV Declarations
*data Declaration
*----------------
Types:begin of T_ekko,
Ebeln TYPE Ekpo-ebeln,
Ebelp TYPE Ekpo-ebelp,
Statu TYPE Ekpo-statu,
Aedat TYPE Ekpo-aedat,
Matnr TYPE Ekpo-matnr,
Menge TYPE Ekpo-menge,
Meins TYPE Ekpo-meins,
NETPR TYPE EKPO-NETPR,
Peinh TYPE Ekpo-peinh,
Field_style TYPE lvc_t_styl, "for DISABLE
End of T_ekko.

Data:it_ekko TYPE STANDARD TABLE of T_ekko INITIAL SIZE 0,
Wa_ekko TYPE T_ekko.

*ALV Data declarations
Data:fieldcatalog TYPE Slis_t_fieldcat_alv with HEADER line.
Data:it_fieldcat TYPE Lvc_t_fcat, "Slis_t_fieldcat_alv with HEADER line,
Wa_fieldcat TYPE Lvc_s_fcat,

Gd_tab_group TYPE Slis_t_sp_group_alv,
Gd_layout TYPE Lvc_s_layo, "Slis_layout_alv,
Gd_repid like Sy-repid.


************************************************************************
*start-of-selection.
Start-of-selection.

Perform data_retrieval.
Perform set_specific_field_attributes.
Perform build_fieldcatalog.
Perform build_layout.
Perform display_alv_report.


*&---------------------------------*
*& Form Build_fieldcatalog
*&---------------------------------*
* Build Fieldcatalog for ALV
*----------------------------------*
FORM Build_fieldcatalog.

Wa_fieldcat-fieldname = ' Ebeln '.
Wa_fieldcat-scrtext_m = ' Purchase order '.
Wa_fieldcat-col_pos = 0.
Wa_fieldcat-outputlen = 10.
wa_fieldcat-emphasize = ' X '.
Wa_fieldcat-key = ' X '.
APPEND Wa_fieldcat to It_fieldcat.
Clear Wa_fieldcat.

Wa_fieldcat-fieldname = ' ebelp '.
Wa_fieldcat-scrtext_m = ' PO Item '.
Wa_fieldcat-col_pos = 1.
APPEND Wa_fieldcat to It_fieldcat.
Clear Wa_fieldcat.

Wa_fieldcat-fieldname = ' Statu '.
wa_fieldcat-scrtext_m = ' Status '.
Wa_fieldcat-col_pos = 2.
APPEND Wa_fieldcat to It_fieldcat.
Clear Wa_fieldcat.

Wa_fieldcat-fieldname = ' Aedat '.
Wa_fieldcat-scrtext_m = ' Item change Date '.
Wa_fieldcat-col_pos = 3.
APPEND Wa_fieldcat to It_fieldcat.
Clear Wa_fieldcat.

Wa_fieldcat-fieldname = ' Matnr '.
Wa_fieldcat-scrtext_m = ' Material number '.
Wa_fieldcat-col_pos = 4.
APPEND Wa_fieldcat to It_fieldcat.
Clear Wa_fieldcat.

Wa_fieldcat-fieldname = ' Menge '.
Wa_fieldcat-scrtext_m = ' PO quantity '.
Wa_fieldcat-col_pos = 5.
APPEND Wa_fieldcat to It_fieldcat.
Clear Wa_fieldcat.

Wa_fieldcat-fieldname = ' Meins '.
Wa_fieldcat-scrtext_m = ' Order unit '.
Wa_fieldcat-col_pos = 6.
APPEND Wa_fieldcat to It_fieldcat.
Clear Wa_fieldcat.

Wa_fieldcat-fieldname = ' NETPR '.
Wa_fieldcat-scrtext_m = ' Net price '.
* Set Unit Price field to edit
Wa_fieldcat-edit = ' X '.
Wa_fieldcat-col_pos = 7.
Wa_fieldcat-outputlen = 15.
Wa_fieldcat-datatype = ' CURR '.
APPEND Wa_fieldcat to It_fieldcat.
Clear Wa_fieldcat.

Wa_fieldcat-fieldname = ' Peinh '.
wa_fieldcat-scrtext_m = ' Price unit '.
Wa_fieldcat-col_pos = 8.
APPEND Wa_fieldcat to It_fieldcat.
Clear Wa_fieldcat.
EndForm. "Build_fieldcatalog


*&---------------------------------*
*& Form Build_layout
*&---------------------------------*
* Build layout for ALV grid
*----------------------------------*
FORM Build_layout.
* Set layout field for field attributes (i.e. input/output)
Gd_layout-stylefname = ' Field_style '.
Gd_layout-zebra = ' X '.
EndForm. "Build_layout


*&---------------------------------*
*& Form Display_alv_report
*&---------------------------------*
* Display the Using ALV grid
*----------------------------------*
FORM Display_alv_report.
Gd_repid = Sy-repid.

* Call function ' Reuse_alv_grid_display '
Call FUNCTION ' REUSE_ALV_GRID_DISPLAY_LVC '
Exporting
I_callback_program = Gd_repid
* I_callback_user_command = ' User_command '
IS_LAYOUT_LVC = Gd_layout
IT_FIELDCAT_LVC = It_fieldcat
I_save = ' X '
TABLES
T_outtab = It_ekko
Exceptions
Program_error = 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.
EndForm. "Display_alv_report


*&---------------------------------*
*& Form Data_retrieval
*&---------------------------------*
* Retrieve data Form Ekpo table and populate Itab It_ekko
*----------------------------------*
FORM Data_retrieval.
SELECT Ebeln ebelp statu aedat matnr Menge meins NETPR Peinh
Up to ten ROWS
From Ekpo
into corresponding FIELDS of TABLE It_ekko.

EndForm. "Data_retrieval


*&---------------------------------*
*& whether a field can be edited based on criteria
*&---------------------------------*
* Populate Field_style table with specific FIELD attributes
*----------------------------------*
Form Set_specific_field_attributes.
DATA Ls_stylerow TYPE lvc_s_styl.
DATA lt_styletab TYPE lvc_t_styl.
* Populate style variable (field_style) with style properties
* The NETPR Field/column has been set to editable in the Fieldcatalog ...
* The following code sets it to is disabled (display only) if ' NETPR '
* is GT than 10.
LOOP at It_ekko into Wa_ekko.
IF WA_EKKO-NETPR GT 10.
Ls_stylerow-fieldname = ' NETPR '.
Ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
"SET field to Disabled
APPEND Ls_stylerow to Wa_ekko-field_style.
* Can be modified by adding multiple fields in the above code
MODIFY It_ekko from Wa_ekko.
ENDIF.
Endloop.

EndForm. "Set_specific_field_attributes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.