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: 

Unicode I/O - Unbelievable?

Former Member
0 Kudos

In a Unicode System: You won't believe this. I open a dataset for output, transfer 1 record to a dataset, close the dataset. I then open the dataset for input and end up reading in 12 records. How, why?

How can this be? I'm using the exact same structure in my READ DATASET statements.

This is the macro I'm using for I/O:

OPEN DATASET &1

IN TEXT MODE

for &2

ENCODING default.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

When using Unicode use OPEN DATASET as:

open dataset DSN in text mode for output <b>encoding utf-8.</b>

See this for more reference:<a href="http://help.sap.com/saphelp_nw04/helpdata/en/79/c554dcb3dc11d5993800508b6b8b11/content.htm">Unicode</a>

Ps: Reward points if helpful.

4 REPLIES 4

Former Member
0 Kudos

Kenneth,

Its hard to believe that it has something to do with the Unicode system, like you are stressing. Would you be able to post the code here? I am sure it should be straight forward, however, doesn't harm chekcing it once.

Regards,

Ravi

0 Kudos

As requested, here is the code. I'm pretty sure this is unicode-related because this application has run successfully for years on multiple non-unicode instances. The only reason I'm changing it now is for Unicode upgrade.

All I do is open a file for output, write to the file, close the file, open for input and read it... but I get too many reads.

data : ctab(8192) occurs 0 with header line.

  • NOTE: CTAB IS FILLED FROM FUNCTION "TABLE_COMPRESS"

  • IT HAS ALWAYS WORKED PRE-UNICODE.

OPEN DATASET filelog-pathandfile

IN TEXT MODE

for output

ENCODING default.

  • CTAB HERE ONLY HAS 1 RECORD

LOOP AT ctab.

TRANSFER ctab TO filelog-pathandfile.

IF sy-subrc = 0.

ELSE.

EXIT.

ENDIF.

ENDLOOP.

close dataset filelog-pathandfile.

  • NOW OPEN AGAIN--- I PUT THIS IMMEDIATELY AFTER THE

  • CLOSE BECAUSE I WANTED TO PROVE IT DOESN'T WORK

  • NORMALLY, THESE STATEMENTS APPEAR IN

  • ANOTHER PROGRAM

OPEN DATASET filelog-pathandfile

IN TEXT MODE

for input

ENCODING default.

**

    • GOING THROUGH HERE, YIELDS ME 12 CTAB RECORDS.

    • I SHOULD ONLY GET 1.

**

do.

READ DATASET filelog-pathandfile INTO ctab-stuff.

IF sy-subrc NE 0.

EXIT.

ENDIF.

APPEND ctab.

CLEAR ctab.

enddo.

0 Kudos

I found my error. In my pre-Unicode code, I was not opening the dataset "in text mode." Thanks for all of your comments!

Former Member
0 Kudos

When using Unicode use OPEN DATASET as:

open dataset DSN in text mode for output <b>encoding utf-8.</b>

See this for more reference:<a href="http://help.sap.com/saphelp_nw04/helpdata/en/79/c554dcb3dc11d5993800508b6b8b11/content.htm">Unicode</a>

Ps: Reward points if helpful.