ImpScipts For Oracle Apps
ImpScipts For Oracle Apps
Given SQL is to fetch the files details uploaded through XML Publisher Administrator Responsibility
SELECT
a.application_short_name,
 a.data_source_code,
 b.lob_code,
 b.lob_type,
 b.file_name,
 b.last_update_date
FROM
  XDO_DS_DEFINITIONS_VL a,
  XDO_LOBS b
WHERE a.data_source_code =b.lob_code
AND a.application_short_name=’XXXXX’
AND a.data_source_code     =:ConCurrentProgram or Data Defintion Code;
Requirement is to have any import method for XML publisher supporting files i.e.
       Data Template file (XML file)
       Bursting Control File (XML file)
       Template (RTF file)
Resolution
XDOLoader is the standard OA utility to suffice this requirement. This is similar to unix based FNDLOAD utility and
should be run from server with all parameters.
Syntex
       java oracle.apps.xdo.oa.util.XDOLoader
       MODE                                             UPLOAD/DOWNLOAD
       –DB_USERNAME                                    apps user name
–DB_PASSOWRD                                apps password
–JDBC_CONNECTION                           jdbc connection string
–LOB_TYPE                                   TEMPLATE_SOURCE/
                                               DATA_TEMPLATE/
                                               BURSTING_FILE
–APPS_SHORT_NAME                            xxxxx
–LOB_CODE                                     Data definition Code
–LANGUAGE                                   en
–XDO_FILE_TYPE                              RTF/XML-DATA-TEMPLATE
                                               /XML-BURSTING-FILE
[–CUSTOM_MODE]                               FORCE
[–LOG_FILE]                                  log file name
[-DEBUG]                                      true/false
    Solution – Data template also provides same flexibilities to list down queries in multiple sections and connect them
    as parent child relationship.
    There are two approached available to join multiple queries in data template.
       Bind variable
       Data link method
    Bind Variable most efficient and faster option. Identify the common column in parent query and use it as bind
    variable in child queries.
    <dataQuery>
    <sqlstatement name="Q1_USER">
    <![CDATA[
    SELECT user_id BIND_USER_ID ,user_name From fnd_user
    ]]>
    </sqlstatement>
    <sqlstatement name="Q2_RESP">
    <![CDATA[
    SELECT responsibility_id From fnd_user_resp_groups WHERE user_id=: BIND_USER_ID
    ]]>
    </sqlstatement>
    </dataQuery>
    Data Link is another way to establish the relationship between multiple queries
    <link name="USER_RESP_LINK" parentQuery="Q1_USER" parentColumn="user_id" childQuery="Q2_RESP"
    childColumn="user_id" condition="Q1_USER.user_id= Q2_RESP.user_id" />
    XML Output
<?xml version="1.0" encoding="UTF-8" ?>
< XXXOALEARNING >
<P_CUSTOMER/>100 </P_CUSTOMER/>
<LIST_G_USER>
<G_USER>
 <USERID>100</USERID>
 <USERNAME>Sandeep</USERNAME>
       <LIST_G_RESP>
       <G_RESP>
       <RESPONSIBILITY_ID>1010</ RESPONSIBILITY_ID >
       <RESPONSIBILITY_ID>1020</ RESPONSIBILITY_ID >
       </G_RESP>
       <LIST_G_RESP>
</G_USER>
<G_USER>
 <USERID>200</USERID>
 <USERNAME>Deepak</USERNAME>
       <LIST_G_RESP>
       <G_RESP>
       <RESPONSIBILITY_ID>1010</ RESPONSIBILITY_ID >
       <RESPONSIBILITY_ID>1030</ RESPONSIBILITY_ID >
       </G_RESP>
       <LIST_G_RESP>
</G_USER>
</LIST_G_USER>
</ XXXOALEARNING >
Options – Instead of creating table in MS word manually, we can use BI publisher desktop utility to insert table in
RTF file.
Table will be created with all column and respective place holders.
Solution – There is several options available to generate XML tags, intend as source for BI/XML publisher reports in
EBS. One among those is use of data template.
Data Template is an xml file having predefined set of tags. Create a data template file and attach file at (XML
Publisher Administrator (R) >> Data Definition >> Add Files >> Data Template)
                                <Parameters>
 Parameter                         <parameter name="p_param1" datatype="number"/>
 Section                        </Parameters>
 Data Trigger          <dataTrigger name="afterParameter"
                       source="T1.afterParameterFunction"/>
                       <dataTrigger name="beforeReport"
                       source="T1.beforeReportFunction"/>
