‎2008 Jul 17 6:07 AM
Hello,
I have a question, can we read multiple files from a folder on application server?
I have a requirement where we have to process multiple files by running the program only once.
If we can read the folder then how?
thanks
‎2008 Jul 17 6:09 AM
you can use the FM RZL_READ_DIR_LOCAL to list the files on the app server.
check this sample code:
PARAMETER: p_fdir type pfeflnamel DEFAULT 'usrsapYRDSYSprofile'.
data:
t_files like salfldir occurs 0 with header line.
*START-OF-SELECTION
START-OF-SELECTION.
* Retrieving the list of files in the given directory
call function 'RZL_READ_DIR_LOCAL'
exporting
name = p_fdir
tables
file_tbl = t_files.
* List of files are contained within table it_filedir
loop at t_files.
write: / t_files-NAME.
endloop.[for more info check this link|http://www.sapdevelopment.co.uk/file/file_disall.htm]
‎2008 Jul 17 6:09 AM
you can use the FM RZL_READ_DIR_LOCAL to list the files on the app server.
check this sample code:
PARAMETER: p_fdir type pfeflnamel DEFAULT 'usrsapYRDSYSprofile'.
data:
t_files like salfldir occurs 0 with header line.
*START-OF-SELECTION
START-OF-SELECTION.
* Retrieving the list of files in the given directory
call function 'RZL_READ_DIR_LOCAL'
exporting
name = p_fdir
tables
file_tbl = t_files.
* List of files are contained within table it_filedir
loop at t_files.
write: / t_files-NAME.
endloop.[for more info check this link|http://www.sapdevelopment.co.uk/file/file_disall.htm]
‎2008 Jul 17 6:12 AM
hi.....
what i can suggest you is..you can use radiobuttons for read different file and get data seperately.
coz at one go you wont be able to read the data from multiple files.You can have diffrnt radiobuttons for diffrent files and read the data into internal table accorindgly.may be this can sole your purpose of reading multiple files from application serer in a single program.
just try...
‎2008 Jul 17 6:19 AM
Hi,
You can read multiple files.
define a form and call it passing the file name and internal table name.
The form will have simple code of Open Dataset anmd so.
However, you should know how many files you are going to read. Be it 5 or 50.
You will have to call these many times.
But if you have random files, like today you want 5 files and tomorrow 17, it may not be useful or additional logic may be required.
Hope this helps.
reaghrds
‎2008 Jul 17 6:31 AM
EPS_GET_DIRECTORY_LISTING
try this fm.................
u can do it like this.......
c first u maintain file in the application server in a flow.
like txt1,txt2,txt3..............
and then..
create a table
name
num
path
r the 3 fields in that table...........
once u read the first file use a count and incr the count...
for a first time the table holds
name as txt
num as 1
path as xxx
next time update the num fiels as 2... and proceed...
for exp: u first file name is txt1(con txt and 1) and pass as txt1
next time txt 2 like that u can proceed............
u can refer this program
tables: zdms_textno.
data: begin of it_upload1 occurs 0,
kunnr like vbak-kunnr,
pno like vbrk-bstnk_vf,
idate(10), " like vbrk-fkdat,
pernr like p0000-pernr,
end of it_upload1.
data: begin of it_upload2 occurs 0,
pno like vbrk-bstnk_vf,
matnr like vbrp-matnr,
kwmeng like rv45a-kwmeng,
end of it_upload2.
data : begin of t_mail_data_01 occurs 0,
vbeln type vbeln_va, "Sales Document
erdat type erdat, "Date on which the record was created
auart type auart, "Sales Document Type
vkorg type vkorg, "Sales Organization
vtweg type vtweg, "Distribution Channel
spart type spart, "Division
vkgrp type vkgrp, "Sales Group
vkbur type vkbur, "Sales Office
gsber type gsber, "Business Area
bstnk type bstnk, "Customer purchase order number
bsark type bsark, "Customer purchase order type
bstdk type bstdk, "Customer purchase order date
kunnr type kunag, "Sold-to party
posnr type posnr_va, "Sales Document Item
matnr type matnr, "Material Number
kwmeng type menge_d, "Cumulative order quantity in sales units
netwr type dmbtr, "Net value of the order item in document currency
werks type werks_ext, "Plant (Own or External)
kannr type char45, "Customer Nmae
end of t_mail_data_01.
data : begin of t_detail_offi occurs 0,
vkorg type vkorg, "Sales Organization
vtweg type vtweg, "Distribution Channel
spart type spart, "Division
vkbur type vkbur, "Sales Office
end of t_detail_offi.
data : begin of t_mail_data occurs 0,
vbeln type vbeln_va, "Sales Document
erdat type erdat, "Date on which the record was created
auart type auart, "Sales Document Type
vkorg type vkorg, "Sales Organization
vtweg type vtweg, "Distribution Channel
spart type spart, "Division
vkgrp type vkgrp, "Sales Group
vkbur type vkbur, "Sales Office
gsber type gsber, "Business Area
bstnk type bstnk, "Customer purchase order number
bsark type bsark, "Customer purchase order type
bstdk type bstdk, "Customer purchase order date
kunnr type kunag, "Sold-to party
posnr type posnr_va, "Sales Document Item
matnr type matnr, "Material Number
kwmeng type char17, "Cumulative order quantity in sales units
netwr type char17, "Net value of the order item in document currency
werks type werks_ext, "Plant (Own or External)
kannr type char45, "Customer Nmae
end of t_mail_data.
data : begin of t_bdc_output_data occurs 0,
vbeln type vbeln_va, "Sales Document
kunnr type kunag, "Sold-to party
matnr TYPE matnr, "Material Number
end of t_bdc_output_data.
data: begin of it_up1 occurs 0,
string1(66),
end of it_up1.
data: begin of it_up2 occurs 0,
string2(70),
end of it_up2.
data: it_zdms_textno like zdms_textno occurs 0 with header line.
data: it_order like standard table of zdms_log with header line.
data: bdcdata like bdcdata occurs 0 with header line.
data: gt_bdcmsg like bdcmsgcoll occurs 0 with header line,
file1 type rlgrap-filename .
data: it_textno like zdms_textno occurs 0,
wa_textno like line of it_textno .
data : gv_filenum like zdms_textno-filenumber ,
gv_filenumc(10) type c .
*DATA : gv_path TYPE rlgrap-filename.
data : gv_path(100) type c.
data: gv_file1 type string.
data: gv_char1(15) ,
gv_char2(16),
gv_char3(15),
gv_qty(15),
n type i,
m(2),
gv_msg(50),
gv_kwmeng(15),
gv_kwmeng1(15),
gv_string1(66),
gv_string2(70),
numc1(10),
rec(70) ,
ln type i,
gv_pernr(8),
gv_pernr1(8),
p type i .
data : lw_string type string.
data : wa_order like line of it_order.
data : mess type string.
data : d_server type string value 'r3prod_EEP_05'.
start-of-selection.
ln = 2 .
while ln gt 1 .
Start of Added by Durai.V 30-May-2008******
clear it_upload1.
clear it_upload1[].
clear it_upload2.
clear it_upload2[].
End of Added by Durai.V 30-May-2008********
perform upload.
if sy-subrc ne 0 .
exit.
endif.
perform bdc_execute.
endwhile.
*****************
Form Upload
**************
form upload.
clear: gv_filenum ,
gv_filenumc,
gv_file1 ,
gv_path,
wa_textno .
select single filenumber path
from zdms_textno
into (gv_filenum,gv_path)
where filename eq 'INCOMING' .
move gv_filenum to gv_filenumc .
shift gv_filenumc left deleting leading '0'.
*
data: begin of it001 occurs 0,
bukrs type t001-bukrs,
butxt type t001-butxt,
end of it001.
*concatenate 'F:\usr\sap\EED\DVEBMGS00\work\EFC_Indent_Hdr_'
concatenate gv_path 'EFC_Indent_Hdr_'
gv_filenumc
'.txt'
into gv_file1 .
Start of Added by Durai.V 30-May-2008******
clear it_up1.
clear it_up1[].
End of Added by Durai.V 30-May-2008********
call function 'DX_FILE_READ' destination d_server
exporting
filename = gv_file1
tables
data_tab = it_up1
exceptions
no_file_on_server = 1
no_data_on_server = 2
gui_upload_failed = 3
no_authority = 4
others = 5.
if sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
write : gv_file1 , 'File not found'.
exit.
endif.
Start of Added by Durai.V 30-May-2008******
write : / 'Application Server File Path for Header: ',gv_file1.
End of Added by Durai.V 30-May-2008********
*************************************Commented By Anbu****************************************************
OPEN DATASET gv_file1 FOR INPUT IN TEXT MODE ENCODING DEFAULT MESSAGE mess .
*
IF sy-subrc = 0.
DO.
READ DATASET gv_file1 INTO rec .
IF sy-subrc = 0.
MOVE rec TO it_up1-string1.
APPEND it_up1 .
ELSE.
EXIT.
ENDIF.
ENDDO .
ELSE .
WRITE : gv_file1 , mess, 'File not found'.
EXIT. "MESSAGE ID 'SDV' TYPE 'E' NUMBER '000' WITH 'Header File Not Available' .
ENDIF.
close dataset gv_file1 .
*************************************Ended By Anbu****************************************************
if sy-subrc = 0.
wa_textno-filename = 'INCOMING' .
wa_textno-filenumber = gv_filenum + 1 .
wa_textno-path = gv_path.
shift zdms_textno left deleting leading ' ' .
modify zdms_textno from wa_textno .
endif.
loop at it_up1.
gv_string1 = it_up1-string1.
if gv_string1 eq 'EOF' .
exit.
else.
split gv_string1 at '~' into: it_upload1-kunnr it_upload1-pno it_upload1-idate it_upload1-pernr .
clear : gv_pernr ,gv_pernr1, p .
p = 0 .
move it_upload1-pernr to gv_pernr1 .
do 8 times.
if ( gv_pernr1(1) eq '0' or gv_pernr1p(1) eq '1' or gv_pernr1p(1) eq '2' or gv_pernr1p(1) eq '3' or gv_pernr1p(1) eq '4'
or gv_pernr1p(1) eq '5' or gv_pernr1p(1) eq '6' or gv_pernr1p(1) eq '7' or gv_pernr1p(1) eq '8'
or gv_pernr1+p(1) eq '9' ).
concatenate gv_pernr1
gv_pernr1+p(1)
into gv_pernr1.
p = p + 1.
else.
exit.
endif.
enddo.
move gv_pernr to it_upload1-pernr .
append it_upload1.
clear gv_string1 .
endif.
endloop.
clear: gv_filenumc,
gv_file1 ,
wa_textno .
gv_filenum = gv_filenum + 1 .
move gv_filenum to gv_filenumc .
shift gv_filenumc left deleting leading '0'.
if gv_filenum < 10 .
concatenate '0' gv_filenumc into gv_filenumc .
endif.
*concatenate 'F:\usr\sap\EED\DVEBMGS00\work\EFC_Indent_Trn_'
concatenate gv_path 'EFC_Indent_Trn_'
gv_filenumc
'.txt'
into gv_file1 .
Start of Added by Durai.V 30-May-2008******
clear it_up2.
clear it_up2[].
End of Added by Durai.V 30-May-2008********
call function 'DX_FILE_READ' destination d_server
exporting
filename = gv_file1
SERVER =
pc =
tables
data_tab = it_up2
exceptions
no_file_on_server = 1
no_data_on_server = 2
gui_upload_failed = 3
NO_AUTHORITY = 4
others = 5
.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
write : gv_file1 , 'File not found'.
exit.
endif.
Start of Added by Durai.V 30-May-2008******
write : / 'Application Server File Path for Item : ',gv_file1.
End of Added by Durai.V 30-May-2008********
*************************************Commented By Anbu****************************************************
OPEN DATASET gv_file1 FOR INPUT IN TEXT MODE ENCODING DEFAULT MESSAGE mess .
IF sy-subrc = 0 .
DO.
READ DATASET gv_file1 INTO rec .
IF sy-subrc = 0.
MOVE rec TO it_up2-string2.
APPEND it_up2 .
ELSE.
EXIT.
ENDIF.
ENDDO.
ELSE.
WRITE : gv_file1 , mess , 'File not found'.
EXIT. "MESSAGE ID 'SDV' TYPE 'E' NUMBER '000' WITH 'Transaction File Not Available' .
ENDIF.
close dataset gv_file1.
*************************************Ended By Anbu****************************************************
if sy-subrc = 0.
wa_textno-filename = 'INCOMING' .
wa_textno-filenumber = gv_filenum + 1 .
wa_textno-path = gv_path.
modify zdms_textno from wa_textno .
endif.
loop at it_up2.
gv_string2 = it_up2-string2.
if gv_string2 eq 'EOF' .
exit.
else.
split gv_string2 at '~' into: it_upload2-pno it_upload2-matnr gv_kwmeng1 .
shift gv_kwmeng1 right deleting trailing '#' .
shift gv_kwmeng1 left deleting leading '' .
clear : gv_kwmeng ,p .
p = 0 .
do 15 times.
if ( gv_kwmeng1p(1) eq '0' or gv_kwmeng1p(1) eq '1' or gv_kwmeng1p(1) eq '2' or gv_kwmeng1p(1) eq '3' or gv_kwmeng1+p(1) eq '4'
or gv_kwmeng1p(1) eq '5' or gv_kwmeng1p(1) eq '6' or gv_kwmeng1p(1) eq '7' or gv_kwmeng1p(1) eq '8'
or gv_kwmeng1+p(1) eq '9' ).
concatenate gv_kwmeng
gv_kwmeng1+p(1)
into gv_kwmeng.
p = p + 1.
else.
exit.
endif.
enddo.
move gv_kwmeng to it_upload2-kwmeng.
append it_upload2.
clear gv_kwmeng .
clear gv_string2.
endif.
endloop.
endform. " f001-gui_upload
Edited by: Anbu B on Jul 17, 2008 7:40 AM