--PO 采购订单关闭脚本
DECLARE
l_return_code VARCHAR2(2000);
l_result BOOLEAN;
CURSOR po_close_cur IS
SELECT poh.segment1
,poll.po_header_id
,poll.po_line_id
,poll.line_location_id
FROM po_line_locations_all poll
,po_headers_all poh
,po_lines_all pol
WHERE poll.po_header_id = poh.po_header_id
AND poll.po_line_id = pol.po_line_id
AND pol.po_header_id = poh.po_header_id
AND upper(poh.authorization_status) = 'APPROVED'
AND upper(poll.closed_code) = 'CLOSED FOR RECEIVING'
AND (pol.unit_price = 0 OR poh.quantity_billed - poh.quantity >= 0)
AND poh.segment1 BETWEEN p_po_from AND p_po_to;
BEGIN
FOR po_close_rec IN po_close_cur LOOP
l_result := po_actions.close_po(p_docid => po_close_rec.po_header_id
,p_doctyp => 'PO'
,p_docsubtyp => 'STANDARD'
,p_lineid => po_close_rec.po_line_id
,p_shipid => po_close_rec.line_location_id
,p_action => 'CLOSE'
,p_reason => p_reason_desc
,p_calling_mode => 'PO'
,p_conc_flag => 'N'
,p_return_code => l_return_code
,p_auto_close => 'N'
,p_action_date => SYSDATE
,p_origin_doc_id => NULL);
IF l_result THEN
fnd_file.put_line(fnd_file.output
,po_close_rec.segment1 || ' is Closed. ');
ELSE
fnd_file.put_line(fnd_file.output
,po_close_rec.segment1 || ' is not Closed. ');
END IF;
END LOOP;
END;