Autor Tema: ALV OO: Añadir, borrar y modificar líneas.......  (Leído 50878 veces)

0 Usuarios y 2 Visitantes están viendo este tema.

Desconectado colosoderada

  • Novato
  • *
  • Mensajes: 11
    • Ver Perfil
ALV OO: Añadir, borrar y modificar líneas.......
« en: 19 de Octubre de 2009, 11:32:49 am »
Hola a todo el mundo, estoy ahora pegándome con los ALV OO y quiero hacer uno que permita añadir, borrar, modificar líneas, poner algún botón , etc...... lo mismo que se haría con ALV no orientado a objetos....... pero me estoy volviendo loco........  Alguien no tendrá por ahi algún ejemplo que me pueda mandar al correo o subir a esta página para verlo.......... Muchas gracias por leer este mensaje... Saludos....

Añadir líneas me la añade pero en cuanto la añado...... pufffff me da el siguiente error....

Me inserta la línea pero continua dando el dump....

Errores tiempo ejec. GETWA_NOT_ASSIGNED
Fecha y hora 05.10.2009 13:01:17

Texto breve
Field symbol has not yet been assigned.

¿Qué ha sucedido?
Error in the ABAP Application Program

The current ABAP program "CL_GUI_ALV_GRID===============CP" had to be
terminated because it has
come across a statement that unfortunately cannot be executed.



Desconectado Enrique.Borroni

  • Moderador_
  • Usuario Completo
  • *****
  • Mensajes: 89
    • Ver Perfil
Re: ALV OO: Añadir, borrar y modificar líneas.......
« Respuesta #1 en: 24 de Octubre de 2009, 02:27:34 am »
Aqui te dejo un ejemplo...Ojala te sirva...

1)  Debes Crear una Dynpro : 3000 en ella un custom control llamado CONTENEDOR
2)  Crear un status Gui vacio
3)  Puedes crear o no una segunda Dynpro : 3100 para edicion en detalle de un registro con OK_CODE.
4)  Modifica lo que sea necesario para tu necesidad como por ejemplo el nombre de la Tabla "Z" ( TABLA_Z ).

Saludos.
Atte.,
Enrique Borroni.




El codigo Fuente es el siguiente :

REPORT  ABM_TABLA_Z NO STANDARD PAGE HEADING MESSAGE-ID zx.

TABLES : TABLA_Z.
TYPE-POOLS: icon.

*&---------------------------------------------------------------------*
*&            Declaration Section for the Internal Tables              *
*&---------------------------------------------------------------------*

DATA : t_intab1 LIKE TABLE OF TABLA_Z WITH HEADER LINE,
       t_intab2 LIKE TABLE OF TABLA_Z WITH HEADER LINE,
       w_intab1 LIKE LINE OF t_intab1.

*&---------------------------------------------------------------------*
*&          Declaration Section for EVENT HANDLER CLASS                *
*&---------------------------------------------------------------------*

CLASS lcl_event_receiver DEFINITION DEFERRED.

*&---------------------------------------------------------------------*
*&               Declaration Section for the ALV Grid                  *
*&---------------------------------------------------------------------*

DATA :  ok_code           LIKE sy-ucomm,
        i_container       TYPE scrfname VALUE 'CONTENEDOR',
        obj_grid          TYPE REF TO cl_gui_alv_grid,
        obj_contenedor    TYPE REF TO cl_gui_custom_container,
        i_event_receiver  TYPE REF TO lcl_event_receiver,
        i_fcat            TYPE lvc_t_fcat,
        w_fcat            LIKE LINE OF i_fcat,
        i_fgroup          TYPE lvc_t_sgrp,
        w_fgroup          LIKE LINE OF i_fgroup,
        i_layout          TYPE lvc_s_layo,
        i_variant         TYPE disvariant,
        x_save,
        i_index_rows      TYPE lvc_t_row,
        i_selected_row    LIKE lvc_s_row.

CONSTANTS : c_check       TYPE c VALUE 'X'.

*&---------------------------------------------------------------------*
*&          Classes definition for tool bar push button
*&---------------------------------------------------------------------*

