View previous topic :: View next topic
|
Author |
Message |
ram_vizag
Active User
Joined: 21 Aug 2008 Posts: 112 Location: hyd
|
|
|
|
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 |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
Maybe after you explain why the hell you post a COBOL question in the JCL forum
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
It appears to be right-justifying and left-zero-filling the data in TEMP-STRING. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
ram_vizag
Active User
Joined: 21 Aug 2008 Posts: 112 Location: hyd
|
|
|
|
expat wrote: |
Maybe after you explain why the hell you post a COBOL question in the JCL forum
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
|