View previous topic :: View next topic |
Author |
Message |
tilak Beginner
Joined: 13 Sep 2006 Posts: 9 Topics: 7
|
Posted: Wed Sep 27, 2006 5:44 am Post subject: interview question in cobol |
|
|
there is a string - a field has value "ilovemycountry" ..
there is no space in between those words.
the question is
1. how can i move each word in the respective fields?
2. i want the position of c of country.
3. i want to find whethrt "count" word is there?
4. i want to move count if found to another field.. |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Wed Sep 27, 2006 7:20 am Post subject: |
|
|
tilak,
1. How do you define a word?
2. Look up the INSPECT verb with tallying option.
3. Once again look up Inspect verb
4. Look UNSTRING verb
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
shekar123 Advanced
Joined: 22 Jul 2005 Posts: 528 Topics: 90 Location: Bangalore India
|
Posted: Wed Sep 27, 2006 8:13 am Post subject: |
|
|
Tilak,
If i have understood u first question properly try this code:
Code: |
WORKING-STORAGE SECTION.
01 WS-VARIABLES.
05 WS-STRING PIC X(14) VALUE 'ILOVEMYCOUNTRY'.
05 WS-POS-C PIC 9(02) VALUE 0.
05 WS-COUNT-FOUND PIC 9(01) VALUE 0.
05 WS-SRCH-COUNT PIC X(05) VALUE 'COUNT'.
05 WS-NEW-MOVED PIC X(05) VALUE SPACES.
05 WS-NEW-STRING PIC X(14) VALUE SPACES.
05 WS-COUNT PIC S9(04) COMP.
PROCEDURE DIVISION.
0000-MAIN.
PERFORM UNTIL WS-COUNT > 14
MOVE WS-STRING(WS-COUNT:1) TO
WS-NEW-STRING(WS-COUNT:1)
ADD +1 TO WS-COUNT
END-PERFORM.
DISPLAY 'NEW STRING IS :' WS-NEW-STRING.
MOVE 1 TO WS-COUNT.
PERFORM UNTIL WS-COUNT > 14
IF WS-STRING(WS-COUNT:1) = 'C'
MOVE WS-COUNT TO WS-POS-C
END-IF
ADD +1 TO WS-COUNT
END-PERFORM.
DISPLAY 'C IS FOUND IN POSITION :' WS-POS-C.
INSPECT WS-STRING TALLYING WS-COUNT-FOUND FOR ALL
WS-SRCH-COUNT.
IF WS-COUNT-FOUND > 0
DISPLAY 'COUNT FOUND IN THE STRING'
MOVE WS-SRCH-COUNT TO WS-NEW-MOVED
DISPLAY 'NEW MOVED STRING :' WS-NEW-MOVED
ELSE
DISPLAY 'COUNT NOT FOUND IN THE STRING'
END-IF.
STOP RUN.
|
OUTPUT
Code: |
NEW STRING IS :ILOVEMYCOUNTRY
C IS FOUND IN POSITION :08
COUNT FOUND IN THE STRING
NEW MOVED STRING :COUNT
|
_________________ Shekar
Grow Technically |
|
Back to top |
|
 |
|
|