cancel
Showing results for 
Search instead for 
Did you mean: 

LEAVE TO SCREEN 0 AFTER REFRESH ALV IS NOT WORKING

Gonza_90
Explorer
0 Kudos
176

Hello everyone, it is the first time that I post in this community, and I hope I am doing it well.... I need some suggestion to solve a problem with an ABAP code, the detail is that I have an ALV that shows a list of data, and when I insert a new record, I call again to the routine so that the ALV shows the updated information, up to here everything works perfectly; but when pressing the back button, it does not return to the main page, but it loads again the previous screen, and it is reiterative according to the amount of operations that I make in the program. I have already tried making the adjustments in the User Command with the code LEAVE TO SCREEN 0, but it does not work... I hope you can help me...Here is my code...Thanks..!!!

 

FORM RECOVER_DATA.

  IMPORT gv_list    = gv_list FROM MEMORY ID 'F4_LIST'.
  IMPORT gv_module  = gv_module FROM MEMORY ID 'F4_MODULE'.

  CLEAR: tt_rdata[].
    ObjBenMto->GetMateriales(
      EXPORTING
        p_prm1 = p_lgort
        p_prm2 = gv_list
        p_prm3 = gv_module
      IMPORTING
        rtdat = tt_rdata ).

  " Calling the form to build the field catalog
  PERFORM BUILD_FIELDCAT USING lt_fieldcat.

ENDFORM.

FORM BUILD_FIELDCAT USING lt_fieldcat TYPE lvc_t_fcat.

  " Build the fieldcat for the ALV
  " ...
  " ..
  " .
  
  PERFORM PRINT_ALV.

ENDFORM.

FORM PRINT_ALV.

  ls_layout-zebra      = abap_true.
  ls_layout-cwidth_opt = abap_true.
  ls_layout-box_fname  = 'MANDT'.

  " Mostrar los datos en la grilla ALV
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      i_structure_name          = 'TI_ALV'
      is_layout_lvc             = ls_layout
      it_fieldcat_lvc           = lt_fieldcat
      i_callback_program        = sy-repid
      i_callback_pf_status_set  = 'SET_STATUS_CABECERA'
      i_callback_user_command   = 'USER_COMMAND_CABECERA'
    TABLES
      t_outtab                  = tt_rdata
    EXCEPTIONS
      program_error             = 1
      OTHERS                    = 2.

  IF sy-subrc <> 0.
    MESSAGE 'Error when processing the information' TYPE 'E'.
  ENDIF.

ENDFORM.

FORM USER_COMMAND_CABECERA USING  pi_ucomm        TYPE sy-ucomm
                                  pi_wa_selfield  TYPE slis_selfield.

  CASE pi_ucomm.
    WHEN '&NEW'.  "New record
      CLEAR: txt_proc, txt_tipproc, txt_grupo, txt_material.
      IMPORT  gv_list_valor = gv_list_valor
              gv_list       = gv_list
              gv_id_item    = gv_id_item FROM MEMORY ID 'F4_LIST'.
      txt_almorigen = gv_lgort.
      txt_proc      = gv_list_valor.
      gv_list_valor = gv_list_valor.
      gv_list       = gv_list.
      gv_id_item    = gv_id_item.

      CALL SCREEN 1001  STARTING AT 10 5
                        ENDING AT 80 21.

    WHEN '&UPD'.  "Update record
      gv_id_item    = gv_id_item.

      PERFORM GET_ROWLIST USING pi_wa_selfield-tabindex.

      CALL SCREEN 1002  STARTING AT 10 5
                        ENDING AT 100 21.

    WHEN '&DEL'.  "Eliminar Registro

      PERFORM DELETE_DATA USING pi_wa_selfield-tabindex.

    WHEN '&LOA'.  "Upload xls
      CLEAR: txt_file.
      IMPORT  gv_list_valor = gv_list_valor
              gv_list       = gv_list FROM MEMORY ID 'F4_LIST'.
      txt_almorigenx  = gv_lgort.
      txt_listax      = gv_list_valor.
      gv_list_valor   = gv_list_valor.
      gv_list         = gv_list.
      gv_id_item      = gv_id_item.

      CALL SCREEN 1003  STARTING AT 10 5
                        ENDING AT 80 17.

    WHEN '&F03'. " Back
      SET SCREEN 0.
  ENDCASE.

  pi_wa_selfield-refresh    = 'X'.
  pi_wa_selfield-row_stable = 'X'.
  pi_wa_selfield-col_stable = 'X'.
  pi_wa_selfield-exit       = 'X'.

