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 running of report in foreground

Former Member
0 Kudos

My requirement is that, the user should not be allowed to run the report in foreground. Since there is a high possibility for the report to go to time-out.. I want to force the user to run it in background only.. How can we do that ? IS it Basis related or .. can it be done in abap ?

Thanking you..

Shankar

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Use this before you start processing.

start-of-selection.
if sy-batch ne 'X'.
* Give an ERROR message here, if you want, instructing 
* the user to run the report only in the background mode. 
  exit.
endif.

Regards,

Anand Mandalika.

33 REPLIES 33

Former Member
0 Kudos

Hi,

Use this before you start processing.

start-of-selection.
if sy-batch ne 'X'.
* Give an ERROR message here, if you want, instructing 
* the user to run the report only in the background mode. 
  exit.
endif.

Regards,

Anand Mandalika.

0 Kudos

Thats really great . That works. Now, can u tell me how can i give a yes/no prompt message . If the user tries to run the report in foreground, it should tell "This should be run in background only. Do you want to run it in Background ?". If he says "yes" it should go to background running .. or else.. leave list-processing ..Can we do that ?

0 Kudos

Hi Shankara

I believe Anand could exactly answer this but for the sake of being faster, let me tell on this.

IF sy-batch NE 'X' .
*--Here you can use the FM "POPUP_TO_CONFIRM_WITH_MESSAGE" 
to ask user his decision
  CALL FUNCTION 'POPUP_TO_CONFIRM_WITH_MESSAGE'
    "...
    "...
    IMPORTING answer = lv_answer .

  IF lv_answer = 'J' . "I assume, your question as asked
*--Use The FM "JOB_OPEN" to open a new job.
*--Here you can use SUBMIT command with its "JOB" 
*--addition to submit the program in background"
  ELSE .
    LEAVE PROGRAM .
  ENDIF .
ENDIF .

Hope this much helps...

P.S.: BTW Let me tell that you should give 10 points to Anand since his post solved the main question.

*--Serdar

0 Kudos

Hi,

I shall give you the algorithm. Tell me if you need the code also.

START-of-SELECTION.

if sy-batch ne 'X'.

  • 1. call FM POPUP_TO_CONFIRM_STEP.

  • 2. If the answer is Yes,

  • 3. Call function JOB_OPEN.

  • 4. get the job number.

  • 5. SUBMIT ZEST VIA JOB name NUMBER number

AND RETURN.

  • Call the FM JOB_CLOSE.

Regards,

Anand Mandalika.

0 Kudos

BTW , you can also refer to the online documentation of SUBMIT statement for a very good illustration.

Regards,

Anand Mandalika.

0 Kudos

FYI

We have an include in all our customer reports which checks the program name against entries on a Z table. This way we can automatically restrict and reinstate which programs can run in the foreground.

bg

andreas_mann3
Active Contributor
0 Kudos

Hi ,

I'd prefer fm <b>K_BATCH_REQUEST</b>

instead of fm job_open , submit via job... and fm close_job, because user is in dialog up to start of the batch job.

regards Andreas

0 Kudos

can u give me a sample code .. showing how to use that FM.

0 Kudos

The following Piece of code is not working for me.. can anyone please resolve the problem... I am getting a dump error in JOB_open fm ...

data: l_jobcount like TBTCJOB-JOBCOUNT.

CALL FUNCTION 'JOB_OPEN'

EXPORTING

jobname = sy-repid

IMPORTING

jobcount = l_jobcount

EXCEPTIONS

CANT_CREATE_JOB = 1

INVALID_JOB_DATA = 2

JOBNAME_MISSING = 3

OTHERS = 4

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

SUBMIT VIA JOB 'ZPPR_ZPIPR' Number 1 AND RETURN.

CALL FUNCTION 'JOB_CLOSE'

EXPORTING

jobcount = l_jobcount

jobname = sy-repid

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

0 Kudos

Hi Shankar,

Look at how easily it can be done...


    CALL FUNCTION 'SIMPLE_BATCH_JOB_SUBMIT'
      EXPORTING
        PROGRAM             = sy-repid
      EXCEPTIONS
        SUBMIT_FAILED       = 1
        OTHERS              = 2 .
    IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

