Monday, 23 March 2015

Creating order using oe_order_pub.process_order api in order management

The major difference between 11i API parameter and R12 parameter is Org_Id . In R12 Org_ID as parameter we need to pass it to the API.

DECLARE
   l_return_status                VARCHAR2 (2000);
   l_msg_count                    NUMBER;
   l_msg_data                     VARCHAR2 (2000);
   -- PARAMETERS
   l_debug_level                  NUMBER                                   := 5; -- OM DEBUG LEVEL (MAX 5)
   l_org                          VARCHAR2 (20)                          := '111'; -- OPERATING UNIT
   l_no_orders                    NUMBER                                   := 1; -- NO OF ORDERS
   -- INPUT VARIABLES FOR PROCESS_ORDER API
   l_header_rec                   oe_order_pub.header_rec_type;
   l_line_tbl                     oe_order_pub.line_tbl_type;
   l_action_request_tbl           oe_order_pub.request_tbl_type;
   -- OUT VARIABLES FOR PROCESS_ORDER API
   l_header_rec_out               oe_order_pub.header_rec_type;
   l_header_val_rec_out           oe_order_pub.header_val_rec_type;
   l_header_adj_tbl_out           oe_order_pub.header_adj_tbl_type;
   l_header_adj_val_tbl_out       oe_order_pub.header_adj_val_tbl_type;
   l_header_price_att_tbl_out     oe_order_pub.header_price_att_tbl_type;
   l_header_adj_att_tbl_out       oe_order_pub.header_adj_att_tbl_type;
   l_header_adj_assoc_tbl_out     oe_order_pub.header_adj_assoc_tbl_type;
   l_header_scredit_tbl_out       oe_order_pub.header_scredit_tbl_type;
   l_header_scredit_val_tbl_out   oe_order_pub.header_scredit_val_tbl_type;
   l_line_tbl_out                 oe_order_pub.line_tbl_type;
   l_line_val_tbl_out             oe_order_pub.line_val_tbl_type;
   l_line_adj_tbl_out             oe_order_pub.line_adj_tbl_type;
   l_line_adj_val_tbl_out         oe_order_pub.line_adj_val_tbl_type;
   l_line_price_att_tbl_out       oe_order_pub.line_price_att_tbl_type;
   l_line_adj_att_tbl_out         oe_order_pub.line_adj_att_tbl_type;
   l_line_adj_assoc_tbl_out       oe_order_pub.line_adj_assoc_tbl_type;
   l_line_scredit_tbl_out         oe_order_pub.line_scredit_tbl_type;
   l_line_scredit_val_tbl_out     oe_order_pub.line_scredit_val_tbl_type;
   l_lot_serial_tbl_out           oe_order_pub.lot_serial_tbl_type;
   l_lot_serial_val_tbl_out       oe_order_pub.lot_serial_val_tbl_type;
   l_action_request_tbl_out       oe_order_pub.request_tbl_type;
   l_msg_index                    NUMBER;
   l_data                         VARCHAR2 (2000);
   l_loop_count                   NUMBER;
   l_debug_file                   VARCHAR2 (200);
   l_user_id                      NUMBER;
   l_resp_id                      NUMBER;
   l_resp_appl_id                 NUMBER;
BEGIN
   -- INITIALIZATION REQUIRED FOR R12
   mo_global.set_policy_context ('S', l_org);
   mo_global.init ('ONT');

   -- INITIALIZE DEBUG INFO
   IF (l_debug_level > 0)
   THEN
      l_debug_file := oe_debug_pub.set_debug_mode ('FILE');
      oe_debug_pub.initialize;
      oe_msg_pub.initialize;
      oe_debug_pub.setdebuglevel (l_debug_level);
   END IF;

 
