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

Need help on Tallying


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
kiran1

New User


Joined: 30 Mar 2007
Posts: 1
Location: kolkata

PostPosted: Tue Sep 16, 2008 6:16 pm
Reply with quote

I need to validate a value in a field. If the value contains spaces in the middle, then it should check for the rest of the characters until 15 positons and if all are spaces, then continue else if a character found after 1st space then error message should be displayed.

ex: UDAY KIRAN , so after UDAY it should capture this space and then check the next character. As it is K, it should display an error message.
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Tue Sep 16, 2008 6:54 pm
Reply with quote

Check if this solves your requirement
Code:

*WS
01 ORIGVAR PIC X(30) VALUE 'UDAY KIRAN'
01 TRUNCVAR PIC X(15).                 
01 DESTVAR1 PIC X(15).                 
01 DESTVAR2 PIC X(15).                 

*PD
MOVE ORIGVAR(1:15) TO TRUNCVAR.     
UNSTRING TRUNCVAR DELIMITED BY SPACES
INTO DESTVAR1 DESTVAR2.             
IF DESTVAR2(1:1) NOT =  ' ' THEN     
DISPLAY "YOUR ERROR MESSAGE".       
Back to top
View user's profile Send private message
Cristopher

New User


Joined: 31 Jul 2008
Posts: 53
Location: NY

PostPosted: Tue Sep 16, 2008 8:24 pm
Reply with quote

kiran1 if i have understood your requirement correctly thn : There should be an error mssg displayed if there is a character found in 1st 15 bytes of the string after the 1st space found.

You can try this aswell :
Code:

01 A PIC X(25).                                               
01 B PIC X(15) VALUE SPACES.
01 Y PIC 9(01) VALUE ZEROES.
01 SPACE-STATUS   PIC X(1) VALUE 'N'.                         
   88 NO-SPACE               VALUE 'N'.                         
   88 SPACES-FOUND            VALUE 'Y'. 

PERFORM UNTIL Y = LENGTH OF A OR SPACES-FOUND   
Increment Y by 1                                                   
IF A (Y:1) EQUAL TO  SPACES                 
  Increment Y by 1
MOVE A (Y: ) to b
  if b not equal to spaces
     display "error found"
  end-if   
  SET SPACES-FOUND TO TRUE                   
END-IF                                         
END-PERFORM


Cris
Back to top
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1287
Location: Chennai, India

PostPosted: Wed Sep 17, 2008 11:34 am
Reply with quote

Sambhaji,

Quote:
IF DESTVAR2(1:1) NOT = ' ' THEN
DISPLAY "YOUR ERROR MESSAGE".


What if the first byte after the first space is also spaces and next few bytes with characters? In that case i think your code would not display the error message.

The above code should be put in a loop with the check for the spaces.
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Wed Sep 17, 2008 12:39 pm
Reply with quote

lil correction to code
Code:


*WS
01 ORIGVAR PIC X(30) VALUE 'UDAY KIRAN'
01 TRUNCVAR PIC X(15).                 
01 DESTVAR1 PIC X(15).                 
01 DESTVAR2 PIC X(15).                 

*PD
MOVE ORIGVAR(1:15) TO TRUNCVAR.     
UNSTRING TRUNCVAR DELIMITED BY ALL SPACES
INTO DESTVAR1 DESTVAR2.             
IF DESTVAR2(1:1) NOT =  ' ' THEN     
DISPLAY "YOUR ERROR MESSAGE".     


It sould be ALL SPACES
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 INSPECT, TALLYING and then REPLACING COBOL Programming 1
No new posts Reference modification with tallying ... COBOL Programming 1
No new posts Why TALLYING field increments when th... COBOL Programming 10
Search our Forums:

Back to Top