메뉴 건너뛰기

SAP 한국 커뮤니티

[요청]ALV GRID에서 EDIT기능 이용시 질문요~!

풍운사랑 2008.06.30 12:05 조회 수 : 3902 추천:5

아래 소스와 같이 수정 하고 싶은 필드에만 EDIT을 하였는데요 DATA CHANGE이벤트 같은거 해줘야 ITAB내용이 수정 될꺼 같더라구요 아래 소스같이만 하면 행삽입, 행삭제 , EDIT기능이용해서 ITAB내용 수정 했을시에 ITAB에 반영이 안되는거 같아요.   글구  추가로 행 선택시 마크에 X표시가 걸려야 되는데 아래 소스에서 엇게 처리 해야 하는지요.....


혹시 아시는 분께선 소스나 참고 자료좀 추천 해주시면 감사하겠습니다.  ( 아래 소스는 외국 사이트서 구한건데 연구중이라요 원래 EDIT기능 하기 위해 짠 소스가 아닌데 제가 그걸 해보려다 막혀서여 도와줍쇼~ ㅜㅜ)


 


* 아래 소스에선 GT_MARA_ALL인터널 테이블러 ALV출력 하는것입니다.


 


 

report z_alv_grid_ctrl_refresh_2.

tables : mara.

types:
  begin of ty_s_mara,
    matnr like mara-matnr,
    ernam like mara-ernam,
    ersda like mara-ersda,
    brgew like mara-brgew,
    meins like mara-meins,
  end of ty_s_mara.

class lcl_event_alv definition deferred.

data:
  gt_mara type standard table of mara,
  go_container type ref to cl_gui_docking_container,
  go_alv_grid  type ref to cl_gui_alv_grid,
  go_events    type ref to lcl_event_alv,

  gt_mara_ftr type standard table of mara,   " Data filtered
  gt_mara_all type standard table of mara,   " Data readfrom DB

  okcode    type syucomm,
  gv_okcode type syucomm.

*---------------------------------------------------------------------*
*       CLASS lcl_event_alv DEFINITION
*---------------------------------------------------------------------*
class lcl_event_alv definition.

  public section.
    methods:
      h_user_command for event after_user_command of cl_gui_alv_grid
                     importing e_ucomm
                               sender.

endclass.                              " LCL_EVENT_ALV DEFINITION
*---------------------------------------------------------------------*
*        Class (Implementation)  lcl_event_alv
*---------------------------------------------------------------------*
class lcl_event_alv implementation.

  method h_user_command.
    case e_ucomm.
      when '&SORT_ASC' or '&SORT_DSC'" Sort
        perform f_sort_big_table.
*        PERFORM f_read_data USING c_first_page.
        perform f_refresh_table.
      when '&FILTER'.                  " Filter
        perform f_filter_data.
*        PERFORM f_read_data USING c_first_page.
        perform f_refresh_table.
      when '&DELETE_FILTER'.           " Delete filter
*        gt_mara_ftr[] = gt_mara_all[].
*        PERFORM f_read_data USING c_first_page.
        perform f_refresh_table.
    endcase.
  endmethod.                           " user_command

endclass.                              " LCL_EVENT_ALV
*---------------------------------------------------------------------*
*SELECTION-SCREEN :
*BEGIN OF LINE,COMMENT 10(20) v_1 FOR FIELD p_max.           "#EC NEEDED
*PARAMETERS p_max(2) TYPE n DEFAULT '30' OBLIGATORY.
*SELECTION-SCREEN END OF LINE.
selection-screen : begin of block param with frame title text-t13.
selection-screen skip 1.
select-options : s_matnr for mara-matnr.
selection-screen skip 1.
selection-screen end of block param.
*---------------------------------------------------------------------*
initialization.

*  v_1 = 'Lines per page'.

*---------------------------------------------------------------------*
start-of-selection.

  select *
    into corresponding fields of table gt_mara_all
    from mara
    where matnr in s_matnr.

  loop at gt_mara_all into mara.
*    APPEND  mara TO gt_mara_ftr.

  endloop.
*  gt_mara_ftr = gt_mara_all.
  call screen 100.

*---------------------------------------------------------------------*
*       Module  pbo_0100  OUTPUT
*---------------------------------------------------------------------*
module pbo_0100 output.

  set pf-status 'MAIN'.
  set titlebar 'MAIN1'.

  perform create_and_init_alv.

endmodule.                             " PBO_0100  OUTPUT
*---------------------------------------------------------------------*
*       Module  user_command_0100  INPUT
*---------------------------------------------------------------------*
module user_command_0100 input.

  gv_okcode = okcode.
  clear okcode.

  case gv_okcode.
    when 'BACK'.
      set screen 0.
    when 'EXIT'.
      leave program.
*    WHEN c_first_page OR c_next_page OR c_last_page OR c_prev_page.
    when 'REFRESH'.
      call screen 200.
  endcase.

