Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

how to restrict the report execution for 5 times when users run at same time in parallel

Former Member
0 Kudos

Hi,

As apart of performance i need to restrict the one custom report execution for 5 times only when users executed at the same time in parallel.

Any clues............

Regards

Ram

1 ACCEPTED SOLUTION

Private_Member_49934
Contributor
0 Kudos

Intresting..

As Rajesh suggested limit the number of people having authoriztion.
I can think of a work around.

Create a customizing table say with just 2 key feilds

Report name and Lock index .

Say if you want the report to restrict to five user then matintain 5 rows and with same report name and lock index

(01,02,03,04,05).

Check the below code

INITIALIZATION.
  DATA : v_key TYPE rstable-varkey,
         v_flag_ok TYPE char1.
*zconfig has keys mandt repname lockindex.
  SELECT * FROM zconfig
    INTO TABLE it_zconfig WHERE repname = sy-repid.
  IF sy-subrc = 0.
    LOOP AT it_zconfig ASSIGNING <fs_zconfig>.

      CONCATENATE  <fs_zconfig>-mandt <fs_zconfig>-repname <fs_zconfig>-lockindex
      INTO  v_key.
      CALL FUNCTION 'ENQUEUE_E_TABLE'
       EXPORTING
*     MODE_RSTABLE         = 'E'
         tabname              = zconfig
         varkey               = v_key
*     X_TABNAME            = ' '
*     X_VARKEY             = ' '
*     _SCOPE               = '2'
*     _WAIT                = ' '
*     _COLLECT             = ' '
       EXCEPTIONS
         foreign_lock         = 1
         system_failure       = 2
         OTHERS               = 3
                .
      IF sy-subrc <> 0.
        CLEAR V_CONFIG.
        CONTINUE.
      ELSE.
        v_flag_ok = 'X'.
        EXIT.
      ENDIF.
    ENDLOOP.
    IF v_flag_ok IS INITIAL.

      MESSAGE 'Max no. of user reached! cannot run report ' TYPE 'E'.
    ENDIF.

  ENDIF.

8 REPLIES 8

Former Member
0 Kudos

Hi,

Ask basis person to create authorization for that report, and give permission to specific users only.....

It might help you....

Go to the below link....

http://scn.sap.com/thread/1909186

regards,

Rajesh Sadula.

raymond_giuseppi
Active Contributor
0 Kudos

You could use a lock object, at start of execution try to enqueue the object with 5 different values (from key = value 1 to value 5) until success or reject with error, perform a commit, rollback or dequeue at end of report.

Regards,

Raymond

Private_Member_49934
Contributor
0 Kudos

Intresting..

As Rajesh suggested limit the number of people having authoriztion.
I can think of a work around.

Create a customizing table say with just 2 key feilds

Report name and Lock index .

Say if you want the report to restrict to five user then matintain 5 rows and with same report name and lock index

(01,02,03,04,05).

Check the below code

INITIALIZATION.
  DATA : v_key TYPE rstable-varkey,
         v_flag_ok TYPE char1.
*zconfig has keys mandt repname lockindex.
  SELECT * FROM zconfig
    INTO TABLE it_zconfig WHERE repname = sy-repid.
  IF sy-subrc = 0.
    LOOP AT it_zconfig ASSIGNING <fs_zconfig>.

      CONCATENATE  <fs_zconfig>-mandt <fs_zconfig>-repname <fs_zconfig>-lockindex
      INTO  v_key.
      CALL FUNCTION 'ENQUEUE_E_TABLE'
       EXPORTING
*     MODE_RSTABLE         = 'E'
         tabname              = zconfig
         varkey               = v_key
*     X_TABNAME            = ' '
*     X_VARKEY             = ' '
*     _SCOPE               = '2'
*     _WAIT                = ' '
*     _COLLECT             = ' '
       EXCEPTIONS
         foreign_lock         = 1
         system_failure       = 2
         OTHERS               = 3
                .
      IF sy-subrc <> 0.
        CLEAR V_CONFIG.
        CONTINUE.
      ELSE.
        v_flag_ok = 'X'.
        EXIT.
      ENDIF.
    ENDLOOP.
    IF v_flag_ok IS INITIAL.

      MESSAGE 'Max no. of user reached! cannot run report ' TYPE 'E'.
    ENDIF.

  ENDIF.

Former Member
0 Kudos

Hi,

I would rather play with an IMPORT/EXPORT..FROM/TO DATABASE indx(xy) at start and end of your program... you could import the current running number of programs with IMPORT statement at initialization event and increase it by one, and the reverse operation at the end with an EXPORT.

No need to create ddic object here.

Cheers,

Manu.

Former Member
0 Kudos

The trouble with using any sort of persistent objects to hold the entries is that they could persist after the program finishes (if it terminates abnormally say).

Lock objects are normally used for this requirement.

Rob

0 Kudos

Hello Ram,

There is no need to create a custom table. And as Rob has already highlighted what problems the custom table data might pose - what if your program terminates & the table entries are not cleared?

You can build you solution using Lock objects without the need to store any persistent data.

  • Create a structure which looks like the one below:

  • Create a  lock object based on this structure

    

  • Use the following code to restrict the number of sessions to 5:

  START-OF-SELECTION.

  DATA: gt_enq_list TYPE STANDARD TABLE OF seqg3 INITIAL SIZE 0,
        gv_count    TYPE i,
        gv_arg      TYPE eqegraarg.

  gv_arg = sy-repid. "Argument of the report

* Check the no. of lock entries
  CALL FUNCTION 'ENQUEUE_READ'
    EXPORTING
      gname                 = 'ZRESTRICTREPORT'
      garg                  = gv_arg
      GUNAME                = '*'
    IMPORTING
      number                = gv_count
    TABLES
      enq                   = gt_enq_list
    EXCEPTIONS
      communication_failure = 1
      system_failure        = 2
      OTHERS                = 3.
  IF sy-subrc = 0 AND gv_count > 5.
    MESSAGE 'Maxm. number of users running the report' TYPE 'E'.
  ENDIF.

* Set the lock on the report execution
  CALL FUNCTION 'ENQUEUE_EZRESTRICTREP'
    EXPORTING
      report         = sy-repid
      _scope         = '1'
    EXCEPTIONS
      foreign_lock   = 1
      system_failure = 2
      OTHERS         = 3.
  IF sy-subrc <> 0.
*    Error handling
  ENDIF.

END-OF-SELECTION.

* Release the lock after the execution is complete
  CALL FUNCTION 'DEQUEUE_EZRESTRICTREP'
    EXPORTING
      report = sy-repid
      _scope = '1'.

So even if your program terminates, the lock object will be enqueued & the lock counter will be reduced by 1!

Hope i'm clear.

BR,

Suhas

0 Kudos

So even with the new SCN, a lot of the old problems remain.

Rob

naimesh_patel
Active Contributor
0 Kudos

I know I am late to reply, but this could be another solution of your problem:

  • Get the Work Processes list using the FM TH_GET_WPINFO
  • Check if your program is being running in multiple WPs - read table WPLIST with key WP_REPORT = your_report_name
  • If exceeds the limit, give the message and exit the program execution.

Regards,
Naimesh Patel