is it possible for us to identify some areas that we can put into consideration if we have to find out the optimal size ?
I can imagine a few areas as below:
1) the ways of program to manage the data (e.g. a cobol pgm handles a table with million rows of records)
2) the volume size of input data to the batch program in JCL (i.e. more data, more region size requirements)
3) the high EXCP count for the job execution (e.g. if higher EXCP count, then higher region size might help somehow)
do the rmode and amode for the program also take effect on the consumption for region size ? or any other things we can put them into consideration ?
One question you need to consider: optimal from what standpoint? Optimal from the program standpoint may be wasteful for the system, and vice versa. Broadly speaking, your site support group should be able to provide some guidance. Each site is somewhat different so what I say here may -- or may not -- apply to your site. As a simple example, many sites prohibit using REGION=0(K or M) due to potential system problems; other sites encourage the use of REGION=0K/0M.
As far as your cases:
1) if the COBOL program has an array then it will obviously need more memory than if it just retrieves one row at a time from the database.
2) I've seen programs where input data volume had an impact on memory needed (where the program was dynamically building a table from the data), but this is actually quite rare. 99%+ of the time, the memory requirements for a program are fixed. They will change with new releases of the operating system or if the program is recompiled (particularly if the compiler version changes), but otherwise it would be rare to see variation in memory usage.
3) EXCP count reflects the amount of data being input to or output from the program and hence would rarely, if ever, have much of an impact on memory requirements for the program. A high EXCP count may indicate other performance issues -- such as long elapsed time due to lack of buffers -- that may be alleviated by additional memory for the program, but in general a program with high EXCP counts that has been optimized for buffer usage will not be helped by more memory.
RMODE and AMODE may impact program memory requirements -- but again, may not (it all depends). In general, an RMODE(24) AMOD(24) program will be limited to the amount of memory available below the line-- depending upon the site, that is usually somewhere between 8 and 10 megabytes. Moving to 31-bit addressing for both RMODE and AMODE allows the program to use up to 2 gigabytes of memory. Note that recent compilers are starting to generate code that uses 31-bit addressing exclusively and 24-bit addressing is slowly dying out.
The most optimal (from the program standpoint) solution is to specify REGION=0M or REGION=0K on the JOB statement and don't code any REGION on any EXEC statement. From the JCL Reference
A value equal to 0K or 0M — gives the job all the storage available below and
above 16 megabytes. The resulting size of the region below and above 16
megabytes is installation-dependent. When REGION=0K/0M is specified, the
MEMLIMIT is set to NOLIMIT.
This may cause storage problems. See the Considerations When Using the
REGION parameter section for more information.
Considerations when using the REGION parameter
Specifying a REGION size that gives the job all the available storage below the 2
GB bar, such as 0K or any value greater than 16,384K, can cause storage problems
if the IBM- or installation-supplied routine IEALIMIT or IEFUSI is not used to
establish a limiting value.
This will let the program use whatever is available. However, your site may override REGION=0M/0K to something else through an installation exit. Only your site support group can tell you for sure.