Generate 100 data randomly, or select if it is possible - gams-math

I want to test my model , I need to test it in some data , I want to generate data , in fact I want to have 125 different parameter from 0 to 10000.
For example , in below we have 4 different parameter ,from 1 to 300.
Set I/0*300/;
Parameter MyParameter;
MyParameter /4 1,10 1,42 1,87 1/;
I don't want to do this by hand.
Is there any method that I generate it automaticly.
another way asking:
how can Select 4 random element of a set ' I' , without repetition?

Try this:
Set I /0*300/
picks /p1*p4/;
Scalar pick;
Parameter MyParameter(I);
MyParameter(I) = 0;
loop(picks,
pick = uniformInt(1, card(I));
* Make sure to not pick the same one twice
while(sum(I$(pick=ord(I)),MyParameter(I))=1,
pick = uniformInt(1, card(I))
Display 'here';
);
MyParameter(I)$(pick=ord(I))=1;
);
Display MyParameter;

Related

How to set variabel In Toad for oracle

How to Set variabel call in toad for orcale?
Like i have Query for input 3 report_dat, and 1 want create variable, so that i only input once
I have create like this
def report_date = 2;
def report_year = 2021;
and in where condition, i have set like this.
where H_CLOSING_PERIOD.BULAN = &report_date
and H_CLOSING_PERIOD.TAHUN = &report_year
But, when i run that query, it's still request input from user, like thisenter image description here
Try replacing with the following:
variable report_date H_CLOSING_PERIOD.BULAN%TYPE; --not sure of your data types, you can adjust these
variable report_year H_CLOSING_PERIOD.TAHUN%TYPE;
SELECT 2
, 2021
INTO :report_date
, :report_year
FROM dual;
and then when you use the binds:
WHERE H_CLOSING_PERIOD.BULAN = :report_date
AND H_CLOSING_PERIOD.TAHUN = :report_year
In TOAD, the simplest way (from my point of view), is to use bind variables. How? Simply precede their names with a colon sign:
where H_CLOSING_PERIOD.BULAN = :report_date
and H_CLOSING_PERIOD.TAHUN = :report_year
TOAD will prompt you to enter their values. For any subsequent execution, just hit ENTER (i.e. you don't have to enter their values, unless you want to).

Carefully select and retrieve one from a large set of data

I don't know what to do when I want to retrieve one item in each column from data like the following.
|name|power|
test1|15
test1|120
test1|40
test2|50
test2|80
test2|100
test3|1
test3|4
test3|10
The results I want.
|name|power|
test1|120
test2|100
test3|10
What I tried.
pickup_one = (
beaconPickUp_three
.withColumn('r_max_date', f.max('power').over(w.partitionBy()))
.filter(f.col('r_max_date') == f.col('power'))
)
or
PickUp_one = beaconPickUp_three.groupBy(f.col("name")).agg({"power": "max"})
I need your help.

user input , user inputs data into the list

I have a eval solution , that the user need to input the names of the people and give a certain value , i am trying to make it work but the input part is not working.
preferencia(ana,joana,1).
preferencia(ana,rui,-1).
preferencia(ana,maria,1).
preferencia(ana,jose,-1).
preferencia(ana,tiago,-1).
preferencia(ana,andre,1).
preferencia(joana,rui,2).
preferencia(joana,maria,1.5).
preferencia(joana,jose,-1).
preferencia(joana,tiago,1).
preferencia(joana,andre,-1).
preferencia(rui,maria,1).
preferencia(rui,jose,-1).
preferencia(rui,tiago,1).
preferencia(rui,andre,1).
preferencia(maria,jose,-1).
preferencia(maria,tiago,1).
preferencia(maria,andre,-1).
preferencia(jose,tiago,1).
preferencia(jose,andre,1).
preferencia(tiago,andre,-1).
preferencia(X,Y,D):-preferencia(Y,X,D),!. % reverse preferenciaance
% representation: S is a list of persons
% evaluation function:
eval([_],0).
eval([Name1,Name2|R],DS):-
preferencia(Name1,Name2,D),
eval([Name2|R],DR),
DS is D+DR.
start :- write('Pick 2 Person to make a group '), read(X), eval([X,X|R],DS).
i want the user to input 2 names via console , so i want is the console working like this , "Pick 2 Person to make a group" the user inputs the (ex. rui , maria) , and return the value of their preference. If i input eval([rui,mariaR],DS) it returns the value 1 , but this in only in static way , i want the user being able to select 2 names and return their preference level. I believe the main error is the start function , thanks

Count order lines by condition and calculate the percentage to total lines

Experts,
Please let me know how to write the code in ABAP to implement the following logic?
From the below screenshot, for each "S_ORD_ITM", I have to determine if Order_Qty = Dlv_Qty. If yes, determine the total count of S_ORD_ITM for which Order_Qty = Dlv_Qty. In this example, for all 6 rows of S_ORD_ITM, Order_Qty = Dlv_Qty. So, this value would be 6. Lets says this as 'X' Next step is to find the total record count of S_ORD_ITM column. It is also 6 in this case. Lets says this as 'Y'.
My result should be [X/Y]*100.
In some cases, there could be total of 18 S_ORD_ITM, out of which only there exists only 6 records of S_ORD_ITM for which Ord_Qty = Dlv_Qty. So, my result would be [6/18]*100 = 33.33%
This logic has to be implemented for delivery numbers which have a first pass indicator as 'X'. Imagine this sales order has many delivery numbers, and the delivery number in this example is a first pass indicator with 'X'. I already have a loop statement in my end routine, that says
LOOP AT RESULT PACKAGE ASSIGNING RESULT FIELDS WHERE /BIC/FIRSTPASS = 'X'.
Please let me know how I can make use of this already available loop statement and implement the above logic.
Thanks a ton,
G.
UPDATE:
Hello Goutham,
You can solve the whole thing a lot easier. You just need to make a data flow from your DSO where the order data is, then you do a lookup. with that you loop through your result data and push just the extracted, aggregated rows in a new DSO. First build the target structure and the DSO and then use an expert routine / end routine with an abap coding like i described.
END UPDATE
so the Structure is like
sales_order, plant, shipping_point, delivery_number, s_ord_itm, ord_qty, dlv_qty
in your result package variable. is that correct? without a screenshot it is very hard to know what you mean, do you mean a SAP BW transformation or just ABAP code?
you could add some helper-variables to your structure or do it in the loop, i prefer doing it in the loop. but first you have to sort your result package!
your coding should be something like this (pseudo code) where your x variable is v_counter_ord_itm and v_counter_ord_dlv is your y:
make some data definitions like
WA_RESULT.../END OF... (build a workarea for sales_order, result)
T_RESULT (make an itab out of workarea)
WA (workarea with sales_order, counter_ord_itm, counter_ord_dlv)
PSEUDO-CODE!!!
SORT RESULT_PACKAGE BY /BIC/SALES_ORDER
WA-SALES_ORDER = 0.
WA-COUNTER_ORD_ITM = 0
WA-COUNTER_ORD_DLV = 0
LOOP AT RESULT PACKAGE ASSIGNING RESULT FIELDS WHERE /BIC/FIRSTPASS = 'X'.
IF WA-SALES_ORDER NE /BIC/SALES_ORDER.
IF WA-SALES_ORDER NE 0.
WA_RESULT-RESULT = WA-COUNTER_ORD_DLV / WA-COUNTER_ORD_ITM * 100.
WA_RESULT-SALES_ORDER = WA-SALES_ORDER.
APPEND WA_RESULT TO T_RESULT.
CLEAR WA, WA_RESULT.
ENDIF.
WA-SALES_ORDER = /BIC/SALES_ORDER.
ENDIF.
WA-COUNTER_ORD_ITM = WA-COUNTER_ORD_ITM + 1.
IF result_fields-ord_qty EQ result_fields-dlv_qty.
WA-COUNTER_ORD_DLV = WA-COUNTER_ORD_DLV + 1.
ENDIF.
ENDLOOP.
then you have the variables in your itab. for usage within data processing in sap bw, do another loop with a lookup to push the result data in a new field "result" (you have to add it in the output structure):
LOOP AT RESULT_PACKAGE ...
LOOP AT IT_RESULT ASSIGNING <z>
WHERE /BIC/SALES_ORDER = <z>-SALES_ORDER.
RESULT_PACKAGE-RESULT = <z>-RESULT.
ENDLOOP
This is the code that I used:
SELECT doc_number plant ship_point dsdel_date s_ord_item deliv_numb /bic/zlord_qty /bic/zldlv_qty
INTO CORRESPONDING FIELDS OF TABLE it_doc_table
FROM /bic/azord_dso00.
SELECT doc_number COUNT( DISTINCT s_ord_item ) AS numr
FROM /bic/azsd_o11000
INTO CORRESPONDING FIELDS OF TABLE it_count_table
GROUP BY doc_number.
READ TABLE lt_min_flag WITH KEY doc_number = source_fields-doc_number
plant = source_fields-plant
ship_point = source_fields-ship_point
deliv_numb = source_fields-deliv_numb
dsdel_date = source_fields-dsdel_date
INTO lt_min_flag_wa
BINARY SEARCH.
CHECK sy-subrc = 0. CLEAR result.
IT_DOC_TABLE = VALUE /bic/azord_dso00( FOR ls_doc IN it_doc_table WHERE ( doc_number = source_fields-doc_number AND plant = source_fields-plant AND ship_point = source_fields-ship_point AND deliv_numb = source_fields-deliv_numb AND dsdel_date = source_fields-dsdel_date AND /bic/zlord_qty = /bic/zldlv_qty ) ( ls_doc ) ).
z_numr = lines( it_doc_table ).
READ TABLE it_count_table INTO wa_count_table WITH KEY doc_number = source_fields-doc_number.
IF sy-subrc = 0 AND wa_count_table-numr <> 0.
result = ( z_numr / wa_count_table-numr ) * 100 .
ENDIF.

Storing Select Query result in Variable Ruby on Rails

I wanted to know how we could store the result of my select query on a variable.
#ppt2 = Ppt.select('slide_name').where('id=?',4)
#ppt1 = Ppt.update_all({:time2=>#ppt2},['id like ?','1'])
Here, slide_name and time2 are both text attributes of the same table ppt.
What happens on the above execution is that the time2 field in id=1 gets the value "#ppt2" whereas I want it to get the value of slide_name from id=4 which does not get stored in #ppt1.
In other words, how do I store the value of the select query in #ppt2 so that it can be used in the next line?
Any help is appreciated.
Call the slide_name method on your first result.
#ppt2 = Ppt.select('slide_name').find(4).slide_name