Rpg free basics l.jpg
Advertisement
This presentation is the property of its rightful owner.
1 / 27

RPG free basics PowerPoint PPT Presentation

RPG free basics Session 1 “C” Spec structure change Fixed Format Structure Factor 1OPCODEFactor 2Result Num1AddNum2Num3 EvalNum3=Num1+Num2 Free Format Structure OPCODEResult Factor 1Factor2 Num3 = Num1+Num2; Implied Opcodes Eval – Evaluate Data (left align)

Download Presentation

RPG free basics

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Rpg free basics l.jpg

RPG free basics

Session 1


C spec structure change l.jpg

“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 1


Implied opcodes l.jpg

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 1


Opcodes replaced with bifs l.jpg

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 1


Opcodes replaced with bifs5 l.jpg

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 1


Opcodes replaced with bifs6 l.jpg

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 1


Opcodes replaced with bifs7 l.jpg

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 1


Opcodes replaced with bifs8 l.jpg

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 1


Opcodes replaced with bifs9 l.jpg

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

RPG free Session 1


Slide10 l.jpg

RPG free Session 1


Slide11 l.jpg

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 1


Slide12 l.jpg

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 1


Slide13 l.jpg

RPG free Session 1


Slide14 l.jpg

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 1


Slide15 l.jpg

RPG free Session 1


Slide16 l.jpg

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 1


Slide17 l.jpg

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 1


Slide18 l.jpg

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 1


Slide19 l.jpg

“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 1


Slide20 l.jpg

RPG free Session 1


Slide21 l.jpg

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 1


Slide22 l.jpg

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 1


Slide23 l.jpg

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 1


Slide24 l.jpg

RPG free Session 1


Slide25 l.jpg

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 1


Slide26 l.jpg

RPG free Session 1


Slide27 l.jpg

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.

RPG free Session 1


  • Login