Report ABAP para visualizar todas las User-Exits Implementadas en entorno R3 (navegable)

Report ABAP para visualizar todas las User-Exits Implementadas en entorno R3 (navegable)

En esta nueva publicación, os presentamos un sencillo código ABAP para revisar todas las User-Exit clásicas implementadas en un entorno R3. La idea del programa es listar de manera práctica los proyectos implementados, tener una visión de su estado de activación y facilitar la navegación a SMOD, CMOD e Módulos de funciones implementados.

El resultado mostrado por pantalla seria:

Los textos a cargar en el programa:

  • Símbolos de Texto:
    • 001 No se han seleccionado datos
    • T01 Datos Generales
  • Textos de Selección:
    • S_MODAC2 Proyecto de cliente
    • S_MODACT Proyecto estándar

A continuación el código fuente:

*&---------------------------------------------------------------------*
*& Report  ZBC_LIST_UE
*&
*&---------------------------------------------------------------------*
*& Lista de User exits implementadas:
*& Estado + Componentes que implementan.
*&
*&---------------------------------------------------------------------*
REPORT zbc_list_ue.

*&---------------------------------------------------------------------*
*&  Report Global types.
*&---------------------------------------------------------------------*

TYPES: rcode(5),

       BEGIN OF s_function,
         fname LIKE mod0-funcname,
         ftext LIKE tftit-stext,
         impl,
         active,
         example,
       END OF s_function,

       BEGIN OF s_cua,
         p_name LIKE mod0-cuaprog,
         fcode  TYPE gui_code,
         impl,
         active,
       END OF s_cua,

       BEGIN OF s_screen,
         g_name  LIKE mod0-gdynprog,
         g_dynnr LIKE mod0-gdynnr,
         bername LIKE mod0-bername,
         c_name  LIKE mod0-cdynprog,
         c_dynnr LIKE mod0-cdynnr,
         text    LIKE mod0-stext,
         impl,
         active,
       END OF s_screen,

       BEGIN OF s_table,
         tname TYPE itabname,
         impl,
         active,
       END OF s_table,

       BEGIN OF ty_output,
         status   TYPE text20,
         name     TYPE cmodname,
         modtextz TYPE modtext-modtext,
         member   TYPE modmember,
         modtext  TYPE modsapt-modtext,
         impl     TYPE icon_d,
         active   TYPE icon_d,
         fname    LIKE mod0-funcname,
         ftext    LIKE tftit-stext,
         p_name   LIKE mod0-cuaprog,
         fcode    TYPE gui_code,
         tname    TYPE itabname,
         g_name   LIKE mod0-gdynprog,
         g_dynnr  LIKE mod0-gdynnr,
         bername  LIKE mod0-bername,
         c_name   LIKE mod0-cdynprog,
         c_dynnr  LIKE mod0-cdynnr,
         text     LIKE mod0-stext,
       END OF ty_output,

       BEGIN OF exit_members,
         name      TYPE modname,
         text      LIKE mod0-memtext,
         functions TYPE s_function OCCURS 0,
         fcodes    TYPE s_cua      OCCURS 0,
         screens   TYPE s_screen   OCCURS 0,
         tables    TYPE s_table    OCCURS 0,
         status    LIKE modattr-status,
       END OF exit_members.

*&---------------------------------------------------------------------*
*&  Report Global Data
*&---------------------------------------------------------------------*

CLASS LCL_EVENT_HANDLER DEFINITION DEFERRED.

TABLES mod0.
DATA: GO_HANDLER TYPE REF TO LCL_EVENT_HANDLER.
DATA: gt_output  TYPE STANDARD TABLE OF ty_output.

*&---------------------------------------------------------------------*
*&  Macros
*&---------------------------------------------------------------------*
DEFINE add_sort.
  lo_sort->add_sort(
    EXPORTING
      columnname = &1
      subtotal   = if_salv_c_bool_sap=>true ).
END-OF-DEFINITION.

*&---------------------------------------------------------------------*
*& Pantalla de selección.
*&---------------------------------------------------------------------*

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-t01.

SELECT-OPTIONS:  s_modact  FOR mod0-name.
SELECT-OPTIONS:  s_modac2  FOR mod0-name.