CLASS lcl_event_receiver DEFINITION.

  PUBLIC SECTION.

    METHODS:

    handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
    IMPORTING e_object e_interactive,

    handle_user_command FOR EVENT user_command OF cl_gui_alv_grid
    IMPORTING e_ucomm,

    handle_double_click FOR EVENT double_click OF cl_gui_alv_grid
    IMPORTING e_row e_column,

    handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid
    IMPORTING e_row_id e_column_id es_row_no.

ENDCLASS.                    "lcl_event_receiver DEFINITION

*&---------------------------------------------------------------------*
*&          Classes implementation section
*&---------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.

  METHOD handle_toolbar.

    CONSTANTS:
    c_button_normal TYPE i VALUE 0,
    c_separator     TYPE i VALUE 1.

    DATA: ls_toolbar TYPE stb_button.
    CLEAR ls_toolbar.
    APPEND ls_toolbar TO e_object->mt_toolbar.
    CLEAR ls_toolbar.

    MOVE 'AGRE' TO ls_toolbar-function.
    MOVE icon_create TO ls_toolbar-icon.
    MOVE 'Agregar Nuevos Registros' TO ls_toolbar-quickinfo.
    MOVE ' Agrear' TO ls_toolbar-text.
    MOVE ' ' TO ls_toolbar-disabled.
    APPEND ls_toolbar TO e_object->mt_toolbar.

*    MOVE 'EDIT' TO ls_toolbar-function.
*    MOVE icon_system_copy TO ls_toolbar-icon.
*    MOVE 'Modificar' TO ls_toolbar-quickinfo.
*    MOVE ' Modificar' TO ls_toolbar-text.
*    MOVE ' ' TO ls_toolbar-disabled.
*    APPEND ls_toolbar TO e_object->mt_toolbar.

    MOVE 'UPDATE' TO ls_toolbar-function.
    MOVE icon_system_save TO ls_toolbar-icon.
    MOVE 'Grabar los Cambios' TO ls_toolbar-quickinfo.
    MOVE ' Grabar' TO ls_toolbar-text.
    MOVE ' ' TO ls_toolbar-disabled.
    APPEND ls_toolbar TO e_object->mt_toolbar.

    MOVE 'DELETE' TO ls_toolbar-function.
    MOVE icon_delete TO ls_toolbar-icon.
    MOVE 'Borrar Registro' TO ls_toolbar-quickinfo.
    MOVE ' Borrar' TO ls_toolbar-text.
    MOVE ' ' TO ls_toolbar-disabled.
    APPEND ls_toolbar TO e_object->mt_toolbar.

    MOVE 'REFRESH' TO ls_toolbar-function.
    MOVE icon_refresh TO ls_toolbar-icon.
    MOVE 'Refrescar' TO ls_toolbar-quickinfo.
    MOVE ' Refrescar' TO ls_toolbar-text.
    MOVE ' ' TO ls_toolbar-disabled.
    APPEND ls_toolbar TO e_object->mt_toolbar.

  ENDMETHOD.                    "handle_toolbar

*    Method that check the events in the created buttons.  *
  METHOD handle_user_command.

    CASE e_ucomm.

      WHEN 'AGRE'.
        CALL SCREEN 3100 STARTING AT 25 3.
*      WHEN 'EDIT'.
*        CALL METHOD obj_grid->set_ready_for_input
*          EXPORTING
*            i_ready_for_input = 1.

      WHEN 'UPDATE'.
        PERFORM update_modified_information.

      WHEN 'DELETE'.
        PERFORM delete_selected_information.

      WHEN 'REFRESH'.
        PERFORM refresh_table_information.

    ENDCASE.

  ENDMETHOD.                    "handle_user_command

*    Method that check the event of double click in the grid         *
  METHOD handle_double_click.

***    read table t_intab1 index e_row-index into w_intab1.
***    read table t_intab2 into w_intab2 with key addcode =
***    w_intab1-addcode.
***    if sy-subrc <> 0.
***      message i005.
***    else.
***      call screen 3001 starting at 10 5.
***    endif.

  ENDMETHOD.                    "handle_double_click

