Application Development and Automation 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: 
Read only

Running ABAP Program in Background

Former Member
0 Likes
1,361

Hi,

I need to write a program which could run in background mode based on some condition. For example, I have two radio buttons, Excel and Spool. If I select Excel the program should run normally in foreground mode. If I select spool the program should run in background mode and save the out put in spool.

How can I do this?

Thanking you in advance

Regards,

Eswar

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
825

Hi,

if p_spool is not intial.

call Fm JOB_OPEn

call FM JOB_SUBMIT

call fm job_close.

else.

ur program logic.

endif.

Revert back if any issues,

Reward with points if helpful ,

Regards,

Naveen

4 REPLIES 4
Read only

Former Member
0 Likes
826

Hi,

if p_spool is not intial.

call Fm JOB_OPEn

call FM JOB_SUBMIT

call fm job_close.

else.

ur program logic.

endif.

Revert back if any issues,

Reward with points if helpful ,

Regards,

Naveen

Read only

Former Member
0 Likes
825

Hello,

Check for SY-BATCH if it is in background.

Vasanth

Read only

Former Member
0 Likes
825

Yes when sy-batch = 'X' the program is executed in the background.

Regards

Read only

Former Member
0 Likes
825

Hi,

long time ago, I found this coding at http://www.4ap.de.

This coding ask in a popup for running in background, when the select-option fields

s_carrid

and

s_connid

are intitial.

Hope it helps you....

Stefan


TABLES: sflight.

DATA: BEGIN OF i_sflight OCCURS   0,
        carrid LIKE sflight-carrid,
        connid LIKE sflight-connid,
        fldate LIKE sflight-fldate,
        currency LIKE sflight-currency,
        paymentsum LIKE sflight-paymentsum,
        zielbetrag LIKE sflight-paymentsum,
      END OF i_sflight.

DATA: sw_int(1) TYPE p.
DATA  answer.
DATA: job LIKE tbtcjob-jobname.
DATA: num LIKE rsjobinfo-jobnumb.

SELECT-OPTIONS: s_carrid FOR sflight-carrid,
                s_connid FOR sflight-connid.
PARAMETERS:     p_curr LIKE tcurr-tcurr OBLIGATORY DEFAULT 'EUR'.


AT SELECTION-SCREEN.
  CLEAR answer.
  CHECK sy-batch IS INITIAL AND sy-ucomm NE 'JOBS'.
  IF s_carrid[] IS INITIAL AND
     s_connid[] IS INITIAL.
    CALL FUNCTION 'POPUP_TO_DECIDE'
         EXPORTING
              textline1      = 'Sie haben nichts eingeschränkt!'(001)
              textline2      = 'Das Programm wird voraussichtlich'(002)
              textline3      = 'länger laufen.'(003)
              text_option1   = 'Im Hintergrund'(004)
              text_option2   = 'Trotzdem ausführen'(005)
              titel          = 'Achtung, Langläufer!'(006)
         IMPORTING
              answer         = answer
         EXCEPTIONS
              OTHERS         = 1.
    CASE answer.
      WHEN '1'.
        CONCATENATE sy-uname sy-repid INTO job SEPARATED BY '_'.
        CALL FUNCTION 'JOB_OPEN'
             EXPORTING
                  jobname          = job
             IMPORTING
                  jobcount         = num
             EXCEPTIONS
                  cant_create_job  = 1
                  invalid_job_data = 2
                  jobname_missing  = 3
                  OTHERS           = 4.
        SUBMIT (sy-repid)
                TO SAP-SPOOL
                VIA SELECTION-SCREEN
                VIA JOB job NUMBER num
                WITH s_carrid IN s_carrid
                WITH s_connid IN s_connid
                WITH p_curr = p_curr
                AND RETURN.
        CALL FUNCTION 'JOB_CLOSE'
             EXPORTING
                  jobcount                    = num
                  jobname                     = job
                  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 s311(tg) WITH job num.
*   Der Batch Job & wurde mit der Nummer & eingeplant
        ELSE.
          MESSAGE e102(ss).
*   Fehler bei der Joberzeugung
        ENDIF.
      WHEN '2'.
      WHEN 'A'.
        SET CURSOR FIELD s_carrid-low.
        MESSAGE e055(c/).
*    Die Selektion ist zu umfangreich. Bitte einschränken.
    ENDCASE.
  ENDIF.

START-OF-SELECTION.
  CHECK sy-ucomm NE 'JOBS' AND answer NE '1'.
  SELECT carrid connid fldate currency paymentsum
         INTO TABLE i_sflight
         FROM sflight
         WHERE carrid IN s_carrid.
  LOOP AT i_sflight.
    FORMAT COLOR COL_NORMAL INTENSIFIED = sw_int.
    sw_int = 1 - sw_int.
    CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
         EXPORTING
              date              = sy-datum
              foreign_amount    = i_sflight-paymentsum
              foreign_currency  = i_sflight-currency
              local_currency    = p_curr
         IMPORTING
              local_amount      = i_sflight-zielbetrag
         EXCEPTIONS
              no_rate_found     = 1
              overflow          = 2
              no_factors_found  = 3
              no_spread_found   = 4
              OTHERS            = 5.
    MODIFY i_sflight TRANSPORTING zielbetrag.
    WRITE: / i_sflight-carrid,
             i_sflight-connid,
             i_sflight-fldate,
             i_sflight-paymentsum CURRENCY i_sflight-currency,
             i_sflight-currency,
             i_sflight-zielbetrag CURRENCY p_curr,
             p_curr,
             AT sy-linsz ''.
    AT END OF connid.
      SUM.
      FORMAT COLOR COL_TOTAL INTENSIFIED OFF.
      WRITE: / i_sflight-carrid,
               i_sflight-connid,
            10 'Summe',
               i_sflight-zielbetrag CURRENCY p_curr
                                    UNDER i_sflight-zielbetrag,
               p_curr,
               AT sy-linsz ''.
    ENDAT.
    AT END OF carrid.
      SUM.
      FORMAT COLOR COL_TOTAL INTENSIFIED ON.
      WRITE: / i_sflight-carrid,
            10 'Summe',
               i_sflight-zielbetrag CURRENCY p_curr
                                    UNDER i_sflight-zielbetrag,
               p_curr,
               AT sy-linsz ''.
      NEW-PAGE.
    ENDAT.
    AT LAST.
      SUM.
      FORMAT COLOR COL_TOTAL INTENSIFIED OFF.
      WRITE: /10 'Gesamtsumme:',
               i_sflight-zielbetrag CURRENCY p_curr
                                    UNDER i_sflight-zielbetrag,
               p_curr,
               AT sy-linsz ''.
    ENDAT.
  ENDLOOP.