View previous topic :: View next topic
|
Author |
Message |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
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 |
|
 |
ofer71
Global Moderator

Joined: 27 Dec 2005 Posts: 2358 Location: Israel
|
|
|
|
If you know REXX, you can use the TRANSLATE function.
O. |
|
Back to top |
|
 |
ofer71
Global Moderator

Joined: 27 Dec 2005 Posts: 2358 Location: Israel
|
|
|
|
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 |
|
 |
sai mainframes
New User
Joined: 02 Nov 2007 Posts: 8 Location: hyderabad
|
|
|
|
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 |
|
 |
dominickim
New User
Joined: 28 Feb 2007 Posts: 65 Location: NS, CA
|
|
|
|
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 |
|
 |
nabarundas
New User
Joined: 21 Jun 2007 Posts: 28 Location: pune
|
|
|
|
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 |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
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 |
|
 |
enrico-sorichetti
Superior Member

Joined: 14 Mar 2007 Posts: 10896 Location: italy
|
|
|
|
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 |
|
 |
CICS Guy
Senior Member

Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
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 |
|
 |
Frank Yaeger
DFSORT Developer

Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
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?
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 |
|
 |
CICS Guy
Senior Member

Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
My bad, I missed the embedded blanks, just 'saw' the leading blanks..... |
|
Back to top |
|
 |
enrico-sorichetti
Superior Member

Joined: 14 Mar 2007 Posts: 10896 Location: italy
|
|
|
|
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 |
|
 |
Frank Yaeger
DFSORT Developer

Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
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 |
|
 |
dominickim
New User
Joined: 28 Feb 2007 Posts: 65 Location: NS, CA
|
|
|
|
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 |
|
 |
|
|