This documentation is not maintained. Please refer to doc.castsoftware.com/technologies to find the latest updates.


Summary: This page explains how to prepare and configure the analysis of your RPG source code.

Source code organization

Before the RPG source code can be delivered to CAST and then analyzed, it needs to be collected from the proper iSeries libraries and transferred to the designated location. During this operation, each artifact (program, CL, DSPF) must be put into a single file only. This will result in a single artifact per file. Furthermore, the type of source code must be expressed using the extension to the file. The appropriate files extensions are listed in the following table. 

Source code is kept in a member of a file. The file is kept in a library. Each file can have many members. Each member is the source code for a program.

The source code files can have any name but conventionally the names start with Q and end with SRC, for source.

Source code type

iSeries library

Required extension

used in MetaModel

RPG-III and GAP3 programs

QRPGSRC

*.rpg

RPG300

ILE RPG and GAP4 Programs

QRPGLESRC

*.rpgle

RPG400

ILE RPG and GAP4 Programs with SQL

QSQLRPGLESRC

*.sqlrpgle

RPG400

Copy source members - GAP4

QCPYLESRC

*.cpyle

RPG400

CL programs

QCLSRC

*.cl

CL400

ILE CL Programs

QCLLESRC

*.clle

CL400

Display Files

QDDSSRC

*.dspf

DDS400

Printer Files

QDDSSRC

*.prtf

DDS400

Logical Files

QDBSRC

*.lf

DB400

Physical Files

QDBSRC

*.pf

DB400

Bound service programs

QBNDPGM

*.bnd

RPG400

Menu

QMNUSRC orQMENUSRC

*.menu

MENU

Source code preprocessing

RPG source code needs to be preprocessed so that CAST can understand it and analyze it correctly. In previous releases of the extension, this preprocessing was a manual action that needed to be completed before the code was analyzed. However, in this release and all future releases, the code preprocessing is actioned automatically when an analysis is launched or a snapshot is generated (the code is preprocessed before the analysis starts). In other words you only need to package, deliver and launch an analysis/generate a snapshot for the preprocessing to be completed.

Note that the CAST Management Studio will use the LISA folder (see CAST Management Studio help for more information about this folder).

Manual preprocessing

If for any reason you are requested to manually preprocess the RPG source code before you package and deliver it, then you can do so as follows:

  • Place all of the source code into the Tools\RPG_PreProcessor\input folder - this folder is created after unpacking the extension archive file.
  • Run Tools\RPG_PreProcessor\launch.bat
  • The resulting preprocessed code will be placed in the Tools\RPG_PreProcessor\output folder - the source code in this folder needs to be packaged in the CAST Delivery Manager Tool.

Known Limitation for code preprocessing

  • If the preprocessed file contains two RPG Programs, it will cause a fatal error during the preprocessing phase. To work around this:
    • retrieve the name of the file causing the error from the command window
    • remove the file from the source code
    • rerun the preprocessing phase

launch.bat file

The table below lists all configurable parameters in the Tools\RPG_Pre-Processor\launch.bat batch file. You can change these to alter the outcome of the preprocessing:

Parameter Name

Parameter Description

ENDIF_RENAME

Enables you to calculate depth of code

EXTERNAL_FIELD_CHECK

EXTERNAL_FIELD_FILE

EXTERNAL_FIELD_FULLNAME

These three parameters are used to with a feature that:

  • checks if the columns defined in the PF files use a common type defined in an external file
  • computes the size of the buffer for a PF
 
Certain RPG Quality Rules require this feature to be enabled.

For example, in a PF file, when you use REFFLD, this means that the type is defined in the file defined in the REF():

A REF(REPERT)
A R AAATSF TEXT('test')
A AAACARJ R REFFLD(CARJ)
A AAACP R REFFLD(CP)
A AAABZTI R REFFLD(BZTI)

Otherwise you will have a field defined as follows - in this case, if you use the same field in another PF, you might have some differences.

 

