Course Document Transact Programming Foundation TR3PRGFO - R22 Revision 1 English
Course Document Transact Programming Foundation TR3PRGFO - R22 Revision 1 English
Table of Contents
Practice 3........................................................................................................................................................................................................115
Practice 3 » Solution ...................................................................................................................................................................................116
Practice 4........................................................................................................................................................................................................117
Practice 4 » Solution ...................................................................................................................................................................................118
Practice 5........................................................................................................................................................................................................119
Practice 5 » Solution ...................................................................................................................................................................................120
Practice 6........................................................................................................................................................................................................121
Practice 6 » Solution ...................................................................................................................................................................................122
Practice 7........................................................................................................................................................................................................123
Practice 7 » Solution ...................................................................................................................................................................................124
Practice 7 » Solution ...................................................................................................................................................................................125
TUT ........................................................................................................................................................................................................ 126
Lesson Summary ..........................................................................................................................................................................................126
UTF Methods » UnitTest Framework ......................................................................................................................................................127
SIMPLE.CALCULATOR API .........................................................................................................................................................................128
SIMPLE.CALCULATOR API .........................................................................................................................................................................129
SIMPLE.CALCULATOR API .........................................................................................................................................................................130
TESTCASE .......................................................................................................................................................................................................131
TESTCASE » Steps ........................................................................................................................................................................................132
TESTCASE » Global UTF Methods ............................................................................................................................................................133
TESTCASE » Global UTF Methods ............................................................................................................................................................134
TESTCASE » Global UTF Methods ............................................................................................................................................................135
Using IDE to Set the target ........................................................................................................................................................................136
TESTCASE » Global UTF Methods ............................................................................................................................................................137
TESTCASE » Assertion .................................................................................................................................................................................138
TESTCASE » Running the Test ..................................................................................................................................................................139
TESTCASE » Debugging the Test .............................................................................................................................................................140
Stubs ................................................................................................................................................................................................................141
Stubs ................................................................................................................................................................................................................142
Stubs ................................................................................................................................................................................................................143
Stubs » Using the IDE to Add STUB and StubParam ..........................................................................................................................144
Stubs ................................................................................................................................................................................................................145
Assertions » NUMBER.DIVISION Test .....................................................................................................................................................146
Lesson Summary ..........................................................................................................................................................................................147
Practice ................................................................................................................................................................................................ 148
Practice 1........................................................................................................................................................................................................148
Practice 1 » Solution ...................................................................................................................................................................................149
Practice 1 » Solution ...................................................................................................................................................................................150
Practice 1 » Solution ...................................................................................................................................................................................151
Document History
Introduction
Lesson Overview
In this lesson, I am going to describe what Your Course is all about, Programming Foundation, Design Studio, and Common
Variables.
Common Variables
The Variables can be created locally within a program or subroutine, local variables. The shareable between programs or
subroutines, common variables. The local variables are variables used within the program or subroutine.
Lesson Summary
In this lesson, I described what Your Course is all about, Programming Foundation, Design Studio, and Common Variables.
Practice
Practice 1
Predict the output of the above code snippets
Practice 1 » Solution
Practice Solution It will throw the error as JBase does not need us to declare the type of VARB and it will not recognise what
INT is and hence it will throw error as seen : ERROR unexpected token: INT The variable 'VARB' is not initialized
Practice 1 » Solution
Practice Solution In the above snippet NAME variable is initialized to DON in Program Customer and it calls the SUBROUTINE
CUST.ADDRESS and then prints the NAME on the console . Since the CUST.ADDRESS subroutine initializes the NAME to SAM
, hence the Printing of NAME after Subroutine call in Program CUSTOMER will print the output as: NAME=SAM
Practice 1 » Solution
Conditional Execution
The expression will be evaluated to a value of Boolean true or false. If the expression is true, the statements defined by the
then clause will be executed (if present). If the expression is false, the statements defined by the else clause are executed.
The then and else clauses may take two different forms, single and multiple-line statements. The simplest form of either
clause is of the form: IF A then CRT A or IF A else CRT A, but the clauses may be expanded to enclose multiple lines of code
using the end keyword as so: IF A then, A equals A multiply by 6, CRT A, end else, A equals 76, CRT A END. The single and
multi-line versions of either clause may be combined to make complex command combinations, if the statements can be
nested within either clause to any number of levels.
Looping Constructs
Looping Constructs: If you want a statement or group of statements multiple times without writing the code repeatedly, then
the solution for this Looping. In other words, Loops, as you are aware, facilitate the repetitive execution of code. The jBC has
two types of looping constructs, for, next and loop, repeat.
Looping Constructs
VAR is the counter variable (aka index variable) used to control the loop. The first time the loop is entered, VAR is assigned
the value of expression1, which must evaluate as a numeric value. After each loop iteration, the VAR is automatically
incremented by one. The expression 2 must also evaluate to a numeric value as it causes the loop to terminate when the
value of var is greater than the value of this expression. Expression 2 is evaluated at the start of every iteration of the loop
and compared with the value of expression 1. If the step expression3 clause is included within the statement, var will
automatically be incremented by the value of expression3 after each iteration of the loop. Expression 3 is evaluated at the
start of each iteration. expression3 may be negative, wherein the loop will terminate when VAR is less than expression2.
Paragraphs
Paragraphs: The Paragraph facilitates the modular programming approach to help make the code more maintainable and
reusable. A few points: The jBC is a structured programming language and follows a modular programming approach. In
Modular programming, a large program is broken into manageable units called paragraphs to create code that can be easily
re-used. Modular programming improves the maintainability of code. A modular program consists of a main module and
one or more auxiliary modules.
Paragraphs » Comments
All data lines other than code should be prefixed with an asterisk to denote that it is a comment line. The compiler ignores
comment lines. All jBC programs must have comments, followed by the author’s name and date of creation. The date and
details of any further amendments to the program must also be recorded.
Editor Functionality
When you right click on the editor or on the main menu or toolbar, you will find 8 editor functionalities: collapse all regions,
expand all regions, create region, create GOSUB, insert comment line, format code, block comment, and block uncomment.
Editor Functionality
The Region: The region is part of the code decorated by some tags ignored by the compiler. In the annotation bar, you can
collapse or expand it. Comment code: You can add a comment line in the code using “Insert comment Line.” You can
comment or uncomment a block of code using “block comment” or “block uncomment.”
Editor Functionality
Format Code: Use the format code option to indent your code. GOSUB: In the code a GOSUB and a region with the label
provided in the dialog box will be created.
Lesson Summary
In this lesson, I described Conditional Execution, Looping Constructs, Paragraphs, Editor Functionality, and Debug Basic Code.
Practice
Practice 1
Write a Simple program to store personal details of an employee as described in the slide above.. What changes will have
to be made to the program if it is written using sub routines instead of paragraphs If the program has to be rewritten using
subroutines, then then variables to accept employee info must be declared as a common variable in an insert file and the
insert file must be included in the subroutine accepting the emp info , displaying the emp info. Main program must be used
to just call the subroutines separately.
Practice 1 » Solution
Practice 1 » Solution
Practice 1 PARAGRAPH TO ACCEPT EMPLOYEE DETAILS
Practice 1 » Solution
Practice 1 PARAGRAPH TO DISPLAY EMPLOYEE DETAILS
Practice 1 » Solution
Practice 1 CONSOLE OUTPUT SHOWING THE INPUT TO ACCEPT AND DISPLAY OF EMPLOYEE DETAILS
Practice 2
Modify the Program created in Practice 1 to use subroutines instead of paragraphs
Practice 2 » Solution
Practice 2 Solution Main Program named EMP_PERSONAL_DETAILS would be using subroutines subroutines separately to
accept and display employee details are shown above..
Practice 2 » Solution
Practice 2 Solution Subroutine named EMP.INFO.ACCEPT is used to accept the employee details is shown above. Variables
are defined in a separate file named I_MYEMP.VARS and inserted in the subroutines using $INSERT statement.
Practice 2 » Solution
Practice 2 Solution Subroutine named EMP.INFO.DISPLAY is used to display the employee details is shown above
Practice 2 » Solution
Practice 2 Solution Console output of Employee Details using subroutines is shown above
Arrays in jBC
We can use a variable to store the details of Jo's friend. Details equal Bob Artist Music 1231231231 India. If we store the
details in a single variable, we need a marker to segregate each piece of information. The first level of the marker is the FM
or the field marker. It is used to separate the different fields. These are the first level of markers that delimit the data and are
referred to as Field Markers or FM in jBC. The ASCII character denotes it equals char(254). S
Arrays in jBC
Arrays in jBC. The Arrays are variables that hold multiple values in continuous memory locations. Every variable in jBC is
Dynamic. The Arrays are not always static. How can the size of this array be decided, especially since unlimited information
can be stored using the markers. The Size of the Array cannot be decided as we can store multiple types of related information
on a single variable.
Arrays in jBC
To cater to this variable length information, jBC has specially optimized arrays, which are also variable in size, to
accommodate its exact length. It obviates the need to declare enormous arrays as we need to be aware of the information
length, running the risk of massive waste of allocated space. An unlimited amount of information can be stored in a single
array: limited only by the RAM capacity.
Dimensioned Array
Dimensioned Array: As the name implies, dimensioned arrays have a dimension. They are declared using the DIM statement.
To store Jo's friend's details, we may declare a dimensioned array as DIM ArrName (row), for example, DIM friend (6).
Allocates 6 rows. Each row in a Dimensioned Array is a Dynamic Array of variable length depending on the data to be stored.
Use a Dimensioned Array when the amount of information stored is vast.
Dimensioned Array
You may visualize Jo's friend list stored in a dimensioned array as shown. Each row is of variable length to provide room for
as many multi-values and sub-values as required. The number of rows is fixed. The use of parenthesis () instead of angular
brackets. The lack of Field Markers to segregate the individual friends. You can see how the dimensioned array is represented
in the above slide, and a total of 7 rows has been declared, with each row having a variable number of elements in it.
Lesson Summary
In this lesson, I described Arrays in jBC, Dynamic Array, and Dimensioned Array.
Practice
Practice 1
Practice 1 » Solution
Answers are shown in the Bold letters in blue color in the slide above red VM maroon FM blue VM green VM marine blue
SM ocean blue SM marine green FM orange VM amber. <1,1> <1,2> <2,1> <2,2> <2,3,1> <2,3,2>
<2,3,3> <3,1,1> <3,2,1> AAA FM BBB VM CCC VM DDD SM EEE FM FFF <1,1> <2,1> <2,2>
<2,3,1> <2,3,2> <3,1> Is the declaration correct? No. Only the number of rows is fixed for a dimensioned array. The
no of columns cannot be specified
Practice 2
Write a program to accept the employee details and display them
Practice 2 » Solution
Write a program named EMP_INFO in Design Studio to store the details of the employee and display it on the console. User
is requested to enter the choice and based on the choice entered by the user it will evaluate the options using case statements
as seen in next slide.
Practice 2 » Solution
Case statements is used to evaluate the choices entered by the user and to proceed with the execution . If the user enters
the valid choice execution proceeds accordingly else if user enter the choice which is not shown, then the user is notified
about his invalid entry of choice
Practice 2 » Solution
Store the details of the employee using paragraph STORE.EMPLOYEE
Practice 2 » Solution
Store the details of the employee using paragraph STORE.EMPLOYEE For year of qualification, phone numbers and Email
id’s.
Practice 2 » Solution
Answers are shown in the Bold letters in blue color in the slide above red VM maroon FM blue VM green VM marine blue
SM ocean blue SM marine green FM orange VM amber. <1,1> <1,2> <2,1> <2,2> <2,3,1> <2,3,2>
<2,3,3> <3,1,1> <3,2,1> AAA FM BBB VM CCC VM DDD SM EEE FM FFF <1,1> <2,1> <2,2>
<2,3,1> <2,3,2> <3,1> Is the declaration correct? No. Only the number of rows is fixed for a dimensioned array. The
no of columns cannot be specified
Practice 2 » Solution
Collect the details of the employee EMAIL ID using paragraph ADD.ANOTHER.EMAIL if the employee has one or more EMAIL
ID’s
Practice 3
DCOUNT Function explained with a syntax above in the slide.. The DCOUNT( ) function counts the number of field elements
in a string that are separated by a specified delimiter.
Practice 3 » Solution
Usage of DCOUNT Function is shown with a simple example
Practice 4
Modify the program written in Practice 2 to make Use of the DCOUNT function to count the number of phone numbers,
email ids entered.
Practice 4 » Solution
Add the paragraph named COUNT.PHONE and COUNT.EMAIL to the existing practice 2 program as seen above with the
DCOUNT function to count the Number of Phone Numbers and Email ID’s held by the employee..
Practice 5
Description of FIELD Function and it’s syntax
Practice 5 » Solution
Usage of FIELD function is shown with a simple example ..
Practice 6
Modify the program written in Practice 2 to make Use of the FIELD function to display each email/phone number on a
separate line
Practice 6 » Solution
Add the paragraph named DISPLAY.PHONES and COUNT.EMAILS to the existing practice 2 program as seen above to display
the Number of Phones and Email ID’s Held by the Employee..
Practice 7
Practice 7 » Solution
Input have been gathered once the choice entered by the user is 1
Practice 7 » Solution
Output is displayed once all the inputs have been entered . Please notice the Phone Numbers and Email ID’s are shown in
separate line because of usage of FIELD function ..
TUT
Lesson Summary
In this lesson, I am going to describe UTF Methods, Testcase, Stubs, and Assertions.
SIMPLE.CALCULATOR API
This is a subroutine to do simple arithmetic. Take a minute to understand the parameters of the sub-routine. Read the
comments to understand the API.
SIMPLE.CALCULATOR API
Understand the DO.basic.checks paragraph. ETEXT is a common variable defined in I_common that contains the error
message. Store.end.error is the API used to display the error. If the Operator or Operand is invalid, an error message is
assigned to ETEXT, and an error is raised.
SIMPLE.CALCULATOR API
In the DO.calculation paragraph, if the operator is plus, the answer is calculated and assigned to the result. If any other
operator is specified, another subroutine is called to do the calculation.
TESTCASE
A test case is a .tut file. The .tut is a JBC file that starts with the keyword testcase (and not subroutine, program, or function).
Anything that can be done in a jBase file can also be done in the .tut. The Testcase automatically adds a low-level reference
to the "UTF" component in the code. The UTF component is a low-level component sitting in the runtime. The UTF component
does not exist on the disk. The dollar use is not required in the test case for the UTF component. We can consider it as a
language extension.
TESTCASE » Steps
The steps to create a test case are as follows: We must first define the target. The subroutine or function being tested. Define
the parameters for the target routine. Once the parameters are specified and the context is defined, the test can be run. The
target routine is executed. As a final step, we do the assertions to check if the target routine has created or updated the
required records or set the variables with expected values.
TESTCASE » Assertion
Every test case must have an assertion to check if the test is successful. Based on the assigned parameters, the
simple.calculator is expected to set the return value as 6. this is checked using the assert statement. If the values are equal,
the test case is successful, or else the test case fails.
Stubs
The scope of the unit test is to test the target API and not any calls made from there. We must create Stubs for the APIs called
from the target routine. The stub is created with UTF.add Stub. Stubs are never called.
Stubs
We will get an error No stub found for number.division when we run a division test. The simple.calculator calls the API
number.division. The test case is to test the simple.calculator and not any calls made from that subroutine. Hence, we must
define a STUB for the number.division API that is called for a division.
Stubs
Use the UTF.add the Stub method to create a reference for a stub. Stubs are not called or executed; hence we must use the
UTF.add Stub Param to set the parameter for the stub. The First parameter is the stub reference obtained from add Stub().
Second is the IN parameter, and Third is the value of the IN parameter after the call. The framework will match the stub based
on the value of the parameters.
Stubs
Stub for number.division is added, and now the test case is successful.
Lesson Summary
In this lesson, I described UTF Methods, Testcase, Stubs, and Assertions.
Practice
Practice 1
Create test cases for the SIMPLE.CALCULATOR to test below: Test Invalid Operator Test Invalid Operand 1 Test Invalid
Operand 2 Test "+" invocation Test "-" invocation Test "*" invocation Test "/" invocation
Practice 1 » Solution
Create a test case with Seven Paragraph for seven tests from runtest1 to runtest7 as seen in Design studio
Practice 1 » Solution
Test for Invalid operator Runtest1 paragraph is used to test invalid operator. When the SIMPLE.CALCULATOR receives an
invalid operator, the DO.BASIC.CHECKS paragraph sets the error in ETEXT common variable, and this is used in the assertion.
Note – if the I_COMMON is not inserted in the TESTCASE, ETEXT will be a local variable and the assertion will fail. Also, you
can see Runtest1 is used to raise or propagate the error stored in ETEXT variable and compare it in assertions .Hence we
have to define a stub for the STORE.END.ERROR as this is used to propagate the error. If we don’t declare stub, then it will
throw the error as : [ERROR] No stub found for 'STORE.END.ERROR’
Practice 1 » Solution
Test for Invalid Operand1 This is similar to runtest1. This Runtest2 checks for Invalid Operand 1
Practice 1 » Solution
Test for Invalid Operand2 This is similar to runtest1. This Runtest3 checks for Invalid Operand 2
Practice 1 » Solution
Test “+” Invocation Runtest4 checks for Plus(+) operator to add two numbers. SIMPLE.CALCULATOR does the calculation by
itself and hence the test case does not define a STUB.
Practice 1 » Solution
Test “-” Invocation Runtest5 is used to test the minus operator. SIMPLE.CALCULATOR calls NUMER.SUBTRACTION hence we
have to define a stub for the same. In the assertion we check if stub is called when the operation is to subtract two numbers.
Practice 1 » Solution
Test “*” Invocation Runtest6 is used to test the multiply operator. SIMPLE.CALCULATOR calls NUMER.MULTIPLICATION hence
we have to define a stub for the same. In the assertion we check if stub is called when the operation is to multiply two
numbers. We also use getNbInvocation method of UTF object to see if the stub is invoked at least once.
Practice 1 » Solution
Test “/” Invocation Runtest7 is used to test the division operator. SIMPLE.CALCULATOR calls NUMER.DIVISION hence we have
to define a stub for the same. In the assertion we check if stub is called when the operation is to multiply two numbers. We
also use getNbInvocation method of UTF object to see if the stub is invoked at least once. Here we have testing the division
operator assuming that both the numerator and denominator will be valid numeric value other than zero. We recommend
to perform a test if the denominator is zero and see how it works . Please do perform a test for dividing a number by zero
and see how it works to get the full taste of testing the Division operator either by storing the “EB-DIVISON BY ZERO” as a
return value from the NUMBER.DIVISION routine or store the value in a local error variable in the test and see how it works.
Practice 1 » Solution
This information for declaring Shared details and shared stub Is specified here if we are not intended to define a stub for
each and every tests instead will prefer to create a common stub to be accessed by all test for STORE.END.ERROR in case if
required then we must define a stub for STORE.END.ERROR in setSharedStub section which can be shared by all test if
required. All the tests' cases and their alternatives are not shown. Just we are giving some basic sample tests .
Transact Caching
Before discussing Transact APIs, it is important to understand Caching in the Transact. Caching is retaining frequently
accessed information in memory so that expensive I or O can be reduced. The caching is done in the Transact by using
Common Variables in jBC.
Transact APIs
Standardize logic to perform operations that are done across applications. Encapsulate the database layer and the Transact
framework logic from the application. Make the code more efficient by caching relevant information.
Lesson Summary
In this lesson, I described Transact Caching, and Transact APIs.
Practice
Practice 1
Steps: Open the file customer Read the specific customer record Retrieve the required data Display the data. After writing
the subroutine, create an entry in PGM.FILE for this subroutine as main line routine and execute it from Transact.
Practice 1 » Solution
Practice 1 Solution 1. Write a routine named CUSTOMER.READ in Design Studio and save and compile the file.
Practice 1 » Solution
Practice 1 » Solution
Practice 1 SOLUTION Create a PGM.FILE entry in transact for the routine CUSTOMER.READ as seen above WITH Type as “M”
and Product as “EB” and commit the record.
Practice 1 » Solution
Practice 1 SOLUTION Create a Run configuration in Design Studio by clicking on Run Menu -> Run Configurations… and the
in the window that is opened fill the following properties : NAME : Classic (Any Meaningful Name can be given) Program : EX
(this is the Transact Classic Application and its name cannot be changed. Should be configured as such) Check on Eclipse
Console . Click on Run which will launch Classic Please see the screen grab above for configurations and do it as such.
Practice 1 » Solution
Practice 1 » Solution
Practice 2
Hint : Read data from Concat file CUSTOMER.ACCOUNT. Process each account separately using DCOUNT and FIELD function
In this case , below three Application needs to be opened and read. - CUSTOMER (To Validate the customer ID entered) -
CUSTOMER.ACCOUNT ( To view the List of Accounts held by the particular Customer) - ACCOUNT(To Display each and every
Account details held by a customer) Then we have to use DCOUNT function to fetch the number of accounts held by a
particular customer and display it separately using FIELD function.
Practice 2 » Solution
Practice 2 SOLUTION 1. Write a routine named READ.CUSTOMER.ACCOUNT in Design Studio and save and compile the file.
Practice 2 » Solution
Practice 2 SOLUTION 1. Write a routine named READ.CUSTOMER.ACCOUNT in Design Studio and save and compile the file.
Practice 2 » Solution
Practice 2 SOLUTION 1. Write a routine named READ.CUSTOMER.ACCOUNT in Design Studio and save and compile the file.
Practice 2 » Solution
Practice 2 » Solution
Practice 2 SOLUTION 1. Write a routine named READ.CUSTOMER.ACCOUNT in Design Studio and save and compile the file.
Practice 2 » Solution
Practice 2 SOLUTION 1. Write a routine named READ.CUSTOMER.ACCOUNT in Design Studio and save and compile the file.
Practice 2 » Solution
Practice 2 SOLUTION Create a PGM.FILE entry in transact for the routine READ.CUSTOMER.ACCOUNT as seen above.
Practice 2 » Solution
Practice 2 SOLUTION Create a PGM.FILE entry in transact for the routine READ.CUSTOMER.ACCOUNT as seen above WITH
Type as “M” and Product as “EB” and commit the record.
Practice 2 » Solution
Practice 2 SOLUTION Create a Run configuration in Design Studio by clicking on Run Menu -> Run Configurations… and the
in the window that is opened fill the following properties : NAME : Classic (Any Meaningful Name can be given) Program : EX
(this is the Transact Classic Application, and its name cannot be changed. Should be configured as such) Check on Eclipse
Console . Click on Run which will launch Classic Please see the screen grab above for configurations and do it as such.
Practice 2 » Solution
Practice 2 SOLUTION Once you run the Run configuration in Design Studio Transact Classic is launched as seen above.
Practice 2 » Solution
Practice 2 SOLUTION In the Transact Classic is launched type in the Credentials Username and Password to login to transact.
Then key in the Routine name which you have created (in this case(READ.CUSTOMER.ACCOUNT) in the Awaiting Application
Prompt as seen above and also provide the input. Once the input is done for any Customer ID, you can see the output too
seen on the right-hand screen which has the name of the application as READ.CUSTOMER.ACCOUNT and the output of EACH
ACCOUNT HELD BY THE CUSTOMER IS SEEN.