*    Method that processes the hotspot event        *
  METHOD handle_hotspot_click.

    PERFORM handle_hotspot USING e_row_id
                                 e_column_id
                                 es_row_no.
  ENDMETHOD.                    "handle_hotspot_click


ENDCLASS.                    "lcl_event_receiver IMPLEMENTATION


*&---------------------------------------------------------------------*
*&            Selection ScreenSection for the ALV Grid
*&---------------------------------------------------------------------*
*SELECTION-SCREEN BEGIN OF BLOCK add1 WITH FRAME TITLE text-001.
*
****select-options : s_acode for TABLA_Z-addcode.
*
*SELECTION-SCREEN END OF BLOCK add1.

*&---------------------------------------------------------------------*
*&               Start Of Selection Event Begins Here                  *
*&---------------------------------------------------------------------*
START-OF-SELECTION.

*                Selects the data into internal tables                 *
  SELECT * FROM TABLA_Z INTO TABLE t_intab1.

  CALL SCREEN 3000.
*&---------------------------------------------------------------------*
*&      Module  STATUS_3000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_3000 OUTPUT.

  SET PF-STATUS 'ABM_TABLA'.
  SET TITLEBAR 'ABM_TABLA'.

  IF obj_contenedor IS INITIAL.
    CREATE OBJECT obj_contenedor "Creating container object
    EXPORTING
    container_name = i_container.

    CREATE OBJECT obj_grid      "Creating AlV Grid Object
    EXPORTING
    i_parent = obj_contenedor.

    CREATE OBJECT i_event_receiver.     "Creating event receiver object

    SET HANDLER i_event_receiver->handle_user_command FOR obj_grid.

    SET HANDLER i_event_receiver->handle_toolbar FOR obj_grid.

    SET HANDLER i_event_receiver->handle_double_click FOR
    obj_grid.

    SET HANDLER i_event_receiver->handle_hotspot_click FOR
    obj_grid.

***    PERFORM create_field_group.         "Grouping of fields funtion

    PERFORM create_field_catalog.       "Field Catalogue creation

**    DATA: BEGIN OF info_tab,
**            client TYPE sy-mandt,
**            username TYPE sy-uname,
**            progname TYPE sy-repid,
**            tcode TYPE sy-tcode,
**            programmer TYPE sy-repid,
**          END OF info_tab.

***    DATA: info_tab1 LIKE TABLE OF info_tab WITH HEADER LINE,
***          w_info_tab1 LIKE LINE OF info_tab1.
***
***    MOVE sy-mandt TO w_info_tab1-client.
***    MOVE sy-uname TO w_info_tab1-username.
***    MOVE sy-repid TO w_info_tab1-progname.
***    MOVE sy-tcode TO w_info_tab1-tcode.
***    APPEND w_info_tab1 TO info_tab1.

    CALL METHOD obj_grid->set_table_for_first_display
      EXPORTING
        is_variant        = i_variant
        i_save            = x_save
        is_layout         = i_layout
        it_special_groups = i_fgroup
      CHANGING
        it_outtab         = t_intab1[]
        it_fieldcatalog   = i_fcat.
  ENDIF.

  CALL METHOD obj_grid->set_ready_for_input
    EXPORTING
      i_ready_for_input = 0.

ENDMODULE.                 " STATUS_3000  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_3000  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_3000 INPUT.

  CALL METHOD cl_gui_cfw=>dispatch.

  CASE ok_code.

    WHEN 'BACK'.
      SET SCREEN 0.
      LEAVE SCREEN.

    WHEN 'EXIT'.
      LEAVE PROGRAM.

  ENDCASE.

ENDMODULE.                 " USER_COMMAND_3000  INPUT

*&---------------------------------------------------------------------*
*&      Module  STATUS_3001  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_3001 OUTPUT.
*  SET PF-STATUS 'xxxxxxxx'.
*  SET TITLEBAR 'xxx'.

ENDMODULE.                 " STATUS_3001  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_3001  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_3001 INPUT.

  CASE ok_code.

    WHEN 'CLOS'.
      SET SCREEN 0.
      LEAVE SCREEN.

  ENDCASE.

