rpg programming language_wipro_v2.pdf

Upload: anurag-nawal

Post on 14-Apr-2018

269 views

Category:

Documents


6 download

TRANSCRIPT

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    1/134

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    2/134

    INTRODUCTION RPG is an abbreviation for Report Program Generator. It is a high level

    language in which the programmer codes the specifications.

    Developed by IBM in 1960s.

    RPG code is written on a variety of specification forms, each with a specific setof functions.

    Many of the entries which make up a specification type are position-dependent.

    Each entry must start in a specific position depending on the type of entry andthe type of specification.

    There are seven types of specifications.

    Each specification type is optional.

    Specifications must be entered into your source program in the order HFELICO.

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    3/134

    FEATURES OF RPG Structured language

    RPG provides structured programming constructs (Opcodes, Subroutines,Subprograms) that helps us in approaching a modular program design.

    Strong at file operationThe data records can be accessed in any direction, sequentially or randomly

    with out need to open and close the files.

    Strong interactive programming languageRPG in combination with Screen Design Aid (SDA) forms a powerful

    interactive programming language. The screens designed through SDA can be easilyaccessed from an RPG program.

    Sub filesThis is excellent feature of RPG. Sub files are special kind of screen files

    using which we can display multiple records onto a screen with minimal programmingeffect.

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    4/134

    Generation of Complex Reports:RPG in combination with RLU (Report Layout Utility) helps us in generating

    formatted and complex reports.

    Interface with CL language :We can establish data communication among a CL language and an RPG

    program.

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    5/134

    Naming Conventions & Data Types

    Naming Conventions First character of all variable names must be A to Z (or a to z), @, # or $.

    Subsequent characters A to Z (or a to z), @, # or $, 0 to 9, or theunderscore (_) character

    Not case sensitive If @, # or $ is used as the first character of a variable name, at least one

    other character must be specified

    No embedded blanks or periods allowed All names are global to all areas of program A file / recrd format name must be 1 to 10 characters in length A file name cannot be the same as record format name

    Data Types

    Character (A or blank) Float (F), Packed (P), Integer (I) Date (D), Time (T), Timestamp (Z)

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    6/134

    Indicators

    An indicatoris a logical variable that is either set ON (1) or OFF (0).

    They are generally used to indicate the result of an operation, indicate errorcondition, indicate file operation status or to condition (control) the processing of anoperation.

    They determine the path the program will take during processing depending on

    how they are set or used.

    Indicators can be defined as variables

    Indicators can be set ON or OFF using Opcodes SETON and SETOFF or usingMOVE statements

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    7/134

    Indicators are of 2 types

    General indicators and special indicators

    General Indicators are 0 99.

    Special Indicators:

    1. Halt indicators H1 H9. These are used to signal severe error. When Halt

    indicator is set on, program ends abnormally. 2. External indicators U1 to U8. Passed from out side RPG program. Used to

    condition opening of a file or to control calculations

    3. First Page 1P - Used in logic cycle program to print Report Header

    4. Matching Indicator MR - Used in logic cycle program to process matchingrecords of Primary and Secondary files

    5. Level Break L0 L9 ( used in logic cycle), LR Last record 6. Return Indicator RT used as return function

    7. Overflow indicator OA to OG, OV used for printer files

    8. Command keys (or) Function keys KA to KN, KP to KY command level

    keys F1 to F24

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    8/134

    Constants and Literal Values

    Named constants are defined with data type N using I Spec Figurative constants: Special, built-in names that have predefined values

    associated with them. Names begin with an asterisk (*)

    *BLANKS*ZEROS*LOVAL*HIVAL*OFF*ON

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    9/134

    Reserved Fields

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    10/134

    Compiler Directives

    Directs compiler to perform certain operations such as printing compiler listing,inclusion of source members. Begin in position 7 of RPG statement

    /COPY : Compiler includes source code from other source member

    /TITLE : Prints specified text on top of each page of compiler listing

    /SPACE : Causes blank lines to be printed on compiler listing

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    11/134

    Reserved Words

    Reserved words are special names with predefined purpose

    *DATE : Used to retrieve program run date.Format is determined by the system value. Format may beoverridden by an entry in column 19 of H spec.

    *DAY : Used to retrieve the session day*MONTH : Used to retrieve the session month*YEAR : Used to retrieve the session year

    *ENTRY : Used with PLIST to define the entry parameter list*INZSR : Used with BEGSR to define the Initialization subroutine*LIKE : Used with DEFN to define a field like another field*LOCK : Used with IN, OUT to perform read/write to data area with lock*DTAARA : Used with DEFN, IN, OUT to define and perform read/write

    operations on data area*PSSR : Used with BEGSR to define the Program status subroutine

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    12/134

    RPG/400 SPECIFICATIONS

    RPG source statements consists of 80-character card images having line numbersin the first few columns of each source statements.

    Every line having a form type in column 6 (H, F, E, L, I, C, O).

    Any statement with an asterisk (*) in column 7 is a comment.

    Specification types:

    1. Control specifications (H spec) provide the compiler with information aboutgenerating and running programs, such as the program name, date format, anduse of alternate collating sequence or file translation.

    2. File description specifications (F Spec) describe all the files that the program uses.

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    13/134

    3. Extension specifications (E Spec) contains the array definitions

    4. Line Counter Specifications (L spec) describe the length of the form and thenumber of lines to print on a page for a program described Printer file

    5. Input Specifications (I spec) describe the structure of program described files,data structure and subfield definitions and named constant definitions

    5. Calculation specifications (C spec) describe the calculations done on the dataand the order of the calculations. Calculation specifications also control certaininput and output operations.

    6. Output specifications (O Spec) describe the output records and fields used bythe program.

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    14/134

    Sample RPG Program - Demo

    Creating a new RPG source member using PDM

    Entering source statements using SEU

    Compilation and resolving compilation errors

    Executing RPG program from command line

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    15/134

    CONTROL SPECIFICATION

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    16/134

    Control Specifications - H Spec

    Identified by H in column 6

    Provides information about generating and running programs

    Only one control specification is allowed per program

    Data area named RPGHSPEC can be created to contain the information to beused for all RPG/400 programs that do not contain a control specification

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    17/134

    CRTDTAARA DTAARA(QGPL/RPGHSPEC)+

    TYPE(*CHAR) +LEN(26) +

    VALUE(DATFMT(*YMD/) TIMFMT(*HMS)) +

    TEXT(Default RPG H-SPEC)

    OR

    CRTDTAARA DTAARA(QPRG/DFTHSPEC)+

    TYPE(*CHAR) +

    LEN(26) +

    VALUE(DATFMT(*YMD/) TIMFMT(*HMS)) +

    TEXT(Default RPG H-SPEC)

    OR

    Use H specification in RPG

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    18/134

    File Specifications

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    19/134

    File Description Specification

    Position Description

    6 F

    7-80 non-commentary part

    742 fixed-format entries

    4480

    81100 Comments

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    20/134

    Columns Description

    6 Form type (F)

    7 14 File Name

    15 File Type (Mode in which file is being used in the program)

    I Input file, O Output file, U Update File, C Combined

    16 File Designation (F Full Procedural, P Primary, S Secondery)

    17 End Of File

    18 Sequence

    19 File Format (E externally described file, F Program described file)

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    21/134

    Columns Description

    20 File addition

    Blank Do not add records

    A Allow record Adds

    21 Match field sequence

    Blank or A Ascending

    D Descending

    22 File Format:

    E Externally Described

    F Program Described

    23-27 Record Length

    28 Limits processing :

    Blank : Sequential or random processing

    L Limits processing

    29-33 Length of key or record address

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    22/134

    Columns Description

    34 Record Address type

    Blank Non keyed processingA - Character keys

    D - Date Keys

    G - Graphic keys

    K - Externally described key

    P - Packed key

    T - Time Keys

    Z - Time Stamp Keys

    35 File Organization

    B Non Keyed , Program described

    I - indexed

    T Record address

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    23/134

    Columns Description

    36-42 DeviceDisk - Disk file

    Printer - Printer File

    SEQ - Sequentially Organized

    SPECIAL - Special device

    WORKSTN - Workstation file

    43 (reserved)

    44-80 File Keywords

    81-100 Comments

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    24/134

    FILE READ

    0001.00 FEMPMASTER IF E K DISK

    0002.00 FDSPLYFILE CF E WORKSTN

    0002.01 C READ EMPRECFMT 10

    0005.00 C DOW *IN10=*OFF

    0006.00 C EXFMT READING

    0007.00 C READ EMPRECFMT 10

    0008.00 C ENDDO

    0009.00 C SETON LR

    File File End of File

    Filename Type Designation File Addition Sequence

    EMPMASTER I F

    File Limits Record

    Format Processing Address Type Device

    E K DISK

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    25/134

    Calculation Specifications

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    26/134

    C-SPEC

    In this specification, we code variable declarations and the executable statements.

    It primarily consists of essentially a Operation code (verb) and three operandsknown as FACTOR-1, FACTOR-2 and RESULT

    Operation codes entered on the calculation specifications indicate the kind ofoperation to be performed

    For example, for reading a record, READ operation code will be used.

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    27/134

    LayoutColumns Description

    1-5 Sequence number

    6 C

    7-8 Control Level : Blank,L0,L1-L9,LR,SR,AN,OR

    9-11 Indicators : Blank,01-99,KA-KN,KP-KY,L1-L9,LR,MR,H!-H9,RT,U1-U8,OA-OG,OV

    12-25 Factor 1

    26-35 Operation code

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    28/134

    Columns Description

    36-49 Factor 2 or Extended factor 2

    50-63 Result Field

    64-68 Result Field Length

    69-70 Result Field Decimal Positions

    71-76 Resulting Indicators (High/Low/Equal)

    77-80 (Blank)

    81-100 Comments

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    29/134

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    30/134

    1. Arithmetic operations

    ADD

    SUB

    MULT

    DIV

    MVR

    SQRT

    Z-ADD

    Z-SUB

    2. Variable Definition and Move operations

    MOVE

    MOVEL

    DEFN

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    31/134

    3. Date/time operations

    TIME (Time of Day)

    4. Structured programming operations

    IFxx (If)

    SELEC (Begin a Select Group)

    WHxx (When True Then Select)

    DO (Do)ENDDO

    DOUxx (Do Until)ENDDO

    DOWxx (Do While)ENDDO

    ITER (Iterate)

    LEAVE (Leave a Do Group)

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    32/134

    5. Branching operations

    TAG (Tag)

    GOTO (Go To)

    CABxx (Compare and Branch)

    6. Call operations

    BEGSR (Beginning of Subroutine)

    ENDSR (End of Subroutine)

    EXSR (execute Subroutine)

    CASxx (Compare And branch to Subroutine)

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    33/134

    CALL (Call a Program)

    PARM (Identify Parameters)

    PLIST (Identify a Parameter List)

    7. File operations

    OPEN (Open File for Processing)

    CLOSE (Close Files)

    READ (Read a Record)

    WRITE (Create New Records)

    READC (Read Next Changed Record)

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    34/134

    READE (Read Equal Key)

    READP (Read Prior Record)

    REDPE (Read Prior Equal)

    SETGT (Set Greater Than)

    SETLL (Set Lower Limit)

    KFLD (Define Parts of a Key)

    KLIST (Define a Composite Key)

    CHAIN (Random Retrieval from a File)

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    35/134

    UPDAT (Modify Existing Record)

    DELET (Delete Record)

    COMIT (Commit)

    ROLBK (Roll Back)

    UNLCK (Unlock a Data Area or Release a Record)

    8. Data area operations

    IN (Retrieve a Data Area)

    OUT (Write a Data Area)

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    36/134

    9. Array operations

    MOVEA (Move Array)

    XFOOT (Summing the Elements of an Array)

    LOKUP (Look Up a Table or Array Element)

    SORTA (Sort an Array)

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    37/134

    10. String operations

    SCAN (Scan String)

    CHECK (Check Characters)

    SUBST (Sub string)

    XLATE (Translate)

    CAT (Concatenate Two Strings)

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    38/134

    ARITHMATIC OPERATIONS

    ADD

    The add verb is used to find the sum of numeric values.it has two formats:

    Format1:

    CODE Factor 1 Factor 2 Result Field INDICATORS

    ADD NUM1 NUM2 RNUM HI LO EQ

    This statement is equivalent to saying RNUM=NUM1+NUM2

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    39/134

    Format : 2

    CODE Factor 1 Factor 2 Result Field INDICATORS

    ADD NUM2 RNUM HI LO EQ

    If factor1 is blank,factor2 is added to result and sum placed in result field.

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    40/134

    SUB

    The SUB verb is with numeric values for subtract operation.

    MULT

    The MULT verb is used to find the product of two numbers.

    DIV

    The DIV verb is used for division operation with numeric values.

    MVR

    The MVR operation moves the remainder from the previous DIV operation to a

    separate field named in the result field.

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    41/134

    SQRT

    The SQRT operation derives the square root of the field named in the resultfield.

    Z-ADD

    The Z-ADD stands for zero add. Zero is added to the factor 2 and the sum isplaced in the result. This is basically used to declare, initialize or move a valueinto the numeric filed.

    Z-SUB

    The Z-SUB stands for zero subtract. Factor 2 is subtracted from zero and thedifference is placed in the result. This is basically used to negate the value of avariable.

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    42/134

    Program for Arithmetic operation

    C MOVE 9 A 2 0

    C MOVE 7 B 2 0

    C MOVE *ZEROS C 3 0

    C MOVE *ZEROS D 2 0

    ** A = A + B

    C* ADD B A

    C* A DSPLY**

    C A ADD B C

    C C DSPLY

    **

    C A SUB B C

    C C DSPLY

    **

    C A MULT B C

    C C DSPLY

    **

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    43/134

    C A DIV B C

    C MVR DC C DSPLY

    C D DSPLY

    C SQRT A C

    C C DSPLY

    **

    C Z-ADD 2 E 2 0C E DSPLY

    **

    C Z-SUB 2 F 2 0

    C F DSPLY

    C SETON LR

    O/P

    DSPLY 16 ,DSPLY 2 ,DSPLY 63 ,DSPLY 1 ,DSPLY 2 ,DSPLY 3

    DSPLY 2 ,DSPLY 2-

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    44/134

    Move operations

    MOVE

    MOVE is used to move data into a field. The value specified in factor1 will bemoved into the filed specified in result field. Used to convert numeric data tocharacter and vice versa

    MOVEL

    MOVEL (move left) is similar to MOVE with the only difference that the factor 2will be moved in to but is left justified.

    DEFN

    Define a field based on the attributes (data type,length and decimal positions)of another field.

    Define field as a data area.

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    45/134

    Program for move operation0001.00 C MOVE 2345678 NUM1 5 0

    0002.00 C NUM1 DSPLY

    0002.01 **

    0002.02 C MOVEL 1234637 NUM1 5 0

    0002.03 C NUM1 DSPLY

    0002.04 **

    0004.03 C MOVEL 'ABCDE' RES 3

    0004.04 C RES DSPLY

    0004.05 **

    0004.06 C MOVE 'ABCDE' RES 3

    0004.07 C RES DSPLY

    0004.08 C SETON LR

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    46/134

    O/p

    DSPLY 45678

    DSPLY 12346DSPLY ABC

    DSPLY CDE

    Structured programming operations

    IFxx

    IF operation is used for conditional execution of statements. Each IF has acorresponding ENDIF or END statement.

    The statements placed between the IF and ENDIF will be executed only when

    the condition satisfied The condition may also be a compound condition supplemented by ANDxx or

    ORxx

    ELSE state can also be coded between IF and ENDIF so that if the condition isnot satisfied then the statements between ELSE and ENDIF can be executed.

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    47/134

    NOTE:

    XX Denotes a relational operator which could any one of the following

    EQ Equal to

    NE Not equal to

    GT Greater than

    LT Less than

    GE Greater than or equal to

    LE Less than or equal to

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    48/134

    Example 1

    Calculation of Bonus AND PERKS if basic greater than or equalto 3000

    0002.00 C Z-ADD3000 BASIC 400003.00 C BASIC IFGE 30000004.00 C Z-ADD4000 BONUS 400005.00 C Z-ADD3000 PERKS 40

    0005.02 C BONUS DSPLY0005.03 C PERKS DSPLY0005.04 C ENDIF0007.00 C SETON LR

    o/p

    DSPLY 4000DSPLY 3000

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    49/134

    Example :2

    A clerk with salary more than 2500 or a manager will get a

    bonus of 4000 and perks of 3000. Otherwise bonus would be

    2000 and perks would be 12000000.02 C MOVEL 'CLERK' DESIGN 70000.03 C MOVEL 'MANAGER' DESIGN 70000.04 C Z-ADD 2500 BASIC 4 00001.00 C DESIGN IFEQ 'CLERK'

    0001.01 C BASIC ANDGT 25000001.02 C DESIGN OREQ 'MANAGER'0001.03 C Z-ADD 4000 BONUS 4 00001.04 C Z-ADD 3000 PERKS 4 00001.07 C ELSE0002.00 C Z-ADD 2000 BONUS 4 0

    0002.01 C Z-ADD 1200 PERKS 4 00005.01 C ENDIF

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    50/134

    0005.04 C BONUS DSPLY

    0005.05 C PERKS DSPLY

    0006.00 C SETON LRO/p

    DSPLY 4000

    DSPLY 3000

    NOTE:

    Only change manager to manager1 you get an output as 2000,1200

    SELEC : when we have multiple nested IFs the code becomes complex and we will

    have to take care of matching the IFs with their corresponding ENDIFs.

    SELECENDSL can be used as an alternative in such a case.

    Here we have multiple WHXX statements between SELEC and ENDSL. Ifany of the WHXX condition is satisfied then the statements under it will beexecuted. If none of the condition satisfy then the statements underOTHER will be executed.

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    51/134

    SYNTAX: FACTOR1 OPCODE FACTOR2

    SELEC

    WHXX

    ------

    OTHER

    ------

    ENDSL

    DO ..ENDDO :A DO statement can be used to repeat the code enclosed between DO and ENDDO,a specific number of times.

    Example:

    DISPLAY ALL ODD NUMBERSS BETWEEN 1 TO 100002.00 C 1 DO 10 NUM 5 0

    0003.00 C NUM DSPLY

    0004.00 C ENDDO 2

    0005.00 C SETON LR

    O/P

    1,3,5,7,9

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    52/134

    DOUXX ..ENDDO :

    DOUXX (do until loop) this loop will be executed at least once irrespective of whether

    the condition is satisfied initially or not because, here the condition is post-tested .

    Example:

    INITIALIZATION AND INCREMENTATION HAS TO BE EXPLICITLYDONE

    0001.00 C Z-ADD 1 NUM 5 0

    0002.00 C NUM DOUGT 10

    0003.00 C NUM DSPLY

    0004.00 C ADD 2 NUM

    0005.00 C ENDDO0006.00 C SETON LR

    O/P

    1,3,5,7,9

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    53/134

    DOWXX ..ENDDO :

    DOWXX (do while loop) is similar to DOU loop except that the loop continues

    execution as long as the condition is true and terminates once it becomes false. Alsothe condition is per-tested.

    Example:

    DISPLAY ALL ODD NUMBERSS BETWEEN 1 TO 10

    0002.00 C Z-ADD 1 BASIC 2 0

    0002.01 C BASIC DOWLE 10

    0002.02 C BASIC DSPLY

    0002.03 C ADD 2 BASIC

    0002.04 C ENDDO0003.00 C SETON LR

    O/P

    1,3,5,7,9

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    54/134

    LEAVE :LEAVE statement can only be given inside a loop. It abruptly terminates the loop

    execution and transfers the control to the next statement after ENDDO.

    ITER :ITER statement can only be given inside any of the loop. It is used to transfer the

    control to the beginning of the loop to continue execution.

    Example:DISPLAY ALL ODD NUMBERSS EXCEPT 5 ,BETWEEN 1 TO 10

    0001.00 C Z-ADD 1 NUM 5 0

    0002.00 C NUM DOWLE 10

    0003.00 C NUM IFEQ 5

    0004.00 C ADD 2 NUM

    0005.00 C ITER

    0005.01 C* LEAVE

    0006.00 C ENDIF

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    55/134

    0007.00 C NUM DSPLY

    0008.00 C ADD 2 NUM

    0009.00 C ENDDO0010.00 C SETON LR

    O/P

    1

    3

    7

    9

    NOTE:

    In the above example if leave is coded in place of ITER the loop executionterminates once the value of num is equal to 5.hence only 1 and 3 will get displayed.

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    56/134

    Branching operations

    TAG & GOTO

    TAG is used in accordance with GOTO in a program. Using GOTO we cantransfer the control from one place to another with in a routine.

    The place where the control needs to be transferred should be labeled (named)using a TAG statement.

    NOTE:

    While using TAG only factor1 is coded which contains the label name.

    GOTO statement is coded with the name of the label in factor 2.

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    57/134

    Example:

    DISPLAY NUMBERS FROM 10 TO 1

    0002.00 C Z-ADD10 NUM 500002.01 C CBSI TAG

    0003.00 C NUM DSPLY

    0004.00 C SUB 1 NUM

    0005.00 C NUM IFGE 1

    0006.00 C GOTO CBSI0006.01 C* NUM CABGE1 CBSI

    0007.00 C ENDIF

    0008.00 C SETON LR

    O/P

    10,9,8,7,6,5,4,3,2,1

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    58/134

    CABXX :CABXX(COMPARE AND BRANCH) command is simply a combination of IF & GOTO

    statement.Example:

    DISPLAY NUMBERS FROM 10 TO 1

    0002.00 C Z-ADD10 NUM 50

    0002.01 C CBSI TAG

    0003.00 C NUM DSPLY

    0004.00 C SUB 1 NUM

    0006.01 C NUM CABGE1 CBSI

    0008.00 C SETON LR

    O/P

    10,9,8,7,6,5,4,3,2,1

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    59/134

    Date/Time operations

    The time operation accesses the system time of day

    Result : Must be of either a 6,12 or 14 digit numeric field (no decimalpositions)

    If six-digit numeric field :Time of the day only

    If 12-digit numeric field :Time of the day and system date with outcentury.

    If 14-digit numeric field: Time of the day and system date with outcentury.

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    60/134

    Example:

    DISPLAY SYSTEM DATE/TIME

    0000.01 C Z-ADD0 NUM1 120

    0001.00 C TIME NUM1

    0002.00 C NUM1 DSPLY

    0003.00 C SETON LR

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    61/134

    Call operations

    BEGSRENDSR

    BEGSRENDSR Is used to code a subroutine with in a program. BEGSR is

    required at the beginning of every subroutine. The name of the subroutine ismentioned in factor 1 of BEGSR.

    EXSR

    EXSR is used to call a subroutine and after the execution of the subroutinecontrol returns back to the next statement after EXSR. The name of thesubroutine is given in factor 2 position.

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    62/134

    Example:

    THE MESSAGES WILL BE DISPLAYED IN THE SEQUENCE

    BEFORE,INSIDE,AFTER0001.00 C 'BEFORE' DSPLY

    0002.00 C EXSR DSPSR

    0003.00 C 'AFTER' DSPLY

    0004.00 C* RETURN0004.01 C SETON LR

    0005.00 C DSPSR BEGSR

    0006.00 C 'INSIDE' DSPLY

    0007.00 C ENDSR

    O/p

    DSPLY BEFORE ,DSPLY INSIDE,DSPLY AFTER

    NOTE: If the name of the subroutine is changed to *INZSR then, the sequence of themessages would be INSIDE,BEFORE,INSIDE,AFTER.

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    63/134

    CODE Factor 1 Factor 2 Result Field INDICATORS

    CASxx Compared Compared Subroutine

    name

    HI LO EQ

    CASXX . END

    This helps us in conditional execution of subroutine. Factor-1 and factor-2 are compared and if the condition satisfied the subroutine

    named in the result field is executed.

    Example:

    HERE ADDSR,SUBSR,MULSRDIVSR WILL BE EXECUTED IF OPT

    CONTAINS A.S,M,OR D RESPECTIVELY.0001.00 FDSPSELECT CF E WORKSTN

    0002.00 C *IN03 DOWEQ *OFF

    0003.00 C EXFMT OPCODE

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    64/134

    0005.00 C OPT CASEQ 'A' ADDSR

    0006.00 C OPT CASEQ 'S' SUBSR

    0007.00 C OPT CASEQ 'M' MULSR

    0008.00 C OPT CASEQ 'D' DIVSR

    0009.00 C ENDCS

    0010.00 C ENDDO

    0011.00 C SETON LR0012.00 C* RETURN

    0013.00 C ADDSR BEGSR

    0014.00 C NUM1 ADD NUM2 RESULT

    0015.00 C ENDSR

    0017.00 C SUBSR BEGSR

    0018.00 C NUM1 SUB NUM2 RESULT

    0019.00 C ENDSR

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    65/134

    0020.00 C MULSR BEGSR

    0021.00 C NUM1 MULT NUM2 RESULT

    0022.00 C ENDSR0022.01 C DIVSR BEGSR

    0022.02 C NUM1 DIV NUM2 RESULT

    0022.03 C ENDSR

    DSPSELECT_CASXX

    0000.40 A R OPCODE

    0000.50 A*%%TS SD 20050802 125252 QSECOFR REL-V4R4M0 5769-PW1

    0000.60 A CA03(03)

    0000.70 A 12 34'B ='0000.80 A 10 34'A ='

    0000.90 A 14 34'OPT ='

    0001.00 A 16 34'C ='

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    66/134

    0001.10 A NUM1 3S 0B 10 50

    0001.20 A NUM2 3S 0B 12 50

    0001.30 A RESULT 5S 0O 16 50

    0001.40 A OPT 1A I 14 50

    CALL :

    CODE Factor 1 Factor 2 ResultField

    INDICATORS

    CALL Called

    program name

    HI LO EQ

    CALL is used to execute another RPG program from inside an RPG program. Theprogram in which had the CALL statement is referred as the parent or a callingprogram and the program being called is termed as child or called program.

    CALLED program has to be compiled before compiling a calling program. Becausewhile compiling the calling program it looks for a compiled object of the calledprogram and if it is not found an error occurs .

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    67/134

    Example:

    CALLING PROGRAM(THIS PROGRAM CALLSUB PROGRAM WHICH FINDS THE

    SUM OF FIRST 100 NATURAL NUMBERS.

    0002.00 C 'BEFORE' DSPLY

    0003.00 C CALL 'CALLSUB'

    0004.00 C 'AFTER' DSPLY

    0005.00 C RETRN

    CALLSUB (Called program)0000.01 C 1 DO 100 NUM

    0000.02 C ADD NUM SUM

    0000.04 C ENDDO

    0000.05 C SUM DSPLY

    0000.06 C RETRN

    0000.07 C *INZSR BEGSR

    0001.01 C Z-ADD0 SUM 80

    0002.00 C Z-ADD0 NUM 30

    0003.00 C ENDSR

    O/p DSPLY BEFORE, DSPLY 5050,DSPLY AFTER

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    68/134

    PLIST & PARM

    When parameters are passed into called program, it should be capable enough toreceive the same. For that reason we code PLIST statement at the top of thecalled program.

    *ENTRY Should appear in factor1 of PLIST command followed by PARMs.

    Example:*ENTRY PLIST

    PARM A

    PARM BPARM C

    POINTS TO NOTE:

    1.The number of parameters passed and receiving should be the same.

    2.Their attributes (data type and size) should preferably the same.

    3.the order of parameters should be the same.

    4.can have different names or same names in called and calling programs.

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    69/134

    Example: PLISTPP_NM

    PROGRAM FOR CALCULATION OF SIMPLE INTEREST

    0001.00 FDSPARR CF E WORKSTN

    0001.01 C LIST1 PLIST

    0002.01 C PARM P 5 0

    0002.02 C PARM R 4 0

    0002.03 C PARM T 2 0

    0002.04 C PARM SI 7 0

    0003.00 C PARM A 8 0

    0004.00 C EXFMT INTEREST

    0004.01 C CALL 'PLISTSUB' LIST10004.02 C EXFMT INTEREST

    0005.00 C SETON LR

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    70/134

    PLISTSUB_NM(SUBPROGRAM)

    0001.00 C *ENTRY PLIST

    0002.00 C PARM P1 5 0

    0003.01 C PARM R1 4 0

    0003.02 C PARM T1 2 0

    0003.03 C PARM SI1 7 0

    0004.00 C PARM A1 8 0

    0004.01 C P1 MULT R1 SI1

    0005.00 C T1 MULT SI1 SI1

    0006.00 C DIV 100 SI10007.00 C SI1 ADD P1 A1

    0008.00 C RETURN

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    71/134

    DSPARR_DSPLAYFILE

    0004.20 A R INTEREST

    0004.40 A 5 27'SIMPLE INTEREST CALCULATION

    0004.70 A 6 27'==========================

    0004.90 A 9 10'ENTER PRINICIPLE :'

    0005.10 A 11 10'ENTER RATE :'

    0005.30 A 13 10'ENTER TIME :'0005.50 A 15 10'SIMPLE INTEREST IS :'

    0005.70 A 17 10'AMOUNT IS :'

    0005.90 A 20 41'PRESS ENTER TO CONTINUE'

    0006.30 A P 5S 0B 9 33

    0006.40 A R 4S 0B 11 33

    0006.50 A T 2S 0B 13 33

    0006.60 A SI 7S 0O 15 33

    0006.70 A A 8S 0O 17 33

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    72/134

    File operations

    READ : The READ operation reads the record from a file.WRITE : The WRITE operation writes a new record into the file.

    READE :The READE operation retrieves the next sequence record from a file.

    READP : READP (read prior) operation reads the prior record from a file.

    READPD :The READPF operation is just a combination of READE and READP.

    READC : The READC operation can be used only with an externally describedworkstation file to obtain the next changed record in a sub file.

    SETGT & SETLL : SETGT & SETLL only positions the record pointer and doesnot read the records.

    UPDAT : The UPDAT operation is modify the records of an update disk file.(U in file type i.e., position 15 of F-Spec).

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    73/134

    PROGRAM FOR FILE READ

    FILEREAD_RPG0001.00 FEMPMASTER IF E K DISK

    0002.00 FDSPLYFILE CF E WORKSTN

    0002.01 C READ EMPRECFMT 10

    0005.00 C DOW *IN10=*OFF

    0006.00 C EXFMT READING

    0007.00 C READ EMPRECFMT 100008.00 C ENDDO

    0009.00 C SETON LR

    EMPMASTER_PF

    0001.00 A R EMPRECFMT0002.00 A EMPNUMBER 5

    0003.00 A EMPNAME 10

    0004.00 A EMPSALARY 10 2

    0005.00 A K EMPNUMBER

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    74/134

    DSPLYFILE_DISPLAY FILE0001.60 A R READING

    0001.90 A CA03(03)0002.00 A 5 33'KARISHMA S/W LTD'

    0002.10 A DSPATR(UL)

    0002.20 A DSPATR(HI)

    0002.30 A 8 38'EMPNO:'

    0002.40 A 10 37'EMPNAME:'

    0002.50 A 12 32' '

    0002.60 A 12 29' '

    0002.70 A 12 27' '

    0002.80 A EMPNUMBER R B 8 46REFFLD(EMPRECFMT/EMPNUMBER

    0002.90 A MINDADB/EMPMASTER)

    0003.00 A EMPNAME R B 10 46REFFLD(EMPRECFMT/EMPNAME0003.10 A MINDADB/EMPMASTER)

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    75/134

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    76/134

    IntroductionData structures allow to define an area of space within memory to store

    individual elements of data.

    Purpose: Subdividing fields into subfields

    Restructure records into different layouts

    Change field data types

    Define character fields longer than 256 bytes To add second dimension to arrays

    Data structures can also be defined externally.

    TYPES: Simple Data Structure

    External data structure Data Area Data structure

    File information data structure

    Program status data structure

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    77/134

    Simple Data Structure

    To define data structure specify DS in 24-25.

    Follow the definition with sub field definitions.

    From to positions indicate the sub fields positions on IPD prompt.

    Examples: DISPLAY SYSTEM DATE AND TIME & YEAR

    0001.00 DDATE1 DS

    0002.00 DDD 1 2

    0003.00 DMM 3 4

    0004.00 DYYYY 5 8

    0005.00 C MOVEL UDATE DATE1

    0005.01 C DD DSPLY0005.02 C MM DSPLY

    0005.03 C YYYY DSPLY

    0006.00 C DATE1 DSPLY

    0007.00 C SETON LR

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    78/134

    External data structure

    READ DATA FROM A DATA BASE FILE USING EXTERNAL DS.

    External Data structures

    FFLTFILE IF F 112 DISK

    FEMPPF UF A E DISK

    DEMPFILE E DS EXTNAME(EMPPF)

    DID 1 6

    DNAME 7 17

    DSTATUS 18 19

    C *LOVAL SETLL FLTFILE

    C READ FLTFILE 90

    C DOW *IN90 = *OFF

    C EVAL EMPFILE = FLTFILE

    C

    C WRITE EREC 90

    C ENDDO

    C SETON LR

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    79/134

    File information data structure

    FMaintCust CF E Workstn INFDS(DSDisplay)

    DSDisplay DS

    D FileName *File

    DFileOpen 9 9

    DFileeof 10 10

    DMsgId 46 52

    DSCRSize *SIZE

    DKeyPress 369 369

    DCursorloc 370 371B 0

    INFDS keyword is specified in the F-spec against the file declaration.

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    80/134

    File Information Data Structure:*FILE File Name

    *RECORDExternal file RECORD FORMAT

    Program file RecordID

    *OPCODE

    *STATUS Error Code

    *ROUTINE Name of the routine where error occurred.

    File Status codes00000 - No Error

    00013 - Sub file Full

    01021 - Duplicate Key Not allowed

    01041 - Array/Table Sequence error

    01211 - I/O operation to closed file

    01215 - OPEN issued to file already open01218 - Unable to allocate Record

    01221 - Update without prior read

    01241 - Record number not found

    01331 - Wait time exceeded for read from work station file.

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    81/134

    Program Status Data structureDS.PSSR_DS

    0002.00 IDS1 SDS

    0003.01 I *STATUS ERR

    0003.04 C Z-ADD100 NUM1 30

    0029.00 C Z-ADD0 NUM2 30

    0029.01 C NUM1 DIV NUM2 NUM3 300029.02 C RETRN

    0029.03 C *PSSR BEGSR

    0033.00 C ERR IFEQ 102

    0033.01 C 'ZERO DIV'DSPLY

    0033.02 C ENDIF

    0033.03 C* MOVE 'CANCLE' RET 6

    0045.04 C ENDSR

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    82/134

    O/P

    DSPLY ZERO DIV

    DS.PSSR 2901 tried to divide by zero (factor 2)

    Program Status codes

    00121- Invalid array index

    00202 Called program failed

    00211- Called program not found

    00231 Called program Halt indicator On

    00333- Error on DSPLY operation

    00414- Not authorized to use data area

    00415 Not authorized to update data area

    00431- Data area previously locked00907- Decimal data error

    09999 System program exception error

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    83/134

    Program for Data Areas

    AUTOMATIC GENARATION OF VEHICAL REGISTRATION NUMBER

    0001.00 FDSPARR CF E WORKSTN

    0001.02 E LETTER 1 26 1

    0002.00 IDS1 UDS

    0002.01 I 1 2 STATE

    0003.01 I 3 40AREA

    0003.02 I 5 5 ALPHA

    0003.03 I 6 90SRLNO

    0007.00 C *NAMVAR DEFN AREA0 9

    0008.00 C *IN03 DOWEQ*OFF

    0009.00 C *LOCK IN AREA0

    0010.00 C MOVE AREA0 DS1

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    84/134

    0011.00 C SRLNO IFEQ 9999

    0012.00 C ALPHA IFEQ 'Z'

    0013.00 C EXSR ADARA

    0014.00 C ELSE

    0015.00 C EXSR ADALPA

    0016.00 C ENDIF

    0017.00 C ELSE0018.00 C EXSR ADSLNO

    0019.00 C ENDIF

    0020.00 C MOVE DS1 FLD001

    0021.00 C EXFMTVEHREG

    0022.00 C EXSR UPDSR

    0023.00 C ENDDO

    0024.00 C SETON LR

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    85/134

    0025.00 C* ERRRTN BEGSR

    0025.01 C* RETRN

    0026.00 C ADARA BEGSR

    0027.00 C ADD 1 AREA

    0028.00 C MOVE 'A' ALPHA

    0029.00 C Z-ADD1 SRLNO

    0030.00 C ENDSR0031.00 C ADALPA BEGSR

    0032.00 C 1 DO 26 I 20

    0033.00 C ALPHA IFEQ LETTER,I

    0034.00 C LEAVE

    0035.00 C ENDIF

    0036.00 C ENDDO

    0037.00 C ADD 1 I

    0038.00 C MOVE LETTER,I ALPHA

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    86/134

    0040.00 C Z-ADD1 SRLNO

    0041.00 C ENDSR

    0043.00 C ADSLNO BEGSR

    0044.00 C ADD 1 SRLNO

    0045.00 C ENDSR

    0045.01 C UPDSR BEGSR

    0045.02 C MOVE DS1 AREA0

    0045.03 C *LOCK OUT AREA0

    0045.04 C ENDSR V

    0046.00 **

    0047.00 A

    0048.00 B ------------z

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    87/134

    Display Data Area

    Data area . . . . . . . : AREA0

    Library . . . . . . . : MINDADB

    Type . . . . . . . . . : *CHAR

    Length . . . . . . . . : 9

    Value 'AP01A0001'

    DSPARR_DISPALYFILE0002.40 A R VEHREG

    0002.50 A*%%TS SD 20050801 182655 QSECOFR REL-V4R4M0 5769-PW1

    0002.60 A CA03(03)

    0002.70 A 8 15'AUTOMATIC GENERATION OF VE

    0002.80 A GISTRATION NUMBER'

    0003.50 A 13 20'NEW VEHICAL REGISTRATON NUM:

    0003.90 A FLD001 12A O 13 60

    0004.00 A 18 56'F3 = EXIT'

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    88/134

    Structure of PSDS16-20 Previous status code

    21-28 RPG Source sequence number40-46 Exception Error ID MCH or CPF

    201-208 Name of the file last used

    244-253 Job Name

    254-263 User name

    264-269 Job Number

    276-281 --System Date in Udate Format

    288-293 Date Compiled

    304-333 Source file/library/member

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    89/134

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    90/134

    Subfiles

    1. A subfile is a series of similar records that can be displayed simultaneously on the

    screen.

    2. When you load data to a subfile data remains in main memory until subfile iswritten on to the screen.

    3.When subfile is written on to the screen data is passed on to the workstationcontroller.

    4. Controller assumes responsibility for handling subfile data on screen until control isreturned to the program.

    5. A subfile can hold a maximum of 9999 records.

    6. At a time 24 subfiles can be active.

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    91/134

    Components of a subfile

    Two record formats are requiredSFL - Subfile record format and

    SFLCTL - Subfile Control Record format.

    The Subfile Record format holds the actual data and is similar to the database file.

    The Subfile Control Record format Describes the headings for the fields andcontrols the subfile size, Display, Number of records and specifies how data isretrieved and what is to be done on data in the subfile on various events.

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    92/134

    SUBFILE TYPES

    Load All Subfile

    Expanded Load

    Single Page Load

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    93/134

    Load All Subfile All records are loaded at once.

    Maximum 9999 records can be loaded.

    Applicable for files with fewer number of records.

    ROLLUP and ROLLDOWN operations are automatically handled by theprogram.

    Control returns to the program once the user moves past the last record in thesubfile.

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    94/134

    Expanded load

    Loads enough records to fill first screen.

    Rollup key impression brings control to the program.

    First screen records stay in the subfile and new records are appended each timerollup is pressed.

    Roll down automatically handled by subfile.

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    95/134

    Page at a time subfile

    Stores only page worth of records.

    Program handles both rollup and roll down keys.

    Subfile is cleared and new page of records are loaded on each key impression afterclearing the subfile.

    Rollup/page down load next set of records.

    Roll down/page up previous set of records are loaded .

    Subfile preferred for database having large set of records works without impactingperformance.

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    96/134

    Key WordsSFLCTL

    Defines Subfile control record format

    Links subfile record format with Subfile format

    One subfile format maps to one and only one subfile control format and

    vice versa

    SFLSIZ

    Specifies size of the subfile. No of records that subfile can hold.Can be

    hard coded or passed as a hidden field ,S type, 0 Decimals and 5 digits long.

    SFLPAG

    Specifies number of records that appear on a single screen and must be less

    than or equal to SFLSIZ

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    97/134

    SFLDSPCTL and SFLCTL

    Normally conditioned with indicators to display control format or the subfile. Empty subfile- (SFLCTL) cannot be displayed so indicator is seton when subfile is filled

    or required to be displayed.

    Having indicator for SFLDSPCTL is optional.

    SFLCLR

    Normally SFLCLR will have the negative conditioning indicator that is given for SFLCTLand SFLDSPCTL.

    When indicator is set on it will clear the records in the subfile.

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    98/134

    Program for Load all sub file0001.00 FEXPPF IF E DISK

    0002.00 FLOADDSP CF E WORKSTN

    0003.00 F SFILE(DATA1 : RRN)

    0004.00 DRRN S 4 0

    0005.03 ** CLEAR SFL

    0005.05 C SETON 1020400007.00 C WRITE HEADING1

    0007.01 C SETOFF 40

    0008.01 C Z-ADD 1 RRN 4 0

    0008.02 ** LOADING DATA

    0008.03 C READ PFREC03 90

    0009.00 C DOW *IN90=*OFF

    0009.01 C WRITE DATA1

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    99/134

    0011.00 C ADD 1 RRN

    0013.00 C READ PFREC03 90

    0013.01 C ENDDO

    0014.01 ** DSPLY SFL

    0014.02 C DOW *IN03=*OFF

    0014.03 C SETON 10200014.04 C WRITE FOOTING

    0016.00 C EXFMT HEADING1

    0017.00 C SETOFF 1020

    0017.01 C ENDDO

    0017.02 **

    0018.00 C SETON LR

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    100/134

    EXPPF_LOADALL

    0000.01 UNIQUE

    0001.00 A R PFREC03

    0002.00 A PFEMNO 7 COLHDG('EMPLOYEE NUMBER')

    0003.00 A PFEMNA 25 COLHDG('EMPLOYEE NAME')

    0004.00 A PFADD1 10 COLHDG('ADDRESS1')

    0005.00 A PFADD2 10 COLHDG('ADDRESS2')

    0006.00 A K PFEMNO

    LOADDSP_DISPALYFILE

    0000.40 A R DATA1 SFL

    0000.60 A PFEMNO R O 13 17REFFLD(PFREC03/PFEMNO MINDADB

    0000.70 A PFEMNA R O 13 27REFFLD(PFREC03/PFEMNA MINDADB

    0000.80 A PFADD1 R O 13 53REFFLD(PFREC03/PFADD1 MINDADB

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    101/134

    0000.90 A R HEADING1 SFLCTL(DATA1)

    0001.10 A CA03(03)

    0001.20 A 10 SFLDSP

    0001.30 A 20 SFLDSPCTL

    0001.40 A 30 SFLINZ

    0001.50 A 40 SFLCLR0001.60 A 50 SFLEND(*MORE)

    0001.70 A SFLSIZ(0050)

    0001.80 A SFLPAG(0005)

    0001.90 A 6 36'EMPDETAILS'

    0003.10 A 11 19'NUMBER'

    0003.30 A 11 37'NAME'

    0003.50 A 11 54'ADDRESS1'

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    102/134

    Program for Expanded Load0001.00 FEXPPF IF E DISK

    0002.00 FEXPDSP CF E WORKSTN

    0003.00 F RRN KSFILE SFLREC

    0004.00 C *IN03 DOWEQ*OFF

    0004.02 C*SFL CLEAR

    0005.00 C SETON 40

    0006.00 C WRITESFLCTL

    0007.00 C SETOF 40

    0007.01 C*

    0007.02 C Z-ADD1 RRN 40

    0007.04 C STR TAG

    0007.05 C SETOF 20

    0007.06 C Z-ADD1 RRNCT 40

    0009.04 C**

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    103/134

    0009.05 C RRNCT DO 10

    0012.00 C READ EXPPF 33

    0013.00 C *IN33 IFEQ *ON

    0014.00 C MOVE *ON *IN50 END

    0015.00 C ELSE

    0016.00 C RRN IFLT 9999

    0017.00 C WRITESFLREC

    0017.01 C ADD 1 RRN

    0017.02 C ADD 1 RRNCT

    0017.03 C ENDIF

    0018.00 C ENDIF

    0020.00 C ENDDO

    0022.03 C SETON 20

    0023.00 C EXFMTSFLCTL

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    104/134

    0023.01 C* PAGE DOWN

    0024.00 C *IN35 IFEQ *ON

    0025.00 C GOTO STR

    0026.00 C ENDIF

    0026.01 C ENDDO

    0028.00 C SETON LR

    EXPDSP_DISPLAYFILE

    0000.40 A CF03(03)

    0000.50 A R SFLREC SFL

    0000.70 A PFEMNO R O 6 4REFFLD(PFREC03/PFEMNO MINDA

    0000.90 A PFEMNA R O 6 14REFFLD(PFREC03/PFEMNA MINDA

    0001.10 A PFADD1 R O 6 40REFFLD(PFREC03/PFADD1 MINDA

    0001.30 A PFADD2 R O 6 62REFFLD(PFREC03/PFADD2 MINDA

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    105/134

    0001.50 A R SFLCTL SFLCTL(SFLREC)

    0001.70 A ROLLUP(35)

    0001.80 A 20 SFLDSP

    0001.90 A 20 SFLDSPCTL

    0002.00 A 40 SFLCLR

    0002.10 A 50 SFLEND(*MORE)

    0002.20 A SFLSIZ(0011)

    0002.30 A SFLPAG(0010)

    0002.40 A 1 29'EXPANDING SUBFILE '

    0001.90 A 6 36'EMPDETAILS'

    0003.10 A 11 19'NUMBER'

    0003.30 A 11 37'NAME'

    0003.50 A 11 54'ADDRESS1'

    P f Si l l d

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    106/134

    Program for Single page load

    0001.00 FPAGEPF IF E DISK

    0002.00 FPAGEDSP CF E WORKSTN

    0003.00 F RRN KSFILE SFLREC

    0003.02 I* 10 C CRSIZE

    0003.03 C Z-ADD10 CRSIZE 40

    0003.04 C EXSR CLE

    0003.05 C EXSR LOA

    0003.06 C *IN03 DOWEQ*OFF

    0003.07 C SETON 10

    0003.08 C WRITEFOOT

    0003.09 C EXFMTSFLCTL

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    107/134

    0007.01 C* PAGE DOWN KEY PRESSED

    0007.02 C *IN22 IFEQ *ON

    0007.03 C EXSR PGD

    0007.04 C ENDIF

    0007.05 C* PAGE UP KEY PRESSED

    0007.07 C *IN23 IFEQ *ON0007.08 C EXSR PUP

    0007.09 C ENDIF

    0007.10 C ENDDO

    0007.11 C SETOF 10

    0007.12 C SETON LR

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    108/134

    0007.13 C* =====================PAGE DOWN==================

    0007.14 C PGD BEGSR

    0007.15 C LKEY SETGTPAGEPF

    0007.16 C READ PAGEPF 31

    0007.17 C *IN31 IFEQ *OFF

    0007.18 C LKEY SETGTPAGEPF

    0007.19 C EXSR CLE0007.20 C EXSR LOA

    0007.21 C ENDIF

    0007.22 C ENDSR

    0007.23 C* =====================PAGE UP=======================

    0007.24 C PUP BEGSR

    0007.25 C FKEY SETLLPAGEPF

    0007.26 C READ PAGEPF 31

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    109/134

    0007.27 C *IN31 IFEQ *OFF

    0007.28 C FKEY SETLLPAGEPF

    0007.29 C Z-ADDCRSIZE SRCNT 20

    0007.31 C DO CRSIZE

    0007.32 C READPPAGEPF 31

    0007.33 C MOVE PFEMNO FKEY

    0007.34 C *IN31 IFEQ *ON

    0007.35 C ENDIF

    0007.36 C ENDDO

    0007.37 C EXSR CLE

    0007.38 C FKEY SETLLPAGEPF

    0007.40 C EXSR LOA

    0007.41 C ENDIF

    0007.42 C ENDSR

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    110/134

    0008.00 C* ===================LOADING DATA===========

    0009.00 C LOA BEGSR

    0009.01 C Z-ADD1 RRN 40

    0009.02 C SETOF 10

    0009.03 C READ PAGEPF 31

    0009.05 C *IN31 IFEQ *OFF

    0009.06 C MOVE PFEMNO FKEY 700009.07 C ENDIF

    0009.10 C RRN DOWLECRSIZE

    0009.11 C *IN31 ANDNE*ON

    0009.13 C WRITESFLREC

    0009.14 C MOVE PFEMNO LKEY 70

    0009.15 C ADD 1 RRN

    0009.16 C READ PAGEPF 31

    0009.17 C ENDDO

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    111/134

    0009.19 C *IN31 IFEQ *ON

    0009.20 C SETON 50

    0009.21 C ELSE

    0009.22 C SETOF 50

    0009.23 C ENDIF

    0009.24 C ENDSR

    0009.25 C*================== CLEAR SCREEN =======================

    0009.26 C CLE BEGSR

    0010.00 C SETON 40

    0011.00 C WRITESFLCTL

    0012.00 C SETOF 40

    0013.00 C ENDSR

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    112/134

    PAGEPF_PHYSICALFILE:

    SAME AS EXPANDED LOAD

    PPAGEDSP_DISPLAYFILE

    0000.40 A CF03(03)

    0000.50 A R SFLREC SFL

    0000.70 A PFEMNO R O 7 3REFFLD(PFREC03/PFEMNO MINDA

    0000.90 A PFEMNA R O 7 18REFFLD(PFREC03/PFEMNA MINDA0001.10 A PFADD1 R O 7 44REFFLD(PFREC03/PFADD1 MINDA

    0001.30 A PFADD2 R O 7 57REFFLD(PFREC03/PFADD2 MINDA

    0001.50 A R SFLCTL SFLCTL(SFLREC)

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    113/134

    0001.70 A PAGEDOWN(22)

    0001.80 A PAGEUP(23)

    0001.90 A 10 SFLDSP

    0002.00 A 10 SFLDSPCTL

    0002.10 A 40 SFLCLR

    0002.20 A 50 SFLEND(*MORE)

    0002.30 A SFLSIZ(0011)

    0002.40 A SFLPAG(0010)

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    114/134

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    115/134

    Introduction

    Arrays and tables allow program to organize groups of related data elements for easy

    retrieval.

    Array consists of series of elements with like characteristics (data type and size).

    Here every element in an array is accessed by means of an index which indicates the

    relative position of the element from the beginning of the array. The numbering startsfrom 1.

    Declaration of Arrays

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    116/134

    Declaration of Arrays

    Arrays are declared on the E-spec, by specifying the array name, entries per record,

    entries per table and length of an entry.

    Position Description

    6 Form Type (E)

    27-32 & 46-51 Array Name

    33-35 Entries per record36-39 Entries per Array or Table

    40-42 & 52-54 Length of Entry

    43 and 55 Data Format

    44 and 56 Decimal positions

    Types of Arrays

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    117/134

    Types of Arrays

    Compile time Array

    Pre runtime Array

    Runtime Array

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    118/134

    Compile time Array

    Compile time array elements are facilitated at the end of the code.

    Pre runtime array elements are facilitated before the execution of the program.

    Run time array elements are facilitated from the data base. They are loaded intoarray during runtime.

    Pre runtime Array

    Runtime Array

    P f il ti

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    119/134

    Program for compile time array0000.01 ** COMPILE TIME ARRAY USING MULTIDIMENSION ARRAY

    0001.00 DABC S 15A Dim(12) PERRCD(1) CTDATA

    0002.00 DI S 4S 0 INZ(1)

    0003.00 C I DOWLE12

    0004.00 C ABC,I DSPLY

    0006.00 C XYZ,I DSPLY

    0007.00 C ADD 1 I

    0008.00 C ENDDO

    0009.00 C SETON LR

    0010.00 **

    0011.00 JANUARY 31

    0012.00 FEBRUARY 28

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    120/134

    0013.00 MARCH 31

    0014.00 APRIL 30

    0015.00 MAY 31

    0016.00 JUNE 30

    0017.00 JULY 30

    0018.00 AUGUST 31

    0019.00 SEPTEMBER 30

    0020.00 OCTOBER 31

    0021.00 NOVEMBER 30

    0022.00 DECEMBER 31

    P f ti ti

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    121/134

    Program for preruntime time array0001.00 FPF1 IT F 30 DISK

    0002.00 DARR1 S 30 DIM(10) FROMFILE(PF1)

    0003.00 DI S 4 0 INZ(1)

    0004.00 C DO 10

    0005.00 C ARR1(I) DSPLY

    0006.00 C EVAL I = I + 10007.00 C ENDDO

    0008.00 C SETON LR

    String operations

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    122/134

    String operationsCAT

    The CAT operation concatenates the character strings specified in factor2 to theend of the character specified in factor1 and places it in the result field.

    SCAN

    The SCAN operation scans a character string (base string) contained in factor 2for a sub string (compare string) contained in factor1. If the string is found then theposition where it is found is placed in the result field.

    XLATE

    XLATE (translate) is used to find for a sub string in Fator2 and replaces it withanother string (Factor1) and places the resulting string into the result field.

    Factor 1 must contain the find string followed by a colon followed by the replacestring. Example ABCDE:abcde

    SUBST

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    123/134

    SUBST

    The SUBST operation returns a sub string from factor2, starting at the locationspecified in factor 2 for the length specified in factor 1 and places this sub string inthe result field.

    CHECK

    The CHECK operation checks a mismatched character string (base string)contained in factor 2 for a sub string (compare string) contained in factor1. If thestring is found then the position where it is found is placed in the result field.

    Program for string opcodes

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    124/134

    Program for string opcodes0000.01 **STRING CONCAT

    0000.02 C MOVE 'ANIL' S1 4

    0000.03 C MOVE 'KUMAR' T1 5

    0001.00 C S1 CAT T1:1 P1 10

    0002.00 C P1 DSPLY

    0002.03 **SCAN METHOD

    0002.04 C 'ABC' SCAN 'DEFABC' NUM 100 90

    0002.05 C NUM DSPLY

    0002.06 **CHECK

    0002.07 C 'ABC' CHECK'DEFABC' NUM 100 90

    0002.08 C NUM DSPLY

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    125/134

    0002.09 **SUBSTRING

    0002.10 C Z-ADD4 S 20

    0002.11 C MOVEL'ABCDEF' S2 10

    0002.12 C 2 SUBSTS2:S P2 10

    0002.13 C P2 DSPLY

    0002.14 **XLATE STRING

    0002.15 C MOVEL'999B9999'NUM1 8

    0002.16 C 'B':'-' XLATENUM1 FLD1 8

    0002.17 C FLD1 DSPLY

    0003.00 C SETON LR

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    126/134

    O/p

    DSPLY ANIL KUMAR

    DSPLY 4

    DSPLY 1

    DSPLY DE

    DSPLY 999-9999

    C-spec---prompt

    pmt SeqNbr Lvl N01 N02N03 Factor 1 OpCode Factor 2 Result

    C 0002.04 'ABC' SCAN 'DEFABC' NUM

    Len Dec H/N/P Hi Lo Eq Comment

    10 0 90

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    127/134

    OUTPUT SPECIFICATION

    O-Spec

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    128/134

    O-Spec

    Describes the record and the format of fields in a program-described output file and

    when the record is to be written.

    Optional for an externally described file.

    Divided into two categories:

    Record identification and control (positions 7 through 51),

    Field description and control (positions 21 through 80).

    Output specification layout Externally Described files

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    129/134

    Output specification layout Externally Described files

    1. Record Identifier specifications

    Columns Descriptions

    1-5 Sequence number

    6 O

    7-15 Record Name

    16-18 Logical Relationship AND,OR

    17 Type of record to write:

    D Detail

    E Exception (EXCEPT)

    H Detail (header)

    T Total

    Record Identifier specifications Continued 2

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    130/134

    Columns Descriptions

    18 Release Record after output : R or Blank

    18-20 Record Addition : ADD, DEL

    21-29 Output Conditioning indicators:Blank,01-99,KA-KN,KP-KY,L1-L9,H1-H9,U1-U8,MR,LR,RT,1P

    30-39 EXCEPT name

    40-80 (Blank)

    81-100 Comments

    Record Identifier specifications Continued .. 2

    2 Field Description Specifications

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    131/134

    Columns Descriptions

    1-5 Sequence number

    6 O

    7-20 (BLANK)

    21-29 Output Conditioning indicators: Blank,10-99,KA-KN,KP-KY,L1-L9,H1-H9,U1-U8,MR,LR,RT,1P

    30-43 Field Name or *ALL

    44 (BLANK)

    45 Result field contents after writing record : Blank or B

    46-80 (BLANK)

    81-100 Comments

    2. Field Description Specifications

    Program for O-spec

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    132/134

    Program for O spec0001.00 FPFNAME IP E K DISK

    0002.00 FQSYSPRT O F 80 OF PRINTER0003.00 OQSYSPRT H 2 2 2 1P

    0003.02 O UDATE Y 70

    0004.00 O 40 'ABC COMPANY'

    0005.00 O*

    0005.02 OQSYSPRT H 2 1P

    0005.03 O 40 '==========='

    0006.00 OQSYSPRT H 2 1P

    0007.00 O 20 'EMPLOYEE DETAILS'

    0007.01 OQSYSPRT H 2 1P

    0007.02 O 20 '================'

    0007.03 O* '

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    133/134

    0009.00 O H 2 1P

    0010.00 O 35 'EMP NUMBER'0011.01 O 53 'EMPLOYEE NAME'

    0012.00 O 73 'EMPLOYEE SALARY'

    0012.01 OQSYSPRT H 2 1P

    0012.02 O 47 '========================'

    0012.03 O 71 '========================

    0012.04 O 74 '==='

    0012.05 O*

  • 7/27/2019 RPG Programming Language_Wipro_V2.pdf

    134/134

    0012.06 OQSYSPRT D 2 N1P

    0013.00 O NUMBER 360013.01 O* SALARY 68

    0013.02 O* NAMERY 69 ' . '

    0014.00 O NAME 68

    0015.00 O SALARY 69 ' . '

    0016.00 O 71 'RS'

    PFNAME_OSPEC

    0001.00 A R RECNAME

    0002.00 A NUMBER 10

    0003.00 A NAME 30

    0004.00 A SALARY 10 2