DECLARE
   CURSOR c_routing_header IS
      SELECT DISTINCT ROUTING_NO,
             ROUTING_VERS,
             ROUTING_DESC,
             EFFECTIVE_START_DATE,
             ROUTING_QTY,
             ROUTING_UOM,
             OWNER_ID,
             OWNER_ORGANIZATION_ID,
             ROUTING_STATUS,
             DELETE_MARK
        FROM mii_gmd_routing
       WHERE flag IS NULL;
 
   CURSOR c_routing_step (
      p_routing_no  varchar2
   )
   IS
      SELECT ROUTINGSTEP_NO
             , OPRN_NO
             , STEP_QTY
             , STEPRELEASE_TYPE
             , ROUTINGSTEP_NO1
             , DEP_ROUTINGSTEP_NO
             , DEP_TYPE
             , STANDARD_DELAY
             , TRANSFER_PCT
             , ROUTINGSTEP_NO_UOM
        FROM mii_gmd_routing
       WHERE flag IS NULL
         AND routing_no = p_routing_no
       ORDER BY routingstep_no;
 
   l_routings                gmd_routings%ROWTYPE;
   l_routings_step_tbl       gmd_routings_pub.gmd_routings_step_tab;
   l_routings_step_dep_tbl   gmd_routings_pub.gmd_routings_step_dep_tab;
   l_count                   NUMBER                                     := 0;
   l_loop_cnt                NUMBER                                     := 0;
   l_record_count            NUMBER                                     := 0;
   l_data                    VARCHAR2 (4000);
   l_return_status           VARCHAR2 (1);
   l_status                  VARCHAR2 (1);
   i                         NUMBER                                     := 1;
   l_dummy_cnt               NUMBER;
   l_api_version             NUMBER                                     := 1;
   l_init_msg_list           BOOLEAN;
   l_commit                  BOOLEAN;
   return_sts                BOOLEAN;
 
   v_routingstep_no           number;
   v_oprn_id                  number;
   v_oprn_no                  varchar2(100);
   v_step_qty                 number;
   v_steprelease_type         number;
   v_routingstep_no1           number;
   v_dep_routingstep_no       number;
   v_dep_type                 number;
   v_standard_delay           number;
   v_transfer_pct             number;
   v_routingstep_no_uom           varchar2(100);
   v_count                      number;
