PB1 User Training SAP Business One and SQL Queries
PB1 User Training SAP Business One and SQL Queries
Table of Contents
• Query Wizard
• Query Generator
• SQL Studio Management
• Crystal Reports
• Excel
• Additional tools
o BI – Business Intelligent Software
o HANA Analytics
• Exercise:
o Connect to SAP Business One and access different query tools
In addition, you will get familiar with different SAP tools related to queries such as printing,
exporting, filtering and more.
• Exercise 1:
o Create a query using any of the tools and save a query under the general category,
then close all windows and execute the same query from the query manager area
• Exercise 2:
o Create a new query that present all open sales orders: Number, customer code and
name, date and due date, freight and total
o Save this query under a selected category
o Make sure you see the grand total in the total column
o Filter only one customer and send the results to excel
o Create a print layout from the query
In most cases View>System information will show the table and field name in the message
area of SAP on the bottom left. You can also see all relevant tables if you tab at the table
section of the query generator. In some cases you may need to use the SDK help center.
• Exercise 1:
o Identify which table stores the information about customers
o Identify which table stores the information about Items
o Identify which table stores the information about sales order
o Identify which table stores the information about sales invoices
o Identify which table stores the information about purchase orders
o The table name will give us a hint of which table it represents, e.g: ORDR – Sales
Orders, OITM=Item Master Data etc.
o Documents tables normally contain header and lines as well as other related tables.
Below you will find main tables related to sales order table, though the same
structure apply to all marketing documents:
▪ ORDR - Sales Order Header
▪ RDR1 - Sales Order Lines
▪ RDR2 - Sales Order - Freight - Rows
▪ RDR3 - Sales Order - Freight
▪ RDR4 - Sales Order - Tax Amount per Document
▪ RDR6 - Sales Order - Installments
▪ RDR 20 - Sales Order - Bin Allocation Data
▪ RDR 21 - Sales Order - Document Reference Information
o History Tables
▪ History tables are stored under ADOC table
▪ This table save information of all objects and object type needs to be filtered
o Draft Tables
▪ Main tables are DRF1 and ODRF and follow the same tables structure of
marketing documents
▪ Those tables save information of all objects and object type needs to be
filtered – E.g. Object Type=’17’ will show only sales orders drafts
There is some good literature on how to structure and write SQL reports in a way that will
be organized and assist other people to read the SQL statement and potentially modify it.
Below you will find a basic structure of any SQL query that will help you read other SQL
reports as well as write queries with consistency.
GROUP BY [Group the report – fields that are not grouped needs to be summaries]
HAVING [Condition on grouped fields]
ORDER BY [Sort the report – Descending/ Ascending]
There are four basic types of SQL joins: inner, left join, right join, and full join. The easiest
and most intuitive way to explain the difference between these four types is by using a Venn
diagram, which shows all possible logical relations between data sets.
FROM RDR1 T0
• Exercise:
o Items availability Report - Create a new query on Items table.
o Show item code, items name, on hand Quantity, committed and On Order
o Execute the report to make sure it’s working and save it
o Add to the report one field ‘main vendor’ – execute the report and make sure you get
the same number of results
• Where options
• Using SAP variables - %1
• Order by statement
• Group by statement
• Advanced - Variables declaration
Documentation:
• Exercise 1:
o Write a query to present all sales invoices between dates
o Sort the query above by document date
o Add a condition to show only customers that have the letter ‘a’ in the customer name
field
• Exercise 2:
o Write a second query to show a total of sales invoices by customer (one line per
customer)
SELECT
CASE WHEN [Condition] THEN [Result]
ELSE [Result] END
FROM [Table Name]
• Exercise:
o Build a query of all vendors’ POs from 1/1/2017 – select your favorit 6 columns to
present
o In addition to the above, present a column called size:
▪ If total is smaller than $100 it will show ‘Small’
▪ If total between $100 and $1,000 it will show ‘Medium’
▪ If total is above $1,000 it will show ‘Large’
• Exercise:
o Create a query to present basic client information of clients that bought more than
twice (have at least 3 invoices or more).
3. Union Statement
The SQL UNION operator is used to combine the result sets of 2 or more SELECT
statements. It removes duplicate rows between the various SELECT statements. Each
SELECT statement within the UNION must have the same number of fields in the result
sets with similar data types.
• Exercise:
o Write a query to show all customers sales (invoices minus credit memos)
Formatted search function can be used to enter values automatically into fields as well as create
dependencies between fields in the system. For example, the value in field X influences the value
in field Y.
To retrieve data from the active window, you need to create a special query. SAP Business One
provides two different syntaxes for this type of query:
• $[Tablename.Fieldname]
o Tablename – Indicates the table to which the active window relates.
o Fieldname – The field from the active window.
Documentation:
http://www.pioneerb1.com/wp-content/uploads/2012/09/How-to-Define-and-Use-Formatted-
Search.pdf?x42527
• Exercise:
o Go to AR invoice and add FMS in the remarks field to show the business partner
account balance
User-defined alerts can be used to notify users of complex or unique business situations.
You can also use user-defined alerts to create routine task lists for users.
https://help.sap.com/doc/saphelpiis_hc_b1_image_repository_consultant_training_basic_b1
_90_tb1200_03_04_pdf/9.0/en-US/B1_90_TB1200_03_04.pdf
• Exercise:
o Display weekly alert for financial users of all AP invoices that are over $1,000
Example 1:
Example 2:
Approval for any purchase order with UDF BaseRef set to ‘N’
SELECT distinct'True'
FROM OPOR T0
WHERE $[OPOR.U_BaseREF] = 'N'
https://wiki.scn.sap.com/wiki/pages/viewpage.action?pageId=96403575
• Exercise:
o Create an approval procedure for every Goods Issue document created without the
word ‘Reason’ in remarks field.
SAP Business One database has many stored procedures out of the box that enables different
features and system reporting. You are not allowed to modify existing stores procedure other than
2 listed below. You can create new stored procedures as you wish.
• Transaction Notification
o This stored procedure is checking logic before an object being added or updated
o You can use this SP in order to apply logic, mandatory fields, restrictions etc.
o Syntax Example – Block PO if Vendor Ref Number is null
• Exercise:
o Block adding a sales order if remarks field is null
Microsoft Excel provides capabilities to integrate with SQL databases that can turn your excel into
a very powerful analytics tool. Utilizing the format options in Excel and pulling real time data from
SAP database can provide comprehensive reports that can be shared throughout the organization.
Connection to a database:
• If you never connected to SQL, you will need to establish a new connection following the
screenshot below
• Once a connection to the database have been established, you can have options like
saving the credentials and refreshing the data every so often
• Once connecting to a data source, you are able to retrieve information from any table and
view you have access to
o Tip: It’s easier to first create a view in the system gathering the information you need
from different tables and then connect Excel directly to the view