SAP Bilgi Merkezi
Ana Sayfa  ABAP   FI   CO   MM   SD   PP   QM   HR   BW 
ABAP Destek
ALV Delete / Update

ALV de satır silme ve kaydetme opsiyonları için USER_COMMAND eventini kodlamak gerekir. Kullanıcı tarafından girilen verileri okumak için aşağıdaki USER_COMMAND kodunu inceleyebilirsiniz.

Örnek Program:

*&---------------------------------------------------------------------*
*& Report  : ZMM_MATNR
*& BY      : Yavuz KOMUT
*& DATE    : 03.04.2006
*& VERSION : 1.0
*&---------------------------------------------------------------------*
REPORT  zmm_matnr.

TABLES: mara.

TYPE-POOLS : slis.

* CONSTANTS
CONSTANTS: gc_title LIKE sy-title VALUE 'Malzeme Listesi',
           gc_x VALUE 'X'.

* DATA DECLERATIONS
DATA : BEGIN OF gt_alv OCCURS 10,
         zmark(1),
         matnr LIKE mara-matnr,
         ernam LIKE mara-ernam,
         matkl LIKE mara-matkl,
         brgew LIKE mara-brgew,
         ntgew LIKE mara-ntgew,
         gewei LIKE mara-gewei,
       END OF gt_alv.

DATA : gv_repid LIKE sy-repid VALUE 'ZMM_MATNR' .

* ALV DATA DECLERATION
DATA : gt_fcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
       gt_hdr  TYPE slis_t_listheader   WITH HEADER LINE,
       gt_sort TYPE slis_t_sortinfo_alv WITH HEADER LINE,
       gs_layout TYPE slis_layout_alv.

*----------------------------------------------------------------------*
*   S E L E C T I O N   S C R E E N                                    *
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK bl1 WITH FRAME TITLE text-000.
SELECT-OPTIONS : s_matnr FOR mara-matnr MEMORY ID mat OBLIGATORY.
PARAMETERS : p_matkl LIKE mara-matkl MEMORY ID mkl OBLIGATORY.
SELECTION-SCREEN END OF BLOCK bl1.

START-OF-SELECTION.
  PERFORM read_data.

END-OF-SELECTION.
  PERFORM display.

*&---------------------------------------------------------------------*
*&      Form  display
*&---------------------------------------------------------------------*
FORM display .
  PERFORM fill_fcat.
  PERFORM display_itab.
ENDFORM.                    " display
*&---------------------------------------------------------------------*
*&      Form  fill_fcat
*&---------------------------------------------------------------------*
FORM fill_fcat .
  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      i_program_name         = gv_repid
      i_internal_tabname     = 'GT_ALV'
      i_inclname             = gv_repid
    CHANGING
      ct_fieldcat            = gt_fcat[]
    EXCEPTIONS
      inconsistent_interface = 1
      program_error          = 2
      OTHERS                 = 3.

  gs_layout-zebra = gc_x.
  gs_layout-box_tabname = 'GT_ALV'.
  gs_layout-box_fieldname = 'ZMARK'.
  gs_layout-colwidth_optimize = gc_x.
*  gs_layout-window_titlebar = gc_title.

  LOOP AT gt_fcat.
    CASE gt_fcat-fieldname.
      WHEN 'ZMARK'.
        gt_fcat-no_out = gc_x.
      WHEN 'MATNR'.
        gt_fcat-key = gc_x.
        PERFORM alv_rename_title USING text-021.
      WHEN 'ERNAM'.
        gt_fcat-no_out = gc_x.
      WHEN 'MATKL'.
        PERFORM alv_rename_title USING text-022.
      WHEN 'BRGEW'.
        PERFORM alv_rename_title USING text-023.
        gt_fcat-edit      = gc_x.
      WHEN 'NTGEW'.
        PERFORM alv_rename_title USING text-024.
        gt_fcat-do_sum    = gc_x.
        gt_fcat-no_zero   = gc_x.
      WHEN 'GEWEI'.
        PERFORM alv_rename_title USING text-025.
    ENDCASE.
    MODIFY gt_fcat.
  ENDLOOP.
ENDFORM.                    " fill_fcat

