count 2 fields combined in qlikview - qlikview

I have two fields in my Qlikview Data - Procedures and 2nd Element
They both contain data that is duplicated between them;
eg Procedures field has: "This", "That", "The other" whilst 2nd Element Field has: "This", "That", "Something else"
I want to create a bar chart that can show the combined totals of the two fields:
eg "This" = 2, "That" = 2, "The other" = 1, "something else" = 1
No matter what expression i put in though i can't get it to work properly.
Has anyone got any suggestions?
Thanks.

I would try to solve this using a script approach. You'll need :
Make sure that every row in you table has an unique id (for instance using RowNo() as RecordId in the Load statement)
After loading the table (let's call it DataTable), do a first resident Load like this LOAD RecordId, Procedures as NewColumn resident DataTable.
Do the same thing for the second column : LOAD RecordId, 2ndElement as NewColumn resident DataTable.
You'll end up with a new table that combines both columns in one. On the chart you'll need to use NewColumn as the dimension and Count(RecordId) as the expression.

this works for me:
Data:
LOAD * INLINE [
F1, F2
This, This
That, That
The Other, Something else
];
load F1 as Dim Resident Data;
join
Load F2 as Dim Resident Data ;
then use Dim as a Dimension and in the expresion write:
count(if(Dim=F1,F1)) +
count(if(Dim=F2,F2))

Related

Is possible do Select * form DynamicValue to perform a query like this in Navision?

Is possible do Select * form DynamicValue to perform a query like this in Navision?
Thanks in advance
To perform a sql query li this select * from DynamicValue You must do something like this.
Imagine that you have a table and you are going to show the data in a page or form.
Variables:
RecDynamicValue (Table).
PagDynamicValues (Page).
Code:
RecDynamicValue.RESET; //Clean filters
CLEAR(PagDynamicValues);
PagDynamicValues.SETTABLEVIEW(RecDynamicValue); //Set RecDynamicValue (Table)
PagDynamicValues.RUN; (Open Page)
In this code when page is open you can see al records from DynamicValue table like a Select * from DynamicValue.
If you need perform a loop for all records from DynamicValue table in code try this:
RecDynamicValue.RESET;
IF RecDynamicValue.FINDSET THEN REPEAT //Repeat clausule for a loop
//Loop...
//Loop...
//Loop...
UNTIL RecDynamicValue.NEXT = 0; //Repeat until last value
In all cases first you need declare a variable, SubType = Record and specified ID or name of record.
You can not change the value of the table variable by code.
But perhaps you can use RecordRef function to do that.
For example:
RecRef.OPEN(27); //Id of ItemTable
RecRef.FINDFIRST;
FldRef := RecRef.FIELD(3); // Item.Description;
FldRef.VALUE('New description');
RecRef.MODIFY;
In your case your DynamicValue is parameter to RecRef.OPEN("Your Dynamic Value") here you need specified value ID of your table.
You can also perform a loop using RecorRef.

Change field length afterwards

TABLES: VBRK.
DATA: BEGIN OF it_test,
BUKRS LIKE VBRK-BUKRS,
FKDAT LIKE VBRK-FKDAT,
END OF it_test.
DATA: wa_test LIKE it_test.
SELECT * FROM VBRK INTO CORRESPONDING FIELD OF wa_test.
IF wa_test-BUKRS = 'xxxx'.
wa_test-BUKRS = 'XXXXX' "Problem occurs here as the BUKRS allow 4 value
APPEND wa_test TO it_test.
ENDIF.
Then I want to map the internal table to output as ALV table. Is they any way to change the field length afterwards?
Apart from multiple issues in your code, you can't. If you need something similar to that, add an additional field to the structure with whatever size you require and copy the values over.
If the objective is to output something to the screen that is different(or differently formatted) that what is stored internally(or in the database), then the use of a data element with a conversion exit maybe the way to go.
For an example, look at the key fields of table PRPS.
Expanding the answer of vwegert:
The MOVE-CORRESPONDINGcommand (and SELECT ... INTO CORRESPONDING FIELDS) don't need the same field type. The content is converted. So you could define a 5-character field in your internal structure and copy the BUKRS-value into this 5-character field:
TABLES: VBRK.
DATA: BEGIN OF it_test,
BUKRS(5), "longer version of VBRK-BUKRS,
FKDAT LIKE VBRK-FKDAT,
END OF it_test.
DATA: tt_test TYPE STANDARD TABLE OF it_test.
* I would strongly recommend to set a filter!
SELECT * FROM VBRK INTO CORRESPONDING FIELD OF it_test.
IF it_test-BUKRS = 'xxxx'.
it_test-BUKRS = 'XXXXX'.
APPEND it_test to tt_test.
ENDIF.
ENDSELECT.
A pitfall: When you use it with ALV you will loose the field description. (on the other side, the field description of the original field will not fit any longer the new field.)

How do I use the "call transaction 'se11' and skip first screen" to activate the search box in ABAP?

What I am trying to do is use
Set Parameter ID 'DTB' Field 'z*'.
Call Transaction 'SE11' and skip First Screen.
At this point I want to activate the search box and take the results into an internal table. Any thoughts? Or is there a way to use the data base statistics to pull this information faster?
Instead of accessing the tables directly, you may want to use a semi-official API that not only handles the activation state, but also takes permissions into account as well:
DATA: lt_tables TYPE STANDARD TABLE OF rpy_tabl.
FIELD-SYMBOLS: <ls_table> TYPE rpy_tabl.
CALL FUNCTION 'RPY_TABLE_SELECT'
EXPORTING
table_name = 'Z*'
TABLES
tabl_inf_tab = lt_tables
EXCEPTIONS
cancelled = 1
not_found = 2
permission_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
* Implement suitable error handling here
ELSE.
LOOP AT lt_tables ASSIGNING <ls_table>.
CASE <ls_table>-tablclass.
WHEN 'TRANSP'. " Transparent table
* ...
WHEN 'INTTAB'. " Structure
* ...
WHEN 'CLUSTER'. " Cluster table
* ...
WHEN 'POOL'. " Pooled table
* ...
WHEN 'VIEW'. " Generated view structure
* ...
WHEN 'APPEND'. " Append structure
* ...
ENDCASE.
ENDLOOP.
ENDIF.
The code below will get what you want, you might need to add some more where clauses to only get active tables (AS4LOCAL EQ 'A')or only transparent tables (TABCLASS EQ 'TRANSP') since this table also contains structures.
DATA: t_tabname TYPE STANDARD TABLE OF tabname.
SELECT tabname INTO TABLE t_tabname FROM dd02l WHERE tabname LIKE 'Z%'.

Update new column with part of JSON column

I have a json column titled 'classifiers' with data like this:
[ { "category": "Building & Trades", "type": "Services"
, "subcategory": "Construction" } ]
I would like to pull each element and insert into columns on the same row titled, for example, 'category', 'type' and 'subcategory'.
This query pulls out what I want, in this case 'category':
SELECT parts->'category' AS category
FROM (SELECT json_array_elements(classifiers) AS parts FROM <tablename>) AS more_parts
I can't figure out the 'WHERE' part in an UPDATE/SET/WHERE type of query, for example:
UPDATE <table>
SET category = (SELECT parts->'category' AS category
FROM (SELECT json_array_elements(classifiers) AS parts
FROM <tablename>
) AS more_parts
) WHERE ???
Without WHERE multiple rows are returned.
I would like to pull each element and insert into columns on the same
row titled, for example, 'category', 'type' and 'subcategory'.
Sounds like you really want this:
UPDATE tbl
SET category = classifiers->0->'category'
,type = classifiers->0->'type'
,subcategory = classifiers->0->'subcategory'
Updates all rows. Requires Postgres 9.3+.
The first operator ->0 reverences the only object in the array (json array index starting from 0 unlike Postgres arrays, which start from 1 per default).
The second operator ->'category' gets the field from the object.
Refer to the manual here.

update an SQL table via R sqlSave

I have a data frame in R having 3 columns, using sqlSave I can easily create a table in an SQL database:
channel <- odbcConnect("JWPMICOMP")
sqlSave(channel, dbdata, tablename = "ManagerNav", rownames = FALSE, append = TRUE, varTypes = c(DateNav = "datetime"))
odbcClose(channel)
This data frame contains information about Managers (Name, Nav and Date) which are updatede every day with new values for the current date and maybe old values could be updated too in case of errors.
How can I accomplish this task in R?
I treid to use sqlUpdate but it returns me the following error:
> sqlUpdate(channel, dbdata, tablename = "ManagerNav")
Error in sqlUpdate(channel, dbdata, tablename = "ManagerNav") :
cannot update ‘ManagerNav’ without unique column
When you create a table "the white shark-way" (see documentation), it does not get a primary index, but is just plain columns, and often of the wrong type. Usually, I use your approach to get the columns names right, but after that you should go into your database and assign a primary index, correct column widths and types.
After that, sqlUpdate() might work; I say might, because I have given up using sqlUpdate(), there are too many caveats, and use sqlQuery(..., paste("Update....))) for the real work.
What I would do for this is the following
Solution 1
sqlUpdate(channel, dbdata,tablename="ManagerNav", index=c("ManagerNav"))
Solution 2
Lcolumns <- list(dbdata[0,])
sqlUpdate(channel, dbdata,tablename="ManagerNav", index=c(Lcolumns))
Index is used to specify what columns R is going to update.
Hope this helps!
If none of the other solutions work and your data is not that big, I'd suggest using sqlQuery() and loop through your dataframe.
one_row_of_your_df <- function(i) {
sql_query <-
paste0("INSERT INTO your_table_name (column_name1, column_name2, column_name3) VALUES",
"(",
"'",your_dataframe[i,1],",",
"'",your_dataframe[i,2],"'",",",
"'",your_dataframe[i,3],"'",",",
")"
)
return(sql_query)
}
This function is Exasol specific, it is pretty similar to MySQL, but not identical, so small changes could be necessary.
Then use a simple for loop like this one:
for(i in 1:nrow(your_dataframe))
{
sqlQuery(your_connection, one_row_of_your_df(i))
}