Tuesday, 17 September 2019

Allowed Header in Runtime Configurations in iflow SAP CPI


Allowed Header in the integration flow in Runtime Configurations


SapAuthenticatedUserName - To identify the Username that calls the integration flow

Note: If the sender channel is configured to use client certificate authentication, no such header is set (as it is not available in this case). Only for User Role it can be used.

CamelHttpUrl - Refers to the complete URL called, without query parameters

 For Example: CamelHttpUrl:https://XXXX-iflmap.hcisbp.XXX.hana.ondemand.com/http/dev/SF/c4c/fileupload

CamelHttpQuery - Refers to the query string that is contained in the request URL.

CamelHttpMethod - Refers to the incoming method names used to make the request. These methods are GET, POST, PUT, DELETE, and so on.

 For Example: CamelHttpMethod:POST

CamelServletContextPath - Refers to the path specified in the address field of the channel.

 For Example: CamelServletContextPath:/dev/SF/c4c/fileupload

Script used to read the header values:

def headers = message.getHeaders()
def userName = headers.get("SapAuthenticatedUserName")

Result of the above script:

SapAuthenticatedUserName:S0020XXXXXXX  (in header)

------------------------------------------------------------------------------------

Cheers!!!



Monday, 2 September 2019

Logging Cookie for session handling Csrf Token - SAP CPI

There is a required step which need to used, when using the CSRF-Token mechanism. To fetch the CSRF- token, the external system will be called and retrieves the token. Session need to be enabled at header to maintain the token to push the actual data to external system.

To Log the Cookie, use the below code after the Get CSRF token request step.

Groovy Script:


import com.sap.gateway.ip.core.customdev.util.Message;
import groovy.xml.*;
import java.io.*;

def Message processData(Message message)
{
def headers = message.getHeaders();

// read cookies to send with next request, especially yMkt Session ID
def cookie = headers.get("Set-Cookie");

StringBuffer bufferedCookie = new StringBuffer();

// bring cookies in right format

for (item in cookie)
{
bufferedCookie.append("\"" + item + "\"" + "; ")
}

message.setHeader("Cookie", bufferedCookie.toString());

def messageLog = messageLogFactory.getMessageLog(message);

if(messageLog != null)
{
messageLog.setStringProperty("Logging_Cookie", bufferedCookie.toString());
}

return message;
}

Hope this helps.



Monday, 26 August 2019

Past 3 Hours based filter in Groovy script in SCPI/HCI

We could follow the below code for the different logic covered.

1. Timer is 15 mins in the iflow and if hours = 00,09,12,15,18 only then the router triggers the message.
2. HTTP query formed in the iflow.
3. Current date time - one hour and Current date time - one day.


Groovy Script:

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {


def cal = Calendar.instance;
def date = cal.time;
def dateFormat1 = 'yyyy-MM-dd\'T\'HH:mm:ss';

def datemin = '14';
def dateFormat = '00';

def dayFormat = 'dd';


def curhour =Integer.parseInt(date.format(dateFormat));

// Current datetime hour - 3 hours

def hour =Integer.parseInt(date.format(dateFormat)) -03;

//Current date - 1 day (previous day)
def pastday=Integer.parseInt(date.format(dayFormat)) -1;

def min=Integer.parseInt(date.format(datemin));

def flag;

def curDateTime = "";

curDateTime ='' + date.format(dateFormat1)+'';



def curDatePastOneHour = curDateTime.substring(0,11)+hour+curDateTime.substring(13,curDateTime.length());

def curDatePastOneDay = curDateTime.substring(0,8)+pastday+curDateTime.substring(10,curDateTime.length());

// Need a validation in my logic to send in router, if hours equals 00, only once the flow should run
if (dateFormat=='00' && datemin<='14')

{

flag = '00'

message.setProperty("flag",flag);

// HTTP Query formation to filter the data from current datetime - previous one hour and status Failed

def datequery = "((LogStart ge datetime"+"'"+curDatePastOneHour+"'"+") and (LogEnd le datetime"+"'"+curDateTime+"'"+"))"+" and CustomStatus eq 'FAILED'"

//Set property for the query
message.setProperty("datequery",datequery);

}

else{

flag = '11'

message.setProperty("flag",flag);

}

// Interface runs every 15 mins(Timer) - Logic should run only once at the hours equals 00,09,12,15,18. every hour has 4 times - i.e HH:mm - 00:00, 00:15, 00:30, 00:45

if((dateFormat=='00' && datemin<='14') || (dateFormat=='09' && datemin<='14') || (dateFormat=='12' && datemin<='14') || (dateFormat=='15' && datemin<='14') || (dateFormat=='18' || dateFormat=='21'))

{

flag = '22'

// HTTP Query formation to filter the data from current datetime - previous one day and status is completed

def datequerycount = "((LogStart ge datetime"+"'"+curDatePastOneDay+"'"+") and (LogEnd le datetime"+"'"+curDateTime+"'"+"))"+" and Status eq 'COMPLETED'"

message.setProperty("datequerycount",datequerycount);

}else{

flag = '33'

message.setProperty("flag",flag);

}



message.setProperty("hour",hour);

message.setProperty("curhour",curhour);

message.setProperty("min",min);



return message;

}



