BSPL_TREE_CREATE

FUNCTION BSPL_TREE_CREATE .
*"----------------------------------------------------------------------
*"*"Globale Schnittstelle:
*"  IMPORTING
*"     VALUE(IS_SETTINGS) LIKE  RFBILA_ALV_SETTINGS STRUCTURE
*"        RFBILA_ALV_SETTINGS
*"     VALUE(IT_LIST_COMMENTARY) TYPE  SLIS_T_LISTHEADER OPTIONAL
*"----------------------------------------------------------------------
  CALL FUNCTION 'RGRE_ERGSL_TEXT_GET'
       EXPORTING
            LANGUAGE        = IS_SETTINGS-FS_LANGUAGE
            BALANCE_VERSION = IS_SETTINGS-FS_VERSION
            TEXT_TYPE       = 'K'
       TABLES
            TEXT_TAB        = GT_ERGSL_TEXT.

  CALL SCREEN 100.

ENDFUNCTION.


MODULE STATUS_0100 OUTPUT.
  SET PF-STATUS 'MAIN'.
  IF NOT ( IS_SETTINGS-TITLE IS INITIAL ).
    SET TITLEBAR 'MAIN' WITH IS_SETTINGS-TITLE.
  ENDIF.
  IF CONTROL_CONTAINER IS INITIAL.
     IF SY-BATCH IS INITIAL.
       CREATE OBJECT CONTROL_CONTAINER
              EXPORTING
                  EXTENSION = 1200.
     ENDIF.
     CREATE OBJECT ALV_TREE_CONTROL
            EXPORTING
                 PARENT         = CONTROL_CONTAINER
                 NO_HTML_HEADER = ' '.

     PERFORM BSPL_TREE_COLUMN_AREA_ADJUST
                                 CHANGING FIELDCATALOG.
     GS_DISVARIANT-REPORT   = IS_SETTINGS-REPID.
     GS_DISVARIANT-HANDLE   = CON_TREE.
     GS_DISVARIANT-USERNAME = SY-UNAME.
     GS_DISVARIANT-VARIANT  = IS_SETTINGS-TREE_VARI.

     PERFORM BSPL_TREE_HEADER_DEFINE
                                    CHANGING HIERARCHY_HEADER.

DATA: L_EVENT_RECEIVER TYPE REF TO LCL_TREE_EVENT_RECEIVER.
*... create object for event receiver
     CREATE OBJECT L_EVENT_RECEIVER.
     SET HANDLER L_EVENT_RECEIVER->HANDLE_TOP_OF_PAGE
                                 FOR ALV_TREE_CONTROL.
     CALL METHOD ALV_TREE_CONTROL->SET_TABLE_FOR_FIRST_DISPLAY
            EXPORTING
                 IS_VARIANT           =  GS_DISVARIANT
                 I_SAVE               = 'A'
                 IS_HIERARCHY_HEADER  = HIERARCHY_HEADER
                 IT_LIST_COMMENTARY   = IT_LIST_COMMENTARY
*                I_LOGO               = 'ENJOYSAP_LOGO'
            CHANGING
                 IT_OUTTAB            = TABLE_POINTER
                 IT_FIELDCATALOG      = FIELDCATALOG.

DATA: LT_NKEY_EXP     TYPE LVC_T_NKEY .
     PERFORM BSPL_TREE_COLUMN_TREE_FILL
                                 TABLES LT_NKEY_EXP.

*    Update calculations which were initially defined by field DO_SUM
*    of the fieldcatalog. (see BSPL_TREE_COLUMN_AREA_ADJUST).
     CALL METHOD ALV_TREE_CONTROL->UPDATE_CALCULATIONS.

     CALL METHOD ALV_TREE_CONTROL->EXPAND_NODES
       EXPORTING
         IT_NODE_KEY             = LT_NKEY_EXP
       EXCEPTIONS
         FAILED                  = 1
         CNTL_SYSTEM_ERROR       = 2
         ERROR_IN_NODE_KEY_TABLE = 3
         DP_ERROR                = 4
         NODE_NOT_FOUND          = 5
         OTHERS                  = 6.

     IF SY-SUBRC <> 0.
       MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
     ENDIF.

     CALL METHOD ALV_TREE_CONTROL->FRONTEND_UPDATE.

     CALL METHOD CL_GUI_CFW=>FLUSH.
  ENDIF.
ENDMODULE.

MODULE USER_COMMAND_0100 INPUT.
  SAVE_OK = OK_CODE.
  CLEAR OK_CODE.

  CASE SAVE_OK.
    WHEN 'BACK'
      OR 'EXIT'
      OR 'CANC'.
         LEAVE TO SCREEN 0.
    WHEN OTHERS.
      CALL METHOD CL_GUI_CFW=>DISPATCH.
  ENDCASE.
