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

Replace Multiple Field values to Other Values with DFSORT


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
pinakimishra

New User


Joined: 21 Jul 2007
Posts: 24
Location: phoenix

PostPosted: Thu Jan 04, 2024 6:58 am
Reply with quote

I have an i/p file like below where I am adding Delimiters after each field.

ID FIELD1 FIELD2 FIELD3 FIELD4 FIELD5 FIELD6 FIELD7 FIELD8
1 SCIENCE 40
2 MATH 80
3 SCIENCE 70

The Sotcard looks like below

SORT FIELDS=COPY
OUTFIL FNAMES=SORTOUT,VTOF,
OUTREC=(5,6, ID
C',', Deimiter
11,8, Field1
C',', Deimiter
19,4, Field2
C',', Deimiter
23,7, Field3
C',', Deimiter
30,6, Field4
C',', Deimiter
36,4, Field5
C',', Deimiter
40,1, Field6
C',', Deimiter
41,5, Field7
C',', Deimiter
46,3) Field8

Alongwith the Addition of the Delimiter I want to replace few fields
I want to replace Field3, Field 6, Field8. These fields have 2 possible values. When Field3 is SCIENCE then it will be replaced as ABCDEFG Else it will be replaced as GHIJKLM. When Field6 is X'00' then 0 Else 1. When Field8 is SUN THEN Relace with CAR ELSE REPLACE WITH BUS.

This can be done thrugh an OUTREC BUILD and IF THEN but I have more than 10 fields which I need to replace and can't repeat them with all the combinations.

Please suggest if there is an easier way
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1329
Location: Bamberg, Germany

PostPosted: Thu Jan 04, 2024 10:43 am
Reply with quote

Use code tags when providing code/data. Otherwise it's hard to read for most of us.

Consider using FINDREP for replacing single or multiple fields at once. Single fields can also be changed by a CHANGE in BUILD statement.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2127
Location: USA

PostPosted: Thu Jan 04, 2024 8:29 pm
Reply with quote

Please, try to be polite to potential readers, if only you plan to get help:

pinakimishra wrote:
I have an i/p file like below where I am adding Delimiters after each field.

Code:
ID    FIELD1   FIELD2   FIELD3  FIELD4   FIELD5   FIELD6  FIELD7 FIELD8 
1      SCIENCE   40
2      MATH      80
3      SCIENCE   70


The Sotcard looks like below

Code:
SORT FIELDS=COPY
OUTFIL FNAMES=SORTOUT,VTOF,
OUTREC=(5,6,          ID
        C',',         Deimiter
        11,8,          Field1
        C',',         Deimiter
        19,4,          Field2
        C',',         Deimiter 
        23,7,          Field3
        C',',         Deimiter 
        30,6,          Field4
        C',',         Deimiter 
        36,4,          Field5
        C',',         Deimiter 
        40,1,          Field6
        C',',         Deimiter 
        41,5,          Field7
        C',',         Deimiter 
        46,3)          Field8


Alongwith the Addition of the Delimiter I want to replace few fields
I want to replace Field3, Field 6, Field8. These fields have 2 possible values. When Field3 is SCIENCE then it will be replaced as ABCDEFG Else it will be replaced as GHIJKLM. When Field6 is X'00' then 0 Else 1. When Field8 is SUN THEN Relace with CAR ELSE REPLACE WITH BUS.

This can be done thrugh an OUTREC BUILD and IF THEN but I have more than 10 fields which I need to replace and can't repeat them with all the combinations.

Please suggest if there is an easier way
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2127
Location: USA

PostPosted: Thu Jan 04, 2024 9:27 pm
Reply with quote

Rule #1: try to assign meaningful names to any object of your code, rather then giving them stupid and useless names like FIELD1, STEP01, VAR3, etc.

