Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting Data from COBOL produced .DAT file

Status
Not open for further replies.

doktord

Technical User
Sep 26, 2006
24
US
Hey guys,

I'm working on a program to run in conjunction with some software that was written in COBOL. The software produces and stores information in .DAT and .KEY files located on a server.

I need to access the data stored in these files to use with a program I'm writing in VB.

I've been searching around the forums and there really aren't too many threads out there about decrypting .DAT files and even fewer are able to successfully do it.

I've tried just simply opening the .DAT files in notepad and all I get are random numbers and symbols. I also tried opening the files in a free trial of DataViewer, which worked to a certain extent but still butchered some of the data.

I can provide pretty much any information that would be helpful in figuring this out. I can provide files to tinker with, some small programs, and I'm waiting to hear back from the software people as to what compiler was used to compile the COBOL program that makes the .DAT files.

I really appreciate your time and patience. I'm just a moderate level (if that) hobby programmer trying to get this program to work in conjunction with this software.
 
doktord, you cant read the indexed file via an fd. Look up the MF COBOL routine "FHREDIR". This routine reads their indexed format. However, it comes with a couple of parameters that are not intuitively obvious. The first is one byte hex value indicating the type of read we want to perform.

*
* OP CODES for the file handler
*
78 FHOP-FA VALUE X"fa".
78 FHOP-00 VALUE X"00".
78 FHOP-OPEN-I VALUE X"00".
78 FHOP-OPEN-O VALUE X"01".
78 FHOP-INFO VALUE X"06".
78 FHOP-DELETE VALUE X"F7".
78 FHOP-OPEN-I-O VALUE X"02".
78 FHOP-CLOSE VALUE X"80".
78 FHOP-WRITE VALUE X"F3".
78 FHOP-REWRITE VALUE X"F4".
78 FHOP-READ-RANDOM VALUE X"F6".
78 FHOP-READ-NEXT VALUE X"F5".
78 FHOP-STEP-NEXT VALUE X"CA".
78 FHOP-START-BROWSE VALUE X"EB".

The second parameter is a lenghty file control definition parameter block. It would be documented in the Micro Focus docs. Good luck!! It took us a while to figure this one out.

*>*********************************************************
*> Uninitialised FCD definition for Callable File Handler *
*>*********************************************************
*>
05 FCD-FILE-STATUS.
10 FCD-STATUS-KEY-1 PIC X.
10 FCD-STATUS-KEY-2 PIC X.
10 FCD-BINARY REDEFINES FCD-STATUS-KEY-2
PIC 99 COMP-X.
05 FCD-LENGTH pic xx comp-x.
05 FCD-VERSION pic x comp-x.
78 fcd--version-number value 0.

05 FCD-ORGANIZATION PIC 9(2) COMP-X.
05 FCD-ACCESS-MODE PIC 9(2) COMP-X.
05 FCD-OPEN-MODE PIC 9(2) COMP-X.
05 FILLER PIC X(2).
05 FCD-BLOCK-SIZE PIC 9(2) COMP-X.
05 FCD-NAME-LENGTH PIC 9(4) COMP-X.
05 FCD-RELADDR-BIG PIC X(8) COMP-X.
05 redefines fcd-reladdr-big.
07 fcd-device-flag pic x comp-x. *> x"0d"
78 dev-normal value 0.
78 dev-device value 1.
78 dev-stdin value 2.
78 dev-stdout value 3.
78 dev-stderr value 4.
78 dev-badname value 5.
78 dev-input-pipe value 6.
78 dev-output-pipe value 7.
78 dev-i-o-pipe value 8.
78 dev-library value 9.
78 dev-disk-file value 10.
78 dev-null value 11.
78 dev-disk-redir value 12.
78 dev-no-map value 13.

