Tutorialspoint

Nogak polytechnic

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-NUM1 PIC 9(9).
   01 WS-NUM2 PIC 9(9).
   01 WS-NUM3 PIC 9(5).
   01 WS-NUM4 PIC 9(6).

PROCEDURE DIVISION.
   A000-FIRST-PARA.
   MOVE 25 TO WS-NUM1 WS-NUM3.mom
   MOVE 15 TO WS-NUM2 WS-NUM4.
   
   IF WS-NUM1 > WS-NUM2 THEN
      DISPLAY 'IN LOOP 2 - IF BLOCK'
      
      IF WS-NUM3 = WS-NUM4 THEN
         DISPLAY 'IN LOOP 232- IF BLOCK'
      ELSE
         DISPLAY 'IN LOOP 2 - ELSE BLOCK'
      END-IF
      
   ELSE
      DISPLAY 'IN LOOP 1 - ELSE BLOCK'
   END-IF.
   
STOP RUN.

HB HW2FL

IDENTIFICATION DIVISION.
PROGRAM-ID. HW02FL.
DATA DIVISION.
WORKING-STORAGE SECTION.
01  EMPLOYEE-RECORD-IN.
    05 WS-EMP-PAY-YY         PIC X(02).
    05 WS-EMP-PAY-MM         PIC X(02).
    05 WS-EMP-PAY-DD         PIC X(02). 
    01 WS-FIRST-NAME         PIC X(08)   VALUE 'HELENE'.
    05 WS-LAST-NAME          PIC X(09)   VALUE 'BASSIMANA'.
PROCEDURE DIVISION.
    DISPLAY 'PAYROLL HW02FL FOR FN LN'.
    DISPLAY '--'.
    ACCEPT EMPLOYEE-RECORD-IN.
    DISPLAY 'PAY DATE: 0000'
    DISPLAY 'EMPLOYEE NAME:' 'WS-LAST-NAME' 'WS-FIRST-NAME'.

    DISPLAY '--'.
    DISPLAY 'END OF PROGRAM FOR FIRSTNAME LASTNAME'.
    STOP RUN.

Fact COBOL

identification division.
program-id. fact.
data division.
working-storage section.

77 fact pic 9(15) comp.
77 n pic 99.
77 i pic 99.
77 facts pic x(18).
77 ist pic xx.
procedure division.
move 0 to i.
move 16 to n.
move 1 to fact.

perform until i greater than n

move fact to facts
display i "!"facts
add 1 to i
multiply i by fact
end-multiply
end-perform.
stop-run.



Compile and Execute COBOL Online

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
PROCEDURE DIVISION.
DISPLAY 'Hello, Stefan'.
STOP RUN.

Compile and Execute COBOL Online

IDENTIFICATION DIVISION.
PROGRAM-ID. HW01FL.
AUTHOR.     STUDENT NAME.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-PROFESSOR-NAME       PICTURE X(08) VALUE 'Lovelace'.

01 WS-COURSE-SCORE-IN      PICTURE X(03).
01 WS-COURSE-SCORE REDEFINES
   WS-COURSE-SCORE-IN      PICTURE 9(03).

01 WS-POINTS-POSSIBLE      PICTURE 9(03) VALUE 105.
01 WS-PASSING-GRADE        PICTURE 9(02) VALUE 70.
01 WS-POINTS-ABOVE-PASSING PICTURE 9(02) VALUE 0.

01 WS-POINT-FEE            PIC     9(02)V99 VALUE 3.00.
01 WS-DOLLARS-EARNED       PIC     9(02)v99 VALUE 0.
01 WS-FORMATTED-DOLLARS    PIC     $$9.00.