ENDMODULE.                 " USER_COMMAND_3001  INPUT


*&---------------------------------------------------------------------*
*&      Form  create_field_catalog
*&---------------------------------------------------------------------*
*       This Subroutine Creates the Field Catalogue.
*----------------------------------------------------------------------*
FORM create_field_catalog.

* Address Code
  w_fcat-fieldname  = 'BWSCL'.
  w_fcat-ref_table  = 'TABLA_Z'.
  w_fcat-ref_field  = 'BWSCL'.
  w_fcat-coltext    = text-100.
  w_fcat-seltext    = text-100.
  w_fcat-col_pos    = 1.
  w_fcat-outputlen  = 15.
  w_fcat-sp_group   = 'GEN'.
  APPEND w_fcat TO i_fcat.
  CLEAR w_fcat.

* Address Name
  w_fcat-fieldname  = 'MSTAE'.
  w_fcat-ref_table  = 'TABLA_Z'.
  w_fcat-ref_field  = 'MSTAE'.
  w_fcat-coltext    = text-105.
  w_fcat-seltext    = text-105.
  w_fcat-col_pos    = 2.
  w_fcat-outputlen  = 15.
  w_fcat-sp_group   = 'GEN'.
  APPEND w_fcat TO i_fcat.
  CLEAR w_fcat.


*  i_layout-grid_title = 'ALV GRID PROGRAMMING'.
  i_layout-zebra        = 'X'.
  i_layout-sel_mode     = 'A'.
  i_variant-report      = sy-repid.
  x_save                = 'A'.

ENDFORM.                    " create_field_catalog

*&---------------------------------------------------------------------*
*&      Form  create_field_group
*&---------------------------------------------------------------------*
*       Creates the Grouping for the Fields in the Grid
*----------------------------------------------------------------------*
FORM create_field_group.

* Employee Information Group
**  w_fgroup-sp_group = 'GEN'.
**  w_fgroup-text     = 'General Details'.
**  APPEND w_fgroup TO i_fgroup.
**
*** Employee Project Information Group
**  w_fgroup-sp_group = 'CON'.
**  w_fgroup-text     = 'Contact Details'.
**  APPEND w_fgroup TO i_fgroup.

ENDFORM.                    " create_field_group

*&---------------------------------------------------------------------*
*&      Form  update_modified_information
*&---------------------------------------------------------------------*
*       Updates all the changed entries into the database table
*----------------------------------------------------------------------*
FORM update_modified_information.

  CALL METHOD obj_grid->refresh_table_display
    EXPORTING
      i_soft_refresh = ''.

  DATA : w_intab1 LIKE TABLE OF TABLA_Z  WITH HEADER LINE .

  UPDATE TABLA_Z FROM TABLE t_intab1.

  IF sy-subrc = 0.
    MESSAGE i000 WITH 'Los Cambios se Guardaron...'.
  ELSE.
    MESSAGE i000 WITH 'Los Cambios NO se Guardaron...'.
  ENDIF.

  CALL METHOD obj_grid->set_ready_for_input
    EXPORTING
      i_ready_for_input = 0.

ENDFORM.                    " update_modified_information

*&---------------------------------------------------------------------*
*&      Form  delete_selected_information
*&---------------------------------------------------------------------*
*       This Deletes the selected row of data form the ALV grid.
*----------------------------------------------------------------------*
FORM delete_selected_information.

  DATA : i_lines TYPE i.

  CLEAR : t_intab2.
  REFRESH : t_intab2.

* Capturar Indice de Fila Marcada
  CALL METHOD obj_grid->get_selected_rows
    IMPORTING
      et_index_rows = i_index_rows.
*
  DESCRIBE TABLE i_index_rows LINES i_lines.

  IF i_lines = 0.
    MESSAGE i000 WITH 'Para Eliminar...Debe Marcar un Registro.'.
    EXIT.
  ENDIF.

* Lee Filas Marcacadas en TBI para Borrado
  LOOP AT i_index_rows INTO i_selected_row.
    READ TABLE t_intab1 INDEX i_selected_row-index INTO w_intab1.
    APPEND w_intab1 TO t_intab2.
  ENDLOOP.
