Skip to Content
0
Jan 10, 2023 at 06:31 PM

Vendor attachment

46 Views

*&---------------------------------------------------------------------*

*& Report ZSD_Vendor_MASS_UPLD

FORM get_files .

CALL FUNCTION 'FILE_GET_NAME'

EXPORTING

logical_filename = c_log_fname

IMPORTING

file_name = v_path_name

EXCEPTIONS

file_not_found = 1

OTHERS = 2.

IF sy-subrc <> 0.

ENDIF.

v_dir = v_path_name.

CALL FUNCTION 'EPS2_GET_DIRECTORY_LISTING'

EXPORTING

iv_dir_name = v_dir

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 sy-subrc <> 0.

"exit from program if error occured during Directory read

IF sy-subrc = 7.

MESSAGE text-020 TYPE c_s DISPLAY LIKE c_e. "'Directory is Empty'.

LEAVE LIST-PROCESSING.

ELSE.

MESSAGE text-021 TYPE c_s DISPLAY LIKE c_e.

LEAVE LIST-PROCESSING.

ENDIF.

"LEAVE PROGRAM.

ENDIF.

ENDFORM.

FORM process_files .

TYPES: BEGIN OF ty_lfa1,

lifnr TYPE lifnr,

END OF ty_lfa1.

TYPES : BEGIN OF ty_vend,

lifnr TYPE lfa1-lifnr,

END OF ty_vend.

TYPES : BEGIN OF ty_string,

name TYPE char200,

END OF ty_string.

DATA: t_vend TYPE TABLE OF ty_vend,

wa_vend TYPE ty_vend.

DATA: t_lfa1 TYPE TABLE OF ty_lfa1,

wa_lfa1 TYPE ty_lfa1.

DATA: v_lifnr TYPE lifnr,

v_vend1 TYPE lfa1-lifnr,

v_file TYPE string. "char5

* DATA: v_htype LIKE dd01v-datatype.

DATA: t_filename TYPE STANDARD TABLE OF ty_string.

t_files_temp[] = t_files[].

IF t_files_temp IS NOT INITIAL.

LOOP AT t_files_temp INTO DATA(wa_files1).

SPLIT wa_files1-name AT c_dash INTO v_vend v_venddesc v_fileno . " v_date v_fileno.

SPLIT wa_files1-name AT c_dot INTO v_file v_ext.

DATA(v_vend_len) = strlen( v_vend ).

IF v_vend_len LE 10.

wa_vend-lifnr = v_vend.

*

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = wa_vend-lifnr

IMPORTING

output = wa_vend-lifnr.

APPEND wa_vend TO t_vend.

ELSE.

PERFORM err_vend USING v_file

v_ext.

DELETE t_files_temp WHERE name = wa_files1-name.

wa_result-vend = v_vend.

wa_result-file = wa_files1-name.

wa_result-status = c_f.

wa_result-message = text-025."c_novend. "'F'.

APPEND wa_result TO t_result.

CLEAR : wa_result.

ENDIF.

CLEAR : wa_vend, wa_files1, v_vend, v_venddesc, v_fileno, v_vend_len, v_file, v_ext, v_vend_len.

ENDLOOP.

ENDIF.

IF t_vend IS NOT INITIAL.

SELECT lifnr FROM lfa1 INTO TABLE t_lfa1

FOR ALL ENTRIES IN t_vend

WHERE lifnr = t_vend-lifnr.

IF sy-subrc EQ 0.

SORT t_lfa1 BY lifnr.

ENDIF.

ENDIF.

SORT t_files_temp BY name.

IF t_files_temp IS NOT INITIAL.

LOOP AT t_files_temp INTO DATA(wa_files).

SPLIT wa_files-name AT c_dash INTO v_vend v_venddesc.

v_vend1 = v_vend.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = v_vend1

IMPORTING

output = v_vend1.

SPLIT wa_files-name AT c_dot INTO TABLE t_filename.

IF lines( t_filename[] ) > 1.

v_ext = t_filename[ lines( t_filename[] ) ].

ENDIF.

DATA(v_length_file) = strlen( wa_files-name ).

DATA(v_file_len) = v_length_file - ( 1 + strlen( v_ext ) ).

v_file = wa_files+0(v_file_len).

IF v_ext IS INITIAL.

IF v_length_file EQ 200.

wa_result-vend = v_vend.

wa_result-file = wa_files-name.