</dataTemplate>
Template >> Create a new template and attach the layout (RTF) file
    For example - Report is having 3 invoices, 2 for one supplier and 1 for second. concurrent
    program will generate one file as output having all 3 invoice detail.
    Project need is to split output either on 3 files (one for each invoice) or 2 files ( for 2
    supplier).
    XML bursting concept help us to cut down the generated output in multiple pieces based on
    requirement.
    Also we can send output through email using this service.
      <xapi:request select="/XXXXX/LIST_G_SUPPLIER_NO/G_SUPPLIER_NO">
<xapi:delivery>
</xapi:document>
</xapi:request></xapi:requestset>
   *${XML_TAG_NAME}
   Request – Describe group level, on which bursting is required. In above example bursting
   will be on G_SUPPLIER_NO level
   Delivery – How to send the split data ( Email, Fax, Printer etc).
   Document output – Subject and format of output
   Template Type – Related template information. Location can have temp directory path
   ( make sure your rtf file is placed at temp directory too) too or use the above syntax only.
   ***en is the territory code.Either use the correct territory code or upload rtf file without territory
   name.
         XML publisher responsibility >> Data Definition >> Search for your Data Definition
   >> Bursting Control file >> Add File
    4)Invoke Bursting Concurrent Program – XDOBURSTREP is oracle provided standard
    concurrent program for bursting. Invoke this concurrent program in your program at the
    last.
      This will read the instructions given in control file and perform bursting.
    l_request_id := FND_REQUEST.SUBMIT_REQUEST (
       'XDO',
       'XDOBURSTREP',
       'XML Publisher Report Bursting Program',
       '',
       FALSE,
       'N',
       fnd_global.conc_request_id, 'Y',
       chr(0), '', '', '', '', '', '',
       '', '', '', '', '', '', '', '', '', '',
       '', '', '', '', '', '', '', '', '', '',
       '', '', '', '', '', '', '', '', '', '',
       '', '', '', '', '', '', '', '', '', '',
       '', '', '', '', '', '', '', '', '', '',
       '', '', '', '', '', '', '', '', '', '',
       '', '', '', '', '', '', '', '', '', '',
       '', '', '', '', '', '', '', '', '', '',
       '', '', '', '', '', '', '', '', '', '');
    Different Header and Footer for First Page - XML Publisher Report
    Requirement was to report invoice details in xml publisher in PDF format. If there is multiple pages for any invoice, it should
    show different header details.
    In rtf it is very easily achievable using MS word features.
   1)     Open the rtf file
   2)   Go Header & Footer section
   3)   Check the flag “Different First Page”
   4)   Write the Header/footer Details
   5)   Go to the second page (if rtf has only one page, put some line space to reach second page)
   6)   Create second header/footer details
   7)   Remove the extra line space created in step 5
   8)   Load the data source
   9)   Preview the output
    1) Leading zero issue - Invoice number can have leading zeros ("000INV1").Reporting any invoice number field in
    excel format can not preserve the leading zeros and display only "INV1".
==========================================================================
3) OPP service failure - This issue occurs during concurrent program execution and most frequently while CP is
generating any xml report and program will end in warning.
Solution - Check with DBA and ask to up the OPP service if down or check your template. there will be few garbage
character available in template, which is causing the issue.(For more details check - OPP Service post)
SELECT REQUEST_ID,
 FU.USER_NAME,
 USER_CONCURRENT_PROGRAM_NAME,
 DECODE(PHASE_CODE,'C','Completed','R','Running','E','Error','P','Pending','Other') PHASE,
DECODE(STATUS_CODE,'C','Normal','E','Error','G','Warning','X','Terminated','Q','Sacheduled',STATUS_CODE)STA
TUS ,
 TO_CHAR(ACTUAL_START_DATE,'DD-MON-YYYY HH24:MI:SS') STARTED_AT,
 TO_CHAR(ACTUAL_COMPLETION_DATE,'DD-MON-YYYY HH24:MI:SS') ENDS_ON,
 ROUND((NVL(ACTUAL_COMPLETION_DATE,SYSDATE)-ACTUAL_START_DATE)*24*60) "Duration (mins)",
 argument_text
FROM FND_CONC_REQ_SUMMARY_V FCR,
 FND_USER FU
WHERE FCR.REQUESTED_BY=FU.USER_ID
AND PROGRAM_SHORT_NAME LIKE ( 'XXXXX%')
ORDER BY NVL(ACTUAL_START_DATE,SYSDATE-1000) DESC
Available Options – XML publisher is one frequently used solution, which has capability to display output in PDF,
EXCEL and RTF formats. EXCEL file generated using xml processing is having more size compare to actuals.
Solution – This post is to discuss another way to generate output file in EXCEL format without using XML publisher.
A small setup change is required.
             1. Create a concurrent program having PL/SQL as executable
             2. Select the output type as any available option (ex - PCI)
             3. Print the output using FND_FILE.PUT_LINE(FND_FILE.OUTPUT,’Output Message’);
              4.   Change the Mime type(view option) as EXCEL for PCL file format
