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

Syntax to check the first 4 digits of a number.


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Tue May 03, 2016 2:25 pm
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: 88
Location: India

PostPosted: Tue May 03, 2016 3:00 pm
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

Moderator Emeritus


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

PostPosted: Tue May 03, 2016 4:42 pm
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

Global Moderator


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

PostPosted: Tue May 03, 2016 9:45 pm
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

Moderator Emeritus


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

PostPosted: Wed May 04, 2016 1:32 am
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

Global Moderator


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

PostPosted: Wed May 04, 2016 1:40 am
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

Moderator Emeritus


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

PostPosted: Wed May 04, 2016 3:04 am
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: 88
Location: India

PostPosted: Wed May 04, 2016 10:51 am
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
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

Moderator Emeritus


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

PostPosted: Wed May 04, 2016 12:17 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Substring number between 2 characters... DFSORT/ICETOOL 2
No new posts SCOPE PENDING option -check data DB2 2
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top