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

applicataion server

Former Member
0 Likes
737

hii gurus....

help me.

how to interact with the application server file? and

hw to archieve the processed file in application server?

regards

K.Saravanakumar.

4 REPLIES 4
Read only

Former Member
0 Likes
641

Hi,

U need to use DATASET statements to get tre file on the application server.

Opening a File

To open a file on the application server, use the OPEN DATASET statement. The basic form of this statement is described in the section

Closing a File

To close a file on the application server, use the close statement.

Syntax:

CLOSE DATASET <dsn>.

This statement closes the file <dsn>. The naming convention is described in the section Opening a File.

Deleting a File

To delete a file from the application server, use the DELETE DATASET statement:

just check this link

http://help.sap.com/saphelp_470/helpdata/en/fc/eb3c72358411d1829f0000e829fbfe/frameset.htm

reward if helpful

raam

Read only

Former Member
0 Likes
641

hi,

1.Refer this:

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

ABAP code for uploading a TAB delimited file into an internal table. See code below for structures.

&----


*& Report ZUPLOADTAB * &----


*& Example of Uploading tab delimited file *

&----


REPORT zuploadtab .

PARAMETERS: p_infile LIKE rlgrap-filename

OBLIGATORY DEFAULT '/usr/sap/'..

DATA: ld_file LIKE rlgrap-filename.

*Internal tabe to store upload data

TYPES: BEGIN OF t_record,

name1 like pa0002-VORNA,

name2 like pa0002-name2,

age type i,

END OF t_record.

DATA: it_record TYPE STANDARD TABLE OF t_record INITIAL SIZE 0,

wa_record TYPE t_record.

*Text version of data table

TYPES: begin of t_uploadtxt,

name1(10) type c,

name2(15) type c,

age(5) type c,

end of t_uploadtxt.

DATA: wa_uploadtxt TYPE t_uploadtxt.

*String value to data in initially.

DATA: wa_string(255) type c.

constants: con_tab TYPE x VALUE '09'.

*If you have Unicode check active in program attributes then you will

*need to declare constants as follows:

*class cl_abap_char_utilities definition load.

*constants:

con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB.

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

*START-OF-SELECTION

START-OF-SELECTION.

ld_file = p_infile.

OPEN DATASET ld_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc NE 0.

ELSE.

DO.

CLEAR: wa_string, wa_uploadtxt.

READ DATASET ld_file INTO wa_string.

IF sy-subrc NE 0.

EXIT.

ELSE.

SPLIT wa_string AT con_tab INTO wa_uploadtxt-name1

wa_uploadtxt-name2

wa_uploadtxt-age.

MOVE-CORRESPONDING wa_uploadtxt TO wa_upload.

APPEND wa_upload TO it_record.

ENDIF.

ENDDO.

CLOSE DATASET ld_file.

ENDIF.

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

*END-OF-SELECTION

END-OF-SELECTION.

*!! Text data is now contained within the internal table IT_RECORD

Display report data for illustration purposes

loop at it_record into wa_record.

write:/ sy-vline,

(10) wa_record-name1, sy-vline,

(10) wa_record-name2, sy-vline,

(10) wa_record-age, sy-vline.

endloop.

2.

For archiving, we can use FM: EPS_DELETE_FILE for archiving a file.

Below code can help you understand for moving a file:

codeFUNCTION y_copy_file_within_appli_serv.

*"----


""Local interface:

*" IMPORTING

*" VALUE(RFC_DESTINATION) LIKE RFCDES-RFCDEST

*" VALUE(LOCAL_FILE) LIKE EPSF-EPSFILNAM

*" VALUE(LOCAL_DIRECTORY) LIKE EPSF-EPSDIRNAM DEFAULT SPACE

*" VALUE(REMOTE_FILE) LIKE EPSF-EPSFILNAM DEFAULT SPACE

*" VALUE(REMOTE_DIRECTORY) LIKE EPSF-EPSDIRNAM DEFAULT SPACE

*" VALUE(OVERWRITE_MODE) LIKE EPSF-EPSOVRWRI DEFAULT SPACE

