Search This Blog

Wednesday, April 19, 2023

API to create Discrete JOB in WIP (WIP Job Order)


DELETE FROM wip_job_schedule_interface;


INSERT INTO wip_job_schedule_interface

(

--organization_code

organization_id

, primary_item_id

, job_name

, start_quantity

, net_quantity

, first_unit_start_date --,SCHEDULED_START_DATE, SCHEDULED_COMPLETION_DATE 

, DATE_RELEASED

, class_code

, status_type

, COMPLETION_SUBINVENTORY

, group_id

, load_type

,WIP_SUPPLY_TYPE

, process_phase

, process_status

, created_by

, creation_date

, last_updated_by

, last_update_date

, description

)

values

(

--'MST' -- organization_id

121

,15834 -- primary_item_id

--,WIP_JOB_NUMBER_S.nextval -- job_name

,'SFF8006'

,2 -- start_quantity

,2 -- Net Quantity

,to_date('01-APR-2023','DD-MON-RRRR') --first_unit_start_date

,to_date('01-APR-2023','DD-MON-RRRR')--,to_date('01-APR-2023','DD-MON-RRRR') ,to_date('01-APR-2023','DD-MON-RRRR')  

,'SGL_AC_ST' --class_code

,3 --status_type 1.UnReleased 3. Released 4.Complete 6.On Hold 7. Cancelled

,'SP-CAB' --COMPLETION_SUBINVENTORY

,10 -- group_id to submit conc program 

,1 -- load_type

/*

1 Create Standard Discrete Job

2 Create Pending Repetitive Schedule

3 Update Standard or Non-Standard Discrete Job

4 Create Non-Standard Discrete Job

*/

,3

,2 -- process_phase 2 Validation 3 Explosion 4 Complete 5 Creation

,1 -- process_status 1 Pending 2 Running 3 Error 4 Complete 5 Warning

,1130 -- created_by

, SYSDATE -- creation_date

,1130 -- last_updated_by

, SYSDATE -- last_update_date

,'Test Description'

);


 /*

Navigation path: WIP - discrete - import jobs and schedules

Concurrent Program to import data :- WIP Mass Load

group_id = 1 (Same group id as in Interface Table)


Error table :- WIP_INTERFACE_ERRORS

https://oracleappss.blogspot.com/2008/07/wip-job-creation.html

*/

SELECT * FROM WIP_DISCRETE_JOBS_V 

WHERE CREATION_DATE LIKE SYSDATE

;


Tuesday, April 18, 2023

API To Create Credit Note Apps R12

 


declare

l_return_status varchar2(1);

p_count  NUMBER;

l_msg_count number;

l_msg_data varchar2(2000);

l_batch_id number;

l_cnt number := 0;

l_batch_source_rec ar_invoice_api_pub.batch_source_rec_type;

l_trx_header_tbl ar_invoice_api_pub.trx_header_tbl_type;

l_trx_lines_tbl ar_invoice_api_pub.trx_line_tbl_type;

l_trx_dist_tbl ar_invoice_api_pub.trx_dist_tbl_type;

l_trx_salescredits_tbl ar_invoice_api_pub.trx_salescredits_tbl_type;

l_customer_trx_id number;

cnt number; 

v_context varchar2(100);

trx_header_id            NUMBER  ;

trx_line_id              NUMBER  ;

trx_dist_id              NUMBER  ;

L_COUNT2 NUMBER;

LV_SQLERRM  varchar2(100);

L_ERRMSG   varchar2(100);

W_MESSAGE  varchar2(100);

W_STATUS  varchar2(100);

LN_MSG_INDEX_OUT  varchar2(100);


l_bill_to_customer_id number;

    

    CURSOR GET_RECORDS IS

          SELECT CUSTOMER_NUMBER, TRX_DATE, GL_DATE,TRX_REFERENCE,QUANTITY, UNIT_PRICE, CURRENCY

          FROM XX_AR_INV_INT_CN

         ;    

BEGIN

FOR I IN GET_RECORDS LOOP

DBMS_OUTPUT.PUT_LINE('1');


SELECT CUSTOMER_ID

INTO l_bill_to_customer_id

 FROM 

AR_CUSTOMERS

