View previous topic :: View next topic |
Author |
Message |
Beswar Beginner
Joined: 04 Feb 2003 Posts: 33 Topics: 15
|
Posted: Tue May 11, 2004 10:00 am Post subject: finding whether the file is empty or not |
|
|
Hi All,
Is there any way to find whether file empty or not in the COBOL program. I mean without opening the file and read. Is there any utility like IDCAMS any other utlities that will find whehter the file is empty or not. If any thing is there can I call the utility in the program to find status of the file.
Thanks
Eswar |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Tue May 11, 2004 10:05 am Post subject: |
|
|
Beswar,
Yes it is possible to call IDCAMS from cobol but that would involve a lot of overhead. It would be simple to open and read the file and check if it is empty. All this takes is just 2 statements.
Another alternative is to check the file if it empty upfront , before you execuete your cobol program. Take a look at my post in this topic for various examples of checking an empty file.
http://www.mvsforums.com/helpboards/viewtopic.php?t=1285&highlight=empty
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
Beswar Beginner
Joined: 04 Feb 2003 Posts: 33 Topics: 15
|
Posted: Tue May 11, 2004 10:19 am Post subject: |
|
|
Kolusu,
Thanks for your the reply. But currently we already calling the IDCAMS through our program and this is usefull to copy all the files into one file. But when we call the IDCAMS I really don't know how to get the return code to find whether the file is empty. Do you know what is the layout of the i need to create to get the return code into the COBOL program.
Thanks
Eswar |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Tue May 11, 2004 3:16 pm Post subject: |
|
|
Beswar,
There is no special layout to get the return-code from IDCAMS. Here is a sample of program which will check if the file is empty by invoking IDCAMS. Even though I am providing the solution, this approach seriously needs a re-design. I am confused as to why you want to take long route instead of 3 statements(open read & close) which is fairly simple. I would like to know your justification of using this approach.
Code: |
CBL DATA(24)
IDENTIFICATION DIVISION.
PROGRAM-ID. CALLDCAM
DATE-COMPILED.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT IDCAMS-FILE
ASSIGN TO IDCOMND
ORGANIZATION IS SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD IDCAMS-FILE
RECORDING MODE IS F
LABEL RECORDS ARE STANDARD
BLOCK CONTAINS 0 RECORDS
DATA RECORD IS IDCAMS-REC.
01 IDCAMS-REC PIC X(80).
WORKING-STORAGE SECTION.
01 WS-FILE-NAME PIC X(44) VALUE SPACES.
01 WS-DYN-MODULE PIC X(08) VALUE 'IDCAMS'.
01 WS-COMMAND-REC PIC X(80) VALUE SPACES.
01 PARM-OPTIONS.
05 PARM-LENGTH PIC S9(04) COMP VALUE 0.
01 DD-OPTIONS.
05 DD-LENGTH PIC S9(04) COMP VALUE +48.
05 FILLER PIC X(32) VALUE LOW-VALUES.
05 SYSIN-DD PIC X(08) VALUE 'IDCOMND'.
05 SYSPRINT-DD PIC X(08) VALUE 'SYSOUT'.
PROCEDURE DIVISION.
OPEN OUTPUT IDCAMS-FILE
MOVE 'YOUR EMPTY FILE TO CHECK' TO WS-FILE-NAME
STRING
' PRINT IDS(' DELIMITED BY SIZE
QUOTE DELIMITED BY SIZE
WS-FILE-NAME DELIMITED BY SPACE
QUOTE DELIMITED BY SIZE
') CHARACTER COUNT(1)' DELIMITED BY SIZE
INTO WS-COMMAND-REC
END-STRING.
WRITE IDCAMS-REC FROM WS-COMMAND-REC
CLOSE IDCAMS-FILE
CALL WS-DYN-MODULE USING PARM-OPTIONS, DD-OPTIONS
EVALUATE RETURN-CODE
WHEN 0
DISPLAY ' THE FILE HAS ATLEAST 1 RECORD'
WHEN 4
DISPLAY ' THE FILE IS EMPTY'
WHEN 12
DISPLAY ' THE FILE IS NOT IN CATALOG'
DISPLAY ' CHECK THE FILE NAME'
WHEN OTHER
DISPLAY ' CATASTROPHIC ERROR'
END-EVALUATE
GOBACK
.
|
The JCL to run this program is below. pay attention to the IDCOMND ddname in the program
Code: |
//STEP0100 EXEC PGM=CALLDCAM
//STEPLIB DD DSN=YOUR PGM LOADLIB,
// DISP=SHR
// DD DSN=SYS1.LINKLIB,
// DISP=SHR
//IDCOMND DD DSN=USERID.COMMAND.FILE,
// DISP=(NEW,CATLG,DELETE),
// UNIT=SYSDA,
// SPACE=(TRK,(1,1),RLSE)
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
/*
|
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
mf_user Intermediate
Joined: 01 Jun 2003 Posts: 372 Topics: 105
|
Posted: Tue Feb 21, 2006 9:15 am Post subject: |
|
|
Hi,
This is simply superb. Would you please let me know why do we use
PARM-LENGTH though there is no linkage section in the program. _________________ MF
==
Any training that does not include the emotions, mind and body is incomplete; knowledge fades without feeling.
== |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
|
Back to top |
|
|
mf_user Intermediate
Joined: 01 Jun 2003 Posts: 372 Topics: 105
|
Posted: Tue Feb 21, 2006 9:58 am Post subject: |
|
|
Thanks for the link Kolusu. I think it is bit advance for the beginner like me... _________________ MF
==
Any training that does not include the emotions, mind and body is incomplete; knowledge fades without feeling.
== |
|
Back to top |
|
|
|
|