Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Justification of a field

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
spoorni

New User


Joined: 29 Nov 2007
Posts: 20
Location: india

PostPosted: Fri Jan 30, 2015 12:05 am    Post subject: Justification of a field
Reply with quote

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
View user's profile Send private message

Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2504
Location: Atlanta, Georgia, USA

PostPosted: Fri Jan 30, 2015 1:17 am    Post subject: Reply to: Justification of a field
Reply with quote

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
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7314

PostPosted: Fri Jan 30, 2015 2:23 am    Post subject: Reply to: Justification of a field
Reply with quote

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
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1827
Location: NY,USA

PostPosted: Fri Jan 30, 2015 3:51 am    Post subject:
Reply with quote

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
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7314

PostPosted: Fri Jan 30, 2015 4:26 am    Post subject: Reply to: Justification of a field
Reply with quote

Rohit,

Why are you reversing the data?
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1827
Location: NY,USA

PostPosted: Fri Jan 30, 2015 4:29 am    Post subject:
Reply with quote

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
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 1932
Location: UK

PostPosted: Fri Jan 30, 2015 3:20 pm    Post subject:
Reply with quote

My understanding is that if the input is ABC then the required stored value is to be 00ABC not 00CBA
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1827
Location: NY,USA

PostPosted: Fri Jan 30, 2015 9:45 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2504
Location: Atlanta, Georgia, USA

PostPosted: Fri Jan 30, 2015 10:17 pm    Post subject: Reply to: Justification of a field
Reply with quote

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
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1252
Location: Israel

PostPosted: Mon Feb 02, 2015 2:48 am    Post subject: Re: Justification of a field
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. Incrementing current time field by 30... arunsoods DFSORT/ICETOOL 11 Thu Oct 26, 2017 3:22 pm
No new posts sort records based on length exceeds ... maxsubrat DFSORT/ICETOOL 7 Wed Oct 04, 2017 4:48 pm
No new posts Partial color change of a field in CI... waseem0424 CICS 5 Fri Sep 29, 2017 7:56 pm
No new posts Remove leading spaces from numeric field rexx77 SYNCSORT 6 Wed Sep 06, 2017 2:15 am
No new posts JES2 job size field matching Windows ... SRICOBSAS All Other Mainframe Topics 4 Tue Sep 05, 2017 5:49 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us