쓸 일 없겠지만 동적으로 테이블 받아서 수정 반영하는 법
(100번 ALV 선택 -> 110 번 스크린 이동 (Table Control)에서 수정 후 100번에 반영)
미리보기
100번
체인지 누르면 이동
100 TOP
" Screnn 100번
DATA: gt_data TYPE REF TO data,
gt_fcat TYPE lvc_t_fcat,
go_dock TYPE REF TO cl_gui_docking_container,
go_grid TYPE REF TO cl_gui_alv_grid.
DATA: gt_dntab LIKE dntab OCCURS 0 WITH HEADER LINE, " 입력받은 Table Info
gt_rows TYPE lvc_t_row,
gs_rows TYPE lvc_s_row.
FIELD-SYMBOLS: <ft_data> TYPE STANDARD TABLE,
<fs_data> TYPE any.
" Screnn 110번
CONTROLS ctr_110 TYPE TABLEVIEW USING SCREEN '0110'. " Table Control
TYPES: BEGIN OF ty_s_data.
TYPES:
fname(100)," 필드내역
bef_val(100)," 복사 값
aft_val(100)," 변경 값
tname(100)." 기술적 필드 이름
TYPES: END OF ty_s_data.
DATA: gt_110 TYPE TABLE OF ty_s_data,
gs_110 TYPE ty_s_data.
100번 get_data
FORM garbage2 .
CONSTANTS: c_x VALUE 'X'.
" fcat RTTS
DATA :
lr_tabdescr TYPE REF TO cl_abap_structdescr,
lr_data TYPE REF TO data,
lt_dfies TYPE ddfields,
ls_dfies TYPE dfies,
ls_fieldcat TYPE lvc_s_fcat,
lv_tabname LIKE dntab-tabname.
lv_tabname = 'SCARR'.
CALL FUNCTION 'NAMETAB_GET'
EXPORTING
tabname = lv_tabname
TABLES
nametab = gt_dntab[].
CREATE DATA gt_data TYPE (lv_tabname).
lr_tabdescr ?= cl_abap_structdescr=>describe_by_data_ref( gt_data ).
" structure의 개별 특성을 lt_dfies에 담음.
lt_dfies = cl_salv_data_descr=>read_structdescr( lr_tabdescr ).
LOOP AT lt_dfies INTO ls_dfies.
ls_fieldcat = CORRESPONDING #( ls_dfies ).
ls_fieldcat-intlen = ls_dfies-leng.
ls_fieldcat-datatype = ls_dfies-datatype.
ls_fieldcat-outputlen = ls_dfies-outputlen.
ls_fieldcat-ref_field = ls_dfies-reffield.
ls_fieldcat-ref_table = ls_dfies-reftable.
CASE ls_fieldcat-fieldname .
WHEN 'MANDT'.
ls_fieldcat-no_out = c_x.
ENDCASE.
READ TABLE gt_dntab INTO DATA(ls_dntab) WITH KEY fieldname = ls_fieldcat-fieldname
keyflag = c_x.
IF sy-subrc EQ 0.
ls_fieldcat-key = c_x.
ELSE.
* ls_fieldcat-edit = c_x.
ENDIF.
ls_fieldcat-coltext = ls_dntab-fieldtext.
APPEND ls_fieldcat TO gt_fcat.
CLEAR: ls_fieldcat , ls_dntab.
ENDLOOP.
* dynamic tab
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
i_style_table = 'X'
it_fieldcatalog = gt_fcat
IMPORTING
ep_table = gt_data
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
ASSIGN gt_data->* TO <ft_data>.
SELECT *
FROM (lv_tabname)
INTO CORRESPONDING FIELDS OF TABLE <ft_data>.
ENDFORM.
대충 도킹으로 띄우고, 라인 선택 후 change 버튼 누르면 110번으로 이동
-> gt_dnttab에 필드명 정보가 담겨있어서 assign component로 넘김
CASE e_ucomm.
WHEN 'CHG'.
"선택 ROW가져오기
CALL METHOD sender->get_selected_rows
IMPORTING
et_index_rows = gt_rows[].
CHECK gt_rows[] IS NOT INITIAL.
READ TABLE gt_rows INTO gs_rows INDEX 1.
CHECK gs_rows IS NOT INITIAL.
READ TABLE <ft_data> ASSIGNING <fs_data> INDEX gs_rows-index.
CHECK <fs_data> IS ASSIGNED.
LOOP AT gt_dntab INTO DATA(ls_dntab).
ASSIGN COMPONENT: ls_dntab-fieldname OF STRUCTURE <fs_data> TO FIELD-SYMBOL(<fs2>).
CHECK <fs2> IS ASSIGNED.
APPEND VALUE #( fname = ls_dntab-fieldname
bef_val = <fs2>
aft_val = <fs2>
tname = '' ) TO gt_110.
ENDLOOP.
CALL SCREEN 110.
ENDCASE.
110번
-> PBO에서 GT_110번 설정하고, PAI에서 수정처리함
init_alv 부분
DESCRIBE TABLE gt_110 LINES ctr_110-lines.
READ TABLE gt_110 INTO gs_110 INDEX ctr_110-current_line.
MODULE modify_tab 부분.
MODIFY gt_110 FROM gs_110 INDEX ctr_110-current_line.
110번 user_command
-> 핵심은 필드명(CARRID 와 같은) ASSIGN COMPONENT로 다뤄서 수정한다는 점~
-> 필드심볼 모르면 다른 블로그 참고
-> CARRID AB로 수정하고 100번으로 돌아가면~
끝.