IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

length of a field


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
nitin_rathor

New User


Joined: 09 Feb 2010
Posts: 6
Location: Pune

PostPosted: Mon Jun 21, 2010 3:17 pm
Reply with quote

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
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Mon Jun 21, 2010 3:23 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Mon Jun 21, 2010 8:26 pm
Reply with quote

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
View user's profile Send private message
Ketan Varhade

Active User


Joined: 29 Jun 2009
Posts: 197
Location: Mumbai

PostPosted: Tue Jun 22, 2010 2:38 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Tue Jun 22, 2010 7:29 pm
Reply with quote

Hello,

Maybe not. . . The length of Y will always be 10. . .
Back to top
View user's profile Send private message
nitin_rathor

New User


Joined: 09 Feb 2010
Posts: 6
Location: Pune

PostPosted: Tue Jun 22, 2010 7:38 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Tue Jun 22, 2010 9:33 pm
Reply with quote

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
View user's profile Send private message
Ketan Varhade

Active User


Joined: 29 Jun 2009
Posts: 197
Location: Mumbai

PostPosted: Wed Jun 23, 2010 10:32 am
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Jun 23, 2010 3:09 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8700
Location: Dubuque, Iowa, USA

PostPosted: Wed Jun 23, 2010 5:06 pm
Reply with quote

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
View user's profile Send private message
Ketan Varhade

Active User


Joined: 29 Jun 2009
Posts: 197
Location: Mumbai

PostPosted: Wed Jun 23, 2010 5:10 pm
Reply with quote

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
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Wed Jun 23, 2010 5:20 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8700
Location: Dubuque, Iowa, USA

PostPosted: Wed Jun 23, 2010 5:21 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Wed Jun 23, 2010 8:17 pm
Reply with quote

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
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6248
Location: Mumbai, India

PostPosted: Wed Jun 23, 2010 8:57 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Jun 23, 2010 9:14 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Help required to reset decimal points... DFSORT/ICETOOL 9
No new posts Sorting Date Field DFSORT/ICETOOL 4
No new posts Get RECORD LENGTH, allocated space of... CLIST & REXX 7
No new posts Store the data for fixed length COBOL Programming 1
No new posts How to split large record length file... DFSORT/ICETOOL 10
Search our Forums:

Back to Top