Categorias

ABAP: Busca Exit’s e Badi’s atráves de uma Transação

Veja como fazer uma busca de Exit’s e Badi’s atráves de uma Transação.

*&---------------------------------------------------------------------*
*& Autor: Pathelle Romanholi Chaves Morais                             *
*& Data : 28.05.2009                                                   *
*&---------------------------------------------------------------------*
*&                 Busca Exit's/Badis para Transações                  *
*&---------------------------------------------------------------------*
*&                             PF-STATUS                               *
*&---------------------------------------------------------------------*
*&  MAIN      Copiar do Programa BDLVTREE                              *
*&---------------------------------------------------------------------*
*&                               TEXT                                  *
*&---------------------------------------------------------------------*
*&  001       Parâmetros de Seleção                                    *
*&  002       Código Transacional Inválido                             *
*&  003       Código de Idioma Inexistente                             *
*&  004       Erro ao Encontrar Pacote Desenvolv. da Transação         *
*&  005       Ampliações                                               *
*&  006       Raiz                                                     *
*&  007       Funções                                                  *
*&  009       Não Existe Ampliações para esta Transação                *
*&  010       Não Existe Badis para esta Transação                     *
*&  011       Exit's                                                   *
*&  012       Badi's                                                   *
*&  013       Badi                                                     *
*&---------------------------------------------------------------------*

REPORT z_busca_exit_badi NO STANDARD PAGE HEADING.

*----------------------------------------------------------------------*
*                                 TYPES                                *
*----------------------------------------------------------------------*
TYPES: BEGIN OF type_tstc,
         tcode TYPE tstc-pgmna,
         pgmna TYPE tstc-pgmna,
       END   OF type_tstc,

       BEGIN OF type_obj,
         pgmid    TYPE tadir-pgmid   ,
         object   TYPE tadir-object  ,
         obj_name TYPE modsap-name   ,
       END   OF type_obj,

       BEGIN OF type_modsap,
         name   TYPE modsap-name   ,
         typ    TYPE modsap-typ    ,
         member TYPE tftit-funcname,
       END   OF type_modsap,

       BEGIN OF type_badi,
         pgmid    TYPE tadir-pgmid        ,
         object   TYPE tadir-object       ,
         obj_name TYPE sxs_attrt-exit_name,
       END   OF type_badi,

       BEGIN OF type_modact,
         name   TYPE modact-name  ,
         typ    TYPE modact-typ   ,
         member TYPE modact-member,
       END   OF type_modact,

       BEGIN OF type_aux,
         pgmid    TYPE tadir-pgmid   ,
         object   TYPE tadir-object  ,
         obj_name TYPE modact-member ,
       END   OF type_aux.

*----------------------------------------------------------------------*
*                                TABELAS                               *
*----------------------------------------------------------------------*
DATA: t_objetos   TYPE TABLE OF type_obj   , "Objetos referente as Exit's
      t_mylist    TYPE TABLE OF snodetext  , "Tabela TREE
      t_modsap    TYPE TABLE OF type_modsap, "Ampliações
      t_modsapt   TYPE TABLE OF modsapt    , "Descrições Ampliações
      t_obj_badi  TYPE TABLE OF type_badi  , "Objetos referente as Badi's
      t_sxs_attrt TYPE TABLE OF sxs_attrt  , "Descrições Badi's
      t_tftit     TYPE TABLE OF tftit      , "Texto Breve Modulos de Função
      t_modact    TYPE TABLE OF modact     , "Projetos
      t_modtext   TYPE TABLE OF modtext    , "Descrições dos Projetos
      t_modsap_b  TYPE TABLE OF type_modsap, "Ampliações
      t_tftit_b   TYPE TABLE OF tftit      , "Texto Breve Modulos de Função
      t_bdcdata   TYPE TABLE OF bdcdata    . "Mapeamento de Telas

*----------------------------------------------------------------------*
*                               VARIÀVEIS                              *
*----------------------------------------------------------------------*
DATA v_ttext  TYPE tstct-ttext. "Descrição da Transação

