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: 

Getting Message as "File not open", when I ran background Job

Former Member
0 Kudos

Hi,

I developed a Migration Program, Which reads the data from Application serever and procced with further process in back ground mode.

Same program is workind fine in Development System in Back ground mode (SY-BATCH = 'X', Scheduled a batch Job). So I transported to Quality system.

Now When I run the program in background mode (SY-BATCH = 'X', Scheduled a batch Job), getting Message as "File is not Open" at Quality system. So I debugged the Batch job through "JDBG", and found file opening and reading the content sucessfully.

But its not working without debugging mode and getting message as "File not open".

Is there any Authorizations required for background mode (without debugging).

So can you please help me on this how to solve this issue.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

rajsekhar,

Please answer my following questions.

1. is there any extension in the file name you are providing? if yes, remove it, might help

2. are you using the same user id for foreground processing and background processing, (i dont think issue lies here)

3. Main Question are your app servers and central instance belong to same OS type? what i mean is: do you have combination of UNIX and WINDOWs for your app servers/central instance??

Please answer these

19 REPLIES 19

Former Member
0 Kudos

Can you please copy the code for reading file, please?

0 Kudos

***opening dataset for reading and preparing an internal table from the applciation server file.

OPEN DATASET p_fname FOR INPUT IN TEXT MODE ENCODING DEFAULT.

DO.

READ DATASET p_fname INTO ls_content.

IF sy-subrc EQ 0.

APPEND ls_content TO lt_content.

ELSE.

EXIT.

ENDIF.

CLEAR :ls_content.

ENDDO.

  • *Delete the entries, where the content is initial

DELETE lt_content WHERE content IS INITIAL.

*******closing dataset

CLOSE DATASET p_fname.

CATCH cx_root INTO gr_exception.

CALL METHOD gr_exception->get_text

RECEIVING

result = lv_msg.

FORMAT COLOR 6 ON.

WRITE:/ lv_msg.

FORMAT COLOR 6 OFF.

EXIT.

ENDTRY.

0 Kudos

There are some exceptions which can be caught and cannot be. try it like below. You can refer this good debate


OPEN DATASET p_fname FOR INPUT IN TEXT MODE ENCODING DEFAULT MESSAGE lv_message.
IF sy-subrc NE 0.
MESSAGE e000 WITH 'The reason was-' lv_message.
ENDIF.

0 Kudos

Please put a sy-subrc check after open dataset so as to know whether the file was opened sucessfully or some authorization issue in background.

thanks

Nabheet

Former Member
0 Kudos

rajsekhar,

Please answer my following questions.

1. is there any extension in the file name you are providing? if yes, remove it, might help

2. are you using the same user id for foreground processing and background processing, (i dont think issue lies here)

3. Main Question are your app servers and central instance belong to same OS type? what i mean is: do you have combination of UNIX and WINDOWs for your app servers/central instance??

Please answer these

0 Kudos

Hi Sowmyaprakash,

Please find my answers below.

1. is there any extension in the file name you are providing? if yes, remove it, might help

While writing data on Application server , upload ed file with text.txt

2. are you using the same user id for foreground processing and background processing, (i dont think issue lies here)

Yes using same User ID

3. Main Question are your app servers and central instance belong to same OS type? what i mean is: do you have combination of UNIX and WINDOWs for your app servers/central instance??

its UNIX not with other OS.

0 Kudos

take out the .txt ,it will work(might)

0 Kudos

Hi Soumya,

Tried as per your suggestion but still problem is there.

Kindly find below result, which i received in Spool.

The file '/usr/sap/tmp/DR_APAC_07122011' is not open

Total no of records = 0

Total no of success records = 0

Total no of error records = 0

Success file is empty. File Not downloaded

Error file is empty. File Not downloaded

But when I debug through JDBG, its working properly.

Edited by: Rajasekhar Reddy P on Dec 7, 2011 3:30 PM

0 Kudos

Might sound silly. Introduce a wait upto few seconds before the open dataset statement and check if it is working.


WAIT UPTO 2 SECONDS. 

Vikranth

0 Kudos

and what is the EXACT file name in OS?

is there any lower case upper case values there?

just check p_fname value in both foreground mode and background mode... are they both having similar CASEs in both mode?

see, in OS if you have ABCD.TXT then p_file should also contain ABCD.TXT (which, i recomend not to add extensions)

in OS if you have Abcd, then p_file should also contaon Abcd.

like that...

0 Kudos

Hi Vikranth,

Yes its silly.

May i know wat is the use if I keep WAIT UP TO 2 Sec before OPEN DATA SET.

Can U pls tell me.

0 Kudos

Hi Soumya,

Checked its coming as per naming. No Problem With UPPER/LOWER cases.

0 Kudos

dont mind but please post the file name...

OS level full path:

p_fname in foreground mode just before read dataset

p_fname is backgrounb(pass a system message of type 'S' at this point with value p_fname, you can get the p_fname value in the job log.):

0 Kudos

Did you try what i said ?. It will give you the full proof message why it was not opened.

0 Kudos

Hi Keshav,

here am catching the exceptions right.

it means it will return the exact errro I hope.

TRY.

***opening dataset for reading and preparing an internal table from the applciation server file.

OPEN DATASET p_fname FOR INPUT IN TEXT MODE ENCODING DEFAULT .

DO.

READ DATASET p_fname INTO ls_content.

IF sy-subrc EQ 0.

APPEND ls_content TO lt_content.

ELSE.

EXIT.

ENDIF.

CLEAR :ls_content.

ENDDO.

  • *Delete the entries, where the content is initial

DELETE lt_content WHERE content IS INITIAL.

*******closing dataset

CLOSE DATASET p_fname.

CATCH cx_root INTO gr_exception.

CALL METHOD gr_exception->get_text

RECEIVING

result = lv_msg.

FORMAT COLOR 6 ON.

WRITE:/ lv_msg.

FORMAT COLOR 6 OFF.

EXIT.

ENDTRY.

From thsi only am getting Message as "File XXXXXXXXXXXXX is open'.

Edited by: Rajasekhar Reddy P on Dec 7, 2011 4:38 PM

0 Kudos

here am catching the exceptions right.

it means it will return the exact errro I hope.

Read the link which i mentioned for better understanding. Try it once and come back

kesav

0 Kudos

Hi Keshav,

After Open Data Set used if Sy-Subrc NE 0 endif and after that used READ DATA SET now its working in back ground.

Still am not understanding wat happend and how its working. If u kno wthe reason can u pls explain that.

thanks for your help

0 Kudos

Try this code:

DATA: PATH_NAME(80) TYPE C,

LV_FILENAME TYPE STRING.

DATA: LW_XSTRING TYPE XSTRING,

X_LEN TYPE I.

DATA: FILE_AUTH_ERR TYPE REF TO CX_SY_FILE_AUTHORITY,

FILE_OPEN_ERR TYPE REF TO CX_SY_FILE_OPEN,

FILE_OPEN_MODE_ERR TYPE REF TO CX_SY_FILE_OPEN_MODE,

FILE_CLOSE_ERR TYPE REF TO CX_SY_FILE_CLOSE,

FILE_CONVERSION_ERR TYPE REF TO CX_SY_CONVERSION_CODEPAGE,

FILE_TOO_MANY_ERR TYPE REF TO CX_SY_TOO_MANY_FILES,

MESS TYPE STRING,

W_TEXT TYPE STRING.

DATA: L_RC TYPE INT4.

concatenate pathname lv_filename into lv_filename.

TRY.

OPEN DATASET LV_FILENAME FOR INPUT IN BINARY MODE MESSAGE MESS.

CATCH CX_SY_FILE_OPEN_MODE INTO FILE_OPEN_MODE_ERR.

W_TEXT = FILE_OPEN_MODE_ERR->GET_TEXT( ).

L_RC = 1.

CATCH CX_SY_FILE_AUTHORITY INTO FILE_AUTH_ERR.

W_TEXT = FILE_AUTH_ERR->GET_TEXT( ).

L_RC = 2.

CATCH CX_SY_CONVERSION_CODEPAGE INTO FILE_CONVERSION_ERR.

L_RC = 3.

W_TEXT = FILE_CONVERSION_ERR->GET_TEXT( ).

CATCH CX_SY_TOO_MANY_FILES INTO FILE_TOO_MANY_ERR.

L_RC = 4.

W_TEXT = FILE_TOO_MANY_ERR->GET_TEXT( ).

CATCH CX_SY_FILE_OPEN INTO FILE_OPEN_ERR. "File already open

L_RC = 5.

W_TEXT = FILE_OPEN_ERR->GET_TEXT( ).

ENDTRY.

IF L_RC = 0.

L_RC = SY-SUBRC.

ENDIF.

IF L_RC <> 0 OR SY-SUBRC NE 0.

  • Issue Error message in open file.

CONCATENATE MESS 'Open dataset failed' w_text INTO MESS SEPARATED BY SPACE.

message Exx(yyy) with mess.

ELSE. "file exists and can be opened

ENDIF.

Former Member
0 Kudos

I doubt if the problem is in reading the file; it is in how p_fname is declared. If there are any lower case letters in the file name, it must be declared as:

PARAMETERS: f_name TYPE string LOWER CASE    "   or CHAR...

Rob