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

In this program the field Price of sflight is editable and when you edit the price this price is modified with modifying the value in the cost column also that has been added in the field sting of the table. When you press enter the values are changed. This example will help u to trance the changed value and then modify other values according to it. 

 

Error rendering macro 'code': Invalid value specified for parameter 'lang'
DATA: OK_CODE LIKE SY-UCOMM,
           SAVE_OK LIKE SY-UCOMM,
           G_GRID TYPE REF TO CL_GUI_ALV_GRID,
           G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
           GT_FIELDCAT TYPE LVC_T_FCAT,
           GS_LAYOUT TYPE LVC_S_LAYO.
DATA : BEGIN OF FS_SFLIGHT,
         CARRID TYPE SFLIGHT-CARRID,
         CONNID TYPE SFLIGHT-CONNID,
         PRICE TYPE SFLIGHT-PRICE,
         COST TYPE SFLIGHT-PRICE,
      END OF FS_SFLIGHT.
CLASS LCL_EVENT_RECEIVER DEFINITION DEFERRED.
DATA: G_EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER.
DATA: T_SFLIGHT LIKE STANDARD TABLE OF FS_SFLIGHT.
*----------------------------------------------------------------------*
* CLASS lcl_event_receiver DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS LCL_EVENT_RECEIVER DEFINITION.
  PUBLIC SECTION.
    METHODS:
    HANDLE_DATA_CHANGED
    FOR EVENT DATA_CHANGED OF CL_GUI_ALV_GRID
    IMPORTING ER_DATA_CHANGED.
    METHODS: CHECK_PRICE
    IMPORTING
    PS_GOOD_PRICE TYPE LVC_S_MODI
    PR_DATA_CHANGED TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.
    METHODS: CH_NEW_PRICE_V_NEW_COST
    IMPORTING
    PSG_COST TYPE LVC_S_MODI
    PS_FLIGHT LIKE FS_SFLIGHT
    PR_DATA_CHANGED TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.
ENDCLASS. "lcl_event_receiver DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_event_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.
  METHOD HANDLE_DATA_CHANGED.
    DATA: LS_GOOD TYPE LVC_S_MODI,
    LS_SFLIGHT TYPE SFLIGHT,
    LS_GOOD_COST TYPE LVC_S_MODI.
    DATA: L_PRICE TYPE SFLIGHT-PRICE.
    LOOP AT ER_DATA_CHANGED->MT_GOOD_CELLS INTO LS_GOOD.
      CASE LS_GOOD-FIELDNAME.
* check if column PLANETYPE of this row was changed
        WHEN 'PRICE'.
          CALL METHOD CHECK_PRICE
            EXPORTING
              PS_GOOD_PRICE   = LS_GOOD
              PR_DATA_CHANGED = ER_DATA_CHANGED.
      ENDCASE.
    ENDLOOP.
  ENDMETHOD. "handle_data_changed
  METHOD CHECK_PRICE.
    DATA: L_PRICE TYPE SFLIGHT-PRICE,
    LS_GOOD_COST TYPE LVC_S_MODI.
    CALL METHOD PR_DATA_CHANGED->GET_CELL_VALUE
      EXPORTING
        I_ROW_ID    = PS_GOOD_PRICE-ROW_ID
        I_FIELDNAME = PS_GOOD_PRICE-FIELDNAME
      IMPORTING
        E_VALUE     = L_PRICE.
    READ TABLE PR_DATA_CHANGED->MT_GOOD_CELLS
    INTO LS_GOOD_COST
    WITH KEY ROW_ID = PS_GOOD_PRICE-ROW_ID
    FIELDNAME = 'PRICE'.
    IF SY-SUBRC = 0.
      READ TABLE T_SFLIGHT INTO FS_SFLIGHT INDEX PS_GOOD_PRICE-ROW_ID.
      MOVE L_PRICE TO FS_SFLIGHT-COST.
      CALL METHOD CH_NEW_PRICE_V_NEW_COST
        EXPORTING
          PSG_COST        = PS_GOOD_PRICE
          PS_FLIGHT       = FS_SFLIGHT
          PR_DATA_CHANGED = PR_DATA_CHANGED.
    ENDIF.
  ENDMETHOD. "check_price
  METHOD CH_NEW_PLANE_V_NEW_SEATSOCC.
    DATA: L_PRICE TYPE SFLIGHT-PRICE.
    DATA: L_COST TYPE SFLIGHT-PRICE.
    .
GET NEW CELL VALUE TO CHECK IT USING METHOD GET_CELL_VALUE.
* (In this case COST).
  CALL METHOD PR_DATA_CHANGED->GET_CELL_VALUE
    EXPORTING
      I_ROW_ID    = PSG_COST-ROW_ID
      I_FIELDNAME = PSG_COST-FIELDNAME
    IMPORTING
      E_VALUE     = L_COST.
  READ TABLE T_SFLIGHT INTO FS_SFLIGHT INDEX PSG_COST-ROW_ID.
  MOVE L_COST TO FS_SFLIGHT-COST.
  CALL METHOD PR_DATA_CHANGED->MODIFY_CELL
    EXPORTING
      I_ROW_ID    = PSG_COST-ROW_ID
      I_FIELDNAME = 'COST'
      I_VALUE     = PS_FLIGHT-COST.
ENDMETHOD. "check_planetype
ENDCLASS. "lcl_event_receiver IMPLEMENTATION
END-OF-SELECTION.
  CALL SCREEN 100.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
  SET PF-STATUS 'STATUS'.
  PERFORM CREATE_AND_INIT_ALV CHANGING T_SFLIGHT
  GT_FIELDCAT
  GS_LAYOUT.
