ABAP 물타기/ALV

SAP TREE : Simple Tree

물타기 2010. 6. 24. 13:19

  • Create Date   : 2010-06-24
  • Change Date : 2010-06-24

잡담 -ㅂ-;

낼은 월급날~
오르긴 한것 같은데(?), 소급이 되진 않을것 같다...

Tree 는 결국 node 랑 parent node랑을 잘 역어주면 된다.
web에서 javascript로 만들었던 기억이 있는데,
거기에 견주자면 ABAP에서의 Tree는 상당히 편한것 같다... (상용 Component를 쓰는 느낌?)
가장 간단한 Simple Tree를 구현해봤다.


SAP TREE

  • Simple Tree
  • Column Tree
  • List Tree

SCREEN

Custom Control 추가한다.




Variants

* 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.


CLASS

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.

    select * from sflight into table gt_sflight
    where carrid = node_key.

    perform refresh_alv.

  ENDMETHOD.
ENDCLASS.
 

DATA : g_application type ref to lcl_application. 


PBO


  MODULE INIT_TREE OUTPUT.
  if g_tree is initial.

** tree grid
    data : node_table type node_table_type.
    create object tree_con_ref
      EXPORTING
        container_name = 'TREE_CONTAINER'.

    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.
*      EXCEPTIONS
*        ERROR_IN_NODE_TABLE            = 1
*        FAILED                         = 2
*        DP_ERROR                       = 3
*        TABLE_STRUCTURE_NAME_NOT_FOUND = 4
*        others                         = 5
            .
    IF SY-SUBRC <> 0.
*     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

** event 
    data : events type cntl_simple_events,
           event  type cntl_simple_event.

    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
*        others                    = 4
            .
    IF SY-SUBRC <> 0.
*     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

** handler!
    set handler g_application->handle_node_double_click for g_tree.

  endif.
ENDMODULE.                 " INIT_TREE  OUTPUT



Set Node

  FORM BUILD_NODE_TABLE  USING    node_table type node_table_type.

  data : node like mtreesnode.

  clear : node.
  node-node_key = 'Root'.
  node-isfolder = 'X'.
  node-text = 'AIRPLANE'.
  append node to node_table.

  clear : node.
  node-node_key = 'Child1'.
  node-relatkey = 'Root'.
  node-isfolder = 'X'.
  node-text = 'CARRID'.
  node-expander = ''.
  append node to node_table.

  clear : node.
  node-node_key = 'LH'.
  node-relatkey = 'Child1'.
  node-isfolder = ''.
  node-text = 'LH'.
  append node to node_table.

  clear : node.
  node-node_key = 'SQ'.
  node-relatkey = 'Child1'.
  node-n_image = '@10@'.
  node-text = 'SQ'.
  append node to node_table.

  clear : node.
  node-node_key = 'DL'.
  node-relatkey = 'Child1'.
  node-expander = ''.
  node-disabled = 'X'.
  node-text = 'SQ'.
  append node to node_table.

ENDFORM.                    " BUILD_NODE_TABLE



RESULT