COBOL-Record is being replaced instead of added - if-statement

my program is suppose to add record to the output file if JOBCODE = S and SALES > 100,000.00. The variables are all being passed properly but when the program is finished only the last record remains in the output file and I can't figure out why. How do I add it under neath the previous record? I have also used OPEN EXTEND already and received the same result. This is what the output currently looks like:
Employee recognition for the week ending: 2022-06-22
----------------------------------------------------
Last Name First Name Store #
----------------------------------------------------
ESTERA BETHANY 0003
It should be:
Employee recognition for the week ending: 2022-06-22
----------------------------------------------------
Last Name First Name Store #
----------------------------------------------------
CAMERON STANLEY 0003
ELDOUR JOHNATHAN 0002
KENT LORENE 0001
NGUYEN CARMELO 0002
SRIVASTAVA SAM 0003
LABRIE ARMAND 0003
CHU LARISA 0001
FORLINI COREEN 0002
ESTERA BETHANY 0003
Here is my program:
program-id. Assignment6 AS "Assignment6".
environment division.
input-output section.
*INPUT FILE DECLARATION
SELECT IN-FILE ASSIGN "C:\DataFiles\dataIn.dat"
ORGANIZATION IS LINE SEQUENTIAL.
*SALES RECONGNITION OUTPUT FILE DECLARATION
SELECT OUT-FILE-SALES ASSIGN
"C:\DataFiles\SalespersonRecongnition.rpt"
ORGANIZATION IS LINE SEQUENTIAL.
*SALARY EXPENSES OUTPUT FILE DECLARATION
configuration section.
data division.
file section.
FD IN-FILE.
01 IN-RECORD.
03 IN-EMPLOYEEID PIC X(4).
03 IN-JOBCODE PIC X(1).
03 IN-LASTNAME PIC X(14).
03 IN-FIRSTNAME PIC X(14).
03 IN-STARTDATE PIC 9(8).
03 IN-STORENUM PIC 9(4).
03 IN-SALARY PIC 9(6).
03 IN-SALES PIC 9(8).
FD OUT-FILE-SALES.
01 SALES-OUT-RECORD PIC X(52).
working-storage section.
*END OF FILE
01 WS-EOF PIC 9(1) VALUE 0.
*WS IN-RECORD HOLDER
01 WS-IN-RECORD.
03 WS-IN-EMPLOYEEID PIC X(4).
03 WS-IN-JOBCODE PIC X(1).
03 WS-IN-LASTNAME PIC X(14).
03 WS-IN-FIRSTNAME PIC X(14).
03 WS-IN-STARTDATE PIC 9(8).
03 WS-IN-STORENUM PIC 9(4).
03 WS-IN-SALARY PIC 9(6).
03 WS-IN-SALES PIC 9(8).
*SALES REPORT HEADINGS STRUCTURE
01 SALES-RECORD-HEADING1.
03 FILLER PIC A(52) VALUE
"Employee recognition for the week ending: 2022-06-22".
01 SALES-RECORD-FILLER1.
03 FILLER PIC X(52) VALUE ALL '-'.
01 SALES-RECORD-HEADING2.
03 FILLER PIC X(9) VALUE "Last Name".
03 FILLER PIC X(13) VALUE SPACE.
03 FILLER PIC X(10) VALUE "First Name".
03 FILLER PIC X(10) VALUE SPACE.
03 FILLER PIC X(7) VALUE "Store #".
03 FILLER PIC X(3) VALUE SPACE.
01 SALES-RECORD-FILLER2.
03 FILLER PIC X(52) VALUE ALL "-".
*SALES RECORD ROW STRUCTURE
01 SALES-ROW.
03 WS-SALES-LASTNAME PIC X(14).
03 FILLER PIC X(8) VALUE SPACE.
03 WS-SALES-FIRSTNAME PIC X(14).
03 FILLER PIC X(8) VALUE SPACE.
03 WS-SALES-STORENUM PIC 9(4).
03 FILLER PIC X(4) VALUE SPACE.
procedure division.
*MAIN PROGRAM
PERFORM OPEN-FILES.
PERFORM READ-FILE
UNTIL WS-EOF = 1.
PERFORM CLOSE-FILES.
OPEN-FILES.
OPEN INPUT IN-FILE
OUTPUT OUT-FILE-SALES
WRITE SALES-OUT-RECORD FROM SALES-RECORD-HEADING1
WRITE SALES-OUT-RECORD FROM SALES-RECORD-FILLER1
WRITE SALES-OUT-RECORD FROM SALES-RECORD-HEADING2
WRITE SALES-OUT-RECORD FROM SALES-RECORD-FILLER2.
READ-FILE.
READ IN-FILE INTO IN-RECORD
AT END
SET WS-EOF TO 1
NOT AT END
PERFORM GOT-A-RECORD
END-READ.
GOT-A-RECORD.
MOVE IN-EMPLOYEEID TO WS-IN-EMPLOYEEID
MOVE IN-JOBCODE TO WS-IN-JOBCODE
MOVE IN-LASTNAME TO WS-IN-LASTNAME
MOVE IN-FIRSTNAME TO WS-IN-FIRSTNAME
MOVE IN-STARTDATE TO WS-IN-STARTDATE
MOVE IN-STORENUM TO WS-IN-STORENUM
MOVE IN-SALARY TO WS-IN-SALARY
MOVE IN-SALES TO WS-IN-SALES
PERFORM SALES-REPORT-ADD-RECORD.
SALES-REPORT-ADD-RECORD.
IF WS-IN-JOBCODE = "S"
AND WS-IN-SALES > 10000000
MOVE WS-IN-LASTNAME TO WS-SALES-LASTNAME
MOVE WS-IN-FIRSTNAME TO WS-SALES-FIRSTNAME
MOVE WS-IN-STORENUM TO WS-SALES-STORENUM
PERFORM WRITE-RECORD
END-IF .
WRITE-RECORD.
WRITE SALES-OUT-RECORD FROM SALES-ROW
DISPLAY SALES-ROW.
CLOSE-FILES.
CLOSE IN-FILE
OUT-FILE-SALES.
.
end program Assignment6.
Any suggestions would be appreciated!

