DECLARE
P_LINE_REC VARCHAR2(300) :='12345,56784,454562';
P_REASON VARCHAR2(300) := 'Customer No Longer Needed';
p_comments VARCHAR2(300) := 'New Code developed to add the Attachement';
TYPE SolCurTyp
IS
ref
CURSOR;
ONT_CV SOLCURTYP;
ONT_CV1 SOLCURTYP;
ONT_STMT VARCHAR2(4000);
ONT_STMT1 VARCHAR2(4000);
L_LINE_ID OE_ORDER_LINES_ALL.LINE_ID%TYPE;
L_ORG_ID OE_ORDER_LINES_ALL.ORG_ID%type;
L_HEADER_ID OE_ORDER_LINES_ALL.HEADER_ID%type;
L_RETURN_STATUS varchar2(1);
L_RET_STATUS VARCHAR2(1);
l_msg_data VARCHAR2(2000);
l_Head_id oe_order_lines_all.Header_id%Type := NULL;
P_ATTACH_LINE_REC VARCHAR2(2000) := NULL;
l_msg_count NUMBER;
L_MESSAGE_DATA varchar (2000);
l_ret_message VARCHAR (2000);
L_MSG_INDEX_OUT NUMBER;
V_ONT_STMT VARCHAR2(4000);
V_COUNT NUMBER;
V_COUNT1 NUMBER;
v_header_id number;
BEGIN
ONT_STMT1 := 'SELECT distinct Header_id
FROM oe_order_lines_all
WHERE line_id in (' ||p_line_rec|| ')
group by Header_id';
OPEN ONT_CV1 FOR ONT_STMT1;
LOOP
FETCH ONT_CV1 INTO V_HEADER_ID;
EXIT WHEN ONT_CV1%NOTFOUND;
DBMS_OUTPUT.PUT_LINE( 'V_COUNT1 ---'||V_HEADER_ID);
ONT_STMT := 'SELECT Header_id,line_id,Org_id
FROM oe_order_lines_all
WHERE line_id in (' ||p_line_rec|| ')
AND HEADER_ID = ( '|| V_HEADER_ID ||')
ORDER by Header_id';
OPEN ONT_CV FOR ONT_STMT;
LOOP
FETCH ONT_CV INTO l_Header_id,l_line_id,l_Org_id;
EXIT WHEN ONT_CV%NOTFOUND;
IF l_line_id IS NOT NULL THEN
-- Calling the API to delete a line from existing order
DBMS_OUTPUT.PUT_LINE( 'V_COUNT2 ---'||l_line_id);
DBMS_OUTPUT.PUT_LINE( 'Before Calling API for line id'||L_LINE_ID ||'---'||l_Org_id);
OE_ORDER_PUB.DELETE_LINE ( P_LINE_ID => L_LINE_ID ,
P_ORG_ID => L_ORG_ID ,
P_OPERATING_UNIT => NULL ,
X_RETURN_STATUS => L_RETURN_STATUS ,
X_MSG_COUNT => L_MSG_COUNT ,
X_MSG_DATA => L_MSG_DATA);
DBMS_OUTPUT.PUT_LINE( 'After Calling API -' ||l_return_status);
IF l_return_status = fnd_api.g_ret_sts_success
THEN
COMMIT;
l_ret_status := l_return_status;
L_RET_MESSAGE := L_MSG_DATA;
IF P_ATTACH_LINE_REC IS NOT NULL THEN
P_ATTACH_LINE_REC := P_ATTACH_LINE_REC||CHR(10) ||L_LINE_ID;
ELSE
P_ATTACH_LINE_REC := L_LINE_ID;
END IF;
ELSE
oe_msg_pub.get (p_msg_index => 1,
p_encoded => fnd_api.g_false,
p_data => l_msg_data,
p_msg_index_out => l_msg_index_out
);
l_ret_status := l_return_status;
L_RET_MESSAGE := L_MSG_DATA;
DBMS_OUTPUT.PUT_LINE( 'After Calling API -'|| 'Error at SO Line Deletion: '||'Return Status of Hearder ID and Line ID - '||L_LINE_ID||' & '||L_HEADER_ID || ' is :'||
L_RET_STATUS || 'and Message is :' ||L_RET_MESSAGE );
FND_FILE.PUT_LINE (FND_FILE.log,
'Error at SO Line Deletion: '||'Return Status of Hearder ID and Line ID - '||L_LINE_ID||' & '||L_HEADER_ID || ' is :'||
L_RET_STATUS || 'and Message is :' ||L_RET_MESSAGE);
END IF;
END IF;
DBMS_OUTPUT.PUT_LINE('Coming here 1');
END LOOP;
CLOSE ONT_CV;
IF P_ATTACH_LINE_REC IS NOT NULL THEN
DBMS_OUTPUT.PUT_LINE( 'Adding attachment for header id :'||L_HEADER_ID);
XX_ADD_HEADER_ATTACHEMENT(p_pk1_value => l_Header_id,
p_org_id => NULL,
P_SHORT_TEXT => P_REASON||CHR(10) ||P_COMMENTS||CHR(10)||P_ATTACH_LINE_REC);
P_ATTACH_LINE_REC := NULL;
DBMS_OUTPUT.PUT_LINE( 'completed adding attachment for header id :'||l_Header_id);
END IF;
END LOOP;
CLOSE ONT_CV1;
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE( 'API Eror :'||SQLERRM);
END ;
P_LINE_REC VARCHAR2(300) :='12345,56784,454562';
P_REASON VARCHAR2(300) := 'Customer No Longer Needed';
p_comments VARCHAR2(300) := 'New Code developed to add the Attachement';
TYPE SolCurTyp
IS
ref
CURSOR;
ONT_CV SOLCURTYP;
ONT_CV1 SOLCURTYP;
ONT_STMT VARCHAR2(4000);
ONT_STMT1 VARCHAR2(4000);
L_LINE_ID OE_ORDER_LINES_ALL.LINE_ID%TYPE;
L_ORG_ID OE_ORDER_LINES_ALL.ORG_ID%type;
L_HEADER_ID OE_ORDER_LINES_ALL.HEADER_ID%type;
L_RETURN_STATUS varchar2(1);
L_RET_STATUS VARCHAR2(1);
l_msg_data VARCHAR2(2000);
l_Head_id oe_order_lines_all.Header_id%Type := NULL;
P_ATTACH_LINE_REC VARCHAR2(2000) := NULL;
l_msg_count NUMBER;
L_MESSAGE_DATA varchar (2000);
l_ret_message VARCHAR (2000);
L_MSG_INDEX_OUT NUMBER;
V_ONT_STMT VARCHAR2(4000);
V_COUNT NUMBER;
V_COUNT1 NUMBER;
v_header_id number;
BEGIN
ONT_STMT1 := 'SELECT distinct Header_id
FROM oe_order_lines_all
WHERE line_id in (' ||p_line_rec|| ')
group by Header_id';
OPEN ONT_CV1 FOR ONT_STMT1;
LOOP
FETCH ONT_CV1 INTO V_HEADER_ID;
EXIT WHEN ONT_CV1%NOTFOUND;
DBMS_OUTPUT.PUT_LINE( 'V_COUNT1 ---'||V_HEADER_ID);
ONT_STMT := 'SELECT Header_id,line_id,Org_id
FROM oe_order_lines_all
WHERE line_id in (' ||p_line_rec|| ')
AND HEADER_ID = ( '|| V_HEADER_ID ||')
ORDER by Header_id';
OPEN ONT_CV FOR ONT_STMT;
LOOP
FETCH ONT_CV INTO l_Header_id,l_line_id,l_Org_id;
EXIT WHEN ONT_CV%NOTFOUND;
IF l_line_id IS NOT NULL THEN
-- Calling the API to delete a line from existing order
DBMS_OUTPUT.PUT_LINE( 'V_COUNT2 ---'||l_line_id);
DBMS_OUTPUT.PUT_LINE( 'Before Calling API for line id'||L_LINE_ID ||'---'||l_Org_id);
OE_ORDER_PUB.DELETE_LINE ( P_LINE_ID => L_LINE_ID ,
P_ORG_ID => L_ORG_ID ,
P_OPERATING_UNIT => NULL ,
X_RETURN_STATUS => L_RETURN_STATUS ,
X_MSG_COUNT => L_MSG_COUNT ,
X_MSG_DATA => L_MSG_DATA);
DBMS_OUTPUT.PUT_LINE( 'After Calling API -' ||l_return_status);
IF l_return_status = fnd_api.g_ret_sts_success
THEN
COMMIT;
l_ret_status := l_return_status;
L_RET_MESSAGE := L_MSG_DATA;
IF P_ATTACH_LINE_REC IS NOT NULL THEN
P_ATTACH_LINE_REC := P_ATTACH_LINE_REC||CHR(10) ||L_LINE_ID;
ELSE
P_ATTACH_LINE_REC := L_LINE_ID;
END IF;
ELSE
oe_msg_pub.get (p_msg_index => 1,
p_encoded => fnd_api.g_false,
p_data => l_msg_data,
p_msg_index_out => l_msg_index_out
);
l_ret_status := l_return_status;
L_RET_MESSAGE := L_MSG_DATA;
DBMS_OUTPUT.PUT_LINE( 'After Calling API -'|| 'Error at SO Line Deletion: '||'Return Status of Hearder ID and Line ID - '||L_LINE_ID||' & '||L_HEADER_ID || ' is :'||
L_RET_STATUS || 'and Message is :' ||L_RET_MESSAGE );
FND_FILE.PUT_LINE (FND_FILE.log,
'Error at SO Line Deletion: '||'Return Status of Hearder ID and Line ID - '||L_LINE_ID||' & '||L_HEADER_ID || ' is :'||
L_RET_STATUS || 'and Message is :' ||L_RET_MESSAGE);
END IF;
END IF;
DBMS_OUTPUT.PUT_LINE('Coming here 1');
END LOOP;
CLOSE ONT_CV;
IF P_ATTACH_LINE_REC IS NOT NULL THEN
DBMS_OUTPUT.PUT_LINE( 'Adding attachment for header id :'||L_HEADER_ID);
XX_ADD_HEADER_ATTACHEMENT(p_pk1_value => l_Header_id,
p_org_id => NULL,
P_SHORT_TEXT => P_REASON||CHR(10) ||P_COMMENTS||CHR(10)||P_ATTACH_LINE_REC);
P_ATTACH_LINE_REC := NULL;
DBMS_OUTPUT.PUT_LINE( 'completed adding attachment for header id :'||l_Header_id);
END IF;
END LOOP;
CLOSE ONT_CV1;
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE( 'API Eror :'||SQLERRM);
END ;
No comments:
Post a Comment