Solved

locking files

Posted on 2014-03-10
4
263 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

If your vDisk VHD file gets deleted from the image store accidentally or on purpose, you won't be able to remove the vDisk from the PVS console. There is a known workaround that is solid.
When we talk about DevOps toolchains, I sometimes wonder how many people really get what we’re talking about. I don’t know if it’s just semantics or tone or something else, but sometimes I think it just sounds like buzzword sausage. So it’s always …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

932 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

15 Experts available now in Live!

Get 1:1 Help Now