Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Background Job to Upload text file

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

Tags:

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question