IBM Mainframe Forum Index
 
Register
 
IBM Mainframe Forum Index Mainframe: Search Log in to check your private messages Log in
 

Parse a String and divide it by 2 and place it back in same


 
IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
magesh23586

Active User


Joined: 06 Jul 2009
Posts: 213
Location: Chennai

PostPosted: Fri Feb 07, 2014 11:34 pm
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: 1788
Location: Bloomington, IL

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

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

Global Moderator


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

PostPosted: Sat Feb 08, 2014 4:37 am
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
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: 213
Location: Chennai

PostPosted: Tue Feb 11, 2014 11:20 pm
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

Senior Member


Joined: 14 Mar 2007
Posts: 10695
Location: italy

PostPosted: Tue Feb 11, 2014 11:43 pm
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: 213
Location: Chennai

PostPosted: Wed Feb 12, 2014 9:40 am
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 All times are GMT + 6 Hours
Forum Index -> CLIST & REXX
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Forum Replies
No new posts Need to split single line into two li... DFSORT/ICETOOL 7
No new posts Trying to add current date in place o... DFSORT/ICETOOL 8
No new posts PARSE using REPEAT DFSORT/ICETOOL 1
No new posts how to convert Hex String t char hex PL/I & Assembler 6
No new posts Get next 5 numeric from a string of '... COBOL Programming 4

Back to Top