MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Add a new character at the end of every record -pos varies

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
bprasanna
Beginner


Joined: 05 Sep 2003
Posts: 119
Topics: 33
Location: Hyderabad

PostPosted: Wed Mar 23, 2005 9:59 am    Post subject: Add a new character at the end of every record -pos varies Reply with quote

Hi,
I am having a PS of length 133(FB).The data inside the file is like below.

XXXX.YYY.AAAAAAAAAA
XXX.YYYY.AA
XXXX.YYYYY.AAAAA

I want to add a new character at the end of each line.The o/p should look like

XXXX.YYY.AAAAAAAAAAZ
XXX.YYYY.AAZ
XXXX.YYYYY.AAAAAZ

Is this possible thru sort?The length of line may vary from line to line.
I just need to add a Z at the ned of each line

Thanks
Bprasanna
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Wed Mar 23, 2005 8:47 pm    Post subject: Reply with quote

bprasanna,

Adding a constant at the end of every record is not possible with the traditional features of sort. You need an e15 exit to do it.The following JCL will give you the desired results.

A brief explanation of the job.


Step0100 : We first convert the FB file into a Variable block file and trim the trailing spaces.

step0200: Using an exit we pad the desired character "z" at the end of every record.

Step0300: we now convert the Variable block file back to fixed block.

Code:

//STEP0100 EXEC PGM=SORT
//SYSOUT   DD SYSOUT=* 
//SORTIN   DD DSN=YOUR INPUT FILE,
//            DISP=SHR
//SORTOUT   DD DSN=&T1,DISP=(,PASS),SPACE=(CYL,(X,Y),RLSE)
//SYSIN     DD *                                         
   SORT FIELDS=COPY                                         
   OUTFIL FTOV,VLTRIM=C' '                                 
/*
//STEP0200 EXEC PGM=SORT                                 
//SYSOUT   DD SYSOUT=*                                   
//SYSLIN   DD DSN=&S1,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)       
//SYSLMOD  DD DSN=&S2,DISP=(,PASS),SPACE=(CYL,(1,1,2),RLSE)
//SORTIN   DD DSN=&T1,DISP=OLD                           
//SORTOUT  DD DSN=&T2,DISP=(,PASS),SPACE=(CYL,(X,Y),RLSE)
//SYSTSPRT DD SYSOUT=*                                   
//MODLIB   DD DSN=YOUR.REXX.PDS,
//            DISP=SHR             
//SYSIN DD *                                             
  SORT FIELDS=COPY                                       
  MODS E15=(E15Z,133,MODLIB,X)                           
/*             
//STEP0300 EXEC PGM=SORT       
//SYSOUT   DD SYSOUT=*         
//SORTIN   DD DSN=&T2,DISP=OLD
//SORTOUT  DD SYSOUT=*         
//SYSIN    DD *               
  SORT FIELDS=COPY             
  OUTFIL CONVERT,               
  OUTREC=(5,133)               
/*



This is the E15z exit for padding the character "z" at the end of every record.

Code:

/* REXX E15Z */   
ADDRESS 'SYNCREXX' 'GIVE'                   
LS = LENGTH(SYRECORD)                       
IF LS > 0                                   
THEN DO                                     
SYACTION = 'REPLACE'                       
SYRECORD = OVERLAY("Z",SYRECORD,LS+1)       
SAY RC                                     
END                                         
ELSE DO                                     
SYACTION = 'CLOSE'                         
END                                         
ADDRESS 'SYNCREXX' 'TAKE'                   
RETURN                                     


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
chandra
Beginner


Joined: 26 Sep 2003
Posts: 130
Topics: 36

PostPosted: Thu Mar 24, 2005 3:03 am    Post subject: Reply with quote

The cobol solution is as follows

