Gui_upload

Hi  i have  one zprogram, it is written for to get the data from application server ,
now i need to change the code to take the file from local drive.
here iam giving the code ,could any one help me in this.
INCLUDE zppiforecasttop.
INCLUDE zppiforecastf01.
SELECTION SCREEN EVENTS
*Check the splitting rules against source file format
AT SELECTION-SCREEN ON RADIOBUTTON GROUP r4.
IF rb_spmon = 'X' AND rb_week = 'X'.
MESSAGE e005(z1) WITH text-t13.
ENDIF.
IF rb_spday <> 'X' AND rb_daily = 'X'.
MESSAGE e005(z1) WITH text-t14.
ENDIF.
F4 value help on filename field
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CLEAR: w_choice, t_filelist.
REFRESH: t_filelist.
w_proc = 'proc'.
w_txt = 'txt'.
get and open logical filename
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
logical_filename = p_lognam
parameter_1 = i_para_1
parameter_2 = i_para_2
parameter_3 = i_para_3
IMPORTING
file_name = w_dir
EXCEPTIONS
file_not_found = 1
OTHERS = 2.
IF sy-subrc NE 0.
MESSAGE e005(z1) WITH text-t18.
ENDIF.
CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
EXPORTING
dir_name = w_dir
file_mask = '.'
TABLES
dir_list = t_files
EXCEPTIONS
invalid_eps_subdir = 1
sapgparam_failed = 2
build_directory_failed = 3
no_authorization = 4
read_directory_failed = 5
too_many_read_errors = 6
empty_directory_list = 7
OTHERS = 8.
*If the return code is not 0 exit from event
IF sy-subrc <> 0.
EXIT.
ELSE.
*Loop at list of files and convert to display format
LOOP AT t_files.
only show processed files with filename 'proc'
SEARCH t_files-name FOR w_proc.
IF sy-subrc = 0.
t_filelist-name = t_files-name.
t_filelist-size = t_files-size.
APPEND t_filelist.
ENDIF.
only show processed files with filename 'txt'
SEARCH t_files-name FOR w_txt.
IF sy-subrc = 0.
t_filelist-name = t_files-name.
t_filelist-size = t_files-size.
APPEND t_filelist.
ENDIF.
ENDLOOP.
IF t_filelist[] IS INITIAL.
EXIT.
ENDIF.
ENDIF.
*Display list of available files in a popup screen
CALL FUNCTION 'POPUP_WITH_TABLE_DISPLAY'
EXPORTING
endpos_col = '100'
endpos_row = '23'
startpos_col = '10'
startpos_row = '5'
titletext = 'Select File'
IMPORTING
choise = w_choice
TABLES
valuetab = t_filelist
EXCEPTIONS
break_off = 1
OTHERS = 2.
IF sy-subrc = 0.
READ TABLE t_filelist INDEX w_choice.
CONCATENATE w_dir t_filelist-name INTO p_file.
ELSE.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Start of Selection
START-OF-SELECTION.
*Check that the filetype corresponds to the selection
PERFORM check_file.
*Upload the file by resolving logical filename.
PERFORM upload_file.
*Depending on the selection criteria, alter the input data into the
*desired format and store.
PERFORM populate_post_split_table.
*Build the idoc of type SOPGEN01
PERFORM post_idoc.
Rename the file extension from '.txt' to '*.proc_yyyymmdd', if
*reprocessing a file do nothing
SEARCH p_file FOR '*txt'.
IF sy-subrc = 0.
PERFORM rename_file.
ENDIF.
End of Selection
END-OF-SELECTION.
*Output error report
PERFORM error_report.
Top of Page
TOP-OF-PAGE.
PERFORM top_of_page.
&#9668;.........this is the first include........................
&#9668;----
INCLUDE ZPPIFORECASTTOP *
TABLES
TABLES: marc, "Plant Data for Material
marm, "Units of Measure for Material
edidd, "Data record (IDoc)
edidc, "Control Segment
e1lipm0, "General characteristic segment
e1lipv0, "General version segment
e1lipp0. "Performance measure segment
SELECTION SCREEN
SELECTION-SCREEN BEGIN OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-t01.
PARAMETERS: rb_1000 RADIOBUTTON GROUP r1 DEFAULT 'X',
rb_1005 RADIOBUTTON GROUP r1.
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-t02.
PARAMETERS: rb_mgx RADIOBUTTON GROUP r2 DEFAULT 'X',
rb_other RADIOBUTTON GROUP r2.
SELECTION-SCREEN END OF BLOCK b3.
SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE text-t03.
PARAMETERS: rb_month RADIOBUTTON GROUP r3 DEFAULT 'X',
rb_week RADIOBUTTON GROUP r3,
rb_daily RADIOBUTTON GROUP r3.
SELECTION-SCREEN END OF BLOCK b4.
SELECTION-SCREEN BEGIN OF BLOCK b5 WITH FRAME TITLE text-t04.
PARAMETERS: rb_spmon RADIOBUTTON GROUP r4 DEFAULT 'X',
rb_spwk RADIOBUTTON GROUP r4,
rb_spday RADIOBUTTON GROUP r4.
SELECTION-SCREEN END OF BLOCK b5.
SELECT-OPTIONS: so_datum FOR sy-datum, " (Planning time horizon)
so_matnr FOR marc-matnr. " (Material Master)
PARAMETERS: p_lognam LIKE filenameci-fileintern
DEFAULT 'ZPPIFORECAST_FILENAME' NO-DISPLAY,
p_file LIKE rlgrap-filename OBLIGATORY. "(Input file)
SELECTION-SCREEN END OF BLOCK b1.
TYPES
TYPES: BEGIN OF workdate,
datum LIKE sy-datum,
day TYPE p,
workday(1) TYPE c,
END OF workdate.
TYPES: BEGIN OF postsplit.
INCLUDE STRUCTURE zppiforecast.
TYPES: fromdat LIKE sy-datum,
todat LIKE sy-datum,
split_date LIKE sy-datum,
split_value(10) TYPE c,
flg_noscp(1) TYPE c,
END OF postsplit.
TYPES: BEGIN OF exception.
INCLUDE STRUCTURE zppiforecast.
TYPES: docnum TYPE docnum,
message TYPE edi_statx_,
END OF exception.
TYPES: BEGIN OF filelist,
name TYPE epsfilnam,
size(10) TYPE c,
END OF filelist.
DATA
DATA: t_files TYPE TABLE OF epsfili INITIAL SIZE 0 WITH HEADER LINE,
i_file TYPE TABLE OF zppiforecast INITIAL SIZE 0 WITH HEADER LINE,
t_exception TYPE TABLE OF exception INITIAL SIZE 0
WITH HEADER LINE,
i_post_split TYPE TABLE OF postsplit INITIAL SIZE 0
WITH HEADER LINE,
t_workdates TYPE TABLE OF workdate INITIAL SIZE 0
WITH HEADER LINE,
t_filelist TYPE TABLE OF filelist INITIAL SIZE 0 WITH HEADER LINE.
DATA: t_edidc TYPE TABLE OF edidc INITIAL SIZE 0 WITH HEADER LINE,
t_edidd TYPE TABLE OF edidd INITIAL SIZE 0 WITH HEADER LINE,
t_edids TYPE TABLE OF edids INITIAL SIZE 0 WITH HEADER LINE.
DATA: w_choice TYPE sy-tabix, "Index of chosen file
w_line(100), "100 character string
w_dir LIKE epsf-epsdirnam, "Directory path
w_hiper LIKE t445p-hiper, "Forecast lower limit
w_fuper LIKE t445p-fuper, "Forecast upper limit
w_count TYPE i, "Counter
w_total TYPE i, "Total
w_start LIKE sy-datum, "Start date in the range
w_end LIKE sy-datum, "End date in the range
w_date LIKE sy-datum, "Curent Date
w_first LIKE sy-datum, "First working date in range
w_flg_noscp(1) TYPE c, "No SCP UoM flag
w_days TYPE butag, "No of days
w_day TYPE p, "Day of the week indicator
w_value LIKE zppiforecast-value, "Record Value
w_post_split TYPE postsplit, "Work area for post split table line
w_docnum LIKE edidc-docnum, "IDOC number
w_docnum_no_zero LIKE w_docnum, " IDOC number wthout zeros
w_statva LIKE stacust-statva,
w_error(1) TYPE c,
w_matnr TYPE matnr,
w_tabix TYPE sytabix,
w_messg TYPE message,
w_msgln TYPE i,
w_todat LIKE sy-datum,
w_fromdat LIKE sy-datum,
w_lines TYPE i,
w_count_idoc_errors TYPE i,
w_count_recs_uploaded TYPE i,
w_count_idoc_posted TYPE i.
DATA: w_proc(4) TYPE c.
DATA: w_txt(4) TYPE c.
DATA: logsys LIKE tbdls-logsys.
CONSTANTS
CONSTANTS: c_uom LIKE marm-meinh VALUE 'SCP', "Unit of measure
c_delim TYPE x VALUE '09',
c_type LIKE rlgrap-filetype VALUE 'DAT',
c_werks_1000 LIKE marc-werks VALUE '1000',
c_werks_1005 LIKE marc-werks VALUE '1005',
c_pltyp_805 LIKE t445p-sctyp VALUE 'Z_805',
c_pltyp_810 LIKE t445p-sctyp VALUE 'Z_810',
c_mestyp_805 TYPE edi_mestyp VALUE 'LIP805',
c_mestyp_810 TYPE edi_mestyp VALUE 'LIP810',
c_rcvprt TYPE edi_rcvprt VALUE 'LS',
c_sndprn TYPE edi_sndprn VALUE 'WEBM_LS',
c_sndprt TYPE edi_sndprt VALUE 'LS'.
&#9668;..............this is the second include.................
&#9668;----
INCLUDE ZPPIFORECASTF01 *
*& Form upload_file
form upload_file.
data: w_matnr like mara-matnr,
w_datum like sy-datum.
*Open file in read mode
open dataset p_file for input in text mode.
if sy-subrc = 0.
do.
clear: t_exception.
*Read line of data into text string variable
read dataset p_file into w_line.
*If successful. append the internal file table
if sy-subrc = 0.
add 1 to w_count_recs_uploaded.
*Split the string at delimiter into internal file table
split w_line at c_delim into i_file-matnr
i_file-datum
i_file-value.
call function 'CONVERSION_EXIT_MATN1_INPUT'
exporting
input = i_file-matnr
importing
output = w_matnr
exceptions
length_error = 1
others = 2.
i_file-index = sy-index.
*Check that the date is in the correct format.
call function 'CONVERT_DATE_TO_INTERN_FORMAT'
exporting
datum = i_file-datum
dtype = 'DATS'
importing
error = w_error
idate = i_file-datum
messg = w_messg
msgln = w_msgln.
*If an error has occurred write entry to error table, otherwise append
*record list
if not w_error is initial.
t_exception = i_file.
t_exception-message = text-006.
append t_exception.
else.
check i_file-datum in so_datum.
append i_file.
endif.
else.
exit.
endif.
enddo.
else.
message w005(z1) with 'File ' p_file ' cannot be opened'.
endif.
*Close the file
close dataset p_file.
endform. " upload_file
*& Form process_monthly
form process_monthly.
data: w_mm type bumon,
w_yyyy type bdatj.
w_mm = i_file-datum+4(2).
w_yyyy = i_file-datum(4).
*Get the number of days in the month
call function 'NUMBER_OF_DAYS_PER_MONTH_GET'
exporting
par_month = w_mm
par_year = w_yyyy
importing
par_days = w_days.
*Set date variable to first day
w_date = i_file-datum.
*Get the first working day in the month
perform get_first_day.
*Set date variable to last day in the month
w_date = i_file-datum + w_days - 1.
*Get the last working day in the month
perform get_last_day.
*Populate the post split table with monthly value
i_post_split-split_value = w_value.
i_post_split-matnr = i_file-matnr.
i_post_split-fromdat = w_fromdat.
i_post_split-todat = w_todat.
i_post_split-datum = i_file-datum.
i_post_split-value = i_file-value.
i_post_split-index = i_file-index.
i_post_split-split_date = i_file-datum.
i_post_split-flg_noscp = w_flg_noscp.
append i_post_split.
endform. " process_monthly
*& Form check_material
form check_material using value(plant) value(pltyp).
*Check that the material plant combination exists
select single matnr from marc into w_matnr
where matnr = i_file-matnr
and werks = plant.
*Check return code, if no record found, write to error table and delete
if sy-subrc <> 0.
w_tabix = sy-tabix.
t_exception = i_file.
t_exception-message = text-001.
append t_exception.
delete i_file index w_tabix.
w_error = 'X'.
exit.
endif.
Start DEVK931385
if plant = c_werks_1000. "DEVK931385
*Check that the material exists in the infotype hierarchy
select single matnr from s805e into w_matnr where ssour = space
and werks = plant
and matnr = i_file-matnr.
else. "DEVK931385
*Check that the material exists in the infotype hierarchy S810e
select single matnr from s810e into w_matnr where ssour = space
and werks = plant
and matnr = i_file-matnr.
endif. "DEVK931385
End DEVK931385
if sy-subrc <> 0.
w_tabix = sy-tabix.
t_exception = i_file.
t_exception-message = text-006.
append t_exception.
delete i_file index w_tabix.
w_error = 'X'.
exit.
endif.
*Get the forcast limits from info structure
select single hiper fuper from t445p into (w_hiper, w_fuper)
where sctyp = pltyp.
*Determine start and end limits for forecasting based on current date
w_start = sy-datum - w_hiper.
Start DEVK931340
w_end = sy-datum + w_fuper. "DEL
w_end = sy-datum + ( ( w_fuper * 7 ) / 5 ).
END DEVK931340
endform. " check_material
12:33:06 PM&#9668;&----
*& Form process_weekly
form process_weekly.
data: w_mm type bumon,
w_yyyy type bdatj.
clear: w_total.
w_date = i_file-datum.
w_mm = i_file-datum+4(2).
w_yyyy = i_file-datum(4).
*If the souce file is in monthly format
if rb_month = 'X'.
*Get the number of days in the current month
call function 'NUMBER_OF_DAYS_PER_MONTH_GET'
exporting
par_month = w_mm
par_year = w_yyyy
importing
par_days = w_days.
*Set date variable to last day in the month
w_date = i_file-datum + w_days - 1.
*Get the last working day in the month
perform get_last_day.
*Set date variable to first day
w_date = i_file-datum.
*Get the first working day in the month
perform get_first_day.
else.
*Otherwise set for days in week
w_days = 7.
endif.
do w_days times.
*Clear the table of workdates
clear: t_workdates.
*Check if the day is a working day
call function 'DATE_CHECK_WORKINGDAY'
exporting
date = w_date
factory_calendar_id = 'GB'
message_type = 'I'
exceptions
date_after_range = 1
date_before_range = 2
date_invalid = 3
date_no_workingday = 4
others = 5.
*If successful, set the workday flag to (Y)es
if sy-subrc = 0.
t_workdates-datum = w_date.
t_workdates-workday = 'Y'.
*Increment the counter for total number of workdays
add 1 to w_total.
else.
*Otherwise (N)o
t_workdates-datum = w_date.
t_workdates-workday = 'N'.
endif.
*Get the day in the week of the current date, (1 = Monday, 7 = Sunday)
call function 'DAY_IN_WEEK'
exporting
datum = w_date
importing
wotnr = t_workdates-day.
append t_workdates.
add 1 to w_date.
enddo.
loop at t_workdates.
*If the day is a workday
if t_workdates-workday = 'Y'.
*If the fromdate is blank, set to current date in loop (first working
*day)
if i_post_split-fromdat is initial.
i_post_split-fromdat = t_workdates-datum.
i_post_split-split_date = t_workdates-datum.
endif.
*Set variable to pick up last working date
i_post_split-todat = t_workdates-datum.
*Increment loop counter
add 1 to w_count.
endif.
*If the day is a Sunday
if ( ( t_workdates-day = 7 or t_workdates-datum+6(2) = w_days )
and w_count <> 0 ).
*Poplulate the post split table
if rb_month = 'X'.
i_post_split-fromdat = w_fromdat.
i_post_split-todat = w_todat.
endif.
i_post_split-matnr = i_file-matnr.
i_post_split-datum = i_file-datum.
i_post_split-value = i_file-value.
i_post_split-index = i_file-index.
i_post_split-split_value = ( ( w_value / w_total ) * w_count ).
i_post_split-flg_noscp = w_flg_noscp.
append i_post_split.
clear: w_count,
i_post_split.
endif.
endloop.
endform. " process_weekly
*& Form get_first_day
form get_first_day.
do w_days times.
call function 'DATE_CHECK_WORKINGDAY'
exporting
date = w_date
factory_calendar_id = 'GB'
message_type = 'I'
exceptions
date_after_range = 1
date_before_range = 2
date_invalid = 3
date_no_workingday = 4
others = 5.
if sy-subrc = 0.
w_fromdat = w_date.
exit.
endif.
add 1 to w_date.
enddo.
endform. " get_first_day
*& Form get_last_day
form get_last_day.
do w_days times.
call function 'DATE_CHECK_WORKINGDAY'
exporting
date = w_date
factory_calendar_id = 'GB'
message_type = 'I'
exceptions
date_after_range = 1
date_before_range = 2
date_invalid = 3
date_no_workingday = 4
others = 5.
if sy-subrc = 0.
w_todat = w_date.
exit.
endif.
subtract 1 from w_date.
enddo.
endform. " get_last_day
12:33:30 PM&#9668;
*& Form process_daily
form process_daily.
data: w_mm type bumon,
w_yyyy type bdatj,
new_w_date like w_date.
clear: w_total.
w_mm = i_file-datum+4(2).
w_yyyy = i_file-datum(4).
w_date = i_file-datum.
if rb_month = 'X'.
*Get the number of days in the current month
call function 'NUMBER_OF_DAYS_PER_MONTH_GET'
exporting
par_month = w_mm
par_year = w_yyyy
importing
par_days = w_days.
*If the source file is in weekly format set to days in week
elseif rb_week = 'X'.
w_days = 7.
else.
*If source file is daily, set to day
w_days = 1.
endif.
do w_days times.
clear: t_workdates.
*Check the current day is a workday
call function 'DATE_CHECK_WORKINGDAY'
exporting
date = w_date
factory_calendar_id = 'GB'
message_type = 'I'
exceptions
date_after_range = 1
date_before_range = 2
date_invalid = 3
date_no_workingday = 4
others = 5.
*If successful, set workday flag to (Y)es and append workday table
if sy-subrc = 0.
t_workdates-datum = w_date.
t_workdates-workday = 'Y'.
append t_workdates.
*Increment total
add 1 to w_total.
START PKA01
else.
Add 1 to w_date and w_days to make it loop again until a the next work
day is found!!!!!
END PKA01
if rb_daily = 'X'.
new_w_date = w_date.
while new_w_date ne ''.
add 1 to new_w_date.
*Check the current day is a workday
call function 'DATE_CHECK_WORKINGDAY'
exporting
date = new_w_date
factory_calendar_id = 'GB'
message_type = 'I'
exceptions
date_after_range = 1
date_before_range = 2
date_invalid = 3
date_no_workingday = 4
others = 5.
if sy-subrc = 0.
t_workdates-datum = new_w_date.
t_workdates-workday = 'Y'.
append t_workdates.
add 1 to w_total.
exit.
endif.
endwhile.
endif.
endif.
*Increment date
add 1 to w_date.
enddo.
*Get the number of workdays in the period
describe table t_workdates lines w_lines.
*Get the first entry in the table
read table t_workdates index 1.
w_fromdat = t_workdates-datum.
*Get the last entry in the table
read table t_workdates index w_lines.
w_todat = t_workdates-datum.
loop at t_workdates.
*Populate the post split table
i_post_split-fromdat = w_fromdat.
i_post_split-todat = w_todat.
i_post_split-split_date = t_workdates-datum.
i_post_split-matnr = i_file-matnr.
i_post_split-datum = i_file-datum.
i_post_split-value = i_file-value.
i_post_split-index = i_file-index.
i_post_split-split_value = w_value / w_total.
i_post_split-flg_noscp = w_flg_noscp.
START PKA01
For daily sorce data which is split daily check that an entry doesnt
already exist in the post split table for this date - only the fromdat
is checked because for daily split fromdat = todat
read table i_post_split into w_post_split
with key matnr = i_file-matnr
fromdat = i_file-datum
split_date = t_workdates-datum.
if sy-subrc = 0.
...an entry exist so add the new value to the existing one and update
the table record
i_post_split-split_value = i_post_split-split_value +
w_post_split-split_value.
append i_post_split.
MODIFY i_post_split from w_post_split index sy-tabix.
else.
END PKA01
append i_post_split.
START PKA01
endif.
END PKA01
endloop.
endform. " process_daily
*& Form check_range
form check_range.
*If file date is not in forcast range discard
if i_file-datum < w_start or i_file-datum > w_end.
w_tabix = sy-tabix.
t_exception = i_file.
t_exception-message = text-002.
append t_exception.
delete i_file index w_tabix.
w_error = 'X'.
endif.
endform. " check_range
*& Form check_uom
form check_uom.
*Get the alternative UoM for Material
select single * from marm where matnr = i_file-matnr
and meinh = c_uom.
if sy-subrc = 0.
w_value = ( i_file-value * ( marm-umren / marm-umrez ) ).
else.
w_value = i_file-value.
w_flg_noscp = 'X'.
endif.
w_flg_noscp = 'X'. "jsa01
endform. " check_uom
*& Form check_first_day
form check_first_day.
*If the date is not the first of the month, copy to error table, delete
*and end current loop process
if i_file-datum+6(2) <> '01'.
w_tabix = sy-tabix.
t_exception = i_file.
t_exception-message = text-003.
append t_exception.
delete i_file index w_tabix.
w_error = 'X'.
endif.
endform. " check_first_day
12:34:00 PM&#9668;&----
*& Form check_monday
form check_monday.
call function 'DAY_IN_WEEK'
exporting
datum = i_file-datum
importing
wotnr = w_day.
*If the day is not a monday, copy to error table, delete
*and end current loop process
if w_day <> 1.
w_tabix = sy-tabix.
t_exception = i_file.
t_exception-message = text-004.
append t_exception.
delete i_file index w_tabix.
w_error = 'X'.
endif.
endform. " check_monday
*& Form populate_post_split_table
form populate_post_split_table.
*Sort the uploaded table by material and date
sort i_file by matnr datum.
loop at i_file.
perform material_internal_format.
*clear loop variables
clear: w_hiper,
w_fuper,
w_count,
w_error,
w_fromdat,
w_todat,
w_flg_noscp,
t_exception.
*Clear the contents of the internal table which holds work days
refresh: t_workdates.
*If plant radiobutton is set
if rb_1000 = 'X'.
*Check the material/plant combination
perform check_material using c_werks_1000 c_pltyp_805.
else.
*Check the material/plant combination
perform check_material using c_werks_1005 c_pltyp_810.
endif.
if w_error = 'X'.
continue.
endif.
*If the uploaded file is in monthly format
if rb_month = 'X'.
*Check that the record is for the first day of the month
perform check_first_day.
if w_error = 'X'.
continue.
endif.
*Check the value is within the range for the infotype
perform check_range.
if w_error = 'X'.
continue.
endif.
*Check that an 'SCP' unit of measure exists and convert value
perform check_uom.
*Otherwise if the file is in weekly format
elseif rb_week = 'X'.
*Check that the record corresponds to a monday
perform check_monday.
if w_error = 'X'.
continue.
endif.
*Check the value is within the range for the infotype
perform check_range.
if w_error = 'X'.
continue.
endif.
*Check that an 'SCP' unit of measure exists and convert value
perform check_uom.
else.
*Check the value is within the range for the infotype
perform check_range.
if w_error = 'X'.
continue.
endif.
*Check that an 'SCP' unit of measure exists and convert value
perform check_uom.
endif.
*If split monthly flag has been chosen
if rb_spmon = 'X'.
*Process value using split monthly process
perform process_monthly.
*Otherwise, if weekly split
elseif rb_spwk = 'X'.
*Process value using split weekly process
perform process_weekly.
*Otherwise daily split
else.
*Process value using split daily process
perform process_daily.
endif.
endloop.
endform. " populate_post_split_table
*& Form build_idoc
Build and submit the idoc for processing
form post_idoc.
*Get the logical system for ALE processing
perform get_ale_data.
check not logsys is initial.
*Populate the IDOC control record
perform build_control_data.
*Sort the data by material, date and value
sort i_post_split by matnr datum value fromdat todat split_date.
*Build idocs and post them
loop at i_post_split.
clear: e1lipp0,
t_exception.
*Move i_post_split header to a work area
w_post_split = i_post_split.
at new datum.
clear: e1lipm0, e1lipv0, t_edidd.
refresh t_edidd.
*Build the general characteristic segment
perform build_e1lipm0_segment.
*Build the general version segment
perform build_e1lipv0_segment.
endat.
*Build the performance measure segment
perform build_e1lipp0_segment.
at end of datum.
*Submit IDOC for inbound processing
perform submit_idoc.
endat.
endloop.
endform. " build_idoc
12:34:22 PM&#9668;&----
*& Form submit_idoc
Start inbound processing of IDOC
form submit_idoc.
clear: w_docnum_no_zero.
call function 'IDOC_WRITE_AND_START_INBOUND'
exporting
i_edidc = edidc
do_commit = 'X'
importing
docnum = w_docnum
tables
i_edidd = t_edidd
exceptions
idoc_not_saved = 1
others = 2.
if sy-subrc = 0.
call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
exporting
input = w_docnum
importing
output = w_docnum_no_zero.
perform check_idoc_status_records.
else.
t_exception-index = w_post_split-index.
t_exception-matnr = w_post_split-matnr.
t_exception-datum = w_post_split-datum.
t_exception-message = t_edids-statxt.
append t_exception.
w_error = 'X'.
endif.
*If the no SCP UoM flag is set, write an entry to exception table
if w_post_split-flg_noscp = 'X'.
t_exception-index = w_post_split-index.
t_exception-matnr = w_post_split-matnr.
t_exception-datum = w_post_split-datum.
t_exception-value = w_post_split-value.
t_exception-docnum = w_docnum_no_zero.
t_exception-message = text-005.
append t_exception.
endif.
endform. " write_idoc
*& Form build_control_data
*& Build the IDOC control record
form build_control_data.
clear edidc.
edidc-idoctp = 'SOPGEN01'. " Basic type
if rb_1000 = 'X'.
edidc-mestyp = c_mestyp_805. " Message type
else.
edidc-mestyp = c_mestyp_810. " Message type
endif.
edidc-rcvprt = c_rcvprt. " Partner type of receiver
concatenate 'SAP' sy-sysid(3) into edidc-rcvpor. " Receiver port
concatenate sy-sysid(3) 'CLNT' sy-mandt into edidc-rcvprn.
edidc-direct = '2'. " Inbound
concatenate 'SAP' sy-sysid(3) into edidc-sndpor.
edidc-sndprt = c_sndprt. " Partner type of sender
edidc-sndprn = c_sndprn. " Partner number of sender
endform. " get_control_data
*& Form get_ale_data
Get logical system for ALE processing
form get_ale_data.
call function 'OWN_LOGICAL_SYSTEM_GET'
importing
own_logical_system = logsys
exceptions
own_logical_system_not_defined = 1
others = 2.
if sy-subrc <> 0.
clear logsys.
endif.
endform. " get_ale_data
*& Form build_e1lipv0_segment
Create the general version segment
form build_e1lipv0_segment.
e1lipv0-vrsio = 'A00'.
e1lipv0-avrsi = 'X'.
e1lipv0-vetxt = 'Active Version'.
move e1lipv0 to t_edidd-sdata.
move 'E1LIPV0' to t_edidd-segnam.
t_edidd-hlevel = '02'.
append t_edidd.
endform. " send_idoc
*& Form build_e1lipm0_segment
form build_e1lipm0_segment.
e1lipm0-vontg = w_post_split-fromdat.
e1lipm0-bistg = w_post_split-todat.
e1lipm0-perio = '0'.
if rb_1000 = 'X'.
e1lipm0-m01 = c_werks_1000.
else.
e1lipm0-m01 = c_werks_1005.
endif.
e1lipm0-m02 = w_post_split-matnr.
e1lipm0-m03 = 'SCP'.
e1lipm0-m06 = 'T'.
move e1lipm0 to t_edidd-sdata.
move 'E1LIPM0' to t_edidd-segnam.
t_edidd-hlevel = '01'.
append t_edidd.
endform. " build_e1lipm0_segment
*& Form build_e1lipp0_segment
form build_e1lipp0_segment.
e1lipp0-sptag = w_post_split-split_date.
if rb_mgx = 'X'.
e1lipp0-kz02 = w_post_split-split_value.
e1lipp0-kz03 = '/'.
else.
e1lipp0-kz02 = '/'.
e1lipp0-kz03 = w_post_split-split_value.
endif.
move e1lipp0 to t_edidd-sdata.
move 'E1LIPP0' to t_edidd-segnam.
t_edidd-hlevel = '03'.
append t_edidd.
endform. " build_e1lipp0_segment
*& Form check_idoc_status_records
form check_idoc_status_records.
clear: t_edids.
refresh: t_edids.
select * from edids into table t_edids where docnum = w_docnum.
clear: w_error.
loop at t_edids.
clear: w_statva.
select single statva from stacust into w_statva
where status = t_edids-status.
case w_statva.
*When the status group is of type 'E' or 'F'.
when 'E' or 'F'.
t_exception-value = w_post_split-value.
t_exception-index = w_post_split-index.
t_exception-matnr = w_post_split-matnr.
t_exception-datum = w_post_split-datum.
t_exception-docnum = w_docnum_no_zero.
t_exception-message = t_edids-statxt.
append t_exception.
w_error = 'X'.
when others.
endcase.
endloop.
if w_error is initial.
add 1 to w_count_idoc_posted.
else.
add 1 to w_count_idoc_errors.
endif.
endform. " check_idoc_status_records
12:34:35 PM&#9668;&----
*& Form rename_file
Form to rename file
form rename_file.
data: l_filename_new(120), " New filename
l_filename_temp(120), " Temporary filename
l_command(250), " Unix command line
w_extension(14).
move p_file to l_filename_new.
*Replace the file extension of the file to indicate that it has been
*processed
concatenate '.proc_' sy-datum into w_extension.
replace '.txt' with w_extension into l_filename_new.
Create UNIX rename command
concatenate 'mv' p_file l_filename_new
into l_command separated by space.
Create temporary unique file name
concatenate p_file 'TEMP'
into l_filename_temp.
move l_filename_new to p_file.
Open temporary dataset but use the filter command to execute the UNIX
rename command 'mv'.
This method has been used instead of SAP external commands because
of file length limitations. The external command only allows a line of
128 chars which means filenames can only be about 62chars when doing
a move i.e. mv <file1> <file2>
open dataset l_filename_temp for output filter l_command.
if sy-subrc ne 0.
message e005(z1) with text-007.
exit.
endif.
Close the temporary dataset
close dataset l_filename_temp.
if sy-subrc ne 0.
message e005(z1) with text-007.
exit.
endif.
Delete the temporary dataset
delete dataset l_filename_temp.
if sy-subrc ne 0.
message e005(z1) with text-007.
exit.
endif.
endform. " rename_file
*& Form material_internal_format
form material_internal_format.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = i_file-matnr
importing
output = i_file-matnr.
endform. " material_internal_format
*& Form error_report
form error_report.
format color col_normal.
skip.
*Loop at exception table and output contents
loop at t_exception.
write: / t_exception-index,
t_exception-matnr,
24 t_exception-datum,
t_exception-value right-justified,
t_exception-docnum,
t_exception-message.
endloop.