wa_result-status = c_f.

wa_result-message = text-027."c_msg1. "'F'.

APPEND wa_result TO t_result.

CLEAR : wa_result.

PERFORM err_vend USING v_file

v_ext.

ELSE.

wa_result-vend = v_vend.

wa_result-file = wa_files-name.

wa_result-status = c_f.

wa_result-message = text-026."c_ext_msg. "'F'.

APPEND wa_result TO t_result.

CLEAR : wa_result.

PERFORM err_vend USING v_file

v_ext.

ENDIF.

ELSE.

READ TABLE t_lfa1 INTO wa_lfa1 WITH KEY lifnr = v_vend1. " v_cust.

IF sy-subrc = 0.

PERFORM add_attchment USING v_vend1

v_file

v_ext.

ELSE.

PERFORM err_vend USING v_file

v_ext.

wa_result-vend = v_vend.

wa_result-file = wa_files-name.

wa_result-status = c_f.

wa_result-message = text-025."c_novend. "'F'.

APPEND wa_result TO t_result.

CLEAR : wa_result.

ENDIF.

ENDIF.

CLEAR: wa_files, v_file,v_vend,v_ext, v_length_file , v_file_len , t_filename[].

ENDLOOP.

ENDIF.

ENDFORM.

FORM add_attchment USING u_vend TYPE lifnr

u_fname TYPE string

u_ext TYPE string.

DATA:

t_content TYPE STANDARD TABLE OF soli,

t_content1 TYPE STANDARD TABLE OF soli,

t_objhead TYPE STANDARD TABLE OF soli,

wa_folmem_k TYPE sofmk,

wa_note TYPE borident,

wa_object TYPE borident,

wa_obj_id TYPE soodk,

wa_content TYPE soli,

wa_content1 TYPE xstring,

v_xstring TYPE xstring,

wa_fol_id TYPE soodk,

wa_obj_data TYPE sood1,

v_ep_note TYPE borident-objkey,

v_lifnr TYPE lifnr,

v_fullpath TYPE string,

v_filename TYPE string,

v_fname TYPE string.

* v_kunnr TYPE kunnr.

DATA : v_file_len TYPE i,

t_soli TYPE STANDARD TABLE OF soli,

t_string TYPE STANDARD TABLE OF string.

CONSTANTS:

c_vmd1 TYPE symsgid VALUE 'VMD',

c_obj TYPE so_obj_sns VALUE 'O',

c_message TYPE c VALUE 'MESSAGE' LENGTH 10.

PERFORM create_log_handle USING u_vend.

v_lifnr = u_vend.

* convert vendor number

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = v_lifnr

IMPORTING

output = v_lifnr.

* Refresh data

REFRESH: t_content[], t_objhead[] , t_soli[] .

CLEAR : v_xstring ,v_file_len.

CONCATENATE u_fname c_dot u_ext INTO v_fname.

CONCATENATE v_dir u_fname c_dot u_ext INTO v_fullpath.

TRANSLATE u_ext TO LOWER CASE.

IF u_ext = c_txt. "'txt'.

TRY.

OPEN DATASET v_fullpath FOR INPUT IN BINARY MODE ."TEXT MODE ENCODING NON-UNICODE.

IF sy-subrc EQ 0.

DO.

READ DATASET v_fullpath INTO wa_content1.

* Do not put Sy-subrc eq 0 here. Please add the last line of the file,

* though sy-subrc may fail

IF sy-subrc = 0.

CONCATENATE v_xstring wa_content1 INTO v_xstring IN BYTE MODE.

CLEAR:wa_content1.

ELSE.

CONCATENATE v_xstring wa_content1 INTO v_xstring IN BYTE MODE.

CLEAR:wa_content1.

EXIT.

ENDIF.

ENDDO.

* Close file

CLOSE DATASET v_fullpath.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

EXPORTING

buffer = v_xstring

IMPORTING

output_length = v_file_len

TABLES

binary_tab = t_content.

CALL FUNCTION 'SCMS_BINARY_TO_TEXT'

EXPORTING

input_length = v_file_len

TABLES

binary_tab = t_content

text_tab = t_soli

EXCEPTIONS

failed = 1

OTHERS = 2.

IF sy-subrc <> 0.

* Implement suitable error handling here

ENDIF.

REFRESH t_content[].

t_content = t_soli.

