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 to Upload text file

Former Member
0 Kudos

Hi, experts,

I have created a program to upload text file to ztable using network path. It is working fine.

But when I execute it in back ground (SM36). It gives error

like below.

Cannot perform frontend function in batch input mode

Job cancelled after system exception ERROR_MESSAGE

Any one can help me on this

My code is:

REPORT ZSMS.

PARAMETERS: P_FILE LIKE RLGRAP-FILENAME.

DATA: BEGIN OF IT_SMS OCCURS 0,

TEXT(100),END OF IT_SMS.

data: wa_sms like zsms.

*P_FILE = '
192.168.104.36\sms\SMS.TXT'.

*Check file on the system

DATA:LV_FILE TYPE STRING, " Filename

LV_RESULT TYPE FLAG. " Result: file exists

LV_FILE = P_FILE.

CLEAR LV_RESULT.

*CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_EXIST

  • EXPORTING

  • FILE = LV_FILE

  • RECEIVING

  • RESULT = LV_RESULT.

CALL FUNCTION 'TMP_GUI_GET_FILE_EXIST'

EXPORTING

FNAME = p_file

IMPORTING

EXIST = LV_RESULT.

**Upload file contents to SAP Ztable

IF LV_RESULT EQ 'X'.

REFRESH IT_SMS.

  • CALL FUNCTION 'WS_UPLOAD'

  • EXPORTING

  • FILENAME = P_FILE

  • FILETYPE = 'DAT'

  • TABLES

  • DATA_TAB = IT_SMS.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = '
192.168.104.36\sms\SMS.TXT'

TABLES

DATA_TAB = IT_SMS

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

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

IF SY-SUBRC Eq 0.

write:/01 'file picked'.

DATA: MDOC LIKE ZSMS-DOCNO.

SELECT MAX( DOCNO ) INTO MDOC FROM ZSMS.

ADD 1 TO MDOC.

LOOP AT IT_SMS.

wa_SMS-DOCNO = MDOC.

wa_SMS-fld1 = it_sms-text.

INSERT ZSMS FROM wa_SMS.

add 1 to mdoc.

ENDLOOP.

write:/01 'inserted to table'.

wait up to 1 SECONDS.

  • CALL FUNCTION 'WS_FILE_DELETE'

  • EXPORTING FILE = P_FILE.

ENDIF.

ENDIF.

Regards

Rajiv singh

5 REPLIES 5

GauthamV
Active Contributor
0 Kudos

hi,

you cannot run programs in background mode if you have used Gui function modules like gui_upload or gui_download...

Former Member
0 Kudos

Thanks for reply.

Is there another function, through which I can Upload file using background process.

Rajiv singh.

GauthamV
Active Contributor
0 Kudos

you can access data in background mode when data is present in Application server...

for uploading to application server you can use read dataset,transfer dataset.....

or CG3Z transaction.

you can access data in foreground mode when data is present in Application server and Presentation server.

so accordingly upload the data from either of the servers..

Former Member
0 Kudos

Hi Rajiv ,

Generally what we do is save the file in the application server if the program is to be run in background and once the execution is complete read the file and save it to the local drive.

Regards

Arun

Former Member
0 Kudos

Hi Rajiv,

Check out the following links:

Regards,

Prashant.