MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

interview question in cobol

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Interview Q & A
View previous topic :: View next topic  
Author Message
tilak
Beginner


Joined: 13 Sep 2006
Posts: 9
Topics: 7

PostPosted: Wed Sep 27, 2006 5:44 am    Post subject: interview question in cobol Reply with quote

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
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Wed Sep 27, 2006 7:20 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
shekar123
Advanced


Joined: 22 Jul 2005
Posts: 528
Topics: 90
Location: Bangalore India

PostPosted: Wed Sep 27, 2006 8:13 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Interview Q & A All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group