The name of the job is same as the name of the program. and the job is run under the surrent user's name, i.e., sy-uname.

Regards,

Anand Mandalika.

0 Kudos

Hi Shankar,

I have already given the best method before (SIMPLE_BATCH_JOB_SUBMIT). However, I would like to address this issue as well.

Try taking the sy-repid into a temporary variable and then pass that variable to the FMs.

Regards,

Anand Mandalika.

0 Kudos

When i call that FM as u told in the last post, I am getting this error message :

" Failed to create job step ZPPR_ZPIPR (see system log) "

where ZPPR_ZPIPR is the report name ...

0 Kudos

I did not get any dump when i executed that program. Could you please post the code for the call ?

Regards,

Anand Mandalika.

0 Kudos

Data: l_answer type c.

start-of-selection.

if sy-batch ne 'X'.

CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'

EXPORTING

DEFAULTOPTION = 'Y'

textline1 = 'The Date range given is more than 31 days .'

TEXTLINE2 = 'Do you want to run it in Background ? '

titel = ' Needs to be run in Background Only'

  • START_COLUMN = 25

  • START_ROW = 6

  • CANCEL_DISPLAY = 'X'

IMPORTING

ANSWER = l_answer.

.

Data: l_sy-repid type sy-repid.

l_sy-repid = sy-repid.

if l_answer eq 'N'.

leave list-processing.

else.

CALL FUNCTION 'SIMPLE_BATCH_JOB_SUBMIT'

EXPORTING

PROGRAM = l_sy-repid

EXCEPTIONS

SUBMIT_FAILED = 1

OTHERS = 2 .

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

endif.

endif.

0 Kudos

Did u get any error when u run my code .. are u able to resolve my problem .. Please reply...

Waiting for ur answer ....

Thanking you..

Shankar

0 Kudos

Hello Shankar,

I did not get any error when I ran your code.

But there's ont hing in your code that I did not understand: Wht are you using the LEAVE LIST-PROCESSING statement ? I don't think it is relevant in this context. It's putpose is totally different.e this code, which is just the same as yours...

DATA: L_ANSWER TYPE C,
      L_REPID TYPE SY-REPID.


START-OF-SELECTION.
  IF SY-BATCH NE 'X'.
    CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
      EXPORTING
        DEFAULTOPTION        = 'Y'
        TEXTLINE1            = 'THE DATE RANGE GIVEN IS MORE THAN 31 DAYS .'
        TEXTLINE2             = 'DO YOU WANT TO RUN IT IN BACKGROUND ? '
        TITEL                = ' NEEDS TO BE RUN IN BACKGROUND ONLY'
      IMPORTING
        ANSWER               = L_ANSWER.

    IF L_ANSWER EQ 'J'.
      L_REPID = SY-REPID.
      CALL FUNCTION 'SIMPLE_BATCH_JOB_SUBMIT'
            EXPORTING
              PROGRAM             = L_SY-REPID
            EXCEPTIONS
              SUBMIT_FAILED       = 1
              OTHERS              = 2 .
  
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNO
           WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDIF.
  ENDIF.

Regards,

Anand Mandalika.

0 Kudos

Okay .. i have commented the leave list-processing statement...

Still i am getting the same error ..

0 Kudos

In system log ... the error is listed like this ..

BP_CHECK_REPORT_VALUES: Invalid program values found. Reason:

> No variant was specified for program ZPPR_ZPIPR

BP_JOB_EDITOR: Job ZPPR_ZPIPR is invalid. Reason:

> Step 1 contains illegal values

0 Kudos

Hi Shankara,

Here is what is happening with your logic.

1. User is running the program and got to the selection screen.

2. User enters the selection values and then presses execute.

3. User gets the diaolog box asking him whether the program should be run in the background.

4. User says yes and you are doing the submit of your program.

The problem lies in the step 4 where you are submitting your program.

Remember, when you submit a program, you are supposed to have passed the selection screen data in one of the standard ways of passing the data which is either creating a variant and passing the variant to the job, or use SPA/GPA parameters if relevant or any other method.

Since you are calling your program again within the same program, but without passing the selection screen values, your program is failing. Here is a sample program to achieve what you are trying to achieve.


REPORT ztest.

PARAMETERS: p_vbeln LIKE vbak-vbeln,
            p_bkrun NO-DISPLAY.

