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 

COBOL sort

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


Joined: 09 Nov 2006
Posts: 35
Topics: 12

PostPosted: Wed Mar 11, 2009 11:13 am    Post subject: COBOL sort Reply with quote

Hi,

I have a input file A. I need to extract 7 strings from the input file based on the position say @position 5,30,40,55,60,75,90 etc.

after extracting the seven strings, i need to put all the strings in the output file. i want to achieve this using COBOL.

I know this can be achieved using JCL. But i need a COBOL solution.

Please help me.

Thanks in advance.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Wed Mar 11, 2009 11:19 am    Post subject: Reply with quote

waves,

Do you need to sort the extracted strings? If you just need to extract strings isn't it a simple case of using a MOVE statement of input to output?

You need to do a better job of explaining as to what you are trying to do. Show us the input layout and desired output layout with a sample data along with the DCB properties of the input and output files.

Kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
waves
Beginner


Joined: 09 Nov 2006
Posts: 35
Topics: 12

PostPosted: Wed Mar 11, 2009 11:41 am    Post subject: Reply with quote

Hi Kolusu,

I dont need to sort the extracted strings.

first i will sort the input file and then i will extract the 7 strings based on the poistions from input file and put it in the output file.

Input file:
Code:

20001345679asddpioqewwr34499000qkmkppl
20001223499asddsslkldwwr34558000qkmkppl
20001444455asddsdsjjwwr344991230qkmkppl

Output file:
Code:

55sd91
79pi99
99ss58

The above string is extracted based on position 10,16,27 respectively.

Thanks a lot
Back to top
View user's profile Send private message
Nic Clouston
Advanced


Joined: 01 Feb 2007
Posts: 1075
Topics: 7
Location: At Home

PostPosted: Wed Mar 11, 2009 1:30 pm    Post subject: Reply with quote

You cannot do it in JCL. JCL is Job Control Langage and is used for definng the programs and datasets to be used by your job. It does not process data.

That said, why can you not just define a record structure for your input records and another for your output records and, as Kolusu suggested, move the appropriate fields from the input structure to the output structure?
_________________
Utility and Program control cards are NOT, repeat NOT, JCL.
Back to top
View user's profile Send private message
waves
Beginner


Joined: 09 Nov 2006
Posts: 35
Topics: 12

PostPosted: Thu Mar 12, 2009 8:32 am    Post subject: Reply with quote

Can somebody pls help with COBOL code.

It will be very helpful to me.

Thanks in advance.
Back to top
View user's profile Send private message
jsharon1248
Intermediate


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

PostPosted: Thu Mar 12, 2009 10:57 am    Post subject: Reply with quote

Show us what you've coded, and I'll be happy to review it to see if I can help.
Back to top
View user's profile Send private message
Nic Clouston
Advanced


Joined: 01 Feb 2007
Posts: 1075
Topics: 7
Location: At Home

PostPosted: Thu Mar 12, 2009 12:40 pm    Post subject: Reply with quote

If you are not a COBOL programmer then why are you doing this task? If you want to learn then try COBOL for Dummies or similar books.
_________________
Utility and Program control cards are NOT, repeat NOT, JCL.
Back to top
View user's profile Send private message
kalatur
Beginner


Joined: 09 Apr 2007
Posts: 2
Topics: 0
Location: Bay Area

PostPosted: Sat Mar 21, 2009 10:36 pm    Post subject: Re: COBOL sort Reply with quote

waves wrote:
Hi,


I know this can be achieved using JCL. But i need a COBOL solution.



What are you saying can be done using JCL? Changing data?
Back to top
View user's profile Send private message
hari_uss
Beginner


Joined: 19 Dec 2002
Posts: 78
Topics: 6
Location: Trivandrum, India

PostPosted: Mon Mar 23, 2009 2:21 am    Post subject: Reply with quote

I think waves meant SORT or similar utilities which can be executed in JCL.
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


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

PostPosted: Mon Mar 23, 2009 6:52 pm    Post subject: Reply with quote

Waves,

Here is an untested cobol program which I just cloned it from one of my existing programs.
Code:

       IDENTIFICATION DIVISION.
       PROGRAM-ID. COBSORT
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.

             SELECT INFILE
             ASSIGN TO INFILE
             ORGANIZATION IS SEQUENTIAL.

             SELECT OUTFILE
             ASSIGN TO OUTFILE
             ORGANIZATION IS SEQUENTIAL.

             SELECT SORT-FILE
             ASSIGN TO TEMPFILE.

       DATA DIVISION.
       FILE SECTION.

       FD INFILE
           RECORDING MODE IS F
           LABEL RECORDS ARE STANDARD
           BLOCK CONTAINS 0 RECORDS
           DATA RECORD IS IN-REC.

       01 IN-REC                       PIC X(80).

       FD OUTFILE
           RECORDING MODE IS F
           LABEL RECORDS ARE STANDARD
           BLOCK CONTAINS 0 RECORDS
           DATA RECORD IS OUT-REC.

       01 OUT-REC.
          05 OUT-KEY1                  PIC X(02).
          05 OUT-KEY2                  PIC X(02).
          05 OUT-KEY3                  PIC X(02).

       SD SORT-FILE
           RECORD CONTAINS 80 CHARACTERS
           DATA RECORD SORT-RECORD.

       01 SORT-RECORD.
          05 FILLER                    PIC X(09).
          05 SD-KEY1                   PIC X(02).
          05 FILLER                    PIC X(04).
          05 SD-KEY2                   PIC X(02).
          05 FILLER                    PIC X(09).
          05 SD-KEY3                   PIC X(02).
          05 FILLER                    PIC X(52).

       WORKING-STORAGE SECTION.
       01 S-EOF-INPUT                  PIC X VALUE 'N'.

       PROCEDURE DIVISION.

           OPEN OUTPUT OUTFILE
           SORT SORT-FILE
             ON ASCENDING KEY SD-KEY1
             ON ASCENDING KEY SD-KEY2
             ON ASCENDING KEY SD-KEY3
                USING INFILE
                OUTPUT PROCEDURE 1000-WRITE-REC
           GOBACK
           .

       1000-WRITE-REC.
      *************************************************************
      * THIS PARAGRAPH WRITES OUTPUT RECORDS                      *
      *************************************************************

           PERFORM 2000-CHECK-EOF
           PERFORM UNTIL S-EOF-INPUT = 'Y'
                IF SORT-RETURN = 0
                   MOVE SD-KEY1        TO OUT-KEY1
                   MOVE SD-KEY2        TO OUT-KEY2
                   MOVE SD-KEY3        TO OUT-KEY3
                   WRITE OUT-REC
                   PERFORM 2000-CHECK-EOF
                END-IF
           END-PERFORM
           .
       2000-CHECK-EOF.
      *************************************************************
      * THIS PARAGRAPH CHECKS FOR END-OF-FILE CONDITION           *
      *************************************************************

           RETURN SORT-FILE AT END
                  MOVE 'Y'             TO S-EOF-INPUT
                  CLOSE OUTFILE
           END-RETURN
           .



Hope this helps...

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