Is there a way to obtain file information from inside a cobol program? Specifically, I'm looking to obtain the creation date of the file. I know I can access from inside an assembler program, but wasn't sure if there was a place that Cobol kept that stuff.
Easiest way is, add a Header to the file which contains Creation Date or add another step before Cobol routine executes which puts the creation date into another file and feed that to the Cobol routine.
Easiest way is, add a Header to the file which contains Creation Date or add another step before Cobol routine executes which puts the creation date into another file and feed that to the Cobol routine.
yeah, that's not an option. The file does not originate from programs under our control, so adding the date to the file won't work. The other option would require operator intervention prior to the job running, also not an option.
How would you get it in assembler? Would the same method work for a COBOL program?
In BAL, when you open the file the file information is placed in the file definition area, which can be accessed. I don't know if that can be done in Cobol, which is why I am asking.
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
You could call IDCAMS from within your COBOL program and extract the information that you want from that. Or, if you don't like doing that then run the IDCAMS as a separate step and parse the output as yet another step.
But it is bad design if your dataset (not file) does not have control information on it especially when coming from external sources. There should be no problem raising a change request. In fact, if the auditors knew about it they would probably insist.
The manuals are easily available on this forum and the internet in general. But they should be accessible to you on your intranet.
Thus far, on this forum, I've found other posts where they are actually trying to help the poster with links to the information. Unfortunately, the links are no longer valid, and everyone says that LISTCAT cannot be called.
Joined: 30 Nov 2013 Posts: 917 Location: The Universe
pahiker wrote:
Nic Clouston wrote:
The manuals are easily available on this forum and the internet in general. But they should be accessible to you on your intranet.
Thus far, on this forum, I've found other posts where they are actually trying to help the poster with links to the information. Unfortunately, the links are no longer valid, and everyone says that LISTCAT cannot be called.
Technically, LISTCAT can be called as a TSO command processor, but doing that from Cobol is probably beyond the skill set of a neophyte.
This is the code to get the creation date directly. It's callable from Cobol. I think the routine is Language Environment compatible, though not LE compliant. It's followed by a unit test routine that can run in TSO.
Code:
GETCRDT RSECT
GETCRDT AMODE 31
GETCRDT RMODE ANY
PUSH PRINT
PRINT NOGEN
DSCB DSECT
IECSDSL1 1
DCBD DSORG=QS,DEVD=DA
WA DSECT
DWORK DS D
OPARMS RDJFCB *-*,MF=L
OPARM EQU OPARMS,*-OPARMS
ADCBS DCB DSORG=PS,MACRF=R,DDNAME=FILLMEIN,EXLST=*-*
ADCB EQU ADCBS,*-ADCBS
XLIST DS A
JFCB DS 0XL176
IEFJFCBN ,
CAMLSTS CAMLST SEARCH,*-*,*-*,*-*
CAMLST EQU CAMLSTS,*-CAMLSTS
DSCBAREA DS XL140,0D
WASIZE EQU *-WA
POP PRINT
EJECT
GETCRDT RSECT
USING WA,8
USING IHADCB,ADCB
USING DSCB,DSCBAREA-(DS1FMTID-DSCB)
USING *,9
SAVE (14,12),,'GETCRDT &SYSDATE &SYSTIME'
LR 9,15
LM 2,4,0(1)
LA 7,WASIZE
GETMAIN R,LV=(7)
LR 6,1
LR 8,1
SR 15,15
MVCL 6,14
MVC ADCB,MASTDCB
MVC DCBDDNAM,0(2)
MVC OPARM,MASTOPEN
MVC CAMLST,MASTCAML
LA 0,XLIST
ICM 0,B'1000',DCBEXLST
ST 0,DCBEXLST
LA 0,JFCB
ST 0,XLIST
MVI XLIST,X'80'+7
RDJFCB ADCB,MF=(E,OPARM)
LA 0,4
LTR 15,15
BNZ EXIT
LA 15,JFCBDSNM
LA 0,JFCBVOLS
LA 1,DSCBAREA
STM 15,1,CAMLST+4
SR 0,0
OBTAIN CAMLST
LA 0,8
LTR 15,15
BNZ EXIT
SR 0,0
SR 1,1
IC 0,DS1CREDT
MHI 0,1000
ICM 1,B'0011',DS1CREDT+1
AR 1,0
CVD 1,DWORK
MVC 0(4,3),DWORK+4
SR 0,0
EXIT ST 0,0(,4)
LA 0,WASIZE
FREEMAIN R,LV=(0),A=(8)
RETURN (14,12)
PUSH PRINT
PRINT NOGEN
MASTOPEN RDJFCB *-*,MF=L
MASTDCB DCB DSORG=PS,MACRF=R,DDNAME=FILLMEIN,EXLST=*-*
MASTCAML CAMLST SEARCH,*-*,*-*,*-*
POP PRINT
DC 0D'0'
END
TEST CSECT
USING *,12
SAVE (14,12),,*
LR 12,15
LA 15,SAVEAREA
ST 13,4(,15)
ST 15,8(,13)
LR 13,15
CALL GETCRDT,(DDNAME,CRDT,RC)
L 15,RC
CVD 15,64(,13)
UNPK LRC,64(8,13)
OI LRC+L'LRC-1,X'F0'
UNPK LCRDT,CRDT
OI LCRDT+L'LCRDT-1,X'F0'
LA 0,L'MSG
LA 1,MSG
TPUT (1),(0),R
L 13,4(,13)
RETURN (14,12),T,RC=0
SAVEAREA DC 9D'0'
RC DC F'0'
CRDT DC PL4'0'
MSG DC 0C'DDNAME=DDDDDDDD RC=NN CREDT=CYYDDD',C'DDNAME='
DDNAME DC CL8'SYSHELP',C' RC='
LRC DC C'NN',C' CREDT='
LCRDT DC C'CYYDDD',0D'0'
END TEST
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
IGGCSI00 can be called from COBOL and DSCRDT2 is the field name for the create date. The format requires some conversion to get a usable date but the manual describes the format quite well. Googling iggcsi00 cobol returns about 335 results and one of them has sample COBOL code.
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
I never mentioned calling LISTCAT - I said IDCAMS. The links to the manuals are not invalid - I have just successfully navigated to the COBOL llanguge reference manual although I did not spot the AMS (iei IDCAMS) manual there so you would have to try the IBM documentation site.
Thanks everyone. I got CSI working, but it is a bit of coding. I tried looking for DSINFO, as Rohit suggested, but every link I come up with from IBM.01 goes to "bad link" pages, I'm guessing that they are no longer supporting the call? Haven't found anyone who posted actual code on using it.