SELECTION-SCREEN END OF BLOCK b1.

*&---------------------------------------------------------------------*
*& Matchcodes.
*&---------------------------------------------------------------------*

AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_modact-low.
  PERFORM f_f4_val_req_exit USING 'P' s_modact-low.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_modact-high.
  PERFORM f_f4_val_req_exit USING 'P' s_modact-high.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_modac2-low.
  PERFORM f_f4_val_req_exit USING space s_modac2-low.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_modac2-high.
  PERFORM f_f4_val_req_exit USING space s_modac2-high.

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

  PERFORM f_data_selection_mapping.
  CHECK gt_output IS NOT INITIAL.
  PERFORM f_alv_show.


*&---------------------------------------------------------------------*
*& local class definition and implementation.
*&---------------------------------------------------------------------*

CLASS lcl_event_handler DEFINITION.

  PUBLIC SECTION.
    METHODS:
        on_link_click
          FOR EVENT link_click OF cl_salv_events_table
            IMPORTING
              row
              column  .
ENDCLASS.

CLASS lcl_event_handler IMPLEMENTATION.
  METHOD on_link_click.

    DATA ls_output TYPE ty_output.

*   Get the Sales Order number from the table
    READ TABLE gt_output INTO ls_output INDEX row.

    CASE column.
      WHEN 'NAME'.
        SET PARAMETER ID 'MON_KUN' FIELD ls_output-name.
        CALL TRANSACTION 'CMOD' AND SKIP FIRST SCREEN.
      WHEN 'MEMBER'. CHECK ls_output-member IS NOT INITIAL.
        SET PARAMETER ID 'MON' FIELD ls_output-member.
        CALL TRANSACTION 'SMOD' AND SKIP FIRST SCREEN.
      WHEN 'FNAME'.  CHECK ls_output-FNAME IS NOT INITIAL.
        SET PARAMETER ID 'LIB' FIELD ls_output-FNAME.
        CALL TRANSACTION 'SE37' AND SKIP FIRST SCREEN.
    ENDCASE.

  ENDMETHOD.                    "on_link_click
