Thursday 29 December 2016

Custom OAF code deployment to Run edition in 12.2.X


Steps to deploy custom OAF code to run edition (assuming that custom OAF code is under $JAVA_TOP/xxcust.

1. Login into instance and source to "Run edition"
2. Go to $JAVA_TOP
3. Take backup of  customall.jar
4. Run adcgnjar command. Just enter adcgnjar and then enter
5. Provide DB apps password.
6. Then go to $ADMIN_SCRIPTS_HOME and bounce OA core on Weblogic
admanagedsrvctl.sh stop oacore_server1
admanagedsrvctl.sh start oacore_server1


BI Publisher useful snippets



1. xdofx vs xdoxslt
<?xdofx:expression?> for extended SQL functions
<?xdoxslt:expression?> for extended XSL functions.

You cannot mix xdofx statements with XSL expressions in the same context


Number-To-Word Conversion


<?xdofx:to_check_number(amount, precisionOrCurrency, caseType, decimalStyle)?>
amount  --> The number to be transformed. --> Any number

precisionOrCurrency -->  For this attribute you can specify either the precision, which is the number of digits after the decimal point; or the currency code, which governs the number of digits after the decimal point. The currency code does not generate a currency symbol in the output. --> An integer, such as 2; or a currency code, such as 'USD'.


caseType  --> The case type of the output. --> Valid values are: 'CASE_UPPER', 'CASE_LOWER', 'CASE_INIT_CAP'


decimalStyle --> Output type of the decimal fraction area. --> Valid values are: 'DECIMAL_STYLE_FRACTION1', 'DECIMAL_STYLE_FRACTION2', 'DECIMAL_STYLE_WORD'

Examples:
<?xdofx:to_check_number(12345.67, 2)?>

Twelve thousand three hundred forty-five and 67/100



<?xdofx:to_check_number(12345.67, 'USD')?>

Twelve thousand three hundred forty-five and 67/100

<?xdofx:to_check_number(12345, 'JPY', 'CASE_UPPER')?>

TWELVE THOUSAND THREE HUNDRED FORTY-FIVE

<?xdofx:to_check_number(12345.67, 'EUR', 'CASE_LOWER', 'DECIMAL_STYLE_WORDS')?>
twelve thousand three hundred forty-five and sixty-seven

2.

Download FND new messages in Other langauges


To download the FND new messages in other languages, first we need to set the NLS lang.

To get the correct setting query FND_LANGUAGES as below

Find the language from FND_LANGUAGES

select NlS_LANGUAGE||'_'||NLS_TERRITORY||'.'||NLS_CODESET from FND_LANGUAGES WHERE INSTALLED_FLAG IN ('I','B');

For example for Simplified Chinese use:

For Download:
$ export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16CGB231280"

$ FNDLOAD apps/<AppsPwd> Y DOWNLOAD$FND_TOP/patch/115/import/afmdmsg.lct  FND_NEW_MESSAGES APPLICATION_SHORT_NAME=XXCUST MESSAGE_NAME=XXCUSTMSG

For Upload:
Note: Do not set any nls lang varaible.. if you have previously alter NLS LANG then disconnect from session and then do upload
FNDLOAD apps/<Apps Password> 0 Y UPLOAD $FND_TOP/patch/115/import/afmdmsg.lct XXCUSTMSG_MSG_ZHS.ldt - UPLOAD_MODE=NLS CUSTOM_MODE=FORCE WARNINGS=TRUE

Workflow translation


Introduction:

Recently came across a situation, where in we need to translate workflow notifications to Simplified Chinese. We evaluated multiple methods 

Approach 1:
  1. Set the NLS_LANG on the desktop and edit the workflow  and update messages with Chinese translations.
  2.  Remove all standard and flex fields workflow from the current definition.
  3.  Set NLS_LANG to ”SIMPLIFIED CHINESE_CHINA”.ZHS16GBK and then upload the workflow using WFLOAD

Approach 2:
1.       Open the workflow in notepad and set the language to ZHS.
2.       Remove all standard and flex fields workflow from the current definition
3.       Update message subject and body with Chinese translations
4.       Set NLS_LANG
5.       Upload the .wft using FNDLOAD and using afwfload.lct

Approach 3:
1.       Give a SQL script to update subject and body columns of WF_MESSAGES_TL for ZHS language as we are only translating the messages and not changing any other part.

Finally we went with approach 3 as it is simple and just we need notifications in simplified Chinese but instead of simple update we went with API approach. Here are the steps..


---First, set the session language:
execute immediate 'alter session set nls_language='||''''||'SIMPLIFIED CHINESE'||'''';

-- Secondly, set the WF mode and access levels..
wf_core.upload_mode := 'FORCE';
wf_core.session_level := 100;

-- Prepare tables, if we want to execute the script in patch edition
-- Need to prepare the seed tables
ad_zd_seed.prepare('WF_MESSAGES');
ad_zd_seed.prepare('WF_MESSAGES_TL');
ad_zd_seed.prepare('WF_RESOURCES');

-- Finally call the API with message

WF_LOAD.UPDATE_MESSAGE (
  p_type =>  'XXCSWF', -- wf type
  p_name => 'XXMSGNAME',  -- message name
  p_subject => l_subject,  -- message subject in Chinese
  p_body =>  l_msg_body,  -- message body in Chinese
  p_html_body => l_body ,   -- message html body in Chinese.
  p_level_error => x_level_error);

         -- Commit or rollback based on success/failure

Note: Use 
SET SERVEROUTPUT ON;
SET DEFINE OFF;
SET VERIFY OFF;

to turn off substitution.

Tuesday 4 October 2016

Migration of XML Publisher Objects using LDTs and XMLLoader

An XML Publisher template defintion will have following things to migrate.

1) Template defintion & Data defintion  => Use FNDLOAD
2)  Actual layout templates (RTF/EXCEL/PDF) & Actual data defintion XML file. => use XDOLOADER command


