0

Suppose I've a batch job which has previously run and created a flat output file of fixed record length. (The output file name will vary for each run of the job.)

I've a CICS program running in a server environment which will receive a request from a web browser for the job results, and I want to read the file and return the content. (Assume the specific file name to use will be included in the text.)

I'm trying to work out how to actually access the file in CICS.

I'd managed to dynamically specify the filename using CEEENV, but then discovered that I can't use the native OPEN/READ commands. I know there are CICS read and browse commands, but they all seem to require having the file defined to CICS beforehand? I've also seen references to using transient data queues to access sequential files, but again, the queue needs to be pre-defined.

The file won't have any particular structure or suitable key, so it looks like I should use the BDAM file commands. Which seems to require a FCT entry. But I can't find any decent examples of how to create that.

Obviously, the web service could be called frequently and concurrently, so I need some way of temporarily associating the file with a means of accessing it, which I can free as soon as I'm done with it.

Obviously, I'm not that familiar with the CICS environment. I feel like I'm either missing something simple, or there's a fundamental reason why this can't be done. Pointers towards either would be welcome!

Mick O'Hea
  • 1,619
  • 2
  • 14
  • 20
  • 1
    To my knowledge, any file you want to read in CICS would have to be defined in that particular CICS region. If you are running multiple CICS regions, or have CICS plexing this may be an issue unless the file is defined in every region. Also, because this dynamic allocation will also be a pain. I wonder if using a queue might work better in this instance. – SaggingRufus Nov 30 '16 at 18:48
  • 1
    You might be able to get away with defining a GDG in CICS and making the entry once and having the CICS program grab the latest generation, someone please correct me if I am wrong, but that's all I can think of to make a dynamic allocated file work in CICS. – SaggingRufus Nov 30 '16 at 18:58
  • 2
    The only way you can get an implementation of your business requirement is by how your site wants to do it. There are numerous ways to serve your business requirement, and it is extremely unlikely that "a dynamicall-allocated file", even more so a non-VSAM dataset, is going to be in your solution. Your site has policies, standards and practices which serve things like security and availabilty, maintainability, audit, compliance and regulatory issues (these latter less so if business is not "fiancial". Ask at your site, not on the internet. – Bill Woodger Dec 01 '16 at 13:11
  • At this point I'm simply trying to answer the technical question of whether it's possible to access, within CICS, a sequential flat file previously created by a batch JCL. There are specific reasons why this is the requirement, which I'm not going into. If it's not possible, I'll have to consider alternative approaches. The "ask at your site, not the internet" somewhat defeats the entire purpose of Stack Overflow, but I appreciate your constructive response – Mick O'Hea Dec 01 '16 at 14:16
  • The technical answer is yes (see my answer below). Whether it's allowed at your site, which seems to be more Bill's point, is of course not something we can address. It is relatively common for people to ask if something is technically possible when they've been told it isn't allowed at their site - two separate issues. – cschneid Dec 01 '16 at 14:48
  • Thanks, and I appreciate your answer, particularly the caveats included. I'm quite happy to be told I've misunderstood some basic premise of something and it's not possible, or that it is but I shouldn't do it for x reasons, or that there's a better alternative I should consider (e.g. using DB2). But I don't think a blanket 'go ask at your site' is particularly helpful while trying to assess what technical options are possible. – Mick O'Hea Dec 01 '16 at 16:22
  • 2
    @SaggingRufus I _think_ one could use the CICS SPI and enq/define/read/disable/discard/deq a TD queue pointing to a flat file on the fly, but there are enough security (and other) implications that even someone such as myself, whose sanity is already in doubt, won't mention it. Wait, oops... – cschneid Dec 01 '16 at 20:36
  • How can it "defeat the entire purpose SO"? OK, try it. Go to your technical people and say "SO says it's OK, so just let me do it, I've even got some code to paste in, I'm told it'll work fine". Your site has various policies, for various reasons, none of which we know. Instead of "I want to do this, or I'll take my toys home", why don't you explain the requirement you have to the people at your site. Your resolution may be as simple as using an ESDS instead of a "flat file", or it may be something else. We have no clue, and we are not supposed to toss stuff for you to paste because of "SO". – Bill Woodger Dec 03 '16 at 21:24
  • I'm honestly bemused. I made it clear in my original post that I'm fairly new to the CICS environment. I've no intention of cutting and pasting something into a production environment without understanding how it works and the implications of it. You keep telling me to talk to "my technical people". Right now, that's me. I'll nab somebody else shortly, but in the meantime it seemed like a good idea to try to get a head start on understanding the options available and the issues involved. And from the answers I've got, I've some fundamental misunderstandings I need to go and read up on. – Mick O'Hea Dec 05 '16 at 11:45

3 Answers3

3

I've done this with Unix Systems Services files via calls to C runtime routines from COBOL. FOPEN, et. al. are available to you.

It is vital that your program execute on an open TCB and that it be thread safe.

If you're running CICS TS 4.2 or later you must define your program as CONCURRENCY(REQUIRED) so you know it's on an open TCB and not on the QR TCB. Doing I/O on the QR TCB is bad for performance and throughput and potentially your continued employment. If your program doing the I/O is not the first program in the transaction, you must LINK to it and not dynamically CALL it in order for the TCB switch to take place automatically.

If you're running CICS TS 4.1 or earlier you must jump through some hoops to force your transaction onto an open TCB. Hopefully you're on a more current version.

Explain this to your CICS Systems Programmer, that you're going to do QSAM I/O but you're going to ensure you're on an open TCB to avoid performance issues.

If you don't know what the different TCBs are about, please consult the documentation. There's a redbook on the topic of thread safety that covers the TCBs. It's well worth your time.

Another way to accomplish this would be to load the data into a DB2 table (if your shop has DB2) at the end of the batch job.

cschneid
  • 10,237
  • 1
  • 28
  • 39
  • Thanks for that, and I appreciate the warning about potential performance issues. I'd been considering the DB option as a fallback, but that might be the safer option. – Mick O'Hea Dec 01 '16 at 14:49
  • Just as a general ROT, from my experience, don't mix non-VSAM files and CICS. As you've seen, the hoops are quite extensive and very spit-and-bailing-wire. For sequential files, you could play with ESDS, but even though it's physically possible, the implementation logic could be troublesome. You might also want to look at a message-type implementation using WMQ or similar. – zarchasmpgmr Dec 01 '16 at 17:05
  • 1
    @zarchasmpgmr absolutely agree. There is a significant difference between "is it possible," "is it allowed," and "is it a good idea." And sometimes one is caught between "can't" and "have to." – cschneid Dec 01 '16 at 18:16
1

You can use the CICS SPI to dynamically do the resource definition for the file, but it isn't a good idea, really more of a pain in the ass, there are just too many considerations -- high availability, which file owning region, the headaches abound.

Anything CAN be done, it is just a computer after all, but you will be violating all of the assumptions that went into building the framework of CICS/TS for the last half century or so. It manages the resources to get maximum concurrency of all tasks running for maximum efficiency of all machine resources. Doing what you suggest could put the entire region into an OS wait state and lock everything up unless you massage it all just right.

If it is just a simple flat file, copy it into a predefined ESDS at the end of the job that creates it and trigger your CICS task read it from there, your debugging life will be much easier and your CICS SysProgs will not hate you and curse your name forever. Or you could use a KSDS keyed with the unique file name and a record sequence number, and process using STARTBROWSE/READNEXT/ENDBROWSE for just those records.

Joe Zitzelberger
  • 4,238
  • 2
  • 28
  • 42
  • I agree it better to work with CICS than against it. We generally used KSDS (with an appropriate key e.g. request ID in these situations). A database (DB2 ?) would be an alternative to the KSDS - save allocating / de-allocating files from CICS. – Bruce Martin Dec 03 '16 at 22:37
1

As the file is a flat file rather than a VSAM cluster of some sort, I'd suggest you read it as an input Extra Partition Transient Data Queue (Extra TDQ).

The data set name can be included in the resource definition but because the data set name cannot be changed using the System Programming Interface, changing to a new data set could be achieved using the CICS ADYN tool but I'd recommend closing and disabling the queue with a SET TDQUEUE command and then replacing it with a CREATE command from within your program.

Alternatively, you could create a new queue for each request using some mechanism to ensure the name is unique within the CICS region, read the queue and then discard the queue again.