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

download data from internal table to application server

Former Member
0 Likes
989

hi

when i tranfer the data in the internal table to application server file..only one line is getting tranfered. i want to transfer all the lines to a file and display it line after a line in the file.

could u plz give me the solution? if u can send me a sample code,itwill be more helpful.

Thanks & Regards

Ravindra

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
941

hi

good

if you r transfering from the internal table than use OPEN DATASET APPENDING statement to appending the more than one line in the application server ,or first loop the internal table and then use OPEN DATASET OUTPUT statement ,

thanks

mrutyun^

hi

when i tranfer the data in the internal table to application server file..only one line is getting tranfered. i want to transfer all the lines to a file and display it line after a line in the file.

could u plz give me the solution? if u can send me a sample code,itwill be more helpful.

Thanks & Regards

Ravindra

6 REPLIES 6
Read only

Former Member
0 Likes
942

hi

good

if you r transfering from the internal table than use OPEN DATASET APPENDING statement to appending the more than one line in the application server ,or first loop the internal table and then use OPEN DATASET OUTPUT statement ,

thanks

mrutyun^

Read only

Former Member
0 Likes
941

try like this.

w_file hold your file name on app server.

t_final1 holds the data you want to transfer

OPEN DATASET w_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc EQ 0.

LOOP AT t_final1 into wa_final1.

TRANSFER wa_final1 TO w_file.

ENDLOOP.

Read only

Former Member
0 Likes
941

hi

i had developed this program for that perpouse only

reward if usefull

REPORT ZSD_EXCEL2.

types: begin of ttab ,

fld1(30) type c,

fld2(30) type c,

fld3(30) type c,

fld4(30) type c,

fld5(30) type c,

end of ttab.

data: itab type table of ttab with header line.

selection-screen skip 1.

parameters: p_file type localfile default

'C:\test.xls'.

selection-screen skip 1.

at selection-screen on value-request for p_file.

call function 'KD_GET_FILENAME_ON_F4'

exporting

static = 'X'

changing

file_name = p_file.

start-of-selection.

clear itab. refresh itab.

perform upload_data.

loop at itab.

write:/ itab-fld1, itab-fld2, itab-fld3, itab-fld4, itab-fld5.

endloop.

************************************************************************

  • Upload_Data

************************************************************************

form upload_data.

data: file type rlgrap-filename.

data: xcel type table of alsmex_tabline with header line.

file = p_file.

call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'

exporting

filename = file

i_begin_col = '1'

i_begin_row = '1'

i_end_col = '200'

i_end_row = '5000'

tables

intern = xcel

exceptions

inconsistent_parameters = 1

upload_ole = 2

others = 3.

loop at xcel.

case xcel-col.

when '0001'.

itab-fld1 = xcel-value.

when '0002'.

itab-fld2 = xcel-value.

when '0003'.

itab-fld3 = xcel-value.

when '0004'.

itab-fld4 = xcel-value.

when '0005'.

itab-fld5 = xcel-value.

endcase.

at end of row.

append itab.

clear itab.

endat.

endloop.

endform.

*CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'

  • EXPORTING

  • DEFAULTOPTION = 'N'

  • TEXTLINE1 = 'The selected report already exists, do you'

  • TEXTLINE2 = LC_LINE2

  • TITEL = 'Report already exists'

  • CANCEL_DISPLAY = SPACE

  • IMPORTING

  • ANSWER = LC_ANSWER

  • EXCEPTIONS

  • OTHERS = 1.

  • ELSE.

  • LC_ANSWER = 'J'.

  • ENDIF.

Read only

varma_narayana
Active Contributor
0 Likes
941

Hi..

This is the Sample code.

REPORT YRP00_20 .

DATA : IT_CARR TYPE TABLE OF SCARR,

WA_CARR TYPE SCARR.

parameters : p_dsn(30) DEFAULT 'EMP.TXT'.

DATA : V_TEXT(40).

START-OF-SELECTION.

***To Transfer the data to file

OPEN DATASET P_DSN FOR OUTPUT

IN TEXT MODE ENCODING DEFAULT.

IF SY-SUBRC NE 0.

WRITE:/ 'FILE NOT OPENED' .

EXIT.

ELSE.

SELECT * FROM SCARR INTO TABLE IT_CARR.

LOOP AT IT_CARR INTO WA_CARR.

TRANSFER WA_CARR TO P_DSN.

ENDLOOP.

CLOSE DATASET P_DSN.

ENDIF.

**To Read the Data from File

OPEN DATASET P_DSN FOR INPUT

IN TEXT MODE ENCODING DEFAULT.

IF SY-SUBRC = 0.

DO.

READ DATASET P_DSN INTO WA_CARR.

IF SY-SUBRC NE 0. "End of file reached

EXIT.

ENDIF.

WRITE:/ WA_CARR-CARRID,

WA_CARR-CARRNAME.

ENDDO.

CLOSE DATASET P_DSN.

ENDIF.

<b>Reward if Helpful</b>

Read only

Former Member
0 Likes
941

Hi Dear,

Go thru this code...

SELECTION-SCREEN BEGIN OF BLOCK BLK_001.

PARAMETERS :PR_FNAME LIKE RLGRAP-FILENAME.

SELECTION-SCREEN END OF BLOCK BLK_001.

PARAMETERS: PR_XBLNR TYPE XBLNR.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR PR_FNAME.

CALL FUNCTION 'F4_FILENAME'

IMPORTING

FILE_NAME = PR_FNAME.

START-OF-SELECTION.

*write '\usr\sap\DEV\interfaces\sample\revenue.txt' to file.

  • condense file.

*

W_FNAME1 = PR_FNAME.

*

*

*

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = W_FNAME1

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = ','

TABLES

DATA_TAB = IT_file.

*CREATING FILE IN THE APPLICATION SERVER

OPEN DATASET file FOR OUTPUT IN TEXT MODE encoding default.

LOOP AT IT_FILE.

TRANSFER IT_FILE to file.

ENDLOOP.

CLOSE DATASET file.

----


  • READING FILE INTO INTERNAL TABLE.

----


*OPEN DATASET PR_FNAME FOR INPUT IN TEXT MODE encoding default.

*

*DO.

*

*READ DATASET PR_FNAME INTO IT_POST.

*

*IF SY-SUBRC NE 0.

*

*EXIT.

*

*ENDIF.

*

*ENDDO.

*

*CLOSE DATASET PR_FNAME.

----


  • DELETING THE FILE FROM THE APPLICATION SERVER.

----


*DELETE DATASET file.

Reward Points if helpful

Regards,

Naveen bohra.

Read only

Former Member
0 Likes
941

Hi Ravindra,

Open dataser p_file for output in text mode

Loop at itab into w_itab.

transfer w_itab to p_file

endloop

Close dataset p_file

Regards

Arun