RPG free basics Session 1. RPG free Session 12 “C” Spec structure change Fixed Format Structure Factor 1OPCODEFactor 2Result Num1AddNum2Num3 EvalNum3=Num1+Num2.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

RPG IV V5R1 Enhancements Presented by Barry Diehl.
C Functions. What are they? In general, functions are blocks of code that perform a number of pre-defined commands to accomplish something productive.
Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
Chapter 7: User-Defined Functions II Instructor: Mohammad Mojaddam.
AU/MITM/1.6 By Mohammed A. Saleh 1. Arguments passed by reference  Until now, in all the functions we have seen, the arguments passed to the functions.
Coding Free Format RPG IV 1:1 Copyright Jim Martin April 2010 SEMIUG & MMUG Coding Free Format RPG IV: Jim Martin Author of Free Format RPG.
Inline Assembly Section 1: Recitation 7. In the early days of computing, most programs were written in assembly code. –Unmanageable because No type checking,
Advanced Package Concepts. 2 home back first prev next last What Will I Learn? Write packages that use the overloading feature Write packages that use.
Chapter 6. 2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single Value Pass by Reference Variable Scope.
 2003 Prentice Hall, Inc. All rights reserved. 1 Functions Modules: functions and classes Programs use new and “prepackaged” modules –New: programmer-defined.
Guide To UNIX Using Linux Third Edition
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
1 Functions Modules: functions and classes Programs use new and “prepackaged” modules –New: programmer-defined functions, classes –Prepackaged: from the.
11 Chapter 5 METHODS. 22 INTRODUCTION TO METHODS A method is a named block of statements that performs a specific task. Other languages use the terms.
CMPE-013/L: “C” Programming Gabriel Hugh Elkaim – Spring 2012 CMPE-013/L Functions Gabriel Hugh Elkaim Spring 2012.
Computer Science 1000 Spreadsheets II Permission to redistribute these slides is strictly prohibited without permission.
1 Using Classes Object-Oriented Programming Using C++ Second Edition 5.
C++ for Engineers and Scientists Third Edition
Operator Precedence First the contents of all parentheses are evaluated beginning with the innermost set of parenthesis. Second all multiplications, divisions,
Chapter 6: Modularity Using Functions. In this chapter, you will learn about: – Function and parameter declarations – Returning a single value – Returning.
CNG 140 C Programming (Lecture set 9) Spring Chapter 9 Character Strings.
PHP meets MySQL.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Classes: A Deeper Look Part.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
8-1 Embedded Systems Fixed-Point Math and Other Optimizations.
Learners Support Publications Classes and Objects.
CS 330 Programming Languages 10 / 07 / 2008 Instructor: Michael Eckmann.
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
Section 4 - Functions. All of the programs that we have studied so far have consisted of a single function, main(). However, having more than one function.
Rpg-ILE Maximum Speed by Robert Arce from PrismaTech. RPG-ILE Maximum Speed New Development Approach Presented by: Robert Arce.
Welcome to RPG544. Bit about Cindy Administrative Stuff Standards Due Dates Web Page.
Built-In and user-Defined functions Software Design Concepts Lecture IV Dr. Sothy Vignarajah.
COMPUTER PROGRAMMING. Functions’ review What is a function? A function is a group of statements that is executed when it is called from some point of.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Python Functions.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
C Functions Three major differences between C and Java functions: –Functions are stand-alone entities, not part of objects they can be defined in a file.
Chapter 9 Classes: A Deeper Look, Part I Part II.
Functions: Part 2 of /11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park 1.
V6R1 – RPG enhancements THREAD(*CONCURRENT) Ability to define a main procedure which does not use the RPG cycle Files defined in subprocedures Qualified.
1 MORE ON MODULAR DESIGN: MODULE COMMUNICATIONS. 2 WHEN A FUNCTION IS INVOKED, MEMORY IS ALLOCATED LOCALLY FOR THE FORMAL PARAMETERS AND THE VALUE OF.
Methods Awesomeness!!!. Methods Methods give a name to a section of code Methods give a name to a section of code Methods have a number of important uses.
Creating FunctionstMyn1 Creating Functions Function can be divided into two groups: –Internal (built in) functions –User-defined functions.
Array Size Arrays use static allocation of space. That is, when the array is created, we must specify the size of the array, e.g., int[] grades = new int[100];
Be “GUI ready” developing in RPG by Robert Arce from PrismaTech. Be “GUI ready” developing in RPG-ILE Presented by: Robert Arce.
Functions Chapter 5. Function A set of instructions that are designed to perform specific task. A complete and independent program. It is executed by.
Functions Skill Area 314 Part B. Lecture Overview Functions Function Prototypes Function Definitions Local Variables Global Variables Default Parameters.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
 2000 Prentice Hall, Inc. All rights reserved Program Components in C++ Function definitions –Only written once –These statements are hidden from.