A R ADRENF TEXT('Adresses d''enlèvement')
A CODPOS 9
A LOCALIT 35
A OCTET 1
A AGENLEV 6

Usage

  • EXTERNAL_FIELD_CHECK : this option activates the feature in the preprocessor. By default in the go.bat file, this is set to Y - i.e. activated.
  • EXTERNAL_FIELD_FILE : reference used in the PF file. In the example code above, you will see "REF(REPERT)", the value for this option should therefore be set to REPERT. When this reference is found, it looks into the file defined by the EXTERNAL_FIELD_FULLNAME parameter. By default this is set to REPERT in the go.bat file.
  • EXTERNAL_FIELD_FULLNAME : full path for the output file. It should be set to a full path, for example C:\Chantiers\RPG\input\DICO\repert.txt

In the REPERT file, you can find the definition of the field CARJ (a string with 6 characters):

A CARJ 6S 0 TEXT('Code agence traitante ')

A COLHDG('Age.trait. ' 'CGN_TRT')

PREFIX_SUBROUTINE

Enables you to define a unique subroutine name

In different files, We can have different subroutines having same name. Setting this parameter to Y, it prefixes that subroutine with the FileName and Suffixes it with "BEGSR"

Please note that having different subroutine having same name can lead to many wrong links created

 

RECORDSTRUCT_RENAMING

Rename DSS record structure for better recognition

Report_FullFileName

Name of the file to report full filename

RULE_EXTRACTION

Enables you to extract rules in specific files

Source_Path

Location of source code for preprocessing

Target_Path

Location of source code following a successful preprocessing

Application Source code delivery and Snapshot generation 

When delivering your source code for analysis with CAST, you need to follow the same process as for technologies that are supported by CAST "out of the box". In other words:

Errors & Warnings

During the application analysis phase, you may receive one of the following errors:

Error or WarningAction
An unnamed object of type 'RPG400SQLStructure' has been detectedThis is because RPG400SQLStructures have no specific name, as such, the CAST framework will give them the name "unnamed". You can safely ignore this warning.
Duplicate object of type 'RPG400SQLStructure' has been detected: '<unnamed>'As mentioned above, structures have no specific name and are automatically given the name "unnamed" by CAST - as such multiple objects with the name "unnamed" will exist and will cause this error. You can safely ignore this warning.
Unable to find the object end for type 'RPG400Rule'This is caused by source code that is referring to a Rule that cannot be found. You can safely ignore this warning.
Duplicate object of type 'MENUItem' has been detected: 'XXXXXX'This is due to a duplicate Menu name in the original Menu file. You can safely ignore this warning.
Warning after preprocessing the source code- Unknown format for ' A XA3439 R REFFLD(DATM FRFGFDI4)'

Follow Sample Reference Function Specifications

|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
00010A                                      REF(FILE1)    (1)
00020A          R RECORD1
00030A            FIELD1    R                             (1)
00040A            FIELD2    R                             (1)
00050A            FIELD3    R               REFFLD(FLD3)  (2)
00060A            FIELD4    R               REFFLD(FLD4 FILE2)  (3)
00070A            FIELD5    R               REFFLD(FLD5 LIB1/FILE3)  (4)
00080A            FIELD6    R               REFFLD(RECORDB/FLD6 LIB1/FILE4)  (5)
00090A            FIELD7    R               REFFLD(FIELD6 *SRC)  (6)
00100A            FIELD8    R               REFFLD(FLD6)  (7)
00110A          R RECORD2
00120A            FIELD1        20  (8)
00130A
00140A          R RECORD3
00150A            FIELD1    R               REFFLD(RECORD2/FIELD1 *SRC)  (9)
00160A
00170A          R RECORD4
00180A            FIELD1    R               REFFLD(FIELD1 *SRC)  (10)
     A

Note:For line 00010, you can also specify library name and record format
name. See the REF keyword example/

You must specify R in position 29 for each field that refers to another field that was previously defined.

RPG preprocessor supports only the cases (2) and (7) : Only one parameter for the REFFLD function.