Sei sulla pagina 1di 6

create or replace

PACKAGE BODY PJB_UI_UTILS AS

procedure validate_dffs( p_application_id in number,


p_dff_code in varchar2,
p_key_col in varchar2,
p_key_col_val in NUMBER,
x_isValid OUT NOCOPY VARCHAR2,
X_Return_Status OUT NOCOPY VARCHAR2,
X_Msg_Count OUT NOCOPY NUMBER,
X_Msg_Data OUT NOCOPY VARCHAR2
) IS
l_gseg_req varchar2(1) := NULL;
l_gseg_enabled varchar2(1) := NULL;
l_gseg_column varchar2(1) := NULL;
l_table_name varchar2(1) := NULL;
l_invalid varchar2(1) := NULL;
l_GlobalCurStmt VARCHAR2(20000) := NULL;
l_ContextCurStmt VARCHAR2(20000) := NULL;
l_ContextSegStmt VARCHAR2(20000) := NULL;
l_contextSeg_sql VARCHAR2(20000) := NULL;
l_gseg_sql VARCHAR2(20000) := NULL;
l_dff_configured varchar2(1) := NULL;
l_context_req varchar2(1) := NULL;
l_yes varchar2(1) := NULL;

TYPE context_cur is REF CURSOR;


l_contextCur context_cur;
TYPE SegmentCur is REF CURSOR;
l_GlobalSegCur SegmentCur;
l_ContextSegCur SegmentCur;

l_globalSegTab SegmentRecTyp;
l_contextSegTab SegmentRecTyp;

l_contextTab ContextRecTyp;

l_FunctionName VARCHAR2(50);

BEGIN

l_FunctionName := 'validate_dffs';
l_dff_configured := 'N';

select 'Y' into l_dff_configured


from fnd_df_flexfields_b df
where df.flexfield_type = 'DFF'
and df.application_id = p_application_id
and df.descriptive_flexfield_code = p_dff_code
and ( exists (select null
from fnd_df_segments_b ds
where ds.application_id = p_application_id
and ds.descriptive_flexfield_code = p_dff_code
and ds.context_code = 'Global Data Elements')
or exists (select null
from fnd_df_contexts_b dc
where dc.application_id = df.application_id
and dc.descriptive_flexfield_code = p_dff_code)
);
IF l_dff_configured = 'Y' THEN
BEGIN
SELECT table_name into l_table_name
FROM fnd_df_table_usages fdtu
WHERE fdtu.application_id = p_application_id
and descriptive_flexfield_code = p_dff_code;

EXCEPTION
WHEN NO_DATA_FOUND THEN
pjb_invoice_generation.WriteLog(PJB_BILLING_UTILS.LEVEL_FINEST,
l_FunctionName, 'No table usage found for the DFF ' || p_dff_code );
x_isValid := 'N';
x_return_status := 'S';
x_msg_data := 'No table usage found for the DFF ' || p_dff_code;
END;

IF l_table_name IS NOT NULL THEN

l_GlobalCurStmt := ' SELECT application_id, descriptive_flexfield_code,


context_code, segment_code, column_name, enable_flag, required_flag ' ||
' FROM fnd_df_segments_b ' ||
' WHERE context_code = ''Global Data Elements'' AND
application_id = ' || p_application_id ||
' AND descriptive_flexfield_code = ' ||
p_dff_code;

OPEN l_GlobalSegCur FOR l_GlobalCurStmt ;

LOOP

FETCH l_GlobalSegCur BULK COLLECT INTO

l_globalSegTab.application_id,l_globalSegTab.descriptive_flexfield_code,l_globalSeg
Tab.context_code,

l_globalSegTab.segment_code,l_globalSegTab.column_name,l_globalSegTab.enable_flag,
l_globalSegTab.required_flag
LIMIT 100;

IF l_globalSegTab.segment_code.count() > 0 THEN

FOR i IN l_globalSegTab.segment_code.first ..
l_globalSegTab.segment_code.last
LOOP

l_gseg_enabled := l_globalSegTab.enable_flag(i);

IF l_globalSegTab.required_flag(i) = 'Y' AND


l_globalSegTab.enable_flag(i) = 'Y' THEN

BEGIN
l_gseg_sql := ' SELECT ' || l_yes || '
FROM ' || l_table_name || ' WHERE ' || p_key_col || ' = ' || p_key_col_val
|| ' AND ' ||
l_globalSegTab.column_name(i) || ' IS NULL ';
EXECUTE IMMEDIATE l_gseg_sql into
l_invalid;

IF l_invalid = 'Y' THEN


x_isValid := 'N';
x_return_status := 'S';
x_msg_data := 'Global Segment is required. But no value
provided for the global segment' || l_globalSegTab.segment_code(i);
exit;
END IF;

EXCEPTION
WHEN OTHERS THEN

pjb_invoice_generation.WriteLog(PJB_BILLING_UTILS.LEVEL_FINEST, l_FunctionName,
'Exception in validating the Global Segs for ' || p_dff_code );
x_isValid := 'N';
x_return_status := 'U';
x_msg_data := 'Exception in validating the Global Segs for '
|| p_dff_code;
END;
END IF;
END LOOP;

