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

Doubt in Open Dataset

Former Member
0 Likes
1,720

Hi Abapers,

I am wrote the syntax for open dataset like below.

OPEN DATASET P_FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

First I declare p_file as a Character type, at that time the sy-subrc value returns 8.

I changed p_file type as String ven though the sy-subrc value returns 8.

Means the p_file is not opened/created.

Please suggest me how to do this.

Thanks in Advance.

Thanks and Regards

AbinavaSiri..

Hi Abapers,

I am wrote the syntax for open dataset like below.

OPEN DATASET P_FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

First I declare p_file as a Character type, at that time the sy-subrc value returns 8.

I changed p_file type as String ven though the sy-subrc value returns 8.

Means the p_file is not opened/created.

Please suggest me how to do this.

Thanks in Advance.

Thanks and Regards

AbinavaSiri..

16 REPLIES 16
Read only

Former Member
0 Likes
1,690

declare the file type as RLGRAP-FILENAME.

DATA: P_FILE TYPE RLGRAP-FILENAME.

OPEN DATASET P_FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,690

Look at [File Interface |http://help.sap.com/erp2005_ehp_03/helpdata/EN/79/c554dcb3dc11d5993800508b6b8b11/frameset.htm]

Regards

Read only

Former Member
0 Likes
1,690

use l_upfile TYPE char50,

v_message(255) TYPE c,

and

OPEN DATASET l_upfile FOR OUTPUT IN TEXT MODE ENCODING DEFAULT

MESSAGE v_message.

Reward point if helpful

Read only

Former Member
0 Likes
1,690

hiiiii

just use like

DATA FNAME(60) VALUE 'myfile'.

OPEN DATASET FNAME FOR OUTPUT in text mode encoding default.
LOOP AT TAB INTO LIN.
  TRANSFER LIN TO FNAME.
ENDLOOP.
CLOSE DATASET FNAME.

declare & use like this..it should work.

regards

twinkal

Read only

Former Member
0 Likes
1,690

Hi,

PARAMETERS: APPPATH LIKE RLGRAP-FILENAME

*open the file on the application server for reading data...
  OPEN DATASET APPPATH FOR INPUT IN TEXT MODE ENCODING DEFAULT.
  IF SYST-SUBRC NE 0.
    WRITE: / 'There was an error opening the file in input mode:',
      SKIP 2.
    WRITE: / 'Please check that the file and directory exists',
    'on the application server:', SYST-HOST.
    STOP.
  ENDIF.

In your case define:

P_FILE LIKE RLGRAP-FILENAME

Regards

Adil

Read only

0 Likes
1,690

Hi Abdul,

Thanks for your reply.I have one doubt.

In the application server there is no P_FILE.

We have one file in presentation server, we transfer that file from here to application server.

Please help.

Thanks and Regards,

Siri.

Read only

Former Member
0 Likes
1,690

parameters:

out_file like rlgrap-filename default

'<xxxxxxxxxxxxxxxxxxx/xxxx.txt>'

open dataset out_file for output in text mode

ENCODING DEFAULT.

rlgrap-filename is char field of size 128

I trust it works...

Read only

Former Member
0 Likes
1,690

parameters:

out_file like rlgrap-filename default

'<xxxxxxxxxxxxxxxxxxx/xxxx.txt>'

open dataset out_file for output in text mode

ENCODING DEFAULT.

rlgrap-filename is char field of size 128

I trust it works...

Read only

Former Member
0 Likes
1,690

Hi Sri,

There should be no problem with the p_file type if it is declared as string. It is works fine.

Just check whether yopu have mentioned the file path in that string.

i.e., p_file = './<filename>.

Hope this helps you.

Regards,

Chandra Sekhar

Read only

Former Member
0 Likes
1,690

Hi,

use the syntax like this.

Data: p_file(120).

open dataset p_file for output / appending in binary / text mode.

(If the dataset p_file already exists then use appending other wise use for output).

loop at itab.

transfer itab to p_file.

(In binary mode it writes the length of the field to the dataset. In text mode it writes one line to the dataset).

endloop.

close dataset p_file.

Reward if helpful.

Read only

0 Likes
1,690

Hi lakshmi,

I did the same.But the problem is, After Open Dataset the sy-subrc value returns 8.

I dont know why this thing is happening.

Please help.

Thanks and Regards

Abinavasiri.

Read only

0 Likes
1,690

please ref the above my post.

declare the filetype as rlgrap-filename.

just check the sy-subrc ,

data: p_file type rlgrap-filename.

p_file = '/sap/tmp/testfile.txt'.

OPEN DATASET P_FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

break-point.

Read only

Former Member
0 Likes
1,690

Hi,

Upload the file contents which is at presentation server to an internal table.

Then create a file at application server using OPEN DATASET . Then loop at that internal table and transfer the contents to that file .

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = W_FNAME

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

HEADER_LENGTH = 0

READ_BY_LINE = 'X'

DAT_MODE = ' '

CODEPAGE = ' '

IGNORE_CERR = ABAP_TRUE

REPLACEMENT = '#'

IMPORTING

FILELENGTH =

HEADER =

tables

data_tab = T_BKPF.

  • Opening a file to write data

OPEN DATASET w_fname

FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

  • Transfering data to file using TRANSFER statement

LOOP AT t_line INTO fs_line.

TRANSFER fs_line TO w_fname.

ENDLOOP.

close dataset w_fname.

Read only

Former Member
0 Likes
1,690

Hi abhinava siri,

Take declare

w_fname Type string.

It will not give any error.

Read only

Former Member
0 Likes
1,690

NO need to write any program for this USE Tcode CG3Z ,

give the presentation file and the Application server file path, and upload the data.

Read only

Former Member
0 Likes
1,690

Hi abinave,

PARAMETERS: P_FILE LIKE RLGRAP-FILENAME
 
*open the file on the application server for reading data...
  OPEN DATASET P_FILE FOR INPUT IN TEXT MODE ENCODING DEFAULT.
  IF SYST-SUBRC NE 0.
    WRITE: / 'There was an error opening the file in input mode:',
   ENDIF.
* read the file and populate the data to an internal table
   READ DATASET P_FILE INTO <WA>
* close the file
  CLOSE DATASET P_FILE.

p_file is a parameter, here enter the file path which is at application server

Reward if usefull

Adil