MOVE v_file_len TO wa_obj_data-objlen.

ELSE.

wa_msg-msgty = c_e.

wa_msg-msgid = c_vmd1. "'VMD'.

wa_msg-msgno = sy-subrc.

wa_msg-msgv1 = text-028."c_msg. " 'Error Occured while opening File'.

wa_msg-msgv2 = u_vend. "sy-msgv2.

wa_msg-msgv3 = v_dir. "sy-msgv3.

wa_msg-msgv4 = v_fname.

v_message = wa_msg-msgv1 && wa_msg-msgv2 && wa_msg-msgv3 && wa_msg-msgv4.

wa_result-vend = v_lifnr.

wa_result-file = v_fname.

wa_result-status = c_f.

wa_result-message = v_message. "'F'.

APPEND wa_result TO t_result.

CLEAR : wa_result.

PERFORM err_vend USING u_fname

u_ext.

PERFORM add_msg_inlog USING wa_msg.

CLEAR : wa_msg.

ENDIF.

CATCH cx_root INTO DATA(o_exception).

wa_msg-msgty = c_e.

wa_msg-msgid = sy-msgid.

wa_msg-msgno = sy-msgno.

wa_msg-msgv1 = sy-msgv1.

wa_msg-msgv2 = sy-msgv2.

wa_msg-msgv3 = u_vend. "sy-msgv3.

wa_msg-msgv4 = v_fullpath. "sy-msgv4.

v_message = wa_msg-msgv1 && wa_msg-msgv2 && wa_msg-msgv3 && wa_msg-msgv4.

wa_result-vend = v_lifnr.

wa_result-file = v_fname.

wa_result-status = c_f.

wa_result-message = v_message. "'F'.

APPEND wa_result TO t_result.

CLEAR : wa_result.

PERFORM err_vend USING " u_vend

u_fname

u_ext.

PERFORM add_msg_inlog USING wa_msg.

CLEAR : wa_msg.

ENDTRY.

ELSE.

TRY.

OPEN DATASET v_fullpath FOR INPUT IN BINARY MODE .

IF sy-subrc EQ 0.

DO.

READ DATASET v_fullpath INTO wa_content1.

* Do not put Sy-subrc eq 0 here. Please add the last line of the file,

* though sy-subrc may fail

IF sy-subrc = 0.

CONCATENATE v_xstring wa_content1 INTO v_xstring IN BYTE MODE.

CLEAR:wa_content1.

ELSE.

CONCATENATE v_xstring wa_content1 INTO v_xstring IN BYTE MODE.

CLEAR:wa_content1.

EXIT.

ENDIF.

ENDDO.

* Close file

CLOSE DATASET v_fullpath.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

EXPORTING

buffer = v_xstring

IMPORTING

output_length = v_file_len

TABLES

binary_tab = t_content.

*** Convert to BIN

CALL FUNCTION 'SO_CONVERT_CONTENTS_BIN'

EXPORTING

it_contents_bin = t_content

IMPORTING

et_contents_bin = t_content.

MOVE v_file_len TO wa_obj_data-objlen.

ELSE.

wa_msg-msgty = c_e.

wa_msg-msgid = c_vmd1. "'VMD'.

wa_msg-msgno = sy-subrc.

wa_msg-msgv1 = text-028."c_msg. "'Error Occured while opening File'.

wa_msg-msgv2 = u_vend."sy-msgv2.

wa_msg-msgv3 = v_dir. "sy-msgv3.

wa_msg-msgv4 = v_fname.

v_message = wa_msg-msgv1 && wa_msg-msgv2 && wa_msg-msgv3 && wa_msg-msgv4.

wa_result-vend = v_lifnr.

wa_result-file = v_fname.

wa_result-status = c_f.

wa_result-message = v_message. " 'F'.

APPEND wa_result TO t_result.

CLEAR : wa_result.

PERFORM err_vend USING u_fname

u_ext.

PERFORM add_msg_inlog USING wa_msg.

CLEAR : wa_msg.

ENDIF.

CATCH cx_root INTO o_exception.

wa_msg-msgty = c_e.

wa_msg-msgid = sy-msgid.

wa_msg-msgno = sy-msgno.

wa_msg-msgv1 = sy-msgv1.

wa_msg-msgv2 = sy-msgv2.

wa_msg-msgv3 = u_vend. "sy-msgv3.

wa_msg-msgv4 = v_fname. "sy-msgv4.

