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 

shrink a string

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


Joined: 12 Oct 2004
Posts: 78
Topics: 39

PostPosted: Thu Nov 06, 2008 5:37 am    Post subject: shrink a string Reply with quote

hello everyone,

i need to transfrom a string pic x(12)
Code:
 goofy   .cob
in
Code:
goofy.cob   
in the same string.

how can i do?

thanks
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Thu Nov 06, 2008 10:16 am    Post subject: Reply with quote

First of all, in COBOL, the only way to 'shrink' a string is to move it to a field that is smaller.
What you are refering to, I would call: Left justification, removing spaces, which by the way - DFSORT does a good job of doing.

This UNTESTED CODE will work
if you only have two words in your string.
If you can have more than 2 words,
then you need to add a WS-WORK-n for each additional word.

Code:

05  YOUR-ORIGINAL-FIELD     PIC X(12).
05  WS-WORK-1               PIC X(12).
05  WS-WORK-2               PIC X(12).

UNSTRING YOUR-ORIGINAL-FIELD
                DELIMITED BY ALL SPACES
    INTO WS-WORK-1
         WS-WORK-2
END-UNSTRING

MOVE SPACES TO YOUR-ORIGINAL-FIELD

STRING WS-WORK-1
            DELIMITED BY ALL SPACES
       WS-WORK-2
            DELIMITED BY ALL SPACES
  INTO YOUR-ORIGINAL-FIELD
END-STRING

_________________
Dick Brenholtz
American living in Varel, Germany


Last edited by dbzTHEdinosauer on Thu Nov 06, 2008 11:22 am; edited 2 times in total
Back to top
View user's profile Send private message
jsharon1248
Intermediate


Joined: 08 Aug 2007
Posts: 291
Topics: 2
Location: Chicago

PostPosted: Thu Nov 06, 2008 10:17 am    Post subject: Reply with quote

For this task, I'd recommend just coding a PERFORM UNTIL that increments an index (or subscript if you prefer). You'll need a second pointer to store the current next available position in the receiving field. MOVE the characters that you want to keep 1 by 1; only bump the next available position pointer when you actually MOVE a character. Here's some untested code that should get you moving in the right direction:

Code:
INITIALIZE RECEIVING-FLD
MOVE +1 TO PTR2
MOVE LENGTH OF RECEIVING-FLD TO RECEIVING-FLD-L
MOVE LENGTH OF SENDING-FLD   TO SENDING-FLD-L

PERFORM VARYING PTR1 FROM +1 BY +1
        UNTIL PTR1 > SENDING-FLD-L

  IF PTR2 <= RECEIVING-FLD-L
    IF SENDING-FLD(PTR1:1) NOT = SPACE
      MOVE SENDING-FLD(PTR1:1) TO RECEIVING-FLD(PTR2:1)
    END-IF
  END-IF

END-PERFORM
Back to top
View user's profile Send private message
enge
Beginner


Joined: 12 Oct 2004
Posts: 78
Topics: 39

PostPosted: Thu Nov 06, 2008 11:29 am    Post subject: Reply with quote

good solutions.
i choose the last one.
thank a lot.
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Thu Nov 06, 2008 12:18 pm    Post subject: Reply with quote

enge,

jsharon1248's solution will work if you add a line to bump PTR2 if it is used (second if is true).
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
jsharon1248
Intermediate


Joined: 08 Aug 2007
Posts: 291
Topics: 2
Location: Chicago

PostPosted: Thu Nov 06, 2008 2:27 pm    Post subject: Reply with quote

DOH!! bonk

Should've paid more attention to what I wrote. Thanks for the second set of eyes dbz.

This is a little closer to what you'll need.

Code:
INITIALIZE RECEIVING-FLD
MOVE +1 TO PTR2
MOVE LENGTH OF RECEIVING-FLD TO RECEIVING-FLD-L
MOVE LENGTH OF SENDING-FLD   TO SENDING-FLD-L

PERFORM VARYING PTR1 FROM +1 BY +1
        UNTIL PTR1 > SENDING-FLD-L

  IF PTR2 <= RECEIVING-FLD-L
    IF SENDING-FLD(PTR1:1) NOT = SPACE
      MOVE SENDING-FLD(PTR1:1) TO RECEIVING-FLD(PTR2:1)
      ADD +1 to PTR2
    END-IF
  END-IF

END-PERFORM
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Fri Nov 07, 2008 3:16 am    Post subject: Reply with quote

no problem jsharon1248. I just had to spend about an hour apologizing and amending several posts that I made this week.

i should have sent a private message to you, so that you could have amended it. It was not necessary to blow my own horn.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
enge
Beginner


Joined: 12 Oct 2004
Posts: 78
Topics: 39

PostPosted: Fri Nov 07, 2008 8:32 am    Post subject: Reply with quote

great work ! thanks you again.
Back to top
View user's profile Send private message
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