Your program has no explicit end, therefore it "falls through":
You likely want to add GOBACK. at the end of your main.

Related

How to dump IP packet buffer for wireshark/How to do hexdump in C++?

I have a simple uint8_t* IP packet buffer like
45 0 0 34 0 0 40 0 40 6 6B 53 C0 A8 FF 6 AC D9 1C EE 0 4D 0 50 0 0 0 0 0 0 0 0 80 2 FD E8 A5 20 0 0 2 4 5 B4 3 3 0 4 2 0 0 0
I want to use Wireshark to view it. I saw that I can import an hex dump on Wireshark, but how can I save this buffer as a hex dump for wireshark to open?
Is it possible to concatenate lots of IP packets together?
If you can modify the data to match the format expected by text2pcap, you can use that tool to convert the data into a pcap (or pcapng) file. For example:
Here's the data you provided in a format acceptable to text2pcap:
0000 45 00 00 34 00 00 40 00 40 06 6B 53 C0 A8 FF 06
0010 AC D9 1C EE 00 4D 00 50 00 00 00 00 00 00 00 00
0020 80 02 FD E8 A5 20 00 00 02 04 05 B4 03 03 00 04
0030 02 00 00 00
0034
Since this appears to start with an IPv4 header, you can generate a pcap file with a link layer header type set to LINKTYPE_RAW, the value of which is obtained from https://www.tcpdump.org/linktypes.html, as referenced in the text2pcap man page. Alternatively, you can choose to add a dummy Ethernet header to the data, in which case you can omit the link layer header type option as LINKTYPE_ETHERNET is the default value; however you do need to add the option to add the dummy Ethernet header. Here I demonstrate both methods:
Method 1: Raw IP
text2pcap -l 101 file.hex file.pcap
Method 2: Add dummy Ethernet header
text2pcap -e 0x0800 file.hex file.pcap
The text2pcap tool is capable of processing any arbitrary number of packets from a file, but note the required format from the man page, i.e. "Note the last byte must either be followed by the expected next offset value as in the example above or a space or a line-end character(s)."
By the way, Wireshark itself is also capable of converting the hex data into a pcap file as well using the File -> Import from Hex Dump... feature, although Wireshark will always import the hex data as a pcapng file. You can choose to save the file as pcap though, but there'll always be that intermediate pcapng file generated. Wireshark should just provide a checkbox to allow the user to select which format to use, just like text2pcap does. I have filed Wireshark Bug 16724 to address this.

JREPL.BAT - regex to remove lines in file

