Thursday, 10 March 2011

* COBOL PROG to PERFORM ARITHMETIC OPERATIONS USING CONDITION-NAME CONDITION

       IDENTIFICATION DIVISION
       PROGRAM-ID. ARITHMETIC OPERATIONS.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77 OPR PIC X.
       88 ADDITION VALUE "+".
       88 SUBTRACTION VALUE "-".
       88 MULT VALUE "*".
       88 DIVI VALUE "/".
       88 EXT VALUE "E".
       88 VALID-VALUES VALUES ARE "+" "-" "*" "/" "E".
       77 A PIC S999V99.
       77 B PIC S999V99.
       77 RESULT PIC -9999.99.
       PROCEDURE DIVISION.
       INP-PARA.
            DISPLAY "ENTER TWO NUMBERS".
            ACCEPT A.
            ACCEPT B.
       MENU-PARA.                                                                                                                                                         PPPPP
            DISPLAY "MENU".
            DISPLAY "ADDITION(+)".
            DISPLAY "SUBTRACTION(-)".
            DISPLAY "MULTIPLICATION(*)".
            DISPLAY "DIVISION(/)".
            DISPLAY "EXIT(E)".
            DISPLAY "ENTER THE OPERATOR".
            ACCEPT OPR.

            IF ADDITION
            COMPUTE RESULT = A + B.
            IF SUBTRACTION
            COMPUTE RESULT = A - B.
            IF MULT
            COMPUTE RESULT = A * B.
            IF EXT GO TO ERR-PARA.
            IF DIVI
            IF B = 0
            DISPLAY "DIVISION BY ZERO" GO TO ERR-PARA
            ELSE
            COMPUTE RESULT = A / B.
            IF NOT VALID-VALUES
            DISPLAY "WRONG CHOICE" GO TO MENU-PARA.
            IF RESULT = 0
               DISPLAY 0.
            DISPLAY "RESULT= ", RESULT GO TO MENU-PARA.
       ERR-PARA.
       STOP-RUN.
.

*COBOL program to generate series which are divisible by 5 but not by 4


       IDENTIFICATION DIVISION.
       PROGRAM-ID. NUM.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77 N PIC 9(3).
       77 I PIC 9(3) VALUE 10.
       77 R PIC 9(3).
       77 Q PIC 9(3).
       PROCEDURE DIVISION.
       READ-PARA.
           DISPLAY "Enter the limit"
           ACCEPT N.
           IF N < 10
           DISPLAY "NO NUMBER DIVISIBLE BY 5 "
           GO TO EXIT-PARA.
           DISPLAY "EVEN NUMBERS DIVISIBLE BY 5".
       COMPUTE-PARA.
           IF I > N GO TO EXIT-PARA.
           DIVIDE I BY 4 GIVING Q REMAINDER R
           IF R NOT = 0
           DISPLAY I.
           ADD 10 TO I
           GO TO COMPUTE-PARA.
       EXIT-PARA.
       STOP-RUN.

*PROGRAM sum of elements of 2 groups using ADD CORRESPONDING verb

       IDENTIFICATION DIVISION
       PROGRAM-ID. ARRAY ADDITION
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 GROUPA.
           02 N1 PIC S999V99.
           02 N2 PIC S999V99.
           02 N3 PIC S999V99.
       01 GROUPB.
           02 N1 PIC S999V99.
           02 N2 PIC S999V99.
           02 N3 PIC S999V99.
       01 GROUPC.
           02 N1 PIC -ZZZ.ZZ.
           02 N2 PIC -ZZZ.9Z.
           02 N3 PIC -ZZZ.9Z.
       PROCEDURE DIVISION.
       ACC-PARA.
           DISPLAY "ENTER THE VALUES OF GROUP A".
           ACCEPT N1 OF GROUPA.
           ACCEPT N2 OF GROUPA.
           ACCEPT N3 OF GROUPA.
          

           DISPLAY "ENTER THE VALUES OF GROUP B".
           ACCEPT N1 OF GROUPB.
           ACCEPT N2 OF GROUPB.
           ACCEPT N3 OF GROUPB.
           MOVE CORR GROUPA TO GROUPC.
           DISPLAY "GROUP A          ", GROUPC.
           MOVE CORR GROUPB TO GROUPC.
           DISPLAY "GROUP B          ", GROUPC.

           ADD CORR GROUPA TO GROUPB.
           MOVE CORR GROUPB TO GROUPC.

           DISPLAY "SUM OF TWO GROUPS", GROUPC.
          
       STOP-RUN.
               

Largest Of 3 Nos using COBOL

*PROGRAM TO FIND LARGEST OF 3 NUMBERS
       IDENTIFICATION DIVISION
       PROGRAM-ID. LARGEST OF 3 NUMBERS
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77 A PIC S9999V99.
       77 B PIC S9999V99.
       77 C PIC S9999V99.
       77 K PIC ZZ99.99.
       PROCEDURE DIVISION.
       EVAL-PARA.
           DISPLAY "ENTER THE VALUES OF A B C".
           ACCEPT A.
           ACCEPT B.
           ACCEPT C.
           IF A = B AND B = C
                DISPLAY "all are equal"
           ELSE IF A > B AND A > C
                MOVE A TO K
                DISPLAY "LARGEST=", K GO TO EXT-PARA
           ELSE IF B > C
                MOVE B TO K
                DISPLAY "LARGEST=", K GO TO EXT-PARA
           ELSE
                MOVE C TO K
                DISPLAY "LARGEST=", K.
       EXT-PARA.
       STOP-RUN.

Get CSV Values in SQL

Query: DECLARE @CSVValue NVARCHAR(50)='100,101,102'                   DECLARE @eachValue NUMERIC(9,0)   while len(@CSVValue) ...