2023 May 18 7:22 PM
Hello,
I am building a small report where the user inserts material number and retrieves the material price (field KBETR in the table KONP). The material is inputted by the user, it must be used to retrieveve KNUMH and with this KNUMH the price will be retrieved from KONP.
MATNR is input field
Table A926: MATNR and KNUMH
Table KONP: KNUMH and KBETR.
I also need a date and a price list category to retrieve this price, both inputted by the user.
The code runs and works, but whenever I have more than one material in the input field, it attributes the price(s) of the first material to the other ones down in the list. I think the problem is here: AND matnr IN @mymatnr.
Sorry if the question is dumb, I am a newbie and I have been desperately googling for three days.
Yo can answer in German, English, Russian, any language.
```
REPORT Z_TEST_1926_L_3.
TABLES: mvke, a926, konp .
SELECT-OPTIONS: mymatnr FOR mvke-matnr.
PARAMETERS:
mydatum LIKE a926-datbi OBLIGATORY,
mypltyp LIKE a926-pltyp OBLIGATORY.
TYPES: BEGIN OF itab_wa,
matnr TYPE mvke-matnr,
vkorg TYPE mvke-vkorg,
kbetr TYPE konp-kbetr,
END OF itab_wa.
DATA: itab_wa .
DATA: itab TYPE TABLE OF itab_wa.
DATA: itab1 LIKE LINE OF itab .
SELECT matnr, vkorg INTO ( @itab1-matnr, @itab1-vkorg )
FROM mvke
WHERE matnr IN @mymatnr .
IF sy-subrc = 0 OR sy-subrc = 4 .
CLEAR konp-kbetr .
SELECT knumh INTO @konp-knumh "retrieve knumh from a926 based on matnr, pricelist and date
FROM A926
WHERE datbi >= @mydatum
AND pltyp = @mypltyp
AND matnr IN @mymatnr.
SELECT SINGLE kbetr INTO ( @itab1-kbetr ) "retrieve kbetr from konp
FROM konp
WHERE knumh = @konp-knumh . "merge the knumh from a926 and from konp
APPEND itab1 TO itab .
ENDSELECT .
ENDIF .
ENDSELECT .
* Create the ALV Grid table
TRY .
DATA: o_salv TYPE REF TO cl_salv_table.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = o_salv
CHANGING
t_table = itab.
o_salv->get_functions( )->set_all( abap_true ) .
o_salv->display( ) .
CATCH cx_salv_msg .
ENDTRY.
```
2023 May 18 8:25 PM
You read the first itab for only one material number at a time, and in the following statement you don't use the last read matnr but the original select-option, so the select return always the same record (depending on the index choosed by the optimizer)
You could
2023 May 18 8:14 PM
Edit the question and use the Code option, paste the code in the area (without formating) so it will be easier to read)
2023 May 18 8:25 PM
You read the first itab for only one material number at a time, and in the following statement you don't use the last read matnr but the original select-option, so the select return always the same record (depending on the index choosed by the optimizer)
You could
2023 May 19 11:27 AM