Need optimized code



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Need optimized code

Postby vishnusrini » Thu Nov 10, 2011 1:00 pm

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.
vishnusrini
 
Posts: 32
Joined: Wed Jul 07, 2010 2:55 pm
Location: India,bangalore
Has thanked: 0 time
Been thanked: 0 time

Re: Need optimized code

Postby BillyBoyo » Thu Nov 10, 2011 1:12 pm

Optimised in with respect to what? Processing speed, readability, something else?
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Need optimized code

Postby vishnusrini » Thu Nov 10, 2011 1:21 pm

both Processing speed and readability. Is it possible for us to use EVALUATE instead of IF condition?
vishnusrini
 
Posts: 32
Joined: Wed Jul 07, 2010 2:55 pm
Location: India,bangalore
Has thanked: 0 time
Been thanked: 0 time

Re: Need optimized code

Postby enrico-sorichetti » Thu Nov 10, 2011 2:21 pm

well... for readability start using the
code tags
when You post code
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Need optimized code

Postby vishnusrini » Thu Nov 10, 2011 2:39 pm

enrico-sorichetti : Sorry i dint get you.
vishnusrini
 
Posts: 32
Joined: Wed Jul 07, 2010 2:55 pm
Location: India,bangalore
Has thanked: 0 time
Been thanked: 0 time

Re: Need optimized code

Postby enrico-sorichetti » Thu Nov 10, 2011 3:07 pm

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 !
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Need optimized code

Postby vishnusrini » Thu Nov 10, 2011 3:28 pm

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
vishnusrini
 
Posts: 32
Joined: Wed Jul 07, 2010 2:55 pm
Location: India,bangalore
Has thanked: 0 time
Been thanked: 0 time

Re: Need optimized code

Postby enrico-sorichetti » Thu Nov 10, 2011 3:37 pm

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
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Need optimized code

Postby vishnusrini » Thu Nov 10, 2011 3:48 pm

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.
vishnusrini
 
Posts: 32
Joined: Wed Jul 07, 2010 2:55 pm
Location: India,bangalore
Has thanked: 0 time
Been thanked: 0 time

Re: Need optimized code

Postby BillyBoyo » Thu Nov 10, 2011 4:22 pm

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.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post