PROCEDURE DIVISION.
    DISPLAY 'Hello, Professor 'WS-PROFESSOR-NAME' Here'.
    ACCEPT WS-COURSE-SCORE-IN.
    DISPLAY "SCORE ENTERED: " WS-COURSE-SCORE-IN.
    IF WS-COURSE-SCORE-IN IS NUMERIC AND 
       WS-COURSE-SCORE >= 0 AND WS-COURSE-SCORE <= 100
      IF WS-COURSE-SCORE > 69 
        DISPLAY 'You Passed the Course with a score of: '
                 WS-COURSE-SCORE
        COMPUTE WS-POINTS-ABOVE-PASSING =
                WS-COURSE-SCORE - WS-PASSING-GRADE 
        DISPLAY 'You have passed by ' WS-POINTS-ABOVE-PASSING ' points'  
        COMPUTE WS-DOLLARS-EARNED = WS-POINTS-ABOVE-PASSING * WS-POINT-FEE
        MOVE WS-DOLLARS-EARNED TO WS-FORMATTED-DOLLARS
        DISPLAY "You earned a " WS-FORMATTED-DOLLARS " BONUS"
      ELSE 
        DISPLAY 'Oh no...Your score of 'WS-COURSE-SCORE' did not pass'
        DISPLAY 'A score below 'WS-PASSING-GRADE' is a failing grade'
    ELSE
      DISPLAY "The Score of " WS-COURSE-SCORE " entered is not correct"
      DISPLAY "Score entered " WS-COURSE-SCORE-IN " is not correct"
      DISPLAY "Enter a numberic score from 000 to 100, including"
              " leading zeroes".
    
    STOP RUN.

Compile and Execute COBOL Online

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-DESCRIPTION.
   05 WS-NUM.
   10 WS-NUM1 PIC 9(2) VALUE 20.
   10 WS-NUM2 PIC 9(2) VALUE 56.
   05 WS-CHAR.
   10 WS-CHAR1 PIC X(2) VALUE 'AA'.
   10 WS-CHAR2 PIC X(2) VALUE 'BB'.
   10 WS-RENAME  RENAMES WS-NUM2 THRU WS-CHAR2 PIC X(06).

PROCEDURE DIVISION.
   DISPLAY "WS-RENAME : " WS-RENAME.
   
STOP RUN.

