SELECT distinct
xddv.data_source_code "Data Definition Code"
, xddv.data_source_name "Data Definition"
, xddv.description "Data Definition Description"
, xtb.template_code "Template Code"
, xtt.template_name "Template Name"
, xtt.description "Template Description"
, xtb.template_type_code "Type"
, xl.file_name "File Name"
, xtb.default_output_type "Default Output Type"
, fat.application_name
FROM
apps.xdo_ds_definitions_vl xddv
, apps.xdo_templates_b xtb
, apps.xdo_templates_tl xtt
, apps.xdo_lobs xl
, apps.fnd_application_tl fat
, apps.fnd_application fa
WHERE
1 =1
and xddv.data_source_code = :CP_Short_Name
AND xddv.application_short_name = fa.application_short_name
AND fat.application_id = fa.application_id
AND xtb.application_short_name = xddv.application_short_name
AND xddv.data_source_code = xtb.data_source_code
AND xtt.template_code = xtb.template_code
AND xl.lob_code = xtb.template_code
AND xl.xdo_file_type = xtb.template_type_code
and xtb.START_DATE <= sysdate
and nvl(xtb.END_DATE,sysdate) >= Sysdate
;