How to get employee transport and accommodation allowance? - abap

I am working on one of our HR system which have integration with SAP, I am using SAP Connector for Microsoft .NET 3.0 and it's working fine for getting basic employee data using BAPI_EMPLOYEE_GETDATA function module.
I wants to know is there any function module in SAP to get employee transport and accommodation allowances.

As far as I know there is no single allowance value for employee in SAP HR. They can be set per diem, per expense type, per country destination, etc.
The most simple and obviuos setting that came to my mind is Define Maximum Rates and Default Values for Expense Types, which is stored in V_T706B2 customizing view
Here you can configure defaults, errors and warnings for expense receipts. Here is the excerpt from help:
In this IMG activity, you define maximum rates depending on the trip provision variant and trip expense type for individual receipts. For the differentiation of maximum rates within a trip expense type, the following parameters are available:
•Statutory and enterprise-specific trip types
•Trip activity type
•Trip country and trip region
•Statutory and enterprise-specific reimbursement group for meals and accommodations
Key piece here is individual receipts, you gotta understand that travel expenses in SAP are settled per trip per destination per receipt. So it may be dozens of receipts in the single trip.
The botton line: the total allowance value per employee (per day/month/year) that you want, may not be available out of the box in SAP ERP and is coded/customized by each client. I saw multiple ways to implement it, but none of them are standard so I will not give them here. In case you are not sure which allowance type do you need, it's better to ask your customer directly about it.
The snippet how to fetch the above Maximum Rates and Default Values for Expense Types is based on standard module RFC_READ_TABLE for querying SAP tabular data.
Here we fetch T706B2 table but I want to highlight it is not equivalent to V_T706B2 view, ideally you must create a database view wrapper for V_T706B2 view and fetch it, however this may not be feasible on your system due to security policy.
The query is context-dependent and here you must know many parameters like travel provision plan MOREI, expense type SPKZL and maybe others. They should be provided by your business analyst, I give this snippet only as a reference (!), it may not be suited for your particular case.
DATA: obj_data TYPE REF TO data,
lt_options TYPE TABLE OF rfc_db_opt,
ls_option TYPE rfc_db_opt,
lt_fields TYPE TABLE OF rfc_db_fld,
ls_field TYPE rfc_db_fld,
lt_entries TYPE STANDARD TABLE OF tab512.
FIELD-SYMBOLS: <fs_tab> TYPE STANDARD TABLE.
TRY.
ls_option-text = ` MOREI = '01' AND SPKZL = 'ABZA' AND BEGDA >= '20220101' AND ENDDA <= '20221231' `.
APPEND ls_option TO lt_options.
ls_field-fieldname = 'MOREI'.
APPEND ls_field TO lt_fields.
ls_field-fieldname = 'SPKZL'.
APPEND ls_field TO lt_fields.
CALL FUNCTION 'RFC_READ_TABLE'
EXPORTING
query_table = 'T706B2'
TABLES
options = lt_options
fields = lt_fields
data = lt_entries.
CATCH CX_SY_DYNAMIC_OSQL_SYNTAX INTO DATA(oref).
DATA(text) = oref->get_text( ).
MESSAGE text TYPE 'E'.
ENDTRY.
It is an ABAP snippet, to wrap it for SAP .Net Connector check this answer.

Related

Database design solution

I am having the following case:
There is entity 'Master_Entity'. This entity has properties as name, type, duration etc. There are other two type of entities 'Entity' and 'Sub-Entity'. There are identical as the 'Master_Entity' (They have absolutely the same properties).
At the end the 'Master_Entity' should hold a collection of 'Entity' and 'Entity' should hold a collection of 'Sub-Entity'. The tricky part is that records of type 'Entity' can be part of different 'Master_Entity' (same for 'Sub-Entity'), but they can have different values for duration for example. How can achieve such modularity?
Here I came up with, but it's not quite do the work. May you guys help me with this.
Edit: Imagine this as some sort of a work tracker. For example you have a 'Create PHP App' (Master entity). This entity contains duration of how long it will take to finish this job. In addition it contains a entity 'Writing Code' (Entity) and this one can be divided to 'Writing Http Client' (Sub-Entity) which has duration property which is specific for this job.
On other side you might have other job: 'Create an Java App' (Master Entity) which will contain the same 'Writing Code' entity, but with duration which will have different value, because of the context of the Application you are building.
I want to have a single record 'Writing Code', but the duration value that it have should be different for every job it's assigned to. How can achieve that with creating a minimum duplicating records of type 'Entity'?
It sounds like something like these 3 tables will work for you:
Entity
* Id
* Name
* Type
EntityGroup
* Id
* Name
* ParentEntityGroupId
* ParentEntityId
EntityRelationship
* Id
* EntityId
* ParentEntityId
* EntityGroupId
With this structure, you can have an Entity be a member of a Group, or a solo Child of another Entity. You can also have a Group be a Child of an Entity, or even a Child of another Group. Without knowing specifics of your data, it's hard to know what you might need, but this should get you started.
From what you have said, it seems that you don't need EAV at all because you don't have different properties for each item just different values. And thus you should not be using it.
What you need is a combination of lookup tables and then tables that address the actual tracking history of the work. This is because this is time sensitive data. The tasks at the time the projects was created may be substantially different than the tasks associated with that task group two years from now, but you need to record the tasks at the the time of creation). Note that this is not denormalizing, it is creating a picture of data in time. The real duration always goes to teh project not ever to the Task. In the task, you can have a suggested duration to use as a starting point. I used a similar design (with far more fields of course) to design a database for building sales proposals for technical-hardware related projects. The real key here is to recognize what data needs to be stored as a point time time and what is lookup data used to build the final project data. If someone adds a new task to the "Create a Java App" group, you don't want to change details about projects already completed or in work, only new projects.
So you need:
Task group
Task Group ID
Task Group Name
Task
TaskID
Task Name
SuggestedDuration (can be null if you have tasks that are always different
but filled in for tasks that usually have a similar duration)
Task_Taskgroup
TaskID
TaskGroupID
Project
ProjectID
ProjectName
TaskGroupID
ProjectTask (should be filled in automatically when the task group is
chosen for the project)
ProjectID
Task ID
EstimatedDuration (fills in the default value, but can be changed
by the person creating the work project)
ActualDuration (Field in after the task is done, can be used by an
analyst to create more reflective task default duration values)
Of course each of these tables may have other fields depending on the need.

SQL Point of sale how does a return work

Im new to POS systems. I have to create a very simple one for a few stores. Here is my SQL Server DB Schema:
The question that I have is how to handle returns.
In the real world how does a return works? Is a return a new sale but with a negative balance? If so then I would need to add to my sale table a "transactiontype" field (sale, return, etc.) and also a "referencesaleuid" field so the new sale (that will be a return) can reference the original sale ticket.
How to handle returns is a business decision.
For one example, we have worked with retailers of larger ticket items that needed to match returned products back to the original line item. So if a customer walked out of the store with two widgets and later returned one widget then we needed to be able to link the returned SKU back to the original transaction and SKU.
As another example, we have worked with retailers of smaller ticket items where returns were treated negative transactions.
I would suggest consulting closely with the business managers to find out what they would like to do in order to manage the business best.

How to get a range of serial numbers based on the movement type?

I'm trying to figure out how to perform the task in object.
I want to get serial numbers from range A (internal) when i perform GR (101, 501) in storage location X. After quality checks, materials are transfered to storage location B via 311. After the 311 movement i want to change serials and get the new ones from another range (external)
I already defined ranges and i'm already posting GR with serials from range A. I have to figure out how to tell to SAP to get serials from the second range after posting the 311.
Thank you very much for your advice
Serial numbers are assigned in popup dialog during goods movement if they are mandatory, otherwise you should go to special dialog Goto->Serial Number. Assignment of external numbers could be done in this way:
Go to SPRO->SAP Customizing Implementation Guide->Plant Maintenance and Customer Service->Master Data in Plant Maintenance and Customer Service->Technical Objects->Serial Number Management and define profile with MMSL procedure or use existing one
Assign some equipment category (or create your custom one in OIET transaction) to your Serial Number profile
Go to SPRO->SAP Customizing Implementation Guide->Plant Maintenance and Customer Service->Master Data in Plant Maintenance and Customer Service->Technical Objects->Equipment->Equipment Categories->Define Number Ranges and assign your previously created number range to your equipment category
[optional] Also you can go to S_ALR_87000304 tcode and assign default equipment category which will be used for serial number assignment if system cannot find equipment category from the profile.

How to make a SQL table of formulas?

I'm have a MS SQL database for storing raw data on utility usage (electric, water, and gas), which I have implemented to compile data from four disparate automated collection systems. The ultimate goal is to generate invoices from this data.
Different customers have one of a dozen different rate structures, which all may-or-may-not use a non-linear function to calculate cost per usage based on peak demand and total usage.
It is not unheard of for a particular customer to change from one rate structure to another, or for the rate calculation for a particular rate class to change from year to year, so I would like to put these formulas into new tables within my database where they can be easily referenced and modified.
Ideally, I would want to run one of these dynamic functions as part of a query without relying on the front-end having to do them, but I have no idea how that would work.
By request, an example formula of the type I am talking about:
All current customer with Electricity Rate Structure A pay $0.005/kW-hr for the first 2,000 kW-hr consumed, $0.004/kW-hr for 2,000-15,000 kW-hr, and $0.003/kW-hr for all consumption above 15,000kW-hr. Additionally, any customer who has higher than 50kW demand will be subject to a $0.002/kW-hr surcharge on all consumption. The values for these coefficients, thresholds, the number of thresholds, and whether or not the customer even gets charged for peak demand can and do change from year to year and from rate structure to rate structure.
The formula for this (if I was programming it) would be:
min(sum(usage),2000)*.005+min(min(sum(usage)-2000,0),15000)*.004 + min(sum(usage)-15000,0)*.002 + (max(usage)>50)*sum(usage)*.002

Dynamic view models

If I'm about to split my application into read and write sides using CQRS principles how would you handle situation of having a "dynamic" read model scenario? E.g. I have a product that consists of several read properties (id, title, slug etc) but in order to display it to user I need to pass its price that is calculated by domain service (to which I pass visitor country and currency)? I can't store this price in database because user is free to change his currency anytime he wants + prices change quite often. So my final product view model should be basically a composite of raw-SQL columns (id, title, slug) and calculated price. Should I use the same view model that I get from the database and use content enrichment pattern or should I create a new view model for my composite?
Changing the price of the product is a COMMAND, it should update the price you store in the database which you then QUERY anytime.
The essence of CQRS is that your queries are not going any logic like that.
For currency conversion, since you say the user can change currency at anytime then you should query the entire list of currency rates and do the calculation yourself on the client side. Alternatively you could query for the base price then query for the current rate. And if the user changes currency you just query for the rate again but keep the same base price.