Skip to Content
avatar image
Former Member

ALV output save

Hi everyone,

I have one requirment, In my ALV(Normal not Oops) output there r some records. If i select one record and click on save it shud be saved.The user shud select only one at a time.

This requirment i want to do in oops. So can anybody tell me r give me sample code(in a simple way) . so that i can understand it and do it.

regards

Sameer

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Oct 15, 2008 at 10:17 AM

    after changing value press enter and then save.

    TABLES : MARA.

    TYPES : BEGIN OF SMARA,

    MATNR TYPE MARA-MATNR,

    ERSDA TYPE MARA-ERSDA,

    ERNAM TYPE MARA-ERNAM,

    MTART TYPE MARA-MTART,

    MBRSH TYPE MARA-MBRSH,

    MATKL TYPE MARA-MATKL,

    BRGEW TYPE MARA-BRGEW,

    NTGEW TYPE MARA-NTGEW,

    GEWEI TYPE MARA-GEWEI,

    CELLTAB TYPE LVC_T_STYL,

    END OF SMARA.

    DATA : IMARA TYPE TABLE OF SMARA,

    WMARA TYPE SMARA.

    DATA : TMARA TYPE TABLE OF MARA,

    TWMARA TYPE MARA.

    DATA : L_INDEX TYPE I,

    LT_CELLTAB TYPE LVC_T_STYL.

    DATA : G_CONTAINER TYPE SCRFNAME VALUE 'GRID1',

    GRID1 TYPE REF TO CL_GUI_ALV_GRID,

    G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,

    MODIFIED TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL,

    SLAYOUT TYPE LVC_S_LAYO,

    IFIELDCAT TYPE LVC_T_FCAT,

    WFIELDCAT TYPE LVC_S_FCAT,

    ISORT TYPE LVC_T_SORT,

    WSORT TYPE LVC_S_SORT,

    ISROWS TYPE LVC_T_ROID,

    WSROWS TYPE LVC_S_ROID,

    REFRESH TYPE LVC_S_STBL.

    • local class to handle semantic checks

    CLASS LCL_EVENT_RECEIVER DEFINITION DEFERRED.

    DATA: G_EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER.

    CLASS LCL_EVENT_RECEIVER DEFINITION.

    PUBLIC SECTION.

    METHODS:

    HANDLE_DATA_CHANGED

    FOR EVENT DATA_CHANGED OF CL_GUI_ALV_GRID

    IMPORTING ER_DATA_CHANGED E_UCOMM.

    PRIVATE SECTION.

    DATA: ERROR_IN_DATA TYPE C.

    METHODS: SAVE_ERNAM

    IMPORTING

    PERNAM TYPE LVC_S_MODI

    PMARA TYPE MARA

    PR_DATA_CHANGED TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.

    METHODS: SAVE_BRGEW

    IMPORTING

    PBRGEW TYPE LVC_S_MODI

    PMARA TYPE MARA

    PR_DATA_CHANGED TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.

    ENDCLASS.

    CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.

    METHOD HANDLE_DATA_CHANGED.

    DATA: LS_GOOD TYPE LVC_S_MODI.

    DATA : MMARA TYPE MARA.

    ERROR_IN_DATA = SPACE.

    LOOP AT ER_DATA_CHANGED->MT_GOOD_CELLS INTO LS_GOOD.

    CASE LS_GOOD-FIELDNAME.

    • check if column ERNAM of this row was changed

    WHEN 'ERNAM'.

    CALL METHOD SAVE_ERNAM

    EXPORTING

    PERNAM = LS_GOOD

    PMARA = MMARA

    PR_DATA_CHANGED = ER_DATA_CHANGED.

    WHEN 'BRGEW'.

    CALL METHOD SAVE_BRGEW

    EXPORTING

    PBRGEW = LS_GOOD

    PMARA = MMARA

    PR_DATA_CHANGED = ER_DATA_CHANGED.

    ENDCASE.

    ENDLOOP.

    *§7.Display application log if an error has occured.

    IF ERROR_IN_DATA EQ 'X'.

    CALL METHOD ER_DATA_CHANGED->DISPLAY_PROTOCOL.

    ENDIF.

    ENDMETHOD.

    METHOD SAVE_ERNAM.

    DATA : VERNAM TYPE ERNAM.

    CALL METHOD PR_DATA_CHANGED->GET_CELL_VALUE

    EXPORTING I_ROW_ID = PERNAM-ROW_ID

    I_FIELDNAME = PERNAM-FIELDNAME

    IMPORTING E_VALUE = VERNAM.

    WMARA-ERNAM = VERNAM .

    MODIFY IMARA FROM WMARA INDEX PERNAM-ROW_ID TRANSPORTING ERNAM.

    • APPEND TWMARA TO TMARA.

    • CALL METHOD PR_DATA_CHANGED->MODIFY_CELL

    • EXPORTING I_ROW_ID = PERNAM-ROW_ID

    • I_FIELDNAME = 'ERNAM'

    • I_VALUE = VERNAM.

    ENDMETHOD.

    METHOD SAVE_BRGEW.

    DATA : VBRGEW TYPE BRGEW.

    CALL METHOD PR_DATA_CHANGED->GET_CELL_VALUE

    EXPORTING I_ROW_ID = PBRGEW-ROW_ID

    I_FIELDNAME = PBRGEW-FIELDNAME

    IMPORTING E_VALUE = VBRGEW.

    WMARA-BRGEW = VBRGEW .

    MODIFY IMARA FROM WMARA INDEX PBRGEW-ROW_ID TRANSPORTING BRGEW.

    • APPEND TWMARA TO TMARA.

    • CALL METHOD PR_忉ATA_CHANGED->MODIFY_CELL

    • EXPORTING I_ROW_ID = PERNAM-ROW_ID

    • I_FIELDNAME = 'ERNAM'

    • I_VALUE = VERNAM.

    ENDMETHOD.

    ENDCLASS.

    SELECT-OPTIONS : S_MATNR FOR MARA-MATNR.

    START-OF-SELECTION.

    CALL SCREEN 2000.

    *&----


    *

    *& Module STATUS_2000 OUTPUT

    *&----


    *

    • text

    *----


    *

    MODULE STATUS_2000 OUTPUT.

    SET PF-STATUS 'SAS'.

    • SET TITLEBAR 'xxx'.

    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.

    SELECT MATNR

    ERSDA

    ERNAM

    MTART

    MBRSH

    MATKL

    BRGEW

    NTGEW

    GEWEI

    FROM MARA

    INTO CORRESPONDING FIELDS OF TABLE IMARA

    WHERE MATNR IN S_MATNR.

    LOOP AT IMARA INTO WMARA.

    REFRESH LT_CELLTAB.

    L_INDEX = SY-TABIX.

    IF WMARA-ERNAM <> 'RUDISILL'.

    PERFORM FILL_CELLTAB USING '00080000'

    CHANGING LT_CELLTAB.

    ELSE.

    PERFORM FILL_CELLTAB USING '00100000'

    CHANGING LT_CELLTAB.

    ENDIF.

    INSERT LINES OF LT_CELLTAB INTO TABLE WMARA-CELLTAB.

    MODIFY IMARA INDEX L_INDEX FROM WMARA.

    ENDLOOP.

    ********STYLE***************

    SLAYOUT-STYLEFNAME = 'CELLTAB'.

    SLAYOUT-SEL_MODE = 'C'.

    ******************************

    *******FIELDCAT*************

    WFIELDCAT-COL_POS = '1'.

    WFIELDCAT-FIELDNAME = 'MATNR'.

    APPEND WFIELDCAT TO IFIELDCAT.

    CLEAR WFIELDCAT.

    WFIELDCAT-COL_POS = '2'.

    WFIELDCAT-FIELDNAME = 'ERSDA'.

    APPEND WFIELDCAT TO IFIELDCAT.

    CLEAR WFIELDCAT.

    WFIELDCAT-COL_POS = '3'.

    WFIELDCAT-FIELDNAME = 'ERNAM'.

    WFIELDCAT-EDIT = 'X'.

    APPEND WFIELDCAT TO IFIELDCAT.

    CLEAR WFIELDCAT.

    WFIELDCAT-COL_POS = '4'.

    WFIELDCAT-FIELDNAME = 'MTART'.

    APPEND WFIELDCAT TO IFIELDCAT.

    CLEAR WFIELDCAT.

    WFIELDCAT-COL_POS = '5'.

    WFIELDCAT-FIELDNAME = 'MBRSH'.

    APPEND WFIELDCAT TO IFIELDCAT.

    CLEAR WFIELDCAT.

    WFIELDCAT-COL_POS = '6'.

    WFIELDCAT-FIELDNAME = 'MATKL'.

    APPEND WFIELDCAT TO IFIELDCAT.

    CLEAR WFIELDCAT.

    WFIELDCAT-COL_POS = '7'.

    WFIELDCAT-FIELDNAME = 'BRGEW'.

    WFIELDCAT-DO_SUM = 'X'.

    • wfieldcat-DECMLFIELD = 'BRGEW'.

    • wfieldcat-DECIMALS_O = '000.00'.

    • WFIELDCAT-EDIT = 'X'.

    APPEND WFIELDCAT TO IFIELDCAT.

    CLEAR WFIELDCAT.

    WFIELDCAT-COL_POS = '8'.

    WFIELDCAT-FIELDNAME = 'NTGEW'.

    WFIELDCAT-DO_SUM = 'X'.

    • WFIELDCAT-DECMLFIELD = 'NTGEW'.

    APPEND WFIELDCAT TO IFIELDCAT.

    CLEAR WFIELDCAT.

    WFIELDCAT-COL_POS = '9'.

    WFIELDCAT-FIELDNAME = 'GEWEI'.

    APPEND WFIELDCAT TO IFIELDCAT.

    CLEAR WFIELDCAT.

    ******************************

    GRID1->SET_TABLE_FOR_FIRST_DISPLAY(

    EXPORTING

    • I_BUFFER_ACTIVE =

    • I_BYPASSING_BUFFER =

    • I_CONSISTENCY_CHECK =

    • I_STRUCTURE_NAME =

    • IS_VARIANT =

    • I_SAVE =

    • I_DEFAULT = 'X'

    IS_LAYOUT = SLAYOUT

    • IS_PRINT =

    • IT_SPECIAL_GROUPS =

    • IT_TOOLBAR_EXCLUDING =

    • IT_HYPERLINK =

    • IT_ALV_GRAPHICS =

    • IT_EXCEPT_QINFO =

    • IR_SALV_ADAPTER =

    CHANGING

    IT_OUTTAB = IMARA

    IT_FIELDCATALOG = IFIELDCAT

    • IT_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 S忉-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    CALL METHOD GRID1->REGISTER_EDIT_EVENT

    EXPORTING

    I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_ENTER.

    CREATE OBJECT G_EVENT_RECEIVER.

    SET HANDLER G_EVENT_RECEIVER->HANDLE_DATA_CHANGED FOR GRID1.

    ENDIF.

    ENDMODULE. " STATUS_2000 OUTPUT

    *&----


    *

    *& Module USER_COMMAND_2000 INPUT

    *&----


    *

    • text

    *----


    *

    MODULE USER_COMMAND_2000 INPUT.

    CASE SY-UCOMM.

    WHEN 'EXIT'.

    LEAVE PROGRAM.

    WHEN 'SWITCH'.

    PERFORM SWITCH_EDIT_MODE.

    WHEN '&DATA_SAVE'.

    DATA :E_UCOMM TYPE SY-UCOMM.

    E_UCOMM = '&DATA_SAVE'.

    LOOP AT IMARA INTO WMARA.

    TWMARA-MATNR = WMARA-MATNR.

    TWMARA-ERSDA = WMARA-ERSDA.

    TWMARA-ERNAM = WMARA-ERNAM.

    TWMARA-MTART = WMARA-MTART.

    TWMARA-MBRSH = WMARA-MBRSH.

    TWMARA-MATKL = WMARA-MATKL.

    TWMARA-BRGEW = WMARA-BRGEW.

    TWMARA-NTGEW = WMARA-NTGEW.

    TWMARA-GEWEI = WMARA-GEWEI.

    MODIFY MARA FROM TWMARA.

    CLEAR TWMARA.

    ENDLOOP.

    CLEAR WMARA.

    CLEAR SY-TABIX.

    LOOP AT IMARA INTO WMARA.

    REFRESH LT_CELLTAB.

    L_INDEX = SY-TABIX.

    IF WMARA-ERNAM <> 'RUDISILL'.

    PERFORM FILL_CELLTAB USING '00080000'

    CHANGING LT_CELLTAB.

    ELSE.

    PERFORM FILL_CELLTAB USING '00100000'

    CHANGING LT_CELLTAB.

    ENDIF.

    • MODIFY TABLE LT_CELLTAB INTO TABLE WMARA-CELLTAB.

    *CLEAR WMARA-CELLTAB.

    WMARA-CELLTAB = LT_CELLTAB.

    MODIFY IMARA INDEX L_INDEX FROM WMARA.

    ENDLOOP.

    GRID1->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.

    GRID1->SET_TABLE_FOR_FIRST_DISPLAY(

    EXPORTING

    • I_BUFFER_ACTIVE =

    • I_BYPASSING_BUFFER =

    • I_CONSISTENCY_CHECK =

    • I_STRUCTURE_NAME =

    • IS_VARIANT =

    • I_SAVE =

    • I_DEFAULT = 'X'

    IS_LAYOUT = SLAYOUT

    • IS_PRINT =

    • IT_SPECIAL_GROUPS =

    • IT_TOOLBAR_EXCLUDING =

    • IT_HYPERLINK =

    • IT_ALV_GRAPHICS =

    • IT_EXCEPT_QINFO =

    • IR_SALV_ADAPTER =

    CHANGING

    IT_OUTTAB = IMARA

    IT_FIELDCATALOG = IFIELDCAT

    • IT_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.

    ENDCASE.

    ENDMODULE. " USER_COMMAND_2000 INPUT

    *----


    *

    FORM SWITCH_EDIT_MODE.

    IF GRID1->IS_READY_FOR_INPUT( ) EQ 0.

    • set edit enabled cells ready for input

    CALL METHOD GRID1->SET_READY_FOR_INPUT

    EXPORTING I_READY_FOR_INPUT = 1.

    ELSE.

    • lock edit enabled cells against input

    CALL METHOD GRID1->SET_READY_FOR_INPUT

    EXPORTING I_READY_FOR_INPUT = 0.

    ENDIF.

    ENDFORM. " SWITCH_EDIT_MODE

    FORM FILL_CELLTAB USING VALUE(P_MODE)

    CHANGING PT_CELLTAB TYPE LVC_T_STYL.

    DATA: LS_CELLTAB TYPE LVC_S_STYL,

    L_MODE TYPE RAW4.

    • This forms sets the style of column 'PRICE' editable

    • according to 'p_mode' and the rest to read only either way.

    IF P_MODE EQ '00080000'.

    *§2a.Use attribute CL_GUI_ALV_GRID=>MC_STYLE_ENABLED to set a cell

    • to status "editable".

    L_MODE = CL_GUI_ALV_GRID=>MC_STYLE_ENABLED.

    ELSE. "p_mode eq '00100000'

    *§2b.Use attribute CL_GUI_ALV_GRID=>MC_STYLE_DISABLED to set a cell

    • to status "non-editable".

    L_MODE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.

    ENDIF.

    LS_CELLTAB-FIELDNAME = 'MATNR'.

    LS_CELLTAB-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.

    INSERT LS_CELLTAB INTO TABLE PT_CELLTAB.

    LS_CELLTAB-FIELDNAME = 'ERSDA'.

    LS_CELLTAB-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.

    INSERT LS_CELLTAB INTO TABLE PT_CELLTAB.

    LS_CELLTAB-FIELDNAME = 'ERNAM'.

    LS_CELLTAB-STYLE = L_MODE.

    INSERT LS_CELLTAB INTO TABLE PT_CELLTAB.

    LS_CELLTAB-FIELDNAME = 'BRGEW'.

    LS_CELLTAB-STYLE = L_MODE.

    INSERT LS_CELLTAB INTO TABLE PT_CELLTAB.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 12, 2008 at 05:04 AM

    Closing Thread

    Add comment
    10|10000 characters needed characters exceeded