*" VALUE(TEXT_MODE) LIKE EPSF-EPSTXTMOD DEFAULT SPACE

*" VALUE(TRANSMISSION_MONITOR) LIKE EPSF-EPSTRAMON DEFAULT 'X'

*" VALUE(RECORDS_PER_TRANSFER) LIKE EPSF-EPSRECTRA DEFAULT 10

*" VALUE(REQUESTED_FILE_SIZE) LIKE EPSF-EPSFILSIZ DEFAULT 0

*" VALUE(MONITOR_TITLE) LIKE EPSF-EPSTEXT OPTIONAL

*" VALUE(MONITOR_TEXT1) LIKE EPSF-EPSTEXT OPTIONAL

*" VALUE(MONITOR_TEXT2) LIKE EPSF-EPSTEXT OPTIONAL

*" VALUE(PROGRESS_TEXT) LIKE EPSF-EPSTEXT OPTIONAL

*" VALUE(OBJECT_NAME) LIKE EPSF-EPSFILNAM OPTIONAL

*" EXPORTING

*" VALUE(LOCAL_DIRECTORY) LIKE EPSF-EPSDIRNAM

*" VALUE(LOCAL_PATH) LIKE EPSF-EPSPATH

*" VALUE(REMOTE_FILE) LIKE EPSF-EPSFILNAM

*" VALUE(REMOTE_DIRECTORY) LIKE EPSF-EPSDIRNAM

*" VALUE(REMOTE_PATH) LIKE EPSF-EPSPATH

*" VALUE(FILE_SIZE) LIKE EPSF-EPSFILSIZ

*" VALUE(LOCAL_SYSTEM_INFO) LIKE EPSFTPSI STRUCTURE EPSFTPSI

*" VALUE(REMOTE_SYSTEM_INFO) LIKE EPSFTPSI STRUCTURE EPSFTPSI

*" EXCEPTIONS

*" OPEN_INPUT_FILE_FAILED

*" OPEN_OUTPUT_FILE_FAILED

*" READ_BLOCK_FAILED

*" WRITE_BLOCK_FAILED

*" CLOSE_OUTPUT_FILE_FAILED

*" INVALID_FILE_SIZE

*" STOPPED_BY_USER

*" INVALID_INPUT_FILE_SIZE

*" RESTART_FAILED

*" CONNECTION_FAILED

*" INVALID_VERSION

*"----


DATA: BEGIN OF eps_buffer OCCURS 10.

INCLUDE STRUCTURE tbl8000.

DATA: END OF eps_buffer.

DATA: BEGIN OF eps_txtbuf OCCURS 0.

INCLUDE STRUCTURE epsteco.

DATA: END OF eps_txtbuf.

DATA: ls_save_moni LIKE g$moni.

DATA: lv_local_file_size LIKE epsf-epsfilsiz,

lv_remote_file_size LIKE epsf-epsfilsiz,

lv_block_size LIKE epsf-epsfilsiz,

lv_number_of_records LIKE epsf-epsrectra,

lv_last_record_length LIKE epsf-epsreclen,

lv_max_record_length LIKE epsf-epsreclen,

lv_end_of_file LIKE epsf-epsflag,

lv_low_rc LIKE sy-subrc,

lv_rfc_message LIKE sy-msgv1,

lv_restart_flag LIKE epsf-epsflag,

lv_pattern LIKE tbl8000-line,

lv_records_to_skip LIKE epsf-epsrectra,

lv_skiped_size LIKE epsf-epsfilsiz.

check parameters (only if not started from EPS_ftp_mput)

IF transmission_monitor gc_mon_flag_m.

PERFORM get_ftp_system_info " get ftp system info

USING

rfc_destination

CHANGING

local_system_info

remote_system_info.

PERFORM check_ftp_version " check ftp version

USING

text_mode

remote_system_info.

PERFORM check_overwrite_mode " check OVERWRITE_MODE

USING

text_mode

CHANGING

overwrite_mode.

PERFORM check_records_per_transfer " check RECORDS_PER_TRANSFER

