Alv Output Editable and Saving The Data To Database
Alv Output Editable and Saving The Data To Database
Alv Output Editable and Saving The Data To Database
The follow program demonstrates how to make individual fields of an ALV grid
editable (NetPR greater than 10). Changes required from a basic ALV grid include
adding a new field to ALV grid data table(it_ekko), Populating this field with style
attribute and adding an entry to layout control table. Also from the previous
examples used on this website you will also need to change the data type of the
fieldcatalog, the layout and use a different function module for displaying the
report.
*&-------------------------------------------------------------*
*& Report ZDEMO_ALVGRID_EDIT
*&
*
*
*&-------------------------------------------------------------*
*&
*& ...................................
*&
*&-------------------------------------------------------------*
REPORT ZDEMO_ALVGRID_EDIT
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.
TYPE lvc_s_layo,
gd_repid
LIKE sy-repid.
"slis_layout_alv,
************************************************************************
*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
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
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'.
wa_fieldcat-fieldname = 'EBELP'.
wa_fieldcat-scrtext_m = 'PO Item'.
wa_fieldcat-col_pos
= 1.
wa_fieldcat-fieldname = 'STATU'.
wa_fieldcat-scrtext_m = 'Status'.
wa_fieldcat-col_pos
= 2.
wa_fieldcat-fieldname = 'AEDAT'.
wa_fieldcat-scrtext_m = 'Item change date'.
wa_fieldcat-col_pos
= 3.
wa_fieldcat-fieldname = 'MATNR'.
= 4.
wa_fieldcat-fieldname = 'MENGE'.
wa_fieldcat-scrtext_m = 'PO quantity'.
wa_fieldcat-col_pos
= 5.
wa_fieldcat-fieldname = 'MEINS'.
wa_fieldcat-scrtext_m = 'Order Unit'.
wa_fieldcat-col_pos
= 6.
wa_fieldcat-fieldname = 'NETPR'.
wa_fieldcat-scrtext_m = 'Net Price'.
wa_fieldcat-edit
wa_fieldcat-col_pos
= 7.
wa_fieldcat-outputlen = 15.
wa_fieldcat-datatype
= 'CURR'.
wa_fieldcat-fieldname = 'PEINH'.
wa_fieldcat-scrtext_m = 'Price Unit'.
wa_fieldcat-col_pos
= 8.
" BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*&
Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM build_layout.
* Set layout field for field attributes(i.e. input/output)
gd_layout-stylefname = 'FIELD_STYLE'.
gd_layout-zebra
ENDFORM.
= 'X'.
" BUILD_LAYOUT
*&---------------------------------------------------------------------*
*&
Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM display_alv_report.
gd_repid = sy-repid.
= 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
OTHERS
=1
= 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
ENDFORM.
" DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*&
Form DATA_RETRIEVAL
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM data_retrieval.
SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh
UP TO 10 ROWS
FROM ekpo
INTO CORRESPONDING FIELDS OF TABLE it_ekko.
ENDFORM.
" DATA_RETRIEVAL
*&---------------------------------------------------------------------*
*&
Form set_specific_field_attributes
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
form set_specific_field_attributes .
DATA ls_stylerow TYPE lvc_s_styl .
DATA lt_styletab TYPE lvc_t_styl .
ls_stylerow-fieldname = 'NETPR' .
ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
"set field to disabled
* APPEND has now been replaced by the INSERT command as it would error
* if entries are not added in correct order
**
ENDLOOP.
endform.
" set_specific_field_attributes
*----------------------------------------------------------*
*
FORM USER_COMMAND
*----------------------------------------------------------*
*
--> R_UCOMM
--> RS_SELFIELD
*----------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
** Any Changes you have entered on screen will now be stored within
** the original internal table which the ALV was build from (it_ekko)
ENDFORM.