A bit Complicate Script Required...

I have A very complex requirement

Dont know if it Possible by scripting....

I have do some parsing and replacement in COBOL Programs

It has Statements like

SORT FSORT ASCENDING KEY FS-KEY1
FS-KEY2
INPUT PROCEDURE INPUT-PROC

the Bold Ones are the Key Feilds..

If the Key feilds are in GROUP level then replace the Individulval variables Instead if Group Name...

The Lay out look like...

01 FS-REC1.
05 FS-KEY1.
10 FS-SOCT1 PIC 9(3) COMP-3.
10 FS-GER71 PIC 9(7) COMP-3.
05 FS-KEY2.
10 FS-TIER1 PIC 9(7) COMP-3.
05 AS-CLI1 PIC X(10).
05 BS-CLI1 PIC X(10).

Here FS-KEY1 and FS-KEY2 are Group feilds so
want the SORT FSORT ASCENDING KEY FS-KEY1
FS-KEY2

to become

SORT FSORT ASCENDING KEY FS-SOCT1
FS-GER71
FS-TIER1
INPUT PROCEDURE INPUT-PROC

The Key Feild can End with eithe INPUT or OUPUT or USING....

I have attached a sample Input file with Differenent Cases..

I would be great help if we can do this via a script..

#! /opt/third-party/bin/perl

my %justHash = ();

open(FILE, "<", "inp") || die "Unable to open file inp <$!>\n";

while (<FILE>) {
  chomp;
  if( /sort/i ) {
    s/.*(\d+)/\1/;
    print "SORT FSORT ASCENDING KEY ";
    my @sub_arr = split(/\|/, $justHash{$_});
    foreach(@sub_arr) {
      print "$_\n";
    }
  }
  print "$_\n";
  next if( /key(\d+)/i || /rec/i );
  if ( /FS-/ ) {
    s/PIC.*$//;
    s/^.* (\d\d)//;
    s/ //g;
    my $val = $_;
    s/.*(\d+)/\1/;
    $justHash{$_} = $justHash{$_} . "|" . $val;
  }
}

close(FILE);

exit 0

try this ! :slight_smile:

Dear Madhan

Its Fine for the Input i gave....(except that is put a number 1 2 3 after every replacement)

but And when i try this on the real COBOL Program(around 4000 lines) is jams the File...

there are some lines like

SELECT FSORT ASSIGN SORTWK1.
SELECT F60UH2 ASSIGN F60UH2E.
SELECT F60U4 ASSIGN F60U4S.

  *             FICHIER SORT                               \*
   SD  FSORT
  77  FIN-FSORT               PIC 9\(1\)  COMP-3 VALUE 0.          88  FINFSORT                             VALUE 1.
  *             SORT PROCEDURE                             \*

which i hope are corrupting the files....

Any word with SORT in it is doing some thing....

I have no clue of perl... I am very sorry ... not able to tell u what is the problem....

But to give u more information
the SORT FSORT ASCENDING KEY FS-SOCT1 is always constant...
then the key fields end with either INPUT or OUTPUT or USING...
and the KEY LAYouts.. group variables are always in 05 level ending with .

Sorry, I couldn't generalize the script with your input.

But made sure its working for the input provided.

Will it be possible to provide a snippet of the input where the script is actually corrupting the files, so that I could revisit the script ? :slight_smile:

If u could just add these inlines to the input file...

SELECT FSORT ASSIGN SORTWK1.

  • FICHIER SORT *
    SD FSORT
    77 FIN-FSORT PIC 9(1) COMP-3 VALUE 0. 88 FINFSORT VALUE 1.
  • SORT PROCEDURE *

that should give u some clue..

I cant post the whole code online....

I will give u the code which is getting changed....

        SELECT FSORT  ASSIGN SORTWK1.                                  
  *             FICHIER SORT                               \*           
   SD  FSORT                                                           
   77  FIN-FSORT               PIC 9\(1\)  COMP-3 VALUE 0.               
       88  FINFSORT                             VALUE 1.               
   77  CTR-FSORT-LUS           PIC 9\(9\)  COMP-3 VALUE ZERO.            
   77  CTR-FSORT-ECR           PIC 9\(9\)       VALUE ZERO.              
  *             SORT PROCEDURE                             \*           
       SORT FSORT ASCENDING KEY FS-KEY                                 
       IF SORT-RETURN NOT = ZERO                                       
          MOVE 'FSORT'         TO FICH                                 
       ADD 1 TO CTR-FSORT-ECR.                                         
            ADD 1 TO CTR-FSORT-ECR                                     
       RETURN FSORT                                                    
                   MOVE 1 TO FIN-FSORT.                                
       PERFORM LECT-FSORT                                              
          THRU LECT-FSORT-EXIT.                                        
          UNTIL FINF60UH2 AND FINFSORT.                                
       PERFORM LECT-FSORT                                              
          THRU LECT-FSORT-EXIT.       
   LECT-FSORT.                                                    
          MOVE 1 TO FIN-FSORT                                     
          PERFORM CUMUL-FSORT                                     
             THRU CUMUL-FSORT-EXIT                                
   LECT-FSORT-EXIT.                                               
  *    CUMUL-FSORT                                         \*      
   CUMUL-FSORT.                                                   
       ADD 1 TO CTR-FSORT-LUS.                                    
       RETURN FSORT                                               
   CUMUL-FSORT-EXIT.                                                                               

