Problem solve Get help with specific problems with your technologies, process and projects.

Prevent multiple program submissions

You may want to prevent users to submit the same program twice for performance reasons. Here is a code snippet to prevent this.

You may want to prevent users to submit the same program twice for performance reasons. Here is a code snippet to prevent this, written in R/3 4.6C.
*---------------------------------------------------------------------*
*       FORM check_running                                            *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM check_running.
*
* For some background update jobs, you might want to stop the
* user from submitting the jobs twice.
*
* Do this checks to prevent the users from submitting the
* same background job twice.
*
* Perform the checks before starting your programs.
* do this check only if sy-batch = 'X'
*
*
*
  TYPES :

  BEGIN OF x_job_data,
          jobname  LIKE tbtco-jobname,
          jobcount LIKE tbtco-jobcount,
          strtdate LIKE tbtco-strtdate,
          strttime LIKE tbtco-strttime,
          END OF x_job_data.

  DATA: 
        curr_jobname    LIKE tbtcm-jobname,
        curr_jobcount   LIKE tbtcm-jobcount,
        g_jobcount      LIKE tbtcjob-jobcount,
        g_jobname       LIKE tbtcjob-jobname,
        t_job_table     TYPE STANDARD TABLE OF x_job_data
                        WITH HEADER LINE,
        t_joblog        TYPE STANDARD TABLE OF tbtc5
                        WITH HEADER LINE,
        t_jobstep       TYPE STANDARD TABLE OF tbtcstep
                        WITH HEADER LINE.

*
* Get own jobdata
  CALL FUNCTION 'GET_JOB_RUNTIME_INFO'
       IMPORTING
            jobcount        = curr_jobcount
            jobname         = curr_jobname
       EXCEPTIONS
            no_runtime_info = 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.

* read all other running jobs
  SELECT * FROM tbtco
           INTO CORRESPONDING FIELDS OF TABLE t_job_table
    WHERE jobcount <> curr_jobcount
      AND strtdate = sy-datum
      AND strttime < sy-uzeit
      AND status   = 'R'.
*
  IF sy-subrc = 0.
    LOOP AT t_job_table.
      g_jobcount = t_job_table-jobcount.
      g_jobname  = t_job_table-jobname.
*     Read all jobsteps belonging to job
      CALL FUNCTION 'BP_JOB_READ'
        EXPORTING
          job_read_jobcount           = g_jobcount
          job_read_jobname            = g_jobname
          job_read_opcode             = '20'
*         JOB_STEP_NUMBER             =
*       importing
*         job_read_jobhead            =
        TABLES
          job_read_steplist           = t_jobstep
*       changing
*         ret                         =
        EXCEPTIONS
          invalid_opcode              = 1
          job_doesnt_exist            = 2
          job_doesnt_have_steps       = 3
          OTHERS                      = 4
                .
      IF sy-subrc = 0.
*       check if current program is part of the job
        LOOP AT t_jobstep.
          IF t_jobstep-program = sy-cprog.
*           program found, issue an error-message          
            MESSAGE i100 WITH 'Please wait '
                              'Program is already part of job'.

            MESSAGE a999 WITH g_jobname
                    'which is started on '
                     t_job_table-strtdate t_job_table-strttime.

          ENDIF.
        ENDLOOP.
      ENDIF.
    ENDLOOP.
  ENDIF.
ENDFORM.
This was last published in August 2003

Dig Deeper on SAP ABAP

PRO+

Content

Find more PRO+ content and other member only offers, here.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchManufacturingERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchCRM

SearchContentManagement

SearchFinancialApplications

Close