Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Issue with inputing data records

Status
Not open for further replies.

adityai

Programmer
Aug 8, 2004
10
US
I am using Fujitsu COBOL v 3.0. In the following source code, I have a field named 'INPUT-EMAIL' in the FD. If the email id entered is less than 30 characters, then I have to enter trailing spaces in order to make the program continue. The program execution just sits there waiting for the trailing spaces. How can I avoid entering trailing spaces?


IDENTIFICATION DIVISION.
PROGRAM-ID. SAMPLE1.
AUTHOR. ADITYA.
*
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT DATAFILE
ASSIGN TO DISK
ORGANIZATION IS LINE SEQUENTIAL.

DATA DIVISION.
FILE SECTION.
FD DATAFILE.
01 INPUT-RECORD.
05 PERSON-RECORD.
10 FIRSTNAME PIC X(6).
10 PIC X.
10 LASTNAME PIC X(9).
10 PIC X.
10 PHONE PIC X(10).
10 PIC X.
10 FAX PIC X(10).
10 PIC X.
10 EMAIL PIC X(30).
10 PIC X.

WORKING-STORAGE SECTION.
01 WORD-INDEX PIC 9(3).
01 INPUT-PERSON.
05 INPUT-FIRST-NAME PIC X(6).
05 PIC X VALUE SPACES.
05 INPUT-LAST-NAME PIC X(9).
05 PIC X VALUE SPACES.
05 INPUT-PHONE PIC X(10).
05 PIC X VALUE SPACES.
05 INPUT-FAX PIC X(10).
05 PIC X VALUE SPACES.
05 INPUT-EMAIL PIC X(30).
05 PIC X VALUE SPACES.



01 REQUEST-MESSAGE PIC X(42)
VALUE "DIGITAL ORGANIZER".
01 OPTION PIC 9.

*
PROCEDURE DIVISION.
DATA-INPUT SECTION.

OPEN OUTPUT DATAFILE.

DISPLAY REQUEST-MESSAGE.
DISPLAY "Enter your information:".

LOOP-INPUT.
DISPLAY "LAST-NAME: " WITH NO ADVANCING.
ACCEPT INPUT-LAST-NAME.

DISPLAY "FIRST-NAME: " WITH NO ADVANCING.
ACCEPT INPUT-FIRST-NAME.

DISPLAY "PHONE: " WITH NO ADVANCING.
ACCEPT INPUT-PHONE.

DISPLAY "FAX: " WITH NO ADVANCING.
ACCEPT INPUT-FAX.

DISPLAY "EMAIL: " WITH NO ADVANCING.
ACCEPT INPUT-EMAIL.


MOVE INPUT-PERSON TO INPUT-RECORD.
WRITE INPUT-RECORD.
* CLOSE DATAFILE.

DISPLAY "SELECT AN OPTION".
DISPLAY "1 - NEW".
DISPLAY "2 - EXIT".
ACCEPT OPTION.

IF OPTION = 1 THEN
GO TO LOOP-INPUT
ELSE
CLOSE DATAFILE.


EXIT PROGRAM.
END PROGRAM SAMPLE1.
 
[tt]
Try this;[/tt]
Code:
       IDENTIFICATION DIVISION.                       
       PROGRAM-ID. SAMPLE1.                           
       AUTHOR.     ADITYA.                            
      *                                               
       ENVIRONMENT DIVISION.                          
       CONFIGURATION SECTION.                         
       INPUT-OUTPUT SECTION.                          
       FILE-CONTROL.                                  
           SELECT DATAFILE                            
              ASSIGN TO DISK                          
              ORGANIZATION IS LINE SEQUENTIAL.        
                                                      
       DATA DIVISION.                                 
       FILE SECTION.                                  
       FD  DATAFILE.                                  
       01  INPUT-RECORD.                              
              05 PERSON-RECORD.                       
              10 FIRSTNAME         PIC X(6).          
              10                   PIC X.             
              10 LASTNAME          PIC X(9).          
              10                   PIC X.             
              10 PHONE             PIC X(10).         
              10                   PIC X.             
              10 FAX               PIC X(10).         
              10                   PIC X.             
              10 EMAIL             PIC X(30).         
              10                   PIC X.             
                                                      
       WORKING-STORAGE SECTION.                       
       01  WORD-INDEX          PIC 9(3).              
       01  INPUT-PERSON.                              
           05  INPUT-FIRST-NAME   PIC X(6).           
           05                     PIC X VALUE SPACES. 
           05  INPUT-LAST-NAME    PIC X(9).           
           05                     PIC X VALUE SPACES. 
           05  INPUT-PHONE        PIC X(10).          
           05                     PIC X VALUE SPACES. 
           05  INPUT-FAX          PIC X(10).          
           05                     PIC X VALUE SPACES. 
           05  INPUT-EMAIL        PIC X(30).          
           05                     PIC X VALUE SPACES. 
                                                      
                                                      
                                                      
       01  REQUEST-MESSAGE     PIC X(42) VALUE        
              "DIGITAL ORGANIZER".                    
       01  OPTION              PIC 9.                 
                                                      
      *                                               
       PROCEDURE DIVISION.                            
       DATA-INPUT  SECTION.                           
               OPEN OUTPUT DATAFILE.                  
                                                      
               DISPLAY REQUEST-MESSAGE UPON CONSOLE.  
               DISPLAY "Enter your information:"      
                UPON CONSOLE.                         
                                                      
        LOOP-INPUT.                                   
               DISPLAY "LAST-NAME:  " UPON CONSOLE    
                NO ADVANCING.                         
               ACCEPT  INPUT-LAST-NAME FROM CONSOLE.  
                                                      
               DISPLAY "FIRST-NAME:  " UPON CONSOLE   
                NO ADVANCING.                         
               ACCEPT  INPUT-FIRST-NAME FROM CONSOLE. 
                                                      
               DISPLAY "PHONE: " UPON CONSOLE         
                NO ADVANCING.                         
               ACCEPT INPUT-PHONE FROM CONSOLE.       
                                                      
               DISPLAY "FAX:   " UPON CONSOLE         
                NO ADVANCING.                         
               ACCEPT INPUT-FAX FROM CONSOLE.         
                                                      
               DISPLAY "EMAIL: " UPON CONSOLE         
                NO ADVANCING.                         
               ACCEPT INPUT-EMAIL FROM CONSOLE.       
                                                      
                                                      
              MOVE INPUT-PERSON TO INPUT-RECORD.      
              WRITE INPUT-RECORD.                     
                                                      
      *       CLOSE DATAFILE.                         
            DISPLAY "SELECT AN OPTION" UPON CONSOLE.  
              DISPLAY "1 - NEW" UPON CONSOLE.         
              DISPLAY "2 - EXIT" UPON CONSOLE.        
              ACCEPT OPTION FROM CONSOLE.             
                                                      
              IF OPTION = 1 THEN                      
                   GO TO LOOP-INPUT                   
              ELSE                                    
                  CLOSE DATAFILE.                     
                                                      
                                                      
           STOP RUN.                                  
      *    END PROGRAM SAMPLE1.
[tt]
Make sure the "window" option is selected. if you are using project manager, right click on the source code filename, select "main", select "window," and then rebuild the project.[/tt]




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top