Code:
       IDENTIFICATION DIVISION.
       PROGRAM-ID.    CHANDRA.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.

             SELECT   IN1FILE
             ASSIGN   TO IN1
             ORGANIZATION IS SEQUENTIAL.

             SELECT   OUT1FL
             ASSIGN   TO OUT1
             ORGANIZATION IS SEQUENTIAL.

       DATA DIVISION.
       FILE SECTION.

       FD IN1FILE
           RECORDING MODE IS F
           LABEL RECORDS ARE STANDARD
           BLOCK CONTAINS 0 RECORDS
           DATA RECORD IS IN1-REC.

       01 IN1-REC                      PIC X(133).
       FD OUT1FL
           RECORDING MODE IS F
           LABEL RECORDS ARE STANDARD
           BLOCK CONTAINS 0 RECORDS
           DATA RECORD IS OUT1-REC.

       01 OUT1-REC                    PIC X(133).

       WORKING-STORAGE SECTION.
       01 S-IN1-FILE                  PIC X(01)  VALUE 'N'.
       01 ALP-FND                     PIC X(01)  VALUE 'N'.
       01 I                           PIC 9(03).

       PROCEDURE DIVISION.

             PERFORM 1000-INITIALIZATION

             PERFORM 2000-MAIN-PROCESS UNTIL
                     S-IN1-FILE = 'Y'

             PERFORM 3000-WRAPUP

             GOBACK
             .

       1000-INITIALIZATION.

             OPEN INPUT  IN1FILE
                  OUTPUT OUT1FL
             .

       2000-MAIN-PROCESS.

             READ IN1FILE
                 AT END
                     MOVE 'Y'            TO S-IN1-FILE
             END-READ

             MOVE 'N' TO ALP-FND

             PERFORM VARYING I FROM 133 BY -1
                      UNTIL I < 1 OR ALP-FND = 'Y' OR S-IN1-FILE = 'Y'

                     IF IN1-REC(I: 1) NOT = SPACE
                          MOVE 'Y' TO ALP-FND
                          ADD 1 TO I
                          MOVE 'Z' TO IN1-REC(I: 1)
                          MOVE IN1-REC TO OUT1-REC
                          WRITE OUT1-REC
                     END-IF
                 END-PERFORM.

       3000-WRAPUP.

             CLOSE  IN1FILE
                    OUT1FL.


Regards,
Chandra
_________________
Regards,
Chandra
Back to top
View user's profile Send private message
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Thu Mar 24, 2005 11:35 am    Post subject: Reply with quote

Here's a DFSORT job that will add the 'Z' using one Copy pass and an Assembler E15 exit (shown below):

Code:

//S1   EXEC  PGM=ICEMAN
//SYSOUT    DD  SYSOUT=*
//EXIT DD DSN=...  exit library
//SORTIN DD DSN=...  input file (FB/133)
//SORTOUT DD DSN=...  output file (FB/133)
//SYSIN    DD    *
  OPTION COPY
  MODS E15=(ADDZ,400,EXIT)
