2/9/2015 Document Display https://support.oracle.com/epmos/faces/SearchDocDisplay?_adf.ctrlstate=peadobiss_9#head4 1/22 Getting GME APIs to Work Using Vision Database Examples From Oracle Support (Doc ID 380457.1) Getting GME APIs to Work Using Vision Database Examples *** Checked for relevance on 11JAN2013 *** Product: Process Execution (GME) APIs Minimum Version:11.5.10 CU 2 An Oracle White Paper Abstract This paper shows several simple test scripts that execute many of the public GME APIs. The basis of all of these scripts has been the Vision database. All of the scripts detailed below have been proven to run successfully using our own internal Vision install using Applications Version 11.5.10 CU 2. You will notice that the scripts are quite simple and have been written principally to test whether or not the APIs function as designed. Most of them have been written by Oracle Applications Support when questions have been raised as to whether the APIs are indeed working as they should You should be able to take the examples listed below and with the necessary changes (that is, changing constants such as Item Id, UOM, document or transaction id) get the scripts to work on your own systems. Remarks are added after each script as what changes should be made in order to get the API(s) called by the script to work for your own circumstances. If you are having problems getting the correct results from an API, you should first of all try using the on line application to recreate what you are trying to achieve in the API. For example, if you are using the application to create a Batch using a particular Recipe, then you should be able to achieve the same result when using the API. This is because the underlying code used by both the application and the API is essentially the same. It is worthwhile commenting here as to the limits of support that Oracle Support Services can provide regarding the use of the publicly provided APIs. Oracle Support Services will support APIs in that they will ensure that they function as designed and that the data inserted by the APIs into the database is correct. It is NOT the function of support to provide help to the user on writing their own custom wrapper files but they may be able to give you the advice on this. An example wrapper file is provided in the User Guide (see below). As a general comment, when a user is setting out to write procedures and functions using these APIs, it is advisable first to write simple scripts like the ones detailed in this paper (that is to say, with a single row of data embedded in the script as constants) to become confident of the working of the API itself before moving on to a wrapper which reads and processes a batch of input rows. It should also be noted that Oracle will support the use of the Public APIs ONLY. You should not directly call the private APIs. For example, the use of 'gme_api_pub.create_batch' is supported, however, 'gme_api_main.create_batch' is not supported. An additional point to is that GME Debugging works when using the APIs in the exactly the same way that it works when using the application in the normal way.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Getting GME APIs to Work Using Vision Database Examples From Oracle Support (Doc ID380457.1)
Getting GME APIs to Work Using Vision DatabaseExamples
*** Checked for relevance on 11JAN2013 ***
Product: Process Execution (GME) APIs Minimum Version:11.5.10 CU 2
An Oracle White Paper
Abstract
This paper shows several simple test scripts that execute many of the public GME APIs. The basis of allof these scripts has been the Vision database. All of the scripts detailed below have been proven to runsuccessfully using our own internal Vision install using Applications Version 11.5.10 CU 2.
You will notice that the scripts are quite simple and have been written principally to test whether or notthe APIs function as designed. Most of them have been written by Oracle Applications Support whenquestions have been raised as to whether the APIs are indeed working as they should
You should be able to take the examples listed below and with the necessary changes (that is, changingconstants such as Item Id, UOM, document or transaction id) get the scripts to work on your ownsystems. Remarks are added after each script as what changes should be made in order to get theAPI(s) called by the script to work for your own circumstances.
If you are having problems getting the correct results from an API, you should first of all try using the online application to recreate what you are trying to achieve in the API. For example, if you are using theapplication to create a Batch using a particular Recipe, then you should be able to achieve the sameresult when using the API. This is because the underlying code used by both the application and the APIis essentially the same.
It is worthwhile commenting here as to the limits of support that Oracle Support Services can provideregarding the use of the publicly provided APIs.
Oracle Support Services will support APIs in that they will ensure that they function as designed and thatthe data inserted by the APIs into the database is correct. It is NOT the function of support to providehelp to the user on writing their own custom wrapper files but they may be able to give you the advice onthis. An example wrapper file is provided in the User Guide (see below).
As a general comment, when a user is setting out to write procedures and functions using these APIs, itis advisable first to write simple scripts like the ones detailed in this paper (that is to say, with a singlerow of data embedded in the script as constants) to become confident of the working of the API itselfbefore moving on to a wrapper which reads and processes a batch of input rows.
It should also be noted that Oracle will support the use of the Public APIs ONLY. You should not directlycall the private APIs. For example, the use of 'gme_api_pub.create_batch' is supported, however,'gme_api_main.create_batch' is not supported.
An additional point to is that GME Debugging works when using the APIs in the exactly the same way thatit works when using the application in the normal way.
This can provide useful additional information if the results of an API run are not as expected.
In order to generate a GME debug file, do the following:
1. Set Profile Option 'FND: Debug Log Enabled' at User level to 'Yes' and Profile Option 'FND: DebugLog Level' at User level to 'Statement' and run the API in the normal way.
2. The GME Debug log files are to be found in the 'utl_file_dir' directory. This query
select nvl(substr(value, 1, instr(value, ',')1),value)from v$parameterwhere name = 'utl_file_dir'/
will show the user the directory where the log file will be generated. GME debug Log file names startwith the Applications User Name, and the format of the file name is 'USERNAMEEvent'; for exampleORAUSRCreateBatch or ORAUSRAllocateLine.
For a detailed description of available public APIs, refer to the Process Execution API User’s GuideRelease 11i Part No. A9738804. When attempting to use an API, it is recommended to read themanual thoroughly, especially the sections that outline the parameters required by the relevant API.
All of the scripts provided in this document should be executed using the APPS SQL*Plus user.
Document History
Create Date : 25JUL2006Last Update Date : 01AUG2006
Table of Contents
Example 1: Creation of batch using the ‘RECIPE’ creation modeExample 2: Creation of batch by ProductExample 3: Creation using Output QuantityExample 4: Create, Release and Save BatchExample 5: Create a batch and insert an additional material lineExample 6: Insert_line_allocation APIExample 7: Close (Complete) BatchExample 8: Release, Record Usage and Complete StepRelated Documents
Example 1: Creation of batch using the ‘RECIPE’ creation mode
alter session set nls_language=american;set serveroutput on size 1000000;
DECLARE
p_api_version NUMBER DEFAULT gme_api_pub.api_version; p_validation_level NUMBER DEFAULT gme_api_pub.max_errors; p_init_msg_list BOOLEAN DEFAULT FALSE; P_batch_type NUMBER DEFAULT 0; p_orgn_code VARCHAR2(4) DEFAULT 'PR1'; x_batch_header gme_batch_header%ROWTYPE; x_unallocated_material gme_api_pub.unallocated_materials_tab; x_message_count NUMBER;
1. Notice the ‘alter session set nls_language=american;’ command. This command is used to ensure that thelanguage in the current SQL*Plus session matches one of the installed languages within the Application. It isalways safe to set this to ‘american’.
2. The ‘set serveroutput on size 1000000’ command is there to ensure that the 'dbms_out.put_line' messages canbe seen on the screen. In real life examples, the user will probably use the 'utl_file.put_line' command in orderto write these messages to a text log file.
3. Note the combination of the Recipe Number and Version and the Validity Rule Id. The Validity Rule Id must beattached to the relevant Recipe, and both must be ‘Approved for General Use’. The Validity Rule must beeffective on the relevant batch dates (in this case, the batch due date). To find the appropriate value of ValidityRule Id, run the script shown above.
4. Note the Batch Size and UOM. These must be valid within the limits set by the Validity Rule being used.5. The ‘fnd_global.apps_initialize’ is used to set the application context. In the above example, the context is set
according to the applications user whose id is 1003637. The relevant id can found for the required user by usingthis command: ‘select user_id from fnd_user where user_name='&user_name'; and entering the requiredusername. The user selected should have a responsibility attached which allows creation of batches via theapplication.
6. A full description of the Create Batch API and its parameters can be found in the User Guide pages 416 to 419.
Example 2: Creation of batch by Product
set serveroutput on size 1000000alter session set nls_language=american;
IF x_unallocated_material.count > 0 THEN FOR i IN x_unallocated_material.first..x_unallocated_material.last LOOP IF x_unallocated_material.exists(i) THEN
dbms_output.put_line('x_unallocated_material('||to_char(i)||').batch_id='||TO_CHAR(x_unallocated_material(i).batch_id)); dbms_output.put_line(SubStr('x_unallocated_material('||to_char(i)||').batch_no='||x_unallocated_material(i).batch_no,1,255)); dbms_output.put_line('x_unallocated_material('||to_char(i)||').material_detail_id='||TO_CHAR(x_unallocated_material(i).material_detail_id)); dbms_output.put_line('x_unallocated_material('||to_char(i)||').line_type='||TO_CHAR(x_unallocated_material(i).line_type)); dbms_output.put_line('x_unallocated_material('||to_char(i)||').line_no='||TO_CHAR(x_unallocated_material(i).line_no)); dbms_output.put_line('x_unallocated_material('||to_char(i)||').item_id='||TO_CHAR(x_unallocated_material(i).item_id)); dbms_output.put_line(SubStr('x_unallocated_material('||to_char(i)||').item_no='||x_unallocated_material(i).item_no,1,255)); dbms_output.put_line('x_unallocated_material('||to_char(i)||').alloc_qty='||TO_CHAR(x_unallocated_material(i).alloc_qty)); dbms_output.put_line('x_unallocated_material('||to_char(i)||').unalloc_qty='||TO_CHAR(x_unallocated_material(i).unalloc_qty)); dbms_output.put_line(SubStr('x_unallocated_material('||to_char(i)||').alloc_uom='||x_unallocated_material(i).alloc_uom,1,255)); END IF; END LOOP;END IF;
specified. Once again, however, there must be a valid Recipe Validity Rule that can used to createthe batch. See remark 3 on example 1 for more details.
3. Notice that when the API creating the batch (gme_api_pub.create_batch) is run, the transactionis not committed. Instead this is done at a later stage using the 'gme_api_pub.save_batch' API. The user may care to use this technique when, for example, creating and releasing a batch in asingle transaction.
Example 3: Creation using Output Quantity
set serveroutput onalter session set nls_language=american;
Following line is set the output buffer dbms_output.enable(100000);/*************************************************************************************** Enter your user id below* NOTE: To retrieve user_id Log on to the application.* Select to Production Supervisor responsibility* Navigate Others>Session parameters* You will see your USER ID and Username on the screen.* fnd_profile.initialize(user_id);**************************************************************************************/ set the applications context fnd_global.apps_initialize( USER_ID =>1007882, resp_id =>NULL, resp_appl_id =>NULL );
/*************************************************************************************** (R) = Required, (O) = Optional* enter your own plant_code (R), recipe_validity_Rule_Id(O), batch_type (R)* specify batch_no (R if testing manual doc ordering)* dates are optional;format of the dates is* TO_DATE('10OCT2001 12:00:00','DDMONYYYY HH24:MI:SS');* In esence you supply the date and appropriate format.* wip_whse_code is optional.* update_inventory_ind is optional and should only be used if the plant is a Lab.* 'Y'=Transactions to be created, 'N'=transactions should not be created.**************************************************************************************/
p_batch_header.plan_start_date := ''; TO_DATE('30JUL2006 12:00:00','DDMONYYYYHH24:MI:SS');p_batch_header.due_date := ''; TO_DATE('');p_batch_header.plan_cmplt_date := ''; TO_DATE('');p_batch_header.wip_whse_code := ''; you have the option to set the below param to N when testing Lab batch creationp_batch_header.update_inventory_ind := 'Y';
/*************************************************************************************** Now call the stored program* Leave first 4 parameters as they are* enter p_batch_size and p_batch_size_uom are required* if p_creation_mode is 'PRODUCT', 'OUTPUT', 'INPUT')* enter p_creation_mode = RECIPE, PRODUCT,OUTPUT,INPUT* p_batch_header_validity_rule_id OR p_recipe_id OR (p_recipe_no and p_recipe_version)* are required if p_creation_mode = 'RECIPE','INPUT','OUTPUT'* p_batch_header_validity_rule_id OR p_product_id OR p_product_no* are required if p_creation_mode = 'PRODUCT'* If p_ignore_shortages id passed as FALSE then in case of shortages* and profile option GMI:Allow negative inventory is set to Warning or Error* Batch will not be created and the x_unallocated procedure will be populated* with the material lines causing shortages.* p_ignore_qty_below_cap: If set to FALSE, then if the process quantity of any of* the resources in the batch is less than the minimum capacity for that resource* batch will not be created.**************************************************************************************/
/**************************************************************************************** Following line can be uncommented, if there are multiple messages return by the* API, and you want to see all those messages. These will be written to the Log file* If generated by the API.***************************************************************************************/ gme_debug.display_messages(x_message_count);
/**************************************************************************************** Output the results* One of the following will be the outcome of the API call( x_return_status)* S Success* E Error* U Unexpected Error* N Items failed auto allocation* V Inventory shortage exists***************************************************************************************/IF x_return_status <> FND_API.g_ret_sts_success THEN IF X_message_count = 1 THEN DBMS_OUTPUT.PUT_LINE('Error:'||X_message_list); ELSE FOR i IN 1..x_message_count LOOP FND_MSG_PUB.get (p_msg_index => i ,p_data => X_message_list ,p_msg_index_out => l_msg_index_out); DBMS_OUTPUT.PUT_LINE('Error: '||X_message_list); END LOOP;END IF;
1. See Remarks for both Example 1 and Example 2. As in Example 1, the Recipe and Versionnumbers are specified and like Example 2, the Product is specified. This example differs from theothers in that it allows the user to control both the recipe used and the output quantity. It basicallyprovides the same functionality as using the ‘Total Output’ tab when creating a batch in theapplication.
Example 4: Create, Release and Save Batch
alter session set nls_language=american;set serveroutput on size 100000;
IF x_return_status <> FND_API.g_ret_sts_success THEN IF X_message_count = 1 THEN DBMS_OUTPUT.PUT_LINE('Error:'||X_message_list); ELSE FOR i IN 1..x_message_count LOOP
IF x_return_status = FND_API.g_ret_sts_success THEN dbms_output.put_line('Batch Released'); p_batch_header.batch_id := x_batch_header.batch_id; SAVE THE CHANGES
gme_api_pub.save_batch( p_batch_header => p_batch_header, X_return_status => x_return_status, p_commit =>TRUE); else dbms_output.put_line('Batch Release failed'); IF X_message_count = 1 THEN DBMS_OUTPUT.PUT_LINE('Error:'||X_message_list); ELSE FOR i IN 1..x_message_count LOOP
FND_MSG_PUB.get (p_msg_index => i ,p_data => X_message_list ,p_msg_index_out => l_msg_index_out); DBMS_OUTPUT.PUT_LINE('Error: '||X_message_list); END LOOP; end if;
end if;end if;
EXCEPTION WHEN OTHERS THEN dbms_output.put_line('Error '||TO_CHAR(SQLCODE)||': '||SQLERRM);RAISE;
END;/
Remarks on example 4
This script creates, releases and saves a batch. Note that when the batch is created and released,these changes are not committed (that is to say, 'p_commit' is set to False). This enables the userto treat both batch creation and release as part of the same transaction and commit the changesif both operations succeed.
Example 5: Create a batch and insert an additional material line
alter session set nls_language=american;set serveroutput on size 100000
This is similar to Example 4 except that this time, once the batch is created, a newingredient line is added. The changes are then saved via the save batch API.
Example 6: Insert_line_allocation API
set serverout on size 100000alter session set nls_language=american;
EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.put_line('Error '||TO_CHAR(SQLCODE)||': '||SQLERRM);RAISE;END;/
Remarks on Example 6
This will create a line allocation for either an ingredient or product line. Note this API can be usedin conjunction with the gme_api_pub.insert_material_line API to both add and allocate a newmaterial line. Once again the gme_api_pub.save_batch procedure can be used to save bothtransactions once the user is sure there are no errors.
of the output product should have been recorded and the ingredients allocated. If the userhas any doubts about this, it is suggested that they create, release, allocate and attempt tocomplete a batch in the Application. If this can be done in the application then a batch inthe same state should be able to be completed using the API. Notice also in this examplethe commit is done at the end of the script i.e. after the save batch.
Example 8: Release, Record Usage and Complete step
alter session set nls_language=american;set serveroutput on size 1000000
if v_return_status = 'S' then l_certify := true; Save the changes gme_api_pub.save_batch(x_batch_header, v_return_status); dbms_output.put_line( 'save_batch: status='|| v_return_status); if v_return_status = 'S' then commit; else rollback; end if; else dbms_output.put_line( 'Certify step: status='|| v_return_status||', message='||v_message_list); rollback; end if; end if;
EXCEPTION WHEN OTHERS THEN dbms_output.put_line('Error '||TO_CHAR(SQLCODE)||': '||SQLERRM);RAISE;
END;/
Remarks on Example 8
This example releases a batch step, records actual resource usage and then completes thestep. Assuming all operations are successful, the changes are then saved using the savebatch API and the changes are committed.
Related Documents
Oracle Process Manufacturing Process Execution API User's Guide
subject to change without notice. Oracle does not warrant that this document is errorfree, nor does itprovide any other warranties or conditions, whether expressed orally or implied in law, includingimplied warranties and conditions of merchantability or fitness for a particular purpose. Oraclespecifically disclaims any liability with respect to this document and no contractual obligations areformed either directly or indirectly by this document. This document may not be reproduced ortransmitted in any form or by any means, electronic or mechanical, for any purpose, without the priorwritten permission of Oracle.