How to Implement in Cobol

Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS
aman8888
Posts: 2
Joined: Tue Feb 19, 2008 7:24 pm
Skillset: Cobol,CICS,VSAM
Referer: GOOGLE

How to Implement in Cobol

Postby aman8888 » Tue Feb 19, 2008 7:29 pm

Hi, i have a Field of X(65) occuring 125 times now i need to modify the content and move it to X(8125)... but i should remove more than 2 spaces and make it a single space. can anyone help me. How can it Implment it in COBOL...

Should i use Inspect or any other Verb is there which would help me.

Plz Help.........

User avatar
dick scherrer
Global moderator
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am

Re: How to Implement in Cobol

Postby dick scherrer » Tue Feb 19, 2008 10:43 pm

Hello aman and welcome to the forums,

If you post some sample "input" data and what you want the output to look like, someone should have a suggestion.

For your example, you could use 30 bytes instead of 65 and only 5 occurances instead of 125. Yo need to show what should happen when one field is completely filled or when one ends with a single or multiple spaces. If your sample data is not complete, any suggested solution may also be incomplete.
Hope this helps,
d.sch.

CICS Guy
Posts: 246
Joined: Wed Jun 20, 2007 4:08 am

Re: How to Implement in Cobol

Postby CICS Guy » Wed Feb 20, 2008 4:24 am

aman8888 wrote:but i should remove more than 2 spaces and make it a single space. can anyone help me. How can it Implment it in COBOL...
A perform varying loop with moves by reference will 'pass the gas', eliminate the extra spaces.
The exact code depends upon what the significance of the 65 byte lines are in the input and output.
Like Dick indicated, a sample of input and expected output will help us to provide your solution.

aman8888
Posts: 2
Joined: Tue Feb 19, 2008 7:24 pm
Skillset: Cobol,CICS,VSAM
Referer: GOOGLE

Re: How to Implement in Cobol

Postby aman8888 » Wed Feb 20, 2008 10:43 am