ENDMODULE.               "USER_COMMAND_0100 INPUT.

FORM BSPL_TREE_COLUMN_AREA_ADJUST
                      CHANGING P_FIELDCATALOG TYPE LVC_T_FCAT.
* local data declaration
DATA: LS_FIELDCATALOG TYPE LVC_S_FCAT.

  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
       EXPORTING
            I_STRUCTURE_NAME = 'BSPL_TREE_FIELDCAT'
       CHANGING
            CT_FIELDCAT      = P_FIELDCATALOG.

  LOOP AT P_FIELDCATALOG INTO LS_FIELDCATALOG.
    CASE LS_FIELDCATALOG-FIELDNAME.
      WHEN 'ID'
        OR 'PARENT'
        OR 'RLDNR'
        OR 'RRCTY'
        OR 'RVERS'.
        LS_FIELDCATALOG-NO_OUT = 'X'.
      WHEN 'REPVAL'
        OR 'COMPVAL'
        OR 'ABSVAR'.
        LS_FIELDCATALOG-DO_SUM  = 'X'.
    ENDCASE.
    MODIFY P_FIELDCATALOG FROM LS_FIELDCATALOG.
  ENDLOOP.

ENDFORM.          " BSPL_TREE_COLUMN_AREA_ADJUST

FORM BSPL_TREE_HEADER_DEFINE
            CHANGING P_HIERARCHY_HEADER TYPE TREEV_HHDR.
  P_HIERARCHY_HEADER-HEADING = 'Bil/GuV-Position/Konto'(001).
  P_HIERARCHY_HEADER-TOOLTIP = 'Bil/GuV-Position/Konto'(001).
  P_HIERARCHY_HEADER-WIDTH = 60.
  P_HIERARCHY_HEADER-WIDTH_PIX = SPACE.
ENDFORM.                    " BSPL_TREE_HEADER_DEFINE

*&---------------------------------------------------------------------*
*&      Form  BSPL_TREE_COLUMN_TREE_FILL
*&---------------------------------------------------------------------*
FORM BSPL_TREE_COLUMN_TREE_FILL
                      TABLES PT_EXPID TYPE LVC_T_NKEY.
* local data declaration
DATA: L_BPOS_KEY        TYPE LVC_NKEY,
      L_LEAF_KEY        TYPE LVC_NKEY,
      L_PARENT_KEY      TYPE LVC_NKEY,
      L_NOTASS_KEY      TYPE LVC_NKEY,
      L_NODE_TEXT       TYPE LVC_VALUE,
      LS_NODE_LAYOUT    TYPE LVC_S_LAYN,
      LT_ITEM_LAYOUT    TYPE LVC_T_LAYI.

DATA: LS_BSPLDATA       LIKE BSPL_TREE_FIELDCAT,
      LS_BSPLDATA_SAVE  LIKE BSPL_TREE_FIELDCAT,
      LS_NODE_SAKNR     TYPE TS_NODE_SAKNR,
      LS_NODE_ERGSL     TYPE TS_NODE_ERGSL.


* Ls_NODE_LAYOUT-N_IMAGE   =  ICON_SPACE.
* Ls_NODE_LAYOUT-EXP_IMAGE =  ICON_SPACE.
* Ls_NODE_LAYOUT-N_IMAGE   =  ICON_CLOSED_FOLDER.
* Ls_NODE_LAYOUT-EXP_IMAGE =  ICON_OPEN_FOLDER.
* Ls_NODE_LAYOUT-HIDDEN    =  'X'.  "Knoten komplett ausblenden
* Ls_NODE_LAYOUT-DISABLED  =  'X'.  "Knoten wird nicht farbig bei
*                                  "Cursorpositionierung

* save different fields like CURTP, WAERS ...
  READ TABLE GT_BSPLDATA INDEX 1 INTO LS_BSPLDATA_SAVE.

  LOOP AT GT_RSTHIE.
*.. prepare node ID
    WRITE: GT_RSTHIE-PARENT TO L_PARENT_KEY
                               NO-ZERO
                               RIGHT-JUSTIFIED.
    SHIFT L_PARENT_KEY LEFT.

    CLEAR: LS_NODE_LAYOUT.
    L_NODE_TEXT = GT_RSTHIE-NAME.

    CASE GT_RSTHIE-TYPE.
    WHEN CON_TOP.
