Copy partial record after a string in a record using SORT.



IBM's flagship sort product DFSORT for sorting, merging, copying, data manipulation and reporting. Includes ICETOOL and ICEGENER

Copy partial record after a string in a record using SORT.

Postby Esmayeelhusen » Thu May 04, 2023 3:03 pm

Hi All,

I have a VB, LRECL=27989 record which contain a string X'0908'. The string may occur multiple times in a record or may not present, its also not in a fixed position in the record..
I want to copy the partial record after the occurrence of this string and the next 2 bytes should be 01,02,03,04 or 05.
I have copied the partial record after the first occurrence of the string but not able to check the next 2 bytes.
Below SORT CARD is to COPY
from 6th to 5 bytes then
from 18th to 5 bytes then
from 31st to 2 bytes then
158 bytes after the first occurrence of string X'0908'.

SORT FIELDS=COPY
INCLUDE COND=(1,27989,SS,EQ,X'0908')
INREC PARSE=(%01=(STARTAFT=X'0908',FIXLEN=158)),
BUILD=(6,5,18,5,31,2,%01)

Could you please suggest how to check 2 bytes after I find the string, if the 2 bytes does not match then I should search next occurrence of the string in record and then check 2 bytes.
Please let me know if you need more information.

Thanks
Husen
Esmayeelhusen
 
Posts: 13
Joined: Thu May 04, 2023 1:57 pm
Has thanked: 3 times
Been thanked: 0 time

Re: Copy partial record after a string in a record using SOR

Postby sergeyken » Fri May 05, 2023 1:40 pm

For RECFM=VB you must take into account the RDW as if it was an actual part of your record. So, all and every offset value in your statements must be adjusted accordingly.

Next, you may need to re-parse your record twice, to get a separate two-bytes field as %02 variable, to be compared as you need. Another way may be, checking the two bytes at the position where %01 value is inserted, in OUTFIL statement.

The third, I do not see a simple way to handle multiple occurrences of X’0908’ within one record. Before thinking of this problem, please resolve all issues with missing RDW field.

Please! Use the Code button to present your samples of code and/or data.
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 409
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 6 times
Been thanked: 40 times

Re: Copy partial record after a string in a record using SOR

Postby Esmayeelhusen » Fri May 05, 2023 3:48 pm

Hi Sergeyken,
Thanks for your time and reply.
I have converted the file to (FB, LRECL=27989), so i believe RDW is not required.
I will try to re-parse 2 byte field %02 and let the forum know.

Thanks
Husen
Esmayeelhusen
 
Posts: 13
Joined: Thu May 04, 2023 1:57 pm
Has thanked: 3 times
Been thanked: 0 time

Re: Copy partial record after a string in a record using SOR

Postby sergeyken » Sat May 06, 2023 3:16 pm

Esmayeelhusen wrote:Hi Sergeyken,
Thanks for your time and reply.
I have converted the file to (FB, LRECL=27989), so i believe RDW is not required.
I will try to re-parse 2 byte field %02 and let the forum know.

Thanks
Husen

Ok.
In order to re-parse the already parsed part of the record you may need the parameter ABSPOS=1, to return the parsing cursor to the beginning of the record.

But it might be easier to check the two bytes at the (fixed) position where %01 value is inserted, via use of IFTHEN=(WHEN=(…)) in the final OUTFIL statement, or in its INCLUDE= parameter.
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 409
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 6 times
Been thanked: 40 times

Re: Copy partial record after a string in a record using SOR

Postby Esmayeelhusen » Fri May 12, 2023 3:24 pm

Hi Sergeyken,
Thanks for your reply.

As I said earlier after X'0908' there is a 2 byte field which contain 01 to 11, so I have created 11 files in 11 job steps with below card. every time changing the value from X'0908F0F1', C'0908F0F2' ...to X'0908F1F1'.
Then I merged all 11 files and produced the required output.
I am after the SORT CARD in which we can achieve this in one step.

SORT FIELDS=COPY
INCLUDE COND=(1,27989,SS,EQ,X'0908F0F1')
INREC PARSE=(%01=(STARTAFT=X'0908F0F1',FIXLEN=158)),
BUILD=(6,5,18,5,31,2,%01)

Few records with X0908' and after that 2 bytes with value ranging from 01 to 11 are looks like as below.

b@ b@ 031002
87000158700FFFFFF000000
2C000352C98031002005000

Few records having multiple X'0908' and in few places not having 2 byte 01 to 11 looks like as below.