USING

text_mode

CHANGING

records_per_transfer.

ENDIF.

determine block_size byte (binary mode only)

IF text_mode 'X'.

*>>> Begin of modification for change log reference UnicodeC <<<

DESCRIBE FIELD eps_buffer-line LENGTH lv_max_record_length.

DESCRIBE FIELD eps_buffer-line LENGTH lv_max_record_length IN

BYTE MODE.

*<<< End of modification for change log reference UnicodeC >>>

lv_block_size = lv_max_record_length * records_per_transfer.

ENDIF.

open local file for input

CALL FUNCTION 'EPS_OPEN_INPUT_FILE'

EXPORTING

file_name = local_file

dir_name = local_directory

text_mode = text_mode

IMPORTING

dir_name = local_directory

file_path = local_path

file_size = lv_local_file_size

EXCEPTIONS

invalid_eps_subdir = 11

sapgparam_failed = 12

build_directory_failed = 13

no_authorization = 14

build_path_failed = 15

open_failed = 16

read_directory_failed = 17

read_attributes_failed = 18.

lv_low_rc = sy-subrc.

IF sy-subrc 0.

CALL FUNCTION 'EPS_CLOSE_FILE'

EXPORTING

file_name = local_file

dir_name = local_directory

EXCEPTIONS

OTHERS = 99.

MESSAGE e001 WITH lv_low_rc local_file local_directory

space " rfc message

RAISING open_input_file_failed.

ENDIF.

check file size

IF requested_file_size 0 AND

requested_file_size lv_local_file_size.

CALL FUNCTION 'EPS_CLOSE_FILE'

EXPORTING

file_name = local_file

dir_name = local_directory

EXCEPTIONS

OTHERS = 99.

lv_low_rc = 0.

MESSAGE e008 WITH lv_low_rc local_file

requested_file_size lv_local_file_size

RAISING invalid_input_file_size.

ENDIF.

open remote file for output

IF remote_file = space. " no remote file specified

remote_file = local_file. " -> remote file = local file

ENDIF.

IF text_mode = 'X' AND " no restart in textmode

overwrite_mode = 'R'.

overwrite_mode = 'S'.

ENDIF.

CALL FUNCTION 'EPS_OPEN_OUTPUT_FILE'

DESTINATION rfc_destination

EXPORTING

file_name = remote_file

dir_name = remote_directory

file_size_request = lv_local_file_size

overwrite_mode = overwrite_mode

text_mode = text_mode

IMPORTING

dir_name = remote_directory

file_path = remote_path

restart_flag = lv_restart_flag

EXCEPTIONS

system_failure = 03 MESSAGE lv_rfc_message

communication_failure = 04 MESSAGE lv_rfc_message

invalid_eps_subdir = 11

sapgparam_failed = 12

build_directory_failed = 13

no_authorization = 14

build_path_failed = 15

open_failed = 16

file_already_exists = 19.

lv_low_rc = sy-subrc.

IF sy-subrc 0.

CALL FUNCTION 'EPS_CLOSE_FILE'

DESTINATION rfc_destination

EXPORTING

file_name = remote_file

dir_name = remote_directory

EXCEPTIONS

OTHERS = 99.

CALL FUNCTION 'EPS_CLOSE_FILE'

EXPORTING

file_name = local_file

dir_name = local_directory

EXCEPTIONS

OTHERS = 99.

MESSAGE e002 WITH lv_low_rc remote_file remote_directory

lv_rfc_message

RAISING open_output_file_failed.

ENDIF.

restart file transfer

IF lv_restart_flag = 'X'.

ls_save_moni = g$moni. " save monitor data

CALL FUNCTION 'EPS_SEEK_OUTPUT_FILE'

DESTINATION rfc_destination

EXPORTING

file_name = remote_file

dir_name = remote_directory

records_per_transfer = records_per_transfer

object_name = object_name

IMPORTING

pattern = lv_pattern

records_to_skip = lv_records_to_skip

EXCEPTIONS

system_failure = 03 MESSAGE lv_rfc_message

