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
 

 

To identify spaces in between alphabets/numbers

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

New User


Joined: 05 Jun 2006
Posts: 51
Location: Bangalore,India

PostPosted: Tue Jan 10, 2012 5:31 pm    Post subject: To identify spaces in between alphabets/numbers
Reply with quote

Hi,

I have requirement to check few scenarios listed below.

01 WS-VAR PIC X(08)

I should validate the above variable,

i)It should not be ZEROS --->Taken care

e.g., 0000000

ii)should not be spaces----->Taken care

iii)Should not have any spaces between numbers of aplhabets.--->Need suggestions

e.g., 12 34567---->I should display error message
ab cdefg----->I should display error message

I am trying to validate each byte by byte using PERFORM. Is there any better way that I can do it?

Thanks
Vardhan
Back to top
View user's profile Send private message

Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Tue Jan 10, 2012 5:42 pm    Post subject: Reply to: To identify spaces in between alphabets/numerics
Reply with quote

Have a look at INSPECT TALLYING.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1219
Location: Israel

PostPosted: Tue Jan 10, 2012 9:04 pm    Post subject: Reply to: To identify spaces in between alphabets/numerics
Reply with quote

Can you have spaces at the beginning or at the end?
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: Tue Jan 10, 2012 9:56 pm    Post subject: Reply to: To identify spaces in between alphabets/numerics
Reply with quote

Use the TALLY special-register (initialize to ZERO first), with the INSPECT TALLYING as Bill has suggested.

However, once the INSPECT is complete and TALLY is non-zero, then what?

Do you need to reformat the data, such as left-justified with low-order SPACES or right-justified with high-order SPACES or just a simple notification via a DISPLAY will suffice?

Mr. Bill
Back to top
View user's profile Send private message
Chiranjeevi9

New User


Joined: 14 Dec 2011
Posts: 11
Location: India

PostPosted: Wed Jan 11, 2012 11:33 am    Post subject:
Reply with quote

As Bill Suggested INSPECT with TALLYING is enough for this scenario.

EX: INSPECT WS-VAR TALLYING COUNT-1 FOR ALL SPACES.

If COUNT-1 greaterthan ZERO means, found spaces in your cobol item(WS-VAR). So DISPLAY your error message when the COUNT-1 > ZERO.

icon_biggrin.gif
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1219
Location: Israel

PostPosted: Wed Jan 11, 2012 3:28 pm    Post subject: Re: Reply to: To identify spaces in between alphabets/numeri
Reply with quote

Marso wrote:
Can you have spaces at the beginning or at the end?
Depending on the complete requirement, suggestions may or may not work...
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Wed Jan 11, 2012 3:53 pm    Post subject: Reply to: To identify spaces in between alphabets/numerics
Reply with quote

So right Marso.

Code:

 234567
 23 567
      8
1       
1 3     
1234567
 2345678
 23 5678


Would all of the above be invalid? Same with the alphas.

Requires more thought about how to use INSPECT and probably FUNCTION REVERSE, for convenience.

We can even get on to whether a mix of numbers and alpahas are valid. What about "special characters"? What about non-display data?

If the full requirement is known, it could well be best to do a loop testing for each being valid rather than trying to pick the invalid.
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: Thu Jan 12, 2012 8:01 am    Post subject: Reply to: To identify spaces in between alphabets/numerics
Reply with quote

If you need to reformat the data, review this previous post -

http://www.ibmmainframes.com/viewtopic.php?p=143786&highlight=#143786

Mr. Bill
Back to top
View user's profile Send private message
vardhan0007

New User


Joined: 05 Jun 2006
Posts: 51
Location: Bangalore,India

PostPosted: Thu Jan 19, 2012 11:57 am    Post subject: Reply to: To identify spaces in between alphabets/numerics
Reply with quote

Hi All,

Thank you for the replies. Below is my code.

05 WS-NEW-KYWD PIC X(08).

01 WS-NEW-KEYWORD
05 WS-NEW-KEYWORD OCCURS 8 INDEXED BY WS-IDX PIC X.


MOVE WS-NEW-KYWD TO WS-NEW-KEYWORD

INSPECT WS-NEW-KYWD TALLYING WS-CNT FOR ALL SPACES

MOVE 0 TO WS-FLG
MOVE 0 TO WS-ZERO-CNT

IF WS-CNT < 8
COMPUTE WS-CNT = 8 - WS-CNT
SET WS-IDX TO 1
PERFORM UNTIL WS-IDX > WS-CNT
IF WS-NEW-KEYWORD (WS-IDX) = ZERO
ADD 1 TO WS-ZERO-CNT
END-IF
IF WS-NEW-KEYWORD (WS-IDX) = SPACE
MOVE 1 TO WS-FLG
END-IF

SET WS-IDX UP BY 1
END-PERFORM
DISPLAY 'WS-FLG:' WS-FLG UPON CONSOLE
IF (WS-FLG = 1 OR ( WS-CNT = WS-ZERO-CNT ))
DISPLAY '** PLEASE ENTER VALID DERIVED KEYWORD **'