Resolution – There are multiple options available to notify the output via email. Some of those are as below -
      Each program requires, additional effort/custom programs to achieve the emailing feature. In this post we shall learn
     the options already available in system. Which need small configuration change and CP will send the o/p as email.
      Steps :-
1)   Configuration Change – 2 profile needs to be set.
    FND: SMTP Host >> This to store the smtp server host details
    FND: SMTP Host >> This to store the smtp server port details
3) Go to Email tab
4) Provide the To/From email address and Subject line, then press OK (B)
5) Submit/Schedule the program
   Email bursting should be better approach, if we are working with XML publisher report.
   Program will send the output file to specified email address. Program log file can be referenced in case any issue
   occurred.
    Solution - Below is one possible option which provides the same behavior in other way.
    This requires one additional parameter as Selection/Choice which will decide the enabled parameter.
    There will be as many dummy (non displayed) parameters as required parameters in program. actual
    parameters will be dependent on respective dummy parameters.
Dummy parameters will be dependent on selection parameters and hold values based on selection.
   Example - User requires 2 parameters supplier number and name to be available on one report and
   only one should be selected at time. So the requirement was to make other disable. dependent
   parameters has limitations and it cannot flow bottom to top. we can achieve this by introducing one
   selection parameter, which can hold 2 values -
1)   Name – Supplier Name
2)   Number – Supplier Number
Initially both Supplier Number and Name range parameter will be disabled.
Now include the below condition for Number and Supplier Value set definition –
       Supplier Number Value set - :$FLEX$.VS1='Y'
       Supplier Name Value set      - :$FLEX$.VS2='Y'
Solution – We can use below script to add custom program to respective request group
    DECLARE
    BEGIN
    FND_PROGRAM.add_to_group
    (
           PROGRAM_SHORT_NAME =>'XX_MANAGERS'
          ,PROGRAM_APPLICATION =>'AR'
          ,REQUEST_GROUP => 'Receivables All'
          ,GROUP_APPLICATION =>'AR'
    );
COMMIT;
    EXCEPTION
    WHEN OTHERS THEN
          dbms_output.put_line('Object already exists');
    END ;
    /
    Solution – This can be easily achieved if we create a custom table having invoice status values along with one
    additional column to map Email options value.
- Assign this program to any request group and validate the results
    Output Validation – Run the program and change the Email option values Yes and No.
Concurrent Program Parameter Validation
Requirement – Input should be in specific format for one parameter. Let’s say we have one free text parameter
(email) which must be ended with “@OLearning.com” .
It should not accept if email is not having @OLearning.com at end
How to Achieve -
        Create one value set of validation type = Special
Validation –
Go to respective responsibility
Run the concurrent program
Pass the email parameter = sandeep@gmail.com and tab out
Value for the Flexfield Segment does not Exist in the Value Set
Defining a value set on any DFF will disallow to search records having non eligible (out of value set range) segment
values.
A good example of this is to create a DFF of segment project task name. Initially associate a value set of Table type
which shows all tasks from pa_tasks_all.
We create some records using assigned DFF. After sometime update value set definition to restrict disabled/end
dated tasks.
Now search for records which has been created earlier and having disabled tasks assigned. Oracle form will throw
below error message –
      Current condition –
      WHERE sysdate between start_date and nvl(completion_date,sysdate)
       Updated Condition –
       WHERE (sysdate between start_date and nvl(completion_date,sysdate))
                     OR
                     (nvl(:$PROFILES$.XXXXX_SANDEEP_PRF,'Y')='N')
  3) Use form personalization to change the profile value in cache in search and edit mode
  4) Set the profile value =Y, when in Edit mode. This will fail the second condition and only first
         condition will be valid and so only active task will appear in LOV.
      Set the profile value = N when in search mode. First condition will be failed since task is
         end dated but profile condition will pass and so record will appear without error.
  5) Did not try this in same form. We have created 2 form functions ( Entry (profile Y) and
      Enquiry (profile N) mode)
Syntex -
SELECT * FROM (
SELECT ColumnA,ColumnB,ColumnC,ColumnD
FROM TABLE_NAME
WHERE conditions)
PIVOT ( groupFunction(ColumnD) FOR ColumnC in (Values of ColumnC))
Example- assume we have employee expense details for each month. Now requirement is to
generate a report which will display each employee’s monthly expenses in column.
To obtain monthly basis expense amount, we used to write below group by code -
SELECT name,
     dept,
     month,
     SUM (amount)
 FROM test_sandeep
