Saturday 27 January 2018

SAP PI/PO & your 0 issues philosophy (yes is possible): Here just your own Analytics / BI via HANA OLAP / Lumira / Java / Excel or other technology that you decide

I will share a complete solution with the objective to achive the logic that will alow you to make corrective decisions for your solutions implemented or to monitor for preventive symptoms for current interfaces… After we can agree that a lot of companies suffer in their integration processes and don’t know the main reason, but this article will not cover that point here; because i just will share a “logical tool” to let you implement your own technology to monitor and decision making reports.

Understanding Michal’s proposal, we can now implement our new tool:

About Metada:
1. Getting metadata:

http://<host>:<port>/mdt/monitor/MessageOverviewQuery.xsd

SAP HANA Tutorials and Materials, SAP HANA Certifications, SAP HANA Guides, SAP HANA Learning

2. Example of execution without values:

http://<host>:<port>/mdt/messageoverviewqueryservlet

SAP HANA Tutorials and Materials, SAP HANA Certifications, SAP HANA Guides, SAP HANA Learning

3. Now your xsd can be uploaded in an external definition via PI Enterprise Service Repository:

SAP HANA Tutorials and Materials, SAP HANA Certifications, SAP HANA Guides, SAP HANA Learning

After you understand the logic about metadata, now we can test with different tools in order to get the Runtime workbech information:

1. Excecute your own url: http://<host>:<port>/mdt/messageoverviewqueryservlet?component=af.<AF.PARAMETER><PITECHNAME>&view=SR_ENTRY_VIEW_XPI&begin=2016-12-31%2018:00:00.0&end=2017-12-31%2018:00:00.0&detailedStatus=true

SAP HANA Tutorials and Materials, SAP HANA Certifications, SAP HANA Guides, SAP HANA Learning

2. Test via POSTMAN:

SAP HANA Tutorials and Materials, SAP HANA Certifications, SAP HANA Guides, SAP HANA Learning

SAP HANA Tutorials and Materials, SAP HANA Certifications, SAP HANA Guides, SAP HANA Learning

This technique is important because you will confirm 2 data information for security cookie:

http://<host>:<port>/mdt/messageoverviewqueryservlet?component=af.<AF.PARAMETER><PITECHNAME>&view=SR_ENTRY_VIEW_XPI&begin=2016-12-31%2018:00:00.0&end=2017-12-31%2018:00:00.0&detailedStatus=true

Authorization: Basic CONFIDENCIA_BASIC_SECURITY_ID

3. Now you can test it via SOAPUI:

SAP HANA Tutorials and Materials, SAP HANA Certifications, SAP HANA Guides, SAP HANA Learning

After you understand how to get the metadata and how to testing, you can implement different solutions since using only java and excel, or using automatic interfaces, or technologies for analytics via hana, lumira, or another in your robust infraestructure for your decision making…

1. Implement Java Call:

SAP HANA Tutorials and Materials, SAP HANA Certifications, SAP HANA Guides, SAP HANA Learning

package test;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

//import org.apache.commons.codec.binary.Base64;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

