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

pgm needed

Former Member
0 Likes
942

can any one please send me the simple pgm to download as a flat file in application server or watever server name is mentioned.

using data sets.

please dont confuse the pgm

simple take 3 to 4 fields and download in application server

if possible with headings.

thats enough

7 REPLIES 7
Read only

Former Member
0 Likes
919

Hi Arun,

Check this simple code.

REPORT YOPENDATASET .

TABLES : LFA1.

PARAMETERS : FILE(200) TYPE C.

DATA: BEGIN OF ITAB OCCURS 0,

LIFNR LIKE LFA1-LIFNR,

ORT01 LIKE LFA1-ORT01,

LAND1 LIKE LFA1-LAND1,

END OF ITAB.

DATA : BEGIN OF JTAB OCCURS 0.

INCLUDE STRUCTURE BDCDATA.

DATA : END OF JTAB.

OPEN DATASET FILE FOR INPUT IN BINARY MODE.

DO.

READ DATASET FILE INTO ITAB.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

PERFORM SUB USING 'YMPOOL' '100'.

PERFORM SUB1 USING : 'LFA1-LIFNR' ITAB-LIFNR,

'LFA1-ORT01' ITAB-ORT01,

'LFA1-LAND1' ITAB-LAND1.

CALL TRANSACTION 'YMTRAN' USING ITAB MODE 'A'.

ENDDO.

CLOSE DATASET FILE.

FORM SUB USING A B .

CLEAR JTAB.

JTAB-PROGRAM = A.

JTAB-DYNPRO = B.

JTAB-DYNBEGIN = 'X'.

APPEND JTAB.

ENDFORM.

FORM SUB1 USING C D.

CLEAR JTAB.

JTAB-FNAM = C.

JTAB-FVAL = D.

APPEND JTAB.

ENDFORM.

Hope this resolves your query.

<b>Reward all the helpful answers.</b>

Regards

Read only

Former Member
0 Likes
919

In your Fieldsymbols declaration define <table> as

FIELD-SYMBOLS <table> TYPE STANDARD TABLE.

Check this code:

PARAMETERS: table(30) TYPE c,

flname TYPE rlgrap-filename.

DATA tabref TYPE REF TO data.

FIELD-SYMBOLS <table> TYPE STANDARD TABLE.

table = 'MARA'.

CREATE DATA tabref TYPE STANDARD TABLE OF (table).

ASSIGN tabref->* TO <table>.

SELECT * FROM (table) INTO TABLE <table>.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'D:\Wences\test.txt'

tables

data_tab = <table>

.

Regards,

Read only

Former Member
0 Likes
919

Hi Arun,

Check this sample code it downloads into aplication and presentation server.

FORM download_file TABLES t_down_tab USING u_down_line.

*

DATA: l_file TYPE string.

CLEAR: l_file.

DATA: tab.

DATA: t_outputline(300).

FIELD-SYMBOLS: <f>.

  • Column break in excel sheet when runned in background

tab = cl_abap_char_utilities=>horizontal_tab.

IF p_prsfil = 'X'.

MOVE filepath TO l_file.

*--- downloading data into presentation server

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = l_file

filetype = 'ASC'

write_field_separator = 'X'

dat_mode = 'X'

TABLES

data_tab = t_down_tab

EXCEPTIONS

file_write_error = 1

no_batch = 2

gui_refuse_filetransfer = 3

invalid_type = 4

no_authority = 5

unknown_error = 6

header_not_allowed = 7

separator_not_allowed = 8

filesize_not_allowed = 9

header_too_long = 10

dp_error_create = 11

dp_error_send = 12

dp_error_write = 13

unknown_dp_error = 14

access_denied = 15

dp_out_of_memory = 16

disk_full = 17

dp_timeout = 18

file_not_found = 19

dataprovider_exception = 20

control_flush_error = 21

OTHERS = 22.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ELSE.

*--- downloading data into application server

  • OPEN DATASET filepath FOR OUTPUT IN TEXT MODE.

OPEN DATASET filepath FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc = 0.

LOOP AT t_down_tab INTO u_down_line.

DO.

ASSIGN COMPONENT sy-index OF STRUCTURE u_down_line TO <f>.

IF sy-subrc NE 0.

EXIT.

ENDIF.

IF sy-index = 1.

MOVE <f> TO t_outputline.

ELSE.

CONCATENATE t_outputline <f> INTO t_outputline SEPARATED BY tab

.

