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
 

 

Syntax to check the first 4 digits of a number.

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
View previous topic :: :: View next topic  
Author Message
kshirabdhi

New User


Joined: 22 Nov 2007
Posts: 13
Location: Noida

PostPosted: Tue May 03, 2016 12:21 pm    Post subject: Syntax to check the first 4 digits of a number.
Reply with quote

Hi All,

I am using SORT to fetch records from a file based on a condition.

Fields part of INCLUDE COND are -

Code:
 TRAN-CODE       PIC  9(05).   
 TRACE-NUMBER    PIC  9(11).   


Requirement -

Fetch records where
1. TRAN-CODE = 101 and
2. TRACE-NUMBER begins with 9954 OR 9568 (excluding the leading zeros)

Position of TRAN-CODE is 1 and TRACE-NUMBER is 7. Number of digits in TRACE-NUMBER can be from 5 to 11.

Input data -

Code:
00101 00000995412
00101 00995412234
00101 00090541274
00101 09568123421
00101 00956895412
00101 00956790989


Output -
Code:
00101 00000995412
00101 00995412234
00101 09568123421
00101 00956895412


I am unable to write the syntax for condition for TRACE-NUMBER. The reason why I am using SORT is , I am extracting data from a file for validation with a report after production implementation.

Please help if SORT has any function/syntax for this. Let me know if I need to furnish more details.
Back to top
View user's profile Send private message

enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Tue May 03, 2016 2:25 pm    Post subject: Reply to: Syntax to check the first 4 digits of a number.
Reply with quote

quick and dirty ( just to show the logic )

Code:
    INCLUDE COND=(7,9,CH,EQ,C'000009954',OR,
                  7,8,CH,EQ,C'00009954',OR, 
                  7,7,CH,EQ,C'0009954',OR,
                  7,6,CH,EQ,C'009954',OR,
                  7,5,CH,EQ,C'09954',OR,
                  7,4,CH,EQ,C'9954',OR,
                  ...           
 
Back to top
View user's profile Send private message
Abid Hasan

New User


Joined: 25 Mar 2013
Posts: 65
Location: India

PostPosted: Tue May 03, 2016 3:00 pm    Post subject:
Reply with quote

Hello,

Have a look at Substring (operator) comparison tests of INCLUDE function in DFSORT; it should give you what you need.

You can look here, for some information on how to use it.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7224

PostPosted: Tue May 03, 2016 4:42 pm    Post subject: Reply to: Syntax to check the first 4 digits of a number.
Reply with quote

The problem with using the substring search is that you are open to "false hits".

A record with non-zero leading "69954", for instance, would be selected.

enrico's suggestion is the way to do it.
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1609
Location: NY,USA

PostPosted: Tue May 03, 2016 9:45 pm    Post subject:
Reply with quote

Try this,
Code:
//SORTIN  DD *                                                     
00101 00000995412                                                 
00101 00995412234                                                 
00101 00090541274                                                 
00101 09568123421                                                 
00101 00956895412                                                 
00101 00956790989                                                 
//SORTOUT DD SYSOUT=*                                             
//SYSIN DD *                                                       
  INREC IFTHEN=(WHEN=(1,5,CH,EQ,C'00101'),                         
         OVERLAY=(7:7,11,ZD,M10,LENGTH=11,7:7,11,SQZ=(SHIFT=LEFT))),
            IFTHEN=(WHEN=NONE,BUILD=(1,17))
  OUTFIL INCLUDE=(7,4,CH,EQ,C'9954',OR,7,4,CH,EQ,C'9568',         
                  AND,1,5,CH,EQ,C'00101'),                         
         BUILD=(1,5,X,7,11,UFF,M11)                               
      OPTION COPY     
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7224

PostPosted: Wed May 04, 2016 1:32 am    Post subject: Reply to: Syntax to check the first 4 digits of a number.
Reply with quote

Rohit,

If you INCLUDE/OMIT COND= you can avoid the repeated record-type test. There's no point in a case like this of retaining data only to ignore it later.

However, there's not indication that there are other than 00101 records, so why bother?

There's no need for the WHEN=NONE if you are just going to BUILD the same record that already exists.

To use an edit mask to get rid of the leading zeros and then SQZ is a good idea, but I don't think you need to destroy the original data just to recreate it later. Extend the record. You can also use LENGTH=4 on the SQZ, as only four characters are wanted, and IFOUTLEN to limit the records (not no important for a COPY, but for a SORT you'd not need spurious extra data hanging around).