hi,
define internal table. e.g. it_data & follow the steps
PARAMETERS: p_rfname LIKE rlgrap-filename OBLIGATORY.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_rfname.
  PERFORM get_desktop_file_help.
     Form  get_desktop_file_help
FORM get_desktop_file_help.
  DATA : v_file LIKE rlgrap-filename.
  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    EXPORTING
      program_name  = syst-repid
      dynpro_number = syst-dynnr
      field_name    = 'P_RFNAME'
    CHANGING
      file_name     = v_file
    EXCEPTIONS
      mask_too_long = 1
      OTHERS        = 2.
  IF sy-subrc <> 0.
    MESSAGE i368(00) WITH 'Enter Correct File'.
    STOP.
  ELSE.
    MOVE : v_file TO p_rfname.
  ENDIF.
ENDFORM.                    " get_desktop_file_help
START-OF-SELECTION.
  PERFORM upload_file_from_desktop CHANGING g_error.
     Form  upload_file_from_desktop
FORM upload_file_from_desktop CHANGING p_error.
  IF NOT sy-batch IS INITIAL.
    MESSAGE e368(00) WITH 'Files can only be uploaded'
                          'in foreground'.
  ELSE.
    CALL FUNCTION 'WS_UPLOAD'
      EXPORTING
        filename                = p_rfname
        filetype                = 'DAT'
      TABLES
        data_tab                = it_data
      EXCEPTIONS
        conversion_error        = 1
        invalid_table_width     = 2
        invalid_type            = 3
        no_batch                = 4
        unknown_error           = 5
        gui_refuse_filetransfer = 6
        OTHERS                  = 7.
    IF sy-subrc NE 0.
      MESSAGE i368(00) WITH 'Error while reading data from file'.
      MOVE : 'X' TO p_error.
    ENDIF.
  ENDIF.
