cancel
Showing results for 
Search instead for 
Did you mean: 

Force FM execution on batch job work process

Former Member
0 Kudos

Hi!

Is it possible to asynchronously start FM execution on batch job work process?

Additions:

CALL FUNCTION func STARTING NEW TASK taskname.

CALL FUNCTION func IN BACKGROUND TASK.

starts FM execution just on another dialog process.

Context of requirement:

There is a program that may be logically splitted into two parts:

- dialog part where data is collected from user input

- BAPI call with a tons of parameters(structures, internal tables) formed on user input

So the problem - system dump by timeout during BAPI execution.

The only solution is to execute BAPI functionality on work process without timeout limitations - batch job work process.

There may be two approaches:

- pass parameters to report and schedule its execution in background job. But here arise question how to pass these dynamic parameters? SAP memory doesn't available for background job work process and "SUBMIT WITH FREE SELECTIONS texpr" seems to be intended for LDB or anyway not for such purposes.

- force FM execution on background job work process - so how if it possible?

Appreciate your suggestions.

Regards,

Maxim.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hello Maxim,

the F1 Documentation for this addition of CALL FUNCTION is very good. There's even an example program which tells you how exactly this can be used.

I think using the BACKGROUND TASK addition is a good idea. On the other hand, if you want to export the data and then use it again in another session, then you can make use of the CLuster Table (INDX, for example).

Let me know if you need further inputs, I'll be glad to help you if I can.

Regards,

Anand Mandalika.

Former Member
0 Kudos

Hi, Poornanand!

As I mentioned earlier all appropriate from available additions to CALL FUNCTION (including BACKGROUND TASK)starts FM execution on separate <b>dialog</b> work process (with timeout limitations), not <b>batch job</b> work process (without timeout limitations). So it isn't solution.

Yes, I thought of using cluster table (exactly INDX) but this would lead to unnecessary table grow, because data must be saved under unique keys (there are a lot of users for this program working with different objects). And there is no need in this data after IMPORT from cluster table. So additional cluster management should be done then.

Still have assumption there should be more straightforward way.

Regards,

Maxim.

Former Member
0 Kudos

Hi Maxim,

Look at this example program where the user can run it online to enter the input values in the selection screen and then the program just goes into background mode, basically achieved by submitting the same program again skipping the selection screen. This is one more option for you.


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

Former Member
0 Kudos

To submit a program via a job you first call fm JOB_OPEN, then submit your program:


SUBMIT zpgm
    TO SAP-SPOOL
    VIA JOB    jobname
        NUMBER jobcount
        AND RETURN
    USER sy-uname
    WITH p_yyy  = 'YYY'
    WITH s_itcpo   = itcpo.

Finally call FM JOB_CLOSE.

You'll have to look at the FMs to determine which parameters need to be passed to them.

Rob