There's also no point, in this case, of recreating the first part of the record in the OUTFIL. It is just sitting there already as 1,6. You could OVERLAY with your second EDIT. However, having not destroyed the input, a simple BUILD to cut off the extension.

Code:
  OPTION COPY
                                     
  INREC IFTHEN=(WHEN=INIT,
         OVERLAY=(18:
                   7,11,
                    ZD,
                    M10,
                    LENGTH=11,
                   18:
                    18,11,
                   JFY=(SHIFT=LEFT,
                        LENGTH=4))),
        IFOUTLEN=21
 
  OUTFIL INCLUDE=(18,4,CH,EQ,C'9954',
                 OR,
                  18,4,CH,EQ,C'9568'),
         BUILD=(1,17)
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1609
Location: NY,USA

PostPosted: Wed May 04, 2016 1:40 am    Post subject:
Reply with quote

Thanks for the notes Bill. that makes me learn and improve my dfsort logic.
I assumed TS wanted onetime sort card so did try some quick sort but your tips certainly helps.
Quote:
However, there's not indication that there are other than 00101 records, so why bother?

TS say's
Quote:
Fetch records where
1. TRAN-CODE = 101 and
2. TRACE-NUMBER begins with 9954 OR 9568 (excluding the leading zeros)
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7224

PostPosted: Wed May 04, 2016 3:04 am    Post subject: Reply to: Syntax to check the first 4 digits of a number.
Reply with quote

Yes, I missed that. There are no other record-types in the sample data. A simple INCLUDE COND= as well, then.

For the actual task, with only two selections, and from a fairly short length of data, enrico's is the best solution. As the number of selections increase, and the length of the data increases, this one comes more into play.

Preserving the original data is not sacrosanct. There are many occasions where changing the data temporarily then setting it back are the best solution to a task. It need not matter if five zeros are removed and five zeros in the same position are added later. However, there is usually no point in doing it just for the sake of doing it.

Note: if dropping the leading zeros for spaces in the original position Abid's SS, with a leading blank for the value, becomes possible. The leading zeros have to be returned later. Although it works, it is likely more expensive.

Oh, and JFY for this is better than SQZ. I'll update my previous post for that.
Back to top
View user's profile Send private message
Abid Hasan

New User


Joined: 25 Mar 2013
Posts: 65
Location: India

PostPosted: Wed May 04, 2016 10:51 am    Post subject:
Reply with quote

To Bill,
Thank you, that was helpful and gave quite a few pointers to better the DFSORT logic.
Back to top
View user's profile Send private message
kshirabdhi

New User


Joined: 22 Nov 2007
Posts: 13
Location: Noida

PostPosted: Wed May 04, 2016 11:15 am    Post subject:
Reply with quote

I used Bill's trick as the requirement I have mentioned is part of a bigger selection condition and the data length is also larger. It served the purpose.

Thank you all for taking out your valuable time to propose different solutions. I learnt some new SORT tricks.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7224

PostPosted: Wed May 04, 2016 12:17 pm    Post subject: Reply to: Syntax to check the first 4 digits of a number.
Reply with quote

If you already have something which you need to amend for new processing, it is always best to post what you already have. There can be different solutions which each are a better fit for one set of existing control cards or another.

If you can show what you have come up with, we will be able to make concrete suggestions for that context.
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 -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts What is the command to check MODE of ... rohanthengal CLIST & REXX 6 Fri Nov 18, 2016 1:48 pm
No new posts Check System time(Minute) Using TIME1... balaji81_k DFSORT/ICETOOL 5 Fri Nov 11, 2016 10:53 am
No new posts Sequence number add in SORT pshongal SYNCSORT 3 Fri Sep 02, 2016 3:32 pm
No new posts Casting a Binary Number to Numeric in... Bob Steinkraus Java & MQSeries 6 Tue Aug 09, 2016 5:58 pm
No new posts Syntax for running batch history repo... polymathtarun CA Products 1 Tue Jun 21, 2016 1:51 pm


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