/*



Here's the source for the E15 exit:

Code:

ADDZ     CSECT
R0       EQU   0
R1       EQU   1
R2       EQU   2
R3       EQU   3
R4       EQU   4
R5       EQU   5
R6       EQU   6
R7       EQU   7
R8       EQU   8
R9       EQU   9
R10      EQU   10
R11      EQU   11
R12      EQU   12
R13      EQU   13
R14      EQU   14
R15      EQU   15
         STM   R14,R12,12(R13)    SAVE ALL REGS EXCPT 13
         BALR  R12,R0             SET BASE REG
         USING *,R12              SHOW BASE REG
         ST    R13,SAVE15+4       SAVE BACKWARD POINTER
         LA    R14,SAVE15         SET FORWARD POINTER IN CALLER
         ST    R14,8(,R13)        SET SAVE AREA
         LR    R13,R14            SET OUR SAVE AREA
         ICM   R2,15,0(R1)        GET POINTER TO RECORD
         BZ    EOI                IF EOI, DO NOT RETURN
         MVC   NEWRCD,0(R2)       COPY RECORD
* IF NO BLANKS IN RECORD, TELL DFSORT TO ACCEPT THE RECORD AS IS.
* OTHERWISE, OVERLAY THE FIRST BLANK IN THE RECORD WITH 'Z' AND
* TELL DFSORT TO ACCEPT THE CHANGED RECORD.
         LA    R1,NEWRCD          POINT TO START OF COPIED RECORD
         LR    R4,R1              COPY POINTER
         LA    R3,133             SET LENGTH OF RECORD
FNDBLK   DS    0H
         CLI   0(R4),C' '         IF FIRST BLANK FOUND,
         BE    Z                    ADD Z
         LA    R4,1(,R4)          INCREMENT RECORD POINTER
         BCT   R3,FNDBLK          CONTINUE LOOKING FOR BLANK
         B     ACCEPT             NO BLANKS IN RECORD - ACCEPT IT
Z        DS    0H
         MVI   0(R4),C'Z'         OVERLAY FIRST BLANK WITH 'Z'
         B     ACCEPT             ACCEPT CHANGED RECORD
EOI      DS    0H
         LA    R15,8              INDICATE DO NOT RETURN
         B     GOBACK             RETURN TO DFSORT
ACCEPT   DS    0H
         SLR   R15,R15            INDICATE ACCEPT
GOBACK   DS    0H                 RETURN TO DFSORT
         L     R13,4(,R13)
         L     R14,12(,R13)
         LM    R2,R12,28(R13)
         BR    R14
*
SAVE15   DS    18F
NEWRCD   DS    CL133
         LTORG
         END

_________________
Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
Back to top
View user's profile Send private message Send e-mail Visit poster's website
coolman
Intermediate


Joined: 03 Jan 2003
Posts: 283
Topics: 27
Location: US

PostPosted: Mon Mar 28, 2005 11:22 am    Post subject: Reply with quote

Kolusu,

Does SYNCREXX, GIVE, TAKE, SYACTION, SYRECORD in the E15 exit that you had illustrated have any significance. If yes, where should I find them?

Cheers,
Coolman
________
uhwh warehouse


Last edited by coolman on Sat Feb 05, 2011 1:40 am; edited 1 time in total
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Mon Mar 28, 2005 11:40 am    Post subject: Reply with quote

coolman,

SyncSort provides a number of special REXX variables to facilitate the development of REXX exits. These variables offer a simple, efficient means of establishing communicationbetween the exit and the sort/merge.

To load these variables, the following command must be used when the exit is called.
Code:

ADDRESS 'SYNCREXX' 'GIVE'


When the exit completes its work, the exit should use the following sequence of commands to return the variables to SyncSort.
Code:

ADDRESS 'SYNCREXX' 'TAKE'
RETURN


The following table describes the special REXX variables.

SYRECORD : When the exit is entered, SYRECORD contains the current data record. The exit can accept the record, modify it or add a new record; SYACTION should be set accordingly.

If SYRECORD is null, then SyncSort has no data remaining. When this happens, the exit can either CLOSE or continue to INSERT new records.

SYACTION : This variable must be set before the exit returns control to SyncSort. It describes the disposition of the current record. Possible values for SYACTION are as follows:
Code:

ACCEPT : Retain the current record with no modification.
REPLACE: Replace the current record with the contents of the SYRECORD.
DELETE: Delete the current record.
INSERT: Insert the contents of the SYRECORD before the current record.
CLOSE: Do not return to the exit.
ABEND: Terminate SyncSort.


If an E15 is providing all the input (SORTIN not present), the only valid values for SYACTION are INSERT, CLOSE or ABEND.

SYEXITYP: This variable will automatically be set to E15 or E35, depending on which type of exit is being called. SYGBLN1... ...SYGBLN8

These eight special variables are global variables. The user may set these to any value provided that the value does not exceed 15 characters in length. SyncSort will insure that these variables are preserved across calls to the exit.

SYGBLSTRP: This is an additional global variable. The user may set this to any value, provided the string does not exceed 1024 characters in length.SyncSort will insure that this variable is preserved across calls to the exit.


You can find the same information in chapter 7 (coding rexx exits) in the syncsort manual

Hope this helps..

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
semigeezer
Supermod


Joined: 03 Jan 2003
Posts: 1014
Topics: 13
Location: Atlantis

PostPosted: Mon Mar 28, 2005 2:48 pm    Post subject: Reply with quote

if you can use USS, use of regular expressions is pretty quick. A sed command like

sed '/s\(..*\)/\1Z/g' filename

will add a Z to every nonblank line (only tested on Linux, but it should work in USS).
My regular expressions and sed syntax are a bit rusty so there may be a better way to do this. You can run shell scripts in batch.
Back to top
View user's profile Send private message Visit poster's website
semigeezer
Supermod


Joined: 03 Jan 2003
Posts: 1014
Topics: 13
Location: Atlantis

PostPosted: Mon Mar 28, 2005 2:50 pm    Post subject: Reply with quote

typo... that should be sed 's/\(..*\)/\1Z/g'
Back to top
View user's profile Send private message Visit poster's website
coolman
Intermediate


Joined: 03 Jan 2003
Posts: 283
Topics: 27
Location: US

PostPosted: Tue Mar 29, 2005 10:12 am    Post subject: Reply with quote

Thanks Kolusu for your detailed explanation.
________
Honda MB50 history


Last edited by coolman on Sat Feb 05, 2011 1:40 am; edited 1 time in total
Back to top
View user's profile Send private message
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Thu Oct 19, 2006 6:59 pm    Post subject: Reply with quote

With DFSORT's new JFY function, you can do what was requested quite easily in one pass - you don't need an E15 exit. Here's the DFSORT/ICETOOL job. You'll need z/OS DFSORT V1R5 PTF UK90007 or DFSORT R14 PTF UK90006 (April, 2006) in order to use DFSORT's SQZ function. If you don't have the April, 2006 PTF, ask your System Programmer to install it (it's free). For complete details on all of the new DFSORT and ICETOOL functions available with the April, 2006 PTF, see:

www.ibm.com/servers/storage/support/software/sort/mvs/peug/

Code:

//S1    EXEC  PGM=ICEMAN
//SYSOUT    DD  SYSOUT=*
//SORTIN DD DSN=... input file (FB/133)
//SORTOUT DD DSN=...  output file (FB/133)
//SYSIN    DD    *
  OPTION COPY
  INREC BUILD=(1,133,JFY=(SHIFT=LEFT,TRAIL=C'Z'))
/*


Note that the data here is left-justified (no leading blanks), so JFY works fine. If there were leading blanks of different lengths in different records, this technique wouldn't work because JFY would remove them which may or may not be what someone wants for a particular case.
_________________
Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group