SAP: create a new product based on existing ones - sap

I am sure that this question already exists but as I am not familiar to SAP development (am an IT auditor) I can't really do a decent search. So I apologize in advance.
We are introducing a new product in our grocery store: a sandwich. The ingredients are : certain amount of bread, rumsteak and cheese.
These base products are already in the SAP.
Can you please tell me how should I create a new product called "sandwich" which will be connected to my basic products? So when I sell or make a sandwich it is taken into account and has an impact on the quantity of bread and cheese etc.?
Thank you so so so much for your help, stackoverflow!

If you just want the stock of your base ingredients to be reduced when your product is sold, you can use a sales BOM (Bill of materials). If you want to produce your product using your base ingredients and then store the final product in your warehouse, you'd create a production BOM and create production orders.
This is of course a very, very, very (repeat about 20 times) short summary of the necessary customizing. Creating a sales BOM is relatively easy, but doesn't give you the ability to track your product stock. Production orders require some additional customization in module PP (maybe even PP-PI, depending on your scenario) and of course need someone to create production orders, create the products, then confirm the production orders.

Related

How to create a junction table with possible reference to a child table

I am designing a SQL database to hold recipe/pricing information. So far, it looks like this:
The idea is to track prices of various ingredients (brand specific) along with their prices so that the total cost of a given recipe can be calculated and tracked over time.
The issue is that not all recipes require brand specific ingredients, but some do. For example, a recipe for one cake may simply call for half a cup of milk, while a recipe for a second cake may call for half a cup of Alta Dena brand milk.
My plan to address this was to create an intermediate table, called Ingredient, with Ingredient: Item as a one to many relationship. In this set up, a recipe would call for a half cup of milk (an Ingredient) and this Ingredient could be mapped to multiple Items, say Alta Dena milk, Horizon milk, etc, each with a separate price.
That set up would look like this (excuse the poor mock up but I wanted just to get a quick visual.) There would need to be a separate IngredientToItem table as well, so think of the Ingredient table as just a placeholder for everything here.
This almost fixes the initial issue that not all recipes call for a specific brand, but it introduces a new problem: some recipes do call for a brand specific ingredient (Item.)
I am wondering what I should do now. Is there a common structure for this type of problem? Should I have two separate tables RecipeIngredients and RecipeItems, one each referring to the brand agnostic ingredients and the brand specific items? Should I add a nullable column to the RecipeIngredients table to refer to a specific Item where necessary?

How should I structure my database?

I'm a complete beginner to SQL. I currently have "coders block" and need help pushing forward.
I am unsure how I should structure my database. I've included an image to hopefully give you a better picture of what I am trying to achieve. Please take a look at it
There will be multiple shops which contain multiple items. Each item will have a buying price and a selling price. An item may be used by multiple shops, and may have a different buying/selling price from other shops. My goal in creating this database is to be able to query an item and determine which shop(s) are buying or selling it at the lowest price.
EDIT:
My idea is to create three tables: Items, Stores, and ItemsStores.
Stores will have columns ID, Name
Items will have columns ID, Name
ItemsStores will have columns Store, Item, Buy Price, Sell Price.
I feel creating a column for just an ID and a name may be redundant. Am I wrong? Is there a better way to do this?
I've read a few articles and even watched videos on the basics of structuring databases, but for some reason it's just not clicking with me. Any help on what my tables / columns should look like would be greatly appreciated.
When you start designing a database, you need to think of the question by highlighting the objects that needs a table. The more the merrier (surprise surprise).
So this is how I would write down the problem:
There will be multiple shops which contain multiple items. Each item will have a buying price and a selling price. An item may be used by multiple shops, and may have a different buying/selling price from other shops. My goal in creating this database is to be able to query an item and determine which shop(s) are buying or selling it at the lowest price.
multiple is highlighted because that means a many to many relationship
obviously you need to decide (that's the tricky part) where you want the price to be: is price an attribute of item? or of an item in a shop?
Once your head stops spinning and you figure that one out you'll be in a much better position.

Consolidating business logic in one place - SQL Server

I have a situation, where with time, the same logic has been scattered at different places (stored procedures) in the application. I am trying to bring it in one place and re-use it as required.
Scenario:
We sell products online, that are classified into categories and the business rules vary by category. When performing a search, it is possible that multiple products are returned from the same category.
Examples of business rules are:
Can the agent sell a product from this category (permission, licensing etc.)?
Can the category be sold in a particular state?
Is there a tax to be applied on the category?
What is the markup for this category?
Does this 'product' meet the customer's requirements?
Current Implementation:
Step 1 - Searching
We have a stored procedure that takes #agent_id, #state_id, #markup_amount, #category_id, #customer_id as inputs and returns all products from a specific category, that meet the customer's requirements. The customer's requirements are derived using customer_id. (SELECT 'product' stored procedure)
Step 2 - Quoting
When adding a particular product to the shopping cart, the above logic is again executed with an additional parameter #product_id, to make sure that the product being added to the shopping cart, satisfies the original requirements (INSERT 'cart' stored procedure)
Step 3 - Re-Validation
If the customer's requirements change, it is possible that products already in the shopping cart still qualify. The ones that do not qualify have to be removed from the UI (is_active_flag is set 0 on SQL). So we re-use the same logic to determine what the products still meet the customer's requirements. (UPDATE 'cart' stored procedure)
Step 4 - Sale
The customer can only buy one product from a particular category. When the customer is ready to buy, we re-run the same logic to see if that particular product still passes all business rules including meeting the customer's requirements (INSERT 'sale' stored procedure)
Consolidation:
What I am looking to do is consolidate this logic in one place and reference it in different stored procedures, as required. The only variable is #product_id. When the initial search is performed, we do not know what products will qualify. Once we have a finite list of product ids, we are drilling down that list at each step.
For Example: The search stored proc may return 500 products which forms the finite list and the customer may end up adding 3 products to the shopping cart, and in the end can buy only 1. The 3 products that were added and the 1 product that was ultimately sold are a part of the finite list of 500 qualifying products.
What is the most efficient way to achieve this? Thank you.
If your goal is create something readable, you can create a boolean sql function that evaluates each product in each scenario.

Relational Database design: handling sales receipts

I am making an online market for a learning project. Pardon me for not having a diagram.
I have the tables Seller and Product,which contains data about the seller and products, respectively. A Seller can have multiple products. There is also a Receipt table that stores information regarding purchases made by a customer. This is an important record and must persist. The receipt should be able to have information on the item purchased.
However, products are dynamic, products may be added and removed. But since the Receipt should reference the Product, it means that I should not delete a Product row even if it is no longer on sale.
Is this the right way to do it? Are there any better design pattern I can use?
Yes, that is the right way to do it. If you set the referential integrity right, the system will not allow you to delete a product or seller if it has receipts. The next thing to do is to use a flag to mark the product or seller as deleted or archived. It could be either a boolean or a date that indicates when it became inactive. Using a 'From' AND a 'To' date to indicate valid time intervals, as Hellmar Becker suggests, is very powerfull, but it opens a whole new can of worms: you can have more than one 'valid' period, so you have to extend your primary key.
Modern databases like HANA (from SAP) just don't allow deletes any more, and have inbuilt 'deleted' flags.
This isn't a proper answer. I just want to give you the gift of a diagram since you didn't have one! :)
(Disclaimer: QuickDatabaseDiagrams is my project)

Database Design - sales from multiple sources

We currently have a SQL database with a table that holds online sales for our company, which sells products using other websites (say, Amazon). The table schema has been set up to hold specific sale data/attributes provided by the website our items are currently sold on (say, Site A).
We are expanding sales to other websites that provide different attributes than Site A uses when an item is sold (e.g. Site A might provide a unique sales id number, and site B might not provide a unique sales id number, but also provide some other info that Site A doesn't provide that we still need to capture).
The question is do I add a separate table for sales on each 'site' that we sell on, as the schema will be different, or try to combine all sales into one table, no matter the platform, leaving some columns null if it doesn't pertain to the particular platform? Or maybe a hybrid approach, separating only the attributes that aren't common among the two sites into separate tables, while a "master" sales table holds attributes that are shared (sale_price, sale_date, etc)?
There are also other tables in play that hold internal information (product Ids, costs, etc), that are linked to the sales table via a unique identifier. Whichever route I choose, I'd need come up with a unique identifier I could use across all tables (auto incremented sale_id, e.g.), and store that in a table for reference/joins.
Any suggestions are welcomed!
A sale is a sale >> same data belongs to the same table. I would definitely not recommend splitting your sales to several tables as this creates lots of difficulty for all that might follow: sales statistics and so on. Try to keep all sales in one table.
If it's a very small project, it might be the best shot to integrate the different fields into one table. Otherwise you might try to create profiles for every sale platform: In this case, use an Entity-Attribute-Value model.
Do not add a table for each site. It sounds like you have a many to many relationship between sites and attributes, so set up your database that way. Also, for any unique identifier you need, create it yourself.