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

Problem with READ DATASET when reading file from app server

0 Likes
4,025

Hi,

wondering if anyone can help, I'm using the following code to read from a file on app server, the file is of type .rtf

OPEN DATASET file_rtf FOR INPUT IN TEXT MODE

ENCODING DEFAULT

WITH SMART LINEFEED.

DO.

READ DATASET file_rtf INTO string.

IF SY-SUBRC = 0.

EXIT.

ENDIF.

ENDDO.

the open dataset part works sy-subrc = 0, but the read returns sy-subrc = 8 and no data is passed to string.

Any ideas as to what is causing this problem appreciated, <removed>

Thanks

Edited by: Thomas Zloch on Mar 17, 2010 3:57 PM - please don't offer p...

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,165

If you are reading an .RTF file, you should open it in binary mode. Not text mode.

What are you intending to use the file for?

You cannot open a true .RTF file and use it the way you use a regular text file. Either you should use a text file or open the rtf in binary mode and find a way to convert it to text. Try function SO_RTF_TO_RAW.

Hi,

wondering if anyone can help, I'm using the following code to read from a file on app server, the file is of type .rtf

OPEN DATASET file_rtf FOR INPUT IN TEXT MODE

ENCODING DEFAULT

WITH SMART LINEFEED.

DO.

READ DATASET file_rtf INTO string.

IF SY-SUBRC = 0.

EXIT.

ENDIF.

ENDDO.

the open dataset part works sy-subrc = 0, but the read returns sy-subrc = 8 and no data is passed to string.

Any ideas as to what is causing this problem appreciated, <removed>

Thanks

Edited by: Thomas Zloch on Mar 17, 2010 3:57 PM - please don't offer p...

14 REPLIES 14
Read only

Former Member
0 Likes
2,165

Hi Adam,

The source code in the below link has details about how to read/write to application server.

[Application server file operartions|http://www.divulgesap.com/blog.php?p=NDk=]

Please let us know if you have any issues.

Regards,

Ravi

Read only

vinod_vemuru2
Active Contributor
0 Likes
2,165

Hi,

I suspect that file has not been written to the server properly!

Can you try to download the file to presentation server using T-code CG3Y and see? If it is success here then just debug and see how SAP is handling. If it fails here also means that the file is not written properly.

Thanks,

Vinod.

Read only

0 Likes
2,165

Thanks for the swift response, unfortuantly I'm writing this program in BI so unable to use transaction cg3y, however, the file content looks as expected when previewed in al11

Read only

Former Member
0 Likes
2,165

data: lv_line type string.
OPEN DATASET file_rtf FOR INPUT IN TEXT MODE
ENCODING DEFAULT
WITH SMART LINEFEED.
 if sy-subrc eq 0.     "was open actually successful?
DO.
READ DATASET file_rtf INTO lv_line." string.
IF SY-SUBRC NE 0.  "exit when NOT EQUAL...
EXIT.
ENDIF.
ENDDO.
close dataset file_rtf.
endif.
 

Suggest you make these changes and retry...verify return code after open and after read.

Read only

0 Likes
2,165

Thanks breakpoint, I should have clarified, the open dataset statement is successful (sy-subrc = 0), bur the read dataset fails sy-subrc = 4.

F1 help states that this is because the end of file has been reached, so unsure why no data transferred to the string.

Read only

0 Likes
2,165

Hi Adam,

Looks like you are trying to transfer your data read from appl.server file into a variable of type string.Instead use a variable of type Character of length around 4000/8000 (which ever suits ur need) and re-run the code.

I think it should help.

Regards

Dedeepya

Read only

0 Likes
2,165

Thanks Dedeepya, have followed your advice, the read dataset still returns sy-subrc 4, but I now get a hexadecimal values off 200020002000.... at certain offset points.

Read only

Former Member
0 Likes
2,165

Hi Adam,

Is there any specific reason that you are using WITH SMART LINEFEED ? Can you just comment that part and use OPEN DATASET FOR INPUT ENCODING DEFAULT and check.

Read only

0 Likes
2,165

Thanks Asmita, with smart linefeed was added following Breakpoint input, removed and no change to read dataset which is the problem, the file opens successfully.

Read only

0 Likes
2,165

I have to wonder what an RTF file looks like if it's sitting on the APPS server? Probably isn't true RTF format anymore, is it? Maybe just gobbledy-gook now.

If something gets saved to APPS server, I'd want to be sure it was in tab- or comma-delimited or space delimited (fixed length) format, so that I could actually read it and work with it in an SAP program.

Can you have the file put back out as tab-delimted(.txt), or comma-separated-values (csv) or fixed length text (.txt) and try to read it that way?

Read only

Former Member
0 Likes
2,166

If you are reading an .RTF file, you should open it in binary mode. Not text mode.

What are you intending to use the file for?

You cannot open a true .RTF file and use it the way you use a regular text file. Either you should use a text file or open the rtf in binary mode and find a way to convert it to text. Try function SO_RTF_TO_RAW.

Read only

0 Likes
2,165

Thank for all your contributions, problem was to do with rtf format, so reverted to binary and rebuilt as text. Points awarded.

Read only

0 Likes
2,165

the question still shows unanswered. but that ok. can you just confirm if function SO_RTF_TO_RAW worked?

Read only

0 Likes
2,165

Getting errors when trying to close thread, will keep trying, thanks again. Oh and it worked!