Need to execute a program in background

Hello,
I have a report program that has a checkbox option to 'Execute in background'. This should also generate a spool file in SAP. I would just like to ask for options on how to do about this.
I have thought of using the SUBMIT command and I read that this command can also generate a spool file. So it is like calling the program itself. Is this possible? Or do I need to make a cloned program and call submit the parameters to the cloned program?
Is there a function module that does this?
I'd appreciate your help on this. Thanks in advance!
Regards,
Kristine

Hello,
To create a Job Step, the FM 'JOB_OPEN' could be used.
To add a JOBSTEP, In your case an ABAP program, "SUBMIT" could be used.
To close the job step, use FM "JOB_CLOSE".
SAMPLE Code:
  CALL FUNCTION 'JOB_OPEN'
       EXPORTING
        DELANFREP        = ' '
        JOBGROUP         = ' '
           jobname          = 'XYZ'
           sdlstrtdt        = sy-datum "Current date
           sdlstrttm        = sy-uzeit
      IMPORTING
           jobcount         = g_jobcount
      EXCEPTIONS
           cant_create_job  = 1
           invalid_job_data = 2
           jobname_missing  = 3
           OTHERS           = 4
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
  SUBMIT z_PROGRAM AND RETURN
     USER sy-uname      " User for runtime authorizations
     WITH p_para   EQ p_para
     "..... Selection screen parameters
     VIA JOB g_jobname NUMBER g_jobcount
                     " Job name and job number
                     " from JOB_OPEN
     TO SAP-SPOOL    " Print and archiving options from
                     " GET_PRINT_PARAMETERS
                     " Both sets of options come from
                     " GET_PRINT_PARAMETERS
        SPOOL PARAMETERS g_s_user_print_params
        ARCHIVE PARAMETERS g_s_user_arc_params
        WITHOUT SPOOL DYNPRO.
  CALL FUNCTION 'JOB_CLOSE'
       EXPORTING
        AT_OPMODE                   = ' '
        AT_OPMODE_PERIODIC          = ' '
        CALENDAR_ID                 = ' '
        EVENT_ID                    = ' '
        EVENT_PARAM                 = ' '
        EVENT_PERIODIC              = ' '
            jobcount                    = g_jobcount
            jobname                     = g_jobname
        LASTSTRTDT                  = NO_DATE
        LASTSTRTTM                  = NO_TIME
        PRDDAYS                     = 0
        PRDHOURS                    = 0
        PRDMINS                     = 0
        PRDMONTHS                   = 0
        PRDWEEKS                    = 0
        PREDJOB_CHECKSTAT           = ' '
        PRED_JOBCOUNT               = ' '
        PRED_JOBNAME                = ' '
           sdlstrtdt                   = g_datum
           sdlstrttm                   = g_uzeit
        STARTDATE_RESTRICTION       = BTC_PROCESS_ALWAYS
        STRTIMMED                   = ' '
        TARGETSYSTEM                = ' '
        START_ON_WORKDAY_NOT_BEFORE = SY-DATUM
        START_ON_WORKDAY_NR         = 0
        WORKDAY_COUNT_DIRECTION     = 0
        RECIPIENT_OBJ               =
        TARGETSERVER                = ' '
      IMPORTING
           job_was_released            = g_job_released
      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
You can get the Print Parameters from FM: 'GET_PRINT_PARAMETERS'.
All the above FMs have detailed documentation which will help you.
Hope this helps you.
Regards, Murugesh AS

