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: 

Background job which will execute two programs

Former Member
0 Kudos

Hi experts,

How to set a background job which will execute first program and take the output as input of the second program and execute it.

Any reference program will be helpful.

Regards

Satya

6 REPLIES 6

horst_keller
Product and Topic Expert
Product and Topic Expert

Pragmatic solution: Write a third program that calls the other two.

0 Kudos

Hi Horst,

then how will the output of first program will be the input of second program??

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

What is the output of a program?

What is the input of a program?

What do you expect at all?

0 Kudos

"then how will the output of first program will be the input of second program??"

If they are your programs - export the results to memory, export the results to a temporary table, exporting list to memory. read the updated database tables for the values your require

If they are SAP custom programs, exporting list to memory, or read the updated database tables.

bertrand_delvallee
Active Participant
0 Kudos

Hello,

You could try something like this :

* Background "print" options
  CALL FUNCTION 'GET_PRINT_PARAMETERS'
    EXPORTING
      no_dialog      = 'X'
    IMPORTING
      out_parameters = print_parameters.
  print_parameters-paart = 'X_62_255'.
  print_parameters-linsz = '132'.
  print_parameters-linct = '108'.
  print_parameters-prrel = space. " direct print
  print_parameters-primm = space. " delete after printing
*-----------------
  nom_prog = sy-repid.
  PERFORM get_spool_name USING nom_prog sy-uname
        CHANGING name.
  CALL FUNCTION 'JOB_OPEN'
    EXPORTING
      jobname          = name
    IMPORTING
      jobcount         = number
    EXCEPTIONS
      cant_create_job  = 1
      invalid_job_data = 2
      jobname_missing  = 3
      OTHERS           = 4.
    CHECK sy-subrc IS INITIAL.
*-----------------
SUBMIT prog1 WITH parameter1 = 'MY VALUE'
                      USING SELECTION-SET 'JOB_DEFAULT'
                      TO SAP-SPOOL
                      SPOOL PARAMETERS print_parameters
                      WITHOUT SPOOL DYNPRO
                      VIA JOB name NUMBER number
                      USER sy-uname
                      AND RETURN.
*------------------
CALL FUNCTION 'JOB_CLOSE'
      EXPORTING
        jobcount             = number
        jobname              = name
        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.
    CHECK sy-subrc IS INITIAL.
*-------------------
* Here you can LOOP with a delay on each iteration. Or just wait X secnds. Or create an EVENT in job and catch it. It depends on average process time of the program.
*-------------------
(LOOP. WAIT X seconds. )
      REFRESH t_spoollist.
      CALL FUNCTION 'BP_JOB_READ'
        EXPORTING
          job_read_jobname  = name
          job_read_jobcount = number
          job_read_opcode   = 36 " read all job data
        TABLES
          spool_attributes  = t_spoollist
        EXCEPTIONS
          job_doesnt_exist  = 1
          OTHERS            = 99.

    CHECK NOT t_spoollist[] IS INITIAL.
    READ TABLE t_spoollist INDEX 1.
    mi_rqident = t_spoollist-spoolid.
(ENDLOOP.)
*--------------

CALL FUNCTION 'RSPO_RETURN_ABAP_SPOOLJOB'
    EXPORTING
      rqident              = mi_rqident
    TABLES
      buffer               = record
    EXCEPTIONS
      no_such_job          = 1
      not_abap_list        = 2
      job_contains_no_data = 3
      no_permission        = 4
      OTHERS               = 8.

* Now you can loop on RECORD which is a CHAR255 table (depending on your print options)
* You can repeat this process several times 

matt
Active Contributor
0 Kudos

If they're well designed(!) then it's a simple case of writing a third program that gets the data from the model of the first program and passes it to the model of the second program. One line of ABAP should do it.

new model2( new model1( )->get_results( ) )->do_stuff( ).