Description: EDI Invoice Outbound Program Report ZVGTRB_EDI_INVOICES_INT no standard page heading
line-size 132
line-count 60
message-id /eur/v_cs_intf.
----------------------------------------------------------------------
- DATA DECLARATIONS
----------------------------------------------------------------------
include zvgtrb_edi_common_top.
tables: EDI_DC40.
data:flg_do_not_send type c.
----------------------------------------------------------------------
- SELECTION SCREEN
----------------------------------------------------------------------
selection-screen begin of block b1 with frame title text-s01.
parameters:
p_bukrs like /eur/xeintid-bukrs obligatory, "Company Code
p_intid like /eur/xeintid-intid "Interface ID
default 'CSINV01',
p_rcvprn like /eur/xeintid-parnum
obligatory, "EDI Partner
p_infile like draw-filep. "Variable filename
select-options:
s_CREDAT for EDI_DC40-credat.
selection-screen end of block b1.
selection-screen begin of block b2 with frame title text-s99.
parameters:
p_kunnr like kna1-kunnr obligatory. "SAP Customer
selection-screen end of block b2.
selection-screen begin of block b3 with frame title text-s03.
parameters:
p_runnml radiobutton group 0001, "Run mode - Normal
p_runrer radiobutton group 0001. "Run mode - Rerun
selection-screen end of block b3.
selection-screen begin of block b4 with frame title text-s04.
parameters:
p_errrej radiobutton group 0002, "Errors - Reject
p_errtra radiobutton group 0002. "Errors - Transmit
selection-screen end of block b4.
----------------------------------------------------------------------
- AT SELECTION SCREEN
*----------------------------------------------------------------------
at selection-screen output.
- loop at screen.
- if screen-name = 'P_INTID'.
- screen-input = '0'.
- modify screen.
- endif.
- endloop.
----------------------------------------------------------------------
- START OF SELECTION
*----------------------------------------------------------------------
start-of-selection.
perform interface_start.
perform extract_idoc_controls.
loop at i_edidc.
perform extract_idoc_segments.
clear: v_error.
loop at i_edid4.
perform process_idoc_segments.
endloop.
perform update_idoc_status.
endloop.
perform write_output_file.
perform output_report.
perform interface_finish.
*Begin of MOD-001
- perform transfer_to_destination.
*End of MOD-001
end-of-selection.
----------------------------------------------------------------------
- SUBROUTINE DECLARATIONS
----------------------------------------------------------------------
*----------------------------------------------------------------------
- Form INTERFACE_START
*---------------------------------------------------------------------- - Performs interface validations and save the interface status
- record
*----------------------------------------------------------------------
form interface_start.
call function '/eur/X_INTERFACE_START_PROC'
EXPORTING
bukrs = p_bukrs
intid = p_intid
parnum = p_rcvprn
input_filename = p_infile
IMPORTING
xeintid = v_xeintid
physical_filename = v_filename
header = v_header
EXCEPTIONS
invalid_interface = 1
last_run_executing = 2
file_not_found = 3
no_header_record = 4
no_footer_record = 5
incorrect_no_records = 6
incorrect_sequence = 7
cannot_open_file = 8
incorrect_partner = 9
others = 10.
if sy-subrc <> 0.
- Begin of MOD-003
- message a104 with 'INTERFACE_START_PROC' sy-subrc.
sy-msgty = 'A'.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. - End of MOD-003
endif.
- Prepare output file with header record
check: sy-subrc eq 0.
append v_header to i_file_all.
endform. " INTERFACE_START
*----------------------------------------------------------------------
- Form EXTRACT_IDOC_CONTROLS
*---------------------------------------------------------------------- - Selects required IDocs from EDIDC
*----------------------------------------------------------------------
form extract_idoc_controls.
- Local Variables
data: l_edidc like edidc.
clear: v_errct.
free: i_edidc,
i_menge_stats, i_summe_stats,
i_menge_error, i_summe_error.
case 'X'.
when p_runnml.
select * from edidc
into l_edidc
where rcvprn = p_rcvprn
and mestyp = c_mestyp
*
INSERT
and ( status = c_ready or
status = c_transerr ).
*{ INSERT R10K932168 1
*
DELETE
*} INSERT
clear: i_edidc.
move-corresponding l_edidc to i_edidc.
append i_edidc.
endselect.
when p_runrer.
select * from edidc
into l_edidc
where rcvprn = p_rcvprn
and mestyp = c_mestyp
*
INSERT
and status = c_transerr.
clear: i_edidc.
move-corresponding l_edidc to i_edidc.
append i_edidc.
endselect.
endcase.
describe table i_edidc lines v_invct.
- Extract translation requirements as to which fields are required to
- be translated and which are not
perform extract_translation_reqmnts.
- Extract the dynamic restriction rules "++MOD-005
perform extract_dynamic_restric_rule. "++MOD-005
- Begin of MOD-006
perform reduce_segments. - End of MOD-006
endform. " EXTRACT_IDOC_CONTROLS
*----------------------------------------------------------------------
- Form EXTRACT_IDOC_SEGMENTS
*---------------------------------------------------------------------- - Reads IDoc segments
*----------------------------------------------------------------------
form extract_idoc_segments.
- Local Variables
data: l_edid4 like edid4.
- Select IDoc segments
refresh: i_edid4.
select * from edid4
into l_edid4
where docnum = i_edidc-docnum.
move-corresponding l_edid4 to i_edid4.
append i_edid4.
clear i_edid4.
endselect.
- Prepare output file with the IDoc segment
free: i_file_one.
move: 'CONTROL' to i_file_one-rectype,
i_edidc to i_file_one-recdetl.
append i_file_one.
endform. " EXTRACT_IDOC_SEGMENTS
*----------------------------------------------------------------------
- Form PROCESS_IDOC_SEGMENTS
*---------------------------------------------------------------------- - Performs all required processing on IDoc segments
*----------------------------------------------------------------------
form process_idoc_segments.
- Local variables
data: l_e1edp01_hold like edi_dd40,
l_p01_flg(1) type c.
clear: v_e1edp01, v_e1eds01, v_e1edka1.
- Translate individual segments
case i_edid4-segnam.
when 'E1EDK01'.
move: i_edid4-sdata to v_e1edk01.
move: v_e1edk01-belnr to v_vbeln.
perform extract_invoice_header.
when 'E1EDKA1'.
move: i_edid4-sdata to v_e1edka1.
perform translate_partn_field using v_e1edka1-parvw
v_e1edka1-partn
changing v_e1edka1-lifnr
v_error.
when 'E1EDP01'.
move: sy-tabix to v_tabix,
i_edid4 to l_e1edp01_hold,
i_edid4-sdata to v_e1edp01,
v_e1edp01-posex to v_posnr,
'Y' to l_p01_flg.
perform extract_invoice_item.
perform translate_matnr_field using v_tabix
changing v_error.
perform translate_ean11_field using v_tabix
changing v_error.
when 'E1EDPA1'.
move: i_edid4-sdata to v_e1edpa1.
perform translate_partn_field using v_e1edpa1-parvw
v_e1edpa1-partn
changing v_e1edpa1-lifnr
v_error.
endcase.
- Prepare output file for this individual IDoc
clear: i_file_one.
if not l_p01_flg is initial.
- Pay special attention to the E1EDP01 segment. Looping logic to
- insert any E1EDP19 rows may have disrupted the content of the
- i_edid4 work area. This ensures that the proper E1EDP01 segment
- is used when populating the file.
clear l_p01_flg.
move l_e1edp01_hold to i_file_one-recdetl.
else.
move i_edid4 to i_file_one-recdetl.
endif.
move: 'DATA' to i_file_one-rectype.
- Begin of MOD-006
- Note that the test has SPECIFICALLY been placed in this position so
- as not to disturb the program processing above
perform if_to_send.
check flg_do_not_send is initial. - End of MOD-006
append i_file_one.
endform. " PROCESS_IDOC_SEGMENTS
*----------------------------------------------------------------------
- Form EXTRACT_TRANSLATION_REQMNTS
*---------------------------------------------------------------------- - Determines if the EDI Partner has specific translation
- requirements. If a row exists for the EDI Partner, then
- special translation requirements exist.
*----------------------------------------------------------------------
form extract_translation_reqmnts.
clear: /eur/veivcfg.
select single * from /eur/veivcfg
where parnum eq p_rcvprn.
endform. " EXTRACT_TRANSLATION_REQMNTS
*----------------------------------------------------------------------
- Form TRANSLATE_PARTN_FIELD
*---------------------------------------------------------------------- - Performs translation on the PARTN field if required
*---------------------------------------------------------------------- - --> %PARVW Partner Type
- --> %PARTN Partner Number
- <-- %LIFNR Translated Customer field
*---------------------------------------------------------------------- - --> %ERROR Sets flag for translation error
*----------------------------------------------------------------------
form translate_partn_field using %parvw %partn
changing %lifnr %error.
data: v_partn like edpar-inpnr,
v_parvw like edpar-parvw,
v_lifnr like edpar-expnr.
check: %lifnr is initial.
check: /eur/veivcfg-kunnr is initial.
check: %parvw = 'AG' or
%parvw = 'RE' or
%parvw = 'RG' or
%parvw = 'WE'.
move: %parvw to v_parvw,
%partn to v_partn.
call function 'SD_INT_TO_EXT_PARTNER_NUMBER'
EXPORTING
customer_number = p_kunnr
internal_partner_number = v_partn
partner_role = v_parvw
IMPORTING
external_partner_number = v_lifnr
EXCEPTIONS
partner_not_found = 1
others = 2.
case sy-subrc.
when 0.
move: v_lifnr to %lifnr.
when others.
move: 'X' to %error.
perform error_message using i_edidc-docnum '/eur/V_CS_INTF'
'E' '101'
i_edidc-rcvprn v_parvw
v_partn space.
endcase.
endform. " TRANSLATE_PARTN_FIELD
*----------------------------------------------------------------------
- Form TRANSLATE_MATNR_FIELD
*---------------------------------------------------------------------- - Performs translation on the MATNR field if required
*---------------------------------------------------------------------- - --> %FRMIX Current table entry for IDoc segment
- --> %ERROR Sets flag for translation error
*----------------------------------------------------------------------
form translate_matnr_field using value(%frmix)
changing %error.
data: l_sreqd(01) type c,
l_edid4 type edi_dd40,
l_insix type sy-tabix,
l_kdmat type knmt-kdmat.
check: /eur/veivcfg-kdmat is initial.
perform check_translation_exists using '001'
changing %frmix l_sreqd
l_insix l_edid4.
check: l_sreqd eq 'X'.
select single kdmat from knmt
into l_kdmat
where vkorg eq vbrk-vkorg
and vtweg eq vbrk-vtweg
and kunnr eq vbrk-kunag
and matnr eq vbrp-matnr.
case sy-subrc.
- If a customer material is found, use it. Otherwise continue
- processing as this qualifier is not mandatory.
when 0.
perform insert_e1edp19 using '001' l_kdmat
l_insix l_edid4.
endcase.
endform. " TRANSLATE_MATNR_FIELD
*----------------------------------------------------------------------
- Form CHECK_TRANSLATION_EXISTS
*---------------------------------------------------------------------- - Determines whether a translation for E1EDP19 segment already
- exists in the IDoc
*---------------------------------------------------------------------- - --> %QUALF E1EDP19 segment identifier
- --> %TABIX Current table entry for IDoc segment
- <-- %SREQD Translation segment required
*----------------------------------------------------------------------
form check_translation_exists using %qualf
changing %frmix %sreqd %insix %edid4.
add: 1 to %frmix.
loop at i_edid4 from %frmix.
- Segment found, no need to add
if i_edid4-segnam = 'E1EDP19' and
i_edid4-sdata+00(03) = %qualf.
exit.
endif.
- Inserting after last E1EDP03 segment. Assumed will always have
- at least a 'Date created' E1EDP03 segment
if i_edid4-segnam = 'E1EDP03'.
move: sy-tabix to %insix,
i_edid4 to %edid4.
add: 1 to %insix.
endif.
- Reached next line item (or Summary segment) and segment not found,
- therefore should be created
if i_edid4-segnam = 'E1EDP01' or
i_edid4-segnam = 'E1EDS01'.
move: 'X' to %sreqd.
exit.
endif.
endloop.
endform. " CHECK_MATNR_TRANSLATION_EXISTS
*----------------------------------------------------------------------
- Form TRANSLATE_EAN11_FIELD
*---------------------------------------------------------------------- - Performs translation on the EAN11 field if required
*---------------------------------------------------------------------- - --> %FRMIX Current table entry for IDoc segment
- --> %ERROR Sets flag for translation error
*----------------------------------------------------------------------
form translate_ean11_field using value(%frmix)
changing %error.
data: l_sreqd(01) type c,
l_edid4 type edi_dd40,
l_insix type sy-tabix,
l_ean11 type marm-ean11.
check: /eur/veivcfg-gtin is initial.
perform check_translation_exists using '003'
changing %frmix l_sreqd
l_insix l_edid4.
check: l_sreqd eq 'X'.
select single ean11 from marm
into l_ean11
where matnr eq vbrp-matnr
and meinh eq vbrp-vrkme.
if l_ean11 is initial.
sy-subrc = 8.
endif.
case sy-subrc.
when 0.
perform insert_e1edp19 using '003' l_ean11
l_insix l_edid4.
when others.
- message e103.
move: 'X' to %error.
perform error_message using i_edidc-docnum '/eur/V_CS_INTF'
'E' '103'
vbrp-matnr vbrp-vrkme
space space.
endcase.
endform. " TRANSLATE_EAN11_FIELD
*----------------------------------------------------------------------
- Form INSERT_E1EDP19
*---------------------------------------------------------------------- - Inserts missing transated data records
*----------------------------------------------------------------------
form insert_e1edp19 using %qualf %idtnr %insix
%edid4 structure edi_dd40.
clear: v_e1edp19.
move: %qualf to v_e1edp19-qualf,
%idtnr to v_e1edp19-idtnr,
v_e1edp19 to %edid4-sdata,
'E1EDP19' to %edid4-segnam.
insert %edid4 into i_edid4 index %insix.
endform. " INSERT_E1EDP19
*----------------------------------------------------------------------
- Form EXTRACT_INVOICE_HEADER
*---------------------------------------------------------------------- - Reads VBRK record for Invoice
*----------------------------------------------------------------------
form extract_invoice_header.
select single * from vbrk
where vbeln = v_vbeln.
endform. " EXTRACT_INVOICE_HEADER
*----------------------------------------------------------------------
- Form EXTRACT_INVOICE_ITEM
*---------------------------------------------------------------------- - Reads VBRK record for Invoice
*----------------------------------------------------------------------
form extract_invoice_item.
select single * from vbrp
where vbeln = v_vbeln
and posnr = v_posnr.
endform. " EXTRACT_INVOICE_ITEM
*----------------------------------------------------------------------
- Form ERROR_MESSAGE
*---------------------------------------------------------------------- - Stores error message for output to the report
*---------------------------------------------------------------------- - --> %DOCNO IDoc Number
- --> %MSGID Message Class
- --> %MSGTY Message Type
- --> %MSGNO Message Number
- --> %MSGV1 Message Variable 1
- --> %MSGV2 Message Variable 2
- --> %MSGV3 Message Variable 3
- --> %MSGV4 Message Variable 4
*----------------------------------------------------------------------
form error_message using %docno %msgid %msgty %msgno
%msgv1 %msgv2 %msgv3 %msgv4.
clear: i_errors.
move: %docno to i_errors-docnum,
%msgid to i_errors-msgid,
%msgty to i_errors-msgty,
%msgno to i_errors-msgno,
%msgv1 to i_errors-msgv1,
%msgv2 to i_errors-msgv2,
%msgv3 to i_errors-msgv3,
%msgv4 to i_errors-msgv4.
append i_errors.
clear: i_bdidocstat.
move: %docno to i_bdidocstat-docnum,
%msgid to i_bdidocstat-msgid,
%msgty to i_bdidocstat-msgty,
%msgno to i_bdidocstat-msgno,
%msgv1 to i_bdidocstat-msgv1,
%msgv2 to i_bdidocstat-msgv2,
%msgv3 to i_bdidocstat-msgv3,
%msgv4 to i_bdidocstat-msgv4.
append i_bdidocstat.
endform. " ERROR_MESSAGE
*----------------------------------------------------------------------
- Form UPDATE_IDOC_STATUS
*---------------------------------------------------------------------- - If no errors have occurred, update the Idoc status to '30' if
- not already updated.
*----------------------------------------------------------------------
form update_idoc_status.
- Local Variables
data: l_lines type sy-tabix,
l_status type edidc-status,
l_edidc like edidc.
- Update counter
if v_error is initial.
add: 1 to v_invok.
else.
add: 1 to v_errct.
endif.
- Update IDoc with appropriate status
if p_errrej eq 'X' and
not ( v_error is initial ).
move: c_transerr to l_status.
else.
move: c_pass2port to l_status. - Prepare output file for individual IDoc content
- check if we need to need to download the IDOC"++MOD-005
v_no_download = ''.
if not v_restriction_rule is initial. "++MOD-005
perform (v_restriction_rule) in program
/eur/vgtrb_edi_invoices_int. "++MOD-005
endif. "++MOD-005
if v_no_download = 'X' and v_error is initial.
v_invok = v_invok - 1. "++MOD-005
v_invno = v_invno + 1. "++MOD-005
move: c_40 to l_status. "++MOD-005
elseif v_no_download = 'X' and not v_error is initial.
v_errct = v_errct - 1. "++MOD-005
v_invno = v_invno + 1. "++MOD-005
move: c_40 to l_status. "++MOD-005
else.
append lines of i_file_one to i_file_all.
endif. "++MOD-005
endif. "++MOD-005 - Update statistics tables
loop at i_edid4.
move: sy-tabix to i_edid4-segnum.
modify i_edid4.
- perform update_stats_tables. "--MOD-005.
perform update_stats_tables using l_status. "++MOD-005.
endloop.
- Update IDoc status records
loop at i_bdidocstat.
move: l_status to i_bdidocstat-status.
modify i_bdidocstat.
endloop.
- Append IDoc Interface file processed status record
if l_status eq c_pass2port.
move: i_edidc-docnum to i_bdidocstat-docnum,
l_status to i_bdidocstat-status,
'I' to i_bdidocstat-msgty,
'/eur/V_CS_INTF' to i_bdidocstat-msgid,
'106' to i_bdidocstat-msgno,
v_header-seqno to i_bdidocstat-msgv1,
v_header-begda to i_bdidocstat-msgv2,
v_header-begti to i_bdidocstat-msgv3.
append i_bdidocstat.
elseif l_status eq c_40. "++MOD-005
move: i_edidc-docnum to i_bdidocstat-docnum, "++MOD-005
l_status to i_bdidocstat-status, "++MOD-005
'I' to i_bdidocstat-msgty, "++MOD-005
'/eur/V_CS_INTF' to i_bdidocstat-msgid, "++MOD-005
'218' to i_bdidocstat-msgno, "++MOD-005
v_header-seqno to i_bdidocstat-msgv1. "++MOD-005
append i_bdidocstat. "++MOD-005
endif.
- Update IDoc status
move-corresponding i_edidc to l_edidc.
call function 'IDOC_STATUS_WRITE_TO_DATABASE'
EXPORTING
idoc_number = l_edidc-docnum
idoc_opened_flag = ' '
no_dequeue_flag = 'X'
IMPORTING
idoc_control = l_edidc
TABLES
idoc_status = i_bdidocstat
EXCEPTIONS
idoc_foreign_lock = 1
idoc_not_found = 2
idoc_status_records_empty = 3
idoc_status_invalid = 4
db_error = 5
others = 6.
if sy-subrc <> 0.
perform error_message using i_edidc-docnum '/eur/V_CS_INTF'
'E' '105'
i_edidc-docnum space
space space.
endif.
- Refresh for each IDoc
free: i_bdidocstat.
endform. " UPDATE_IDOC_STATUS
*----------------------------------------------------------------------
- Form WRITE_OUTPUT_FILE
*---------------------------------------------------------------------- - Produces the output file containing the Header record, IDoc
- content and Footer record
*----------------------------------------------------------------------
form write_output_file.
- Local variables
data: l_lngth type edisegmdef-expleng.
- Ensure error count is less than threshold, otherwise file is not sent
case 'X'.
when p_errrej.
if v_errct gt v_xeintid-err_threshold.
move: c_failure to v_status.
else.
move: c_success to v_status.
endif.
when p_errtra.
move: c_success to v_status.
endcase.
check: v_status eq c_success.
- Prepare footer record
clear: v_footer.
describe table i_file_all lines v_recct.
add 1 to v_recct.
move: 'FOOTER' to v_footer-rectyp,
v_recct to v_footer-records. - v_invct to v_footer-trans. "--MOD-005
if p_errrej eq 'X'. "++MOD-005
move v_invok to v_footer-trans. "++MOD-005
else. "++MOD-005
v_invct = v_invok + v_errct. "++MOD-005
move v_invct to v_footer-trans. "++MOD-005
endif. "++MOD-005
append v_footer to i_file_all.
- Open file for output
open dataset v_filename for output in text mode.
if sy-subrc ne 0.
message a104 with 'OPEN_FILE' sy-subrc.
endif.
- Transfer data to file
loop at i_file_all.
clear: l_lngth.
case i_file_all-rectype.
when 'HEADER'.
l_lngth = 62.
when 'CONTROL'.
l_lngth = 534.
when 'FOOTER'.
l_lngth = 59.
when others.
call function 'SEGMENT_EXTERNAL_NAME_GET'
EXPORTING
segmenttyp = i_file_all-recdetl
IMPORTING
exportlength = l_lngth.
l_lngth = l_lngth + 73.
endcase.
transfer i_file_all to v_filename length l_lngth.
endloop.
- Close file
close dataset v_filename.
endform. " WRITE_OUTPUT_FILE
*----------------------------------------------------------------------
- Form OUTPUT_REPORT
*---------------------------------------------------------------------- - Prepares the report and send to the inbox of the person
- responsible in the case of translation errors, or to spool
- if no translation errors are encountered
*----------------------------------------------------------------------
form output_report.
- Prepare report output in file format
perform prepare_output_report.
- Only send error report via SAPMail if translation errors have
- occurred - otherwise, send to spool
if v_errct gt 0.
perform send_output_report.
else.
perform write_output_report.
endif.
endform. " OUTPUT_REPORT
*----------------------------------------------------------------------
- Form PREPARE_OUTPUT_REPORT
*---------------------------------------------------------------------- - Prepares the report to be sent
*----------------------------------------------------------------------
form prepare_output_report.
data: l_uzeit(08) type c,
l_datum(10) type c,
l_summe(24) type c,
l_rtext(54) type c,
l_summe_err(24) type c,
l_stat_text(10) type c.
free: i_report.
write: sy-uzeit to l_uzeit.
- Headings
write: sy-datum to l_datum.
perform report_line using text-h01 6 l_datum 68 sy-uname.
perform report_line using text-h02 6 l_uzeit space space.
perform report_line using space space space space space.
- Interface Details
perform report_line using text-h03 16 p_bukrs space space.
move: p_intid to l_rtext+00(10),
'-' to l_rtext+11(01),
v_xeintid-intdesc to l_rtext+13.
perform report_line using text-h04 16 l_rtext space space.
perform retrieve_kunnr_name using p_rcvprn l_rtext.
perform report_line using text-h05 16 l_rtext space space.
perform report_line using space space space space space.
- Interface Status
case v_status.
when c_failure.
move: c_fail_text to l_stat_text.
when c_success.
move: c_succ_text to l_stat_text.
endcase.
write: v_header-begda to l_datum.
perform report_line using text-h09 16 l_stat_text 71 v_invct.
perform report_line using text-h11 16 v_header-seqno 71 v_invok.
perform report_line using text-h12 16 l_datum 71 v_errct.
perform report_line using text-h17 space space 71 v_invno.
"++MOD-005
perform report_line using space space space space space.
- IDoc Statistics
loop at i_menge_stats.
if sy-tabix eq 1.
perform report_line using text-h10 29 i_menge_stats-menge
46 i_menge_stats-menee.
else.
perform report_line using space 29 i_menge_stats-menge
46 i_menge_stats-menee.
endif.
endloop.
loop at i_menge_error.
if sy-tabix eq 1.
perform report_line using text-h14 29 i_menge_error-menge
46 i_menge_error-menee.
else.
perform report_line using space 29 i_menge_error-menge
46 i_menge_error-menee.
endif.
endloop.
loop at i_menge_nodw. "++MOD-005
if sy-tabix eq 1.
perform report_line using text-h18 29 i_menge_nodw-menge
46 i_menge_nodw-menee.
"++MOD-005
else.
perform report_line using space 29 i_menge_nodw-menge
46 i_menge_nodw-menee.
"++MOD-005
endif.
endloop.
perform report_line using space space space space space.
loop at i_summe_stats.
if sy-tabix eq 1.
perform report_line using text-h08 24 i_summe_stats-summe
46 i_summe_stats-waerq.
else.
perform report_line using space 24 i_summe_stats-summe
46 i_summe_stats-waerq.
endif.
endloop.
loop at i_summe_error.
if sy-tabix eq 1.
perform report_line using text-h13 24 i_summe_error-summe
46 i_summe_error-waerq.
else.
perform report_line using space 24 i_summe_error-summe
46 i_summe_error-waerq.
endif.
endloop.
loop at i_summe_nodw.
if sy-tabix eq 1.
perform report_line using text-h19 24 i_summe_nodw-summe
46 i_summe_nodw-waerq.
else.
perform report_line using space 24 i_summe_nodw-summe
46 i_summe_nodw-waerq.
endif.
endloop.
perform report_line using space space space space space.
- Errors
loop at i_errors.
at first.
perform report_line using text-h06 space space
space space.
perform report_line using text-h07 space space
space space.
endat.
call function 'WRITE_MESSAGE'
EXPORTING
msgid = i_errors-msgid
msgno = i_errors-msgno
msgty = i_errors-msgty
msgv1 = i_errors-msgv1
msgv2 = i_errors-msgv2
msgv3 = i_errors-msgv3
msgv4 = i_errors-msgv4
msgv5 = space
IMPORTING
messg = v_error_msg.
perform report_line using space 1 i_errors-docnum
20 v_error_msg-msgtx.
endloop.
endform. " PREPARE_OUTPUT_REPORT
*----------------------------------------------------------------------
- Form REPORT_LINE
*---------------------------------------------------------------------- - Formats report line for output
*---------------------------------------------------------------------- - --> %HEADR Heading
- --> %POSN1 Position 1 for field output
- --> %FVAL1 Field Value 1 for output
- --> %POSN2 Position 2 for field output
- --> %FVAL2 Field Value 2 for output
*----------------------------------------------------------------------
form report_line using %headr %posn1 %fval1 %posn2 %fval2.
data: l_strln type i,
l_rline type solisti1-line,
l_fchar type solisti1-line.
- Line template
clear: l_rline.
if not %headr is initial.
move: %headr to l_rline.
endif.
- Field 1 at Position 1
describe field %fval1 output-length l_strln.
if not %fval1 is initial.
move: %fval1 to l_rline+%posn1(l_strln).
endif.
- Field 2 at Position 2
describe field %fval2 output-length l_strln.
if not %fval2 is initial.
move: %fval2 to l_rline+%posn2(l_strln).
endif.
append: l_rline to i_report.
endform. " REPORT_LINE
*----------------------------------------------------------------------
- Form RETRIEVE_KUNNR_NAME
*---------------------------------------------------------------------- - Retrieves the customer name
*---------------------------------------------------------------------- - --> %KUNNR Customer Number
- <-- %NAME1 Retrieved Name
*----------------------------------------------------------------------
form retrieve_kunnr_name using %kunnr
changing %name1.
clear: %name1.
move: %kunnr to %name1+00(10),
'-' to %name1+11(01).
clear: kna1.
select single name1 from kna1
into %name1+13(35).
endform. " RETRIEVE_KUNNR_NAME
*----------------------------------------------------------------------
- Form SEND_OUTPUT_REPORT
*---------------------------------------------------------------------- - Prepares the report and send to the inbox of the person
- responsible
*----------------------------------------------------------------------
form send_output_report.
data: l_obj_hd_change type sodocchgi1,
l_receivers type somlreci1,
l_objcont_tab type standard table of solisti1,
l_receivers_tab type standard table of somlreci1.
- SAPMail report header
l_obj_hd_change-obj_langu = sy-langu.
l_obj_hd_change-obj_descr = text-h20.
l_obj_hd_change-sensitivty = 'F'.
- Notify Business Agent via SAPMail if translation errors
move: c_express to l_receivers-express. - Begin of MOD-004
- 'B' to l_receivers-rec_type,
- v_xeintid-bus_agent to l_receivers-receiver.
case v_xeintid-bus_agent_type.
when c_user.
move: 'B' to l_receivers-rec_type,
v_xeintid-bus_agent to l_receivers-receiver.
when c_org_unit or c_job.
move: 'H' to l_receivers-rec_type,
v_xeintid-bus_agent_type
to l_receivers-receiver+0(02),
v_xeintid-bus_agent to l_receivers-receiver+2.
when c_position.
move: 'G' to l_receivers-rec_type,
v_xeintid-bus_agent_type
to l_receivers-receiver+0(02),
v_xeintid-bus_agent to l_receivers-receiver+2.
endcase.
- End of MOD-004
append l_receivers to l_receivers_tab.
- Notifiy ISIT Agent via SAPMail if File not produced
if v_status eq c_failure. - Begin of MOD-004
- move: v_xeintid-is_agent to l_receivers-receiver.
case v_xeintid-is_agent_type.
when c_user.
move: 'B' to l_receivers-rec_type,
v_xeintid-is_agent to l_receivers-receiver.
when c_org_unit or c_job.
move: 'H' to l_receivers-rec_type,
v_xeintid-is_agent_type
to l_receivers-receiver+0(02),
v_xeintid-is_agent to l_receivers-receiver+2.
when c_position.
move: 'G' to l_receivers-rec_type,
v_xeintid-is_agent_type
to l_receivers-receiver+0(02),
v_xeintid-is_agent to l_receivers-receiver+2.
endcase.
- End of MOD-004
append l_receivers to l_receivers_tab.
endif.
- Populate mail content with return code
append lines of i_report to l_objcont_tab.
- Begin of MOD-003
- Clear error message fields so residual errors are not displayed
clear: sy-msgid, sy-msgty, sy-msgno,
sy-msgv1, sy-msgv2, sy-msgv3, sy-msgv4. - End of MOD-003
- Send mail
call function 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_data = l_obj_hd_change
TABLES
object_content = l_objcont_tab
receivers = l_receivers_tab
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
others = 8.
if sy-subrc <> 0.
message w002.
endif.
endform. " SEND_OUTPUT_REPORT
*----------------------------------------------------------------------
- Form WRITE_OUTPUT_REPORT
*---------------------------------------------------------------------- - Writes the report to spool if no translation errors have
- occurred
*----------------------------------------------------------------------
form write_output_report.
loop at i_report.
if i_report-line is initial.
skip 1.
endif.
write: / i_report-line.
endloop.
endform. " WRITE_OUTPUT_REPORT
----------------------------------------------------------------------
- Form UPDATE_STATS_TABLES
---------------------------------------------------------------------- - Updates the error tables accordingly
----------------------------------------------------------------------
form update_stats_tables using l_status.
case i_edid4-segnam.
when 'E1EDP01'.
move: i_edid4-sdata to v_e1edp01.
check: not v_e1edp01-menee is initial.
clear: i_menge_stats.
move: v_e1edp01-menee to i_menge_stats-menee,
v_e1edp01-menge to i_menge_stats-menge.
collect i_menge_stats.
- if not v_error is initial. "--MOD-005
if l_status eq c_transerr. "++MOD-005
clear: i_menge_error.
move: v_e1edp01-menee to i_menge_error-menee,
v_e1edp01-menge to i_menge_error-menge.
collect i_menge_error.
elseif l_status eq c_40. "++MOD-005
clear: i_menge_nodw. "++MOD-005
move: v_e1edp01-menee to i_menge_nodw-menee, "++MOD-005
v_e1edp01-menge to i_menge_nodw-menge. "++MOD-005
collect i_menge_nodw. "++MOD-005
endif.
when 'E1EDS01'.
move: i_edid4-sdata to v_e1eds01.
check: v_e1eds01-sumid = '011'.
check: not v_e1eds01-waerq is initial.
clear: i_summe_stats.
move: v_e1eds01-waerq to i_summe_stats-waerq,
v_e1eds01-summe to i_summe_stats-summe.
collect i_summe_stats.
- if not v_error is initial. "--MOD-005
if l_status eq c_transerr. "++MOD-005
clear: i_summe_error.
move: v_e1eds01-waerq to i_summe_error-waerq,
v_e1eds01-summe to i_summe_error-summe.
collect i_summe_error.
elseif l_status eq c_40. "++MOD-005
clear: i_summe_nodw. "++MOD-005
move: v_e1eds01-waerq to i_summe_nodw-waerq, "++MOD-005
v_e1eds01-summe to i_summe_nodw-summe. "++MOD-005
collect i_summe_nodw.
endif.
endcase.
endform. " UPDATE_STATS_TABLES
*----------------------------------------------------------------------
- Form INTERFACE_FINISH
*---------------------------------------------------------------------- - Saves the updated interface status record
*----------------------------------------------------------------------
form interface_finish.
call function '/eur/X_INTERFACE_END_PROC'
exporting
header = v_header
status = v_status
recct = v_recct
trans = v_invct
errct = v_errct
exceptions
invalid_interface = 1
last_run_executing = 2
file_not_found = 3
- Begin of MOD-003
- others = 4.
status_invalid = 4
others = 10. - End of MOD-003
if sy-subrc <> 0.
- Begin of MOD-003
- message a104 with 'INTERFACE_END_PROC' sy-subrc.
sy-msgty = 'A'.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. - End of MOD-003
endif.
endform. " INTERFACE_FINISH
*Begin of MOD-001
*----------------------------------------------------------------------
- Form TRANSFER_TO_DESTINATION
---------------------------------------------------------------------- - Transfer file to destination
----------------------------------------------------------------------
*orm transfer_to_destination.
- data: l_cmd(500) type c,
- l_path type draw-filep, "Filename + extension
- l_file type draw-filep. "Pathname
- Extract pure file name
- call function 'CV120_SPLIT_PATH'
- exporting
- pf_path = v_filename
- importing
- pfx_path = l_path
- pfx_file = l_file.
- if sy-subrc <> 0.
- message a113 with sy-subrc.
- endif.
- l_cmd = text-001.
- concatenate: l_cmd text-002
- l_file+00(23) into l_cmd separated by space,
- l_cmd text-003 sy-sysid into l_cmd separated by space,
- l_cmd text-004 l_path into l_cmd separated by space.
- Call remote function
- call function 'RFC_REMOTE_EXEC'
- destination v_xeintid-destination
- exporting command = l_cmd
- exceptions communication_failure = 1 "MESSAGE MESS
- system_failure = 2 "MESSAGE MESS
- others = 4.
*ndform. " TRANSFER_TO_DESTINATION
*----------------------------------------------------------------------
- Form extract_dynamic_restric_rule
*---------------------------------------------------------------------- - In this form we will download an optional rule which will allow
- us to restrict download of certain IDOCs
*----------------------------------------------------------------------
form extract_dynamic_restric_rule.
select single proced from /eur/veivrul
into v_restriction_rule
where parnum eq p_rcvprn.
endform. " extract_dynamic_restric_rule
*--------------------------------------------------------------------
- Form restrict_partner_cheinvoic1
*-------------------------------------------------------------------- - This form will check if the invoices for this partner needs to
- be downloaded. This needs to be implemented as implementation
- on output determinaion level would have an impact on billing
*********************************************************************
form restrict_partner_cheinvoic1.
constants: c_e1edp01 like edid4-segnam value 'E1EDP01'.
constants: c_e1edp01_01_edi like edid4-segnam value
'/eur/E1EDP01_01_EDI'.
data: l_e1edp01 like e1edp01.
data: l_werks like e1edp01-werks.
data: l_e1edp011 like /eur/e1edp01_01_edi.
data: l_mvgr2 like /glb/rchtsmvgr2-mvgr2.
- check plant criteria
loop at i_edid4 where segnam eq c_e1edp01.
move i_edid4-sdata to l_e1edp01.
if not l_e1edp01-werks is initial.
select single werks from /glb/rchtswerks
into l_werks
where werks eq l_e1edp01-werks.
if sy-subrc ne 0.
v_no_download = 'X'.
else.
clear v_no_download.
exit.
endif.
endif.
endloop.
check v_no_download = 'X'.
*check material group 2 criteria
loop at i_edid4 where segnam eq c_e1edp01_01_edi.
move i_edid4-sdata to l_e1edp011.
if not l_e1edp011-mvgr2 is initial.
select single mvgr2 from /glb/rchtsmvgr2
into l_mvgr2
where mvgr2 eq l_e1edp011-mvgr2.
if sy-subrc ne 0.
v_no_download = 'X'.
else.
clear v_no_download.
exit.
endif.
endif.
endloop.
endform. "restrict_partner_cheinvoic1
- Begin of MOD-006
&---------------------------------------------------------------------
*& Form reduce_segments
&--------------------------------------------------------------------- - Reduce the segments not to be downloaded
----------------------------------------------------------------------
form reduce_segments.
*Get segments to be reduced.
select segnam
qualifier
from /eur/rch_reds into table i_reduce_segment where
bukrs = p_bukrs and
parnum = p_rcvprn and
intid = p_intid.
check: sy-subrc = 0.
- Need this Function Module to read all
call function 'IDOCTYPE_READ_COMPLETE'
EXPORTING
pi_idoctyp = c_idoc_type
pi_cimtyp = c_idoc_ext
TABLES
pt_segments = i_idoc_struct
EXCEPTIONS
object_unknown = 1
segment_unknown = 2
relation_not_found = 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.
else.
perform prepair_reduce_segments.
endif.
endform. " reduce_segments
&---------------------------------------------------------------------
*& Form prepair_reduce_segments
&---------------------------------------------------------------------
- Get all the segments to be removed from downloading.
----------------------------------------------------------------------
form prepair_reduce_segments.
data: i_reduce_segment1 type standard table of ty_reduce_segment
initial size 0 with header line.
data: w_idoc_struct type edi_iapi11.
data: w_segment_struct type ledid_segment_struct.
data: l_hlevel type i.
data: l_idoc_struct_tabix type sytabix.
data: l_got_it type c.
data: l_segtyp type edisegmhd-segtyp.
loop at i_reduce_segment.
- Get the Hlevel for the given segment
read table i_idoc_struct into w_idoc_struct
with key segmenttyp = i_reduce_segment-segnam.
check: sy-subrc = 0.
l_idoc_struct_tabix = sy-tabix.
l_hlevel = w_idoc_struct-hlevel.
- When there is a QUALIFIER for this segment; set the qualifier_flag
if not w_idoc_struct-qualifier is initial.
i_reduce_segment-qualifier_flag = c_true. - Get the Qualifier length
call function 'IDOC_COMPLETE_SEGMENT_READ'
EXPORTING
segtyp = i_reduce_segment-segnam
TABLES
segment = i_segments
segment_struct = i_segment_struct
EXCEPTIONS
segment_unknown = 1
segment_structure_unknown = 2
segment_not_in_release = 3
segment_inconsistent = 4
others = 5.
if sy-subrc <> 0.
- MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
- WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
read table i_segment_struct into w_segment_struct
with key segment_type = i_reduce_segment-segnam.
if sy-subrc = 0.
i_reduce_segment-offset = w_segment_struct-field_attrib-intlen.
endif.
modify i_reduce_segment.
endif.
- Check the HLEVEL of the next segment in i_idoc_struct
do.
l_idoc_struct_tabix = l_idoc_struct_tabix + 1.
read table i_idoc_struct into w_idoc_struct
index l_idoc_struct_tabix.
if sy-subrc ne 0.
exit.
endif.
if w_idoc_struct-hlevel <= l_hlevel.
exit.
else. - When there is a QUALIFIER for this segment; set the
- qualifier_flag
clear: i_reduce_segment,
i_reduce_segment1.
if not w_idoc_struct-qualifier is initial.
i_reduce_segment-qualifier_flag = c_true. - Get the Qualifier length.
move: w_idoc_struct-segmenttyp to l_segtyp.
call function 'IDOC_COMPLETE_SEGMENT_READ'
EXPORTING
segtyp = l_segtyp
TABLES
segment = i_segments
segment_struct = i_segment_struct
EXCEPTIONS
segment_unknown = 1
segment_structure_unknown = 2
segment_not_in_release = 3
segment_inconsistent = 4
others = 5.
if sy-subrc <> 0.
- MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
- WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
read table i_segment_struct into w_segment_struct
with key segment_type = w_idoc_struct-segmenttyp.
if sy-subrc = 0.
i_reduce_segment-offset =
w_segment_struct-field_attrib-intlen.
endif.
endif.
i_reduce_segment = w_idoc_struct-segmenttyp.
i_reduce_segment1 = i_reduce_segment.
append i_reduce_segment1.
endif.
enddo.
endloop.
append lines of i_reduce_segment1 to i_reduce_segment.
endform. " prepair_reduce_segments
&---------------------------------------------------------------------
*& Form if_to_send
&---------------------------------------------------------------------
- text
----------------------------------------------------------------------
form if_to_send.
data:l_str(10) type c.
clear flg_do_not_send.
- Read table ( any record for that segment ) to get qualifier
- length
read table i_reduce_segment with key segnam = i_edid4-segnam.
check: sy-subrc = 0.
if not i_reduce_segment-qualifier is initial.
if i_reduce_segment-qualifier_flag = c_true.
l_str = i_edid4-sdata+0(i_reduce_segment-offset).
- if l_str = i_reduce_segment-qualifier.
- Now that qualifier length is determined, need to check
- whether entry exists for that qualifier. If so, do not send
read table i_reduce_segment with key segnam = i_edid4-segnam
qualifier = l_str.
if sy-subrc eq 0.
flg_do_not_send = c_true.
endif.
else.
flg_do_not_send = c_true.
endif.
else.
flg_do_not_send = c_true.
endif.
endform. " if_to_send
- End of MOD-006
*Messages
*----------------------------------------------------------
*
- Message class: /EUR/V_CS_INTF
*002
*104