View previous topic :: View next topic
|
Author |
Message |
srinivas_cog
New User
Joined: 05 Jun 2008 Posts: 17 Location: chennai
|
|
|
|
Hi
Our scenario goes like this
we have one variable name WS-NAME PIC X(12), its length is 12 bytes.
now, if a data of length 4 bytes, say BALA got entered in WS-NAME, we would like to know how to compute the exact length of the data entered in WS-NAME? |
|
Back to top |
|
|
Aji
New User
Joined: 03 Feb 2006 Posts: 53 Location: Mumbai
|
|
|
|
Hi,
Inspect text1 tallying leng for trailing spaces.
act_len = len(text1) - leng.
Thanks
Aji |
|
Back to top |
|
|
balaji81_k
Active User
Joined: 29 Jun 2005 Posts: 155
|
|
|
|
Hi Friend,
I believe u need to declare the WS-NAME as VARCHAR like in DB2
(i,e)
01 WS.
02 WS-NAME PIC X(12).
02 WS-LENGTH PIC S9(4) COMP.
01 WS-CAL-LENGTH PIC 9(12).
IF WE MOVE BALA:
MOVE 'BALA' TO WS-NAME.
MOVE FUNCTION LENGTH(WS-NAME) TO WS-CAL-LENGTH.
DISPLAY WS-CAL-LENGTH.
the variable WS-CAL-LENGTH will have length of what the text u entered in WS-NAME.
Thanks
Balaji K |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Balaji K,
obviously you have neither tested your code nor read the documentation.
Aji,
When AFTER is specified, counting and/or replacing of the inspected item
(identifier-1) begins with the first character position to the right of the
delimiter and continues toward the rightmost character position in the
inspected item. If no delimiter is present in the inspected item, no counting or
replacement takes place.
possibly:
Code: |
Inspect function reverse (ws-name) tallying lding-spaces-count for leading spaces
compute actual-length
= function length (ws-name) - lding-spaces-count
end-compute
|
I say possibly, because I,
like both of you,
have not tested the code. |
|
Back to top |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
Dick Brenholtz wrote: |
I say possibly, because I,
like both of you,
have not tested the code. |
No worries
It works well |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi Sambhaji,
If you can guarantee that there will be no interspersed spaces in the field (e.g. "B A L A")', you s/b OK. |
|
Back to top |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
Jack wrote: |
Hi Sambhaji,
If you can guarantee that there will be no interspersed spaces in the field (e.g. "B A L A")', you s/b OK. |
In case of interspersed spaces e.g. "B A L A"
in above example lding-spaces-count will be 5
and so actual-length will be 12 - 5 = 7, Which is correct. |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
Why don't you try your own code by yourself ??? None of the following is working:
Aji wrote: |
Inspect text1 tallying leng for trailing spaces. |
TRAILING spaces ???
balaji81_k wrote: |
01 WS-CAL-LENGTH PIC 9(12).
MOVE 'BALA' TO WS-NAME.
MOVE FUNCTION LENGTH(WS-NAME) TO WS-CAL-LENGTH.
DISPLAY WS-CAL-LENGTH.
the variable WS-CAL-LENGTH will have length of what the text u entered in WS-NAME. |
PIC 9(12) because the computer is counting on its 12 fingers ???
All the rest is just plain wrong. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
Dick's code works as presented. I tested it using
Code: |
MOVE 'BALA' TO WS-NAME.
MOVE ZERO TO LDING-SPACES-COUNT.
INSPECT FUNCTION REVERSE (WS-NAME)
TALLYING LDING-SPACES-COUNT
FOR LEADING SPACES.
COMPUTE ACTUAL-LENGTH
= FUNCTION LENGTH (WS-NAME) - LDING-SPACES-COUNT
END-COMPUTE.
DISPLAY WS-NAME ' ' LDING-SPACES-COUNT ' ' ACTUAL-LENGTH.
MOVE 'B A L A' TO WS-NAME.
MOVE ZERO TO LDING-SPACES-COUNT.
INSPECT FUNCTION REVERSE (WS-NAME)
TALLYING LDING-SPACES-COUNT
FOR LEADING SPACES.
COMPUTE ACTUAL-LENGTH
= FUNCTION LENGTH (WS-NAME) - LDING-SPACES-COUNT
END-COMPUTE.
DISPLAY WS-NAME ' ' LDING-SPACES-COUNT ' ' ACTUAL-LENGTH. |
and received as output:
Code: |
BALA 08 04
B A L A 05 07 |
|
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
Also, LENGTH OF WS-NAME can be substituted for FUNCTION LENGTH (WS-NAME). |
|
Back to top |
|
|
|