Simple Report to update material description
REPORT ZMATN_MAKTX_EDIT.
TYPE-POOLS: SLIS. "ALV Declarations
TYPES : BEGIN OF TY_MAKTX,
SEL TYPE C, "Get selected row details
MATNR TYPE MAKT-MATNR,
MAKTX TYPE MAKT-MAKTX,
FIELD_STYLE TYPE LVC_T_STYL, "For Disable
END OF TY_MAKTX.
DATA: IT_MAKT TYPE STANDARD TABLE OF TY_MAKTX,
WA_MAKT LIKE LINE OF IT_MAKT.
*ALV data declarations
DATA: IT_FIELDCAT TYPE LVC_T_FCAT,
WA_FIELDCAT TYPE LVC_S_FCAT,
GD_LAYOUT TYPE LVC_S_LAYO,
GD_REPID LIKE SY-REPID.
DATA: LS_STYLEROW TYPE LVC_S_STYL .DATA: LT_STYLETAB TYPE LVC_T_STYL .
************************************************************************
*Start-of-selection.
START-OF-SELECTION.
PERFORM DATA_RETRIEVAL.
PERFORM BUILD_FIELDCATALOG.
PERFORM BUILD_LAYOUT.
PERFORM DISPLAY_ALV_REPORT.
*&---------------------------------------------------------------------*
*& Form DATA_RETRIEVAL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DATA_RETRIEVAL .
SELECT MATNR MAKTX FROM MAKT INTO CORRESPONDING FIELDS OF TABLE IT_MAKT UP TO 25 ROWS WHERE SPRAS = SY-LANGU .
LOOP AT IT_MAKT INTO WA_MAKT.
LS_STYLEROW-FIELDNAME = 'MAKTX' .
LS_STYLEROW-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.
INSERT LS_STYLEROW INTO TABLE WA_MAKT-FIELD_STYLE.
MODIFY IT_MAKT FROM WA_MAKT.
CLEAR : WA_MAKT.
ENDLOOP.
ENDFORM. " DATA_RETRIEVAL
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM BUILD_FIELDCATALOG .
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'MAKT'
CHANGING
CT_FIELDCAT = IT_FIELDCAT
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
IF SY-SUBRC = 0.
DELETE IT_FIELDCAT WHERE FIELDNAME = 'SPRAS'.
DELETE IT_FIELDCAT WHERE FIELDNAME = 'MAKTG'.
WA_FIELDCAT-EDIT = 'X'.
MODIFY IT_FIELDCAT FROM WA_FIELDCAT TRANSPORTING EDIT WHERE FIELDNAME = 'MAKTX'.
ENDIF.
ENDFORM. " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM BUILD_LAYOUT .
GD_LAYOUT-STYLEFNAME = 'FIELD_STYLE'.
GD_LAYOUT-ZEBRA = 'X'.
GD_LAYOUT-BOX_FNAME = 'SEL'.
ENDFORM. " BUILD_LAYOUT
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DISPLAY_ALV_REPORT .
GD_REPID = SY-REPID.
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_MAKT
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 USER_COMMAND *
*----------------------------------------------------------*
* --> R_UCOMM *
* --> RS_SELFIELD *
*----------------------------------------------------------*
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
CASE R_UCOMM.
WHEN '&IC1'.
LOOP AT IT_MAKT INTO WA_MAKT WHERE SEL = 'X'.
LS_STYLEROW-FIELDNAME = 'MAKTX' .
LS_STYLEROW-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_ENABLED.
WA_MAKT-SEL = ''.
REFRESH : WA_MAKT-FIELD_STYLE.
INSERT LS_STYLEROW INTO TABLE WA_MAKT-FIELD_STYLE.
MODIFY IT_MAKT FROM WA_MAKT INDEX SY-TABIX.
CLEAR : WA_MAKT.
ENDLOOP.
WHEN '&DATA_SAVE'. "or what even event you want
LOOP AT IT_MAKT INTO WA_MAKT.
* process each line of table including new values
ENDLOOP.
ENDCASE.
RS_SELFIELD-REFRESH = 'X'.
ENDFORM. "USER_COMMAND
Ouput:
3 comments
commentsGreat information. the information provided is of great use as i got to learn new things. If you are looking for real time training in SAP ABAP, kindly contact sieve software
ReplySieve software offers real time training by industry experts with live projects and placement support.
SAP ABAP TRAINING IN HYDERABAD
Great Post. The information provided is of great use as I got to learn new things. Keep Blogging.
ReplySAP ABAP TRAINING IN HYDERABAD
Is this not possible via fm "reuse all grid display" and not lvc
Reply