GROUP BY name, dept, month
--User Details
select * from FND_USER where user_name = :name
PS – Post intention is to be familiar with HRMS Tables name, below written script can be used by
adding additional filter conditions to filter inactive records.
       TRUNC(effective_start_date) <= TRUNC(SYSDATE)
              AND      TRUNC(effective_end_date) > TRUNC(SYSDATE)
File Handling using PL/SQL - UTL_FILE
Intention of this post is to list out different exceptions being raised while using UTL_FILE.
DECLARE
 p_file_path VARCHAR2 (200);
 p_file_handle UTL_FILE.FILE_TYPE;
 p_data_file VARCHAR2 (200);
BEGIN
 p_data_file := 'SANDEEP_UTLFILE_TEST.txt';
 p_file_path := 'SANDEEP_DIR';
/**********************************************************************************
  p_file_path                >> Location where data file being placed
  p_data_file                >> Data file name
 ‘W’                       >> Operation Mode
                                'W' indicates write mode ,
                                 'R' indicates read mode ,
                                 'A' indicates Append mode
  32767                     >> Length of the string. 32767 is the max length.
**********************************************************************************/
  UTL_FILE.PUT_LINE (p_file_handle, 'Sandeep is working on UTL File Demo');
  // WRITE into FILE
-- UTL_FILE.FFLUSH(p_file_handle);
-- FFLUSH will write all buffer contents, useful if contents are larger in size.
EXCEPTION
END;
Resolution - Check the Database connection and re connect. This error is because of Database disconnection.
     Solution - Workflow files (with extension .wft) are being stored in database and it can be upload (to) or download
     (from) database using below 2 methods.
1)    Standard Concurrent Program
2)    WFLOAD Utility
     Standard Concurrent Program – Run the program Workflow Definitions Loader using sysadmin responsibility
     (you can add this program to any of responsibility and run from there).
     This program has 3 parameters as below
1)    Mode – Upload/Download
2)    File - /staging/sandeep/Project/PAPROWF.wft
             (wft file name with Full Path. Make sure file is available at given path for UPLOAD Mode)
3)    Item Type – Item type Name for above file (This can be get from workflow builder. Open your wft file in workflow
     builder and create any process. The first attribute will be Item Type Name)
4)
     WFLOAD Utility – similar to FNDLOAD utility used for LDT files, oracle has provided WFLOAD for workflow files.
     Below are the available options -
              To upgrade        - WFLOAD apps/pwd 0 Y UPGRADE filename.wft
              To upload         - WFLOAD apps/pwd 0 Y UPLOAD filename.wft
      To force     - WFLOAD apps/pwd 0 Y FORCE filename.wft
      To download - WFLOAD apps/pwd 0 Y DOWNLOAD filename.wft ITEMTYPE1
