Saturday, September 6, 2014

GL API: How to insert Journal Entries using Interface tables (Real Example)

DECLARE
   l_iface_run_id           NUMBER;
   v_to_currency_code       VARCHAR2 (10);
   v_chart_of_accounts_id   NUMBER;
   v_set_of_books_id        NUMBER;



   l_grp_id                 NUMBER;
   v_req_id                 NUMBER;
   v_wait_for_request       BOOLEAN;
   v_request_number         NUMBER;
   v_request_phase          VARCHAR2 (500);
   v_request_status         VARCHAR2 (500);
   v_request_dev_phase      VARCHAR2 (500);
   v_request_message        VARCHAR2 (1000);
BEGIN
   SELECT gl_journal_import_s.NEXTVAL
     INTO l_iface_run_id
     FROM DUAL;
   INSERT INTO gl_interface
               (status, set_of_books_id, accounting_date,
                currency_code, date_created, created_by, actual_flag,
                user_je_category_name, user_je_source_name,
                currency_conversion_date, encumbrance_type_id,
                budget_version_id, user_currency_conversion_type,
                currency_conversion_rate, average_journal_flag, segment1,
                segment2, segment3, segment4, segment5, segment6,
                segment7, segment8, segment9, segment10, segment11,
                segment12, segment13, segment14, segment15, segment16,
                segment17, segment18, segment19, segment20, segment21,
                segment22, segment23, segment24, segment25, segment26,
                segment27, segment28, segment29, segment30, entered_dr,
                entered_cr, accounted_dr, accounted_cr, transaction_date,
                reference1, reference2, reference3, reference4, reference5,
                reference6, reference7, reference8, reference9, reference10,
                reference11, reference12, reference13, reference14,
                reference15, reference16, reference17, reference18,
                reference19, reference20, reference21, reference22,
                reference23, reference24, reference25, reference26,
                reference27, reference28, reference29, reference30,
                je_batch_id, period_name, je_header_id, je_line_num,
                chart_of_accounts_id, functional_currency_code,
                code_combination_id, date_created_in_gl, warning_code,
                status_description, stat_amount, GROUP_ID, request_id,
                subledger_doc_sequence_id, subledger_doc_sequence_value,
                attribute1, attribute2, attribute3, attribute4, attribute5,
                attribute6, attribute7, attribute8, attribute9, attribute10,
                attribute11, attribute12, attribute13, attribute14,
                attribute15, attribute16, attribute17, attribute18,
                attribute19, attribute20, CONTEXT, context2, invoice_date,
                tax_code, invoice_identifier, invoice_amount, context3,
                ussgl_transaction_code, descr_flex_error_message,
                jgzz_recon_ref, originating_bal_seg_value, gl_sl_link_id,
                gl_sl_link_table, reference_date
               )
        VALUES ('NEW', v_set_of_books_id, i.accounting_date,
                v_to_currency_code, SYSDATE, fnd_global.user_id, 'A',
                'Payables', 'Payables',
                NULL, NULL,
                NULL, NULL,
                NULL, NULL, i.segment1,
                i.segment2, i.segment3, i.segment4, i.segment5, i.segment6,
                NULL, NULL, NULL, NULL, NULL,
                NULL, NULL, NULL, NULL, NULL,
                NULL, NULL, NULL, NULL, NULL,
                NULL, NULL, NULL, NULL, NULL,
                NULL, NULL, NULL, NULL, 999,
                                           --DECODE (i.dr_cr, 'DB', i.amount),
                999,                       --DECODE (i.dr_cr, 'CR', i.amount),
                    999,                   --DECODE (i.dr_cr, 'DB', i.amount),
                        999,               --DECODE (i.dr_cr, 'CR', i.amount),
                            SYSDATE,
                NULL,                                             --Reference1
                     NULL, NULL, NULL,                            --Reference4
                                      NULL,
                NULL, NULL, NULL, NULL, NULL,
                NULL, NULL, NULL, NULL,
                NULL, NULL, NULL, NULL,
                NULL, NULL, NULL, NULL,
                NULL, NULL, NULL, NULL,
                NULL, NULL, NULL, NULL,
                NULL, NULL, NULL, i.je_line_num,
                v_chart_of_accounts_id, NULL,
                NULL, NULL, NULL,
                NULL, NULL, l_iface_run_id,   --i.GROUP_ID, --Needs to discuss
                                           NULL,
                NULL, NULL,
                NULL, NULL, NULL, NULL, NULL,
                NULL, NULL, NULL, NULL, NULL,
                NULL, NULL, NULL, NULL,
                NULL, NULL, NULL, NULL,
                NULL, NULL, NULL, SYSDATE, NULL,
                NULL, NULL, NULL, NULL,
                NULL, NULL,
                NULL, NULL, NULL,
                NULL, SYSDATE
               );
   COMMIT;
-- Run Journal Import here.
   IF (v_req_id = 0)
   THEN
/* HANDLE SUBMISSION ERROR */
      fnd_message.raise_error;
   END IF;
   fnd_file.put_line (fnd_file.LOG, 'Group ID : ' || TO_CHAR (l_grp_id));
   fnd_file.put_line (fnd_file.LOG,
                      'Interface Run ID: ' || TO_CHAR (l_iface_run_id)
                     );
   COMMIT;
END;