I have a source data file which I have been using JREPL.BAT to perform some very simple search and replace operations quite successfully. I now need to expand on that to do 2 jobs.
1. remove all lines that start with the string "appX_formContent". This line contain a lot of html output also, it all needs to be deleted on that line.
2. remove all lines that start with "Hex Payload:" and the subsequent line that comes with it.
This is an example of the input data file which shows 2 records. The delimiter between each record is the row that contains "-----------------".
-----------------
Message Headers
JMSCorrelationID: 60bb7750-e9e2-11e9-98bb-42010a961307
JMSPriority: 4
JMSRedelivered: false
Message Properties
app_trackingId: 190990a2-d8d8-43eb-814a-36ceba7a9111
appX_formInstanceIdentifier: FRM389083
appX_formContent: {"data":{"C7d14a6eb-70e7-402d-9d6e-4efd01ba561c":"N","Y","test.</p>\n<p>test form data to be informed </p>\n<p>...............</p>\n<p><strong>Update</strong></p>\n<p><strong>years</strong>"<p>supervision</p>","<p>:true,"c9377ae2-901d-4461-929c-c76e26dc6183":false}}}
app_sourceSystemId: source
app_eventCode: FORM_OUTPUT
app_instigatingUserId: 66
JMSXGroupSeq: 0
Hex Payload:
25 50 44 46 2D 31 2E 35 0D 0A 34 20 30 20 6F 62 6A 0D 0A 3C 3C 2F 54
-----------------
Message Headers
JMSCorrelationID: 641a80d0-e9e2-11e9-98bb-42010a961307
JMSPriority: 4
JMSTimestamp: 2019 10 08 16:43:40
JMSRedelivered: false
Message Properties
app_trackingId: a3c2fe93-ef71-4611-9605-9858ff67a6e8
appX_formInstanceIdentifier: FRM388843
appX_formContent: {"data":{"C7d14a6eb-70e7-402d-9d6e-4efd01ba561c":"N","Y","test.</p>\n<p>test form data to be informed </p>\n<p>...............</p>\n<p><strong>Update</strong></p>\n<p><strong>years</strong>"<p>supervision</p>","<p>:true,"c9377ae2-901d-4461-929c-c76e26dc6183":false}}}
app_sourceSystemId: source
app_eventCode: FORM_OUTPUT
app_instigatingUserId: 433
JMSXGroupSeq: 0
Hex Payload:
25 50 44 46 2D 31 2E 35 0D 0A 34 20 30 20 6F 62 6A 0D 0A 3C 3C 2F
-----------------
This is the batch file that I use to call jrepl - very simple.
call jrepl ".*(?:appX_formContent: .*)" "" /m /f "inpu.txt" /o "output.txt"
I've only tried to remove the appX_formContent line with the regex but it isn't producing any output. I'm not good with regex so help appreciated.
Not sure how to handle the second task of deleting the Hex Payload: line.

SAS reading a file in long format

I have a file in long format, like so:
name weight month cal
bob 80 01 5000
ben 70 01 4989
mary 60 01 3000
bob 81 02 4999
ben 68 02 6000
mary 57 02 2800
...
I would like to create N linear regressions of weight over cal: one for each of the months.
I know how to read the data into a dataset and how to fit a regression model.
I am not sure how I do this in a loop for the N months...
Any pointers?
Many thanks!

using numeric or alphabetic codes in statements; for use in "if" statements

I am wondering how to do something in COBOL. I am trying to write a program that uses if statements to output matching data records from a data file. But I have not done it like this yet see what I need to do is make codes for the different data types.
blue = 1
brown = 2.
So I tried it like this but it wouldn't work. This I have declared in the master-record:
01 COLOR-IN PIC (9)
05 BLUE VALUE 1.
05 BROWN VALUE 2.
Then I figured I could just write an if statement like
IF COLOR-IN = BLUE
PERFORM 200-OUTPUT.
So what I am asking is how do I make the colors equal a numeric or alphabetic code. What kind of statement should I write.
I figured it out. I used the 88 statements. Like this
88 MALE VALUE 'M'.
But I have another problem. The output does list the records that meet the 'if' statement criteria, however, I need to code in the program the actual hair and eye color so that when the program executes it prints the hair and eye color instead of 1 or 2. Can anyone give me an example or hint on how to do that?
+1 for learning about 88s. They are very useful.
A table (array) of labels that correspond to your values is what you're looking for. If you use alphabetic codes, as in your
88 MALE VALUE 'M' case, then your table has an entry for the value and for the label.
01 INPUT-VALUE PIC X(1).
88 MALE VALUE "M".
88 FEMALE VALUE "F".
01 LABELS-AND-VALUES-AREA.
05 LABELS-AND-VALUES.
07 ONE-LABEL-AND-VALUE OCCURS 2.
09 ONE-LABEL PIC X(6).
09 ONE-VALUE PIC X(1).
05 FILLER REDEFINES LABELS-AND-VALUES
VALUE "MALE MFEMALEF".
01 I PIC S9(4) COMP.
01 DISPLAY-LABEL PIC x(6).
MOVE "?" TO DISPLAY-LABEL
PERFORM VARYING I FROM 1 BY 1 UNTIL I > 2
IF INPUT-VALUE = ONE-VALUE(I)
MOVE ONE-LABEL(I) TO DISPLAY-LABEL
END-IF
END-PERFORM
If you use numerics for your input values, you can skip the lookup and go right to the label you want.
01 INPUT-VALUE PIC 9(1).
88 MALE VALUE "1".
88 FEMALE VALUE "2".
88 VALID-INPUT VALUE "1", "2".
01 LABELS-AND-VALUES-AREA.
05 LABELS-AND-VALUES.
07 ONE-LABEL-AND-VALUE OCCURS 2.
09 ONE-LABEL PIC X(6).
05 FILLER REDEFINES LABELS-AND-VALUES
VALUE "MALE FEMALE".
01 DISPLAY-LABEL PIC x(6).
IF VALID-INPUT
MOVE ONE-LABEL(INPUT-VALUE) TO DISPLAY-LABEL
ELSE
MOVE "?" TO DISPLAY-LABEL
END-IF
For this case, you might want to add some code for missing/unknown data.
Update
I added some code to handle missing/unknown data.

