SELECT gjl.effective_date jrnl_effective_date
,gjh.doc_sequence_value jrnl_doc_seq_num
,gjs.user_je_source_name jrnl_source
,&gc_int_doc_num internal_doc_num
,fnd_flex_xml_publisher_apis.process_kff_combination_1('flex_select', 'SQLGL', 'GL#', gcc.CHART_OF_ACCOUNTS_ID, NULL, gcc.CODE_COMBINATION_ID, 'ALL', 'Y', 'VALUE') acct
,gjl.entered_cr jrnl_line_ent_cr
,gjl.entered_dr jrnl_line_ent_dr
,gjl.accounted_cr jrnl_line_cr
,gjl.accounted_dr jrnl_line_dr
,gjh.currency_code jrnl_currency_code
,gjc.user_je_category_name jrnl_category
,gjb.name batch_name
,gjh.name jrnl_name
,gjl.je_line_num jrnl_line_number
,gjl.description jrnl_line_desc
FROM gl_je_headers gjh
,gl_je_lines gjl
,gl_je_sources gjs
,gl_je_categories gjc
,gl_je_batches gjb
,gl_code_combinations gcc
,gl_period_statuses gps
WHERE gcc.code_combination_id = gjl.code_combination_id
AND gjl.je_header_id = gjh.je_header_id
AND gjh.je_source = gjs.je_source_name
AND gjh.je_category = gjc.je_category_name
AND gjh.je_batch_id = gjb.je_batch_id
AND fnd_flex_xml_publisher_apis.process_kff_combination_1('flex_account', 'SQLGL', 'GL#', gcc.CHART_OF_ACCOUNTS_ID, NULL, gcc.CODE_COMBINATION_ID, 'GL_ACCOUNT', 'N', 'VALUE') = :ACCT_VALUE
AND &FLEX_OWNER = :ADDITIONAL_SEGMENT_VALUE1
AND NVL(&FLEX_SUBORD,-1) = NVL(:ADDITIONAL_SEGMENT_VALUE2,-1)
AND gjh.period_name = gps.period_name
AND gjh.ledger_id = gps.ledger_id
AND gjh.je_header_id = gjl.je_header_id
AND gjh.ledger_id = :LEDGER_ID_PARAM
AND gjh.actual_flag = :BALANCE_TYPE_PARAM
AND (gjl.accounted_dr IS NOT NULL
OR gjl.accounted_cr IS NOT NULL)
AND (gjl.accounted_dr <> 0
OR gjl.accounted_cr <> 0)
AND gps.application_id = 101
AND gjh.status = 'P'
AND gjb.average_journal_flag = 'N'
AND gcc.chart_of_accounts_id = :COA_ID_PARAM
AND :PRINT_JRNL_DETAIL_PARAM = 'Y'
AND gps.effective_period_num BETWEEN &gc_per_eff_from_num
AND &gc_per_eff_to_num
AND &GC_DAS_JE_WHERE
AND &GC_CURRENCY_WHERE
AND &GC_BALANCE_WHERE
AND &FLEX_WHERE |