View previous topic :: View next topic
|
Author |
Message |
spoorni
New User
Joined: 29 Nov 2007 Posts: 20 Location: india
|
|
|
|
I have a field X(05) coming in as input. If the user enters 1, I need to make it 00001. If the user enters 111, I need to make it 00111. If the user enters AA, I need to make it 000AA. I will further be using this as a 9(03) field to query a database. How can I acheive this? |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Search the COBOL forum for NUMVAL. You should be able to use one (or a combination thereof) of these search returned posts.
HTH.... |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
If alphabetics are valid, you can't use NUMVAL.
Which part of the five is going to appear in the three bytes? Can you show some actual representative sample data and expected output? |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3053 Location: NYC,USA
|
|
|
|
see if something like this if it works...
Code: |
move 5 to J
move zeroes to ws-output
perform varying i from 1 by 1 until I = 5 or end-loop
if ws-input(I:1) = ' '
set end-loop to true
else
move ws-input(I:1) to ws-output(j:1)
sub -1 from J
end-if |
or if you anyways have a DB2 then go for below query,
Code: |
SELECT
STRIP(CAST( TRANSLATE('54321',replace('AA ',' ','0'), '12345')
AS VARCHAR(5) ))
FROM SYSIBM.SYSDUMMY1; |
|
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Rohit,
Why are you reversing the data? |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3053 Location: NYC,USA
|
|
|
|
Hello Bill,
I think, Spoorni wants to have it reversed. I may be wrong but my understanding is if she is having input as char(5) then the values are left justified and now she wants them to be right justified by prefixing it with '0'. |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
My understanding is that if the input is ABC then the required stored value is to be 00ABC not 00CBA |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3053 Location: NYC,USA
|
|
|
|
Nic and Bill, I guess you both were right so may below logic now can help her.
Code: |
INSPECT ws-input TALLYING k
FOR CHARACTERS BEFORE INITIAL SPACE.
move 5 to J
move zeroes to ws-output
perform para-name until k = 0
move ws-input(k:1) to ws-output(j:1)
comupte J = J -1
compute k = k-1
end-perform |
|
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Try this (desk checked only) -
Code: |
03 WS-INPUT PIC X(05).
03 WS-WORK PIC X(05).
03 WS-SUB PIC S9(08) COMP-5.
03 WS-POS PIC S9(08) COMP-5.
MOVE '1A' TO WS-INPUT.
MOVE ZERO TO WS-WORK.
MOVE LENGTH OF WS-WORK TO WS-POS.
*
PERFORM VARYING WS-SUB FROM LENGTH OF WS-INPUT BY -1
UNTIL WS-SUB < 1
IF (WS-INPUT (WS-SUB:1) NOT < '1'
AND WS-INPUT (WS-SUB:1) NOT > '9')
OR (WS-INPUT (WS-SUB:1) ALPHABETIC-UPPER
AND WS-INPUT (WS-SUB:1) NOT = SPACE)
MOVE WS-INPUT (WS-SUB:1)
TO WS-WORK (WS-POS:1)
SUBTRACT 1 FROM WS-POS
END-IF
END-PERFORM.
|
After falling out of the In-Line Perform, 'WS-WORK' equals '0001A'.
HTH.... |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
spoorni wrote: |
I have a field X(05) coming in as input. If the user enters 1, I need to make it 00001. If the user enters 111, I need to make it 00111. If the user enters AA, I need to make it 000AA. I will further be using this as a 9(03) field to query a database. How can I acheive this? |
How do you plan to store 000AA into a pic 9(03) area ?
Whatever you do, it will be hard to squeeze 5 digits into 3, and alphabetic into numeric... |
|
Back to top |
|
|
|