Compile and Execute COBOL Online

      ***************************************************
      * COBOL Stored Procedure SAMPLE.COBSAMP
      * @param Action
      * @param City
      * @param Country
      * @param Response
      ***************************************************
       IDENTIFICATION DIVISION.
       PROGRAM-ID. COBSAMP.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
            EXEC SQL INCLUDE SQLCA END-EXEC.
       01 Sqlcode-Pic PIC +++999 USAGE DISPLAY.
       LINKAGE SECTION.
       01 Action.
            49 VAR-LEN  PIC S9(4)  USAGE BINARY.
            49 VAR-TEXT PIC X9(8)  USAGE DISPLAY.
       01 City.
            49 VAR-LEN  PIC S9(4)  USAGE BINARY.
            49 VAR-TEXT PIC X9(32) USAGE DISPLAY.
       01 Country.
            49 VAR-LEN  PIC S9(4)  USAGE BINARY.
            49 VAR-TEXT PIC X9(32) USAGE DISPLAY.
       01 Response.
            49 VAR-LEN  PIC S9(4)  USAGE BINARY.
            49 VAR-TEXT PIC X9(80) USAGE DISPLAY.
       PROCEDURE DIVISION USING
            Action
            City
            Country
            Response.
            Move Function Upper-case(VAR-TEXT of Action)
              to VAR-TEXT of Action
            Evaluate VAR-TEXT of Action(1:VAR-LEN of Action)
              When 'S'
              When 'SELECT'
                Evaluate true also true
                  When VAR-LEN of City = 0 also VAR-LEN of Country = 0
                    EXEC SQL
                      DECLARE C1 CURSOR WITH RETURN WITH HOLD FOR
                        SELECT * FROM SAMPLE.CITYTABLE
                    END-EXEC
                    EXEC SQL
                      OPEN C1
                    END-EXEC
                  When VAR-LEN of City = 0 also VAR-LEN of Country > 0
                    EXEC SQL
                      DECLARE C2 CURSOR WITH RETURN WITH HOLD FOR
                        SELECT * FROM SAMPLE.CITYTABLE
                          WHERE COUNTRY=:COUNTRY
                    END-EXEC
                    EXEC SQL
                      OPEN C2
                    END-EXEC
                  When VAR-LEN of City > 0 also VAR-LEN of Country = 0
                    EXEC SQL
                      DECLARE C3 CURSOR WITH RETURN WITH HOLD FOR
                        SELECT * FROM SAMPLE.CITYTABLE
                          WHERE CITY=:CITY
                    END-EXEC
                    EXEC SQL
                      OPEN C3
                    END-EXEC
                  When Other
                    EXEC SQL
                      DECLARE C4 CURSOR WITH RETURN WITH HOLD FOR
                        SELECT * FROM SAMPLE.CITYTABLE
                          WHERE CITY=:CITY AND COUNTRY=:COUNTRY
                    END-EXEC
                    EXEC SQL
                      OPEN C4
                    END-EXEC
                End-Evaluate
                If Sqlcode = 0 then
                  String 'Select successful'
                    delimited by Size into VAR-TEXT of Response
                Else
                  Move SQLCode to SQLCode-Pic
                  String 'Select unsuccessful: Sqlcode ' Sqlcode-Pic
                    delimited by Size into VAR-TEXT of Response
                End-If
              When 'I'
              When 'INSERT'
                Evaluate true also true
                  When VAR-LEN of City = 0 also VAR-LEN of Country = 0
                    String 'Insert unsuccessful: '
                           'City and Country not specified'
                      delimited by Size into VAR-TEXT of Response
                  When VAR-LEN of City = 0 also VAR-LEN of Country > 0
                    String 'Insert unsuccessful: City not specified'
                      delimited by Size into VAR-TEXT of Response
                  When VAR-LEN of City > 0 also VAR-LEN of Country = 0
                    String 'Insert unsuccessful: Country not specified'
                      delimited by Size into VAR-TEXT of Response
                  When Other
                    EXEC SQL
                      INSERT INTO SAMPLE.CITYTABLE
                        (CITY, COUNTRY) VALUES (:CITY, :COUNTRY)
                    END-EXEC
                    If Sqlcode = 0 then
                      String 'Insert successful'
                        delimited by Size into VAR-TEXT of Response
                    Else
                      Move SQLCode to SQLCode-Pic
                      String 'Insert unsuccessful: Sqlcode ' Sqlcode-Pic
                        delimited by Size into VAR-TEXT of Response
                    End-If
                End-Evaluate
              When 'D'
              When 'DELETE'
                Evaluate true also true
                  When VAR-LEN of City = 0 also VAR-LEN of Country = 0
                    String 'Delete unsuccessful: '
                           'City and Country not specified'
                      delimited by Size into VAR-TEXT of Response
                  When VAR-LEN of City = 0 also VAR-LEN of Country > 0
                    String 'Delete unsuccessful: City not specified'
                      delimited by Size into VAR-TEXT of Response
                  When VAR-LEN of City > 0 also VAR-LEN of Country = 0
                    String 'Delete unsuccessful: Country not specified'
                      delimited by Size into VAR-TEXT of Response
                  When Other
                    EXEC SQL
                      DELETE FROM SAMPLE.CITYTABLE
                        WHERE CITY=:CITY AND COUNTRY=:COUNTRY
                    END-EXEC
                    If Sqlcode = 0 then
                      String 'Delete successful'
                        delimited by Size into VAR-TEXT of Response
                    Else
                      Move SQLCode to SQLCode-Pic
                      String 'Delete unsuccessful: Sqlcode ' Sqlcode-Pic
                        delimited by Size into VAR-TEXT of Response
                    End-If
                End-Evaluate
              When Other
                String 'Action "'
                       VAR-TEXT of Action(1:VAR-LEN of Action)
                       '" not supported'
                  delimited by Size into VAR-TEXT of Response
            End-Evaluate.
            Inspect VAR-TEXT of Response tallying VAR-LEN of Response
              for characters before initial x'00'
            GOBACK.

working number 12


