728x90
반응형
예제
[프로그램 로직]
INCLUDE ZS1D00_033_TOP. . " Global Data
INCLUDE ZS1D00_033_O01. . " PBO-Modules
INCLUDE ZS1D00_033_I01. . " PAI-Modules
INCLUDE ZS1D00_033_F01. . " FORM-Routines
INITIALIZATION. "SELECTION SCREEN 초기값 설정
AT SELECTION-SCREEN.
START-OF-SELECTION. "메인 프로세스스 시작
PERFORM select_data.
END-OF-SELECTION.
* screen 호출
CALL SCREEN 100.
<TOP>
*TREE 참조 변수
TYPES: node_table_type LIKE STANDARD TABLE OF mtreesnode WITH DEFAULT KEY.
DATA: tree_con_ref TYPE REF TO cl_gui_custom_container,
g_tree TYPE REF TO cl_gui_simple_tree.
TABLES: ZS1D11T_01,ZS1D11T_02, dd07t.
*테이블 데이터 담을 변수
DATA: gs_tab TYPE ZS1D11T_01,
gt_tab TYPE TABLE OF ZS1D11T_01,
gs_tab2 TYPE ZS1D11T_02,
gt_tab2 TYPE TABLE OF ZS1D11T_02. "
DATA: gs_tab3 TYPE dd07t,
gt_tab3 TYPE TABLE OF dd07t.
DATA: ok_code TYPE sy-ucomm.
team 도메인의 fixed value 값을 필드를 가지고 있는 dd07t
를 사용한다.
*ALV 참조 변수
DATA: g_custom_con TYPE REF TO cl_gui_custom_container, "컨테이너
g_alv TYPE REF TO cl_gui_alv_grid, "ALV GRID
g_custom_con2 TYPE REF TO cl_gui_custom_container,
g_alv2 TYPE REF TO cl_gui_alv_grid.
DATA: gs_fieldcat TYPE lvc_s_fcat,
gt_fieldcat TYPE lvc_t_fcat,
gs_layo TYPE lvc_s_layo,
gs_sort TYPE lvc_s_sort,
gt_sort TYPE lvc_t_sort,
gs_functions TYPE ui_functions,
gs_refto TYPE REF TO data,
gs_pos TYPE i.
DATA: gs_fieldcat2 TYPE lvc_s_fcat,
gt_fieldcat2 TYPE lvc_t_fcat,
gs_layo2 TYPE lvc_s_layo,
gs_sort2 TYPE lvc_s_sort,
gt_sort2 TYPE lvc_t_sort,
gs_functions2 TYPE ui_functions.
FIELD-SYMBOLS : <fcat> TYPE lvc_t_fcat.
*화면 구성
SELECT-OPTIONS: s_team FOR zs1d11t_01-team.
*클래스 선언
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.
CLASS lcl_application IMPLEMENTATION.
METHOD handle_node_double_click.
PERFORM node_double_click_0100 USING node_key.
ENDMETHOD. "handle_node_double_click
ENDCLASS. "LCL_EVENT IMPLEMENTATION
DATA: g_application TYPE REF TO lcl_application.
트리를 더블클릭했을때 팀원정보를 ALV로 뿌려주어야 되니 더블클릭 이벤트를 생성한다.
<화면100>
트리와 ALV를 나타내줄 2개의 컨테이너를 그린다. HD_CON
, HD_CON2
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
MODULE INIT_TREE.
MODULE CREATE_CONTAINER.
PROCESS AFTER INPUT.
MODULE EXIT AT EXIT-COMMAND.
MODULE USER_COMMAND_0100.
<PBO>
MODULE status_0100 OUTPUT.
SET PF-STATUS '0100'.
SET TITLEBAR '0100'.
ENDMODULE.
* TREE
MODULE init_tree OUTPUT.
IF g_tree IS INITIAL.
DATA: node_table TYPE node_table_type, "트리 값들 관계 넣어주기위해
events TYPE cntl_simple_events, "더블클릭 이벤트
event TYPE cntl_simple_event. "더블클릭 이벤트
"컨테이너 생성
CREATE OBJECT tree_con_ref
EXPORTING
container_name = 'TREE1'.
"TREE 컨트롤 생성
CREATE OBJECT g_tree
EXPORTING
parent = tree_con_ref
node_selection_mode = cl_gui_simple_tree=>node_sel_mode_single. "싱글선택
"노드 생성
PERFORM build_node_table USING node_table. "트리에 데이터 넣어줌
"트리 노드 추가
CALL METHOD g_tree->add_nodes
EXPORTING
table_structure_name = 'MTREESNODE'
node_table = node_table. "트리 데이터 들어가있는 int
"이벤트
CREATE OBJECT g_application.
event-eventid = cl_gui_simple_tree=>eventid_node_double_click.
event-appl_event = 'X'.
APPEND event TO events.
"트리 이벤트 등록
CALL METHOD g_tree->set_registered_events
EXPORTING
events = events
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
illegal_event_combination = 3.
"트리 이벤트 헨들러
SET HANDLER g_application->handle_node_double_click FOR g_tree.
ENDIF.
ENDMODULE.
* ALV
MODULE create_container OUTPUT.
IF g_custom_con IS INITIAL.
CREATE OBJECT g_custom_con
EXPORTING
container_name = 'CONT1'.
CREATE OBJECT g_alv
EXPORTING
i_parent = g_custom_con.
PERFORM make_fieldcat. "필드 카탈로그 설정
PERFORM sort. "정렬
* ALV 출력
CALL METHOD g_alv->set_table_for_first_display
EXPORTING
is_layout = gs_layo
CHANGING
it_outtab = gt_tab2
it_fieldcatalog = gt_fieldcat
it_sort = gt_sort
.
ELSE.
PERFORM refresh_grid.
ENDIF.
ENDMODULE.
ALV 화면에 보여줄건 2번테이블의 팀원정보기 때문에 2번테이블을 참조한 GT_TAB2
를 OUTTAB에 넣어준다.
<FORM>
FORM select_data .
SELECT * FROM dd07t
INTO CORRESPONDING FIELDS OF TABLE gt_tab3
WHERE domname = 'Z11D_TEAM'
AND domvalue_l IN s_team.
SORT gt_tab3 BY domvalue_l ASCENDING.
SELECT * FROM zs1d11t_01
INTO TABLE gt_tab.
ENDFORM.
도메인의 fixed value
를 필드로 가지고 있는 테이블 dd07t
에서 조 필드의 도메인을 가져온다.
FORM make_fieldcat .
gs_fieldcat-fieldname = 'SEQNR'.
gs_fieldcat-coltext = '순번'.
gs_fieldcat-just = 'C'.
gs_fieldcat-key = 'X'.
APPEND gs_fieldcat TO gt_fieldcat. CLEAR gs_fieldcat.
gs_fieldcat-fieldname = 'NAME'.
gs_fieldcat-coltext = '이름'.
gs_fieldcat-just = 'C'.
APPEND gs_fieldcat TO gt_fieldcat. CLEAR gs_fieldcat.
gs_fieldcat-fieldname = 'TEL_NUM'.
gs_fieldcat-coltext = '휴대폰번호'.
gs_fieldcat-just = 'C'.
APPEND gs_fieldcat TO gt_fieldcat. CLEAR gs_fieldcat.
gs_fieldcat-fieldname = 'GENDER'.
gs_fieldcat-coltext = '성별'.
gs_fieldcat-just = 'C'.
APPEND gs_fieldcat TO gt_fieldcat. CLEAR gs_fieldcat.
gs_fieldcat-fieldname = 'EMAIL'.
gs_fieldcat-coltext = '이메일 주소'.
gs_fieldcat-just = 'C'.
APPEND gs_fieldcat TO gt_fieldcat. CLEAR gs_fieldcat.
gs_fieldcat-fieldname = 'NOTE'.
gs_fieldcat-coltext = '비고'.
gs_fieldcat-just = 'C'.
APPEND gs_fieldcat TO gt_fieldcat. CLEAR gs_fieldcat.
ENDFORM.
FORM sort .
gs_sort-spos = 1.
gs_sort-fieldname = 'SEQNR'.
gs_sort-up = 'X'.
APPEND gs_sort TO gt_sort. CLEAR gs_sort.
ENDFORM.
* 트리에 데이터 넣어줌
FORM build_node_table USING node_table TYPE node_table_type.
DATA: node LIKE mtreesnode,
l_name TYPE zs1d11t_02-name,
l_team(2).
CLEAR node.
node-node_key = 'Root'. "tree 상위항목
node-isfolder = 'X'.
node-text = '서울1반'.
APPEND node TO node_table.
LOOP AT gt_tab3 INTO gs_tab3.
CLEAR node.
CONCATENATE 'T' gs_tab3-domvalue_l INTO l_team.
CONDENSE l_team NO-GAPS.
node-node_key = l_team.
node-relatkey = 'Root'.
node-isfolder = 'X'.
node-text = gs_tab3-ddtext.
APPEND node TO node_table.
LOOP AT gt_tab INTO gs_tab WHERE team = gs_tab3-domvalue_l.
CLEAR node.
node-node_key = gs_tab-seqnr.
node-relatkey = l_team.
SELECT SINGLE name FROM zs1d11t_02
INTO l_name WHERE seqnr = gs_tab-seqnr.
IF SY-SUBRC = 0.
node-text = l_name.
APPEND node TO node_table.
ENDIF.
ENDLOOP.
ENDLOOP.
ENDFORM.
트리는 node key와 relation key의 관계만 잘이해해서 node 로직만 잘구현해주면 된다!!! 그래서 트리에서 가장 중요한 부분.
* 트리에서 더블클릭했을때 alv에 표시해줄 데이터 select
FORM node_double_click_0100 USING p_node_key.
SELECT * FROM zs1d11t_02
INTO CORRESPONDING FIELDS OF TABLE gt_tab2
WHERE seqnr = p_node_key.
PERFORM refresh_grid.
ENDFORM.
FORM refresh_grid .
DATA: l_scroll TYPE lvc_s_stbl.
l_scroll-row = 'X'.
l_scroll-col = 'X'.
CALL METHOD g_alv->refresh_table_display
EXPORTING
i_soft_refresh = ''
is_stable = l_scroll.
ENDFORM.
<PAI>
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN 'BACK'.
LEAVE TO SCREEN 0. "이전화면
WHEN OTHERS.
ENDCASE.
ENDMODULE.
MODULE exit INPUT.
CASE ok_code.
WHEN 'EXIT' OR 'CANC'.
LEAVE PROGRAM. "프로그램 종료
WHEN OTHERS.
ENDCASE.
ENDMODULE.
[실행 화면]
728x90
반응형
'ABAP' 카테고리의 다른 글
ALV Tree 2 (0) | 2023.02.20 |
---|---|
ALV Tree (0) | 2023.02.20 |
Simple Tree (0) | 2023.02.20 |
ALV 7 (0) | 2023.02.16 |
ALV 6 (필드카탈로그 구성) (0) | 2023.02.16 |
댓글