제가 책을 따라 제가 만든 테이블을 토대로 제구성한 프로그램입니다.
실행화면을 보시면 왼쪽에 트리가 있고 트리에서 이름을 클릭하면 오른쪽 텍스트 필드에 자료출력되고 alv에도 자료가 출력되야하는데요
소스가 잘못된건지 이름을 클릭하면 아무 반응이 없네요 전체 소스 첨부 할게요
에러가 안나서 머가 문제인지 모르겠네요 잘 좀 부탁드립니다.
소스가 좀 기네요. 초보라서 이제 막 알아가는 과정입니다.
메인 프로그램----------------------------------------------------------------------------------------------
INCLUDE ZDOC_TOP.
INCLUDE ZDOC_cl1.
INCLUDE ZDOC_o01.
INCLUDE ZDOC_i01.
INCLUDE ZDOC_f01.
START-OF-SELECTION.
CREATE OBJECT g_application.
set SCREEN 100.
TOP INCLUDE ----------------------------------------------------------------------------------------
PROGRAM ZDOC MESSAGE-id zq00.
TABLES: ZINPUT, ZOUTPUT.
CLASS LCL_APPLICATION DEFINITION DEFERRED.
CLASS CL_GUI_CFW DEFINITION LOAD.
TYPES: NODE_TABLE_TYPE LIKE STANDARD TABLE OF MTREESNODE WITH DEFAULT KEY.
DATA: NODE_TABLE TYPE NODE_TABLE_TYPE,
NODE LIKE NODE_STR,
EVENTS TYPE CNTL_SIMPLE_EVENTS,
EVENT TYPE CNTL_SIMPLE_EVENT.
DATA: G_APPLICATION TYPE REF TO LCL_APPLICATION,
CONTAINER_TREE TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
CONTAINER_ALV TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
TREE TYPE REF TO CL_GUI_SIMPLE_TREE,
GRID TYPE REF TO CL_GUI_ALV_GRID,
OK_CODE TYPE SY-UCOMM,
gt_fieldcatalog TYPE lvc_t_fcat,
gt_fieldcatalog_ln LIKE LINE OF gt_fieldcatalog.
DATA CONTAINER_TOOLBAR TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
DATA MYTOOLBAR TYPE REF TO CL_GUI_TOOLBAR.
DATA BUTTONGROUP TYPE TTB_BUTTON.
DATA: EDPOSX TYPE i,
EDPOSy type i,
rdclick,
rddrop,
edoutput(20),
myevent_tab type CNTL_SIMPLE_EVENTs,
myevent type CNTL_SIMPLE_EVENT,
menu_dynamic type REF TO cl_ctmenu.
data: x_save,
g_repid like sy-repid,
gs_variant type disvariant,
gs_layout type lvc_s_layo.
data: g_event(30),
g_node_key type tv_nodekey.
data: it_zoutput type table of zoutput.
data: p_docname like zoutput-docname,
p_major like ZINPUT-docmajor,
name like ZINPUT-name,
repid type sy-repid.
CL1 INCLUDE ---------------------------------------------------------------------------------------------
CLASS LCL_MY_EVENT_HANDLER DEFINITION.
PUBLIC SECTION.
METHODS: on_function_selected
FOR EVENT function_selected of cl_gui_toolbar
IMPORTING fcode.
ENDCLASS. "LCL_MY_EVENT_HANDLER
CLASS LCL_APPLICATION DEFINITION.
PUBLIC SECTION.
METHODS:
handle_node_double_click
for EVENT node_double_click
of cl_gui_simple_tree
IMPORTING node_key.
ENDCLASS. "LCL_APPLICATION
CLASS lcl_my_event_handler IMPLEMENTATION.
METHOD on_function_selected.
edoutput = fcode.
edposx = 0.
edposy = 0.
CLEAR rddrop.
rdclick = 'X'.
ENDMETHOD.
ENDCLASS. "lcl_my_event_handler
CLASS LCL_APPLICATION IMPLEMENTATION.
METHOD handle_node_double_click.
select SINGLE docmajor docname name
INTO (p_major, p_docname, name )
from zinput
where docname = node_key.
ENDMETHOD.
ENDCLASS. "LCL_APPLICATION
O01 INCLUDE-----------------------------------------------------------------------------------------
MODULE START OUTPUT.
SET PF-STATUS 'BASE'.
if container_tree is initial or container_alv is INITIAL OR
container_toolbar is INITIAL.
PERFORM create_control.
PERFORM register_toolbar_event.
PERFORM build_toolbar.
PERFORM register_tree_grid_event.
PERFORM build_node_table USING node_table.
PERFORM tree_nodes_create.
CALL METHOD tree->expand_node
EXPORTING
node_key = 'MAJOR'.
ENDIF.
PERFORM DATA_SELECT.
PERFORM WRITE_DATA.
ENDMODULE. " START OUTPUT
I01 INCLUDE --------------------------------------------------------------------------------------------
MODULE USER_COMMAND_0100 INPUT.
data: return_code type i.
call METHOD cl_gui_cfw=>dispatch
IMPORTING
return_code = return_code.
IF return_code <> cl_gui_cfw=>rc_noevent.
clear ok_code.
ENDIF.
case ok_code.
when 'EXIT'.
IF NOT CONTAINER_TREE IS INITIAL.
CALL METHOD CONTAINER_TREE->FREE
EXCEPTIONS
CNTL_SYSTEM_ERROR = 1
CNTL_ERROR = 2.
if sy-subrc <> 0.
message w000.
endif.
call METHOD CONTAINER_alv->free
EXCEPTIONS
CNTL_SYSTEM_ERROR = 1
CNTL_ERROR = 2.
if sy-subrc <> 0.
message w000.
endif.
call METHOD cl_gui_cfw=>flush
EXCEPTIONS
CNTL_SYSTEM_ERROR = 1
CNTL_ERROR = 2.
if sy-subrc <> 0.
message w000.
endif.
clear CONTAINER_TREE.
CLEAR tree.
CLEAR CONTAINER_alv.
CLEAR grid.
endif.
LEAVE PROGRAM.
when others.
if edoutput = 'FC1'.
CALL METHOD tree->expand_root_nodes
EXPORTING
level_count = 1
expand_subtree = 'X'
EXCEPTIONS
failed = 1
illegal_level_count = 2
CNTL_SYSTEM_ERROR = 3.
CLEAR edoutput.
elseif edoutput = 'FC2'.
CALL METHOD tree->COLLAPSE_ALL_nodes.
CLEAR edoutput.
ENDIF.
ENDCASE.
CLEAR OK_CODE.
ENDMODULE. " USER_COMMAND_0100 INPUT
F01 INCLUDE --------------------------------------------------------------------------------------------
FORM CREATE_CONTROL .
CREATE OBJECT CONTAINER_TOOLBAR
EXPORTING CONTAINER_NAME = 'CONTAINER_TOOLBAR'.
CREATE OBJECT CONTAINER_TREE
EXPORTING CONTAINER_NAME = 'CONTAINER_TREE'.
CREATE OBJECT CONTAINER_ALV
EXPORTING CONTAINER_NAME = 'CONTAINER_ALV'.
CREATE OBJECT MYTOOLBAR
EXPORTING PARENT = CONTAINER_TOOLBAR.
CREATE OBJECT TREE
EXPORTING
PARENT = CONTAINER_TREE
NODE_SELECTION_MODE = CL_GUI_SIMPLE_TREE=>NODE_SEL_MODE_SINGLE
EXCEPTIONS
LIFETIME_ERROR = 1
CNTL_SYSTEM_ERROR = 2
CREATE_ERROR = 3
FAILED = 4
ILLEGAL_NODE_SELECTION_MODE = 5.
if sy-subrc <> 0.
MESSAGE w000.
endif.
CREATE OBJECT grid
EXPORTING i_parent = CONTAINER_alv.
ENDFORM. " CREATE_CONTROL
*&---------------------------------------------------------------------*
*& Form REGISTER_TOOLBAR_EVENT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM REGISTER_TOOLBAR_EVENT .
myevent-eventid = cl_gui_toolbar=>m_id_function_selected.
myevent-appl_event = 'X'.
APPEND myevent to myevent_tab.
data: evt_receiver type REF TO lcl_my_event_handler.
CREATE OBJECT evt_receiver.
call METHOD MYTOOLBAR->set_registered_events
EXPORTING
events = myevent_tab.
set HANDLER evt_receiver->on_function_selected for MYTOOLBAR.
ENDFORM. " REGISTER_TOOLBAR_EVENT
*&---------------------------------------------------------------------*
*& Form REGISTER_TREE_GRID_EVENT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM REGISTER_TREE_GRID_EVENT .
"node double click
event-eventid = CL_GUI_SIMPLE_TREE=>eventid_node_double_click.
event-appl_event = 'X'.
APPEND event to events.
call METHOD tree->set_registered_events
EXPORTING
events = events
EXCEPTIONS
cntl_error = 1
CNTL_SYSTEM_ERROR = 2
illegal_event_combination = 3.
if sy-subrc <> 0.
MESSAGE w000.
endif.
set HANDLER g_application->handle_node_double_click for tree.
ENDFORM. " REGISTER_TREE_GRID_EVENT
*&---------------------------------------------------------------------*
*& Form DATA_SELECT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DATA_SELECT .
SELECT * FROM zOUTput INTO TABLE IT_zOUTput
WHERE docname = p_docname.
ENDFORM. " DATA_SELECT
*&---------------------------------------------------------------------*
*& Form WRITE_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM WRITE_DATA .
gs_layout-grid_title = text-101.
g_repid = sy-repid.
gs_variant-report = g_repid.
x_save = 'A'.
CLEAR gt_fieldcatalog. refresh gt_fieldcatalog.
CLEAR gt_fieldcatalog_ln.
gt_fieldcatalog_ln-fieldname = 'CHART'.
gt_fieldcatalog_ln-row_pos = '1'. gt_fieldcatalog_ln-col_pos = '1'.
gt_fieldcatalog_ln-coltext = '차트번호'.
gt_fieldcatalog_ln-just = 'R'.
APPEND gt_fieldcatalog_ln to gt_fieldcatalog.
clear gt_fieldcatalog_ln.
gt_fieldcatalog_ln-fieldname = 'DOCNAME'.
gt_fieldcatalog_ln-row_pos = '1'. gt_fieldcatalog_ln-col_pos = '2'.
gt_fieldcatalog_ln-coltext = '진료의사'.
gt_fieldcatalog_ln-just = 'R'.
APPEND gt_fieldcatalog_ln to gt_fieldcatalog.
clear gt_fieldcatalog_ln.
gt_fieldcatalog_ln-fieldname = 'ZDTIN'.
gt_fieldcatalog_ln-row_pos = '1'. gt_fieldcatalog_ln-col_pos = '5'.
gt_fieldcatalog_ln-coltext = '입원여부'.
gt_fieldcatalog_ln-just = 'R'.
APPEND gt_fieldcatalog_ln to gt_fieldcatalog.
clear gt_fieldcatalog_ln.
gt_fieldcatalog_ln-fieldname = 'INDATE'.
gt_fieldcatalog_ln-row_pos = '1'. gt_fieldcatalog_ln-col_pos = '3'.
gt_fieldcatalog_ln-coltext = '입원일'.
gt_fieldcatalog_ln-just = 'R'.
APPEND gt_fieldcatalog_ln to gt_fieldcatalog.
clear gt_fieldcatalog_ln.
gt_fieldcatalog_ln-fieldname = 'OUTDATE'.
gt_fieldcatalog_ln-row_pos = '1'. gt_fieldcatalog_ln-col_pos = '4'.
gt_fieldcatalog_ln-coltext = '퇴원일'.
gt_fieldcatalog_ln-just = 'R'.
APPEND gt_fieldcatalog_ln to gt_fieldcatalog.
clear gt_fieldcatalog_ln.
gt_fieldcatalog_ln-fieldname = 'QUIZ'.
gt_fieldcatalog_ln-row_pos = '1'. gt_fieldcatalog_ln-col_pos = '6'.
gt_fieldcatalog_ln-coltext = '수술여부'.
gt_fieldcatalog_ln-just = 'R'.
APPEND gt_fieldcatalog_ln to gt_fieldcatalog.
CALL METHOD grid->set_table_for_first_display
EXPORTING
i_structure_name = 'zoutput'
is_variant = gs_variant
i_save = x_save
CHANGING
it_outtab = it_zoutput
it_fieldcatalog = gt_fieldcatalog.
ENDFORM. " WRITE_DATA
*&---------------------------------------------------------------------*
*& Form BUILD_TOOLBAR
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM BUILD_TOOLBAR .
CLEAR buttongroup.
PERFORM fill_data_table USING:
'fc1' '@68@' cntb_btype_button '늘이기' 'Expand All',
'fc2' '@69@' cntb_btype_button '줄이기' 'Collapse All'.
call METHOD MYTOOLBAR->add_button_group
EXPORTING
data_table = buttongroup.
ENDFORM. " BUILD_TOOLBAR
*&---------------------------------------------------------------------*
*& Form FILL_DATA_TABLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0360 text
* -->P_0361 text
* -->P_CNTB_BTYPE_BUTTON text
* -->P_0363 text
* -->P_0364 text
*----------------------------------------------------------------------*
FORM FILL_DATA_TABLE USING fcode type ui_func
icon type iconname
type type tb_btype
text type text40
tip type iconquick.
call METHOD MYTOOLBAR->fill_buttons_data_table
EXPORTING
fcode = fcode
icon = icon
butn_type = type
text = text
quickinfo = tip
CHANGING
data_table = buttongroup.
ENDFORM. " FILL_DATA_TABLE
*&---------------------------------------------------------------------*
*& Form TREE_NODES_CREATE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM TREE_NODES_CREATE .
CALL METHOD TREE->ADD_NODES
EXPORTING
TABLE_STRUCTURE_NAME = 'MTREESNODE'
NODE_TABLE = node_table
EXCEPTIONS
FAILED = 1
ERROR_IN_NODE_TABLE = 2
DP_ERROR = 3
TABLE_STRUCTURE_NAME_NOT_FOUND = 4
OTHERS = 5.
if sy-subrc <> 0.
MESSAGE w000.
endif.
call METHOD tree->expand_node
EXPORTING
node_key = 'MAJOR'.
ENDFORM. " TREE_NODES_CREATE
*&---------------------------------------------------------------------*
*& Form BUILD_NODE_TABLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_NODE_TABLE text
*----------------------------------------------------------------------*
FORM BUILD_NODE_TABLE USING P_NODE_TABLE.
data: node like mtreesnode.
data: t_major like ZINPUT-DOCMAJOR,
T_DOCNAME LIKE ZINPUT-DOCNAME.
CLEAR: T_MAJOR, T_DOCNAME.
node-node_key = 'MAJOR'.
CLEAR NODE-RELATKEY.
CLEAR NODE-RELATSHIP.
NODE-hidden = ' '.
node-disabled = ' '.
node-isfolder = 'X'.
CLEAR node-n_image.
CLEAR node-exp_image.
CLEAR node-expander.
node-text = '진료과'.
APPEND node to node_table.
select DISTINCT docmajor into t_major
FROM ZINPUT.
CLEAR node.
node-node_key = t_major.
node-RELATKEY = 'MAJOR'.
node-RELATSHIP = cl_gui_list_tree=>relat_last_child.
node-isfolder = 'X'.
node-text = t_major.
APPEND node to node_table.
select DISTINCT docname into t_docname
FROM zinput
WHERE docmajor = t_major.
CLEAR node.
node-node_key = t_docname.
node-RELATKEY = t_major.
node-RELATSHIP = cl_gui_list_tree=>relat_last_child.
node-text = t_docname.
APPEND node to node_table.
CLEAR t_docname.
ENDSELECT.
CLEAR t_major.
ENDSELECT.
ENDFORM. " BUILD_NODE_TABLE
댓글 7
-
버미!
2010.08.24 16:58
처음부터 너무 어렵게 공부하시네요..기초적인 ALV부터 시작하시고 그다음에 Class 개념으로 된 ALV를 시작하시는 것이 쉽게 접근하실수 있을 거 같은데... -
맑은하늘
2010.08.24 18:20
소스만 훑어봤는데요. node_double_click 이벤트에서 해당 노드에 대한 데이터를 선택한 후에 alv-grid refresh 를 해주시면
되지 않을까 생각됩니다. 한가지 더 말씀드리면 tree에 appl_event 가 설정되어있기 때문에 PBO 부분에 grid->refresh_table_display( )가 있어도 될 것 같네요. 더블클릭이벤트 발생후 alv-data 는 선택이 되었지만 이 데이터가 alv-grid 에서 갱신되지 않아 data 는 바뀌었지만 gui 의 viewer 는 그대로인 상태로 보여지네요. 위 소스가 전체라면 소스정리를 좀 하시는 것이 보시기에 좋을 것 같네요. toolbar, tree, grid 로 구분해서 코드작성을 하시면 좋을 것 같습니다. 보기가 좀 헷갈리네요. ^^; 오브젝트는 보통 1. 컨테이너 생성, 2 해당 컨테이너에 오브젝트(toolbar, tree, grid 기타등등) 링크, 3 해당 오브젝트에 대한 구성요소 추가로 해서 화면에 표시가 되는데요. 1은 디폴트화면 사용시에는 생략할 수 있습니다. 오브젝트별로 위 단계로 정의하심이 좋을 듯 하네요.
예를 들면 grid 오브젝트에 대하여는
if grid is not bound.
1. container 생성
create container
container_name = 'CONT_NAME'.
( or parent = other container )
2. grid 생성
create grid
importing parent = container.
3. grid 구성요소
- field-catalog, layout, variant, sort, and so on...
display_grid.
else.
refresh grid.
endif.
가 일반적이라 볼 수 있겠네요.
프로그램이라는게 한번 짜고 절대 안보는 것이 아니기 때문에 언제 누가 봐도 잘 알아볼수 있도록 구현하시는 것이
좋을 것 같네요. ^^;
-
초보생
2010.08.24 18:38
클래스 개념 이해하기 쉽지 않은데 어렵게 시작하시네요 기본적인 write 부터 시작해서 펑션 alv 다음에 Class 개념의 ALV 로
접근하시는게 좋을 듯 합니다만...
-
아밥 잭
2010.08.24 18:51
안녕하세요,,,
일단, 아래 부분에 중단점을 설정하고 디버깅해보세요.
METHOD handle_node_double_click.
select SINGLE docmajor docname name
INTO (p_major, p_docname, name )
from zinput
where docname = node_key.
ENDMETHOD.
디버깅해서 여기에 들어오면 데이터를 제대로 가지고 오는지 확인 하시고요,
데이터가 제대로 가져오는데 안보이면 위의 맑은 하늘님이 말한것 처럼.
container가 한번 생성되면 alv보여주는 로직을 안타니깐요, else해서
refresh구문을 넣어주어야 alv에 새로운 데이터가 보입니다.
만일, 위의 디버깅으로 안들어가면 노드클릭이벤트가 안먹는것인데 소스를보니
문제는 없을것 같습니다.
감사합니다.
-
유정a
2010.08.24 20:39
자세한 답변 갑사합니다.
refresh grid 구문을 넣어주면 에러가 나는데 refresh 구문을 어느 위치 쯤 넣어야 할까요?
해결되면 오늘은 책 처음부터 봐야겠네요
-
아밥 잭
2010.08.24 22:00
IF G_CUSTOM_CONTAINER1 IS INITIAL.
ELSE.
*-- ALV REFRESH
DATA: LS_STABLE TYPE LVC_S_STBL.
LS_STABLE-ROW = 'X'.
LS_STABLE-COL = 'X'.
CALL METHOD G_GRID->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = LS_STABLE.
ENDIF.
-
유정a
2010.10.01 01:41
감사합니다.