Use dynamic values in CDS access control - abap

How can I compare a cds element to a return value of an ABAP function?
As an example:
An employee is assigned to a company and the company has orders from customers. These orders are displayed in a table and employees should only see orders for the company they are working for.
If employee A was working for Company B, the role would be something like this:
grant select on ConsumptionViewName
where company = ‚B‘;
I now want to make this hardcoded 'B' dynamic and there is an ABAP helper function that returns the employer of an employee which should be used. There aren't any authorization objects that have a field for the company, is it possible to do it without one?

There is no way you can supply your dynamic values for the CDS DCL.
If no suitable authority object is found, either you define your own one and let DCL do its job. Alternatively you can filter the result at Gateway layer (methods in ...DPC_EXT class) by filtering the result with the ABAP helper function.

Related

Retreiving ship-to-party country SAP QuickViewer

I've created a QuickView, where I enter Sales Document data as search criterias.
Selection fields are
VBAP-VBELN, VBAP-POSNR, VBAP-MATNR and VBAP-KWMENG
As the Sales Document Item data.
Furthermore I retrieve the Schedule line date from
VBEP-EDATU
From General Data in Customer Header KNA1, I use
KNA1-KUNNR and KNA1-LAND1
Now, all connections and keys works out. My issue is, I wish to list the Country Key for ship-to-part rather than sold-to-party (which is represented by KUNNR). How could this be solved?
Tables are joined as follows:
VBAK-VBELN -> (VBAP-VBELN,-POSNR) -> (VBEP-VBELN, -POSNR)
VBAK-KUNNR -> KNA1-KUNNR
I do know I would probably need a new table in here to retreive what Iæm looking for, but I'm completely blank. Any help would be greatly appriciated. I
Ship-To-Party is stored in table VPBA (Sales Document Partners) in field KUNNR1 for partner function SH, so to select it you should join KNA1 not with VBAK but with VBPA-KUNNR restricting function to SH.
However, SQVI is a very primitive tool which doesn't allow setting complex (neither trivial) conditions so you should switch to ABAP queries tool (SQ01).
But just in case you wanna do this in SQVI here is the workaround:
Join necessary tables in SQVI builder
Add necessary KNA1 fields to layout: KUNNR and LANDX
Go to layout mode and enable selection by partner function PARVW
Run your query by SH partner function
and voilá! You will be shown only the orders with ship-to-party specified with their countries

How to create a dynamic LOV at runtime

How to create a dynamic attribute in lov at runtime?
Suppose I have a employee lov, where only two attributes are currently present like employee id and employee name.
It user want to add a few more column at run time like employee age and employee salary.
Without changing the LOV logic. The user has one master table where IT user can handle how many attribute should be displayed to business user. They can add a new parameter in table which can be displayed.
Can anybody suggest me some approach to handle this type of scenario?
If I got you right, I'd use backingBean with method that returns List, that implemented as ArrayList<SelectItem>. Then populate from any source(like VO, or whatever mixed) label and value according to your current user request.

Return rows that have every kind of instances that appear in a table for a given attribute

E.g, given the schema:
account(id, type, cname)
I want to return the cnames of customers with every type of account that appears in account.
The following query will do:
SELECT cname, type
FROM account AS cust_account
WHERE NOT EXISTS (
SELECT type
FROM account
EXCEPT
SELECT type
FROM account
WHERE account.cname = cust_account.cname
);
However, I'm having trouble understanding the logic behind it. In particular, I don't see what's going on with the EXCEPT statement. Can anybody clarify this? Thank you.
As the WHERE NOT EXIST clause processes each record, it runs the following steps for the customer in that record. If it sees an empty list from step #3 it will include the customer in the query results (NOT EXISTS) .
Make a list of all the possible account types.
Make list of all accounts types that THIS customer has.
Subtract the list in step #2 from the list in step #1. This will create a list of any account types that THIS customer does NOT have. This will be empty for customers that have all accounts.
To be clear, since the WHERE NOT EXIST clause contains a correlated-sub query, steps 1-3 (which are performed by the sub query) are run one time for EACH row in the account table. For example, if the accounts table contains 100,000, the sub query will be run 100,000 times.

How to make a record belong to all options of a field

I have a database of records called "services", each service has about 30 attributes and each service has an associated country as an attribute. The problem is some services are offered to ALL countries. On the front end of this database I have a drop-down menu that selects all the records based on a country filter. How would I be able to include the service offered to ALL countries without needing to duplicate the record for the service and replacing the country name.
P.S. For those interested in the actual implementation, I am using Drupal nodes to represent each service and a view with exposed filters to select the country. But if I have to do some SQL work then I can do that too.
Your WHERE clause would follow this pattern
WHERE (CounrtyID = PassedVariable OR PassedVariable = 'all')

LDAP query to retrieve list of department or company

Can anyone help me with this ?
What I am trying to do is retrieve a distinct list of company from the AD using LDAP query.
I wrote a query which returns all the company names, with duplicate values.
What I am trying to achieve is to get a list of distinct companies from AD.
My query for this is as given below.
DistinguishedName used is "ou=Users,o=rackspace"
And I am trying to filter it using the filter
Filter = "(company=*)"
Will you help me to get the list as I need it.
Thanks,
AR
Sorry, but LDAP in its filter definitions does not support a 'distinct' function.
Your filter will only return object who have a company value populated, but it will return duplicates.
You will have to use something else, whether that is something coded, or even a simple Excel spreadsheet to get the distinct values.