Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Parse a String and divide it by 2 and place it back in same

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CLIST & REXX
View previous topic :: :: View next topic  
Author Message
magesh23586

Active User


Joined: 06 Jul 2009
Posts: 211
Location: Chennai

PostPosted: Fri Feb 07, 2014 11:34 pm    Post subject: Parse a String and divide it by 2 and place it back in same
Reply with quote

Hi I have requirement.

I have to get three value from a line then divide it by two, replace it in the same position with right aligned, in this some of the values have negative which has to be placed in same position as below

Example
Input
Code:

Command ===>                                                  Scroll ===> CSR 
=COLS> ---+----7----+----8----+----9----+----0----+----1----+----2----+----3---
000047                              150.00-           150.00              0.00


Output should be
Code:

Command ===>                                                  Scroll ===> CSR 
=COLS> ---+----7----+----8----+----9----+----0----+----1----+----2----+----3---
000047                               75.00-            75.00              0.00


Advance thanks
Back to top
View user's profile Send private message

Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1783
Location: Bloomington, IL

PostPosted: Sat Feb 08, 2014 12:15 am    Post subject:
Reply with quote

And you would like us to...?
Back to top
View user's profile Send private message
Pedro

Senior Member


Joined: 01 Sep 2006
Posts: 2088
Location: Silicon Valley

PostPosted: Sat Feb 08, 2014 4:37 am    Post subject: Reply to: Parse a String and divide it by 2 and place it bac
Reply with quote

The slash character is used to perform division, for example:
Code:
var1 = var2 / 2
Back to top
View user's profile Send private message
TheMFKid

New User


Joined: 20 Nov 2013
Posts: 91
Location: India

PostPosted: Mon Feb 10, 2014 9:45 am    Post subject:
Reply with quote

You can use a combination of functions(ex: POS/SUBSTR/Parse, RIGHT) to achieve this.
What is the problem you are facing in coding?
Back to top
View user's profile Send private message
magesh23586

Active User


Joined: 06 Jul 2009
Posts: 211
Location: Chennai

PostPosted: Tue Feb 11, 2014 11:20 pm    Post subject: Reply to: Parse a String and divide it by 2 and place it bac
Reply with quote

Thanks guys for the kind information.
I have done the following code to achieve this.

Code:

PARSE VAR A STR1 STR2 STR3   
/********/
IF POS('-',STR1)>0 THEN       
  DO                         
    SUB1 = LENGTH(STR1)       
    SUB1 = SUB1 - 1           
  STR1 = LEFT(STR1,SUB1)     
  STR1 = STR1 / 2             
  STR1 = FORMAT(STR1,,2)     
  STLEN = LENGTH(STR1)       
  STR1 = STR1'-'             
   END                         
ELSE                         
  DO                         
     STR1 = STR1 / 2         
     STR1 = FORMAT(STR1,,2)
     STLEN = LENGTH(STR1)     
  END                         
  STR1 = 'RPLR ' STR1         
  STLEN = 97 - (STLEN + 5)   
VAR1 = SPACE(STR1,STLEN)         
/***********/
IF POS('-',STR2)>0 THEN           
  DO                             
    SUB1 = LENGTH(STR2)           
    SUB1 = SUB1 - 1               
  STR2 = LEFT(STR2,SUB1)         
  STR2 = STR2 / 2                 
  STR2 = FORMAT(STR2,,2)         
  STLEN = LENGTH(STR2)           
  STR2 = STR2'-'                 
  END                             
ELSE                             
  DO                             
     STR2 = STR2 / 2
     STR2 = FORMAT(STR1,,2)             
     STLEN = LENGTH(STR2)         
  END                             
  STR2 = 'RPLR ' STR2             
  STLEN = 18 - (STLEN + 5)       
  VAR2 = SPACE(STR2,STLEN)       
/*********/
IF POS('-',STR3)>0 THEN           
  DO                             
    SUB1 = LENGTH(STR3)           
    SUB1 = SUB1 - 1               
  STR3 = LEFT(STR3,SUB1)         
  STR3 = STR3 / 2                 
  STR3 = FORMAT(STR3,,2)         
  STLEN = LENGTH(STR3)           
  STR3 = STR3'-'                 
  END                             
ELSE                             
  DO                             
     STR3 = STR3 / 2             
      STR3 = FORMAT(STR3,,2)
     STLEN = LENGTH(STR3)         
  END                             
  STR3 = 'RPLR ' STR3             
  STLEN = 18 - (STLEN + 5)       
  VAR3 = SPACE(STR3,STLEN) 
VARF = VAR1 '' VAR2 '' VAR3     


Finally find all replace 'RPLR' with ' ' .
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10374
Location: italy

PostPosted: Tue Feb 11, 2014 11:43 pm    Post subject: Reply to: Parse a String and divide it by 2 and place it bac
Reply with quote

You could have saved a bit of typing by using something like

Code:
rec = "                             150.00-           150.00              0.00 "
parse var rec str.1 str.2 str.3

off = 20
out = copies(" ",off)

do  i = 1 to 3
    neg = " "
    if  pos("-", str.i ) > 0 then do
        neg = "-"
        str.i = translate(str.i," ","-")
    end

    str.i = strip(str.i) / 2
    str.i = format(str.i,,2) || neg
    out = out ||  right(str.i,18)

end

say ">>>>>" || out || "<<<<<"
Back to top
View user's profile Send private message
magesh23586

Active User


Joined: 06 Jul 2009
Posts: 211
Location: Chennai

PostPosted: Wed Feb 12, 2014 9:40 am    Post subject: Reply to: Parse a String and divide it by 2 and place it bac
Reply with quote

This is Fantastic, Thank you enrico.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CLIST & REXX All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. ISREDIT Macro is not returning back t... nico_neoz CLIST & REXX 21 Sat Nov 18, 2017 7:40 pm
No new posts line 52: Name or string > 250 char... Ashishpanpaliya CLIST & REXX 5 Sat Oct 14, 2017 2:29 am
No new posts Search for a string in many PDS KARTHIGADEVI CLIST & REXX 5 Fri Sep 08, 2017 2:32 pm
No new posts How to change a string containing the... chong.zhou TSO/ISPF 6 Tue Aug 29, 2017 4:54 pm
No new posts String after '.' (period) is not copy... balaji81_k SYNCSORT 6 Wed Aug 23, 2017 9:35 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us