Rule #2: try to add comments to any part of your code
Code:
//*=====================================================================
//* GENERATE TEST DATA IN REQUIRED FORMAT                               
//*=====================================================================
//FTOV     EXEC PGM=IEBGENER                                           
//SYSPRINT DD  SYSOUT=*                                                 
//SYSIN    DD  DUMMY                                                   
//SYSUT1   DD  *                                                       
1     11111111222233333334444445555677777888                           
2     111111112222SCIENCE4444445555 77777SUN                           
3     111111112222MATH   4444445555677777WED                           
//*-+----1----+----2----+----3----+----4----+----5----+----6----+----7 
//*                                                                     
//SYSUT2   DD  DISP=(NEW,PASS),DSN=&&VFORMAT,                           
//             SPACE=(TRK,(10,10),RLSE),                               
//             RECFM=VB,LRECL=104,BLKSIZE=0                             
//*                                                                     
//*=====================================================================
//* CONVERT INPUT RECFM=VB DATA TO CSV FORMAT, RECFM=FB                 
//*=====================================================================
//CSVDATA  EXEC PGM=SORT                                               
//SYSOUT   DD  SYSOUT=*                                                 
//*                                                                     
//SYMNAMES DD  *                                                       
RDW,1,4,BI             RECFM=V DESCRIPTION WORD                         
*      FIELDS ARE GOING ONE AFTER ONE; NO NEED TO CALCULATE POSITIONS! 
ID,*,6,CH                                                             
FIELD1,*,8,CH                                                         
FIELD2,*,4,CH                                                         
FIELD3,*,7,CH                                                         
FIELD4,*,6,CH                                                         
FIELD5,*,4,CH                                                         
FIELD6,*,1,CH                                                         
FIELD7,*,5,CH                                                         
FIELD8,*,3,CH                                                         
* . . . . . . .                                                       
DELIMITER,C','        FIELD DELIMITER; SUBJECT TO CHANGE IN THE FUTURE
//*                                                                   
//SORTIN   DD  DISP=(OLD,DELETE),DSN=&&VFORMAT                       
//SORTOUT  DD  SYSOUT=*,RECFM=FB,LRECL=100,BLKSIZE=0                 
//*                                                                   
//SYSIN    DD  *                                                     
 SORT FIELDS=COPY                                                     
 OUTFIL FNAMES=SORTOUT,VTOF,                                         
       OUTREC=(ID,DELIMITER,                                         
               FIELD1,DELIMITER,                                     
               FIELD2,DELIMITER,                                     
               FIELD3,CHANGE=(7,C'SCIENCE',C'ABCDEFG'),               
                      NOMATCH=(C'GHIJKLM'),                           
               DELIMITER,                                             
               FIELD4,DELIMITER,                                     
               FIELD5,DELIMITER,                                         
               FIELD6,CHANGE=(1,X'00',C'0'),                             
                      NOMATCH=(C'1'),                                   
               DELIMITER,                                               
               FIELD7,DELIMITER,                                         
               FIELD8,CHANGE=(3,C'SUN',C'CAR'),                         
                      NOMATCH=(C'BUS'))                                 
 END                                                                     
//*                                                                     
//*=====================================================================


Code:
********************************* TOP OF DATA **********
1     ,11111111,2222,GHIJKLM,444444,5555,1,77777,BUS   
2     ,11111111,2222,ABCDEFG,444444,5555,0,77777,CAR   
3     ,11111111,2222,GHIJKLM,444444,5555,1,77777,BUS   
******************************** BOTTOM OF DATA ********
Back to top
View user's profile Send private message
pinakimishra

New User


Joined: 21 Jul 2007
Posts: 24
Location: phoenix

PostPosted: Fri Jan 05, 2024 7:53 pm
Reply with quote

Thanks for the response. I tried the below and it throws a Syntax error. Seems it's not recognizing CHANGE.