WHERE CUSTOMER_NUMBER = I.CUSTOMER_NUMBER

;


--1. Set applications context if not already set.

    /* Setting the oracle applications context for the particular session */

    fnd_global.apps_initialize ( user_id      => 1110

                                ,resp_id      => 50917

                                ,resp_appl_id => 222);

    /* Setting the org context for the particular session */

    mo_global.set_policy_context('S',121);


        BEGIN

            SELECT ra_customer_trx_s.NEXTVAL INTO trx_header_id FROM DUAL;

        END;

        BEGIN

            SELECT ra_customer_trx_lines_s.NEXTVAL INTO trx_line_id FROM DUAL;

        END;


        BEGIN

            SELECT ra_cust_trx_line_gl_dist_s.NEXTVAL

              INTO trx_dist_id

              FROM DUAL;

        END;

        

        DBMS_OUTPUT.PUT_LINE('TRX_HEADER_ID-'||ra_customer_trx_s.CURRVAL);


l_batch_source_rec.batch_source_id := 4002;

                l_trx_header_tbl(1).trx_header_id := trx_header_id;

                l_trx_header_tbl(1).trx_number := I.TRX_NUMBER;

                l_trx_header_tbl(1).bill_to_customer_id := l_bill_to_customer_id;

                l_trx_header_tbl(1).cust_trx_type_id := 6001; 

                l_trx_header_tbl(1).trx_date :=I.TRX_DATE;

                l_trx_header_tbl(1).gl_date :=TO_DATE('31-MAR-2023');

                l_trx_header_tbl(1).trx_currency  := I.CURRENCY;

--                l_trx_header_tbl(1).exchange_date := I.GL_DATE; --non functional currency

  --              l_trx_header_tbl(1).exchange_rate_type := 'Corporate'; --non functional currency

                l_trx_header_tbl(1).primary_salesrep_id := -3;

                l_trx_header_tbl(1).org_id := 121;

                l_trx_header_tbl(1).comments :=I.TRX_REFERENCE; 

                 l_trx_header_tbl(1).trx_class:='CM'; 

--                 l_trx_header_tbl(1).bill_to_site_use_id := 6051;

                 l_trx_header_tbl(1).term_id             :=  NULL;

                 l_trx_header_tbl(1).finance_charges        :=  null;

                l_trx_header_tbl(1).status_trx                     :=  'OP';

                l_trx_header_tbl(1).printing_option            :=  'PRI';

                

                

              ---Calling API 

                       BEGIN

                         SELECT

                         ra_customer_trx_lines_s.nextval

                         INTO

                         trx_line_id

                         FROM  dual;

                       END;

  

                       BEGIN

                           SELECT

                           ra_cust_trx_line_gl_dist_s.nextval

                           INTO  trx_dist_id

                       FROM  dual;

                       END; 

                       l_count2 := 1;

                        l_trx_lines_tbl(l_count2).trx_header_id := trx_header_id;

                        l_trx_lines_tbl(l_count2).trx_line_id := trx_line_id; 

                        l_trx_lines_tbl(l_count2).line_number := l_count2;

                        l_trx_lines_tbl(l_count2).DESCRIPTION := NVL(I.DESCRIPTION,I.TRX_REFERENCE);

                        l_trx_lines_tbl(l_count2).quantity_invoiced := 1;

                        l_trx_lines_tbl(l_count2).unit_selling_price :=I.UNIT_PRICE;--P_line_amt(i);

                        l_trx_lines_tbl(l_count2).line_type := TRIM('LINE');

                        l_trx_lines_tbl(l_count2).taxable_flag := NULL;

                      l_trx_dist_tbl(l_count2).trx_dist_id := trx_dist_id;

                      l_trx_dist_tbl(l_count2).trx_header_id := trx_header_id;

                      l_trx_dist_tbl(l_count2).trx_line_id := trx_line_id;

                      l_trx_dist_tbl(l_count2).account_class := 'REV';

                      l_trx_dist_tbl(l_count2).percent := 100;

                      l_trx_dist_tbl(l_count2).amount := I.UNIT_PRICE;--P_line_amt(i);

                       l_trx_dist_tbl(l_count2).code_combination_id := 27016; 

                  

 

              ----Call the invoice api 

                fnd_global.apps_initialize(1110,50917,222);

                      mo_global.set_policy_context('S',121);

                     