BEGIN

   fnd_global.apps_initialize (user_id           => 1090,
                               resp_id           => 22882,
                               resp_appl_id      => 552
                              );

   l_init_msg_list := TRUE;
   l_commit := TRUE;

   FOR l_routing_header IN c_routing_header
   LOOP
      l_routings.routing_no := l_routing_header.routing_no;
      l_routings.routing_vers := l_routing_header.routing_vers;
      l_routings.routing_desc := l_routing_header.routing_desc;
      l_routings.routing_qty := l_routing_header.routing_qty;
      –l_routings.item_um := l_routing_header.item_um;
      l_routings.routing_uom := l_routing_header.routing_uom;
      l_routings.effective_start_date := l_routing_header.effective_start_date;
      l_routings.owner_id := l_routing_header.owner_id;
      l_routings.routing_status := l_routing_header.routing_status;
      l_routings.delete_mark := l_routing_header.delete_mark;
      l_routings.owner_organization_id := l_routing_header.owner_organization_id;
 
      SELECT COUNT(*)
        INTO v_count
        FROM mii_gmd_routing
       WHERE flag IS NULL
         AND routing_no = l_routing_header.routing_no;
       
      OPEN c_routing_step (l_routing_header.routing_no);
      FOR i IN 1 .. v_count
      LOOP
         FETCH c_routing_step INTO v_routingstep_no,
                                   v_oprn_no,
                                   v_step_qty,
                                   v_steprelease_type,
                                   v_routingstep_no1,
                                   v_dep_routingstep_no,
                                   v_dep_type,
                                   v_standard_delay,
                                   v_transfer_pct,
                                   v_routingstep_no_uom;
       
         SELECT oprn_id
           INTO v_oprn_id
           FROM GMD_OPERATIONS_VL    
          WHERE oprn_no = v_oprn_no;
       
         –dbms_output.put_line (‘v_oprn_id: ‘ || v_oprn_id);
                                 
         l_routings_step_tbl (i).routingstep_no := v_routingstep_no;
         l_routings_step_tbl (i).oprn_id := v_oprn_id;
         l_routings_step_tbl (i).step_qty := v_step_qty;
         l_routings_step_tbl (i).steprelease_type := v_steprelease_type;
       
         –dbms_output.put_line (‘l_routings_step_tbl (‘||i||’).routingstep_no: ‘ || l_routings_step_tbl (i).routingstep_no);
       
         –IF v_routingstep_no1 IS NOT NULL THEN
            l_routings_step_dep_tbl (i).routingstep_no := v_routingstep_no1;
            l_routings_step_dep_tbl (i).dep_routingstep_no := v_dep_routingstep_no;
            l_routings_step_dep_tbl (i).dep_type := v_dep_type;
            l_routings_step_dep_tbl (i).standard_delay := v_standard_delay;
            l_routings_step_dep_tbl (i).transfer_pct := v_transfer_pct;
            l_routings_step_dep_tbl (i).routingstep_no_uom := v_routingstep_no_uom;
         –END IF;
       
         UPDATE mii_gmd_routing
         set flag = ‘Y’
         WHERE routing_no = l_routing_header.routing_no
         AND oprn_no = v_oprn_no;
      END LOOP;
     
      CLOSE c_routing_step;
     
      –DBMS_OUTPUT.put_line (‘Value Test ‘ || l_routings.routing_no);

      gmd_routings_pub.insert_routing
                          (p_api_version                => 1.0,
                           p_init_msg_list              => l_init_msg_list,
                           p_commit                     => l_commit,
                           p_routings                   => l_routings,
                           p_routings_step_tbl          => l_routings_step_tbl,
                           p_routings_step_dep_tbl      => l_routings_step_dep_tbl,
                           x_message_count              => l_count,
                           x_return_status              => l_return_status,
                           x_message_list               => l_data
                          );
     
     
   END LOOP;
 
   IF l_count >= 0
   THEN
      l_loop_cnt := 1;

      LOOP
         fnd_msg_pub.get (p_msg_index          => l_loop_cnt,
                          p_data               => l_data,
                          p_encoded            => fnd_api.g_false,
                          p_msg_index_out      => l_dummy_cnt
                         );
         DBMS_OUTPUT.put_line (‘Record = ‘ || l_loop_cnt);
         DBMS_OUTPUT.put_line (l_data);

         IF l_status = ‘E’ OR l_status = ‘U’
         THEN
            l_data := CONCAT (‘ERROR ‘, l_data);
         END IF;

         DBMS_OUTPUT.put_line (l_data);

         IF (l_status = ‘U’)
         THEN
            l_return_status := l_status;
         ELSIF (l_status = ‘E’ AND l_return_status <> ‘U’)
         THEN
            l_return_status := l_status;
         ELSE
            l_return_status := l_status;
         END IF;

         l_loop_cnt := l_loop_cnt + 1;

         IF l_loop_cnt > l_count
         THEN
            EXIT;
         END IF;
      END LOOP;
   END IF;
   COMMIT;
END;

API Material:

DECLARE
   CURSOR c_master IS
      SELECT *
        FROM nfi_gmd_recipe
       WHERE flag = ‘V’
         AND routing_no IS NOT NULL;
 
   CURSOR c_formula (
      p_formula_id  number
   )
   IS
      SELECT *
        FROM FM_MATL_DTL
       WHERE formula_id = p_formula_id
       ORDER BY line_type, line_no;

   l_recipe_flex_tbl     gmd_recipe_detail.recipe_flex;
   l_recipe_mtl_tbl      gmd_recipe_detail.recipe_mtl_tbl;
   l_recipe              nfi_gmd_recipe%ROWTYPE;
   l_formula             FM_MATL_DTL%ROWTYPE;
   l_count               NUMBER                        := 0;
   l_count_mtl               NUMBER                        := 0;
   l_loop_cnt            NUMBER                        := 0;
   l_record_count        NUMBER                        := 0;
   l_data                VARCHAR2 (2000);
   l_data_mtl                VARCHAR2 (2000);
   l_return_status       VARCHAR2 (1);
   l_status              VARCHAR2 (1);
   i                     NUMBER                        := 1;
   l_dummy_cnt           NUMBER;
   l_api_version         NUMBER                        := 1;
   l_init_msg_list       BOOLEAN;
   l_commit              BOOLEAN;
   return_sts            BOOLEAN;
   v_routing_id          number;
   v_formula_id          number;
   v_routingstep_id      number;
   v_formulaline_id      number;
 
BEGIN
–FND_GLOBAL.APPS_INITIALIZE(1112,22882,552,0);
   fnd_global.apps_initialize (user_id           => 1090,
                               resp_id           => 50618,
                               resp_appl_id      => 552
                              );
 
   l_init_msg_list := TRUE;
   l_commit := TRUE;
 
   i := i;
 