ENDCLASS.
*&---------------------------------------------------------------------*
*& FORMS DEFINITION
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& FORM F_DATA_SELECTION_MAPPING*
*&---------------------------------------------------------------------*
FORM f_data_selection_mapping.

  DATA:
        lt_modact   TYPE STANDARD TABLE OF modact,
        lt_modattr  TYPE STANDARD TABLE OF modattr,
        lt_modsapt  TYPE STANDARD TABLE OF modsapt,
        lt_modtext  TYPE STANDARD TABLE OF modtext,
        ls_exit     TYPE exit_members,
        ls_modact   TYPE modact,
        ls_modtext  TYPE modtext,
        ls_modsapt  TYPE modsapt,
        ls_modattr  TYPE modattr,
        ls_output   TYPE ty_output,
        ls_output2  TYPE ty_output,
        lv_rcode    TYPE rcode,
        lv_name     TYPE modname,
        lv_function TYPE s_function,
        lv_fcode    TYPE s_cua,
        lv_screen   TYPE s_screen,
        lv_table    TYPE s_table,
        lv_stext    TYPE tftit-stext.

  FIELD-SYMBOLS:  <ls_output>   TYPE ty_output.

  SELECT * FROM modact INTO TABLE lt_modact WHERE name    IN s_modact
                                              AND member  IN s_modac2.
  IF sy-subrc = 0.

    SELECT * FROM modattr INTO TABLE lt_modattr.
    SELECT * FROM modsapt INTO TABLE lt_modsapt WHERE sprsl = sy-langu.
    SELECT * FROM modtext INTO TABLE lt_modtext WHERE sprsl = sy-langu.
    SORT lt_modtext BY name.
    SORT lt_modsapt BY name.
    SORT lt_modattr BY name.

    LOOP AT lt_modact INTO ls_modact.

      CLEAR ls_output.
      MOVE-CORRESPONDING ls_modact TO ls_output.

      READ TABLE lt_modattr INTO ls_modattr WITH KEY name = ls_output-name BINARY SEARCH.
      IF sy-subrc = 0 AND ls_modattr-status = 'A'.
        ls_output-status = 'Activa'.
      ELSE.
        ls_output-status = 'Inactiva'.
      ENDIF.

      READ TABLE lt_modsapt  INTO ls_modsapt  WITH KEY name = ls_output-member BINARY SEARCH.
      IF sy-subrc = 0.
        ls_output-modtext = ls_modsapt-modtext.
      ENDIF.
      READ TABLE lt_modtext  INTO ls_modtext  WITH KEY name = ls_output-name BINARY SEARCH.
      IF sy-subrc = 0.
        ls_output-modtextz = ls_modtext-modtext.
      ENDIF.

      lv_name = ls_output-member.

      APPEND ls_output TO gt_output.

      CLEAR ls_exit.
      PERFORM get_exit_members(saplsmod) USING  lv_name CHANGING  ls_exit lv_rcode.

      LOOP AT ls_exit-functions INTO  lv_function.
        CLEAR ls_output2.
        ls_output2 = ls_output.
        MOVE-CORRESPONDING lv_function TO ls_output2.

        SELECT SINGLE stext INTO lv_stext
          FROM tftit
          WHERE funcname = lv_function-fname
            AND spras    = sy-langu.
        IF sy-subrc = 0.
          ls_output2-ftext =  lv_stext.
        ENDIF.

        APPEND ls_output2 TO gt_output.
      ENDLOOP.
      LOOP AT ls_exit-fcodes INTO  lv_fcode.
        CLEAR ls_output2.
        ls_output2 = ls_output.
        MOVE-CORRESPONDING lv_fcode TO ls_output2.
        APPEND ls_output2 TO gt_output.
      ENDLOOP.
      LOOP AT ls_exit-screens INTO  lv_screen.
        CLEAR ls_output2.
        ls_output2 = ls_output.
        MOVE-CORRESPONDING lv_screen TO ls_output2.
        APPEND ls_output2 TO gt_output.
      ENDLOOP.
      LOOP AT ls_exit-tables INTO  lv_table.
        CLEAR ls_output2.
        ls_output2 = ls_output.
        MOVE-CORRESPONDING lv_table TO ls_output2.
        APPEND ls_output2 TO gt_output.
      ENDLOOP.

    ENDLOOP.

    LOOP AT gt_output ASSIGNING <ls_output>.
      IF  <ls_output>-impl = abap_true.
        <ls_output>-impl =  icon_checked.
      ENDIF.
      IF <ls_output>-active  = abap_true.
        <ls_output>-active  =  icon_checked.
      ENDIF.
    ENDLOOP.

  ELSE.

    MESSAGE 'No se han seleccionado datos'(001) TYPE 'I'.

  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM F_F4_val_req_exit*
*&---------------------------------------------------------------------*
FORM f_f4_val_req_exit USING objtype TYPE c CHANGING name.

  DATA: lv_modname   TYPE modname,
        lt_dynfields LIKE dynpread OCCURS 1 WITH HEADER LINE,
        lv_funcname  TYPE rs38l_fnam.

  IF objtype = 'P'.
    lv_funcname = 'F4_CUSTOMER_PROJECT'.
  ELSE.
    lv_funcname = 'F4_CUSTOMER_EXIT'.
  ENDIF.

  lt_dynfields-fieldname = 'MOD0-NAME'.
  APPEND lt_dynfields.

  CALL FUNCTION 'DYNP_VALUES_READ'
    EXPORTING
      dyname     = 'SAPMSMOD'
      dynumb     = sy-dynnr
    TABLES
      dynpfields = lt_dynfields
    EXCEPTIONS
      OTHERS     = 0.
  READ TABLE lt_dynfields INDEX 1.

  lv_modname = lt_dynfields-fieldvalue.

  CALL FUNCTION lv_funcname
    EXPORTING
      object             = lv_modname
      suppress_selection = space
      display_only       = space
    IMPORTING
      result             = lv_modname.
  name = lv_modname.
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM F_ALV_SHOW "Creación del ALV
*&---------------------------------------------------------------------*
FORM f_alv_show.

  DATA: lo_table          TYPE REF TO cl_salv_table.
  DATA: lo_functions_list TYPE REF TO cl_salv_functions_list.
  DATA: lo_columns        TYPE REF TO cl_salv_columns_table.
  DATA: lo_column         TYPE REF TO cl_salv_column_table.
  DATA: lo_layout         TYPE REF TO cl_salv_layout.
  DATA: ls_key            TYPE salv_s_layout_key.
  DATA: lo_selection      TYPE REF TO cl_salv_selections.
  DATA: lo_sort           TYPE REF TO cl_salv_sorts.
  DATA: lo_events         TYPE REF TO cl_salv_events_table.



  TRY.
      cl_salv_table=>factory( IMPORTING r_salv_table = lo_table
                              CHANGING  t_table      = gt_output ).

