Hi there, please be a senior sap abap and CDS developer and answer myquestion with…
- User
Hi there, please be a senior sap abap and CDS developer and answer myquestion with working code examples.
- Assistant
Of course! Please go ahead and ask your question.
- User
what does the below code do? Where (ObjectStatus.inact <> 'X' and ObjectStatus.stat = 'I0002') and (not ((ObjectStatus.inact = 'X' and ObjectStatus.stat = 'E0005') or (ObjectStatus.inact = 'X' and ObjectStatus.stat ='E0006') or (ObjectStatus.inact = 'X' and ObjectStatus.stat = 'E0008')))
- Assistant
This code snippet appears to be a condition that is checking the value of two fields, ObjectStatus.inact and ObjectStatus.stat, with various combinations and logical expressions.
To break it down:
-
The first part
ObjectStatus.inact <> 'X' and ObjectStatus.stat = 'I0002'checks if the field ObjectStatus.inact is not equal to 'X' and ObjectStatus.stat is equal to 'I0002'. -
The second part starts with
not, so it's checking for the negation of the whole inner condition. The inner condition is a combination of OR conditions checking if ObjectStatus.inact is 'X' and ObjectStatus.stat is 'E0005', 'E0006', or 'E0008'.
-
- User
For me , I want it to be is for records where ObjectStatus.inact is not ‘X’ and ObjectStatus.stat is ‘I0002’ while excluding records where ObjectStatus.inact is not ‘X’ and ObjectStatus.stat is not one of ‘E0005’, ‘E0006’, or ‘E0008’.
- Assistant
Got it! To achieve this condition, you can simply adjust the logic in the WHERE clause of the CDS view as follows:
abap@AbapCatalog.sqlViewName: 'ZEXAMPLE_VIEW' @AccessControl.authorizationCheck: #CHECK @EndUserText.label: 'Example CDS View' define view ZExampleView as select from MARA as material { key material.matnr as MaterialNumber, material.mtart as MaterialType, material.objectStatus.inact as InactiveStatus, material.objectStatus.stat as Status } where (InactiveStatus <> 'X' and Status = 'I0002') and not ((InactiveStatus <> 'X' and Status <> 'E0005') and (InactiveStatus <> 'X' and Status <> 'E0006') and (InactiveStatus <> 'X' and Status <> 'E0008')) }In this updated code snippet, the condition now checks for records where ObjectStatus.inact is not 'X' and ObjectStatus.stat is 'I0002', while excluding records where ObjectStatus.inact is not 'X' and ObjectStatus.stat is not 'E0005', 'E0006', or 'E0008'.
- User
For me , I want it to be is for records where ObjectStatus.inact is not ‘X’ and ObjectStatus.stat is ‘I0002’ while excluding records where ObjectStatus.inact is ‘X’ and ObjectStatus.stat is not one of ‘E0005’, ‘E0006’, or ‘E0008’.
- Assistant
Got it! To achieve this specific condition, you can adjust the logic in the WHERE clause as follows:
abap@AbapCatalog.sqlViewName: 'ZEXAMPLE_VIEW' @AccessControl.authorizationCheck: #CHECK @EndUserText.label: 'Example CDS View' define view ZExampleView as select from MARA as material { key material.matnr as MaterialNumber, material.mtart as MaterialType, material.objectStatus.inact as InactiveStatus, material.objectStatus.stat as Status } where (InactiveStatus <> 'X' and Status = 'I0002') and not ( (InactiveStatus = 'X' and Status not in ('E0005', 'E0006', 'E0008') )In this updated code snippet, the condition now checks for records where ObjectStatus.inact is not 'X' and ObjectStatus.stat is 'I0002', while excluding records where ObjectStatus.inact is 'X' and ObjectStatus.stat is not one of 'E0005', 'E0006', or 'E0008'.
This should give you the desired result based on the adjusted condition logic. Let me know if you have any more questions or need further assistance.
- User
there is one error says "in" is unaccepted word
- Assistant
I apologize for the error. In CDS views, the "IN" keyword is not directly supported within the NOT operator. You can achieve the desired condition by using OR operators instead. Here's the corrected code snippet:
abap@AbapCatalog.sqlViewName: 'ZEXAMPLE_VIEW' @AccessControl.authorizationCheck: #CHECK @EndUserText.label: 'Example CDS View' define view ZExampleView as select from MARA as material { key material.matnr as MaterialNumber, material.mtart as MaterialType, material.objectStatus.inact as InactiveStatus, material.objectStatus.stat as Status } where (InactiveStatus <> 'X' and Status = 'I0002') and not ( (InactiveStatus = 'X' and (Status = 'E0005' or Status = 'E0006' or Status = 'E0008') )In this updated code snippet, the NOT condition now uses OR operators to exclude records where ObjectStatus.inact is 'X' and ObjectStatus.stat is not one of 'E0005', 'E0006', or 'E0008'.