ICE143I 0 BLOCKSET COPY TECHNIQUE SELECTED
ICE250I 0 VISIT www.ibm.com/storage/dfsort FOR DFSORT PAPERS, EXAMPLES AN
ICE000I 1 - CONTROL STATEMENTS FOR 5650-ZOS, Z/OS DFSORT V2R5 - 09:10 ON FRI JA
SORT FIELDS=COPY
OUTFIL FNAMES=SORTOUT,VTOF,
OUTREC=(5,6,PD,EDIT=('STTTTTTTTTT'),SIGNS=(+,-),
C'~}|',
11,4,
C'~}|',
15,10,
C'~}|',CHANGE=(25,X'FF',C'Y',NOMATCH=C'N'),
$
ICE007A 1 SYNTAX ERROR
C'~}|',
$
ICE007A 1 SYNTAX ERROR
26,10,
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2127
Location: USA

PostPosted: Fri Jan 05, 2024 8:26 pm
Reply with quote

pinakimishra wrote:
Thanks for the response. I tried the below and it throws a Syntax error. Seems it's not recognizing CHANGE.

Code:
ICE143I 0 BLOCKSET     COPY  TECHNIQUE SELECTED
ICE250I 0 VISIT http://www.ibm.com/storage/dfsort FOR DFSORT PAPERS, EXAMPLES AN
ICE000I 1 - CONTROL STATEMENTS FOR 5650-ZOS, Z/OS DFSORT V2R5  - 09:10 ON FRI JA
              SORT FIELDS=COPY
              OUTFIL FNAMES=SORTOUT,VTOF,
              OUTREC=(5,6,PD,EDIT=('STTTTTTTTTT'),SIGNS=(+,-),
                  C'~}|',
                  11,4,
                  C'~}|',
                  15,10,
                  C'~}|',CHANGE=(25,X'FF',C'Y',NOMATCH=C'N'),
                          $
ICE007A 1 SYNTAX ERROR
                  C'~}|',
                   $
ICE007A 1 SYNTAX ERROR
                  26,10,

The inability of newcomers to simply RTFM just makes me crazy...

Please, try to verify the syntax of CHANGE and NOMATCH parameters carefully, and fix your own error.

I gave you the READY-TO-COPY-AND-PASTE solution (despite my rules), but you are still not able even to count commas, and parenthesis!

Use //SYMNAMES feature to make your code a little bit maintainable in the future!

I remind you again: DO NOT USE SCREENSHOTS in your messages. Use the Code button instead, please!!!
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1329
Location: Bamberg, Germany

PostPosted: Sat Jan 06, 2024 5:42 pm
Reply with quote

Learning from mistakes helps fairly often.

Symbols are a good choice to use when you have too much variables. I for myself find it easier to use mixed case for variable names. Even a type writer could distinguish between upper and lower case, and that was some time ago. ;)
Back to top
View user's profile Send private message
pinakimishra

New User


Joined: 21 Jul 2007
Posts: 24
Location: phoenix

PostPosted: Sat Jan 06, 2024 10:53 pm
Reply with quote

Thanks for the inputs. Got the issue with the Syntax fixed. Also got a hang of the symbols usage which I hadn't done before.

I have some special characters in FIELD4 and FIELD7 which I need to replace with Spaces.

I/P

Code:
--------------------------------------------
1     11111111222233333334444445555677777888
F44444FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
10000011111111222233333334444445555677777888
--------------------------------------------
2     111111112222SCIENCE4 4 4 5555 7 7 7SUN
F44444FFFFFFFFFFFFECCCDCCF0FFF0FFFF4F1F3FEED
2000001111111122222395535404F45555507A7A7245
--------------------------------------------
3     111111112222MATH   ^4 4 455556 7 77WED
F44444FFFFFFFFFFFFDCEC444BF0F4FFFFFF1F1FFECC
30000011111111222241380000484145555637577654
--------------------------------------------


Required O/P

Code:
1     ,11111111,2222,GHIJKLM,444444,5555,1,77777,BUS
F444446FFFFFFFF6FFFF6CCCDDDD6FFFFFF6FFFF6F6FFFFF6CEE
100000B11111111B2222B7891234B444444B5555B1B77777B242
-----------------------------------------------------
2     ,11111111,2222,ABCDEFG,4 4 4 ,5555,1,7 7 7,CAR
F444446FFFFFFFF6FFFF6CCCCCCC6F4F4F46FFFF6F6F4F4F6CCD
200000B11111111B2222B1234567B404040B5555B1B70707B319
-----------------------------------------------------
3     ,11111111,2222,GHIJKLM, 4 4 4,5555,1, 7 77,BUS
F444446FFFFFFFF6FFFF6CCCDDDD64F4F4F6FFFF6F64F4FF6CEE
300000B11111111B2222B7891234B040404B5555B1B07077B242


I can do that with an INREC FINDREP on the entire record like below. But is there a simpler way to do that at Field Level i.e. I can apply that to only Field4 and Field7 so that it doesn't have to go through all the fields?

Code:
//*=====================================================================
//* GENERATE TEST DATA IN REQUIRED FORMAT
//*=====================================================================
//FTOV     EXEC PGM=IEBGENER
//SYSPRINT DD  SYSOUT=*
//SYSIN    DD  DUMMY
//SYSUT1   DD  *
1     11111111222233333334444445555677777888
2     111111112222SCIENCE4 4 4 5555 7 7 7SUN
3     111111112222MATH   ^4 4 455556 7 77WED
//*-+----1----+----2----+----3----+----4----+----5----+----6----+----7
//*
//SYSUT2   DD  DISP=(NEW,PASS),DSN=&&VFORMAT,
//             SPACE=(TRK,(10,10),RLSE),UNIT=SYSDA,
//             RECFM=VB,LRECL=104,BLKSIZE=0
//*
//*=====================================================================
//* CONVERT INPUT RECFM=VB DATA TO CSV FORMAT, RECFM=FB
//*=====================================================================
//CSVDATA  EXEC PGM=SORT
//SYSOUT   DD  SYSOUT=*
//*
//SYMNAMES DD  *
RDW,1,4,BI             RECFM=V DESCRIPTION WORD
*      FIELDS ARE GOING ONE AFTER ONE; NO NEED TO CALCULATE POSITIONS!
ID,*,6,CH
FIELD1,*,8,CH
FIELD2,*,4,CH
FIELD3,*,7,CH
FIELD4,*,6,CH
FIELD5,*,4,CH
FIELD6,*,1,CH
FIELD7,*,5,CH
FIELD8,*,3,CH
DELIMITER,C','        FIELD DELIMITER; SUBJECT TO CHANGE IN THE FUTURE
//*
//SORTIN   DD  DISP=(OLD,DELETE),DSN=&&VFORMAT
//SORTOUT  DD  SYSOUT=*,RECFM=FB,LRECL=52,BLKSIZE=0
//*
//SYSIN    DD  *
 SORT FIELDS=COPY
 INREC FINDREP=(INOUT=(X'00',X'40',X'40',X'40',X'05',X'40',
                      X'B0',X'40',X'1A',X'40',X'3A',X'40',
                      X'01',X'40',X'41',X'40',X'13',X'40',
                      X'15',X'40',X'08',X'40',X'FF',X'40'))
 OUTFIL FNAMES=SORTOUT,VTOF,
       OUTREC=(ID,DELIMITER,
               FIELD1,DELIMITER,
               FIELD2,DELIMITER,
               FIELD3,CHANGE=(7,C'SCIENCE',C'ABCDEFG'),
                      NOMATCH=(C'GHIJKLM'),
               DELIMITER,
               FIELD4,DELIMITER,
                           FIELD5,DELIMITER,
               FIELD6,CHANGE=(1,X'00',C'0'),
                      NOMATCH=(C'1'),
               DELIMITER,
               FIELD7,DELIMITER,
               FIELD8,CHANGE=(3,C'SUN',C'CAR'),
                      NOMATCH=(C'BUS'))
 END
//*
//*==================================================================
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2127
Location: USA

PostPosted: Sun Jan 07, 2024 6:27 am
Reply with quote

Read about the statement ALTSEQ CODE= and parameter TRAN=ALTSEQ

Also: shift the line “FIELD5,DELIMETER,” back to its proper position. Minor inaccuracies lead to big problems after a while.
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1329
Location: Bamberg, Germany

PostPosted: Sun Jan 07, 2024 12:27 pm
Reply with quote

@sergeyken is absolutely right. ALTSEQ and TRAN are most of the time easier to handle for single bytes. CHANGE operator is good for single field replacements, and FINDREP finally, the ultimate weapon for multiple fields in a record.

Besides the SORT coding, any reason to use DISP=(OLD,DELETE) on SORTIN when you are passing the DSN? IMHO it should be DISP=(OLD,PASS)
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2127
Location: USA

PostPosted: Sun Jan 07, 2024 8:08 pm
Reply with quote

Joerg.Findeisen wrote:

Besides the SORT coding, any reason to use DISP=(OLD,DELETE) on SORTIN when you are passing the DSN? IMHO it should be DISP=(OLD,PASS)

This is a specific test-related update: the temporary data created exclusively by the previous step, in required format. In such case it is usually not needed later. But of course, it depends…
Back to top
View user's profile Send private message
pinakimishra

New User


Joined: 21 Jul 2007
Posts: 24
Location: phoenix

PostPosted: Mon Jan 08, 2024 8:15 am
Reply with quote

Thanks for the inputs. Both INREC FINDREP with INOUT parameters at all Field levels as well as the ALTSEQ CODE= and parameter TRAN=ALTSEQ at multiple field level with OUTREC worked well and didn't see much performance difference between these 2 options. So based on the requirement we can apply any of these I suppose. These worked when the combination of i/p and changed o/p of characters is same across all fields.

If different fields have different requirements then tried with INREC IFTHEN FINDREP with STARTPOS and ENDPOS. If there is any other approach for this then will like to know that.

Code:
 SORT FIELDS=COPY
 INREC IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(X'00',X'F4',X'FF',X'F4',
                      X'B0',X'5F',X'41',X'F4',X'08',X'F4',X'05',X'F4'),
                      STARTPOS=30,ENDPOS=35)),
       IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(X'1A',X'F7',X'3A',X'F7',
                      X'15',X'F7',X'13',X'F7'),STARTPOS=41,ENDPOS=45))
 OUTFIL FNAMES=SORTOUT,VTOF,
       OUTREC=(ID,DELIMITER,
               FIELD1,DELIMITER,
               FIELD2,DELIMITER,
               FIELD3,CHANGE=(7,C'SCIENCE',C'ABCDEFG'),
                      NOMATCH=(C'GHIJKLM'),
               DELIMITER,
               FIELD4,DELIMITER,
               FIELD5,DELIMITER,
               FIELD6,CHANGE=(1,X'00',C'0'),
                      NOMATCH=(C'1'),
               DELIMITER,
               FIELD7,DELIMITER,
               FIELD8,CHANGE=(3,C'SUN',C'CAR'),
                      NOMATCH=(C'BUS'))
 END