ELSE
pjb_invoice_generation.WriteLog(PJB_BILLING_UTILS.LEVEL_FINEST,
l_FunctionName, 'No Global Segments setup for the DFF ' || p_dff_code );
END IF;

END LOOP; -- End of global segment cursor

----------------------------------------------
------------ Handle Context Segments----------
----------------------------------------------

IF x_isValid <> 'N' THEN -- Any exception in processing the Global Segments

BEGIN
SELECT required_flag INTO l_context_req
FROM fnd_df_segments_b
WHERE descriptive_flexfield_code = p_dff_code
AND column_name = 'ATTRIBUTE_CATEGORY'
AND segment_code = 'Context Segment';

EXCEPTION
WHEN NO_DATA_FOUND THEN
pjb_invoice_generation.WriteLog(PJB_BILLING_UTILS.LEVEL_FINEST,
l_FunctionName, 'No Context/ContextSegments were setup for the DFF ' || p_dff_code
);

END;

-- Validate context sensitive segments here

--
IF l_invalid <> 'Y' AND l_context_req IS NOT NULL THEN ---- When valid GSeg
and any context seg setup

l_ContextCurStmt := 'SELECT ATTRIBUTE_CATEGORY FROM ' || l_table_name ||


' WHERE ' || p_key_col || ' = ' || p_key_col_val;
OPEN l_contextCur FOR l_ContextCurStmt ;

LOOP

FETCH l_contextCur BULK COLLECT INTO


l_contextTab.attribute_category
LIMIT 100;
-- Query the required segments here

FOR i IN l_contextTab.attribute_category.first ..
l_contextTab.attribute_category.last
LOOP

-- check here if context is requreid and no context is selected


IF l_context_req = 'Y' and l_contextTab.attribute_category(i) IS
NULL THEN
l_invalid := 'Y';
x_isValid := 'N';
x_return_status := 'S';
x_msg_data := 'Context is required. But no context selected ' ||
p_dff_code;
EXIT;

ELSE

l_ContextSegStmt := ' SELECT application_id,


descriptive_flexfield_code, context_code, segment_code, column_name, enable_flag,
required_flag ' ||
' FROM fnd_df_segments_b ' ||
' WHERE context_code = ' ||
l_contextTab.attribute_category(i) || ' AND application_id = ' || p_application_id
||
' AND descriptive_flexfield_code
= ' || p_dff_code;
OPEN l_ContextSegCur FOR l_ContextSegStmt ;

LOOP

FETCH l_ContextSegCur BULK COLLECT INTO

l_contextSegTab.application_id,l_contextSegTab.descriptive_flexfield_code,l_context
SegTab.context_code,

l_contextSegTab.segment_code,l_contextSegTab.column_name,l_contextSegTab.enable_fla
g,
l_contextSegTab.required_flag
LIMIT 100;

IF l_contextSegTab.segment_code.count() > 0 THEN

FOR i IN l_contextSegTab.segment_code.first ..
l_contextSegTab.segment_code.last
LOOP
IF l_contextSegTab.required_flag(i)= 'Y'
and l_contextSegTab.enable_flag(i) = 'Y' THEN

BEGIN
l_contextSeg_sql := ' SELECT '
|| l_yes || ' FROM ' || l_table_name || ' WHERE ' || p_key_col || ' = ' ||
p_key_col_val

|| ' AND ATTRIBUTE_CATEGORY = ' || l_contextSegTab.context_code(i)

|| ' AND ' || l_contextSegTab.column_name(i) || ' IS NULL ';


EXECUTE IMMEDIATE
l_contextSeg_sql into l_invalid;

IF l_invalid = 'Y' THEN


x_isValid := 'N';
x_return_status := 'S';
x_msg_data := 'Context Segment is required. But
no value provided for the context segment ' || l_contextSegTab.segment_code(i) ;
exit;
END IF;

EXCEPTION
WHEN NO_DATA_FOUND THEN

pjb_invoice_generation.WriteLog(PJB_BILLING_UTILS.LEVEL_FINEST, l_FunctionName, 'No


context segment created for the context ' || l_contextSegTab.context_code(i) );

END;
END IF;

END LOOP; -- End of contextSegTab For


Loop
END IF;

END LOOP;

END IF;

END LOOP;

END LOOP; -- End of Cursor Loop

-- If the selected context is required, then only validate the segments

END IF;

END IF; -- End of Any exception in processing the Global Segments


END IF; -- l_table_name if End

ELSE
pjb_invoice_generation.WriteLog(PJB_BILLING_UTILS.LEVEL_FINEST, l_FunctionName,
'No DFFs Configured... ');
x_return_status := 'S';
x_isValid := 'Y';
x_msg_data := 'No DFFs Configured';

END IF;

EXCEPTION
WHEN NO_DATA_FOUND THEN
x_return_status := 'S';
x_msg_data := '';
x_msg_count := '' ;

WHEN OTHERS THEN


x_return_status := 'U';
x_msg_data := sqlerrm;
x_msg_count := 1 ;
END;

END PJB_UI_UTILS;

Potrebbero piacerti anche