News
Abstract
Information about the PTFs to provide the ILE RPG enhancement to define constant standalone fields and data structures
Content
You are in: RPG Cafe > RPG Cafe: Spring 2024: Define constant standalone fields and data structures
Short URL: https://ibm.biz/rpgcafe_spring_2024_const_fld_and_ds
Spring 2024: Define constant standalone fields and data structures
- Add the CONST keyword for a standalone field or data structure. Similar to parameters defined with the CONST keyword, the variable cannot be modified in the module.
- Unlike ordinary data structures which default to being initialized to blanks, all the subfields of a constant data structure are initialized.
Example of a constant standalone field
The originalUserid field is initiaiized at the beginning of the procedure to the current user profile. The compiler does not allow any statements that would change the value of the field. The example shows the error message when the procedure tries to change the constant variable.
dcl-proc myproc;
dcl-s originalUserid char(10) inz(*user) const;
... code that may swap the current user profile
if originalUserid <> getCurrentUserid();
... code to restore the current user profile
originalUserid = *BLANK;
aaaaaaaaaaaaaa
*RNF5346 30 a 002500 The operation modifies the field,
but the field cannot be modified.
endif;
end-proc;
Example of a constant data structure
The programmer can rely on the fact that the subfields of the defaults data structure can never change after they are initialized.
dcl-ds defaults qualified const;
account_type int(10) inz(STANDARD_ACCOUNT);
...
end-ds;
dcl-proc create_new_account;
dcl-pi *n;
new_account likeds(account_t);
cust_id int(10) const;
cust_type int(10) const;
end-pi;
dcl-ds new_account likeds(account_t);
eval-corr new_account = defaults;
new_account.customer_id = cust_id;
if cust_type <> defaults.account_type;
setup_special_account (new_account : account_type);
endif;
...
end-proc;
. .
. .
PTFs for 7.4 and 7.5
7.4:
- ILE RPG compiler: 5770WDS SJ01353
7.5:
- ILE RPG compiler: 5770WDS SJ01351
- ILE RPG compiler, TGTRLS(V7R4M0): 5770WDS SJ01354
The PTFs will also be available with later Db2 for i Fix Packs. See Db2 for IBM i 2022 PTF Group Schedule.
RDi support
The next update for RDi will support these enhancements.
Documentation
The 7.4 and 7.5 ILE RPG Reference and ILE RPG Programmer's Guide are updated with full information about these enhancements.
- What's new since 7.4? https://www.ibm.com/docs/en/ssw_ibm_i_74/rzasl/rpgrelv7r4post.htm
- What's new since 7.5? https://www.ibm.com/docs/en/ssw_ibm_i_75/rzasl/rpgrelv7r5post.htm
Was this topic helpful?
Document Information
Modified date:
15 July 2024
UID
ibm17149873