*.... top node
      CLEAR: LS_BSPLDATA.
      LS_NODE_LAYOUT-HIDDEN = 'X'.
      L_NODE_TEXT = T011T-VSTXT.
      LS_BSPLDATA-CURTP  = LS_BSPLDATA_SAVE-CURTP.
      LS_BSPLDATA-WAERS  = LS_BSPLDATA_SAVE-WAERS.
      PERFORM BSPL_TREE_NODE_ADD USING    LS_BSPLDATA
                                          ' '
                                          L_NODE_TEXT
                                          LS_NODE_LAYOUT
                                          LT_ITEM_LAYOUT
                                 CHANGING L_PARENT_KEY.

    WHEN CON_BPOS.
*.... bs/p+l item
      CLEAR: LS_BSPLDATA.
      LS_NODE_ERGSL     = GT_RSTHIE-NAME.
      LS_BSPLDATA-ERGSL = LS_NODE_ERGSL-ERGSL.
      LS_BSPLDATA-CURTP  = LS_BSPLDATA_SAVE-CURTP.
      LS_BSPLDATA-WAERS  = LS_BSPLDATA_SAVE-WAERS.
      READ TABLE GT_ERGSL_TEXT
                 WITH KEY ERGSL = LS_NODE_ERGSL-ERGSL.
      IF SY-SUBRC = 0.
        L_NODE_TEXT = GT_ERGSL_TEXT-TXT45.
      ENDIF.
      IF GT_RSTHIE-TLEVEL = '02'.
*...... start with first column
        PERFORM BSPL_TREE_NODE_ADD USING   LS_BSPLDATA
                                            ' '
                                           L_NODE_TEXT
                                           LS_NODE_LAYOUT
                                           LT_ITEM_LAYOUT
                                  CHANGING L_BPOS_KEY.
        IF LS_NODE_ERGSL-ERGSL <> T011-ZUORD
       AND L_NOTASS_KEY IS INITIAL.
          APPEND L_BPOS_KEY TO PT_EXPID.
        ELSE.
          L_NOTASS_KEY = L_BPOS_KEY.
        ENDIF.
      ELSE.
*       IF GT_RSTHIE-TLEVEL >= '05'.    " bewirkt Anzeige bis
*         LS_NODE_LAYOUT-HIDDEN = 'X'.  " Stufe vier
*       ENDIF.
        PERFORM BSPL_TREE_NODE_ADD USING   LS_BSPLDATA
                                           L_PARENT_KEY
                                           L_NODE_TEXT
                                           LS_NODE_LAYOUT
                                           LT_ITEM_LAYOUT
                                  CHANGING L_BPOS_KEY.
      ENDIF.

    WHEN CON_FBER.
*.... function area
      SELECT SINGLE FKBTX INTO L_NODE_TEXT
                          FROM TFKBT WHERE SPRAS = SY-LANGU
                                       AND FKBER = GT_RSTHIE-NAME.
      CONCATENATE GT_RSTHIE-NAME
                  L_NODE_TEXT
             INTO L_NODE_TEXT SEPARATED BY ' '.

      LS_BSPLDATA-RFAREA = GT_RSTHIE-NAME.
      LS_BSPLDATA-CURTP  = LS_BSPLDATA_SAVE-CURTP.
      LS_BSPLDATA-WAERS  = LS_BSPLDATA_SAVE-WAERS.
      LS_BSPLDATA-RYEAR  = LS_BSPLDATA_SAVE-RYEAR.
      LS_BSPLDATA-POPER  = LS_BSPLDATA_SAVE-POPER.
      LS_NODE_LAYOUT-N_IMAGE   =  ICON_CONTROLLING_AREA.
      LS_NODE_LAYOUT-EXP_IMAGE =  ICON_CONTROLLING_AREA.
      PERFORM BSPL_TREE_NODE_ADD USING   LS_BSPLDATA
                                         L_PARENT_KEY
                                         L_NODE_TEXT
                                         LS_NODE_LAYOUT
                                         LT_ITEM_LAYOUT
                                CHANGING L_BPOS_KEY.

    WHEN CON_ACCT.
*.... account number
      LS_NODE_SAKNR = GT_RSTHIE-NAME.
      IF NOT ( IS_SETTINGS-ALTACCT IS INITIAL ).
*...... alternative account number is used
        LS_BSPLDATA-KTOP2 = LS_NODE_SAKNR-KTOPL.
        LS_BSPLDATA-ALTKT = LS_NODE_SAKNR-SAKNR.
      ELSEIF NOT ( T011-XERGS IS INITIAL ).
*...... group account number is used
        LS_BSPLDATA-KKTPL = LS_NODE_SAKNR-KTOPL.
        LS_BSPLDATA-BILKT = LS_NODE_SAKNR-SAKNR.
      ELSE.