—   IF NOT c_master%ISOPEN THEN
—      CLOSE c_master;
—   END IF;
 
   OPEN c_master;
 
   LOOP
      FETCH c_master INTO l_recipe;
      exit WHEN c_master%NOTFOUND;
     
      IF l_recipe.routing_no IS NOT NULL THEN
         SELECT routing_id
           INTO v_routing_id
           FROM fm_rout_hdr
          WHERE routing_no = l_recipe.routing_no
            AND routing_vers = l_recipe.routing_vers;
      END IF;
       
      SELECT formula_id
        INTO v_formula_id
        FROM FM_FORM_MST
       WHERE formula_no = l_recipe.formula_no
         AND formula_vers = l_recipe.formula_vers;
       
     
     
      IF l_recipe.routing_no IS NOT NULL THEN
       
         OPEN c_formula(v_formula_id);
         LOOP
            FETCH c_formula INTO l_formula;
            exit WHEN c_formula%NOTFOUND;
           
            IF l_formula.line_type = -1 AND l_formula.line_no = 1 THEN
               SELECT routingstep_id
                 INTO v_routingstep_id
                 FROM fm_rout_dtl
                WHERE routing_id = v_routing_id
                  AND routingstep_no = 10;
                 
            ELSIF  l_formula.line_type = -1 AND l_formula.line_no > 1 THEN
               SELECT routingstep_id
                 INTO v_routingstep_id
                 FROM fm_rout_dtl
                WHERE routing_id = v_routing_id
                  AND routingstep_no = 20;
           
            ELSIF  l_formula.line_type = 1 THEN
               SELECT routingstep_id
                 INTO v_routingstep_id
                 FROM fm_rout_dtl
                WHERE routing_id = v_routing_id
                  AND routingstep_no = 30;
                       
            END IF;
           
            l_recipe_mtl_tbl (i).recipe_no := l_recipe.recipe_no;
            l_recipe_mtl_tbl (i).recipe_version := l_recipe.recipe_version;
            l_recipe_mtl_tbl (i).formulaline_id := l_formula.formulaline_id;
            l_recipe_mtl_tbl (i).routingstep_id := v_routingstep_id;
           
            DBMS_OUTPUT.put_line(i);
            DBMS_OUTPUT.put_line(l_recipe_mtl_tbl (i).formulaline_id);
            DBMS_OUTPUT.put_line(l_recipe_mtl_tbl (i).recipe_no);
            i := i + 1;
           
            –DBMS_OUTPUT.put_line (‘Value Test ‘ || i || ‘: ‘|| l_recipe_mtl_tbl (i).recipe_no);
         END LOOP;
       
         CLOSE c_formula;
      END IF;
     
     
      UPDATE nfi_gmd_recipe
         set flag = ‘M’
       WHERE recipe_no = l_recipe.recipe_no;  
           
   END LOOP;
   
      CLOSE c_master;
      gmd_recipe_detail.create_recipe_mtl
                                  (p_api_version             => 1.0,
                                   –p_init_msg_list           => FND_API.G_TRUE,
                                   –p_commit                  => FND_API.G_TRUE,    
                                   p_called_from_forms       => ‘NO’,                      
                                   x_return_status           => l_return_status,
                                   x_msg_count               => l_count_mtl,
                                   x_msg_data                => l_data_mtl,
                                   p_recipe_mtl_tbl           => l_recipe_mtl_tbl,
                                   p_recipe_mtl_flex          => l_recipe_flex_tbl
                                  );                        
         
 
   IF l_count_mtl >= 0
   THEN
      l_loop_cnt := 1;

      LOOP
         fnd_msg_pub.get (p_msg_index          => l_loop_cnt,
                          p_data               => l_data_mtl,
                          p_encoded            => fnd_api.g_false,
                          p_msg_index_out      => l_dummy_cnt
                         );
         DBMS_OUTPUT.put_line (‘Record = ‘ || l_loop_cnt);
         DBMS_OUTPUT.put_line (l_data_mtl);

         IF l_status = ‘E’ OR l_status = ‘U’
         THEN
            l_data_mtl := CONCAT (‘ERROR ‘, l_data_mtl);
         END IF;

         DBMS_OUTPUT.put_line (l_data_mtl);

         IF (l_status = ‘U’)
         THEN
            l_return_status := l_status;
         ELSIF (l_status = ‘E’ AND l_return_status <> ‘U’)
         THEN
            l_return_status := l_status;
         ELSE
            l_return_status := l_status;
         END IF;

         l_loop_cnt := l_loop_cnt + 1;

         IF l_loop_cnt > l_count_mtl
         THEN
            EXIT;
         END IF;
      END LOOP;
   END IF;
   COMMIT;

END;

API Validity Rule:

