cancel
Showing results for 
Search instead for 
Did you mean: 

S4HANA Cloud SDK Filter not working

0 Kudos

Hi Experts,

We are working on Cloud SDK Filter. But, its not working. As per below blog, its in roadmap and when we can expend working version in SDK package.

https://blogs.sap.com/2018/06/05/deep-dive-9-use-the-sap-s4hana-cloud-sdk-in-the-application-program...

Regards,

Dileep

Accepted Solutions (1)

Accepted Solutions (1)

HenningH
Advisor
Advisor
0 Kudos

Hello Dileep,

could you explain a bit what you are trying and what is not working?

Are you maybe looking for a way to pass filters from the query to the OData VDM? Then this release blog may be relevant to you: https://blogs.sap.com/2019/02/28/sap-s4hana-cloud-sdk-version-2.12.0-is-available/ (Section Further Improvements).

Best regards,

Henning

former_member604560
Participant
0 Kudos

Hi Henning,

OData VDM query filter is working for single CDS service.But, I am trying a scenario to retrieve data from two separate services and merging it based on primary key.

Finally I am getting the list of merged data.After that is it possible to use ODATA VDM query filter?

I am adding my cds and merged code

my-service.cds

using CUSTOM_CDS  from '../srv/external/csn/CUSTOM_CDS.json';
service ProfitCtrSegment {
@cds.persistence.skip
  entity profitctrRes as Projection on CUSTOM_CDS.CUSTOMType {
 key CompanyCode,
 PRCTR,
 GLAccount,
   Customer,
   AccountingDocument,
   AccountingDocumentItem,
    FiscalYear,
      ProfitCntr,
       SEGMENT,
   AccountingDocumentType,
   FiscalYearPeriod,
  NetDueDate,
   NetDueArrearsDays,
  AmountInTransactionCurrency,
   CompanyCodeCurrency,
   CustomerName,
   KeyDate,
    ClearingStatus
  };
}

Business logic

@Query(serviceName = "ProfitCtrSegment", entity = "profitctrRes")
public QueryResponse readProfitCtr_segment(QueryRequest req) throws Exception{
List<CUSTOM> results = new ArrayList<>();
String profitCenter = "";
final List<SERVICE1> customLineResult = new DefaultSERVICE1Service().getAllSERVICE1()
.execute();
final List<SERVICE2> SegmentResult = new DefaultSERVICE2Service()
.getAllSERVICE2().execute();
Map<String, SERVICE2> segmentMap = new HashMap<String, SERVICE2>();
for (SERVICE2 segment : SegmentResult) {
profitCenter = removeLeadingChar(segment.getPRCTR());
if (profitCenter != null && profitCenter.trim() != "" && segment.getSEGMENT() != null
&& segment.getSEGMENT().trim() != "") {
segmentMap.put(profitCenter, segment); /*DUPLICATES OF PRCTR ARE Replaced*/
}
}
for (SERVICE1 customLines : customLineResult) {
profitCenter = removeLeadingChar(customLines.getProfitCntr());
// if (segmentMap.containsKey(profitCenter)) {// If segment not mapped profit
// center will not add in result
if (profitCenter != null && profitCenter!="") {
CUSTOM resultDto = new CUSTOM();
resultDto.setCompanyCode(customLines.getCompanyCode() != null ? customLines.getCompanyCode() : "");
resultDto.setGLAccount(customLines.getGLAccount() != null ? customLines.getGLAccount() : "");
resultDto.setCustomer(customLines.getCustomer() != null ? customLines.getCustomer() : "");
resultDto.setAccountingDocument(
customLines.getAccountingDocument() != null ? customLines.getAccountingDocument() : "");
resultDto.setAccountingDocumentItem(
customLines.getAccountingDocumentItem() != null ? customLines.getAccountingDocumentItem() : "");
resultDto.setFiscalYear(customLines.getFiscalYear() != null ? customLines.getFiscalYear() : "");
resultDto.setProfitCntr(customLines.getProfitCntr() != null ? customLines.getProfitCntr() : "");
if (segmentMap.containsKey(profitCenter)) {
resultDto.setSEGMENT(segmentMap.get(profitCenter).getSEGMENT());
}
resultDto.setAccountingDocumentType(
customLines.getAccountingDocumentType() != null ? customLines.getAccountingDocumentType() : "");
resultDto.setFiscalYearPeriod(
customLines.getFiscalYearPeriod() != null ? customLines.getFiscalYearPeriod() : "");
resultDto.setNetDueDate(customLines.getNetDueDate());
resultDto.setNetDueArrearsDays(
customLines.getNetDueArrearsDays() != null ? customLines.getNetDueArrearsDays()
: new BigDecimal(0));
resultDto.setAmountInTransactionCurrency(customLines.getAmountInTransactionCurrency() != null
? customLines.getAmountInTransactionCurrency()
: new BigDecimal(0));
resultDto.setCompanyCodeCurrency(
customLines.getCompanyCodeCurrency() != null ? customLines.getCompanyCodeCurrency() : "");
resultDto.setCustomerName(customLines.getCustomerName() != null ? customLines.getCustomerName() : "");
resultDto.setClearingStatus(
customLines.getClearingStatus() != null ? customLines.getClearingStatus() : "");
results.add(resultDto);

}
}
return QueryResponse.setSuccess().setData(results).response();
}
public String removeLeadingChar(String profitCenter) {
if (profitCenter != null && profitCenter.trim() != "") {
for (int i = 0; i < profitCenter.length(); ++i) {
char c = profitCenter.charAt(i);
if (c != '0') {
return profitCenter.substring(i);
}
}
}
return ""; // or return "0";
}
}

Here I want to apply OData VDM query filter in List<CUSTOM> results. Is it possible using cloud sdk?

Please suggest me.

HenningH
Advisor
Advisor
0 Kudos

So you basically want to apply the VDM-style filter on a list of plain Java objects? This is not possible with the OData VDM out of the box.

Answers (0)