Friday, July 21, 2017

Common Compilation Errors in RPGLE

Hello Friends,

Today we are going to see some of the common errors we come across while compiling the RPGLE code. If you are beginner then this post could be useful if you come across these error messages in your future.

It always give happiness when you compile you code with error code 0 on first time J

Sample code with Error:


Order file:


Program:

Basically this program gets Ord_No & Cust_No as input and checks if the order is available in ORDER file. If available then it prints the Order quantity else it writes new record for the customer and order number with other fields (Name & quantity) as default.


After compiling this below is the list of errors:



Let us go one by one and fix it.

RNF7030 à ORD_QTY is not defined

The intention of this line is to display order quantity from file but variable used is Ord_Qty but file contains field as ORDQTY. So compiler is not able to recognize Ord_Qty. Thus we need to remove this underscore

Eval      Msg = 'Order is available '+
                'Qty : ' + Ord_Qty    

RNF7055 à Factor 1 ORD_KEY is not valid for the specified operation.

Ord_Key       Chain     Order

Here we are trying to do chain operation on the file Order but the file specification is not having record access as Key (‘K’)

FOrder     IF   E             Disk  à This should be changed as below
FOrder     IF   E           K Disk

RNF7016 à Display length 100 greater than maximum allowed of 52;

This is because we are trying to display Msg variable using DSPLY function. But the Max length that could be displayed is 52. But Msg variable is having length 100. We need to change this to Max 52.

RNF7416 à The types of the right and left hand side do not match in EVAL operation.

This is most common error you might have already seen it.

Eval      OrdName  = Ord_No     // we are trying to eval char variable with numeric

RNF5196 à File in Factor 2 does not have allowed file type for WRITE

When we need to add new records, the file specification should be defined with File Addition = ‘A’

FOrder     IF A E           K Disk 

Ok now let us quickly make the changes and compile again. 


Now we eliminated all previous errors and ended with new 2 errors. Let us fix these.



RNF7073 à KFLD at sequence number 18 is 4 long. Key field is 5 long.

This is because, our key Ord_Key is formed using Ord_No & Cust_No variables with 4 and 10 length. But the actual files key is ORDNO (5 length) and CUSNO (10 length).

So to fix this, either we can change length of Ord_No from 4 to 5, else we can use Like keyword during 
declaration to ask program to refer data type directly from PF.

RNF7421 à Operands are not compatible with the type of operator.

This is because we are trying to concatenate string and OrdQty in Msg variable. But OrdQty is numeric and thus we need to convert it to %Char before concatenate

So the final code is here.


These are very basic errors and there are more to come when you use Copy book and Procedures and introduce other ILE concepts.

I will try to cover few more in my future posts until then

Have fun..!!! Happy coding..!!!

No comments:

Post a Comment