程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> DB2數據庫 >> DB2教程 >> 使用API創建AR貸項通知單

使用API創建AR貸項通知單

編輯:DB2教程

使用API創建AR貸項通知單


DECLARE
  --8000000063
  l_dummy              varchar2(240);
  l_customer_trx_id    ra_customer_trx.customer_trx_id%type;
  l_line_credits_flag  ra_cm_requests.line_credits_flag%type;
  l_line_amount        number;
  l_freight_amount     number := 0;
  l_cm_lines_tbl       arw_cmreq_cover.cm_line_tbl_type_cover;
  l_cm_reason_code     varchar2(150);
  l_comments           varchar2(150);

  l_msg_count          number := 0;
  l_msg_data           varchar2(20000) := null;
  l_return_status      varchar2(1);
  l_request_id         NUMBER;
  l_batch_source_name  varchar2(150) default null;

  cm_trx_id            number;

BEGIN

   -- c. Set the applications and org context
   fnd_global.apps_initialize(1110,50683,222);

   mo_global.init('AR'); 
   mo_global.set_policy_context('S',121);


   -- d. provide CUSTOMER_TRX_ID of the invoice to credit
   l_customer_trx_id := 165023;
  
   l_comments := 'Demo for Create_Request API';

   -- e. Populate Batch Source information
   l_batch_source_name := 'OM前受';

   -- f. the presence of l_cm_lines_tbl indicates this is a LINE-LEVEL credit
   -- details for (1) are credits against line #1 identified by customer_trx_line_id = 824472
   l_cm_lines_tbl(1).customer_trx_line_id := 403228;
   l_cm_lines_tbl(1).quantity_credited := null;
   l_cm_lines_tbl(1).price := null;
   l_cm_lines_tbl(1).extended_amount := -151000;

   -- details for (2) are credits against line #2 identified by customer_trx_line_id = 824473
   --l_cm_lines_tbl(2).customer_trx_line_id := 824473;
   --l_cm_lines_tbl(2).quantity_credited := -2;
   --l_cm_lines_tbl(2).price := 2000.00;
   --l_cm_lines_tbl(2).extended_amount := -4000.00;

   -- g. call CREATE_REQUEST
   AR_CREDIT_MEMO_API_PUB.CREATE_REQUEST(
      P_API_VERSION => 1.0,
      P_INIT_MSG_LIST => FND_API.G_TRUE,
      P_COMMIT => FND_API.G_FALSE,
      P_VALIDATION_LEVEL => FND_API.G_VALID_LEVEL_FULL,
      P_CUSTOMER_TRX_ID => l_customer_trx_id,
      P_LINE_CREDIT_FLAG => 'Y',
      P_CM_REASON_CODE => 'RETURN',
      P_CM_LINE_TBL => l_cm_lines_tbl,
      P_SKIP_WORKFLOW_FLAG => 'Y',
      P_CREDIT_METHOD_INSTALLMENTS => null,
      P_CREDIT_METHOD_RULES => null,
      P_BATCH_SOURCE_NAME => l_batch_source_name,
      P_ORG_ID => 121,
      X_REQUEST_ID => l_request_id,
      X_RETURN_STATUS => l_return_status,
      X_MSG_COUNT => l_msg_count,
      X_MSG_DATA => l_msg_data);

   -- h. return information about the status of the API run
   FND_MSG_PUB.count_and_get (
      p_encoded => FND_API.g_false,
      p_count => l_msg_count,
      p_data => l_msg_data );

   dbms_output.put_line('Return Status ==> '||l_return_status);
   dbms_output.put_line('Credit Memo request_id ==> '||l_request_id);
   dbms_output.put_line('l_msg_count ==> '||l_msg_count);

   
   -- i. display messages from the message stack
   FOR I IN 1..L_MSG_COUNT LOOP
       DBMS_OUTPUT.PUT_LINE(SUBSTR(FND_MSG_PUB.GET(P_MSG_INDEX => I, P_ENCODED => 'F'), 1, 254));
   END LOOP;

   IF l_return_status <> 'S' THEN
      NULL;
   ELSE
     select cm_customer_trx_id 
     into cm_trx_id
     from ra_cm_requests_all
     where request_id = l_request_id;

     dbms_output.put_line(' CM trx_id = '|| cm_trx_id );
     -- You can issue a COMMIT; at this point if you want to save the created credit memo to the database
   END IF;
   
EXCEPTION
WHEN OTHERS THEN
   dbms_output.put_line('exception error!');
   dbms_output.put_line(substr(sqlerrm, 1, 80));
   fnd_message.retrieve(l_dummy);
   dbms_output.put_line(l_dummy);
END;

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved