SAP How-to GuideSybase Unwired PlatformHow To...Use Data Change Notification for CDB updateApplicable Releases:Sybase Unwi...
© Copyright 2012 SAP AG. All rights reserved.                               All other product and service names mentioned ...
Document HistoryDocument Version   Description1.10               << Enter your summary of changes in this version >>1.00  ...
Typographic Conventions                         IconsType Style     Description                      Icon    DescriptionEx...
Table of Contents1.   Business Scenario .....................................................................................
How To... Use Data Change Notificatoin for CDB update    1.      Business Scenario    It is one of the most essential part...
How To... Use Data Change Notificatoin for CDB updateFor DCN without Payload, a HTTP request from EIS will contain some pa...
How To... Use Data Change Notificatoin for CDB update4.      Step-by-Step Procedure<< In this section, first provide a hig...
How To... Use Data Change Notificatoin for CDB update4.1.2       Create MBORight click on the folder Mobile Business Objec...
How To... Use Data Change Notificatoin for CDB updateClick on browse.It will connect to the SAP Backend System and retriev...
How To... Use Data Change Notificatoin for CDB updateSelect FLIGHT_LIST as output attributes and click Finish.You will see...
How To... Use Data Change Notificatoin for CDB updateClick on the MBO.In the property tab, chose Attributes -> Attributes ...
How To... Use Data Change Notificatoin for CDB update4.1.3         Create new cache policy and assign the MBORight Click o...
How To... Use Data Change Notificatoin for CDB update4.1.4       Deploy Project.Right click on the project and choose depl...
How To... Use Data Change Notificatoin for CDB updateChoose POST.Enter the URL.http://<hostname>:<dcnport>/dcn/HttpAuthDCN...
How To... Use Data Change Notificatoin for CDB updateClick on SendYou can see HTTP code 200 is back.May 2012              ...
How To... Use Data Change Notificatoin for CDB update4.1.6       Check the data with SQL Anywhere ClientStart SQL Anywhere...
How To... Use Data Change Notificatoin for CDB updateIf SQL Anywhere is running on the another host, you can use the follo...
How To... Use Data Change Notificatoin for CDB updateDouble click on Tables.The tables holding the MBO data will be called...
How To... Use Data Change Notificatoin for CDB update4.1.7       Multiple record transmissionIt is possible to insert seve...
How To... Use Data Change Notificatoin for CDB updateHTTP response returns like this.[{ "recordID": "AA00172011-07-06" ,"s...
How To... Use Data Change Notificatoin for CDB update4.1.8       Delete an entry with a DCN.You also can send a delete req...
How To... Use Data Change Notificatoin for CDB updateClick Purge button.A confirmation message pops up and click on OK.Whe...
How To... Use Data Change Notificatoin for CDB update4.2        Configuration Steps DCN without payload4.2.1       Project...
How To... Use Data Change Notificatoin for CDB update4.2.3      Add an operation to the MBODouble Click on the MBO.Select ...
How To... Use Data Change Notificatoin for CDB updateClick on “Browse”.In the pop up screen, enter “BAPI_FLIGHT_GETLIST” a...
How To... Use Data Change Notificatoin for CDB updateSelect the created operation and click on Edit.In the parameter tab, ...
How To... Use Data Change Notificatoin for CDB updateIn Cache Update Policy, check "Apply result to cache" on.Save the pro...
How To... Use Data Change Notificatoin for CDB update4.2.4      Push data from Firefox REST ClientSend DCN message with Fi...
How To... Use Data Change Notificatoin for CDB updateChoose HTTP POST.Enter user id and password of SUP and set URL.http:/...
How To... Use Data Change Notificatoin for CDB updateThe HTTP body should look like this.{"pkg":"dummy","messages":[{"id":...
How To... Use Data Change Notificatoin for CDB updateMay 2012                                                27
How To... Use Data Change Notificatoin for CDB update5.      Sample ABAP Program to send a DCN Message5.1.1      HTTP Dest...
How To... Use Data Change Notificatoin for CDB updateIn the authentication tab, specify SUP user name and password.May 201...
How To... Use Data Change Notificatoin for CDB update5.1.2      Sample program to send DCN data from ABAP systemUtility IN...
How To... Use Data Change Notificatoin for CDB update*&-------------------------------------------------------------------...
How To... Use Data Change Notificatoin for CDB update*&-------------------------------------------------------------------...
How To... Use Data Change Notificatoin for CDB updateSample program to send a DCN message.*&------------------------------...
How To... Use Data Change Notificatoin for CDB update      PERFORM write_string_to_json USING mbo Flight CHANGING         ...
How To... Use Data Change Notificatoin for CDB update  client->request->set_form_field(       EXPORTING         name = dom...
How To... Use Data Change Notificatoin for CDB update         DATA num TYPE i .         LOOP AT lt_string INTO lw_string. ...
How To... Use Data Change Notificatoin for CDB update5.1.3      Sample program to send a DCN request to pull data from    ...
How To... Use Data Change Notificatoin for CDB update        internal_error           = 2        argument_not_found = 3   ...
How To... Use Data Change Notificatoin for CDB update>get_status( IMPORTING code = http_rc reason = http_reason ).  IF htt...
How To... Use Data Change Notificatoin for CDB update6.     AppendixConsideration points / limitations If you use the DCN...
www.sap.com/contactsapwww.sdn.sap.com/irj/sdn/howtoguides
Upcoming SlideShare
Loading in …5
×

How to use data change notification for cdb update

2,442 views

Published on

Published in: Education, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,442
On SlideShare
0
From Embeds
0
Number of Embeds
21
Actions
Shares
0
Downloads
50
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

How to use data change notification for cdb update

  1. 1. SAP How-to GuideSybase Unwired PlatformHow To...Use Data Change Notification for CDB updateApplicable Releases:Sybase Unwired Platform 2.1Version 1.0February 2012
  2. 2. © Copyright 2012 SAP AG. All rights reserved. All other product and service names mentioned are the trademarks ofNo part of this publication may be reproduced or transmitted in any form their respective companies. Data contained in this document servesor for any purpose without the express permission of SAP AG. The informational purposes only. National product specifications may vary.information contained herein may be changed without prior notice. The information in this document is proprietary to SAP. No part of thisSome software products marketed by SAP AG and its distributors document may be reproduced, copied, or transmitted in any form or forcontain proprietary software components of other software vendors. any purpose without the express prior written permission of SAP AG.Microsoft, Windows, Excel, Outlook, and PowerPoint are registered This document is a preliminary version and not subject to your licensetrademarks of Microsoft Corporation. agreement or any other agreement with SAP. This document contains only intended strategies, developments, and functionalities of the SAP®IBM, DB2, DB2 Universal Database, System i, System i5, System p, product and is not intended to be binding upon SAP to any particularSystem p5, System x, System z, System z10, System z9, z10, z9, iSeries, course of business, product strategy, and/or development. Please notepSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390, that this document is subject to change and may be changed by SAP atOS/400, AS/400, S/390 Parallel Enterprise Server, PowerVM, Power any time without notice.Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER,OpenPower, PowerPC, BatchPipes, BladeCenter, System Storage, GPFS, SAP assumes no responsibility for errors or omissions in this document.HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex, SAP does not warrant the accuracy or completeness of the information,MVS/ESA, AIX, Intelligent Miner, WebSphere, Netfinity, Tivoli and text, graphics, links, or other items contained within this material. ThisInformix are trademarks or registered trademarks of IBM Corporation. document is provided without a warranty of any kind, either express or implied, including but not limited to the implied warranties ofLinux is the registered trademark of Linus Torvalds in the U.S. and other merchantability, fitness for a particular purpose, or non-infringement.countries. SAP shall have no liability for damages of any kind including withoutAdobe, the Adobe logo, Acrobat, PostScript, and Reader are either limitation direct, special, indirect, or consequential damages that maytrademarks or registered trademarks of Adobe Systems Incorporated in result from the use of these materials. This limitation shall not apply inthe United States and/or other countries. cases of intent or gross negligence.Oracle is a registered trademark of Oracle Corporation. The statutory liability for personal injury and defective products is notUNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open affected. SAP has no control over the information that you may accessGroup. through the use of hot links contained in these materials and does notCitrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, endorse your use of third-party Web pages nor provide any warrantyand MultiWin are trademarks or registered trademarks of Citrix Systems, whatsoever relating to third-party Web pages.Inc. SAP “How-to” Guides are intended to simplify the product implement-HTML, XML, XHTML and W3C are trademarks or registered trademarks tation. While specific product features and procedures typically areof W3C®, World Wide Web Consortium, Massachusetts Institute of explained in a practical business context, it is not implied that thoseTechnology. features and procedures are the only approach in solving a specificJava is a registered trademark of Sun Microsystems, Inc. business problem using SAP NetWeaver. Should you wish to receiveJavaScript is a registered trademark of Sun Microsystems, Inc., used additional information, clarification or support, please refer to SAPunder license for technology invented and impl emented by Netscape. Consulting.SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP Any software coding and/or code lines / strings (“Code”) included in thisBusinessObjects Explorer, StreamWork, and other SAP products and documentation are only examples and are not intended to be used in aservices mentioned herein as well as their respective logos are productive system environment. The Code is only intended better explaintrademarks or registered trademarks of SAP AG in Germany and other and visualize the syntax and phrasing rules of certain coding. SAP doescountries. not warrant the correctness and completeness of the Code given herein,Business Objects and the Business Objects logo, BusinessObjects, and SAP shall not be liable for errors or damages caused by the usage ofCrystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and other the Code, except if such damages were caused by SAP intentionally orBusiness Objects products and services mentioned herein as well as their grossly negligent.respective logos are trademarks or registered trademarks of Business DisclaimerObjects Software Ltd. Business Objects is an SAP company. Some components of this product are based on Java™. Any code changeSybase and Adaptive Server, iAnywhere, Sybase 365, SQL Anywhere, in these components may cause unpredictable and severe malfunctionsand other Sybase products and services mentioned herein as well as their and is therefore expressively prohibited, as is any decompilation of theserespective logos are trademarks or registered trademarks of Sybase, Inc. components.Sybase is an SAP company. Any Java™ Source Code delivered with this product is only to be used by SAP’s Support Services and may not be modified or altered in any way.
  3. 3. Document HistoryDocument Version Description1.10 << Enter your summary of changes in this version >>1.00 First official release of this guide
  4. 4. Typographic Conventions IconsType Style Description Icon DescriptionExample Text Words or characters quoted Caution from the screen. These include field names, screen Note or Important titles, pushbuttons labels, Example menu names, menu paths, and menu options. Recommendation or Tip Cross-references to other documentationExample text Emphasized words or phrases in body text, graphic titles, and table titlesExample text File and directory names and their paths, messages, names of variables and parameters, source text, and names of installation, upgrade and database tools.Example text User entry texts. These are words or characters that you enter in the system exactly as they appear in the documentation.<Example Variable user entry. Angletext> brackets indicate that you replace these words and characters with appropriate entries to make entries in the system.EXAMPLE TEXT Keys on the keyboard, for example, F2 or ENTER.
  5. 5. Table of Contents1. Business Scenario ................................................................................................ 12. Introduction to DCN .............................................................................................. 13. Prerequisites....................................................................................................... 24. Step-by-Step Procedure ....................................................................................... 3 4.1 Configuration Steps DCN with payload ....................................................................3 4.1.1 Create a project ...........................................................................................3 4.1.2 Create MBO ................................................................................................ 4 4.1.3 Create new cache policy and assign the MBO ............................................. 8 4.1.4 Deploy Project. ........................................................................................... 9 4.1.5 Push data from Firefox REST Client ............................................................ 9 4.1.6 Check the data with SQL Anywhere Client ................................................. 12 4.1.7 Multiple record transmission ..................................................................... 15 4.1.8 Delete an entry with a DCN. ....................................................................... 17 4.2 Configuration Steps DCN without payload............................................................. 19 4.2.1 Project and MBO Creation ......................................................................... 19 4.2.2 Create a Personalization Key ..................................................................... 19 4.2.3 Add an operation to the MBO.................................................................... 20 4.2.4 Push data from Firefox REST Client .......................................................... 245. Sample ABAP Program to send a DCN Message .................................................... 28 5.1.1 HTTP Destination Creation ....................................................................... 28 5.1.2 Sample program to send DCN data from ABAP system ........................... 30 5.1.3 Sample program to send a DCN request to pull data from ABAP system ..376. Appendix .......................................................................................................... 40
  6. 6. How To... Use Data Change Notificatoin for CDB update 1. Business Scenario It is one of the most essential parts of an SUP implementation to think about how to efficiently update cache data in SUP. Above all, if the data volume is relatively large or users would like to have fresher data, DCN is the preferred approach for cache updates. This How-To Guide provides details on how to configure SUP to update the CDB with DCN and test it. 2. Introduction to DCN Data change notification (DCN) is an update mechanism that allows an enterprise information system (EIS) to send data changes to an Unwired Server over an HTTP or HTTPS connection using JavaScript Object Notation (JSON) format. There are two types of DCN. This document will only refer to Regular DCNs, and not Workflow DCNs. Regular DCN (DCN) –DCN to update MBO cache data in Consolidated Database(CDB) Workflow DCN (WF-DCN) –DCN for Mobile Workflow clients Server Initiated scenario All DCN commands support both GET and POST methods. The EIS developer creates and sends a DCN to the Unwired Server through HTTP GET or POST operations. The portion of the DCN command parameters that come after http://host:8000/dcn/DCNServlet, can all be in POST. Any name=var pair can be in either the URL (GET) or in the POST. The HTTP POST method is more secure than HTTP GET methods, and therefore Sybase recommends that you include the authenticate password parameter as well as any sensitive data provided for attributes and parameters in the POST method. DCN with Payload and DCN with payload DCN requests can be issued with or without payload. For DCN with Payload, a HTTP request from EIS will contain all of the cache information. When it arrives at the Unwired Server, it will invoke standard operations (:upsert or :delete ) to insert/update/delete entries in CDB. May 2012 1
  7. 7. How To... Use Data Change Notificatoin for CDB updateFor DCN without Payload, a HTTP request from EIS will contain some parameters only, When it arrives atthe Unwired Server, it will invoke custom MBO operations, execute the operation of EIS and update thecache database (CDB).While DCN can trigger the data push to device side as well (“server initiated synchronization“), thisdocument only focus on the CDB cache data update.3. PrerequisitesIn this example, SAP ABAP backend system is required.Install Firefox and Firefox REST Client.You can download the software from the following page.http://www.mozilla.org/en-US/firefoxhttps://addons.mozilla.org/en-US/firefox/addon/restclient/Download SQL Anywhere Client Tool from here.http://www.sybase.com/detail?id=1087327May 2012 2
  8. 8. How To... Use Data Change Notificatoin for CDB update4. Step-by-Step Procedure<< In this section, first provide a high-level overview about the steps that need to be performed.Then, provide a more detailed description of the procedure. >>4.1... Configuration Steps DCN with payload4.1.1 Create a projectOpen Mobile SDK and select File -> New -> Mobile Application ProjectName your project and click on Finish.May 2012 3
  9. 9. How To... Use Data Change Notificatoin for CDB update4.1.2 Create MBORight click on the folder Mobile Business Object in your project.Choose New -> Mobile Business ObjectName your MBO and click on Next.Choose “SAP” for data source type and select your Connection profile.(If you haven’t created it, you also can create the connection to your SAP system).Click on Next.May 2012 4
  10. 10. How To... Use Data Change Notificatoin for CDB updateClick on browse.It will connect to the SAP Backend System and retrieve BOR (Business Object Repository)information.Enter “BAPI_FLIGHT_GETLIST” and click on Search BAPI/RFC.Select the line of “GetList” and click on “OK”.May 2012 5
  11. 11. How To... Use Data Change Notificatoin for CDB updateSelect FLIGHT_LIST as output attributes and click Finish.You will see the MBO like this.You also can use another type of MBO (JDBC, Web Service etc.) for DCN instead of the SAP MBOused in this example.May 2012 6
  12. 12. How To... Use Data Change Notificatoin for CDB updateClick on the MBO.In the property tab, chose Attributes -> Attributes Mapping.Select “Primary Key” to AIRLINEID, CONNECTID and FLIGHTDATE.The warning message shown below can be safely ignored.Save project.May 2012 7
  13. 13. How To... Use Data Change Notificatoin for CDB update4.1.3 Create new cache policy and assign the MBORight Click on Cache GroupChoose New -> Cache GroupName your cache Group “DCN” and choose “DCN” for the cache policy.Drag your MBO and drop onto the new cache group “DCN”It will look like this.May 2012 8
  14. 14. How To... Use Data Change Notificatoin for CDB update4.1.4 Deploy Project.Right click on the project and choose deploy project..Deploy the project with default values.4.1.5 Push data from Firefox REST ClientOpen Firefox REST ClientClick on Login and enter user name and password.May 2012 9
  15. 15. How To... Use Data Change Notificatoin for CDB updateChoose POST.Enter the URL.http://<hostname>:<dcnport>/dcn/HttpAuthDCNServlet?cmd=dcn&domain=default&package=DCN1:1.0{"pkg":"dummy","messages":[{"id":"NH01112012-02-29","mbo":"Flight","op":":upsert","cols":{"AIRLINEID":"NH","AIRLINE":"All Nippon Airways","CONNECTID":"0111","FLIGHTDATE":"2012-02-29","AIRPORTFR":"NRT","CITYFROM":"Tokyo","AIRPORTTO":"SIN","CITYTO":"Singapore","DEPTIME":"10:40:00","ARRTIME":"17:25:00","ARRDATE":"2012-02-29","PRICE":68000,"CURR":"JPY","CURR_ISO":"JPY"}}]}May 2012 10
  16. 16. How To... Use Data Change Notificatoin for CDB updateClick on SendYou can see HTTP code 200 is back.May 2012 11
  17. 17. How To... Use Data Change Notificatoin for CDB update4.1.6 Check the data with SQL Anywhere ClientStart SQL Anywhere Client.Right click on SQL Anywhere 12 and choose Connect.If SQL Anywhere is running on the same host, you can use the following parameter (the user ID andpassword are the defaults set during installation).User ID: dbaPassword: sqlAction: Connect with and ODBC Data SourceODBC Data Source Name: default-cdbMay 2012 12
  18. 18. How To... Use Data Change Notificatoin for CDB updateIf SQL Anywhere is running on the another host, you can use the following parameter.User ID: dbaPassword: sqlAction: Connect to a running database on another computerHost name: <host name of CDB>Port: 5200 (this is the default port)May 2012 13
  19. 19. How To... Use Data Change Notificatoin for CDB updateDouble click on Tables.The tables holding the MBO data will be called something like [domain number e.g. d1]_[projectname] [first 6 chars of MBO name][suffix( in case of naming conflict)].It will be look like this.IRight Click on the table and select “View Data in Interactive SQL”May 2012 14
  20. 20. How To... Use Data Change Notificatoin for CDB update4.1.7 Multiple record transmissionIt is possible to insert several entries with a single HTTP request.Use{"pkg":"dummy","messages":[{"id":" AA58502012-03-08","mbo":"Flight","op":":upsert","cols":{"AIRLINEID":"AA","AIRLINE":"American Airline","CONNECTID":"5815","FLIGHTDATE":"2012-03-08","AIRPORTFR":"SFO","CITYFROM":"San Francisco","AIRPORTTO":"HND","CITYTO":"Haneda Tokyo","DEPTIME":"18:05:00","ARRTIME":"10:20:00","ARRDATE":"2012-03-09","PRICE":98000.1,"CURR":"JPY","CURR_ISO":"JPY"} },{"id":" LH07102012-02-29","mbo":"Flight","op":":upsert", "cols":{"AIRLINEID":"LH","AIRLINE":"Lufthansa","CONNECTID":"0710","FLIGHTDATE":"2012-02-29","AIRPORTFR":"FRA","CITYFROM":"Frankfurt","AIRPORTTO":"NRT","CITYTO":"Tokyo Narita","DEPTIME":"13:25:00","ARRTIME":"08:35:00","ARRDATE":"2012-03-01","PRICE":1100,"CURR":"EURO","CURR_ISO":"EURO"}}]}May 2012 15
  21. 21. How To... Use Data Change Notificatoin for CDB updateHTTP response returns like this.[{ "recordID": "AA00172011-07-06" ,"success":true,"statusMessage":""}, { "recordID": " LH07102012-02-29","success":true,"statusMessage":""} ]You can see multiple entries are added with a HTTP request.May 2012 16
  22. 22. How To... Use Data Change Notificatoin for CDB update4.1.8 Delete an entry with a DCN.You also can send a delete request with a DCN.The content will look like this.{"pkg":"dummy","messages":[{"id":"LH0112012-02-29","mbo":"Flight","op":":delete","cols":{"AIRLINEID":"LH","AIRLINE":"Lufthansa","CONNECTID":"0710","FLIGHTDATE":"2012-02-29"} }]}You can see LOGICAL_DEL field became “1” at this stage..Go to Sybase Control Center.Choose menu <server name> --> Domain --> <domain name> -->Packages --> <package name>Select Cache tab.You can see an entry is logically deleted.May 2012 17
  23. 23. How To... Use Data Change Notificatoin for CDB updateClick Purge button.A confirmation message pops up and click on OK.When you click on Refresh, the logically deleted entry was physically deleted.You also can see it in SQL anywhere client.This physical deletion can be executed through Admin API.http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc01332.0210/doc/html/apr1276106349832.htmlMay 2012 18
  24. 24. How To... Use Data Change Notificatoin for CDB update4.2 Configuration Steps DCN without payload4.2.1 Project and MBO CreationRepeat same thing as 4.1.1 – 4.1.3 or use existing project created in 4.1.1 – 4.1.3.4.2.2 Create a Personalization KeyThis personalization key will be used to pass a variable to an operation as an input parameter.Right Click on Personalization Keys in your project and choose New -> Personalization KeyName the Personalization Key "PK_AIRLINE" .Choose “Transient” for the Storage.May 2012 19
  25. 25. How To... Use Data Change Notificatoin for CDB update4.2.3 Add an operation to the MBODouble Click on the MBO.Select property “Operations” tab and Click on “Add”.Name your operation "CreateDataWithDCN" and select “CREATE” for operation type and click onNext.May 2012 20
  26. 26. How To... Use Data Change Notificatoin for CDB updateClick on “Browse”.In the pop up screen, enter “BAPI_FLIGHT_GETLIST” and click on Search BAPI/RFCs.Select GetList and Click on OK.Select AIRLINE and FLIGHT_LIST.Click Finish.May 2012 21
  27. 27. How To... Use Data Change Notificatoin for CDB updateSelect the created operation and click on Edit.In the parameter tab, assign the personalization key PK_AIRLINE.May 2012 22
  28. 28. How To... Use Data Change Notificatoin for CDB updateIn Cache Update Policy, check "Apply result to cache" on.Save the project .Right click on the project and choose Deploy Project.May 2012 23
  29. 29. How To... Use Data Change Notificatoin for CDB update4.2.4 Push data from Firefox REST ClientSend DCN message with Firefox REST clientIn order to check the RFC module is really called, we set session break point in SAP system.Logon to the SAP system with SAP GUI.Go to SE37 and click on Display.Put a cursor on the source code and click on the “Session Break Point” button .May 2012 24
  30. 30. How To... Use Data Change Notificatoin for CDB updateChoose HTTP POST.Enter user id and password of SUP and set URL.http://<server name>:<port>/dcn/HttpAuthDCNServlet?cmd=dcn&domain=default&package=DCN1:1.0When using DCNs without payload, a custom operation like “CreateDataWithDCN” will be usedinstead of standard operation :upsert or :delete.In order to pass the personalization key as the input parameter, we use a parameter “ppm”.The value of ppm needs to be encoded with BASE64.First you have to prepare a string like this.{"PK_AIRLINE":"AA "}It will be encoded with base 64.eyJQS19BSVJMSU5FIjoiQUEgIn0="}]For testing purposes, you can use a freely available online encoder/decoder (do a web search forthis).May 2012 25
  31. 31. How To... Use Data Change Notificatoin for CDB updateThe HTTP body should look like this.{"pkg":"dummy","messages":[{"id":"1","mbo":"Flight","op":"CreateDataWithDCN", "ppm" :"eyJQS19BSVJMSU5FIjoiQUEgIn0="}] }Click on the Send button.When the SUP server receives the HTTP request, it will immediately call an RFC module bound tothe operation.A debugger pops up and you can see the input parameter is passed to the function module.Click on Continue or hit F8 key.You can see the CDB table is filled from the return parameter of the function module.May 2012 26
  32. 32. How To... Use Data Change Notificatoin for CDB updateMay 2012 27
  33. 33. How To... Use Data Change Notificatoin for CDB update5. Sample ABAP Program to send a DCN Message5.1.1 HTTP Destination Creation...Log in to SAP System with SAP GUI and go to Transaction Code SM59.Click on the Create button.Use G for connection type.Target Host: <SUP Host name>Service Number: <Port Number for DCN>Path prefix: /dcn/HttpAuthDCNServletQuery string parameters like those below will be added dynamically from the programming.?cmd=dcn&domain=default&package=DCN1:1.0May 2012 28
  34. 34. How To... Use Data Change Notificatoin for CDB updateIn the authentication tab, specify SUP user name and password.May 2012 29
  35. 35. How To... Use Data Change Notificatoin for CDB update5.1.2 Sample program to send DCN data from ABAP systemUtility INCLUDE program*&---------------------------------------------------------------------**& Include Z_DCN_UTILS*&---------------------------------------------------------------------**&---------------------------------------------------------------------**& Form write_time_to_json*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** -->FIELD_NAME text* -->FIELD_time text* -->JSON_CONTENT text*----------------------------------------------------------------------FORM write_time_to_jsonUSING field_name TYPE any field_time TYPE anyCHANGING json_content. DATA time_str TYPE string. IF json_content <> . CONCATENATE json_content ," field_name " INTO json_content. ELSE. CONCATENATE json_content " field_name " INTO json_content. ENDIF. CONCATENATE field_time(2) field_time+2(2) field_time+4(2) INTO time_str SEPARATED BY :. CONCATENATE json_content :" time_str " INTO json_content.ENDFORM. "write_time_to_json*&---------------------------------------------------------------------**& Form write_dec_to_json*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** -->FIELD_NAME text* -->FIELD_dec text* -->JSON_CONTENT text*----------------------------------------------------------------------FORM write_dec_to_jsonUSING field_name TYPE any field_dec TYPE anyCHANGING json_content. DATA dec_str TYPE string. IF json_content <> . CONCATENATE json_content ," field_name " INTO json_content. ELSE. CONCATENATE json_content " field_name " INTO json_content. ENDIF. dec_str = field_dec. condense dec_str. CONCATENATE json_content : dec_str INTO json_content.ENDFORM. "write_dec_to_jsonMay 2012 30
  36. 36. How To... Use Data Change Notificatoin for CDB update*&---------------------------------------------------------------------**& Form write_date_to_json*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** -->FIELD_NAME text* -->FIELD_VALUE text* -->JSON_CONTENT text*----------------------------------------------------------------------FORM write_date_to_jsonUSING field_name TYPE any field_date TYPE anyCHANGING json_content. DATA date_str TYPE string. IF json_content <> . CONCATENATE json_content ," field_name " INTO json_content. ELSE. CONCATENATE json_content " field_name " INTO json_content. ENDIF. CONCATENATE field_date(4) field_date+4(2) field_date+6(2) INTO date_str SEPARATED BY -. CONCATENATE json_content :" date_str " INTO json_content.ENDFORM. "write_date_to_json*&---------------------------------------------------------------------**& Form write_datetime_to_json*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** -->FIELD_NAME text* -->FIELD_DATE text* -->FIELD_TIME text* -->JSON_CONTENT text*----------------------------------------------------------------------*FORM write_datetime_to_jsonUSING field_name TYPE any field_date TYPE any field_time TYPE anyCHANGING json_content. DATA date_str TYPE string. DATA time_str TYPE string. IF json_content <> . CONCATENATE json_content ," field_name " INTO json_content. ELSE. CONCATENATE json_content " field_name " INTO json_content. ENDIF. CONCATENATE field_date(4) field_date+4(2) field_date+6(2) INTO date_str SEPARATED BY -. CONCATENATE field_time(2) field_time+2(2) field_time+4(2) INTO time_str SEPARATED BY :. CONCATENATE json_content :" date_str T time_str " INTO json_content.ENDFORM. "write_datetime_to_json*&---------------------------------------------------------------------**& Form write_boolean_to_jsonMay 2012 31
  37. 37. How To... Use Data Change Notificatoin for CDB update*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** -->FIELD_NAME text* -->FIELD_VALUE text* -->JSON_CONTENT text*----------------------------------------------------------------------*FORM write_boolean_to_jsonUSING field_name TYPE anyfield_value TYPE anyCHANGING json_content. IF json_content <> . CONCATENATE json_content ," field_name " INTO json_content. ELSE. CONCATENATE json_content " field_name " INTO json_content. ENDIF. CONCATENATE json_content : field_value INTO json_content.ENDFORM. "write_boolean_to_json*&---------------------------------------------------------------------**& Form write_string_to_json*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** -->FIELD_NAME text* -->FIELD_VALUE text* -->JSON_CONTENT text*----------------------------------------------------------------------*FORM write_string_to_jsonUSING field_name TYPE anyfield_value TYPE anyCHANGING json_content. DATA str TYPE string. DATA strout TYPE string. DATA strtemp TYPE string. DATA c1 TYPE c LENGTH 1. DATA c2 TYPE c LENGTH 4. DATA int4 TYPE i. str = field_value. strout = str. IF json_content <> . CONCATENATE json_content ," field_name " INTO json_content. ELSE. CONCATENATE json_content " field_name " INTO json_content. ENDIF. REPLACE ALL OCCURRENCES OF IN str WITH . REPLACE ALL OCCURRENCES OF " IN str WITH ". int4 = strlen( str ). DO int4 TIMES. c1 = str(1). c2 = cl_abap_conv_out_ce=>uccp( c1 ). IF NOT c2(2) = 00. CONCATENATE u c2 INTO strtemp. REPLACE ALL OCCURRENCES OF c1 IN strout WITH strtemp. ENDIF. SHIFT str. ENDDO. CONCATENATE json_content :" strout " INTO json_content.ENDFORM. "write_string_to_jsonMay 2012 32
  38. 38. How To... Use Data Change Notificatoin for CDB updateSample program to send a DCN message.*&---------------------------------------------------------------------**& Report Z_FLIGHT_JSON_SEND*&*&---------------------------------------------------------------------**&*&*&---------------------------------------------------------------------*REPORT z_flight_json_send.INCLUDE z_dcn_utils .DATA : lv_body TYPE string , lv_id TYPE string , json_content TYPE string , json_data TYPE string , json_col TYPE string , dcn_id TYPE string.DATA : http_rc TYPE i , http_reason TYPE string.DATA : lt_flight TYPE TABLE OF bapisfldat ,lt_return TYPE TABLE OF bapiret2 .FIELD-SYMBOLS <flight> LIKE LINE OF lt_flight.DATA : dest TYPE rfcdest , client TYPE REF TO if_http_client , errortext TYPE string, subrc TYPE sy-subrc.DATA: lv_resp TYPE string, lt_match_open TYPE match_result_tab , lt_match_close TYPE match_result_tab , lw_match_open TYPE match_result , lw_match_close TYPE match_result, lt_string TYPE TABLE OF string , lw_string TYPE string , lf_length TYPE i.START-OF-SELECTION. DATA maxrow TYPE bapisflaux-bapimaxrow . maxrow = 15 . CALL FUNCTION BAPI_FLIGHT_GETLIST* EXPORTING* max_rows = maxrow TABLES flight_list = lt_flight return = lt_return. LOOP AT lt_flight ASSIGNING <flight> . CLEAR : json_col , json_content. CONCATENATE <flight>-airlineid <flight>-connectid <flight>-flightdate INTO lv_id . PERFORM write_string_to_json USING id lv_id CHANGING json_content .May 2012 33
  39. 39. How To... Use Data Change Notificatoin for CDB update PERFORM write_string_to_json USING mbo Flight CHANGING json_content . PERFORM write_string_to_json USING op :upsert CHANGING json_content . PERFORM write_string_to_json USING AIRLINEID <flight>-airlineid CHANGING json_col. PERFORM write_string_to_json USING AIRLINE <flight>-airline CHANGING json_col. PERFORM write_string_to_json USING CONNECTID <flight>-connectid CHANGING json_col. PERFORM write_date_to_json USING FLIGHTDATE <flight>-flightdate CHANGING json_col. PERFORM write_string_to_json USING AIRPORTFR <flight>-airportfr CHANGING json_col. PERFORM write_string_to_json USING CITYFROM <flight>-cityfrom CHANGING json_col. PERFORM write_string_to_json USING AIRPORTTO <flight>-airportto CHANGING json_col. PERFORM write_string_to_json USING CITYTO <flight>-cityto CHANGING json_col. PERFORM write_time_to_json USING DEPTIME <flight>-deptime CHANGING json_col. PERFORM write_date_to_json USING ARRDATE <flight>-arrdate CHANGING json_col. PERFORM write_time_to_json USING ARRTIME <flight>-arrtime CHANGING json_col. PERFORM write_dec_to_json USING PRICE <flight>-price CHANGING json_col. PERFORM write_string_to_json USING CURR <flight>-curr CHANGING json_col. PERFORM write_string_to_json USING CURR_ISO <flight>-curr_iso CHANGING json_col. IF sy-tabix = 1 . CONCATENATE { json_content ,"cols":{ json_col }} INTO json_data . ELSE. CONCATENATE json_data ,{ json_content ,"cols":{ json_col }} INTO json_data . ENDIF. ENDLOOP. CONCATENATE {"pkg":"dummy","messages":[ json_data ]} INTO lv_body. dest = DCN_DESTINATION . cl_http_client=>create_by_destination( EXPORTING destination = dest IMPORTING client = client EXCEPTIONS destination_not_found = 1 internal_error = 2 argument_not_found = 3 destination_no_authority = 4 plugin_not_active = 5 OTHERS = 6 ) . client->request->set_form_field( EXPORTING name = cmd value = dcn) .May 2012 34
  40. 40. How To... Use Data Change Notificatoin for CDB update client->request->set_form_field( EXPORTING name = domain value = default) . client->request->set_form_field( EXPORTING name = package value = DCN1:1.0) . client->request->set_cdata( lv_body ). client->send( EXCEPTIONS http_communication_failure = 1 http_invalid_state = 2 http_processing_failed = 3 OTHERS = 4 ) . IF sy-subrc <> 0. client->get_last_error( IMPORTING code = subrc message = errortext ) . WRITE: / communication_error( send ), / code: , subrc, message: , errortext. EXIT. ENDIF. client->receive( EXCEPTIONS http_communication_failure = 1 http_invalid_state = 2 http_processing_failed = 3 OTHERS = 4 ) . IF sy-subrc <> 0. client->get_last_error( IMPORTING code = subrc message = errortext ) . WRITE: / communication_error( receive ), / code: , subrc, message: , errortext. EXIT. ELSE. " not communicaiton error client->response->get_status( IMPORTING code = http_rc reason = http_reason ). IF http_rc NE 200 . WRITE : Error. HTTP response code: , http_rc , / , http_reason . ELSE.*HTTP return code 200 Check Application error.*check if there is any record which contain false with Regex. lv_resp = client->response->get_cdata( ). FIND ALL OCCURRENCES OF REGEX { IN lv_resp RESULTS lt_match_open. FIND ALL OCCURRENCES OF REGEX } IN lv_resp RESULTS lt_match_close. LOOP AT lt_match_open INTO lw_match_open . READ TABLE lt_match_close INTO lw_match_close INDEX sy-tabix. lf_length = lw_match_close-offset - lw_match_open-offset + 1 . lw_string = lv_resp+lw_match_open-offset(lf_length) . APPEND lw_string TO lt_string . ENDLOOP.May 2012 35
  41. 41. How To... Use Data Change Notificatoin for CDB update DATA num TYPE i . LOOP AT lt_string INTO lw_string. FIND ALL OCCURRENCES OF REGEX false IN lw_string MATCH COUNT num . IF num > 0 . WRITE lw_string . ENDIF. ENDLOOP. ENDIF. ENDIF.May 2012 36
  42. 42. How To... Use Data Change Notificatoin for CDB update5.1.3 Sample program to send a DCN request to pull data from ABAP system...*&---------------------------------------------------------------------**& Report Z_FLIGHT_JSON_WITHOUT_PAYLOAD*&*&---------------------------------------------------------------------**&*&*&---------------------------------------------------------------------*REPORT z_flight_json_without_payload.PARAMETERS lp_fid TYPE bapisflkey-airlineid.DATA : lv_str TYPE string , lv_x64str TYPE string , lv_body TYPE string .DATA : http_rc TYPE i , http_reason TYPE string.DATA : dest TYPE rfcdest , client TYPE REF TO if_http_client , errortext TYPE string, subrc TYPE sy-subrc.DATA: lv_resp TYPE string, lt_match_open TYPE match_result_tab , lt_match_close TYPE match_result_tab , lw_match_open TYPE match_result , lw_match_close TYPE match_result, lt_string TYPE TABLE OF string , lw_string TYPE string , lf_length TYPE i.lv_str = lp_fid .CONCATENATE {"PK_AIRLINE":" lv_str "} INTO lv_str .lv_x64str = cl_http_utility=>if_http_utility~encode_base64( lv_str ) .CONCATENATE{"pkg":"dummy","messages":[{"id":"lp_fid","mbo":"Flight","op":"CreateDataWithDCN", "ppm" : "lv_x64str"}] } INTO lv_body.dest = DCN_DESTINATION .cl_http_client=>create_by_destination( EXPORTING destination = dest IMPORTING client = client EXCEPTIONS destination_not_found = 1May 2012 37
  43. 43. How To... Use Data Change Notificatoin for CDB update internal_error = 2 argument_not_found = 3 destination_no_authority = 4 plugin_not_active = 5 OTHERS = 6 ) .client->request->set_form_field( EXPORTING name = cmd value = dcn) .client->request->set_form_field( EXPORTING name = domain value = default) .client->request->set_form_field( EXPORTING name = package value = DCN1:1.0) .client->request->set_cdata( lv_body ).client->send( EXCEPTIONS http_communication_failure = 1 http_invalid_state = 2 http_processing_failed = 3 OTHERS = 4 ) .IF sy-subrc <> 0. client->get_last_error( IMPORTING code = subrc message = errortext ) . WRITE: / communication_error( send ), / code: , subrc, message: , errortext. EXIT.ENDIF.client->receive( EXCEPTIONS http_communication_failure = 1 http_invalid_state = 2 http_processing_failed = 3 OTHERS = 4 ) .IF sy-subrc <> 0. client->get_last_error( IMPORTING code = subrc message = errortext ) . WRITE: / communication_error( receive ), / code: , subrc, message: , errortext. EXIT.ELSE. " not communicaiton error client->response-May 2012 38
  44. 44. How To... Use Data Change Notificatoin for CDB update>get_status( IMPORTING code = http_rc reason = http_reason ). IF http_rc NE 200 . WRITE : Error. HTTP response code: , http_rc , / , http_reason . ELSE.*HTTP return code 200 Check Application error.*check if there is any record which contain false with Regex. lv_resp = client->response->get_cdata( ). FIND ALL OCCURRENCES OF REGEX { IN lv_resp RESULTS lt_match_open. FIND ALL OCCURRENCES OF REGEX } IN lv_resp RESULTS lt_match_close. LOOP AT lt_match_open INTO lw_match_open . READ TABLE lt_match_close INTO lw_match_close INDEX sy-tabix. lf_length = lw_match_close-offset - lw_match_open-offset + 1 . lw_string = lv_resp+lw_match_open-offset(lf_length) . APPEND lw_string TO lt_string . ENDLOOP. DATA num TYPE i . LOOP AT lt_string INTO lw_string. FIND ALL OCCURRENCES OF REGEX false IN lw_string MATCH COUNT num . IF num > 0 . WRITE lw_string . ENDIF. ENDLOOP. ENDIF.ENDIF.May 2012 39
  45. 45. How To... Use Data Change Notificatoin for CDB update6. AppendixConsideration points / limitations If you use the DCN mechanism, take care to specify primary key(s) for MBOs, otherwise duplicate records will be inserted. It’s not possible to have multiple CDB partitions when using DCNs (like with the on-demand cache policy). It is technically possible to send a DCN message to an MBO belonging to other cache policy than DCN. However it is highly recommended to use the DCN cache policy for DCN updates. You must use exactly the same attribute name in the return parameter of the operation when using DCNs without payload If you’d like you send messages asynchronously from an ABAP backend,, internal queuing technology like qRFC or bgRFC can help. DCN without payload cannot update multiple MBOs at the same time even if multiple MBOs were generated from a RFC Module/Web service.May 2012 40
  46. 46. www.sap.com/contactsapwww.sdn.sap.com/irj/sdn/howtoguides

×