begin

 AR_INVOICE_API_PUB.create_single_invoice(

                      p_api_version           => 1.0,

                      P_INIT_MSG_LIST         => FND_API.G_FALSE,

                      P_COMMIT                => FND_API.G_FALSE,

                      p_batch_source_rec      => l_batch_source_rec,

                      p_trx_header_tbl        => l_trx_header_tbl,

                      p_trx_lines_tbl         => l_trx_lines_tbl,

                      p_trx_dist_tbl          => l_trx_dist_tbl,

                      p_trx_salescredits_tbl  => l_trx_salescredits_tbl,

                      x_customer_trx_id       => l_customer_trx_id,

                      x_return_status         => l_return_status,

                      x_msg_count             => l_msg_count,

                      x_msg_data              => l_msg_data); 

                    commit;

                    exception when others then

                     W_Status:='E';

  W_Message:=sqlerrm;

end;                    

     

   END LOOP;

          

 IF l_return_status = fnd_api.g_ret_sts_error OR

        l_return_status = fnd_api.g_ret_sts_unexp_error THEN


        dbms_output.put_line('FND_MSG_PUB.Count_Msg ');

        dbms_output.put_line(l_return_status||':'||sqlerrm);            

            

              FOR l_msg_count IN 1..FND_MSG_PUB.Count_Msg

      LOOP

      FND_MSG_PUB.Get(p_msg_index     => l_msg_count

                     ,p_encoded       => 'F'

                     ,p_data          => l_msg_data

                     ,p_msg_index_OUT => ln_msg_index_out

                     );

       lv_sqlerrm   := SUBSTR(lv_sqlerrm||REPLACE(l_msg_data,CHR(10),''),1,3998);

       W_Status := 'E';

       W_Message := lv_sqlerrm;

       dbms_output.put_line(l_return_status||':'||lv_sqlerrm);

     END LOOP;

    FND_MSG_PUB.Delete_Msg;

    ELSE   

         dbms_output.put_line('FND_MSG_PUB.Count_Msg else :'||FND_MSG_PUB.Count_Msg); 

    END IF;

              EXCEPTION WHEN OTHERS THEN

            l_ErrMsg :=SQLERRM;

            

          END ;



 --for any errors check the table

SELECT * FROM ar_trx_errors_gt;

--OPEN Issues

Not able to find CT_Reference field, so used comments field to pass the value.

API Create Debit Note Apps R12

 declare

l_return_status varchar2(1);

p_count  NUMBER;

l_msg_count number;

l_msg_data varchar2(2000);

l_batch_id number;

l_cnt number := 0;

l_batch_source_rec ar_invoice_api_pub.batch_source_rec_type;

l_trx_header_tbl ar_invoice_api_pub.trx_header_tbl_type;

l_trx_lines_tbl ar_invoice_api_pub.trx_line_tbl_type;

l_trx_dist_tbl ar_invoice_api_pub.trx_dist_tbl_type;

l_trx_salescredits_tbl ar_invoice_api_pub.trx_salescredits_tbl_type;

l_customer_trx_id number;

cnt number; 

v_context varchar2(100);

trx_header_id            NUMBER  ;

trx_line_id              NUMBER  ;

trx_dist_id              NUMBER  ;

L_COUNT2 NUMBER;

LV_SQLERRM  varchar2(100);

L_ERRMSG   varchar2(100);

W_MESSAGE  varchar2(100);

W_STATUS  varchar2(100);

LN_MSG_INDEX_OUT  varchar2(100);


l_bill_to_customer_id number;

    

    CURSOR GET_RECORDS IS

        SELECT CUSTOMER_NUMBER, TRX_DATE, GL_DATE,TRX_REFERENCE,QUANTITY, UNIT_PRICE, CURRENCY

          FROM XX_AR_INV_INT_DN

         ;    

BEGIN

FOR I IN GET_RECORDS LOOP

DBMS_OUTPUT.PUT_LINE('1');


SELECT CUSTOMER_ID