q % & & - / b@ b@ 031002
00000000019003100401456004100501471005100601609000b87000158700FFFFFF000000
00000000028980C980C002C980C980C000C980C980C010C002 C000352C98031002005000

Is there any way we can PARSE the record starting after X'0908' and check the 2 bytes in required position and if 2 bytes are not matching then continue search for next X'0908' and then check.
Please suggest.
Thanks
Husen
Esmayeelhusen
 
Posts: 13
Joined: Thu May 04, 2023 1:57 pm
Has thanked: 3 times
Been thanked: 0 time

Re: Copy partial record after a string in a record using SOR

Postby sergeyken » Sat May 13, 2023 1:04 am

Please! Use the Code button to present your samples of code and/or data.
Please! Use the Code button to present your samples of code and/or data.
Please! Use the Code button to present your samples of code and/or data.
Please! Use the Code button to present your samples of code and/or data.
Please! Use the Code button to present your samples of code and/or data.
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 409
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 6 times
Been thanked: 40 times

Re: Copy partial record after a string in a record using SOR

Postby sergeyken » Sat May 13, 2023 1:06 am

Does this mean that people are specifically taught to make the very primitive tasks as messy as possible????

The initial task is as straightforward as a chicken's egg...
//*====================================================================        
//SORT0908 EXEC PGM=SORT                                                    
//SYSOUT   DD  SYSOUT=*                                                        
//*                                                                            
//SORTIN   DD  *                                                                
?????AAAAA???????BBBBB????????CC??  01-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1
?????AAAAA???????BBBBB????????CC??  X1-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD  
?????AAAAA???????BBBBB????????CC??   02-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-
?????AAAAA???????BBBBB????????CC??   X2-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD
?????AAAAA???????BBBBB????????CC??    03-3-3-3-3-3-3-3-3-3-3-3-3-3-3-3-3-3-3-3-3
?????AAAAA???????BBBBB????????CC??    X3-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD
?????AAAAA???????BBBBB????????CC??     04-4-4-4-4-4-4-4-4-4-4-4-4-4-4-4-4-4-4-4-
?????AAAAA???????BBBBB????????CC??     X4-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BA
?????AAAAA???????BBBBB????????CC??      05-5-5-5-5-5-5-5-5-5-5-5-5-5-5-5-5-5-5-5
?????AAAAA???????BBBBB????????CC??      X5-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-B
?????AAAAA???????BBBBB????????CC??       06-6-6-6-6-6-6-6-6-6-6-6-6-6-6-6-6-6-6-
?????AAAAA???????BBBBB????????CC??       X6-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-
?????AAAAA???????BBBBB????????CC??        07-7-7-7-7-7-7-7-7-7-7-7-7-7-7-7-7-7-7
?????AAAAA???????BBBBB????????CC??        X7-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD
?????AAAAA???????BBBBB????????CC??         08-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-
?????AAAAA???????BBBBB????????CC??         X8-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BA
?????AAAAA???????BBBBB????????CC??          09-9-9-9-9-9-9-9-9-9-9-9-9-9-9-9-9-9
?????AAAAA???????BBBBB????????CC??          X9-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-B
?????AAAAA???????BBBBB????????CC??           10-10-10-10-10-10-10-10-10-10-10-10
?????AAAAA???????BBBBB????????CC??           X0-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-
?????AAAAA???????BBBBB????????CC??            11-11-11-11-11-11-11-11-11-11-11-1
?????AAAAA???????BBBBB????????CC??            1X-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD
?????AAAAA???????BBBBB????????CC??||01-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1
?????AAAAA???????BBBBB????????CC??||X1-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD  
?????AAAAA???????BBBBB????????CC?? ||02-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-
?????AAAAA???????BBBBB????????CC?? ||X2-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD
?????AAAAA???????BBBBB????????CC??  ||03-3-3-3-3-3-3-3-3-3-3-3-3-3-3-3-3-3-3-3-3
?????AAAAA???????BBBBB????????CC??  ||X3-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD
?????AAAAA???????BBBBB????????CC??   ||04-4-4-4-4-4-4-4-4-4-4-4-4-4-4-4-4-4-4-4-
?????AAAAA???????BBBBB????????CC??   ||X4-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BA
?????AAAAA???????BBBBB????????CC??    ||05-5-5-5-5-5-5-5-5-5-5-5-5-5-5-5-5-5-5-5
?????AAAAA???????BBBBB????????CC??    ||X5-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-B
?????AAAAA???????BBBBB????????CC??     ||06-6-6-6-6-6-6-6-6-6-6-6-6-6-6-6-6-6-6-
?????AAAAA???????BBBBB????????CC??     ||X6-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-
?????AAAAA???????BBBBB????????CC??      ||07-7-7-7-7-7-7-7-7-7-7-7-7-7-7-7-7-7-7
?????AAAAA???????BBBBB????????CC??      ||X7-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD
?????AAAAA???????BBBBB????????CC??       ||08-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-
?????AAAAA???????BBBBB????????CC??       ||X8-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BA
?????AAAAA???????BBBBB????????CC??        ||09-9-9-9-9-9-9-9-9-9-9-9-9-9-9-9-9-9
?????AAAAA???????BBBBB????????CC??        ||X9-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-B
?????AAAAA???????BBBBB????????CC??         ||10-10-10-10-10-10-10-10-10-10-10-10
?????AAAAA???????BBBBB????????CC??         ||X0-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD-
?????AAAAA???????BBBBB????????CC??          ||11-11-11-11-11-11-11-11-11-11-11-1
?????AAAAA???????BBBBB????????CC??          ||1X-BAD-BAD-BAD-BAD-BAD-BAD-BAD-BAD
//*                                                                            
//SORTOUT  DD  SYSOUT=*                                                  
//*--------------------------------------------------------------------  
//SYSIN    DD  *                                                          
 INCLUDE COND=(1,80,SS,EQ,X'0908')      GET RID IF THOSE NOT X'0908'      
 INREC  PARSE=(%01=(STARTAFT=X'0908',FIXLEN=158)),                        
        BUILD=(6,5,                                                      
              18,5,                                                      
              31,2,                                                      
              %01)                      WHOLE PART AFTER X'0908'          
 SORT FIELDS=COPY                                                        
 OUTFIL INCLUDE=(13,2,CH,EQ,L(C'01',    GET RID OF THOSE NOT '01'-'11'    
                              C'02',                                      
                              C'03',                                      
                              C'04',                                      
                              C'05',                                      
                              C'06',                                      
                              C'07',                                      
                              C'08',                                      
                              C'09',                                      
                              C'10',                                      
                              C'11'))                                    