*----------------------------------------------------------------------*
*                               ESTRUTURAS                             *
*----------------------------------------------------------------------*
DATA: st_tstc   TYPE type_tstc  , "Código Transação
      st_modsap TYPE type_modsap. "Uso Structure

*----------------------------------------------------------------------*
*                            TELA DE SELEÇÂO                           *
*----------------------------------------------------------------------*

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME.
PARAMETERS :
  p_tcode TYPE tstc-tcode OBLIGATORY,
  p_langu TYPE spras      OBLIGATORY DEFAULT sy-langu.
SELECTION-SCREEN END   OF BLOCK b2.
SELECTION-SCREEN END   OF BLOCK b1.

*----------------------------------------------------------------------*
* p_tcode -> Código Transacional                                       *
* p_langu -> Idioma                                                    *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
*                         AT SELECTION SCREEN                          *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON p_tcode.

* Verifica Código Informado
  PERFORM z_verifica_tcode.

AT SELECTION-SCREEN ON p_langu.

* Verifica Idioma Informado
  PERFORM z_verifica_langu.

*----------------------------------------------------------------------*
*                          START OF SELECTION                          *
*----------------------------------------------------------------------*
START-OF-SELECTION.

* Seleciona Dados
  PERFORM: z_seleciona_dados,

* Monta Relatório
           z_monta_relat    ,

* Monta ALV TREE
           z_monta_tree     ,

* Monta DRAW TREE
           z_monta_draw     .

*&---------------------------------------------------------------------*
*&      Form  Z_VERIFICA_TCODE                                         *
*&---------------------------------------------------------------------*
*                      Verifica Código Informado                       *
*----------------------------------------------------------------------*
FORM z_verifica_tcode.

  CLEAR st_tstc.

  SELECT SINGLE tcode pgmna
    FROM tstc
    INTO st_tstc
  WHERE  tcode EQ p_tcode.

  IF NOT sy-subrc IS INITIAL.
    MESSAGE text-002 TYPE 'E'.
  ENDIF.

ENDFORM.                    " Z_VERIFICA_TCODE

*&---------------------------------------------------------------------*
*&      Form  Z_VERIFICA_LANGU                                         *
*&---------------------------------------------------------------------*
*                        Verifica Idioma Informado                     *
*----------------------------------------------------------------------*
FORM z_verifica_langu.

  SELECT SINGLE spras
    FROM t002
    INTO p_langu
  WHERE  spras EQ p_langu.

  IF NOT sy-subrc IS INITIAL.
    MESSAGE text-003 TYPE 'E'.
  ENDIF.

ENDFORM.                    " Z_VERIFICA_LANGU

*&---------------------------------------------------------------------*
*&      Form  Z_SELECIONA_DADOS                                        *
*&---------------------------------------------------------------------*
*                             Seleciona Dados                          *
*----------------------------------------------------------------------*
FORM z_seleciona_dados.

  DATA: vl_classe   TYPE tadir-devclass,
        vl_subc     TYPE trdir-subc    ,
        vl_funcname TYPE tfdir-funcname,
        vl_area     TYPE enlfdir-area  ,
        vl_subrc    TYPE sysubrc       .

* Seleciona TADIR
  PERFORM z_seleciona_tadir USING st_tstc-pgmna
                                  'R3TR'
                                  'PROG'
                         CHANGING vl_classe
                                  vl_subrc.

  IF NOT vl_subrc IS INITIAL.

*   Seleciona TRDIR
    PERFORM z_seleciona_trdir CHANGING vl_subc
                                       vl_subrc.

    IF vl_subrc IS INITIAL.

      CASE vl_subc.
        WHEN 'F'.
*         Seleciona TFDIR
          PERFORM z_seleciona_tfdir CHANGING vl_funcname
                                             vl_subrc.

          IF vl_subrc IS INITIAL.