Tarik Booker CS 242. What we will cover…  Functions  Function Syntax  Local Variables  Global Variables  The Scope of Variables  Making Functions.
C++ Programming Lecture 13 Functions – Part V By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Gator Engineering Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 9 Functions.
Chapter 9: Value-Returning Functions
Week 3-4 Control flow (review) Function definition Program Structures
User-Written Functions
FUNCTIONS In C++.
Chapter 6: Functions Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
MACRO Processors CSCI/CMPE 3334 David Egle.
April 2010 SEMIUG & MMUG Coding Free Format RPG IV:
Chapter 4 void Functions
Packages and Interfaces
Functions, Part 2 of 3 Topics Functions That Return a Value
Classes and Objects.
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Java Programming Language
Functions, Part 2 of 3 Topics Functions That Return a Value
Procedures.
Functions, Part 2 of 3 Topics Functions That Return a Value
Presentation transcript:

RPG free basics Session 1

RPG free Session 12 “C” Spec structure change Fixed Format Structure Factor 1OPCODEFactor 2Result Num1AddNum2Num3 EvalNum3=Num1+Num2 Free Format Structure OPCODEResult Factor 1Factor2 Num3 = Num1+Num2;

RPG free Session 13 Implied Opcodes Eval – Evaluate Data (left align) CallP – Call Procedure (internal or external) Note: You do NOT have to omit the opcodes but it is a better accepted practice in free-format. For EVALR you must explicitly include the opcode.

RPG free Session 14 Opcodes replaced with BIFs ADD replaced with “+” sign SUB replaced with “-” sign DIV replaced with %DIV() MVR replaced with %REM() MOVE replaced with EVAL MOVEL replaced with EVALR or BIFs MOVEA not allowed (use workarounds)

RPG free Session 15 Opcodes replaced with BIFs ALLOC – Replaced with %ALLOC() CALL – replaced with CALLP CALLB – Replaced with CALLP CASxx – Replaced with IF & EXSR CAT – Replaced with “+” sign CHECK – Replaced with %CHECK() CHECKR – Replaced with %CHECKR() COMP – Replaced with “=“, “ ”,etc.

RPG free Session 16 Opcodes replaced with BIFs DEFINE – Replaced by D spec keyword DTAARA DO – Replaced by For loops END – not allowed ENDCS – not allowed EXTRCT – Replaced by %SUBDT() KFLD – not allowed KLIST – not allowed

RPG free Session 17 Opcodes replaced with BIFs LOOKUP – Replaced with %LOOKUP() MULT – Replaced with “*” sign OCCUR – Replaced with %OCCUR() PARM – Replaced with D spec PR PLIST – Replaced with D spec PR REALLOC – Replaced with %REALLOC() SCAN – Replaced with %SCAN() SETOFF – not allowed

RPG free Session 18 Opcodes replaced with BIFs SETON – not allowed SHTDN – Replaced with %SHTDN() SQRT – Replaced with %SQRT() TIME – Replaced with %DATE(), %TIME(),%TIMESTAMP() ADDDUR – Replaced with “+” %YEARS(),%MONTHS(),%DAYS() SUBDUR – Replaced with %DIFF()

RPG free Session 19 Opcodes replaced with BIFs SUBST – Replaced with %SUBST() XFOOT – Replaced with %XFOOT() XLATE – Replaced with %XLATE() Z-ADD – Use Eval Z-SUB – Use Eval Full listing is available at

RPG free Session 110

RPG free Session 111 D Specs are identical to what is done in fixed format. Parameter Entry can still be done using PLIST but must be in fixed format outside of the /free & /end- free tags

