Application Development 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: 

how to write file to application server

Former Member
0 Kudos

Hi Group,

Can any body give me some idea how to write the a file on

Application server.

8 REPLIES 8

vinod_gunaware2
Active Contributor
0 Kudos

Use

<b>CG3Y and CG3Z</b> transaction

USe <b>AL11</b> to view file

Reading and Writing a text file from and to the application server

  • sy-subrc = 0 Record read from file

  • sy-subrc = 4 End of file reached

data: w_dataset1(27) value '/var/textfile.txt',

w_dataset2(27) value '/var/outfile.txt'.

data:begin of itab1 occurs 0, "Text file format

matnr(18), "MATERIAL NUMBER

bwkrs(4), "PLANT

end of itab1.

*Uploading of text file from Application server.

open dataset w_dataset1 for input in text mode.

do.

if sy-subrc <> 0.

exit.

endif.

read dataset w_dataset1 into itab1.

append itab1.

clear itab1.

enddo.

close dataset w_dataset1.

*Downloading of text file to Application server.

open dataset w_dataset2 for output in text mode.

loop at itable.

transfer itable to w_dataset2.

endloop.

close dataset w_dataset2.

regards

vinod

abdul_hakim
Active Contributor
0 Kudos

use the below syntax.

OPEN DATASET <filename> FOR OUTPUT IN TEXT MODE.

OPEN DATASET <filename> FOR OUTPUT.

Also read the docu under http://help.sap.com

Cheers,

Abdul

Reward points for useful answers..

0 Kudos

To read data from App server.

open dataset p_fleunx for input in text mode.

if sy-subrc ne 0.

write: / 'Process will be aborted.'.

exit.

endif.

  • Load internal table

do.

read dataset p_fleunx into fltab.

if sy-subrc ne 0.

exit.

endif.

append fltab.

enddo.

To write to App. server.

open dataset p_fleunx for output in text mode.

loop at fltab.

transfer fltab to p_fleunx.

endloop.

close dataset p_fleunx.

former_member927251
Active Contributor
0 Kudos

Hi,

Use the following code to achieve this.

DATA: lv_string TYPE string.

CONSTANTS : lc_comma TYPE char1 VALUE ','.

  • Open the file to write the output

  • GV_DSN is your file path

OPEN DATASET gv_dsn FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

  • Display error if the path specified is incorrect

IF sy-subrc NE 0.

MESSAGE ID gc_msg_class

TYPE gc_error

NUMBER gc_msgno_266.

ENDIF.

  • Prepare the Column Heading for the file

CONCATENATE text-009

text-010

text-011

text-012

text-013

text-014

text-015

text-016

text-017

text-018

text-019

INTO lv_string

SEPARATED BY lc_comma .

TRANSFER lv_string TO gv_dsn.

  • Start Writing into the file

  • Internal table Git_Contract_data contains your data to * be written on the application server

LOOP AT git_contract_det INTO wa_contract_det.

CONCATENATE wa_contract_det-cust_ref

wa_contract_det-cont_acct_ref

wa_contract_det-cont_line_item_ref

wa_contract_det-sap_site_ref

wa_contract_det-user_site_ref

wa_contract_det-mprn

wa_contract_det-contract_status

wa_contract_det-selection_criteria

wa_contract_det-credit_score

wa_contract_det-pl_cont_stdate

wa_contract_det-cont_stdate

INTO lv_string

SEPARATED BY lc_comma .

TRANSFER lv_string TO gv_dsn.

ENDLOOP.

  • Close the File

CLOSE DATASET gv_dsn.

ENDFORM. " f7000_write_output

<b>Hope this helps.

Mark helpful answer.</b>

Regards,

Amit Mishra

Message was edited by: Amit Mishra

Message was edited by: Amit Mishra

former_member184569
Active Contributor
0 Kudos

Hello!!

First you get your data into an internal table.

Then copy the following code.

FORM write_to_file.

                                    • Setting the file name ************************

CONCATENATE 'zfiapimg_' sy-datum '.txt' INTO wa_filename.

wa_filepath = '/data/ftp/out/'.

CONCATENATE wa_filepath wa_filename INTO wa_c_filename.

                                    • Open the file for output **********************

OPEN DATASET wa_c_filename FOR OUTPUT IN TEXT MODE.

IF sy-subrc NE 0.

MESSAGE a999 WITH 'The file could not be created'.

ENDIF.

                                • Write header data to file ************************

TRANSFER header TO wa_c_filename.

                                • Write line items to file ************************

LOOP AT i_final_file.

TRANSFER i_final_file TO wa_c_filename.

ENDLOOP.

                                          • Close the file ******************************

CLOSE DATASET wa_c_filename.

ENDFORM.

You will have the contents in the file name and file path as specified.

REgards,

SUsmitha

0 Kudos

Useful
Thank you so much!

former_member188685
Active Contributor
0 Kudos

Hi,

check these Programs.

RPCIFU03

Download Unix File to PC

RPCIFU04

Upload PC File to Unix File

Regards

vijay

Former Member
0 Kudos

Hai Swabap

Try with the following Code

&----


*& Report ZTRAINING_FILE_UPLOAD_APPL *

*& *

&----


*& *

*& *

&----


REPORT ZTRAINING_FILE_UPLOAD_APPL message-id ztraining .

----


  • types

----


**-- types for data to be downloaded

types: begin of tp_kna1,

KUNNR type kna1-kunnr, " customer number

LAND1 type kna1-land1, " Country Key

NAME1 type kna1-name1, " customer name

ORT01 type kna1-ort01, " city

PSTLZ type kna1-pstlz, " postal code

REGIO type kna1-regio, " region

end of tp_kna1.

----


  • I n t e r n a l T a b l e s

----


**-- Internal table for data to be downloaded

data: it_kna1 type standard table of tp_kna1 with header line.

----


  • S e l e c t i o n S c r e e n

----


selection-screen begin of block b1 with frame title text-001.

parameters: p_afile type rlgrap-filename

default 'customer.txt'.

selection-screen end of block b1.

----


----


  • S t a r t o f s e l e c t i o n

----


start-of-selection.

*-- Upload the data from Sales Deal file

perform upload_app_file.

end-of-selection.

perform write_data.

*&----


*& Form upload_app_file

*&----


  • Upload the application server file data

*----


form upload_app_file.

data: l_msg(100). " error message

open dataset p_afile for input in text mode encoding default message

l_msg.

if sy-subrc <> 0.

message i004 with l_msg.

else.

do.

read dataset p_afile into it_kna1.

if sy-subrc = 0.

append it_kna1.

clear it_kna1.

else.

exit.

endif.

enddo.

close dataset p_afile.

endif.

endform. " upload_app_file

&----


*& Form write_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM write_data .

loop at it_kna1.

write:/ it_kna1-kunnr,

it_kna1-land1,

it_kna1-name1,

it_kna1-ort01,

it_kna1-pstlz,

it_kna1-regio.

endloop.

ENDFORM. " write_data

Thanks & regards

Sreenivasulu P