//*
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2127
Location: USA

PostPosted: Mon Jan 08, 2024 10:21 pm
Reply with quote

Just no comments.
Comments are useless in this topic...

In order to compare performance you may need 1,000,000-100,000,000 records in your test.

Method 1:
Code:
 SORT FIELDS=COPY
 OUTFIL FNAMES=SORTOUT,VTOF,
       OUTREC=(ID,DELIMITER,
               FIELD1,DELIMITER,
               FIELD2,DELIMITER,
               FIELD3,CHANGE=(7,C'SCIENCE',C'ABCDEFG'),
                      NOMATCH=(C'GHIJKLM'),
               DELIMITER,
               FIELD4,CHANGE=(1,X'00',C'4',
                                X'FF',C'4',
                                X'B0',C'5',
                                X'41',C'4',
                                X'08',C'4',
                                X'05',C'4'),
               DELIMITER,
               FIELD5,DELIMITER,
               FIELD6,CHANGE=(1,X'00',C'0'),
                      NOMATCH=(C'1'),
               DELIMITER,
               FIELD7,CHANGE=(1,X'1A',C'7',
                                X'3A',C'7',
                                X'15',C'7',
                                X'13',C'7'),
               DELIMITER,
               FIELD8,CHANGE=(3,C'SUN',C'CAR'),
                      NOMATCH=(C'BUS'))
 END
