View previous topic :: View next topic |
Author |
Message |
nadh Intermediate
Joined: 08 Oct 2004 Posts: 192 Topics: 89
|
Posted: Tue Nov 02, 2004 1:23 am Post subject: Finding the length of the String |
|
|
Hi,
I have a record declared as below
01 rec pic x(100).
I will be getting variable length string into that record. I want to move that data to db2 table field which is of varchar. so I have to find out the length of the string in record.
for eg. A community of and for mvs professionals.
using length function in cobol i'm getting the bytes used by the rec. But my requirement is to find the length of the string. Can any one suggest me how to do it. I have one solution with me that is searching in the record for non space character in the record starting from back. But as this program is to be run in batch it is not effiecient way i believe. Pls. suggest any other way to find the length of the string. in COBOL
Thanks in advance!!!
nadh |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
|
Back to top |
|
 |
nadh Intermediate
Joined: 08 Oct 2004 Posts: 192 Topics: 89
|
Posted: Fri Nov 05, 2004 11:31 am Post subject: |
|
|
Hi Kolusu,
Thanks for your links.
by the way i want to find the lenth of the string in a record in cobol not in db2.
it will be great if you suggest a method for it.
nadh |
|
Back to top |
|
 |
Phantom Data Mgmt Moderator

Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
|
Posted: Fri Nov 05, 2004 11:47 am Post subject: |
|
|
nadh,
I think you mis-understood what Kolusu said. He gave u a DB2 Plugin solution. ie. you can use Db2 features inside your cobol program to achieve what you need.
Code: |
SELECT LENGTH('A COMMUNITY OF AND FOR MVS PROFESSIONALS')
FROM SYSIBM.SYSDUMMY1;
|
Instead of the Hard coded value 'A COMMUNITY......' pass your variable/group variable (which contains the record you read from your input file) as a parameter to the above mentioned SQL statement to get the desired results.
Code: |
EXEC SQL
SELECT
LENGTH(:WS-INPUT-RECORD)
INTO
:WS-LENGTH
FROM
SYSIBM.SYSDUMMY1
END-EXEC
|
Hope this helps,
Phantom |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Fri Nov 05, 2004 12:09 pm Post subject: |
|
|
Quote: |
by the way i want to find the lenth of the string in a record in cobol not in db2.
|
Nadh,
The 2 links in my first post discusses a COBOL solution. I also supplied an additional solution of using DB2 in a cobol program.
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
nadh Intermediate
Joined: 08 Oct 2004 Posts: 192 Topics: 89
|
Posted: Sat Nov 06, 2004 3:55 am Post subject: |
|
|
Thank you Kolusu, the links provided by you solved my problem. Thank you very much.
nadh |
|
Back to top |
|
 |
|
|