public class ConnectToUrlUsingBasicAuthentication {

public static void main(String[] args) {

try {
String webPage = "http://hostname:port/mdt/messageoverviewqueryservlet?component=af.<AF.PI.PARAMETERS>&view=SR_ENTRY_VIEW_XPI&begin=2016-12-31%2018:00:00.0&end=2017-12-31%2018:00:00.0&detailedStatus=true";
String name = "admin";
String password = "admin";

// String authString = name + ":" + password;
// System.out.println("auth string: " + authString);
// byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
// String authStringEnc = new String(authEncBytes);
// System.out.println("Base64 encoded auth string: " + authStringEnc);

URL url = new URL(webPage);
URLConnection urlConnection = url.openConnection();
urlConnection.setRequestProperty("Authorization", "Basic " + "SPACEAuthentification ID");
InputStream is = urlConnection.getInputStream();
InputStreamReader isr = new InputStreamReader(is);

int numCharsRead;
char[] charArray = new char[1024];
StringBuffer sb = new StringBuffer();
while ((numCharsRead = isr.read(charArray)) > 0) {
sb.append(charArray, 0, numCharsRead);
}
String result = sb.toString();

System.out.println("*** BEGIN ***");
System.out.println(result);
System.out.println("*** END ***");
                        
                         /*
                 * To write contents of StringBuffer to a file, use
                 * BufferedWriter class.
                 */
               
                BufferedWriter bwr = new BufferedWriter(new FileWriter(new File("C:\\Path/demo.xml")));
                //write contents of StringBuffer to a file
                bwr.write(sb.toString());
               
                //flush the stream
                bwr.flush();
               
                //close the stream
                bwr.close();
               
                System.out.println("Content of StringBuffer written to File.");
                        
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

}

Test your java solution:

SAP HANA Tutorials and Materials, SAP HANA Certifications, SAP HANA Guides, SAP HANA Learning

2. Implement PI call insted manual solution:

SAP HANA Tutorials and Materials, SAP HANA Certifications, SAP HANA Guides, SAP HANA Learning

Data Source:

<?xml version="1.0" encoding="UTF-8"?>
<ns0:MessageStatisticsQueryResults xmlns:ns0="http://com.sap.aii/mdt/MessageOverviewQuery">
   <ns0:Results>
      <ns0:Code>OK</ns0:Code>
      <ns0:Details>Nice</ns0:Details>
      <ns0:Text>Test</ns0:Text>
   </ns0:Results>
   <ns0:Data>
      <ns0:ColumnNames>
         <ns0:Column>Sender Component </ns0:Column>
      </ns0:ColumnNames>
      <ns0:DataRows>
         <ns0:Row>
            <ns0:Entry>NA</ns0:Entry>
            <ns0:Entry>SENDER_COMPONENT </ns0:Entry>
            <ns0:Entry>NA</ns0:Entry>
            <ns0:Entry>RECEIVER_COMPONENT </ns0:Entry>
            <ns0:Entry>SERVICE_INTERFACE </ns0:Entry>
            <ns0:Entry>NAMESPACE </ns0:Entry>
            <ns0:Entry>A </ns0:Entry>
            <ns0:Entry>0 </ns0:Entry>
            <ns0:Entry>0 </ns0:Entry>
            <ns0:Entry>0 </ns0:Entry>
            <ns0:Entry>0 </ns0:Entry>
            <ns0:Entry>0 </ns0:Entry>
            <ns0:Entry>0 </ns0:Entry>
            <ns0:Entry>22 </ns0:Entry>
         </ns0:Row>
      </ns0:DataRows>
   </ns0:Data>
</ns0:MessageStatisticsQueryResults>

Target Metadata:    
MT_ MessageType Element  DT_DataType  null 
row  Element 0..unbounded false 
SenderPartner  Element  xsd:string  false  

Implement transformation (with one logic proposed but you can change it):

Mapping: in simple idea is a direct mapping node and childnode(here you add UDF)
/ns1:MT_MessageType=/ns0:MessageStatisticsQueryResults
/ns1:MT_MessageType/row=/ns0:MessageStatisticsQueryResults/ns0:Data/ns0:DataRows/ns0:Row
/ns1:MT_Test/row/SenderPartner=ConcatSubnodes(/ns0:MessageStatisticsQueryResults/ns0:Data/ns0:DataRows/ns0:Row)

UDF: ConcatSubnodes

SAP HANA Tutorials and Materials, SAP HANA Certifications, SAP HANA Guides, SAP HANA Learning

SAP HANA Tutorials and Materials, SAP HANA Certifications, SAP HANA Guides, SAP HANA Learning

public String ConcatSubnodes(String srcTreeFragment, Container container) throws StreamTransformationException{
Document doc = null;
String resStr = "";
try {
 InputStream in = new ByteArrayInputStream(srcTreeFragment.getBytes("UTF-8"));;
 doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in);
}
 catch (Exception e){
 throw new RuntimeException(e.getMessage());
}
NodeList items = doc.getDocumentElement().getChildNodes();
if(items.getLength()>0){
 for(int i=0;i<items.getLength();i++){
  if(items.item(i).getNodeType()==Node.ELEMENT_NODE)
   resStr = resStr + " | " + items.item(i).getTextContent().trim();
 }
}

return resStr;
}

Result to import to Excel (you can modify the logic):

<?xml version="1.0" encoding="UTF-8"?>
<ns1:MT_MessageType xmlns:ns1="http://example">
   <row>
      <SenderPartner> | NA | SENDER_COMPONENT | NA | RECEIVER_COMPONENT | SERVICE_INTERFACE | NAMESPACE | A | 0 | 0 | 0 | 0 | 0 | 0 | 22</SenderPartner>
   </row>
</ns1:MT_MessageType>

3. Implement Analytics in a simple way via Excel:

SAP HANA Tutorials and Materials, SAP HANA Certifications, SAP HANA Guides, SAP HANA Learning

SAP HANA Tutorials and Materials, SAP HANA Certifications, SAP HANA Guides, SAP HANA Learning

No comments:

Post a Comment