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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Scan for CR control chars 2

Status
Not open for further replies.

SiouxCityElvis

Programmer
Jun 6, 2003
228
US
Hi,

I'm using RMCOBOL-85 and I need to learn how to tell when I've run into a ^L(carriage return?) control character. I found the EBSIDIC/ASCII table in my manual but am lost as far as the approach to scanning each line.

I'm reading in a checkprint file that is put into a queue for me originating from QuickBooks.

I need to set a flag indicating when I've hit a new employee(Below 2 employees in example).

I need to set a flag indicating when I've got the amount line and the amount is found.

I need to set a flag indicating when I've got the SSN field.

I need to set a flag indicating when I've started a new pay stub(1st rec no ^L in the beginning, 2nd employee I can set this flag based off fact I've got a ^L)

This last flag, concerning the ^L, is the one I have not idea how I'll set. INSPECT?

Any ideas? Thanks.
-David
An example of a file is:

Code:
^M




                                                                     7/30/2004^M


           Bob Smith                                         **214.49^M

     Two Hundred Fourteen and 49/100**************************************^M

          Bob E. Smith^M
          c/o Blah^M
          99999 blah blah Road^M
          blah, TX 99999^M

        07/16/2004 - 07/31/2004 Pay Peri^M





      Bob E. Smith                                 7/30/2004          YTD^M
      c/o Herring Ranch      Blah blah Salary       232.26     8,032.26^M
      99999 BLah blah Ro Social Security Employ       -14.40      -498.00^M
      Blah, TX 99999     Medicare Employee             -3.37      -116.47^M
                             Federal Income Tax Wit         0.00      -299.00^M
      999-99-9999^M

      Blah blah Ranch^M
      P. O. Box 0000^M
      blah, TX  99999^M







                        07/16/2004 - 07/31/2004 Pay       214.49^M



      BOb E. Smith                                 7/30/2004          YTD^M
      c/o Blah Ranch      Blah blah blah Salary       232.26     8,032.26^M
      99999 BLah Ranch Ro Social Security Employ       -14.40      -498.00^M
      Blah, TX 79083     Medicare Employee             -3.37      -116.47^M
                             Federal Income Tax Wit         0.00      -299.00^M
      999-99-9999^M

      Blah Blah Ranch^M
      P. O. Box 0000^M
      Blah, TX  00000^M







                        07/16/2004 - 07/31/2004 Pay       214.49^L^M




                                                                     7/30/2004^M


           John Doe                                             **120.06^M

     One Hundred Twenty and 06/100****************************************^M

          John Doe^M
          99999 Blah Ranch Road^M
          Blah, TX 99999^M


        07/16/2004 - 07/31/2004 Pay Peri^M





      John Doe                                   7/30/2004          YTD^M
      99999 Blah Ranch Ro Blah-BLah Salary       130.00       580.00^M
      Blah, TX 99999     Social Security Employ        -8.06       -35.96^M
                             Medicare Employee             -1.88        -8.41^M
      999-99-9999^M

      Blah Blah Ranch^M
      P. O. Box 0000^M
      Blah, TX  99999^M








                        07/16/2004 - 07/31/2004 Pay       120.06^M



      John Doe                                   7/30/2004          YTD^M
      99999 Blah Ranch Ro Blah-Blah Salary       130.00       580.00^M

      Blah, TX 99999     Social Security Employ        -8.06       -35.96^M
                             Medicare Employee             -1.88        -8.41^M
      999-99-9999^M

      Blah Blah Ranch^M
      P. O. Box 0000^M
      Blah, TX  99999^M








                        07/16/2004 - 07/31/2004 Pay       120.06^L^M

 
First of all, ^L is a form-feed, not a carriage-return. Its code is X"0C". Those ^M's in the example file are the carriage-returns.

Second, depending on the implementation in your COBOL system, the program may never "see" the form-feed. It may be removed by the input processing code.

If the form-feed is not removed, it is likely to be in the first byte of the line. If that is the case, simply check for INPUT-RECORD(1:1) = X"0C".
 
A direct answer to your question appears below. Have you considered an alternative solution? There appear to be several QuickBooks import/export solutions, including one that is free. Perhaps it would be more reliable if you were exporting data from QuickBooks in XML format and then using the RM/COBOL XML Toolkit to bring the data into your application.

Now, in the ENVIRONMENT DIVISION:
Code:
  SPECIAL-NAMES.
      SYMBOLIC CHARACTER FORM-FEED IS 13.

In PROCEDURE DIVISION:
Code:
      MOVE 0 TO FF-COUNT.
      INSPECT INPUT-LINE TALLYING FF-COUNT FOR ALL FORM-FEED.
      IF FF-COUNT > 0
          <process CTRL-L found>
      END-IF.

Tom Morrison
 
Thanks all.

I will use your suggestions and see what I can come up with.

As far as doing things with XML export out of QuickBooks, that sounds great.

Is the XML ToolKit with RMCOBOL included in the default setup/install?

Thanks.
-David
 
Aw, webrabbit, you were doing so well, too....

