IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

REGARDING FUNCTION REVERSE...


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ram_vizag

Active User


Joined: 21 Aug 2008
Posts: 112
Location: hyd

PostPosted: Mon Sep 23, 2013 7:23 pm
Reply with quote

Hi Friends,

Could some one please explain the follwoing code with example: i mean input and out put value.

Code:


05  TEMP-STRING                 PIC X(10).
05  TEMP-STRING-B               PIC X(10).

                                                                 
    MOVE ZERO TO TRAIL-CNTR.                                     
    INSPECT FUNCTION REVERSE (TEMP-STRING)                       
       TALLYING TRAIL-CNTR                                       
       FOR LEADING SPACES.                                       
    MOVE SPACE TO TEMP-STRING-B.                                 
    IF TRAIL-CNTR < FUNCTION LENGTH (TEMP-STRING)               
       MOVE TEMP-STRING   TO TEMP-STRING-B ((TRAIL-CNTR + 1) : )
       MOVE TEMP-STRING-B TO TEMP-STRING                         
    END-IF.                                                     
                                                                 
    INSPECT TEMP-STRING                                         
       REPLACING LEADING SPACES BY ZEROES.   

Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Mon Sep 23, 2013 7:38 pm
Reply with quote

Maybe after you explain why the hell you post a COBOL question in the JCL forum icon_evil.gif

Why should someone else supply the inputs and outputs for you. Do you not have access to a mainframe to test things yourself.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Mon Sep 23, 2013 7:58 pm
Reply with quote

It appears to be right-justifying and left-zero-filling the data in TEMP-STRING.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Sep 23, 2013 8:11 pm
Reply with quote

Hello,

Suggest you make up a few test input values and see what is returned.

Break out this bit of code into a bit of code that is only to test thi function.

Post back here if there are any surprises.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Sep 23, 2013 8:18 pm
Reply with quote

Unless the input field is blank, in which case it stays blank,

Code:
    IF ( TEMP-STRING NOT EQUAL TO SPACE )
        PERFORM RIGHT-JUST-LEFT-ZERO-FILL
    END-IF

    ...

RIGHT-JUST-LEFT-ZERO-FILL.
    MOVE ZERO TO TRAIL-CNTR                                     
    INSPECT FUNCTION REVERSE (TEMP-STRING)                       
       TALLYING TRAIL-CNTR                                       
       FOR LEADING SPACES                                       
    MOVE ZERO TO TEMP-STRING-B                                 
    MOVE TEMP-STRING  TO TEMP-STRING-B ( ( TRAIL-CNTR + 1 ) : )
    MOVE TEMP-STRING-B TO TEMP-STRING     


Or:

Code:
    IF ( NO-INPUT-QUANTITY  )
        CONTINUE
    ELSE
        PERFORM RIGHT-JUST-LEFT-ZERO-FILL
    END-IF

    ...

RIGHT-JUST-LEFT-ZERO-FILL.

    MOVE ZERO TO COUNT-OF-TRAILING-BLANKS                                     

    INSPECT FUNCTION REVERSE ( INPUT-QUANTITY )                       
       TALLYING COUNT-OF-TRAILING-BLANKS                                       
       FOR LEADING SPACES                                       

    MOVE ZERO TO IQ-WITH-LEADING-ZEROS                                 

    MOVE INPUT-QUANTITY TO IQ-WITH-LEADING-ZEROS
                            ( ( COUNT-OF-TRAILING-BLANKS + 1 ) : )

    MOVE IQ-WITH-LEADING-ZEROS TO INPUT-QUANTITY     


Isn't that easier to read?

It is also easier to code and test :-)

Although I haven't this time.... asking for trouble :-)

Other ways to do it as well, of course...
Back to top
View user's profile Send private message
ram_vizag

Active User


Joined: 21 Aug 2008
Posts: 112
Location: hyd

PostPosted: Tue Sep 24, 2013 2:22 pm
Reply with quote

expat wrote:
Maybe after you explain why the hell you post a COBOL question in the JCL forum icon_evil.gif

Why should someone else supply the inputs and outputs for you. Do you not have access to a mainframe to test things yourself.


Hi, I dont have access to test and submit a job in mainframe...thats the reason why i have posted...also if the input is __abc_____ what is output???

first two is space 3,4,5 th position is having a,b,c values respectively. and after that till 10 bytes spaces. then in this scenarion what is the output??

what will be the count of the trailer-cnt abobe 2 or 7. i mean if a string is read from back what is leading spaces in this case???

explain...
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Sep 24, 2013 4:35 pm
Reply with quote

With the original code, you'll get seven zeros then abc.

The count of the leading spaces will be five, having reversed the field, so there are five trailing spaces.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Calling an Open C library function in... CICS 1
No new posts DATE2 function SYNCSORT 15
No new posts Help on PL/I jsonPutValue function PL/I & Assembler 8
No new posts how to use Tso outtrap external function All Other Mainframe Topics 8
No new posts INSYNC option with same function as I... JCL & VSAM 0
Search our Forums:

Back to Top