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 7191825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:48:40+00:00 2026-05-28T19:48:40+00:00

I’ll start by admitting this is for my homework and I don’t expect anything

  • 0

I’ll start by admitting this is for my homework and I don’t expect anything specific just a tip perhaps. The input file is just one 30 byte field that contains names. The output file is two fields 30 bytes each. I’ll list the code to show what I mean by this. The program needs to read the input file putting the names into an array and then print them to the two fields in the output file. It would be simple enough if the out put file was like this:

name 1             name 2
name 3             name 4
etc...

but it’s supposed to be:

name 1             name 55
name 2             name 56
....
name 54            name 108

I’m not quite understanding how I can code the program to do this without having 54 lines of code (1 for each line in the output). Well here’s the code I have so far:

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

SELECT NAMELIST-FILE-IN                                  
    ASSIGN TO 'NAMELIST.SEQ'                             
    ORGANIZATION IS LINE SEQUENTIAL.                     

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

 DATA DIVISION.                                               
 FILE SECTION.                                                

 FD NAMELIST-FILE-IN.                                         
    01 NAME-IN                       PIC X(30).                  

 FD NAMELIST-FILE-OUT.                                        
    01 NAME-OUT                      PIC X(60).                  

WORKING-STORAGE SECTION.                                     
    01 ARE-THERE-MORE-RECORDS        PIC X(3)  VALUE 'YES'.      
    01 PAGE-CTR                      PIC 99    VALUE ZERO.       
    01 SUB                           PIC 999   VALUE 1.          
    01 LEFT-NAME                     PIC 99    VALUE 54.         
    01 RIGHT-NAME                    PIC 9(3)  VALUE 108.        

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

01 HEADING-LINE.                                             
    05                           PIC X(15) VALUE SPACES.     
    05                           PIC X(20)                   
        VALUE 'NAME LIST REPORT'.                            
    05 HL-DATE.                                              
        10  DAY-HL               PIC XX.                     
        10                       PIC X     VALUE '/'.        
        10  MONTH-HL             PIC XX.                     
        10                       PIC X     VALUE '/'.        
        10  YEAR-HL              PIC XX.                     
    05                           PIC X(3)  VALUE SPACES.     
    05                           PIC X(5)  VALUE 'PAGE'.     
    05  PAGE-NUMBER-HL           PIC Z9    VALUE 1.          

01 DETAIL-LINE.                                              
    05 NAME-LEFT                 PIC X(30).                  
    05 NAME-RIGHT                PIC X(30).                  

01 NAME-ARRAY.                                               
    05 NAME-X   OCCURS 108       PIC X(30).                  

PROCEDURE DIVISION.                                          
100-MAIN.                                                    
    OPEN INPUT NAMELIST-FILE-IN                              
    OPEN OUTPUT NAMELIST-FILE-OUT                            

    ACCEPT WS-DATE FROM DATE.                                
        MOVE RUN-MONTH TO MONTH-HL                           
        MOVE RUN-DAY TO DAY-HL                               
        MOVE RUN-YEAR TO YEAR-HL                             

    PERFORM 200-ACCEPT-INPUT                                 


    CLOSE NAMELIST-FILE-IN                                   
    CLOSE NAMELIST-FILE-OUT                                  
    STOP RUN.                                                

200-ACCEPT-INPUT.                                            
    PERFORM UNTIL SUB > 108                                  
        READ NAMELIST-FILE-IN                                
        MOVE NAME-IN TO NAME-X (SUB)                         
        ADD 1 TO SUB                                         
    END-PERFORM                                              

    PERFORM 300-PRINT-ONE-PAGE.                              

300-PRINT-ONE-PAGE.                                          
    WRITE NAME-OUT FROM HEADING-LINE                         
        AFTER ADVANCING PAGE                                 
    ADD 1 TO PAGE-CTR                                        

Here’s the final code for this program if anyone is interested in seeing it.

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

    SELECT NAMELIST-FILE-IN                                      
        ASSIGN TO 'NAMELIST.SEQ'                                 
        ORGANIZATION IS LINE SEQUENTIAL.                         

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

DATA DIVISION.                                                   
FILE SECTION.                                                    

FD NAMELIST-FILE-IN.                                             
01 NAME-IN                       PIC X(30).                      

FD NAMELIST-FILE-OUT.                                            
01 NAME-OUT                      PIC X(80).                      

