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

How to read a file IN BINARY MODE

Former Member
0 Likes
3,990

Hi all,

I've a file on the AL11 which I need to read in binary mode line by line.

I've did it but I cant reach to do line by line, when the read dataset sentence is executed it returns all the data contained in the file and, as there is any kind of character which can be used as separator I'm not able to know how to split it.

Does anybody know how to read only one line?

Thanks in advance,

Regards.

Hi thanks for your replies,

the split option is not valid because I've no mark to know when there is a end of line.

I were checking the refered link but any of my test worked, it allways returns all the data contained on the file, so which is the correct option to read only one line?

6 REPLIES 6
Read only

Former Member
0 Likes
1,931

Use SPLIT command for splitting the data.

Refer following code:

==================

  • Local data delaration.

DATA: v_string TYPE string.

  • Opening the file from the given location.

OPEN DATASET p_pathup FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc 0.

MESSAGE i000 WITH text-018.

LEAVE LIST-PROCESSING.

ENDIF.

  • File opened, Reading the contents and transfering to internal table.

DO.

READ DATASET p_pathup INTO v_string.

IF sy-subrc = 0.

SPLIT v_string AT c_sep

INTO w_upload-lifnr

w_upload-loevm_ven

w_upload-banksrec

w_upload-bankkrec

w_upload-banknrec

w_upload-loevm_rec

w_upload-waers

w_upload-bankssnd

w_upload-bankksnd

w_upload-loevm_snd

w_upload-chainno

w_upload-chainbankt

w_upload-chainbanks

w_upload-chainbankk

w_upload-chainbankn

w_upload-loevm_cor.

ELSE.

EXIT.

ENDIF.

APPEND w_upload TO i_upload.

CLEAR: w_upload,

v_string.

ENDDO.

  • Closing the file.

CLOSE DATASET p_pathup.

Let me know if you need any help on understanding the logic.

Regards

Read only

Former Member
Read only

Former Member
0 Likes
1,931

Hi thanks for your replies,

the split option is not valid because I've no mark to know when there is a end of line.

I were checking the refered link but any of my test worked, it allways returns all the data contained on the file, so which is the correct option to read only one line?

Read only

Former Member
0 Likes
1,931

Hi,

OPEN DATASET p_pathup FOR INPUT IN BINARY MODE ENCODING DEFAULT

give binary instead of text.

hope it'll help.

Regards,

Sneha.

Read only

Former Member
0 Likes
1,931

Yes Sneha,

but this instruction return all the data conteined on the file on a single execution, is there any option to read the data line by line as in the text mode?

Regards,

Read only

Former Member
0 Likes
1,931

When you open a file in binary mode, the system expects an unstructured sequence of bytes in the file. If you have fixed number of bytes in a line, then try using the MAXIMUM LENGTH addition while reading the file.

Why do you have to read the file in binary mode only?

Regards,

Susanta