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 

max value in a string

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
enge
Beginner


Joined: 12 Oct 2004
Posts: 78
Topics: 39

PostPosted: Wed Aug 17, 2005 9:33 am    Post subject: max value in a string Reply with quote

hi all,
i have a string pic x(8 ) and i must get the max value numeric.
for example:

BYEBYE01 ---- > return value 1

how can i do? (cobol language)

thx in advance.
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 Aug 17, 2005 9:57 am    Post subject: Reply with quote

Enge,

Try this

Code:

01 W-STRING         PIC X(08) VALUE 'BYEBYE01'.               
                                                               
01 T-STR-TABLE REDEFINES W-STRING.                             
   05 T-STR         PIC X(01) OCCURS 8 TIMES.                 
                                                               
01 W-SUB1           PIC S9(4) COMP.                           
01 W-SUB2           PIC S9(4) COMP.                           
01 W-TMP-STR        PIC X(01).                                 
                                                               
PROCEDURE DIVISION.                                           
                                                               
    PERFORM  VARYING W-SUB1 FROM 1 BY 1 UNTIL W-SUB1 >= 8     
       PERFORM VARYING W-SUB2 FROM 8 BY -1                     
         UNTIL W-SUB2 <= W-SUB1                               
         EVALUATE TRUE                                         
             WHEN T-STR (W-SUB2) < T-STR (W-SUB2 - 1)         
                  MOVE T-STR (W-SUB2)     TO W-TMP-STR         
                  MOVE T-STR (W-SUB2 - 1) TO T-STR (W-SUB2)   
                  MOVE W-TMP-STR          TO T-STR (W-SUB2 - 1)
             WHEN T-STR (W-SUB2) > T-STR (W-SUB2 - 1)         
                  CONTINUE                                     
         END-EVALUATE                                         
       END-PERFORM                                             
    END-PERFORM                                               

    DISPLAY 'The Max char is : ' T-STR(8)



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
bonnie_mathew
Beginner


Joined: 05 Aug 2005
Posts: 8
Topics: 0

PostPosted: Thu Aug 18, 2005 4:04 am    Post subject: Reply with quote

Kolusu,

Correct me if I am wrong, but I think the following logic can do the job.
Code:

MOVE T-STR(1) TO WS-TMP-STR
PERFORM
VARYING W-SUB1 FROM 1 BY 1 UNTIL W-SUB1 >= 8
     IF T-STR (W-SUB1) > WS-TMP-STR
        MOVE T-STR (W-SUB1) TO WS-TMP-STR
     END-IF
END-PERFORM
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: Thu Aug 18, 2005 7:04 am    Post subject: Reply with quote

bonnie_mathew,

Your code needs a sligt modification to work. Your perform statement should be performed until w-sub1 is greater than 8, so that you won't miss the last occurance.

Code:

PERFORM VARYING W-SUB1 FROM 1 BY 1 UNTIL W-SUB1 > 8


My code will sort the entire table. I am aware that it is a overkill just to find out the max value. But if he wants to find the max and min values with the string, the above posted code does it all.

Thanks

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming 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