WORKING-STORAGE SECTION.                                         
01 ARE-THERE-MORE-RECORDS        PIC X(3)  VALUE 'YES'.          
01 PAGE-CTR                      PIC 99    VALUE ZERO.           
01 SUB                           PIC 999.                        
01 SUB2                          PIC 999.                        
01 LEFT-NAME                     PIC 99    VALUE 54.             
01 RIGHT-NAME                    PIC 9(3)  VALUE 108.            

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

01 HEADING-LINE.                                                 
    05                           PIC X(26) VALUE SPACES.         
    05                           PIC X(35)                       
        VALUE 'NAME LIST REPORT'.                                
    05 HL-DATE.                                                  
        10  DAY-HL               PIC XX.                         
        10                       PIC X     VALUE '/'.            
        10  MONTH-HL             PIC XX.                         
        10                       PIC X     VALUE '/'.            
        10  YEAR-HL              PIC XX.                         
    05                           PIC X(3)  VALUE SPACES.         
    05                           PIC X(5)  VALUE 'PAGE'.         
    05  PAGE-NUMBER-HL           PIC Z9.                         

01 DETAIL-LINE.                                                  
    05 NAME-LEFT                 PIC X(40).                      
    05 NAME-RIGHT                PIC X(40).                      

01 NAME-ARRAY.                                                   
    05 NAME-X   OCCURS 108       PIC X(30).                      

PROCEDURE DIVISION.                                              
100-MAIN.                                                        
    OPEN INPUT NAMELIST-FILE-IN                                  
    OPEN OUTPUT NAMELIST-FILE-OUT                                

    ACCEPT WS-DATE FROM DATE.                                    
        MOVE RUN-MONTH TO MONTH-HL                               
        MOVE RUN-DAY TO DAY-HL                                   
        MOVE RUN-YEAR TO YEAR-HL                                 

    PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO'                  
        PERFORM 200-ACCEPT-INPUT                                 
    END-PERFORM                                                  

    CLOSE NAMELIST-FILE-IN                                       
    CLOSE NAMELIST-FILE-OUT                                      
    STOP RUN.                                                    

200-ACCEPT-INPUT.                                                
    INITIALIZE NAME-ARRAY                                        
    MOVE 1 TO SUB                                                

    PERFORM UNTIL SUB > 108 OR ARE-THERE-MORE-RECORDS = 'NO'     
        READ NAMELIST-FILE-IN                                    
            AT END                                               
                MOVE 'NO' TO ARE-THERE-MORE-RECORDS              
                MOVE SPACES TO NAME-IN                           
        END-READ                                                 
        MOVE NAME-IN TO NAME-X (SUB)                             
        ADD 1 TO SUB                                             

    END-PERFORM                                                  

    PERFORM 300-PRINT-ONE-PAGE.                                  

300-PRINT-ONE-PAGE.                                              
    ADD 1 TO PAGE-CTR                                            
    MOVE PAGE-CTR TO PAGE-NUMBER-HL                              
    WRITE NAME-OUT FROM HEADING-LINE                             
        AFTER ADVANCING PAGE                                     

    MOVE SPACES TO DETAIL-LINE                                   
    WRITE NAME-OUT FROM DETAIL-LINE                              
        AFTER ADVANCING 1                                        

    PERFORM VARYING SUB FROM 1 BY 1 UNTIL SUB > 54               
        MOVE NAME-X (SUB) TO NAME-LEFT                           
        COMPUTE SUB2 = SUB + 54                                  
        MOVE NAME-X (SUB2) TO NAME-RIGHT                         
        WRITE NAME-OUT FROM DETAIL-LINE                          
            AFTER ADVANCING 1                                    
    END-PERFORM.                                                 
  • 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-05-28T19:48:41+00:00Added an answer on May 28, 2026 at 7:48 pm

    I must apologize, I cannot think of a way to guide you without giving away the answer. I guess this is a spoiler alert.

    One possible method you could use would be to add a variable SUB2 to Working-Storage and…

    Perform Varying SUB From 1 By 1 Until SUB > 54
      Move NAME-X(SUB) to NAME-LEFT
      Compute SUB2 = SUB + 54
      MOVE NAME-X(SUB2) to NAME-RIGHT
      Write NAME-OUT from DETAIL-LINE After Advancing 1 Line
    End-Perform
    

    This is kind of kludgy and ties you to an array of 108 elements. You could use a record counter that you increment by 1 for each record read and then compute the values I show hardcoded in the sample above (54 is simply half of 108).

    I don’t show the page break logic, so perhaps I didn’t give the whole show away.

    I hope this helps you.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Specifically, suppose I start with the string string =hello \'i am \' me And
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported

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.