v_message = wa_msg-msgv1 && wa_msg-msgv2 && wa_msg-msgv3 && wa_msg-msgv4.

wa_result-vend = v_lifnr.

wa_result-file = v_fname.

wa_result-status = c_f.

wa_result-message = v_message. " 'F'.

APPEND wa_result TO t_result.

CLEAR : wa_result.

PERFORM err_vend USING u_fname

u_ext.

PERFORM add_msg_inlog USING wa_msg.

CLEAR : wa_msg.

ENDTRY.

ENDIF.

* Get folder id

CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'

EXPORTING

region = c_b

IMPORTING

folder_id = wa_fol_id

EXCEPTIONS

communication_failure = 1

owner_not_exist = 2

system_failure = 3

x_error = 4

OTHERS = 5.

* Sy-subrc check not required

* Keeping file in string data type

CONCATENATE u_fname c_dot u_ext INTO v_filename.

CONCATENATE '&SO_FILENAME=' v_filename INTO wa_content.

APPEND wa_content TO t_objhead.

CLEAR wa_content.

wa_object-objkey = v_lifnr.

* For example, business object name for PO is BUS2012,

* business object for PR is BUS2105,

* business object for vendor is 'LFA1' etc

wa_object-objtype = c_lfa1. "'LFA1'.

wa_obj_data-objsns = c_obj. " 'O'.

wa_obj_data-objla = sy-langu.

wa_obj_data-objdes = v_filename. "u_fname. JAMKA0620

wa_obj_data-file_ext = u_ext.

TRANSLATE wa_obj_data-file_ext TO UPPER CASE.

* This is very important step. If your object size does not match with the input

* file size, then your object might get attached, but it will show error while you

* try to open it.

* If you have a way, where you can read the input file size directly, then assign

* it directly else, use the below formula

* wa_obj_data-objlen = lines( t_content ) * 255.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = wa_obj_data-objlen

IMPORTING

output = wa_obj_data-objlen.

IF t_content IS NOT INITIAL.

CALL FUNCTION 'SO_OBJECT_INSERT'

EXPORTING

folder_id = wa_fol_id

object_type = c_ext

object_hd_change = wa_obj_data

IMPORTING

object_id = wa_obj_id

TABLES

objhead = t_objhead

objcont = t_content

EXCEPTIONS

active_user_not_exist = 1

communication_failure = 2

component_not_available = 3

dl_name_exist = 4

folder_not_exist = 5

folder_no_authorization = 6

object_type_not_exist = 7

operation_no_authorization = 8

owner_not_exist = 9

parameter_error = 10

substitute_not_active = 11

substitute_not_defined = 12

system_failure = 13

x_error = 14

OTHERS = 15.

IF sy-subrc = 0 AND wa_object-objkey IS NOT INITIAL.

wa_folmem_k-foltp = wa_fol_id-objtp.

wa_folmem_k-folyr = wa_fol_id-objyr.

wa_folmem_k-folno = wa_fol_id-objno.

* Please note: lwa_fol_id and lwa_obj_id are different work areas

wa_folmem_k-doctp = wa_obj_id-objtp.

wa_folmem_k-docyr = wa_obj_id-objyr.

wa_folmem_k-docno = wa_obj_id-objno.

v_ep_note = wa_folmem_k.

wa_note-objtype = c_message. " 'MESSAGE'.

* lwa_note-logsys = lv_logical_system.

wa_note-objkey = v_ep_note.

* Link it

CALL FUNCTION 'BINARY_RELATION_CREATE_COMMIT'

EXPORTING

obj_rolea = wa_object

obj_roleb = wa_note

relationtype = c_atta

EXCEPTIONS

no_model = 1

internal_error = 2

unknown = 3

OTHERS = 4.

IF sy-subrc EQ 0.

* Commit it

COMMIT WORK.

wa_result-vend = v_lifnr.

wa_result-file = v_filename. "u_fname.

wa_result-status = c_s.

wa_result-message = text-022."'File update successfully'. "'S'.

APPEND wa_result TO t_result.

CLEAR : wa_result.

PERFORM archive_file USING v_fullpath

u_vend.

ELSE.

wa_msg-msgty = c_e.

wa_msg-msgid = sy-msgid.

wa_msg-msgno = sy-msgno.

wa_msg-msgv1 = sy-msgv1.

wa_msg-msgv2 = sy-msgv2.