INTO l_bill_to_customer_id

 FROM 

AR_CUSTOMERS

WHERE CUSTOMER_NUMBER = I.CUSTOMER_NUMBER

;


--1. Set applications context if not already set.

    /* Setting the oracle applications context for the particular session */

    fnd_global.apps_initialize ( user_id      => 1110

                                ,resp_id      => 50917

                                ,resp_appl_id => 222);

    /* Setting the org context for the particular session */

    mo_global.set_policy_context('S',121);


        BEGIN

            SELECT ra_customer_trx_s.NEXTVAL INTO trx_header_id FROM DUAL;

        END;

        BEGIN

            SELECT ra_customer_trx_lines_s.NEXTVAL INTO trx_line_id FROM DUAL;

        END;


        BEGIN

            SELECT ra_cust_trx_line_gl_dist_s.NEXTVAL

              INTO trx_dist_id

              FROM DUAL;

        END;

        

        DBMS_OUTPUT.PUT_LINE('TRX_HEADER_ID-'||ra_customer_trx_s.CURRVAL);


                l_batch_source_rec.batch_source_id := 4002;

                l_trx_header_tbl(1).trx_header_id := trx_header_id;

                l_trx_header_tbl(1).trx_number := I.TRX_NUMBER;

                l_trx_header_tbl(1).bill_to_customer_id := l_bill_to_customer_id;

                l_trx_header_tbl(1).cust_trx_type_id := 6002; 

                l_trx_header_tbl(1).trx_date :=I.TRX_DATE;

                l_trx_header_tbl(1).gl_date :=TO_DATE('31-MAR-2023');

               l_trx_header_tbl(1).trx_currency  := I.CURRENCY;

              --  l_trx_header_tbl(1).exchange_date := I.GL_DATE; --if other than functional curr

                -- l_trx_header_tbl(1).exchange_rate_type := 'Corporate';  --if other than functional curr

                l_trx_header_tbl(1).primary_salesrep_id := -3;

                l_trx_header_tbl(1).org_id := 121;

                l_trx_header_tbl(1).comments :=I.TRX_REFERENCE; 

                 l_trx_header_tbl(1).trx_class:='DM'; 

--                 l_trx_header_tbl(1).bill_to_site_use_id := 6051;

                 l_trx_header_tbl(1).term_id             :=  NULL;

                 l_trx_header_tbl(1).finance_charges        :=  null;

                l_trx_header_tbl(1).status_trx                     :=  'OP';

                l_trx_header_tbl(1).printing_option            :=  'PRI';

                

                

              ---Calling API 

                       BEGIN

                         SELECT

                         ra_customer_trx_lines_s.nextval

                         INTO

                         trx_line_id

                         FROM  dual;

                       END;

  

                       BEGIN

                           SELECT

                           ra_cust_trx_line_gl_dist_s.nextval

                           INTO  trx_dist_id

                       FROM  dual;

                       END; 

                       l_count2 := 1;

                        l_trx_lines_tbl(l_count2).trx_header_id := trx_header_id;

                        l_trx_lines_tbl(l_count2).trx_line_id := trx_line_id; 

                        l_trx_lines_tbl(l_count2).line_number := l_count2;

                        l_trx_lines_tbl(l_count2).DESCRIPTION := NVL(I.DESCRIPTION,I.TRX_REFERENCE);

                        l_trx_lines_tbl(l_count2).quantity_invoiced := 1;

                        l_trx_lines_tbl(l_count2).unit_selling_price :=I.UNIT_PRICE;--P_line_amt(i);

                        l_trx_lines_tbl(l_count2).line_type := TRIM('LINE');

                        l_trx_lines_tbl(l_count2).taxable_flag := NULL;

                      l_trx_dist_tbl(l_count2).trx_dist_id := trx_dist_id;

                      l_trx_dist_tbl(l_count2).trx_header_id := trx_header_id;

                      l_trx_dist_tbl(l_count2).trx_line_id := trx_line_id;

                      l_trx_dist_tbl(l_count2).account_class := 'REV';

                      l_trx_dist_tbl(l_count2).percent := 100;

                      l_trx_dist_tbl(l_count2).amount := I.UNIT_PRICE;--P_line_amt(i);

                       l_trx_dist_tbl(l_count2).code_combination_id := 27016; 

                  

 

              ----Call the invoice api 

                fnd_global.apps_initialize(1110,50917,222);

                      mo_global.set_policy_context('S',121);

                     