[ITEMTYPE2 ... ITEMTYPEN]
SLA or XLA(AP-GL,RECEIPT-GL,AR-GL)(SubledgerAccounting)
SELECT DISTINCT PS.PERIOD_NAME,
GJL.REFERENCE_2,
TO_CHAR (NULL) PO_ORDER_NUMBER,
TO_CHAR (NULL) "RECEIPT NUMBER",
TO_DATE (NULL) "RECEIPT DATE",
TO_CHAR (NULL) "INVOICE NUMBER",
TO_DATE (NULL) "INVOICE DATE",
TO_CHAR (NULL) "VENDOR NAME",
TO_CHAR (NULL) "VENDOR NUMBER",
JE_SOURCE "SOURCE",
GJH.LEDGER_ID "SET_OF_BOOKS_ID" ,
FND_FLEX_EXT.GET_SEGS('SQLGL','GL#',GSCV.CHART_OF_ACCOUNTS_ID,
GSCV.CODE_COMBINATION_ID) SEGMENT,
FND_FLEX_EXT.GET_SEGS('SQLGL','GL#',GSCV.CHART_OF_ACCOUNTS_ID,
GSCV.CODE_COMBINATION_ID) SEGMENT2,
GJH.CURRENCY_CODE,
GJL.ENTERED_DR ,
GJL.ENTERED_CR,
TO_NUMBER(DECODE ( LR.RELATIONSHIP_TYPE_CODE, 'BALANCE', NULL, GJL.ACCOUNTED_DR ))
ACCOUNTED_DR,
TO_NUMBER(DECODE ( LR.RELATIONSHIP_TYPE_CODE, 'BALANCE', NULL, GJL.ACCOUNTED_CR ))
ACCOUNTED_CR,
GJH.JE_HEADER_ID,
GJL.JE_LINE_NUM,
GJL.CODE_COMBINATION_ID ,
GJH.DOC_SEQUENCE_VALUE "VOCHER NUMBER",
GJH.DEFAULT_EFFECTIVE_DATE GL_DATE,
GJL.ATTRIBUTE1 "STAFF NUMBER",
GJL.ATTRIBUTE2 "PROJECT",
GJL.ATTRIBUTE3 "CUSTOMER NUM/NAME" ,
GJL.DESCRIPTION DESCRIPTION
FROM GL_JE_LINES GJL , GL_JE_HEADERS GJH, GL_SUMMARY_COMBINATIONS_V GSCV,
GL_LEDGERS,GL_PERIOD_STATUSES PS,GL_JE_BATCHES B,
GL_LEDGER_RELATIONSHIPS LR
WHERE GSCV.CODE_COMBINATION_ID =GJL.CODE_COMBINATION_ID
AND GJH.JE_HEADER_ID=GJL.JE_HEADER_ID
AND GJL.PERIOD_NAME        = PS.PERIOD_NAME
AND PS.LEDGER_ID         = GJL.LEDGER_ID
AND B.JE_BATCH_ID        = GJH.JE_BATCH_ID
AND GJH.LEDGER_ID          = LR.SOURCE_LEDGER_ID
AND LR.SOURCE_LEDGER_ID = LR.TARGET_LEDGER_ID
AND B.ACTUAL_FLAG = 'A'
AND B.STATUS || '' = 'P'
AND GJH.CURRENCY_CODE != 'STAT'
AND JE_SOURCE NOT IN ('PAYABLES','COST MANAGEMENT','CONSOLIDATION','RECEIVABLES')
AND GJH.LEDGER_ID = GL_LEDGERS.LEDGER_ID
--- AND GL_LEDGERS.SUSPENSE_ALLOWED_FLAG = 'P'
AND ( NVL (PS.EFFECTIVE_PERIOD_NUM, 0) >= :CF_PERIOD_FROM
AND (NVL (PS.EFFECTIVE_PERIOD_NUM, 0) <= :CF_PERIOD_TO)
)
AND ( NVL (GSCV.SEGMENT5, 0) >= :P_ACCOUNT_FROM
AND (NVL (GSCV.SEGMENT5, 0) <= :P_ACCOUNT_TO)
)
AND ( NVL (GSCV.SEGMENT1, 0) >=:P_COMPANY_FROM
AND (NVL (GSCV.SEGMENT1, 0) <= :P_COMPANY_TO)
)
AND GJH.LEDGER_ID NOT IN ( 1014,1015,1016 )
AND GJH.CURRENCY_CODE =DECODE(:P_CURRENCY_CODE,'INR','INR',
'ALL',GJH.CURRENCY_CODE,
'NON INR',DECODE(GJH.CURRENCY_CODE,'INR','###',GJH.CURRENCY_CODE))
UNION ALL
SELECT
GPS.PERIOD_NAME,
GJL.REFERENCE_2,
(SELECT DISTINCT PHA.SEGMENT1 FROM AP_INVOICE_LINES_ALL AILLA, PO_HEADERS_ALL PHA
WHERE AILLA.INVOICE_ID=AIA.INVOICE_ID AND AILLA.PO_HEADER_ID=PHA.PO_HEADER_ID)
PO_ORDER_NUMBER,
   --AND AIA.ORG_ID=:P_ORG
   AND XAH.JE_CATEGORY_NAME='PURCHASE INVOICES'
   AND ( NVL (GPS.EFFECTIVE_PERIOD_NUM, 0) >=:CF_PERIOD_FROM
   AND (NVL (GPS.EFFECTIVE_PERIOD_NUM, 0) <=:CF_PERIOD_TO)
        )
--      AND 24116=:P_ACCOUNT_FROM
--      AND 24116=:P_ACCOUNT_TO
          AND ( NVL (CC.SEGMENT5, 0) >= :P_ACCOUNT_FROM
      AND (NVL (CC.SEGMENT5, 0) <= :P_ACCOUNT_TO)
     )
