Friday, October 4, 2013

API to Check the Available credit On a Sales Order.


 --Mainline Function that will read an Order Header and Determine if should be checked, Consumes available Credit and applies a credit hold if Appropriate

DECLARE
   l_header_id                                       NUMBER;
   l_calling_action                                  VARCHAR2 (200);
   l_msg_index                                       NUMBER;
   l_error_message                                   VARCHAR2 (2000);
   x_msg_count                                       NUMBER;
   x_msg_data                                        VARCHAR2 (200);
   x_result_out                                      VARCHAR2 (200);
   x_return_status                                   VARCHAR2 (200);
BEGIN
   l_header_id                                              := 885421;
   l_calling_action                                         := 'BOOKING';
   x_msg_count                                              := NULL;
   x_msg_data                                               := NULL;
   x_result_out                                             := NULL;
   x_return_status                                          := NULL;
   apps.oe_credit_pub.check_available_credit (p_header_id                   => l_header_id
                                            , p_calling_action              => l_calling_action
                                            , p_msg_count                   => x_msg_count
                                            , p_msg_data                    => x_msg_data
                                            , p_result_out                  => x_result_out
                                            , p_return_status               => x_return_status
                                             );

   IF x_return_status <> fnd_api.g_ret_sts_success
   THEN
      FOR i IN 1 .. x_msg_count
      LOOP
         apps.fnd_msg_pub.get (p_msg_index                   => i
                             , p_encoded                     => fnd_api.g_false
                             , p_data                        => x_msg_data
                             , p_msg_index_out               => l_msg_index
                              );

         IF l_error_message IS NULL
         THEN
            l_error_message                                          := SUBSTR (x_msg_data, 1, 250);
         ELSE
            l_error_message                                          :=
                                                                      l_error_message || ' /' || SUBSTR (x_msg_data, 1, 250);
         END IF;
      END LOOP;

      DBMS_OUTPUT.put_line ('*****************************************');
      DBMS_OUTPUT.put_line ('API Error : ' || l_error_message);
      DBMS_OUTPUT.put_line ('*****************************************');
      ROLLBACK;
   ELSE
      DBMS_OUTPUT.put_line ('*****************************************');
      DBMS_OUTPUT.put_line ('Resul Out For Header Id : ' || l_header_id || '---' || x_result_out);
      DBMS_OUTPUT.put_line ('*****************************************');
      COMMIT;
   END IF;
EXCEPTION
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.put_line ('Error is ' || SQLCODE || '---' || SQLERRM);
END;

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.