begin

 AR_INVOICE_API_PUB.create_single_invoice(

                      p_api_version           => 1.0,

                      P_INIT_MSG_LIST         => FND_API.G_FALSE,

                      P_COMMIT                => FND_API.G_FALSE,

                      p_batch_source_rec      => l_batch_source_rec,

                      p_trx_header_tbl        => l_trx_header_tbl,

                      p_trx_lines_tbl         => l_trx_lines_tbl,

                      p_trx_dist_tbl          => l_trx_dist_tbl,

                      p_trx_salescredits_tbl  => l_trx_salescredits_tbl,

                      x_customer_trx_id       => l_customer_trx_id,

                      x_return_status         => l_return_status,

                      x_msg_count             => l_msg_count,

                      x_msg_data              => l_msg_data); 

                    commit;

                    exception when others then

                     W_Status:='E';

  W_Message:=sqlerrm;

end;                    

     

   END LOOP;

          

 IF l_return_status = fnd_api.g_ret_sts_error OR

        l_return_status = fnd_api.g_ret_sts_unexp_error THEN


        dbms_output.put_line('FND_MSG_PUB.Count_Msg ');

        dbms_output.put_line(l_return_status||':'||sqlerrm);            

            

              FOR l_msg_count IN 1..FND_MSG_PUB.Count_Msg

      LOOP

      FND_MSG_PUB.Get(p_msg_index     => l_msg_count

                     ,p_encoded       => 'F'

                     ,p_data          => l_msg_data

                     ,p_msg_index_OUT => ln_msg_index_out

                     );

       lv_sqlerrm   := SUBSTR(lv_sqlerrm||REPLACE(l_msg_data,CHR(10),''),1,3998);

       W_Status := 'E';

       W_Message := lv_sqlerrm;

       dbms_output.put_line(l_return_status||':'||lv_sqlerrm);

     END LOOP;

    FND_MSG_PUB.Delete_Msg;

    ELSE   

         dbms_output.put_line('FND_MSG_PUB.Count_Msg else :'||FND_MSG_PUB.Count_Msg); 

    END IF;

              EXCEPTION WHEN OTHERS THEN

            l_ErrMsg :=SQLERRM;

            

          END ;


--for any issues check the table

SELECT * FROM ar_trx_errors_gt;


--OPEN Issues

Not able to find CT_Reference field, so used comments field to pass the value.

Friday, April 14, 2023

Apps R12 create Sales Order with status Booked

 Step1: Create SO

Step2: Process SO status to Booked


Step1: 

--SET SERVEROUTPUT ON;

DECLARE

v_api_version_number           NUMBER    := 1;

v_return_status                VARCHAR2(2000);

v_msg_count                    NUMBER;

v_msg_data                     VARCHAR2(2000);

-- IN Variables --

v_header_rec                   oe_order_pub.header_rec_type;

v_line_tbl                     oe_order_pub.line_tbl_type;

v_action_request_tbl           oe_order_pub.request_tbl_type;

v_line_adj_tbl                 oe_order_pub.line_adj_tbl_type;

-- OUT Variables --

v_header_rec_out               oe_order_pub.header_rec_type;

v_header_val_rec_out           oe_order_pub.header_val_rec_type;

v_header_adj_tbl_out           oe_order_pub.header_adj_tbl_type;

v_header_adj_val_tbl_out       oe_order_pub.header_adj_val_tbl_type;

v_header_price_att_tbl_out     oe_order_pub.header_price_att_tbl_type;

v_header_adj_att_tbl_out       oe_order_pub.header_adj_att_tbl_type;

v_header_adj_assoc_tbl_out     oe_order_pub.header_adj_assoc_tbl_type;

v_header_scredit_tbl_out       oe_order_pub.header_scredit_tbl_type;

v_header_scredit_val_tbl_out   oe_order_pub.header_scredit_val_tbl_type;

v_line_tbl_out                 oe_order_pub.line_tbl_type;

