Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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: 158
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: 1738
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: 2019
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: 158
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: 10202
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: 158
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
No new posts CICS Roll back partially - Need to re... dwijadas CICS 4 Wed Nov 16, 2016 4:30 pm
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
No new posts Random Password (in string format) ge... ezhavendhan COBOL Programming 10 Mon Aug 29, 2016 3:18 pm
No new posts How to insert a lengthy string havin... vidyaa DB2 7 Thu Aug 25, 2016 5:20 pm
No new posts Which function does the Ampersand (&a... Andi1982 PL/I & Assembler 3 Wed Aug 24, 2016 2:05 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us