--    INITIALIZE ENVIRONMENT
   fnd_global.apps_initialize (l_user_id, l_resp_id, l_resp_appl_id);
   -- INITIALIZE HEADER RECORD
   l_header_rec := oe_order_pub.g_miss_header_rec;
   -- POPULATE REQUIRED ATTRIBUTES
   l_header_rec.operation := oe_globals.g_opr_create;
   l_header_rec.pricing_date := SYSDATE;
   l_header_rec.cust_po_number := 'TSTPO30';
   l_header_rec.sold_to_org_id := 45928;
   l_header_rec.price_list_id := 29061;
   l_header_rec.ordered_date := SYSDATE;
   l_header_rec.sold_from_org_id := 400674685;
   --l_header_rec.ship_from_org_id := 857545;
   l_header_rec.ship_to_org_id := 416327212;
   l_header_rec.invoice_to_org_id := 401869206;
   l_header_rec.salesrep_id := -3;
   --  l_header_rec.flow_status_code := 'ENTERED';
   l_header_rec.order_type_id := 700203;
   -- INITIALIZE ACTION REQUEST RECORD
   l_action_request_tbl (1) := oe_order_pub.g_miss_request_rec;
   -- INITIALIZE LINE RECORD
   l_line_tbl (1) := oe_order_pub.g_miss_line_rec;
   l_line_tbl (1).operation := oe_globals.g_opr_create; -- Mandatory Operation to Pass
   l_line_tbl (1).inventory_item_id := 4408;
   l_line_tbl (1).ordered_quantity := 1;
   l_line_tbl (1).ship_from_org_id := 1163;
   l_line_tbl (1).subinventory := NULL;

   FOR i IN 1 .. l_no_orders
   LOOP -- BEGIN LOOP
      -- CALLTO PROCESS ORDER API
      oe_order_pub.process_order (
         p_org_id=> l_org,
         --     p_operating_unit           => NULL,
         p_api_version_number=> 1.0,
         p_header_rec=> l_header_rec,
         p_line_tbl=> l_line_tbl,
         p_action_request_tbl=> l_action_request_tbl,
         -- OUT variables
         x_header_rec=> l_header_rec_out,
         x_header_val_rec=> l_header_val_rec_out,
         x_header_adj_tbl=> l_header_adj_tbl_out,
         x_header_adj_val_tbl=> l_header_adj_val_tbl_out,
         x_header_price_att_tbl=> l_header_price_att_tbl_out,
         x_header_adj_att_tbl=> l_header_adj_att_tbl_out,
         x_header_adj_assoc_tbl=> l_header_adj_assoc_tbl_out,
         x_header_scredit_tbl=> l_header_scredit_tbl_out,
         x_header_scredit_val_tbl=> l_header_scredit_val_tbl_out,
         x_line_tbl=> l_line_tbl_out,
         x_line_val_tbl=> l_line_val_tbl_out,
         x_line_adj_tbl=> l_line_adj_tbl_out,
         x_line_adj_val_tbl=> l_line_adj_val_tbl_out,
         x_line_price_att_tbl=> l_line_price_att_tbl_out,
         x_line_adj_att_tbl=> l_line_adj_att_tbl_out,
         x_line_adj_assoc_tbl=> l_line_adj_assoc_tbl_out,
         x_line_scredit_tbl=> l_line_scredit_tbl_out,
         x_line_scredit_val_tbl=> l_line_scredit_val_tbl_out,
         x_lot_serial_tbl=> l_lot_serial_tbl_out,
         x_lot_serial_val_tbl=> l_lot_serial_val_tbl_out,
         x_action_request_tbl=> l_action_request_tbl_out,
         x_return_status=> l_return_status,
         x_msg_count=> l_msg_count,
         x_msg_data=> l_msg_data
      );

      -- CHECK RETURN STATUS
      IF l_return_status = fnd_api.g_ret_sts_success
      THEN
         IF (l_debug_level > 0)
         THEN
            DBMS_OUTPUT.put_line ('Sales Order Successfully Created');
         END IF;

         COMMIT;
      ELSE
         IF (l_debug_level > 0)
         THEN
            DBMS_OUTPUT.put_line ('Failed to Create Sales Order');
         END IF;

         ROLLBACK;
      END IF;
   END LOOP;

   -- DISPLAY RETURN STATUS FLAGS
   IF (l_debug_level > 0)
   THEN
      DBMS_OUTPUT.put_line (
            'Process Order Return Status is: ========>'
         || l_return_status
      );
      DBMS_OUTPUT.put_line (
            'Process Order msg data is: ===========>'
         || l_msg_data
      );
      DBMS_OUTPUT.put_line (
            'Process Order Message Count is:=======>'
         || l_msg_count
      );
      DBMS_OUTPUT.put_line (
            'Sales Order Created is:===============>'
         || TO_CHAR (l_header_rec_out.order_number)
      );
      DBMS_OUTPUT.put_line (
            'Booked Flag for the Sales Order is:======>'
         || l_header_rec_out.booked_flag
      );
      DBMS_OUTPUT.put_line (
            'Header_id for the Sales Order is:========>'
         || l_header_rec_out.header_id
      );
      DBMS_OUTPUT.put_line (
            'Flow_Status_Code For the Sales Order is=>:'
         || l_header_rec_out.flow_status_code
      );
   END IF;

   -- DISPLAY ERROR MSGS
   IF (l_debug_level > 0)
   THEN
      FOR i IN 1 .. l_msg_count
      LOOP
         oe_msg_pub.get (
            p_msg_index=> i,
            p_encoded=> fnd_api.g_false,
            p_data=> l_data,
            p_msg_index_out=> l_msg_index
         );
         DBMS_OUTPUT.put_line (   'message is:'
                               || l_data);
         DBMS_OUTPUT.put_line (   'message index is:'
                               || l_msg_index);
      END LOOP;
   END IF;

   IF (l_debug_level > 0)
   THEN
      DBMS_OUTPUT.put_line (   'Debug = '
                            || oe_debug_pub.g_debug);
      DBMS_OUTPUT.put_line (
            'Debug Level = '
         || TO_CHAR (oe_debug_pub.g_debug_level)
      );
      DBMS_OUTPUT.put_line (
            'Debug File ='
         || oe_debug_pub.g_dir
         || '/'
         || oe_debug_pub.g_file
      );
      oe_debug_pub.debug_off;
   END IF;
