Cobol dashes are confusing me [duplicate] - cobol

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
cobol difference with Picture having a dash (-) and a having a X
I'm tying to get to grips with Cobol and can't understand the dashes when formatting a number. I have this example:
--9
Am I correct with the following?
The first dash - If number is a negative put a dash otherwise don't.
the second dash - I'm confused with this. There is already a dash at the start to specify whether its negative or positive.
9 - Numeric digit (0-9)
An example would be good. :S
Thanks

In view of your previous question, Im not sure what you are having trouble with. But lets try again...
In COBOL, numeric display fields may contain various types of "punctuation". This "punctuation" is defined in the items PICTURE clause. A few examples of the type of "punctuation" symbols you can use are: Explicit decimal points, plus/minus signs, CR/DR indicators and thousnads separators (commas in North America). There is a well defined set of rules that determine what type of "punctuation" can occur in the PICTURE clause and where. This link to PICTURE CLAUSE editing explains how to construct (or read) any given PICTURE clause.
One thing that you, and many others new to COBOL, trip up on is that a data definition in COBOL specifies two distinctly different types of information about numeric display data. One is the range of values it may hold and the other is how
that range of values may be displayed. Your example: PICTURE --9 tells me two things about the data item: 1) Values are integers in the range of -99 through to +99, and 2) Displaying this item will take 3 spaces. If the number is positive, spaces will appear before the first non zero digit. If the number is negative a minus sign will appear immediately to the left of the first non zero digit. Consider the following COBOL DISPLAY statement:
DISPLAY '>' DISP-NBR '<'
IF DISP-NBR has a PICTURE clause of: --9 this is how various values will be displayed.
0 displays as: > 0<
-1 displays as: > -1<
-11 displays as: >-11<
10 displays as: > 10<
Note that all displays take 3 character positions. At least 1 digit will always be displayed (because of the '9' in the PICTURE clause), other than that, no leading zeros are displayed. A minus sign will display only for negative values. The minus sign, if displayed will be to the immediate left of the first displayed digit.
Now to answer you specific question: The total number of character positions needed to display a numeric display data item is determined by the length of the PICTURE. You have a 3 character PICTURE so 3 character positions are needed. When
a sign is specified in the PICTURE, a space is always reserved for it. This is what limits the range of integers to those containing at most 2 digits. The second minus sign indicates 'zero supression'. Zero supression just means not printing leading zeros. Only 1 minus sign is ever printed and it will be to the immediate left of the first displayed digit.
COBOL contains a lot of flexability with respect to displaying numbers. Understanding the numeric display PICTURE clause is key to understanding how this all works.

from stackoverflow:cobol-difference-with-picture-having-a-dash-and-a-having-a-x
The dash means that if you have a negative number, a dash will be
shown beside (at the left) of the number. Only one dash will be
displayed. If the number is positive, a space will shown for every
dashes.

Related

Display lines not beginning with one or more letters and not ending with one or more digits

I am attempting to display lines that do NOT begin with one or more letters and do NOT end in one or more digits - using grep.
What I have so far is
grep '^[^a-zA-Z]'
This shows me all the lines that do not start with a letter, so a, abc do not show BUT abc (has a leading space) is shown, correctly, for example.
I am not sure how to include the second portion of this which is NOT end in one or more digits.
Thanks
Why not:
^[^a-zA-Z].*[^0-9]$
Note that this doesn't cover the case when only one character is present.

google sheet, position of first number in a string

BJ190215P00020000
this is the string. I want to extract the left letters "BJ" (they are from 1 letter up to letters).
I think i need to find the position of the first digit, then apply LEFT function to get out the "BJ". (the letters could be 1-8).
is there a way to find the position of first digit in the string. OR, is there a better way to extract the letters before the first digit?
Try ...
=regexextract(A1,"\D+")

Get all characters before a whitespace in LUA (ROBLOX)

I have a 5x5 grid of tiles that are number like:
Numerical order Row number(eg: 1 1 would be the first tile on the first row and 6 2 would be the first tile on the second row)
I need to get the blocks around a clicked tile (above, below, left and right), I thought about doing this by taking off numbers from the numerical order and row number. I wrote this:
local ab = tostring(tonumber(v.Name)-5)..tostring(tonumber(string.sub(v.Name,-1))-1)
local be = tostring(tonumber(v.Name)+5)..tostring(tonumber(string.sub(v.Name,-1))+1)
ab being the tile above and be being the tile below. I ran into a problem where I cannot get the first two letters of a tile who's numerical order is two digits using one line (I don't want to use if statements since I'm pretty sure there's a one line solution)
I came up with a solution and that is to get all the characters before the whitespace (which separates the order from the row number) but I have no idea how to write it.
Just ask for all non-whitespace characters from the beginning of the string:
print(("test123 more456"):match("^(%S+)"))
This should print test123.

