In VFP 6 I have a table called "cars" and inside a button I want to find an ID based on the name. What did I do wrong?
... code
SELECT cars
LOCATE FOR ALLTRIM(UPPER(name)) = variable_read_from_textbox
IF NOT FOUND()
messagebox("not found")
ELSE
messagebox(cars.id_car)
ENDIF
Running the code works ok when the name is not found but when it is found it errors out.
Thanks!
Your code is right in general. Slight modification for safety and fix for error:
SELECT cars
* this implies an exact match, regardless of set exact, and makes casing same
* remember this wouldn't use an index unless there is an index with the same signature
LOCATE FOR ALLTRIM(UPPER(name)) == ALLTRIM(UPPER(m.variable_read_from_textbox))
IF NOT FOUND()
messagebox("not found")
ELSE
messagebox(transform(cars.id_car))
ENDIF
As far as I remember, in VFP6, messagebox() was not yet capable transforming the value to string for you and expects a string (you didn't tell what the error is but that should be it).
A little caution about your search.
ALLTRIM(UPPER(name))
will NOT use an index, unless there is an index with key "ALLTRIM(UPPER(name))". If there is, it would be used, but such an index is actually useless because of the alltrim(). A better index would simply be:
Upper(name)
and then your search would look like:
variable_read_from_textbox = ALLTRIM(UPPER(m.variable_read_from_textbox))
SET EXACT ON
SELECT cars
LOCATE FOR UPPER(name) = m.variable_read_from_textbox
IF NOT FOUND()
...
Related
I need the "elabora prenotazione" button to be shown only when the column "stato prenotazione" is "IN SOSPESO"
I tried to set a condition but I don't know how to pick the column value
If I understand your question, this could help:
For the source of your report:
SELECT
CASE
WHEN stato_prenotazione = 'in sospeso' THEN 'elabora prenotazione'
ELSE ''
END name_of_column,
prenotazione,
username,
nome,
cognome,
viaggio,
stato_viaggio,
data_prenota,
stato_prenotazione,
numero_ospiti
FROM your_table
Then set the column "name_of_column" to type: link, and fill the target.
Wrap a condition around a call to apex_page.get_url within your SQL, so it will only produce a link when relevant
Example of function in use, sans condition:
https://azureoutput.wordpress.com/2017/10/18/custom-hyperlink-in-interactive-report/
Use this to make the button look prettier, and maybe get some other ideas
https://www.grassroots-oracle.com/2015/12/tutorial-include-action-button-in-report.html
See this in regard to escaping special characters, otherwise you'll just see HTML in your report
https://www.grassroots-oracle.com/2017/01/escape-special-characters-apex-demo.html
This could be resolved by a simple case statement as #sara mentioned.
something like:
select (case stato_prenotazione when 'in sospeso' then 'elabora prenotazione' end) as your_column
I would not keep else condition so that the column will simply contain null value if the condition is not met.
I know they advice to get a cell value this way:
columnValue = vars.getObject("resultObject").get(0).get("Column Name");
as stated on jMeter doc : component reference : JDBC_Request.
But: How to access the same RS cell value by just a number of the column?
RS.get(0).get(4);
...instead of giving it a String of column Name/Label.
edit 1: Lets use Groovy/Java, instead of BeanShell. Thanks.
edit 2: The original motivation was the difference between column Name / Label, as these seem to be not fully guaranteed (? seems to be not clear here, not to me), especially due case-sensitivity ("id"/"ID", "name"/"Name"/"NAME" ..)
It should be something like:
String value = (new ArrayList<String>(vars.getObject("resultObject").get(0).values())).get(4)
More information: Debugging JDBC Sampler Results in JMeter
Be aware that according to HashMap documentation:
This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time.
So the order of columns might be a big question mark.
The row itself is a HashMap, defined in source code as:
HashMap<String, Object> row
So using BeanShell syntax, you could get it as
row = vars.getObject("resultObject").get(0); // returns HashMap
In HashMap, you cannot access item (column) by ID. You could, however, apply one of the methods described here, but HashMap doesn't guarantee order, so you cannot be sure what "column 4" will contain.
If you want to be able to loop through all columns, it's better to do it in a Map style, not by index. For example using entrySet() with BeanShell:
for(Map.Entry entry : row.entrySet())
{
log.info(entry.getKey() + "=" + entry.getValue());
}
See various ways to iterate through Map here.
How can I do the following:
data: ls_header type BAPIMEPOHEADER.
" fill it
write ls_header.
currently I'm getting an error because write can not parse the complex type to a string. Is there a simple way to get this code running in abap?
You could use something like:
DATA: g_struct TYPE bapimepoheader.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE g_struct TO FIELD-SYMBOL(<f>).
IF sy-subrc NE 0.
EXIT.
ENDIF.
WRITE: / <f>.
ENDDO.
Perhaps not exactly the answer you expect: If you list each field.
This can be done quite easy via the Pattern-mask in SE38:
Select the Write-pattern:
Enter the structure you want:
Select the fields
Confirm with "Copy"
Confirm and you get
WRITE: bapimepoheader-po_number,
bapimepoheader-comp_code,
bapimepoheader-doc_type,
bapimepoheader-delete_ind,
bapimepoheader-status,
bapimepoheader-creat_date,
bapimepoheader-created_by,
bapimepoheader-item_intvl,
bapimepoheader-vendor,
bapimepoheader-langu,
bapimepoheader-langu_iso,
bapimepoheader-pmnttrms,
bapimepoheader-dscnt1_to,
bapimepoheader-dscnt2_to,
bapimepoheader-dscnt3_to,
bapimepoheader-dsct_pct1,
bapimepoheader-dsct_pct2,
bapimepoheader-purch_org,
bapimepoheader-pur_group,
bapimepoheader-currency,
bapimepoheader-currency_iso,
bapimepoheader-exch_rate,
bapimepoheader-ex_rate_fx,
bapimepoheader-doc_date,
bapimepoheader-vper_start,
bapimepoheader-vper_end,
bapimepoheader-warranty,
bapimepoheader-quotation,
bapimepoheader-quot_date,
bapimepoheader-ref_1,
bapimepoheader-sales_pers,
bapimepoheader-telephone,
bapimepoheader-suppl_vend,
bapimepoheader-customer,
bapimepoheader-agreement,
bapimepoheader-gr_message,
bapimepoheader-suppl_plnt,
bapimepoheader-incoterms1,
bapimepoheader-incoterms2,
bapimepoheader-collect_no,
bapimepoheader-diff_inv,
bapimepoheader-our_ref,
bapimepoheader-logsystem,
bapimepoheader-subitemint,
bapimepoheader-po_rel_ind,
bapimepoheader-rel_status,
bapimepoheader-vat_cntry,
bapimepoheader-vat_cntry_iso,
bapimepoheader-reason_cancel,
bapimepoheader-reason_code,
bapimepoheader-retention_type,
bapimepoheader-retention_percentage,
bapimepoheader-downpay_type,
bapimepoheader-downpay_amount,
bapimepoheader-downpay_percent,
bapimepoheader-downpay_duedate,
bapimepoheader-memory,
bapimepoheader-memorytype,
bapimepoheader-shiptype,
bapimepoheader-handoverloc,
bapimepoheader-shipcond,
bapimepoheader-incotermsv,
bapimepoheader-incoterms2l,
bapimepoheader-incoterms3l.
Now you can make a simple replacement of bapimepoheader with ls_header and you have an output of all fields of the structure.
Maybe this is not elegant and you must adapt your report, if the structure changes. But I like this way, because often I don't need all fields and I can select the fields in an easy way.
I know two ways, one is procedural, the other is oop.
Here is the procedural approach.
Select the structure's fields (or whatever else You might need ) from the data-dictionary table DD03L into a local internal table.
Loop over the table into a work-area
Check, whether current field is a flat single datatype, and if so,
Assign component workarea-fieldname of structure ls_header into anyfieldsymbol
Write anyfieldsymbol
Do You need the code ?
Class CL_ABAP_CONTAINER_UTILITIES was specially introduced for that by SAP.
Use FILL_CONTAINER_C method for output the structure in a WRITE manner:
DATA: ls_header type BAPIMEPOHEADER.
CALL METHOD CL_ABAP_CONTAINER_UTILITIES=>FILL_CONTAINER_C
EXPORTING
IM_VALUE = ls_header
IMPORTING
EX_CONTAINER = DATA(container)
EXCEPTIONS
ILLEGAL_PARAMETER_TYPE = 1
others = 2.
WRITE container.
You can write your structure to a string and then output the string. Same method idoc segments are created.
How do I create an object if one is not found? This is the query I was running:
#event_object = #event_entry.event_objects.find_all_by_plantype('dog')
and I was trying this:
#event_object = EventObject.new unless #event_entry.event_objects.find_all_by_plantype('dog')
but that does not seem to work. I know I'm missing something very simple like normal :( Thanks for any help!!! :)
find_all style methods return an array of matching records. That is an empty array if no matching records are found. And an empty is truthy. Which means:
arr = []
if arr
puts 'arr is considered turthy!' # this line will execute
end
Also, the dynamic finder methods (like find_by_whatever) are officially depreacted So you shouldn't be using them.
You probably want something more like:
#event_object = #event_entry.event_objects.where(plantype: 'dog').first || EventObject.new
But you can also configure the event object better, since you obviously want it to belong to #event_entry.
#event_object = #event_entry.event_objects.where(plantype: 'dog').first
#event_object ||= #event_entry.event_objects.build(plantype: dog)
In this last example, we try to find an existing object by getting an array of matching records and asking for the first item. If there are no items, #event_object will be nil.
Then we use the ||= operator that says "assign the value on the right if this is currently set to a falsy value". And nil is falsy. So if it's nil we can build the object form the association it should belong to. And we can preset it's attributes while we are at it.
Why not use built in query methods like find_or_create_by or find_or_initialize_by
#event_object = #event_entry.event_objects.find_or_create_by(plantype:'dog')
This will find an #event_entry.event_object with plantype = 'dog' if one does not exist it will then create one instead.
find_or_initialize_by is probably more what you want as it will leave #event_object in an unsaved state with just the association and plantype set
#event_object = #event_entry.event_objects.find_or_initialize_by(plantype:'dog')
This assumes you are looking for a single event_object as it will return the first one it finds with plantype = 'dog'. If more than 1 event_object can have the plantype ='dog' within the #event_entry scope then this might not be the best solution but it seems to fit with your description.
I am getting error (ORA - 00972 : identifier too long) while creating the view.
Please find the view statement.
create or replace view ELVW_ATM_REC_HANDOFF_1
(Rectype
,Recseq
,Record_Type
,Record_Sequence
,MESSAGE_TYPE
,PAN
,PROCESSING_CODE
,TRANSACTION_AMOUNT
,TRANSACTION_CURRENCY_CODE
,SETTLEMENT_AMOUNT
,SETTLEMENT_CURRENCY_CODE
,Billing_AMOUNT
,Billing_CURRENCY_CODE
,Transaction_DATE
,Settlement_Date
,TRACE
,REFERENCE_NUMBER
,Switch_Log_ID
,AUTHORIZATION_NUMBER
,RESPONSE_CODE
,Host_Error_Code
,TERMINAL_ID
,Acceptor_ID
,ACQUIRING_INSTITUTION_CODE
,REV_FLAG
,Original_Trace_Number
,From_Account
,To_Account)
as
select * from
(select 'FT'
,'count'
,'DT'
,rownum
,msg_type
,pan,proc_code
,txn_amt
,txn_ccy_code
,setl_amt
,setl_ccy_code
,bill_amt
,bill_ccy_code
,trans_dt_time
,setl_date
,stan,trn_ref_no
,'iso field 60'
,'isofield 38'
,resp_code
,error_code
,term_id
,'ISOmessage42'
,acq_ins_id
,decode(substr(msg_type,1,1),4,reverse(msg_type),msg_type)
,'ISOfield90'
,from_acc
,to_acc
from swtb_txn_log)
It seems error occurs at the decode function. if i comment it. its working fine. Please find the below code
create or replace view ELVW_ATM_REC_HANDOFF_1(Rectype,Recseq,Record_Type,Record_Sequence,MESSAGE_TYPE,PAN,PROCESSING_CODE,TRANSACTION_AMOUNT,TRANSACTION_CURRENCY_CODE,SETTLEMENT_AMOUNT,SETTLEMENT_CURRENCY_CODE,Billing_AMOUNT,Billing_CURRENCY_CODE,Transaction_DATE,/*Transaction_TIME,*/Settlement_Date,TRACE,REFERENCE_NUMBER,Switch_Log_ID,AUTHORIZATION_NUMBER,RESPONSE_CODE,Host_Error_Code,TERMINAL_ID,Acceptor_ID,ACQUIRING_INSTITUTION_CODE,/*REV_FLAG,*/Original_Trace_Number,From_Account,To_Account) as
select * from (select 'FT','count','DT',rownum,msg_type,pan,proc_code,txn_amt,txn_ccy_code,setl_amt,setl_ccy_code,bill_amt,bill_ccy_code,trans_dt_time,/*trans_dt_time,*/setl_date,stan,trn_ref_no,'iso field 60',
'isofield 38',resp_code,error_code,term_id,'ISOmessage42',acq_ins_id,/*decode(substr(msg_type,1,1),4,reverse(msg_type),msg_type),*/'ISOfield90',from_acc,to_acc from swtb_txn_log)
I have checked the length of the column name. Its less than 30 characters. Looking forward for your help.
Try giving an alias (that is shorter than 30 characters) to the DECODE function.
Example:
DECODE( ...stuff... ) MYALIAS
True, all of the column names in the view spec are less than thirty characters.
Howver, your view includes a inline query:
select * from ( select ...
This may be the problem. Because it may be trying to work out at identifier for DECODE() statement at that intermediate point. I say "may" because I can't reproduce this on my 10g box: defining column names for the view solves the ORA-01948.
Regardless, you can fix the problem simply by giving your DECODE() column an alias which is of an acceptable length.