Update ZTable from editable ALV

Hi All,
i'm calling a Function Module from within a Badi Class ( Workorder_Update) which uses an ALV to Add Comments in a Field of the ALV for Transportation to a ZTable. Therefore the ALV is set to editable.
The Problem is that if the User does not press 'enter' after she/he added the Comment, the value is not send back to the internal Table wich updates the ZTab. If the User presses 'enter' ONLY the Comment is transported but the remainder of the Fields are cleared.
This is part of the Coding:
Before Calling FM -->
  + IF wa_header_old-pronr NE wa_header-pronr.
        CLEAR wa_zthlog.
        wa_zthlog-uzeit     = sy-uzeit.
        wa_zthlog-aufnr     = wa_header-aufnr.
        wa_zthlog-objnr     = wa_header-objnr.
        wa_zthlog-vornr     = wa_operation-vornr.
        wa_zthlog-ktext     = wa_header-ktext.
        wa_zthlog-aenam     = sy-uname.
        wa_zthlog-aedat     = sy-datum.
        wa_zthlog-larnt     = wa_operation-larnt.
        wa_zthlog-pronr     = wa_header-pronr.
        wa_zthlog-arbei     = wa_operation-arbei.
        wa_zthlog-dauno     = wa_operation-dauno.
        wa_zthlog-dauno     = wa_operation-dauno.
        wa_zthlog-ltxa1     = wa_operation-ltxa1.
        wa_zthlog-arbid     = wa_operation-arbid.
        wa_zthlog-fieldname = 'PRONR'.
        wa_zthlog-matkl     = wa_operation-matkl.
        wa_zthlog-preis     = wa_operation-preis.
        wa_zthlog-waers     = wa_header-waers.
        wa_zthlog-old_value = wa_header_old-pronr.
        wa_zthlog-new_value = wa_header-pronr.
Fill t_zthlog - Call FM
        APPEND wa_zthlog TO t_zthlog.
      ENDIF.
    ENDLOOP.
Secure Values before change
    MOVE t_zthlog TO y_zthlog.+
Calling FM -->
+function z_thlog.
  t_zthlog[] = c_zthlog[].
  call screen 0100 starting at 10 3.
  c_zthlog[] = t_zthlog[].
endfunction.+
ALV Grid - Processing -->
+module output_0100 output.
Fill Fieldcatalog
  call function 'LVC_FIELDCATALOG_MERGE'
    exporting
      i_structure_name       = 'ZTHLOG'
    changing
      ct_fieldcat            = gt_fieldcat[]
    exceptions
      inconsistent_interface = 1
      program_error          = 2
      others                 = 3.
  if g_custom_container is initial.
Prepare ALV
    create object g_custom_container
         exporting container_name = g_container.
    create object grid1
         exporting i_parent = g_custom_container.
    g_repid = sy-repid.
    gs_layout-grid_title = 'Änderungsprotokoll'.
    gs_layout-zebra      = 'X'.
    gs_layout-cwidth_opt = 'X'.
    gs_variant-report    = g_repid.
    gs_variant           = '/default'.
gs_layout-edit = 'X'.
Call ALV
    call method grid1->set_table_for_first_display
      exporting
        i_structure_name = 'ZTHLOG'
        is_layout        = gs_layout
        i_save           = 'A'
        is_variant       = gs_variant
      changing
        it_outtab        = t_zthlog
        it_fieldcatalog  = gt_fieldcat[].
Ready for Input
    call method grid1->set_ready_for_input
      exporting
        i_ready_for_input = 1.
Eventregistration
    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.
  else.
Refresh, if filled
    call method grid1->refresh_table_display.
  endif.
set Cursor
  call method cl_gui_control=>set_focus
    exporting
      control = grid1.
endmodule.                 " output_0100  OUTPUT+
There are alot of fields so the manual creation of the fieldcatalog should be avoided if possible.
Any Help is appreciated!
Best Regards
Stefan

Hi,
Check this
* Module Pai INPUT                                                     *
* PAI module                                                           *
module pai input.
  save_ok = ok_code.
  clear ok_code.
  call method grid1->check_changed_data
    importing
      e_valid = v_valid.
" After this system will automatically update your changed data into
" internal table t_zthlog
  case save_ok.
    when 'EXIT'.
      perform f_exit_program.
    when 'CANC'.
      perform f_exit_program.
    when 'BACK'.
      perform f_exit_program.
    when 'SAVE'.
      perform f_save_data.
  endcase.
