As part of a recent project development we had a new conversion program for build i.e Open Dispute Upload in SAP FSCM module. The requirement is from a flat file we have to read dispute data and upload into SAP system, in the file we will be having dispute case details, open items and URL to store in services of objects in dispute case. Open items is assigned to dispute case and URL is a web link of supporting documents which saved in some portal based application. When I start this build, neither in Google nor SDN have much or correct solutions for the same requirement, I had seen many Open discussions started long back but still which are not answered. At this moment I decided to share the code in our favorite SDN once I complete this build. Let me know if you need any kind of clarification or help is required regarding this requirement.
*&---------------------------------------------------------------------------------------------------*
*& Report zopen_dispute_upload
*&
*&----------------------------------------------------------------------------------------------------*
*& Programe Name : zopen_dispute_upload
*& TYPE : Conversion
*& Author : Raju C D
*&Brief Purpose : It will upload Open disputes from an input excel file
* and Assign open items to dispute case and create URL
* in services of object of Dispute case
*& Tcode :
*&------------------------------------------------------------------------------------------------------*
REPORT zopen_dispute_upload.
*Golbal Declarations and Selection Screen Design
INCLUDE zopen_dispute_upload_top.
*All Subroutines'code
INCLUDE zopen_dispute_uploadf01.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_pfile.
* F4 Help for Input file
PERFORM f_pre_f4help_pfile.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_ppath.
* F4 Help for Output file
PERFORM f_pre_f4help_ppath.
START-OF-SELECTION.
*Read Open Dispute file from Presentation Server
PERFORM f_read_file.
*Create Dispute case, Open account assignment and URL Creation
PERFORM f_create_dispute.
* Output file storing in Presenation Server
PERFORM f_output_file_save.
END-OF-SELECTION.
* Display an Overview Log as a result
PERFORM f_display_result.
*------------------------End of the program----------------------
*&---------------------------------------------------------------------*
*& Include ZOPEN_DISPUTE_UPLOAD_TOP
*&---------------------------------------------------------------------*
TYPES: BEGIN OF gt_input,
title TYPE scmg_case_title,
customer TYPE udm_kunnr,
company_code TYPE bukrs,
case_type TYPE scmgcase_type,
external_reference TYPE scmg_ext_ref,
category TYPE scmg_category,
reason TYPE scmg_reason_code,
status TYPE scmgstatusonr,
priority TYPE scmg_priority,
coordinator TYPE udm_coordinator,
person_responsible TYPE scmg_responsible,
process_deadline TYPE udm_due_date,
original_disputed_amount TYPE udm_original_amt,
disputed_amount TYPE udm_disputed_amt,
currency TYPE udm_dispute_curr,
contact_person TYPE udm_contact_name,
telephone_no TYPE udm_contact_phone,
email TYPE udm_contact_email,
fax_number TYPE udm_contact_fax,
ctry_of_fax_no TYPE udm_contact_faxc,
accounting_document_no TYPE belnr_d,
fiscal_yr TYPE gjahr,
web_url TYPE so_text255,
web_url_des TYPE so_obj_des,
notes TYPE char100,
END OF gt_input.
TYPES: BEGIN OF gt_output,
title TYPE scmg_case_title,
customer TYPE udm_kunnr,
company_code TYPE bukrs,
case_type TYPE scmgcase_type,
external_reference TYPE scmg_ext_ref,
category TYPE scmg_category,
reason TYPE scmg_reason_code,
status TYPE scmgstatusonr,
priority TYPE scmg_priority,
coordinator TYPE udm_coordinator,
person_responsible TYPE scmg_responsible,
process_deadline TYPE udm_due_date,
original_disputed_amount TYPE udm_original_amt,
disputed_amount TYPE udm_disputed_amt,
currency TYPE udm_dispute_curr,
contact_person TYPE udm_contact_name,
telephone_no TYPE udm_contact_phone,
email TYPE udm_contact_email,
fax_number TYPE udm_contact_fax,
ctry_of_fax_no TYPE udm_contact_faxc,
accounting_document_no TYPE belnr_d,
fiscal_yr TYPE gjahr,
web_url TYPE so_text255,
web_url_des TYPE so_obj_des,
notes TYPE char100,
record_status TYPE char10,
error_details TYPE char100,
END OF gt_output.
DATA: gi_input TYPE STANDARD TABLE OF gt_input,
gi_output TYPE STANDARD TABLE OF gt_output.
DATA: gv_success_cnt TYPE i,
gv_error_cnt TYPE i.
*Selection Screen Design
SELECTION-SCREEN BEGIN OF BLOCK b01 WITH FRAME TITLE text-b01. " Upload File
PARAMETERS : p_pfile TYPE dxfile-filename OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b01.
SELECTION-SCREEN : BEGIN OF BLOCK b02 WITH FRAME TITLE text-b02. " Log File Storage
PARAMETERS : p_ppath TYPE ibipparms-path OBLIGATORY,
p_tstrun AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN : END OF BLOCK b02.
*----------------------------------------------------------------------*
***INCLUDE ZOPEN_DISPUTE_UPLOADF01 .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form F_PRE_F4HELP_PFILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_pre_f4help_pfile .
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = 'P_PFILE'
IMPORTING
file_name = p_pfile.
ENDFORM. " F_PRE_F4HELP_PFILE
*&---------------------------------------------------------------------*
*& Form F_PRE_F4HELP_PPATH
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_pre_f4help_ppath .
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = 'P_PPATH'
IMPORTING
file_name = p_ppath.
ENDFORM. " F_PRE_F4HELP_PPATH
*&---------------------------------------------------------------------*
*& Form READ_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_read_file .
CONSTANTS: lc_start_col TYPE i VALUE '1',
lc_start_row TYPE i VALUE '2',
lc_end_col TYPE i VALUE '28',
lc_end_row TYPE i VALUE '2000'.
DATA: li_tab TYPE STANDARD TABLE OF alsmex_tabline,
lwa_tab TYPE alsmex_tabline,
lwa_inputtxt TYPE gt_input,
lv_filepath TYPE rlgrap-filename.
lv_filepath = p_pfile.
* Read Open Disputes Excel File into Internal Table
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = lv_filepath
i_begin_col = lc_start_col
i_begin_row = lc_start_row
i_end_col = lc_end_col
i_end_row = lc_end_row
TABLES
intern = li_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.
* Storing Excel data into Internal Table
LOOP AT li_tab INTO lwa_tab.
CASE lwa_tab-col.
WHEN '001'. lwa_inputtxt-title = lwa_tab-value.
WHEN '002'. lwa_inputtxt-customer = lwa_tab-value.
WHEN '003'. lwa_inputtxt-company_code = lwa_tab-value.
WHEN '004'. lwa_inputtxt-case_type = lwa_tab-value.
WHEN '005'. lwa_inputtxt-external_reference = lwa_tab-value.
WHEN '006'. lwa_inputtxt-category = lwa_tab-value.
WHEN '007'. lwa_inputtxt-reason = lwa_tab-value.
WHEN '008'. lwa_inputtxt-status = lwa_tab-value.
WHEN '009'. lwa_inputtxt-priority = lwa_tab-value.
WHEN '010'. lwa_inputtxt-coordinator = lwa_tab-value.
WHEN '011'. lwa_inputtxt-person_responsible = lwa_tab-value.
WHEN '012'. lwa_inputtxt-process_deadline = lwa_tab-value.
WHEN '013'. lwa_inputtxt-original_disputed_amount = lwa_tab-value.
WHEN '014'. lwa_inputtxt-disputed_amount = lwa_tab-value.
WHEN '015'. lwa_inputtxt-currency = lwa_tab-value.
WHEN '016'. lwa_inputtxt-contact_person = lwa_tab-value.
WHEN '017'. lwa_inputtxt-telephone_no = lwa_tab-value.
WHEN '018'. lwa_inputtxt-email = lwa_tab-value.
WHEN '019'. lwa_inputtxt-fax_number = lwa_tab-value.
WHEN '020'. lwa_inputtxt-ctry_of_fax_no = lwa_tab-value.
WHEN '021'. lwa_inputtxt-accounting_document_no = lwa_tab-value.
WHEN '022'. lwa_inputtxt-fiscal_yr = lwa_tab-value.
WHEN '023'. lwa_inputtxt-web_url = lwa_tab-value.
WHEN '024'. lwa_inputtxt-web_url_des = lwa_tab-value.
WHEN '025'. lwa_inputtxt-notes = lwa_tab-value.
ENDCASE.
AT END OF row.
APPEND lwa_inputtxt TO gi_input.
CLEAR lwa_inputtxt.
ENDAT.
ENDLOOP.
ENDFORM. " READ_FILE
*&---------------------------------------------------------------------*
*& Form F_CREATE_DISPUTE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_create_dispute .
TYPES: BEGIN OF lt_bsid,
bukrs TYPE bukrs,
gjahr TYPE gjahr,
belnr TYPE belnr_d,
buzei TYPE buzei,
END OF lt_bsid.
DATA: li_attr TYPE STANDARD TABLE OF bapi_dispute_attribute,
li_bsid TYPE STANDARD TABLE OF lt_bsid,
li_ret TYPE STANDARD TABLE OF bapiret2,
li_bseg TYPE TABLE OF fdm_ar_bseg,
li_bseg1 TYPE TABLE OF fdm_ar_bseg,
li_notes TYPE STANDARD TABLE OF bapi_dispute_note,
lwa_notes TYPE bapi_dispute_note,
lwa_bsid TYPE lt_bsid,
lwa_input TYPE gt_input,
lwa_bseg TYPE fdm_ar_bseg,
lwa_attr TYPE bapi_dispute_attribute,
lv_guid TYPE guid_16,
lv_guid_dm TYPE bdm_case_guid,
lv_guid_im TYPE bdm_case_guid,
lv_ext_key TYPE scmg_t_case_attr-ext_key,
li_attr1 TYPE fdm_t_attribute,
lwa_attr1 TYPE fdm_attribute,
lv_obj_key TYPE borident-objkey,
lwa_output TYPE gt_output,
lv_flag1 TYPE char1,
lv_flag2 TYPE char1,
lv_flag3 TYPE char3,
lwa_dis_amt TYPE bapi_dispute_amounts,
lwa_ret TYPE bapiret2,
lv_num_rng_key TYPE dfpm_numb-key1,
lv_new_proc_seqnr TYPE n,
li_dcproc TYPE STANDARD TABLE OF fdm_dcproc,
lwa_dcproc TYPE fdm_dcproc.
* Processing Dispute data.
LOOP AT gi_input INTO lwa_input.
lwa_attr-attr_id = 'CCASE_TYPE'(074).
lwa_attr-attr_value = lwa_input-case_type.
APPEND lwa_attr TO li_attr.
lwa_attr-attr_id = 'EXT_REF'(073).
lwa_attr-attr_value = lwa_input-external_reference.
APPEND lwa_attr TO li_attr.
lwa_attr-attr_id = 'RESPONSIBLE'(072).
lwa_attr-attr_value = lwa_input-person_responsible.
APPEND lwa_attr TO li_attr.
lwa_attr-attr_id = 'CASE_TITLE'(071).
lwa_attr-attr_value = lwa_input-title.
APPEND lwa_attr TO li_attr.
lwa_attr-attr_id = 'CATEGORY'(070).
lwa_attr-attr_value = lwa_input-category.
APPEND lwa_attr TO li_attr.
lwa_attr-attr_id = 'PRIORITY'(069).
lwa_attr-attr_value = lwa_input-priority.
APPEND lwa_attr TO li_attr.
lwa_attr-attr_id = 'PROFILE_ID'(068).
lwa_attr-attr_value = 'FIN_DISP'.
APPEND lwa_attr TO li_attr.
lwa_attr-attr_id = 'STAT_ORDERNO'(067).
lwa_attr-attr_value = lwa_input-status.
APPEND lwa_attr TO li_attr.
lwa_attr-attr_id = 'REASON_CODE'(065).
lwa_attr-attr_value = lwa_input-reason.
APPEND lwa_attr TO li_attr.
lwa_attr-attr_id = 'FIN_COORDINATOR'(064).
lwa_attr-attr_value = lwa_input-coordinator.
APPEND lwa_attr TO li_attr.
lwa_attr-attr_id = 'FIN_DUE_DATE'(063).
lwa_attr-attr_value = lwa_input-process_deadline.
APPEND lwa_attr TO li_attr.
lwa_attr-attr_id = 'FIN_DISPUTE_CURR'(062).
lwa_attr-attr_value = lwa_input-currency.
APPEND lwa_attr TO li_attr.
lwa_attr-attr_id = 'FIN_PROC_SEQNR'(061).
lwa_attr-attr_value = '002'.
APPEND lwa_attr TO li_attr.
lwa_attr-attr_id = 'FIN_CONTACT_NAME'(060).
lwa_attr-attr_value = lwa_input-contact_person.
APPEND lwa_attr TO li_attr.
lwa_attr-attr_id = 'FIN_KUNNR'(059).
lwa_attr-attr_value = lwa_input-customer.
APPEND lwa_attr TO li_attr.
lwa_attr-attr_id = 'FIN_BUKRS'(058).
lwa_attr-attr_value = lwa_input-company_code.
APPEND lwa_attr TO li_attr.
lwa_attr-attr_id = 'FIN_CONTACT_TEL'(075).
lwa_attr-attr_value = lwa_input-telephone_no.
APPEND lwa_attr TO li_attr.
lwa_attr-attr_id = 'FIN_CONTACT_MAIL'(076).
lwa_attr-attr_value = lwa_input-email.
APPEND lwa_attr TO li_attr.
lwa_attr-attr_id = 'FIN_CONTACT_FAX'(077).
lwa_attr-attr_value = lwa_input-fax_number.
APPEND lwa_attr TO li_attr.
lwa_attr-attr_id = 'FIN_CONTACT_FAXC'(078).
lwa_attr-attr_value = lwa_input-ctry_of_fax_no.
APPEND lwa_attr TO li_attr.
* Building Disputes Amount Structure
IF lwa_input-accounting_document_no IS INITIAL.
lwa_dis_amt-delta_original = lwa_input-original_disputed_amount.
lwa_dis_amt-delta_disputed = lwa_input-disputed_amount.
lwa_dis_amt-dispute_curr = lwa_input-currency.
ENDIF.
* Notes
lwa_notes-text_line = lwa_input-notes.
APPEND lwa_notes TO li_notes.
* Generating GUID
CALL FUNCTION 'GUID_CREATE'
IMPORTING
ev_guid_16 = lv_guid.
lv_guid_dm = lv_guid.
* Create Dispute case
clear: lv_guid_im,lwa_ret.
CALL FUNCTION 'BAPI_DISPUTE_CREATE'
EXPORTING
case_guid_create = lv_guid_dm
case_type = lwa_input-case_type
amounts_delta = lwa_dis_amt
IMPORTING
case_guid = lv_guid_im
return = lwa_ret
TABLES
attributes = li_attr
notes = li_notes
.
IF NOT p_tstrun IS INITIAL.
IF NOT lv_guid_im IS INITIAL.
MOVE-CORRESPONDING lwa_input TO lwa_output.
lwa_output-record_status = 'Success'(037).
CONCATENATE 'GUID-'(079) lv_guid_im INTO lwa_output-error_details.
APPEND lwa_output TO gi_output.
CLEAR lwa_output.
gv_success_cnt = gv_success_cnt + 1.
ELSE.
MOVE-CORRESPONDING lwa_input TO lwa_output.
lwa_output-record_status = 'Failed'(039).
IF lwa_ret IS INITIAL.
lwa_output-error_details = 'Failed in Dispute Creation'(038).
ELSE.
lwa_output-error_details = lwa_ret-message.
ENDIF.
APPEND lwa_output TO gi_output.
CLEAR lwa_output.
gv_error_cnt = gv_error_cnt + 1.
ENDIF.
ELSE.
*Dispute case has been created successfully,If GUID has been
*saved in import case_guid in the above FM
IF NOT lv_guid_im IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
.
* Checking whether Dispute case has been saved in scmg_t_case_attr.
CLEAR lv_ext_key.
SELECT SINGLE ext_key INTO lv_ext_key FROM scmg_t_case_attr WHERE case_guid EQ lv_guid_im.
IF sy-subrc EQ 0.
lv_num_rng_key = lv_guid_im.
* To increase sequence number manually,
* otherwise open account assignment has not been done properly
CLEAR lv_new_proc_seqnr.
CALL FUNCTION 'GET_NEXT_NUMBERS'
EXPORTING
i_object = 'FDM_ID'
i_key1 = lv_num_rng_key
i_key2 = space
i_xreorg = ' '
IMPORTING
e_first_number = lv_new_proc_seqnr
EXCEPTIONS
foreign_lock = 1.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
CLEAR lv_new_proc_seqnr.
ENDIF.
lwa_dcproc-mandt = sy-mandt.
lwa_dcproc-case_guid_loc = lv_guid_im.
lwa_dcproc-proc_seqnr = '001'.
lwa_dcproc-proc_step = '001'.
APPEND lwa_dcproc TO li_dcproc.
CLEAR lwa_dcproc.
* To increase sequence number and process step manually,
* otherwise open account assignment has not been done properly
CALL FUNCTION 'FDM_LOCAL_UPDATE'
TABLES
it_dcproc = li_dcproc
EXCEPTIONS
update_failure = 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.
lv_flag1 = 'X'. " Case creation Flag
IF NOT lwa_input-accounting_document_no IS INITIAL.
* getting data from BSEG for building t_bseg_fdm in FDM_AR_DOC_DISPUTE_BUILD
SELECT * FROM bseg INTO TABLE li_bseg WHERE bukrs EQ lwa_input-company_code
AND belnr EQ lwa_input-accounting_document_no
AND gjahr EQ lwa_input-fiscal_yr.
IF sy-subrc EQ 0.
SORT li_bseg BY bukrs gjahr belnr buzei.
* Getting data from Open item table BSID
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = lwa_input-customer
IMPORTING
output = lwa_input-customer.
*Get Open account data from BSID
SELECT bukrs gjahr belnr buzei INTO TABLE li_bsid FROM bsid
FOR ALL ENTRIES IN li_bseg
WHERE bukrs EQ li_bseg-bukrs
AND kunnr EQ lwa_input-customer
AND gjahr EQ li_bseg-gjahr
AND belnr EQ li_bseg-belnr.
IF sy-subrc EQ 0.
CLEAR lwa_bsid.
*Get first record from BSID records, usually one line item will be there for an account
READ TABLE li_bsid INTO lwa_bsid INDEX 1.
IF sy-subrc EQ 0.
CLEAR lwa_bseg.
*Read Bseg record to process accounting item
CLEAR lwa_bseg.
READ TABLE li_bseg INTO lwa_bseg WITH KEY bukrs = lwa_bsid-bukrs
gjahr = lwa_bsid-gjahr
belnr = lwa_bsid-belnr
buzei = lwa_bsid-buzei
BINARY SEARCH.
IF sy-subrc EQ 0.
APPEND lwa_bseg TO li_bseg1.
* Building Attributes internal table for FDM_AR_DOC_DISPUTE_BUILD
lwa_attr1-attr_id = 'CASE_GUID'(051).
lwa_attr1-attr_value = lv_guid_im.
APPEND lwa_attr1 TO li_attr1.
lwa_attr1-attr_id = 'CASE_TYPE'(052).
lwa_attr1-attr_value = lwa_input-case_type.
APPEND lwa_attr1 TO li_attr1.
lwa_attr1-attr_id = 'EXT_KEY'(053).
lwa_attr1-attr_value = lv_ext_key.
APPEND lwa_attr1 TO li_attr1.
lwa_attr-attr_id = 'FIN_PROC_SEQNR'(061).
lwa_attr-attr_value = '001'.
APPEND lwa_attr TO li_attr1.
* Updating Currency in waers and hwaers with pswsl, otherwise below FM will give exception
IF ( lwa_bseg-waers IS INITIAL ) OR ( lwa_bseg-hwaer IS INITIAL ).
READ TABLE li_bseg INTO lwa_bseg INDEX 1.
IF ( lwa_bseg-waers IS INITIAL ).
lwa_bseg-waers = lwa_bseg-pswsl.
ENDIF.
IF lwa_bseg-hwaer IS INITIAL.
lwa_bseg-hwaer = lwa_bseg-pswsl.
ENDIF.
MODIFY li_bseg1 FROM lwa_bseg INDEX 1 TRANSPORTING waers hwaer .
ENDIF.
* Open item assignment to Dispute case.
CALL FUNCTION 'FDM_AR_DOC_DISPUTE_BUILD'
EXPORTING
i_single = 'X'
i_dialog = space
i_check = 'X'
i_save = 'X'
i_message = space
i_action = '5'
it_attributes = li_attr1
i_caller = '3'
TABLES
t_bseg_fdm = li_bseg1
EXCEPTIONS
cancelled = 1
item_locked = 2
item_cleared = 3
item_disputed = 4
vendor_not_active = 5
no_invoice = 6
no_items = 7
no_partner = 8
cdis_not_active = 9
OTHERS = 10
.
IF sy-subrc <> 0.
MOVE-CORRESPONDING lwa_input TO lwa_output.
lwa_output-record_status = 'Failed'(039).
CASE sy-subrc.
WHEN '1'. lwa_output-error_details = 'cancelled'(050).
WHEN '2'. lwa_output-error_details = 'item_locked'(049).
WHEN '3'. lwa_output-error_details = 'item_cleared'(048).
WHEN '4'. lwa_output-error_details = 'item_disputed'(047).
WHEN '5'. lwa_output-error_details = 'vendor_not_active'(046).
WHEN '6'. lwa_output-error_details = 'no_invoice'(045).
WHEN '7'. lwa_output-error_details = 'no_items'(044).
WHEN '8'. lwa_output-error_details = 'no_partner'(043).
WHEN '9'. lwa_output-error_details = 'cdis_not_active'(042).
WHEN OTHERS. lwa_output-error_details = 'Failed in Account assignment'(041).
ENDCASE.
APPEND lwa_output TO gi_output.
CLEAR lwa_output.
gv_error_cnt = gv_error_cnt + 1.
ELSE.
lv_flag2 = 'X'. " Open accoount assigment to case successful flag
ENDIF.
ENDIF.
ENDIF.
ELSE.
MOVE-CORRESPONDING lwa_input TO lwa_output.
lwa_output-record_status = 'Failed'(039).
lwa_output-error_details = 'Accounting Document is not there in BSID table'(081).
APPEND lwa_output TO gi_output.
CLEAR lwa_output.
gv_error_cnt = gv_error_cnt + 1.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
.
ENDIF.
ENDIF.
ENDIF.
IF NOT lwa_input-web_url IS INITIAL .
lv_obj_key = lv_guid_im.
* URL Creation in Service of objects in Dispute case
CALL FUNCTION 'Z_FI_FM_GOS_URL_CREATE'
EXPORTING
i_objecttype = 'SCASE'
i_objectkey = lv_obj_key
i_url = lwa_input-web_url
i_urldes = lwa_input-web_url_des
TABLES
ot_return = li_ret
EXCEPTIONS
update_fail = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* Updating output file with record status and error deatils
MOVE-CORRESPONDING lwa_input TO lwa_output.
lwa_output-record_status = 'Failed'(039).
lwa_output-error_details = 'Failed in URL Creation'(040).
APPEND lwa_output TO gi_output.
CLEAR lwa_output.
gv_error_cnt = gv_error_cnt + 1.
ELSE.
lv_flag3 = 'X'." URL creation Successful flag
ENDIF.
ENDIF.
ELSE.
* Updating output file with record status and error deatils
MOVE-CORRESPONDING lwa_input TO lwa_output.
lwa_output-record_status = 'Failed'(039).
lwa_output-error_details = lwa_ret.
APPEND lwa_output TO gi_output.
CLEAR lwa_output.
gv_error_cnt = gv_error_cnt + 1.
ENDIF.
ELSE.
* Updating output file with record status and error deatils
MOVE-CORRESPONDING lwa_input TO lwa_output.
lwa_output-record_status = 'Failed'(039).
IF lwa_ret IS INITIAL.
lwa_output-error_details = 'Failed in Dispute Creation'(038).
ELSE.
lwa_output-error_details = lwa_ret-message.
ENDIF.
APPEND lwa_output TO gi_output.
CLEAR lwa_output.
gv_error_cnt = gv_error_cnt + 1.
ENDIF.
* Checking the record status, whether all three activities have been successfully completed
IF ( NOT lwa_input-accounting_document_no IS INITIAL )
AND ( NOT lwa_input-web_url IS INITIAL ) .
IF lv_flag1 = 'X' AND " Dispute Case Create
lv_flag2 = 'X' AND " Open Items assignment to Dispute Case
lv_flag3 = 'X'. " URL Creation in Dispute Case
* Updating Output file with success record
MOVE-CORRESPONDING lwa_input TO lwa_output.
lwa_output-record_status = 'Success'(037).
CONCATENATE 'Dispute Case-'(036) lv_ext_key INTO lwa_output-error_details.
APPEND lwa_output TO gi_output.
CLEAR lwa_output.
gv_success_cnt = gv_success_cnt + 1.
ENDIF.
ENDIF.
IF ( NOT lwa_input-accounting_document_no IS INITIAL )
AND ( lwa_input-web_url IS INITIAL ) .
IF lv_flag1 = 'X' AND " Dispute Case Create
lv_flag2 = 'X'. " Open Items assignment to Dispute Case
* Updating Output file with success record
MOVE-CORRESPONDING lwa_input TO lwa_output.
lwa_output-record_status = 'Success'(037).
CONCATENATE 'Dispute Case-'(036) lv_ext_key INTO lwa_output-error_details.
APPEND lwa_output TO gi_output.
CLEAR lwa_output.
gv_success_cnt = gv_success_cnt + 1.
ENDIF.
ENDIF.
IF ( lwa_input-accounting_document_no IS INITIAL )
AND ( NOT lwa_input-web_url IS INITIAL ).
IF lv_flag1 = 'X' AND " Dispute Case Create
lv_flag3 = 'X'. " Open Items assignment to Dispute Case
* * Updating Output file with success record
MOVE-CORRESPONDING lwa_input TO lwa_output.
lwa_output-record_status = 'Success'(037).
CONCATENATE 'Dispute Case-'(036) lv_ext_key INTO lwa_output-error_details.
APPEND lwa_output TO gi_output.
CLEAR lwa_output.
gv_success_cnt = gv_success_cnt + 1.
ENDIF.
ENDIF.
IF ( lwa_input-accounting_document_no IS INITIAL )
AND ( lwa_input-web_url IS INITIAL ).
IF lv_flag1 = 'X'. " Dispute Case Create
* Updating Output file with success record
MOVE-CORRESPONDING lwa_input TO lwa_output.
lwa_output-record_status = 'Success'(037).
CONCATENATE 'Dispute Case-'(036) lv_ext_key INTO lwa_output-error_details.
APPEND lwa_output TO gi_output.
CLEAR lwa_output.
gv_success_cnt = gv_success_cnt + 1.
ENDIF.
ENDIF.
ENDIF.
CLEAR: lv_flag1, lv_flag2, lv_flag3.
REFRESH: li_attr1,li_bseg1,li_ret,li_attr,li_notes.
ENDLOOP.
ENDFORM. " F_CREATE_DISPUTE
*&---------------------------------------------------------------------*
*& Form F_DISPLAY_RESULT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_display_result .
DATA: lv_line TYPE i.
* Counting Total number records in the input file
DESCRIBE TABLE gi_input LINES lv_line.
WRITE: 'An Overview Log'(035).
WRITE: / 'Total Records Processed:'(034), lv_line.
WRITE: / 'Total Success Records:'(033), gv_success_cnt.
WRITE: / 'Total Failed Records:'(032), gv_error_cnt.
WRITE: /'The detailed Log file has been saved in'(031),p_ppath.
ENDFORM. " F_DISPLAY_RESULT
*&---------------------------------------------------------------------*
*& Form F_OUTPUT_FILE_SAVE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_output_file_save .
TYPES: BEGIN OF lt_fieldname,
name TYPE char30,
END OF lt_fieldname.
DATA : li_fieldname TYPE STANDARD TABLE OF lt_fieldname,
lv_filename TYPE string,
lwa_fieldname TYPE lt_fieldname.
lv_filename = p_ppath.
* Filling columns names of output file.
lwa_fieldname-name = 'Title'(030).
APPEND lwa_fieldname TO li_fieldname.
CLEAR lwa_fieldname.
lwa_fieldname-name = 'Customer'(029).
APPEND lwa_fieldname TO li_fieldname.
CLEAR lwa_fieldname.
lwa_fieldname-name = 'Company Code'(028).
APPEND lwa_fieldname TO li_fieldname.
CLEAR lwa_fieldname.
lwa_fieldname-name = 'Case Type'(027).
APPEND lwa_fieldname TO li_fieldname.
CLEAR lwa_fieldname.
lwa_fieldname-name = 'External Reference'(026).
APPEND lwa_fieldname TO li_fieldname.
CLEAR lwa_fieldname.
lwa_fieldname-name = 'Category'(025).
APPEND lwa_fieldname TO li_fieldname.
CLEAR lwa_fieldname.
lwa_fieldname-name = 'Reason'(024).
APPEND lwa_fieldname TO li_fieldname.
CLEAR lwa_fieldname.
lwa_fieldname-name = 'Status'(023).
APPEND lwa_fieldname TO li_fieldname.
CLEAR lwa_fieldname.
lwa_fieldname-name = 'Priority'(022).
APPEND lwa_fieldname TO li_fieldname.
CLEAR lwa_fieldname.
lwa_fieldname-name = 'Coordinator'(021).
APPEND lwa_fieldname TO li_fieldname.
CLEAR lwa_fieldname.
lwa_fieldname-name = 'Person Responsible'(020).
APPEND lwa_fieldname TO li_fieldname.
CLEAR lwa_fieldname.
lwa_fieldname-name = 'Process Deadline'(019).
APPEND lwa_fieldname TO li_fieldname.
CLEAR lwa_fieldname.
lwa_fieldname-name = 'Original Disputed Amount'(017).
APPEND lwa_fieldname TO li_fieldname.
CLEAR lwa_fieldname.
lwa_fieldname-name = 'Disputed Amount'(016).
APPEND lwa_fieldname TO li_fieldname.
CLEAR lwa_fieldname.
lwa_fieldname-name = 'Currency'(015).
APPEND lwa_fieldname TO li_fieldname.
CLEAR lwa_fieldname.
lwa_fieldname-name = 'Contact Person'(014).
APPEND lwa_fieldname TO li_fieldname.
CLEAR lwa_fieldname.
lwa_fieldname-name = 'Telephone No.'(013).
APPEND lwa_fieldname TO li_fieldname.
CLEAR lwa_fieldname.
lwa_fieldname-name = 'e-mail'(012).
APPEND lwa_fieldname TO li_fieldname.
CLEAR lwa_fieldname.
lwa_fieldname-name = 'Fax Number'(011).
APPEND lwa_fieldname TO li_fieldname.
CLEAR lwa_fieldname.
lwa_fieldname-name = 'Ctry of Fax No.'(010).
APPEND lwa_fieldname TO li_fieldname.
CLEAR lwa_fieldname.
lwa_fieldname-name = 'Accounting document no.'(007).
APPEND lwa_fieldname TO li_fieldname.
CLEAR lwa_fieldname.
lwa_fieldname-name = 'Fiscal Year'(006).
APPEND lwa_fieldname TO li_fieldname.
CLEAR lwa_fieldname.
lwa_fieldname-name = 'Web URL'(005).
APPEND lwa_fieldname TO li_fieldname.
CLEAR lwa_fieldname.
lwa_fieldname-name = 'Web URL Title'(004).
APPEND lwa_fieldname TO li_fieldname.
CLEAR lwa_fieldname.
lwa_fieldname-name = 'Notes'(003).
APPEND lwa_fieldname TO li_fieldname.
CLEAR lwa_fieldname.
lwa_fieldname-name = 'Record Status'(002).
APPEND lwa_fieldname TO li_fieldname.
CLEAR lwa_fieldname.
lwa_fieldname-name = 'Error Details'(082).
APPEND lwa_fieldname TO li_fieldname.
CLEAR lwa_fieldname.
*Download excel formatted output file into presentation server
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = lv_filename
filetype = 'ASC'(080)
write_field_separator = 'X'
TABLES
data_tab = gi_output
fieldnames = li_fieldname
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22
.
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. " F_OUTPUT_FILE_SAVE
FUNCTION Z_FI_FM_GOS_URL_CREATE.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(I_OBJECTTYPE) LIKE BORIDENT-OBJTYPE
*" VALUE(I_OBJECTKEY) LIKE BORIDENT-OBJKEY
*" REFERENCE(I_URL) LIKE SOLI-LINE
*" REFERENCE(I_URLDES) LIKE SOOD1-OBJDES
*" REFERENCE(I_NOCOMMIT) TYPE XFELD OPTIONAL
*" TABLES
*" OT_RETURN STRUCTURE BAPIRET2
*" EXCEPTIONS
*" UPDATE_FAIL
*"----------------------------------------------------------------------
*Local data definitions.
data: l_owner like soud-usrnam,
l_folderid like soodk,
l_obj_id like soodk,
l_objdata like sood1,
lt_objcont type table of soli with header line,
lt_objhead type table of soli with header line,
l_object like borident,
l_reldoc like borident,
l_syst like syst.
*-----------------------------------------------------------------------
*
*1. Get folder id.
l_owner = sy-uname.
call function 'SO_FOLDER_ROOT_ID_GET'
EXPORTING
owner = l_owner
region = 'B'
IMPORTING
folder_id = l_folderid
EXCEPTIONS
communication_failure = 1
owner_not_exist = 2
system_failure = 3
x_error = 4
others = 5.
if sy-subrc <> 0.
l_syst = syst.
perform collect_message using ot_return l_syst '1.FolderRoot'.
append ot_return.
exit.
endif.
*2. Insert object
l_objdata-objla = 'EN'.
l_objdata-objdes = i_urldes.
l_objdata-objsns = 'O'.
concatenate '&KEY&' i_url into lt_objcont.
append lt_objcont.
call function 'SO_OBJECT_INSERT'
EXPORTING
folder_id = l_folderid
object_type = 'URL'
object_hd_change = l_objdata
owner = l_owner
IMPORTING
object_id = l_obj_id
TABLES
objcont = lt_objcont
objhead = lt_objhead
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.
l_syst = syst.
perform collect_message using ot_return l_syst '2.ObjectInsert'.
append ot_return.
exit.
endif.
*3. Create binary relation
l_object-objkey = i_objectkey.
l_object-objtype = i_objecttype.
concatenate l_folderid l_obj_id into l_reldoc-objkey.
l_reldoc-objtype = 'MESSAGE'.
call function 'BINARY_RELATION_CREATE'
EXPORTING
obj_rolea = l_object
obj_roleb = l_reldoc
relationtype = 'URL'
EXCEPTIONS
no_model = 1
internal_error = 2
unknown = 3
others = 4.
if sy-subrc <> 0.
l_syst = syst.
perform collect_message using ot_return l_syst
'3.BinaryRelationCreate'.
append ot_return.
exit.
endif.
*4. Commit LUW
* All successful, sent success message.
clear: l_syst-msgid, l_syst-msgno.
l_syst-msgty = 'S'.
l_syst-msgv1 = 'Link created successfully'.
perform collect_message using ot_return l_syst '4. URLLinkCreated'.
append ot_return.
if i_nocommit is initial.
call function 'BAPI_TRANSACTION_COMMIT'.
endif.
ENDFUNCTION.