Link to home
Start Free TrialLog in
Avatar of RajAntonyV
RajAntonyV

asked on

Reading From A File

Hi,

I have been trying to work on a project that requires me to read a file with information in it.  After reading the file, I am going to process the data and then write an output text file.  Now the file that I am working on as an input is not in any particular format.  But I do have the definitions for the mainframe extract. It is not delimited and also one row can go over a line; while some lines are only on one line...

Example:

AS030210034RESERVESIE01212003322       322       N    0000000FD0121200305565501212003055655012120030557080121200306000501212003060332              01212003061226      T390  5008            73K   02288052  06951549  FW           2905 DERRICK DR                                    NE23   E23   E23                           (MOVADO TR & GUNTHER)                               100NY001                                  

I have been trying to work on this and pretty much pulled out most of my hair; if not all of it.  

Any help is appreciate and thanks in advance for all your help,

Raj Antony V
Avatar of aeklund
aeklund

Can you define which parts of the file you want broken down info fields.. also are those spaces or tabs seperating each field?
Avatar of RajAntonyV

ASKER

Lets say hypothetically, I wanted the only the ones that had the asterick next to them.  Also, another thing of importance is that:

1.  I haven't seen a row delimiter on the extract.  So I don't know where to stop on extracting.  I was hoping the fields that started with "FI" designate that as a new line...

2.  I haven't seen any tabs or spaces as a column delimiter either.  Only have the field defintions to work with.  Is it possible to reach character to character or lets say from character 10 to character 12 in VB?

I have been trying to read the file as binary file access and haven't had any luck on it yet...

Sample field definitions are listed below.  If you need all of it please let me know...

01  TSFR-CALL-SEGMENT.
           02  TSFR-CALL-DATA-REC.
*************** 04  TSFR-CALL-SEG-TYPE      PIC XX.
                 88  TSFR-FDES               VALUE 'FI'.
                 88  TSFR-PILC-HDR           VALUE 'PI'.
                 88  TSFR-PILC-CALL          VALUE 'PS'.
                 88  TSFR-PILC-TRLR          VALUE 'PU'.
                 88  TSFR-EMC                VALUE 'EI'.
             04  TSFR-CALL-DATA-AREA.
               06  TSFR-CALL-NR          PIC X(9).
               06  TSFR-CALL-AGENCY.
**************  08  TSFR-CALL-AGEN      PIC X.
                    08  TSFR-CALL-AGTYPE    PIC X.
               06  TSFR-CALL-DAREA       PIC X(4).
               06  TSFR-CALL-HDAREA      PIC X(4).
               06  TSFR-CALL-INC-DATE    PIC X(8).
               06  TSFR-CALL-ORIG-CALL   PIC X(10).
************** 06  TSFR-CALL-NBR-TYPE    PIC X(10).
               06  TSFR-CALL-911         PIC X.
               06  TSFR-CALL-JURISC      PIC XX.
               06  TSFR-CALL-DR.
                 08  TSFR-CALL-DR-YR     PIC XX.
                 08  TSFR-CALL-DR-NBR    PIC 9(7).
               06  TSFR-CALL-JURISC      PIC XX.
               06  TSFR-CALL-RC-DATE     PIC X(8).
************** 06  TSFR-CALL-RC-TIME     PIC X(6).
               06  TSFR-CALL-ET-DATE     PIC X(8).
               06  TSFR-CALL-ET-TIME     PIC X(6).
               06  TSFR-CALL-DI-DATE     PIC X(8).
               06  TSFR-CALL-DI-TIME     PIC X(6).
               06  TSFR-CALL-EN-DATE     PIC X(8).
               06  TSFR-CALL-EN-TIME     PIC X(6).
               06  TSFR-CALL-OK-DATE     PIC X(8).

Thanks and appreciate all your help.
2) Yes you can do from char to char.. use the mid$() function, which you can specify the start, and length... so from char 10 to 12 would be mid$(string, 10, 2)

In order to successfully parse this file, you have to find something in common for the data you want to grab.  Either where it starts, a tab before, a new line char, etc... then you can start parsing it...
How are the records written to the file? Are they not perhaps fixed length records?

Email me the sample file and i'll code up some script for it. but you must let me know what fields are needed and what rules apply for those fields.

Hello,

The sample records are a mainframe dump that is being FTPed to a new location, from where it must processed using VB, and then inserted into a SQL Server database.

All I have the the field defintion or what I got from the guy as the field definitions.  But I am not sure how to determine when the end of line occurs...  One thing I had to go on is maybe target the "DI" or "FI" as the beginning of a new line.