END-IF
END-IF
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Thu Jan 19, 2012 3:35 pm    Post subject: Reply to: To identify spaces in between alphabets/numerics
Reply with quote

If leading/trailing blanks are not valid, you have overcomplicated things by sticking to your byte-at-a-time approach.

Code:
01  WS-COUNT-BLANKS-IN-NEW-KEYWRD COMP PIC S9(4).
    88  WS-CBNK-THERE-ARE-SOME-BLANKS VALUE +1 THRU +7.
    88  WS-CBNK-THERE-ARE-ONLY-BLANKS VALUE +8.

INSPECT WS-NEW-KYWD
    TALLYING WS-COUNT-BLANKS-IN-NEW-KEYWRD
      FOR SPACE

IF ( WS-CBNK-THERE-ARE-SOME-BLANKS )
OR ( WS-NEW-KEYWD EQUAL TO ZERO )
    DISPLAY '** PLEASE ENTER VALID DERIVED KEYWORD **'
END-IF


I have left out any reference to WS-CBNK-THERE-ARE-ONLY-BLANKS as your code ignores the all blank case.

You are using WS-CNT for two purposes at the same time. Firstly to count blanks, and then as an arbitrary value which only has a meaning for the rest of the code when it is 8.

You have a duplicate definition of WS-NEW-KEYWORD, I don't know how that works. I don't know what the "UPON CONSOLE" is about, are you running it in foreground?

What are you doing with the KEYWRD afterwards? If it is validated against a value in the program, all of the above can be avoided anyway.
Back to top
View user's profile Send private message
lindovaldolpn

New User


Joined: 25 Feb 2010
Posts: 16
Location: Brazil

PostPosted: Thu Jan 19, 2012 6:10 pm    Post subject:
Reply with quote

It´s a another way
-------------------

01 WS-VAR PIC X(08)
77 BYTE1 PIC X VALUE SPACES.
77 BYTE2 PIC X VALUE SPACES.

UNSTRING WS-VAR
INTO BYTE1 DELIMITED BY SPACE
BYTE2
END-UNSTRING
IF BYTE2 NOT EQUAL SPACES
NOTE there are at least 1 byte with spaces
END-IF

Lindovaldo
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Thu Jan 19, 2012 6:14 pm    Post subject: Reply to: To identify spaces in between alphabets/numerics
Reply with quote

Have you tried this with one or more trailing spaces? What happens?

What happens when you code this, an embedded space is found, and you go on to test the next value?
Back to top
View user's profile Send private message
lindovaldolpn

New User


Joined: 25 Feb 2010
Posts: 16
Location: Brazil

PostPosted: Thu Jan 19, 2012 6:53 pm    Post subject:
Reply with quote

it´s new source file.

ID DIVISION.
PROGRAM-ID. PGM1.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 TALLY PIC S9(4) COMP.
77 WS-VAR PIC X(08).
77 BYTE1 PIC X(01) VALUE SPACES.
77 BYTE2 PIC X(01) VALUE SPACES.
PROCEDURE DIVISION.
INICIO.
DISPLAY 'ACCEPT NUMBER'.
ACCEPT WS-VAR.
IF WS-VAR EQUAL 'EXIT' STOP RUN.
MOVE ZEROS TO TALLY.
UNSTRING WS-VAR DELIMITED BY SPACE
INTO BYTE1
BYTE2 TALLYING IN TALLY.
DISPLAY 'TALLY=' TALLY, ',WS-VAR=(' WS-VAR ')'.
IF TALLY GREATER 1
DISPLAY 'THERE ARE AT LEAST 1 BYTE'
ELSE
DISPLAY 'OK'.
GO INICIO.

When I run...

(SPLXWAA8XA) C:\COBOL>PGM1
ACCEPT NUMBER
12345678
TALLY=+0001,WS-VAR=(12345678)
OK
ACCEPT NUMBER
1 3 5 7
TALLY=+0002,WS-VAR=(1 3 5 7 )
THERE ARE AT LEAST 1 BYTE
ACCEPT NUMBER
2 4 6 8
TALLY=+0002,WS-VAR=( 2 4 6 8)
THERE ARE AT LEAST 1 BYTE
ACCEPT NUMBER
1 8
TALLY=+0002,WS-VAR=(1 8)
THERE ARE AT LEAST 1 BYTE
ACCEPT NUMBER
1
TALLY=+0002,WS-VAR=(1 )
THERE ARE AT LEAST 1 BYTE
ACCEPT NUMBER
EXIT

(SPLXWAA8XA) C:\COBOL>



I hope that it will be solve your problem.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Thu Jan 19, 2012 7:37 pm    Post subject: Reply to: To identify spaces in between alphabets/numerics
Reply with quote

Mmm...

So, you've changed your mind but want to keep it. You define two extra fields, populated (maybe) by UNSTRING, neither of which you use, just to provide an alternative to INSPECT TALLYING? Are you showing how it might be done on a PC, rather than a mainframe? Any-old-code-will-do, as long as the "right" answer pops out at the end?