Monday, 29 July 2019

Excel Macro to split large files into multiple small files

If there is a scenario of migrating the data from one system to other system, the data load will be huge and while loading the huge record in CPI will lead to timeout issue/performance issue. So we would need to split up the files into several small files and then load into the system.

For this scenario, splitting the files, we use excel macro for splitting the file.

1.Open the huge data excel and save it.
2.Then Alt+F11 key - Microsoft Visual Basic Application screen opens
3. Go to Insert menu - Module, then paste the below code in the pop up screen.

Script:

Sub Test()

Dim wb As Workbook
Dim ThisSheet As Worksheet
Dim NumOfColumns As Integer
Dim RangeToCopy As Range
Dim WorkbookCounter As Integer
Dim RowsInFile
Dim Prefix As String
Application.ScreenUpdating = False


'Initialize data
Set ThisSheet = ThisWorkbook.ActiveSheet
NumOfColumns = ThisSheet.UsedRange.Columns.Count
WorkbookCounter = 1
RowsInFile = 10000 'how many rows (incl. header) in new files?
Prefix = "SCI_user_deletion_input_QA" 'prefix of the file name


For p = 1 To ThisSheet.UsedRange.Rows.Count Step RowsInFile
Set wb = Workbooks.Add


'Paste the chunk of rows for this file
Set RangeToCopy = ThisSheet.Range(ThisSheet.Cells(p, 1), ThisSheet.Cells(p + RowsInFile - 1, NumOfColumns))
RangeToCopy.Copy wb.Sheets(1).Range("A1")


'Save the new workbook, and close it

wb.SaveAs ThisWorkbook.Path & "\" & Prefix & "_" & WorkbookCounter &".csv",FileFormat:=xlCSV
wb.Close


'Increment file counter
WorkbookCounter = WorkbookCounter + 1
Next p


Application.ScreenUpdating = True
Set wb = Nothing
End Sub

---------------------------------------------------------------------------

4. Save and close it.
5. Again back to excel sheet -then press Alt+F8.

Now you can find the files in the folder. where you save the (huge data) excel.


--- If really helpful, just give some feedback ---




Tuesday, 23 July 2019

SAP Maintenance window / downtime of all Cloud application

Refer the below link to check the system distribution/ downtime of cloud application / maintenance window of

1. SAP CPI/HCI,
2. SAP C4C(Cloud for Customer)
3. SAP Ariba
4. SAP Concur
5. SAP Fieldglass
6. SAP Marketing Cloud( Hybris marketing)
7. SAP S/4 Hana Cloud
8. SAP Service Cloud
9. SAP SuccessFactors
10. SAP Integrated Busniess Planning (SAP IBP)

Check on the below link:

Click Here for SAP Cloud applications server status


Happy Learning!!!





HTTP Sender CSRF token Handling in SAP CPI

We would like to add some more authentication on the passing the message from the Sender system to CPI, so HTTP adapter is capable of handling the CSRF token at the sender side.

As this feature is not enabled for the HTTP receiver, so we can go ahead with the ODATA adapter to use this feature.

In this post, will read about fetching the CSRF token and post the data to CPI from sender system.

For the demonstration, we use POSTMAN tool as a sender system.

Step 1: Get the CSRF token by calling the CPI system

                                                       (Click to Zoom if not visible)


Step 2: POST the actual data with the CSRF token as mentioned in the below screenshot:



CPI Flow design for simple testingSimple connectivity cal made to CPI and posted the data successfully.


Happy Learning!!!





Tuesday, 9 July 2019

java.io.IOException: Remotely closed - SAP CPI

When you are facing this issue on the development phase, then it could be the minor mistake in URL as mentioned below.

If you encounter this same issue at the live scenario, then it could be the connection to the respective system is broken..Eg: No able to connect to the target system.

https://test/sap/opu/odata//SAP/test_SRV/MarketingPermissions

FYI.. Some occasions minor mistakes can happen.