ENDFORM.                    "upload_file_from_desktop
raj

Similar Messages

  • Difference between GUI_UPLOAD and WS_UPLOAD

    Hi,
    Please make me clear about the difference between GUI_UPLOAD and WS_UPLOAD. In which cases we need to use these modules...??
    Thanks,
    Satish

    I would suggest to always use the GUI_UPLOAD.  I say this because this is the function module which is used in the GUI_UPLOAD method of the class CL_GUI_FRONTEND_SERVICES.   Really, you should probably use the class/method instead of the function module.
      data: filename type string.
      filename = p_file.
      call method cl_gui_frontend_services=>gui_upload
             exporting
                  filename                = filename
                  filetype                = 'ASC'
             changing
                  data_tab                = iflatf
             exceptions
                  file_open_error         = 1
                  file_read_error         = 2
                  no_batch                = 3
                  gui_refuse_filetransfer = 4
                  no_authority            = 6
                  unknown_error           = 7
                  bad_data_format         = 8
                  unknown_dp_error        = 12
                  access_denied           = 13
                  others                  = 17.
    Regards,
    Rich Heilman

  • WS_UPLOAD,WS_DOWNLOAD and GUI_UPLOAD,GUI_DOWNLOAD.

    Hi,
    Any one Explain difference between WS_UPLOAD,WS_DOWNLOAD and GUI_UPLOAD,GUI_DOWNLOAD.
    Regards,
    Maya

    hi maya,
       ws_upload and gui_upload, will do the same funtionality.
    ws_download and gui_download will do the same functionality.
    but ws* are obsolete.
    Regards....
    Arun.
    Reward points if useful.

  • "Cannot interpret data in file" error while using GUI_UPLOAD for .xls file

    Hi,
         I have made a program using FM GUI_UPLOAD to upload an .xls file to an internal table. But upon executing ,it gives error "Cannot Interpret data in file". I have seen in other posts people talking about GUI_UPLOAD FM to upload data from excel directly into internal table. Kindly help.
    Here is my code. I had tried using different combination for HAS_FIELD_SEPARATOR but still its not working.
    In my emp1.xls file , the data in each column is present in the same order as in the internal table. Although the first column in my internal table is NUMC. I dont know if that is causing the problem.
    REPORT  ZUPLOAD_1.
    data: itab TYPE TABLE OF zempl_master WITH HEADER LINE.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        FILENAME                      = 'C:\empl1.xls'
        FILETYPE                      = 'ASC'
        HAS_FIELD_SEPARATOR           = 'X'
    *   HEADER_LENGTH                 = 0
    *   READ_BY_LINE                  = 'X'
    *   DAT_MODE                      = ' '
    *   CODEPAGE                      = ' '
    *   IGNORE_CERR                   = ABAP_TRUE
    *   REPLACEMENT                   = '#'
    *   CHECK_BOM                     = ' '
    *   VIRUS_SCAN_PROFILE            =
    *   NO_AUTH_CHECK                 = ' '
    * IMPORTING
    *   FILELENGTH                    =
    *   HEADER                        =
      TABLES
        DATA_TAB                      = itab.
    * EXCEPTIONS
    *   FILE_OPEN_ERROR               = 1
    *   FILE_READ_ERROR               = 2
    *   NO_BATCH                      = 3
    *   GUI_REFUSE_FILETRANSFER       = 4
    *   INVALID_TYPE                  = 5
    *   NO_AUTHORITY                  = 6
    *   UNKNOWN_ERROR                 = 7
    *   BAD_DATA_FORMAT               = 8
    *   HEADER_NOT_ALLOWED            = 9
    *   SEPARATOR_NOT_ALLOWED         = 10
    *   HEADER_TOO_LONG               = 11
    *   UNKNOWN_DP_ERROR              = 12
    *   ACCESS_DENIED                 = 13
    *   DP_OUT_OF_MEMORY              = 14
    *   DISK_FULL                     = 15
    *   DP_TIMEOUT                    = 16
    *   OTHERS                        = 17
    IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    LOOP at itab.
      write:/ itab-emp_no,itab-name.
    endloop.

    hi amber22 you need to use the below fm to upload an xls file
    FORM EXCEL_UPLOAD .
    CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
        EXPORTING
          FILENAME    = FILENAM
          I_BEGIN_COL = 1
          I_BEGIN_ROW = 1
          I_END_COL   = 6
          I_END_ROW   = 100
        TABLES
          INTERN      = xl_itab.
    * EXCEPTIONS
    * INCONSISTENT_PARAMETERS = 1
    * UPLOAD_OLE = 2
    * OTHERS = 3 .
      IF SY-SUBRC = 0.
    MESSAGE 'DATA UPLOADED SUCCESSFULLY' TYPE 'I'.
      ENDIF.
    ENDFORM.                    " EXCEL_UPLOAD

  • GUI_UPLOAD to read data from an Excel File

    Hi Folks,
    I'm using FM GUI_UPLOAD to read data from an Excel File. But all I see in the table returned is 1 row with garbage values (special chacaters). Excel Workbook has proper data in the sheet, but its not getting uploaded properly. Sy-subrc is 0.
    What could be the reason?
    Thanks

    use FM : ALSM_EXCEL_TO_INTERNAL_TABLE
    See the example program to get from XLS file to Internal table
    REPORT ZLWMI151_UPLOAD no standard page heading
                           line-size 100 line-count 60.
    *tables : zbatch_cross_ref.
    data : begin of t_text occurs 0,
           werks(4) type c,
           cmatnr(15) type c,
           srlno(12) type n,
           matnr(7) type n,
           charg(10) type n,
           end of t_text.
    data: begin of t_zbatch occurs 0,
          werks like zbatch_cross_ref-werks,
          cmatnr like zbatch_cross_ref-cmatnr,
          srlno like zbatch_cross_ref-srlno,
          matnr like zbatch_cross_ref-matnr,
          charg like zbatch_cross_ref-charg,
          end of t_zbatch.
    data : g_repid like sy-repid,
           g_line like sy-index,
           g_line1 like sy-index,
           $v_start_col         type i value '1',
           $v_start_row         type i value '2',
           $v_end_col           type i value '256',
           $v_end_row           type i value '65536',
           gd_currentrow type i.
    data: itab like alsmex_tabline occurs 0 with header line.
    data : t_final like zbatch_cross_ref occurs 0 with header line.
    selection-screen : begin of block blk with frame title text.
    parameters : p_file like rlgrap-filename obligatory.
    selection-screen : end of block blk.
    initialization.
      g_repid = sy-repid.
    at selection-screen on value-request for p_file.
      CALL FUNCTION 'F4_FILENAME'
           EXPORTING
                PROGRAM_NAME = g_repid
           IMPORTING
                FILE_NAME    = p_file.
    start-of-selection.
    Uploading the data into Internal Table
      perform upload_data.
      perform modify_table.
    top-of-page.
      CALL FUNCTION 'Z_HEADER'
      EXPORTING
        FLEX_TEXT1       =
        FLEX_TEXT2       =
        FLEX_TEXT3       =
    *&      Form  upload_data
          text
    FORM upload_data.
      CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
           EXPORTING
                FILENAME                = p_file
                I_BEGIN_COL             = $v_start_col
                I_BEGIN_ROW             = $v_start_row
                I_END_COL               = $v_end_col
                I_END_ROW               = $v_end_row
           TABLES
                INTERN                  = itab
           EXCEPTIONS
                INCONSISTENT_PARAMETERS = 1
                UPLOAD_OLE              = 2
                OTHERS                  = 3.
      IF SY-SUBRC <> 0.
        write:/10 'File '.
      ENDIF.
      if sy-subrc eq 0.
        read table itab index 1.
        gd_currentrow = itab-row.
        loop at itab.
          if itab-row ne gd_currentrow.
            append t_text.
            clear t_text.
            gd_currentrow = itab-row.
          endif.
          case itab-col.
            when '0001'.
              t_text-werks = itab-value.
            when '0002'.
              t_text-cmatnr = itab-value.
            when '0003'.
              t_text-srlno = itab-value.
            when '0004'.
              t_text-matnr = itab-value.
            when '0005'.
              t_text-charg = itab-value.
          endcase.
        endloop.
      endif.
      append t_text.
    ENDFORM.                    " upload_data
    *&      Form  modify_table
          Modify the table ZBATCH_CROSS_REF
    FORM modify_table.
      loop at t_text.
        t_final-werks = t_text-werks.
        t_final-cmatnr = t_text-cmatnr.
        t_final-srlno = t_text-srlno.
        t_final-matnr = t_text-matnr.
        t_final-charg = t_text-charg.
        t_final-erdat = sy-datum.
        t_final-erzet = sy-uzeit.
        t_final-ernam = sy-uname.
        t_final-rstat = 'U'.
        append t_final.
        clear t_final.
      endloop.
      delete t_final where werks = ''.
      describe table t_final lines g_line.
      sort t_final by werks cmatnr srlno.
    Deleting the Duplicate Records
      perform select_data.
      describe table t_final lines g_line1.
      modify zbatch_cross_ref from table t_final.
      if sy-subrc ne 0.
        write:/ 'Updation failed'.
      else.
        Skip 1.
        Write:/12 'Updation has been Completed Sucessfully'.
        skip 1.
        Write:/12 'Records in file ',42 g_line .
        write:/12 'Updated records in Table',42 g_line1.
      endif.
      delete from zbatch_cross_ref where werks = ''.
    ENDFORM.                    " modify_table
    *&      Form  select_data
          Deleting the duplicate records
    FORM select_data.
      select werks
             cmatnr
             srlno from zbatch_cross_ref
             into table t_zbatch for all entries in t_final
             where werks = t_final-werks
             and  cmatnr = t_final-cmatnr
             and srlno = t_final-srlno.
      sort t_zbatch by werks cmatnr srlno.
      loop at t_zbatch.
        read table t_final with key werks = t_zbatch-werks
                                    cmatnr = t_zbatch-cmatnr
                                    srlno = t_zbatch-srlno.
        if sy-subrc eq 0.
          delete table t_final .
        endif.
        clear: t_zbatch,
               t_final.
      endloop.
    ENDFORM.                    " select_data

  • Getting error while uploading data  using the EXCEL( GUI_upload)

    Dear Freinds,
    I am uploading data from my excel sheet to my Custom table . I am using the below code
    call function 'GUI_UPLOAD'
    exporting
    filename = l_fn
    filetype = 'BIN' "'ASC'
    has_field_separator = 'X'
    tables
    data_tab = p_i_ins_db
    exceptions
    others = 17.
    i can see in my internal P_i_ins_db ...all the data is coming in encrypted format.
    The flat given to me is the .CSV file .
    Could any one please let me know how i can upload the data which is there in .csv file.
    regards
    syamala

    Hi Syamala,
    Before using the GUI_UPLOAD to upload the data from the excel file to the internal table,you can try usng the Function Module 'SAP_CONVERT_TO_TEX_FORMAT' or 'SAP_CONVERT_TO_CSV_FORMAT' as it helps n formatting the data.
    In case you have any further clarifications,do let me know.
    Regards,
    Puneet Jhari.

  • Error while using the function module GUI_UPLOAD

    Hi,
    My requirement is to upload the data from .txt file into internal table.
    I have given my code like this
    PARAMETERS: p_fname LIKE rlgrap-filename.
    data: begin of gt_string occurs 0,
           record type char255,
          end of gt_string.
    AT SELECTION-SCREEN ON VALUE-REQUEST for p_fname.
      CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
       EXPORTING
        PROGRAM_NAME        = SYST-REPID
        DYNPRO_NUMBER       = SYST-DYNNR
        FIELD_NAME          = ' '
         STATIC              = 'X'
        MASK                = ' '
        CHANGING
          file_name           = p_fname
       EXCEPTIONS
         MASK_TOO_LONG       = 1
         OTHERS              = 2
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      CALL FUNCTION 'GUI_UPLOAD'
        EXPORTING
          filename                      = p_fname
         FILETYPE                      = 'ASC'
         HAS_FIELD_SEPARATOR           = 'X'
         HEADER_LENGTH                 = 0
        READ_BY_LINE                  = 'X'
        DAT_MODE                      = ' '
        CODEPAGE                      = ' '
        IGNORE_CERR                   = ABAP_TRUE
        REPLACEMENT                   = '#'
        CHECK_BOM                     = ' '
        NO_AUTH_CHECK                 = ' '
      IMPORTING
        FILELENGTH                    =
        HEADER                        =
        tables
          data_tab                      = gt_string
       EXCEPTIONS
         FILE_OPEN_ERROR               = 1
         FILE_READ_ERROR               = 2
         NO_BATCH                      = 3
         GUI_REFUSE_FILETRANSFER       = 4
         INVALID_TYPE                  = 5
         NO_AUTHORITY                  = 6
         UNKNOWN_ERROR                 = 7
         BAD_DATA_FORMAT               = 8
         HEADER_NOT_ALLOWED            = 9
         SEPARATOR_NOT_ALLOWED         = 10
         HEADER_TOO_LONG               = 11
         UNKNOWN_DP_ERROR              = 12
         ACCESS_DENIED                 = 13
         DP_OUT_OF_MEMORY              = 14
         DISK_FULL                     = 15
         DP_TIMEOUT                    = 16
         OTHERS                        = 17
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    Here I am getting dump error as 'Type conflict when calling a function module.
    The function module interface allows you to specify only fields
    of a particular type under "FILENAME". The field "P_FNAME" specified here has a different field type'.
    What would be the reason for this error?
    Can anyone help me?
    Regards,
    Hema

    see this sample program for F4 help
    *& Report  ZSD_EXCEL_INT_APP
    REPORT  ZSD_EXCEL_INT_APP.
    parameter: file_nm type localfile.
    types : begin of it_tab1,
            f1(20),
            f2(40),
            f3(20),
           end of it_tab1.
    data : it_tab type table of ALSMEX_TABLINE with header line,
           file type rlgrap-filename.
    data : it_tab2 type it_tab1 occurs 1,
           wa_tab2 type it_tab1,
           w_message(100)  TYPE c.
    at selection-screen on value-request for file_nm.
    CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    EXPORTING
      PROGRAM_NAME        = SYST-REPID
      DYNPRO_NUMBER       = SYST-DYNNR
      FIELD_NAME          = ' '
       STATIC              = 'X'
      MASK                = ' '
      CHANGING
       file_name           = file_nm
    EXCEPTIONS
       MASK_TOO_LONG       = 1
       OTHERS              = 2
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    start-of-selection.
    refresh it_tab2[].clear wa_tab2.
    file = file_nm.
    CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
      EXPORTING
        filename                      = file
        i_begin_col                   = '1'
        i_begin_row                   =  '1'
        i_end_col                     = '10'
        i_end_row                     = '35'
      tables
        intern                        = it_tab
    EXCEPTIONS
       INCONSISTENT_PARAMETERS       = 1
       UPLOAD_OLE                    = 2
       OTHERS                        = 3
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    loop at it_tab.
      case it_tab-col.
       when '002'.
        wa_tab2-f1 = it_tab-value.
       when '004'.
        wa_tab2-f2 = it_tab-value.
      when '008'.
        wa_tab2-f3 = it_tab-value.
    endcase.
    at end of row.
      append wa_tab2 to it_tab2.
    clear wa_tab2.
      endat.
    endloop.
    data : p_file TYPE  rlgrap-filename value 'TEST3.txt'.
    OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    *--- Display error messages if any.
      IF sy-subrc NE 0.
        MESSAGE e001(zsd_mes).
        EXIT.
      ELSE.
    *---Data is downloaded to the application server file path
        LOOP AT it_tab2 INTO wa_tab2.
          TRANSFER wa_tab2 TO p_file.
        ENDLOOP.
      ENDIF.
    *--Close the Application server file (Mandatory).
      CLOSE DATASET p_file.
    loop at it_tab2 into wa_tab2.
      write : / wa_tab2-f1,wa_tab2-f2,wa_tab2-f3.
    endloop.

  • Getting #while using gui_upload

    im using gui_upload to upload data into internal table itab
    this itab has field of type string
    my input text file has values ++;100;0101+;
    but when i m using gui_upload i m getting extra value # in my internal table.
    plz tell me why this # value is coming Extra.
    My internal table is of folllowing type
    begin of itab occurs 0,
    line type string,
    end of itab.
    regards

    hi,
    use this code.
    parameters: p_fname like rlgrap-filename.
    at selection-screen on value-request for p_fname.
    call function 'F4_FILENAME'
    exporting
       program_name        = syst-cprog
       dynpro_number       = syst-dynnr
    importing
       file_name           = p_fname.
    start-of-selection.
    data:v_fname type string.
         move p_fname to v_fname.
    *reading the input file
    call function 'GUI_UPLOAD'
      exporting
       filename                      = v_fname
       filetype                      = 'ASC'
       has_field_separator           = 'X'
      tables
        data_tab                     = itab.

  • Gui_upload for uploading binary file

    Hello All,
    I am trying to upload '.jpg' files using gui_upload function.
    But something goes wrong and it dumps.
    I am new to ABAP.
    following is the code i used.
      DATA: xline TYPE xstring.
      DATA : t_file LIKE TABLE OF xline WITH HEADER LINE.
      CALL FUNCTION 'GUI_UPLOAD'
        EXPORTING
          filetype = 'BIN'
          filename = 'C:\Documents and Settings\I046674\Desktop\RawTest\images\Image_1000.jpg'
        TABLES
          data_tab = t_file.
    It dumps in the 'GUI_UPLOAD' function itself.
    Saying follownig,
    ==========================================
    Error analysis
        The error occurred at a statement in the form
          ASSIGN f TO <fs> TYPE t
        One of these two cases occurred:
        1) Field f is a string, a data reference, an object reference, an
           internal table or a structure that contains such a field. With the
           TYPE addition, this is not possible.
        2) Field f is of type x and field symbol <fs> has a character-type type.
           When executing the statement, the length of f is not a multiple of
           the length (in bytes) of a Unicode character.
    ===============================================
    Can someone help me on this?
    Thanks & Regards,
    Abhijit

    hi,
    Master Data Documents Upload ABAP Program
    Re: Upload Master Data documents
    CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
    filename = 'c:\temp\text.txt'
    filetype = ' '
    IMPORTING
    filelength = fleng
    TABLES
    data_tab = text_tab
    EXCEPTIONS
    file_write_error = 1
    invalid_type = 2
    no_authority = 3
    unknown_error = 4
    OTHERS = 10.
    thanks

  • Problem with GUI_UPLOAD using excel sheet

    Hi,
      I am trying to upload excel sheet thru GUI_UPLOAD ... this excel sheet has a header line and 3 line of data. Even if I remove the header line then also the internal while debugging is showing 28 lines of entries with "#" "squares" in some columns ... while in others where data should be there shows all Zeros....
    The excel sheet has the following info
    Rate Type Valid From Date     From Currency     To Currency      Indirect Quote     Direct Quote
    M       29.09.2006             SGD             USD             1.6932     
    M       29.09.2006             USD             SGD                          1.6932
    M       29.09.2006             SGD             MYR                          2.19653
    KURST GDATU    FCURR TCURR INUKURS     DUKURS
    ###&#2161; |########|#####|### #|   0.00000 |0.00000 |
    ##29 |00000000|     |     |   0.00000 |0.00000 |
    o#d# |00000000|     |     |   0.00000 |0.00000 |
    The code that I am writing is as follows:-
    *& INTERNAL TABLES
    DATA : BEGIN OF T_INPUT occurs 0,
             KURST   LIKE TCURV-KURST,  " Exchange rate type
             GDATU   LIKE SY-DATUM,     " Date from which rate is effective
             FCURR   LIKE TCURC-WAERS,  " From currency
             TCURR   LIKE TCURC-WAERS,  " To currency
             INUKURS LIKE TCURR-UKURS,  " Indirect Quote
             DUKURS  LIKE TCURR-UKURS,  " Direct Quote
           END OF T_INPUT.
                S T A R T - O F - S E L E C T I O N                      *
    START-OF-SELECTION.
    Perform to upload the excel file.
      PERFORM UPLOAD_EXCEL_FILE.
    FORM UPLOAD_EXCEL_FILE .
      DATA: L_FILENM TYPE STRING.
      L_FILENM = P_FILENM.
      CALL FUNCTION 'GUI_UPLOAD'
        EXPORTING
          FILENAME                      = L_FILENM
          FILETYPE                      = 'ASC'
          HAS_FIELD_SEPARATOR           = 'X'
      HEADER_LENGTH                 = 0
      READ_BY_LINE                  = 'X'
      DAT_MODE                      = ' '
      CODEPAGE                      = ' '
      IGNORE_CERR                   = ABAP_TRUE
      REPLACEMENT                   = '#'
      CHECK_BOM                     = ' '
    IMPORTING
      FILELENGTH                    =
      HEADER                        =
        TABLES
          DATA_TAB                      = T_INPUT
       EXCEPTIONS
         FILE_OPEN_ERROR               = 1
         FILE_READ_ERROR               = 2
         NO_BATCH                      = 3
         GUI_REFUSE_FILETRANSFER       = 4
         INVALID_TYPE                  = 5
         NO_AUTHORITY                  = 6
         UNKNOWN_ERROR                 = 7
         BAD_DATA_FORMAT               = 8
         HEADER_NOT_ALLOWED            = 9
         SEPARATOR_NOT_ALLOWED         = 10
         HEADER_TOO_LONG               = 11
         UNKNOWN_DP_ERROR              = 12
         ACCESS_DENIED                 = 13
         DP_OUT_OF_MEMORY              = 14
         DISK_FULL                     = 15
         DP_TIMEOUT                    = 16
         OTHERS                        = 17 .
      IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.

    Hi SB,
    pls change the data type declared for 'valid from date'
    from
    DATA : BEGIN OF T_INPUT occurs 0,
    KURST LIKE TCURV-KURST, " Exchange rate type
    <b>GDATU LIKE SY-DATUM,</b> " Date from which rate is effective
    FCURR LIKE TCURC-WAERS, " From currency
    TCURR LIKE TCURC-WAERS, " To currency
    INUKURS LIKE TCURR-UKURS, " Indirect Quote
    DUKURS LIKE TCURR-UKURS, " Direct Quote
    END OF T_INPUT.
    to
    DATA : BEGIN OF T_INPUT occurs 0,
    KURST LIKE TCURV-KURST, " Exchange rate type
    GDATU(10) type c, " Date from which rate is effective
    FCURR LIKE TCURC-WAERS, " From currency
    TCURR LIKE TCURC-WAERS, " To currency
    INUKURS LIKE TCURR-UKURS, " Indirect Quote
    DUKURS LIKE TCURR-UKURS, " Direct Quote
    END OF T_INPUT.
    Cheers,
    Vikram
    Please reward for helpful replies!!

  • Runtime error while using GUI_UPLOAD

    Hi All,
    I have a text file which contains few records delimited by tab.
    I am trying to upload the contents of the file into an internal table using the FM GUI_UPLOAD
    But, I am getting run time error 'Type conflict when calling a function module'.
    The code that I had written is shown below.
    Please let me know where I went wrong.
    REPORT  Z84364BDC                               .
    TYPES : BEGIN OF ITAB_TP,
            MATNR TYPE MARA-MATNR,
            EAN11 TYPE MARA-EAN11,
            END OF ITAB_TP.
    DATA : FILE_ITAB TYPE STANDARD TABLE OF ITAB_TP.
    DATA : ITAB_WA TYPE ITAB_TP.
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-T01.
    PARAMETERS : P_FILE TYPE RLGRAP-FILENAME DEFAULT 'D:\Example.txt'.
    SELECTION-SCREEN END OF BLOCK B1.
    ***FILLING THE INTERNAL TABLE****
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        filename                      = P_FILE
        FILETYPE                      = 'ASC'
        has_field_separator           = ','
        tables
        data_tab                      = FILE_ITAB
    EXCEPTIONS
       FILE_OPEN_ERROR               = 1
       FILE_READ_ERROR               = 2
       NO_BATCH                      = 3
       GUI_REFUSE_FILETRANSFER       = 4
       INVALID_TYPE                  = 5
       NO_AUTHORITY                  = 6
       UNKNOWN_ERROR                 = 7
       BAD_DATA_FORMAT               = 8
       HEADER_NOT_ALLOWED            = 9
       SEPARATOR_NOT_ALLOWED         = 10
       HEADER_TOO_LONG               = 11
       UNKNOWN_DP_ERROR              = 12
       ACCESS_DENIED                 = 13
       DP_OUT_OF_MEMORY              = 14
       DISK_FULL                     = 15
       DP_TIMEOUT                    = 16
       OTHERS                        = 17
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

    The file is delimited by Comma field as mentioned above.
    Below is the code that I had written. But, I face the same problem
    REPORT  Z84364BDC                               .
    TYPES : BEGIN OF ITAB_TP,
            MATNR TYPE MARA-MATNR,
            EAN11 TYPE MARA-EAN11,
            END OF ITAB_TP.
    DATA : FILE_ITAB TYPE STANDARD TABLE OF ITAB_TP.
    DATA : ITAB_WA TYPE ITAB_TP.
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-T01.
    PARAMETERS : P_PATH TYPE RLGRAP-FILENAME DEFAULT 'D:\Example.txt'.
    SELECTION-SCREEN END OF BLOCK B1.
    DATA : P_FILE TYPE STRING.
    P_FILE = P_PATH.
    ****FILLING THE INTERNAL TABLE*****
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        filename                      = P_FILE
        FILETYPE                      = 'ASC'
        has_field_separator           = 'X'
        tables
        data_tab                      = FILE_ITAB
    EXCEPTIONS
       FILE_OPEN_ERROR               = 1
       FILE_READ_ERROR               = 2
       NO_BATCH                      = 3
       GUI_REFUSE_FILETRANSFER       = 4
       INVALID_TYPE                  = 5
       NO_AUTHORITY                  = 6
       UNKNOWN_ERROR                 = 7
       BAD_DATA_FORMAT               = 8
       HEADER_NOT_ALLOWED            = 9
       SEPARATOR_NOT_ALLOWED         = 10
       HEADER_TOO_LONG               = 11
       UNKNOWN_DP_ERROR              = 12
       ACCESS_DENIED                 = 13
       DP_OUT_OF_MEMORY              = 14
       DISK_FULL                     = 15
       DP_TIMEOUT                    = 16
       OTHERS                        = 17
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ***Displaying the Material*****
    LOOP AT FILE_ITAB INTO ITAB_WA.
    WRITE:/ ITAB_WA-MATNR.
    ENDLOOP.

  • Error in gui_upload

    hi guru,
    iam doing some bdc program.. but ity will going to dump on gui_upload.. so plz help me.
    An exception occurred that is explained in detail
    The exception, which is assigned to class 'CX_SY_DYN_CALL_ILLEGAL_TYPE', was
    not caught in.
    procedure "F_UPLOAD_FILE" "(FORM)", nor was it propagated by a RAISING clause.
    Since the caller of the procedure could not have anticipated that the
    exception would occur, the current program is terminated.
    The reason for the exception is:
    The call to the function module "GUI_UPLOAD" is incorrect:
    The function module interface allows you to specify only
    fields of a particular type under "FILENAME".
    The field "P_P_FILE" specified here is a different
    field type
    SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-h01.                         
    PARAMETERS: p_file LIKE rlgra-filename                                                                               
    SELECTION-SCREEN : END OF BLOCK b1.                                                                                .----
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.                                                                               
    PERFORM f_get_file USING p_file.                                                                               
    CALL FUNCTION 'KD_GET_FILENAME_ON_F4'       
    *EXPORTING-                                                                               
    CHANGING                                                                               
    FILE_NAME           = p_p_file                                                                               
    endform.               
    form f_upload_file  using    p_p_file.                                                                               
    CALL FUNCTION 'GUI_UPLOAD'                                                                               
    EXPORTING                                                                               
    FILENAME                      = p_p_file                                                                               
    FILETYPE                      = 'DAT'                                                                               
    endform.

    Hi,
    Refer the program given below. it is working fine for me.
    make the paramerter as:
    pa_dfile TYPE rcgfiletr-ftfront.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR pa_dfile.
      CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
        EXPORTING
          static        = 'X'
          mask          = '(Text file|*.TXT'
        CHANGING
          file_name     = pa_dfile
        EXCEPTIONS
          mask_too_long = 1
          OTHERS        = 2.
      IF sy-subrc <> 0.
        MESSAGE ID 'PG' TYPE 'E' NUMBER '016'
              WITH 'Error in F4 help'(005).
        "The provided file is not an excel sheet.
        RETURN.
      ENDIF.
    DATA: lv_filetype(10) TYPE c,
            lv_gui_sep TYPE c,
            lv_file_name TYPE string.
      lv_filetype = 'ASC'.
      lv_gui_sep = 'X'.
      lv_file_name = pa_dfile.
    FM call to upload file
      CALL FUNCTION 'GUI_UPLOAD'
        EXPORTING
          filename                = lv_file_name
          filetype                = lv_filetype
          has_field_separator     = lv_gui_sep 
        TABLES
          data_tab                = gi_table
        EXCEPTIONS
          file_open_error         = 1
          file_read_error         = 2
          no_batch                = 3
          gui_refuse_filetransfer = 4
          invalid_type            = 5
          no_authority            = 6
          unknown_error           = 7
          bad_data_format         = 8
          header_not_allowed      = 9
          separator_not_allowed   = 10
          header_too_long         = 11
          unknown_dp_error        = 12
          access_denied           = 13
          dp_out_of_memory        = 14
          disk_full               = 15
          dp_timeout              = 16
          OTHERS                  = 17.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    Hope it helps.
    Regards
    Rajesh Kumar
    Edited by: Rajesh Kumar on Jul 24, 2009 7:11 AM

  • Issue with use of Function Module GUI_UPLOAD

    Hi Experts,
    I have an issue in using the Function Module GUI_UPLOAD for uploading the contents of an Excel file on the Presentation Server to an internal table in an ABAP Program.
    My file consists of around 300 records but the FM succeeds in uploading only the first 6 lines to the Internal Table specified while calling the FM.
    I dont have any idea why this happens. Any pointers in this direction will be helpful.
    Thanks in advance.
    Regards,
    Keerthi

    Hi,
    Kindly go through this link below:
    https://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=60655105
    Hope it helps you
    Regards
    Mansi

  • Issue with field separator in GUI_UPLOAD

    Hello Gurus
    I am facing issue with gui_upload. I have a text file in which the fields are eparated by single Pipe  i.e |. Now when I try to read the data from file in internal table even with using field separator it does not insert data in proper fields.
    DATA: BEGIN OF IT_TAB OCCURS 0,
          OBJECT_ID type string,
          VERSION_SERIES_ID TYPE string,
          VERSION_NUMBER TYPE string,
          REVISION TYPE string,
          DOC_NUMBER TYPE string,
          DOCTITLE TYPE string,
          FILESIZE TYPE string,
          MIME_TYPE TYPE string,
          PLANTUNIT TYPE string,
          END OF IT_TAB.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        FILENAME                      = w_mpath
        FILETYPE                      = 'ASC'
        HAS_FIELD_SEPARATOR           = '|'
      HEADER_LENGTH                 = 0
       READ_BY_LINE                  = 'X'
      DAT_MODE                      = ' '
      CODEPAGE                      = ' '
      IGNORE_CERR                   = ABAP_TRUE
      REPLACEMENT                   = '#'
      CHECK_BOM                     = ' '
      VIRUS_SCAN_PROFILE            =
      NO_AUTH_CHECK                 = ' '
    IMPORTING
      FILELENGTH                    =
      HEADER                        =
      TABLES
        DATA_TAB                      = it_tab[]
    EXCEPTIONS
       FILE_OPEN_ERROR               = 1
       FILE_READ_ERROR               = 2
       NO_BATCH                      = 3
       GUI_REFUSE_FILETRANSFER       = 4
       INVALID_TYPE                  = 5
       NO_AUTHORITY                  = 6
       UNKNOWN_ERROR                 = 7
       BAD_DATA_FORMAT               = 8
       HEADER_NOT_ALLOWED            = 9
       SEPARATOR_NOT_ALLOWED         = 10
       HEADER_TOO_LONG               = 11
       UNKNOWN_DP_ERROR              = 12
       ACCESS_DENIED                 = 13
       DP_OUT_OF_MEMORY              = 14
       DISK_FULL                     = 15
       DP_TIMEOUT                    = 16
       OTHERS                        = 17
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    I want the data to get appended in internal table based on | separator.
    Please help.
    Regards,
    Rajesh.

    Hi,
    I believe the field separator parameter will work for Excel files..You have to get the internal table in a string format..and then use split statement..
    check this example..
    DATA: BEGIN OF it_tab OCCURS 0,
           object_id TYPE string,
           version_series_id TYPE string,
           version_number TYPE string,
           revision TYPE string,
           doc_number TYPE string,
           doctitle TYPE string,
           filesize TYPE string,
           mime_type TYPE string,
           plantunit TYPE string,
         END OF it_tab.
    DATA: t_tab   TYPE TABLE OF string,
          v_string TYPE string.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        filename                = 'C:\TEST.TXT'
    *    has_field_separator     = '|'          "Actually not required.
      TABLES
        data_tab                = t_tab
      EXCEPTIONS
        file_open_error         = 1
        file_read_error         = 2
        no_batch                = 3
        gui_refuse_filetransfer = 4
        invalid_type            = 5
        no_authority            = 6
        unknown_error           = 7
        bad_data_format         = 8
        header_not_allowed      = 9
        separator_not_allowed   = 10
        header_too_long         = 11
        unknown_dp_error        = 12
        access_denied           = 13
        dp_out_of_memory        = 14
        disk_full               = 15
        dp_timeout              = 16
        OTHERS                  = 17.
    IF sy-subrc <> 0.
    ENDIF.
    LOOP AT t_tab INTO v_string.
      SPLIT v_string AT ','
            INTO
            it_tab-object_id
            it_tab-version_series_id
            it_tab-version_number
            it_tab-revision
            it_tab-doc_number
            it_tab-doctitle
            it_tab-filesize
            it_tab-mime_type
            it_tab-plantunit.
      APPEND it_tab.
      CLEAR: it_tab.
    ENDLOOP.
    Thanks
    Naren
    Edited by: Narendran Muthukumaran on Oct 15, 2008 4:58 PM

  • Excel data transfer into SAP internal table with GUI_UPLOAD

    hi all,
      i m using SRM4 system and i wanted to develop one report which will upload data from excel and convert it into IT.
    i know that many threads are posted on this topic.
    but my requirement is slight different. in the system only one function module is available that is "GUI_UPLOAD" and we want that user shd not save file as tab delimited before calling this fm. instead, program shd take care of all these things...
    please suggest something asap..
    helpful ans will be rewarded..
    thanks,
    jigs.

    Dear Jigs,
    Please go though the following lines of code:
    D A T A D E C L A R A T I O N *
    TABLES: ANEP,
    BKPF.
    TYPES: BEGIN OF TY_TABDATA,
    MANDT LIKE SY-MANDT, " Client
    ZSLNUM LIKE ZSHIFTDEPN-ZSLNUM, " Serial Number
    ZASSET LIKE ZSHIFTDEPN-ZASSET, " Original asset that was transferred
    ZYEAR LIKE ZSHIFTDEPN-ZYEAR, " Fiscal Year
    ZPERIOD LIKE ZSHIFTDEPN-ZPERIOD, " Fiscal Period
    ZSHIFT1 LIKE ZSHIFTDEPN-ZSHIFT1, " Shift No. 1
    ZSHIFT2 LIKE ZSHIFTDEPN-ZSHIFT1, " Shift No. 2
    ZSHIFT3 LIKE ZSHIFTDEPN-ZSHIFT1, " Shift No. 3
    END OF TY_TABDATA.
    Declaration of the Internal Table with Header Line comprising of the uploaded data.
    DATA: BEGIN OF IT_FILE_UPLOAD OCCURS 0.
    INCLUDE STRUCTURE ALSMEX_TABLINE. " Rows for Table with Excel Data
    DATA: END OF IT_FILE_UPLOAD.
    S E L E C T I O N - S C R E E N *
    SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME,
    BEGIN OF BLOCK B2 WITH FRAME.
    PARAMETERS: P_FNAME LIKE RLGRAP-FILENAME OBLIGATORY.
    SELECTION-SCREEN: END OF BLOCK B2,
    END OF BLOCK B1.
    E V E N T : AT S E L E C T I O N - S C R E E N *
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FNAME.
    CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    EXPORTING
    PROGRAM_NAME = SYST-REPID
    DYNPRO_NUMBER = SYST-DYNNR
    FIELD_NAME = ' '
    STATIC = 'X'
    MASK = '.'
    CHANGING
    FILE_NAME = P_FNAME
    EXCEPTIONS
    MASK_TOO_LONG = 1
    OTHERS = 2
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    E V E N T : S T A R T - O F - S E L E C T I O N *
    START-OF-SELECTION.
    Upload Excel file into Internal Table.
    PERFORM UPLOAD_EXCEL_FILE.
    Organize the uploaded data into another Internal Table.
    PERFORM ORGANIZE_UPLOADED_DATA.
    E V E N T : E N D - O F - S E L E C T I O N *
    END-OF-SELECTION.
    *& Form UPLOAD_EXCEL_FILE
    text
    --> p1 text
    <-- p2 text
    FORM UPLOAD_EXCEL_FILE .
    CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
    FILENAME = P_FNAME
    I_BEGIN_COL = 1
    I_BEGIN_ROW = 3
    I_END_COL = 7
    I_END_ROW = 32000
    TABLES
    INTERN = IT_FILE_UPLOAD
    EXCEPTIONS
    INCONSISTENT_PARAMETERS = 1
    UPLOAD_OLE = 2
    OTHERS = 3
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDFORM. " UPLOAD_EXCEL_FILE
    *& Form ORGANIZE_UPLOADED_DATA
    text
    --> p1 text
    <-- p2 text
    FORM ORGANIZE_UPLOADED_DATA .
    SORT IT_FILE_UPLOAD BY ROW
    COL.
    LOOP AT IT_FILE_UPLOAD.
    CASE IT_FILE_UPLOAD-COL.
    WHEN 1.
    WA_TABDATA-ZSLNUM = IT_FILE_UPLOAD-VALUE.
    WHEN 2.
    WA_TABDATA-ZASSET = IT_FILE_UPLOAD-VALUE.
    WHEN 3.
    WA_TABDATA-ZYEAR = IT_FILE_UPLOAD-VALUE.
    WHEN 4.
    WA_TABDATA-ZPERIOD = IT_FILE_UPLOAD-VALUE.
    WHEN 5.
    WA_TABDATA-ZSHIFT1 = IT_FILE_UPLOAD-VALUE.
    WHEN 6.
    WA_TABDATA-ZSHIFT2 = IT_FILE_UPLOAD-VALUE.
    WHEN 7.
    WA_TABDATA-ZSHIFT3 = IT_FILE_UPLOAD-VALUE.
    ENDCASE.
    AT END OF ROW.
    WA_TABDATA-MANDT = SY-MANDT.
    APPEND WA_TABDATA TO IT_TABDATA.
    CLEAR: WA_TABDATA.
    ENDAT.
    ENDLOOP.
    ENDFORM. " ORGANIZE_UPLOADED_DATA
    In the subroutine --> ORGANIZE_UPLOADED_DATA, data are organized as per the structure declared above.
    Regards,
    Abir
    Don't forget to award points *

  • GUI_Upload & GUI_Download for excel files

    Hi experts,
    I want to upload excel file into sap. i am trying with GUI_Upload function module. when i see the data it is filled with # and other special char. When i save the excel file as .txt file and then read the txt file. Now i am getting correct data. Is it possible to read Excel data using GUI_UPLOAD directly without changing .xls to .txt.
    Also, how to change data in  second or  third tab of excel file using GUI_Download.
    -RK

    Hi
    Actually ur file selection s wrong.
    CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
        EXPORTING
          PROGRAM_NAME  = SYST-REPID
          DYNPRO_NUMBER = SYST-DYNNR
          FIELD_NAME    = 'P_FNAME'
          STATIC        = 'X'
         MASK          = '*.txt'
        CHANGING
          FILE_NAME     = P_FNAME
        EXCEPTIONS
          MASK_TOO_LONG = 1
          OTHERS        = 2.
    Upload:
    CALL FUNCTION 'GUI_UPLOAD'
        EXPORTING
          FILENAME                = LV_FNAME
          FILETYPE                = 'ASC'
          HAS_FIELD_SEPARATOR     = 'X'
        TABLES
          DATA_TAB                = IT_UEXBANK01
        EXCEPTIONS
          FILE_OPEN_ERROR         = 1
          FILE_READ_ERROR         = 2
          NO_BATCH                = 3
          GUI_REFUSE_FILETRANSFER = 4
          INVALID_TYPE            = 5
          NO_AUTHORITY            = 6
          UNKNOWN_ERROR           = 7
          BAD_DATA_FORMAT         = 8
          HEADER_NOT_ALLOWED      = 9
          SEPARATOR_NOT_ALLOWED   = 10
          HEADER_TOO_LONG         = 11
          UNKNOWN_DP_ERROR        = 12
          ACCESS_DENIED           = 13
          DP_OUT_OF_MEMORY        = 14
          DISK_FULL               = 15
          DP_TIMEOUT              = 16
          OTHERS                  = 17.
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.

