Skip to Content
avatar image
-1
Former Member

Background job which will execute two programs

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Jul 11, 2017 at 12:08 PM

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

    Add comment
    10|10000 characters needed characters exceeded

    • "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.

  • Jul 11, 2017 at 01:34 PM

    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 
    Add comment
    10|10000 characters needed characters exceeded

  • Jul 11, 2017 at 02:20 PM

    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( ).

    Add comment
    10|10000 characters needed characters exceeded