* Borra Las Filas Marcadas en TBI de Borrado
  LOOP AT t_intab2 INTO w_intab1.
    DELETE t_intab1 WHERE BWSCL = w_intab1-BWSCL
                    AND   MSTAE = w_intab1-MSTAE.

    DELETE FROM TABLA_Z WHERE BWSCL = w_intab1-BWSCL
                                AND   MSTAE = w_intab1-MSTAE.
  ENDLOOP.

  COMMIT WORK.

  PERFORM refresh_table_information.

  IF sy-subrc = 0.
    MESSAGE i000 WITH 'Proceso de Borrado Ok.'.
  ELSE.
    MESSAGE i000 WITH 'Fallo el Proceso de Borrado'.
  ENDIF.


ENDFORM.                    " delete_selected_information
*&---------------------------------------------------------------------*
*&      Form  refresh_table_information
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM refresh_table_information.

  CALL METHOD obj_grid->set_ready_for_input
    EXPORTING
      i_ready_for_input = 0.

  CALL METHOD obj_grid->refresh_table_display.

ENDFORM.                    " refresh_table_information
*&---------------------------------------------------------------------*
*&      Form  handle_hotspot
*&---------------------------------------------------------------------*
*       The Process that are done in a hotspot of ALV
*----------------------------------------------------------------------*
FORM handle_hotspot USING    p_e_row_id TYPE lvc_s_row
                             p_e_column_id TYPE lvc_s_col
                             p_es_row_no TYPE lvc_s_roid.

***  READ TABLE t_intab1 INDEX p_e_row_id INTO w_intab1.
***  read table t_intab2 into w_intab2 with key addcode =
***  w_intab1-BWSCL.

***  IF sy-subrc <> 0.
***    MESSAGE i005.
***  ELSE.
***    CALL SCREEN 3001 STARTING AT 10 5.
***  ENDIF.

ENDFORM.                    " handle_hotspot
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_3100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_3100 INPUT.

  CASE ok_code.
    WHEN 'GRAB'.
      PERFORM nuevo_registro.
      SET SCREEN 0.
    WHEN 'CANC'.
      SET SCREEN 0.
  ENDCASE.
  CLEAR : ok_code,
          sy-ucomm.
ENDMODULE.                 " USER_COMMAND_3100  INPUT
*&---------------------------------------------------------------------*
*&      Form  NUEVO_REGISTRO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM nuevo_registro .

  DATA : w_BWSCL LIKE TABLA_Z-BWSCL.

  SELECT SINGLE BWSCL INTO w_BWSCL FROM  TABLA_Z CLIENT SPECIFIED
         WHERE  mandt  = sy-mandt
         AND    BWSCL  = w_intab1-BWSCL
         AND    MSTAE  = w_intab1-MSTAE.
  IF ( sy-subrc EQ 0 ).
    MESSAGE e000 WITH 'Relacion de Bloqueo Ya Existe...'.
  ELSE.
    CLEAR : TABLA_Z.
    MOVE-CORRESPONDING w_intab1 TO TABLA_Z.
    INSERT TABLA_Z.
    COMMIT WORK.

    CLEAR : t_intab1.
    REFRESH : t_intab1.

    SELECT * FROM TABLA_Z INTO TABLE t_intab1.

    CALL METHOD obj_grid->refresh_table_display.

  ENDIF.

ENDFORM.                    " NUEVO_REGISTRO
*&---------------------------------------------------------------------*
*&      Module  STATUS_3100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_3100 OUTPUT.
*  SET PF-STATUS 'xxxxxxxx'.
*  SET TITLEBAR 'xxx'.
  CLEAR : w_intab1.
ENDMODULE.                 " STATUS_3100  OUTPUT
Saludos.

Atte.,
Enrique Borroni

maito : enrique.borroni@abap.es

Desconectado colosoderada

  • Novato
  • *
  • Mensajes: 11
    • Ver Perfil
Re: ALV OO: Añadir, borrar y modificar líneas.......
« Respuesta #2 en: 15 de Diciembre de 2009, 08:54:15 am »
Muchas gracias, le voy a probar............