*...... default normal accounts used
        LS_BSPLDATA-KTOPL = LS_NODE_SAKNR-KTOPL.
        LS_BSPLDATA-RACCT = LS_NODE_SAKNR-SAKNR.
      ENDIF.
      LS_BSPLDATA-CURTP  = LS_BSPLDATA_SAVE-CURTP.
      LS_BSPLDATA-WAERS  = LS_BSPLDATA_SAVE-WAERS.
      LS_BSPLDATA-RYEAR  = LS_BSPLDATA_SAVE-RYEAR.
      LS_BSPLDATA-POPER  = LS_BSPLDATA_SAVE-POPER.
      CLEAR: LS_BSPLDATA-RBUKRS.
      CALL FUNCTION 'READ_HAUPTBUCH_TEXT'
           EXPORTING
                KONTENPLAN     =  LS_NODE_SAKNR-KTOPL
                SACHKONTO      =  LS_NODE_SAKNR-SAKNR
                SPRACHE        =  IS_SETTINGS-FS_LANGUAGE
           IMPORTING
                TEXT_WA        =  SKAT
           EXCEPTIONS
                TEXT_NOT_FOUND = 1
                OTHERS         = 2 .
      IF SY-SUBRC = 0.
*...... fix account number to relevant length
        PERFORM BSPL_ACCOUNT_LENGTH_FIX
                               CHANGING LS_NODE_SAKNR.
        CONCATENATE LS_NODE_SAKNR-SAKNR
                    SKAT-TXT50
               INTO L_NODE_TEXT SEPARATED BY ' '.
      ELSE.
*...... fix account number to relevant length
        PERFORM BSPL_ACCOUNT_LENGTH_FIX
                               CHANGING LS_NODE_SAKNR.
        CONCATENATE LS_NODE_SAKNR-KTOPL
                    LS_NODE_SAKNR-SAKNR
               INTO L_NODE_TEXT SEPARATED BY ' '.
      ENDIF.

      LS_NODE_LAYOUT-N_IMAGE   =  ICON_ACCOUNT_ASSIGNMENT.
      LS_NODE_LAYOUT-EXP_IMAGE =  ICON_ACCOUNT_ASSIGNMENT.
      PERFORM BSPL_TREE_NODE_ADD USING   LS_BSPLDATA
                                         L_PARENT_KEY
                                         L_NODE_TEXT
                                         LS_NODE_LAYOUT
                                         LT_ITEM_LAYOUT
                                CHANGING L_BPOS_KEY.

    WHEN CON_CCOD.
*.... company code
      SELECT SINGLE BUTXT INTO L_NODE_TEXT
                          FROM T001 WHERE BUKRS = GT_RSTHIE-NAME.
      CONCATENATE GT_RSTHIE-NAME
                  L_NODE_TEXT
             INTO L_NODE_TEXT SEPARATED BY ' '.

      LS_BSPLDATA-RBUKRS = GT_RSTHIE-NAME.
      LS_BSPLDATA-CURTP  = LS_BSPLDATA_SAVE-CURTP.
      LS_BSPLDATA-WAERS  = LS_BSPLDATA_SAVE-WAERS.
      LS_BSPLDATA-RYEAR  = LS_BSPLDATA_SAVE-RYEAR.
      LS_BSPLDATA-POPER  = LS_BSPLDATA_SAVE-POPER.
      LS_NODE_LAYOUT-N_IMAGE   =  ICON_COMPANY_CODE.
      LS_NODE_LAYOUT-EXP_IMAGE =  ICON_COMPANY_CODE.
      PERFORM BSPL_TREE_NODE_ADD USING   LS_BSPLDATA
                                         L_PARENT_KEY
                                         L_NODE_TEXT
                                         LS_NODE_LAYOUT
                                         LT_ITEM_LAYOUT
                                CHANGING L_BPOS_KEY.

    WHEN CON_LEAF.
