I am creating a RPG program (In PUB400 server) that simulates an ATM cashier with some options. This RPG program uses three tables as: Customers(Id, Name, RegistrationDate), Accounts(AccountNumber, CustomerId, Balance) and Transactions(Id, CustomerId, TransactionType, TransactionDate).
When I am coding the RPG program I get multiple sintax errors that I do not know how to fix. For example, in
0001.00 D Withdrawal pr
0001.01 D CustomerId Like(Accounts.CustomerId)
0001.02 D AccountNumber Like(Accounts.AccountNumber)
0004.00 D Amount Like(Accounts.Balance)
0005.00
0006.00 D Withdrawal PI
0007.00 D CustomerId Like(Accounts.CustomerId)
0008.00 D AccountNumber Like(Accounts.AccountNumber)
0009.00 D Amount Like(Accounts.Balance)
0010.00
0011.00 /FREE
0012.00 //Check if the account has sufficient balance
0013.00 SELECT Balance INTO :Balance
0014.00 FROM Accounts
0015.00 WHERE CustomerId = :CustomerId
0016.00 AND AccountNumber = :AccountNumber
0017.00 FOR UPDATE OF Accounts;
0018.00 IF :Balance >= :Amount;
0019.00 //Update the balance
0020.00 UPDATE Accounts
0021.00 SET Balance = Balance - :Amount
0022.00 WHERE CustomerId = :CustomerId
0023.00 AND AccountNUmber = :AccountNumber;
0024.00 //Record the transaction
0025.00 INSERT INTO Transactions(CustomerId, TransactionType, TransactionDate)
0026.00 VALUES (: CustomerId, 'W', CURRENT_TIMESTAMP);
0027.00 ELSE;
0028.00 //Display an error message
0029.00 ENDIF;
0030.00 /END-FREE
****************** End of data ****************************************
This is the return displayed of the WRKSPLF:
5770WDS V7R5M0 220415 RN IBM ILE RPG REUY851/ATMSIM1
Command . . . . . . . . . . . . : CRTBNDRPG
Issued by . . . . . . . . . . : REUY85
Program . . . . . . . . . . . . : ATMSIM1
Library . . . . . . . . . . . : REUY851
Text 'description' . . . . . . . : *SRCMBRTXT
Source Member . . . . . . . . . : ATMSIM1
Source File . . . . . . . . . . : QRPGLESRC
Library . . . . . . . . . . . : REUY851
CCSID . . . . . . . . . . . . : 273
Text 'description' . . . . . . . : RGP PROGRAM ATM TRANSACTIONS
Last Change . . . . . . . . . . : 04/20/23 15:45:05
Generation severity level . . . : 10
Default activation group . . . . : *YES
Compiler options . . . . . . . . : *XREF *GEN *NOSECLVL *SHOWC
*EXPDDS *EXT *NOSHOWSKP *NOSRC
*DEBUGIO *UNREF *NOEVENTF
Debugging views . . . . . . . . : *STMT
Debug encryption key . . . . . . : *NONE
Output . . . . . . . . . . . . . : *PRINT
Optimization level . . . . . . . : *NONE
Source listing indentation . . . : *NONE
Type conversion options . . . . : *NONE
Sort sequence . . . . . . . . . : *HEX
Language identifier . . . . . . : *JOBRUN
Replace program . . . . . . . . : *NO
User profile . . . . . . . . . . : *USER
Authority . . . . . . . . . . . : *LIBCRTAUT
Truncate numeric . . . . . . . . : *YES
Fix numeric . . . . . . . . . . : *NONE
Target release . . . . . . . . . : *CURRENT
Allow null values . . . . . . . : *NO
Define condition names . . . . . : *NONE
Enable performance collection . : *PEP
Profiling data . . . . . . . . . : *NOCOL
Licensed Internal Code options . :
Generate program interface . . . : *NO
Include directory . . . . . . . :
Preprocessor options . . . . . . : *NONE
REQUIRE PROTOTYPE FOR EXPORT . . : *NO
-=* http://pub400.com *=-
5770WDS V7R5M0 220415 RN IBM ILE RPG REUY851/ATMSIM1
Line <---------------------- Source Specifications -------------------------
Number ....1....+....2....+....3....+....4....+....5....+....6....+....7....+.
S o u r c e L i s t i n g
1 D Withdrawal PR
======> aaaaaaaaaa
*RNF3788 30 a 000100 DFTACTGRP(*NO) must be specified for a prototype th
not have the EXTPGM keyword.
2 D CustomerId Like(Accounts.CustomerId)
3 D AccountNumber Like(Accounts.AccountNumber)
4 D Amount Like(Accounts.Balance)
5
6 D Withdrawal PI
======> aaaaaaaaaa
*RNF3751 30 a 000600 External procedure on prototype for main procedure
same as actual external name.
7 D CustomerId Like(Accounts.CustomerId)
8 D AccountNumber Like(Accounts.AccountNumber)
9 D Amount Like(Accounts.Balance)
10
11 /FREE
12 //Check if the account has sufficient balance
======> aaaaaa
*RNF0274 30 a 001200 Compiler directive not recognized; directive ignore
13 SELECT Balance INTO :Balance
======> aaaaaaa
*RNF5507 30 a 001300 A semi-colon is not specified at the end of a free-
statement.
14 FROM Accounts
15 WHERE CustomerId = :CustomerId
16 AND AccountNumber = :AccountNumber
17 FOR UPDATE OF Accounts;
18 IF :Balance >= :Amount;
======>a
*RNF0257 30 a 001800 Form-Type entry for main procedure not valid or out
sequence.
19 //Update the balance
======> aaaaaaa
*RNF0274 30 a 001900 Compiler directive not recognized; directive ignore
20 UPDATE Accounts
======>a
*RNF0257 30 a 002000 Form-Type entry for main procedure not valid or out
sequence.
21 SET Balance = Balance - :Amount
======>a
*RNF0257 30 a 002100 Form-Type entry for main procedure not valid or out
sequence.
22 WHERE CustomerId = :CustomerId
======>a
*RNF0257 30 a 002200 Form-Type entry for main procedure not valid or out
sequence.
23 AND AccountNUmber = :AccountNumber;
======>a
*RNF0257 30 a 002300 Form-Type entry for main procedure not valid or out
sequence.
24 //Record the transaction
======> aaaaaaa
*RNF0274 30 a 002400 Compiler directive not recognized; directive ignore
25 INSERT INTO Transactions(CustomerId, TransactionType, TransactionDate)
======>a
*RNF0257 30 a 002500 Form-Type entry for main procedure not valid or out
sequence.
26 VALUES (: CustomerId, 'W', CURRENT_TIMESTAMP);
======>a
*RNF0257 30 a 002600 Form-Type entry for main procedure not valid or out
sequence.
27 ELSE;
======>a
*RNF0257 30 a 002700 Form-Type entry for main procedure not valid or out
sequence.
28 //Display an error message
======> aaaaaaaa
*RNF0274 30 a 002800 Compiler directive not recognized; directive ignore
29 ENDIF;
======>a
*RNF0257 30 a 002900 Form-Type entry for main procedure not valid or out
sequence.
30 /END-FREE
======>a
*RNF0257 30 a 003000 Form-Type entry for main procedure not valid or out
sequence.
*RNF5177 30 13 001300 ENDyy operation missing for SELECT operation group
statement 13; END assumed.
Once again, you are on v7.5, you should not be using any fixed format at all. Start your programs with **free
starting in line 1, column 1 of your source. In this case there is NO special columns in the code, no comment area, no specification column, no sequence columns. All your code can start in column 1 of the source line. As Dam said, SQL statements start with exec sql
, variables in the SQL statement must be prefixed by a colon (:), but that only applies to variables embedded in SQL statements.
Also drop /free
and /end-free
statements, they just clutter the code.
It seems you need to find a better you-tube channel to learn RPG coding from. The one you are currently using is confusing you with obsolete techniques.
One thing you are missing is your control specs. These were H specs in days past, but now in the **free
world, they are ctl-opt
The set of control options I use depends on whether I am coding a program or a module. for Programs I use:
ctl-opt DatFmt(*iso) TimFmt(*iso)
DftActGrp(*No) ActGrp(*New)
BndDir('COMMON')
Option(*NoDebugIo: *SrcStmt: *NoUnref)
Main();
The parameter for Main() is the name of the main procedure. I always use the program name for this, it is also the source file name.
For modules I use:
ctl-opt DatFmt(*iso) TimFmt(*iso)
Option(*NoDebugIo: *SrcStmt: *NoUnref)
NoMain;