ENDMODULE. " STATUS_0100 OUTPUT
*---------------------------------------------------------------------*
** MODULE PAI INPUT **
*---------------------------------------------------------------------*
MODULE PAI INPUT.
  SAVE_OK = OK_CODE.
  CLEAR OK_CODE.
  CASE SAVE_OK.
    WHEN 'EXIT'.
      PERFORM EXIT_PROGRAM.
  ENDCASE.
ENDMODULE. "pai INPUT
*---------------------------------------------------------------------*
** FORM EXIT_PROGRAM **
*---------------------------------------------------------------------*
FORM EXIT_PROGRAM.
  LEAVE PROGRAM.
ENDFORM. "exit_program
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GT_FIELDCAT text
*----------------------------------------------------------------------*
FORM BUILD_FIELDCAT CHANGING PT_FIELDCAT TYPE LVC_T_FCAT.
  DATA W_CAT TYPE LVC_S_FCAT.
  W_CAT-FIELDNAME = 'CARRID'.
  W_CAT-COLTEXT = 'CARRID'.
  W_CAT-COL_POS = 1.
  W_CAT-EMPHASIZE = 'C700'.
  APPEND W_CAT TO PT_FIELDCAT.
  CLEAR W_CAT.
  W_CAT-FIELDNAME = 'CONNID'.
  W_CAT-COLTEXT = 'Connection id'.
  W_CAT-COL_POS = 2.
  W_CAT-JUST = 'C'.
  APPEND W_CAT TO PT_FIELDCAT.
  CLEAR W_CAT.
  W_CAT-FIELDNAME = 'PRICE'.
  W_CAT-COLTEXT = 'PRICE'.
  W_CAT-COL_POS = 3.
  APPEND W_CAT TO PT_FIELDCAT.
  CLEAR W_CAT.
  W_CAT-FIELDNAME = 'COST'.
  W_CAT-COLTEXT = 'COST'.
  W_CAT-EDIT = 'X'.
  W_CAT-COL_POS = 4.
  APPEND W_CAT TO PT_FIELDCAT.
  CLEAR W_CAT.
  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
      I_STRUCTURE_NAME = 'FS_SFLIGHT'
    CHANGING
      CT_FIELDCAT      = PT_FIELDCAT.
  LOOP AT PT_FIELDCAT INTO W_CAT.
    IF W_CAT-FIELDNAME EQ 'PRICE'.
      W_CAT-EDIT = 'X'.
      MODIFY PT_FIELDCAT FROM W_CAT.
    ENDIF.
  ENDLOOP.
ENDFORM. "build_fieldcat
*&---------------------------------------------------------------------*
*& Form create_and_init_alv
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PT_OUTTAB text
* -->PT_FIELDCAT text
* -->PS_LAYOUT text
*----------------------------------------------------------------------*
FORM CREATE_AND_INIT_ALV CHANGING PT_OUTTAB LIKE T_SFLIGHT
PT_FIELDCAT TYPE LVC_T_FCAT
PS_LAYOUT TYPE LVC_S_LAYO.
  DATA: LT_EXCLUDE TYPE UI_FUNCTIONS.
  CREATE OBJECT G_CUSTOM_CONTAINER
  EXPORTING
  CONTAINER_NAME = 'CONTAINER1'.
  CREATE OBJECT G_GRID
  EXPORTING
  I_PARENT = G_CUSTOM_CONTAINER.
  PERFORM BUILD_FIELDCAT CHANGING PT_FIELDCAT.
  PERFORM EXCLUDE_TB_FUNCTIONS CHANGING LT_EXCLUDE.
  SELECT * FROM SFLIGHT INTO CORRESPONDING FIELDS OF TABLE PT_OUTTAB .
  CALL METHOD G_GRID->SET_TABLE_FOR_FIRST_DISPLAY
    EXPORTING
      IS_LAYOUT            = PS_LAYOUT
      IT_TOOLBAR_EXCLUDING = LT_EXCLUDE
    CHANGING
      IT_FIELDCATALOG      = PT_FIELDCAT
      IT_OUTTAB            = PT_OUTTAB.
* set editable cells to ready for input
  CALL METHOD G_GRID->SET_READY_FOR_INPUT
    EXPORTING
      I_READY_FOR_INPUT = 1.
*Optionally register ENTER to raise event DATA_CHANGED.
* (Per default the user may check data by using the check icon).
  CALL METHOD G_GRID->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 G_GRID.
ENDFORM. "CREATE_AND_INIT_ALV
*&---------------------------------------------------------------------*
*& Form EXCLUDE_TB_FUNCTIONS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_LT_EXCLUDE text
*----------------------------------------------------------------------*
FORM EXCLUDE_TB_FUNCTIONS CHANGING PT_EXCLUDE TYPE UI_FUNCTIONS.
* Only allow to change data not to create new entries (exclude
* generic functions).
  DATA LS_EXCLUDE TYPE UI_FUNC.
  LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY_ROW.
  APPEND LS_EXCLUDE TO PT_EXCLUDE.
  LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_DELETE_ROW.
  APPEND LS_EXCLUDE TO PT_EXCLUDE.
  LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_APPEND_ROW.
  APPEND LS_EXCLUDE TO PT_EXCLUDE.
  LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_INSERT_ROW.
  APPEND LS_EXCLUDE TO PT_EXCLUDE.
  LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_MOVE_ROW.
  APPEND LS_EXCLUDE TO PT_EXCLUDE.
ENDFORM. " EXCLUDE_TB_FUNCTIONS
  • No labels