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: 

Open dataset file length

Former Member
0 Kudos

Hi Friends,

I am uploading a file into SAP server and I would like to upload with 300 length char. ( I mean The file should contian 300 coloms)

where we can declare the length of the file?

Thanks,

Sridhar

2 REPLIES 2

rainer_hbenthal
Active Contributor
0 Kudos

write a string having exactly this length. Note that a string can have trailing blanks which will nox be cut off like in char variables.

0 Kudos

Hi Sridhar,

Define variable of type string or type CHAR(XXX), XXX should be equal or more than expected length of record.

Open dataset in text mode or binary mode.(prefer binary mode - if user will go to OS and see the file by double click prefer text mode so that it will get downloaded in readable format).

if dataset is opened successfully -

Loop at your internal table into string or defined variable .

Use transfer command to transfer each line.

Close the dataset.

Here goes some code:

DATA: lv_file1 TYPE string.

FIELD-SYMBOLS: <f_t_table> TYPE ANY.

lv_file1 = lfile_path.

IF im_binary_mode IS NOT INITIAL.

OPEN DATASET lv_file1 FOR OUTPUT IN BINARY MODE.

ELSE.

OPEN DATASET lv_file1 FOR OUTPUT IN TEXT MODE ENCODING DEFAULT .

ENDIF.

IF sy-subrc EQ 0.

LOOP AT t_table ASSIGNING <f_t_table> .

TRANSFER <f_t_table> TO lv_file1.

ENDLOOP.

CLOSE DATASET lv_file1.

  • MESSAGE s027(zdev) RAISING download_success.

ELSE.

MESSAGE e028(zdev) RAISING download_error.

ENDIF.

Now important thing:

Record with length more than 255 gets downloaded successfuly intext mode but when you try to read it via AL11, CG3Y, or with OPEN dataset- READ- write ..CLOSE dataset you can see only 255 character.

Dont worry about this.

AL11 and CG3Y is unable to display more than 255 char in text mode. if you are writing content of the file on list screen, use OFFSET, like WRITE: /01(500) lv_string.

write statement in AL11/cg3y doesnt have this offset in write so more than 255 length cant be seen.

I hope u get the answer and able to understand this solution.

Bless u.