Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ABAP retrieve KONP-KBETR from MATNR

laurammf
Discoverer
0 Kudos
843

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.

```

1 ACCEPTED SOLUTION

raymond_giuseppi
Active Contributor
753

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

  • Use the read matnr (itab1-matnr) of the first external select in the internal selects (keeping most or your, one record by one record, code)
  • For performance: Change your code, filling internal table in on select statement, use join when available or for all entries to fill other internal tables and then build the final table (use sorted type table to optimize the loop statements performance)

3 REPLIES 3

raymond_giuseppi
Active Contributor
0 Kudos
753

Edit the question and use the Code option, paste the code in the area (without formating) so it will be easier to read)

raymond_giuseppi
Active Contributor
754

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

  • Use the read matnr (itab1-matnr) of the first external select in the internal selects (keeping most or your, one record by one record, code)
  • For performance: Change your code, filling internal table in on select statement, use join when available or for all entries to fill other internal tables and then build the final table (use sorted type table to optimize the loop statements performance)

0 Kudos
753

It worked, thank you very much!