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
 

 

How to check for the last 2 chars of a field of varying data

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

New User


Joined: 20 Jul 2009
Posts: 24
Location: Mumbai

PostPosted: Fri Jun 11, 2010 3:14 pm    Post subject: How to check for the last 2 chars of a field of varying data
Reply with quote

I have a field called WS-GROUP PIC X(15)
The length of the contents of the field can vary.
I need to put a check that if the last 2 chars of the value is 'XY'
I execute some code else I execute some other code.

The only thing that comes to my mind is that first I have to calculate the length of the contents of the field and then I can use reference modification for the check.But I am not sure what logic to use to calculate
the length of the data.Length function will always give 15 for the field which is not what I want.

Or I can read backwards and take the first 2 chars.Again I am not sure what logic to be used to read backwards.

Can anyone please give the logic?Thanks in advance...
Back to top
View user's profile Send private message

Phrzby Phil

Active Member


Joined: 31 Oct 2006
Posts: 962
Location: Richmond, Virginia

PostPosted: Fri Jun 11, 2010 5:08 pm    Post subject:
Reply with quote

I presume you mean that the length of the non-blank contents can vary, as the length of the contents is always 15. Blank (x'40') is a character, too.

PERFORM VARYING a numeric variable from 15 by -1 UNTIL you have your two non-blanks or variable < 1, in which case it's all blank.

Suppose you have 'ABC D '. Do you want the blank-D?

If you have just one non-blank, then 14 blanks, do you want that?
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Fri Jun 11, 2010 7:16 pm    Post subject:
Reply with quote

Hi Jnana,

Hoping I understood your requirement .... icon_razz.gif

Use this link as a base for your requirement

Step 1 : Use INSPECT to get the count of trailing spaces
Step 2 : Use the count along with the reference modification to do the comparison ...
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 Jun 11, 2010 7:47 pm    Post subject: Reply to: How to check for the last 2 chars of a field of va
Reply with quote

Another way, which won't expand into calling any COBOL run-time routine(s) -

Code:

           03  WS-GROUP            PIC  X(15).
           03  WS-SUB              PIC S9(08)      BINARY.
           03  WS-POS              PIC S9(08)      BINARY.
*
           MOVE SPACES                 TO WS-GROUP.
           MOVE 'XY'                   TO WS-GROUP (10:2).
           MOVE LENGTH OF WS-GROUP     TO WS-SUB.
           MOVE ZERO                   TO WS-POS.
*
           PERFORM UNTIL WS-SUB < 1
               IF  WS-GROUP (WS-SUB:1) = 'X'
                   IF  WS-SUB < LENGTH OF WS-GROUP
                       IF  WS-GROUP (WS-SUB + 1:1) = 'Y'
                           MOVE WS-SUB TO WS-POS
                           MOVE 1      TO WS-SUB
                       END-IF
                   END-IF
               END-IF
               ADD -1                  TO WS-SUB
           END-PERFORM.
*
           IF  WS-POS NOT = ZERO
               PERFORM CHARACTERS-FOUND
           ELSE
               PERFORM CHARACTERS-NOT-FOUND
           END-IF.

After completing the PERFORM, WS-POS will contain the position in WS-GROUP where 'XY' can be found, traversing backwards. In this example, the position will be 10.

The example code only recognizes the last occurrence in WS-GROUP of an 'X' followed immediately by a 'Y'.

Bill
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Fri Jun 11, 2010 8:24 pm    Post subject: Re: How to check for the last 2 chars of a field of varying
Reply with quote

JnanaR wrote:
The only thing that comes to my mind is that first I have to calculate the length of the contents of the field and then I can use reference modification for the check.But I am not sure what logic to use to calculate
the length of the data.Length function will always give 15 for the field which is not what I want.
"The LENGTH function returns an integer equal to the length of the argument"
"The LENGTH OF special register contains the number of bytes used by a data item."
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Fri Jun 11, 2010 9:52 pm    Post subject:
Reply with quote

Hi CICS Guy,

Just a little curious ... icon_razz.gif

A snapshot from the link u sent ...
Quote:
The intrinsic function LENGTH can also be used to obtain the length of a data item. For data items of usage NATIONAL , the length returned by the LENGTH function is the number of national character positions, rather than bytes; thus the LENGTH OF special register and the LENGTH intrinsic function have different results for data items of usage NATIONAL . For all other data items, the result is the same


Will this work for OP's requirement ?
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Fri Jun 11, 2010 10:12 pm    Post subject:
Reply with quote

Without a compiler handy....
Since the "type of the function is integer" and reference modification requires a "positive nonzero integer" for the "leftmost-character-position", I thought it might.
Back to top
View user's profile Send private message
JnanaR

New User


Joined: 20 Jul 2009
Posts: 24
Location: Mumbai

PostPosted: Sat Jun 12, 2010 12:22 am    Post subject:
Reply with quote

Thanks for the response guys.I have done it ery close to Bill's logic.
Thanks Bill....
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Sat Jun 12, 2010 12:44 am    Post subject:
Reply with quote

Code:
IF WS-GROUP(LENGTH of WS-GROUP - 1:2) = 'XY'
  DO whatever
ELSE
  DO something else
END-IF
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: Sat Jun 12, 2010 3:26 am    Post subject: Reply to: How to check for the last 2 chars of a field of va
Reply with quote

Oops, just realized that populating WS-POS needs to be a calculation, not a move, because I'm going backwards (not forwards) and it should be -

Code:

COMPUTE WS-POS = (LENGTH OF WS-GROUP - WS-SUB)

(15 - 5 = 10)

Slowly removing egg from face icon_redface.gif

Bill
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 Check Binary Values for symbols gandikk CA Products 3 Tue Mar 21, 2017 5:11 am
No new posts Export flat file data into excel sheet murali.andaluri DFSORT/ICETOOL 2 Mon Mar 20, 2017 5:39 pm
No new posts Append data from two files into a sin... Praveen04 DFSORT/ICETOOL 5 Thu Mar 16, 2017 7:29 pm
No new posts SORT VSAM file with each field one by... maxsubrat DFSORT/ICETOOL 6 Tue Mar 14, 2017 1:07 pm
No new posts IMS DB-How to update a record (a sing... Nic Clouston IMS DB/DC 9 Thu Mar 09, 2017 4:38 pm


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