How can we convert Ascii string char to its decimal value in Cobol or Screen Cobol requester?
On Tue, 11 Jan 2022 08:14:18 -0800 (PST), Rupesh Sonawane <rupso...@gmail.com> wrote:
How can we convert Ascii string char to its decimal value in Cobol or Screen Cobol requester?Rupesh,
In most COBOL languages this is done with a REDEFINES structure. For example:
01 CHAR-TEST-INT PIC 9(4) COMP.
01 CHAR-TEST-CHAR REDEFINES CHAR-TEST-INT.
02 FILLER PIC X.
02 CHAR-TEST-CHAR-VAL PIC X.
...
MOVE ZERO TO CHAR-TEST-INT.
MOVE CHAR-TO-TEST to CHAR-TEST-CHAR-VAL.
...
After the above two statements, the CHAR-TEST-INT variable will contain the decimal value you need.
Disclaimer - this example as entered from memory and may contain syntax errors. It's meant as a description of the solution only.
Bill
On Tuesday, January 11, 2022 at 10:15:31 AM UTC-8, Bill Honaker wrote:has. If I were doing the programming, that probably is the way I would go, unless it was important that the COBOL program be portable to other operating systems.
On Tue, 11 Jan 2022 08:14:18 -0800 (PST), Rupesh Sonawane <rupso...@gmail.com> wrote:
How can we convert Ascii string char to its decimal value in Cobol or Screen Cobol requester?Rupesh,
In most COBOL languages this is done with a REDEFINES structure. For example:
01 CHAR-TEST-INT PIC 9(4) COMP.
01 CHAR-TEST-CHAR REDEFINES CHAR-TEST-INT.
02 FILLER PIC X.
02 CHAR-TEST-CHAR-VAL PIC X.
...
MOVE ZERO TO CHAR-TEST-INT.
MOVE CHAR-TO-TEST to CHAR-TEST-CHAR-VAL.
...
After the above two statements, the CHAR-TEST-INT variable will contain the decimal value you need.
Disclaimer - this example as entered from memory and may contain syntax errors. It's meant as a description of the solution only.
Bill
The REDEFINES idea is a valid way to approach the task, but you got a lot of the details wrong. Don't feel bad. I imagine it has been a long time since you have done any COBOL programming!
I think what would work a little better (but is not perfect) would be:
01 ASCII-TEXT PIC X(5).
01 DISPLAY-NUMERIC REDEFINES ASCII-TEXT PIC 9(5).
01 INPUT-TEXT PIC X(5).
01 BINARY-VALUE PIC 9(5) COMP.
MOVE INPUT-TEXT TO ASCII-TEXT.
MOVE DISPLAY-NUMERIC TO BINARY-VALUE.
The above would only work if INPUT-TEXT contained 5 digit characters -- no leading, trailing, or embedded spaces, no sign. With further programming, those limitations can be addressed, but I'm not going to try to do that right now.
For COBOL, not Screen COBOL, it would be possible to call a system procedure that scans an ASCII string that contains a representation of a numeric value and returns a binary value. That would have a lot fewer restrictions that the simple code above
On Tue, 11 Jan 2022 11:42:34 -0800 (PST), Keith Dick <rkd...@gmail.com> wrote:has. If I were doing the programming, that probably is the way I would go, unless it was important that the COBOL program be portable to other operating systems.
On Tuesday, January 11, 2022 at 10:15:31 AM UTC-8, Bill Honaker wrote:
On Tue, 11 Jan 2022 08:14:18 -0800 (PST), Rupesh Sonawane <rupso...@gmail.com> wrote:
How can we convert Ascii string char to its decimal value in Cobol or Screen Cobol requester?Rupesh,
In most COBOL languages this is done with a REDEFINES structure. For example:
01 CHAR-TEST-INT PIC 9(4) COMP.
01 CHAR-TEST-CHAR REDEFINES CHAR-TEST-INT.
02 FILLER PIC X.
02 CHAR-TEST-CHAR-VAL PIC X.
...
MOVE ZERO TO CHAR-TEST-INT.
MOVE CHAR-TO-TEST to CHAR-TEST-CHAR-VAL.
...
After the above two statements, the CHAR-TEST-INT variable will contain the decimal value you need.
Disclaimer - this example as entered from memory and may contain syntax errors. It's meant as a description of the solution only.
Bill
The REDEFINES idea is a valid way to approach the task, but you got a lot of the details wrong. Don't feel bad. I imagine it has been a long time since you have done any COBOL programming!
I think what would work a little better (but is not perfect) would be:
01 ASCII-TEXT PIC X(5).
01 DISPLAY-NUMERIC REDEFINES ASCII-TEXT PIC 9(5).
01 INPUT-TEXT PIC X(5).
01 BINARY-VALUE PIC 9(5) COMP.
MOVE INPUT-TEXT TO ASCII-TEXT.
MOVE DISPLAY-NUMERIC TO BINARY-VALUE.
The above would only work if INPUT-TEXT contained 5 digit characters -- no leading, trailing, or embedded spaces, no sign. With further programming, those limitations can be addressed, but I'm not going to try to do that right now.
For COBOL, not Screen COBOL, it would be possible to call a system procedure that scans an ASCII string that contains a representation of a numeric value and returns a binary value. That would have a lot fewer restrictions that the simple code above
Keith,
I understood the question differently than you. I thought he was looking to find the integral equivalent of the ASCII character. That is, a space would be equal to 32.
This would be equivalent to the Basic (or Visuaal Basic) chr() function.
If the OP intended to convert a sequence of numeric characters to a comp field, then your solution is correct.
Bill
On Tuesday, January 11, 2022 at 12:23:48 PM UTC-8, Bill Honaker wrote:has. If I were doing the programming, that probably is the way I would go, unless it was important that the COBOL program be portable to other operating systems.
On Tue, 11 Jan 2022 11:42:34 -0800 (PST), Keith Dick <rkd...@gmail.com> wrote:
On Tuesday, January 11, 2022 at 10:15:31 AM UTC-8, Bill Honaker wrote:
On Tue, 11 Jan 2022 08:14:18 -0800 (PST), Rupesh Sonawane <rupso...@gmail.com> wrote:
How can we convert Ascii string char to its decimal value in Cobol or Screen Cobol requester?Rupesh,
In most COBOL languages this is done with a REDEFINES structure. For example:
01 CHAR-TEST-INT PIC 9(4) COMP.
01 CHAR-TEST-CHAR REDEFINES CHAR-TEST-INT.
02 FILLER PIC X.
02 CHAR-TEST-CHAR-VAL PIC X.
...
MOVE ZERO TO CHAR-TEST-INT.
MOVE CHAR-TO-TEST to CHAR-TEST-CHAR-VAL.
...
After the above two statements, the CHAR-TEST-INT variable will contain the decimal value you need.
Disclaimer - this example as entered from memory and may contain syntax errors. It's meant as a description of the solution only.
Bill
The REDEFINES idea is a valid way to approach the task, but you got a lot of the details wrong. Don't feel bad. I imagine it has been a long time since you have done any COBOL programming!
I think what would work a little better (but is not perfect) would be:
01 ASCII-TEXT PIC X(5).
01 DISPLAY-NUMERIC REDEFINES ASCII-TEXT PIC 9(5).
01 INPUT-TEXT PIC X(5).
01 BINARY-VALUE PIC 9(5) COMP.
MOVE INPUT-TEXT TO ASCII-TEXT.
MOVE DISPLAY-NUMERIC TO BINARY-VALUE.
The above would only work if INPUT-TEXT contained 5 digit characters -- no leading, trailing, or embedded spaces, no sign. With further programming, those limitations can be addressed, but I'm not going to try to do that right now.
For COBOL, not Screen COBOL, it would be possible to call a system procedure that scans an ASCII string that contains a representation of a numeric value and returns a binary value. That would have a lot fewer restrictions that the simple code above
Keith,
I understood the question differently than you. I thought he was looking to find the integral equivalent of the ASCII character. That is, a space would be equal to 32.
This would be equivalent to the Basic (or Visuaal Basic) chr() function.
If the OP intended to convert a sequence of numeric characters to a comp field, then your solution is correct.
Bill
Bill,
Ah, I see now. Yes, the original question could be interpreted either way. That's a frequent problem with remote help like this. I wonder which interpretation is the one the original poster had in mind.
On Tue, 11 Jan 2022 12:37:34 -0800 (PST), Keith Dick <rkd...@gmail.com> wrote:above has. If I were doing the programming, that probably is the way I would go, unless it was important that the COBOL program be portable to other operating systems.
On Tuesday, January 11, 2022 at 12:23:48 PM UTC-8, Bill Honaker wrote:
On Tue, 11 Jan 2022 11:42:34 -0800 (PST), Keith Dick <rkd...@gmail.com> wrote:
On Tuesday, January 11, 2022 at 10:15:31 AM UTC-8, Bill Honaker wrote: >> >> On Tue, 11 Jan 2022 08:14:18 -0800 (PST), Rupesh Sonawane <rupso...@gmail.com> wrote:
How can we convert Ascii string char to its decimal value in Cobol or Screen Cobol requester?Rupesh,
In most COBOL languages this is done with a REDEFINES structure. For example:
01 CHAR-TEST-INT PIC 9(4) COMP.
01 CHAR-TEST-CHAR REDEFINES CHAR-TEST-INT.
02 FILLER PIC X.
02 CHAR-TEST-CHAR-VAL PIC X.
...
MOVE ZERO TO CHAR-TEST-INT.
MOVE CHAR-TO-TEST to CHAR-TEST-CHAR-VAL.
...
After the above two statements, the CHAR-TEST-INT variable will contain the decimal value you need.
Disclaimer - this example as entered from memory and may contain syntax errors. It's meant as a description of the solution only.
Bill
The REDEFINES idea is a valid way to approach the task, but you got a lot of the details wrong. Don't feel bad. I imagine it has been a long time since you have done any COBOL programming!
I think what would work a little better (but is not perfect) would be: >> >
01 ASCII-TEXT PIC X(5).
01 DISPLAY-NUMERIC REDEFINES ASCII-TEXT PIC 9(5).
01 INPUT-TEXT PIC X(5).
01 BINARY-VALUE PIC 9(5) COMP.
MOVE INPUT-TEXT TO ASCII-TEXT.
MOVE DISPLAY-NUMERIC TO BINARY-VALUE.
The above would only work if INPUT-TEXT contained 5 digit characters -- no leading, trailing, or embedded spaces, no sign. With further programming, those limitations can be addressed, but I'm not going to try to do that right now.
For COBOL, not Screen COBOL, it would be possible to call a system procedure that scans an ASCII string that contains a representation of a numeric value and returns a binary value. That would have a lot fewer restrictions that the simple code
Keith,
I understood the question differently than you. I thought he was looking to find the integral equivalent of the ASCII character. That is, a space would be equal to 32.
This would be equivalent to the Basic (or Visuaal Basic) chr() function. >>
If the OP intended to convert a sequence of numeric characters to a comp field, then your solution is correct.
Bill
Bill,
Ah, I see now. Yes, the original question could be interpreted either way. That's a frequent problem with remote help like this. I wonder which interpretation is the one the original poster had in mind.Keith,
Hopefully the OP will reply to us. Rupesh, please clarify and let us know if your question got answered.
Bill
Thanks for your response.above has. If I were doing the programming, that probably is the way I would go, unless it was important that the COBOL program be portable to other operating systems.
Yes Bill, Keith,
I was looking to find the integral equivalent of the ASCII character. That is, a space would be equal to 32.
So will it work with REDEFINES as mentioned earlier?
I have 7 alphanumeric chars strings and need to convert in Numeric data so I was referring to convert it to the equivalent decimal value of ASCII char.
On Wednesday, January 12, 2022 at 4:34:29 AM UTC+5:30, Bill Honaker wrote:
On Tue, 11 Jan 2022 12:37:34 -0800 (PST), Keith Dick <rkd...@gmail.com> wrote:
On Tuesday, January 11, 2022 at 12:23:48 PM UTC-8, Bill Honaker wrote:
On Tue, 11 Jan 2022 11:42:34 -0800 (PST), Keith Dick <rkd...@gmail.com> wrote:
On Tuesday, January 11, 2022 at 10:15:31 AM UTC-8, Bill Honaker wrote: >> >> On Tue, 11 Jan 2022 08:14:18 -0800 (PST), Rupesh Sonawane <rupso...@gmail.com> wrote:
How can we convert Ascii string char to its decimal value in Cobol or Screen Cobol requester?Rupesh,
In most COBOL languages this is done with a REDEFINES structure. For example:
01 CHAR-TEST-INT PIC 9(4) COMP.
01 CHAR-TEST-CHAR REDEFINES CHAR-TEST-INT.
02 FILLER PIC X.
02 CHAR-TEST-CHAR-VAL PIC X.
...
MOVE ZERO TO CHAR-TEST-INT.
MOVE CHAR-TO-TEST to CHAR-TEST-CHAR-VAL.
...
After the above two statements, the CHAR-TEST-INT variable will contain the decimal value you need.
Disclaimer - this example as entered from memory and may contain syntax errors. It's meant as a description of the solution only.
Bill
The REDEFINES idea is a valid way to approach the task, but you got a lot of the details wrong. Don't feel bad. I imagine it has been a long time since you have done any COBOL programming!
I think what would work a little better (but is not perfect) would be: >> >
01 ASCII-TEXT PIC X(5).
01 DISPLAY-NUMERIC REDEFINES ASCII-TEXT PIC 9(5).
01 INPUT-TEXT PIC X(5).
01 BINARY-VALUE PIC 9(5) COMP.
MOVE INPUT-TEXT TO ASCII-TEXT.
MOVE DISPLAY-NUMERIC TO BINARY-VALUE.
The above would only work if INPUT-TEXT contained 5 digit characters -- no leading, trailing, or embedded spaces, no sign. With further programming, those limitations can be addressed, but I'm not going to try to do that right now.
For COBOL, not Screen COBOL, it would be possible to call a system procedure that scans an ASCII string that contains a representation of a numeric value and returns a binary value. That would have a lot fewer restrictions that the simple code
Keith,
I understood the question differently than you. I thought he was looking to find the integral equivalent of the ASCII character. That is, a space would be equal to 32.
This would be equivalent to the Basic (or Visuaal Basic) chr() function.
If the OP intended to convert a sequence of numeric characters to a comp field, then your solution is correct.
Bill
Bill,
Ah, I see now. Yes, the original question could be interpreted either way. That's a frequent problem with remote help like this. I wonder which interpretation is the one the original poster had in mind.Keith,
Hopefully the OP will reply to us. Rupesh, please clarify and let us know if your question got answered.
Bill
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 296 |
Nodes: | 16 (2 / 14) |
Uptime: | 74:06:50 |
Calls: | 6,657 |
Calls today: | 3 |
Files: | 12,203 |
Messages: | 5,332,501 |
Posted today: | 1 |