IDENTIFICATION DIVISION.
PROGRAM-ID.     HW12FL.
DATA DIVISION.
WORKING-STORAGE SECTION.
01  WS-INPUT-RECORD.
    05 WS-INPUT-NAME           PIC X(10).
    05 WS-INPUT-HOURS          PIC 99V99.
    05 WS-INPUT-PAYRATE        PIC 99V99.
    
01  WS-NUMBER-LINE.
    05 FIILER                  PIC X(40) VALUE
       '----+----1----+----2----+----3----+----4'.
    05 FIILER                  PIC X(40) VALUE
       '----+----5----+----6----+----7----+----8'.   
     
01  REPORT-TITLE.
    05 FILLER                  PIC X(33) VALUE SPACES.
    05 filler                  PIC X(14) VALUE 'PAYROLL REPORT'.
    05 FILLER                  PIC X(33) VALUE SPACES.
    
01  REPORT-DATE-HEADING.
    05 FILLER                  PIC X(33) VALUE SPACES.
    05 filler                  PIC X(6) VALUE 'AS OF '.
    05 CENTERED-DATE           PIC X(8).
    05 FILLER                  PIC X(33) VALUE SPACES.
       
    
01  REPORT-CREATOR-HEADING.
    05 FILLER                  PIC X(27) VALUE SPACES.
    05 filler                  PIC X(25) VALUE 'PREPARED BY JACOB STEINER'.
    05 FILLER                  PIC X(28) VALUE SPACES.
    
01  REPORT-DETAIL.
    05 FILLER                  PIC X(21) VALUE SPACES.
    05 DETAIL-NAME             PIC X(10).
    05 DETAIL-RATE             PIC ZZ.99.
    05 FILLER                  PIC X(3) VALUE SPACES.
    05 DETAIL-HOURS            PIC ZZ.99.
    05 FILLER                  PIC X(3) VALUE SPACES.
    05 DETAIL-GROSS            PIC $Z,ZZ9.99.
    

01  REPORT-SUMMARY.
    05 FILLER                  PIC X(21) VALUE SPACES.
    05 REPORT-TOTALS           PIC X(26) VALUE 'TOTALS'.
    05 REPORT-GROSS            PIC $Z,ZZ9.99.
    

01  BLANK-LINE                 PIC X(80) VALUE SPACES.

01  UNDERSCORE-LINE            PIC X(80) VALUE ALL '_'.

01  WS-RUN-DATE.
    05 WS-RUN-YY               PIC X(02).
    05 WS-RUN-MM               PIC X(02). 
    05 WS-RUN-DD               PIC X(02).
    
01  WS-FORMATTED-DATE.
    05 WS-FORMATTED-DATE-MM    PIC X(02).
    05 FILLER                  PIC X(01) VALUE '/'.
    05 WS-FORMATTED-DATE-DD    PIC X(02).
    05 FILLER                  PIC X(01) VALUE '/'.
    05 WS-FORMATTED-DATE-YY    PIC X(02).
    
01  WS-TOTAL-GROSS             PIC 9(05)V99 VALUE 0.