Similar Messages

  • Executing the program in Background

    Hi experts i'm trying to Execute the Program in background.
    Given the Input and output file locations and Press F9 for process the program in background from SE38. cause i want to run my program as a batch(Background)
    but its not accepting. can you please help me how to resolve this issue.
    i'm providing the code can you please verify that.
    Many Thanks
    SELECTION-SCREEN                                                     *
    selection-screen begin of block b1 with frame title text-001.
    *.. Filename
    PARAMETERS: f_name TYPE char100,     "Upload filename
                d_name TYPE char100.     " Download filename
    selection-screen end of block b1 .
    SELECTION-SCREEN: BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
    PARAMETERS: p_serv radiobutton group RAD1,
                p_frnt radiobutton group RAD1 default 'X'.
    SELECTION-SCREEN: END OF BLOCK b2.
    AT SELECTION-SCREEN ON VALUE-REQUEST  FOR f_name.
    *.. Data Declaration
      DATA: lt_file TYPE filetable,
            lv_file TYPE LINE OF filetable,
            rc_i TYPE i,
            cl_gui TYPE REF TO cl_gui_frontend_services,
            w_path  LIKE dxfields-longpath.
    *.. Check if from server or frontend
      IF p_frnt = 'X'.
    *.. Create objects for method
      CREATE OBJECT cl_gui.
    *.. Clear the filename
      CLEAR f_name.
    *.. Call method to search for file
      CALL METHOD cl_gui_frontend_services=>file_open_dialog
        EXPORTING
          window_title = 'Choose Input File'
        CHANGING
          file_table   = lt_file
          rc           = rc_i
        EXCEPTIONS
          OTHERS       = 4.
    *.. Check if file found
      IF sy-subrc EQ 0.
    *.. Check that file path not empty
        CHECK NOT lt_file[] IS INITIAL.
        LOOP AT lt_file INTO lv_file.
    *..   Set parameter to filename
          f_name = lv_file-filename.
        ENDLOOP.
      ENDIF.
    *.. Free object
      FREE cl_gui.
    *.. Upload from Server
      ELSE.
    Retrieve filename
        CALL FUNCTION 'F4_DXFILENAME_TOPRECURSION'
          EXPORTING
            i_location_flag       = 'A'
            i_server              = ' '
            i_path                = '/sap_ftp/'
            filemask              = '**'
            fileoperation         = 'R'
          IMPORTING
      O_LOCATION_FLAG       =
      O_SERVER              =
            o_path                = w_path
      ABEND_FLAG            =
          EXCEPTIONS
           rfc_error             = 1
           error_with_gui        = 2
           OTHERS                = 3.
    Set file path
        f_name = w_path.
      ENDIF.
    *.. File selection for output file
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR d_name.
    *.. Only allow search for front-end
      IF p_frnt = 'X'.
    *.. Data Declaration
        DATA: lt_file TYPE filetable,
              lv_file TYPE LINE OF filetable,
              rc_i TYPE i,
              cl_gui TYPE REF TO cl_gui_frontend_services.
    *.. Create objects for method
        CREATE OBJECT cl_gui.
    *.. Clear the filename
        CLEAR d_name.
    *.. Call method to search for file
        CALL METHOD cl_gui_frontend_services=>file_open_dialog
          EXPORTING
            window_title = 'Choose Input File'
          CHANGING
            file_table   = lt_file
            rc           = rc_i
          EXCEPTIONS
            OTHERS       = 4.
    *.. Check if file found
        IF sy-subrc EQ 0.
    *.. Check that file path not empty
          CHECK NOT lt_file[] IS INITIAL.
          LOOP AT lt_file INTO lv_file.
    *..   Set parameter to filename
            d_name = lv_file-filename.
          ENDLOOP.
        ENDIF.
    *.. Free object
        FREE cl_gui.
      ENDIF.
    *.. General Checks for Selection screen
    AT SELECTION-SCREEN.
    *.. Check if program run in batch mode and ping directory
      IF sy-batch = 'X'.
    *.. Move filename to file_name
        file_name = d_name.
    *.. Check if path can be reached
        OPEN DATASET file_name FOR INPUT IN TEXT MODE.
        IF sy-subrc NE 0.
          MESSAGE e082(zsomerfield).
        ENDIF.
      ENDIF.
    NITIALIZATION.
    *.. ALV Variables
      variant_save = 'A'.
      w_repid   = sy-repid.
      w_variant_handle = c_handl.
    START-OF-SELECTION                                                   *
    START-OF-SELECTION.
    *.. Check if batch program running in batch mode or not
      IF sy-batch = 'X'.
    *.. Open file on application server for reading
      OPEN DATASET file_name FOR INPUT IN TEXT MODE.
      DO.
    *.. Upload entries
        READ DATASET file_name INTO zpernr.
    *.. IF end of file reached then exit DO statement
        IF sy-subrc = '4'.
          EXIT.
        ELSE.
    *.. IF entry found then add to employee table
          in_file-empnum = zpernr.
    *..     Add entries to table
          APPEND: in_file.
    *..     Clear header lines
          CLEAR: in_file, zpernr.
        ENDIF.
      ENDDO.
    *.. Close dataset
      CLOSE DATASET file_name.
    *.. Get file from frontend and run in foreground
      ELSE.
    *.. Upload from local machine.
    DATA: file_name TYPE string.  "LIKE rlgrap-filename,
    *.. Set filename to filename from screen
      file_name = f_name.
    *.. Upload the information from the file into the table in_file
      CALL FUNCTION 'GUI_UPLOAD'
           EXPORTING
                filename                = file_name
           TABLES
                data_tab                = in_file
           EXCEPTIONS
                file_open_error         = 1
                file_read_error         = 2
                no_batch                = 3
                gui_refuse_filetransfer = 4
                invalid_type            = 5
                no_authority            = 6
                unknown_error           = 7
                bad_data_format         = 8
                header_not_allowed      = 9
                separator_not_allowed   = 10
                header_too_long         = 11
                unknown_dp_error        = 12
                access_denied           = 13
                dp_out_of_memory        = 14
                disk_full               = 15
                dp_timeout              = 16
                OTHERS                  = 17.
    *..   Make sure file uploaded correctly
      IF sy-subrc <> 0.
       MESSAGE E018(ZHR_MESSAGES).
      ELSE.
      MESSAGE i017(ZHR_MESSAGES).
      ENDIF.
      ENDIF.

    Hi Vamsi,
    <b>First Check in the Foreground your program is working for the application server file or not</b>
    When you will Execute your program in Background internal table "ZPERNR" will be populated from the file that is there on the application server.
    After that what you want to do with the internal table.I think you have not sent the whole code.
    In background FM GUI_UPLOAD willl not work.
    If you want to debug your code put wait for 100 seconds at the place where you want to dubug your code.Go to transaction code SM50 your job will be running there.
    Select Your job
    Go to  Menu Bar Program/Mode - > program - > Debugging.
    In this way you can debug your code.
    First Check in the Foreground your program is working for the application server file or not

  • BDC is not working in when executing the program in background

    Hi gurus,
    I have a problem that in BDC is not working when i'm executing the upload program in background thru scheduling(SM36) , while it works fine when i execute directly with NO screen display mode

    Many transactions behave differently when executed in foreground and background. The fields on the screen may be different.
    In transaction SHBD when starting a recording there is a checkbox where you can select 'Simulate Background Mode'. If you do your recording using this option you will get the code suitable for background mode. If you do not select this option you will get a code for foreground mode.
    By compairing the two codes you will know the changes required for background mode.
    Hope this helps you

  • Executing a program in background is failed

    Hi Experts,
                    i am having a program while executing it in foreground its executing perfectly but while executing it in background, it is failed in job log its showing: this error:-Control Framework: Fatal error - GUI cannot be reached
    ABAP/4 processor: RAISE_EXCEPTION.
    While debugging i found the job is getting canceled at the statement
    SUBMIT rs_display_variant WITH SELECTION-TABLE i_params
                 EXPORTING LIST TO MEMORY
                 AND RETURN.
    RS_DISPLAY_VARIANT is not executimg while executing it in background. So if anybody knows how to resolve this or what i need to use instead of RS_DISPLAY_VARIANT . Please let me know.
    Thanks

    Hi,
    Use Offline method of CL_GUI_ALV_GRID
    Refer following documentation of the method.
    http://help.sap.com/saphelp_nw70/helpdata/EN/bf/3bd1369f2d280ee10000009b38f889/frameset.htm
    Regards,
    Mohaiyuddin

  • Error in executing a program in background?

    Hi all,
    I have one report , which is alv grid display using Oops.
    it is going to be executed in online but when we are try to execute this in background through path
    Program->Execute in background.
    the job is going to be canceled with error "Control Framework: Fatal error - GUI cannot be reached" and also i am getting one popup message like " format set to x_65_132"
    how can we rectify this error , what we have to code in program to overcome this problem.....
    thanks in advance

    Hi,
    1)Goto SM36,
    2)Enter all the options
    3)Click step,
    4)If the job is being scheduled to run an ABAP program, follow the directions mentioned below. Else, jump to Step 5.
    Fill the “User” field . This is very important,     Put the program name in the “NAME” field,Put the variant name in the “VARIANT” field and save.
    5)If the job executes an external command, then follow the steps below:Click on “External Command” and fill the fields and click save.
    Reward if useful

  • Executing a program in background is not creating spool

    Hi all,
    I am facing a small problem with one of the program. Below are the details.
    Its a simple program of uploading file from local machine and displaying the output. when I am running in foreground, the contents of file are copied into internal table and getting displayed in List.
    Where as when I run background, No spool is getting created. Also I found that, the internal table is getting cleared. I  have put an IF NOT INITIAL check and found that, Internal table is getting cleared and error message is written in the spool .
    There is no problem with file upload in background or foreground.
    Please advise.

    Hi
    What you means with "uploading file from local machine":
    - Presentation Server or Application Server?
    If u're using the fm as GUI_UPLOAD or WS_UPLOAD in order to upload the data from a file of Presentation Server u should consider those fms work foreground only.
    So how do u upload the file?
    Max

  • How to create a variant and execute a Z-program in background

    Hello,
    I have created a specific transaction to update relationships between partners (BP).
    For this i have create a screen painter, but as the run time is long i want to execute the program in background.
    How to save a variant and to execute the report in background ?
    Thanks in advance
    Christophe

    Hi,
    Please go to your z-transaction.
    Enter your selection criteria. & click on save button to save your your selection criteria as a variant.
    Now go to tcode SM36 to shedule your program with saved variant.
    Regards,
    Narendra

  • Executing 4 programs parallely via main program in background

    I am executing a program in background and that program internally calls 4 other programs. I want to execute those 4 programs at the same time (concurrently).
    Please suggest.
    Regards,
    Rajendra Dhaka

    Refer:
    http://help.sap.com/saphelp_nw04/helpdata/en/fa/096e92543b11d1898e0000e8322d00/content.htm
    http://help.sap.com/saphelp_nw70/helpdata/EN/c4/3a7f1f505211d189550000e829fbbd/content.htm
    Edited by: AJAY TIWARI on Nov 15, 2008 7:33 AM

  • To run a program in BACKGROUND using SUBMIT

    I need to run a program in background using the SUBMIT option. Here i have to pass an internal table form one program to another which will be used to update sales orders using BDC.
    Questions
    1} Can we execute a program in background using SUBMIT?
    2} I am sending data to a MEMORY ID , if i run the program in background will the memory id work. As in do  memory IDs work in the background.
    Thanks in Advance

    refer  same thread.
    Re: Problem with SUBMIT in Background

  • Require Job name in SM37 while executing call transaction in background

    Hi all,
    I am executing a report program, which contains Call transaction.
    I have recorded properly. The recording contains background job screen also ( means a separate popup came and i gave the job name and i gave immediately )
    When i execute in this program in foreground its creating job,its showing the job in sm37.
    But when i execute this program in background, it does not showing the job name in sm37.
    Anyone kindly help this out?
    Anandhab

    Hi,
    The job will be created by the step level user.
    Try searching again with jobname and * for username.
    Regards,
    Jovito

  • Running BDC program in background for the transaction VL02N

    Hi All,
    I have coded a BDC program (call transaction method) for the transaction code VL02N. I can able to run the program manually & successfully. But if I execute the program in background(SM36), it is going to dump giving CNTL_ERROR.
    Note: I am not using any of the GUI_UPLOAD, GUI_DOWNLOAD funciton modules in the program. But I am using the FTP command funtion modules like( FTP_COMMAND, FTP_CONNECT, FTP_DISCONNECT and FTP_SERVER_TO_R/3).
    <removed_by_moderator>
    Thanks in advance.
    Ramesh.
    Edited by: Julius Bussche on Jul 8, 2008 5:55 PM

    VL02N is an enjoy transaction. You cant run it in background. Please try VL02.
    Thanks
    Romit

  • When to Execute ABST2 program for Fixed Assets?

    Hi,
    Do we need to execute ABST2 program extractly at the end of the year 31/12/2008 or we can also execute after 31/12/2008?Because for my client-they have executed that program in July-2009.Now it is showing 0.01 differance for one of the depreciation account.the differance amount is showing for 2009 year.I am confused whether it is for 2008 or 2009.
    Now in ABST2 program it is showing the 0.01 differance for 2009.Still can i ignore ABST2 error and can i proceed to close 2008 year for fixed assets? or it will give any error?
    Kindlyl help me
    Thanks
    Suvarna

    HI,
    Generally it is executed before year-end closing. It picks up the asset balances and matches with the GL A/c balances. If any differences are found it shows the differences.
    Run it and check in which year the difference popped up. Then verify balances for that particular year. If it started in 2008 you can check only 2008 balances and need not check for 2009.
    Thanks,
    Giridhar

  • How to Prevent the Executing a Program but Allow to Run as Background Job?

    Hi All,
    I have an ABAB List Program. I need to restrict this program from executing. This has to always run as a Background Job. How do I check this condition in the program?
    Thanks,
    Kishan

    Check for the system variable SY-BATCH. If this field is 'X', then allow the execution of the program. If not then exit. Do this coding in the initialization event or start of selection.
    INITIALIZATION.
    IF sy-batch IS INITIAL.
      STOP.
    ENDIF.
    Manoj

  • Execute program in background(Scheduled)

    Hi guyz
    I want to execute a program on every last friday of the month. It should be scheduled automatically in back ground with out any manual interruption. Is there any way i can do that?
    Thanks

    Hi Satya,
    For executing jobs in non-interactive mode, schedule the job for background processing. To create a background processing job you should specify:
      The name of the report
      The name of any variant it needs
      What to do with output
      When to start it
    After this, the SAP system does not require user’s intervention and can proceed with the job even without you. It executes the report and prints the output using printer or output controller. While scheduling a job in background process, three parameters should be specified. These parameters are:
      Definition of programs
      Its start time
      The printing specification for getting the prints as required
    After this, you can check whether your job was executed successfully and display a log of any system messages.
    For scheduling background processing, you have to direct the system to process an ABAP/4 or external program in the background. This is a two-step process:
       Scheduling the program
       Releasing the job
    This needs to have a special authorization for releasing and scheduling the job. Generally, the system administrator, who organizes and monitors background processing, supervises the release of these jobs. Many users are also authorized to schedule background processing of reports. You cannot schedule a job unless and until you have a release authorization. If a user is authorized and has specified a start date or selected "start immediately," he or she can release the job.
    Authorized users can change start time. A program can be scheduled as a separate job or you can append it to an existing job, which has not yet been processed. Background process can be run while doing some other online work. However, this can adversely affect online operation and should be avoided. For example, if you run a program that locks the database, the work of online users will be hampered or stopped. Often, long-running reports are scheduled automatically or semi-automatically for background processing.
    First Step
    Initiate the job scheduling function. Standard job scheduling must be used in case of scheduling of an external command or external program as a background job and ABAP job scheduling function can be used to schedule ABAP programs. For starting a standard job scheduling function choose the following:
    Administration menu bar option à CCMS option à Jobs option à Definition option.
    For starting ABAP job scheduling function, navigate to ABAP Editor and choose Program menu bar option àExecute option à Background option.
    Second Step
    Now define a job. Using the Job Wizard you can define your job. From the Application toolbar, choose the wizard button. After this, the initial screen of the SAP Job Wizard appears. The Job Wizard is available only from the standard job scheduling function.
    Third Step
    Now, you have to save the job. When it displays the message "Job saved" it means the job has been successfully scheduled. We know that a job must be released before it is scheduled. Only authorized users can release the job, otherwise your system administrator will release your job.
    Fourth Step
    This is the last step of scheduling. In this step you have to check the status of your job. For this you need to choose System menu bar option à Own jobs option.
    In SAP System, the background processing runs according to your instructions. In case a list is generated by the report, the report either prints directly or waits for you in the SAP output controller. The status of background processing can be checked for its correctness.
    I think this will help you.
    If so then award the points.
    Thanks and regards
    Vipin Das V

  • Executing a report program in background from another program

    Hi Experts,
    I developed a report to display material change history based on change date range. Report is taking much time (around 15-20 mins) as I'm hitting CDPOS and CDHDR tables. User wants to execute the report in foreground because he/she can give selection criteria that is required everytime.
    So, my requirment is now to create another program with same selection screen elements which will execute the original program in background. In the new program, we will be just capturing the selection elements and will pass them to original program to run in background and display a message to user without wait for the background job to complete. Original program should send an email to an fixed email id with the report output as attachment (for example excel file).
    Please suggest.
    Thanks in Advance,
    Siva Sankar

    Hi Siva,
    Please see the link
    http://help.sap.com/saphelp_nw04/helpdata/EN/2a/fa01dd493111d182b70000e829fbfe/content.htm
    Regarding a Change Document Function Module ----- VERY VERY Urgent
    When using function modules , I dont think you can directly get data based on material and plant . these function modules usualy works with object class and creation date .
    Once you retrieve the data using the function modules you have to filter out the unncecessary data based on your selection screen conditions .
    Regards,
    Ratheesh BS
    Edited by: Ratheesh Bhaskarapillai Suseeladev on Mar 8, 2012 5:19 AM
    Regarding a Change Document Function Module ----- VERY VERY Urgent

Maybe you are looking for

  • Open sales order report with billing date.

    Hi, I want to know if there's an available report for open sales order with billing date field. Thank you.

  • IPad 2 with dock and smart cover?

    Can you put the iPad2 in the charging dock with the smart cover on? thanks, tom

  • KE21S-Valuation Simultaion COPA

    Hi, while doing transaction KE21S I am not able to enter the values in Sales Order and Sales Order Item fields in Orgin data Tab.Because of this, I am not able to do valuation in this Transaction.I am here providing the selection creteria which I use

  • Raid 1 advice for externals.

    I am looking to get a Raid1 external set up and these are the three that I am considering. Any thoughts or current users of these products would be more than helpful. I like the speed of the Sata but also like using the FW becuase many times I use my

  • Pre - photo albums do not sync correctly!

    Hi all,  Total newbie - and also a newbie to Palm.  Having moved from iphone to pre, and remaining a mac user, i'm becoming a little stressed at how the simple things just dont seem to be working!!!! I've downgraded my itunes so i can sync photos to