DECLARE
   CURSOR c_master IS
      SELECT *
        FROM nfi_gmd_recipe
       WHERE flag = ‘Y’;
 
     
   l_recipe_flex_tbl     gmd_recipe_detail.recipe_flex;
   l_recipe_vr_tbl       gmd_recipe_detail.recipe_vr_tbl;
   l_recipe              nfi_gmd_recipe%ROWTYPE;
   l_formula             FM_MATL_DTL%ROWTYPE;
   l_count               NUMBER                        := 0;
   l_count_mtl               NUMBER                        := 0;
   l_loop_cnt            NUMBER                        := 0;
   l_record_count        NUMBER                        := 0;
   l_data                VARCHAR2 (2000);
   l_data_mtl                VARCHAR2 (2000);
   l_return_status       VARCHAR2 (1);
   l_status              VARCHAR2 (1);
   i                     NUMBER                        := 1;
   l_dummy_cnt           NUMBER;
   l_api_version         NUMBER                        := 1;
   l_init_msg_list       BOOLEAN;
   l_commit              BOOLEAN;
   return_sts            BOOLEAN;
   v_routing_id          number;
   v_formula_id          number;
   v_routingstep_id      number;
   v_formulaline_id      number;
 
BEGIN
–FND_GLOBAL.APPS_INITIALIZE(1112,22882,552,0);
   fnd_global.apps_initialize (user_id           => 1090,
                               resp_id           => 50618,
                               resp_appl_id      => 552
                              );
 
   l_init_msg_list := TRUE;
   l_commit := TRUE;
 
   i := 0;
 
   DBMS_OUTPUT.put_line (‘Open cursor’);
 
   OPEN c_master;
 
   LOOP
      FETCH c_master INTO l_recipe;
      exit WHEN c_master%NOTFOUND;
     
           
      l_recipe_vr_tbl (c_master%ROWCOUNT).recipe_no := l_recipe.recipe_no;
      l_recipe_vr_tbl (c_master%ROWCOUNT).recipe_version := l_recipe.recipe_version;
      l_recipe_vr_tbl (c_master%ROWCOUNT).organization_id := l_recipe.organization_id;
      l_recipe_vr_tbl (c_master%ROWCOUNT).start_date := l_recipe.start_date;
     
     
 
      DBMS_OUTPUT.put_line (‘Value Test ‘ || c_master%ROWCOUNT || ‘: ‘|| l_recipe_vr_tbl (c_master%ROWCOUNT).recipe_no);
     
      UPDATE nfi_gmd_recipe
         set flag = ‘V’
       WHERE recipe_no = l_recipe.recipe_no;  
           
   END LOOP;
 
    CLOSE c_master;
    DBMS_OUTPUT.put_line (‘Close cursor’);
   
      gmd_recipe_detail.create_recipe_vr
                                  (p_api_version             => 1.0,
                                   p_init_msg_list           => fnd_api.g_true,
                                   p_commit                  => fnd_api.g_true,    
                                   p_called_from_forms       => ‘NO’,                      
                                   x_return_status           => l_return_status,
                                   x_msg_count               => l_count,
                                   x_msg_data                => l_data,
                                   p_recipe_vr_tbl           => l_recipe_vr_tbl,
                                   p_recipe_vr_flex          => l_recipe_flex_tbl
                                  );                        
       
   UPDATE GMD_RECIPE_VALIDITY_RULES
      set VALIDITY_RULE_STATUS = 700
    WHERE VALIDITY_RULE_STATUS != 700;
 
   IF l_count >= 0
   THEN
      l_loop_cnt := 1;

      LOOP
         fnd_msg_pub.get (p_msg_index          => l_loop_cnt,
                          p_data               => l_data,
                          p_encoded            => fnd_api.g_false,
                          p_msg_index_out      => l_dummy_cnt
                         );
         DBMS_OUTPUT.put_line (‘Record = ‘ || l_loop_cnt);
         DBMS_OUTPUT.put_line (l_data);

         IF l_status = ‘E’ OR l_status = ‘U’
         THEN
            l_data := CONCAT (‘ERROR ‘, l_data);
         END IF;

         DBMS_OUTPUT.put_line (l_data);

         IF (l_status = ‘U’)
         THEN
            l_return_status := l_status;
         ELSIF (l_status = ‘E’ AND l_return_status <> ‘U’)
         THEN
            l_return_status := l_status;
         ELSE
            l_return_status := l_status;
         END IF;

         l_loop_cnt := l_loop_cnt + 1;

         IF l_loop_cnt > l_count
         THEN
            EXIT;
         END IF;
      END LOOP;
   END IF;
   COMMIT;

END;

API Recipe Header:

DECLARE
CURSOR c_master IS
SELECT *
FROM nfi_gmd_recipe
WHERE flag IS NULL;