Detect text columns from word positions

I have a tiff file and the text on it, which has been OCR'd at an earlier stage. The words have their exact positions as information (upper left, lower right). I now need to read the text within a user-drawn rectangle.
Normal paragraphs are no problem, but I don't know how I should handle text columns. If there are two paragraphs next to each other, simply taking the row as a single line would make the result unusable.
Are there algorithms to help me put the words in the right order? I'm guessing that I have to examine the spaces between words to detect patterns that identify columns. I would like to avoid processing the image directly, although it should be possible (but no OCR).
I am also unsure about the influence of lists/tables, e.g. in orders & bills. A line-orientated approach would probably be better here.
I am developing in Delphi, but adaptable algorithms in other languages would also be appreciated.
edit: I will try to post sample data tomorrow, but basically I have an Array of Words, with their respective coordinates on the image (I could easily draw a rectangle around them, for example).
Suppose your original text is in two columns like this:
Aaaa bb ccc ddddd mmmm nn oooo pp
eee fff ggggg hh qqq rrrrrrrrr
i jjjj kkk lll sss tttt uu.
From your description, it sounds like your OCR has given you the individual words and their bounding rectangles. If the original page is scanned orthogonally, then all of the words on a given line should have the same (or very close) y values. If they're not exactly the same, you can do an integer division on the vertical positions with some fraction of a typical box height. That should cluster the y values. You can do similar processing on the x coordinates to ensure that words at the edge of a column also have identical x values.
To detect the separate columns, I'd try making a histogram of all the "left" values of all the words (or right edges if your text runs right-to-left). You should see a peak at the beginning of each column.
You can probably rule out any false positives by ensuring that, on every line, there is a gap between the right coordinate of the last box before the candidate start of a column. The gap should probably be at least as large as the smallest width of any word.
You can then partition your words up into column groups by checking which horizontal range their left and right coordinates fall in to. In our example, the words from Aaaa through lll would end up in the first partition and the words from mmmm through uu. would end up in the second partition.
Within each partition, you can then partition on line by sorting on the y coordinates. Finally, for each line, you sort on the x coordinate. (Whether you sort on ascending or descending depends on your coordinate system and the direction your text flows.)
The same basic idea could be applied to tables as well as columns of text, but you might need some tweaks to deal with things like right-justified cells.

cobol difference with Picture having a dash (-) and a having a X

What are the differences between the 2 pictures below?
PIC X(15)
PIC ----,---,---.99.
Is the bottom just another way to represent the top?
PIC X(15) Represents 15 characters of virtually any type of data, could be
digits, letters or any other symbol (printable or not).
PIC ----,---,---.99 Represents a numeric edited data item capable of holding
values in the range +999999999.99 through -999999999.99. This item will display a leading minus sign if the
value placed into it is negative, otherwise it will display the number without a leading sign. The displayed
number will have comma separators at the indicated positions provided there is at least 1 digit in front of it.
Here are a few samples of the way certain numbers will display:
999999999.99 displays as 999,999,999.99
1234.56 displays as 1,234.56
0 displays as .00
-1234567.12 displays as -1,234,567.12
-3 displays as -3.00
Variables such as this are for display only. Don't even think
about doing arithmetic with them! Given the following data declarations:
01 DISP-NBR PIC ----,---,---.99.
01 NBR PIC S9(9)V99.
The following MOVE operations are both valid
MOVE 1234.56 TO NBR
MOVE 1234.56 TO DISP-NBR
However,
ADD 1 TO NBR
is perfectly valid but...
ADD 1 TO DISP-NBR
Will give you a compile error. Even though DISP-NBR contains numeric data it is in a display only
format. You need to do math using data items that are purely numeric and then MOVE them to display fields
for 'pretty printing'.
This table
describes all of the PICTURE elements that may be used in COBOL and what they are for.
The first one can have any alpha-numeric caracters.
The second one is used to format number. The dash means that if you have a negative number, a dash will be shown beside (at the left) of the number. Only one dash will be displayed. If the number is positive, a space will shown for every dashes.

Resources