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

read a file from application server

SwarnaliBasu
Participant
0 Likes
3,361

HI

i want to read a file from application server using read dataset. for that i have written the code as




select * from zbdclog INTO CORRESPONDING FIELDS OF TABLE i_bdclog

where RICEFID = p_ricef

and username = p_user.

if sy-subrc = 0.

loop at i_bdclog into wg_bdclog.

fname = wg_bdclog-filepath.

OPEN DATASET fname FOR output IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc = 0.

READ DATASET fname INTO wg_bdclog1-filepath.

append wg_bdclog1 to i_bdclog1.

ENDIF.

CLOSE DATASET fname.

endloop.

endif.

can anyone tell me where is the problem as the values of sy-subrc = 8, so its not getting inside the loop.

28 REPLIES 28
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,610

Hello Swarnali.

select * from zbdclog INTO CORRESPONDING FIELDS OF TABLE i_bdclog
where RICEFID = p_ricef
and username = p_user.
IF sy-subrc = 0.
* Do porcessing
ENDIF.

If this sy-subrc is failing goto SE16 & check if there is any data in the table zbdclog for

RICEFID = p_ricef and username = p_user

BR,

Suhas

Read only

former_member404244
Active Contributor
0 Likes
2,610

HI,

Check the data base table for the entries

AS u want to read the data from application server u need to write like this

OPEN DATASET <DATASET NAME> for INPUT in text mode endoing default.

OUTPUT->To write into the application server

INPUT->To read from application server.

Regards,

Nagaraj

Read only

Former Member
0 Likes
2,610

Hi,

Please check if there are any corresponding records available for your input that you have used in the select query i.e the ricefid and username.

And moreover, to read data from the application server, you use something like this


OPEN DATASET P_FNAME2 FOR INPUT IN BINARY MODE.
  READ DATASET P_FNAME2 INTO WA_SALESDETAILS.
  APPEND WA_SALESDETAILS TO T_SALESDETAILS.
  CLEAR WA_SALESDETAILS.
CLOSE DATASET P_FNAME2.

Edited by: Nitwick on Aug 17, 2009 2:50 PM

Read only

Former Member
0 Likes
2,610

Hi,

Check in table zbdclog whether any entries exist matching values of p_ricef and p_user.

Regards,

Ankur Parab

Read only

0 Likes
2,610

Hi,

I think there is a problem in ur select query... ur saying select * and putting those in CORRESPONDING FIELDS..... Check the declaration or ur internal table..

AND

Check the declaration of the field FNAME

DATA : FNAME TYPE STRING.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
2,610

You can use transaction CG3Y

Read only

SwarnaliBasu
Participant
0 Likes
2,610

hi

i have checked, records are available, the second sy-subrc is failing, i,e. its not going to read dataset

Regards

Swarnali

Read only

0 Likes
2,610

Also check whether you have authorization for reading,writing etc

Read only

0 Likes
2,610

Hi,

Do you want to read data from the application server. Then you gotto use the syntax

OPEN DATASET P_FNAME FOR INPUT IN BINARY MODE.

OUTPUT is for writing data into application server. Your file wouldnt have been existing in the application server. So it is possibly returning a 8 for the sy-subrc.

Read only

former_member404244
Active Contributor
0 Likes
2,610

HI,

Did u try to change ur code as i suggested

AS u want to read the data from application server u need to write like this

OPEN DATASET <DATASET NAME> for INPUT in text mode endoing default.

OUTPUT->To write into the application server

INPUT->To read from application server.

Regards,

Nagaraj

Read only

SwarnaliBasu
Participant
0 Likes
2,610

hi

even if i use FOR INPUT , still i am getting this error, please help

Read only

0 Likes
2,610

Hi,

After the select statement, check if i_bdclog -filepath has a valid application server file path.

Read only

Former Member
0 Likes
2,610

Hi,

Change the open dataset statement and check


OPEN DATASET fname FOR output IN TEXT MODE ENCODING DEFAULT.   "previous

to


OPEN DATASET fname FOR INPUT IN TEXT MODE ENCODING DEFAULT.  "corrected

Regards,

Vik

Read only

0 Likes
2,610

hi

i used for input , still the sy-subrc value is 8 just before the read dataset

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,610

Hello,

Quick check if the filepath exists in AL11. If yes, then go to the next lines

Just before the OPEN DATASET statement you can call the auth. obj S_DATASET (or the FM: AUTHORITY_CHECK_DATASET).

I think you donot have the access to read/write files from the folder.

BR,

Suhas

Edited by: Suhas Saha on Aug 17, 2009 11:31 AM

Read only

0 Likes
2,610

Hi,

Check the mode in which you are trying to open the file. Please do a F1 on the modes. See if it works with BINARY MODE. As suggested, try to use ENCODING DEFAULT addition to the OPEN DATASET.

Read only

Former Member
0 Likes
2,610

Use

OPEN DATASET fname FOR INPUT IN TEXT MODE ENCODING DEFAULT.

Read only

SwarnaliBasu
Participant
0 Likes
2,610

HI

i have used IN BINARY MODE as well as i checked whether it has a valid filepath, but still i m getting the sy-subrc = 8.