Template defintion & Data defintion 
FNDLOAD apps/<appsPwd> 0 Y DOWNLOAD  $XDO_TOP/patch/115/import/xdotmpl.lct XXCUSTEMPL.ldt XDO_DS_DEFINITIONS APPLICATION_SHORT_NAME='XXCUST' DATA_SOURCE_CODE='Data defintion Code' TMPL_APP_SHORT_NAME='XXCUST' TEMPLATE_CODE='Template Code'

With the above command you will fetch both data defintion and template defintion.

You upload the above using the UPLOAD command.

FNDLOAD apps/<appsPwd> 0 Y UPLOAD $XDO_TOP/patch/115/import/xdotmpl.lct XXCUSTEMPL.ldt

Once the definitions are created in the instance, you need to upload the actual layout and data defintion files using XDOLOADER.

Data Template/Data Source:

java oracle.apps.xdo.oa.util.XDOLoader DOWNLOAD -DB_USERNAME apps -DB_PASSWORD <appsPwd> -JDBC_CONNECTION '(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=XX_DB_HOST_NAME)(PORT=XX_DB_PORT_NUMBER))(CONNECT_DATA=(SERVICE_NAME=XX_DB_SERVICE_NAME)))' -LOB_TYPE DATA_TEMPLATE -LOB_CODE XX_DATA_TEMPL_CODE -APPS_SHORT_NAME XXCUST -LANGUAGE en -lct_FILE $XDO_TOP/patch/115/import/xdotmpl.lct -LOG_FILE $LOG_FILE_NAME


java oracle.apps.xdo.oa.util.XDOLoader UPLOAD -DB_USERNAME apps -DB_PASSWORD <appsPwd> -JDBC_CONNECTION '(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=XX_HOST_NAME)(PORT=XX_PORT_NUMBER))(CONNECT_DATA=(SERVICE_NAME=XX_SERVICE_NAME)))' -LOB_TYPE DATA_TEMPLATE -LOB_CODE XX_DATA_TEMPL_CODE -XDO_FILE_TYPE XML -FILE_NAME $DATA_FILE_PATH/$DATA_FILE_NAME.xml -APPS_SHORT_NAME XXCUST -NLS_LANG en -TERRITORY US -LOG_FILE $LOG_FILE_NAME


 RTF TEMPLATE (Report Layout .rtf file) 

java oracle.apps.xdo.oa.util.XDOLoader DOWNLOAD -DB_USERNAME apps -DB_PASSWORD appsPwd  -JDBC_CONNECTION '(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=XX_HOST_NAME)(PORT=XX_PORT_NUMBER))(CONNECT_DATA=(SERVICE_NAME=XX_SERVICE_NAME)))' -LOB_TYPE TEMPLATE -LOB_CODE XX_TEMPLATE -APPS_SHORT_NAME XXCUST -LANGUAGE en -TERRITORY US -lct_FILE $XDO_TOP/patch/115/import/xdotmpl.lct -LOG_FILE $LOG_FILE_NAME




java oracle.apps.xdo.oa.util.XDOLoader UPLOAD -DB_USERNAME apps -DB_PASSWORD appsPwd -JDBC_CONNECTION '(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=XX_HOST_NAME)(PORT=XX_PORT_NUMBER))(CONNECT_DATA=(SERVICE_NAME=SERVICE_NAME)))' -LOB_TYPE TEMPLATE -LOB_CODE XX_TEMPLATE -XDO_FILE_TYPE RTF -FILE_NAME $RTF_FILE_PATH/$RTF_FILE_NAME.rtf -APPS_SHORT_NAME XXCUST -NLS_LANG en -TERRITORY US -LOG_FILE $LOG_FILE_NAME

FNDLOAD to migrate AOL objects to different instances

During development we generally do required AOL setups in lower instances and to migrate the AOL objects such as messages/lookups/Concurrent programs etc, we generate LDTs using FNDLOAD - DOWNLOAD  from lower instance and upload them using FNDLOAD - UPLOAD command in higher instances.

Structure of FNDLOAD command:

FNDLOAD apps/<AppsPwd> 0 Y [DOWNLOAD]  [LCT file] [LDT FILE name] [ENTITY_NAME]  [KEY1=[VAL].. [KEY/CTX]=VAL]

Open the LCT file using notepad you will be able to easily understand what KEY or context you need to use/what parameters you can create.

We can create custom lcts similar to Seed lcts for any table and migrate data using the custom lct and FNDLOAD.

Tips and Examples Using FNDLOAD (Doc ID 735338.1)


Messages
FNDLOAD apps/<appsPwd> 0 Y DOWNLOAD $FND_TOP/patch/115/import/afmdmsg.lct XX_CUSTOM_MESG.ldt FND_NEW_MESSAGES APPLICATION_SHORT_NAME="XXCUST" MESSAGE_NAME="XX_AP_CUST_MSG"

FNDLOAD apps/apps O Y UPLOAD $FND_TOP/patch/115/import/afmdmsg.lct XX_CUSTOM_MESG.ldt UPLOAD_MODE=REPLACE CUSTOM_MODE=FORCE

Lookup

FNDLOAD apps/<appsPwd> O Y DOWNLOAD $FND_TOP/patch/115/import/aflvmlu.lct XX_APCUST_LKP_LKP.ldt FND_LOOKUP_TYPE APPLICATION_SHORT_NAME="SQLAP" LOOKUP_TYPE="XX_APCUST_LKP"

Concurrent Program:

FNDLOAD apps/<appsPwd> O Y DOWNLOAD $FND_TOP/patch/115/import/afcpprog.lct XX_CONC_CP.ldt PROGRAM APPLICATION_SHORT_NAME="XXCUST" CONCURRENT_PROGRAM_NAME="XX_CONC_CP"

Value set:
FNDLOAD apps/<appsPwd> 0 Y DOWNLOAD $FND_TOP/patch/115/import/afffload.lct XX_CUST_LEGAL_ENTITY_VS.ldt VALUE_SET FLEX_VALUE_SET_NAME="XX_CUST_LEGAL_ENTITY"


Desc flex:
FNDLOAD apps/<appsPwd> 0 Y DOWNLOAD $FND_TOP/patch/115/import/afffload.lct OKC_ARTICLES_DESC_FLEX_DFF.ldt DESC_FLEX P_LEVEL=:COL_ALL:REF_ALL:CTX_ONE:SEG_ALL? APPLICATION_SHORT_NAME="OKC" DESCRIPTIVE_FLEXFIELD_NAME="OKC_ARTICLES_DESC_FLEX"

Func Objec:
FNDLOAD apps/<appsPwd> 0 Y DOWNLOAD $FND_TOP/patch/115/import/afsload.lct XX_CUST_INV_UPLOAD_FUNCTION.ldt FUNCTION FUNCTION_NAME="XX_CUST_INV_UPLOAD"

Profile:
FNDLOAD apps/<appsPwd> O Y DOWNLOAD $FND_TOP/patch/115/import/afscprof.lct XX_CUST_AME_TXN_TYPE_PRF.ldt PROFILE PROFILE_NAME="XX_CUST_AME_TXN_TYPE" APPLICATION_SHORT_NAME="XXCUST"

Folder:

FNDLOAD APPS/<appsPwd> 0 Y DOWNLOAD $FND_TOP/patch/115/import/fndfold.lct XXCUST_TEST_FOLD.ldt FND_FOLDERS FOLDER_NAME="TEST ACCRUAL"


Request Set:
FNDLOAD apps/<appsPwd> 0 Y DOWNLOAD $FND_TOP/patch/115/import/afcprset.lct XX_CUST_RS.ldt REQ_SET REQUEST_SET_NAME='REQUEST_SET_NAME'

Forms:
FNDLOAD apps/<appsPwd> 0 Y DOWNLOAD $FND_TOP/patch/115/import/afsload.lct XX_CUST_FORM.ldt FORM FORM_NAME="FORM_NAME" 


Form Function :
FNDLOAD apps/<appsPwd> 0 Y DOWNLOAD $FND_TOP/patch/115/import/afsload.lct XX_CUST_FUNC.ldt FUNCTION FUNCTION_NAME="FORM_FUNCTION_NAME"

Alerts:
FNDLOAD apps/<appsPwd> 0 Y DOWNLOAD $ALR_TOP/patch/115/import/alr.lct XX_CUST_ALR.ldt ALR_ALERTS APPLICATION_SHORT_NAME="XXCUST" ALERT_NAME="XX - Alert Name"

XML Publisher Data definition and XML Layout templates:

FNDLOAD apps/<appsPwd> 0 Y DOWNLOAD  $XDO_TOP/patch/115/import/xdotmpl.lct XXCUSTTEMPL.ldt XDO_DS_DEFINITIONS APPLICATION_SHORT_NAME='XXCUST' DATA_SOURCE_CODE='Data defintion code' TMPL_APP_SHORT_NAME='XXCUST' TEMPLATE_CODE='Template Code'

Wednesday 28 September 2016

Oracle EBS 12.2.x Notes


---------------------------------------------------------------------------------------------------
To display the current connected edition

$echo $FILE_EDITION

$ sqlplus apps/apps
SQL> select ad_zd.get_edition_type from dual;

---------------------------------------------------------------------------------------------------
Useful metalink notes:
* Developing and Deploying Customizations in Oracle E-Business Suite Release 12.2 (Doc ID 1577661.1)

* How to deploy customizations that are created in the package oracle.apps.xxprod.* rather than xxprod.oracle.apps.* or xxprod.oracle.apps.xxprod.* on EBS 12.2.X? (Doc ID 1609939.1)

---------------------------------------------------------------------------------------------------
OAF deployment steps 12.2.x:

1) Connect to middle tier
2) Source to Run file system
$. ./EBSapps.env
3) Then enter 'R'
4) Go to JAVA TOP
$cd $JAVA_TOP
5) Backup customall.jar file
6) Run adcgnjar by entering apps DB password to regenrate customall.jar file and check the time stamp
$adcgnjar
7) Restart OACORE by giving weblogic admin password.
$admanagedsrvctl.sh stop oacore_server1
$admanagedsrvctl.sh start oacore_server1
---------------------------------------------------------------------------------------------------

Workflow Notes

Download Workflow Builder:

Download workflow builder from Metalink - Patch Number 6970344.

Workflow builder works on both 32 bit machine and 64 bit machine. But if you are using 64 bit machine you need to have Admin Access on your 64 bit system from where you are launching the Workflow builder.

Refer note Recommended Set Up for Client/Server Products with Oracle E-Business Suite 11i and R12 (Doc ID 277535.1) for getting appropriate Workflow builder patch.

Workflow Access Levels:

   0-9           Reserved for Oracle Workflow
   10-19       Resereved for Oracle Application Object Library
   20-99       Resereved for Oracle Applications Development

   100-999   Reserved for Customer Organization
    1000       Public

When developing custom workflow or modifying a seeded workflow you need to set the access level to 100. Setting any other access level and modifying seeded workflow objects may corrupt the workflow and you might see abnormal functionality.

If any activity/object is locked by Oracle Applications Development the protection level will be 20 and you will not be able to modify with access level 100. If it is not locked the protection level will be 1000 and you will be able to modify with access level 100.

After you modify, you need to check the preserve customiztions and lock at this access level to protect the customizations from upgrade/patching. With this Customization value will be 100 and Protection will also be 100. However by checking Allow modifications to customized objects Oracle App development will also be able to modify.

Set the access level from workflow bulider Help (Menu) --> About Workflow Builder

WFLOAD Commands:

Download workflow from the instance:
WFLOAD apps/<apps pwd> 0 Y DOWNLOAD XXCUST.wft <ITEMTYPE>

Upload workflow to database - Upgrade mode:
WFLOAD apps/<apps pwd>0 Y UPGRADE XXR2REXT820B.wft

Upgrade mode honours both protection and customiztion levels of data

Upload workflow to database - Upload mode:
WFLOAD apps/<apps pwd>0 Y UPLOAD XXR2REXT820B.wft

Upload mode honours only protection levels of data.

Upload workflow to database - Force mode:
WFLOAD apps/<apps pwd> 0 Y FORCE XXR2REXT820B.wft
Force upload  does not honor both protection and customiztion levels of data

Below are some useful metalink notes on workflow:
How To Use WFLOAD To Download, Upload, Upgrade, Force Upload A Workflow To Database? (Doc ID 1569004.1)
How to Ensure Workflow File Customizations/Changes Are Not OverWritten By Upgrades/Patches (Doc ID 1343956.1)
WFLOAD Fails On Customizations (Doc ID 1015861.102)



Compile Flexfiled or Concurrent Program Flexfields


When running concurrent program some times we get error Concurrent program flexfield not compiled or not freezed. You can do it through Compile All Flex fields concurrent program or using below command

fdfcmp apps/<apps password> 0 Y D 'XXCUST'  '$SRS$.XX_CONC_PROG_SHORT_NAME'

XXCUST --> Concuurent program application short name
XX_CONC_PROG_SHORT_NAME --> Concurrent program short name

Scripts required for 12.2.X custom table development



1) For new table creations - after creating the table in custom schema execute below script to generate editoning view and synonym for it in APPS schema.

exec AD_ZD_TABLE.UPGRADE('XXCUST','XX_CUST_TBL1');

2) For table alteratuons - after running the DDL run below script to regenerate the editioning view for syncing any table changes.

exec AD_ZD_TABLE.PATCH('XXCUST','XX_CUST_TBL1')

3) Table grants must be done through API to avoid invalids.

exec AD_ZD.GRANT_PRIVS('SELECT','XX_CUST_TBL1','XX_ROLE0')

4) To view objects in all editions..add _ae to the data dictionary views

select * from user_objects_ae;

5) To update seed data tables in Patch edition, execute prepare command.

example:
 exec ad_zd_seed.prepare('WF_MESSAGES');

The prepare will create a edition based storage for the run edition data for which the updates will be made. During cutover, the run time data will be synced using forward/reverse cross edition triggers.

Thursday 21 July 2016

Launching JDeveloper for a given folder without seeing other projects.


When we are accessing jdeveloper without Admin previleges, we want to open a specific project under our Jdev home, then follow the below steps:

Go to cmd prompt:
set JDEV_USER_DIR=<JdevHone>\<projid>
then
launch jdevloper  <Jdev Bin Install dir>\jdeveloper.exe

example:

set JDEV_USER_DIR=C:\SK\Work\Work\jdev\xxtest
C:\SK\Software\p9879989_R12_GENERIC\jdevbin\jdeveloper.exe

Tuesday 19 July 2016

Query to find GL periods for a given legal entity

Query to find GL periods for a given legal entity:

 select gp.period_name
                  from gl_ledger_norm_seg_vals bsv,gl_ledgers gl, gl_periods gp
                 where  1=1
                 AND Bsv.Legal_Entity_Id = :Legal Entity Id
                 And Bsv.Segment_Type_Code = 'B'
                AND sysdate between nvl(bsv.start_date,sysdate-1) and nvl(bsv.end_date,sysdate+1)
                And Gl.Object_Type_Code = 'L'                
                And Gl.Ledger_Category_Code = 'PRIMARY'
                And Gl.Ledger_Id=Bsv.Ledger_Id
                AND gp.period_set_name=gl.period_set_name
                order by gp.start_date
                ;

Derive GL Start and End Dates..

select start_date,end_date
                  from gl_ledger_norm_seg_vals bsv,gl_ledgers gl, gl_periods gp
                 where  1=1
                 AND Bsv.Legal_Entity_Id = :p_Legal_entity_id
                 And Bsv.Segment_Type_Code = 'B'
                AND sysdate between nvl(bsv.start_date,sysdate-1) and nvl(bsv.end_date,sysdate+1)
                And Gl.Object_Type_Code = 'L'                
                And Gl.Ledger_Category_Code = 'PRIMARY'
                And Gl.Ledger_Id=Bsv.Ledger_Id
                AND gp.period_set_name=gl.period_set_name
                and gp.period_name = :p_period_name
                order by gp.start_date

                ;

Query to find legal entity,registration and address details


Query to find legal entity details

