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

Reg: Transferring data from internal table to Application server

Former Member
0 Likes
1,496

Hi Experts,

How do i transfer data from internal table to a file in application server without using open dataset, close dataset.

Regards

Naveen

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,077

TABLES: BSEG.

*

*DATA: BEGIN OF INT_TAB OCCURS 1000.

  • INCLUDE STRUCTURE BSEG.

*DATA: END OF INT_TAB.

*

*DATA:W_DATASET(50) VALUE '/USERS/TESTDAT.TXT'.

*

*SELECT * FROM BSEG INTO TABLE INT_TAB WHERE GJAHR = '1996'.

*

*

*

*OPEN DATASET W_DATASET FOR OUTPUT IN TEXT MODE.

*LOOP AT INT_TAB.

  • TRANSFER INT_TAB TO w_dataset.

*ENDLOOP.

*CLOSE DATASET W_DATASET.

6 REPLIES 6
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,077

JUst use FM GUI_DOWNLOAD and try...i guess it will throw a error

since no FM resides in the application server..its not possible i think...Open data sets work fine in this case..

Read only

Former Member
0 Likes
1,077

You have no option other than OPENDATA SET to store the data of your internal table to your appl server.

Regards,

Madan.

Read only

Former Member
0 Likes
1,077

Hi ,

I guess it wont work if you dont use Open Dataset.

To write data to a file on the application server, use the TRANSFER statement:

Syntax

TRANSFER <f> to <dsn> [LENGTH <len>].

This statement writes the values of the field <f> into the file <dsn>. You can specify the transfer mode in the OPEN DATASET statement. If you have not already opened the file for writing, the system tries to open it either in binary mode, or using the additions from the last OPEN DATASET statement. However, it is good practice only to open files using the OPEN DATASET statement. For further information about the OPEN DATASET statement and the naming conventions for files, refer to Opening a File. <f> can have an elementary data type, but may also be a structure, as long as it does not contain an internal table. You cannot write internal tables into files in a single step.

You can specify the length of the data you want to transfer using the LENGTH addition. The system then transfers the first <len> bytes into the file. If <len> is too short, excess bytes are truncated. If <len> is greater than the length of the field, the system adds trailing blanks.

The following program shows how you can write internal tables into a file:

DATA FNAME(60) VALUE 'myfile'.

TYPES: BEGIN OF LINE,

COL1 TYPE I,

COL2 TYPE I,

END OF LINE.

TYPES ITAB TYPE LINE OCCURS 10.

DATA: LIN TYPE LINE,

TAB TYPE ITAB.

DO 5 TIMES.

LIN-COL1 = SY-INDEX.

LIN-COL2 = SY-INDEX ** 2.

APPEND LIN TO TAB.

ENDDO.

OPEN DATASET FNAME FOR OUTPUT.

LOOP AT TAB INTO LIN.

TRANSFER LIN TO FNAME.

ENDLOOP.

CLOSE DATASET FNAME.

OPEN DATASET FNAME FOR INPUT.

DO.

READ DATASET FNAME INTO LIN.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

WRITE: / LIN-COL1, LIN-COL2.

ENDDO.

CLOSE DATASET FNAME.

The output is:

1 1

2 4

3 9

4 16

5 25

In this example, a structure LIN and an internal table TAB with line type LINE are created. Once the internal table TAB has been filled, it is written line by line into the file "myfile". The file is then read into the structure LIN, whose contents are displayed on the screen.

Reward If Helpfull,

Naresh.

Read only

Former Member
0 Likes
1,078

TABLES: BSEG.

*

*DATA: BEGIN OF INT_TAB OCCURS 1000.

  • INCLUDE STRUCTURE BSEG.

*DATA: END OF INT_TAB.

*

*DATA:W_DATASET(50) VALUE '/USERS/TESTDAT.TXT'.

*

*SELECT * FROM BSEG INTO TABLE INT_TAB WHERE GJAHR = '1996'.

*

*

*

*OPEN DATASET W_DATASET FOR OUTPUT IN TEXT MODE.

*LOOP AT INT_TAB.

  • TRANSFER INT_TAB TO w_dataset.

*ENDLOOP.

*CLOSE DATASET W_DATASET.

Read only

Former Member
0 Likes
1,077

Hi Naveen,

I have got a very simple procedure for that.

First download the flat file into a file in presentation server using GUI_DOWNLOAD.

Then using the tcode CG3Z you can put that file into the application server . You just need to give the source and destination file names in that tcode.

Reward if useful.

Thanks,

Khan.

Read only

0 Likes
1,077

very good khan

cheers

uday