Know Who is doing What in your SAP System

Know Who is doing What in your SAP System

Nowadays miniature administration has become extremely normal. Clients need the breakdown of basically everything you do consistently, some of the time as ludicrous as at t-code level. . I know clients who screen when the project worker last signed into the framework and from which terminal.

Assuming you are that supervisor who is in that undeniable situation where you need to monitor the exercises of certain clients (who are attempting to trick you), this apparatus would be helpful for you. Or the consequences will be severe, in the event that you are only an engineer yet might want to see who performs what movement anytime of time, you can likewise utilize this device.

This is more for scholarly fun instead of having genuine undertaking utilization. No HANA, SAP UI5, OData or Fiori here. Regular old Vanilla ABAP. Thus, unwind and attempt the code for this apparatus in your framework and check what your colleagues and clients do. . You can likewise check in the event that your Group captain/Undertaking Lead at any point sign into their particular SAP framework or are they cheerful getting ready calculation sheet and introductions.

We have given just 4 radio buttons. You can make do upon it and make different stages and mixes.

The heart and brain of this application device is FM ‘TH_LONG_USR_INFO’. The data is returned in structure UINFO2 (Full data on a client).

Lock in, we are moving!!!

a) Let us see what all’s identity is signed into the framework. Only for participation.

See the result beneath. It gives the extraordinary rundown of UserId alongside the name. Terminal (PC/work area) name is likewise given. Is it great data?

b) Let us find in subtleties what t-code each logged client is utilizing. Have they quite recently signed in or would they say they are truly working?

Check Ali has 6 meetings opened and Shrestha has 3 meetings. You likewise get the data about the exchange they are utilizing and the time they last signed into that t-code. Assuming somebody is in the t-code for a really long time, it implies he is inactive or not utilizing that SAP meeting.

c) Let us check what my closest companion is doing in his SAP framework.

The second you click the third radio button, the SAP Client Id component of the screen would be noticeable. The straightforward stow away and show code is composed at introduction (for freshers as it were).

Register Shrestha is logged with two unique clients and opened six distinct meetings. Seems as though he is working a great deal.

d) At long last, let us see who all are playing with a similar t-code at one place of time.

Appears to be three changed clients (ali, man and prescription) in three distinct clients (110, 120, 140) are playing with t-code HRFORMS. HR is consistently well known.

This post is only a breather from all the intensity and commotion from HANA, SAPUI5 and Fiori. All things considered, the typical ABAP has been the bread and butter of all ABAPers till date. It resembles the old propensity which can’t be neglected or left with such ease.

Kindly track down beneath the functioning code for the apparatus. You could have to populate the text components physically in your program. Make the program in your turn of events/test box and be the spy.

*---------------------------------------------------------------------*
* TABLES *
*---------------------------------------------------------------------*
TABLES: tstc, usr21.

*---------------------------------------------------------------------*
* TYPES *
*---------------------------------------------------------------------*
TYPES:
BEGIN OF ty_report,
session TYPE numc4, "usession,
client TYPE mandt,
user TYPE ubname,
name TYPE ad_namtext,
terminal TYPE uterm,
tcode TYPE utcode,
ltime TYPE syst_uzeit,
END OF ty_report.
*---------------------------------------------------------------------*
* DATA *
*---------------------------------------------------------------------*
DATA:
it_output TYPE STANDARD TABLE OF uinfo2,
it_report TYPE STANDARD TABLE OF ty_report.


*---------------------------------------------------------------------*
* SELECTION SCREEN *
*---------------------------------------------------------------------*

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

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(75) text-c01.
PARAMETERS:
r_onl RADIOBUTTON GROUP opt1 DEFAULT 'X' USER-COMMAND aa.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(75) text-c02.
PARAMETERS:
r_det RADIOBUTTON GROUP opt1.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(75) text-c03.
PARAMETERS:
r_usr RADIOBUTTON GROUP opt1.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(75) text-c04.
PARAMETERS:
r_tcd RADIOBUTTON GROUP opt1.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-s02.
SELECT-OPTIONS: s_tcode FOR tstc-tcode NO INTERVALS.
SELECTION-SCREEN END OF BLOCK b2.

SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-s03.
SELECT-OPTIONS: s_user FOR usr21-bname NO INTERVALS.
SELECTION-SCREEN END OF BLOCK b3.

*---------------------------------------------------------------------*
* INITIALIZATION *
*---------------------------------------------------------------------*
INITIALIZATION.
* Restrict user to enter range in t-code and user id
PERFORM restrict_range.

*---------------------------------------------------------------------*
* AT SELECTION-SCREEN OUTPUT. *
*---------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
PERFORM hide_unrelevent_select_options.

*---------------------------------------------------------------------*
* AT SELECTION-SCREEN. *
*---------------------------------------------------------------------*
AT SELECTION-SCREEN.

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

* Get the user/system info
PERFORM get_user_system_info.

*---------------------------------------------------------------------*
* END-OF-SELECTION. *
*---------------------------------------------------------------------*
END-OF-SELECTION.
* Show ALV Report
PERFORM display_report.

