Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "RPG free basics Session 1. RPG free Session 12 “C” Spec structure change Fixed Format Structure Factor 1OPCODEFactor 2Result Num1AddNum2Num3 EvalNum3=Num1+Num2."— Presentation transcript:

1 RPG free basics Session 1

2 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;

3 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.

4 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)

5 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.

6 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

7 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

8 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()

9 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 http://therpgsource.com http://therpgsource.com

10 RPG free Session 110

11 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

12 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.

13 RPG free Session 113

14 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.

15 RPG free Session 115

16 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.

17 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.

18 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.

19 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.

20 RPG free Session 120

21 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.

22 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.

23 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.

24 RPG free Session 124

25 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.

26 RPG free Session 126

27 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.


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

Similar presentations


Ads by Google