And, of oourse, having been asked specifically about trailing space in your first "solution", you've tested this one with leading space, haven't you?
Back to top
View user's profile Send private message
lindovaldolpn

New User


Joined: 25 Feb 2010
Posts: 16
Location: Brazil

PostPosted: Thu Jan 19, 2012 11:12 pm    Post subject:
Reply with quote

Ok, I agree with you.

I add an option using INSPECT, I think it is a better way.


MOVE ZEROS TO COUNT1
INSPECT WS-VAR TALLYING COUNT1 FOR ALL SPACE.
IF COUNT1 GREATER ZEROS
DISPLAY 'INSPECT - THERE ARE ' COUNT1 ' BYTE/S'
ELSE
DISPLAY 'INSPECT - OK'.


Mainframe with JES3


EDIT xxxxxxxx.STS.JOBS(JPGM1) - 01.01 Columns 00001 00072
Command ===> Scroll ===> CSR
****** ***************************** Top of Data ******************************
000001 //F334021T JOB '9999999,1,SPEC',F334097,CLASS=D,MSGCLASS=S
000002 //*MAIN SYSTEM=A4
000003 //*
000004 //STEP1 EXEC PGM=PGM1
000005 //STEPLIB DD DSN=F334021.STS.LINKLIB2,DISP=SHR
000006 //SYSPRINT DD SYSOUT=*
000007 //SYSOUT DD SYSOUT=*
000008 //SYSIN DD *
000009 12345678
000010 1 3 5 7
000011 2 4 6 8
000012 1 8
000013 1
000014 EXIT
****** **************************** Bottom of Data ****************************

. . . . . . . . . . . . . . . . . . . . . . . . . . .
Jobs Resources Devices Tools Filter View Options Help
-------------------------------------------------------------------------------
F334021T JOB22679 < .STEP1 .SYSOUU > Line 1 of 21
Command ===> Scroll ===> CSR
Current Find Text: Dataset 1 of 1
---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+---->
ACCEPT NUMBER
TALLY=00001,WS-VAR=(12345678)
OK
INSPECT - OK
ACCEPT NUMBER
TALLY=00002,WS-VAR=(1 3 5 7 )
THERE ARE AT LEAST 1 BYTE
INSPECT - THERE ARE 0004 BYTE/S
ACCEPT NUMBER
TALLY=00002,WS-VAR=( 2 4 6 8)
THERE ARE AT LEAST 1 BYTE
INSPECT - THERE ARE 0004 BYTE/S
ACCEPT NUMBER
TALLY=00002,WS-VAR=(1 8)
THERE ARE AT LEAST 1 BYTE
INSPECT - THERE ARE 0006 BYTE/S
ACCEPT NUMBER
TALLY=00002,WS-VAR=(1 )
THERE ARE AT LEAST 1 BYTE
INSPECT - THERE ARE 0007 BYTE/S
ACCEPT NUMBER





Lindovaldo
Back to top
View user's profile Send private message
vardhan0007

New User


Joined: 05 Jun 2006
Posts: 51
Location: Bangalore,India

PostPosted: Fri Jan 20, 2012 8:47 am    Post subject: Reply to: To identify spaces in between alphabets/numerics
Reply with quote

Hi Bill,


01 WS-COUNT-BLANKS-IN-NEW-KEYWRD COMP PIC S9(4).
88 WS-CBNK-THERE-ARE-SOME-BLANKS VALUE +1 THRU +7.
88 WS-CBNK-THERE-ARE-ONLY-BLANKS VALUE +8.

INSPECT WS-NEW-KYWD
TALLYING WS-COUNT-BLANKS-IN-NEW-KEYWRD
FOR SPACE

IF ( WS-CBNK-THERE-ARE-SOME-BLANKS )
OR ( WS-NEW-KEYWD EQUAL TO ZERO )
DISPLAY '** PLEASE ENTER VALID DERIVED KEYWORD **'
END-IF


The above code will even restrict me to enter any space in the field. i.e.,
12345 <---last 3 bytes spaces
12 <---Last 6 bytes spaces
1 <---Last 7 bytes spaces.

Yes I am already handling all spaces and zeros in another paragraph.

This is an IMS DC program hence I am using UPON CONSOLE statement for my debugging purpose.

Thanks again.

-Vardhan
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 Row-Numbers of distinct rows? Auryn DB2 1 Thu Oct 20, 2016 4:38 pm
No new posts To trim spaces in a pipe delimited da... Nish84 COBOL Programming 16 Mon Oct 10, 2016 1:54 pm
No new posts Removing Extra Spaces in a comma sepa... Puspojit DFSORT/ICETOOL 3 Tue Sep 13, 2016 7:46 am
No new posts comparing comp-3 and unpacked numbers juares castro COBOL Programming 3 Mon May 30, 2016 6:46 pm
No new posts Identify error records krsenthil85 DFSORT/ICETOOL 11 Thu Apr 28, 2016 9:45 pm


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