Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

*&---------------------------------------------------------------------*

*& Report ZABAP00ALV

*&

*&---------------------------------------------------------------------*

*&

*&

*&---------------------------------------------------------------------*REPORT ZABAPAALVEDIT MESSAGE-ID ZDEV.

.

TYPE-POOLS:

VIMTY.

TYPES : BEGIN OF TY_MOD,

ROW TYPE I,

END OF TY_MOD.

DATA :

LH_NOREC TYPE I,

LH_TOTAL(5) TYPE C,

LH_SUCC(40) TYPE C,

LWA_DEL TYPE TY_MOD,

LWA_MOD TYPE TY_MOD,

LH_TOTDEL TYPE I,

LH_FLAG TYPE C,

LI_FIELDCAT TYPE LVC_T_FCAT,

LWA_FIELDCAT TYPE LVC_S_FCAT.

DATA: G_CONTAINER TYPE SCRFNAME VALUE 'CUSTOM_CONTAINER',

GRID1 TYPE REF TO CL_GUI_ALV_GRID,

G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.

DATA: I_TABLE TYPE REF TO DATA,

WA_ALL TYPE REF TO DATA.

DATA: ORG_CRIT_INST TYPE VIMTY_OC_TYPE,

OLD_RC LIKE SY-SUBRC,

ACT_LEVEL LIKE AUTHB-ACTVT,

ONLY_SHOW_ALLOWED TYPE C,

I_EXCLUDE TYPE UI_FUNCTIONS.

DATA :I_MOD TYPE STANDARD TABLE OF TY_MOD,

I_DEL TYPE STANDARD TABLE OF TY_MOD.

FIELD-SYMBOLS:

<I_ITAB> TYPE TABLE,

<WA_TAB> TYPE ANY.

DATA: BEGIN OF HEADER OCCURS 1.

INCLUDE STRUCTURE VIMDESC.

DATA: END OF HEADER.DATA: BEGIN OF NAMTAB OCCURS 50.

INCLUDE STRUCTURE VIMNAMTAB.

DATA: END OF NAMTAB.

DATA: VIM_WHERETAB LIKE VIMWHERETB OCCURS 10.

DATA: DBA_SELLIST LIKE VIMSELLIST OCCURS 10.

SELECTION-SCREEN BEGIN OF BLOCK BB WITH FRAME TITLE TEXT-100.

PARAMETER: VIEWNAME TYPE TVDIR-TABNAME.

SELECTION-SCREEN SKIP 2.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN PUSHBUTTON 20(10) TEXT-101 USER-COMMAND B1. "Display

SELECTION-SCREEN PUSHBUTTON 36(10) TEXT-102 USER-COMMAND B2. "Change

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK BB.

AT SELECTION-SCREEN.

CASE SY-UCOMM.

WHEN 'B1'.

SET PF-STATUS 'ALV'.

CALL SCREEN 9001.

WHEN 'B2'.

SET PF-STATUS 'ALV'.

CALL SCREEN 9001.

ENDCASE.* Class used to get changed dataCLASS LCL_EVENT_HANDLER DEFINITION .

PUBLIC SECTION .

METHODS: HANDLE_DATA_CHANGED

FOR EVENT DATA_CHANGED OF CL_GUI_ALV_GRID

IMPORTING ER_DATA_CHANGED.

ENDCLASS. "lcl_event_handler DEFINITION* Class used to get changed dataCLASS LCL_EVENT_HANDLER IMPLEMENTATION .* Handle Data ChangedMETHOD HANDLE_DATA_CHANGED .

PERFORM HANDLE_DATA_CHANGED USING ER_DATA_CHANGED .

ENDMETHOD. "handle_data_changedENDCLASS.

ENDCLASS. "lcl_event_handler IMPLEMENTATION*&---------------------------------------------------------------------*

*& Module STATUS_9001 OUTPUT

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*MODULE STATUS_9001 OUTPUT.

DATA :

GR_EVENT_HANDLER TYPE REF TO LCL_EVENT_HANDLER .* Creating an instance for the event handlerCREATE OBJECT GR_EVENT_HANDLER .

TRY.

CREATE DATA I_TABLE TYPE TABLE OF (VIEWNAME).

ASSIGN I_TABLE->* TO <I_ITAB>.

CREATE DATA WA_ALL LIKE LINE OF <I_ITAB>.

ASSIGN WA_ALL->* TO <WA_TAB>.

* Selecting data dynamically

SELECT * FROM (VIEWNAME) INTO TABLE <I_ITAB>.

* Building the fieldcatelog

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

I_STRUCTURE_NAME = VIEWNAME

CHANGING

CT_FIELDCAT = LI_FIELDCAT

EXCEPTIONS

INCONSISTENT_INTERFACE = 1

PROGRAM_ERROR = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

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

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

ENDIF.

* Making fields editable except key fields

IF SY-UCOMM = 'UPD' OR SY-UCOMM = 'CHANGE'.

LOOP AT LI_FIELDCAT INTO LWA_FIELDCAT.

IF LWA_FIELDCAT-KEY = SPACE.