l_recipe_header_tbl gmd_recipe_header.recipe_tbl;
l_recipe_flex_tbl gmd_recipe_header.recipe_flex;
l_recipe nfi_gmd_recipe%ROWTYPE;
l_formula FM_MATL_DTL%ROWTYPE;
l_count NUMBER := 0;
l_count_mtl NUMBER := 0;
l_loop_cnt NUMBER := 0;
l_record_count NUMBER := 0;
l_data VARCHAR2 (2000);
l_data_mtl VARCHAR2 (2000);
l_return_status VARCHAR2 (1);
l_status VARCHAR2 (1);
i NUMBER := 1;
l_dummy_cnt NUMBER;
l_api_version NUMBER := 1;
l_init_msg_list BOOLEAN;
l_commit BOOLEAN;
return_sts BOOLEAN;
v_routing_id number;
v_formula_id number;
v_routingstep_id number;
v_formulaline_id number;

BEGIN
–FND_GLOBAL.APPS_INITIALIZE(1112,22882,552,0);
fnd_global.apps_initialize (user_id => 1090,
resp_id => 50618,
resp_appl_id => 552
);

l_init_msg_list := TRUE;
l_commit := TRUE;

DBMS_OUTPUT.put_line (‘Open cursor’);

OPEN c_master;

LOOP
FETCH c_master INTO l_recipe;
exit WHEN c_master%NOTFOUND;

IF l_recipe.routing_no IS NOT NULL THEN
SELECT routing_id
INTO v_routing_id
FROM fm_rout_hdr
WHERE routing_no = l_recipe.routing_no
AND routing_vers = l_recipe.routing_vers;

l_recipe_header_tbl (c_master%ROWCOUNT).routing_id := v_routing_id;

END IF;

SELECT formula_id
INTO v_formula_id
FROM FM_FORM_MST
WHERE formula_no = l_recipe.formula_no
AND formula_vers = l_recipe.formula_vers;

l_recipe_header_tbl (c_master%ROWCOUNT).recipe_no := l_recipe.recipe_no;
l_recipe_header_tbl (c_master%ROWCOUNT).recipe_description := l_recipe.recipe_description;
l_recipe_header_tbl (c_master%ROWCOUNT).recipe_version := l_recipe.recipe_version;
l_recipe_header_tbl (c_master%ROWCOUNT).user_id := 1090;
l_recipe_header_tbl (c_master%ROWCOUNT).owner_organization_id := l_recipe.owner_organization_id;
l_recipe_header_tbl (c_master%ROWCOUNT).formula_id := v_formula_id;

l_recipe_header_tbl (c_master%ROWCOUNT).recipe_status := ‘700’;

DBMS_OUTPUT.put_line (‘Value Test ‘ || c_master%ROWCOUNT || ‘: ‘|| l_recipe_header_tbl (c_master%ROWCOUNT).recipe_no);

UPDATE nfi_gmd_recipe
set flag = ‘Y’
WHERE recipe_no = l_recipe.recipe_no;

END LOOP;

CLOSE c_master;

DBMS_OUTPUT.put_line (‘Close cursor’);

gmd_recipe_header.create_recipe_header
(p_api_version => 1.0,
–p_init_msg_list => FND_API.G_TRUE,
–p_commit => FND_API.G_TRUE,
p_recipe_header_tbl => l_recipe_header_tbl,
p_recipe_header_flex => l_recipe_flex_tbl,
x_return_status => l_return_status,
x_msg_count => l_count,
x_msg_data => l_data
);

IF l_count >= 0
THEN
l_loop_cnt := 1;

LOOP
fnd_msg_pub.get (p_msg_index => l_loop_cnt,
p_data => l_data,
p_encoded => fnd_api.g_false,
p_msg_index_out => l_dummy_cnt
);
DBMS_OUTPUT.put_line (‘Record = ‘ || l_loop_cnt);
DBMS_OUTPUT.put_line (l_data);

IF l_status = ‘E’ OR l_status = ‘U’
THEN
l_data := CONCAT (‘ERROR ‘, l_data);
END IF;

DBMS_OUTPUT.put_line (l_data);

IF (l_status = ‘U’)
THEN
l_return_status := l_status;
ELSIF (l_status = ‘E’ AND l_return_status <> ‘U’)
THEN
l_return_status := l_status;
ELSE
l_return_status := l_status;
END IF;

l_loop_cnt := l_loop_cnt + 1;

IF l_loop_cnt > l_count
THEN
EXIT;
END IF;
END LOOP;
END IF;
COMMIT;

END;

API Formula:

DECLARE
   CURSOR c_header IS
      SELECT DISTINCT formula_no
      FROM mii_gmd_formula
       WHERE flag IS NULL;
     
   CURSOR c_master  (
      p_formula     varchar2
   ) IS
      SELECT *
        FROM mii_gmd_formula
       WHERE flag IS NULL
         AND formula_no = p_formula;
     
   l_formula_header_tbl   gmd_formula_pub.formula_insert_hdr_tbl_type;
   l_formula              mii_gmd_formula%ROWTYPE;
   l_count                NUMBER                                      := 0;
   l_loop_cnt             NUMBER                                      := 0;
   l_record_count         NUMBER                                      := 0;
   l_data                 VARCHAR2 (2000);
   l_return_status        VARCHAR2 (1);
   l_status               VARCHAR2 (1);
   i                      NUMBER                                      := 1;
   l_dummy_cnt            NUMBER;
   l_api_version          NUMBER                                      := 1;
   l_init_msg_list        BOOLEAN;
   l_commit               BOOLEAN;
   return_sts             BOOLEAN;
   v_item_id              number;
   v_organization_id      number;
   v_user_id                            number;
BEGIN
–FND_GLOBAL.APPS_INITIALIZE(1112,22882,552,0);
   fnd_global.apps_initialize (user_id           => 1090,
                               resp_id           => 22882,
                               resp_appl_id      => 552
                              );
/*FND_GLOBAL.APPS_INITIALIZE(user_id, resp_id, resp_appl_id);*/
   l_init_msg_list := TRUE;
   l_commit := TRUE;

FOR l_header IN c_header  
LOOP
   OPEN c_master(l_header.formula_no);
   LOOP
      FETCH c_master INTO l_formula;
      exit WHEN c_master%NOTFOUND;
     
      dbms_output.put_line (c_master%ROWCOUNT);
      BEGIN
         SELECT DISTINCT inventory_item_id
           INTO v_item_id
           FROM mtl_system_items_b
          WHERE segment1 = UPPER(l_formula.inventory_item_code);
     
         SELECT organization_id
          INTO v_organization_id
           FROM mtl_parameters
          WHERE organization_code = l_formula.owner_organization_code;
     
         SELECT user_id
           INTO v_user_id
           FROM fnd_user
          WHERE user_name = l_formula.owner_name;
      EXCEPTION
         WHEN others THEN
            UPDATE mii_gmd_formula
             set flag = ‘E’
             –, note = ‘Ada exception’
            WHERE formula_no = l_formula.formula_no;
      END;
      l_formula_header_tbl (c_master%ROWCOUNT).record_type := ‘I’;
      l_formula_header_tbl (c_master%ROWCOUNT).formula_no := UPPER(l_formula.formula_no);
      l_formula_header_tbl (c_master%ROWCOUNT).formula_vers := l_formula.formula_vers;
      l_formula_header_tbl (c_master%ROWCOUNT).formula_type := l_formula.formula_type;
      l_formula_header_tbl (c_master%ROWCOUNT).formula_desc1 := l_formula.formula_desc1;
      l_formula_header_tbl (c_master%ROWCOUNT).formula_class := l_formula.formula_class;
      l_formula_header_tbl (c_master%ROWCOUNT).inactive_ind := l_formula.inactive_ind;
      l_formula_header_tbl (c_master%ROWCOUNT).owner_organization_id := v_organization_id;
      l_formula_header_tbl (c_master%ROWCOUNT).formula_status := l_formula.formula_status;
      l_formula_header_tbl (c_master%ROWCOUNT).owner_id := v_user_id;
      l_formula_header_tbl (c_master%ROWCOUNT).line_type := l_formula.line_type;
      l_formula_header_tbl (c_master%ROWCOUNT).line_no := l_formula.line_no;
      l_formula_header_tbl (c_master%ROWCOUNT).inventory_item_id := v_item_id;
      l_formula_header_tbl (c_master%ROWCOUNT).qty := l_formula.qty;
      l_formula_header_tbl (c_master%ROWCOUNT).detail_uom := l_formula.detail_uom;
      l_formula_header_tbl (c_master%ROWCOUNT).release_type := l_formula.release_type;
      l_formula_header_tbl (c_master%ROWCOUNT).scale_type_hdr := l_formula.scale_type_hdr;
      l_formula_header_tbl (c_master%ROWCOUNT).scale_type_dtl := l_formula.scale_type_dtl;
      l_formula_header_tbl (c_master%ROWCOUNT).cost_alloc := l_formula.cost_alloc;
      l_formula_header_tbl (c_master%ROWCOUNT).CONTRIBUTE_YIELD_IND := l_formula.CONTRIBUTE_YIELD_IND;
      l_formula_header_tbl (c_master%ROWCOUNT).PHANTOM_TYPE := l_formula.PHANTOM_TYPE;
      l_formula_header_tbl (c_master%ROWCOUNT).delete_mark := l_formula.delete_mark;
      l_formula_header_tbl (c_master%ROWCOUNT).CONTRIBUTE_STEP_QTY_IND := ‘N’;
     
     
      DBMS_OUTPUT.put_line (‘Value Test ‘ || l_formula_header_tbl (1).formula_no);
     
