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

gui_upload

Former Member
0 Likes
623

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.

if t_exception[] is initial.

message s005(z1) with text-s01.

else.

message s005(z1) with text-s02.

endif.

skip.

format reset.

write : /40 text-eor.

endform. " error_report

&----


*& Form check_file

&----


form check_file.

*The source format in the report selection should match the upload file

*naming conventions

*start of insert - mpc01

if not t_filelist is initial.

refresh: t_filelist.

clear: t_filelist.

endif.

split p_file at '/' into table t_filelist.

describe table t_filelist lines sy-tabix.

sy-tabix = sy-tabix - 1.

delete t_filelist from 1 to sy-tabix.

read table t_filelist index 1.

*end of insert - mpc01

case t_filelist-name(1).

when 'M'.

if rb_month <> 'X'.

message e005(z1) with text-t15.

endif.

when 'W'.

if rb_week <> 'X'.

message e005(z1) with text-t16.

endif.

when 'D'.

if rb_daily <> 'X'.

message e005(z1) with text-t17.

endif.

endcase.

endform. " check_file

&----


*& Form top_of_page

&----


form top_of_page.

  • FORMAT COLOR COL_HEADING INTENSIFIED OFF.

format reset.

  • START PKA01

if rb_1000 = 'X'.

write: / 'Plant: ', 25 c_werks_1000.

else.

write: / 'Plant: ', 25 c_werks_1005.

endif.

if rb_mgx = 'X'.

write: / text-t02, 25 'MGX'.

else.

write: / text-t02, 25 'Other'.

endif.

if rb_month = 'X'.

write: / text-t03, 25 'Monthly'.

elseif rb_week = 'X'.

write: / text-t03, 25 'Weekly'.

else.

write: / text-t03, 25 'Daily'.

endif.

if rb_spmon = 'X'.

write: / text-t04, 25 'Month'.

elseif rb_spwk = 'X'.

write: / text-t04, 25 'Weekly'.

else.

write: / text-t04, 25 'Daily'.

endif.

skip.

write: / 'Number of records uploaded: ', w_count_recs_uploaded.

write: / 'Number of IDOCs posted : ', w_count_idoc_posted.

write: / 'Number of IDOC errors : ', w_count_idoc_errors.

skip.

write: / 'File: ', p_file.

skip.

format color col_heading intensified on.

uline.

write: /6 'File',

13 'Material',

24 'Forecast',

40 'Value',

46 'IDOC',

67(70) 'Error '.

write: /6 'Index',

13 'Number',

24 'Date',

67(70) 'Message'.

uline.

format color col_heading intensified off.

endform. " top_of_page

3 REPLIES 3
Read only

Former Member
0 Likes
532

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

Read only

0 Likes
532

could u observe my code and pls build the code accordingly at proper place and send me.

Read only

former_member404244
Active Contributor
0 Likes
532

Hi,

first get the local file by using f4 help..Remove the FM'S FILE_GET_NAME.and also code related to appication server..rest evrything remains same

PARAMETERS : p_file TYPE rlgrap-filename .

CALL FUNCTION 'F4_FILENAME'"#EC *

EXPORTING

PROGRAMNAME = SY-REPID

DYNPRO_NUMBER = SY-DYNNR

FIELD_NAME = P_FILE.

IMPORTING

filename = pv_file

EXCEPTIONS

inv_winsys = 1

no_batch = 2

selection_cancel = 3

selection_error = 4

OTHERS = 5.

IF sy-subrc <> 0 AND sy-subrc <> 3.

MESSAGE i134.

LEAVE LIST-PROCESSING.

ENDIF.

PV_FILE will be the file selected from presentation server.

Now call the FM

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = PV_FILE

filetype = c_asc

has_field_separator = c_x

TABLES

data_tab = i_temp

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.

  • File not found.

MESSAGE e138.

ENDIF.

Now data will be uploaded to the internal table i_temp.

Regards,

Nagaraj