SlideShare a Scribd company logo
1 of 7
Download to read offline
Data Services Functions, an exercise in base number conversions
Data Services (DS) scripting language is often seen purely as a means for setting global variables or
handling calls to OS level commands. While it is not designed for complex coding or cursor operations
the basic operations available in DS lend themselves to a variety of applications. You will see some of
those capabilities demonstrated in this article implementing numeric case conversions from and to
Binary, Octal, Decimal and Hexadecimal.
Converting Hexadecimal numbers to Binary numbers
Let’s start out with a function to convert hexadecimal (base 16) numbers over to binary (base 2). Figure
1 contains the header comment block, a break down by section follows.
Figure 1 – Header Comment Block
The first feature you should utilize when using the DS scripting language is the comment. Comments
start with a pound (#) sign and everything after that symbol is ignored during script execution.
Comments are shown in the auto-documentation generated by DS and can serve as a version log,
function parameter summary and notepad for why you used a particular method instead of other
alternatives in the code.
The header comment block should include the following sections (numbered in Figure 1 for
identification purposes):
 Section 1 contains a simple function usage schematic. The schematic allows you to see at a
glance the data type and length of each parameter as well te parameters usage in the function
(input, output or inout).
 Section 2 provides basic information about who wrote the function, its intended use and when it
was authored.
 Section 3 gives a chronological log of changes to the function and a basic description of the
change made.
 Section 4 lists the locally scoped variables used with type, length and a short description.
 Section 5 provides an area for notes that can be used for any general information about the
function, limitations, or other pertinent facts for later reference.
Figure 2 - Variable Setting
At this point in the script, you should set your variables to their starting values. While this can be done
later in the script, grouping and setting them all in the same place make locating them simple as you
follow the code or begin troubleshooting. Figure 2 shows an example of variable values that are utilized
in this script. Use the equal operator for assignment and the semi-colon to end the statement.
Figure 3 - While loop
In Figure 3 you see a while statement, which is the looping structure used in DS scripting. If you are
familiar with the While transform or almost any iterative control statement (FOR-NEXT, etc) this
structure will be easy to follow. It starts with a condition to be satisfied and continues repeating the
steps defined until the condition fails to be met. In cases where multiple satisfying conditions are
possible you should take care to order them in such a way that the desired condition-value pair is
evaluated first. If no condition is satisfied then the final value of the decode statement (an ELSE value) is
returned.
In this example, the first hex character is selected and the binary equivalent is assigned to the output
string. The assignment is done by appending (using a double pipe concatenation operator) the result of
a decode statement to the end of output variable that will be passed back from the function. The
decode statement works by evaluating conditions and returning a value (a condition-value pair). When a
condition is satisfied the value portion of the condition-value pair is returned and no further conditions
are evaluated. Then the loop counter increments and the code repeats until there are no more
characters to convert.
Figure 4 - Return result
Lastly Figure 4 shows the output string returned. It contains the binary number that was built by the
while loop in Figure 3.
Converting Binary to Octal
The reverse of converting binary to hexadecimal would be very similar to what I described so far, so let’s
take a look at a binary to octal conversion to review a few other DS script commands.
Figure 5 - Binary to octal
Figure 5 shows the basic structure and variable defaults, which are very similar to the example covered
in Figure 1. You can read through it again and see what is going on, if needed.
Figure 6 - Positional padding
In Figure 6, you see the mod function used to append additional placeholder values at the beginning of
the binary input string to make number of positions evenly divisible by 3. This makes conversion easier
by providing consistent binary triplets for assignment to octal.
Figure 7 - Conversion code Figure 8 - Conversion code, revised
The difference you may notice from Figure 3 to Figure 7 is the addition of a substring to remove leading
zeros. This is done because binary numbers often are a set length with leading zeros and octal is not
commonly displayed with a leading zero. The substring was used in Figure 7 to show that there are often
multiple ways to accomplish a desired outcome in DS script. In this case, it is simpler to use another
native DS function, LTRIM. See Figure 8 for revised code using the LTRIM function.
Figure 9 – Conditional calls
When you have a need to do accomplish a task on a variety of different input types in the context of a
function, you can accomplish it with a structure similar to the one in Figure 9. This nesting of functions
can make your code more versatile and reusable at the same time. In this snippet, inside a wrapper
function called fn_base_convert, other functions are called as needed to return the desired value. You
can mix calls to other functions or use additional code to handle scenarios where no existing function
fits your needs. The decimal conversion uses another DS script function called POWER to calculate the
decimal value of a binary position. It calculates the decimal value of a given position by multiplying the
binary value by two to the power of that position minus one, represented as 2(length-iteration)
.
In conclusion, Data Services scripting language can accomplish a variety of tasks that you might
otherwise have to rely on database functions or other outside tools to accomplish. This allows you to
maintain all your code in a single location reducing the need for multiple toolsets and speeds
development through re-use. If you would like to play with the functions and come up with more
efficient ways to do the conversions or show off a different set of commands, feel free to download the
scripts in the linked file.
Ernie Phelps, Business Intelligence Consultant
Decision First Technologies
Ernie.phelps@decisionfirst.com
Ernie Phelps is a BI consultant with 15 years experience in Enterprise Information Management (EIM).
He is the Chair of ASUG’s Data Management Special Interest Group and previous Customer Chair of the
EIM Influence Council. At Decision First Technologies, Ernie fulfills a variety of roles including data
modeling, ETL development, mentoring, profiling and teaching.

More Related Content

What's hot

C programming session 09
C programming session 09C programming session 09
C programming session 09Dushmanta Nath
 
Programming in c++ ppt
Programming in c++ pptProgramming in c++ ppt
Programming in c++ pptMalarMohana
 
Database Management System-session 3-4-5
Database Management System-session 3-4-5Database Management System-session 3-4-5
Database Management System-session 3-4-5Infinity Tech Solutions
 
CPU : Structures And Unions
CPU : Structures And UnionsCPU : Structures And Unions
CPU : Structures And UnionsDhrumil Patel
 
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdfMANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdfSowmyaJyothi3
 
Structure of c_program_to_input_output
Structure of c_program_to_input_outputStructure of c_program_to_input_output
Structure of c_program_to_input_outputAnil Dutt
 
Overview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiOverview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiSowmya Jyothi
 
C programming session 07
C programming session 07C programming session 07
C programming session 07Dushmanta Nath
 
C intro
C introC intro
C introKamran
 

What's hot (18)

C programming session 09
C programming session 09C programming session 09
C programming session 09
 
Structures
StructuresStructures
Structures
 
C programming part4
C programming part4C programming part4
C programming part4
 
Shanks
ShanksShanks
Shanks
 
Programming in c++ ppt
Programming in c++ pptProgramming in c++ ppt
Programming in c++ ppt
 
Database Management System-session 3-4-5
Database Management System-session 3-4-5Database Management System-session 3-4-5
Database Management System-session 3-4-5
 
C Structures And Unions
C  Structures And  UnionsC  Structures And  Unions
C Structures And Unions
 
Programming
ProgrammingProgramming
Programming
 
CPU : Structures And Unions
CPU : Structures And UnionsCPU : Structures And Unions
CPU : Structures And Unions
 
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdfMANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
 
C material
C materialC material
C material
 
C tokens
C tokensC tokens
C tokens
 
Structure of c_program_to_input_output
Structure of c_program_to_input_outputStructure of c_program_to_input_output
Structure of c_program_to_input_output
 
Pointers In C
Pointers In CPointers In C
Pointers In C
 
Overview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiOverview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya Jyothi
 
C programming session 07
C programming session 07C programming session 07
C programming session 07
 
C intro
C introC intro
C intro
 
Assignment#08
Assignment#08Assignment#08
Assignment#08
 

Viewers also liked

Student Groups by Adrian Holliday
Student Groups by Adrian HollidayStudent Groups by Adrian Holliday
Student Groups by Adrian HollidayOla Sayed Ahmed
 
Transactional & Interactional Features of Student Cultures in Tishreen Univer...
Transactional & Interactional Features of Student Cultures in Tishreen Univer...Transactional & Interactional Features of Student Cultures in Tishreen Univer...
Transactional & Interactional Features of Student Cultures in Tishreen Univer...Ola Sayed Ahmed
 
Case study "Thesis Writing" Developing Courses in Englsih By Helen Basturkmen
Case study "Thesis Writing" Developing Courses in Englsih By Helen BasturkmenCase study "Thesis Writing" Developing Courses in Englsih By Helen Basturkmen
Case study "Thesis Writing" Developing Courses in Englsih By Helen BasturkmenOla Sayed Ahmed
 
Villa quarda august2011
Villa quarda august2011Villa quarda august2011
Villa quarda august2011Aliona Josanu
 
459 policy initatives for improved financial services national
459 policy initatives for improved financial services   national459 policy initatives for improved financial services   national
459 policy initatives for improved financial services nationalJai Jp
 
FLA First Langugae Acquisition Theories
FLA First Langugae Acquisition TheoriesFLA First Langugae Acquisition Theories
FLA First Langugae Acquisition TheoriesOla Sayed Ahmed
 
Designing the Needs Analysis
Designing the Needs AnalysisDesigning the Needs Analysis
Designing the Needs AnalysisOla Sayed Ahmed
 
Language Assessment Types
Language Assessment TypesLanguage Assessment Types
Language Assessment TypesOla Sayed Ahmed
 
Great Ideas-unit 4 Market Leader pre-intermediate
Great Ideas-unit 4 Market Leader pre-intermediate Great Ideas-unit 4 Market Leader pre-intermediate
Great Ideas-unit 4 Market Leader pre-intermediate Ola Sayed Ahmed
 
Bengkel 64 studi banding edited
Bengkel 64 studi banding editedBengkel 64 studi banding edited
Bengkel 64 studi banding editedMas Baz
 
Presentacion del blogger
Presentacion  del bloggerPresentacion  del blogger
Presentacion del bloggerGrupo6ma
 
chỗ nào dịch vụ giúp việc quận 11 tại hcm
chỗ nào dịch vụ giúp việc quận 11 tại hcmchỗ nào dịch vụ giúp việc quận 11 tại hcm
chỗ nào dịch vụ giúp việc quận 11 tại hcmadolfo399
 
Modis National Jobs Report October 2015
Modis National Jobs Report October 2015Modis National Jobs Report October 2015
Modis National Jobs Report October 2015Modis
 
Nayiuski admistracion
Nayiuski admistracionNayiuski admistracion
Nayiuski admistracionNayiuski
 
Propuesta literaria:"El monstruo de colores"
Propuesta literaria:"El monstruo de colores" Propuesta literaria:"El monstruo de colores"
Propuesta literaria:"El monstruo de colores" MaleEspindola
 

Viewers also liked (20)

Rohetgarh Photo Gallery
Rohetgarh Photo GalleryRohetgarh Photo Gallery
Rohetgarh Photo Gallery
 
Student Groups by Adrian Holliday
Student Groups by Adrian HollidayStudent Groups by Adrian Holliday
Student Groups by Adrian Holliday
 
ADR in Service of Human Rights
ADR in Service of Human RightsADR in Service of Human Rights
ADR in Service of Human Rights
 
Transactional & Interactional Features of Student Cultures in Tishreen Univer...
Transactional & Interactional Features of Student Cultures in Tishreen Univer...Transactional & Interactional Features of Student Cultures in Tishreen Univer...
Transactional & Interactional Features of Student Cultures in Tishreen Univer...
 
Case study "Thesis Writing" Developing Courses in Englsih By Helen Basturkmen
Case study "Thesis Writing" Developing Courses in Englsih By Helen BasturkmenCase study "Thesis Writing" Developing Courses in Englsih By Helen Basturkmen
Case study "Thesis Writing" Developing Courses in Englsih By Helen Basturkmen
 
Villa quarda august2011
Villa quarda august2011Villa quarda august2011
Villa quarda august2011
 
459 policy initatives for improved financial services national
459 policy initatives for improved financial services   national459 policy initatives for improved financial services   national
459 policy initatives for improved financial services national
 
FLA First Langugae Acquisition Theories
FLA First Langugae Acquisition TheoriesFLA First Langugae Acquisition Theories
FLA First Langugae Acquisition Theories
 
Designing the Needs Analysis
Designing the Needs AnalysisDesigning the Needs Analysis
Designing the Needs Analysis
 
Language Assessment Types
Language Assessment TypesLanguage Assessment Types
Language Assessment Types
 
Great Ideas-unit 4 Market Leader pre-intermediate
Great Ideas-unit 4 Market Leader pre-intermediate Great Ideas-unit 4 Market Leader pre-intermediate
Great Ideas-unit 4 Market Leader pre-intermediate
 
Web 2.0
Web 2.0 Web 2.0
Web 2.0
 
Bengkel 64 studi banding edited
Bengkel 64 studi banding editedBengkel 64 studi banding edited
Bengkel 64 studi banding edited
 
Presentacion del blogger
Presentacion  del bloggerPresentacion  del blogger
Presentacion del blogger
 
chỗ nào dịch vụ giúp việc quận 11 tại hcm
chỗ nào dịch vụ giúp việc quận 11 tại hcmchỗ nào dịch vụ giúp việc quận 11 tại hcm
chỗ nào dịch vụ giúp việc quận 11 tại hcm
 
икт форма взаимодействия
икт форма взаимодействияикт форма взаимодействия
икт форма взаимодействия
 
Modis National Jobs Report October 2015
Modis National Jobs Report October 2015Modis National Jobs Report October 2015
Modis National Jobs Report October 2015
 
Nayiuski admistracion
Nayiuski admistracionNayiuski admistracion
Nayiuski admistracion
 
El medallero presentación
El medallero presentaciónEl medallero presentación
El medallero presentación
 
Propuesta literaria:"El monstruo de colores"
Propuesta literaria:"El monstruo de colores" Propuesta literaria:"El monstruo de colores"
Propuesta literaria:"El monstruo de colores"
 

Similar to Data services-functions

Sterling Integrator Map Editor
Sterling Integrator Map EditorSterling Integrator Map Editor
Sterling Integrator Map EditorJeyhind M
 
C programming language
C programming languageC programming language
C programming languageAbin Rimal
 
Functions and modular programming.pptx
Functions and modular programming.pptxFunctions and modular programming.pptx
Functions and modular programming.pptxzueZ3
 
Cobol programming language
Cobol programming languageCobol programming language
Cobol programming languageBurhan Ahmed
 
Dbms important questions and answers
Dbms important questions and answersDbms important questions and answers
Dbms important questions and answersLakshmiSarvani6
 
Core C# Programming Constructs, Part 1
Core C# Programming Constructs, Part 1Core C# Programming Constructs, Part 1
Core C# Programming Constructs, Part 1Vahid Farahmandian
 
Important notes· NOTE it is usually fine and often encouraged i.docx
Important notes· NOTE it is usually fine and often encouraged i.docxImportant notes· NOTE it is usually fine and often encouraged i.docx
Important notes· NOTE it is usually fine and often encouraged i.docxwilcockiris
 
04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptxManas40552
 
Chapter 2 programming concepts - I
Chapter 2  programming concepts - IChapter 2  programming concepts - I
Chapter 2 programming concepts - ISHREEHARI WADAWADAGI
 
Chapter3: fundamental programming
Chapter3: fundamental programmingChapter3: fundamental programming
Chapter3: fundamental programmingNgeam Soly
 
The future of DSLs - functions and formal methods
The future of DSLs - functions and formal methodsThe future of DSLs - functions and formal methods
The future of DSLs - functions and formal methodsMarkus Voelter
 
Assembler directives and basic steps ALP of 8086
Assembler directives and basic steps ALP of 8086Assembler directives and basic steps ALP of 8086
Assembler directives and basic steps ALP of 8086Urvashi Singh
 
Stop hardcoding follow parameterization
Stop hardcoding  follow parameterizationStop hardcoding  follow parameterization
Stop hardcoding follow parameterizationPreeti Sagar
 
introductory concepts
introductory conceptsintroductory concepts
introductory conceptsWalepak Ubi
 
Functional programming in TypeScript
Functional programming in TypeScriptFunctional programming in TypeScript
Functional programming in TypeScriptbinDebug WorkSpace
 

Similar to Data services-functions (20)

unit 2.pptx
unit 2.pptxunit 2.pptx
unit 2.pptx
 
Sterling Integrator Map Editor
Sterling Integrator Map EditorSterling Integrator Map Editor
Sterling Integrator Map Editor
 
C programming language
C programming languageC programming language
C programming language
 
Functions and modular programming.pptx
Functions and modular programming.pptxFunctions and modular programming.pptx
Functions and modular programming.pptx
 
Cobol programming language
Cobol programming languageCobol programming language
Cobol programming language
 
Dbms important questions and answers
Dbms important questions and answersDbms important questions and answers
Dbms important questions and answers
 
Core C# Programming Constructs, Part 1
Core C# Programming Constructs, Part 1Core C# Programming Constructs, Part 1
Core C# Programming Constructs, Part 1
 
Fahri tugas cloud1
Fahri tugas cloud1Fahri tugas cloud1
Fahri tugas cloud1
 
Important notes· NOTE it is usually fine and often encouraged i.docx
Important notes· NOTE it is usually fine and often encouraged i.docxImportant notes· NOTE it is usually fine and often encouraged i.docx
Important notes· NOTE it is usually fine and often encouraged i.docx
 
04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
Operators
OperatorsOperators
Operators
 
Chapter 2 programming concepts - I
Chapter 2  programming concepts - IChapter 2  programming concepts - I
Chapter 2 programming concepts - I
 
Chapter3: fundamental programming
Chapter3: fundamental programmingChapter3: fundamental programming
Chapter3: fundamental programming
 
The future of DSLs - functions and formal methods
The future of DSLs - functions and formal methodsThe future of DSLs - functions and formal methods
The future of DSLs - functions and formal methods
 
Assembler directives and basic steps ALP of 8086
Assembler directives and basic steps ALP of 8086Assembler directives and basic steps ALP of 8086
Assembler directives and basic steps ALP of 8086
 
Stop hardcoding follow parameterization
Stop hardcoding  follow parameterizationStop hardcoding  follow parameterization
Stop hardcoding follow parameterization
 
Visual basic
Visual basicVisual basic
Visual basic
 
introductory concepts
introductory conceptsintroductory concepts
introductory concepts
 
Functional programming in TypeScript
Functional programming in TypeScriptFunctional programming in TypeScript
Functional programming in TypeScript
 

Recently uploaded

WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2
 
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...WSO2
 
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2
 
WSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in UgandaWSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in UgandaWSO2
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2
 
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2
 
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next IntegrationWSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next IntegrationWSO2
 
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of TransformationWSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of TransformationWSO2
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 

Recently uploaded (20)

WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
 
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
WSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in UgandaWSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in Uganda
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
 
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next IntegrationWSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
 
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of TransformationWSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 

Data services-functions

  • 1. Data Services Functions, an exercise in base number conversions Data Services (DS) scripting language is often seen purely as a means for setting global variables or handling calls to OS level commands. While it is not designed for complex coding or cursor operations the basic operations available in DS lend themselves to a variety of applications. You will see some of those capabilities demonstrated in this article implementing numeric case conversions from and to Binary, Octal, Decimal and Hexadecimal. Converting Hexadecimal numbers to Binary numbers Let’s start out with a function to convert hexadecimal (base 16) numbers over to binary (base 2). Figure 1 contains the header comment block, a break down by section follows. Figure 1 – Header Comment Block The first feature you should utilize when using the DS scripting language is the comment. Comments start with a pound (#) sign and everything after that symbol is ignored during script execution. Comments are shown in the auto-documentation generated by DS and can serve as a version log, function parameter summary and notepad for why you used a particular method instead of other alternatives in the code.
  • 2. The header comment block should include the following sections (numbered in Figure 1 for identification purposes):  Section 1 contains a simple function usage schematic. The schematic allows you to see at a glance the data type and length of each parameter as well te parameters usage in the function (input, output or inout).  Section 2 provides basic information about who wrote the function, its intended use and when it was authored.  Section 3 gives a chronological log of changes to the function and a basic description of the change made.  Section 4 lists the locally scoped variables used with type, length and a short description.  Section 5 provides an area for notes that can be used for any general information about the function, limitations, or other pertinent facts for later reference. Figure 2 - Variable Setting At this point in the script, you should set your variables to their starting values. While this can be done later in the script, grouping and setting them all in the same place make locating them simple as you follow the code or begin troubleshooting. Figure 2 shows an example of variable values that are utilized in this script. Use the equal operator for assignment and the semi-colon to end the statement. Figure 3 - While loop
  • 3. In Figure 3 you see a while statement, which is the looping structure used in DS scripting. If you are familiar with the While transform or almost any iterative control statement (FOR-NEXT, etc) this structure will be easy to follow. It starts with a condition to be satisfied and continues repeating the steps defined until the condition fails to be met. In cases where multiple satisfying conditions are possible you should take care to order them in such a way that the desired condition-value pair is evaluated first. If no condition is satisfied then the final value of the decode statement (an ELSE value) is returned. In this example, the first hex character is selected and the binary equivalent is assigned to the output string. The assignment is done by appending (using a double pipe concatenation operator) the result of a decode statement to the end of output variable that will be passed back from the function. The decode statement works by evaluating conditions and returning a value (a condition-value pair). When a condition is satisfied the value portion of the condition-value pair is returned and no further conditions are evaluated. Then the loop counter increments and the code repeats until there are no more characters to convert. Figure 4 - Return result Lastly Figure 4 shows the output string returned. It contains the binary number that was built by the while loop in Figure 3. Converting Binary to Octal The reverse of converting binary to hexadecimal would be very similar to what I described so far, so let’s take a look at a binary to octal conversion to review a few other DS script commands.
  • 4. Figure 5 - Binary to octal Figure 5 shows the basic structure and variable defaults, which are very similar to the example covered in Figure 1. You can read through it again and see what is going on, if needed. Figure 6 - Positional padding In Figure 6, you see the mod function used to append additional placeholder values at the beginning of the binary input string to make number of positions evenly divisible by 3. This makes conversion easier by providing consistent binary triplets for assignment to octal.
  • 5. Figure 7 - Conversion code Figure 8 - Conversion code, revised The difference you may notice from Figure 3 to Figure 7 is the addition of a substring to remove leading zeros. This is done because binary numbers often are a set length with leading zeros and octal is not commonly displayed with a leading zero. The substring was used in Figure 7 to show that there are often multiple ways to accomplish a desired outcome in DS script. In this case, it is simpler to use another native DS function, LTRIM. See Figure 8 for revised code using the LTRIM function.
  • 6. Figure 9 – Conditional calls When you have a need to do accomplish a task on a variety of different input types in the context of a function, you can accomplish it with a structure similar to the one in Figure 9. This nesting of functions can make your code more versatile and reusable at the same time. In this snippet, inside a wrapper function called fn_base_convert, other functions are called as needed to return the desired value. You can mix calls to other functions or use additional code to handle scenarios where no existing function fits your needs. The decimal conversion uses another DS script function called POWER to calculate the decimal value of a binary position. It calculates the decimal value of a given position by multiplying the binary value by two to the power of that position minus one, represented as 2(length-iteration) . In conclusion, Data Services scripting language can accomplish a variety of tasks that you might otherwise have to rely on database functions or other outside tools to accomplish. This allows you to maintain all your code in a single location reducing the need for multiple toolsets and speeds development through re-use. If you would like to play with the functions and come up with more efficient ways to do the conversions or show off a different set of commands, feel free to download the scripts in the linked file.
  • 7. Ernie Phelps, Business Intelligence Consultant Decision First Technologies Ernie.phelps@decisionfirst.com Ernie Phelps is a BI consultant with 15 years experience in Enterprise Information Management (EIM). He is the Chair of ASUG’s Data Management Special Interest Group and previous Customer Chair of the EIM Influence Council. At Decision First Technologies, Ernie fulfills a variety of roles including data modeling, ETL development, mentoring, profiling and teaching.