Replacing space with NULL value

This is a Mainframe COBOL forum - you can post your queries on Mainframe COBOL, VS COBOL II, COBOL/370 , Enterprise COBOL

Moderators: dbzTHEdinosauer, Moderator Group

Post Reply
User avatar
JACK
Member
Posts: 20
Joined: Mon Jan 30, 2006 6:18 am

Replacing space with NULL value

Post by JACK » Wed Jun 24, 2009 2:40 pm

Hi All,

Please provide the COBOL code to replace spaces will NULL. i.e, if i have the string like 'COMMON BUSINESS' . space in the string to bre removed.
and string in the output shoul be 'COMMONBUSINESS'.

User avatar
Chanti
Member
Posts: 32
Joined: Thu Nov 27, 2008 4:31 pm

Post by Chanti » Thu Jun 25, 2009 12:21 pm

Try out using UNSTRING & STRING COBOL Functions.

or you can run through the string and eliminate spaces.

User avatar
JACK
Member
Posts: 20
Joined: Mon Jan 30, 2006 6:18 am

Post by JACK » Thu Jun 25, 2009 12:59 pm

Hi Chanti,

Thanks for your response...
I have tried using UNSTRING.. but i am facing issues with that.
If you have time, can you provide COBOL code for this. :?:

Thanks for help.
:|

User avatar
dbzTHEdinosauer
Moderator
Posts: 981
Joined: Mon Oct 02, 2006 8:31 pm

Post by dbzTHEdinosauer » Thu Jun 25, 2009 1:20 pm

Here is some code to start with.

Code: Select all

05  WS-INPUT-IMAGE         PIC X(40).
05  WS-INPUT-TABLE
    REDEFINES
    WS-INPUT-IMAGE         OCCURS 40 TIMES
                           INDEXED BY INPUT-IDX
                           PIC X(01).
    88  WS-INPUT-SPACE     VALUE SPACE.

05  WS-OUTPUT-IMAGE        PIC X(40).
    88  INIT-OUTPUT-IMAGE  VALUE SPACES.
05  WS-OUTPUT-TABLE
    REDEFINES
    WS-OUTPUT-IMAGE        OCCURS 40 TIMES
                           INDEXED BY OUTPUT-IDX
                           PIC X(01).
.... 

SET OUTPUT-IDX             TO 1
SET INIT-OUTPUT-IMAGE      TO TRUE

PERFORM VARYING INPUT-IDX
                FROM       1
                BY         1
                UNTIL      INPUT-IDX
                         > 40
    IF WS-INPUT-SPACE(INPUT-IDX)
    THEN
       CONTINUE
    ELSE
       MOVE WS-INPUT-TABLE(INPUT-IDX) 
         TO WS-OUTPUT-TABLE(OUTPUT-IDX)
       SET  OUTPUT-IDX     UP BY 1
    END-IF
END-PERFORM
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.

User avatar
Chanti
Member
Posts: 32
Joined: Thu Nov 27, 2008 4:31 pm

Post by Chanti » Thu Jun 25, 2009 4:11 pm

Jack,
You can use the one of the solution(running through the string and eliminating spaces) offered by dick

Or you can try out this

UNSTRING WS-STRING DELIMITED BY SPACES
INTO WS-STRING1 WS-STRING2
END-UNSTRING.

STRING WS-STRING1 DELIMITED BY SPACE
WS-STRING2 DELIMITED BY SPACE
INTO WS-STRING3
END-STRING.

Thanks,
Chanti.

User avatar
dbzTHEdinosauer
Moderator
Posts: 981
Joined: Mon Oct 02, 2006 8:31 pm

Post by dbzTHEdinosauer » Thu Jun 25, 2009 5:30 pm

Chanti,

what will happen if there are more than two (2) words in the input string?
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others