Skip to Content
author's profile photo Former Member
Former Member

To store Editable Field in ALV

hi! all,

I'm displaying an ALV Grid Report with a field as editable. Now i need to store the values entered in the editable field to a table how to access the data from that field and store. Kindly help me.

Thanks and Regards,

Nagulan

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 06:08 AM

    hi,

    using pf-status set a button with fcode &REFRESH and use the event user_command.

    so when ever u click on button the data is reflected to internal table.

    and also use event_exit using structure slis_event_exit and pass 'X' to parameter AFTER. and pass this to grid display..

    i think this resolve ur problem

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      hi GADDAMEEDI SUBASH

      Thanks for ur immediate reply.

      i have tried this concept tbut its throwing an dump error as

      PERFORM_NOT_FOUND

      CX_SY_DYN_CALL_ILLEGAL_FORM

      Call (PERFORM) to a non-existent routine.

      whats the probelm ? Kindly guide me.

      Thanks & Regards,

      Nagulan

  • author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 06:17 AM

    Hi

    after editing the field write code under user command save button like modify that database table

    so after clicking the save button that values will be stored in DB table

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 06:20 AM

    Hi,

    You can handle the data changed by OOPS (Classes) concept.

    This example will surely help you. This example have three roles is representative, supervisor and planner.

    Representative will only change the status of request to Submit.

    Supervisor will mark the request to Approved or Changed needed.

    Planner will just see the status.

    So we need to handle the data changed i.e. status changed in ALV at runtime.

    In TOP module of program we need to declare a class

    *----------------------------------------------------------------------* 
    * Class Definition . 
    *----------------------------------------------------------------------* 
    CLASS g_cl_alv_control DEFINITION. 
      PUBLIC SECTION. 
        CLASS-METHODS: 
        handle_data_changed 
        FOR EVENT data_changed OF cl_gui_alv_grid 
        IMPORTING er_data_changed. 
    
    ENDCLASS.                    "lcl_alv_control DEFINITION

    In PAI module:

    *&---------------------------------------------------------------------* 
    *&      Module  USER_COMMAND_9001  INPUT 
    *&---------------------------------------------------------------------* 
    MODULE user_command_9001 INPUT. 
    
    * check if the data is changed in ALV. 
    
      CALL METHOD g_alv_grid_9001->check_changed_data. 
      CASE g_ok_code . 
        WHEN 'SUBM'. 
    
          PERFORM f0601_save. 
    
        WHEN 'SHOW'. 
    
           PERFORM f0600_show_selections. 
        CALL SCREEN 9002 STARTING AT 1 1 ENDING AT 130 20. 
    
      ENDCASE. 
    ENDMODULE.                 " USER_COMMAND_9001  INPUT

    In main program we write :

    IF g_flag_role = 'S' OR g_flag_role = 'R'. 
          CALL METHOD g_alv_grid_9001->set_ready_for_input 
            EXPORTING 
              i_ready_for_input = '1'. 
          SET HANDLER g_cl_alv_control=>handle_data_changed 
          FOR g_alv_grid_9001. 
    
          g_screen_active_9001 = 'X'. 
        ELSE. 
          CALL METHOD g_alv_grid_9001->refresh_table_display. 
    
        ENDIF.

    In main program even we write the class implementation:

    *----------------------------------------------------------------------* 
    *       CLASS g_cl_alv_control IMPLEMENTATION 
    *----------------------------------------------------------------------* 
    * 
    *----------------------------------------------------------------------* 
    CLASS g_cl_alv_control IMPLEMENTATION. 
    
    *method to handle the changed data in ALV. 
      METHOD handle_data_changed. 
    *local data 
        DATA: l_wa_good TYPE lvc_s_modi. 
    
        LOOP AT er_data_changed->mt_good_cells INTO l_wa_good. 
    
          CLEAR : g_wa_outtab, g_error. 
          READ TABLE g_t_outtab INTO g_wa_outtab INDEX l_wa_good-row_id . 
          CHECK sy-subrc EQ 0. 
          IF g_wa_outtab-status = l_wa_good-value. 
            CONTINUE. 
          ENDIF. 
    *logic to set the status as per role. 
    * if the status is approved we cannot change the status to any thing else. 
          IF g_wa_outtab-status = c_app. 
    
            MESSAGE e021. 
            g_error = 'X'. 
            l_wa_good-value = c_app. 
    
          ENDIF. 
    * if the role is representative, he can only change the status to 'submitted' only. 
          IF g_flag_role = 'R'. 
            IF l_wa_good-value NE c_sub. 
              MESSAGE e015. 
              g_error = 'X'. 
              g_wa_outtab-status = l_wa_good-value. 
            ENDIF. 
    * if the role is supervisor, he can only change the status to 'change needed' or 'approved' only if the request is submitted by representative. 
          ELSEIF g_flag_role = 'S'. 
            IF g_wa_outtab-status = c_sub. 
              IF l_wa_good-value = c_chg_needed OR l_wa_good-value = c_app. 
    
              ELSE. 
                MESSAGE e016. 
                g_error = 'X'. 
                g_wa_outtab-status = l_wa_good-value. 
              ENDIF. 
            ELSEIF g_wa_outtab-status = c_chg_needed. 
              MESSAGE e016. 
            ELSE. 
              MESSAGE e052. 
              g_error = 'X'. 
              g_wa_outtab-status = l_wa_good-value. 
            ENDIF. 
          ENDIF. 
          IF g_error NE 'X'. 
            g_wa_outtab-update = 'X'. 
            MODIFY g_t_outtab FROM g_wa_outtab INDEX l_wa_good-row_id. 
          ENDIF. 
        ENDLOOP. 
      ENDMETHOD.                    "handle_data_changed 
    
    ENDCLASS.                    "lcl_alv_control IMPLEMENTATION
    

    Hope this will give you a clear picture of how editable ALV is handled.

    Plz reward if useful.

    Thanks,

    Dhanashri.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 06:33 AM

    This code of mine may be help u to achieve ur requirement.

    REPORT z_demo_alv_jg.

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

    • TYPE-POOLS *

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

    TYPE-POOLS: slis.

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

    • INTERNAL TABLES/WORK AREAS/VARIABLES *

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

    DATA: i_fieldcat TYPE slis_t_fieldcat_alv,

    i_index TYPE STANDARD TABLE OF i WITH HEADER LINE,

    w_field TYPE slis_fieldcat_alv,

    p_table LIKE dd02l-tabname,

    dy_table TYPE REF TO data,

    dy_tab TYPE REF TO data,

    dy_line TYPE REF TO data.

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

    • FIELD-SYMBOLS *

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

    FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,

    <dyn_wa> TYPE ANY,

    <dyn_field> TYPE ANY,

    <dyn_tab_temp> TYPE STANDARD TABLE.

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

    • SELECTION SCREEN *

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

    PARAMETERS: tabname(30) TYPE c,

    lines(5) TYPE n.

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

    • START-OF-SELECTION *

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

    START-OF-SELECTION.

    • Storing table name

    p_table = tabname.

    • Create internal table dynamically with the stucture of table name

    • entered in the selection screen

    CREATE DATA dy_table TYPE STANDARD TABLE OF (p_table).

    ASSIGN dy_table->* TO <dyn_table>.

    IF sy-subrc <> 0.

    MESSAGE i000(z_zzz_ca_messages) WITH ' No table found'.

    LEAVE TO LIST-PROCESSING.

    ENDIF.

    • Create workarea for the table

    CREATE DATA dy_line LIKE LINE OF <dyn_table>.

    ASSIGN dy_line->* TO <dyn_wa>.

    • Create another temp. table

    CREATE DATA dy_tab TYPE STANDARD TABLE OF (p_table).

    ASSIGN dy_tab->* TO <dyn_tab_temp>.

    SORT i_fieldcat BY col_pos.

    • Select data from table

    SELECT * FROM (p_table)

    INTO TABLE <dyn_table>

    UP TO lines ROWS.

    REFRESH <dyn_tab_temp>.

    • Display report

    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

    EXPORTING

    i_callback_program = sy-repid

    i_structure_name = p_table

    i_callback_user_command = 'USER_COMMAND'

    i_callback_pf_status_set = 'SET_PF_STATUS'

    TABLES

    t_outtab = <dyn_table>

    EXCEPTIONS

    program_error = 1

    OTHERS = 2.

    IF sy-subrc <> 0.

    ENDIF.

    &----


    *& Form SET_PF_STATUS

    &----


    • Setting custom PF-Status

    ----


    • -->RT_EXTAB Excluding table

    ----


    FORM set_pf_status USING rt_extab TYPE slis_t_extab.

    SET PF-STATUS 'Z_STANDARD'.

    ENDFORM. "SET_PF_STATUS

    &----


    *& Form user_command

    &----


    • Handling custom function codes

    ----


    • -->R_UCOMM Function code value

    • -->RS_SELFIELD Info. of cursor position in ALV

    ----


    FORM user_command USING r_ucomm LIKE sy-ucomm

    rs_selfield TYPE slis_selfield.

    • Local data declaration

    DATA: li_tab TYPE REF TO data,

    l_line TYPE REF TO data.

    • Local field-symbols

    FIELD-SYMBOLS:<l_tab> TYPE table,

    <l_wa> TYPE ANY.

    • Create table

    CREATE DATA li_tab TYPE STANDARD TABLE OF (p_table).

    ASSIGN li_tab->* TO <l_tab>.

    • Create workarea

    CREATE DATA l_line LIKE LINE OF <l_tab>.

    ASSIGN l_line->* TO <l_wa>.

    CASE r_ucomm.

    • When a record is selected

    WHEN '&IC1'.

    • Read the selected record

    READ TABLE <dyn_table> ASSIGNING <dyn_wa> INDEX

    rs_selfield-tabindex.

    IF sy-subrc = 0.

    • Store the record in an internal table

    APPEND <dyn_wa> TO <l_tab>.

    • Fetch the field catalog info

    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

    EXPORTING

    i_program_name = 'Z_DEMO_PDF_JG'

    i_structure_name = p_table

    CHANGING

    ct_fieldcat = i_fieldcat

    EXCEPTIONS

    inconsistent_interface = 1

    program_error = 2

    OTHERS = 3.

    IF sy-subrc = 0.

    • Make all the fields input enabled except key fields

    w_field-input = 'X'.

    MODIFY i_fieldcat FROM w_field TRANSPORTING input

    WHERE key IS INITIAL.

    ENDIF.

    • Display the record for editing purpose

    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

    EXPORTING

    i_callback_program = sy-repid

    i_structure_name = p_table

    it_fieldcat = i_fieldcat

    i_screen_start_column = 10

    i_screen_start_line = 15

    i_screen_end_column = 200

    i_screen_end_line = 20

    TABLES

    t_outtab = <l_tab>

    EXCEPTIONS

    program_error = 1

    OTHERS = 2.

    IF sy-subrc = 0.

    • Read the modified data

    READ TABLE <l_tab> INDEX 1 INTO <l_wa>.

    • If the record is changed then track its index no.

    • and populate it in an internal table for future

    • action

    IF sy-subrc = 0 AND <dyn_wa> <> <l_wa>.

    <dyn_wa> = <l_wa>.

    i_index = rs_selfield-tabindex.

    APPEND i_index.

    ENDIF.

    ENDIF.

    ENDIF.

    • When save button is pressed

    WHEN 'SAVE'.

    • Sort the index table

    SORT i_index.

    • Delete all duplicate records

    DELETE ADJACENT DUPLICATES FROM i_index.

    LOOP AT i_index.

    • Find out the changes in the internal table

    • and populate these changes in another internal table

    READ TABLE <dyn_table> ASSIGNING <dyn_wa> INDEX i_index.

    IF sy-subrc = 0.

    APPEND <dyn_wa> TO <dyn_tab_temp>.

    ENDIF.

    ENDLOOP.

    • Lock the table

    CALL FUNCTION 'ENQUEUE_E_TABLE'

    EXPORTING

    mode_rstable = 'E'

    tabname = p_table

    EXCEPTIONS

    foreign_lock = 1

    system_failure = 2

    OTHERS = 3.

    IF sy-subrc = 0.

    • Modify the database table with these changes

    MODIFY (p_table) FROM TABLE <dyn_tab_temp>.

    REFRESH <dyn_tab_temp>.

    • Unlock the table

    CALL FUNCTION 'DEQUEUE_E_TABLE'

    EXPORTING

    mode_rstable = 'E'

    tabname = p_table.

    ENDIF.

    ENDCASE.

    rs_selfield-refresh = 'X'.

    ENDFORM. "user_command

    Regards,

    Joy.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.