SELECT xep.name,                                          -- Legal Entity Name
       xjv.registration_code_le registration_code,        -- Registration Code
       xr.registration_number,                          -- Registration Number
          DECODE (hl.address_line_1, NULL, '', hl.address_line_1 || ', ')
       || DECODE (hl.address_line_2, NULL, '', hl.address_line_2 || ', ')
       || DECODE (hl.address_line_3, NULL, '', hl.address_line_3 || ', ')
       || DECODE (hl.town_or_city, NULL, '', hl.town_or_city || ', ')
       || DECODE (hl.region_2, NULL, '', hl.region_2 || ', ')
       || DECODE (hl.postal_code, NULL, '', hl.postal_code || ', ')
       || DECODE (ftv.territory_short_name,
                  NULL, '',
                  ftv.territory_short_name)
          Address --Address
  FROM xle_registrations xr,
       xle_jurisdictions_vl xjv,
       hr_locations hl,
       fnd_territories_vl ftv,
       xle_entity_profiles xep
 WHERE     1 = 1
       AND xep.legal_entity_id = :legal_entity_id
       AND xr.source_table = 'XLE_ENTITY_PROFILES'
       AND xr.source_id = xep.legal_entity_id
       AND xjv.jurisdiction_id = xr.jurisdiction_id
       AND hl.location_id = xr.location_id
       AND ftv.territory_code = hl.country
       AND SYSDATE BETWEEN NVL (xr.effective_from, SYSDATE - 1)
                       AND NVL (xr.EFFECTIVE_TO, SYSDATE + 1);

Invalid number error when working with DFF attributes..

Invalid number error when working with DFF attributes when using to_number:

When we are working with DFFs, segments can be configured to store numbers but due to user wrong input or some misconfiguration some rows might end with having string with numbers and characters. When we use that attribute in a query and try to compare it to a number or try to convert to a number, the system will throw error. To avoid the error, we can use the following condition in the query:

select * from po_headers_all
where org_id=101
and nvl(length(regexp_replace(attribute5,'^[0-9]+', ''),0)=0;


to find invalid rows you can use below.

nvl(length(regexp_replace(attribute5,'^[0-9]+', ''),0)>0;

Monday 11 July 2016

API and Query to get AP Invoice Status


API and Query to get AP Invoice Status:


1.  Get Invoice status from API
SELECT ai.invoice_num,
       ai.invoice_amount,
       AP_INVOICES_PKG.GET_APPROVAL_STATUS (ai.invoice_id,
                                            ai.invoice_amount,
                                            ai.payment_status_flag,
                                            ai.invoice_type_lookup_code)
          inv_status
  FROM ap_invoices_all ai
 WHERE invoice_num = '<inv number>' AND org_id = <org id>;



2. Get actual meaning from below query from lookup:
  SELECT lookup_type,
         LOOKUP_CODE,
         MEANING,
         DESCRIPTION,
         TAG,
         START_DATE_ACTIVE,
         END_DATE_ACTIVE,
         ENABLED_FLAG
    FROM FND_LOOKUP_VALUES_VL
   WHERE     (   NVL ('', territory_code) = territory_code
              OR territory_code IS NULL)
         AND (VIEW_APPLICATION_ID = 200)
         AND (SECURITY_GROUP_ID = 0)
         AND lookup_Type = 'NLS TRANSLATION'
         AND LOOKUP_CODE =  '<Inv_status from above query> ' ---'NEVER APPROVED'
ORDER BY LOOKUP_CODE;

Sunday 3 July 2016

Useful Queries

1. Print Date and time using sysdate:
    SELECT TO_CHAR (SYSDATE, 'DD-MM-YY HH:MI:SS') FROM DUAL;

2. Print Numbers from 1 to 10.
 SELECT ROWNUM r
      FROM DUAL
CONNECT BY ROWNUM <= 10;

3. Kill Session
alter system kill session '1266,54057'; --'sid, serial#'

4. Gather Schema stats:
begin
DBMS_STATS.GATHER_TABLE_STATS('AP','AP_SUPPLIER_SITES_ALL');
end;
/

5. Remove special  (control chars) characeters from the string

SELECT REGEXP_REPLACE(colx, '[[:cntrl:]]', ' ') FROM xx_tab;

6. REPLACE ONE OR MORE COMMAS WITH SINGLE COMMA AND SPACE

select regexp_replace(' Address Line1,,Addressline3,,Postal Code,,57000  ',',{1,}', ', ') from dual;

Useful data dictionary views




NLS_DATABASE_PARAMETERS --> lists permanent NLS parameters of the database.NLS_INSTANCE_PARAMETERS lists NLS parameters of the instance.
There is one row for each component.You can query any of DBA_*, ALL_*,USER_*.In the below table I am listing only USER_


Dictionary Name
Details
USER_OBJECTS
Stores details about all the objects in a schema –
Object Types – Table, View, Synonym, Trigger, Sequence, Procedure, Function, Package, Package Body, Trigger, Index, Database Link, Type, polcies, Rules (VPD policy rules)
USER_TABLES
Table – Table Space, Disk block allocation details
USER_TAB_COLS
Column of table
USER_VIEWS
Views data dictionary – You can get the view text 
USER_SEQUENCES
Sequence information – Seq min, max, increment, etc.
user_synonyms
Synonyms – Reference object details
User_triggers
Stores the all the trigger in the schema. – You can get the trigger text and trigger table etc.
User_trigger_cols
Trigger column details
User_source
Stores all the source code – You can get code for trigger, procedure, package, package body, type body, type, function, procedure.
User_procedures
Lists all the procedure – You can get a list of procedure for a given package.
User_arguments
List of all the parameters for a given procedure. It includes package procedures as well.
User_indexes
List of Indexes
ex: select * from user_indexes where table_name=''
user_ind_columns
Index column names

user_dependencies

Dependencies 

select * from user_dependencies 
                where referenced_name='GL_LEDGER_NORM_SEG_VALS' 
                and name not like 'XX%'

                and referenced_type='SYNONYM' and referenced_owner='APPS';

Useful Dynamic Performance (V$) Views


V$ Views vs GV$ Views:V$ views are CONTAINER_DATA objects. When a user connected to the root queries a V$ view, the query results will depend on the CONTAINER_DATA attribute for users. For almost every V$ view,  Oracle has a corresponding GV$ (global V$) view. In Oracle Real Application Clusters, querying a GV$ view retrieves the V$ view information from all qualified instances. In addition to the V$ information, each GV$ view contains an extra column named INST_ID of data type NUMBER. The INST_ID column displays the instance number from which the associated V$ view information was obtained.
V$ACCESS displays objects in the database that are currently locked and the sessions that are accessing them.V$ACTIVE_INSTANCES displays the mapping between instance names and instance numbers for all instances that have the database currently mounted.V$AQ displays statistics for the queues in the database.V$CONTEXT lists set attributes in the current session.V$CONTROLFILE lists the names of the control files.V$DATABASE displays information about the database from the control file.V$DATAFILE contains datafile information from the control file.V$DBFILE lists all datafiles making up the database. This view is retained for historical compatibility. Use of V$DATAFILE is recommended instead.V$DBLINK describes all database links (links with IN_TRANSACTION = YES) opened by the session issuing the query on V$DBLINK. These database links must be committed or rolled back before being closed.V$INSTANCE view displays the state of the current instance.V$LICENSE contains information about license limits.V$NLS_PARAMETERS view contains current values of NLS parameters. =>NLS_CALENDAR, NLS_CHARACTERSET, NLS_CURRENCY, NLS_DATE_FORMAT, NLS_DATE_LANGUAGE, NLS_ISO_CURRENCY, NLS_LANGUAGE, NLS_NUMERIC_CHARACTERS, NLS_SORT, NLS_TERRITORY, NLS_UNION_CURRENCY, NLS_NCHAR_CHARACTERSET, NLS_COMPV$NLS_VALID_VALUES lists all valid values for NLS parameters. V$OBJECT_USAGE to monitor index usage. The view displays statistics about index usage gathered from the database. All indexes that have been used at least once can be monitored and displayed in this view. V$OPTION lists options that are installed with the Oracle Database.V$PARAMETER displays information about the initialization parameters that are currently in effect for the session. A new session inherits parameter values from the instance-wide values displayed by the V$SYSTEM_PARAMETER view.V$PARAMETER2 displays information about the initialization parameters that are currently in effect for the session, with each list parameter value appearing as a row in the view. A new session inherits parameter values from the instance-wide values displayed in the V$SYSTEM_PARAMETER2 view.Presenting the list parameter values in this format enables you to quickly determine the values for a list parameter. For example, if a parameter value is a, b, then the V$PARAMETER view does not tell you if the parameter has two values (both a and b) or one value (a, b). V$PARAMETER2 makes the distinction between the list parameter values clear.V$SESSION view lists session information for each current session.V$SGA displays summary information about the system global area (SGA).V$SQL lists statistics on shared SQL area without the GROUP BY clause and contains one row for each child of the original SQL text entered.V$SQL_BIND_DATA For each distinct bind variable in each cursor owned by the session querying this view/V$SQL_PLAN contains the execution plan information for each child cursor loaded in the library cache.V$SQL_PLAN_STATISTICS provides execution statistics at the row source level for each child cursor.V$SQLTEXT contains the text of SQL statements belonging to shared SQL cursors in the SGA.V$VERSION displays version numbers of core library components in the Oracle Database. 


Useful Supplier Queries

1. Supplier Details:

SELECT     s.segment1 supplier_number,                
                s.vendor_name supplier_name,
                s.vendor_name_alt supplier_alternate_name,
                ss.vendor_site_code supplier_site_code,
                ss.vendor_site_id supplier_site_id,
                hp.jgzz_fiscal_code tax_payer_id,
                ss.org_id operating_unit,                
                s.end_date_active supplier_inactive_date,
                ss.inactive_date supplier_site_inactive_date,
                NVL (ss.terms_id, s.terms_id) payment_term_id,
                hp.jgzz_fiscal_code national_id,
                ss.vat_code tax_code,
                NVL (ss.awt_group_id, s.awt_group_id)
                   withholding_tax_group_id,              
                s.party_id,
                ss.party_site_id               
           FROM ap_suppliers s,
                ap_supplier_sites_all ss               
                hz_parties hp,
                hz_party_sites hps
          WHERE     1 = 1
                AND s.vendor_type_lookup_code = lv.lookup_code
                AND ss.org_id = g_org_id
                AND s.vendor_id = ss.vendor_id
                AND hp.party_id = s.party_id

                AND hps.party_site_id = ss.party_site_id;

2. Query to get Supplier Tax Registration Number:

SELECT tax_reference
  FROM hz_organization_profiles hzop, ap_suppliers aps
 WHERE     1 = 1
       AND aps.segment1='1000' --> Supplier Number
       AND hzop.party_id = aps.party_id
       AND hzop.effective_end_date IS NULL;

3.Payment Terms:

SELECT name
           FROM ap_terms_vl

          WHERE term_id = <Terms Id from Query 1>;

4. Withhold Tax Group:

SELECT name, last_update_date
           FROM ap_awt_groups

          WHERE GROUP_ID = <withholding_tax_group_id from Query 1>

5.Supplier Payment Method:


  SELECT pv.payment_method_name
             FROM iby_external_payees_all ip,
                  iby_ext_party_pmt_mthds pm,
                  iby_payment_methods_vl pv
            WHERE     1 = 1
                  AND ip.supplier_site_id IS NULL
                  AND ip.payee_party_id = <Party Id from query 1>  --supp party id
                  AND ip.ext_payee_id = pm.ext_pmt_party_id
                  AND pm.payment_method_code = pv.payment_method_code

         ORDER BY pm.primary_flag DESC, pm.last_update_date DESC;


6.Supplier site Payment method:

SELECT pv.payment_method_name,
                  pm.last_update_date,
                  pv.last_update_date pm_last_update_date
             FROM iby_external_payees_all ip,
                  iby_ext_party_pmt_mthds pm,
                  iby_payment_methods_vl pv
            WHERE     ip.supplier_site_id = <Supp site Id from query 1>
                  AND ip.org_id = p_org_id
                  AND ip.ext_payee_id = pm.ext_pmt_party_id
                  AND pm.payment_method_code = pv.payment_method_code

         ORDER BY pm.primary_flag DESC, pm.last_update_date DESC;


7. Supplier Contact details Including phone,  email and fax details:

SELECT hp.person_last_name || ' ' || hp.person_first_name
                     contact_name,
                  hcpe.email_address,
                  LTRIM (
                     RTRIM (hcpp.phone_area_code || ' ' || hcpp.phone_number))
                     AS primary_phone_number,
                  LTRIM (
                     RTRIM (hcpf.phone_area_code || ' ' || hcpf.phone_number))
                     fax_number,
                  hzr.end_date,
                  hzr.last_update_date
             FROM hz_parties hp,
                  hz_relationships hzr,
                  hz_party_usg_assignments hpua,
                  hz_contact_points hcpp,
                  hz_contact_points hcpe,
                  hz_contact_points hcpf
            WHERE     hp.party_id = hzr.subject_id
                  AND hzr.object_id = <<p_supplier_party_id>> -- party of supplier
                  AND hzr.relationship_type = 'CONTACT'
                  AND hzr.relationship_code = 'CONTACT_OF'
                  AND hzr.subject_type = 'PERSON'
                  AND hzr.object_type = 'ORGANIZATION'
                  AND hzr.status IN ('A', 'I')
                  AND hpua.party_id = hp.party_id
                  AND hpua.status_flag IN ('A', 'I')
                  AND hpua.party_usage_code = 'SUPPLIER_CONTACT'
                  AND hcpp.owner_table_name(+) = 'HZ_PARTIES'
                  AND hcpp.owner_table_id(+) = hzr.party_id
                  AND hcpp.phone_line_type(+) = 'GEN'
                  AND hcpp.contact_point_type(+) = 'PHONE'
                  AND hcpp.primary_flag(+) = 'Y'
                  AND hcpe.owner_table_name(+) = 'HZ_PARTIES'
                  AND hcpe.owner_table_id(+) = hzr.party_id
                  AND hcpe.contact_point_type(+) = 'EMAIL'
                  AND hcpe.primary_flag(+) = 'Y'
                  AND (hcpe.status IS NULL OR hcpe.status IN ('A', 'I'))
                  AND hcpf.owner_table_name(+) = 'HZ_PARTIES'
                  AND hcpf.owner_table_id(+) = hzr.party_id
                  AND hcpf.contact_point_type(+) = 'PHONE'
                  AND hcpf.phone_line_type(+) = 'FAX'
                  AND (hcpf.status IS NULL OR hcpf.status IN ('A', 'I'))
                  AND (hcpp.status IS NULL OR hcpp.status IN ('A', 'I'))

         ORDER BY hzr.end_date DESC;

8. Supplier site contact details:

SELECT hp.person_last_name || ' ' || hp.person_first_name
                     contact_name,
                  hcpe.email_address,
                  LTRIM (
                     RTRIM (hcpp.phone_area_code || ' ' || hcpp.phone_number))
                     AS primary_phone_number,
                  LTRIM (
                     RTRIM (hcpf.phone_area_code || ' ' || hcpf.phone_number))
                     fax_number,
                  hzr.end_date,
                  hzr.last_update_date
             FROM hz_parties hp,
                  hz_party_sites hps,
                  hz_relationships hzr,
                  ap_supplier_contacts ascs,
                  hz_party_usg_assignments hpua,
                  hz_contact_points hcpp,
                  hz_contact_points hcpe,
                  hz_contact_points hcpf
            WHERE     1 = 1
                  AND NVL (hps.end_date_active, SYSDATE) >= SYSDATE
                  AND hzr.relationship_type = 'CONTACT'
                  AND hzr.relationship_code = 'CONTACT_OF'
                  AND hzr.subject_type = 'PERSON'
                  AND hzr.subject_table_name = 'HZ_PARTIES'
                  AND hzr.object_type = 'ORGANIZATION'
                  AND hzr.object_table_name = 'HZ_PARTIES'
                  AND hzr.status = 'A'
                  AND hps.party_id = hzr.object_id
                  AND hps.party_site_id = p_supplier_party_site_id
                  AND hzr.relationship_id = ascs.relationship_id
                  AND hzr.party_id = ascs.rel_party_id
                  AND hps.party_site_id = ascs.org_party_site_id
                  AND hzr.subject_id = ascs.per_party_id
                  AND hp.party_id = hzr.subject_id
                  AND hpua.party_id = hp.party_id
                  AND hpua.status_flag IN ('A', 'I')
                  AND hpua.party_usage_code = 'SUPPLIER_CONTACT'
                  AND hcpp.owner_table_name(+) = 'HZ_PARTIES'
                  AND hcpp.owner_table_id(+) = hzr.party_id
                  AND hcpp.phone_line_type(+) = 'GEN'
                  AND hcpp.contact_point_type(+) = 'PHONE'
                  AND hcpp.primary_flag(+) = 'Y'
                  AND hcpe.owner_table_name(+) = 'HZ_PARTIES'
                  AND hcpe.owner_table_id(+) = hzr.party_id
                  AND hcpe.contact_point_type(+) = 'EMAIL'
                  AND hcpe.primary_flag(+) = 'Y'
                  AND (hcpe.status IS NULL OR hcpe.status IN ('A', 'I'))
                  AND hcpf.owner_table_name(+) = 'HZ_PARTIES'
                  AND hcpf.owner_table_id(+) = hzr.party_id
                  AND hcpf.contact_point_type(+) = 'PHONE'
                  AND hcpf.phone_line_type(+) = 'FAX'
                  AND (hcpf.status IS NULL OR hcpf.status IN ('A', 'I'))
                  AND (hcpp.status IS NULL OR hcpp.status IN ('A', 'I'))
         ORDER BY hzr.end_date DESC;

9. Bank account owner details:

SELECT hp.party_name, iba.last_update_date
             FROM iby_account_owners iba, hz_parties hp
            WHERE     iba.ext_bank_account_id = p_bank_account_id
                  AND iba.account_owner_party_id = hp.party_id
         ORDER BY NVL (primary_flag, 'N') DESC;

10. Supplier Bank Details:

SELECT s.segment1 supplier_number,
                hps.attribute1 legacy_supplier_number,
                ss.vendor_site_code supplier_site_code,
                ss.org_id operating_unit,
                ss.vendor_site_id supplier_site_id,
                s.party_id party_id,
                ib_pmt_instr.order_of_preference priority_number,
                ib_pmt_instr.start_date,
                ib_pmt_instr.end_date,
                ib_pmt_instr.last_update_date instr_last_update_date -- bank account details
                                                                    ,
                bank_ac.bank_account_num bank_account_number,
                bank_ac.ext_bank_account_id bank_account_id,
                bank_ac.bank_account_name payee,
                bank_ac.last_update_date bank_ac_last_update_date -- bank branch details
                                                                 ,
                bank_branch.bank_branch_name_alt supp_bank_name,
                bank_branch.branch_number supp_bank_branch_num,
                bank_branch.bank_number supp_bank_num,
                   bank_branch.address_line1
                || ','
                || bank_branch.address_line2
                || ','
                || bank_branch.address_line3
                || ','
                || bank_branch.address_line4
                || ','
                || bank_branch.city
                || ','
                || bank_branch.state
                   supp_bank_branch_address,
                bank_branch.eft_swift_code swift_code
           FROM ap_suppliers s,
                ap_supplier_sites_all ss,
              
                hz_party_sites hps,
                iby_external_payees_all ib_xt_payee,
                iby_pmt_instr_uses_all ib_pmt_instr,
                iby_ext_bank_accounts bank_ac,
                ce_bank_branches_v bank_branch
          WHERE     1 = 1
                AND ss.org_id =  <<g_org_id>>
                AND s.vendor_id = ss.vendor_id
                AND hps.party_site_id = ss.party_site_id
                AND ib_xt_payee.supplier_site_id = ss.vendor_site_id
                AND ib_xt_payee.payee_party_id = hps.party_id
                AND ib_pmt_instr.ext_pmt_party_id = ib_xt_payee.ext_payee_id
                AND ib_pmt_instr.instrument_type = 'BANKACCOUNT'
                AND ib_pmt_instr.instrument_id = bank_ac.ext_bank_account_id
                AND bank_ac.branch_id = bank_branch.branch_party_id(+)

11. Banks at Supplier Site Level:

SELECT s.segment1 supplier_number,
                hps.attribute1 legacy_supplier_number,
                ss.vendor_site_code supplier_site_code,
                ss.org_id operating_unit,
                ss.vendor_site_id supplier_site_id,
                s.party_id party_id,
                ib_pmt_instr.order_of_preference priority_number,
                ib_pmt_instr.start_date,
                ib_pmt_instr.end_date,
                ib_pmt_instr.last_update_date instr_last_update_date -- bank account details
                                                                    ,
                bank_ac.bank_account_num bank_account_number,
                bank_ac.ext_bank_account_id bank_account_id,
                bank_ac.bank_account_name,
                bank_ac.last_update_date bank_ac_last_update_date -- bank branch details
                                                                 ,
                bank_branch.bank_branch_name_alt supp_bank_name,
                bank_branch.branch_number supp_bank_branch_num,
                bank_branch.bank_number supp_bank_num,
                   bank_branch.address_line1
                || ','
                || bank_branch.address_line2
                || ','
                || bank_branch.address_line3
                || ','
                || bank_branch.address_line4
                || ','
                || bank_branch.city
                || ','
                || bank_branch.state
                   supp_bank_branch_address,
                bank_branch.eft_swift_code swift_code
           FROM ap_suppliers s,
                ap_supplier_sites_all ss,              
                hz_party_sites hps,
                iby_external_payees_all ib_xt_payee,
                iby_pmt_instr_uses_all ib_pmt_instr,
                iby_ext_bank_accounts bank_ac,
                ce_bank_branches_v bank_branch
          WHERE     1 = 1
                
                AND ss.org_id = <<g_org_id>>
                AND s.vendor_id = ss.vendor_id
                AND hps.party_site_id = ss.party_site_id
                AND ib_xt_payee.supplier_site_id IS NULL
                AND ib_xt_payee.payee_party_id = hps.party_id
                AND ib_pmt_instr.ext_pmt_party_id = ib_xt_payee.ext_payee_id
                AND ib_pmt_instr.instrument_type = 'BANKACCOUNT'
                AND ib_pmt_instr.PAYMENT_FUNCTION = 'PAYABLES_DISB'
                AND ib_pmt_instr.instrument_id = bank_ac.ext_bank_account_id
                AND bank_ac.branch_id = bank_branch.branch_party_id(+)
                AND NOT EXISTS
                       (SELECT 'Y'
                          FROM iby_external_payees_all ib_xt_payee,
                               iby_pmt_instr_uses_all ib_pmt_instr
                         WHERE     ib_xt_payee.supplier_site_id =
                                      ss.vendor_site_id
                               AND ib_pmt_instr.ext_pmt_party_id =
                                      ib_xt_payee.ext_payee_id
                               AND ib_pmt_instr.instrument_type =
                                      'BANKACCOUNT');