Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
length of a alphanumeric

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
saagu

New User


Joined: 15 May 2008
Posts: 41
Location: Chennai

PostPosted: Thu Jan 29, 2009 2:42 pm    Post subject: length of a alphanumeric
Reply with quote

Hi
Can anyone let me know how to find the length of a alphanumeric variable using any function in cobol.

Ex. variable1 x(20).

move 'laxy' to variable1.

Now i want the lenth of the content in the variable.

Let me know if any answers.

Thanks in advance
Saagu
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


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

PostPosted: Thu Jan 29, 2009 3:11 pm    Post subject:
Reply with quote

this should be in the cobol forum.

there are threads concerning this. look for REVERSE and INSPECT Counting Leading.
Back to top
View user's profile Send private message
beruoist

New User


Joined: 14 Nov 2007
Posts: 70
Location: mumbai

PostPosted: Thu Jan 29, 2009 4:03 pm    Post subject:
Reply with quote

Try below logicc

inspect reverse(variable1) tallying ws-t-spaces
for leading spaces
compute ws-len-of-string = length of variable1
- ws-t-spaces

This will work.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Thu Jan 29, 2009 5:55 pm    Post subject:
Reply with quote

Quote:
Try below logicc

inspect reverse(variable1) tallying ws-t-spaces
for leading spaces
compute ws-len-of-string = length of variable1
- ws-t-spaces

This will work.
Please test your code before attempting to post it. Actually, no it won't work:
Code:
            PROCEDURE DIVISION.
            S1000-MAIN       SECTION.
                INSPECT REVERSE (VENDOR)    TALLYING WS-T-SPACES

IGYPS2121-S "REVERSE" was not defined as a data-name.  The statement was discarded.

IGYPS2120-S Expected a reference-modification specification but found ")".  The
            "INSPECT" statement was discarded.

                FOR LEADING SPACES.
                COMPUTE WS-LEN-OF-STRING = LENGTH OF VENDOR
                - WS-T-SPACES.
The REVERSE function can be used in a MOVE statement but it cannot be used in the INSPECT statement because as the Language Reference manuals says about the INSPECT field:
Quote:
identifier-1
Is the inspected item and can be any of the following:

* An alphanumeric data item
* A numeric data item with USAGE DISPLAY
* A DBCS data item
* A national data item
* An external floating-point item
I don't see "Intrinsic function" listed which implies that COBOL does not support using a function directly in the INSPECT -- as the code above proves.
Back to top
View user's profile Send private message
Shashank.kapoor

New User


Joined: 14 Jan 2009
Posts: 24
Location: Mumbai

PostPosted: Thu Jan 29, 2009 6:17 pm    Post subject: Reply to: length of a alphanumeric
Reply with quote

Hi Robert,

The reply posted by "beruoist" is correct, the only thing he missed is keyword "FUNCTION".
The below statement will work fine.
INSPECT FUNCTION REVERSE(WS-VARIABLE-LEN)
TALLYING WS-SPACE-LEN
FOR LEADING SPACES


COMPUTE WS-EXACT-LEN = TOTAL-LEN - WS-SPACE-LEN

Please try with the keyword FUNCTION along with the reverse in inspect.

Feel free to let me know your views and also correct me if any thing you found. icon_smile.gif

Thanks & Regards,
Shashank Kapoor
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Thu Jan 29, 2009 6:28 pm    Post subject:
Reply with quote

I'm not saying it won't work if the FUNCTION name is added -- what I'm saying is that the code posted by beruoist is not syntactically valid. With the FUNCTION keyword the structure becomes an alphanumeric data item -- which is fine for INSPECT -- but without the FUNCTION keyword the program won't compile. Code that is posted needs to be perfectly accurate in syntax and functionality -- and beruoist's code failed the first part of that test.
Back to top
View user's profile Send private message
Shashank.kapoor

New User


Joined: 14 Jan 2009
Posts: 24
Location: Mumbai

PostPosted: Thu Jan 29, 2009 6:36 pm    Post subject:
Reply with quote

Hi,

I totally agree with you Robert. icon_smile.gif

If specific code is provided in the post then it should be syntactically correct.

Thanks for your quick response!!

Thanks & Regard,
Shashank Kapoor
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Fri Jan 30, 2009 11:30 am    Post subject:
Reply with quote

As long as we're getting detailed here, WS-T-SPACES must be initialized before the INSPECT statement. icon_smile.gif
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
This topic is locked: you cannot edit posts or make replies. Can a alphanumeric data be moved to a... nico_neoz COBOL Programming 10 Mon Oct 30, 2017 8:28 am
No new posts sort records based on length exceeds ... maxsubrat DFSORT/ICETOOL 7 Wed Oct 04, 2017 4:48 pm
This topic is locked: you cannot edit posts or make replies. Selecting two copybooks of different ... Vignesh Sid COBOL Programming 8 Tue Sep 05, 2017 7:28 pm
No new posts Can we limit length in concatenation ... balaji81_k DB2 7 Tue Aug 22, 2017 2:50 am
No new posts Length of Tape file Mohan Kothakota JCL & VSAM 9 Thu Apr 20, 2017 10:24 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us