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

Replacing leading spaces by zeroes


IBM Mainframe Forums -> JCL & VSAM
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Wed Oct 31, 2007 7:51 pm
Reply with quote

Hi all,

Is there any way out by which we can replace the leading spaces by zeroes..??

Sample input record
Code:

    10305,1 9267041,   1,  11,   1,123453456
    10 05,169237041,   1,  11,   1,123453456

 

Expected output
Code:

000010305,1 9267041,0001,0011,0001,123453456
000010 05,169237041,0001,0011,0001,123453456


Thanks,
Arun
Back to top
View user's profile Send private message
ofer71

Global Moderator


Joined: 27 Dec 2005
Posts: 2358
Location: Israel

PostPosted: Wed Oct 31, 2007 7:55 pm
Reply with quote

If you know REXX, you can use the TRANSLATE function.

O.
Back to top
View user's profile Send private message
ofer71

Global Moderator


Joined: 27 Dec 2005
Posts: 2358
Location: Israel

PostPosted: Thu Nov 01, 2007 4:46 pm
Reply with quote

Here are three methods of replacing leading spaces with zeroes using REXX:
Code:
/* REXX */           
                                                                   
/*--------------------------------------------------------------------*/
A = '  KUKU  '                                                         
SAY A                                                                   
                                                                       
/*--------------------------------------------------------------------*/
B = TRANSLATE(SUBSTR(A,1,WORDINDEX(A,1)-1),'0',' ')||,                 
              SUBSTR(A,WORDINDEX(A,1))                                 
                                                                       
SAY B                                                                   
                                                                       
/*--------------------------------------------------------------------*/
C = OVERLAY('0',A,1,WORDINDEX(A,1)-1,'0')                               
                                                                       
SAY C                                                                   
                                                                       
/*--------------------------------------------------------------------*/
D = ''                                                                 
                                                                       
DO I = 1 TO LENGTH(A)                                                   
  IF SUBSTR(A,I,1) ¬= ' ' THEN                                         
    LEAVE I                                                             
  ELSE                                                                 
    D = D'0'                                                           
END I                                                                   
                                                                       
SAY D||SUBSTR(A,I)                                                     
                                                                       
EXIT                                                                   
                                                                       


O.
Back to top
View user's profile Send private message
sai mainframes

New User


Joined: 02 Nov 2007
Posts: 8
Location: hyderabad

PostPosted: Fri Nov 02, 2007 4:31 pm
Reply with quote

hi Arun,

i dont have any idea regarding jcl approach....i those are fielsd names........and....it is possible with cobol....


we have INSPECT verb.....

INSPECT WS-X REPLACING LEADING SPACES BY ZEROES.


i am not sure...plz ry this.......


Regards
aikrishna yadav
Back to top
View user's profile Send private message
dominickim

New User


Joined: 28 Feb 2007
Posts: 65
Location: NS, CA

PostPosted: Sat Nov 03, 2007 1:30 am
Reply with quote

Used REXX with overlay
Code:
/* REXX */                                                   
"alloc f(xxin) ds('HLQ.TEST.INPUT') shr"                     
"execio * diskr xxin (finis stem in."                         
"free f(xxin)"                                               
do recid = 1 to in.0                                         
   parse var in.recid a ',' b ',' c ',' d ',' e ',' f         
   ra=overlay('0',a,1,wordindex(a,1)-1,'0')                   
   rb=overlay('0',b,1,wordindex(b,1)-1,'0')                   
   rc=overlay('0',c,1,wordindex(c,1)-1,'0')                   
   rd=overlay('0',d,1,wordindex(d,1)-1,'0')                   
   re=overlay('0',e,1,wordindex(e,1)-1,'0')                   
   rf=overlay('0',f,1,wordindex(f,1)-1,'0')                   
   out.recid = ra||','||rb||','||rc||','||rd||','||re||','||rf
end                                                           
say 'Completed'                                               
"alloc da('HLQ.TEST.OUTPUT') f(out) old"                     
"execio * diskw out (finis stem out."                         
"free f(out)"                                                 

Input
Code:
=COLS>    ----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
******    ***************************** Top of Data ******************************
000001        10305,1 9267041,   1,  11,   1,123453456                           
000002        10 05,169237041,   1,  11,   1,123453456                           
******    **************************** Bottom of Data ****************************

Output
Code:
=COLS>    ----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
******    ***************************** Top of Data ******************************
000001    000010305,1 9267041,0001,0011,0001,123453456                           
000002    000010 05,169237041,0001,0011,0001,123453456                           
******    **************************** Bottom of Data ****************************
Back to top
View user's profile Send private message
nabarundas

New User


Joined: 21 Jun 2007
Posts: 28
Location: pune

PostPosted: Mon Nov 05, 2007 4:33 pm
Reply with quote

Hi Arun,
Tou can use the simple logic to remove the leading spaces

Code:

IDENTIFICATION DIVISION.                   
PROGRAM-ID. TSTPGM.                         
DATA DIVISION.                             
WORKING-STORAGE SECTION.                   
01 WS-IN  PIC X(80) VALUE SPACES.           
01 A REDEFINES WS-IN.                       
   05 B PIC X OCCURS 80 TIMES.             
01 C PIC 9 VALUE ZERO.                     
01 X PIC 99 VALUE ZERO.                     
01 Y PIC 99 VALUE ZERO.                     
PROCEDURE DIVISION.                         
P1.                                         
     
     ACCEPT WS-IN.                               
     INSPECT WS-IN TALLYING Y FOR CHARACTERS.                 
     PERFORM P2 VARYING X FROM 1 BY 1 UNTIL X  > Y.         
     DISPLAY WS-IN.                                           
     STOP RUN.                                               
P2.                                                         
     IF C = 0                                             
         IF B ( X ) IS NUMERIC                           
               MOVE 1 TO C                                   
         END-IF                                           
         IF B ( X ) = SPACES                             
               MOVE 0 TO B ( X )                             
         END-IF                                           
     END-IF
                                               
     IF B ( X ) =  ","   
         COMPUTE C = 0   
     END-IF.             


Thanks & Regards,
Nabarun
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Mon Nov 05, 2007 6:30 pm
Reply with quote

Hi Nabarun,

I know this will work very well in COBOL; It would be great if the same thing works via a JCL.

Thanks,
Arun
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Nov 05, 2007 6:35 pm
Reply with quote

Quote:
It would be great if the same thing works via a JCL.


Your JCL will not do it by itself,

it will invoke a program/utility which given the appropriate parameters
will perform the task You asked for;

You were given a few choices

Rexx script,
Cobol program

I would add
easytrieve

since we do not know what utilities You have available at Your location..
we cannot give You the details

from what I heard on the forums You can use

Fileaid,
SORT ( dfsort/syncsort )
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Mon Nov 05, 2007 7:47 pm
Reply with quote

arcvns wrote:
It would be great if the same thing works via a JCL.
If by JCL you mean SORT, yes, I do believe it can be done.....
Do you need a link to a SORT Manual?
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Mon Nov 05, 2007 10:12 pm
Reply with quote

Quote:
from what I heard on the forums You can use

SORT ( dfsort/syncsort )


Quote:
If by JCL you mean SORT, yes, I do believe it can be done.....


I think you're sending the OP off on a wild goose chase. Can you figure out how it can be done or are you just assuming sort can do everything? icon_wink.gif

The input records have leading blanks and embedded blanks like this:

Code:

    10305,1 9267041,...
    10 05,169237041,...


According to the OP, the output records should have the leading blanks changed to leading zeros, but keep the embedded blanks.

Code:

000010305,1 9267041,...
000010 05,169237041,...


I can't think of a way to do that with sort. Replacing the leading and embedded blanks with zeros could certainly be done with sort, but here the embedded blanks must be kept.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Mon Nov 05, 2007 10:21 pm
Reply with quote

icon_redface.gif My bad, I missed the embedded blanks, just 'saw' the leading blanks.....
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Nov 05, 2007 11:01 pm
Reply with quote

Quote:
Can you figure out how it can be done or are you just assuming sort


I was not figuring out anything, I am no sort expert,
I was just listing some alternative to INVESTIGATE
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Mon Nov 05, 2007 11:35 pm
Reply with quote

Quote:
I was not figuring out anything, I am no sort expert,
I was just listing some alternative to INVESTIGATE


Well then perhaps you could phrase it that way to indicate your level of confidence to avoid having somebody go chasing down something in the books that might not exist, rather than the more confident (but vague):

Quote:
from what I heard on the forums You can use

Fileaid,
SORT ( dfsort/syncsort )


Just a suggestion.
Back to top
View user's profile Send private message
dominickim

New User


Joined: 28 Feb 2007
Posts: 65
Location: NS, CA

PostPosted: Tue Nov 06, 2007 12:53 am
Reply with quote

REXX program above can be called by JCL
Code:
//IRXJCL   EXEC PGM=IRXJCL,PARM='OVERLAY'
//SYSTSPRT DD SYSOUT=*                   
//SYSTSIN  DD DUMMY                       
//SYSEXEC  DD DSN=HLQ.REXX,DISP=SHR       
//XXIN     DD DSN=HLQ.TEST.INPUT,DISP=SHR
//OUT      DD DSN=HLQ.TEST.OUTPUT,DISP=OLD
//SYSOUT   DD SYSOUT=*
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 -> JCL & VSAM

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts Keep leading zero(s) after convert fl... SYNCSORT 7
No new posts Remove leading zeroes SYNCSORT 4
No new posts leading spaces can be removed in trai... DFSORT/ICETOOL 1
No new posts Cobol program with sequence number ra... COBOL Programming 5
Search our Forums:

Back to Top