Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

length of a field

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: length of a field
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: 2150
Location: At my coffee table

PostPosted: Mon Jun 21, 2010 3:23 pm    Post subject:
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

Site Director


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

PostPosted: Mon Jun 21, 2010 8:26 pm    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Tue Jun 22, 2010 7:29 pm    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Tue Jun 22, 2010 9:33 pm    Post subject:
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    Post subject:
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    Post subject:
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: 7913
Location: Bellevue, IA

PostPosted: Wed Jun 23, 2010 5:06 pm    Post subject:
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    Post subject:
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    Post subject:
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: 7913
Location: Bellevue, IA

PostPosted: Wed Jun 23, 2010 5:21 pm    Post subject:
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

Site Director


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

PostPosted: Wed Jun 23, 2010 8:17 pm    Post subject:
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

Senior Member


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

PostPosted: Wed Jun 23, 2010 8:57 pm    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Performing arithmetic on input field zh_lad DFSORT/ICETOOL 24 Tue Dec 06, 2016 8:04 pm
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts SQZ pipe delimited file with 1 column... Rick Silvers DFSORT/ICETOOL 2 Sun Nov 06, 2016 8:11 pm
No new posts Joinkeys operation when key1 and key2... Susanta DFSORT/ICETOOL 5 Wed Nov 02, 2016 5:35 pm
No new posts How to split the records using the am... vnktrrd DFSORT/ICETOOL 24 Fri Oct 28, 2016 7:33 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us