communication_failure = 04 MESSAGE lv_rfc_message

invalid_eps_subdir = 11

sapgparam_failed = 12

build_directory_failed = 13

no_authorization = 14

build_path_failed = 15

open_failed = 16

read_directory_failed = 17

read_attributes_failed = 18

read_failure = 20

write_failure = 21

OTHERS = 99.

lv_low_rc = sy-subrc.

IF sy-subrc 0.

CALL FUNCTION 'EPS_CLOSE_FILE'

EXPORTING

file_name = local_file

dir_name = local_directory

EXCEPTIONS

OTHERS = 99.

g$moni = ls_save_moni. " restore monitor data

MESSAGE e009 WITH lv_low_rc remote_file remote_directory

lv_rfc_message

RAISING restart_failed.

ENDIF.

CALL FUNCTION 'EPS_SEEK_INPUT_FILE'

EXPORTING

pattern = lv_pattern

records_to_skip = lv_records_to_skip

file_path = local_path

records_per_transfer = records_per_transfer

EXCEPTIONS

read_failure = 20

write_failure = 21

end_of_file = 22

pattern_not_found = 23

OTHERS = 99.

lv_low_rc = sy-subrc.

IF sy-subrc 0.

CALL FUNCTION 'EPS_CLOSE_FILE'

DESTINATION rfc_destination

EXPORTING

file_name = remote_file

dir_name = remote_directory

EXCEPTIONS

OTHERS = 99.

CALL FUNCTION 'EPS_CLOSE_FILE'

EXPORTING

file_name = local_file

dir_name = local_directory

EXCEPTIONS

OTHERS = 99.

CALL FUNCTION 'EPS_DELETE_FILE'

DESTINATION rfc_destination

EXPORTING

file_name = remote_file

dir_name = remote_directory

EXCEPTIONS

OTHERS = 99.

g$moni = ls_save_moni. " restore monitor data

MESSAGE e009 WITH lv_low_rc remote_file remote_directory

space " rfc message

RAISING restart_failed.

ENDIF.

lv_skiped_size = lv_records_to_skip * lv_max_record_length.

g$moni = ls_save_moni. " restore monitor data

ENDIF.

start transmission monitor

IF transmission_monitor 'M'.

PERFORM monitor_open

USING transmission_monitor

monitor_title.

PERFORM monitor_set_values

USING gc_ftp_put

progress_text

monitor_text1

monitor_text2

rfc_destination

local_file

0 " total files

0 " current file

0 " maxval gauge 1

lv_local_file_size " maxval gauge 2

0 " skiped size gauge 1

lv_skiped_size. " skiped size gauge 2

ELSE.

PERFORM monitor_update_values

USING 0 " increment

0 " skiped size gauge 1

lv_skiped_size. " skiped size gauge 2

ENDIF.

*

file transfer

-


begin

-


*

CLEAR lv_end_of_file.

WHILE lv_end_of_file 'X'.

read block from input file

IF text_mode = 'X'.

REFRESH eps_txtbuf.

CALL FUNCTION 'EPS_READ_TEXT_BLOCK'

EXPORTING

file_path = local_path

records_per_transfer = records_per_transfer

IMPORTING

end_of_file = lv_end_of_file

TABLES

eps_buffer = eps_txtbuf

EXCEPTIONS

read_failure = 20.

ELSE.

REFRESH eps_buffer.

CALL FUNCTION 'EPS_READ_BLOCK'

EXPORTING

file_path = local_path

records_per_transfer = records_per_transfer

IMPORTING

number_of_records = lv_number_of_records

last_record_length = lv_last_record_length

end_of_file = lv_end_of_file

TABLES

eps_buffer = eps_buffer

EXCEPTIONS

read_failure = 20.

ENDIF.

lv_low_rc = sy-subrc.

IF sy-subrc 0.

IF transmission_monitor = 'X'. " stop monitor

PERFORM monitor_stop.

ENDIF.

MESSAGE e003 WITH lv_low_rc local_path space

RAISING read_block_failed.

ENDIF.

