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

Executing the program in Background

Former Member
0 Likes
1,480

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.

4 REPLIES 4
Read only

Former Member
0 Likes
868

Hi

Create a Variant for the Program and

Schedule JOB in background:

Go to SM36 create a Job

click on Start Condition

Click on DATE and TIME enter date scheduled Start and END times

click on Period Values

Click on HOURLY/WEEKLY etc

CLick on RESTRICTIONS also to use further criteria.

so your job will be scheduled and run as per your requirement.

and in SM37 Transaction check the status of that JOB

Check this link for scheduling jobs..

http://help.sap.com/saphelp_nw2004s/helpdata/en/c4/3a7f87505211d189550000e829fbbd/content.htm

Reward points for useful Answers

Regards

Anji

Read only

Former Member
0 Likes
868

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

Read only

Former Member
0 Likes
868

Hi

I could not make out what are you doing with the contents of in_file?

In other words, how do you conclude that this prg is not working in background.?

Regards

Raj

Read only

rainer_hbenthal
Active Contributor
0 Likes
868

You can not use gui functionality in batch programs cause there is no gui. You have to choose another place for your files and access them via open statement or with ftp functionality,