how to find a position in string



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

how to find a position in string

Postby mohd dalib » Thu Jul 03, 2008 9:14 pm

like variable x = 'abcdef---z012----upto9' all character a-z and 0-9
i want to firstly search a character like for example 'c' and and then update the variable contains 'c' to 'd'
like variable temp = 'c'
then i want to search the character of veriable temp in string x and update the veriable temp as next character in string.
mohd dalib
 
Posts: 5
Joined: Thu Jul 03, 2008 9:08 pm
Has thanked: 0 time
Been thanked: 0 time

Re: how to find a position in string

Postby dick scherrer » Fri Jul 04, 2008 12:12 am

Hello mohd dalib and welcome to the forums,

To get some help here, you need to much more clearly define your requirement.

Changing a "c" to "d" seems pretty straight forward, but after that your request is not clear.

If you post a couple of examples of some "input", the search/change value(s), and the output you want when a specific input is processed using your "rules", we may be able to offer suggestions.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: how to find a position in string

Postby mohd dalib » Fri Jul 04, 2008 10:20 am

hi dick,
firstly i take a variable
string1 pic x(10) value '0123456789abcdefghijklmnopqrstuvwxyz'.
and second variable
temp1 pic x.
now variable temp contains any value that is between '0---9a--------z' that is in variable string1.
now i want to increment the value of variable temp1 just one.
for example
suppose first time temp1 contains value 'a'.
now i want to find the position of value temp1 in string1 and just make the value of temp1 next value in string1
i.e temp1='b'


like if temp1='1'
then find the position of value in temp1 in string1 and just assing the temp1 the next value in string1
i.e temp1 ='2'

like if temp1 ='d'
then increment temp1 by 1 position in string1
and make it 'e'
i.e temp1= 'e'

i m clear now.
anyway thanks dick
mohd dalib
 
Posts: 5
Joined: Thu Jul 03, 2008 9:08 pm
Has thanked: 0 time
Been thanked: 0 time

Re: how to find a position in string

Postby dick scherrer » Fri Jul 04, 2008 12:20 pm

Hello,

i m clear now.
Sorry, not yet. I'm sure that your meaning is completely clear to you, but the challange is to make it clear to those who read it.

string1 pic x(10) value '0123456789abcdefghijklmnopqrstuvwxyz'.
This is not correct, regardless of what the process needs to do :?

temp1 pic x.
now variable temp contains any value that is between '0---9a--------z' that is in variable string1.
Who/what is "temp"? How does it contain "any value that is between '0---9a--------z' that is in variable string1".

When your process is working, what service will it provide? If the requirement is understood, that will help.

If, one way or another, you need to look for only a single-byte value and then do something accordngly, set the "string" of values in an array of 1-byte values, look thru the array until the single-byte value is found and then go on from there. You would need to handle the case where the value was not found or the value found was in the "last" position.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: how to find a position in string

Postby jayind » Fri Jul 04, 2008 5:04 pm

Hi mohd dalib,

to my understanding from your postings,

firstly i take a variable
string1 pic x(10) value '0123456789abcdefghijklmnopqrstuvwxyz'.
and second variable
temp1 pic x.
now variable temp contains any value that is between '0---9a--------z' that is in variable string1.
now i want to increment the value of variable temp1 just one.


1. you have a string of characters '0123456789abcdefghijklmnopqrstuvwxyz' in a variable STRING-1 [it should be 10+26= 36 chars long, so use pic x(36)]
2. You have another variable TEMP-1 [pic x(1)] which has a character that needs to be searched in STRING-1
3. using Search criteria, you want to find the existing position of character in TEMP-1 in STRING-1 and get the next character in sequence into TEMP-1
4. use this for futher manipulations

Hope this is what you are expecting.

if my understand about your requirement is correct, as suggested by Dick, use the following pseudocode

1. Define

01 ORIG-STRING.
     05 STRING-1     PIC X(36).
     05 STRING-2  REDEFINES STRING-1 PIC X(1) OCCURS 36 TIMES INDEXED BY INDX1.
01 TEMP-1 PIC X(1) value 'a'.

the indentation 01 and 05 is not coming correctly in this editor so use appropriately

2. MOVE '0123456789abcdefghijklmnopqrstuvwxyz' TO STRING-1.

3. SEARCH STRING-2 using TEMP-1. The index will be placed at the location of the character found.

4. SET INDX1 UP BY 1 and MOVE STRING-2(INDX1) TO TEMP-1 to get the next character in the STRING-1

Hope this helps...
let me know if you need any other help..
jayind
 
Posts: 62
Joined: Wed Apr 23, 2008 1:37 pm
Location: Chennai, India
Has thanked: 0 time
Been thanked: 0 time

Re: how to find a position in string

Postby dick scherrer » Fri Jul 04, 2008 11:30 pm

Hello jayind,

When you post code, jcl or data and want to preserve the indentation (as well as used a fixed font rather than proportional to preserve alignment of characters), use the "Code" tag at the top of the reply panel. I've done this with your posted ws code. I also changed the level 07 to 01.

Also, when you have keyed a post, you can use the "Preview" (next to Submit) to see what your post will look like to the forum. Just make sure to click Submit when you are satisfied with how your post appears. If Submit is not clicked, your post is lost - i've done that a few times. . . ;)
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post