REPORT  yh_alvtreedemo1.
TYPE-POOLS : fibs,stree.
TYPE-POOLS:slis.
DATA : t_node TYPE snodetext.
DATA : it_node LIKE TABLE OF t_node,
       wa_node LIKE t_node.
DATA: t_fieldcat    TYPE slis_t_fieldcat_alv,
      fs_fieldcat   TYPE slis_fieldcat_alv.
DATA:w_repid LIKE sy-repid.
*Internal Table declarations
DATA: BEGIN OF fs_scarr,
        carrid LIKE scarr-carrid,
      END OF fs_scarr.
DATA:BEGIN OF fs_spfli,
        carrid LIKE spfli-carrid,
        connid LIKE spfli-connid,
     END OF fs_spfli.
DATA:BEGIN OF fs_sflight,
        carrid LIKE sflight-carrid,
        connid LIKE sflight-connid,
        fldate LIKE sflight-fldate,
     END OF fs_sflight.
DATA:BEGIN OF fs_sbook,
        carrid LIKE sbook-carrid,
        connid LIKE sbook-connid,
        fldate LIKE sbook-fldate,
        bookid LIKE sbook-bookid,
     END OF fs_sbook.
DATA:t_scarr LIKE TABLE OF fs_scarr,
     t_spfli LIKE TABLE OF fs_spfli,
     t_sflight LIKE TABLE OF fs_sflight,
     t_sbook LIKE TABLE OF fs_sbook.
START-OF-SELECTION.
  PERFORM get_data.
  PERFORM build_tree.
  PERFORM display_tree.
*&----------------------------------------------------------------*
*&      Form  get_data
*&----------------------------------------------------------------*
FORM get_data .
  SELECT carrid
         FROM scarr
         INTO TABLE t_scarr.
  SELECT carrid
          connid
          FROM spfli
          INTO TABLE t_spfli
          FOR ALL ENTRIES IN t_scarr
          WHERE carrid EQ t_scarr-carrid.
ENDFORM.                    " get_data
*&----------------------------------------------------------------*
*&      Form  build_tree
*&----------------------------------------------------------------*
FORM build_tree .
  CLEAR: it_node,
         wa_node.
  SORT: t_scarr BY carrid,
        t_spfli BY carrid connid,
        t_sflight BY carrid connid fldate,
        t_sbook BY carrid connid fldate bookid.
  wa_node-type = 'T'.
  wa_node-name = 'Flight Details'.
  wa_node-tlevel = '01'.
  wa_node-nlength = '15'.
  wa_node-color = '4'.
  wa_node-text = 'Flight'.
  wa_node-tlength ='20'.
  wa_node-tcolor = 3.
  APPEND wa_node TO it_node.
  CLEAR wa_node.
  LOOP AT t_scarr INTO fs_scarr.
    wa_node-type = 'P'.
    wa_node-name = 'CARRID'.
    wa_node-tlevel = '02'.
    wa_node-nlength = '8'.
    wa_node-color = '1'.
    wa_node-text = fs_scarr-carrid.
    wa_node-tlength ='20'.
    wa_node-tcolor = 4.
    APPEND wa_node TO it_node.
    CLEAR wa_node.
    LOOP AT t_spfli INTO fs_spfli WHERE carrid EQ fs_scarr-carrid.
      wa_node-type = 'P'.
      wa_node-name = 'CONNID'.
      wa_node-tlevel = '03'.
      wa_node-nlength = '8'.
      wa_node-color = '1'.
      wa_node-text = fs_spfli-connid.
      wa_node-tlength ='20'.
      wa_node-tcolor = 4.
      APPEND wa_node TO it_node.
      CLEAR wa_node.
    ENDLOOP.
  ENDLOOP.
ENDFORM.                    " build_tree
*&----------------------------------------------------------------*
*&      Form  display_tree
*&----------------------------------------------------------------*
FORM display_tree .
  CALL FUNCTION 'RS_TREE_CONSTRUCT'
    TABLES
      nodetab = it_node.
  w_repid = sy-repid.
  CALL FUNCTION 'RS_TREE_LIST_DISPLAY'
    EXPORTING
      callback_program      = w_repid
      callback_user_command = 'USER_COMMAND'
      callback_gui_status   = 'SET_PF'.
ENDFORM.                    " display_tree
*&----------------------------------------------------------------*
*&      Form  pick
*&----------------------------------------------------------------*
*      -->COMMAND    text
*      -->NODE       text
*-----------------------------------------------------------------*
FORM user_command    TABLES pt_nodes         STRUCTURE seucomm
                     USING pv_command       TYPE c
                 CHANGING pv_exit        TYPE c
                          pv_list_refresh  TYPE c.
  pv_list_refresh = 'X'.
  IF pt_nodes-tlevel = '03'.
    CLEAR t_fieldcat[].
    SELECT carrid
           connid
           fldate
           FROM sflight
           INTO TABLE t_sflight
           WHERE connid EQ pt_nodes-text.
    fs_fieldcat-col_pos = 1.
    fs_fieldcat-fieldname = 'CARRID'.
    fs_fieldcat-seltext_m = 'Airlinecarrier'.
    fs_fieldcat-key = 'X'.
    fs_fieldcat-hotspot = 'X'.
    APPEND fs_fieldcat TO t_fieldcat.
    CLEAR fs_fieldcat.
    fs_fieldcat-col_pos = 2.
    fs_fieldcat-fieldname = 'CONNID'.
    fs_fieldcat-seltext_m = 'Connection No'.
    fs_fieldcat-key = 'X'.
    fs_fieldcat-hotspot = 'X'.
    APPEND fs_fieldcat TO t_fieldcat.
    CLEAR fs_fieldcat.
    fs_fieldcat-col_pos = 3.
    fs_fieldcat-fieldname = 'FLDATE'.
    fs_fieldcat-seltext_m = 'Flight Date'.
    fs_fieldcat-key = 'X'.
    fs_fieldcat-hotspot = 'X'.
    APPEND fs_fieldcat TO t_fieldcat.
    CLEAR fs_fieldcat.
    w_repid = sy-repid.
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
      EXPORTING
        i_callback_program = w_repid
        it_fieldcat        = t_fieldcat[]
      TABLES
        t_outtab           = t_sflight.
  ENDIF.
ENDFORM.                    "pick
*&----------------------------------------------------------------*
*&      Form  set_pf
*&----------------------------------------------------------------*
*       text
*-----------------------------------------------------------------*
FORM set_pf.
  SET PF-STATUS 'MYPF'.
ENDFORM.                    "set_pf
OUTPUT: 
Primary Screen: 
 
OUTPUT:
Secondary screen: