Upload
alex-psarras
View
35
Download
2
Tags:
Embed Size (px)
Citation preview
Alex Psarras
Question Box
Alex Psarras, ACDASenior Data Insight Analyst
3 Appleton Court, Calder Park, Wakefield WF2 7AR
T +44 (0)1924 254101 F +44 (0)1924 253358 M +44 (0)75 8596 7438
E: [email protected] W: www.dataconsulting.co.uk
Top Queries
1.Calculate number of months between dates
2.Identify duplicates over multiple fields
3.Automating SAP Direct Link background query retrieval
Calculating months between dates
Quick and dirty way• Months = (End Date – Start Date) / 30.00 (2 d.p.)• Months = (End Date – Start Date) / 30 (0 d.p.)
= (08/11/2014 – 28/08/2014) / 30.00 = 72 / 30.00 = 2.40 (2 d.p.) = 2 (0 d.p.)
Calculating months between dates
Quick and dirty way• Months = (End Date – Start Date) / 30.00 (2 d.p.)• Months = (End Date – Start Date) / 30 (0 d.p.)
= (08/11/2014 – 28/08/2014) / 30.00 = 72 / 30.00 = 2.40 (2 d.p.) = 2 (0 d.p.)
Calculating months between dates
A better approach*Months = MONTH(End Date) – MONTH(Start Date)
= MONTH(08/11/2014) – MONTH(28/08/2014) = 11 - 8 = 3
* version 10 onwards
Calculating months between dates
A better approach*Months = MONTH(End Date) – MONTH(Start Date)
* version 10 onwards
Calculating months between dates
A better approach*Months = (YEAR(End Date) – YEAR(Start Date)) * 12 + MONTH(End Date) – MONTH(Start Date)
= (YEAR(15/01/2015) – YEAR(08/11/2014)) * 12 + MONTH(15/01/2015) – MONTH(08/11/2014)
= (2015 – 2014) * 12 + 1 - 11 = 1 * 12 + 1 - 11 = 12 + 1 - 11 = 2
* version 10 onwards
Calculating months between dates
Pre-version 10
• MONTH() = VALUE(SPLIT(DATE(Date), “/”, 2), 0)• YEAR() = VALUE(SPLIT(DATE(Date), “/”, 3), 0)
Day / Month / Year
Segment 1 Separator Segment 2 Separator Segment 3
05 / 01 / 2015
Duplicates in different fields
Vendor ID
Name 1 Name 2 Address #
1st Line Address
Post Code
45463 Clownfish Telecom
Finance Department
3 North Forest St
TT8 9UX
48923 Clownfish Ltd (DON’T USE)
Clownfish Telecom
3 North Forest Street
TT8 9UX
48782 Death Star Enterprise
Mos Eisley Cantina
8 SW1 3PO
49969 A.Skywalker aka Darth Vader
8 Mos Eisley Cantina
SW1 3PO
Duplicates in different fields
Combine all key fields into one field:• Name 2 + Post Code• Address # + Post Code• 1st Line Address + Post Code• “Clean” versions of the above
45463 – TT8 9UX Digits 1st Line
45463 NorthForestSt – TT8 9UX Chars 1st Line
45463 North Forest St – TT8 9UX 1st Line
45463 3 - TT8 9UX Digits Address #
45463 - TT8 9UX Chars Address #
45463 - TT8 9UX Digits Name 2
45463 FinanceDepartment - TT8 9UX Chars Name 2
45463 Finance Department - TT8 9UX Name 2
Duplicates in different fieldsVendor ID Address Address Type
45463 3 - TT8 9UX Address #
45463 – TT8 9UX Digits 1st Line
45463 NorthForestSt – TT8 9UX Chars 1st Line
45463 North Forest St – TT8 9UX 1st Line
45463 3 - TT8 9UX Digits Address #
45463 - TT8 9UX Chars Address #
45463 - TT8 9UX Digits Name 2
45463 FinanceDepartment - TT8 9UX Chars Name 2
45463 Finance Department - TT8 9UX Name 2
Duplicates in different fieldsVendor ID Address Address Type
45463 3 - TT8 9UX Address #
48923 3 – TT8 9UX Digits 1st Line
48923 3 North Forest Street – TT8 9UX 1st Line
48923 Clownfish Telecom - TT8 9UX Name 2
45463 – TT8 9UX Digits 1st Line
45463 NorthForestSt – TT8 9UX Chars 1st Line
45463 North Forest St – TT8 9UX 1st Line
45463 3 - TT8 9UX Digits Address #
45463 - TT8 9UX Chars Address #
45463 - TT8 9UX Digits Name 2
45463 FinanceDepartment - TT8 9UX Chars Name 2
45463 Finance Department - TT8 9UX Name 2
Duplicates in different fieldsVendor ID Address Address Type
45463 3 - TT8 9UX Address #
Duplicates in different fields
• 45463 & 48923 (1 match)– Address # vs Digits 1st Line
• 48782 & 49962 (2 matches)– Name 2 vs 1st Line– 1st Line vs Address #
Vendor ID Address Address Type
45463 3 - TT8 9UX Address #
48923 3 – TT8 9UX Digits 1st Line
48782 Mos Eisley Cantina - SW1 3PO Name 2
48782 8 - SW1 3PO 1st Line
49969 Mos Eisley Cantina - SW1 3PO 1st Line
49969 8 - SW1 3PO Address #
Duplicates in different fieldsCOMMENT ** Extract all fields to Combined_Addresses
EXTRACT FIELDS TO "Combined_Addresses"Vendor_Number SUBSTRING(Name_2 + "-" + Post_Code, 1, 50) AS "Address" SUBSTRING("Name 2", 1, 20) AS "Type"
EXTRACT FIELDS TO "Combined_Addresses" APPENDVendor_Number SUBSTRING(INCLUDE(UPPER(Name_2), "A…Z") + "-" + Post_Code, 1, 50) SUBSTRING("Chars Name 2", 1, 20)
EXTRACT FIELDS TO "Combined_Addresses" APPENDVendor_Number SUBSTRING(INCLUDE(Name_2, "0123456789") + "-" + Post_Code, 1, 50) SUBSTRING("Digits Name 2", 1, 20)
COMMENT ** Repeat for next field
Auto-retrieve SAP Direct Link jobs
• ACL Direct Link has two modes:1. Extract Now
• For small queries, 488 KB or less• ACL retrieves data as soon as possible
2. Background • For larger queries• User has to manually retrieve data
• Background retrieval can be automated by using SAP table TBTCO - Job Status Overview
Job Name Start Date Start Time User Status End Date End Time
BSEG.DAT 13/01/2014 09:52:18 APsarras F 13/01/2014 13:49:02
BKPF.DAT 13/01/2014 09:58:34 APsarras R
Auto-retrieve SAP Direct Link jobs
How to automate SAP retrievals
1. Submit all queries in background mode2. Capture and log the SAP job names3. For each un-retrieved table
a) Check TBTCO and see if the data is readyb) If ready then retrieve data and log findingsc) Move on to next un-retrieved table
4. Wait X minutes and repeat step 3 5. Continue once we have all files
Auto-retrieve SAP Direct Link jobs
1. Submit all queries in background mode
EKKO.DAT 13/01/2014 09:52:19 N
LFA1.DAT 13/01/2014 09:52:18 N
BSEG.DAT 13/01/2014 09:52:18 N
Auto-retrieve SAP Direct Link jobs
2. Capture and log the SAP job names
Job Name Submit Date
SubmitTime
Complete Complete Date
Complete Time
Records
Auto-retrieve SAP Direct Link jobs
3. For each un-retrieved table
TBTKO
EKKO.DAT 13/01/2014 09:52:19 N
LFA1.DAT 13/01/2014 09:52:18 N
BSEG.DAT 13/01/2014 09:52:18 N
Job Name Submit Date
SubmitTime
Complete Complete Date
Complete Time
Records
Job Name Start Date Start Time User Status End Date End Time
BSEG.DAT 13/01/2014 09:52:18 APsarras R
Auto-retrieve SAP Direct Link jobs
3. For each un-retrieved table
TBTKO
EKKO.DAT 13/01/2014 09:52:19 N
LFA1.DAT 13/01/2014 09:52:18 Y
BSEG.DAT 13/01/2014 09:52:18 N
Job Name Submit Date
SubmitTime
Complete Complete Date
Complete Time
Records
Job Name Start Date Start Time User Status End Date End Time
LFA1.DAT 13/01/2014 09:52:18 APsarras F 13/01/2014 09:52:59
13/01/2014 09:52:59 52,485
Auto-retrieve SAP Direct Link jobs
3. For each un-retrieved table
TBTKO
EKKO.DAT 13/01/2014 09:52:19 N
LFA1.DAT 13/01/2014 09:52:18 Y
BSEG.DAT 13/01/2014 09:52:18 N
Job Name Submit Date
SubmitTime
Complete Complete Date
Complete Time
Records
Job Name Start Date Start Time User Status End Date End Time
EKKO.DAT 13/01/2014 09:52:19 APsarras R
13/01/2014 09:52:59 52,485
Auto-retrieve SAP Direct Link jobs
4. All tables retrieved?
No - so wait 10 minutes
EXECUTE "TIMEOUT /t 600“
Then go back to step 3
Auto-retrieve SAP Direct Link jobs
3. For each un-retrieved table
EKKO.DAT 13/01/2014 09:52:19 N
LFA1.DAT 13/01/2014 09:52:18 Y
BSEG.DAT 13/01/2014 09:52:18 N
Job Name Submit Date
SubmitTime
Complete Complete Date
Complete Time
Records
13/01/2014 09:52:59 52,485
Auto-retrieve SAP Direct Link jobs
3. For each un-retrieved table
Wait 10 minutes!
EKKO.DAT 13/01/2014 09:52:19 N
LFA1.DAT 13/01/2014 09:52:18 Y
BSEG.DAT 13/01/2014 09:52:18 N
Job Name Submit Date
SubmitTime
Complete Complete Date
Complete Time
Records
13/01/2014 09:52:59 52,485
Auto-retrieve SAP Direct Link jobs
3. For each un-retrieved table
Wait 10 minutes!
EKKO.DAT 13/01/2014 09:52:19 N
LFA1.DAT 13/01/2014 09:52:18 Y
BSEG.DAT 13/01/2014 09:52:18 N
Job Name Submit Date
SubmitTime
Complete Complete Date
Complete Time
Records
13/01/2014 09:52:59 52,485
Auto-retrieve SAP Direct Link jobs
3. For each un-retrieved table
EKKO.DAT 13/01/2014 09:52:19 Y
LFA1.DAT 13/01/2014 09:52:18 Y
BSEG.DAT 13/01/2014 09:52:18 Y
Job Name Submit Date
SubmitTime
Complete Complete Date
Complete Time
Records
13/01/2014 09:52:59 52,485
13/01/2014 11:38:12 11,848,179
13/01/2014 18:08:32 89,711,009
Questions?
Alex Psarras075 8596 [email protected]