*           Seleciona ENLFDIR
            PERFORM z_seleciona_enlfdir USING vl_funcname
                                     CHANGING vl_area
                                              vl_subrc.
          ENDIF.

          IF vl_subrc IS INITIAL.
*           Seleciona TADIR
            PERFORM z_seleciona_tadir USING vl_area
                                            'R3TR'
                                            'FUGR'
                                   CHANGING vl_classe
                                            vl_subrc.
          ENDIF.

        WHEN OTHERS.
      ENDCASE.

    ENDIF.

  ENDIF.

  IF vl_classe IS INITIAL.
    MESSAGE text-004 TYPE 'I'.
    EXIT.
  ENDIF.

* Seleciona Objetos, Tabela TADIR (Exit's)
  PERFORM: z_seleciona_objetos TABLES t_objetos
                                USING vl_classe
                                      'SMOD'  ,

* Seleciona Texto Breve da Transação, Tabela TSTCT
           z_seleciona_tstct                  ,

* Seleciona Ampliações, Tabela MODSAP (Exit's)
           z_seleciona_modsap TABLES t_objetos
                                     t_modsap ,

* Seleciona Texto Breve Módulo de Função, Tabela TFTIT (Exit's)
           z_seleciona_tftit  TABLES t_modsap
                                     t_tftit  ,

* Seleciona Texto Breve Ampliações, Tabela MODSAPT
           z_seleciona_modsapt                ,

* Seleciona Objetos, Tabela TADIR (Badi's)
           z_seleciona_objetos TABLES t_obj_badi
                                USING vl_classe
                                      'SXSD'  ,

* Seleciona Texto Breve Badi, Tabela SXS_ATTRT
           z_seleciona_sxs_attrt              ,

* Seleciona Projetos, Tabela MODACT
           z_seleciona_modact                 ,

* Seleciona Texto Breve Projeto, Tabela MODTEXT
           z_seleciona_modtext                ,

* Seleciona Ampliações, Tabela MODSAP (Badi's)
           z_seleciona_modsap TABLES t_obj_badi
                                     t_modsap_b,

* Seleciona Texto Breve Módulo de Função, Tabela TFTIT (Badi's)
           z_seleciona_tftit  TABLES t_modsap_b
                                     t_tftit_b .

ENDFORM.                    " Z_SELECIONA_DADOS

*&---------------------------------------------------------------------*
*&      Form  Z_SELECIONA_TADIR                                        *
*&---------------------------------------------------------------------*
*                             Seleciona TADIR                          *
*----------------------------------------------------------------------*
FORM z_seleciona_tadir USING p_name   TYPE c
                             p_pgmid  TYPE c
                             p_object TYPE c
                    CHANGING p_classe TYPE tadir-devclass
                             p_subrc  TYPE sysubrc.

  CLEAR: p_classe,
         p_subrc .

  SELECT SINGLE devclass
    FROM tadir
    INTO p_classe
  WHERE pgmid    EQ p_pgmid
    AND object   EQ p_object
    AND obj_name EQ p_name.

  p_subrc = sy-subrc.

ENDFORM.                    " Z_SELECIONA_TADIR

*&---------------------------------------------------------------------*
*&      Form  Z_SELECIONA_TRDIR                                        *
*&---------------------------------------------------------------------*
*                             Seleciona TRDIR                          *
*----------------------------------------------------------------------*
FORM z_seleciona_trdir CHANGING p_subc  TYPE trdir-subc
                                p_subrc TYPE sysubrc.

  CLEAR: p_subc  ,
         p_subrc .

  SELECT SINGLE subc
    FROM trdir
    INTO p_subc
  WHERE name EQ st_tstc-pgmna.

  p_subrc = sy-subrc.

ENDFORM.                    " Z_SELECIONA_TRDIR

*&---------------------------------------------------------------------*
*&      Form  Z_SELECIONA_TFDIR                                        *
*&---------------------------------------------------------------------*
*                              Seleciona TFDIR                         *
*----------------------------------------------------------------------*
FORM z_seleciona_tfdir CHANGING p_funcname TYPE tfdir-funcname
                                p_subrc    TYPE sysubrc.

  CLEAR: p_funcname,
         p_subrc   .

  SELECT SINGLE funcname
    FROM tfdir
    INTO p_funcname
  WHERE pname EQ st_tstc-pgmna.

  p_subrc = sy-subrc.

ENDFORM.                    " Z_SELECIONA_TFDIR

*&---------------------------------------------------------------------*
*&      Form  Z_SELECIONA_ENLFDIR                                      *
*&---------------------------------------------------------------------*
*                         Seleciona ENLFDIR                            *
*----------------------------------------------------------------------*
FORM z_seleciona_enlfdir USING p_funcname TYPE tfdir-funcname
                      CHANGING p_area     TYPE c
                               p_subrc    TYPE sysubrc.

  CLEAR: p_area ,
         p_subrc.

  SELECT SINGLE area
    FROM enlfdir
    INTO p_area
  WHERE funcname EQ p_funcname.

  p_subrc = sy-subrc.

ENDFORM.                    " Z_SELECIONA_ENLFDIR

*&---------------------------------------------------------------------*
*&      Form  Z_SELECIONA_OBJETOS                                      *
*&---------------------------------------------------------------------*
*                   Seleciona Objetos, Tabela TADIR                    *
*----------------------------------------------------------------------*
FORM z_seleciona_objetos TABLES p_table
                          USING p_classe TYPE tadir-devclass
                                p_object TYPE c.

  REFRESH p_table.

  SELECT pgmid    object
         obj_name
    FROM tadir
    INTO TABLE p_table
  WHERE devclass EQ p_classe
    AND pgmid    EQ 'R3TR'
    AND object   EQ p_object.

ENDFORM.                    " Z_SELECIONA_OBJETOS

*&---------------------------------------------------------------------*
*&      Form  Z_SELECIONA_TSTCT                                        *
*&---------------------------------------------------------------------*
*         Seleciona Texto Breve da Transação, Tabela TSTCT             *
*----------------------------------------------------------------------*
FORM z_seleciona_tstct.

  CLEAR v_ttext.

  SELECT SINGLE ttext
    FROM tstct
    INTO v_ttext
  WHERE  sprsl EQ p_langu
    AND  tcode EQ p_tcode.

ENDFORM.                    " Z_SELECIONA_TSTCT

*&---------------------------------------------------------------------*
*&      Form  Z_SELECIONA_MODSAP                                       *
*&---------------------------------------------------------------------*
*               Seleciona Ampliações, Tabela MODSAP                    *
*----------------------------------------------------------------------*
FORM z_seleciona_modsap TABLES p_objetos
                               p_modsap  STRUCTURE st_modsap.

  DATA tl_obj TYPE TABLE OF type_obj.

  REFRESH p_modsap.

  CHECK NOT p_objetos[] IS INITIAL.

  tl_obj[] = p_objetos[].

  SELECT name typ member
    FROM modsap
    INTO TABLE p_modsap
    FOR ALL ENTRIES IN tl_obj
  WHERE  name EQ tl_obj-obj_name
    AND  typ  EQ 'E'.

  SORT p_modsap BY name ASCENDING.

ENDFORM.                    " Z_SELECIONA_MODSAP

*&---------------------------------------------------------------------*
*&      Form  Z_SELECIONA_TFTIT                                        *
*&---------------------------------------------------------------------*
*         Seleciona Texto Breve Módulo de Função, Tabela TFTIT         *
*----------------------------------------------------------------------*
FORM z_seleciona_tftit TABLES p_modsap STRUCTURE st_modsap
                              p_tftit  STRUCTURE tftit.

  REFRESH p_tftit.

  CHECK NOT p_modsap[] IS INITIAL.

  SELECT spras funcname stext
    FROM tftit
    INTO TABLE p_tftit
    FOR ALL ENTRIES IN p_modsap
  WHERE  spras    EQ p_langu
    AND  funcname EQ p_modsap-member.

  SORT p_tftit BY funcname ASCENDING.

ENDFORM.                    " Z_SELECIONA_TFTIT

*&---------------------------------------------------------------------*
*&      Form  Z_SELECIONA_MODSAPT                                      *
*&---------------------------------------------------------------------*
*          Seleciona Texto Breve Ampliações, Tabela MODSAPT            *
*----------------------------------------------------------------------*
FORM z_seleciona_modsapt.

  REFRESH t_modsapt.

  CHECK NOT t_objetos[] IS INITIAL.

  SELECT sprsl name modtext
    FROM modsapt
    INTO TABLE t_modsapt
    FOR ALL ENTRIES IN t_objetos
  WHERE  sprsl EQ p_langu
    AND  name  EQ t_objetos-obj_name.

  SORT t_modsapt BY name ASCENDING.

ENDFORM.                    " Z_SELECIONA_MODSAPT

*&---------------------------------------------------------------------*
*&      Form  Z_SELECIONA_SXS_ATTRT                                    *
*&---------------------------------------------------------------------*
*          Seleciona Texto Breve Badi, Tabela SXS_ATTRT                *
*----------------------------------------------------------------------*
FORM z_seleciona_sxs_attrt.

  REFRESH t_sxs_attrt.

  CHECK NOT t_obj_badi[] IS INITIAL.

  SELECT exit_name sprsl text
    FROM sxs_attrt
    INTO TABLE t_sxs_attrt
    FOR ALL ENTRIES IN t_obj_badi
  WHERE  exit_name EQ t_obj_badi-obj_name
    AND  sprsl     EQ p_langu.

  SORT t_sxs_attrt BY exit_name ASCENDING.

ENDFORM.                    " Z_SELECIONA_SXS_ATTRT

*&---------------------------------------------------------------------*
*&      Form  Z_SELECIONA_MODACT                                       *
*&---------------------------------------------------------------------*
*                    Seleciona Projetos, Tabela MODACT                 *
*----------------------------------------------------------------------*
FORM z_seleciona_modact.

  DATA tl_obj TYPE TABLE OF type_aux.

  REFRESH t_modact.

  CHECK NOT t_obj_badi[] IS INITIAL.

  tl_obj[] = t_obj_badi[].

  SELECT name typ member
    FROM modact
    INTO TABLE t_modact
    FOR ALL ENTRIES IN tl_obj
  WHERE  member EQ tl_obj-obj_name
    AND  typ    EQ 'E'.

  SORT t_modact BY member ASCENDING.

ENDFORM.                    " Z_SELECIONA_MODACT

*&---------------------------------------------------------------------*
*&      Form  Z_SELECIONA_MODTEXT                                      *
*&---------------------------------------------------------------------*
*           Seleciona Texto Breve Projeto, Tabela MODTEXT              *
*----------------------------------------------------------------------*
FORM z_seleciona_modtext.

  REFRESH t_modtext.

  CHECK NOT t_modact[] IS INITIAL.

  SELECT sprsl name modtext
    FROM modtext
    INTO TABLE t_modtext
    FOR ALL ENTRIES IN t_modact
  WHERE sprsl EQ p_langu
    AND name  EQ t_modact-name.

  SORT t_modtext BY name ASCENDING.

ENDFORM.                    " Z_SELECIONA_MODTEXT

*&---------------------------------------------------------------------*
*&      Form  Z_MONTA_RELAT                                            *
*&---------------------------------------------------------------------*
*                            Monta Relatório                           *
*----------------------------------------------------------------------*
FORM z_monta_relat.

  DATA: sl_objetos   TYPE type_obj    ,
        sl_modsap    TYPE type_modsap ,
        sl_modsapt   TYPE modsapt     ,
        sl_tftit     TYPE tftit       ,
        sl_obj_badi  TYPE type_badi   ,
        sl_sxs_attrt TYPE sxs_attrt   ,
        sl_modact    TYPE type_modact ,
        sl_modtext   TYPE modtext     .

  REFRESH t_mylist.

  IF t_objetos[] IS INITIAL.
    MESSAGE text-009 TYPE 'I'.
  ENDIF.

  IF t_obj_badi[] IS INITIAL.
    MESSAGE text-010 TYPE 'I'.
  ENDIF.

  IF t_objetos[] IS INITIAL AND
     t_obj_badi[] IS INITIAL.
    EXIT.
  ENDIF.

* Preenche Tabela Hierárquica T_MYLIST
  PERFORM z_preenche_mylist USING p_tcode
                                  6
                                  1
                                  p_tcode
                                  10
                                  1
                                  6
                                  1
                                  v_ttext
                                  30
                                  6
                                  2
                                  space
                                  space
                                  space
                                  space
                                  space
                                  space
                                  space
                                  space
                                  space.

  IF NOT t_objetos[] IS INITIAL.
    PERFORM z_preenche_mylist USING text-011
                                    5
                                    1
                                    text-011
                                    10
                                    2
                                    5
                                    1
                                    text-011
                                    30
                                    5
                                    2
                                    space
                                    space
                                    space
                                    space
                                    space
                                    space
                                    space
                                    space
                                    space.
  ENDIF.

  LOOP AT t_objetos INTO sl_objetos.

    CLEAR: sl_modsap ,
           sl_modsapt,
           sl_tftit  .

    READ TABLE t_modsapt INTO sl_modsapt
      WITH KEY name = sl_objetos-obj_name
      BINARY SEARCH.

    CHECK sy-subrc IS INITIAL.

*   Preenche Tabela Hierárquica T_MYLIST
    PERFORM z_preenche_mylist USING text-005
                                    4
                                    1
                                    sl_objetos-obj_name
                                    10
                                    3
                                    4
                                    1
                                    sl_modsapt-modtext
                                    50
                                    4
                                    2
                                    space
                                    space
                                    space
                                    space
                                    space
                                    space
                                    space
                                    space
                                    space.

    READ TABLE t_modsap INTO sl_modsap
      WITH KEY name = sl_objetos-obj_name
      BINARY SEARCH.

    CHECK sy-subrc IS INITIAL.

    READ TABLE t_tftit INTO sl_tftit
      WITH KEY funcname = sl_modsap-member
      BINARY SEARCH.

*   Preenche Tabela Hierárquica T_MYLIST
    PERFORM z_preenche_mylist USING text-007
                                    7
                                    1
                                    sl_modsap-member
                                    30
                                    4
                                    7
                                    1
                                    sl_tftit-stext
                                    50
                                    7
                                    2
                                    space
                                    space
                                    space
                                    space
                                    space
                                    space
                                    space
                                    space
                                    space.

    CLEAR sl_objetos.

  ENDLOOP.

  IF NOT t_obj_badi[] IS INITIAL.
    PERFORM z_preenche_mylist USING text-012
                                    5
                                    1
                                    text-012
                                    10
                                    2
                                    5
                                    1
                                    text-012
                                    30
                                    5
                                    2
                                    space
                                    space
                                    space
                                    space
                                    space
                                    space
                                    space
                                    space
                                    space.
  ENDIF.

  LOOP AT t_obj_badi INTO sl_obj_badi.

    CLEAR: sl_sxs_attrt,
           sl_modact   ,
           sl_modtext  ,
           sl_modsap   ,
           sl_tftit    .

    READ TABLE t_modact INTO sl_modact
      WITH KEY member = sl_obj_badi-obj_name
      BINARY SEARCH.

    IF sy-subrc IS INITIAL.
      READ TABLE t_modtext INTO sl_modtext
        WITH KEY name = sl_modact-name
        BINARY SEARCH.
    ENDIF.

    READ TABLE t_sxs_attrt INTO sl_sxs_attrt
      WITH KEY exit_name = sl_obj_badi-obj_name
      BINARY SEARCH.

*   Preenche Tabela Hierárquica T_MYLIST
    PERFORM z_preenche_mylist USING text-013
                                    4
                                    1
                                    sl_obj_badi-obj_name
                                    10
                                    3
                                    4
                                    1
                                    sl_sxs_attrt-text
                                    50
                                    4
                                    2
                                    'X'
                                    sl_modact-name
                                    10
                                    6
                                    2
                                    sl_modtext-modtext
                                    25
                                    2
                                    2.

    READ TABLE t_modsap_b INTO sl_modsap
      WITH KEY name = sl_obj_badi-obj_name
      BINARY SEARCH.

    CHECK sy-subrc IS INITIAL.

    READ TABLE t_tftit_b INTO sl_tftit
      WITH KEY funcname = sl_modsap-member
      BINARY SEARCH.

*   Preenche Tabela Hierárquica T_MYLIST
    PERFORM z_preenche_mylist USING text-007
                                    7
                                    1
                                    sl_modsap-member
                                    30
                                    4
                                    7
                                    1
                                    sl_tftit-stext
                                    50
                                    7
                                    2
                                    space
                                    space
                                    space
                                    space
                                    space
                                    space
                                    space
                                    space
                                    space.


    CLEAR sl_obj_badi.

  ENDLOOP.

ENDFORM.                    " Z_MONTA_RELAT

*&---------------------------------------------------------------------*
*&      Form  Z_PREENCHE_MYLIST                                        *
*&---------------------------------------------------------------------*
*                  Preenche Tabela Hierárquica T_MYLIST                *
*----------------------------------------------------------------------*
FORM z_preenche_mylist USING p_name
                             p_color
                             p_intensiv
                             p_text
                             p_tlength
                             p_tlevel
                             p_tcolor
                             p_tintensiv
                             p_text1
                             p_tlength1
                             p_tcolor1
                             p_tintensiv1
                             p_badi
                             p_text2
                             p_tlength2
                             p_tcolor2
                             p_tintensiv2
                             p_text3
                             p_tlength3
                             p_tcolor3
                             p_tintensiv3.

  DATA sl_mylist TYPE snodetext.

  sl_mylist-name       = p_name.
  sl_mylist-color      = p_color.
  sl_mylist-intensiv   = p_intensiv.
  sl_mylist-text       = p_text.
  sl_mylist-tlength    = p_tlength.
  sl_mylist-tlevel     = p_tlevel.
  sl_mylist-tcolor     = p_tcolor.
  sl_mylist-tintensiv  = p_tintensiv.
  sl_mylist-text1      = p_text1.
  sl_mylist-tlength1   = p_tlength1.
  sl_mylist-tcolor1    = p_tcolor1.
  sl_mylist-tintensiv1 = p_tintensiv1.

  IF NOT p_badi IS INITIAL.
    sl_mylist-text2      = p_text2.
    sl_mylist-tlength2   = p_tlength2.
    sl_mylist-tcolor2    = p_tcolor2.
    sl_mylist-tintensiv2 = p_tintensiv2.
    IF NOT p_text3 IS INITIAL.
      sl_mylist-text3      = p_text3.
      sl_mylist-tlength3   = p_tlength3.
      sl_mylist-tcolor3    = p_tcolor3.
      sl_mylist-tintensiv3 = p_tintensiv3.
    ENDIF.
  ENDIF.

  APPEND sl_mylist TO t_mylist.

ENDFORM.                    " Z_PREENCHE_MYLIST

*&---------------------------------------------------------------------*
*&      Form  Z_MONTA_TREE                                             *
*&---------------------------------------------------------------------*
*                             Monta ALV TREE                           *
*----------------------------------------------------------------------*
FORM z_monta_tree.

  CHECK NOT t_mylist[] IS INITIAL.

  SET PF-STATUS 'MAIN'.

  CALL FUNCTION 'RS_TREE_CONSTRUCT'
    TABLES
      nodetab            = t_mylist
    EXCEPTIONS
      tree_failure       = 1
      id_not_found       = 2
      wrong_relationship = 3
      OTHERS             = 4.

  IF NOT sy-subrc IS INITIAL.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

ENDFORM.                    " Z_MONTA_TREE

*&---------------------------------------------------------------------*
*&      Form  Z_MONTA_DRAW                                             *
*&---------------------------------------------------------------------*
*                             Monta DRAW TREE                          *
*----------------------------------------------------------------------*
FORM z_monta_draw.

  CHECK NOT t_mylist[] IS INITIAL.

  CALL FUNCTION 'RS_TREE_LIST_DISPLAY'
    EXPORTING
      callback_program      = sy-repid
      callback_user_command = 'Z_USER_COMMAND'.

ENDFORM.                    " Z_MONTA_DRAW

*&---------------------------------------------------------------------*
*&      Form  z_user_command                                           *
*&---------------------------------------------------------------------*
*                           User Command TREE                          *
*----------------------------------------------------------------------*
FORM z_user_command TABLES nodes STRUCTURE seucomm
                     USING command
                  CHANGING exit
                           list_refresh.

  DATA vl_cursor TYPE char30.

  GET CURSOR FIELD vl_cursor.

  CASE command.
    WHEN 'TRSL'.
      CASE nodes-name.
        WHEN text-005.
          SET PARAMETER ID 'MON' FIELD nodes-text.
          CALL TRANSACTION 'SMOD' AND SKIP FIRST SCREEN.
          exit = space.
        WHEN text-007.
          SET PARAMETER ID 'LIB' FIELD nodes-text.
          CALL TRANSACTION 'SE37'.
          exit = space.
        WHEN text-013.
          IF vl_cursor EQ 'NODELIST-TEXT2'.
            SET PARAMETER ID 'MON_KUN' FIELD nodes-text2.
            CALL TRANSACTION 'CMOD'.
          ELSE.
*           Preenche Mapeamento da Transação SE18
            PERFORM z_preenche_bdc USING nodes-text.
            CALL TRANSACTION 'SE18' USING t_bdcdata MODE 'E'.
          ENDIF.
      ENDCASE.
  ENDCASE.

  list_refresh = 'X'.

ENDFORM.                    "z_user_command

*&---------------------------------------------------------------------*
*&      Form  Z_PREENCHE_BDC                                           *
*&---------------------------------------------------------------------*
*                       Preenche Tabela BDCDATA                        *
*----------------------------------------------------------------------*
FORM z_preenche_bdc USING p_name TYPE c.

  REFRESH t_bdcdata.

  PERFORM z_insere_bdc USING: 'X'    'SAPLSEXO'   '0100'    ,
                              space  'BDC_OKCODE' '=ISSPOT' ,
                              space  'G_IS_BADI'  'X'       ,

                              'X'    'SAPLSEXO'   '0100'    ,
                              space  'BDC_OKCODE' '=SHOW'   ,
                              space  'G_BADINAME' p_name    .

ENDFORM.                    " Z_PREENCHE_BDC

*&---------------------------------------------------------------------*
*&      Form  Z_INSERE_BDC                                             *
*&---------------------------------------------------------------------*
*                         Insere Tabela BDCDATA                        *
*----------------------------------------------------------------------*
FORM z_insere_bdc USING p_tela
                        p_campo
                        p_val.

  DATA sl_bdcdata TYPE bdcdata.

  CASE p_tela.
    WHEN 'X'.
      sl_bdcdata-dynbegin = p_tela.
      sl_bdcdata-program  = p_campo.
      sl_bdcdata-dynpro   = p_val.
    WHEN OTHERS.
      sl_bdcdata-fnam     = p_campo.
      sl_bdcdata-fval     = p_val.
  ENDCASE.

  APPEND sl_bdcdata TO t_bdcdata.

ENDFORM.                    " Z_INSERE_BDC

Arquivos para Download:

z_busca_exit_badi.txt