endmodule.                               " Pai INPUT
aRs

Similar Messages

  • How to update Ztable from Excel file and how to check conditions ,

    HI this uday,
    pls help me how can i update Ztable from Excel file and how to check conditions .
    regards
    uday
    Moderator message: please (re)search yourself before asking.
    Edited by: Thomas Zloch on Jul 13, 2010 12:00 PM

    Hi
    Use Fm : ALSM_EXCEL_TO_INTERNAL_TABLE.
    L_INTERN : internal table with your fields .
    make sure that the fields in the Excel should be formatted (as numeric , characher ) depending upon the data types .
    LOOP AT L_INTERN INTO WA_LINTERN .
            MOVE WA_LINTERN-COL TO L_INDEX.
            ASSIGN COMPONENT  L_INDEX OF STRUCTURE WA_INREC TO <FS> .
            IF SY-SUBRC = 0.
              MOVE WA_LINTERN-VALUE TO <FS>.
            ENDIF.
            AT END OF  ROW .                                    "#EC *
              APPEND WA_INREC TO IT_DATA.  "
              CLEAR WA_INREC.
            ENDAT.
         ENDLOOP.
    Regards
    Swapnil

  • Getting changed data back from editable ALV...

    Hello Gurus,
    I am working on ALV using standard ALV function module REUSE_ALV_GRID_DISPLAY. Now, To make the fields editale, I am using flag EDIT = 'X' in field catalog. This working fine.
    Now, when the data is changed in ALV grid and user clicks on SAVE button that I have programmed in i_callback_usercommand, how can I get the changed data back from editable ALV so that I can change data in custom table ?
    Please help.
    Regards,
    Rajesh.

    I see that the method CHECK_CHANGED_DATA is used. I am also doing it as follows. But how do I get the changed data back in table. There are no table parameters in
    CALL METHOD REF_GRID->CHECK_CHANGED_DATA .
    DATA: REF_GRID TYPE REF TO CL_GUI_ALV_GRID.
    IF REF_GRID IS INITIAL.
    CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
    E_GRID = REF_GRID.
    ENDIF.
    IF NOT REF_GRID IS INITIAL.
    CALL METHOD REF_GRID->CHECK_CHANGED_DATA .
    ENDIF.
    Please guide

  • How to Transfer Data from editable ALV grid control to internal table?

    Hi,
    Can anyone give me a simple example by which I can transfer data from editable alv grid control back to the internal table. The ALV has been created by OO approach.
    I would appreciate if the solution is provided without handling any events.
    Regards,
    Auro

    Hello Auro
    You simply need to call method <b>go_grid->check_changed_data</b> at PAI of the dynpro displaying the ALV grid. If data have been changed on the editable ALV grid then this method will raise event DATA_CHANGED. If you do not want or need to handle this event (e.g. for validating the edited values) then you do not define any event handler method.
    Regards
      Uwe

  • Need to update Ztable from final internal table

    Hi,
    ITAB   = Final internal table has 9 fields : 1 2 3 4 5 6 7 8 9
    Ztable = Ztable has 6 fields ex : 1 3 4 6 7 8
    Structure of both Itab and Ztable are different.
    I have data in the Final Internal table and needs to update data into a ztable.
    If condition is true...
      Modify ztable from itab
    endif.
    Any suggestions how I can update Ztable from the INternal table
    Regards,
    Kittu

    Hello,
    First keep the loop to the final internal table then move all the records to the work area after moving to workarea then create another workarea for the Ztable then move only the field values which are there in Ztable then use modify keyword.
    example
    move:
    y_wa_final_itab-kdauf to y_wa_zhr_item-vbeln,
    y_wa_final_itab-kdpos to y_wa_zhr_item-posnr,
    y_wa_final_itab-receiptno to y_wa_zhr_item-receiptno
    modify zhr_item from y_wa_zhr_item

  • Retrieve changed record from editable alv grid

    hello,
          i am new to alv grid... i am facing some problems working on it... plz help me solve my problems...
          i have created an alv grid displaying the timesheet of some employee's...
          the worktime cells are editable and rest of the information is read only...
          the worktime is changed and then a SAVE button is pushed...
          how do i retrieve the changed time into my internal table?
          once i update the internal table, i can modify the database table...
    thank you.

    Hi,
    Refer this program:-
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
         i_callback_program                = v_rep_id       " report id
         i_callback_pf_status_set          = 'PF'           " for PF-STATUS
         i_callback_user_command           = 'USER_COMMAND' " for User-Command
         is_layout                         = wa_layout      " for layout
         it_fieldcat                       = it_field       " field catalog
         it_sort                           = it_sort        " sort info
        TABLES
          t_outtab                          = it_final      " internal table
       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.
    *&      Form  pf
    *       SUB-ROUTINE PF IS USED TO SET THE PF-STATUS OF THE SCREEN
    *       ON WHICH THE ALV GRID IS DISPLAYED
    *       -->RT_EXTAB
    FORM pf USING rt_extab TYPE slis_t_extab.
      SET PF-STATUS 'ZTG_STAT'.
    ENDFORM.                    "pf
    *&      Form  USER_COMMAND
    *       SUB-ROUTINE USER_COMMAND IS USED TO HANDLE THE USER ACTION
    *       AND EXECUTE THE APPROPIATE CODE
    *      -->LV_OKCODE   used to capture the function code
    *                     of the user-defined push-buttons
    *      -->L_SELFIELD   text
    FORM user_command USING lv_okcode LIKE sy-ucomm l_selfield TYPE slis_selfield.
    * assign the function code to variable v_okcode
      lv_okcode = sy-ucomm.
    * handle the code execution based on the function code encountered
      CASE lv_okcode.
    * when the function code is SAVE then save records into internal table
        WHEN 'SAVE'.
    * to reflect the data changed into internal table
          DATA : ref_grid TYPE REF TO cl_gui_alv_grid. "new
          IF ref_grid IS INITIAL.
            CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
              IMPORTING
                e_grid = ref_grid.
          ENDIF.
          IF NOT ref_grid IS INITIAL.
            CALL METHOD ref_grid->check_changed_data.
          ENDIF.
    "now at this time you have modified internal table
    * refresh the ALV Grid output from internal table
          l_selfield-refresh = c_check.
    "alv output is refreshed as per changes in internal table
    "now you can include code to modify your ztable from internal table
      ENDCASE.
    ENDFORM.                    "USER_COMMAND
    Regards,
    Tarun

  • Update ztable from internal table

    I want to update the Ztable from internal table datas.
    what is the syntax to update.
    Its urgent send with coding example is better

    Hi
    PARAMETERS: p_carrid TYPE sflight-carrid,
                percent(1) TYPE p DECIMALS 0.
    DATA sflight_tab TYPE TABLE OF sflight.
    FIELD-SYMBOLS <sflight> TYPE sflight.
    SELECT *
           FROM sflight
           INTO TABLE sflight_tab
           WHERE carrid = p_carrid AND
                 fldate = sy-datum.
    IF sy-subrc = 0.
      LOOP AT sflight_tab ASSIGNING <sflight>.
        <sflight>-price =
          <sflight>-price * ( 1 - percent / 100 ).
      ENDLOOP.
    ENDIF.
    <b>UPDATE sflight FROM TABLE sflight_tab.</b>
    Thanks
    Vijay
    PLZ reward points if helpful

  • Update ztable from database table directly

    hi all,
    can u tell me the possible ways to update a ztable from database table directly.
    i mean is there anyway to update ztable whenever entry is created in database table .
    i dont want to update using insert,modify statements.
    points will be rewarded to all hlpful answers.

    A slightly dirty solution:
    Use SAP functions for reading from CDHEADER and CDPOS tables [with enough filters such that you extract minimum records possible] to read changes to MARA table fields since last run of your program. Use this information to update your ZTABLE. I would recommend having a table maintainance generator on ZTABLE. The actual update should be by a BDC by calling transaction SM30 for ZTABLE maintainance. Now the program may be set up as a batch job running 1ce an hour. You get updates to the extent of 1 hour latency.
    Alternatively, you may look if an opportunistic BADI / user Exit is there alongside MM01/02 transactions - assuming the latter are the only ones updating MARA. In this BADI you may write the code to update ZTABLE- again, look to do it by BDC call transaction sm30 to maintain ZTable. To lighten up the code -load on BADI you may simply raise a custom event and move on. You will configure a job that runs your program when that particular event is raised. This will need the 'burden' of figuring out the changes, though.
    An elegant way would be to fire a MATMAS fIDOC for every change to Material, capture that and turn back the changes to ZTABLE. This will facilitate the delta load.

  • Updating DB from Edit control

    Hi
       I have a list control that displays the data from a database.When I click on an item in a list control, the details of that item are displayed in the Edit control. Now, when I edit on those details in edit controls and click on an Update button
    I want the newly entered details in the edit control to replace the old data in the list control.
    This is my code to display the details in the edit control when the item is clicked in the list control.
    void CDB2View:: OnClickYourListCtrl(NMHDR* pNMHDR, LRESULT* pResult)
    int row=m_List.GetSelectionMark();
    if(row<0)
        return;
    CString s1=m_List.GetItemText(row,0);
    CString s2=m_List.GetItemText(row,1);
    CString s3=m_List.GetItemText(row,2);
    c_Name.SetWindowText(s1);
    c_Job.SetWindowText(s2);
    c_Age.SetWindowText(s3);
    I don't know how to replace the old data in the list control with the new data that is entered in the edit control. Pls help.

    Use some collection class to store all the data and perform your update/Insert/Delete  data inside the collection class and then simply Fill the data inside the List control with these classes now you just have to Update the List control on the basis
    of index that's all you have to do you simply can call SetItemtext() on particular index to change the text of list control with new item or delete all the item from list and fill it again ,Do whatever you want. Perform Update() on your control as well after
    SetItemtext()
    Thanks
    Rupesh Shukla

  • Updating ztable from the table maintenance

    hi,
           I want to knw how and where to check , whether the records which user has entered in the table control of new entries screen exists in the ztable table or not . if the same record exists then that record should not go for saving it shd be deleted when it is detected that it exists in the ztable . can any one tell me how . where and what code to be written . so that the duplicate entries are deleted and others entries get appended in the database.
    thank you.

    Hi
    if you have declared some Primary key fields then by default when you enter the records in the Table maintenance using SM30 it will not allow duplicate records with the same key fields
    You can check the Table entries in SE16 Tcode
    go to Se16 enter table name execute and see the table records
    Reward points for useful Answers
    Regards
    Anji

  • Udate ztable from a structure

    hello gurus,  i have to change an existing record in ztable with a new value that is stored in a structure,
    i have used this
    update <ztable>from<structure>.
    any help thanks in advance

    Hi Narendar ,
    Check the following program.
    REPORT  zvenkat_container_alv.
    TABLES mara.
    UPDATE mara FROM mara."This is possible if and only if structures should be same.
    "or If structures are different.you have to do the following way.Otherwise syntax error
    DATA: BEGIN OF w_mara,
            matnr TYPE mara-matnr,
            laeda TYPE mara-laeda,
          END OF w_mara.
    UPDATE mara SET laeda = w_mara-laeda
             WHERE matnr = w_mara-matnr.
    I hope that it helps u .
    Regards,
    Venkat.O

  • Editable ALV issue: When Delete/Modify a row, ztable doesnt reflect changes

    Greeting Fellow Abapers,.
    I have been running into an issue that I need some advice on.  I am allowing users to edit a Ztable via ALV.  When the quantity field is updated everything is fine. However, when the field "lic_plate" is edited the code appends another row into the Ztable instead of modifying it.  Also, when the delete row functionality of the grid is used the row is not deleted from the Ztable.
    Here is the ztable structure. The fields I allow to be edited are in BOLD...
    ZPALLET-VBELN
    ZPALLET-MATNR
    ZPALLET-LINE_NUM
    ZPALLET-LIC_PLATE
    ZPALLET-LOT_NUMBER
    ZPALLET-PAL_TYPE
    ZPALLET-MAN_DATE
    ZPALLET-QUANTITY
    ZPALLET-PROC_DATE
    Here is the source code that the APPEND is taking place...
    FORM save_database .
    Getting the selected rows index*
      CALL METHOD o_grid->get_selected_rows
        IMPORTING
          et_index_rows = i_selected_rows.
    Through the index capturing the values of selected rows*
      LOOP AT i_selected_rows INTO w_selected_rows.
        READ TABLE itab INTO wa INDEX w_selected_rows-index.
        IF sy-subrc EQ 0.
          MOVE-CORRESPONDING wa TO w_modified.
          APPEND w_modified TO i_modified.
        ENDIF.
      ENDLOOP.
    IF sy-subrc = 0.
        MODIFY zpallet FROM TABLE i_modified.
    ENDIF.
    ENDFORM.
    Please help. I am in your debt.
    ...as always, points will be awarded.
    Best,
    Dan

    Hello Dan
    When you are using an editable ALV for table maintenance you have to take care that the users
    - cannot edit the key fields of existing DB records   and
    - every new record (row) does not match any existing record (i.e. has identical key field values)
    Instead of relying on selected rows for the DB update I would recommend to store a "PBO image" of your data and compare this with the "PAI image" of the data as soon as the user pushes the SAVE button.
    Example:
    DATA:
      gt_outtab_pbo    TYPE   < your table type>,  " PBO image
      gt_outtab           TYPE   < your table type>.  " PAI image
    " 1. Select data from DB table and store in both itabs:
      SELECT * ... INTO TABLE gt_outtab.
      gt_outtab_pbo = gt_outtab.
    " 2. Display editable ALV list -> user modifies gt_outtab
    " 3. SAVE function requested
    " ... compare gt_outtab vs. gt_outtab_pbo
    " .... INSERT, UPDATE, or DELETE DB records
    " Finally set:
      gt_outtab_pbo = gt_outtab.
    " 2. User continues with editing
    In order to compare PBO vs. PAI data you may have a look at my sample coding:
    [Comparing Two Internal Tables - A Generic Approach|https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/comparing%2btwo%2binternal%2btables%2b-%2ba%2bgeneric%2bapproach]
    Regards,
      Uwe

  • Capture contents from an editable alv

    I'm trying to capture fields from an editable alv. I have an update button in the application toolbar. So when i press this button, whatever changes I have done on the screen, the internal table should get updated. I'm using the function module    REUSE_ALV_GRID_DISPLAY.
    Can anybody help me out??

    Yes you can,
    If you have access to the element in the context that is bound to the row in the ALV then you can connect the message. Marking a * is not possible by default with the WD message manager and you willl need to do it manually. Use the element method of the message manager API for this purpose.

  • Editable ALV- I need to increase curr to be 12 chars from 8 chars in o/p.

    I am getting problem in Editable ALV, I wanted to increase the currency field from 8 chars to 12 chars at the output.
    But after the output i am able to enter only eight chars.
    I want '123456789012'  but i am able to put only '12345678'.
    Plz have alook.

    hi !
    check the length of field in your data declaration
    you can set the length of o/p field in alv for that just check
    intlen or outputlen in fieldcat
    but by using these you can not update these in your internal table b'coz of your type declaration for that field

  • Editable ALVs - How to update DB?

    Hi Experts,
    Out of my curiosity, wuld like to know,
    How the Editable ALVs do updation of DB? I mean, prog. flow?
    thanq.

    ThanQ Sarda,
    OK, I got it.
    Actually, I dont hv much idea abt Editable ALVs! My thinking is like,
    Supose,
    the user changed from 4.63 to 5.63 on ALV grid,
    then, the user either pressed the SAVE(Floppy) or used the programmer defined push button on the front end screen, say the push button name is, UPDATE.
    So,
    1 - Now, How I hv to pull( I mean, How I hv to read the ALV grid?) the (front end value of) 5.63 value to back end, which is to b used for passing to either BAPI/FM or BDC etc. in the prog. for DB updation?
    2 - If the user used the FLOPPY button i.e. SAVE, How to track it ( I know, if the user defined push button is there, we can track by using SY-UCOMM)?
    thanq.