endmodule.                             " USER_COMMAND_0100  INPUT

*---------------------------------------------------------------------*
*       Form  create_and_init_alv
*---------------------------------------------------------------------*
form create_and_init_alv.

* Macro definition
  define m_fieldcat.

    ls_alv_cat-col_pos = 1.
    ls_alv_cat-fieldname = 'ERNAM'.
    ls_alv_cat-ref_table = 'MARA'.
    ls_alv_cat-edit = ' '.
    append ls_alv_cat to lt_alv_cat.

    ls_alv_cat-col_pos = 2.
    ls_alv_cat-fieldname = 'MATNR'.
    ls_alv_cat-ref_table = 'MARA'.
    ls_alv_cat-edit = ' '.
    append ls_alv_cat to lt_alv_cat.

    ls_alv_cat-col_pos = 3.
    ls_alv_cat-fieldname = 'ERSDA'.
    ls_alv_cat-ref_table = 'MARA'.
    ls_alv_cat-edit = 'X'.
    append ls_alv_cat to lt_alv_cat.

    ls_alv_cat-col_pos = 4.
    ls_alv_cat-fieldname = 'BRGEW'.
    ls_alv_cat-ref_table = 'MARA'.
    ls_alv_cat-edit = 'X'.
    append ls_alv_cat to lt_alv_cat.

    ls_alv_cat-col_pos = 5.
    ls_alv_cat-fieldname = 'MEINS'.
    ls_alv_cat-ref_table = 'MARA'.
    ls_alv_cat-no_out = 'X'.

    append ls_alv_cat to lt_alv_cat.
  end-of-definition.

  data:
    ls_variant      type disvariant,
    lt_alv_cat      type lvc_t_fcat,
    ls_alv_cat      type lvc_s_fcat,
    ls_alv_lay      type lvc_s_layo,
    l_offline       type char1.

  check go_container is initial.

  call method cl_gui_alv_grid=>offline
    receiving
      e_offline = l_offline.

  if l_offline eq 0.
    create object go_container
        exporting
            extension = 2000
        exceptions
            cntl_error = 1
            cntl_system_error = 2
            create_error = 3
            lifetime_error = 4
            lifetime_dynpro_dynpro_link = 5
            others                      = 6.
    if sy-subrc ne 0.
      message e999(zmcmm) with 'The control could not be created'.
    endif.
  endif.

* Create an instance of alv control
  create object go_alv_grid
      exporting i_parent = go_container.

  create object go_events.
  set handler go_events->h_user_command for go_alv_grid.

* Build field catalog
  m_fieldcat.
*  m_fieldcat.
*  m_fieldcat.
*  m_fieldcat.

* Layout
  clear ls_alv_lay.
  ls_alv_lay-zebra      = 'X'.
  ls_alv_lay-cwidth_opt = 'X'.

  ls_variant-report = sy-cprog.

* Display
  call method go_alv_grid->set_table_for_first_display
    exporting
      is_variant      = ls_variant
      is_layout       = ls_alv_lay
      i_save          = 'A'
    changing
      it_outtab       = gt_mara_all
      it_fieldcatalog = lt_alv_cat.

endform.                               " CREATE_AND_INIT_ALV
*---------------------------------------------------------------------*
*      Form  F_REFRESH_TABLE
*---------------------------------------------------------------------*
form f_refresh_table.

  data: ls_layout type lvc_s_layo.

  call method go_alv_grid->get_frontend_layout
    importing
      es_layout = ls_layout.

  ls_layout-cwidth_opt = 'X'.

  call method go_alv_grid->set_frontend_layout
    exporting
      is_layout = ls_layout.

  call method go_alv_grid->refresh_table_display.

endform.                               " F_REFRESH_TABLE
*---------------------------------------------------------------------*
*       Form  F_SORT_BIG_TABLE
*---------------------------------------------------------------------*
form f_sort_big_table.

  data:
    lt_sort_kkblo type kkblo_t_sortinfo,
    lt_sort       type lvc_t_sort.

  call method go_alv_grid->get_sort_criteria
    importing
      et_sort = lt_sort.

  check not lt_sort[] is initial.

* Format LVC --> KKBLO
  call function 'LVC_TRANSFER_TO_KKBLO'
    exporting
      it_sort_lvc   = lt_sort
    importing
      et_sort_kkblo = lt_sort_kkblo.

* The big tables must be sorted like the small one
  perform fb_outtab_sort(saplkkbl) tables gt_mara_ftr
                                          lt_sort_kkblo
                                    using 'X'
                                          'X'.

  perform fb_outtab_sort(saplkkbl) tables gt_mara_all
                                          lt_sort_kkblo
                                    using 'X'
                                          'X'.

endform.                               " F_SORT_BIG_TABLE
*---------------------------------------------------------------------*
*      Form  f_filter_data
*---------------------------------------------------------------------*
form f_filter_data.

  data:
    lt_filter_lvc   type lvc_t_filt,
    lt_filter_index type lvc_t_fidx with header line.

  call method go_alv_grid->get_filter_criteria
    importing
      et_filter = lt_filter_lvc.

