The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Lab Instruction
Lab:RPG IV Intermediate
Lab Overview-- Scenario / Summary:
Exercises are cumulative. One exercise may build an object you need in a later exercise. Do not skip sections.
There are three exercises in this lab activity that cover more advanced RPG IV syntax.
Exercise 1: Basic Array Handling
What this exercise is about
The objective of this exercise is to introduce basic array handling.
What you should be able to do
At the end of the exercise you should be able to
Exercise 2: More on Arrays
What this exercise is about
The objective of this exercise is to introduce qualified data structures and more advanced array handling.
What you should be able to do
At the end of the exercise you should be able to
Exercise 3: Subroutines
What this exercise is about
The objective of this exercise is to introduce you to subroutines and some of the basics of modular design.
What you should be able to do
At the end of the exercise you should be able to code and execute a subroutine.
Deliverables:
|
Part A: Exercise 1 - Basic Array Handling |
|
Part B: Exercise 2 - More on Arrays |
|
Part C: Exercise 3 – Subroutines |
Lab Steps:
|
Part A: |
|
Exercise 1-- Basic Array Handling Exercise instructions - Lab 1 Create a new source member named MOD20101. Enter a D spec to define a standalone run time array containing four elements, each element being a five-digit integer. Give the array any name you wish. Enter a D spec to define a standalone field named i as a five-digit integer. Enter a D spec to define a standalone field named total as a 10-digit integer. Code an expression to set each element of the array to a value of 10. Code a FOR loop to display the value of each element. The text displayed should be similar to "The value for element 1 is 10.” You will need to use a BIF to convert the numeric fields to character. Code a FOR loop to set the value of each element of the array to the value of the index + 10. Code an expression to accumulate the values of each element in the array to the field total. Code a FOR loop to display the value of each element. Display the value of the field total. The text displayed should be similar to "The total of all elements is 50.” Set the *INLR indicator. Save and compile the program. Correct any compile errors. In the 5250 emulation session, call the program MOD20101. The information displayed should be similar to the following: DSPLY The value of element 1 is 10 DSPLY The value of element 2 is 10 DSPLY The value of element 3 is 10 DSPLY The value of element 4 is 10 DSPLY The value of element 1 is 11 DSPLY The value of element 2 is 12 DSPLY The value of element 3 is 13 DSPLY The value of element 4 is 14 DSPLY The total of all elements is 50 Modify the program so that the array now contains five elements and each loop processes all five elements. How many lines of code did you have to change? The answer should be one. If you had to change more than 1 line of code, you may not have been not controlling your FOR loops using the most efficient technique. Hint: Check for BIFs relating to arrays. Exercise instructions - Lab 2Create a new source member named MOD20102. Enter a D Spec to define a standalone compile time array called MonthNames. The array contains 12 elements, each element being a nine-character field. There should be six entries per record. Enter a D spec to define a standalone field named i as a five-digit integer. Code a FOR loop to display the value of each element of the MonthNames array. Set the *INLR indicator. Enter the compile time data for the MonthNames array. Save and compile the program. Correct any compile errors. In the 5250 emulation session, call the program MOD20102. The information displayed should be similar to the following: DSPLY January DSPLY February DSPLY March DSPLY April DSPLY May DSPLY June DSPLY July DSPLY August DSPLY September DSPLY October DSPLY November DSPLY December Exercise instructions - Lab 3Create a new source member named MOD20103. This time, you will accomplish a task similar to that in the previous exercise on compile time arrays, but this time you are to use the preferred technique of creating a run time array and supplying values to the array using the Overlay keyword in a Data Structure. Detailed instructions follow on how to do this. Code a D spec for a Data Structure called Days. Enter seven subfields at the beginning of the Data Structure, each initialized to the value of the name of a day of the week, beginning with Monday. Note that field names are not necessary for these subfields since we won't be referring to them in the program. They are used simply to supply values to the array elements. Enter a D Spec to define a standalone run time array called DayNames. The array contains seven elements, each element being a nine-character field. The array should get its values for the seven elements by overlaying the Days data structure. Enter a D spec to define a standalone field named DayNo as a five-digit integer. Code a DOU loop that will loop until the value of DayNo is 99. Within the loop, use the DSPLY operation to enter a value for DayNo (make sure you specify that a value of 99 ends the program) and If the value entered is not 99, display the appropriate element in the DayNames array that corresponds to the value of DayNo. For example, if the user enters “3,” the array element containing the value of Wednesday should be displayed. Set the *INLR indicator. Save and compile the program. Correct any compile errors. In the 5250 emulation session, call the program MOD20103. Test the program by entering valid day numbers (1 through 7) and end the program by entering a value of 99. Call the program again. What happens if you enter a value of 0? What happens if you enter a value greater than 7? This completes the exercise. |
|
Part B: |
|
Exercise 2--More on Arrays Exercise instructions Create a new source member named MOD20201. Define a data structure with a subfield in the first 10 characters initialized to the value “FEDABC”. Define an array named Array1 containing 10 one-character elements. The array should also occupy the first 10 characters of the data structure (i.e., the same space as the initialized subfield defined above.) Note that since you have initialized only the first six characters of the data structure, the last four elements of Arr1 contain blanks. Define a second array named Array2 containing 10 one-character elements. The array should also occupy the first 10 characters of the data structure (i.e., it will contain the same data as Array1) and have a keyword that specifies the array should be sorted in descending sequence. You should now have a 10-character data structure where the 10 character are initialized to a value that is overlaid by two arrays, one of which may be sorted in descending sequence. Define a standalone integer field to contain the index of the array element that matches on the later locate operations. Code a Dsply statement to display the static text "Original Data." Code a FOR loop to display each element of Array1 (which, by definition will also be the same data as in Array2.) Code the appropriate SORTA operation code to sort only the first six (i.e., the non-blank) element values of the two arrays into ascending order. Hint: This will involve the use of a BIF in addition to the SORTA operation. Code a Dsply statement to display the static text "Sort Ascending". Code another FOR loop to display each element of Array1 (which, by definition will also be the same data as in Array2.) Code the appropriate SORTA operation code to sort only the first six (i.e., the non-blank) element values of the two arrays in descending order. Code a Dsply statement to display the static text "Sort Descending". Code another FOR loop to display each element of Array1 (which, by definition will also be the same data as in Array2.) Code a SORTA operation code to sort all the elements in the two arrays into descending sequence. Use the appropriate BIF to locate which element of Array1 contains the character C, and then display the element number. Set the *INLR indicator. Save and compile the program. Correct any compile errors. In the 5250 emulation session, call the program MOD20201. The information displayed should be similar to the following: DSPLY Original Data DSPLY F DSPLY E DSPLY D DSPLY A DSPLY B DSPLY C DSPLY DSPLY DSPLY DSPLY DSPLY Sort Ascending DSPLY A DSPLY B DSPLY C DSPLY D DSPLY E DSPLY F DSPLY DSPLY DSPLY DSPLY DSPLY Sort Descending DSPLY F DSPLY E DSPLY D DSPLY C DSPLY B DSPLY A DSPLY DSPLY DSPLY DSPLY DSPLY C Found in position 4
Something to think about: What type of search (i.e., binary or sequential) was done when you looked for a value of C? How do you know? This completes the exercise. |
|
Part C: |
|
Exercise 3-- Subroutines Exercise Instructions-- Lab 1
You are going to restructure the program from Exercise 2 to reduce the redundant code. Copy the source member MOD20201 to a new source member named MOD20301. Create a subroutine to contain the code the FOR loop that currently exists in this program three times. Copy one of the FOR loops to the subroutine. Replace each iteration of the FOR loop in the main part of the program with an operation to execute the subroutine. Save and compile the program. Correct any compile errors. In the 5250 emulation session, call the program MOD20301. Compare your results to ensure you get the same results as you did when you tested MOD20201. This completes the exercise. |
|
END OF LAB |
-----------