01  WS-CURRENT-GROSS           PIC 9(05)V99.
01  WS-CURRENT-HOURS           PIC 9(04).
01  WS-CURRENT-RATE            PIC 9(04).
PROCEDURE DIVISION.
    DISPLAY WS-NUMBER-LINE.
    DISPLAY REPORT-TITLE.
    
    ACCEPT  WS-RUN-DATE FROM DATE.
    
    MOVE WS-RUN-DD  TO  WS-FORMATTED-DATE-DD.
    MOVE WS-RUN-MM  TO  WS-FORMATTED-DATE-MM.
    MOVE WS-RUN-YY  TO  WS-FORMATTED-DATE-YY.
    MOVE WS-FORMATTED-DATE TO CENTERED-DATE.
    
    DISPLAY REPORT-DATE-HEADING.
    
    DISPLAY REPORT-CREATOR-HEADING.
    DISPLAY BLANK-LINE.
    display "                     NAME       PAY    HOURLY     GROSS "
    displaY "                                RATE    RATE       PAY"
    ACCEPT  WS-INPUT-RECORD.
    
    MOVE WS-INPUT-NAME TO DETAIL-NAME.
    MOVE WS-INPUT-HOURS TO DETAIL-HOURS.
    MOVE WS-INPUT-PAYRATE TO DETAIL-RATE.
    COMPUTE WS-CURRENT-GROSS = WS-INPUT-HOURS * WS-INPUT-PAYRATE.
    COMPUTE WS-TOTAL-GROSS = WS-TOTAL-GROSS + WS-CURRENT-GROSS.
    MOVE WS-CURRENT-GROSS TO DETAIL-GROSS.
    
    DISPLAY BLANK-LINE.
    
    DISPLAY REPORT-DETAIL.
    
    
    
   ACCEPT  WS-INPUT-RECORD.
    
    MOVE WS-INPUT-NAME TO DETAIL-NAME.
    MOVE WS-INPUT-HOURS TO DETAIL-HOURS.
    MOVE WS-INPUT-PAYRATE TO DETAIL-RATE.
    COMPUTE WS-CURRENT-GROSS = WS-INPUT-HOURS * WS-INPUT-PAYRATE.
    COMPUTE WS-TOTAL-GROSS = WS-TOTAL-GROSS + WS-CURRENT-GROSS.
    MOVE WS-CURRENT-GROSS TO DETAIL-GROSS.
    
    DISPLAY BLANK-LINE.
    
    DISPLAY REPORT-DETAIL.
    
    
    ACCEPT  WS-INPUT-RECORD.
    
    MOVE WS-INPUT-NAME TO DETAIL-NAME.
    MOVE WS-INPUT-HOURS TO DETAIL-HOURS.
    MOVE WS-INPUT-PAYRATE TO DETAIL-RATE.
    COMPUTE WS-CURRENT-GROSS = WS-INPUT-HOURS * WS-INPUT-PAYRATE.
    COMPUTE WS-TOTAL-GROSS = WS-TOTAL-GROSS + WS-CURRENT-GROSS.
    MOVE WS-CURRENT-GROSS TO DETAIL-GROSS.
    
    DISPLAY BLANK-LINE.

    MOVE WS-TOTAL-GROSS TO REPORT-GROSS.
    DISPLAY REPORT-DETAIL.
    
    DISPLAY BLANK-LINE.
    DISPLAY REPORT-SUMMARY.
    DISPLAY BLANK-LINE.
    DISPLAY "                    * * *  E N D  O F  R E P O R T  * * * "
    Display WS-NUMBER-LINE.
    

Spencer Youngblood HW01SY

IDENTIFICATION DIVISION.
PROGRAM-ID.    HW01SY.
AUTHOR.        SPENCER YOUNGBLOOD.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-PROFESSOR-NAME       PICTURE X(10) VALUE 'Youngblood'.
01 WS-COURSE-SCORE         PICTURE 9(03) VALUE 68.
01 WS-PASSING-SCORE        PICTURE 9(02) VALUE 70.
01 WS-POINTS-UNDER-PASSING PICTURE 9(02) VALUE 0.
PROCEDURE DIVISION.
    DISPLAY 'Hello, Professor ' WS-PROFESSOR-NAME ' here!'
    ACCEPT WS-COURSE-SCORE.
    IF WS-COURSE-SCORE >= WS-PASSING-SCORE
      DISPLAY 'You passed the course with a score of: '
              WS-COURSE-SCORE
      DISPLAY 'Good job!'
    ELSE 
      DISPLAY 'Uh-oh, your score of ' WS-COURSE-SCORE ' did not pass.'
      DISPLAY 'A score below ' WS-PASSING-SCORE ' is a failing grade.'
      COMPUTE WS-POINTS-UNDER-PASSING = 
              WS-PASSING-SCORE - WS-COURSE-SCORE
      DISPLAY 'You needed ' WS-POINTS-UNDER-PASSING ' more points to pass.' 
      DISPLAY 'Please insert 3 more credits and try again...'
    STOP RUN.

Ejemplo

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
PROCEDURE DIVISION.
DISPLAY 'Hello, world'.
STOP RUN.

1 2 3 4 5 6 7 ... 67 Next
Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.