[Hi, i have a Field of X(65) occuring 125 times now i need to modify the content and move it to X(8125)... but i should remove more than 2 spaces and make it a single space. can anyone help me. How can it Implment it in COBOL...

Should i use Inspect or any other Verb is there which would help me.

Plz Help.......

I/P

<--------------------65------------------------->
This_____is______a sample line ________!
this is 2nd line_______________________! 125 times
this______________is___third line_____!

O/P

<--------8125-------------------------------->
This is a sample line this is 2nd line this is third line


actually the sample data which would be coming will be formated in lines (occuring 125, i know the data will be stored in continuous format)

try visualising it like an email written ( in para ) if some one leaves to or more spaces i need to format it so that only one space is left.

arunprasad.k
Posts: 110
Joined: Thu Dec 27, 2007 5:18 pm
Skillset: Known little stuffs to answer a few queries!!
Referer: Google
Contact:

Re: How to Implement in Cobol

Postby arunprasad.k » Wed Feb 20, 2008 8:26 pm

Here you go!!

Code: Select all

       IDENTIFICATION DIVISION.                                         
       PROGRAM-ID.    SAMPLE                                           
       ENVIRONMENT DIVISION.                                           
       CONFIGURATION SECTION.                                           
       INPUT-OUTPUT SECTION.                                           
       FILE-CONTROL.                                                   
       DATA DIVISION.                                                   
       FILE SECTION.                                                   
       WORKING-STORAGE SECTION.                                         
       01 VAR1.                                                         
            05 VAR-A1                   PIC X(65) OCCURS 3 TIMES.       
       01 VAR-A2                        PIC X(200).                     
       01 WS-ID                         PIC 9(02) VALUE 1.             
       01 I                             PIC 9(02) VALUE 1.             
       01 J                             PIC 9(02) VALUE 1.             
       PROCEDURE DIVISION.                                             
            MOVE 'THIS  IS      A SAMPLE LINE         ' TO             
                  VAR-A1(1).                                           
            MOVE 'THIS IS 2ND LINE                       ' TO           
                  VAR-A1(2).                                           
            MOVE 'THIS              IS   THIRD LINE      ' TO           
                  VAR-A1(3).                                           
            PERFORM LOOP-FOR-EACH-ARRAY                                 
               THRU LOOP-FOR-EACH-ARRAY-XT UNTIL WS-ID > 3.             
            DISPLAY 'VAR-A2 :' VAR-A2.                                 
            GOBACK.                                                     
       LOOP-FOR-EACH-ARRAY.                                             
            MOVE 1 TO I.                                               
            MOVE SPACES TO VAR-A2(J:1).                                 
            ADD 1 TO J.                                                 
            PERFORM UNTIL I = 65                                       
               IF NOT VAR-A1(WS-ID) (I:1) = ' '                         
                  MOVE VAR-A1(WS-ID) (I:1) TO  VAR-A2(J:1)             
                  COMPUTE J = (J + 1) END-COMPUTE                       
                  COMPUTE I = (I + 1) END-COMPUTE                       
               ELSE                                                     
                  COMPUTE I = (I + 1) END-COMPUTE                       
                  IF NOT VAR-A1(WS-ID) (I:1) = ' '                     
                     COMPUTE I = (I - 1) END-COMPUTE                   
                     MOVE VAR-A1(WS-ID) (I:1) TO VAR-A2(J:1)           
                     COMPUTE I = (I + 1) END-COMPUTE                   
                     COMPUTE J = (J + 1) END-COMPUTE                   
                     MOVE VAR-A1(WS-ID) (I:1) TO  VAR-A2(J:1)           
                     COMPUTE J = (J + 1) END-COMPUTE                   
                     COMPUTE I = (I + 1) END-COMPUTE                   
                  END-IF                                               
               END-IF                                                   
            END-PERFORM.                                               
            ADD 1 TO WS-ID.                                             
       LOOP-FOR-EACH-ARRAY-XT.                                         

User avatar
dick scherrer
Global moderator
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am

Re: How to Implement in Cobol

Postby dick scherrer » Wed Feb 20, 2008 11:09 pm

Hello,

Has the posted suggestion been tested?

I believe it will not do what is intended. . .

Time permitting later, i'll see if i can upload and run it, but in the meantime, i just wanted to post a caution. . .
Hope this helps,
d.sch.

arunprasad.k
Posts: 110
Joined: Thu Dec 27, 2007 5:18 pm
Skillset: Known little stuffs to answer a few queries!!
Referer: Google
Contact:

Re: How to Implement in Cobol

Postby arunprasad.k » Thu Feb 21, 2008 6:23 pm

Yep!! I found a bug and fixed. In any occrance if the first byete is spaces then my code will add an extra space.

I do not find any other mistake in that. Did you find time to run that code?

Also could you please post why you believe that the previous code will not work as intended? (Just out of curiosity :D )

Just added an IF statement and changed the value of J. See the changes tagged with ARUN**.

Modified code:

Code: Select all

       IDENTIFICATION DIVISION.                                         
       PROGRAM-ID.    SAMPLE                                           
       ENVIRONMENT DIVISION.                                           
       CONFIGURATION SECTION.                                           
       INPUT-OUTPUT SECTION.                                           
       FILE-CONTROL.                                                   
       DATA DIVISION.                                                   
       FILE SECTION.                                                   
       WORKING-STORAGE SECTION.                                         
       01 VAR1.                                                         
            05 VAR-A1                   PIC X(65) OCCURS 3 TIMES.       
       01 VAR-A2                        PIC X(200).                     
       01 WS-ID                         PIC 9(02) VALUE 1.             
       01 I                             PIC 9(02) VALUE 1.             
ARUN***01 J                             PIC 9(02) VALUE 1.             
ARUN** 01 J                             PIC 9(02) VALUE 0.             
       PROCEDURE DIVISION.                                             
            MOVE ' THIS  IS   A SAMPLE LINE         ' TO               
                  VAR-A1(1).                                           
            MOVE '  THIS IS 2ND LINE                       ' TO         
                  VAR-A1(2).                                           
            MOVE 'THIS              IS   THIRD LINE      ' TO           
                  VAR-A1(3).                                           
            PERFORM LOOP-FOR-EACH-ARRAY                                 
               THRU LOOP-FOR-EACH-ARRAY-XT UNTIL WS-ID > 3.             
            DISPLAY 'VAR-A2 :' VAR-A2.                                 
            GOBACK.                                                     
       LOOP-FOR-EACH-ARRAY.                                             
            MOVE 1 TO I.                                               
ARUN**      IF VAR-A1(WS-ID) (I:1) NOT = ' '                           
              MOVE SPACES TO VAR-A2(J:1)                               
              ADD 1 TO J                                               
ARUN**      END-IF.                                                     
            PERFORM UNTIL I = 65                                       
               IF NOT VAR-A1(WS-ID) (I:1) = ' '                         
                  MOVE VAR-A1(WS-ID) (I:1) TO  VAR-A2(J:1)             
                  COMPUTE J = (J + 1) END-COMPUTE                       
                  COMPUTE I = (I + 1) END-COMPUTE                       
               ELSE                                                     
                  COMPUTE I = (I + 1) END-COMPUTE                       
                  IF NOT VAR-A1(WS-ID) (I:1) = ' '                     
                     COMPUTE I = (I - 1) END-COMPUTE                   
                     MOVE VAR-A1(WS-ID) (I:1) TO VAR-A2(J:1)           
                     COMPUTE I = (I + 1) END-COMPUTE                   
                     COMPUTE J = (J + 1) END-COMPUTE                   
                     MOVE VAR-A1(WS-ID) (I:1) TO  VAR-A2(J:1)           
                     COMPUTE J = (J + 1) END-COMPUTE                   
                     COMPUTE I = (I + 1) END-COMPUTE                   
                  END-IF                                               
               END-IF                                                   
            END-PERFORM.                                               
            ADD 1 TO WS-ID.                                             
       LOOP-FOR-EACH-ARRAY-XT.                                         

CICS Guy
Posts: 246
Joined: Wed Jun 20, 2007 4:08 am

Re: How to Implement in Cobol

Postby CICS Guy » Thu Feb 21, 2008 9:36 pm

aman8888 wrote:I/P
<--------------------65------------------------->
This_____is______a sample line ________!
this is 2nd line_______________________! 125 times
this______________is___third line_____!
O/P
<--------8125-------------------------------->
This is a sample line this is 2nd line this is third line
Or possibly something like this?

Code: Select all

Perform varying I from 1 to LENGTH-OF-GROUP
   if GROUP(I:2) = space
      continue
   else
      move GROUP(I:1) to Group(J:1)
      add 1 to J
   end-if
end-perform

arunprasad.k
Posts: 110
Joined: Thu Dec 27, 2007 5:18 pm
Skillset: Known little stuffs to answer a few queries!!
Referer: Google
Contact:

Re: How to Implement in Cobol

Postby arunprasad.k » Thu Feb 21, 2008 10:06 pm

CG, Could you please post the exact code? Because I tried it and it was not working for me. Arun.

William Thompson
Posts: 81
Joined: Sat Jun 09, 2007 4:24 am
Skillset: Some?
Referer: mcmillan
Location: Tucson AZ

Re: How to Implement in Cobol

Postby William Thompson » Thu Feb 21, 2008 10:31 pm

If you understand COBOL, the provided solution should be enough to work from.
Just where and what is it not working for you?


  • Similar Topics
    Replies
    Views
    Last post