*.... assigned accounts  (BUSA's)
      SELECT SINGLE GTEXT INTO L_NODE_TEXT
                          FROM TGSBT WHERE SPRAS = SY-LANGU
                                       AND GSBER = GT_RSTHIE-NAME.

      READ TABLE GT_BSPLDATA WITH KEY ID = GT_RSTHIE-ID
                                           BINARY SEARCH.
      IF SY-SUBRC <> 0.
        CLEAR: GT_BSPLDATA.
      ENDIF.

      IF L_NODE_TEXT = CON_RESULT.
        L_NODE_TEXT = TEXT-003.
        LS_NODE_LAYOUT-N_IMAGE   =  ICON_SPACE.
        LS_NODE_LAYOUT-EXP_IMAGE =  ICON_SPACE.
        CLEAR: GT_BSPLDATA-RACCT,
               GT_BSPLDATA-BILKT,
               GT_BSPLDATA-ALTKT.
      ELSE.
        IF L_NODE_TEXT IS INITIAL.
          L_NODE_TEXT = TEXT-002.
        ENDIF.
        CONCATENATE GT_RSTHIE-NAME
                    L_NODE_TEXT
               INTO L_NODE_TEXT SEPARATED BY ' '.
        LS_NODE_LAYOUT-N_IMAGE   =  ICON_BUSINESS_AREA.
        LS_NODE_LAYOUT-EXP_IMAGE =  ICON_BUSINESS_AREA.
      ENDIF.
      PERFORM BSPL_TREE_NODE_ADD USING GT_BSPLDATA
                                       L_BPOS_KEY
                                       L_NODE_TEXT
                                       LS_NODE_LAYOUT
                                       LT_ITEM_LAYOUT
                              CHANGING L_LEAF_KEY.
    ENDCASE.
  ENDLOOP.
ENDFORM.                    " BSPL_TREE_COLUMN_TREE_FILL

*&---------------------------------------------------------------------*
*&      Form  BSPL_TREE_NODE_ADD
*&---------------------------------------------------------------------*
FORM BSPL_TREE_NODE_ADD USING P_BSPLDATA LIKE BSPL_TREE_FIELDCAT
                              P_RELAT_KEY     TYPE LVC_NKEY
                              P_NODE_TEXT     TYPE LVC_VALUE
                              PS_NODE_LAYOUT  TYPE LVC_S_LAYN
                              PT_ITEM_LAYOUT  TYPE LVC_T_LAYI
                     CHANGING P_NEW_KEY.

  CALL METHOD ALV_TREE_CONTROL->ADD_NODE
    EXPORTING
       I_RELAT_NODE_KEY = P_RELAT_KEY
       I_RELATIONSHIP   = CL_GUI_COLUMN_TREE=>RELAT_LAST_CHILD
       I_NODE_TEXT      = P_NODE_TEXT
       IS_OUTTAB_LINE   = P_BSPLDATA
       IS_NODE_LAYOUT   = PS_NODE_LAYOUT
       IT_ITEM_LAYOUT   = PT_ITEM_LAYOUT
    IMPORTING
       E_NEW_NODE_KEY = P_NEW_KEY.

ENDFORM.                    " BSPL_TREE_NODE_ADD

* local classes
*---------------------------------------------------------------------*
*       CLASS LCL_TREE_EVENT_RECEIVER IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS LCL_TREE_EVENT_RECEIVER IMPLEMENTATION.

METHOD HANDLE_TOP_OF_PAGE.
* local adata declaration
DATA: LT_LIST_COMMENTARY TYPE SLIS_T_LISTHEADER.
DATA: LS_LIST_COMMENTARY TYPE SLIS_LISTHEADER.

  IF LT_LIST_COMMENTARY[] IS INITIAL.
*.. check if list commentary is filled by caller
    IF NOT IT_LIST_COMMENTARY[] IS INITIAL.
*.... yes, take it over
      LT_LIST_COMMENTARY[] = IT_LIST_COMMENTARY[].
    ELSE.
*.... no, then set default list commentary
      LS_LIST_COMMENTARY-TYP  = 'H'.
      LS_LIST_COMMENTARY-INFO = T011T-VSTXT.
      APPEND LS_LIST_COMMENTARY
          TO LT_LIST_COMMENTARY.
    ENDIF.
  ENDIF.

* fill standard page header
  BHDGD-INIFL = CON_0.
  BHDGD-LINES = SY-LINSZ.
  BHDGD-UNAME = SY-UNAME.
  BHDGD-REPID = IS_SETTINGS-REPID.
  READ TABLE LT_LIST_COMMENTARY INDEX 1
                                 INTO LS_LIST_COMMENTARY.
  BHDGD-LINE1 = LS_LIST_COMMENTARY-INFO.
  BHDGD-LINE2 = IS_SETTINGS-ALLGLINE.
  BHDGD-BUKRS = IS_SETTINGS-BUKRS.
  BHDGD-DOMAI = 'BUKRS'.
  BHDGD-START_PAGNO = IS_SETTINGS-PAGE_NO.

* write standard page header
  PERFORM BATCH-HEADING1 IN PROGRAM RSBTCHH0 USING BHDGD.

ENDMETHOD.                    "HANDLE_TOP_OF_PAGE
ENDCLASS.

你可能感兴趣的:(image,list,tree,header,command,hierarchy)