*---------------------------------------------------------------------*
* SUB-ROUTINES *
*---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form RESTRICT_RANGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* Restrict range
*----------------------------------------------------------------------*
FORM restrict_range .
CONSTANTS: lc_opt_list TYPE rsrest_opl VALUE 'OPT_LIST',
lc_s TYPE rsscr_kind VALUE 'S',
lc_tcode TYPE blockname VALUE 'S_TCODE',
lc_user TYPE blockname VALUE 'S_USER',
lc_inc TYPE c VALUE 'I'.

DATA: lw_opt_list TYPE sscr_opt_list,
lw_restrict TYPE sscr_restrict,
lw_ass TYPE sscr_ass.

lw_opt_list-name = lc_opt_list.
lw_opt_list-options-bt = space.
lw_opt_list-options-eq = 'X'.
APPEND lw_opt_list TO lw_restrict-opt_list_tab.

lw_ass-kind = lc_s.
lw_ass-name = lc_tcode.
lw_ass-sg_main = lc_inc.
lw_ass-op_main = lc_opt_list.
APPEND lw_ass TO lw_restrict-ass_tab.

lw_ass-kind = lc_s.
lw_ass-name = lc_user.
lw_ass-sg_main = lc_inc.
lw_ass-op_main = lc_opt_list.
APPEND lw_ass TO lw_restrict-ass_tab.

CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'
EXPORTING
restriction = lw_restrict
EXCEPTIONS
too_late = 1
repeated = 2
selopt_without_options = 3
selopt_without_signs = 4
invalid_sign = 5
empty_option_list = 6
invalid_kind = 7
repeated_kind_a = 8
OTHERS = 9.


ENDFORM.
*&---------------------------------------------------------------------*
*& Form HIDE_UNRELEVENT_SELECT_OPTIONS
*&---------------------------------------------------------------------*
* Hide the select options when not needed
*----------------------------------------------------------------------*
FORM hide_unrelevent_select_options .

LOOP AT SCREEN.

* If user radio button is not chosen, hide the user block
IF r_usr IS INITIAL.
CASE screen-name.

WHEN '%B003006_BLOCK_1000'.
screen-active = 0.

WHEN '%_S_USER_%_APP_%-TEXT'.
screen-active = 0.

WHEN '%_S_USER_%_APP_%-OPTI_PUSH'.
screen-active = 0.

WHEN 'S_USER-LOW'.
screen-active = 0.

WHEN '%_S_USER_%_APP_%-VALU_PUSH'.
screen-active = 0.

WHEN OTHERS.

ENDCASE.

ENDIF.
MODIFY SCREEN.

* If t-code radio button is not chosen, hide the t-code block
IF r_tcd IS INITIAL.
CASE screen-name.

WHEN '%B003006_BLOCK_1000'.
screen-active = 0.

WHEN '%_S_TCODE_%_APP_%-TEXT'.
screen-active = 0.

WHEN '%_S_TCODE_%_APP_%-OPTI_PUSH'.
screen-active = 0.

WHEN 'S_TCODE-LOW'.
screen-active = 0.

WHEN '%_S_TCODE_%_APP_%-VALU_PUSH'.
screen-active = 0.

WHEN OTHERS.

ENDCASE.

ENDIF.
MODIFY SCREEN.

ENDLOOP.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form GET_USER_SYSTEM_INFO
*&---------------------------------------------------------------------*
* Get the user and system information
*----------------------------------------------------------------------*
FORM get_user_system_info .

CALL FUNCTION 'TH_LONG_USR_INFO'
EXPORTING
user = '*'
TABLES
user_info = it_output[].
IF it_output[] IS INITIAL.
MESSAGE 'No one has logged into the system' TYPE 'I'.
LEAVE LIST-PROCESSING.

ELSE.
IF r_onl IS NOT INITIAL.

SORT it_output BY user.
DELETE ADJACENT DUPLICATES FROM it_output[] COMPARING user.

ELSEIF r_usr IS NOT INITIAL.

IF s_user IS NOT INITIAL.
DELETE it_output[] WHERE user NOT IN s_user.
ENDIF.

IF it_output[] IS INITIAL.
MESSAGE 'User(s) are not logged into the system' TYPE 'I'.
LEAVE LIST-PROCESSING.
ENDIF.

ELSEIF r_tcd IS NOT INITIAL.
IF s_tcode IS NOT INITIAL.
DELETE it_output[] WHERE tcode NOT IN s_tcode.
ENDIF.

IF it_output[] IS INITIAL.
MESSAGE 'No one is using the input T-Code(s)' TYPE 'I'.
LEAVE LIST-PROCESSING.
ENDIF.

ENDIF.

ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form DISPLAY_REPORT
*&---------------------------------------------------------------------*
* Display the output
*----------------------------------------------------------------------*
FORM display_report .