Read only

SwarnaliBasu
Participant
0 Likes
2,610

hi

before this i have used to create a file in application server and it worked fine so i think i have the authrosation, this is nt the problem, any other advice?

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,610

>

> hi

> before this i have used to create a file in application server and it worked fine so i think i have the authrosation, this is nt the problem, any other advice?

Hello,

Did you create the file in the same folder as the one you are trying to access?

If YES, please check if you have READ access to the file.

AUTHORITY-CHECK OBJECT 'S_DATASET'
             ID 'PROGRAM'  FIELD SY-REPID
             ID 'ACTVT'    FIELD '33'    "33 -> Read Access
             ID 'FILENAME' FIELD <your filepath>
             
             CHECK sy-subrc IS INITIAL.

Please note that an F1 on OPEN DATASET FOR INPUT says if the file does not exist the sy-subrc is set to 8.

BR,

Suhas

Read only

0 Likes
2,610

Hi,

The F1 help says if the sy-subrc eq 8 then the operating system was not able to open the file.

Possibly,

The file does not exist in the application server. Please check if it does, in the application server. You may use the FM 'FILE_GET_NAME_USING_PATH' to get the file path or in the AL11 directory. Just a check if the file does exist on the application server.

You might possibly not have the necessary authorizations to read data from the file. There are no catchable exceptions if this is the case.

Read only

0 Likes
2,610

hi

i checked the authorisation , at tht point of time sy-subrc = 0 then it shows that it has authorisation , so that is not a problem, this file is a filepath from the table zbclog it has no relation with the filepath i had created before.

the issue is it will fetch the filepath from table zbdclog and read tht file from the application server, which is created through this custom table.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,610

>

> hi

> i checked the authorisation , at tht point of time sy-subrc = 0 then it shows that it has authorisation , so that is not a problem, this file is a filepath from the table zbclog it has no relation with the filepath i had created before.

>

> the issue is it will fetch the filepath from table zbdclog and read tht file from the application server, which is created through this custom table.

Hello Swarnali,

This means that we can eliminate the authorisation as a potential issue.

If you read my previous post you can see that from SAP documentation if READ DATASET FOR INPUT has sy-subrc = 8 => that the file does not exist.

I think that this must be the issue.

BR,

Suhas

Read only

former_member585060
Active Contributor
0 Likes
2,610

Hi,

Try as below


SELECT * FROM zbdclog INTO CORRESPONDING FIELDS OF TABLE i_bdclog
WHERE ricefid = p_ricef
AND username = p_user.

IF sy-subrc = 0.
LOOP AT i_bdclog INTO wg_bdclog.
fname = wg_bdclog-filepath.

OPEN DATASET fname FOR INPUT IN TEXT MODE ENCODING DEFAULT.  " It must be INPUT not OUTPUT, to read file we use INPUT
IF sy-subrc NE 0.             " To create file on App Server we use OUTPUT
EXIT.
ENDIF.

DO.
CLEAR wg_bdclog1.
READ DATASET fname INTO wg_bdclog1-filepath.

IF sy-subrc NE 0.
EXIT.
ELSE.
APPEND wg_bdclog1 to i_bdclog1.
ENDIF.

ENDDO.
CLOSE DATASET fname.
ENDLOOP.
ENDIF.

Regards

Bala Krishna

Edited by: Bala Krishna on Aug 17, 2009 3:14 PM

Read only

Former Member
0 Likes
2,610

Hi,

I think CLOSE DATASET needs to be given after the loop.

select * from zbdclog INTO CORRESPONDING FIELDS OF TABLE i_bdclog

where RICEFID = p_ricef

and username = p_user.

if sy-subrc = 0.

loop at i_bdclog into wg_bdclog.

fname = wg_bdclog-filepath.

OPEN DATASET fname FOR output IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc = 0.

READ DATASET fname INTO wg_bdclog1-filepath.

append wg_bdclog1 to i_bdclog1.

ENDIF.

endloop.

endif.

CLOSE DATASET fname.

Rgds,

Sripal

Read only

Former Member
0 Likes
2,610

Hi,

You can first validate the application server path if it exists or not,

data: l_file type tpfht-pffile.

clear l_file.

l_file = p_file. " In p_file the paaplicn server path entered by the user is captured

Then Call function PFL_CHECK_OS_FILE_EXISTENCE which will validate your

application server path.

It will return in its importing parameter one variable having value

'X' means the file exists or space that is it does not exists.

On its value 'X', then we can use OPEN DATASET statement that is,

OPEN DATASET L_FILE FOR INPUT IN TEXT MODE ENCODING DEFAULT.

Hope it helps

Regards

Mansi

Read only

swaroop_g2
Explorer
0 Likes
2,610

Hi,

OPEN DATASET <path variable> IN TEXT MODE FOR OUTPUT ENCODING DEFAULT.

IF sy-subrc EQ 0.

    • Write the contents in to the Application Server

LOOP AT it_download.

TRANSFER < Internal table > TO <Path Variable>

ENDLOOP.

ENDIF.

CLOSE DATASET <Path Vairable>

Read only

SwarnaliBasu
Participant
0 Likes
2,610

solved,points given