DATA: ls_vbak LIKE vbak.

DATA: v_answer,
      v_jobcount LIKE tbtcjob-jobcount.
  IF p_bkrun IS INITIAL.
*-- not background processing
    CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
         EXPORTING
              textline1      = 'This may time out.'
              textline2      = 'Do you want to run in background?'
              titel          = 'Warning!!!'
              cancel_display = space
         IMPORTING
              answer         = v_answer.
    IF v_answer = 'J'.
*-- run in the background
      CALL FUNCTION 'JOB_OPEN'
           EXPORTING
                jobname          = 'ZTEST'
           IMPORTING
                jobcount         = v_jobcount
           EXCEPTIONS
                cant_create_job  = 1
                invalid_job_data = 2
                jobname_missing  = 3
                OTHERS           = 4.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        EXIT.
      ENDIF.
*-- submit the program in the background
      SUBMIT ztest
        WITH p_bkrun = 'X'
        WITH p_vbeln = p_vbeln
        USER sy-uname
        VIA JOB 'ZTEST' NUMBER v_jobcount AND RETURN.
*-- close the job
      CALL FUNCTION 'JOB_CLOSE'
           EXPORTING
                jobcount             = v_jobcount
                jobname              = 'ZTEST'
                strtimmed            = 'X'
           EXCEPTIONS
                cant_start_immediate = 1
                invalid_startdate    = 2
                jobname_missing      = 3
                job_close_failed     = 4
                job_nosteps          = 5
                job_notex            = 6
                lock_failed          = 7
                OTHERS               = 8.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE 'W' NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
      EXIT.
    ELSE.
      CLEAR v_answer.
    ENDIF.
  ENDIF.

  CHECK v_answer IS INITIAL.
  SELECT SINGLE * FROM vbak
                  INTO ls_vbak
                 WHERE vbeln = p_vbeln.

  IF sy-subrc <> 0.
    WRITE:/ 'Invalid Order Id.'.
  ENDIF.


*-----------------
END-OF-SELECTION.
*-----------------
  CHECK v_answer IS INITIAL.
  IF p_bkrun IS INITIAL.
    WRITE:/ 'Here is the result running the program in foreground.'.
  ELSE.
    WRITE:/ 'Here is the result running the program in background.'.
  ENDIF.

  WRITE:/ ls_vbak-vbeln,
          ls_vbak-vkorg.

Let me know if you have any questions.

Srinivas

0 Kudos

My selection screen is this :

SELECT-OPTIONS:

s_werks FOR pbid-werks OBLIGATORY.

SELECT-OPTIONS:

s_matnr FOR pbid-matnr obligatory.

SELECT-OPTIONS:

s_pbdnr FOR pbid-pbdnr.

SELECT-OPTIONS:

s_laeda FOR pbhi-laeda OBLIGATORY.

PARAMETER:

c_print TYPE checkbox.

PARAMETER:

c_sumry TYPE checkbox.

Can u please give me the submit statement for this selection parameters .. I run ur code .. but its not getting scheduled as a background job. Can u please run ur code again and varify it ?

0 Kudos

Dear Srinivas,

I copied ur code into a report and executed it. If i execute it.. its getting scheduled properly. In sm37, its showing the job status as "Completed". But We are not getting the spool . So , no output . But anyhow job is created but.. with no spool . Can u please check ur code oce again ? Please reply at the earliest ..

Thanking you in advance ,

Shankar

0 Kudos

Hi Shankar,

Sorry, I didn't respond immediately as I was away for the weekend and monday.

I executed my program both in foreground and background and I did get the results that I expected. If I click 'Yes' on the pop-up, it does schedule the job and I did get the spool with the text 'Here is the result running the program in background.'.

Remember that the program itself should not be run in the background. You will decide to run it in the background only after the pop-up comes up. If you want to directly execute the program in background without the pop-up, then you need additional condition before the call to the pop-up function checking whether the program is run in foreground.

Let me know how it goes.

Srinivas

0 Kudos

But there is some problem here.. I am not getting the required result in spool.. though the job gets scheduled properly.. Now i am using the FM SIMPLE_BATCH_JOB_SUBMIT which Poornanad has suggested. It works fine .. But the only thing is that we have to pass a variant to that .