07 fcd-idxname-length pic xx comp-x. *> x"0e"
07 fcd-index-name usage pointer. *> x"10"
05 FILLER PIC X.
05 FCD-TRANS-LOG PIC 9(2) COMP-X.
05 FILLER PIC X(1).
05 FCD-LOCK-MODE PIC 9(2) COMP-X.
05 FCD-OTHER-FLAGS PIC 9(2) COMP-X.
05 FILLER PIC X(2).
05 FCD-HANDLE USAGE POINTER.
05 FCD-HANDLE-NUM REDEFINES FCD-HANDLE
PIC X(4) COMP-X.
05 FCD-PERCENT PIC 9(2) COMP-X.
05 FCD-REC-COUNT-SET REDEFINES FCD-PERCENT
PIC 9(2) COMP-X.
05 FCD-STATUS-TYPE PIC 9(2) COMP-X.
05 FCD-FILE-FORMAT PIC 9(2) COMP-X.
05 FILLER PIC X(3).
05 FCD-MAX-REC-LENGTH PIC 9(4) COMP-X.
05 FILLER PIC X(2).
05 FCD-MVS-FLAGS PIC 9(2) COMP-X.
05 FCD-RELATIVE-KEY PIC 9(9) COMP-X.
05 FCD-RECORDING-MODE PIC 9(2) COMP-X.
05 FCD-CURRENT-REC-LEN PIC 9(4) COMP-X.
05 FCD-MIN-REC-LENGTH PIC 9(4) COMP-X.
05 FCD-KEY-ID PIC 9(4) COMP-X.
05 FCD-LINE-COUNT REDEFINES FCD-KEY-ID
PIC 9(4) COMP-X.
05 REDEFINES FCD-KEY-ID.
10 FCD-USE-FILES PIC X COMP-X.
10 FCD-GIVE-FILES PIC X COMP-X.
05 FCD-KEY-LENGTH PIC 9(4) COMP-X.
05 FCD-RECORD-ADDRESS USAGE POINTER.
05 FCD-FILENAME-ADDRESS USAGE POINTER.
05 FCD-KEY-DEF-ADDRESS USAGE POINTER.
05 FCD-COL-SEQ-ADDRESS USAGE POINTER.
05 FCD-RELADDR-OFFSET PIC 9(9) COMP-X.
05 FCD-RELADDR REDEFINES FCD-RELADDR-OFFSET
PIC 9(9) COMP-X.
05 FCD-FILDEF-ADDRESS REDEFINES FCD-RELADDR-OFFSET
USAGE POINTER.
05 FCD-NLS-ID PIC 9(4) COMP-X.
05 FCD-DATA-COMPRESS PIC 9(2) COMP-X.
05 FCD-SESSION-ID PIC 9(9) COMP-X.
05 FCD-FS-FILE-ID PIC 9(4) COMP-X.
05 FCD-MAX-REL-KEY PIC 9(9) COMP-X.
05 FCD-FLAGS-1 PIC 99 COMP-X.
05 FCD-BLOCKING PIC 99 COMP-X.
05 FCD-additional-status redefines FCD-blocking
pic x comp-x.
05 FCD-LOCKTYPES PIC 99 COMP-X.
05 FCD-FS-FLAGS PIC 99 COMP-X.
05 FCD-CONFIG-FLAGS PIC 99 COMP-X.
05 FCD-MISC-FLAGS PIC 99 COMP-X.
05 FCD-CONFIG-FLAGS2 PIC 99 COMP-X.
05 FCD-IDXCACHE-SIZE PIC 99 COMP-X.
05 FCD-IDXCACHE-BUFFS PIC 99 COMP-X.
05 FCD-internal-flags-1 pic x comp-x.
05 FCD-internal-flags-2 pic x comp-x.
 
Thanks for the replies, I appreciate it. I'll definitely take a good hard look at the info in the last post.

I'll also try to compile the code again to tell you what the errors were, webrabbit.

I was gone all weekend so I was a little slow to reply to the posts.
 
Do you have the Micro Focus runtime system or just the compiler? If you have the run time system, then it would come with a utility to take the indexed file and convert it to a sequential format.
 
I'm using Micro Focus Net Express 5.0 in conjunction with Visual Studio 2005.
 
A starting point to convert COMP-3 values in basic:

Speaking of this, this reminds me of the DLL I linked to in a post above. Is there any interest in it or a need to develop it any further?

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
doktord,

Net Express 5.0 has a tool to convert indexed files. It is under the Tools / Data Tools / Convert. This will convert an indexed file into a sequential file format. We only use Micro Focus format indexed files, it recognizes that it is that type of input file. I don't remember if it is another type of indexed file, it you can specify the input type. You might try it and see.
 
Just a thought.

Have you given any consideration to opening your Cobol data with an ODBC link. This way, you could just process the data inside you VB program with simple SQL statements.

Here is a link to ODBC connection from Micro Focus

Good Luck,
Hap...

Access Developer [pc] Access based Accounting Solutions - with free source code
Access Consultants forum
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top