wa_msg-msgv3 = u_vend.

wa_msg-msgv4 = v_fname.

v_message = wa_msg-msgv1 && wa_msg-msgv2 && wa_msg-msgv3 && wa_msg-msgv4.

wa_result-vend = v_lifnr.

wa_result-file = v_filename.

wa_result-status = c_f.

wa_result-message = v_message. " 'F'.

APPEND wa_result TO t_result.

CLEAR : wa_result.

PERFORM err_vend USING " u_vend

u_fname

u_ext.

PERFORM add_msg_inlog USING wa_msg.

ENDIF.

ELSE.

wa_msg-msgty = c_e.

wa_msg-msgid = sy-msgid.

wa_msg-msgno = sy-msgno.

wa_msg-msgv1 = sy-msgv1.

wa_msg-msgv2 = sy-msgv2.

wa_msg-msgv3 = u_vend.

wa_msg-msgv4 = v_fname.

v_message = wa_msg-msgv1 && wa_msg-msgv2 && wa_msg-msgv3 && wa_msg-msgv4.

wa_result-vend = v_lifnr.

wa_result-file = v_filename.

wa_result-status = c_f.

wa_result-message = v_message. " 'F'.

APPEND wa_result TO t_result.

CLEAR : wa_result.

PERFORM err_vend USING " u_vend

u_fname

u_ext.

PERFORM add_msg_inlog USING wa_msg.

ENDIF.

ENDIF.

FORM create_log_handle USING u_vend TYPE lifnr.

*use slg0 to create object

CONSTANTS : c_objt TYPE balobj_d VALUE 'ZVMD_MASS_UPLD',

c_err TYPE balsubobj VALUE 'ZVMD_ERR'.

* define some header data of this log

wa_log-extnumber = u_vend.

wa_log-object = c_objt. "'ZVMD_MASS_UPLD'.

wa_log-subobject = c_err. "'ZVMD_ERR'.

wa_log-aldate = sy-datum.

wa_log-altime = sy-uzeit.

wa_log-aluser = sy-uname.

wa_log-alprog = sy-repid.

CALL FUNCTION 'BAL_LOG_CREATE'

EXPORTING

i_s_log = wa_log

IMPORTING

e_log_handle = v_log_handle

EXCEPTIONS

log_header_inconsistent = 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.

ENDFORM.

FORM add_msg_inlog USING u_wa_msg LIKE wa_msg.

CALL FUNCTION 'BAL_LOG_MSG_ADD'

EXPORTING

i_log_handle = v_log_handle

i_s_msg = u_wa_msg

EXCEPTIONS

log_not_found = 1

msg_inconsistent = 2

log_is_full = 3

OTHERS = 4.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

PERFORM save_log_db USING v_log_handle.

ENDFORM.

FORM save_log_db USING u_v_log_handle TYPE balloghndl.

DATA: v_log TYPE balloghndl,

t_log_t TYPE bal_t_logh.

v_log = u_v_log_handle.

APPEND v_log TO t_log_t.

CALL FUNCTION 'BAL_DB_SAVE'

EXPORTING

i_client = sy-mandt

i_save_all = c_x

i_t_log_handle = t_log_t

EXCEPTIONS

log_not_found = 1

save_not_allowed = 2

numbering_error = 3

OTHERS = 4.

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.

FORM archive_file USING u_fullpath TYPE string

u_vend TYPE lifnr.

IF u_vend IS NOT INITIAL.

TRY.

"Delete file from source location

DELETE DATASET u_fullpath.

CATCH cx_root INTO DATA(o_exception).

ENDTRY.

ELSE.

TRY.

"Delete file from source location

DELETE DATASET u_fullpath.

CATCH cx_root INTO DATA(o_exception1).

ENDTRY.

ENDIF.

ENDFORM.

FORM send_file .

SORT t_result BY vend status.

DATA: v_count TYPE i.

CONSTANTS: c_vendor(13) TYPE c VALUE 'Vendor Number',

c_file(9) TYPE c VALUE 'File Name',

c_status(6) TYPE c VALUE 'Status',

c_message(7) TYPE c VALUE 'Message'.

DATA: v_data_string TYPE string,

v_fstring TYPE string.

CONCATENATE c_vendor c_file c_status c_message INTO v_data_string SEPARATED BY

cl_abap_char_utilities=>horizontal_tab.