LWA_FIELDCAT-EDIT = 'X'.

MODIFY LI_FIELDCAT FROM LWA_FIELDCAT.

ENDIF.

ENDLOOP.

ENDIF.

* Making fields editable

IF SY-UCOMM = 'NEW'.

LOOP AT LI_FIELDCAT INTO LWA_FIELDCAT.

LWA_FIELDCAT-EDIT = 'X'.

MODIFY LI_FIELDCAT FROM LWA_FIELDCAT.

ENDLOOP.

LH_FLAG = 'X'.

CLEAR : <I_ITAB>.

DO 100 TIMES.

APPEND <WA_TAB> TO <I_ITAB>.

ENDDO.

ENDIF.

* Exclude buttons

PERFORM EXCLUDE_TB_FUNCTIONS CHANGING I_EXCLUDE.

IF G_CUSTOM_CONTAINER IS INITIAL.

CREATE OBJECT G_CUSTOM_CONTAINER

EXPORTING

CONTAINER_NAME = G_CONTAINER.

CREATE OBJECT GRID1

EXPORTING

I_PARENT = G_CUSTOM_CONTAINER.

ENDIF.

* Making all fields non-editable if display mode

IF SY-UCOMM = 'SHOW'.

LOOP AT LI_FIELDCAT INTO LWA_FIELDCAT.

LWA_FIELDCAT-EDIT = ' '.

MODIFY LI_FIELDCAT FROM LWA_FIELDCAT.

ENDLOOP.

ENDIF.

IF SY-UCOMM = 'SAVE'.

LOOP AT LI_FIELDCAT INTO LWA_FIELDCAT.

IF LWA_FIELDCAT-KEY NE SPACE.

LWA_FIELDCAT-EDIT = SPACE.

MODIFY LI_FIELDCAT FROM LWA_FIELDCAT.

ENDIF.

ENDLOOP.

ENDIF.

* Displaying ALV Grid

CALL METHOD GRID1->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

I_STRUCTURE_NAME = VIEWNAME

IT_TOOLBAR_EXCLUDING = I_EXCLUDE

CHANGING

IT_OUTTAB = <I_ITAB>

IT_FIELDCATALOG = LI_FIELDCAT.

IF SY-SUBRC NE 0.

EXIT.

ENDIF.

* Getting the changed data

SET HANDLER GR_EVENT_HANDLER->HANDLE_DATA_CHANGED FOR GRID1 .

CATCH CX_SY_CREATE_DATA_ERROR. ENDTRY.

ENDMODULE. "status_9001 OUTPUT

*&------------------------------------------------------------*

*& Module USER_COMMAND_9001 INPUT

*&------------------------------------------------------------*

* text

*-------------------------------------------------------------*

MODULE USER_COMMAND_9001 INPUT.

CASE SY-UCOMM.

WHEN 'CHANGE'.

SET PF-STATUS 'ALV'.

WHEN 'SAVE'.

* Lock the table

CALL FUNCTION 'ENQUEUE_E_TABLE'

EXPORTING

MODE_RSTABLE = 'E'

TABNAME = VIEWNAME

EXCEPTIONS

FOREIGN_LOCK = 1

SYSTEM_FAILURE = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

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

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

ENDIF.

IF NOT GRID1 IS INITIAL .

CALL METHOD GRID1->CHECK_CHANGED_DATA .

ENDIF .

SORT I_MOD BY ROW.

DELETE ADJACENT DUPLICATES FROM I_MOD COMPARING ROW.

LH_NOREC = LINES( I_MOD ).

LH_TOTAL = LH_NOREC.

SHIFT LH_TOTAL LEFT DELETING LEADING SPACE.* Standard Table UpdateIF I_MOD[] IS NOT INITIAL.

LOOP AT I_MOD INTO LWA_MOD.

READ TABLE <I_ITAB> INTO <WA_TAB> INDEX

LWA_MOD-ROW.

IF SY-SUBRC = 0 .

IF LH_FLAG NE 'X'.

MODIFY (VIEWNAME) FROM <WA_TAB>.

ELSE.

INSERT (VIEWNAME) FROM <WA_TAB>.

IF SY-SUBRC NE 0.

MESSAGE E009.

ENDIF.

ENDIF.

ENDIF.

ENDLOOP.

CONCATENATE LH_TOTAL ' ' TEXT-S01 INTO LH_SUCC SEPARATED BY SPACE.

MESSAGE I000 WITH LH_SUCC.

ELSE.

MESSAGE I000 WITH TEXT-S02.

ENDIF.* Unlock the tableCALL FUNCTION 'DEQUEUE_E_TABLE'

EXPORTING

MODE_RSTABLE = 'E'

TABNAME = VIEWNAME.

CLEAR : I_MOD[], LH_FLAG.

WHEN 'DELETE'.

* Selecting Selected Rows

PERFORM HANDLE_USER_COMMAND USING SY-UCOMM.

IF I_DEL[] IS NOT INITIAL.

LOOP AT I_DEL INTO LWA_DEL.

READ TABLE <I_ITAB> INTO <WA_TAB> INDEX

