View previous topic :: View next topic
|
Author |
Message |
abhishekmdwivedi
New User
Joined: 22 Aug 2006 Posts: 95 Location: india
|
|
|
|
Hi All,
Here's the problem scenario :
In my code I am taking value from user's terminal as n1,n2 & n3.
In n1 & n2 I am passing a 2 digit number & in n3 I am passing a 10 digit number. All these number are to be written into a file which has a mapped copybook with variables defined as 999,9(5),s9(10).
Here I am bound to have these numbers being written in the above specified format that is n1 -> file-field1 (as 999),n2 -> file-field2 (as 9(5)) & n3 -> file-field3 (as s9(10)).
Currently I am facing following issues :
1)As how can I convert the input n variable data into the cobol numeric presentation so that same copybook format can be followed while writing.
2) For any field if the rexx input is smaller then the allocated space then the leading spaces should be put as zero while writing the data into the output file. ( as for 999 if the input is only one digit number then leading two digits should be put as zero) |
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
Usually the RIGHT function will work. |
|
Back to top |
|
|
abhishekmdwivedi
New User
Joined: 22 Aug 2006 Posts: 95 Location: india
|
|
|
|
Thanks Superk. This will resolve the second part of my query.
Can you please help me out on my first issue. |
|
Back to top |
|
|
ajaypmenon
New User
Joined: 30 Mar 2007 Posts: 21 Location: North Carolina
|
|
|
|
Read it as a alphanumeric field. Redefine it and use it as numeric.
just a sample.
pic1 pic X(5)
pic2 redefines pic1. make it an array of 1 byte each
for i = 1 to 5
if pic2(i) not numeric
move pic2(1,i-1) to a numeric field and use it.
return
end-if
end |
|
Back to top |
|
|
abhishekmdwivedi
New User
Joined: 22 Aug 2006 Posts: 95 Location: india
|
|
|
|
Hi ajaypmenon,
Thanks for the input.
But I don't know how your solution is related to the given problem, as the code is to be written under REXX and not in COBOL. |
|
Back to top |
|
|
abhishekmdwivedi
New User
Joined: 22 Aug 2006 Posts: 95 Location: india
|
|
|
|
Hi all,
One of my queries under this thread is still unanswered .
Quote: |
1)As how can I convert the input n variable data into the Cobol numeric presentation so that same copybook format can be followed while writing. |
Please look at the top for complete Problem Description.
Can anyone please help me out on this.
If required I may elaborate the issue further more for clarification. |
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
abhishekmdwivedi wrote: |
If required I may elaborate the issue further more for clarification. |
Yes, I think you need to. Keep in mind that not all of us speak in COBOL. |
|
Back to top |
|
|
abhishekmdwivedi
New User
Joined: 22 Aug 2006 Posts: 95 Location: india
|
|
|
|
Hi all,
Here's the Problem Elaboration :
I have a REXX code which creates a file with following data :
1) AcctNo
2) TransID
3) UniID
Following code is used to take data from user and write the same into a output file :
Code: |
SAY " PLEASE PROVIDE THE ACCOUNT NO. : "
PULL ANO
SAY " PLEASE PROVIDE THE TRANSID : "
PULL TID
SAY " PLEASE PROVIDE THE UNIID : "
PULL UID
PUSH ANO||TID||UID
"EXECIO 1 DISKW OUTDS(FINIS"
|
The given file is then feed into a production COBOL program which uses following copybook specification for reading the file:
Code: |
ANO PIC S9(10)
TRANSID PIC 9(5)
UID PIC 999
|
Currently I want the values taken from USER through the REXX being converted to the above copybook specification as :
ANO (Var. in REXX) -> (Maps to) ANO PIC S9(10)
TRANSID(Var. in REXX) -> (Maps to) TRANSID PIC 9(5)
UID(Var. in REXX) -> (Maps to) UID PIC 999
As the production COBOL code cannot be modified I want this mapping in REXX.
Hope this will help in understanding the issue. |
|
Back to top |
|
|
ajaypmenon
New User
Joined: 30 Mar 2007 Posts: 21 Location: North Carolina
|
|
|
|
Hi Abhishek,
Sorry i could not understand the requirement.
pull ano
ano = strip(ano)
len = length(ano)
ano = copies('0',10-len) || ano
if ano is entered as '345'
output will be 0000000345
lly all can be modifed to have its expected size. Hope this helps.
Thanks,
Ajay |
|
Back to top |
|
|
abhishekmdwivedi
New User
Joined: 22 Aug 2006 Posts: 95 Location: india
|
|
|
|
Hi Ajay,
Thanks a lot for the update.
The code will work fine for variable 999 * 9(5) , but will this code map the values to a S9(10) variable correctly.....??? |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
Code: |
ano = strip(ano)
len = length(ano)
ano = copies('0',10-len) || ano
if ano is entered as '345'
output will be 0000000345 |
The same result can be obtained with:
Code: |
ano = Right(ano,10,'0') |
The complete code could look like that:
Code: |
SAY " PLEASE PROVIDE THE ACCOUNT NO. : "
PULL ANO
SAY " PLEASE PROVIDE THE TRANSID : "
PULL TID
SAY " PLEASE PROVIDE THE UNIID : "
PULL UID
QUEUE RIGHT(ANO,10,'0') || RIGHT(TID,5,'0') || RIGHT(UID,3,'0')
"EXECIO 1 DISKW OUTDS(FINIS" |
ANO value will be unsigned, COBOL will accept that. |
|
Back to top |
|
|
ajaypmenon
New User
Joined: 30 Mar 2007 Posts: 21 Location: North Carolina
|
|
|
|
Hi Abhishek,
If its not having negative values, it will work properly. This is always an absolute value.
Thanks, |
|
Back to top |
|
|
abhishekmdwivedi
New User
Joined: 22 Aug 2006 Posts: 95 Location: india
|
|
|
|
Hi,
This is how the current production file looks like:
And here is the file which I created through given code :
here 00001 - TID (copybook : TID pic 9(5)) - matches production file format
006 - UID (Copybook : UID pic 999) - matches production file format
987544500 - ANO (Copybook : ANO pic s9(10)) - Unmatched format
This is what I asked earlier as whether the given code will work for S9(10) variable or not ???
Can anyone please suggest on this problem.
Regards,
Abhi |
|
Back to top |
|
|
abhishekmdwivedi
New User
Joined: 22 Aug 2006 Posts: 95 Location: india
|
|
|
|
Sorry, the ANO variable is of type PIC S9(10) comp-3. Please ignore the above info. on that variable. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
The value shown "0987544500" is not a comp-3 (packed-decimal) value. To be a valid comp-3 value, the low-order half-byte must be a C, D, or F sign. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10888 Location: italy
|
|
|
|
there is no such thing as mapping in rexx.....
in rexx anything is a char string
but You can convert string representing a number to the proper cobol representation
for example
the rexx expression
Code: |
d2c(1,4) will give as a result four bytes containing x"00000001" which is the cobol comp of a positive one |
in the same way
Code: |
d2c(-1,4) will give as a result four bytes containing x"ffffffff" which is the cobol comp of a negative one
|
the following code snippet will give the cobol representation of a packed number
call format
Code: |
packed = pack(number,lenght) |
Code: |
/* */
pack: procedure
parse arg numb , leng
sign = left(numb,1)
if sign = "-" then do
sign = "D"
numb = substr(numb,2)
end
else ,
if sign = "+" then do
sign = "C"
numb = substr(numb,2)
end
else ,
sign = "C"
size = leng * 2 - 1
temp = right(numb,size,"0") || sign
pack = x2c(temp)
return pack
|
|
|
Back to top |
|
|
abhishekmdwivedi
New User
Joined: 22 Aug 2006 Posts: 95 Location: india
|
|
|
|
Hi Dick,
Thanks for the reply.
Quote: |
The value shown "0987544500" is not a comp-3 (packed-decimal) value. |
This is what I am saying. The file which i created using the REXX is not populating the value "0987544500" as packed-decimal in the file , If you check I have given a file detail :
which is current correct production file. I want that REXX code to write a Packed-Decimal format into the file.
Please look into the chain of discussion for problem scenario. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10888 Location: italy
|
|
|
|
Quote: |
I want that REXX code to write a Packed-Decimal format into the file. |
REXX will not do it on its own... You must do it!
that' s what the code snipped I posted does |
|
Back to top |
|
|
abhishekmdwivedi
New User
Joined: 22 Aug 2006 Posts: 95 Location: india
|
|
|
|
Quote: |
REXX will not do it on its own... You must do it!
that' s what the code snipped I posted does
|
Got that man !!!
Thanks for the suggestion . And yup, the code works fine now... |
|
Back to top |
|
|
abhishekmdwivedi
New User
Joined: 22 Aug 2006 Posts: 95 Location: india
|
|
|
|
All of you, thanks a lot for your participation. |
|
Back to top |
|
|
ajaypmenon
New User
Joined: 30 Mar 2007 Posts: 21 Location: North Carolina
|
|
|
|
Hi,
The following code will help.
ANO = STRIP(ANO) || 'C'
ANO = RIGHT(ANO,12,'0')
ANO = X2C(ANO)
if the value of ano is 1234567890, the output will be X'01234567890C' which will be 6 bytes.
Thanks, |
|
Back to top |
|
|
ajaypmenon
New User
Joined: 30 Mar 2007 Posts: 21 Location: North Carolina
|
|
|
|
Oops Sorry. dint see the solution from Enrico. |
|
Back to top |
|
|
|