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

Justification of a field


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Fri Jan 30, 2015 1:17 am
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

Moderator Emeritus


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

PostPosted: Fri Jan 30, 2015 2:23 am
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

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Fri Jan 30, 2015 3:51 am
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

Moderator Emeritus


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

PostPosted: Fri Jan 30, 2015 4:26 am
Reply with quote

Rohit,

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

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Fri Jan 30, 2015 4:29 am
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: 2455
Location: Hampshire, UK

PostPosted: Fri Jan 30, 2015 3:20 pm
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

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Fri Jan 30, 2015 9:45 pm
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Fri Jan 30, 2015 10:17 pm
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: 1353
Location: Israel

PostPosted: Mon Feb 02, 2015 2:48 am
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Join 2 files according to one key field. JCL & VSAM 3
No new posts How to move the first field of each r... DFSORT/ICETOOL 5
No new posts S0C7 - Field getting overlayed COBOL Programming 2
No new posts Masking variable size field - min 10 ... DFSORT/ICETOOL 4
Search our Forums:

Back to Top