       IDENTIFICATION DIVISION.
       PROGRAM-ID. ediParser.
	   AUTHOR. Team 3.

       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
	  SELECT INCOMING_EDI ASSIGN TO "Team3_EDI_Data.txt"
		ORGANIZATION IS LINE SEQUENTIAL.
      
	  SELECT DONE_EDI ASSIGN TO "Team3_EDI_FINAL.txt"
 		ORGANIZATION IS LINE SEQUENTIAL.
		
	   DATA DIVISION.
       FILE SECTION.
	   
	   FD INCOMING_EDI.
	   01 EDI.
		88 END-OF-FILE VALUE HIGH-VALUES.
		02 EDI-DETAILS			 PIC x(70).
	   
	   FD DONE_EDI.
	   01 DONE_EDI_DETAILS		 PIC X(100).
	   
	   WORKING-STORAGE SECTION.   
	   01 EDI-INFO.
		05 EDI_SEG				PIC X(70).
		05 STRING-END			PIC 99.

	   01 DISPLAY-EDI_SEG		PIC X(70).
	   
	   PROCEDURE DIVISION.
       		    
		0100-BEGIN.
		
		OPEN INPUT INCOMING_EDI.
		OPEN OUTPUT DONE_EDI.
		READ INCOMING_EDI
			AT END SET END-OF-FILE TO TRUE
			END-READ.
			
		PERFORM 0200-PROCESS-EDI UNTIL END-OF-FILE.
		
		PERFORM 0300-STOP-RUN.
			   
	   0200-PROCESS-EDI.
		   
		PERFORM VARYING STRING-END FROM 70 BY -1
			UNTIL EDI-DETAILS(STRING-END : 1) NOT = SPACE
		END-PERFORM.
		
		UNSTRING EDI-DETAILS(1 : STRING-END)
			INTO EDI_SEG
		END-UNSTRING.
		
		MOVE SPACES TO DISPLAY-EDI_SEG.
		
		STRING EDI_SEG INTO DISPLAY-EDI_SEG.
		
		WRITE DONE_EDI_DETAILS FROM DISPLAY-EDI_SEG.
		WRITE DONE_EDI_DETAILS FROM " ".
		
		READ INCOMING_EDI
			AT END SET END-OF-FILE TO TRUE
		END-READ.
	   
	   0200-END.
	   
	   0300-STOP-RUN.	
		
           CLOSE INCOMING_EDI.		
           STOP RUN.
           
          END PROGRAM ediParser.