DATA:
lr_alv TYPE REF TO cl_salv_table,
lr_columns TYPE REF TO cl_salv_columns_table,
lr_column TYPE REF TO cl_salv_column,
lr_functions TYPE REF TO cl_salv_functions_list,
lr_display TYPE REF TO cl_salv_display_settings,
lr_layout TYPE REF TO cl_salv_layout,
ls_key TYPE salv_s_layout_key,
lr_sorts TYPE REF TO cl_salv_sorts.

" Check to make sure the internal table has data.
IF lines( it_output ) > 0.

* Get username
PERFORM get_user_name.

TRY.
* Create ALV instance
* Use CALL METHOD since this is a static method
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = lr_alv
CHANGING
t_table = it_report.

* Get functions object and then set all the functions to be
* allowed
lr_functions = lr_alv->get_functions( ).
lr_functions->set_all( ).

lr_columns = lr_alv->get_columns( ).

CALL METHOD lr_columns->get_column
EXPORTING
columnname = 'LTIME'
RECEIVING
value = lr_column.

CALL METHOD lr_column->set_short_text
EXPORTING
value = ' '.

CALL METHOD lr_column->set_medium_text
EXPORTING
value = ' '.

CALL METHOD lr_column->set_long_text
EXPORTING
value = 'Start Time'.

CALL METHOD lr_columns->get_column
EXPORTING
columnname = 'SESSION'
RECEIVING
value = lr_column.

CALL METHOD lr_column->set_short_text
EXPORTING
value = 'Session'.

lr_columns->set_optimize( ).

* Set sort column
lr_sorts = lr_alv->get_sorts( ).
lr_sorts->clear( ).

* This code is to get the layout, save the layout
* and display the layout
lr_layout = lr_alv->get_layout( ).
ls_key-report = sy-repid.
lr_layout->set_key( ls_key ).
lr_layout->set_default( ' ' ).
lr_layout->set_save_restriction( cl_salv_layout=>restrict_none ).


lr_display = lr_alv->get_display_settings( ).
lr_display->set_striped_pattern( cl_salv_display_settings=>true ).

* Now display the report as an ALV grid
lr_alv->display( ).

CATCH cx_salv_msg.
WRITE: 'Error displaying grid CX_SALV_MSG!'.

CATCH cx_salv_not_found.
WRITE: 'Error displaying grid CX_SALV_NOT_FOUND!'.

CATCH cx_salv_data_error.
WRITE: 'Error displaying grid CX_SALV_DATA_ERROR!'.

CATCH cx_salv_existing.
WRITE: 'Error displaying grid CX_SALV_EXISTING!'.

ENDTRY.

ELSE.
MESSAGE 'No data to display' TYPE 'I'.
LEAVE LIST-PROCESSING.

ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form GET_USER_NAME
*&---------------------------------------------------------------------*
* Get user name and format
*----------------------------------------------------------------------*
FORM get_user_name .

*--------------------------------------------------------------------*
* Prior to ABAP 7.4
* DATA:
* lwa_report type ty_report,
* lit_output TYPE STANDARD TABLE OF uinfo2,
* lit_username TYPE STANDARD TABLE OF v_username.
*
* lit_output[] = it_output[].
*
* SORT lit_output[] BY user.
* DELETE ADJACENT DUPLICATES FROM lit_output[] COMPARING user.
*
* SELECT * FROM v_username INTO TABLE lit_username[]
* FOR ALL ENTRIES IN lit_output
* WHERE bname = lit_output-user.
*
* IF lit_username[] IS NOT INITIAL.
*
* ENDIF.
*--------------------------------------------------------------------*
DATA: lwa_report TYPE ty_report.

* Making use of inline declaration and host variables ABAP 7.4
DATA(lit_output) = it_output[].

SORT lit_output[] BY user.
DELETE ADJACENT DUPLICATES FROM lit_output[] COMPARING user.

* Escape @
SELECT * FROM v_username INTO TABLE @DATA(lit_username)
FOR ALL ENTRIES IN @lit_output
WHERE bname = @lit_output-user.
* Sy-subrc check not needed
SORT lit_username[] BY bname.

LOOP AT it_output INTO DATA(lwa_output).
READ TABLE lit_username INTO DATA(lwa_username)
WITH KEY bname = lwa_output-user
BINARY SEARCH.
IF sy-subrc EQ 0.
lwa_report-name = lwa_username-name_text. " Full name
ENDIF.

MOVE-CORRESPONDING lwa_output TO lwa_report.
WRITE lwa_output-time TO lwa_report-ltime.
APPEND lwa_report TO it_report[].

CLEAR lwa_report.

ENDLOOP.

* Just sort
SORT it_report[] BY session.
ENDFORM.

One of our peruser ‘Bikas’ shared that t-code “AL08” claims exactly the same thing what we attempted with our code piece. On account of Bikas for telling us. For the reference of our perusers, kindly find the screen print of t-code AL08.

sap abap interview questions

This is an ideal instance of advancing by sharing. Nobody can know it all in this world. However, we can share our insight and teach one another.

YOU MAY LIKE THIS

Core Data Services (CDS) in SAP

Virtual Data Model (VDM)

Process automation

SAP AI

WhatsApp WhatsApp us