//*                                                                      
//*====================================================================

********************************* TOP OF DATA ***********************
AAAAABBBBBCC01-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1            
AAAAABBBBBCC02-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-              
AAAAABBBBBCC03-3-3-3-3-3-3-3-3-3-3-3-3-3-3-3-3-3-3-3-3              
AAAAABBBBBCC04-4-4-4-4-4-4-4-4-4-4-4-4-4-4-4-4-4-4-4-                
AAAAABBBBBCC05-5-5-5-5-5-5-5-5-5-5-5-5-5-5-5-5-5-5-5                
AAAAABBBBBCC06-6-6-6-6-6-6-6-6-6-6-6-6-6-6-6-6-6-6-                  
AAAAABBBBBCC07-7-7-7-7-7-7-7-7-7-7-7-7-7-7-7-7-7-7                  
AAAAABBBBBCC08-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-                    
AAAAABBBBBCC09-9-9-9-9-9-9-9-9-9-9-9-9-9-9-9-9-9                    
AAAAABBBBBCC10-10-10-10-10-10-10-10-10-10-10-10                      
AAAAABBBBBCC11-11-11-11-11-11-11-11-11-11-11-1                      
******************************** BOTTOM OF DATA *********************
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 409
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 6 times
Been thanked: 40 times

Re: Copy partial record after a string in a record using SOR

Postby Esmayeelhusen » Sat May 13, 2023 4:41 pm

Hi Sergeyken,
Apology, i am new to this forum and was not aware how code works while pasting the content from mainframe.
Thanks for the SORT card.
 
It solved my problem by 99%, the only missing part is the records which are having multiple occurrences of X'0908' are not selected. The example of record is as below.

Command ===>
=COLS> ----+----1----+----2----+----3----+----4----+----5----+----6----+----7
012113    q          ₂%  011002  ãØ    &/@ j
       001900310040145600FFFFFF0048000156719210000000000000000000000000000001
       0028980C980C002C98011002006000D101C413C000000C000C000C000000C000C000C2
-----------------------------------------------------------------------------
****** ****************************************************** Bottom of Data