Help needed in converting a few lines of ruby code to c++!

I have to convert the following code into Qt c++
So I need to understand what these lines to.
#key in this code is a pem key file contents by openssl
key = KEY+#key.public_key.to_der
so i think this is converting that key to der format and then combining it with KEY.
is it right?
whats does this do? to_sizet(key.size)
As you can see the function returns [num].pack('V'). But i dont know wht does it do? I mean [num].pavck('V'). what is it?
And whats does this mean. key.size is it the strlen of key?
def write_crx
print "write crx..." if #verbose
key = KEY+#key.public_key.to_der
File.open(#crx, 'wb') do |file|
file << MAGIC
file << EXT_VERSION
file << to_sizet(key.size)
file << to_sizet(#sig.size)
file << key
file << #sig
File.open(#zip, 'rb') do |zip|
file << zip.read
end
end
puts "done at \"#{#crx}\"" if #verbose
end
def to_sizet num
return [num].pack('V')
end
Well I have one more Question. Forgot to add last time.
what does this line do?
KEY = %w(30 81 9F 30 0D 06 09 2A 86 48 86 F7 0D 01 01 01 05 00 03 81 8D 00).map{|s| s.hex}.pack('C*')
so i think this is converting that key to der format and then combining it with KEY. is it right?
Yes.
whats does this do? to_sizet(key.size) As you can see the function returns [num].pack('V'). But i dont know wht does it do? I mean [num].pavck('V'). what is it?
Well, just have a look at what the documentation on Array#pack says. With the V modifier, it just converts the array to a binary representation of a 32 bit unsigned integer type.
And whats does this mean. key.size is it the strlen of key?
Again, the Ruby documentation helps. String#size is indeed the string length.
what does this line do?
KEY = %w(30 81 9F 30 0D 06 09 2A 86 48 86 F7 0D 01 01 01 05 00 03 81 8D 00)
.map{|s| s.hex}.pack('C*')
%(…) defines an array where each of its entries, separated by whitespace is treated as a separate string. %w(one two) is essentially a shorthand for ["one", "two"].
After that, we have to look up (again in the documentation) the meanings of Array#map and String#hex.
map simply applies an operation to each element of an array and creates a new array with the result. The operation is s.hex – that is, parse each of the strings as a hexadecimal number.
The result is once again packed, this time using the C* operation which, the documentation tells us, converts the numbers into their corresponding (unsigned) 8-bit character codes.
In summary: that line converts the hexadecimal values into a string of their respective characters.
Afterthought: you should really install Ruby and play a bit with the interactive Ruby console, irb. Keying in the above line already helps a lot:
$ irb
>> %w(30 81 9F 30 0D 06 09 2A 86 48 86 F7 0D 01 01 01 05 00 03 81 8D 00).map{|s| s.hex}
=> [48, 129, 159, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 3, 129, 141, 0]
>> %w(30 81 9F 30 0D 06 09 2A 86 48 86 F7 0D 01 01 01 05 00 03 81 8D 00).map{|s| s.hex}.pack('C*')
=> "0\201\2370\r\006\t*\206H\206\367\r\001\001\001\005\000\003\201\215\000"