LWA_DEL-ROW.

IF SY-SUBRC = 0.

DELETE (VIEWNAME) FROM <WA_TAB>.

ENDIF.

ENDLOOP.

LH_TOTDEL = LINES( I_DEL ).

MESSAGE I011 WITH LH_TOTDEL.

CLEAR : I_DEL[], LH_TOTDEL .

ELSE.

MESSAGE I000 WITH TEXT-S03.

ENDIF.

WHEN 'EXIT' OR

'BACK' OR

'CANCEL'.

CLEAR : LI_FIELDCAT[],

I_EXCLUDE[],

I_DEL[],

LH_TOTDEL.

LEAVE TO SCREEN 0.

ENDCASE.

ENDMODULE. " USER_COMMAND_9001 INPUT5. Write

*&---------------------------------------------------------------------*

*& Form handle_data_changed

*&---------------------------------------------------------------------*

FORM HANDLE_DATA_CHANGED USING P_ER_DATA_CHANGED TYPE REF TO

CL_ALV_CHANGED_DATA_PROTOCOL.

DATA :

LWA_MOD_CELL TYPE LVC_S_MODI,

LWA_MOD TYPE TY_MOD.

LOOP AT P_ER_DATA_CHANGED->MT_GOOD_CELLS

INTO LWA_MOD_CELL.

LWA_MOD-ROW = LWA_MOD_CELL-ROW_ID.

APPEND LWA_MOD TO I_MOD.

ENDLOOP.

ENDFORM. "

*&--------------------------------------------------------------------*

*& Form exclude_tb_functions

*&---------------------------------------------------------------------*

FORM EXCLUDE_TB_FUNCTIONS CHANGING PT_EXCLUDE TYPE UI_FUNCTIONS .

DATA:

LWA_EXCLUDE TYPE UI_FUNC.

LWA_EXCLUDE =

CL_GUI_ALV_GRID=>MC_FC_LOC_APPEND_ROW.

APPEND LWA_EXCLUDE TO PT_EXCLUDE. LWA_EXCLUDE =

CL_GUI_ALV_GRID=>MC_FC_LOC_COPY.

APPEND LWA_EXCLUDE TO PT_EXCLUDE. LWA_EXCLUDE =

CL_GUI_ALV_GRID=>MC_FC_LOC_COPY_ROW.

APPEND LWA_EXCLUDE TO PT_EXCLUDE. LWA_EXCLUDE =

CL_GUI_ALV_GRID=>MC_FC_LOC_CUT.

APPEND LWA_EXCLUDE TO PT_EXCLUDE. LWA_EXCLUDE =

CL_GUI_ALV_GRID=>MC_FC_LOC_DELETE_ROW.

APPEND LWA_EXCLUDE TO PT_EXCLUDE. LWA_EXCLUDE =

CL_GUI_ALV_GRID=>MC_FC_LOC_INSERT_ROW.

APPEND LWA_EXCLUDE TO PT_EXCLUDE. LWA_EXCLUDE =

CL_GUI_ALV_GRID=>MC_FC_LOC_MOVE_ROW.

APPEND LWA_EXCLUDE TO PT_EXCLUDE. LWA_EXCLUDE =

CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE.

APPEND LWA_EXCLUDE TO PT_EXCLUDE. LWA_EXCLUDE =

CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE_NEW_ROW.

APPEND LWA_EXCLUDE TO PT_EXCLUDE.

ENDFORM. "user_command_9001 INPUT

*&---------------------------------------------------------------------*

*& Form handle_user_command

*&---------------------------------------------------------------------*

FORM HANDLE_USER_COMMAND USING P_UCOMM TYPE SYUCOMM.

DATA :

I_SELECTED_ROWS TYPE LVC_T_ROID .

DATA :

LWA_SELECTED_ROW TYPE LVC_S_ROID,

LWA_DEL TYPE TY_MOD.

CALL METHOD GRID1->GET_SELECTED_ROWS

IMPORTING

ET_ROW_NO = I_SELECTED_ROWS.

LOOP AT I_SELECTED_ROWS INTO

LWA_SELECTED_ROW.

LWA_DEL-ROW = LWA_SELECTED_ROW-ROW_ID.

APPEND LWA_DEL TO I_DEL.

ENDLOOP.

ENDFORM. " handle_user_command6.

*Text elements

*----------------------------------------------------------

* 100 OOALV

* 101 Display

* 102 Change

* S01 Records Saved

* S02 No Changes Made

* S03 Please Select Rows First

*Selection texts

*----------------------------------------------------------

* VIEWNAME VIEWNAME

*Messages

*----------------------------------------------------------

*

* Message class: ZDEV

*000

*009

*011

*Text elements

*----------------------------------------------------------

* 100 OOALV

* 101 Display

* 102 Change

* S01 Records Saved

* S02 No Changes Made

* S03 Please Select Rows First

*Selection texts

*----------------------------------------------------------

* VIEWNAME VIEWNAME

*Messages

*----------------------------------------------------------

*

* Message class: ZDEV

*000

*009

*011

  • No labels