How to verify pressed key on OnKeyUp event - pascal

I have a lot of lines to check the typed content of a edit1.text field, but I need to use the OnKeyUp event (for some reasons), so how can I 'translate' this code to Key:Word type (normaly its Key:Char on OnKeyPress)?
if not (key in ['0'..'9', #08]) then begin
key:=#0;

Use Ord( Key ) to convert a keyboard Key's Word value to a character value. Otherwise use a VK_ value if available.
In your snippet you've mixed char's ( '0'..'9' ) with Values ( #08 ), I'm not sure that is ok you need to test it. If not then ( #08 ) needs to be checked either directly to Key or Chr( Key ) in another comparison.
Also it may be preferable to use VK_UNKNOWN rather than #0.
Here is a KeyUp event I'm using in some working code I've written in Lazarus. HTH.
procedure TfrmMain.lbCmdLinesKeyUp( Sender : TObject; var Key : Word; Shift : TShiftState );
begin
if ( Key = vk_return ) and ( lbCmdLines.ItemIndex > -1 ) then
begin
if ( Shift = [ ssCtrl ] ) then
begin
if btnLineEdit.Enabled then
btnLineEdit.Click;
end
else
begin
if btnRun.Enabled then
btnRun.Click;
end;
end;
if ( Key = Ord( 'C' ) ) or ( Key = Ord( 'c' ) ) then
begin
if Shift = [ ssCtrl ] then
actCopyClipCmdLine.Execute;
//order, apparently, doesn't matter, both work
//if Shift = [ ssCtrl, ssShift ] then
if Shift = [ ssShift, ssCtrl ] then
mniCopyCLListClipClick( Self );
//if ( ssCtrl in Shift ) and ( ssShift in Shift ) and ( ssAlt in Shift ) then
if Shift = [ ssCtrl, ssShift, ssAlt ] then
actCopyCmdLine.Execute;
end;
end;

Related

I use create type [name] is object or type [name] record method . but Return different results?

I've been wondering what's wrong.
There are too many data in my table. I can't get them all out
In the 3 sql statements, the other parameters and conditions are the same except that [ t1 ] uses three different methods.
1.Mode1 is Physical table.
2.Mode2 is Create type Object.
3.Mode3 is type Record.
enter image description here
Table t1 has 900000 data.
Oracle database 12c Enterprice 12.1.0.2.0
Result:
I got an incredible result.
1. Mode 1 Result (Physical table) = Mode3 Result(Record Mode).
2. Mode2 Result(Object Mode) != (Mode1 or Mode3).
code:
1. create or replace type o_record is object ( a1 varchar2(100) ,a2 number ,a3 varchar2(50) );
2.creae or reaplce type o_table is table of o_record ;
In package space :
type r_record is record (a1 varchar2(100) , a2 number ,a3 varchar2(50) );
type r_table is table of r_record ;
r_record_mode r_table ;
In package Body:
create or reaplce package body test is
procedure main ( result1 out number
,result2 out number
,result3 out number
,para in number
) is
o_object_mode o_table ;
------------------------------------------------------------------
cursor cur_a1 is
select count(1) num
from **table1 t1** , -- Physical table (Mode 1)
table2 t2.....
where t1.a1=t2.a1
and t1.a2=nvl(para,t1.a2)
....
;
cursor cur_a2 is
select count(1) num
from **table( o_object_mode ) t1**, ; --Object (Mode2)
table2 t2.....
where t1.a1=t2.a1
and t1.a2=nvl(para,t1.a2)
....
;
cursor cur_a3 is
select count(1) num
from **table( t_record_mode ) t1**, --Record (Mode3)
table2 t2.....
where t1.a1=t2.a1
and t1.a2=nvl(para,t1.a2)
....
------------------------------------------------------------------
begin
select o_record ( t.a1 ,t.a2 ,t.a3 )
bulk collect
into o_object_mode
from table1 t
;
------------------------------------------------------------------
select t.a1 ,t.a2 ,t.a3
bulk collect
into r_record_mode
from table1 t
;
------------------------------------------------------------------
for i in cur_a1 loop
result1 :=i.num;
end loop;
--------------------------
for i in cur_a2 loop
result2 :=i.num;
end loop;
--------------------------
for i in cur_a3 loop
result3 :=i.num;
end loop;
------------------------------------------------------------------
end main;
end test ;
I can get the correct result by replacing [type object] with [type record].
It is so difficult that [type object] needs special attention and usage

How to MOVE or MERGE different fields into the subfile in ONE LINE in RPGLE

i'm stuck on how to move or display different value from different field in one line.
My output supposed to look like this
Real Output
but for now, my output is look like this
Recent Output
This is my physical file
CUREXG file
I have three field in physical file which are :
EXGDAT = date And the key field
EXGCOD = exchange code
EXGRAT = exchange rate
I have 2 dates, and basically i need the output to only have 2 line which one is 31 May, and the second one is 1 june.
I tried to group them by doing the if condition but it didnt work. How I'm supposed to do? Please help me
Thanks in advance
//Add a logical for the table by date, exchange code
fcurexg2 if e k disk
**---------------------- start of your code
*LOVAL setll curexg
read curexg
dou %eof(curexg);
c eval ##date = exgdat
c exsr $GetVals
eval rrn = rrn + 1
write sfl01
// move to the next date
exgdat setgt curexg
read curexg
enddo
**------------------------
Begsr $GetVals; // runs for each code -- usd, eur, etc
##gcod = 'USD'
exsr $GetGrat;
move ##grat USD
##gcod = 'GBP'
exsr $GetGrat;
move ##grat GBP
##gcod = 'EUR'
exsr $GetGrat;
move ##grat EUR
##gcod = 'AUD'
exsr $GetGrat;
move ##grat AUD
##gcod = 'SGD'
exsr $GetGrat;
move ##grat SGD
Endsr;
**------------------------
Begsr $GetGrat; //find the rate for that date and code
*like define curexg ##date
*like define exgcod ##gcod
*like define exgrat ##grat
clear ##grat
Chain (##date: ##gcod) curexg2; //the new logical
if %found(curexg2);
##grat = exgrat
endif
Endsr;
**------------------------
consider an SQL function. Here is an SQL function which returns the exchange rate of a specific exchange code and date.
CREATE or replace function curexg_exchangeRate(
inDate date,
inCurrency char(3))
returns decimal(7,2)
language sql
begin
declare Sqlcode int ;
declare vSqlcode DECIMAL(5,0) default 0 ;
declare vExgrat decimal(7,2) default 0 ;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
SET vSqlcode = SQLCODE ;
select a.exgrat
into vExgrat
from curexg a
where a.exgdat <= inDate
and a.exgcod = inCurrency
order by a.exgdat desc
fetch first row only ;
return coalesce( vExgrat, 0 ) ;
end
RPG code that calls the exchangeRate sql function:
d usdRate s 7p 2
d gbpRate s 7p 2
d eurRate s 7p 2
/free
// get exchange rate, of each exchange code, as of the specified date
exec sql
set :usdRate = curexg_exchangeRate( :exgdat, 'USD' ) ;
exec sql
set :gbpRate = curexg_exchangeRate( :exgdat, 'GBP' ) ;
exec sql
set :eurRate = curexg_exchangeRate( :exgdat, 'EUR' ) ;
this code reads the exchange rates for each exchange date:
// list exchange rates for each exchange date.
exec sql
declare c1 cursor for
with t1 as (
select distinct a.exgdat
from curexg a
order by a.exgdat )
select a.exgdat,
curexg_exchangeRate( a.exgdat, 'USD' ) usdRate,
curexg_exchangeRate( a.exgdat, 'GBP' ) gbpRate,
curexg_exchangeRate( a.exgdat, 'EUR' ) eurRate
from t1 a
order by a.exgdat ;
exec sql
open c1 ;
exec sql
fetch c1
into :exgdat, :usdRate, :gbpRate, :eurRate ;
if sqlcode <> 0 ;
leave ;
endif ;
// write to subfile
sfExgdat = exgdat ;
sfUsdRate = usdRate ;
sfGbpRate = gbpRate ;
sfEurRate = eurRate ;
write sflrcd ;
enddo ;
exec sql
close c1 ;
*inlr = '1' ;
return ;
/end-free

Download header line into TXT with GUI_DOWNLOAD

Got a little problem by using the function 'GUI_DOWNLOAD'. Tried to append a header line at the top of my .txt file i created. My solution is:
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = lv_file
filetype = 'ASC'
write_field_separator = 'X'
TABLES
data_tab = it_outh. "internal table just with the header line
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = lv_file
filetype = 'ASC'
append = 'X'
write_field_separator = 'X'
TABLES
data_tab = it_output. "internal table with selected data
The code works. But the formatting is crap, cause of the different length (header line and data)
Is the only way to fix that problem, using shorter descriptions in it_outh? Or does anyone of you have a better idea for me?
Have a nice day.
Regards,
Dennis
Here is a quick-n-dirty workaround how to make an aligned output of itab with header into text:
FIELD-SYMBOLS: <fs_table> TYPE STANDARD TABLE.
DATA: lref_struct TYPE REF TO cl_abap_structdescr,
o_table TYPE REF TO data.
lref_struct ?= cl_abap_structdescr=>describe_by_name( 'CRCO' ).
DATA(components) = lref_struct->get_components( ).
DATA(fields) = VALUE ddfields( FOR line IN lref_struct->get_ddic_field_list( ) ( line ) ).
" making all types as char by replacing with existing PRZ char field
MODIFY components FROM VALUE abap_componentdescr( type = components[ name = 'PRZ' ]-type ) TRANSPORTING type WHERE name <> ''.
lref_struct = cl_abap_structdescr=>create( components ).
DATA(o_ref_table) = cl_abap_tabledescr=>create( p_line_type = lref_struct p_table_kind = cl_abap_tabledescr=>tablekind_std ).
CHECK o_ref_table IS BOUND.
CREATE DATA o_table TYPE HANDLE o_ref_table.
ASSIGN o_table->* TO <fs_table>.
APPEND INITIAL LINE TO <fs_table>. " reserving line for headers
SELECT
CAST( mandt AS CHAR( 12 ) ) AS mandt,
CAST( objty AS CHAR( 2 ) ) AS objty,
CAST( objid AS CHAR( 8 ) ) AS objid,
CAST( laset AS CHAR( 6 ) ) AS laset,
CAST( endda AS CHAR( 8 ) ) AS endda,
CAST( lanum AS CHAR( 4 ) ) AS lanum,
CAST( begda AS CHAR( 8 ) ) AS begda,
CAST( aedat_kost AS CHAR( 8 ) ) AS aedat_kost,
CAST( aenam_kost AS CHAR( 12 ) ) AS aenam_kost,
CAST( kokrs AS CHAR( 10 ) ) AS kokrs,
CAST( kostl AS CHAR( 6 ) ) AS kostl,
CAST( lstar AS CHAR( 12 ) ) AS lstar,
CAST( lstar_ref AS CHAR( 12 ) ) AS lstar_ref,
CAST( forml AS CHAR( 12 ) ) AS forml,
CAST( prz AS CHAR( 12 ) ) AS prz,
CAST( actxy AS CHAR( 12 ) ) AS actxy,
CAST( actxk AS CHAR( 12 ) ) AS actxk,
CAST( leinh AS CHAR( 12 ) ) AS leinh,
CAST( bde AS CHAR( 12 ) ) AS bde,
CAST( sakl AS CHAR( 1 ) ) AS sakl
UP TO 10 ROWS
FROM crco
APPENDING CORRESPONDING FIELDS OF TABLE #<fs_table>.
" writing headers
ASSIGN <fs_table>[ 1 ] TO FIELD-SYMBOL(<empty>).
LOOP AT fields ASSIGNING FIELD-SYMBOL(<field>).
ASSIGN COMPONENT <field>-fieldname OF STRUCTURE <empty> TO FIELD-SYMBOL(<heading>).
CHECK sy-subrc = 0.
<heading> = <field>-scrtext_m.
ENDLOOP.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = 'C:\tab.txt'
filetype = 'ASC'
write_field_separator = 'X'
TABLES
data_tab = <fs_table>.
Though, it is not that simple, but it definitely does the job
The trick that is used in the above snippet: target internal table is created dynamically making all the fields char unlike real DB table, then the dummy line is added at the top of the table and all the headings are put there.
This approach requires additional preliminary work (like explicit casting of all DB fields) but I see no other way to make formatted TXT output.

Circular Dependency in DAX calculated column::AAS model

I am stuck in the situation where I am adding a new calculated column but it's prompting me the circular dependency. The first column is calculated like:
=VAR Denominator = ( Validation_Accounts_Agreements[CalculatedClosedDateVsFirstPurchaseDate] + 1 )
VAR Sales =
CALCULATE (
SUM ( SalesR48NBVBySolution[TotalSales] ),
FILTER (
SalesR48NBVBySolution,
SalesR48NBVBySolution[invoicedate] >= Validation_Accounts_Agreements[CalculatedFirstAnchorPurchaseDateAfterGTWClosedDate]
)
)
VAR R6AnchorSales =
CALCULATE (
SUM ( SalesR48NBVBySolution[TotalSales] ),
FILTER (
SalesR48NBVBySolution,
SalesR48NBVBySolution[invoicedate]
>= EDATE (
Validation_Accounts_Agreements[CalculatedFirstAnchorPurchaseDateAfterGTWClosedDate],
-6
)
&& SalesR48NBVBySolution[invoicedate] < Validation_Accounts_Agreements[CalculatedFirstAnchorPurchaseDateAfterGTWClosedDate]
&& SalesR48NBVBySolution[ClensedAnchorDesignation] = "Y"
)
)
RETURN
IF ( ISBLANK ( R6AnchorSales ),
IF ( NOT (ISBLANK ( Validation_Accounts_Agreements[CalculatedFirstAnchorPurchaseDateAfterGTWClosedDate] )
)
&& ISBLANK ( R6AnchorSales ),
DIVIDE ( Sales, Denominator ) * 12
)
)
The next column I want to create here is:
=VAR Denominator = ( Validation_Accounts_Agreements[CalculatedClosedDateVsFirstPurchaseDate_SLN] + 1 )
VAR Sales =
CALCULATE (
SUM ( SalesR48NBVBySolution[TotalSales] ),
FILTER (
SalesR48NBVBySolution,
SalesR48NBVBySolution[invoicedate] >= Validation_Accounts_Agreements[CalculatedFirstPurchasedateAfterGTWClosedDate_SLN]
)
)
VAR R6AnchorSales =
CALCULATE (
SUM ( SalesR48NBVBySolution[TotalSales] ),
FILTER (
SalesR48NBVBySolution,
SalesR48NBVBySolution[invoicedate]
>= EDATE (
Validation_Accounts_Agreements[CalculatedFirstPurchasedateAfterGTWClosedDate_SLN],
-6
)
&& SalesR48NBVBySolution[invoicedate] < Validation_Accounts_Agreements[CalculatedFirstPurchasedateAfterGTWClosedDate_SLN]
&& SalesR48NBVBySolution[ClensedAnchorDesignation] = "N" && CALCULATE(MAX('CAM Alignment'[NodeCd_L3])=="C3-10-00015")
)
)
RETURN
IF ( ISBLANK ( R6AnchorSales ),
IF ( NOT (ISBLANK ( Validation_Accounts_Agreements[CalculatedFirstPurchasedateAfterGTWClosedDate_SLN] )
)
&& ISBLANK ( R6AnchorSales ),
DIVIDE ( Sales, Denominator ) * 12
)
)
Here is more info about my model::
In the above picture, the yellow highlighted columns I am using to create the calculated column 1 (calculated Annualization).The red circled columns are being used to create column 2 ( calculated Annualization_SLN).both sets of columns are almost similar (changes in the filter).But when I am trying to create column 2 ( calculated Annualization_SLN) that time I am getting this error of circular dependency; which is dependent on column 1.
In general, according to best-practice avoid extensively using Calculated Columns. Instead, add them in your data source (back-end) or use M-Query.
In order to answer your question precisely, you need to share more information about your model (i.e. relationships). However, we can provide you some guidelines referring to this article in order to avoid circular dependencies.
Quoting the conclusion of the article:
Most of the time, circular dependencies occur when you use calculated tables. You can easily avoid them by paying attention to your choice of functions. The difference between DISTINCT and VALUES, or between ALL and ALLNOBLANKROW is a subtle difference. But once you get used to it, your code will be safer when it comes to relationships and circular references.

Measure that should summarize sales for parent company regardless of child company filter

I have a table with SalesCompanies. The table contains one column ChildCompany and another column ParentCompany.
How can I make the measure below aggregate per ParentCompany regardless of ChildCompany filtering?
CustomerSalesSinceLastInventory:=CALCULATE(
SUM(factCustomerSales[Quantity])
;FILTER(
ALL(dimCalendar[Date])
;dimCalendar[Date] >= MIN(parCurrentMonth[Date])
&& dimCalendar[Date] <= MAX(dimCalendar[Date])
)
)
This is one way of achieving the desired result:
CustomerSalesSinceLastInventory :=
SUMX (
ADDCOLUMNS (
VALUES ( 'dimSalesCompanies'[ParentCompany] );
"Total sales"; CALCULATE (
SUM ( [Quantity] );
ALL ( 'dimSalesCompanies'[Company] );
FILTER (
ALL ( dimCalendar[Date] );
dimCalendar[Date] >= MIN ( parCurrentMonth[Date] )
&& dimCalendar[Date] <= MAX ( dimCalendar[Date] )
)
)
);
[Total sales]
)
This measure adds a column(in memory, you will not actually see it) which groups/aggregates the sale per ParentCompany. The time filter is also included in this column.

Resources