write block into output file

IF text_mode = 'X'.

CALL FUNCTION 'EPS_WRITE_TEXT_BLOCK'

DESTINATION rfc_destination

EXPORTING

file_path = remote_path

IMPORTING

transfered_bytes = lv_block_size

TABLES

eps_buffer = eps_txtbuf

EXCEPTIONS

system_failure = 03 MESSAGE lv_rfc_message

communication_failure = 04 MESSAGE lv_rfc_message

write_failure = 21.

ELSE.

CALL FUNCTION 'EPS_WRITE_BLOCK'

DESTINATION rfc_destination

EXPORTING

file_path = remote_path

number_of_records = lv_number_of_records

last_record_length = lv_last_record_length

TABLES

eps_buffer = eps_buffer

EXCEPTIONS

system_failure = 03 MESSAGE lv_rfc_message

communication_failure = 04 MESSAGE lv_rfc_message

write_failure = 21.

ENDIF.

lv_low_rc = sy-subrc.

IF sy-subrc 0.

IF transmission_monitor = 'X'. " stop monitor

PERFORM monitor_stop.

ENDIF.

MESSAGE e004 WITH lv_low_rc remote_path lv_rfc_message

RAISING write_block_failed.

ENDIF.

update transmission monitor

PERFORM monitor_update_values

USING lv_block_size " increment

0 " skiped size gauge 1

0. " skiped size gauge 2

IF g$moni-cancel = 'X'. " stop transmission

MESSAGE e007 RAISING stopped_by_user.

ENDIF.

ENDWHILE.

*

file transfer

-


end

-


*

stop transmission monitor

IF transmission_monitor = 'X'.

PERFORM monitor_stop.

ENDIF.

close output file and get size

CALL FUNCTION 'EPS_CLOSE_FILE'

DESTINATION rfc_destination

EXPORTING

file_name = remote_file

dir_name = remote_directory

IMPORTING

file_size = lv_remote_file_size

EXCEPTIONS

system_failure = 03 MESSAGE lv_rfc_message

communication_failure = 04 MESSAGE lv_rfc_message

build_path_failed = 15

read_directory_failed = 17

read_attributes_failed = 18.

lv_low_rc = sy-subrc.

IF sy-subrc 0.

MESSAGE e005 WITH lv_low_rc remote_file remote_directory

lv_rfc_message

RAISING close_output_file_failed.

ENDIF.

compare size of local and remote file (binary mode only)

IF text_mode 'X'.

IF lv_local_file_size lv_remote_file_size.

lv_low_rc = 0.

MESSAGE e006 WITH lv_low_rc local_file lv_local_file_size

RAISING invalid_file_size.

ENDIF.

ENDIF.

file_size = lv_local_file_size.

ENDFUNCTION.[/code]

Read only

manubhutani
Active Contributor
0 Likes
641

HI see the code to read data from app server.

OPEN DATASET p_infile FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc = 0.

DO.

CLEAR wa_file.

READ DATASET p_infile INTO wa_file. " Reads record by record

IF sy-subrc = 0.

APPEND wa_file TO t_file.

ELSE.

EXIT.

ENDIF.

ENDDO.

ELSE.

MESSAGE i030 WITH p_infile. "If unable to open the record

similarly towrite use output instead of input in open dataset

and write

please revert in case of doubt

please reward points

Read only

Former Member
0 Likes
641

hi,

To process the files from appilication server Read dataset and Transfer statements are used.

Before reading or writing the data from the appilication server the file must be opened and closed after processing it.

the syntaxes for opening , reading and closing the files are:

1.opening a file:

open dataset <file name> for input in<tbinarymode/text>.

2. Reading a file

Read dataset <file name> to <filed>

*3. close a file *

Close dataset <file name>

Example

here the example for xk01 transaction.

open dataset file_path in text mode for input encoding default.

Do.

Read dataset file_path into wa_xk01.

if sy-subrc ne 0.

EXIT.

ENDIF.

Append wa_xk01 to i_xk01.

ENDDO.

CLOSE DATASET FILE_PATH.