UNION ALL
SELECT
        GJH.PERIOD_NAME,
        NULL REFERENCE_2,
        NULL PO_ORDER_NUMBER,
        NULL "RECEIPT NUMBER",
        NULL "RECEIPT DATE",
     ENT.TRANSACTION_NUMBER "INVOICE NUMBER",
     AIA.CHECK_DATE "INVOICE DATE",
     AV.VENDOR_NAME "VENDOR NAME",
     AV.SEGMENT1 "VENDOR NUMBER",
     GJH.JE_SOURCE "SOURCE",
     GJH.LEDGER_ID "SET_OF_BOOKS_ID" ,
     GCCK.CONCATENATED_SEGMENTS SEGMENT,
     GCCK.CONCATENATED_SEGMENTS SEGMENT21,
     AIA.CURRENCY_CODE CURRENCY_CODE
     ,AEL.ENTERED_DR,
     AEL.ENTERED_CR,
     AEL.ACCOUNTED_DR,
     AEL.ACCOUNTED_CR,
     GIR.JE_HEADER_ID,
     GIR.JE_LINE_NUM,
     GCCK.CODE_COMBINATION_ID
     ,GIR.SUBLEDGER_DOC_SEQUENCE_VALUE "VOCHER NUMBER"
     ,AEH.ACCOUNTING_DATE "GL_DATE"
     ,NULL "STAFF NUMBER"
     ,NULL "PROJECT"
     ,NULL "CUSTOMER NUM/NAME"
     ,AEL.DESCRIPTION "DESCRIPTION"
     FROM
     XLA_AE_HEADERS             AEH
    ,XLA_AE_LINES            AEL
    ,XLA_EVENTS              XLE
    ,XLA_EVENT_TYPES_TL           XET
    ,XLA_TRANSACTION_ENTITIES        ENT
    ,GL_LEDGERS              GLG
    ,GL_PERIODS              GLP
    ,XLA_SUBLEDGERS             XLS
    ,GL_CODE_COMBINATIONS_KFV          GCCK
         ,GL_IMPORT_REFERENCES          GIR
     ,GL_JE_LINES            GJL
     ,GL_JE_HEADERS             GJH
     ,GL_JE_BATCHES            GJB
     --,AP_INVOICE_DISTRIBUTIONS_ALL AID
--     ,AP_INVOICE_LINES_ALL AILA
     ,AP_CHECKS_ALL AIA
     ,GL_PERIOD_STATUSES GPS
     ,AP_SUPPLIERS AV
     --,PA_PROJECT_CUSTOMERS_V PPCV
     --,PA_PROJECTS_ALL PPA
      WHERE 1=1
      AND AEH.LEDGER_ID          = GLG.LEDGER_ID
      AND AEL.APPLICATION_ID       = AEH.APPLICATION_ID
      AND AEL.AE_HEADER_ID         = AEH.AE_HEADER_ID
      AND XLE.APPLICATION_ID       = AEH.APPLICATION_ID
       AND XLE.EVENT_ID           = AEH.EVENT_ID
       AND XET.APPLICATION_ID         = XLE.APPLICATION_ID
       AND XET.EVENT_TYPE_CODE           = XLE.EVENT_TYPE_CODE
       AND XET.LANGUAGE             = USERENV('LANG')
       AND ENT.APPLICATION_ID         = AEH.APPLICATION_ID
       AND ENT.ENTITY_ID           = AEH.ENTITY_ID
       AND GLP.PERIOD_NAME            = AEH.PERIOD_NAME
       AND GLP.PERIOD_SET_NAME           = GLG.PERIOD_SET_NAME
       AND XLS.APPLICATION_ID         = AEH.APPLICATION_ID
       AND GCCK.CODE_COMBINATION_ID = AEL.CODE_COMBINATION_ID
       AND AEH.ACCOUNTING_ENTRY_STATUS_CODE <> 'N' AND
