Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

alv grid OO runtime error after adding new rows

Hi everybody,

I have a problem with alv OO.

I want to add an empty and editable row to my alv grid and save it after the user filled it.

I have my alv grid:

 
  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.

    CALL METHOD grid1->set_ready_for_input
      EXPORTING
        i_ready_for_input = 1. 
    CALL METHOD GRID1->SET_TABLE_FOR_FIRST_DISPLAY
      EXPORTING
        it_toolbar_excluding = it_exclude
        is_layout = ls_layout
      CHANGING
        IT_OUTTAB            = it_outtab
        it_fieldcatalog      = it_fieldcat[].


    CREATE OBJECT event_receiver.
    SET HANDLER event_receiver->handle_user_command FOR grid1.
    SET HANDLER event_receiver->handle_toolbar FOR grid1.

    CALL METHOD grid1->set_toolbar_interactive.

Then i have a button, that adds a new row to my grid:

      

METHOD handle_user_command.
DATA: lt_rows TYPE lvc_t_row.
 CASE e_ucomm.
 when 'newline'.
        wa_outtab-field1= ''.
        wa_outtab-field2 = ''.
        wa_outtab-field3 = ''.
        wa_outtab-field4 = ''.
        wa_outtab-flag = 'N'.
        ls_celltab-Style = GRID1->mc_style_enabled.
        CLEAR wa_outtab-Style.

        ls_celltab-fieldname = 'field1'.
        insert ls_celltab into table wa_outtab-Style.
        ls_celltab-fieldname = 'field2'.
        insert ls_celltab into table wa_outtab-Style.
        ls_celltab-fieldname = 'field3'.
        insert ls_celltab into table wa_outtab-Style.
        ls_celltab-fieldname = 'field4'.
        insert ls_celltab into table wa_outtab-Style.
        append wa_outtab to IT_OUTTAB.
        clear wa_outtab.
        Call METHOD GRID1->refresh_table_display. 

Now the problem is, i can add a row, but as soon as i fill it, i get a runtime error for any user_command.

So for example:

1. I add an empty row

2. I fill it.

3. I want to add another row --> runtimer error:

Trigger Location of Runtime Error

Program CL_GUI_ALV_GRID===============CP

Include CL_GUI_ALV_GRID===============CM031

Row 96

Module type (METHOD)

Module Name FOREIGN_KEY_CHECK

   

   66                        OF STRUCTURE <ls_ref_table> TO <l_field_to>.
   67
   68       CLEAR lflg_moved.
   69       CLEAR l_no_check.
   70
   71       READ TABLE ct_mod_cells INTO ls_mod_cells
   72                               WITH KEY fieldname = ls_fields-fieldname
   73                                        row_id    = i_row_id.
   74
   75       IF sy-subrc EQ 0.
   76         l_changed_field = ls_fields-fieldname.
   77
   78         READ TABLE m_cl_variant->mt_fieldcatalog INTO l_fcat WITH KEY
   79                  fieldname = ls_fields-fieldname.
   80         IF ls_mod_cells-value IS INITIAL AND l_fcat-no_init_ch ca 'XB'.
   81           l_no_check = 'X'.
   82         ELSEIF ls_mod_cells-error EQ 'X'.
   83           <l_field_to> = ls_mod_cells-value.
   84           lflg_moved = 'X'.
   85         ENDIF.
   86       ENDIF.
   87
   88       IF l_no_check = 'X'.
   89         MOVE-CORRESPONDING ls_mod_cells TO ls_good_cells.
   90         APPEND ls_good_cells TO ct_good_cells.
   91       ELSE.
   92         IF lflg_moved IS INITIAL.
   93           ASSIGN COMPONENT ls_fields-fieldname
   94                            OF STRUCTURE cs_wa TO <l_field_from>.
   95           IF sy-subrc NE 0.
>>>>>             MESSAGE x000(0k).
   97           ENDIF.
   98           <l_field_to> = <l_field_from>.
   99         ENDIF.
  100
  101 *... does checktable contain other key fields which need to be
  102 *    considered
  103         MOVE ls_check-ref_table  TO ls_buf_id-tabname.
  104         MOVE ls_fields-fieldname TO ls_buf_id-fieldname.
  105
  106         MOVE ls_check-ref_table  TO l_tbfk_tabname.
  107         IF ls_fields-ref_field IS INITIAL.
  108           MOVE ls_fields-fieldname TO l_tbfk_fieldname.
  109         ELSE.
  110           MOVE ls_fields-ref_field TO l_tbfk_fieldname.
  111         ENDIF.
  112
  113         IMPORT dd05m_tab TO lt_dd05m
  114                dd08v_tab TO lt_dd08v
  115                timestamp TO ls_timestamp 

First i thought the Problem is that i fill in wrong data (because of "Foreign_key_check"), but thats definitivly not the problem, because if i add the new row with default values like this, i can save it without any problems. But if i edit any of these cells, i get an error again, so the problem has nothing to do with the content of the cells.

      

METHOD handle_user_command.
DATA: lt_rows TYPE lvc_t_row.
 CASE e_ucomm.
 when 'newline'.
        wa_outtab-field1= 'Text'.
        wa_outtab-field2 = '12345'.
        wa_outtab-field3 = '100'.
        wa_outtab-field4 = 'AB'.
        wa_outtab-flag = 'N'.
        ls_celltab-Style = GRID1->mc_style_enabled.
        CLEAR wa_outtab-Style.

        ls_celltab-fieldname = 'field1'.
        insert ls_celltab into table wa_outtab-Style.
        ls_celltab-fieldname = 'field2'.
        insert ls_celltab into table wa_outtab-Style.
        ls_celltab-fieldname = 'field3'.
        insert ls_celltab into table wa_outtab-Style.
        ls_celltab-fieldname = 'field4'.
        insert ls_celltab into table wa_outtab-Style.
        append wa_outtab to IT_OUTTAB.
        clear wa_outtab.
        Call METHOD GRID1->refresh_table_display. 

Does anyone have an idea where's my mistake?

Thanks for your help.

Cheers

DTox2k

Edited by: DTox2k on Oct 21, 2008 9:08 AM

Edited by: DTox2k on Oct 21, 2008 9:18 AM

Former Member

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question