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: 

regarding Open dataset

Former Member
0 Kudos

I have two questionshere.

1-i want create text file in Application server.

in below directory is it possible.

E_FILE LIKE RLGRAP-FILENAME VALUE

'DIR_HOME\payhome.txt'.

(does my path will create file in this virtual direcotry)

2-for each loop i want to write one line

in text file.

should i have to include delimeter while transfer data to file or write to file.

my below piece of code is correct?

DATA E_FILE LIKE RLGRAP-FILENAME VALUE

'DIR_HOME\payhome.txt'.

OPEN DATASET E_FILE FOR OUTPUT IN TEXT MODE.

LOOP AT ITAB_LIFNR.

PERFORM LISTDATA.

ENDLOOP.

CLOSE DATASET E_FILE.

In PERFORM LISTDATA.

....................

WRITE : / PAGENO,

SUBNO,

DATAKBN,

ITAB_LIFNR-LIFNR,

ITAB_LIFNR-NAME2(20),

P_PAY_T,

GLT0-TSL01,

GLT0-TSL02,

GLT0-TSL03,

GLT0-TSL04,

GLT0-TSL05 TO E_FILE.

......................

ENDFORM.

ambichan

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hello Ambichan,

Here are the answers to your questions -

1. DIR_HOME is called a <i>logical filename</i>. The OPEN DATASET expects a <i>physical finename</i>. If you go to AL11, you will be able to see the physical filename that is associated with this logical filename.

SAP has provided the concept of a logical filename to make the filenames platform-independent. You should use the Function Module FILE_GET_NAME to get the physical filename. This FM has a detailed documentation. You can go through that. It also has an example.

2. If you want to write one line for each of the entries of an internal table, you would do something like this....

START-OF-SELECTION.

OPEN DATASET <fname>.

LOOP AT ITAB.
  PERFORM TRANSFER_ITAB_DATA_TO_FILE.
ENDLOOP.

CLOSE DATASET <fname>.

FORM TRANSFER_ITAB_DATA_TO_FILE.
  TRANSFER ITAB-FIELD1 TO FILE.
  TRANSFER ITAB-FIELD2 TO FILE.   
  .
  .
  .
ENDFORM.

Now, whether you want to have a delimiter is something that you should decide, based on your requirement. But, in general, there would be a delimiter of some kind.

Regards,

Anand Mandalika.

5 REPLIES 5

former_member214131
Active Contributor
0 Kudos

Hello,

Please use Transfer dataset instead of Write...

Please refer to SAP online help for more variants.

Hope this helps you...

Regards, Murugesh AS

0 Kudos

Hey murugesh,

thanks for your reply.

should i have to include any delimiter while writing datas in text file?

if so whats that delimter(tab/,/space?)

how can i include one empty line in text file.

could you pls guide me.

ambichan.

0 Kudos

Hello,

Please read thro' the complete documentation,

You do have options for:

OPEN DATASET <dsn> IN BINARY MODE [FOR ....].

OPEN DATASET <dsn> FOR .... IN TEXT MODE.

You can use these as per your reqmt. This is similar to the option 'DAT' and 'TXT in WS_UPLOAD / WS_DOWNLOAD. Hope this helps you.

Regards, Murugesh AS

0 Kudos

Use a tab delimiter:

CONSTANTS: LIT_TAB_CHAR TYPE X VALUE '09'.
...
...
DATA: BEGIN OF GSTR_MATERIAL,
        MATNR LIKE MARA-MATNR,
        TAB01 LIKE LIT_TAB_CHAR,
        MAKTG LIKE MAKT-MAKTG,
      END OF GSTR_MATERIAL.

...
...
* now transfer your internal table
OPEN DATASET PC_FILEPATH FOR OUTPUT IN TEXT MODE.

LOOP AT ITAB_MATERIAL.
  TRANSFER ITAB_MATERIAL TO PC_FILEPATH.
ENDLOOP.

Former Member
0 Kudos

Hello Ambichan,

Here are the answers to your questions -

1. DIR_HOME is called a <i>logical filename</i>. The OPEN DATASET expects a <i>physical finename</i>. If you go to AL11, you will be able to see the physical filename that is associated with this logical filename.

SAP has provided the concept of a logical filename to make the filenames platform-independent. You should use the Function Module FILE_GET_NAME to get the physical filename. This FM has a detailed documentation. You can go through that. It also has an example.

2. If you want to write one line for each of the entries of an internal table, you would do something like this....

START-OF-SELECTION.

OPEN DATASET <fname>.

LOOP AT ITAB.
  PERFORM TRANSFER_ITAB_DATA_TO_FILE.
ENDLOOP.

CLOSE DATASET <fname>.

FORM TRANSFER_ITAB_DATA_TO_FILE.
  TRANSFER ITAB-FIELD1 TO FILE.
  TRANSFER ITAB-FIELD2 TO FILE.   
  .
  .
  .
ENDFORM.

Now, whether you want to have a delimiter is something that you should decide, based on your requirement. But, in general, there would be a delimiter of some kind.

Regards,

Anand Mandalika.