View previous topic :: View next topic
|
Author |
Message |
nitin_rathor
New User
Joined: 09 Feb 2010 Posts: 6 Location: Pune
|
|
|
|
Hi,
i have a file having a header and detail record. the first byte is 'H' and then one filler followed by 10 bytes of account number. I need to perform a check on the length of account number. If length is of 10 bytes then only file is accepted else it is rejected. How can i extract the length of account number from the header record and use it in check condition?
please suggest. thanks!! |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
Quote: |
I need to perform a check on the length of account number. If length is of 10 bytes then only file is accepted else it is rejected. |
If the field is ten bytes, check the 10th byte (reference modification) to see if it is not numeric (or valid for the account number or not a blank or not low value). |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
I need to perform a check on the length of account number. If length is of 10 bytes then only file is accepted else it is rejected |
First, you need to define the "rules".
If the field has a defined length of 10 bytes, it will always be 10 bytes. What should happen if there is an embedded letter or blank in the 10 bytes? Does a valid account number contain only numerics? What if the "account number" was stored incorrectly and was 12 numeric bytes?
When you have defined the rules, then you can implement the code. . . |
|
Back to top |
|
|
Ketan Varhade
Active User
Joined: 29 Jun 2009 Posts: 197 Location: Mumbai
|
|
|
|
HI, first checkx(1:1) is equal to 'H' and then Move the x(3:10) to Y and then check for the length of Y and the process the data |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Maybe not. . . The length of Y will always be 10. . . |
|
Back to top |
|
|
nitin_rathor
New User
Joined: 09 Feb 2010 Posts: 6 Location: Pune
|
|
|
|
Quote: |
What should happen if there is an embedded letter or blank in the 10 bytes? Does a valid account number contain only numerics? What if the "account number" was stored incorrectly and was 12 numeric bytes? |
Hi,
if account number contains anything other than numeric data, it got to be rejected. It has to numeric only. And it is 10 bytes only. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Suggest you create a little test program (An "if numeric" test may do what you want. . .) and a test file of values similar to :
Code: |
0123456789 valid
0 12345678 invalid
012345678 invalid
0123 45678 invalid
012345B678 invalid |
and add any other pattterns you want to test.
Execute your validation code to make sure that valid data is accepted and the others are identified as "bad". Once you are satisfied with your validatoin code, use it in the "real" program. |
|
Back to top |
|
|
Ketan Varhade
Active User
Joined: 29 Jun 2009 Posts: 197 Location: Mumbai
|
|
|
|
Hi Dick,
I disagree, The lenght of the function will return the lenght that variable contains and not the lenght of the variable |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Ketan Varhade wrote: |
Hi Dick,
I disagree, The lenght of the function will return the lenght that variable contains and not the lenght of the variable |
well, you can disagree, but in COBOL,
the length function determines the length based on defined memory
(either picture clause or reference modification length)
and NEVER based on the content of the field.
if you are referring to an old version of e-cobol manual that speaks about
null delimited strings, that has been updated to reflect what I have said above. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Ketan, from the COBOL Language Reference manual (link at the top of the page):
Quote: |
1.3.8.4 LENGTH OF
The LENGTH OF special register contains the number of bytes used by a data item. |
COBOL is not like C or Perl or other such languages -- variable lengths are set at compile time and cannot be changed at run time. And an alphanumeric variable always contains the number of bytes it is defined to have -- whether they are LOW-VALUES, data bytes, or HIGH-VALUES, or spaces. |
|
Back to top |
|
|
Ketan Varhade
Active User
Joined: 29 Jun 2009 Posts: 197 Location: Mumbai
|
|
|
|
I have used this in a program in which I have used to return the length of the data the varaiable is holding |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Ketan Varhade wrote: |
I have used this in a program in which I have used to return the length of the data the varaiable is holding |
I doubt it! But I only have 40 years experience with COBOL. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Code I tested:
Code: |
01 WS-VAR.
05 WS-1-LEN PIC S9(04) COMP VALUE ZERO.
05 WS-2-LEN PIC S9(04) COMP VALUE ZERO.
05 WS-1 PIC X(26) VALUE 'ABCDE'.
05 WS-2 PIC X(26) VALUE
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
PROCEDURE DIVISION.
MAIN-PARA.
DISPLAY ' LENGTH OF WS-1 ' LENGTH OF WS-1.
DISPLAY ' LENGTH OF WS-2 ' LENGTH OF WS-2.
COMPUTE WS-1-LEN = FUNCTION LENGTH (WS-1).
COMPUTE WS-2-LEN = FUNCTION LENGTH (WS-2).
DISPLAY 'FN LENGTH OF WS-1 ' WS-1-LEN.
DISPLAY 'FN LENGTH OF WS-2 ' WS-2-LEN. |
produces results of
Code: |
LENGTH OF WS-1 000000026
LENGTH OF WS-2 000000026
FN LENGTH OF WS-1 00026
FN LENGTH OF WS-2 00026 |
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
I have used this in a program in which I have used to return the length of the data the varaiable is holding |
Yes, but to no purpose. . .
The code will compile and run, but there is no value/functionality added. . . |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6248 Location: Mumbai, India
|
|
|
|
This
Code: |
compute lth-of-fld = function length(variablename). |
or this
Code: |
compute lth-of-fld = length of variablename. |
will give the length of the field, not the length of the data in the field. If the field is defined pic x(10) and the content is 'ABC', the length returned by the function is 10. To claculate teh length of contents you might need to write a bit of code:
Code: |
01 SOMETEXT PIC X(40) VALUE 'THIS IS THE TEXT'.
INSPECT FUNCTION REVERSE(SOMETEXT) TALLYING L FOR LEADING SPACES
COMPUTE L = LENGTH OF SOMETEXT - L |
L will contain the length of the "contents of" SOMETEXT. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
I believe,
that if you look at past behavior of Ketan,
after he has made one of his ridiculous comments,
that he will absent himself from the forum for a while,
hoping everyone will forget his erroneous posts,
and then start again. |
|
Back to top |
|
|
|