END;

Friday, 20 February 2015

How to enable the MOAC parameter “Operating Unit” for a Concurrent Program in Oracle EBS R12

You can notice that the new field “Operating Unit” which is new field in R12 and by default is in disabled mode:-




With the introduction of multi-org access control in release 12, an applications responsibility
can access multiple operating units. Some concurrent programs have been enhanced to process multiple operating units simultaneously, while for other requests the operating unit must be specified when you run the program.

To support this, concurrent programs are defined with an operating unit mode of 'S' for single operating unit or 'M'(concurrent program will be in this mode by default) for multiple operating units. If the 'Operating Unit Mode' is not set for the concurrent program it will fail.
The “Operating Unit” field/parameter is known as “Reporting Context” in MOAC(Multi Org Access Control) terminology.

For a concurrent program though there may be a need to only run for Single Operating Unit, though the Responsibility has access to Multiple Operating Units’ data based on the “MO: Security Profile” profile option.

Running a particular concurrent program for only a Single Operating Unit can be achieved by a simple update statement or from the front-end application:-
--Execute the following update statement in the database for the particular concurrent program you want set to run for "Single Operating Unit"

UPDATE fnd_concurrent_programs
   SET multi_org_category = 'S'
 WHERE concurrent_program_name = '<your program name>';

Now we will see how we can achieve from the Oracle Applications front-end.
1. Login into application with System Administration responsibility (NOT System
     Administrator)
2. Navigate: Concurrent -> Programs


3. Query for short name of the concurrent program
4. Click on Update pencil icon of your program 




5. Under 'Update Concurrent Program' region, select Request tab
6. Under 'Request Setting' region, select 'Single' from the drop down of 'Operating Unit
     Mode' field
7. Save changes by clicking on 'Apply' button


















8. Change responsibility to the responsibility where the “Concurrent Program” can be run, in
    this example “TESTOU” is assigned to “AR Super User” responsibility                              
9. Select the “Concurrent Program” from the “SRS Window”, now you can see that “Operating 
    Unit” field is enabled and you can see the Operating Units in the LOV




10. This particular selected Operating Unit value can be accessed using the standard MOAC API:MO_GLOBAL.get_current_org_id

Note:- The return value for the “Operating Unit” reporting context is corresponding “ORG_ID” for the selected “Operating Unit Name”

Monday, 19 January 2015

The queries below lets one verify from the backend whether the template and the Data Definition were uploaded by your System Administrators or not.

/* Query for Data Definition */
SELECT xddt.data_source_name "Data Source Name",
xddb.data_source_code "Code",
fat.application_name "Application Name"
FROM xdo_ds_definitions_b xddb,
xdo_ds_definitions_tl xddt,
fnd_application fa,
fnd_application_tl fat
WHERE xddb.data_source_code LIKE 'XX%'
AND xddt.data_source_code = xddb.data_source_code
AND xddt.LANGUAGE = 'US'
AND fa.application_short_name = xddb.application_short_name
AND fat.application_id = fa.application_id
AND fat.LANGUAGE = 'US'
/* Query for Templates */
SELECT xtt.template_name "Template Name",
xtb.template_code "Template Code",
fat.application_name "Application Name",
xddt.data_source_name "Data Definition",
xtb.template_type_code "Template Type",
xtb.default_language "Language",
xtb.default_territory "Territory",
xl.file_name "File Name",
xl.file_data "File"
FROM xdo_templates_tl xtt,
xdo_templates_b xtb,
fnd_application_tl fat,
xdo_ds_definitions_tl xddt,
xdo_lobs xl
WHERE (xtt.template_name LIKE '%' OR xtt.template_name LIKE 'XX%')
AND xtt.LANGUAGE = 'US'
AND xtb.template_code = xtt.template_code
AND fat.application_id = xtb.application_id
AND fat.LANGUAGE = 'US'
AND xddt.data_source_code = xtb.data_source_code
AND xddt.LANGUAGE = 'US'
AND xl.lob_code = xtb.template_code
AND NVL (xl.program, 'X') <> 'RTF2XSLParser 5.6.3'
AND xl.LANGUAGE = xtb.default_language
AND xl.territory = xtb.default_territory

