I have been searching and searching trying to figure out how to do this, but I can't seem to find the answer...
I have a list of delivery names saved in a custom table. Now what I want to assign all those deliveries to a trip, and ship confirm the trip.
Right now I have the attached code working. It will successfully create a unique trip for each delivery, and ship confirm each trip. But I really need to be able to create only ONE trip for all deliveries. Please help!
function f_download_order_ship_confirm return boolean
is
cursor c_deliveries is
select *
from tup_mexico_dlvrs_to_reconcile
where nvl(attribute1,'0') != 'SHIP_CONFIRMED'
order by delivery_name;
p_ship_conf_status varchar2(5000);
x_msg_data varchar2(5000);
p_api_version_number number;
init_msg_list varchar2(30);
x_msg_count number;
x_msg_details varchar2(32000);
x_msg_summary varchar2(32000);
p_validation_level number;
p_commit varchar2(30);
x_return_status varchar2(15);
source_code varchar2(15);
changed_attributes wsh_delivery_details_pub.changedattributetabtype;
p_action_code varchar2(15);
p_delivery_id number;
p_delivery_name varchar2(30);
p_asg_trip_id number;
p_asg_trip_name varchar2(30);
p_asg_pickup_stop_id number;
p_asg_pickup_loc_id number;
p_asg_pickup_loc_code varchar2(30);
p_asg_pickup_arr_date date;
p_asg_pickup_dep_date date;
p_asg_dropoff_stop_id number;
p_asg_dropoff_loc_id number;
p_asg_dropoff_loc_code varchar2(30);
p_asg_dropoff_arr_date date;
p_asg_dropoff_dep_date date;
p_sc_action_flag varchar2(10);
p_sc_close_trip_flag varchar2(10);
p_defer_iface varchar2(10);
p_sc_create_bol_flag varchar2(10);
p_sc_stage_del_flag varchar2(10);
p_sc_trip_ship_method varchar2(30);
p_sc_actual_dep_date varchar2(30);
p_sc_report_set_id number;
p_sc_report_set_name varchar2(60);
p_wv_override_flag varchar2(10);
x_trip_id varchar2(30);
x_trip_name varchar2(30);
p_msg_data varchar2(32000);
fail_api exception;
n_cursor_count number := 0;
v_first_delivery varchar2(30);
v_last_delivery varchar2(30);
begin
x_return_status := wsh_util_core.g_ret_sts_success;
p_action_code := 'CONFIRM';
p_sc_action_flag := 'B';
p_sc_close_trip_flag := 'Y';
p_defer_iface := 'N';
for x in c_deliveries loop
wsh_deliveries_pub.delivery_action(p_api_version_number => 1.0
,p_init_msg_list => init_msg_list
,x_return_status => x_return_status
,x_msg_count => x_msg_count
,x_msg_data => p_msg_data
,p_action_code => p_action_code
,p_delivery_id => p_delivery_id
,p_delivery_name => x.delivery_name -- delivery name
,p_asg_trip_id => p_asg_trip_id
,p_asg_trip_name => p_asg_trip_name
,p_asg_pickup_stop_id => p_asg_pickup_stop_id
,p_asg_pickup_loc_id => p_asg_pickup_loc_id
,p_asg_pickup_loc_code => p_asg_pickup_loc_code
,p_asg_pickup_arr_date => p_asg_pickup_arr_date
,p_asg_pickup_dep_date => p_asg_pickup_dep_date
,p_asg_dropoff_stop_id => p_asg_dropoff_stop_id
,p_asg_dropoff_loc_id => p_asg_dropoff_loc_id
,p_asg_dropoff_loc_code => p_asg_dropoff_loc_code
,p_asg_dropoff_arr_date => p_asg_dropoff_arr_date
,p_asg_dropoff_dep_date => p_asg_dropoff_dep_date
,p_sc_action_flag => p_sc_action_flag
,p_sc_close_trip_flag => p_sc_close_trip_flag
,p_sc_create_bol_flag => p_sc_create_bol_flag
,p_sc_stage_del_flag => p_sc_stage_del_flag
,p_sc_trip_ship_method => p_sc_trip_ship_method
,p_sc_actual_dep_date => p_sc_actual_dep_date
,p_sc_report_set_id => p_sc_report_set_id
,p_sc_report_set_name => p_sc_report_set_name
,p_sc_defer_interface_flag => p_defer_iface
,p_wv_override_flag => p_wv_override_flag
,x_trip_id => x_trip_id
,x_trip_name => x_trip_name);
-- if api was not successful --
if (x_return_status <> wsh_util_core.g_ret_sts_success) then
wsh_util_core.get_messages('Y'
,x_msg_summary
,x_msg_details
,x_msg_count);
if x_msg_count > 1 then
x_msg_data := x_msg_summary || x_msg_details;
else
x_msg_data := x_msg_summary;
end if;
-- if api was successful --
else
-- mark as ship confirmed in custom table --
update tup_mexico_dlvrs_to_reconcile md
set md.attribute1 = 'SHIP_CONFIRMED'
,md.attribute5 = x_trip_id
where md.delivery_name = x.delivery_name;
end if;
end loop;
return true;
exception
when others then
return false;
end f_download_order_ship_confirm;
If you configure the Oracle EBS Shipping Execution module correctly, you can make it autocreate deliveries and assign them to open trips automatically.
Otherwise, you need to do that work yourself via the API.
The wsh_deliveries_pub public API, which you are already using, can do this if you specify the correct values for p_action_code
AUTOCREATE-TRIP ==> automatically create a trip for the delivery
ASSIGN-TRIP ==> assign a delivery to an existing trip
You'd probably want to call with "AUTOCREATE-TRIP" for the first delivery in the batch and then "ASSIGN-TRIP" for the subsequent ones.
Keep in mind the API will validate that the delivery can really be assigned to the trip you choose. There are rules. E.g., you cannot assign a delivery going to customer A to a trip that's only stopping at customer B.
Refer to Oracle's documentation for more about how to use the API with these action codes.
Related
If was ok when i create a function and add a policy in Oracle. Error happen when i want to select a table (OBJECT_NAME). It seems like error happen in the select into variable, but i dont know how to fix it (I make sure that select into 1 variable only and the same type as variable)
CREATE OR REPLACE FUNCTION TC6_NHANVIEN(P_SCHEMA VARCHAR2, P_OBJ VARCHAR2)
RETURN VARCHAR2
AS
USERCHECK VARCHAR2(100);
VAITROCHECK VARCHAR(100);
BEGIN
USERCHECK := SYS_CONTEXT('USERENV', 'SESSION_USER');
VAITROCHECK :='';
IF (USER LIKE 'NV%') THEN --i want to check a variable. Error maybe right here
SELECT VAITRO INTO VAITROCHECK
FROM SYSTEM.NHANVIEN
WHERE MANV=USER;
END IF;
IF (USERCHECK LIKE 'NV%'AND VAITROCHECK!='THANHTRA') THEN
RETURN 'MANV = '''||USERCHECK||'''';
ELSE
RETURN '1=1';
END IF;
END;
BEGIN
dbms_rls.add_policy(
OBJECT_SCHEMA => 'SYSTEM',
OBJECT_NAME => 'NHANVIEN',
POLICY_NAME => 'PC_2',
POLICY_FUNCTION => 'TC6_NHANVIEN',
STATEMENT_TYPES => 'SELECT,UPDATE',
UPDATE_CHECK => TRUE
);
END;
grant select on SYSTEM.NHANVIEN to NV001;
select * from SYSTEM.NHANVIEN --LOG IN AS NV001
I have a page with 2 date fields and a button. A dynamic action with PLSQL code that references the value from the 2 date fields is created. For some reason, the page item values does not get passed in the dynamic action. When i use constant values, the DA works without any problem, but when i reference the item values, it doesn't work. No idea why. Can somebody please help??
I have included the DA (not working) code and the DA that works.
Not working DA
DECLARE
I_VCNAME VARCHAR2(200);
I_LPARAMS PK_JRXML2PDF_REPGEN.TPARAMLIST;
I_VCDIR VARCHAR2(200);
I_VCFILENAME VARCHAR2(200);
bl BLOB;
BEGIN
I_VCNAME:='Fundraiser_Stats';
I_VCDIR := 'FUNDAMENTAL_FTP';
I_LPARAMS(1).vcName:='date_from';
I_LPARAMS(1).vcValue:=:R1_FROM_DATE;
I_LPARAMS(2).vcName:='date_to';
I_LPARAMS(2).vcValue:=:R1_TO_DATE;
I_LPARAMS(3).vcName:='fundraiser';
FOR fundraiser_name IN (SELECT DISTINCT B.FUNDRAISER fundraiser FROM WAYSACT_SRC_VW A, PLEDGE_EXT B WHERE A.PLEDGE_ID = B.PLEDGE_ID
AND A.PLEDGE_DATE BETWEEN :R1_FROM_DATE AND :R1_TO_DATE)
LOOP
I_LPARAMS(3).vcValue:= fundraiser_name.fundraiser;
I_VCFILENAME := fundraiser_name.fundraiser||'-'||to_char(sysdate,'dd-Mon-yyyy')||'.pdf';
PK_JRXML2PDF_REPGEN.PR_RUN_TO_FILE(I_VCNAME => I_VCNAME, I_LPARAMS => I_LPARAMS, I_VCDIR => I_VCDIR,I_VCFILENAME => I_VCFILENAME);
END LOOP fundraiser_name;
--APEX_APPLICATION.STOP_APEX_ENGINE;
END;
Working DA:
DECLARE
I_VCNAME VARCHAR2(200);
I_LPARAMS PK_JRXML2PDF_REPGEN.TPARAMLIST;
I_VCDIR VARCHAR2(200);
I_VCFILENAME VARCHAR2(200);
bl BLOB;
BEGIN
I_VCNAME:='Fundraiser_Stats';
I_VCDIR := 'FUNDAMENTAL_FTP';
I_LPARAMS(1).vcName:='date_from';
I_LPARAMS(1).vcValue:='02-jun-2018';
I_LPARAMS(2).vcName:='date_to';
I_LPARAMS(2).vcValue:='02-jun-2018';
I_LPARAMS(3).vcName:='fundraiser';
FOR fundraiser_name IN (SELECT DISTINCT B.FUNDRAISER fundraiser FROM WAYSACT_SRC_VW A, PLEDGE_EXT B WHERE A.PLEDGE_ID = B.PLEDGE_ID
AND A.PLEDGE_DATE BETWEEN '02-jun-2018' AND '02-jun-2018')
LOOP
I_LPARAMS(3).vcValue:= fundraiser_name.fundraiser;
I_VCFILENAME := fundraiser_name.fundraiser||'-'||to_char(sysdate,'dd-Mon-yyyy')||'.pdf';
PK_JRXML2PDF_REPGEN.PR_RUN_TO_FILE(I_VCNAME => I_VCNAME, I_LPARAMS => I_LPARAMS, I_VCDIR => I_VCDIR,I_VCFILENAME => I_VCFILENAME);
END LOOP fundraiser_name;
--APEX_APPLICATION.STOP_APEX_ENGINE;
END;
This is the "Execute PL/SQL Code" dynamic action, is it not? Within DA's "Settings" section, there's the "Items to Submit" field - put names of all items you use in that code; I've noticed
R1_FROM_DATE, R1_TO_DATE
You'll know whether there are additional ones. If so, include them into the list.
I am trying to take a ROWTYPE, RECORD, or OBJECT type and dynamically convert it to a single string representation.
I want to do this dynamically.
Update: Doing this for an OBJECT type now working thanks to Justin Cave's feedback.
Example Data:
ID | VAL
---------
1 | BOB
Desired Output:
ID=1, VAL=BOB
Error Received:
ORA-06550: line 7, column 25:
PLS-00306: wrong number or types of arguments in call to 'TO_STRING'
ORA-06550: line 7, column 4:
PL/SQL: Statement ignored
What I have so Far (Doesn't loop through columns yet.):
CREATE OR REPLACE FUNCTION to_string (
ip_anydata in out anydata --note the "out" - this is required for the "piecewise"
)
RETURN VARCHAR2
IS
lv_typecode PLS_INTEGER;
lv_anytype anytype;
BEGIN
DBMS_OUTPUT.PUT_LINE('[Expected='||dbms_types.typecode_object||', Actual='||ip_anydata.getType(lv_anytype)||']');
--Get the typecode, and the ANYTYPE
lv_typecode := ip_anydata.getType(lv_anytype);
--Check that it's really an object
IF lv_typecode = dbms_types.typecode_object
THEN
--If it is an object, find the first item
DECLARE
lv_first_attribute_typecode pls_integer;
lv_aname varchar2(32767);
lv_result pls_integer;
lv_varchar varchar2(32767);
--Variables we don't really care about, but need for function output
lv_prec pls_integer;
lv_scale pls_integer;
lv_len pls_integer;
lv_csid pls_integer;
lv_csfrm pls_integer;
lv_attr_elt_type anytype;
BEGIN
lv_first_attribute_typecode := lv_anytype.getAttrElemInfo(
pos => 1, --First attribute
prec => lv_prec,
scale => lv_scale,
len => lv_len,
csid => lv_csid,
csfrm => lv_csfrm,
attr_elt_type => lv_attr_elt_type,
aname => lv_aname
);
--Check typecode of attribute
IF lv_first_attribute_typecode = dbms_types.typecode_varchar2
THEN
--Now that we've verified the type, get the actual value.
ip_anydata.piecewise;
lv_result := ip_anydata.getVarchar2(c => lv_varchar);
--DEBUG: Print the attribute name, in case you're curious
--dbms_output.put_line('lv_aname: '||lv_aname);
RETURN lv_aname||'='||lv_varchar;
ELSE
raise_application_error(-20000, 'Unexpected 1st Attribute Typecode: '||lv_first_attribute_typecode);
END IF;
END;
ELSE
raise_application_error(-20000, 'Unexpected Typecode: '||lv_typecode);
END IF;
END;
/
Scenario#1 - Select INTO w/ ROWTYPE:
DECLARE
lv_cv dual%ROWTYPE;
lv_str VARCHAR2(32767);
BEGIN
DBMS_OUTPUT.PUT_LINE('-----------------------------');
SELECT * INTO lv_cv FROM dual WHERE ROWNUM <= 1;
DBMS_OUTPUT.PUT_LINE(to_string(lv_cv));
END;
/
Scenario#2 - FETCH INTO w/ Cursor ROWTYPE:
DECLARE
CURSOR cv_cur IS SELECT * FROM dual WHERE ROWNUM <= 1;
lv_cv cv_cur%ROWTYPE;
lv_str VARCHAR2(32767);
BEGIN
DBMS_OUTPUT.PUT_LINE('-----------------------------');
OPEN cv_cur;
FETCH cv_cur INTO lv_cv;
CLOSE cv_cur;
DBMS_OUTPUT.PUT_LINE(to_string(lv_cv));
END;
/
Scenario#3 - Regular OBJECT: (Updated)
DECLARE
lv_cv T_CODE_VAL_REC := T_CODE_VAL_REC('BOB', 5);
lv_str VARCHAR2(32767);
lv_any ANYDATA;
BEGIN
DBMS_OUTPUT.PUT_LINE('-----------------------------');
lv_any := sys.anydata.ConvertObject(lv_cv);
DBMS_OUTPUT.PUT_LINE(to_string(lv_any));
EXCEPTION WHEN OTHERS THEN
pts2_test_valitation_util.fail(999, CHR(10)||CHR(10)||'Unexpected Error:'||CHR(10)||SQLERRM||CHR(10)||DBMS_UTILITY.FORMAT_ERROR_BACKTRACE);
END;
/
I have written a package :
CREATE OR REPLACE
PACKAGE BODY NEW_HIRE_PKG
AS
PROCEDURE load_emp(
errbuf OUT VARCHAR2,
retcode OUT VARCHAR2 )
AS
CURSOR cur_person_info
IS
SELECT * FROM table_abc;
CURSOR cur_person_adr
IS
SELECT * FROM table_adr;
l_person_id NUMBER;
l_emp_num NUMBER;
lv_add_type VARCHAR2(100);
lv_address_line1 VARCHAR2(100);
BEGIN
FOR person_info_rec IN cur_address_info
LOOP
hr_employee_api.create_employee ( p_validate => FALSE,
--INPUT Parameter
P_HIRE_DATE =>person_info_rec.DATE_START,
-- output
p_employee_number => lc_employee_number, p_person_id => ln_person_id );
END LOOP ;
END;
PROCEDURE load_add(
errbuf OUT VARCHAR2,
retcode OUT VARCHAR2 )
as
ln_person_id number;
BEGIN
FOR address_info_rec IN cur_address_info
LOOP
BEGIN
hr_person_address_api.create_person_address
(p_validate => FALSE,
p_effective_date => TRUNC(SYSDATE),
p_person_id=> ln_person_id,
--output
p_address_type => lv_add_type,
p_address_line1 => lv_address_line1);
end;
end loop;
end;
end;
Now in the procedure the load_add there is a variable ln_person_id which should be the person ids generated in the procedure load_emp. I want to pass it in this procedure one by one. Can i do it by making ln_person_id an object ?
Judging by your code you have two concurrent programs - one that calls load_emp() and one that calls load_add(). If that's really the structure you want then the two calls will run in separate sessions and there's nothing you can do to pass a variable from one to the other. The best you could do would be to hold all the person_id values from load_emp in a custom table. The data could then later be consumed by load_add().
However I would restructure your package. Why not call load_add() from within the LOOP in load_emp() ?
I have to check this procedure
im giving following values as parameters
34220, 2815,'7/20/2011', 32760, 100, 'PMNT_CHECK', 1, null, "", false, null, null
DECLARE
P_APP_ID NUMBER;
P_USER_ID NUMBER;
P_DATE DATE;
P_INV_IDS WB_PROD.WB_PCK_TYPES.T_IDS;
P_AMNTS WB_PROD.WB_PCK_TYPES.T_NUMBERS;
P_PMNT_METHOD VARCHAR2(15);
P_BANK_AC_FROM NUMBER;
P_CHECK_NUMBERS WB_PROD.WB_PCK_TYPES.T_NUMBERS;
P_MEMO VARCHAR2(1000);
P_PAY_MULTIPLE NUMBER;
P_CRD_IDS WB_PROD.WB_PCK_TYPES.T_IDS;
P_CRD_AMOUNTS WB_PROD.WB_PCK_TYPES.T_PRICES;
O_PY_ID NUMBER;
BEGIN
P_APP_ID := 34220;
P_USER_ID := 2815;
P_DATE := '7/20/2011';
-- Modify the code to initialize the variable
P_INV_IDS := 32760;
-- Modify the code to initialize the variable
P_AMNTS := 100;
P_PMNT_METHOD := 'PMNT_CHECK';
P_BANK_AC_FROM := 1;
-- Modify the code to initialize the variable
--P_CHECK_NUMBERS := NULL;
P_MEMO := '';
P_PAY_MULTIPLE := false;
-- Modify the code to initialize the variable
-- P_CRD_IDS := NULL;
-- Modify the code to initialize the variable
-- P_CRD_AMOUNTS := NULL;
WB_PCK_BILL_PAYMENTS.PAY_BILLS(
P_APP_ID => P_APP_ID,
P_USER_ID => P_USER_ID,
P_DATE => P_DATE,
P_INV_IDS => P_INV_IDS,
P_AMNTS => P_AMNTS,
P_PMNT_METHOD => P_PMNT_METHOD,
P_BANK_AC_FROM => P_BANK_AC_FROM,
P_CHECK_NUMBERS => P_CHECK_NUMBERS,
P_MEMO => P_MEMO,
P_PAY_MULTIPLE => P_PAY_MULTIPLE,
P_CRD_IDS => P_CRD_IDS,
P_CRD_AMOUNTS => P_CRD_AMOUNTS,
O_PY_ID => O_PY_ID
);
DBMS_OUTPUT.PUT_LINE('O_PY_ID = ' || O_PY_ID);
END;
Im getting error at this line
P_INV_IDS := 32760;
i checked type of
P_INV_IDS WB_PROD.WB_PCK_TYPES.T_IDS;
which is in Declare statement, which is like this
type t_ids is table of t_id
index by binary_integer;
I donot understand how to give parameter to this type. Please let me know how to give this parameter.
Thank you
P_INV_IDS is an associative array as per your type declaration.
you can not assign this way
P_INV_IDS := 32760;
you need to specify the index in P_INV_IDS to which you are assigning value
something like
P_INV_IDS(0) := 32760;
P_INV_IDS(1) := 32761;
http://www.java2s.com/Tutorial/Oracle/0520__Collections/AssignvaluetoPLSQLtable.htm
How is the TYPE t_id defined? That will dictate how you initialize this array. If it were a number, then you will want to initialize your value this way:
P_INV_IDS(1) := 32760;
If, however, t_id is defined as, say a RECORD:
TYPE t_id IS RECORD (
ID INTEGER;
DESCRIPTION VARCHAR2(32);
);
Then you might want to initialize thusly:
P_INV_IDS(1).id := 32760;
P_INV_IDS(1).description := 'Description for 32760';