* Find data to filter
  call function 'LVC_FILTER_APPLY'
    exporting
      it_filter       = lt_filter_lvc
    importing
      et_filter_index = lt_filter_index[]
    tables
      it_data         = gt_mara_all.


  sort lt_filter_index descending.
  loop at lt_filter_index.
    delete gt_mara_all index lt_filter_index.
  endloop.

endform.                               " F_FILTER_DATA
*&---------------------------------------------------------------------*
*&      Module  STATUS_0200  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module status_0200 output.
  set pf-status 'ZKJK1'.
  set titlebar 'xxx'.

endmodule.                 " STATUS_0200  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0200  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module user_command_0200 input.
  gv_okcode = okcode.
  clear okcode.

  case gv_okcode.
    when 'BACK'.
      set screen 100.
    when 'EXIT'.
      leave program.
  endcase.
endmodule.                 " USER_COMMAND_0200  INPUT
*&---------------------------------------------------------------------*
*&      Module  ITAB_MODIFY  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module itab_modify input.

  loop at screen.
    modify screen.
  endloop.

  loop at gt_mara_all into mara.
    modify  gt_mara_all index sy-tabix from mara.
  endloop.
*  MODIFY  gt_mara_all FROM mara-ernam.
*  MODIFY  gt_mara_all FROM mara-ersda.
*  MODIFY  gt_mara_all FROM mara-brgew.
*  MODIFY  gt_mara_all FROM mara-meins.
endmodule.                 " ITAB_MODIFY  INPUT
*&---------------------------------------------------------------------*
*&      Module  ITAB_MODIFY0  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module itab_modify0 output.

  loop at screen.
    modify screen.
  endloop.


  loop at gt_mara_all into mara.
    modify  gt_mara_all index sy-tabix from mara.
  endloop.
endmodule.                 " ITAB_MODIFY0  OUTPUT

번호 제목 글쓴이 날짜 조회 수
6267 [요청]인터널 테이블을 이용한 필드 카탈로그를 가져올 때..... [5] 효방 ^-^ 2008.09.19 4235
6266 <b>[완료]</b>PFCG(롤생성 및 권한 관리)에 관해서 궁금합니다 [4] chanmaniac 2008.06.11 4228
6265 [re] Static Method와 Instance Method의 차이 좀 알려주세요. file sapjoy 2007.08.06 4213
6264 [요청]스마트 폼에서 바코드를 출력할 때, 페이지 포맷에 관해..... [3] Seph 2008.09.10 4192
6263 [re] 데이터 발췌 방법 [3] file sapjoy 2007.01.30 4188
6262 백그라운드 실행에 대해서 [2] 강진규 2007.04.03 4184
6261 <img src=3.gif>엑셀 업로드 시 이런경우가 발생할 수 있는지요. [7] 열공합시다 2010.12.30 4182
6260 <b>[완료]</b>Number RANGE OBJEC 삭제는 어디서 하나요? [3] 예슬짱 2008.12.09 4178
6259 [요청]MB1A BAPI명 어떤건가요? [4] 벤또 2007.11.08 4174
6258 <img src=3.gif>select 관련 질문 하나 드립니다. 답변을 애타게 기다립니다 ㅠ [13] 초밥 2010.12.01 4158
6257 <img src=3.gif>BAPI_INCOMINGINVOICE_CREATE 사용해 보신분요.. [2] 지니 2011.01.19 4152
6256 <b>[완료]</b>Func ALV에서 라인별 control 질문 [5] w 2007.10.11 4124
6255 <b>[완료]</b>if문 안에서의 commit work rollback work 구문개념좀 부탁드려요 [4] 아밥시작4일 2008.08.13 4123
6254 <img src=2.gif>급해요 !!! 화면에 옵션설정 하는 방법좀 알려주세요 . 옵션창이 어딨는지는 압니다. 그림첨부해요 [12] file 오렌지겅주님 2010.08.06 4120
6253 <img src=3.gif>Open SQL 에서 substring 하는 방법 [2] 모포 2010.06.23 4117
6252 <img src=2.gif>은행 계좌번호가 0으로 시작하는 경우 엑셀 다운로드시 문제점.. [6] 삼색볼펜 2010.03.22 4113
6251 HINTS ?, 아래와 같이 쓰는 구문의 차이가 뭔지 알 수 있을까요? [6] 김창훈 2007.08.15 4108
6250 [요청]alv register_edit_event 메소드 사용!! [6] genius 2008.04.15 4105
6249 <b>[완료]</b>Carry out repairs in non-original system only if they are urgent???? [9] SD2 2008.11.21 4104
6248 [요청]ALV 에서 checkbox 비활성 가능한가요? [1] 파파 2008.07.17 4094