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
 

 

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: 2502
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: 7234

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: 1610
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: 7234

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: 1610
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: 1715
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: 1610
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: 2502
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: 1219
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
No new posts Performing arithmetic on input field zh_lad DFSORT/ICETOOL 22 Tue Dec 06, 2016 8:04 pm
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts How to split the records using the am... vnktrrd DFSORT/ICETOOL 24 Fri Oct 28, 2016 7:33 pm
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm
No new posts Amount field is getting corrupted whe... thesumitk SYNCSORT 5 Tue Oct 18, 2016 8:20 pm


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