v_line_val_tbl_out             oe_order_pub.line_val_tbl_type;

v_line_adj_tbl_out             oe_order_pub.line_adj_tbl_type;

v_line_adj_val_tbl_out         oe_order_pub.line_adj_val_tbl_type;

v_line_price_att_tbl_out       oe_order_pub.line_price_att_tbl_type;

v_line_adj_att_tbl_out         oe_order_pub.line_adj_att_tbl_type;

v_line_adj_assoc_tbl_out       oe_order_pub.line_adj_assoc_tbl_type;

v_line_scredit_tbl_out         oe_order_pub.line_scredit_tbl_type;

v_line_scredit_val_tbl_out     oe_order_pub.line_scredit_val_tbl_type;

v_lot_serial_tbl_out           oe_order_pub.lot_serial_tbl_type;

v_lot_serial_val_tbl_out       oe_order_pub.lot_serial_val_tbl_type;

v_action_request_tbl_out       oe_order_pub.request_tbl_type;

BEGIN

DBMS_OUTPUT.PUT_LINE('Starting of script');

-- Setting the Enviroment --

mo_global.init('ONT');

fnd_global.apps_initialize ( user_id      => 1170

                            ,resp_id      => 50957

                            ,resp_appl_id => 660);

mo_global.set_policy_context('S',121);

-- Header Record --

v_header_rec                        := oe_order_pub.g_miss_header_rec;

v_header_rec.operation              := oe_globals.g_opr_create;

v_header_rec.order_type_id          := 1261;   

v_header_rec.sold_to_org_id         := 8318; --CUSTOMER_ID/VENDOR_ID

v_header_rec.ship_to_org_id         := 8588; --SHIP_TO  hz_cust_site_uses_all

v_header_rec.invoice_to_org_id      := 8589; --BILL_TO  hz_cust_site_uses_all

v_header_rec.order_source_id        := 0;

v_header_rec.booked_flag            := 'N';

v_header_rec.price_list_id          := 9007;

v_header_rec.pricing_date           := SYSDATE;

v_header_rec.flow_status_code       := 'ENTERED'; --'BOOKED';-- NOT WORKING 

--v_header_rec.cust_po_number         := '99478222532';

v_header_rec.sold_from_org_id       := 121;

v_header_rec.salesrep_id            := 100000051;

v_header_rec.transactional_curr_code:= 'AED';

v_action_request_tbl (1) := oe_order_pub.g_miss_request_rec;

-- Line Record --

v_line_tbl (1)                      := oe_order_pub.g_miss_line_rec;

v_line_tbl (1).operation            := oe_globals.g_opr_create;

v_line_tbl (1).inventory_item_id    := 15322;

v_line_tbl (1).ordered_quantity     := 1;

v_line_tbl (1).unit_selling_price   := 2200;

v_line_tbl (1).calculate_price_flag := 'Y';

DBMS_OUTPUT.PUT_LINE('Starting of API');

-- Calling the API to create an Order --

OE_ORDER_PUB.PROCESS_ORDER (

p_api_version_number            => v_api_version_number

, p_header_rec                  => v_header_rec

, p_line_tbl                    => v_line_tbl

, p_action_request_tbl          => v_action_request_tbl

, p_line_adj_tbl                => v_line_adj_tbl

-- OUT variables

, x_header_rec                  => v_header_rec_out

, x_header_val_rec              => v_header_val_rec_out

, x_header_adj_tbl              => v_header_adj_tbl_out

, x_header_adj_val_tbl          => v_header_adj_val_tbl_out

, x_header_price_att_tbl        => v_header_price_att_tbl_out

, x_header_adj_att_tbl          => v_header_adj_att_tbl_out

, x_header_adj_assoc_tbl        => v_header_adj_assoc_tbl_out

, x_header_scredit_tbl          => v_header_scredit_tbl_out

, x_header_scredit_val_tbl      => v_header_scredit_val_tbl_out

, x_line_tbl                    => v_line_tbl_out

, x_line_val_tbl                => v_line_val_tbl_out

, x_line_adj_tbl                => v_line_adj_tbl_out

, x_line_adj_val_tbl            => v_line_adj_val_tbl_out

, x_line_price_att_tbl          => v_line_price_att_tbl_out

, x_line_adj_att_tbl            => v_line_adj_att_tbl_out

, x_line_adj_assoc_tbl          => v_line_adj_assoc_tbl_out

, x_line_scredit_tbl            => v_line_scredit_tbl_out

, x_line_scredit_val_tbl        => v_line_scredit_val_tbl_out

, x_lot_serial_tbl              => v_lot_serial_tbl_out

, x_lot_serial_val_tbl          => v_lot_serial_val_tbl_out

, x_action_request_tbl          => v_action_request_tbl_out

, x_return_status               => v_return_status

, x_msg_count                   => v_msg_count

, x_msg_data                    => v_msg_data

);