Sample File From MainFrame Data

DI030210039FFFIREFIRE01212003112       112       N    0000000FD0121200306270901212003062814012120030628250121200306300901212003063403              01212003063635      P394 2304            48R   02330980  06985684  FW           4701 GOLD SPIKE DR                               NK24   K23   Q26                           (MALCOLM BL & TAILHEAD)                 B13          3 1N 0 1                                 040950040950JOHNB/////SWDISP                                                                                                        345 567 78
FD030210039FF01212003112       00000000TAILD   00101349003062814040950RIS2             000   TEXT:CONSEFS///GENERAL \COMP:BUBBA/////SEDISP \PH:874 457 9847

02  TSFR-CALL-DATA-REC.
              ***04  TSFR-CALL-SEG-TYPE      PIC XX.
                 88  TSFR-KEIR               VALUE 'FI'.
                 88  TSFR-LKE9-HDR           VALUE 'DI'.
                 88  TSFR-KE84-CALL          VALUE 'PS'.
                 88  TSFR-MDKE-TRLR          VALUE 'PU'.
                 88  TSFR-EMS                VALUE 'EI'.
             04  TSFR-CALL-DATA-AREA.
            ***06  TSFR-CALL-NR          PIC X(9).
               06  TSFR-CALL-AGENCY.
                 08  TSFR-CALL-AGEN      PIC X.
              ***08  TSFR-CALL-AGTYPE    PIC X.
               06  TSFR-CALL-DAREA       PIC X(4).
               06  TSFR-CALL-HDAREA      PIC X(4).
               06  TSFR-CALL-INC-DATE    PIC X(8).
               06  TSFR-CALL-ORIG-CALL   PIC X(10).
               06  TSFR-CALL-NBR-TYPE    PIC X(10).
            ***06  TSFR-CALL-800         PIC X.
               06  TSFR-CALL-JURISC      PIC XX.
               06  TSFR-CALL-DR.
                 08  TSFR-CALL-DR-YR     PIC XX.
                 08  TSFR-CALL-DR-NBR    PIC 9(7).
            ***06  TSFR-CALL-JURISC      PIC XX.
               06  TSFR-CALL-RC-DATE     PIC X(8).
               06  TSFR-CALL-RC-TIME     PIC X(6).
            ***06  TSFR-CALL-ET-DATE     PIC X(8).
            ***06  TSFR-CALL-ET-TIME     PIC X(6).
               06  TSFR-CALL-DI-DATE     PIC X(8).
               06  TSFR-CALL-DI-TIME     PIC X(6).
               06  TSFR-CALL-EN-DATE     PIC X(8).
               06  TSFR-CALL-EN-TIME     PIC X(6).
               06  TSFR-CALL-OK-DATE     PIC X(8).
               06  TSFR-CALL-OK-TIME     PIC X(6).
               06  TSFR-CALL-AR-DATE     PIC X(8).
               06  TSFR-CALL-AR-TIME     PIC X(6).
               06  TSFR-CALL-CL-DATE     PIC X(8).
               06  TSFR-CALL-CL-TIME     PIC X(6).
               06  TSFR-CALL-DISPO       PIC X(6).
               06  TSFR-CALL-RD          PIC X(6).
               06  TSFR-CALL-FD          PIC X(8).
               06  TSFR-CALL-ED          PIC X(8).
               06  TSFR-CALL-MAP.
                 08  TSFR-CALL-MAP-PAGE  PIC X(4).
                 08  TSFR-CALL-MAP-X     PIC X.
                 08  TSFR-CALL-MAP-Y     PIC X.
               06  TSFR-CALL-MAP-COORDS.
                 08  TSFR-CALL-COORD-X   PIC X(10).
                 08  TSFR-CALL-COORD-Y   PIC X(10).
               06  TSFR-CALL-CITY        PIC X(13).
               06  TSFR-CALL-LOC         PIC X(40).
               06  TSFR-CALL-APT         PIC X(7).
               06  TSFR-CALL-AREA        PIC XX.
               06  TSFR-CALL-GEO-FLAG    PIC X.
               06  TSFR-CALL-PUNIT       PIC X(6).
               06  TSFR-CALL-OFF1        PIC X(6).
               06  TSFR-CALL-OFF2        PIC X(6).
               06  TSFR-CALL-OFF3        PIC X(6).
               06  TSFR-CALL-OFF4        PIC X(6).
               06  TSFR-CALL-OFF5        PIC X(6).
               06  TSFR-CALL-OFF6        PIC X(6).
               06  TSFR-CALL-CROSS       PIC X(40).
      * TSFR-CALL-BEAT 4 DIGITS PER STEVE GILLOW 11/12/2002
               06  TSFR-CALL-BEAT        PIC X(4).
               06  TSFR-CALL-DUPE-TO     PIC X(9).
               06  TSFR-CALL-PRIORITY    PIC X.
               06  TSFR-CALL-IN-PROG     PIC X.
               06  TSFR-CALL-PRIOR       PIC X.
               06  TSFR-CALL-ACT-CU      PIC X.
               06  TSFR-CALL-PH-FLAG     PIC X.
               06  TSFR-CALL-OS-FLAG     PIC X.
               06  TSFR-CALL-OV-FLAG     PIC X.
               06  TSFR-CALL-ALRM-LVL    PIC X.
               06  TSFR-CALL-XREF.
                 08  TSFR-CALL-FIRE      PIC X(11).
                 08  TSFR-CALL-LAW       PIC X(11).
                 08  TSFR-CALL-EMS       PIC X(11).
               06  TSFR-CALL-ENT-DID     PIC X(6).
               06  TSFR-CALL-DISP-DID    PIC X(6).
               06  TSFR-CALL-REPORTING-PARTY.
                 08  TSFR-CALL-NAM       PIC X(72).
                 08  TSFR-CALL-ADR       PIC X(50).
                 08  TSFR-CALL-PHON      PIC X(10).
                 08  TSFR-CALL-ORIGIN    PIC X(6).

