ST03N – A custom solution
Hi all.
This is a simple program I developed years ago to show Users’s activity on programs and transactions.
It’s a simpler solution, to use instead of ST03N standard. (Nugg file attached if you need)
To implement the solution, you’ll have to create a custom DYNPRO 100.
Create a structure named ZWORKLOAD with these fields:
MANDT | MANDT | CLNT | 3 |
PERIOD | SPMON | NUMC | 6 |
ACCOUNT | ZWKACCOUNT | CHAR | 12 |
NMACCOUNT | ZWKNMACC | CHAR | 80 |
ZTCODE | ZSWLTCODE | CHAR | 40 |
DDTEXT | ZWKDTEXT | CHAR | 70 |
TYPELEM | ZTYPELEM | CHAR | 1 |
ZLNCHT | ZWKZLNCHT | CHAR | 10 |
ZREPNM | ZWKDREPBN | CHAR | 40 |
ZDESREPNM | ZWKDESREPNM | CHAR | 70 |
DEVCLASS | ZWKCLASS | CHAR | 30 |
DESCLASS | ZWKDESCL | CHAR | 80 |
COMPID | ZWKCOMPID | CHAR | 24 |
CNAM | ZWKCNAM | CHAR | 12 |
CDAT | ZWKCDAT | DATS | 8 |
CNAMOD | ZWKCNAMOD | CHAR | 12 |
CDATMOD | ZWKCDATMOD | DATS | 8 |
DESTASKTYPE | ZWKTSKTYP | CHAR | 16 |
ZSTEPS | ZWKSTEPS | INT4 | 10 |
*&---------------------------------------------------------------------*
*& Report Z_ST03N
*&
*&---------------------------------------------------------------------*
*& Statistic report and transaction consume
*&
*&---------------------------------------------------------------------*
REPORT Z_ST03N.
* Table Declaration
TABLES: ZWORKLOAD, V_USR_NAME, TSTCP, TRDIRT, TSTCT,
TADIR, TDEVC, DF14L, TSTC, TRDIR, TDEVCT.
* Global data
*DATA: t_output TYPE TABLE OF SWNCAGGUSERTCODE, "SWNCHITLIST, ""Final output table
DATA: t_work TYPE TABLE OF SWNCAGGUSERTCODE "SWNCHITLIST
WITH HEADER LINE, "Tabella temporanea
t_dirmoni TYPE TABLE OF SWNCMONIKEY
WITH HEADER LINE. "Workload component
DATA: t_output TYPE TABLE OF ZWORKLOAD WITH HEADER LINE.
DATA: itsktp TYPE SWNCTASKTYPERAW.
DATA: BEGIN OF t_elcod OCCURS 0,
ztcode TYPE ZWORKLOAD-ztcode,
END OF t_elcod.
DATA: BEGIN OF it_tstcp OCCURS 0,
tcode TYPE tstcp-tcode,
zrepnm TYPE ZWORKLOAD-zrepnm,
zdesrepnm TYPE ZWORKLOAD-zdesrepnm,
END OF it_tstcp.
CONSTANTS: ZNAMESTRUC TYPE DD02L-TABNAME VALUE 'ZWORKLOAD'.
*-----------------------------------------------------------------------
* ALV specific Declarations...........................................
*-----------------------------------------------------------------------
* ALV specific Internal table declarations.............................
DATA: i_field_cat TYPE lvc_t_fcat, " Field catalogue
i_alv_sort TYPE lvc_t_sort. " Sort table
* ALV variables........................................................
DATA: w_alv_layout TYPE lvc_s_layo, " ALV Layout
w_alv_save TYPE c, " ALV save
w_alv_variant TYPE disvariant. " ALV Variant
* Selection parameters
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-t01.
SELECT-OPTIONS: s_period FOR ZWORKLOAD-PERIOD DEFAULT sy-datum,
s_tcode FOR ZWORKLOAD-ZTCODE,
s_user FOR ZWORKLOAD-ACCOUNT,
s_reptr FOR ZWORKLOAD-TYPELEM.
SELECTION-SCREEN END OF BLOCK b1.
* ALV Class definitions................................................
*-----------------------------------------------------------------------
CLASS lcl_event_handler DEFINITION.
*-----------------------------------------------------------------------
PUBLIC SECTION.
METHODS:
handle_double_click FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row e_column,
handle_hotspot FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING e_row_id e_column_id.
ENDCLASS. " CLASS LCL_EVENT_HANDLER DEF..
* ALV Class implementation............................................
* In the Event of a Double Click drill down to the corresponding CHANGE REQUEST
*-----------------------------------------------------------------------
CLASS lcl_event_handler IMPLEMENTATION.
*-----------------------------------------------------------------------
METHOD handle_double_click.
ENDMETHOD. " HANDLE_DOUBLE_CLICK
* not working yet - hotspot seems to stay in the gui!!
METHOD handle_hotspot.
ENDMETHOD. " HANDLE_DOUBLE_CLICK
ENDCLASS. " CLASS LCL_EVENT_HANDLER IMPL...
* ALV Grid Control definitions........................................
DATA:
* ALV Grid Control itself
o_grid TYPE REF TO cl_gui_alv_grid,
* Container to hold the ALV Grid Control
o_custom_container TYPE REF TO cl_gui_custom_container,
* Event handler (defined in the class above)
o_event_handler TYPE REF TO lcl_event_handler.
*&----------------------------------------------------------------------*
INITIALIZATION.
*&----------------------------------------------------------------------*
PERFORM create_field_catalogue USING ZNAMESTRUC
CHANGING i_field_cat. " Create ALV Field Catalog
START-OF-SELECTION.
* Carica dati di output
PERFORM get_data_workload.
IF NOT t_output[] IS INITIAL.
PERFORM list_output_to_alv. " Perform ALV Output operations
ENDIF.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
* FORM LIST_OUTPUT_TO_ALV *
*----------------------------------------------------------------------*
* This subroutine is used to call the screen for ALV Output. *
*----------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine. *
*----------------------------------------------------------------------*
FORM list_output_to_alv.
CALL SCREEN 100.
*
ENDFORM. " LIST_OUTPUT_TO_ALV
*----------------------------------------------------------------------*
* Module STATUS_0100 OUTPUT *
*----------------------------------------------------------------------*
* This is the PBO module which will be processed befor displaying the *
* ALV Output. *
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS '0100'. " PF Status for ALV Output Screen
SET TITLEBAR 'STD'.
CREATE OBJECT: o_grid
EXPORTING i_parent = cl_gui_container=>screen0. "o_custom_container.
PERFORM define_alv_layout. " ALV Layout options definitions
PERFORM save_alv_layout_options. " save ALV layout options
PERFORM call_alv_grid. " Call ALV Grid Control
ENDMODULE. " STATUS_0100 OUTPUT
*----------------------------------------------------------------------*
* Module USER_COMMAND_0100 INPUT *
*----------------------------------------------------------------------*
* This is the PAI module which will be processed when the user performs*
* any operation from the ALV output. *
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN 'EXIT' OR 'BACK' OR 'CANC'.
* may need to do this so display is refreshed if other report selected
* CALL METHOD o_custom_container->free.
SET SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*----------------------------------------------------------------------*
* FORM DEFINE_ALV_LAYOUT *
*----------------------------------------------------------------------*
* This subroutine is used to Define the ALV layout. *
*----------------------------------------------------------------------*
FORM define_alv_layout .
* w_alv_layout-numc_total = 'X'. " Numc total line
w_alv_layout-cwidth_opt = 'X'. " Optimal column width
* w_alv_layout-detailinit = 'X'. " Show values that are initial in
" detail list.
w_alv_layout-sel_mode = 'A'. " Column selection mode
w_alv_layout-no_merging = 'X'. " No merging while sorting columns
* w_alv_layout-keyhot = 'X'.
ENDFORM. " DEFINE_ALV_LAYOUT
*----------------------------------------------------------------------*
* FORM SAVE_ALV_LAYOUT_OPTIONS *
*----------------------------------------------------------------------*
* This subroutine is used to Save the ALV layout options. *
*----------------------------------------------------------------------*
FORM save_alv_layout_options.
* See the ALV grid control documentation for full list of options
w_alv_save = 'A'.
w_alv_variant-report = sy-repid.
ENDFORM. " SAVE_ALV_LAYOUT_OPTIONS
*----------------------------------------------------------------------*
* FORM CALL_ALV_GRID *
*----------------------------------------------------------------------*
* This subroutine is used to call ALV Grid control for processing. *
*----------------------------------------------------------------------*
FORM call_alv_grid.
CALL METHOD o_grid->set_table_for_first_display
EXPORTING
is_layout = w_alv_layout
i_save = w_alv_save
is_variant = w_alv_variant
CHANGING
it_outtab = t_output[]
it_sort = i_alv_sort
it_fieldcatalog = i_field_cat.
* Link used Events and Event Handler Methods
CREATE OBJECT o_event_handler.
* Set handler
SET HANDLER o_event_handler->handle_double_click FOR o_grid.
ENDFORM. " CALL_ALV_GRID
*&---------------------------------------------------------------------*
*& Form create_field_catalogue
*&---------------------------------------------------------------------*
* set up field catalogue
*&---------------------------------------------------------------------*
FORM create_field_catalogue USING tb_name LIKE DD02L-TABNAME
CHANGING pt_fieldcat TYPE lvc_t_fcat..
DATA: ls_fcat type lvc_s_fcat.
FIELD-SYMBOLS: <lf1> TYPE lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = tb_name
CHANGING
ct_fieldcat = pt_fieldcat[]
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Exceptions handling
ENDIF.
LOOP AT pt_fieldcat ASSIGNING <lf1>.
CASE <lf1>-fieldname.
* WHEN 'TERMINALID'.
* <lf1>-SCRTEXT_S = text-f01.
* <lf1>-SCRTEXT_M = text-f01.
* <lf1>-SCRTEXT_L = text-f01.
* WHEN 'TCODE'.
* <lf1>-SCRTEXT_S = text-f02.
* <lf1>-SCRTEXT_M = text-f02.
* <lf1>-SCRTEXT_L = text-f02.
WHEN OTHERS.
<lf1>-KEY = 'X'.
ENDCASE.
ENDLOOP.
ENDFORM. " create_field_catalogue
*&---------------------------------------------------------------------*
*& Form get_data_workload
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get_data_workload.
DATA: i_valido TYPE c.
DATA: i_entry(40),
i_account TYPE ZWORKLOAD-account.
TYPES: BEGIN OF t_steps,
period TYPE ZWORKLOAD-period,
account TYPE ZWORKLOAD-account,
entry_id(40),
count TYPE ZWORKLOAD-zsteps,
END OF t_steps.
DATA: it_steps TYPE HASHED TABLE OF t_steps WITH UNIQUE KEY period account entry_id.
DATA: h_steps TYPE t_steps.
REFRESH: t_dirmoni, t_output, it_steps, it_tstcp, t_elcod.
* Lettura carichi di lavoro
CALL FUNCTION 'SWNC_COLLECTOR_GET_DIRECTORY'
EXPORTING
GET_DIR_FROM_CLUSTER = ' '
EXCLUDE_SUMMARY = ' '
TABLES
DIRECTORY_KEYS = t_dirmoni
EXCEPTIONS
NO_DATA_FOUND = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
ENDIF.
" Application servers WORKLOAD
* with month registration period
LOOP AT t_dirmoni WHERE COMPONENT NE 'TOTAL' OR
PERIODTYPE NE 'M'.
DELETE t_dirmoni.
ENDLOOP.
LOOP AT t_dirmoni.
REFRESH t_work.
" Read aggregated activity
CHECK t_dirmoni-periodstrt(6) IN s_period.
CALL FUNCTION 'SWNC_COLLECTOR_GET_AGGREGATES'
EXPORTING
component = t_dirmoni-COMPONENT
periodtype = t_dirmoni-PERIODTYPE
periodstrt = t_dirmoni-PERIODSTRT
TABLES
USERTCODE = t_work
* HITLIST_DATABASE = t_work
EXCEPTIONS
no_data_found = 1
OTHERS = 2.
SORT t_work BY account entry_id.
CLEAR: i_entry, i_account.
LOOP AT t_work.
* Step Counter for each report/transaction
CLEAR h_steps.
MOVE t_work-account TO h_steps-account.
MOVE t_work-entry_id(40) TO h_steps-entry_id.
MOVE t_dirmoni-periodstrt(6) TO h_steps-period.
MOVE t_work-count TO h_steps-count. "numero di steps
READ TABLE it_steps WITH KEY account = h_steps-account
entry_id = h_steps-entry_id
period = h_steps-period
TRANSPORTING NO FIELDS.
IF sy-subrc EQ 0. "If already exists
" Collect data steps
COLLECT h_steps INTO it_steps.
DELETE t_work.
CONTINUE.
ELSE.
" Collectdata steps
COLLECT h_steps INTO it_steps.
ENDIF.
"Filter to verify selection conditions
CLEAR t_output.
MOVE t_work-account TO t_output-account.
MOVE t_work-entry_id+72(1) TO t_output-typelem.
MOVE t_work-entry_id(40) TO t_output-ztcode. "Save transaction code or report
CONDENSE t_output-ztcode NO-GAPS.
IF NOT t_work-entry_id+40(32) IS INITIAL. "If name defined = JOB
MOVE 'B' TO t_output-zlncht.
ENDIF.
MOVE t_dirmoni-periodstrt(6) TO t_output-period.
MOVE t_work-tasktype TO t_output-destasktype. "To convert
PERFORM verifica_selezioni USING t_output
CHANGING i_valido.
IF i_valido EQ 'X'.
PERFORM add_info CHANGING t_output.
append t_output.
ENDIF.
ENDLOOP.
ENDLOOP.
IF t_output[] IS INITIAL.
MESSAGE i000(fb) WITH text-e01.
ENDIF.
SORT t_output BY period account ztcode zrepnm.
DELETE ADJACENT DUPLICATES FROM t_output COMPARING period account ztcode zrepnm.
LOOP AT t_output.
CLEAR: h_steps.
READ TABLE it_steps INTO h_steps WITH KEY entry_id = t_output-ztcode
period = t_output-period
account = t_output-account.
IF sy-subrc EQ 0.
"Assign step value calculated
t_output-zsteps = h_steps-count.
ENDIF.
IF sy-subrc EQ 0.
MODIFY t_output.
ENDIF.
ENDLOOP.
ENDFORM. "get_data_workload
*&---------------------------------------------------------------------*
*& Form add_info
*&---------------------------------------------------------------------*
* Info details
*----------------------------------------------------------------------*
* -->T_OUTPUT output table
*----------------------------------------------------------------------*
FORM add_info CHANGING t_output TYPE ZWORKLOAD.
DATA: ipgmna TYPE tstc-pgmna,
ifctr_id TYPE tdevc-component.
DATA: iconta TYPE i.
DATA: search_trsn TYPE string.
" Conversion task type description
CLEAR itsktp.
MOVE t_output-destasktype TO itsktp.
CLEAR t_output-destasktype.
CALL METHOD CL_SWNC_COLLECTOR_INFO=>TRANSLATE_TASKTYPE
EXPORTING
TASKTYPERAW = itsktp
RECEIVING
TASKTYPE = t_output-destasktype.
" Set extend name account
CLEAR t_output-NMACCOUNT.
SELECT SINGLE name_text FROM V_USR_NAME INTO t_output-NMACCOUNT
WHERE BNAME eq t_output-account.
IF t_output-typelem EQ 'T'.
****************** DATA on transaction*****************************
CLEAR t_output-DDTEXT.
SELECT SINGLE ttext FROM TSTCT INTO t_output-DDTEXT
WHERE tcode EQ t_output-ztcode AND
sprsl EQ sy-langu.
* Development class
* Component
* Creator
* Creation Data
* Modification author
* Modification date
CLEAR: t_output-devclass.
SELECT SINGLE devclass
FROM TADIR INTO t_output-devclass
WHERE obj_name EQ t_output-ztcode AND
object EQ 'TRAN' AND
pgmid EQ 'R3TR'.
" Search application component
CLEAR: t_output-COMPID, ifctr_id.
IF NOT t_output-devclass IS INITIAL.
SELECT SINGLE component FROM TDEVC INTO ifctr_id
WHERE devclass EQ t_output-devclass.
IF sy-subrc EQ 0.
SELECT SINGLE ps_posid FROM DF14L INTO t_output-COMPID
WHERE fctr_id EQ ifctr_id.
ENDIF.
ENDIF.
CLEAR: ipgmna.
SELECT SINGLE pgmna FROM TSTC INTO ipgmna
WHERE tcode EQ t_output-ztcode.
CLEAR: t_output-cnam, t_output-cdat, t_output-cnamod, t_output-cdatmod.
SELECT SINGLE cnam cdat unam udat
FROM TRDIR INTO (t_output-cnam,t_output-cdat,t_output-cnamod,t_output-cdatmod)
WHERE name EQ ipgmna.
* Development class description
CLEAR t_output-DESCLASS.
SELECT SINGLE ctext FROM TDEVCT INTO t_output-DESCLASS
WHERE devclass EQ t_output-devclass AND
spras EQ sy-langu.
ELSEIF t_output-typelem EQ 'R'.
****************** DATA on REPORT *****************************
* Object description
CLEAR t_output-DDTEXT.
SELECT SINGLE text FROM TRDIRT INTO t_output-DDTEXT
WHERE name EQ t_output-ztcode AND
sprsl EQ sy-langu.
* Development Class
* Component
* Creator
* Creation data
* Modification author
* Modification date
CLEAR: t_output-devclass.
SELECT SINGLE devclass
FROM TADIR INTO t_output-devclass
WHERE obj_name EQ t_output-ztcode AND
object EQ 'PROG' AND
pgmid EQ 'R3TR'.
" Search application component
CLEAR: t_output-COMPID, ifctr_id.
IF NOT t_output-devclass IS INITIAL.
SELECT SINGLE component FROM TDEVC INTO ifctr_id
WHERE devclass EQ t_output-devclass.
IF sy-subrc EQ 0.
SELECT SINGLE ps_posid FROM DF14L INTO t_output-COMPID
WHERE fctr_id EQ ifctr_id.
ENDIF.
ENDIF.
CLEAR: t_output-cnam, t_output-cdat, t_output-cnamod, t_output-cdatmod.
SELECT SINGLE cnam cdat unam udat
FROM TRDIR INTO (t_output-cnam,t_output-cdat,t_output-cnamod,t_output-cdatmod)
WHERE name EQ t_output-ztcode.
* Development class description
CLEAR t_output-DESCLASS.
SELECT SINGLE ctext FROM TDEVCT INTO t_output-DESCLASS
WHERE devclass EQ t_output-devclass AND
spras EQ sy-langu.
* For report search transactions code related
CLEAR: iconta, search_trsn. ", it_tstcp,.
CONCATENATE '%D_SREPOVARI-REPORT=' t_output-ztcode '%' INTO search_trsn.
CONDENSE search_trsn NO-GAPS.
CLEAR: tstcp, t_output-zrepnm, t_output-ZDESREPNM, it_tstcp.
READ TABLE t_elcod WITH KEY ztcode = t_output-ztcode.
CHECK sy-subrc NE 0. ""If object code founded, it's a report with no association
READ TABLE it_tstcp WITH KEY tcode = t_output-ztcode.
IF sy-subrc EQ 0.
t_output-zrepnm = it_tstcp-zrepnm.
t_output-zdesrepnm = it_tstcp-zdesrepnm.
ELSE.
SELECT SINGLE * FROM tstcp WHERE param LIKE search_trsn.
IF sy-subrc EQ 0.
t_output-zrepnm = tstcp-tcode.
CLEAR t_output-ZDESREPNM.
SELECT SINGLE ttext FROM TSTCT INTO t_output-ZDESREPNM
WHERE tcode EQ t_output-zrepnm AND
sprsl EQ sy-langu.
SELECT SINGLE * FROM tstcp WHERE param LIKE search_trsn AND
tcode NE tstcp-tcode.
IF sy-subrc EQ 0.
t_output-zrepnm = text-i01.
t_output-ZDESREPNM = text-i02.
it_tstcp-tcode = t_output-ztcode.
ELSE.
it_tstcp-tcode = tstcp-tcode.
ENDIF.
it_tstcp-zrepnm = t_output-zrepnm.
it_tstcp-zdesrepnm = t_output-zdesrepnm.
APPEND it_tstcp.
ELSE.
t_elcod-ztcode = t_output-ztcode.
APPEND t_elcod.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. "add_info
*&---------------------------------------------------------------------*
*& Form verifica_selezioni
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->F_LINE text
* -->F_VALIDO text
*----------------------------------------------------------------------*
FORM verifica_selezioni USING f_line TYPE ZWORKLOAD "SWNCHITLIST
CHANGING f_valido.
CLEAR f_valido.
* Report or Transaction?
CHECK f_line-typelem IN s_reptr.
* Check report and transaction Filter Selection
CHECK NOT f_line-ztcode IS INITIAL AND f_line-ztcode IN s_tcode.
* Check Username Filter Selection
CHECK NOT f_line-account IS INITIAL AND f_line-account IN s_user.
f_valido = 'X'.
ENDFORM. "verifica_selezioni
That’s all folks. I hope you enjoy.
Probably this utility will be useful, or probably not. It’s all part of the game 🙂
Bye!
Text Definition
E01 | No data available |
F01 | Terminal |
F02 | Transaction |
F03 | User |
F04 | Object name |
I01 | **** |
I02 | Found many transactions |
T01 | Selection parameters |
Hi Roberto,
It would be easier if you could upload the .NUGG files.
BR,
Suhas
Hi Suhas,
thanks I know but I did the ZSAPLINK implementation years ago and it was a pretty waste of time because of the software bugs. Probably because of the starting phase of the project.
Now I suppose it's all functioning well . I'll look forward, someday, thanks.
Bye
SAPLink works perfectly fine for me.
🙂 I'll do it...
That's my old post 🙂
http://forums.sdn.sap.com/thread.jspa?forumID=50&threadID=1822126
Hi Suhas Saha , ... The day was today 😉 Please could you tell me if nugg file here attached is working fine? Thanks
Some issues installing SAPLINK related to versioning.
Nugg file was renamed in TXT for SDN checks on attached file.
Hope it works, thanks!
Hi sir,
Could you please help to describe more for the custom DYNPRO 100?
Thank you so much!
Hi,
sorry for the delay 🙂
In DYNPRO 100 , a standard dynpro, we have two module
PBO with a MODULE status_0100 where we create a grid object to show our data (see blogs on how to create and handle events for alv grid with classes)
PAI with MODULE user_command_0100 where we simply manage the ok-code to exit from the main dynpro.
Nothing else.
Hope to help
Bye