ENDIF.

ENDDO.

  • Transfer data to excel file

TRANSFER t_outputline TO filepath.

CLEAR t_outputline.

  • TRANSFER u_down_line TO filepath.

ENDLOOP.

ENDIF.

*End of changes

CLOSE DATASET filepath.

ENDIF.

ENDFORM. " DOWNLOAD_FILE

<b>Dont forget to allot points dude this is what we do it for.</b>Hope this will solve ur problem.

Read only

0 Likes
919

Hi

thank u for ur help.

but l_file will b empty rite according to this pmg

can u please send by taking some sample fields from sap table.

and heading will also cum or it will not

please do the needfull

Read only

0 Likes
919

yes i understood please send me the full

becoz i want to know where they r calling wat datas are present

how the declaratin part and all.

Read only

Former Member
0 Likes
919

HI Arun

Analyse this code.

REPORT test.

*--Internal table & Work area Declaration

DATA : t_data TYPE STANDARD TABLE OF t000,

wa_data TYPE t000.

DATA : w_message(100) TYPE c.

*--Application Server File path from user

PARAMETERS : p_file TYPE rlgrap-filename.

START-OF-SELECTION.

*--Get data into the Internal table t_data

SELECT * FROM t000 INTO TABLE t_data .

*--- Create the application server file path

OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT MESSAGE w_message.

*--- Display error messages if any.

IF sy-subrc NE 0.

MESSAGE w_message TYPE 'E'.

EXIT.

ELSE.

*---Data is downloaded to the application server file path

LOOP AT t_data INTO wa_data.

TRANSFER wa_data TO p_file.

ENDLOOP.

ENDIF.

*--Close the Application server file (Mandatory).

CLOSE DATASET p_file.

IF sy-subrc NE 0.

MESSAGE 'Error closing the File' TYPE 'E'.

EXIT.

ELSEIF sy-subrc IS INITIAL.

WRITE : 'File saved in the location' , p_file.

ENDIF.

Take a look at this help.

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3c8c358411d1829f0000e829fbfe/frameset.htm

You will find some sample code as well.

This has been discussed a lot . Please refer the following links

Regards,

Rk

Read only

Former Member
0 Likes
919

Hi,

Try the following code.

*"Table declarations...................................................

tables: bkpf. " Accounting Document Header

*"Selection screen elements............................................

parameters:

p_burks like bkpf-bukrs. " Company Code

select-options:

s_gjahr for bkpf-gjahr. " Fiscal year

"----


  • Type declaration of the structure to hold Accounting Document Header*

"----


data:

begin of fs_bkpf,

bukrs type bkpf-bukrs, " Company Code

belnr type bkpf-belnr, " Accounting Document Number

gjahr type bkpf-gjahr, " Fiscal year

blart type bkpf-blart, " Document type

bldat type bkpf-bldat, " Document date in document

end of fs_bkpf.

"----


  • Internal table to hold Accounting Document Header *

"----


data:

t_bkpf like standard table

of fs_bkpf.

"----


  • Type declaration of the structure to hold file data *

"----


data:

begin of fs_table,

str type string,

end of fs_table.

"----


  • Internal table to hold file data *

"----


data:

t_table like standard table

of fs_table.

field-symbols: <fs>.

*" Data declarations...................................................

"----


  • Work variables *

"----


data:

w_char(50) type c,

w_file_name(50) type c value 'YH645_050103'.

select bukrs " Company Code

belnr " Accounting Document Number

gjahr " Fiscal year

blart " Document type

bldat " Document date in document

from bkpf

into table t_bkpf

where bukrs eq p_burks

and gjahr in s_gjahr.

if sy-subrc eq 0.

loop at t_bkpf into fs_bkpf.

do.

assign component sy-index of structure fs_bkpf to <fs>.

if sy-subrc ne 0.

exit.

else.

move <fs> to w_char.

if sy-index eq 1.

fs_table-str = <fs>.

else.

concatenate fs_table-str ',' w_char into fs_table-str.

endif. " IF SY-INDEX...

endif. " IF SY-SUBRC...

enddo. " DO...

append fs_table to t_table.

endloop. " LOOP AT T_KNA1...

endif. " IF SY-SUBRC...

open dataset w_file_name for output in text mode encoding default.

loop at t_table into fs_table.

transfer fs_table-str to w_file_name.

endloop. " LOOP AT T_TABLE...

reward points if helpful.

regards,

kiran kumar k