*&---------------------------------------------------------------------*
*&      Form  top_of_page
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM top_of_page.

  REFRESH gt_hdr.
  MOVE : 'H' TO gt_hdr-typ,
       text-011 TO gt_hdr-info.
  APPEND gt_hdr. CLEAR gt_hdr.

  PERFORM add_top USING text-012 s_matnr-low s_matnr-high.
  PERFORM add_top USING text-013 p_matkl p_matkl.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary       = gt_hdr[].

ENDFORM.                    "top_of_page

*&---------------------------------------------------------------------*
*&      Form  add_top
*&---------------------------------------------------------------------*
FORM add_top USING i_fname i_low i_high.

  MOVE : 'S' TO gt_hdr-typ,
         i_fname TO gt_hdr-key.

  IF i_low EQ i_high OR i_high IS INITIAL.
    WRITE : i_low  TO gt_hdr-info.
  ELSE.
    WRITE : i_low  TO gt_hdr-info(12),
            ' - '  TO gt_hdr-info+12(3),
            i_high TO gt_hdr-info+15(10).
  ENDIF.

  APPEND gt_hdr. CLEAR gt_hdr.

ENDFORM.                    "set_pf_status

*&---------------------------------------------------------------------*
*&      Form  display_itab
*&---------------------------------------------------------------------*
FORM display_itab .
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program       = gv_repid
      i_callback_pf_status_set = 'SET_PF_STATUS'
      i_callback_user_command  = 'USER_COMMAND'
      i_callback_top_of_page   = 'TOP_OF_PAGE'
      i_save                   = 'A'
      is_layout                = gs_layout
      it_fieldcat              = gt_fcat[]
      it_sort                  = gt_sort[]
    TABLES
      t_outtab                 = gt_alv
    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.

ENDFORM.                    " display_itab

*&---------------------------------------------------------------------*
*&      Form  set_pf_status
*&---------------------------------------------------------------------*
FORM set_pf_status USING rt_extab TYPE slis_t_extab.
  SET TITLEBAR 'ZMMTITL'.
  SET PF-STATUS 'ZMMSTAT'.
ENDFORM.                    "set_pf_status

*&---------------------------------------------------------------------*
*&      Form  user_command
*&---------------------------------------------------------------------*
FORM user_command  USING i_ucomm LIKE sy-ucomm
                         i_selfl TYPE slis_selfield.

  DATA: lo_grid TYPE REF TO cl_gui_alv_grid.

  IF lo_grid IS INITIAL.
    CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
      IMPORTING
        e_grid = lo_grid.
  ENDIF.
  IF NOT lo_grid IS INITIAL.
    CALL METHOD lo_grid->check_changed_data.
  ENDIF.

  CASE i_ucomm.
    WHEN 'UPDT'.
      i_selfl-refresh = gc_x.
    WHEN '&IC1'.
      READ TABLE gt_alv INDEX i_selfl-tabindex.
      SET PARAMETER ID 'MAT' FIELD gt_alv-matnr.
      CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
  ENDCASE.
ENDFORM.                    "user_command

*&---------------------------------------------------------------------*
*&      Form  alv_rename_title
*&---------------------------------------------------------------------*
FORM alv_rename_title  USING    p_text.

  gt_fcat-seltext_l    = p_text.
  gt_fcat-seltext_m    = p_text.
  gt_fcat-seltext_s    = p_text.
  gt_fcat-reptext_ddic = p_text.

ENDFORM.                    " alv_rename_title

*&---------------------------------------------------------------------*
*&      Form  read_data
*&---------------------------------------------------------------------*
FORM read_data .

  SELECT * FROM mara
    INTO CORRESPONDING FIELDS OF TABLE gt_alv
   WHERE matnr IN s_matnr
     AND matkl EQ p_matkl.

ENDFORM.                    " read_data
ABAP Programlar
SAP Chain
SAP NetWeaver
ticket sistemimize katılın ve ücretsiz
10 adam gün kazanın >>
 Ana Sayfa  |  ABAP  |  FI  |  CO  |  MM  |  SD  |  PP  |  QM  |  HR  |  BW 
ykomut@gmail.com