RPG free Session 112 This is the body of the code. This is a very simple utility that basically receives a data string that is 500 bytes long & the actual field length that contains the data. The program then centers the data & returns the data to the calling program.

RPG free Session 113

RPG free Session 114 Key lists can still be defined but must be done in fixed format. These key lists can be used in your free format code.

RPG free Session 115

RPG free Session 116 Prototype & Prototype Interfaces replace the PLIST/PARM functionality for free format. Above is an example of a “MAIN” prototype. The EXTPGM keyword in this case is the program itself. The definitions below the PR statement do not have to have “field names” and are NOT usable as fields. Above is the corresponding prototype interface. This is the actual *ENTRY portion of the functionality. The “field names” are required on the PI statements & can be used in your program.

RPG free Session 117 Above is an example of an internal procedure. A procedure is basically similar in functionality as a subroutine but has more features & functionality than subroutines offer. Notice that on the PR statement a return variable of type n is defined (indicator). In order to use this prototype the result field must be specified on the procedure call as shown below. ItsWfc is defined as a standalone indicator. In the procedure the Return statement will return either *ON or *OFF, depending on the code.

RPG free Session 118 Above is the internal procedure we defined. The “P” spec is fixed format & there must be a “B” & “E” record at the beginning & the end of the subprocedure. Note that the Return statements have *ON or *OFF.

RPG free Session 119 “Position” is a standalone integer field. Each section of this code performs a %SCAN() for a search string & the position where the string is found is loaded into the “Position” field. “Position” is a GLOBAL variable and can be used in any subprocedure defined in the program & is used in the FileCheck() subprocedure.

RPG free Session 120

RPG free Session 121 Now let’s look at some internal procedures that pass parameters. Specifically, we’ll look at the GetZuluDate subprocedure. Since this subprocedure does not return a value, the invocation does not require a return variable as we saw earlier. The structure for the CALLP is the same as in the fixed format version, we could specify CALLP or leave it as above implied. All parameters are separated by the “:”. Notice that we are passing the field “ZDATE” to the subprocedure. If ZDATE did not match the prototype definition, this would not compile which is one benefit of using prototypes versus PLIST.

RPG free Session 122 This is the subprocedure GetZuluDate. Notice that an additional field has been defined inside this subprocedure. This is a LOCAL variable. If you use try to use this variable outside this subprocedure, the program will not compile due to variable not defined error. This variable can only be used in this subprocedure which is another benefit to using subprocedures instead of subroutines. With a subroutine any field used inside of it can be altered by the subroutine, intentionally or not. With local variables you can ensure that your calling procedure’s data doesn’t get altered unintentionally.

RPG free Session 123 Now let’s look at the code in the subprocedure. The TrnDate is a global variable which is used to initialize the local variable WrkDate. TrnDateC is also a globally defined variable & is a character representation of the TrnDate field. TimeStampWrk is a global timestamp variable which is used to convert the partial timestamp (TrnTimeStamp) stored in Kronos to a full timestamp for processing. ZDate is then calculated using the %DIFF BIF which is then passed back to the main procedure.

RPG free Session 124

RPG free Session 125 Better alternative to using KLISTs in free format is using in-line key values as shown above. To use an in-line key list you must be on V5R3M0 or better. The structure is the same as for parameters. The in-line key list is enclosed in parentheses & the fields are separated by a “:”. This allows more flexibility with your key values as well as having to duplicate KLISTs multiple times to use different key fields.

RPG free Session 126

RPG free Session 127 Calling other programs from free format is done via prototype definitions as shown above. A good rule of thumb for utility programs, etc. is to place the prototype source in a copybook. This way you ensure that the prototype is correct in all calling programs by using /COPY or /INCLUDE. The prototype for calling external procedures (or programs) makes use of the EXTPGM keyword on the PR record. After the PR record comes the parameter list for the program being called. Using prototypes in this manner ensures that your calls to the program contain the correct structure & order of the parameters at compile time preventing possible errors. Notice the keyword CONST on the parameters for the UpdateSecrtry Procedure. What this does is pass your parameters to the called program & will not alter the values upon return from the called program. In a nutshell it makes the parameter input only.