Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7882863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:23:09+00:00 2026-06-03T04:23:09+00:00

Hello I am total beginner in cobol and needing some homework help. I am

  • 0

Hello I am total beginner in cobol and needing some homework help. I am trying to write a program that prints address labels on the ouput. But in the output there has to be a header, page number, and date. I have successfully got the program to print the addresses in label format but cannot seem to get the heading line (with the page and date) to show up above it. With my program the way it is there is an error code stating that I have the wrong access mode for the data file. I am unsure what this means. Here is my program. I got rid of the date part just to try and get the heading line in above the addresses. *EDIT: I have added the open and close for “print header out” but now it gives me the error code “file locked” Can anyone shed some light on this.

   ENVIRONMENT DIVISION.
   INPUT-OUTPUT SECTION.
   FILE-CONTROL.

   SELECT LABEL-FILE-IN
   ASSIGN TO 'C0603.DAT'
   ORGANIZATION IS LINE SEQUENTIAL.

   SELECT LABEL-FILE-OUT
   ASSIGN TO 'C0603.RPT'
   ORGANIZATION IS LINE SEQUENTIAL.

   SELECT PRINT-HEADER-OUT
   ASSIGN TO 'C0603.RPT'
   ORGANIZATION IS LINE SEQUENTIAL.

   DATA DIVISION.
   FILE SECTION.


   FD LABEL-FILE-IN.
   01 LABEL-RECORD-IN.
   05 CUST-NAME-IN PIC X(20).
   05 ADDRESS-IN PIC X(20).
   05 CITY-STATE-ZIP-IN PIC X(20).

   FD LABEL-FILE-OUT.
   01 LABEL-RECORD-OUT.
   05 PRINT-LABEL-OUT PIC X(20).

   FD  PRINT-HEADER-OUT.
   01  REPORT-OUT                  PIC X(80).


             WORKING-STORAGE SECTION.
   01  ARE-THERE-MORE-RECORDS PIC X(3) VALUE 'YES'.

   01  HEADING-LINE1.
       05                          PIC X(40) VALUE SPACES.
       05                          PIC X(12) VALUE
           "MAILING LIST".

   01  DATE-WS.
       05 MONTH-WS                 PIC XX.
       05 YEAR-WS                  PIC XX.

   01  DATE-WS-OUT.
       05                           PIC X(45) VALUE SPACES.
       05  MONTH-WS-OUT              PIC XX.
       05                          VALUE "/".
       05  YEAR-WS-OUT               PIC XX.


             PROCEDURE DIVISION.

   000-MAIN-MODULE.
       PERFORM 100-INITIALIZATION-MODULE.
       PERFORM 200-PROCESS-ONE-RECORD
           UNTIL ARE-THERE-MORE-RECORDS = "NO ".
       PERFORM 900-TERMINATION-MODULE.
       STOP RUN.

   100-INITIALIZATION-MODULE.
       OPEN OUTPUT PRINT-HEADER-OUT
       OPEN INPUT LABEL-FILE-IN
       OPEN OUTPUT LABEL-FILE-OUT
       ACCEPT DATE-WS FROM DATE.
       MOVE MONTH-WS TO MONTH-WS-OUT.
       MOVE YEAR-WS TO YEAR-WS-OUT.
       PERFORM 600-READ-MODULE.
       PERFORM 300-TOP-OF-PAGE-MODULE.

   200-PROCESS-ONE-RECORD.
       MOVE SPACES TO PRINT-LABEL-OUT

       MOVE CUST-NAME-IN TO PRINT-LABEL-OUT
       WRITE LABEL-RECORD-OUT

       MOVE ADDRESS-IN TO PRINT-LABEL-OUT
       WRITE LABEL-RECORD-OUT

       MOVE CITY-STATE-ZIP-IN TO PRINT-LABEL-OUT
       WRITE LABEL-RECORD-OUT


   PERFORM 600-READ-MODULE.

   300-TOP-OF-PAGE-MODULE.
       MOVE HEADING-LINE1 TO REPORT-OUT.
       WRITE REPORT-OUT AFTER ADVANCING 9 LINES.
       MOVE DATE-WS-OUT TO REPORT-OUT.
       WRITE REPORT-OUT AFTER ADVANCING 1 LINES.


   600-READ-MODULE.
       READ LABEL-FILE-IN
            AT END MOVE "NO " TO ARE-THERE-MORE-RECORDS
       END-READ.

   900-TERMINATION-MODULE.
       CLOSE PRINT-HEADER-OUT.
       CLOSE LABEL-FILE-IN.
       CLOSE LABEL-FILE-OUT.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T04:23:10+00:00Added an answer on June 3, 2026 at 4:23 am

    I think the problem you are having is that both LABEL-FILE and HEADER-FILE point to the
    same physically file (‘C0603.RPT’). You can do this, but only one of them may be open at a time. This is
    the source of the “file locked” message when you try to open it a second time under a different
    name.

    The typical way of doing this is to open one file but have multiple record definitions for
    writing to it.

    Drop the:

        SELECT PRINT-HEADER-OUT
        ASSIGN TO 'C0603.RPT'
        ORGANIZATION IS LINE SEQUENTIAL.
    

    and change the FD’s for LABEL-FILE-OUT to include the Header record…

        FD LABEL-FILE-OUT.
        01.
           05 LABEL-BUFFER              PIC X(80).
           05 LABEL-RECORD-OUT REDEFINES LABEL-BUFFER.
              10 PRINT-LABEL-OUT PIC X(20).
              10                 PIC X(60).
           05 PRINT-HEADER-OUT REDEFINES LABEL-BUFFER.
              10 REPORT-OUT      PIC X(80).
    

    There are other ways of doing this, but the basic idea is to have an output buffer that is the
    at least as big as the largest ouput record andREDEFINE it for multiple usages (LABEL or HEADER).

    When writing a label line or header line just use WRITE LABEL-BUFFER and then move SPACES to it
    after each write to ensure it gets properly initialized before re-populating any of the subordiante
    data items.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

**Hello, I'm trying to create an archiver in java. This means that I am
Hello I have this code I am trying to fix, the issue is that
hello i'm trying to parse some packets, and when using struct ip i get
Hello I'm trying to dynamically generate some inputs for my form, but it's not
Hello friends i am a total beginner in c#. I want to read numbers
hello i'm beginner for programming I've got a homework. googled it but couldnt find
Hello i have created a javascript function that recaculates the grand total of an
Hello I'm trying to write a CUDA kernel to perform the following piece of
Hello and thanks in advance for the help! I am trying to generate a
Hello I hope someone can help me. I need to know how to write

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.