IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

COBOL sorting, with input GDG base


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
AlexSalas95

New User


Joined: 18 Mar 2024
Posts: 10
Location: United States

PostPosted: Tue Nov 19, 2024 4:16 am
Reply with quote

I've written a program that uses a GDG base as input. The GDG base may contain several generations. The input is sorted internally within the COBOL program, as opposed to using SyncSort/DFSort, due to processing requirements.

The issue I'm having is when I sort the file, it's also actually writing this sorted data into one of the generations. In my testing, it's generally the last generation but I believe it's also written to the initial generation also.

I'm fairly confident I know what my error is, but I'm not exactly sure what would be the best solution. See the incomplete COBOL code below;

Code:
       IDENTIFICATION DIVISION.
       PROGRAM-ID. ATEST.
      ******************************************************************
       ENVIRONMENT DIVISION.
      ******************************************************************
       CONFIGURATION SECTION.
      ******************************************************************
       INPUT-OUTPUT SECTION.
      ******************************************************************
       FILE-CONTROL.
      ******************************************************************
           SELECT INFILE          ASSIGN TO INFILE
                                  FILE STATUS IS INFILE-STATUS.
           SELECT SORT-INFILE     ASSIGN TO SORT-INFILE.

           SELECT OUTFILE1        ASSIGN TO OUTFILE1
                                  FILE STATUS IS OUTFILE1-STATUS.
      ******************************************************************
       DATA DIVISION.
      ******************************************************************
       FILE SECTION.
      ******************************************************************
       FD  INFILE
           BLOCK CONTAINS 0 RECORDS
           LABEL RECORDS ARE STANDARD.
       01  INFILE-RECORD.
           02 IN-FIELD             PIC X(80).
       SD  SORT-INFILE.
       01  INFILE-RECORD-S.
           02 IN-FIELD-S           PIC X(80).

       FD  OUTFILE1
           BLOCK CONTAINS 0 RECORDS
           LABEL RECORDS ARE STANDARD.
       01  OUTFILE1-RECORD      PIC X(097).

      ******************************************************************
       PROCEDURE DIVISION.
      ******************************************************************
           SORT SORT-INFILE
              ON ASCENDING KEY IN-FIELD-S
              USING INFILE
              GIVING INFILE.




I'm 99% it's when the last line shown,
Code:
GIVING INFILE
executes.

For a visual, assume input data as follows;

input gdg0001v00 contains 1 record; ALPHA
input gdg0002v00 contains 1 record; BRAVO
input gdg0003v00 contains 1 record; CHARLIE

After performing the sort (alphabetically, ascending for this example), the data is as follows;

input gdg0001v00 contains 1 record; ALPHA
input gdg0002v00 contains 1 record; BRAVO
input gdg0003v00 contains 3 record; CHARLIE BRAVO ALPHA

How could I sort the input internally without altering the actual input gdgs?
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1050
Location: Richmond, Virginia

PostPosted: Tue Nov 19, 2024 9:27 am
Reply with quote

I never used the COBOL sort, but I find two things here confusing.

1.
Quote:
...but I believe it's also written to the initial generation also

Yet your example shows only the last generation modified

2. Your sort says ASCENDING, yet your last generation's records are: CHARLIE BRAVO ALPHA
Back to top
View user's profile Send private message
Pete Wilson

Active Member


Joined: 31 Dec 2009
Posts: 592
Location: London

PostPosted: Tue Nov 19, 2024 5:38 pm
Reply with quote

Seems a bizarre thing to be doing. Can you include the JCL used,
Back to top
View user's profile Send private message
AlexSalas95

New User


Joined: 18 Mar 2024
Posts: 10
Location: United States

PostPosted: Tue Nov 19, 2024 7:28 pm
Reply with quote

@Phrzby Phil

Sorry I should've made that clearer. It seems that when I sort ascending, it puts the records in the initial GDG. Descending puts it in the last GDG. In the example I gave, it should've been descending which would've resulted in the data shown


@Pete Wilson

Yeah, I may end up doing this another way. I think this way would've been fine had I not been using a GDG base as input. I'll drop the jcl in here anyway;

Code:
//S001   EXEC PGM=ATEST,COND=(4,LT),REGION=4M
//STEPLIB  DD DSN=SYS2.TEST,DISP=SHR
//SYSOUT   DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//*                \/ THIS IS A GDG BASE
//INFILE   DD DSN=USERNAME.SEQ.TEST.GDG,DISP=SHR
//OUTFILE1 DD DSN=USERNAME.SEQ.NEW.OUT,
//            DISP=(NEW,CATLG,DELETE),UNIT=DISK,
//            BUFNO=50,DATACLAS=F097,
//            SPACE=(CYL,(1,1),RLSE)
Back to top
View user's profile Send private message
Pete Wilson

Active Member


Joined: 31 Dec 2009
Posts: 592
Location: London

PostPosted: Tue Nov 19, 2024 7:48 pm
Reply with quote

Based on the JCL OUTFILE1 is a completely separate dataset and not a GDG, so how you end up with all the INFILE1 GDG generations combined into generation G0003V00 of INFILEI really don't know. The program also seems to refer to INFILE rather than INFILE1 as well.
Back to top
View user's profile Send private message
AlexSalas95

New User


Joined: 18 Mar 2024
Posts: 10
Location: United States

PostPosted: Tue Nov 19, 2024 7:49 pm
Reply with quote

For progeny, I wouldn't recommend doing this unless you have to. And if you think you have to, there's probably another, better way

However, a solution I found is to just write (or "give") the sort to a separate output file as opposed to an input. When I originally wrote the code, it felt wrong to write to my input anyway, but it would've been fine had it not been a GDG base

The COBOL sort to do this is very simple;

Code:
           SORT SORT-INFILE
              ON ASCENDING KEY IN-FIELD-S
              USING INFILE
              GIVING OUTFILE1.


I generally use a sort utility to sort my input, but it would've been a little tricky for this program in particular. Also, the input is only a few hundred, maybe a thousand rows per run, so performance wasn't really a concern.
Back to top
View user's profile Send private message
AlexSalas95

New User


Joined: 18 Mar 2024
Posts: 10
Location: United States

PostPosted: Tue Nov 19, 2024 7:59 pm
Reply with quote

@Pete Wilson

The "giving" command in the internal sort function of the program writes the output to the file specified. The file does not need to be opened for output (or opened at all) for it do this, allowing you to output to an input file

Sketchy, but I think for most applications it's safe since it's only sorting the file and not changing record lengths or anything
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1050
Location: Richmond, Virginia

PostPosted: Tue Nov 19, 2024 8:34 pm
Reply with quote

My preference was always a separate JCL Sort: COBOL-Program-A, Sort, COBOL-Program-B.

I found this kept my logic simpler, plus very few other programmers I worked with used COBOL Sort, so much safer.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Need help with ADABAS query (COBOL-AD... All Other Mainframe Topics 0
No new posts GDG generation name to GDG Base name ... DFSORT/ICETOOL 3
No new posts Replacing FILLER with FILLER<SeqNu... DFSORT/ICETOOL 2
No new posts Sorting Date Field DFSORT/ICETOOL 4
No new posts Concatenate 2 input datasets and give... JCL & VSAM 2
Search our Forums:

Back to Top