—      UPDATE mii_gmd_formula
—         set flag = ‘Y’
—       WHERE formula_no = l_formula.formula_no
—         AND line_no = l_formula.line_no
—         AND inventory_item_code = l_formula.inventory_item_code;
       
   END LOOP;
 
   CLOSE c_master;
 
   gmd_formula_pub.insert_formula
                                (p_api_version             => 1.0,
                                 p_formula_header_tbl      => l_formula_header_tbl,
                                 x_return_status           => l_return_status,
                                 x_msg_count               => l_count,
                                 x_msg_data                => l_data
                                );
                                DBMS_OUTPUT.put_line (‘l_return_status:’||l_return_status);
                                DBMS_OUTPUT.put_line (‘l_data:’||l_data);
                               
   –IF l_return_status = ‘E’ OR l_return_status = ‘U’
   —      THEN
            UPDATE mii_gmd_formula
             set flag = l_return_status
             –, note = l_data
       WHERE formula_no = l_formula.formula_no;
—   ELSE
—     UPDATE mii_gmd_formula
—             set flag = ‘Y’
—             , note = l_data
—       WHERE formula_no = l_formula.formula_no;
—   END IF;                            
                                   
END LOOP;
/*
   IF l_count >= 0
   THEN
      l_loop_cnt := 1;

      LOOP
         fnd_msg_pub.get (p_msg_index          => l_loop_cnt,
                          p_data               => l_data,
                          p_encoded            => fnd_api.g_false,
                          p_msg_index_out      => l_dummy_cnt
                         );
         DBMS_OUTPUT.put_line (‘Record = ‘ || l_loop_cnt);
         DBMS_OUTPUT.put_line (l_data);

         IF l_status = ‘E’ OR l_status = ‘U’
         THEN
            l_data := CONCAT (‘ERROR ‘, l_data);
         END IF;

         DBMS_OUTPUT.put_line (l_data);

         IF (l_status = ‘U’)
         THEN
            l_return_status := l_status;
         ELSIF (l_status = ‘E’ AND l_return_status <> ‘U’)
         THEN
            l_return_status := l_status;
         ELSE
            l_return_status := l_status;
         END IF;

         l_loop_cnt := l_loop_cnt + 1;

         IF l_loop_cnt > l_count
         THEN
            EXIT;
         END IF;
      END LOOP;
   END IF;*/
   COMMIT;

END;

Background:
When we run, the following SQL Query/Script will provide the profile option values set at different levels. That is Site, Application, Responsibility, User.
So, this script lists ALL Users/Responsibilities/Applications set against a particular Profile option

SQL Script:
Enter ‘Profile Option Name’ while running this query.
Eg. FND: Debug Log EnabledMO: Operating Unit
[You can get the exact name from table fnd_profile_options_tl]  

  SELECT fpo.profile_option_name SHORT_NAME,
         fpot.user_profile_option_name NAME,
         DECODE (fpov.level_id,
                 10001, ‘Site’,
                 10002, ‘Application’,
                 10003, ‘Responsibility’,
                 10004, ‘User’,
                 10005, ‘Server’,
                 ‘UnDef’)
            LEVEL_SET,
         DECODE (TO_CHAR (fpov.level_id),
                 ‘10001’, ”,
                 ‘10002’, fap.application_short_name,
                 ‘10003’, frsp.responsibility_key,
                 ‘10005’, fnod.node_name,
                 ‘10006’, hou.name,
                 ‘10004’, fu.user_name,
                 ‘UnDef’)
            “CONTEXT”,
         fpov.profile_option_value VALUE
    FROM fnd_profile_options fpo,
         fnd_profile_option_values fpov,
         fnd_profile_options_tl fpot,
         fnd_user fu,
         fnd_application fap,
         fnd_responsibility frsp,
         fnd_nodes fnod,
         hr_operating_units hou
   WHERE     fpo.profile_option_id = fpov.profile_option_id(+)
         AND fpo.profile_option_name = fpot.profile_option_name
         AND fu.user_id(+) = fpov.level_value
         AND frsp.application_id(+) = fpov.level_value_application_id
         AND frsp.responsibility_id(+) = fpov.level_value
         AND fap.application_id(+) = fpov.level_value
         AND fnod.node_id(+) = fpov.level_value
         AND hou.organization_id(+) = fpov.level_value
         AND fpot.user_profile_option_name IN (‘&User_Profile_Option_Name’)
ORDER BY short_name;

Developing XML Publisher Report – Using Data Template as Data Source

Background: 
Developing XML Publisher Report – Using Data Template(.xml) as Data Source and Template(.rtf) as Layout.
Note that, we can use .rdf file as data source. But for this demo we are using Date XML Template.
Prerequisite for the below Example:

1. Create a table
CREATE TABLE demo_products
(  product_code   NUMBER,
   product_name   VARCHAR2 (100));