So, if we have to get the required o/p in spool, we have to save the user input into a variant at run time automatically.. the moment he says "YES" , a the input should be stored in a variant say "TEMP". Then we can pass the variant "TEMP" to the above FM. can u please tell me how to do that .

Thanking you..

0 Kudos

Hello Shankar,

The program which Srinivas has given works perfectly. Did you execute the program he has given exactly as it is without any modifications? IF yes, then you must be getting the spool. I have just checked it out.

First confirm whether his example is working for you. Then we can modify your submit statement to take your selection-screen variables into consideration.

Regards,

Anand Mandalika.

0 Kudos

Ya.. I have run his code without any changes.. But in sp01, I am not getting the spool for that .. In sm37, i can see that . That means , the job is scheduled properly , but the spool is not coming .We are using Version 620. This confirms that the given code is not working properly here.. though its working properly for you guys. I dont know the reason behind this. Please give me a solution ...or please give an answer to my previous query .

Thanking you ..

Shankar

0 Kudos

Hi Shankar,

Are you saying that you can see the spool in SM37 but not in SP01 ? Then I'm sure that the selection conditions in SP01 are wrong. Give the user-name as your user-ID and check the dates. If you are still not getting it, take the spool number in SM37 and give it in SP01.

BTW, in SP01, there are two tabs: <b>Spool Requests</b> and <b>Output Requests</b>. You should be looking at the <b>Spool Requests</b> tab.

Please confirm this first, because, obviously there's no point going ahead with your program if this (simple) one is not working for you.

Regards,

Anand Mandalika.

0 Kudos

In sm37, i am getting the job status as completed .. But the icon for seeing the o/p /.. i mean the Spool icon itself is not there.. even if i select that and press spool button, Its telling " No spool is available" . That means by any means i cannot see the spool output.

0 Kudos

Hi Shankar,

This seems impossible to me. Just try one thing out. When you get the pop-up, Select NO and let the processing take place in the foreground. Do you get any list output ?

Regards,

Anand Mandalika.

0 Kudos

Hi Shankar,

Please check the printer parameters defined for spool options.

Thanks

Lakshman

0 Kudos

ya.. If i click "No".. i am getting the output. But in case of "Yes" O/p is not soming in spool .. Please think why its happening .. IS it anything related to version ? We are using ver 620 .

0 Kudos

Hello Shankar,

Really can't think of what could've gone wrong. But in the meanwhile, try to execute your report, with the following SUBMIT statement -

SUBMIT <<i>your report name</i>>  
  WITH c_print eq c_print
       c_sumry eq c_sumry
       s_werks in s_werks
       s_matnr in s_matnr
       s_pbdnr in s_pbdnr
       s_laeda in s_laeda
  USER sy-uname        
   VIA JOB <<i>name of the job</i>> 
 NUMBER <<i>the number you get from JOB_OPEN</i>> AND RETURN.

Just execute your report and schedule the report in background. See if you are able to at least schedule the job successfully. And get back with the results. then we shall see what could have gone wrong with the sppol.

Regards,

Anand Mandalika.

0 Kudos

Ya.. I already tried that .. the result is the same thing .. Instead of finding out the reason behind the strange behaviour of the code, please suggest a way to save the user input into a variant and i can pass that variant to the FM simple_batch_input and get the desired o/p. The FM will work only if i give some variant..

Please reply..

Thaanking you..

Shankar

Former Member
0 Kudos

Shankar,

I am not sure if you still have this issue or not but following solution also works great.

*---------------------------------------------------------------------*
*       AT SELECTION-SCREEN OUTPUT                                    *
*---------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
      APPEND: 'ONLI' TO itab_ucomms,  "Execute (F8)
            'PRIN' TO itab_ucomms,  "Execute and Print
            'GET'  TO itab_ucomms,  "Get Variant (Shift+F5)
            'VSHO' TO itab_ucomms,  "Display Variant...
            'VDEL' TO itab_ucomms,  "Delete Variant...
            'SPOS' TO itab_ucomms.  "Save as Variant...

    CALL FUNCTION 'RS_SET_SELSCREEN_STATUS'
         EXPORTING
              p_status  = sy-pfkey
         TABLES
              p_exclude = itab_ucomms.