Alter variable format using SQR programming language - database

I am new to Peoplesoft and Peoplecode/SQR in general and I want to ask a question.
What I wish to do, is to try and output a large (clob) string variable on a PDF file using SQR programming language, on 3 columns on the page, just as you can change the layout of a text in Microsoft Word by going to Layout -> Columns -> Three
What I have until now is this:
begin-select
TXT.U_PO_TXT &TXT.PO_TXT
from PS_U_PO_DISC_TXT TXT
where TXT.BUSINESS_UNIT = &PO.BUSINESS_UNIT
and TXT.PO_ID = &PO.PO_ID
end-select
So,
TXT.U_PO_TXT
is a CLOB stored in the database of 10000 characters and I want to output
&TXT.PO_TXT
on the PDF using the layout described above.
I have tried using COLUMNS and NEXT-COLUMN SQR commands but to no avail.
I find the documentation of SQR on the Oracle website poorly written.
This is the example I have found, applied to my case:
columns 10 50 110
move 55 to #bottom_line
begin-select
TXT.U_PO_TXT &TXT.PO_TXT
if #current-line >= #bottom_line
next-column goto-top=1 at-end=newpage
else
position (+1,1) !what is this even, it throws me an error "Unknown command"
end-if
from PS_U_PO_DISC_TXT TXT
where TXT.BUSINESS_UNIT = &PO.BUSINESS_UNIT
and TXT.PO_ID = &PO.PO_ID
end-select
I couldn't find an answer anywhere. Please help me.