ENDFORM.

FORM NEW_DATA USING ptxt_almorigen  TYPE ZBI_BEN_S02-ALMORIGEN
                    ptxt_proc       TYPE ZBI_BEN_S01H-IDITEM
                    ptxt_tipproc    TYPE ZBI_BEN_S01D-VALORITEM
                    ptxt_grupo      TYPE ZBI_BEN_S02-GRUPO
                    ptxt_material   TYPE MAKT-MAKTX.

  DATA:   rv_cod      TYPE INT4,
          rv_msg      TYPE STRING,
          gv_msg      TYPE STRING.

  CLEAR: rv_cod, rv_msg, gv_msg.

  " User upload confirmation dialog box for upload confirmation
  CALL FUNCTION 'POPUP_TO_CONFIRM'
    EXPORTING
      titlebar      = 'New Record'
      text_question = '¿Are you sure to create the record?'
      text_button_1 = 'YES'
      icon_button_1 = 'ICON_OKAY'
      text_button_2 = 'NO'
      icon_button_2 = 'ICON_CANCEL'
    IMPORTING
      answer        = v_ans.

  IF v_ans NE 'A'.
    IF v_ans EQ '1'.
      ObjBenMto->NewData(
        EXPORTING
          p_prm1 = ptxt_almorigen
          p_prm2 = ptxt_proc
          p_prm3 = ptxt_tipproc
          p_prm4 = ptxt_material
          p_prm5 = ptxt_grupo
        IMPORTING
          lv_cod = rv_cod
          lv_msg = rv_msg ).

        IF rv_cod EQ 1.
          COMMIT WORK.
          MESSAGE rv_msg TYPE 'I'.
          PERFORM RECOVER_DATA. " Calling the Form to update the data from the ALV
        ELSE.
          ROLLBACK WORK.
          MESSAGE rv_msg TYPE 'I'.
        ENDIF.
    ELSE.
      ROLLBACK WORK.
    ENDIF.
  ELSE.
    ROLLBACK WORK.
    MESSAGE 'Process canceled by user' TYPE 'I'.
  ENDIF.

ENDFORM.

 

 

Accepted Solutions (0)

Answers (1)

Answers (1)

Gonza_90
Explorer
0 Kudos

Hi @Sandra_Rossi, thanks for the answer...about the comment:
- I call the ALV routine again to show the updated information, I understand the correct thing is as you mention, that I use the syntax pi_wa_selfield-refresh = “X”, however when I perform this, the ALV is not updated. I do this inside the user command that identifies the tasks to be executed by the program. Or maybe I am wrong to put it here?

FORM USER_COMMAND_CABECERA USING pi_ucomm TYPE sy-ucomm
                                 pi_wa_selfield TYPE slis_selfield.
  CASE pi_ucomm.
    WHEN '&NEW'.  “New record
	“Insert New Record 
    WHEN '&UPD'.  “Update record
	“ Update Record
    WHEN '&DEL'.  “ Delete Record
	“ Delete Record
    WHEN '&LOA'.  “ Upload xls
	“Upload FIle
    WHEN '&F03'. “ Back
	“ Back to previous page
  ENDCASE.
  pi_wa_selfield-refresh = 'X'.
  pi_wa_selfield-row_stable = 'X'.
  pi_wa_selfield-col_stable = 'X'.
ENDFORM.

- About the back button, I press it after doing any action that affects the ALV (Create, modify, delete), with the purpose of returning to the selection screen to consult information with other filters, but the button does not make this function, but it returns to the initial screen of the ALV (screen without showing the new records), and when pressing again the back button, it takes me to the screen that I need.
I hope to have expressed better the incidence that I have... 

