Solved

locking files

Posted on 2014-03-10
4
265 Views
Last Modified: 2014-03-10
RPG PROGRAM A, opens 30 files, it calls a CL which is Calling another CL, which tries to clear those files. It can not clear the because RPG still has them in the stack
0
Comment
Question by:sniger
  • 3
4 Comments
 
LVL 34

Accepted Solution

by:
Gary Patterson earned 500 total points
ID: 39918618
Yes, that's right.  By design, you cannot clear a file while it is open.  Clearing a file requires an exclusive lock.  

Generally you must close the files in RPGA before calling a program that may try to clear them.

One note, and I hesitate to mention it - is that you CAN delete all the rows in a file when the file is open (as opposed to clearing them) - except for any individual rows that might be locked at the moment.

If you use embedded SQL to clear the tables:

DELETE FROM TABLE1
DELETE FROm TABLE2

SQL will pick the best method.  Clearing is best, if the required exclusive lock can be obtained.  Clearing actually frees up the disk space, where deleting doesn't.  

If an exclusive lock cannot be obtained, SQL will automatically revert to single-row deletion, and delete each row individually.  This can take much longer, uses more CPU and disk IO, and will not free the disk space, but all the active records will be removed - and if the file is set up to reuse deleted records, the some or all of the deleted space will get reused the next time the file is populated.
0
 
LVL 34

Assisted Solution

by:Gary Patterson
Gary Patterson earned 500 total points
ID: 39918635
An alternative to closing and reopening files in RPGA (that might take some significant re-engineering depending on the program structure), one solution to this problem is to rearrange your program a little.

Instead of RPGA -> CL1 -> CL2, you may want to do something like this:

CL0 calls RPGA
   When user selects a function that may require clearing files,
   terminate RPGA with *INLR = *ON and return to CL0,
   setting a return value telling CL0 to call CL1

CL0 calls CL1call CL2
   Files get cleared

CL2 returns to CL1 returns to CL0

CL0 can now call RPGA again, or do whatever needs to be done at this point.
0
 

Author Comment

by:sniger
ID: 39918640
Thanks Gary,  how about putting everything in one activation group (CALLER activation group)


would this help ?
0
 
LVL 34

Expert Comment

by:Gary Patterson
ID: 39918741
Reasonable thought, but no not in this case.  Try it - it is what? - about 5 lines of code?

Rpg:

Fmyfile if              e disk
c                     read  myfile
c                     call 'TESTCLEAR'
c                     eval *INLR = *ON

Open in new window

TESTCLEAR (Clle)

clrpfm myfile

Open in new window


CLRPFM requires a system-side exclusive lock.  That means no locks on this file by anything in this job - same activation group or different activation group - or any lock in any other job on the system, either.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
HTTP *Admin and DCM 1 178
PDF TO PCL format conversion on AS400 - infoprint server 4 82
iSeries Memory Utilization 2 82
BRMS - TSM API DSMERROR.LOG 5 32
Binary Differential Replication, What it is, how it works and how it differs from standard delta file replication
Read about the ways of improving workplace communication.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now