webrabbit is correct about the possibility of the COBOL file system consuming the form feed (and line feed) characters before you ever see them. If you attempt to read this file using ORGANIZATION LINE SEQUENTIAL, form feeds, line feeds, and carriage returns are treated as record separators and your COBOL program never gets them. You must read the file as binary sequntial and use UNSTRING to separate the various chunks of the printed output for processing. Very, very tedious. I would suggest using one of the free QuickBooks EDI solutions available to do the export in a more disciplined fashion.

But...
webrabbit said:
Form-feed is 12, not 13. 13 is carriage-return.
By this comment, I presume webrabbit is admonishing me. The [tt]SYMBOLIC CHARACTER[/tt] phrase uses the ordinal position. Form feed is coded with cardinal value of 12 in both the ASCII and EBCDIC alphabets, and its ordinal position in both is 13, because in both alphabets the first ordinal position is held by a character the cardinal value of which is 00.

Tom Morrison
 
Tom's solution is accurate. And it does only work when I read it Binary Sequential.
I'll run the export formats solution by the others involved with that step in the flow of this project. I don't have high expectations there though :)

-David
 
Okay. So, we know Form Feed is "13".

what is ^M stand for and how would I check for both?

My guess:

In Environment Division.
Code:
SPECIAL-NAMES.
      SYMBOLIC CHARACTER FORM-FEED IS 13.
      SYMBOLIC CHARACTER CARR-RET IS 12???????.

In Procedure DIvision.
Code:
MOVE 0 TO FF-COUNT.
      INSPECT INPUT-LINE TALLYING FF-COUNT FOR ALL FORM-FEED.
      IF FF-COUNT > 0
          <process CTRL-L found>
      END-IF.
How do I code the Environment Division with
SYMBOLIC CHARACTERS ( for more than one; char return AND Form Feed)?
I don't see an example in the manual showing 2 or more characters on the SYMBOLIC CHARACTERS.
Thanks.
-David
 
The [tt]SYMBOLIC CHARACTER[/tt] clause is an unusually malleable COBOL construct.

You could code:
Code:
SPECIAL-NAMES.
    SYMBOLIC CHARACTER FORM-FEED CARRIAGE-RETURN ARE
                       13        14
or
Code:
SPECIAL-NAMES.
    SYMBOLIC CHARACTER FORM-FEED IS 13
    SYMBOLIC CHARACTER CARRIAGE-RETURN IS 14
or (my favorite)
Code:
SPECIAL-NAMES.
    SYMBOLIC CHARACTER FORM-FEED IS 13
                       CARRIAGE-RETURN IS 14

How to test for both? Given the problem you have outlined, I don't think you want to test for both at the same time.

I invite you to consider my next post, however...

Tom Morrison
 
Anyway, ^L = 12 = FF and ^M = 13 = CR

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Well, I just discovered that FF = 13 as Tom mentioned and ^M(carriage return) = 14.

Futhermore, Tom's correct, this will be VERy VERY tedious reading in Binary and trying to parse out my needed data especially since the record lengths are not fixed.

-David
 
David,

My suggestion is to use sed or some other batch mode editor (on Linux) to preprocess the file, replacing the ^L characters with another not-so-special character, such as the vertical bar |.
Code:
sed 's/^L/\|/' infile.txt > outfile.txt
Remember that it is tricky to type this (use CTRL-V CTRL-L).

The output of the sed can then be opened and processed as a normal line sequential file. Instead of looking for ^L you would look for the vertical bar |, which will pass through the line sequential file system unscathed.

I will email you a tar file that you can use as a model.

Tom Morrison
 
PHV,

You are specifying the cardinal value, but in the [tt]SYMBOLIC CHARACTER[/tt] clause one must specify the ordinal position of the character within the alphabet.

Tom Morrison
 
k5tm, I agree and admit I have to read more carefully previous posts before I press the submit button :~/
 
Everyone,

Thanks alot for the help on this.

I've decided to go with a "preprocessor" solution using Tom's sed script to convert the ^L to another character such as "|" so that I can simply read the file in LINE SEQUENTIAL format and then set up my parsing code around that.

Thanks again.
-David
 
Yeah, I had forgotten that SYMBOLIC-CHARACTER uses the ordinal vaues. In Micro Focus, I use the 78-level instead. It is more straight-forward, I think. On the other hand, it is not standard.

The preprocessor is probably the best way to handle a unique situation. I run into the problem frequently of processing "line-seqential" files that do not conform to the "rules" for such animals, so I wrote an I/O routine to handle all l-s files. It eats CR & LF, but nothing else.
 
webrabbit said:
I use the 78-level instead. It is more straight-forward, I think.
The 78 level defines a constant-name, whereas the [tt]SYMBOLIC CHARACTER[/tt] clause creates a user-defined figurative constant.


Now there is a substantial intersection of use of constant-names and figurative constants, but there are a few subtle differences, just as there are between " " and SPACE.
webrabbit said:
On the other hand, it is not standard.
The 2002 standard includes constant-names, though it eschews the 78 level for an alternative construct.

Tom Morrison
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top