MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

STRING function but for numeric variables in COBOL

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
arvibala
Beginner


Joined: 12 Feb 2008
Posts: 142
Topics: 67

PostPosted: Thu Aug 28, 2008 2:45 pm    Post subject: STRING function but for numeric variables in COBOL Reply with quote

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
View user's profile Send private message Yahoo Messenger
CraigG
Intermediate


Joined: 02 May 2007
Posts: 202
Topics: 0
Location: Viginia, USA

PostPosted: Thu Aug 28, 2008 3:34 pm    Post subject: Reply with quote

Move the numeric fields to a numeric editted field then do the string.
Back to top
View user's profile Send private message
CZerfas
Intermediate


Joined: 31 Jan 2003
Posts: 211
Topics: 8

PostPosted: Fri Aug 29, 2008 2:32 am    Post subject: Reply with quote

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
View user's profile Send private message
arvibala
Beginner


Joined: 12 Feb 2008
Posts: 142
Topics: 67

PostPosted: Fri Aug 29, 2008 10:37 am    Post subject: Reply with quote

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
View user's profile Send private message Yahoo Messenger
Santlou
Beginner


Joined: 18 Apr 2007
Posts: 21
Topics: 4
Location: sw florida

PostPosted: Sun Aug 31, 2008 12:59 pm    Post subject: Reply with quote

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
View user's profile Send private message
arvibala
Beginner


Joined: 12 Feb 2008
Posts: 142
Topics: 67

PostPosted: Thu Sep 25, 2008 3:22 pm    Post subject: Reply with quote

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
View user's profile Send private message Yahoo Messenger
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Thu Sep 25, 2008 3:56 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group