//*


Method 2:
Code:
 ALTSEQ CODE=(00F4FFF4B0F541F408F405F41AF73AF715F713F7)
 SORT FIELDS=COPY
 OUTFIL FNAMES=SORTOUT,VTOF,
       OUTREC=(ID,DELIMITER,
               FIELD1,DELIMITER,
               FIELD2,DELIMITER,
               FIELD3,CHANGE=(7,C'SCIENCE',C'ABCDEFG'),
                      NOMATCH=(C'GHIJKLM'),
               DELIMITER,
               FIELD4,TRAN=ALTSEQ,
               DELIMITER,
               FIELD5,DELIMITER,
               FIELD6,CHANGE=(1,X'00',C'0'),
                      NOMATCH=(C'1'),
               DELIMITER,
               FIELD7,TRAN=ALTSEQ,
               DELIMITER,
               FIELD8,CHANGE=(3,C'SUN',C'CAR'),
                      NOMATCH=(C'BUS'))
 END
//*
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 combine multiple unique records into ... DFSORT/ICETOOL 2
No new posts Date format correction using dfsort DFSORT/ICETOOL 3
No new posts Sorting Date Field DFSORT/ICETOOL 4
No new posts how to eliminate null indicator value... DB2 7
No new posts SORT JCL to merge multiple tow into s... DFSORT/ICETOOL 6
Search our Forums:

Back to Top