Thursday, 8 January 2015

XML publisher Tips

XML publisher Tips

1)  IF ELSE’ condition in XML publisher
2)  How to get SYSDATE in the header section dynamically 
        when we run the report
3)  What are the XML publisher tables?
4)  How to write a loop in rtf template design?
5)  How to design sub templates in rtf layout?
6)  How to call a header or footer?
7)  How to break the page in specific condition?
8)  How to use section break?
9)  How to create multi layouts in XMLP?
10) How to submit a layout in the backend?
11) How to display the images in XMLP?
12) How to pass the page numbers in rtf layout?
13) How to display last page is differently in XML Publisher Reports.
14) Useful XML Publisher Report Syntax 


1) ‘IF ELSE’ condition in XML publisher 
XML Publisher supports the common programming construct “if-then-else”.
 This is extremely useful when you need to test a condition and conditionally show a result. 
For example:
IF X=0 THEN
Y=2

ELSE
Y=3

END IF
You can also nest these statements as follows:
IF X=0 THEN
Y=2

ELSE
IF X=1 THEN

Y=10
ELSE Y=100

END IF
Use the following syntax to construct an if-then-else statement in your RTF template:
<?xdofx:if element_condition then result1 else result2 end if?>
For example, the following statement tests the AMOUNT element value. If the value is greater 
than 1000, show the word “Higher”; if it is less than 1000, show the word “Lower”; 
if it is equal to 1000, show “Equal”:
<?xdofx:if AMOUNT > 1000 then 'Higher'
if AMOUNT < 1000 then 'Lower'
Else

'Equal'
end if?>








  2) How to get SYSDATE in the header section dynamically when we
 run the report
You cannot insert form fields in the Header section, but you can just insert the code to achieve this. 
For example: insert this in the header section to view the sysdate: You could format the date as you 
would like..
<?xdofx: sysdate(‘YYYY-MM-DD’)?>


 3)  What are the XML publisher tables?

 PER_GB_XDO_TEMPLATES
XDO_DS_DEFINITIONS_B
XDO_DS_DEFINITIONS_TL
XDO_DS_DEFINITIONS_VL
XDO_LOBS
XDO_TEMPLATES_B
XDO_TEMPLATES_TL

XDO_TEMPLATES_VL
XDO_TEMPLATE_FIELDS
XDO_TRANS_UNITS
XDO_TRANS_UNIT_PROPS
XDO_TRANS_UNIT_VALUES

4) How to write a loop in rtf template design?
<? For-each:G_invoice_no?>
     ……………………..<? End for each?>

5)  How to design sub templates in rtf layout?
Using following tags..
  <? Template: template_name?>
          This is Last Page
                            <? End template?>

6)  How to call a header or footer?
Using this tag
 <?call:header?> and <?call:footer?>
    We have to use header section and footer section of the page.
7)  How to break the page in specific condition?
<?split-by-page-break:?>
8)  How to use section break?
<?for-each@section:G_CUSTOMER(This is group name)?>
9)  How to create multi layouts in XMLP?
<?choose:?>
          <?when:CF_CHOICE=’VENDOR’?>
            Your template….
          <?end when?>
                   <?when:CF_CHOICE=’INVOICE’?>
                   Your template….
                   <?end when?>
                        <?when:CF_CHOICE=’RECEIPT’?>
                         Your template….
                        <?end when?>
<?end choose?>

10) How to submit a layout in the backend?
we have to write a procedure for this using the below code
FND_REQUEST.ADD_LAYOUT 
( TEMPLATE_APPL_NAME     => 'application name',
TEMPLATE_CODE           => 'your template code',
TEMPLATE_LANGUAGE       => 'En',
TEMPLATE_TERRITORY      => 'US',
OUTPUT_FORMAT           => 'PDF'
);

11) How to display the images in XMLP?
url:{'http://image location'}
                 For example, enter:
                   url:{'http://www.oracle.com/images/ora_log.gif'}
                      url:{'${OA_MEDIA}/image name'}

12) How to pass the page numbers in rtf layout?
<REPORT>
<PAGESTART>200<\PAGESTART>
....
</REPORT>

13) How to display last page is differently in XML Publisher Reports.
<?start@last-page-first:body?>    <?end body?>