DBMS_OUTPUT.PUT_LINE('Completion of API');

IF v_return_status = fnd_api.g_ret_sts_success THEN

    COMMIT;

    DBMS_OUTPUT.put_line ('Order Import Success : '||v_header_rec_out.header_id);

ELSE

    DBMS_OUTPUT.put_line ('Order Import failed:'||v_msg_data);

    ROLLBACK;

    FOR i IN 1 .. v_msg_count

    LOOP

      v_msg_data := oe_msg_pub.get( p_msg_index => i, p_encoded => 'F');

      dbms_output.put_line( i|| ') '|| v_msg_data);

    END LOOP;

END IF;

END;

/


Step2:

DECLARE

v_api_version_number           NUMBER  := 1;

v_return_status                VARCHAR2 (2000);

v_msg_count                    NUMBER;

v_msg_data                     VARCHAR2 (2000);


-- IN Variables --

v_header_rec                   oe_order_pub.header_rec_type;

v_line_tbl                     oe_order_pub.line_tbl_type;

v_action_request_tbl           oe_order_pub.request_tbl_type;

v_line_adj_tbl                 oe_order_pub.line_adj_tbl_type;


-- OUT Variables --

v_header_rec_out               oe_order_pub.header_rec_type;

v_header_val_rec_out           oe_order_pub.header_val_rec_type;

v_header_adj_tbl_out           oe_order_pub.header_adj_tbl_type;

v_header_adj_val_tbl_out       oe_order_pub.header_adj_val_tbl_type;

v_header_price_att_tbl_out     oe_order_pub.header_price_att_tbl_type;

v_header_adj_att_tbl_out       oe_order_pub.header_adj_att_tbl_type;

v_header_adj_assoc_tbl_out     oe_order_pub.header_adj_assoc_tbl_type;

v_header_scredit_tbl_out       oe_order_pub.header_scredit_tbl_type;

v_header_scredit_val_tbl_out   oe_order_pub.header_scredit_val_tbl_type;

v_line_tbl_out                 oe_order_pub.line_tbl_type;

v_line_val_tbl_out             oe_order_pub.line_val_tbl_type;

v_line_adj_tbl_out             oe_order_pub.line_adj_tbl_type;

v_line_adj_val_tbl_out         oe_order_pub.line_adj_val_tbl_type;

v_line_price_att_tbl_out       oe_order_pub.line_price_att_tbl_type;

v_line_adj_att_tbl_out         oe_order_pub.line_adj_att_tbl_type;

v_line_adj_assoc_tbl_out       oe_order_pub.line_adj_assoc_tbl_type;

v_line_scredit_tbl_out         oe_order_pub.line_scredit_tbl_type;

v_line_scredit_val_tbl_out     oe_order_pub.line_scredit_val_tbl_type;

v_lot_serial_tbl_out           oe_order_pub.lot_serial_tbl_type;

v_lot_serial_val_tbl_out       oe_order_pub.lot_serial_val_tbl_type;

v_action_request_tbl_out       oe_order_pub.request_tbl_type;



BEGIN


DBMS_OUTPUT.PUT_LINE('Starting of script');


-- Setting the Enviroment --


mo_global.init('ONT');

fnd_global.apps_initialize ( user_id      => 1170

                            ,resp_id      => 50957

                            ,resp_appl_id => 660);

mo_global.set_policy_context('S',121);


v_action_request_tbl (1)             := oe_order_pub.g_miss_request_rec;