LOOP AT t_result INTO wa_result.

CONCATENATE wa_result-vend wa_result-file wa_result-status wa_result-message INTO v_fstring SEPARATED BY

cl_abap_char_utilities=>horizontal_tab.

CONCATENATE v_data_string v_fstring INTO v_data_string SEPARATED BY

cl_abap_char_utilities=>newline.

CLEAR: v_fstring, wa_result .

ENDLOOP.

IF t_result IS NOT INITIAL .

PERFORM send_mail USING v_data_string . "subroutine to attach excel file of error logs and send mail

* wa_result-vend.

CLEAR : v_data_string.

ENDIF.

ENDFORM.

FORM get_fore_files .

CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'

EXPORTING

full_name = p_file

IMPORTING

stripped_name = v_name

file_path = v_path

EXCEPTIONS

x_error = 1

OTHERS = 2.

IF sy-subrc <> 0.

* Implement suitable error handling here

ENDIF.

SPLIT v_name AT c_dash INTO v_vend v_venddesc v_fileno.

DATA(v_vend_len) = strlen( v_vend ).

IF v_vend_len LE 10.

v_vendor = v_vend.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = v_vendor

IMPORTING

output = v_vendor.

SELECT SINGLE lifnr

FROM lfa1

INTO @DATA(v_lifnr)

WHERE lifnr = @v_vendor.

IF sy-subrc EQ 0.

* IF v_lifnr IS NOT INITIAL.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = v_lifnr

IMPORTING

output = v_lifnr.

wa_borident-objkey = v_lifnr. "Venor Number

* wa_borident-objtype = c_equi. " 'EQUI'. "Object Type

wa_borident-objtype = c_lfa1. " 'LFA1'. "BUS Number

*/ Filename Assign to the Structure

wa_files-fname = p_file . "Path

APPEND wa_files TO t_files1 .

*/ Folder Root

CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'

EXPORTING

region = c_b

IMPORTING

folder_id = wa_folder_id

EXCEPTIONS

OTHERS = 1.

*/ Append data to the MOM Structure

wa_document-foltp = wa_folder_id-objtp.

wa_document-folyr = wa_folder_id-objyr .

wa_document-folno = wa_folder_id-objno .

wa_document-objdes = v_name . "Name of file

wa_document-objnam = v_name . "Name of file

*/ Attachment FileName Assignment

wa_h_data-objdes = v_name . "Name of file

*/ Using this function module to read FILE from Presentation server

CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER'

EXPORTING

method = 'IMPORTFROMPC'

ref_document = wa_document

IMPORTING

rcode = v_ret_code

TABLES

files = t_files1

CHANGING

document = wa_document

header_data = wa_h_data

folmem_data = wa_fol_data

receive_data = wa_rec_data.

*/ File Creation OkCodes

IF wa_document-okcode = c_crea OR wa_document-okcode = c_chng.

wa_attachement-objtype = c_msg1. " 'MESSAGE'.

wa_attachement-objkey = wa_document(34).

CALL FUNCTION 'BINARY_RELATION_CREATE_COMMIT'

EXPORTING

obj_rolea = wa_borident

obj_roleb = wa_attachement

relationtype = c_atta

EXCEPTIONS

no_model = 1

internal_error = 2

unknown = 3

OTHERS = 4.

IF sy-subrc EQ 0.

MESSAGE text-022 TYPE c_s. " 'File has been updated successfully'.

*/Error Handling

ELSE.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDIF.

ELSE.

MESSAGE 'Incorrect Vendor Number or File Name format'(003) TYPE c_s DISPLAY LIKE c_e.

LEAVE LIST-PROCESSING.

ENDIF.

ELSE.

MESSAGE 'Incorrect Vendor Number or File Name format'(003) TYPE c_s DISPLAY LIKE c_e.

LEAVE LIST-PROCESSING.

ENDIF.

ENDFORM.

FORM err_vend USING u_fname TYPE string

u_ext TYPE string.

DATA:v_fullpath TYPE string.

CONCATENATE v_dir u_fname c_dot u_ext INTO v_fullpath.

PERFORM arc_err_file USING v_fullpath.

ENDFORM.

FORM arc_err_file USING u_fullpath TYPE string.

TRY.

"Delete file from source location

DELETE DATASET u_fullpath.

CATCH cx_root INTO DATA(o_exception).

ENDTRY.

ENDFORM.