Maybe you are looking for

  • QM Notification Through Email

    Hi SAP Team, I have a requirement, where I want that whenever a QM Notification is created, an email with Subject line of Notification, Purchase Order  sgould go to the User. Is there some std. way of doing it i.e. without activating Workflow etc, as

  • Faulty ObjectMessage Payload in Message Driven Bean

    To all, I have a frustrating problem. I am using iPlanet application server 6.5 and Java Message Queue 2.0 beta. I have deployed a message driven bean into the application server. This bean expects ObjectMessage's. The bean successfully receives mess

  • Is it "OK" to have a single .xml file that's identified by a specific app (Sound Studio)?

    Since I'm have trouble in getting "Amazon's Cloud" to see my music files in iTunes, I'm wondering if the peculiarity I'm noticing with the .xml file in my iTunes folder is causing a problem.  I have only one such file and alongside it is the green ic

  • Adpreclone.pl query

    Hi. I understand what this script does (creates directories in ORACLE_HOME/appsutil/clone, converts inventory from binary to xml, generates a db creation driver and copies some JDBC libraries, and creates template files ... I am thinking of the db st

  • Sync with outlook 2007

    I have problem to sync my MS outlook 2007 with iphone 4 even I follow the intruction on this link www.sync-iphone.com. nothing appear on my iphone.