Sandra_Rossi
Active Contributor
0 Kudos
If you want to change the contents displayed in the ALV, you must change the global internal table passed to the parameter T_OUTTAB (TT_RDATA), as after the refresh the display will reflect the internal table. "Insert New Record", "Update" and so on should update the internal table, not the database table. Of course, you may do the changes at both, but the screens are usually designed to have a SAVE button to transfer the screen data to the database table(s).
Sandra_Rossi
Active Contributor
0 Kudos
The back button is handled in standard, you don't have to do anything for '&F03'. The problem is probably that when leaving the ALV, you are asking at the same time to refresh the ALV screen, hence you are confusing ALV about what you really want to do.
Gonza_90
Explorer
0 Kudos

Hello @Sandra_Rossi, as I understand then to avoid calling the AVL painting, I must update in first instance the internal table TT_RDATA, and then, made the change, I can automatically insert it to the DB (without using a save button), this is correct? under this premise, I made the change in the routine to delete records and it is working without problems, I attach the code that I am applying to see if I am doing the correct thing, or I am redundant in deletion processes:

FORM DELETE_DATA USING pi_tabindex.

    DATA: gr_alv_grid       TYPE REF TO cl_gui_alv_grid,
          lt_selected_rows  TYPE lvc_t_row,
          lv_index          TYPE lvc_index,
          ls_selected_row   TYPE ts_data,
          rv_cod            TYPE INT4,
          rv_msg            TYPE STRING.

    CLEAR: rv_cod, rv_msg.

    " Read the selected row of the internal table you are displaying in the ALV
    READ TABLE tt_rdata INTO ls_selected_row INDEX pi_tabindex.
    IF sy-subrc = 0.

      " Confirmation dialog box
      CALL FUNCTION 'POPUP_TO_CONFIRM'
        EXPORTING
          titlebar      = 'Delete Record'
          text_question = '¿Are you sure to delete the selected record?'
          text_button_1 = 'Yes'
          icon_button_1 = 'ICON_OKAY'
          text_button_2 = 'No'
          icon_button_2 = 'ICON_CANCEL'
        IMPORTING
          answer        = v_ans.

      IF v_ans NE 'A'.
        IF v_ans EQ '1'. " User confirms deletion

          " Delete the record from the internal table
          DELETE tt_rdata INDEX pi_tabindex.

          IF sy-subrc = 0.
            " Calling the method to delete the record in the database
            ObjBenMto->DelData(
              EXPORTING
                p_prm1 = ls_selected_row-almorigen
                p_prm2 = ls_selected_row-idreg
                p_prm3 = ls_selected_row-reftexto
                p_prm4 = ls_selected_row-sku
              IMPORTING
                lv_cod = rv_cod
                lv_msg = rv_msg ).

            IF rv_cod EQ 1.
              gv_flag = 'X'.
              COMMIT WORK.
              MESSAGE rv_msg TYPE 'I'.
            ELSE.
              ROLLBACK WORK.
              MESSAGE rv_msg TYPE 'I'.
            ENDIF.

          ELSE.
            MESSAGE 'The record could not be found in the internal table.' TYPE 'E'.
          ENDIF.

        ELSE. " User cancels deletion
          MESSAGE 'Deletion canceled by the user.' TYPE 'I'.
        ENDIF.

      ELSE.
        MESSAGE 'Process canceled by the user.' TYPE 'I'.
      ENDIF.

    ENDIF.

  ENDFORM.
Sandra_Rossi
Active Contributor
ALV and database content are two completely different things. If you want to change the database contents, it's advised to implement a SAVE button and transfer the ALV contents to the database. Maybe you are confused that the ABAP statements INSERT, MODIFY and DELETE can be used either for updating an internal table or for updating a database, e.g. "INSERT wa INTO TABLE itab" is for an internal table, "INSERT dbtab FROM TABLE itab" is for inserting lines into a database table. See the ABAP documentation for more information.