Page 1 of 1

add leading zero's to output file based on certain condition

PostPosted: Tue Sep 18, 2018 8:35 pm
by thotlma
we have input file like this.first we have to check the first 4 digit length before comma if 4 digit length found then we have to remove the first digit and added zero in the second digit postion.other case suppose three digits only before comma then we have add first digit as zero.we have to verify lengh of digits after comma ,if lengh less than 15 then we have to add leading zeros after comma

I/P
3290,9174990831
3290,1775998230
4560,7000135
3290,6500007975
101,8868000005

O/P
090,000009174990831
001,000008868000005

Re: add leading zero's to output file based on certain condi

PostPosted: Tue Sep 18, 2018 9:10 pm
by Robert Sample
Why do you have 5 input and 2 output records? You did not indicate in your post any exclusion conditions so 5 records input should be 5 records output.

Furthermore, you posted in the JCL section and JCL cannot do this. You can write a program in the language of your choice to do it, or you might be able to use a utility (such as your sort product) to do it, but definitely JCL cannot do it.

Re: add leading zero's to output file based on certain condi

PostPosted: Wed Sep 19, 2018 3:40 pm
by thotlma
Hi Robert

that sample out put .please see below corercted input and output. we have do in JCl only only.the last 10 digidt are account number we have 5 zeros before account number.

I/P
3290,9174990831
101,8868000005

O/P
090000009174990831
001000008868000005

Re: add leading zero's to output file based on certain condi

PostPosted: Wed Sep 19, 2018 4:07 pm
by NicC
As stated by Robert JCL cannot do this.
Many people seem to mis-understand what JCL is.
Although the 'L' in JCL stands for 'Language' JCL is not executable.
JCL does not manipulate data, it does not even look at data.
JCL is like a memo from you to the Operating System (OS) requesting it (the OS) to run one or more programs.
The JCL specifies some, or all, of the resources required to accomplish the requested tasks.
When the JCL is read the OS reads it and sets up whatever it requires to do the tasks defined in the JCL.
It then DISCARDS the JCL, i.e. writes it to the output spool, never to look at it again.
The OS then runs the program(s) in accordance with the information it has extracted.


Now, presumably you want to do this using your sort utility. Which one is it? DFSort or SyncSort?

Re: add leading zero's to output file based on certain condi

PostPosted: Wed Sep 19, 2018 4:56 pm
by expat
It is really so important that you state your requirement accurately - we do appreciate that there may be a language problem, so do try to accomodate this .................. but

first we have to check the first 4 digit length before comma if 4 digit length found then we have to remove the first digit and added zero in the second digit postion.

3290,9174990831 - remove first digit = 290,9174990831 - then added zero in second digit position

- Do you mean mathematically added, in which case why bother - or physically inserted ?
Your example output shows that the first digit from the revised data has replaced by the zero

From what you have written I would have inserted a zero into the second position and ended up with 2090,9174990831

Also, your second example of output seems to have lost the comma. is this new or a typo ?

Re: add leading zero's to output file based on certain condi

PostPosted: Wed Sep 19, 2018 5:44 pm
by NicC
Here is rexx solution using your revised sample data:
my_input.1 = "3290,9174990831"
my_input.2 = "101,8868000005"

Do ix = 1 To 2

    Parse var my_input.ix first_part ',' second_part
    first_part = Right(Right(first_part,2),3,0)
    second_part = Right(second_part,15,0)
    my_output.ix = first_part||second_part
   
End
Say my_output.1
Say my_output.2
Exit


Output is
090000009174990831
001000008868000005

Re: add leading zero's to output file based on certain condi

PostPosted: Wed Sep 19, 2018 7:44 pm
by thotlma
expat wrote:It is really so important that you state your requirement accurately - we do appreciate that there may be a language problem, so do try to accomodate this .................. but

first we have to check the first 4 digit length before comma if 4 digit length found then we have to remove the first digit and added zero in the second digit postion.

3290,9174990831 - remove first digit = 290,9174990831 - then added zero in second digit position

- Do you mean mathematically added, in which case why bother - or physically inserted ?
Your example output shows that the first digit from the revised data has replaced by the zero

From what you have written I would have inserted a zero into the second position and ended up with 2090,9174990831

Also, your second example of output seems to have lost the comma. is this new or a typo ?


Thanks for reply..please can post the JCL code..this is my clear requirement...

the first four digits are bank number so some times bank number is four digits or three digits.
if four digits then remove the first two digits and add zero leading
if three digits then remove or replace first digit and add zero leading
the comma shoundnot get in the out put file

Re: add leading zero's to output file based on certain condi

PostPosted: Wed Sep 19, 2018 11:44 pm
by NicC
please can post the JCL code..this is my clear requirement.

and you have been clearly told that JCL can not do this.
Assuming you want a sort solution here is a sample JCL to run when you have the sort control statements
//STEP    EXEC PGM=SORT
//SORTIN   DD DSN=your.input.data. set,DISP=SHR
//SORTOUT  DD DSN=your.output.data. set,DISP=(,CATLG,CATLG),
//             RECFM=recorfm,LRECL=lrecl,SPACE=your space requirement
//SYSIN    DD *
 sort control statements - these are NOT JCL
/*
//SYSOUT   DD SYSOUT=*
 

Re: add leading zero's to output file based on certain condi

PostPosted: Fri Sep 21, 2018 6:39 pm
by thotlma
HI NIC

i did in JCL only the above requirement.please see the below code.

//SYSIN DD *
SORT FIELDS=COPY
INREC IFTHEN=(WHEN=(5,1,CH,EQ,C','),
BUILD=(1:C'0',2:3,2,4:6,15,UFF,M11,LENGTH=15)),
IFTHEN=(WHEN=(4,1,CH,EQ,C','),
BUILD=(1:C'0',2:2,2,4:5,15,UFF,M11,LENGTH=15))

o/p file

090000006500012315
001000008868000123

Re: add leading zero's to output file based on certain condi

PostPosted: Fri Sep 21, 2018 6:49 pm
by NicC
This line is JCL:
//SYSIN DD *

These lines are NOT JCL - they are sort control statements:
SORT FIELDS=COPY
INREC IFTHEN=(WHEN=(5,1,CH,EQ,C','),
BUILD=(1:C'0',2:3,2,4:6,15,UFF,M11,LENGTH=15)),
IFTHEN=(WHEN=(4,1,CH,EQ,C','),
BUILD=(1:C'0',2:2,2,4:5,15,UFF,M11,LENGTH=15))

And use the code tags when presenting code and data.