Page 1 of 1

Need optimized code

PostPosted: Thu Nov 10, 2011 1:00 pm
by vishnusrini
Hi,

Can anyone please suggest me an optimized code using EVALUATE for the below IF conditions.

IF TSM00-LEGEND-1 = ' ' OR
TSM00-LEGEND-2 = ' ' OR
TSM00-LEGEND-3 = ' ' OR
TSM00-LEGEND-4 = ' ' OR
TSM00-LEGEND-5 = ' '
IF TSM00-COUNTRY-CODE = ' '
IF TSM00-PAYMENT-CODE = ' '
IF TSM00-SUBTYPE = 'VA' OR 'FI' OR 'IM'
MOVE '18000' TO FO01-ASSET-CLASS
FO02-CURR-ASSET-CLASS
ELSE
MOVE '06301' TO FO01-ASSET-CLASS
FO02-CURR-ASSET-CLASS
END-IF
ELSE
IF TSM00-PAYMENT-CODE = 'Y'
MOVE '14000' TO FO01-ASSET-CLASS
FO02-CURR-ASSET-CLASS
ELSE
IF TSM00-PAYMENT-CODE = 'D'
MOVE '17000'
TO FO01-ASSET-CLASS
FO02-CURR-ASSET-CLASS
END-IF
END-IF
END-IF
END-IF
END-IF.

IF TSM00-LEGEND-1 = 'F' OR
TSM00-LEGEND-2 = 'F' OR
TSM00-LEGEND-3 = 'F' OR
TSM00-LEGEND-4 = 'F' OR
TSM00-LEGEND-5 = 'F'
IF TSM00-PAYMENT-CODE = ' '
IF TSM00-COUNTRY-CODE = ' '
MOVE '11001' TO FO01-ASSET-CLASS
FO02-CURR-ASSET-CLASS

ELSE
IF COUNTRY
MOVE '11000' TO FO01-ASSET-CLASS
FO02-CURR-ASSET-CLASS
END-IF
END-IF
END-IF
END-IF.

Re: Need optimized code

PostPosted: Thu Nov 10, 2011 1:12 pm
by BillyBoyo
Optimised in with respect to what? Processing speed, readability, something else?

Re: Need optimized code

PostPosted: Thu Nov 10, 2011 1:21 pm
by vishnusrini
both Processing speed and readability. Is it possible for us to use EVALUATE instead of IF condition?

Re: Need optimized code

PostPosted: Thu Nov 10, 2011 2:21 pm
by enrico-sorichetti
well... for readability start using the
code tags
when You post code

Re: Need optimized code

PostPosted: Thu Nov 10, 2011 2:39 pm
by vishnusrini
enrico-sorichetti : Sorry i dint get you.

Re: Need optimized code

PostPosted: Thu Nov 10, 2011 3:07 pm
by enrico-sorichetti
OMG...
both Processing speed and readability. Is it possible for us to use EVALUATE instead of IF condition?

since You expressed the readability concern to <help> Your colleagues to do a their job in a better/less distressing way/environment,
the same concern should be applied also for people helping You on their own time and free of charge

using the code tags areond the code You post ( like I showed You ) will improve readability for people willing to help You !

Re: Need optimized code

PostPosted: Thu Nov 10, 2011 3:28 pm
by vishnusrini
Hi,
I am not able to paste the screeshot of code, so i ahve attacehd the code screen shot for easy readability. Please check and help me..
Embedded file deleted

Re: Need optimized code

PostPosted: Thu Nov 10, 2011 3:37 pm
by enrico-sorichetti
here is what I mean by code tags

 ****** ***************************** Top of Data ******************************
 000001        IDENTIFICATION DIVISION.                                         
 000002        PROGRAM-ID     HELLO.                                           
 000003        AUTHOR.        <SOME AUTHOR>                                     
 000004        ENVIRONMENT    DIVISION.                                         
 000005        DATA           DIVISION.                                         
 000006        WORKING-STORAGE SECTION.                                         
 000007        PROCEDURE      DIVISION.                                         
 000008            DISPLAY 'Cobol said... Hello World!' .                       
 000009            GOBACK.                                                     
 ****** **************************** Bottom of Data ****************************


more readable than screen shots

Re: Need optimized code

PostPosted: Thu Nov 10, 2011 3:48 pm
by vishnusrini
Here i have attacehd the code so that it will be easy to ready..

IF  TSM00-LEGEND-1    = ' ' OR                         
    TSM00-LEGEND-2    = ' ' OR                         
    TSM00-LEGEND-3    = ' ' OR                         
    TSM00-LEGEND-4    = ' ' OR                         
    TSM00-LEGEND-5    = ' '                             
    IF  TSM00-COUNTRY-CODE = ' '                       
        IF  TSM00-PAYMENT-CODE = ' '                   
            IF  TSM00-SUBTYPE     = 'VA' OR 'FI' OR 'IM'
                MOVE '18000'  TO  FO01-ASSET-CLASS     
                                  FO02-CURR-ASSET-CLASS
            ELSE                                       
                MOVE '06301'  TO  FO01-ASSET-CLASS     
                                  FO02-CURR-ASSET-CLASS
            END-IF                                     
        ELSE                                           
            IF  TSM00-PAYMENT-CODE = 'Y'               
                MOVE '14000'  TO  FO01-ASSET-CLASS     
                                  FO02-CURR-ASSET-CLASS
            ELSE                                       
                IF  TSM00-PAYMENT-CODE = 'D'           
                    MOVE '17000'                       
                              TO  FO01-ASSET-CLASS     
                                  FO02-CURR-ASSET-CLASS
                END-IF                                 
            END-IF                                     
        END-IF                                         
    END-IF                                             
END-IF.                                               
                                                       
IF  TSM00-LEGEND-1     = 'F'  OR                       
    TSM00-LEGEND-2     = 'F'  OR                       
    TSM00-LEGEND-3     = 'F'  OR                       
    TSM00-LEGEND-4     = 'F'  OR                       
    TSM00-LEGEND-5     = 'F'                           
    IF  TSM00-PAYMENT-CODE = ' '                       
        IF  TSM00-COUNTRY-CODE = ' '                   
            MOVE '11001'     TO   FO01-ASSET-CLASS     
                                  FO02-CURR-ASSET-CLASS
                                                       
        ELSE                                           
            IF  COUNTRY                                 
                MOVE '11000' TO   FO01-ASSET-CLASS     
                                  FO02-CURR-ASSET-CLASS
            END-IF                                     
        END-IF                                         
    END-IF                                             
END-IF.

Re: Need optimized code

PostPosted: Thu Nov 10, 2011 4:22 pm
by BillyBoyo
Thank you, that is much better.

As far as machine performance is concerned, forget it. Unless you are pushing an enormous number of records through here, you'll not notice a difference either way, although I suspect the IF route would actually come out on top.

So, readability.

Don't use literals. Define items in the Data Division with the values that you need, and give them names which accurately describe those values.

Use 88-levels, again with meaningful names in terms of what that value indicates in the business sense.

If you do those first, you'll find it helps a lot. Then post that and we get to the next step.