Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Replacing leading spaces by zeroes

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> JCL & VSAM
View previous topic :: :: View next topic  
Author Message
Arun Raj

Moderator


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

PostPosted: Wed Oct 31, 2007 7:51 pm    Post subject: Replacing leading spaces by zeroes
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: 2360
Location: Israel

PostPosted: Wed Oct 31, 2007 7:55 pm    Post subject:
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: 2360
Location: Israel

PostPosted: Thu Nov 01, 2007 4:46 pm    Post subject:
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    Post subject:
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    Post subject: REXX overlay
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    Post subject: Please try the code
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: 2285
Location: @my desk

PostPosted: Mon Nov 05, 2007 6:30 pm    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10327
Location: italy

PostPosted: Mon Nov 05, 2007 6:35 pm    Post subject: Reply to: Replacing leading spaces by zeroes
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: 2150
Location: At my coffee table

PostPosted: Mon Nov 05, 2007 7:47 pm    Post subject:
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 Moderator


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

PostPosted: Mon Nov 05, 2007 10:12 pm    Post subject:
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: 2150
Location: At my coffee table

PostPosted: Mon Nov 05, 2007 10:21 pm    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10327
Location: italy

PostPosted: Mon Nov 05, 2007 11:01 pm    Post subject: Reply to: Replacing leading spaces by zeroes
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 Moderator


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

PostPosted: Mon Nov 05, 2007 11:35 pm    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> JCL & VSAM All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Remove leading spaces from numeric field rexx77 SYNCSORT 6 Wed Sep 06, 2017 2:15 am
No new posts replacing junk with hyphen Nitin32 DFSORT/ICETOOL 10 Fri Jun 02, 2017 7:47 pm
No new posts Format record to remove Leading zeroes Learncoholic DFSORT/ICETOOL 14 Wed Apr 05, 2017 2:43 pm
No new posts Replacing same string with different ... vickey_dw DFSORT/ICETOOL 6 Wed Feb 22, 2017 10:44 pm
No new posts Count Trailing Spaces in variable str... Virendra Shambharkar SYNCSORT 10 Thu Feb 02, 2017 12:23 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us