View previous topic :: View next topic |
Author |
Message |
arvibala Beginner
Joined: 12 Feb 2008 Posts: 142 Topics: 67
|
Posted: Thu Aug 28, 2008 2:45 pm Post subject: STRING function but for numeric variables in COBOL |
|
|
Hi,
I want to combine multiple fields delimited by "`". But some of the fields are numeric ( like amount Totals). I want function like STRING but should work for Numeric values too.
Can some one help?
Cheers, _________________ Arvind
"You can make a difference with your smile. Have that with you always" |
|
Back to top |
|
|
CraigG Intermediate
Joined: 02 May 2007 Posts: 202 Topics: 0 Location: Viginia, USA
|
Posted: Thu Aug 28, 2008 3:34 pm Post subject: |
|
|
Move the numeric fields to a numeric editted field then do the string. |
|
Back to top |
|
|
CZerfas Intermediate
Joined: 31 Jan 2003 Posts: 211 Topics: 8
|
Posted: Fri Aug 29, 2008 2:32 am Post subject: |
|
|
To handle that within a SELECT you can transform the numeric columns to character values with the CHAR or the CAST function:
SELECT CHAR(numeric-filed-1) !! "-" !! CAST(numeric-field-2) as CHAR(10)
FROM ...
regards
Christian |
|
Back to top |
|
|
arvibala Beginner
Joined: 12 Feb 2008 Posts: 142 Topics: 67
|
Posted: Fri Aug 29, 2008 10:37 am Post subject: |
|
|
I am reading this from a Flat File using COBOL program and writing into a Flat file again. _________________ Arvind
"You can make a difference with your smile. Have that with you always" |
|
Back to top |
|
|
Santlou Beginner
Joined: 18 Apr 2007 Posts: 21 Topics: 4 Location: sw florida
|
Posted: Sun Aug 31, 2008 12:59 pm Post subject: |
|
|
If the fields are not signed or packed, you can use reference modification to reference them as Alphanumeric fields:
Example:
Code: | STRING WS-NUM1 (1:) WS-NUM2(1:) DELIMITED BY SIZE INTO WS-DISPLAY-TEXT. |
Using reference modification turns the move into an Alphanumeric move. |
|
Back to top |
|
|
arvibala Beginner
Joined: 12 Feb 2008 Posts: 142 Topics: 67
|
Posted: Thu Sep 25, 2008 3:22 pm Post subject: |
|
|
Thanks Santlou,
Its working. But Iam looking for Robust logic so that the number gets appended without leading zeros. Like if I want to append
Code: |
XXXXX - X(10)
94 - 9(10)
55 - 9(08)
YYYY - X(10)
|
I want like XXXXX9455YYYY
but I will get XXXXX000000009400000055YYYY
More help will be great
Thanks _________________ Arvind
"You can make a difference with your smile. Have that with you always" |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Thu Sep 25, 2008 3:56 pm Post subject: |
|
|
arvibala,
untested code
Code: |
01 WS-CHAR-FLD1 PIC X(10) VALUE 'XXXX'.
01 WS-NUM-FLD1 PIC 9(10) VALUE 94.
01 WS-NUM-FLD2 PIC 9(08) VALUE 55.
01 WS-CHAR-FLD2 PIC X(10) VALUE 'YYYY'.
01 WS-TALLY1 PIC S9(04) COMP.
01 WS-LEN1 PIC S9(04) COMP.
01 WS-TALLY2 PIC S9(04) COMP.
01 WS-LEN2 PIC S9(04) COMP.
01 WS-OUT-STRING PIC X(80).
PROCEDURE DIVISION.
INITIALIZE WS-LEN1 WS-TALLY1
WS-LEN2 WS-TALLY2
INSPECT WS-NUM-FLD1 TALLYING WS-TALLY1 FOR LEADING ZEROES
COMPUTE WS-LEN1 = LENGTH OF WS-NUM-FLD1 - WS-TALLY1
INSPECT WS-NUM-FLD2 TALLYING WS-TALLY2 FOR LEADING ZEROES
COMPUTE WS-LEN2 = LENGTH OF WS-NUM-FLD2 - WS-TALLY2
STRING WS-CHAR-FLD1 DELIMITED BY SPACES
WS-NUM-FLD1(WS-TALLY1 + 1 : WS-LEN1)
WS-NUM-FLD2(WS-TALLY2 + 1 : WS-LEN2)
WS-CHAR-FLD2 DELIMITED BY SPACES
INTO WS-OUT-STRING
END-STRING
DISPLAY WS-OUT-STRING
|
Kolusu |
|
Back to top |
|
|
|
|