2018 Oct 22 9:40 AM
I am working on abap 740 / SP 018 in SAP ERP
In a method, I get the above syntax error I do not understand on a rather complex table constructor expression.
When I reconstruct an equivalent with loop and append, everything works fine. Since it's already the second time I had to replace a table construction with a loop, I'd like to know what's wrong hiere...
You can use the coding to reproduce this.
report zp_tmp_expr_syn_err.
types:
begin of gty_s_material,
material type matnr,
mrp_group type disgr,
end of gty_s_material,
gty_t_sales_req type standard table of vbbe with default key
with non-unique sorted key itm components vbeln posnr,
gty_t_plannedord type standard table of plaf with default key
with non-unique sorted key itm components kdauf kdpos,
gty_t_stocks type standard table of mska with default key
with non-unique sorted key itm components vbeln posnr,
gty_t_prodord type standard table of mdfa with default key
with non-unique sorted key itm components kdauf kdpos,
gty_t_material type sorted table of gty_s_material
with unique key material,
begin of gty_s_production,
t_sales_req type gty_t_sales_req,
t_plannedord type gty_t_plannedord,
t_prodord type gty_t_prodord,
t_stocks type gty_t_stocks,
t_material type gty_t_material,
end of gty_s_production.
class lcl_pp_item definition.
public section.
methods:
constructor
importing is_prod type gty_s_production
iv_doc_number type vbeln
iv_itm_number type posnr.
endclass.
class lcl_app definition.
public section.
methods:
main
raising zcx_gens.
private section.
types:
begin of gty_s_pp_item,
doc_number type vbeln,
itm_number type posnr,
attrib_name type atnam,
attrib_val type atwrt,
o_pp_item type ref to lcl_pp_item,
end of gty_s_pp_item,
gty_t_pp_items type standard table of gty_s_pp_item with default key
with unique sorted key itm components doc_number itm_number,
begin of gty_s_item,
doc_number type vbeln,
itm_number type posnr,
material type matnr,
mrp_group type disgr,
short_text type arktx,
attrib_name type atnam,
attrib_val type atwrt,
special type flag,
end of gty_s_item,
gty_t_items type standard table of gty_s_item
with non-unique sorted key itm components doc_number itm_number.
endclass.
start-of-selection.
new lcl_app( )->main( ).
class lcl_app implementation.
method main.
data: lt_items type gty_t_items,
ls_production type gty_s_production,
lt_pp_items type gty_t_pp_items.
loop at ls_production-t_sales_req into data(ls_req)
group by ( doc_number = ls_req-vbeln itm_number = ls_req-posnr
material = ls_req-matnr plant = ls_req-werks )
into data(ls_itm).
" this loop does not have syntax errors
loop at ls_production-t_material
into data(ls_mat)
where material = ls_itm-material.
data(lv_ix_color) = line_index( lt_items[
key itm doc_number = ls_itm-doc_number itm_number = ls_itm-itm_number ] ).
data(ls_color) = cond #( when lv_ix_color > 0 then lt_items[ lv_ix_color ] ).
append value #(
doc_number = ls_itm-doc_number
itm_number = ls_itm-itm_number
attrib_name = ls_color-attrib_name
attrib_val = ls_color-attrib_val
o_pp_item = new #( is_prod = ls_production
iv_doc_number = ls_itm-doc_number
iv_itm_number = ls_itm-itm_number ) ) to lt_pp_items.
endloop.
endloop.
" on the following line, I get
" '. the formal parameter is final. structures in an OO context must be compatible.'
lt_pp_items = value #(
for groups s_itm of s_req in ls_production-t_sales_req
group by ( doc_number = s_req-vbeln itm_number = s_req-posnr
material = s_req-matnr plant = s_req-werks )
for s_mat in ls_production-t_material where ( material = s_itm-material )
let ix_color = line_index( lt_items[
key itm doc_number = s_itm-doc_number itm_number = s_itm-itm_number ] )
s_color = cond #( when ix_color > 0 then lt_items[ ix_color ] ) in
( doc_number = s_itm-doc_number
itm_number = s_itm-itm_number
attrib_name = s_color-attrib_name
attrib_val = s_color-attrib_val
o_pp_item = new #( is_prod = ls_production
iv_doc_number = s_itm-doc_number
iv_itm_number = s_itm-itm_number ) ) ).
endmethod.
endclass.
class lcl_pp_item implementation.
method constructor.
endmethod.
endclass.
2018 Oct 25 2:46 PM
quynh.doanmanh 's proposal might be correct - but I do not know how to evaluate this. However, eyjfc made a very useful point introducing the filter statement. Thanks to all.
2018 Oct 22 3:28 PM
Hello Jörg,
what is the loop over ls_production-t_material doing? variable ls_mat is not used.
JNN
2018 Oct 23 6:43 AM
The loop is used to restrict the lines processed of t_sales_req to materials in the table t_material. In fact, I could have used "transporting no fields" here.
2018 Oct 23 7:27 PM
LOOP AT ls_production-t_sales_req INTO DATA(ls_req)
GROUP BY ( doc_number = ls_req-vbeln
itm_number = ls_req-posnr
material = ls_req-matnr
plant = ls_req-werks ) INTO DATA(ls_itm).
" this loop does not have syntax errors
CHECK line_exists( ls_production-t_material[ material = ls_itm-material ] ).
DATA(lv_ix_color) = line_index( lt_items[ KEY itm COMPONENTS doc_number = ls_itm-doc_number
itm_number = ls_itm-itm_number ] ).
DATA(ls_color) = COND #( WHEN lv_ix_color > 0 THEN lt_items[ lv_ix_color ] ).
APPEND VALUE #(
doc_number = ls_itm-doc_number
itm_number = ls_itm-itm_number
attrib_name = ls_color-attrib_name
attrib_val = ls_color-attrib_val
o_pp_item = NEW #( is_prod = ls_production
iv_doc_number = ls_itm-doc_number
iv_itm_number = ls_itm-itm_number ) ) TO lt_pp_items.
ENDLOOP.
* on the following line, I get
* '. the formal parameter is final. structures in an OO context must be compatible.'
lt_pp_items = VALUE gty_t_pp_items(
LET workload = FILTER #( ls_production-t_sales_req IN ls_production-t_material
WHERE matnr = material ) IN
FOR GROUPS s_itm OF s_req IN workload
GROUP BY ( doc_number = s_req-vbeln
itm_number = s_req-posnr
material = s_req-matnr
plant = s_req-werks )
LET ix_color = line_index( lt_items[
KEY itm COMPONENTS doc_number = s_itm-doc_number
itm_number = s_itm-itm_number ] )
s_color = COND gty_s_item( WHEN ix_color > 0 THEN lt_items[ ix_color ] ) IN
( doc_number = s_itm-doc_number
itm_number = s_itm-itm_number
attrib_name = s_color-attrib_name
attrib_val = s_color-attrib_val
o_pp_item = NEW lcl_pp_item( is_prod = ls_production
iv_doc_number = s_itm-doc_number
iv_itm_number = s_itm-itm_number ) )
).OK, this is how I understand your logic.
JNN
2018 Oct 24 5:41 AM
Your solution is working - thank you. I didn't know about this form of the filter expression.
However, the question remains: why is there a syntax error in the first version?
2018 Oct 24 9:13 AM
Hello Jörg,
my guess would be that the additional FOR is generating a result of type
STANDARD TABLE OF gty_t_pp_items
while you are expecting the type
gty_t_pp_items.
2018 Oct 24 6:24 PM
Hello Jörg,
it seems to me the expression can be simplified with VALUE #( ... OPTIONAL )
LET s_color = VALUE #( lt_items[ KEY itm COMPONENTS doc_number = s_itm-doc_number
itm_number = s_itm-itm_number ] OPTIONAL ) IN
( doc_number = .... ) )
2018 Oct 24 6:21 AM
lt_pp_items =VALUE gty_t_pp_items(Jacques has made a type specification. This could be the reason.
There are interesting things that I notice when working with ABAP 7.4. I tried moving data between two internal tables itab1 and itab2 with OCCURS specification (I hope the ABAP gods forgive me for this blasphemy ) using this statement,
itab1 = CORRESPONDING #(itab2) the contents did not move. Now, I use the regular TYPES declaration and the above statement works.
2018 Oct 24 6:36 AM
There is already a type for lt_pp_items
data: lt_items type gty_t_items,
ls_production type gty_s_production,
lt_pp_items type gty_t_pp_items.
so this should not be the reason. However, I tried it out
" on the following line, I get
" '. the formal parameter is final. structures in an OO context must be compatible.'
lt_pp_items = value gty_t_pp_items(
for groups s_itm of s_req in ls_production-t_sales_req
group by ( doc_number = s_req-vbeln itm_number = s_req-posnr
material = s_req-matnr plant = s_req-werks )
for s_mat in ls_production-t_material where ( material = s_itm-material )
let ix_color = line_index( lt_items[
key itm doc_number = s_itm-doc_number itm_number = s_itm-itm_number ] )
s_color = cond #( when ix_color > 0 then lt_items[ ix_color ] ) in
( doc_number = s_itm-doc_number
itm_number = s_itm-itm_number
attrib_name = s_color-attrib_name
attrib_val = s_color-attrib_val
o_pp_item = new #( is_prod = ls_production
iv_doc_number = s_itm-doc_number
iv_itm_number = s_itm-itm_number ) ) ).
The syntax error remains.
Regarding your question: when you declare a table with occurs, two data objects are created:
- the table
- the head line
to specify the table, you have to use brackets, otherwise - in statements with operators that are not explicitely meant to be talbes, the header line is affected. So use
itab1[] = CORRESPONDING #( itab2[] )
instead.
2018 Oct 25 6:27 AM
i think it because the FOR statement cant be nested under FOR GROUPS (although you can use nested FOR).
in all example, its always FOR ..IN GROUP after FOR GROUPS...
the FILTER solution worked because its group all value to 1 help variable first then FOR GROUPS...
in your such complex structure, i think its might better to use MESH instead.
2018 Oct 25 2:46 PM
quynh.doanmanh 's proposal might be correct - but I do not know how to evaluate this. However, eyjfc made a very useful point introducing the filter statement. Thanks to all.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |