*
* This program uses a tree structure to dispaly the 
* transports of a specified period. You can drill
* down in a tree to display the transports by type,
* number and date and to display the objects inside.
*
REPORT ZTRPLIST.

TABLES: E070, E071.
PARAMETERS: STRDAT TYPE D DEFAULT SY-DATUM,
            ENDDAT TYPE D DEFAULT SY-DATUM.
DATA: BEGIN OF ITAB OCCURS 100,
    TRFUNCTION LIKE E070-TRFUNCTION,
    AS4DATE    LIKE E070-AS4DATE,
    TRKORR     LIKE E070-TRKORR,
    PGMID      LIKE E071-PGMID,
    OBJECT     LIKE E071-OBJECT,
    OBJ_NAME   LIKE E071-OBJ_NAME,
END OF ITAB.
DATA: BEGIN OF SITAB OCCURS 100,
    TRFUNCTION LIKE E070-TRFUNCTION,
    AS4DATE    LIKE E070-AS4DATE,
    TRKORR     LIKE E070-TRKORR,
    PGMID      LIKE E071-PGMID,
    OBJECT     LIKE E071-OBJECT,
    OBJ_NAME   LIKE E071-OBJ_NAME,
END OF SITAB.
DATA: C(3), TEXT1(50), TEXT2(50), COL1 TYPE I, COL2 TYPE I, LEVEL TYPE
      I, F15 TYPE C, LEN1 TYPE I, LEN2 TYPE I, COUNT TYPE I.
DATA: BEGIN OF TREE OCCURS 100.
        INCLUDE STRUCTURE SNODETEXT.
DATA: END OF TREE.

SELECT-OPTIONS SRC_SYTS FOR C NO INTERVALS DEFAULT 'DEV'.

START-OF-SELECTION.
  SET PF-STATUS 'LIBS1'.
  SELECT * FROM E070 WHERE AS4DATE >= STRDAT AND
                           AS4DATE <= ENDDAT
                           ORDER BY TRFUNCTION AS4DATE.
    SELECT * FROM E071 WHERE TRKORR = E070-TRKORR AND
      PGMID <> 'CORR'.
      MOVE-CORRESPONDING E070 TO ITAB.
      MOVE-CORRESPONDING E071 TO ITAB.
      APPEND ITAB.
    ENDSELECT.
  ENDSELECT.

  LOOP AT ITAB.
    SITAB = ITAB. APPEND SITAB.
  ENDLOOP.

  DATA: BEGIN OF STRUCC OCCURS 500.
          INCLUDE STRUCTURE SNODETEXT.
  DATA: END OF STRUCC.

  LOOP AT ITAB.
    AT FIRST.
*   write: / 'Transports between', strdat, 'and', enddat.
      TEXT1 = 'Transports between'.
      TEXT1+21 = STRDAT.
      TEXT1+31 = 'and'.
      TEXT1+35 = ENDDAT.
      CLEAR TEXT2.
      LEN1 = 50. LEN2 = 0.
      COL1 = 1. COL2 = 2. LEVEL = 1.
      PERFORM FILL_TREETAB.
    ENDAT.
    AT NEW TRFUNCTION.
*   write: / itab-trfunction color 3.
      COUNT = 0.
      LOOP AT SITAB.
        IF ITAB-TRFUNCTION = SITAB-TRFUNCTION.
          COUNT = COUNT + 1.
        ENDIF.
      ENDLOOP.
      TEXT1 = ITAB-TRFUNCTION.
      TEXT1+3 = 'type transport'.
      TEXT2 = COUNT.
      CONDENSE TEXT2.
      LEN1 = 20. LEN2 = 16.
      COL1 = 3. COL2 = 7. LEVEL = 2.
      PERFORM FILL_TREETAB.
    ENDAT.
    AT NEW TRKORR.
*   write: / itab-trkorr color 4, itab-as4date color 4.
      TEXT1 = ITAB-TRKORR.
      TEXT2 = ITAB-AS4DATE.
      LEN1 = 10. LEN2 = 10.
      COL1 = 4. COL2 = 4. LEVEL = 3.
      PERFORM FILL_TREETAB.
    ENDAT.
* write: / itab-pgmid color 5, itab-object color 5, itab-obj_name(30)
    TEXT1 = ITAB-PGMID.
    TEXT1+4 = ITAB-OBJECT.
    TEXT1+10 = ITAB-OBJ_NAME(30).
    CLEAR TEXT2.
    LEN1 = 50. LEN2 = 0.
    COL1 = 5. COL2 = 5. LEVEL = 4.
    PERFORM FILL_TREETAB.

  ENDLOOP.

  CALL FUNCTION 'RS_TREE_CONSTRUCT'
       TABLES
            NODETAB      = TREE
       EXCEPTIONS
            TREE_FAILURE = 1.
  SY-LSIND = 0.
  CALL FUNCTION 'RS_TREE_LIST_DISPLAY'
       EXPORTING
            CALLBACK_PROGRAM      = 'ZTRPLIST'
            CALLBACK_USER_COMMAND = 'NODE_SELECT'
       IMPORTING
            F15                   = F15.

*---------------------------------------------------------------------*
*       FORM NODE_SELECT                                              *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  KNOTEN                                                        *
*  -->  COMMAND                                                       *
*  -->  EXIT                                                          *
*  -->  LIST_REFRESH                                                  *
*---------------------------------------------------------------------*
FORM NODE_SELECT TABLES KNOTEN STRUCTURE SEUCOMM
  USING COMMAND
  CHANGING EXIT
           LIST_REFRESH.
  EXIT = ' '.
  LIST_REFRESH = 'X'.
ENDFORM.


*---------------------------------------------------------------------*
*       FORM FILL_TREETAB                                             *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM FILL_TREETAB.
  TREE-NAME = TEXT1.
  TREE-COLOR = COL1.
  TREE-INTENSIV = '1'.
  TREE-TEXT = TEXT1.
  TREE-TLENGTH = LEN1.
  TREE-TLEVEL = LEVEL.
  TREE-TCOLOR = COL1.
  TREE-TINTENSIV = '1'.
  TREE-TEXT1 = TEXT2.
  TREE-TLENGTH1 = LEN2.
  TREE-TCOLOR1 = COL2.
  TREE-TINTENSIV = '0'.
  APPEND TREE.
ENDFORM.