I don't think this is possible by using COLUMNS. Defining and printing to SQR columns determines where you start printing, but the text won't automatically wrap once it hits the end of the column. It'll just keep printing.
You can, however, use the WRAP parameter to PRINT to accomplish this. Here's an example
LET $left = 'This is the left column. This is the left column. This is the left column. This is the left column. This is the left column. This is the left column.'
LET $middle = 'This is the middle column. This is the middle column. This is the middle column. This is the middle column. This is the middle column. This is the middle column. This is the middle column. This is the middle column. This is the middle column. This is the middle column. This is the middle column. This is the middle column.'
LET $right = 'This is the right column. This is the right column. This is the right column. This is the right column. This is the right column. This is the right column.'
! These variables are used to track which column is the tallest and then
! move the current position (#start-line) down by the largest number of
! lines that were printed
LET #line-offset = 0
LET #start-line = 1
LET #start-line-offset = #current-line - #start-line
! Print the left column
PRINT $left (#start-line, 1) WRAP 40 100
IF #current-line - #start-line-offset > #line-offset
LET #line-offset = #current-line - #start-line-offset
END-IF
! Print the middle column
PRINT $middle (#start-line, 50) WRAP 50 100
IF #current-line - #start-line-offset > #line-offset
LET #line-offset = #current-line - #start-line-offset
END-IF
! Print the right column
PRINT $right (#start-line, 110) WRAP 40 100
IF #current-line - #start-line-offset > #line-offset
LET #line-offset = #current-line - #start-line-offset
END-IF
! Update #start-line to be the original line position, plus the
! number of lines that were printed in the tallest column
LET #start-line = #start-line + #line-offset
PRINT 'Rest of the report goes here' (#start-line, 1)
The first number after WRAP is the character width of that column.
The second number after WRAP is the maximum number of lines that will be printed.
Most of the complexity in my code comes from that fact that you'll have to track which column printed the most lines (is the largest vertically) and then move your current cursor position down that many lines. The difficulty comes from that fact that your tallest column may be either the left or center column, so you need to track which column is your tallest rather than simply moving the cursor downward after printing your right column. In my example, the middle column is the tallest.
The reason I'm using #line-offset and #start-line-offset is because #current-line is the current line position in your report including the offset for the header. For example, if your header is 5 lines tall, then #current-line will start equal to 6 (the first line after your header) and doing PRINT 'hello' (#current-line, 1) will actually print to the 11th line of your report (6 lines down from the 5 line header). Also, assigning a value to #current-line doesn't seem to work, so I don't think your can manipulate the current line position directly.
If, however, you don't need to print anything else after your three columns, then you can use the KEEP-TOP parameter to WRAP so that your current line position doesn't change between each PRINT and you don't have to do any of the line offset tracking.
In your situation, you'll have to parse &TXT.PO_TXT into three separate variables (one for each column) based on how your text and column position data is stored in that field.
One thing to watch out for is that if you have two or more spaces in a row within the data you're printing, SQR may put a space as the first character of a line because word breaks seem to only be determined by the first space, rather than a sequence of one or more spaces.

Related

ISBLANK(...) = FALSE even thought the cell is blank in google sheet

Hi everyone,
I have 2 tables, 3rd column for Table 1 is Value 1 and 3rd column for Table 2 is Value 2. I combined these 2 tables by expanding both tables first so that all the columns are aligned as shown in the screenshot above (Column E to Column H).
The formula in all the yellow cells are:
Cell E4 : =QUERY(A4:C10,"Select A,B,C,' ' label ' ' 'Value 2' ")
Cell E12 : =QUERY(A12:C20,"Select A,B,' ',C label ' ' 'Value 1' ")
Cell K7 : =QUERY({E5:H10;E13:H17},"Select * where Col1 is not null",0)
Cell P7 : =ArrayFormula(IF(ISBLANK(M7:M12),100,M7:M12))
In column P, I want to return 100 as Value 1 if the cells in Column M is blank. So by right I should get 2,34,55,100,100,100 in column P but right now the formula still return 3 blank cells.
I suspect that is because the QUERY function that I used before which make the cell is not blank although it seems like still a blank cell. May I know is there any trick that I can use to find the blank cells in column M and column N (preferably don't touch the QUERY formula) since ISBLANK() is not working in this case?
Any help or advise will be greatly appreciated!
Edited
makes sense. you cant use ISBLANK because cell is not blank. remember that QUERY inserted an empty space.
try:
=ARRAYFORMULA(IF(ISBLANK(TRIM(M7:M12)), 100, M7:M12))
ISBLANK is so sensitive that it will detect even residue from TRIM
update:
=ARRAYFORMULA(IF(TRIM(M7:M12)="", 100, M7:M12))

Inserting rows to dataframe on multiple indices based on conditions in python-pandas

I have a dataframe like this
Whenever I see an instance where start is followed by stop and DURATION column is 0, I need to insert a row after that (at 4th and 8th row in this case), which should contain pretty much the same values of its previous row, but the event column should be denoted by E1.
I need to get something like this
How can I achieve this since multiple indices can have the values with START-STOP and duration as 0?
Thanks in advance!
If you always have a sequence 'start-stop' (stop is always followed by start), it will work:
df.loc[(df['DURATION'] == 0) & (df['event'] == 'stop'), 'event'] = 'E1'
What means: Put 'E1' in column 'event' for each row which has 0 in column 'DURATION' and 'stop' in column 'event'.

How to Get SSIS Expression Leftover odd Rows right?

I’m trying to come up with Expression in Conditional Split To Return Whatever leftOver Rows.
For example I have Flat File with 10 Rows and if want to split the file onto 2 Rows, I will have 5 files with 2 Rows in each file, but what if I want to split the file By 3 I will have only 3 files with 3 Rows each file, But Where is the Leftover 1 Row modulus remainder will go?. I tried the Conditional split and was fine But the LeftOver Rows Output DID NOT Come out Right. Please take look at my images and tell me if I have issues with my expression in Conditional Split and For Loop.
I have these variables:
#Counter = 0
#ReCount = total count that comes from RowCount Transformation
#SplitRow = Given Number that will Divided by
#EndCount = #ReCount / #SplitRow
I need to have Right expression for LeftOver or modulus remainder of any ‘Odds’ Number
Given that you already know the rownumber for each row as well as the rowcount of the entire file and the split number of rows in each destination file, the expression that will flag up any leftover rows from your splitting is any row in which the following returns true:
rownumber > (rowcount - (rowcount % split))

Power BI - How can I visualize percent of rows with a certain value and of those rows, percent with a value above or below a number?

Data
My data looks like this. I want to see a bar chart of the % of rows where column Y/N? contains "Y" and of those rows, the percent that % column contains a value of 7 or above, and the percent where % column contains a value below 7
Something like...
IF [C2:C19] = Y, THEN COUNTIF [B2:B19] >=7
and
IF [C2:C19] = Y, THEN COUNTIF [B2:B19] <7
Sorry if this is unclear or an obvious question!
One way to do this is to create three different measures
first countrows with filter on "Y" and similarly others - then you can bring these values on your bar chart

Tab based split on lines misses empty columns - Perl

I have a tab separated text file. I read line by line and column by column. I make few changes in each column and write the line to a new file. When I read each column using split function of perl
my #aLastOldElements = split(/\t/, $_);
I miss out on empty columns in the end. For example if file has 33 tab separated columns, out of which 10 in the end are empty. The split function creates array of size 23. I want to have all the columns. Because this way the header of file (33 columns) doesn't match the data (23 columns) and I get errors while writing the file to the database.
split accepts an optional third parameter for the maximum number of fields to return. If this is present, empty trailing fields will not be discarded:
perl -E '#arr = split(/ /, "foo bar ", 100); say scalar #arr'
14
So long as the tabs to separate the empty fields at the end of the line are present, this should always give you 33 fields in the array, even if the last 10 are empty. (In my example, there are 14 fields returned because the string contains 13 separators, even though the specified limit was 100.)
Edit: In answer to the question in the first comment:
perl -wE '#arr = split(/\t/, "foo\tbar\t\thello\t", 100); say $_ || "(empty field)" for #arr'
foo
bar
(empty field)
hello
(empty field)
If you know that the columns should be there, whether or not they have any data, you can just ensure the result yourself.
my #aLastOldElements = split(/\t/, $_);
my $short_fall = 33 - #aLastOldElements;
if ( $short_fall > 0 ) {
push #aLastOldElements => ( '' ) x $short_fall;
}

Resources