Friday, April 18, 2014

Library, Source Physical File, Member, Record and Record Format



It is very important to understand the above jargons. All terms are related to each other in a following hierarchy.



Record & Record Format:
          The data in a file is called Record. it should be in some specific format and that format is called Record Format.

For example: On a page of paper, you have following data.



All the above detail/ data on the page is record.

Whole page is written in a pre-defined rules and that rules are specified in a template or format as mention below.

Example of Record Format.



If I want to code the above format as PF then I may code as following:

R       PFLETTERR                                       
                    SALUTATION      15A             TEXT('SALUTATION')    
                    BLNK_LINE1       80A             TEXT('BLANK LINE 1')  
                    DETAILS             500A           TEXT('DETAILS')       
                    BLNK_LINE2       80A             TEXT('BLANK LINE2')    
                    THANKS             15A             TEXT('THANKING YOU')  
                    BLNK_LINE3       80A             TEXT('BLANK LINE3')   
                    REGRADS          15A             TEXT('YOURS SINCERELY')
                    NAME                  30A             TEXT('NAME')          


Now a proper Example of Record Format & Records

Record Format – PF1R



PF1



In PF1R image:


  • it is restricted that each record (that means each line of data) will have only two columns.
  • It is restricting or telling us that any data (even blanks) in the 1st col: will be consider as CUSTOMER ID and anything in 2nd col: will be COUSTOMER NAME

In PF1 image:


  • PF1 has 3 lines of data that means it has 3 Records
  • It is a two column PF just as described by its format (PF1R).
  • First col: has ID and 2nd col: has Name.

Member:

          Member is the collection of record(s). it contains line of data in a proper
In the above PF1 example.
  • ·        PF1 is a Member
  • ·        It has 3 Records
  • ·        Record Format PF1R is for all the records in the Member PF


Source Physical File:
            Source physical file is a file which contains the sources of different types of objects. 
  • ·         It is the collection of file member(s).
  • ·         There can be up to 32767 members
  • ·        Used CRTSRCPF command to create library

·          

Library:
Library is a collection of files. Read more about Library (Here
  • ·        Used CRTLIB command to create library


Thursday, April 17, 2014

A Simple Loop Program

Here it is a simple program that print counting upto 10. it is a one of the basic programs but still it has so many advance topics and techniques. let us see the full coding first.

0001.00 DCOUNTER          S              2P 0                                                               
0002.00 D                                                                                                   
0003.00 C                   FOR       COUNTER = 1 TO 10                                                     
0004.00 C     COUNTER       DSPLY                                                                           
0005.00 C                   ENDFOR                                                                          
0006.00 C                   SETON                                            LR                              

Now, Let us parse the program line by line

0001.00 DCOUNTER          S              2P 0                                             
It is the very first line of the program.
0001.00 = line number
D = shows that it is Data Specification (RPGLE program is consists of specification such as H, F, D, I, C, . . . ). D-spec is used to declare variables
counter = variable name
S = it shows that variable is data structure (DS), single(S), constant(C)...
2 = variable length
P = data type ( few data type are character(A), Packed Decimal(P), zoned(S). 0 is showing that there is NO decimal Place

0002.00 D      (blank line)


0003.00 C                   FOR       COUNTER = 1 TO 10


C = indicate that following line is Calculation (C) Specification related. every calculation, looping, branching, program-calling is done here in C-Spec.
this line tells the compiler that a 'for-loop' has to be execute from 1 to 10.

0004.00 C     COUNTER       DSPLY

it display the value of 'counter' variable

0005.00 C                   ENDFOR      

this line complete the for loop and every thing between 'FOR' and 'ENDFOR' is part/ body of for loop. 

FOR-LOOP Syntax


FOR

.
.
.
.
ENDFOR 

0006.00 C                   SETON                                            LR        

it set on the last record(LR) indicator. which tells the compiler that end now.
A very importantand must have line in the RPG PGM. Without having this line compiler will generate following error while compiling the PGM and PGM will not compile.

 Msg id  Sv Number Seq     Message text                                               *RNF7023 40      0         The Compiler cannot determine how the program can end.        

Images