Thanks for all your help and please let me know if you need anything else...

Raj Antony V
     
SOLUTION
Avatar of aeklund
aeklund

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GrahamSkan
They are fixed-width records without a delimiter. The field lengths are contained in the brackets following the PIC X, or the number of Xs if there are no brackets.
The '88' (constants) have an implicit length from their defined values.
You could use the 88 values to find the beginning of the record, but I think that you should just use this as a check against your calculations.
Note: If it's not 88, the first number on the line denotes a hierarchy level. The field size is only defined at the lowest level.

I'd be tempted to create a user type from the definition file by it into the declarations section of a module. Toy could replace the 'PIC(' with 'As String *',  the ')' with nothing and the '-' as '_'. I've done a bit of it so:
Type CobolRecord
    TSFR_CALL_DAREA       As String * 4
    TSFR_CALL_HDAREA      As String * 4
    TSFR_CALL_INC_DATE    As String * 8
    TSFR_CALL_ORIG_CALL   As String * 10
    TSFR_CALL_NBR_TYPE    As String * 10
End Type

This will ensure that you can define a variable as this type
Dim cr as CobolRecord
 
'Open the file in binary mode and to use the Get statement:

Do Until EOF(f)
  Get #f,,cr
  HDarea = cr.TSFR_CALL_HDAREA
loop
     
Sorry, I was a bit misleading about the 88 values.
The 88 values are permitted alternatives, used here to define the record type. The length is in the actually define at the 04 level above, so you might want your programme to check that each record begins with one of the 5 values specified.
Hello

The problem with doing that is there is differences in the length and definitions between the first line and the next line. See the first line is longer than the second line and they have a different definition compared to the first line.

DF030210034GGGGGGGGGG01212003322       322       N    0000000FD0121200305565501212003055655012120030557080121200306000501212003060332              01212003061226      T390  5008            73K   02288052  06951549  FW           2905 DEREK DR                                    NE23   E23   E23                           (Throckmorton TR & James)                               100NY001
FS030210034GG01212003322       00000000DISPATCH00301412003055708040950TDSE             000   E23,

FU030210034FFE23   E23   E23                           012120030557080121200306000501212003060332                                          01212003061120              01212003061120                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                N
                                 
Right now, when I use a "Line Input#" it reads the different lines as a single line; starting with the first line and going all the way to end of the last line.

I don't think it is seeing the end of line for each line and reading them as separate lines.  There is supposed to be an end of line character ({CL}{RF}) ( I believe) for each line when mainframe dumps it.

Anyway, any help is appreciated and thanks in advance for your help,

Raj Antony V

 
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi RajAntonyV,
This old question (QID 20553792) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
This question has been classified as abandoned.  I will make a recommendation to the moderators on its resolution in a week or two.  I would appreciate any comments by the experts that would help me in making a recommendation.
It is assumed that any participant not responding to this request is no longer interested in its final deposition.

If the asker does not know how to close the question, the options are here:
https://www.experts-exchange.com/help/closing.jsp

GPrentice00
Cleanup Volunteer
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

 -->Split between aeklund and CD-Softy and GrahamSkan

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER

GPrentice00
Cleanup Volunteer