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

Calculate the length of a string


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

New User


Joined: 23 May 2005
Posts: 19

PostPosted: Fri Jun 09, 2006 9:55 am
Reply with quote

Hi

i want to calculate the length of a string.The varilable is declared

01 GR.
05 A PIC X(200).
05 B PIC S9(3) COMP.

now the varilable "A" contains "god is great ". the actual length of the srting is 12. Please tell me how to calculate the lenght.

thank you
Back to top
View user's profile Send private message
Aji

New User


Joined: 03 Feb 2006
Posts: 53
Location: Mumbai

PostPosted: Fri Jun 09, 2006 10:48 am
Reply with quote

Hi


Please try out the code below.
INSPECT FUNCTION REVERSE(TEXT1) TALLYING
L FOR LEADING SPACE

compute l = length of text1 - l


Regards

Aji Cherian
Back to top
View user's profile Send private message
gowtham_1982
Warnings : 1

Active User


Joined: 02 Dec 2005
Posts: 109

PostPosted: Mon Jun 12, 2006 8:32 am
Reply with quote

sunish wrote:
Hi

i want to calculate the length of a string.The varilable is declared

01 GR.
05 A PIC X(200).
05 B PIC S9(3) COMP.

now the varilable "A" contains "god is great ". the actual length of the srting is 12. Please tell me how to calculate the lenght.

thank you


Hi sunish,

please try this code...

compute b = function length of (a).

suggestions welcomed...

gowtham
Back to top
View user's profile Send private message
shreevamsi

Active User


Joined: 23 Feb 2006
Posts: 305
Location: Hyderabad,India

PostPosted: Mon Jun 12, 2006 10:38 am
Reply with quote

hi gowtham_1982,

AJI is right.

You can't go for FUNCTION Lenght of (a) directly.
SInce the lenght includes the following spaces which is not the requirement.

~Vamsi
Back to top
View user's profile Send private message
sundaresanjs

New User


Joined: 29 May 2006
Posts: 18
Location: USA

PostPosted: Sat Jun 17, 2006 1:07 pm
Reply with quote

sunish,

i have done a program regarding it, i think it may be helpful for u,
(using display(name(2:1)) which gives the value of the second position in name)

01 GR.
05 A PIC X(200).
05 B PIC S9(3) COMP

according to ur program a has value god is great,

MOVE 300 TO I.
PERFORM 300 TIMES
IF A(I:1) = " " THEN NEXT SENTENCE
ELSE
COMPUTE LEN = 300 - I
GO TO PRINTPARA
END-IF
END-PERFORM.
PRINTPARA.
DISPLAY "THE LENGTH OF STRING IN A IS : ", LEN.
STOP RUN.

comment if any errors

regards,
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 How to split large record length file... DFSORT/ICETOOL 10
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts VB to VB copy - Full length reached SYNCSORT 8
Search our Forums:

Back to Top