*     habilitamos funciones std. del ALV
      lo_functions_list = lo_table->get_functions( ).
      lo_functions_list->set_all( abap_true ).

*     Modificación de las propiedades de los campos de salida y del layout.
      lo_columns = lo_table->get_columns( ).
      lo_columns->set_optimize( abap_true ).
      lo_column  ?= lo_columns->get_column( 'NAME' ).
      lo_column->set_cell_type( if_salv_c_cell_type=>hotspot ).
      lo_column  ?= lo_columns->get_column( 'MEMBER' ).
      lo_column->set_cell_type( if_salv_c_cell_type=>hotspot ).
      lo_column  ?= lo_columns->get_column( 'FNAME' ).
      lo_column->set_cell_type( if_salv_c_cell_type=>hotspot ).
      lo_column  ?= lo_columns->get_column( 'STATUS' ).
      lo_column->set_long_text( 'Estado' ).
      lo_column->set_medium_text( 'Estado' ).
      lo_column->set_short_text( 'Estado' ).
      lo_column  ?= lo_columns->get_column( 'MODTEXT' ).
      lo_column->set_long_text( 'Descripción' ).
      lo_column->set_medium_text( 'Descripción' ).
      lo_column->set_short_text( 'Descr.' ).
      lo_column  ?= lo_columns->get_column( 'MODTEXTZ' ).
      lo_column->set_long_text( 'Descripción' ).
      lo_column->set_medium_text( 'Descripción' ).
      lo_column->set_short_text( 'Descr.' ).
      lo_column  ?= lo_columns->get_column( 'ACTIVE' ).
      lo_column->set_long_text( 'Activo' ).
      lo_column->set_medium_text( 'Activo' ).
      lo_column->set_short_text( 'Act.' ).
      lo_column->set_icon( if_salv_c_bool_sap=>true ).
      lo_column  ?= lo_columns->get_column( 'IMPL' ).
      lo_column->set_long_text( 'Implementado' ).
      lo_column->set_medium_text( 'Implementado' ).
      lo_column->set_short_text( 'Imp.' ).
      lo_column->set_icon( if_salv_c_bool_sap=>true ).

*     Layout.
      lo_layout = lo_table->get_layout( ).
      ls_key-report = sy-repid.
      lo_layout->set_key( ls_key ).
      lo_layout->set_save_restriction( cl_salv_layout=>restrict_none ).
*      lo_layout->set_initial_layout( p_vari )."Fijar layaout para el ALV
      lo_sort = lo_table->get_sorts( ).

*     Añadimos ordenaciones por defecto.
      add_sort:  'STATUS', 'NAME', 'MODTEXTZ', 'MEMBER', 'MODTEXT'.

*     all events
      lo_events = lo_table->get_event( ).

*     event handler
      CREATE OBJECT go_handler.
      SET HANDLER go_handler->on_link_click FOR lo_events.
*     Show ALV
      lo_table->display( ).


    CATCH cx_salv_msg.
      MESSAGE e001(zmm_apps).
    CATCH cx_salv_not_found .
      MESSAGE e001(zmm_apps).
    CATCH cx_salv_existing .
      MESSAGE e001(zmm_apps).
    CATCH cx_salv_data_error .
      MESSAGE e001(zmm_apps).
  ENDTRY.

ENDFORM.                  " show_alv

 

Facebooktwitterlinkedinmailrss

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *