You are on page 1of 5

3/24/2010 SAP Community Network Wiki - Code G…

Log In Register About Us How to Contribute


Welcome Guest

SDN Community BPX Community BusinessObjects University Alliances SAP EcoHub


Home Forums Wiki Blogs Articles Dow nloads eLearning Career Center Events InnoCentive Shop

My Home > Code Gallery > Community Code Gallery > ABAP - Reading-Writing to-from application-presentation server with F4 help for filename Search the w iki

ABAP - Reading-Writing to-from application-presentation server with F4 help for filename Welcome Guest

View Comments (0) Info Additional Features

Added by Pratik Vora , last edited by Pratik Vora on Jan 15, 2009
Labels: (None)

REPORT z_appl_presentation_server NO STANDARD PAGE HEADING .

*&----------------DATA DECLARATION----------------------------------&

INCLUDE z_appl_presentation_server_data_declaration.

*&----------------INCLUDE FOR PERFORMS------------------------------&*

INCLUDE z_appl_presentation_server_forms.

*&----------------AT SELECTION SCREEN EVENT-------------------------&*

*& At selection screen output for screen attributes

AT SELECTION-SCREEN OUTPUT.

PERFORM screen_attributes.

*& Providing f4 help path to filmanager on presentation server

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

PERFORM source_destination

.*& Providing f4 help path to Application server

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file1.

PERFORM application_server_path.

*&----------------START OF SELECTION--------------------------------&*

START-OF-SELECTION.

*& Reading data from application server and copy it to presentation server

IF p_read = 'X'.

PERFORM read_from_server.

*& Copy the data from presentation server and write to application server

ELSE.

PERFORM write_to_server.

ENDIF.
*&---------------------------------------------------------------------*

*& Include z_appl_presentation_server_DATA_DECLARATION

*&---------------------------------------------------------------------*

*& Types Declaration

types : begin of ty_bseg, "Accounting Document Segment

bukrs(4), "Company Code

belnr(10), "Accounting Document Number

gjahr(4), "Fiscal Year

buzei(3), "Number of Line Item Within Accounting Document

kostl(10), "Cost Center

saknr(10), "G/L Account No

end of ty_bseg

.*& Work area and Internal tabel

data: wa_bseg type ty_bseg,

it_bseg type standard table of ty_bseg.

*& Data declaratio for read/write data to application serve

…sap.com/…/ABAP+-+Reading-Writing… 1/5
3/24/2010 SAP Community Network Wiki - Code G…
rdata: d_filename(128),

file type string.


*& Selection Screen

PARAMETERS : p_read RADIOBUTTON GROUP rad1 default 'X' "Copy the file from Application server to PC

USER-COMMAND CHEK,

p_write RADIOBUTTON GROUP rad1, "Copy the file from PC to Application server

p_file LIKE rlgrap-filename OBLIGATORY

default 'C:\Documents and Settings\pvora\Desktop\test.txt'

modif id G02, "Filename on PC

p_file1 LIKE rlgrap-filename default '.\Pratik.txt' "Filename on server

modif id G01

.*&---------------------------------------------------------------------*

*& Include z_appl_presentation_server_FORMS

*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*

*& Form read_from_server

*&---------------------------------------------------------------------*

FORM read_from_server.

CLEAR d_filename.

d_filename = p_file1.

*& Reading file from application server

OPEN DATASET d_filename FOR INPUT IN TEXT MODE ENCODING DEFAULT.

DO.

READ DATASET d_filename INTO wa_bseg.

IF sy-subrc <> 0.

EXIT.

ENDIF.

APPEND wa_bseg TO it_bseg.

ENDDO.

CLOSE DATASET d_filename.


*& Dwonloading file to Presentation Server

file = p_file.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = file

filetype = 'ASC'

append = ' '

TABLES

data_tab = it_bseg

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

…sap.com/…/ABAP+-+Reading-Writing… 2/5
3/24/2010 SAP Community Network Wiki - Code G…
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.

ENDFORM. " read_from_server

*&---------------------------------------------------------------------*

*& Form write_to_server

*&---------------------------------------------------------------------*

FORM write_to_server.

*& Uploading file from Presentation server

file = p_file.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = file

filetype = 'ASC'

TABLES

data_tab = it_bseg

EXCEPTIONS

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

invalid_type = 5

no_authority = 6

unknown_error = 7

bad_data_format = 8

header_not_allowed = 9

separator_not_allowed = 10

header_too_long = 11

unknown_dp_error = 12

access_denied = 13

dp_out_of_memory = 14

disk_full = 15

dp_timeout = 16.

CLEAR d_filename.

d_filename = p_file1.

*& Writing in the file on application server

OPEN DATASET d_filename FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

LOOP AT it_bseg INTO wa_bseg.

TRANSFER wa_bseg TO d_filename.

ENDLOOP.

CLOSE DATASET d_filename.

…sap.com/…/ABAP+-+Reading-Writing… 3/5
3/24/2010 SAP Community Network Wiki - Code G…
OPEN DATASET d_filename FOR INPUT IN TEXT MODE ENCODING DEFAULT.

DO.

READ DATASET d_filename INTO wa_bseg.

IF sy-subrc <> 0.

EXIT.

ENDIF.

WRITE:/ wa_bseg-bukrs, wa_bseg-belnr, wa_bseg-gjahr, wa_bseg-kostl, wa_bseg-saknr.

ENDDO.

CLOSE DATASET d_filename.

ENDFORM. " write_to_server

*&---------------------------------------------------------------------*

*& Form source_destination

*&---------------------------------------------------------------------*

FORM source_destination.

file = p_file.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

program_name = syst-repid

dynpro_number = syst-dynnr

field_name = p_file

* STATIC = ' '

* MASK = ' '

CHANGING

file_name = p_file

EXCEPTIONS

mask_too_long = 1

ENDFORM. " source_destination

*&---------------------------------------------------------------------*

*& Form application_server_path

*&---------------------------------------------------------------------*

FORM application_server_path.

IF p_read = 'X'.

*& Selecting file from server on pressing f4

CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'

EXPORTING

directory = '.\'

filemask = ' '

IMPORTING

serverfile = p_file1

EXCEPTIONS

canceled_by_user = 1.

ELSE.

MESSAGE 'F4 is only valid for transfering data from Server to PC' TYPE 'S'.

ENDIF.

ENDFORM. " application_server_path

*&---------------------------------------------------------------------*

*& Form screen_attributes

*&---------------------------------------------------------------------*

…sap.com/…/ABAP+-+Reading-Writing… 4/5
3/24/2010 SAP Community Network Wiki - Code G…
FORM screen_attributes .

IF p_write = 'X'.

LOOP AT SCREEN.

IF screen-group1 = 'G01'.

screen-input = 0.

MODIFY SCREEN.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT SCREEN.

IF screen-group1 = 'G02'.

screen-input = 0.

MODIFY SCREEN.

ENDIF.

ENDLOOP.

ENDIF.

ENDFORM. " screen_attributes

Contact Us Site Index Marketing Opportunities Legal Terms Privacy Impressum


Powered by SAP NetWeaver

…sap.com/…/ABAP+-+Reading-Writing… 5/5

You might also like