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

Opening files on Application server!!

Former Member
0 Likes
785

Hi all,

My requirement is I have 6 plants for which I have two internal tables in which data is coming from

a function module. Now here inside a loop at plant I want to open 6 files from one internal table and 6 from another table. Files are getting opened for both tables once and after its trying to open the same files due to which am getting an error.

Inside a perform :

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

inputfile-zprc = '\usr\sap\QAS\DVEBMGS00\work\ZJOHN.TXT'.

append inputfile.

inputfile-zprc = '\usr\sap\QAS\DVEBMGS00\work\test1.txt'.

append inputfile.

inputfile-zprc = '\usr\sap\QAS\DVEBMGS00\work\TEST.TXT'.

append inputfile.

inputfile-zprc = '\usr\sap\QAS\DVEBMGS00\work\ZSAMPLE.TXT'.

append inputfile.

inputfile-zprc = '\usr\sap\QAS\DVEBMGS00\work\ZSAMPLE2.TXT'.

append inputfile.

inputfile-zprc = '\usr\sap\QAS\DVEBMGS00\work\ZSAMPLE1.TXT'.

append inputfile.

CLEAR INPUTFILE.

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

LOOP AT inputfile.

PERFORM OPEN_DATASET USING w_input_file.

PERFORM PASS_FILE.

ENDLOOP.

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

outfile-zprc = '\usr\sap\QAS\DVEBMGS00\work\ZSITA.TXT'.

append outfile.

outfile-zprc = '\usr\sap\QAS\DVEBMGS00\work\ZSITA1.txt'.

append outfile.

outfile-zprc = '\usr\sap\QAS\DVEBMGS00\work\ZSITA2.TXT'.

append outfile.

outfile-zprc = '\usr\sap\QAS\DVEBMGS00\work\ZSITA4.TXT'.

append outfile.

outfile-zprc = '\usr\sap\QAS\DVEBMGS00\work\ZSITA5.TXT'.

append outfile.

outfile-zprc = '\usr\sap\QAS\DVEBMGS00\work\ZSITA6.TXT'.

append outfile.

clear outfile.

refresh outfile.

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

LOOP AT outfile.

PERFORM OUT_DATASET USING w_OUTPUT_file.

PERFORM OUT_FILE.

ENDLOOP.

ENDFORM. "OPEN_FILE

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

FORM OPEN_DATASET USING p_w_input_file.

w_input_file = inputfile-zprc.

OPEN DATASET w_input_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc NE c_zero.

MESSAGE a002 WITH w_input_file. "File & could not be opened

ENDIF.

ENDFORM.

FORM PASS_FILE.

R_VAR = R_VAR + 1.

CASE R_VAR.

WHEN 1.

w_input_file1 = inputfile-zprc.

WHEN 2.

w_input_file2 = inputfile-zprc.

WHEN 3.

w_input_file3 = inputfile-zprc.

WHEN 4.

w_input_file4 = inputfile-zprc.

WHEN 5.

w_input_file5 = inputfile-zprc.

WHEN 6.

w_input_file6 = inputfile-zprc.

WHEN OTHERS.

ENDCASE.

ENDFORM.

Thanks & Regards

Jerry

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
728

Hi Jerry,

Looking at the code I can see some problems:

1) You are not passing the file name to the open_dataset routine correctly. See Below for correction.

LOOP AT inputfile.

PERFORM OPEN_DATASET USING inputfile-zprc.

PERFORM PASS_FILE.

ENDLOOP.

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

LOOP AT outfile.

PERFORM OUT_DATASET USING outfile-zprc.

PERFORM OUT_FILE.

ENDLOOP.

ENDFORM. "OPEN_FILE

2) The datasets need to be closed. after reading the content.

Open Input Files

Read Input Files into Internal Tables or Process 1 record at a time building up output files in an internal table

Close Input Files

Open Output Files

Transfer data to output files

Close Output Files.

5 REPLIES 5
Read only

former_member585060
Active Contributor
0 Likes
728

Try to use CLOSE DATASET also inside the loop at input file & endloop. In ur code there is no CLOSE DATASET. May be thats why u r getting error. Try it and see...

Read only

Former Member
0 Likes
729

Hi Jerry,

Looking at the code I can see some problems:

1) You are not passing the file name to the open_dataset routine correctly. See Below for correction.

LOOP AT inputfile.

PERFORM OPEN_DATASET USING inputfile-zprc.

PERFORM PASS_FILE.

ENDLOOP.

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

LOOP AT outfile.

PERFORM OUT_DATASET USING outfile-zprc.

PERFORM OUT_FILE.

ENDLOOP.

ENDFORM. "OPEN_FILE

2) The datasets need to be closed. after reading the content.

Open Input Files

Read Input Files into Internal Tables or Process 1 record at a time building up output files in an internal table

