Error : Field "S_MARA-MATNR" is unkown during FOR statement - abap

DATA: t_mara type STANDARD TABLE OF mara WITH EMPTY KEY.
DATA(t_data1) = VALUE ty_data( FOR s_mara IN t_mara ( s_mara–matnr ) ).
I am trying to implement a similar code using FOR statement but I am getting an error that the field is unknown in the work area even though it would be declared inline.
Can you please let me know what went wrong? This is my first time I am facing this error on FOR loop.

Not sure because you are not providing too much detail but try this:
DATA t_mara type STANDARD TABLE OF mara WITH EMPTY KEY.
DATA(t_data1) = VALUE ty_data( FOR s_mara IN t_mara ( matnr = s_mara-matnr ) ).

Related

Joining Two Tables with Different Data types MS ACCESS - 'type mismatch in expression' error

I'm trying to run a query on access using two live CSVs which has a common field with different data types(numbers and short text). I've discovered that you can join different data types using 'CStr'. I've added the 'CStr' to my code on the sql view. Please find the see the code below.
This gives me the output i want on access and i can now see the output when i click on 'datasheet view'. However, when i try to export the data (i'm actually trying create a export specification so that i can export a csv using macro) as a csv i'm getting a 'type mismatch in expression' error message.
Here's my code:
SELECT Sixthform_Reg_Year_Groups.Forename,
Sixthform_Reg_Year_Groups.Surname,
Sixthform_Reg_Year_Groups.Reg, Students.objectGUID
FROM Sixthform_Reg_Year_Groups INNER JOIN
Students
ON CStr(Sixthform_Reg_Year_Groups.Person_id) = Students.employeeID
WHERE (((Sixthform_Reg_Year_Groups.Reg)="12E"));`
I've also tried adding 'CStr' on both sides. as below, but experiencing the same issue.
FROM Sixthform_Reg_Year_Groups INNER JOIN
Students
ON CStr(Sixthform_Reg_Year_Groups.Person_id) = CStr (Students.employeeID)
WHERE (((Sixthform_Reg_Year_Groups.Reg) = "12E"));`
And of course, without 'CStr' i can't even view the output on 'datasheet view'. Every time when i click on datasheet view it's giving me the 'type mismatch in expression' error message.
Any help in resolving this would be much appreciated.
Thanks in advance.
Additinal info: the data types are EmpoyeeID is 'Short Text' and Person ID is 'Number'
Try the other way round:
ON Sixthform_Reg_Year_Groups.Person_id = Val(Students.employeeID)
and/or prevent Null errors:
ON CStr(Nz(Sixthform_Reg_Year_Groups.Person_id, 0)) = Nz(Students.employeeID)
OK guys, I've managed to resolve this issue, It turned out to be simple in the end. This is what i did.
Basically, I re imported the linked table. This time on the import window i clicked on 'advanced' and changed the data type to 'short text' on the 'person ID' column to match with the 'employeeID' data type. And then all problems solved. (I didn't know you could do this)
Thank you all for your replies. Going through your comments guided me to the right path.
Much appreciated.

How to retrieve a specific field from a list output?

I don't have any developer rights in my SAP-System but I found a way to write some ABAP-Code in a tiny "User-Exit" box (I don't know if that's what you call it) inside a report.
I'm trying to submit a HR-Report and plug it's outcoming PERNR into that same report again.
There's a syntax-error that is telling me that t_list doesn't have a component with the Name PERNR.
What do I have to do in order to get this to work?
DATA: t_list TYPE TABLE OF abaplist WITH HEADER LINE,
seltab TYPE TABLE OF rsparams,
selline LIKE LINE OF seltab.
*I found out that the name of the selection field in the Report-GUI is "PNPPERNR" and tested it
selline-selname = 'PNPPERNR'.
selline-sign = 'I'.
selline-option = 'EQ'.
SUBMIT Y5000112
USING SELECTION-SET 'V1_TEST'
EXPORTING LIST TO MEMORY
AND RETURN.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = t_list
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
WRITE 'Unable to get list from memory'.
ELSE.
LOOP AT t_list.
*The Problem is here: how do I get the pnppernr out of t_list, it's the first column of the report output
selline-low = t_list-pernr.
append selline to seltab.
ENDLOOP.
SUBMIT Y5000112
WITH SELECTION-TABLE seltab
USING SELECTION-SET 'V2_TEST'
AND RETURN.
ENDIF.
Use the function module LIST_TO_ASCI to decode the contents of t_list into something readable. This answer contains some sample code including the data types required. At this point, the data you're looking for will probably occur at the same column range in the output. Use the standard substring access methods - e. g. line+42(21) to obtain the part of the line you need.
The vwegert's answer is more than useful! In my previous answer I forgot to mention LIST_TO_ASCI FM :)
The only thing I can add is that parsing of result lines has no universal solution and greatly depends on its structure. Usually it is done like:
LOOP AT t_list.
SPLIT t_list AT '|' INTO <required_structure>.
selline-low = <required_structure>-pernr.
APPEND selline TO seltab.
ENDLOOP.
where <`required_structure> is your Y5000112 output structure. But this may be not so simple and may require additional manipulations.

Mule ESB: How to do Condition checking in Datamapper using Xpath

i'm facing issue in xpath-I need do a check two attribute values, if the condition satisfies need to do hard code my own value. Below is my xml.
I need to check the condition like inside subroot- if ItemType=Table1 and ItemCondition=Chair1 then i have to give a hard coded value 'Proceed'( this hard coded value i will map to target side of datamapper).
<Root>
<SubRoot>
<ItemType>Table1</ItemType>
<ItemCondition>Chair1</ItemCondition>
<ItemValue>
.......
</ItemValue>
</SubRoot>
<SubRoot>
<ItemType>Table2</ItemType>
<ItemCondition>chair2</ItemCondition>
<ItemValue>
.......
</ItemValue>
</SubRoot>
....Will have multiple subroot
</Root>
I have tried to define rules as below, but it is throwing error
Type: String
Context:/Root
Xpath: substring("Proceed", 1 div boolean(/SubRoot[ItemType="Table1" and ItemCondition="Chair1"]))
But it is throwing error like
net.sf.saxon.trans.XPathException: Arithmetic operator is not defined for arguments of types (xs:integer, xs:boolean)
Is there any other shortcut way to perform this.Could you please help me, i have given lot more effort. Not able to resolve it. Thanks in advance.
I am not sure where you are applying this but the XPath expression you are looking for is:
fn:contains(/Root/SubRoot[2]/ItemCondition, "chair") and fn:contains(/Root/SubRoot[2]/ItemType, "Table")
So here is an example returning "Proceed" or "Stop" as appropriate:
if (fn:contains(/Root/SubRoot[1]/ItemCondition, "Chair") and fn:contains(/Root/SubRoot[2]/ItemType, "Table")) then 'Proceed' else 'Stop'
To implement the above condition , i was initially tired to do in xpath, gave me lot of error. I have implemented by simple if else condition in script part of data mapper
if ( (input.ItemType == 'Table') and (input.ItemCondition == 'chair')) {
output.Item = 'Proceed'}
else {
output.Item = 'Stop '};
Make sure about your precedence. Example, Here in the xml structure( or converted POJO) ItemType has to be checked first then followed with ItemCondition.
&& not seems to be working for me, change to 'and' operator
If you were first time trying to implement the logic. It may help you.

ActiveRecord where clause error

I'm a newbie to rails.I have a model called OfflineExport. In the table I have data like this
#<OfflineExport id: 2,
parameters:
{"project_id"=>"3",
"type"=>"submissions",
"filters"=>{"task_type"=>"",
"corrections"=>"", "grade"=>"",
"min_duration"=>"", "after"=>"",
"max_duration"=>"", "reviews"=>"",
"before"=>""},
"send_email"=>"true",
"options"=>{"offline_record_id"=>2}}>
Am trying to fetch parameters["project_id"] in where clause like
OfflineExport.where("parameters[project_id] = '3'")
But am getting error like:
ActiveRecord::StatementInvalid: PGError: ERROR: cannot subscript type text because it is not an array
can anyone help me in solving this?
It seems that you have a serialized column in your model. Something like this: serialize :parameters. This means the data is stored in the database not in an easily readable format, which leads that you can not query on it. Same as here.
Solution: extract the field you want to query on, and make a column for it.

Yii framework - picking up field value from other model

I have been struggling with this, i have two models and showing data in Cgridview with one model, this model contains some id's whose values are in different table
So, i have added
'value'=> 'TblAreaoflaw::model()->FindByPk($data->typeoflaw)->areaoflaw'
which is giving this error
"Trying to get property of non-object"
Might be due to this reason that the some records doesn't exist in the TblAreaoflaw. Can't we check in this line through isset?
When i put static value, it work well, like
'value'=> 'TblAreaoflaw::model()->FindByPk(5)->areaoflaw',
Could anyone please help
thanks a lot
The error you get is because this expression TblAreaoflaw::model()->FindByPk($data->typeoflaw) is returning null. This means that you are effectively trying to get null->areaoflaw which won't work (this is what the error message "Trying to get property of non-object" clarifies).
My best guess is that $data->typeoflaw returns a non-existing primary key for the TblAreaoflaw model.
Make sure :
TblAreaoflaw is actually a model, I doubt its Areaoflaw
You have database specified primary key which is the id (5) you are passing
Try:
'value'=> '(TblAreaoflaw::model()->FindByPk($data->typeoflaw)->areaoflaw) ?
: "default or null value"'
Obviously substitute the null string to whatever you want. You may need to adjust the condition to use !empty() or similar, but see how it goes. (And if you do that or aren't using PHP 5.3, use the full ternary expression.)