2. Insert Values
INSERT INTO demo_products
     VALUES (569, ‘Oracle Cost Management’);
3. Issue Commit

Step1: Define Data Template:

The data template is the method by which you communicate your request for data to the data engine.
The data template is an XML document that consists of four basic sections:  

  • Define parameters: In which parameters are declared in child <parameter> elements
  • Define triggers:
  • Define data query: In which the SQL queries are defined in child <sqlStatement> elements
  • Define data structure: In which the output XML structure is defined
 Create Data Template: (Save this file as XXDPDT.xml)
<?xml version=”1.0″ encoding=”UTF-8″?>
<dataTemplate name=”demoProductsDT” description=”Demo Products Details” version=”1.0″>
   <parameters>
     <parameter name=”p_product_id” datatype=”number”/>
   </parameters>
  <dataQuery>
    <sqlStatement name=”DQ”>
         <![CDATA[ SELECT product_code, product_name FROM demo_products 
                            WHERE product_code = NVL(:p_product_id,product_code) ]]>
    </sqlStatement>
  </dataQuery>
  <dataStructure>
    <group name=”G_DP” source=”DQ”>
      <element name=”PRODUCT_CODE” value=”product_code”/>
      <element name=”PRODUCT_NAME” value=”product_name”/>
    </group>
  </dataStructure>
</dataTemplate>
  • This Data Template selects the product details from the demo_products table. It uses a bind parameter to find the product name against the product code.
  • For each bind parameter in the query , we need to define a Parameter in the Concurrent Program

Step 2: Create Data Definition & Associate with Data Template
Navigation: XML Publisher Administrator -> Data Definitions -> Create Data Definition
Screen 1 : Create Data Definition
       Enter the data definition Details and click on Apply. Note down the Code. 
       The code should be used as the short name of the concurrent program.

Screen 2: Associate Data Template
       View Data Definition
Click on ‘Add File’ button to upload Data Template file that was created through step 1
Screen 3: Data Definiton
       Data Template is associated with Data Definition

Step 3: Define a Concurrent Program to generate the Data XML output. 
Note:
1. Output format should be XML
2. Short Name in the concurrent program and Code in the data definition should be same.
Screen 2: Concurrent Program – Parameters
For each parameter in the Data Template, define a parameter in the concurrent program.
The Data Template parameter name should match the concurrent program parameter token
Note:
Token is p_product_id. This is the bind parameter we have used in date template. For every bind parameter used in the data template, we have to define parameter in the concurrent program.
Screen 3: Associate the Concurrent Program to a request group.
Screen 4: Execute the concurrent program “Product Demo Report”and click on the output button get the Data XML. Save the XML file. We will use it to generate the RTF Template.
Screen 5: Concurrent Program Output
Note:
We are getting the output in xml because we didn’t define template & associated yet.

Step 4: Define the RTF Template using the Generated Data XML

Pre-requisite : Install XML Publisher Desktop
After installation following Menus & Toolbars gets added to the MS Word.

Load XML Data generated by Concurrent Program
Data -> Load XML Data
Message after loading the data
Using the Table Wizard as below to create the ‘Table Report Format’ with the columns of demo_products.

Final Output layout look like this.

Save this file with .rtf extension
Step 5: Registering the Template with BI Publisher
Navigation: XML Publisher Administrator -> Templates -> Create Template

Step 6: Run the concurrent program to see the output

Note:

As already mentioned output format can be anything. Here it is pdf. We can select format that we want at the runtime.

References:
http://www.oracle.com/technology/products/xml-publisher/index.htm
http://www.oracle.com/technetwork/middleware/bi-publisher/overview/index.html
http://xdo.us.oracle.com
Oracle® XML Publisher Administration and Developer’s Guide

FAQ:
What is XDODTEXE used in the Executable section of Concurrent Program?

XDODTEXE is a BI Publisher Data Template Executable. The purpose of this executable is to identify data template file (.xml) and execute the data template to generate the raw xml data, that later can be used by BI Publisher formatting engine to format as as per the layout (RTF, PDF etc).
This executable will be used by all the BI Publisher reports (Concurrent Program) which are using Data Template to generate the xml data. 

Standard Package : INV_CONVERT

Get the Conversion rate from below function easily.

FUNCTION inv_um_convert (p_item_id IN NUMBER,
                          p_from_uom_code IN VARCHAR2,
                          p_to_uom_code IN VARCHAR2) RETURN NUMBER; 

select msi.segment1,
        msi.primary_uom_code,
        ‘Kg’ as second_uom,
        inv_convert.inv_um_convert (msi.inventory_item_id, ‘kg’
                                   msi.primary_uom_code) as coefficient from mtl_system_items_b
where msi.segment1 = ‘OEAG01-ITEM’;