Maybe you are looking for

  • My Imac is showing gray screen with red line when booting and restarts again

    My Imac is showing gray screen with red line when booting and restart again, I can load it in windows 7 safe mode with red lines across the display, pls help

  • Need help on How to edit RDF file to  see fields

    Hi all , Thank you all for being helping could please someone explain where and how to edit the RDF file to view the code and fields, sometimes we need extra fields to add in the RTF templates. And if I get XML file from EBS, on top of the page of xm

  • CONTAINS clause and keywords

    We have an application which uses context indexes, and a user ran the following query today which resulted in an error: select * from paghtrd a where CONTAINS(A.NAME, 'ALL ABOUT AUTOS') > 0; SQL Error: ORA-29902: error in executing ODCIIndexStart() r

  • REUSE_ALV_LIST_DISPLAY  print problem

    Hello, we need to print an ALV using REUSE_ALV_LIST_DISPLAY. We want print immediately the ALV, so we put l_print-print = 'X'. We set the name of the printer in l_print-print_ctrl-pri_params-pdest = 'NAME_PRINTER'. But it doesn't work. Our code is: d

  • I'm trying to set the value of a textfield to a instance of another textfield in a repeating subform

    Hello all, I am trying set the value of a textfield in a repeating subform/table row to another textfield in a repeating subform with the corrosponding instance number. The user enters a list of Key Activities in the first part: -- KeyActivityRow is