Close Input Files

Open Output Files

Transfer data to output files

Close Output Files.

Read only

0 Likes
728

Hi , thanks for your help!!

Now I am not getting any error in openings files on application server but when I have to transfer the data that is fetched from database to app server files data is not getting transferred........

p1 = 2.

form conver_data using p1.

FIELD-SYMBOLS <ff>.

DO.

CASE p1.

WHEN 1.

ASSIGN COMPONENT sy-index OF STRUCTURE header_record TO <ff>.

WHEN 2.

ASSIGN COMPONENT sy-index OF STRUCTURE out_rec1 TO <ff>.

WHEN 3.

ASSIGN COMPONENT sy-index OF STRUCTURE itab_hts TO <ff>.

WHEN 4.

ASSIGN COMPONENT sy-index OF STRUCTURE header_record TO <ff>.

WHEN 5.

ASSIGN COMPONENT sy-index OF STRUCTURE out_rec2 TO <ff>.

WHEN 6.

ASSIGN COMPONENT sy-index OF STRUCTURE trailer_record TO <ff>.

ENDCASE.

***Break at internal table inside of itab_material table

IF sy-index EQ 9.

EXIT.

ENDIF.

IF sy-subrc <> 0.

EXIT.

ENDIF.

  • following needed if you need a field separator within the record

  • if sy-index > 1.

  • MOVE C_SEPARATOR TO W_WA+W_OFFSET(C_ONE).

  • w_rec_len = w_rec_len + c_one.

  • w_offset = w_offset + c_one.

  • endif.

DESCRIBE FIELD <ff> OUTPUT-LENGTH w_len.

w_rec_len = w_rec_len + w_len.

MOVE <ff> TO w_wa+w_offset(w_len).

w_offset = w_offset + w_len.

ENDDO.

endform

TRANSFER w_wa TO w_output_file1 LENGTH w_rec_len.

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

TRANSFER w_wa TO w_output_file2 LENGTH w_rec_len.

TRANSFER w_wa TO w_output_file3 LENGTH w_rec_len.

TRANSFER w_wa TO w_output_file4 LENGTH w_rec_len.

TRANSFER w_wa TO w_output_file5 LENGTH w_rec_len.

TRANSFER w_wa TO w_output_file6 LENGTH w_rec_len.

Your help is appreciated

Thanks & Regards

Jerry

Read only

0 Likes
728

Hi Jerry,

Personally I am not a big fan of using field-symbols in this way.

My preference would be as follows:

form conver_data using p1.

field-symbols: <fs> type any.

data: l_text(50) type c.

CASE p1.

WHEN 1.

ASSIGN COMPONENT sy-index OF STRUCTURE header_record TO <fs>

WHEN 2.

do 9 times.

ASSIGN COMPONENT sy-index OF STRUCTURE out_rec1 TO <fs>.

if sy-subrc eq 0. "Test if assignment worked

l_text = <fs>.

concatenate w_wa l_text into w_wa separated by c_separator.

endif.

enddo.

WHEN 3.

ASSIGN COMPONENT sy-index OF STRUCTURE itab_hts TO <fs>

WHEN 4.

ASSIGN COMPONENT sy-index OF STRUCTURE header_record TO <fs>

WHEN 5.

ASSIGN COMPONENT sy-index OF STRUCTURE out_rec2 TO <fs>

WHEN 6.

ASSIGN COMPONENT sy-index OF STRUCTURE trailer_record TO <fs>

ENDCASE.

endform.

Kind Regards

David Cooper

Edited by: David Cooper on Aug 18, 2008 11:30 AM

Read only

0 Likes
728

Hi, thanks for your answer!!!

As I said I have 6 company codes and for each company code the plant information should be transferred to outfile i.e 6 plants info should be transferred to 6 output files of app server.

LOOP AT S_COMPCODE.

outfile-zprc = '\usr\sap\QAS\DVEBMGS00\work\ZJOHN.TXT'.

append outfile.

outfile-zprc = '\usr\sap\QAS\DVEBMGS00\work\test1.txt'.

append outfile.

outfile-zprc = '\usr\sap\QAS\DVEBMGS00\work\TEST.TXT'.

append outfile.

outfile-zprc = '\usr\sap\QAS\DVEBMGS00\work\ZSAMPLE.TXT'.

append outfile.

outfile-zprc = '\usr\sap\QAS\DVEBMGS00\work\ZSAMPLE2.TXT'.

append outfile.

outfile-zprc = '\usr\sap\QAS\DVEBMGS00\work\ZSAMPLE1.TXT'.

append outfile.

CLEAR OUTFILE.

LOOP AT outfile.

PERFORM OUT_DATASET USING w_output_file.

PERFORM OUT_FILE.

ENDLOOP.

ENDFORM.