Merge Statement (COBOL) - cobol

I was working on a program that needed to use a merge statement to put two files together and sort them. Of course though I would not be here if I didn't have a problem. When I run my program I have to do a little work afterward to add to the output. When it it goes to perform that paragraph it gives an error that says "Merge File out of sequences ORDER-FILE-SOR". Here is my code:
100-MAIN.
MERGE ORDERS-FILE-SORT
ON ASCENDING KEY REQUEST-DATE-S
ON ASCENDING KEY CUST-NUMBER-S
ON ASCENDING KEY CUST-ORDER-NUMBER-S
ON ASCENDING KEY PART-NUMBER-S
USING ORDERS-FILE-PRIOR-IN
ORDERS-FILE-NEW-IN
OUTPUT PROCEDURE 200-FILE-START
STOP RUN.
200-FILE-START.
OPEN OUTPUT ORDERS-FILE-OUT
ACCEPT WS-DATE FROM DATE
MOVE RUN-MONTH TO MONTH-1
MOVE RUN-DAY TO DAY-1
MOVE RUN-YEAR TO YEAR-1
PERFORM 300-NEXT-PAGE
PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO '
RETURN ORDERS-FILE-SORT
AT END
MOVE 'NO ' TO ARE-THERE-MORE-RECORDS
NOT AT END
PERFORM 400-PROCESS-FILE
END-RETURN
END-PERFORM.
CLOSE ORDERS-FILE-OUT.
The output it does show is the heading line and it seems to stop at the "RETURN ORDERS-FILE-SORT" line.
Any help would be greatly appreciated as I feel the rest of the program will run just fine, but I can't check it till this is fixed.

The MERGE verb combines two or more identically sequenced files. To have it work, you must have already sorted them according to an identical set of ascending/descending keys.
If your input is not already in that order, you might need to sort each file by REQUEST-DATE-S, CUST-NUMBER-S, CUST-ORDER-NUMBER-S and PART-NUMBER-S

Related

check for matching rows in csv file ruby

I am very new to ruby and I want to check for rows with the same number in a csv file.
What I am trying to do is go through the input csv file and copy element from the input file to the output file also adding another column called "duplicate" to the output file, then check if a similar phone is already in the output file while copying data from input to output then if the phone already exist, add "dupl" to the row in the duplicate column.
This is what I have.
file=CSV.read('input_file.csv')
output_file=File.open("output2.csv","w")
for row in file
output_file.write(row)
output_file.write("\n")
end
output_file.close
Example:
Phone
(202) 221-1323
(201) 321-0243
(202) 221-1323
(310) 343-4923
output file
Phone
Duplicate
(202) 221-1323
(201) 321-0243
(202) 221-1323
dupl
(310) 343-4923
So basically you want to write the input to output and append a "dupl" on the second occurrence of a duplicate?
Your input to output seems fine. To get the "dupl" flag, simply count the occurrence of each number in the list. If it's more than one, its a duplicate. But since you only want the flag to be shown on the second occurrence just count how often the number appeared up until that point:
lines = CSV.read('input_file.csv')
lines.each_with_index do |l,i|
output_file.write(l + ",")
if lines.take(i).count(l) >= 1
output_file.write("dupl")
end
output_file.write("\n")
end
l is the current line. take(i) is all lines before but not including the current line and count(l) applied to this counts how often the number appeared before if it's more than one, print a "dupl"
There probably is a more efficient answer to this, this is just a quick and easy to understand version.

We giving a task for Lua table but it is not working as expectable