AEH.APPLICATION_ID = 200 AND AEH.BALANCE_TYPE_CODE = 'A' AND (
NVL(AEL.ACCOUNTED_CR,0) <> 0
                      OR NVL(AEL.ACCOUNTED_DR,0) <> 0 )
       AND GIR.GL_SL_LINK_ID(+)      = AEL.GL_SL_LINK_ID
       AND GIR.GL_SL_LINK_TABLE(+) = AEL.GL_SL_LINK_TABLE
       AND GJL.JE_HEADER_ID(+)        = GIR.JE_HEADER_ID
       AND GJL.JE_LINE_NUM(+)        = GIR.JE_LINE_NUM
       AND GJH.JE_HEADER_ID(+)         = GIR.JE_HEADER_ID
       AND GJB.JE_BATCH_ID (+)       = GIR.JE_BATCH_ID
       AND DECODE(GJH.JE_HEADER_ID,NULL,'Y',GJH.JE_FROM_SLA_FLAG) IN ('U', 'Y')
       --AND AEL.ACCOUNTING_CLASS_CODE IN ('ITEM
EXPENSE','CASH_CLEARING','LIABILITY','PREPAID_EXPENSE','RTAX','INTRA')
AND ENT.SOURCE_ID_INT_1 = AIA.CHECK_ID
      -- AND AIA.DOC_SEQUENCE_VALUE=GIR.SUBLEDGER_DOC_SEQUENCE_VALUE
       AND AIA.VENDOR_ID=AV.VENDOR_ID
       AND GJH.JE_SOURCE ='PAYABLES'
       AND AEH.JE_CATEGORY_NAME='PAYMENTS'
AND GJH.LEDGER_ID=GPS.LEDGER_ID
 AND 101=GPS.APPLICATION_ID
 AND GPS.SET_OF_BOOKS_ID=GJH.LEDGER_ID
 AND GJH.LEDGER_ID NOT IN ( 1014,1015,1016 )
AND GJH.PERIOD_NAME        = GPS.PERIOD_NAME
 --AND AIA.ORG_ID=:P_ORG
 AND ( NVL (GPS.EFFECTIVE_PERIOD_NUM, 0) >=:CF_PERIOD_FROM
     AND (NVL (GPS.EFFECTIVE_PERIOD_NUM, 0) <=:CF_PERIOD_TO)
         )
           AND ( NVL (GCCK.SEGMENT5, 0) >= :P_ACCOUNT_FROM
     AND (NVL (GCCK.SEGMENT5, 0) <= :P_ACCOUNT_TO)
    )
   AND ( NVL (GCCK.SEGMENT1, 0) >=:P_COMPANY_FROM
     AND (NVL (GCCK.SEGMENT1, 0) <= :P_COMPANY_TO)
    )
    AND AIA.CURRENCY_CODE =DECODE(:P_CURRENCY_CODE,'INR','INR',
                         'ALL',AIA.CURRENCY_CODE,
                         'NON INR',DECODE(AIA.CURRENCY_CODE,'INR','###',AIA.CURRENCY_CODE))
UNION ALL
--ADDED BY MANOHAR
 SELECT GJH.PERIOD_NAME,
      NULL REFERENCE_2,
      NULL PO_ORDER_NUMBER,
      CASE
      WHEN (GJH.JE_CATEGORY IN ('RECEIPTS','MISC RECEIPTS')) THEN
      XTE.TRANSACTION_NUMBER
      ELSE
       NULL
       END "RECEIPT NUMBER",
       CASE
 WHEN (GJH.JE_CATEGORY IN ('RECEIPTS','MISC RECEIPTS')) THEN
 XAH.ACCOUNTING_DATE
 ELSE
  NULL
  END "RECEIPT DATE",
  CASE
  WHEN (GJH.JE_CATEGORY NOT IN ('RECEIPTS','MISC RECEIPTS')) THEN
  XTE.TRANSACTION_NUMBER ELSE
 NULL
 END "INVOICE NUMBER",
 CASE
  WHEN (GJH.JE_CATEGORY NOT IN ('RECEIPTS','MISC RECEIPTS')) THEN
  XAH.ACCOUNTING_DATE
  ELSE
 NULL
 END "INVOICE DATE",
CASE
  WHEN XAL.PARTY_TYPE_CODE = 'S' THEN
   (SELECT          APS.SEGMENT1
       ||'|'||APS.VENDOR_NAME
       ||'|'||HZP.JGZZ_FISCAL_CODE
       ||'|'||HZP.TAX_REFERENCE
       ||'|'||HPS.PARTY_SITE_NUMBER
       ||'|'||HPS.PARTY_SITE_NAME
       ||'|'||NULL
    FROM AP_SUPPLIERS             APS
       ,AP_SUPPLIER_SITES_ALL APSS
       ,HZ_PARTIES           HZP
       ,HZ_PARTY_SITES         HPS
       ,XLA_AE_LINES          AEL2
    WHERE APS.VENDOR_ID              = AEL2.PARTY_ID
     AND HZP.PARTY_ID            = APS.PARTY_ID
     AND APSS.VENDOR_SITE_ID(+) = AEL2.PARTY_SITE_ID
     AND HPS.PARTY_SITE_ID(+) = APSS.PARTY_SITE_ID
     AND AEL2.APPLICATION_ID = XAL.APPLICATION_ID
     AND AEL2.AE_HEADER_ID           = XAL.AE_HEADER_ID
     AND AEL2.AE_LINE_NUM           = XAL.AE_LINE_NUM )
  WHEN (XAL.PARTY_TYPE_CODE = 'C' AND XAL.PARTY_ID IS NOT NULL) THEN
   (SELECT          --HCA.ACCOUNT_NUMBER||'|'||
   HZP.PARTY_NAME
       --||'|'||HZP.JGZZ_FISCAL_CODE
       --||'|'||HZP.TAX_REFERENCE
       --||'|'||HPS.PARTY_SITE_NUMBER
       --||'|'||HPS.PARTY_SITE_NAME
       --||'|'||HZCU.TAX_REFERENCE
    FROM HZ_CUST_ACCOUNTS               HCA
       ,HZ_CUST_ACCT_SITES_ALL HCAS
       ,HZ_CUST_SITE_USES_ALL HZCU
       ,HZ_PARTIES            HZP
       ,HZ_PARTY_SITES          HPS
       ,XLA_AE_LINES           AEL2
    WHERE HCA.CUST_ACCOUNT_ID              = AEL2.PARTY_ID
     AND HZP.PARTY_ID              = HCA.PARTY_ID
     AND HZCU.SITE_USE_ID(+)          = AEL2.PARTY_SITE_ID
     AND HCAS.CUST_ACCT_SITE_ID(+) = HZCU.CUST_ACCT_SITE_ID
     AND HPS.PARTY_SITE_ID(+)          = HCAS.PARTY_SITE_ID
     AND AEL2.APPLICATION_ID           = XAL.APPLICATION_ID
     AND AEL2.AE_HEADER_ID             = XAL.AE_HEADER_ID
     AND AEL2.AE_LINE_NUM             = XAL.AE_LINE_NUM )
  ELSE
   NULL
  END       "VENDOR NAME",
     CASE
     WHEN (XAL.PARTY_TYPE_CODE = 'C' AND XAL.PARTY_ID IS NOT NULL) THEN
       (SELECT             HCA.ACCOUNT_NUMBER
       --||'|'|| HZP.PARTY_NAME
              --||'|'||HZP.JGZZ_FISCAL_CODE
              --||'|'||HZP.TAX_REFERENCE
              --||'|'||HPS.PARTY_SITE_NUMBER
              --||'|'||HPS.PARTY_SITE_NAME
              --||'|'||HZCU.TAX_REFERENCE
         FROM HZ_CUST_ACCOUNTS                HCA
              ,HZ_CUST_ACCT_SITES_ALL HCAS
              ,HZ_CUST_SITE_USES_ALL HZCU
              ,HZ_PARTIES            HZP
              ,HZ_PARTY_SITES          HPS
              ,XLA_AE_LINES           AEL2
        WHERE HCA.CUST_ACCOUNT_ID                = AEL2.PARTY_ID
          AND HZP.PARTY_ID               = HCA.PARTY_ID
          AND HZCU.SITE_USE_ID(+)           = AEL2.PARTY_SITE_ID
          AND HCAS.CUST_ACCT_SITE_ID(+) = HZCU.CUST_ACCT_SITE_ID
          AND HPS.PARTY_SITE_ID(+)           = HCAS.PARTY_SITE_ID
          AND AEL2.APPLICATION_ID            = XAL.APPLICATION_ID
          AND AEL2.AE_HEADER_ID              = XAL.AE_HEADER_ID
          AND AEL2.AE_LINE_NUM              = XAL.AE_LINE_NUM )
     ELSE
      NULL
     END          "VENDOR NUMBER",
     GJH.JE_SOURCE"SOURCE",
     GJH.LEDGER_ID "SET_OF_BOOKS_ID" ,
              CC.CONCATENATED_SEGMENTS SEGMENT,
    CC.CONCATENATED_SEGMENTS SEGMENT21,
     XAL.CURRENCY_CODE CURRENCY_CODE,
     XAL.ENTERED_DR,XAL.ENTERED_CR,
     XAL.ACCOUNTED_DR,XAL.ACCOUNTED_CR,
     GIR.JE_HEADER_ID,
    GIR.JE_LINE_NUM,
    CC.CODE_COMBINATION_ID
    ,GIR.SUBLEDGER_DOC_SEQUENCE_VALUE "VOCHER NUMBER"
    ,XAH.ACCOUNTING_DATE "GL_DATE"
    ,NULL "STAFF NUMBER"
    ,NULL "PROJECT"
    ,NULL "CUSTOMER NUM/NAME"
    ,XAH.DESCRIPTION "DESCRIPTION"
   --AND AIA.ORG_ID=:P_ORG
   --AND XAH.JE_CATEGORY_NAME='PURCHASE INVOICES'
  AND ( NVL (GPS.EFFECTIVE_PERIOD_NUM, 0) >=:CF_PERIOD_FROM
      AND (NVL (GPS.EFFECTIVE_PERIOD_NUM, 0) <=:CF_PERIOD_TO)
        )
--      AND 24116=:P_ACCOUNT_FROM
--      AND 24116=:P_ACCOUNT_TO
          AND ( NVL (CC.SEGMENT5, 0) >= :P_ACCOUNT_FROM
      AND (NVL (CC.SEGMENT5, 0) <= :P_ACCOUNT_TO)
     )