× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Here's a sample COBOL program that uses the stat API to access file
information. The path is passed as a parameter and can be up to 32 bytes
in length (as written). You could certainly use larger parameters, but I
was testing from the command line...

If you know the file names in advance you could also just hardcode them.
In that case you could also use the z literal type.

To compile CRTBNDCBL STAT BNDDIR(QC2LE)

PROCESS NOMONOPRC NOSTDTRUNC.

IDENTIFICATION DIVISION.
* CRTBNDCBL BNDDIR(QC2LE)
PROGRAM-ID. CBLSTAT.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 Path-Name PIC X(33).

01 Stat-Buffer.
05 Stat-Mode PIC 9(9) BINARY.
05 File-ID PIC 9(9) BINARY.
05 Number-Links PIC 9(4) BINARY.
05 Filler PIC 9(4) BINARY.
05 UID PIC 9(9) BINARY.
05 GID PIC 9(9) BINARY.
05 Stat-Size PIC S9(9) BINARY.
05 Access-Time PIC S9(9) BINARY.
05 Content-Change-Time PIC S9(9) BINARY.
05 Status-Change-Time PIC S9(9) BINARY.
05 File-System-ID PIC 9(9) BINARY.
05 Block-Size PIC 9(9) BINARY.
05 Allocated-Size PIC 9(9) BINARY.
05 Object-Type PIC X(11).
05 Code-Page PIC 9(4) BINARY.
05 CCSID PIC 9(4) BINARY.

01 Return-Value PIC S9(9) BINARY.
01 Errno-Pointer POINTER.
01 Message-Wait PIC X(01).

LINKAGE SECTION.
01 Path-Parameter PIC X(32).
01 Errno PIC S9(9) BINARY.

PROCEDURE DIVISION USING Path-Parameter.
MAIN-LINE.
STRING FUNCTION TRIMR(Path-Parameter)
x"00"
DELIMITED BY SIZE
INTO Path-Name.
CALL LINKAGE PRC "stat" USING
BY REFERENCE Path-Name,
BY REFERENCE Stat-Buffer,
RETURNING Return-Value.
IF Return-Value = -1
* File not found
CALL LINKAGE PRC "__errno" RETURNING Errno-Pointer
SET ADDRESS OF Errno TO Errno-Pointer
DISPLAY "Failure " Errno " on stat"
ELSE
* File found
DISPLAY Object-Type " found."
END-IF
ACCEPT Message-Wait
STOP RUN.

My testing was not extensive. It consisted of:

call stat '/binary' for a *stmf that did exist
call stat '/nothere' for a *stmf that did not exist
call stat '/QIBM' for a *dir that did exist
call stat '/qsys.lib/vining.lib/a.file' for a file that didn't exist
call stat '/qsys.lib/vining.lib/b.file' for a file that did exist

Hope you find this useful,
Bruce Vining




"Adrienne McConnon" <Adrienne.McConnon@xxxxxxxxxxxx>
Sent by: cobol400-l-bounces@xxxxxxxxxxxx
04/17/2007 09:11 AM
Please respond to
COBOL Programming on the iSeries/AS400 <cobol400-l@xxxxxxxxxxxx>


To
<cobol400-l@xxxxxxxxxxxx>
cc

Subject
[COBOL400-L] COBOL - list stream files/list library files/no spool






Hello,

We have a problem that is occurring in our 'sleeper' process.
Basically, this program runs continuously, checking for the existance of
files within the COBOL program. It is currently calling a CL that does
a DSPLNK to check for the existence of a stream file or a library file.
Depending on what it finds, it proceeds to process - whatever. The
problem is that, apparently, there is a limit as to the number of spool
files that gets created from a job. AZnd even though this process is
cleaning up the spool files, as needed, it still aborts at a certain
point.

Option 1 - Ideally, we would like to not create a spoolfile at all, but
list the results of the DSPLNK to a flat file. As far as we know, the
results must go to spool or screen, which is not an option either, since
there is no support staff to moniter screen results. If anyone knows
how to direct DSPLNK command results to a flat file and suppress the
create spool file option when calling this from a COBOL program, that
would be great!!!!

Option 2 - maybe we have not researched methods of displaying both
library and stream files from within a COBOL program - does anyone have
any suggestions here? Of course, creating a spool file needs to be
suppressed or eventually the limit will occur.

Option 3 - We are considering teaching the program to turn itself on and
off - our mastermind is currently researching this option, but this may
be a roundabout way to resolve this issue - I'd like to learn how to
best resolve the spoolfile creation issue or list file to flat file
issue.

Any comments or suggestions would be appreciated -

Have a great day!

Adrienne McConnon

Vercuity - Parsippany - NJ

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.