Our task is create a table, and read values to the table using a loop. Print the values after the process is complete. - Create a table. - Read the number of values to be read to the table. - Read the values to the table using a loop. - Print the values in the table using another loop. for this we had written code as
local table = {}
for value in ipairs(table) do
io.read()
end
for value in ipairs(table) do
print(value)
end
not sure where we went wrong please help us. Our exception is
Input (stdin)
3
11
22
abc
Your Output (stdout)
~ no output ~
Expected Output
11
22
abc
Correct Code is
local table1 = {}
local x = io.read()
for line in io.lines() do
table.insert(table1, line)
end
for K, value in ipairs(table1) do
print(value)
end
Let's walk through this step-by-step.
Create a table.
Though the syntax is correct, table is a reserved pre-defined global name in Lua, and thus cannot should not be declared a variable name to avoid future issues. Instead, you'll need to want to use a different name. If you're insistent on using the word table, you'll have to distinguish it from the function global table. The easiest way to do this is change it to Table, as Lua is a case-sensitive language. Therefore, your table creation should look something like:
local Table = {}
Read values to the table using a loop.
Though Table is now established as a table, your for loop is only iterating through an empty table. It seems your goal is to iterate through the io.read() instead. But io.read() is probably not what you want here, though you can utilize a repeat loop if you wish to use io.read() via table.insert. However, repeat requires a condition that must be met for it to terminate, such as the length of the table reaching a certain amount (in your example, it would be until (#Table == 4)). Since this is a task you are given, I will not provide an example, but allow you to research this method and use it to your advantage.
Print the values after the process is complete.
You are on the right track with your printing loop. However, it must be noted that iterating through a table always returns two results, an index and a value. In your code, you would only return the index number, so your output would simply return:
1
2
3
4
If you are wanting the actual values, you'll need a placeholder for the index. Oftentimes, the placeholder for an unneeded variable in Lua is the underscore (_). Modify your for loop to account for the index, and you should be set.
Try modifying your code with the suggestions I've given and see if you can figure out how to achieve your end result.
Edited:
Thanks, Piglet, for corrections on the insight! I'd forgotten table itself wasn't a function, and wasn't reserved, but still bad form to use it as a variable name whether local or global. At least, it's how I was taught, but your comment is correct!

How to remove records from a file having same values at a location?

I have a sequential file having record length of 11. I have a field in-between starting from 9th position till 11th position and is of PIC 9(03). I want to delete all the records where I have same data in above specified location. This needs to be done using JCL only. Any utility can be used but should be supporting in microfocus cobol. See the example below:
Example File:
Rob ,d,012
Mike ,h,013
Kim ,g,014
Bob ,k,014
Wiz ,t,015
In the above example I want to delete rows for Kim and Mike as it is having same value for the location i.e. 014 and final output should be:
Rob ,d,012
Mike ,h,013
Wiz ,t,015
Try these statements in the SYSIN DD of DFSORT utility.
SORT FIELDS=COPY
OMIT COND=(9,3,ZD,EQ,014)
Microfocus use the mfsort utility which emulates all the major functions of IBM's DFSORT product.
mfsort option copy
use input-file [record definition]
[org organization] [key structure]
give output-file [record definition]
[org organization] [key structure]
omit cond (9,3,nu,eq,014)
More details about mfsort can be found here.
checkout nsort from ordinal. also syncsort now precisely. these are cots utilities that can drop duplicate records.
Sort by the name, and add up the count of records by name.
Use the OUTFIL command to delete the records that had more than one record:
RECORD TYPE=F,LENGTH=11
INREC FIELDS=(1,11,C'0001') * Include a dummy field to sum up
SORT FIELDS=(9,3,BI,A) * Sort by the "id"
SUM FIELDS=(12,4,ZD) * Count the number of records by "id"
OUTFIL FILES=OUT,BUILD=(1,11),OMIT=(12,4,NE,C'0001') * Get rid of duplicated records
END
This should work on DFSORT or SYNCSORT, not sure about MFSORT.

Can you use the JD Edwards Update command to change a field that is also part of the WHERE clause?

In JD Edward's One World (E1) package, is it possible to use the built in Update table function to update a particular field that is also used in the where clause?
The use case is that I am executing a batch process that loops through a series of "unprocessed" records and after processing them, updates the table to show a "processed" status. There are three statuses (Processed, Unprocessed, and Ignored). During my update, I can't simply update all flags to "Processed" without accidentally updating the ones labeled "Ignored".
If PO cProcessedFlag is equal to "U"
Table1.Select
Table1.Fetch Next
While SV File_IO_Status is equal to CO SUCCESS
...
Table1.Fetch Next
End While
End If
Table1.Update
I need to be able to update the processed field here (Table1.Update) while also being able to specify where the field is not "I".
You can select and update records at the same time. No problem doing this (Assuming that DOCO is the primary key of Table1):
Table1.Select
PO cProcessedFlag = BC cProcessedFlag
Table1.Fetch Next
VA mnOrderNumber[DOCO] <- BC mnOrderNumber[DOCO]
While SV File_IO_Status is equal to CO SUCCESS
...
Table1.Update
VA mnOrderNumber[DOCO] = VA mnOrderNumber[DOCO]
ā€œPā€ -> BC cProcessedFlag
Table1.Fetch Next
VA mnOrderNumber[DOCO] <- BC mnOrderNumber[DOCO]
End While
When you write code in ER, the middleware will actually perform an open, select, close etc. for each tableIO. So the handle for the second Table1.FetchNext is very different to the open, select, update, close generated for the Table1.Update

How to skip records with if else statement

Can anyone provide me logic for this problem
Only process the gtV with bVH01-iMS-FLG = 'Y' .
1) If not iMS-ORDER, bypass the record , read next record & find next gTV to check. One gTV can have multiple records in the input file gTVFLE.
2) If iMS-ORDER, continue process -> abc00-PROCESS-RECORDS.Need to make sure if any tVL didn't pass the validation/error, then the whole gTV should be held; and then continue to find/read next gTV.
From the limited information you have provided it appears there will be a field on some record that you are reading called BVH01-IMS-FLG, you will need to identify the condition for that using an 88 level, like so:
01 BVH01-IMS-FLAG pic X.
88 PROCESS-THIS-RECORD value 'Y'.
It also seems that you have related records in the gTV file and those need to be processed as a group, so something like this:
Perform Read-gTV-Record
Perform until End-Of-File
If PROCESS-THIS-RECORD
Perform abc00-Process-Records
End-IF
Perform Read-gTV-Record
End-Perform
Really, you need to provide more description of what you are trying to do. Record layouts of the gTV and what it means to be a valid tVL would be helpful.

Resources