5th and 9th position X'0908' is present, in our SORT card first occurrence is selected and as there is no 01 ...to 11 etc this record is not selected. However, in 17the position another X'0908' is present and a valid bytes after that.
I understand you said it is very difficult to handle multiple occurrences of the string in the same record.

Please suggest is it possible in SORT to deal with multiple occurrences of string search in a record.

Thanks
Husen
Esmayeelhusen
 
Posts: 13
Joined: Thu May 04, 2023 1:57 pm
Has thanked: 3 times
Been thanked: 0 time

Re: Copy partial record after a string in a record using SOR

Postby sergeyken » Sat May 13, 2023 7:22 pm

Esmayeelhusen wrote:
Command ===>
=COLS> ----+----1----+----2----+----3----+----4----+----5----+----6----+----7
012113    q          ₂%  011002  ãØ    &/@ j
       001900310040145600FFFFFF0048000156719210000000000000000000000000000001
       0028980C980C002C98011002006000D101C413C000000C000C000C000000C000C000C2
-----------------------------------------------------------------------------
****** ****************************************************** Bottom of Data


5th and 9th position X'0908' is present, in our SORT card first occurrence is selected and as there is no 01 ...to 11 etc this record is not selected. However, in 17the position another X'0908' is present and a valid bytes after that.
I understand you said it is very difficult to handle multiple occurrences of the string in the same record.

Please suggest is it possible in SORT to deal with multiple occurrences of string search in a record.

Thanks
Husen

After so many words it still remains unclear: how the output should look like for multiple occurrences of X’0908’, when some are valid ‘01’-‘11’, but some are not?

It is also not clear how to BUILD the output when X’0908’ has been found before positions 31-32, which are mandatory included by your example of BUILD?

Why do the members of the forum need to guess all those issues? Why not to explain this clearly, with good examples?
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 409
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 6 times
Been thanked: 40 times

Re: Copy partial record after a string in a record using SOR

Postby Esmayeelhusen » Mon May 15, 2023 12:11 pm

Hi Sergeyken,
As i said in my initial email,
I want the records which are having X'0908' suffices with 2 bytes values '01' - '11'. Don't want records having only X'0908' and not padded with 2 bytes value '01' to '11'.

There is a chance that multiple X'0908' may present in a record but there will be only one occurrence of 'X0908' with 2-byte values '01' to '11' suffixed.
There is a chance that multiple X'0908' are present without X'0908' with 2-byte value '01' - '11'.

There will not be X'0908' before 34 bytes in the input record.
I want 158 bytes (%01) to be parsed after X'0908' If sufficed with '01 - '11'. as per BUILD CARD shown (BUILD=(6,5,18,5,31,2,%01)).

1) Records having X'0908' with valid suffices at 47th position.
----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1-
             011002             a"                                a@  a@DF1
0441000044100FFFFFF00000000002028700000000000000000000000000000002870287CCF4
857D000857D98011002001000D910F901F000000F000F000F000000F000F000F901C901C4610
----------------------------------------------------------------------------

2) Records having X'0908' without valid suffices at 90, 94 and 102 etc position.
----9----+----0----+----1----+----2----+----3----+----4----+----5----+----6----+
   q           %      &       &   -  /
00190031004014560041005014710051006016090000000000000000000000000000000000000000
0028980C980C002C980C980C000C980C980C010C000C000C000C000C000C000C000C000C000C000C
--------------------------------------------------------------------------------

3) Records having X'0908' with and without suffices, valid value at 107.
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+---
******************************************************* Top of Data ********************
   q          ₂%  08011001         /"                                          PD1
001900310040145600FFFFFFFF00020000767012000000000000000000000000000000001200120DCF444444
0028980C980C002C9808011001000000D801F911F000000F000F000F000000F000F000F911C911C741000000
----------------------------------------------------------------------------------------


Output should look like.

BUILD=(6,5,18,5,31,2,%01)

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0--
     69   08011001         /"                                          PD1
00000FF302FFFFFFFF00020000767012000000000000000000000000000000001200120DCF4444440000000000000000000000
1002F6927C08011001000000D801F911F000000F000F000F000000F000F000F911C911C741000000000000C000C000C000000C
------------------------------------------------------------------------------------------------------
Esmayeelhusen
 
Posts: 13
Joined: Thu May 04, 2023 1:57 pm
Has thanked: 3 times
Been thanked: 0 time

Next

Return to DFSORT/ICETOOL/ICEGENER

 


  • Related topics
    Replies
    Views
    Last post