I if can just append these lines to input.... U shoule be able to see...

>cat inputfile

SELECT FSORT ASSIGN SORTWK1.

* FICHIER SORT *
SD FSORT
77 FIN-FSORT PIC 9(1) COMP-3 VALUE 0. 88 FINFSORT VALUE 1.
* SORT PROCEDURE *

AAAAAA       01  FS-REC1.
BBBBBB           05  FS-KEY1.
                     10  FS-SOCT1               PIC 9(3) COMP-3.
D50180*              10  FS-GERA1               PIC 9(3) COMP-3.
D50180               10  FS-GER71               PIC 9(7) COMP-3.
                     10  FS-TIER1               PIC 9(7) COMP-3.
                 05  AS-CLI1                      PIC X(10).
                 05  BS-CLI1                      PIC X(10).



AAAAAA       01  FS-REC2.
BBBBBB           05  FS-KEY2.
                     10  FS-SOCT2              PIC 9(3) COMP-3.
D50180*              10  FS-GERA2               PIC 9(3) COMP-3.
                     10  FS-TIER2               PIC 9(7) COMP-3.
                 05  AS-CLI2                      PIC X(10).
                 05  BS-CLI2                      PIC X(10).


AAAAAA       01  FS-REC3.
BBBBBB           05  FS-KEY3.
D50180*              10  FS-GERA3               PIC 9(3). 
                     10  FS-TIER3               PIC 9(7). 
                 05  AS-CLI2                      PIC X(10).
                 05  BS-CLI2                      PIC X(10).

SORT FSORT ASCENDING KEY FS-KEY1
                         BS-CLI1
          INPUT PROCEDURE INPUT-PROC


SORT FSORT ASCENDING KEY FS-KEY2
                         BS-CLI2
           OUTPUT PROCEDURE OUTPUT-PROC.


SORT FSORT ASCENDING KEY FS-KEY3
            USING PROCEDURE OUTPUT-PROC.
            OUTPUT PROCEDURE OUTPUT-PROC.

And now execute the script I had provided and that doesn't really seem to affect the output anyway.

If you think that the script is screwing up the output, then just paste that of the input alone in CODE tags which would be quite easier to view and the output you are expecting out of the input !

:slight_smile:

Dear madhan i am attaching the new inp file and out file geneted by running ur perl script

input file --- inp
Output file-- out

I have run ur script in the following manner...

I saved my file in file name "inp" and run ur script as

tmp.prl > out

thats right na...???

I am posting both on now...

Madhan...

As u said i have posted the Input and Output files

Can u have a look at those..

Been waithing for u from last 3 days :slight_smile:

Hi All

I was tring for Madhan but was not succesful...

I am using his perl script...

but there is somting not working it.. i have uploaded the latest input files

If any one can tell me whats to be changed in it..??

You are not supposed to bump posts.

Coming to the question.

I asked for,

sample input and the output you expect and not the output that is obtained by running the script I had posted, which I could literally see that.

Please try to post, a sample input and the output you expect. :slight_smile:

Sorry for that madhan

the only chnage i have done in ur script is

#! /usr/bin/perl instead of #! /opt/third-party/bin/perl

I wanted the out put as followes

But when i run the script as follows

with input saved in "inp" .....

and say $ script.perl > out

the out file has the following

Am i doning something wrong????

#! /opt/third-party/bin/perl

my %justHash = ();

open(FILE, "<", "inp") || die "Unable to open file inp <$!>\n";

while (<FILE>) {
  chomp;
  if( /FS-KEY/i ) {
    print "SORT FSORT ASCENDING KEY\n";
  }
  if( /sort/i ) {
    if( /^select/i ) {
      print "$_\n";
      next;
    }
    s/.*(\d+)/\1/;
    my @sub_arr = split(/\|/, $justHash{$_});
    foreach(@sub_arr) {
      s/(\d\d)(.*$)/\2/ if( /FS-/ );
      print "$_\n";
    }
  }
  print "$_\n";
  next if( /key(\d+)/i || /rec/i );
  if ( /FS-/ ) {
    s/PIC.*$//;
    s/^.* (\d\d)//;
    s/ //g;
    my $val = $_;
    s/.*(\d+)/\1/;
    $justHash{$_} = $justHash{$_} . "|" . $val;
  }
}

close(FILE);

exit 0