Google Search - Blog...........

ABAP - Uploading Multiple Files At One Time.



There is a function module for this.. UPLOAD FILES to attach the multiple files .

Here is the sample coding for this …

report zmultiple_upload.
tables: t100,
hrp1000,
t77eo,
t778o,
hrp1500,
hrp1520.

*----internal table declarations

data: begin of msgtbl occurs 0.
include structure bdcmsgcoll.
data: end of msgtbl.

data: itab_1500 type hrp1500 occurs 0 with header line,
itab_1520 type hrp1520 occurs 0 with header line,
itab_1500_updt type hrp1500 occurs 0 with header line,
itab_1520_updt type hrp1520 occurs 0 with header line,
file_path_list like rlgrap occurs 1 with header line.

data: begin of wc_in1500 occurs 0,
mandt type hrp1500-mandt,
plvar type hrp1500-plvar,
otype type hrp1500-otype,
objid type hrp1500-objid,
end of wc_in1500.

data: begin of wc_in1520 occurs 0,
mandt type hrp1520-mandt,
plvar type hrp1520-plvar,
otype type hrp1520-otype,
objid type hrp1520-objid,
end of wc_in1520.

*-----variables declaration

data: wa_total_1500 type i,
wa_total_1520 type i,
wa_begda(10) type c,
dos_type type c.

*----selection screen design

parameters: file1500 like rlgrap-filename default 'C:\HRP1500.txt',
file1520 like rlgrap-filename default 'C:\HRP1520.txt',
testrun as checkbox default 'X' .


*---- start of selection

start-of-selection.

if file1500 cs ':' and sy-fdpos = 1.
dos_type = 'X'.

else.

clear dos_type.

endif.

file_path_list-filename = file1500.
append file_path_list.

call function 'UPLOAD_FILES'
exporting
i_filetype = 'ASC'
i_xpc = dos_type
tables
file_all = wc_in1500
tab_file = file_path_list .

if sy-subrc <> 0.
write: / 'FAILED TO UPLOAD DATA FILE. MESSAGE ID:', sy-msgid.
write: / sy-msgv1.
write: / sy-msgv2.
write: / sy-msgv3.
write: / sy-msgv4.
exit.
endif.

refresh file_path_list.

if file1520 cs ':' and sy-fdpos = 1.
dos_type = 'X'.

else.
clear dos_type.

endif.

file_path_list-filename = file1520.
append file_path_list.

call function 'UPLOAD_FILES'
exporting
i_filetype = 'ASC'
i_xpc = dos_type
tables
file_all = wc_in1520
tab_file = file_path_list .

if sy-subrc <> 0.
write: / 'FAILED TO UPLOAD DATA FILE. MESSAGE ID:', sy-msgid.
exit.
endif.


describe table wc_in1500 lines wa_total_1500.
describe table wc_in1520 lines wa_total_1520.

perform update1500.
perform update1520.

end-of-selection.

*&---------------------------------------------------------------------*
*& Form UPDATE1500
*----------------------------------------------------------------------*

form update1500.

loop at wc_in1500.
clear: itab_1500, itab_1500_updt.
write wc_in1500-plvar to itab_1500-plvar.
write wc_in1500-otype to itab_1500-otype.
write wc_in1500-objid to itab_1500-objid.

select single * from hrp1500
where plvar = itab_1500-plvar
and otype = itab_1500-otype
and objid = itab_1500-objid
and istat = itab_1500-istat
and begda = itab_1500-begda
and endda = itab_1500-endda.

if sy-subrc = 0.
move itab_1500 to itab_1500_updt.
append itab_1500_updt.

else.
append itab_1500.
endif.

endloop.

write: / wa_total_1500, 'RECORDS INPUT FROM FILE FOR HRP1500'.

if testrun ne 'X'.
insert hrp1500 from table itab_1500.
write: / sy-dbcnt, 'RECORDS INSERTED INTO HRP1500'.
update hrp1500 from table itab_1500_updt.
write: / sy-dbcnt, 'RECORDS UPDATED IN HRP1500'.
endif.

endform. " UPDATE1500

*&---------------------------------------------------------------------*
*& Form UPDATE1520
*----------------------------------------------------------------------*

form update1520.

loop at wc_in1520.
clear: itab_1520, itab_1520_updt.
write wc_in1520-plvar to itab_1520-plvar.
write wc_in1520-otype to itab_1520-otype.
write wc_in1520-objid to itab_1520-objid.

select single * from hrp1520
where plvar = itab_1520-plvar
and otype = itab_1520-otype
and objid = itab_1520-objid
and istat = itab_1520-istat
and begda = itab_1520-begda
and endda = itab_1520-endda.

if sy-subrc = 0.
move itab_1520 to itab_1520_updt.
append itab_1520_updt.

else.
append itab_1520.
endif.

endloop.

write: / wa_total_1520, 'RECORDS INPUT FROM FILE FOR HRP1520'.

if testrun ne 'X'.
update hrp1520 from table itab_1520_updt.
write: / sy-dbcnt, 'RECORDS UPDATED HRP1520'.
insert hrp1520 from table itab_1520.
write: / sy-dbcnt, 'RECORDS INSERTED INTO HRP1520'.
endif.

endform. " UPDATE1520



ALSO READ:

- Download A File With The Specified Delimit Character Dynamically.

- Download ABAP Source Code & TEXTPOOL To The Desktop.

- Downloading Programs Into A Folder In Presentation Server.

- Download SAP Data In XML Format.

- Download SAPScript Output To PDF File.


RETURN TO MAIN INDEX:

- Sample Programs On Uploading & Downloading Files.

- Sample Programs On HR ABAP.

- Sample Report Programs On ALV List/ Grid Display.

- Sample Programs On Selection Screen.

- Sample Programs On BDC.

.....Back To MAIN INDEX.



No comments:

Post a Comment