v_action_request_tbl(1).request_type := OE_GLOBALS.G_BOOK_ORDER;

v_action_request_tbl(1).entity_code  := OE_GLOBALS.G_ENTITY_HEADER;

v_action_request_tbl(1).entity_id    := 43001; --pass header_id here


DBMS_OUTPUT.PUT_LINE('Starting of API');


-- Calling the API to to Book an Existing Order --


OE_ORDER_PUB.PROCESS_ORDER (

p_api_version_number            => v_api_version_number

, p_header_rec                  => v_header_rec

, p_line_tbl                    => v_line_tbl

, p_action_request_tbl          => v_action_request_tbl

, p_line_adj_tbl                => v_line_adj_tbl

-- OUT variables

, x_header_rec                  => v_header_rec_out

, x_header_val_rec              => v_header_val_rec_out

, x_header_adj_tbl              => v_header_adj_tbl_out

, x_header_adj_val_tbl          => v_header_adj_val_tbl_out

, x_header_price_att_tbl        => v_header_price_att_tbl_out

, x_header_adj_att_tbl          => v_header_adj_att_tbl_out

, x_header_adj_assoc_tbl        => v_header_adj_assoc_tbl_out

, x_header_scredit_tbl          => v_header_scredit_tbl_out

, x_header_scredit_val_tbl      => v_header_scredit_val_tbl_out

, x_line_tbl                    => v_line_tbl_out

, x_line_val_tbl                => v_line_val_tbl_out

, x_line_adj_tbl                => v_line_adj_tbl_out

, x_line_adj_val_tbl            => v_line_adj_val_tbl_out

, x_line_price_att_tbl          => v_line_price_att_tbl_out

, x_line_adj_att_tbl            => v_line_adj_att_tbl_out

, x_line_adj_assoc_tbl          => v_line_adj_assoc_tbl_out

, x_line_scredit_tbl            => v_line_scredit_tbl_out

, x_line_scredit_val_tbl        => v_line_scredit_val_tbl_out

, x_lot_serial_tbl              => v_lot_serial_tbl_out

, x_lot_serial_val_tbl          => v_lot_serial_val_tbl_out

, x_action_request_tbl          => v_action_request_tbl_out

, x_return_status               => v_return_status

, x_msg_count                   => v_msg_count

, x_msg_data                    => v_msg_data

);


DBMS_OUTPUT.PUT_LINE('Completion of API');



IF v_return_status = fnd_api.g_ret_sts_success THEN

    COMMIT;

    DBMS_OUTPUT.put_line ('Booking of an Existing Order is Success ');

ELSE

    DBMS_OUTPUT.put_line ('Booking of an Existing Order failed:'||v_msg_data);

    ROLLBACK;

    FOR i IN 1 .. v_msg_count

    LOOP

      v_msg_data := oe_msg_pub.get( p_msg_index => i, p_encoded => 'F');

      dbms_output.put_line( i|| ') '|| v_msg_data);

    END LOOP;

END IF;


END;

Apps r12 PO Approve from Backend (From Incomplete to Approved)

 /* Formatted on 4/14/2023 10:41:12 AM (QP5 v5.336) */

DECLARE

    l_return_status   VARCHAR2 (1000);


    l_msg_data        VARCHAR2 (1000);


    CURSOR c1 IS

        (SELECT *

           FROM po_headers_all

          WHERE     segment1 IN ('22729')

                AND type_lookup_code = 'STANDARD'

                AND (   authorization_status != 'APPROVED'

                     OR authorization_status IS NULL));

BEGIN

    mo_global.init ('PO');

    fnd_global.apps_initialize (1337, 51017, 201);


    FOR i IN c1

    LOOP

        po_document_action_pvt.do_approve (

            p_document_id        => i.po_header_id,

            p_document_type      => 'PO',

            p_document_subtype   => 'STANDARD',

            p_note               => '', --– Your comments that need to be displayed in action History,

            p_approval_path_id   => 0,  --SELECT * FROM po_action_history where creation_date like sysdate;

            x_return_status      => l_return_status,

            x_exception_msg      => l_msg_data);


        DBMS_OUTPUT.put_line (l_return_status);


        COMMIT;

    END LOOP;

END;