2021 Jul 20 12:43 PM
Im having a little trouble building the logic.
I need to retrieve the highest concat column value per material
2021 Jul 20 2:37 PM
Hi Adrian,
Take a look at the documentation for the openSQL GROUP BY clause.
Adjust your original database query if possible to avoid selecting unnecessary data.
Alternatively, if your system supports it (>7.40), you can select from your internal table:
SELECT
FROM @original_itab AS material
FIELDS material~matnr,
MAX( material~concat ) AS max_concat_for_material
GROUP BY material~matnr
INTO TABLE @DATA(materials_with_max_concat).
Finally, another option is sorting your itab, loop over it, and extract the maximum value per material number.
Hello kuser0320
Just sort the table by CONCAT column descending and read the first row - see SAP Help SORT itab
Best regard
Dominik Tylczynski
2021 Jul 20 1:49 PM
Hi Adrian,
How exactly are you having trouble/what have you tried to achieve the desired result?
Have you tried searching the Q&A section for similar questions?
2021 Jul 20 1:56 PM
Yes, I already searched for some Q&A sections, I only saw on how to get the highest value on the column. But what I need is to get the highest value in concat column per material
2021 Jul 20 2:33 PM
Hello kuser0320
Just sort the table by CONCAT column descending and read the first row - see SAP Help SORT itab
Best regard
Dominik Tylczynski
2021 Jul 20 2:38 PM
Hello Dominik, I can't just sort concat column. Your solution will just give me the highest value in concat column. But what I need is the highest value for every matnr column
2021 Jul 20 2:43 PM
2021 Jul 20 2:36 PM
If you just need to order the data:
If you need a new table with just the highest values:
But if you have problem with this "logic", you need to go back to the basics of programming, I fear. No offense.
2021 Jul 20 2:37 PM
Hi Adrian,
Take a look at the documentation for the openSQL GROUP BY clause.
Adjust your original database query if possible to avoid selecting unnecessary data.
Alternatively, if your system supports it (>7.40), you can select from your internal table:
SELECT
FROM @original_itab AS material
FIELDS material~matnr,
MAX( material~concat ) AS max_concat_for_material
GROUP BY material~matnr
INTO TABLE @DATA(materials_with_max_concat).
Finally, another option is sorting your itab, loop over it, and extract the maximum value per material number.
2021 Jul 20 2:39 PM
Hello ,
Please refer to below piece of code:
Output is :
2562 20251
2562 20221
2705 20211
2705 20201
types: begin of ty_mara,
matnr type matnr,
concat(15) type c,
end of ty_mara.
types: ty_t_mara type standard table of ty_mara.
data: ls_mara type ty_mara.
data : lt_mara type standard table of ty_mara.
ls_mara-matnr = '000000000000002705'.
ls_mara-concat = '20201'.
append ls_mara to lt_mara.
ls_mara-matnr = '000000000000002705'.
ls_mara-concat = '20211'.
append ls_mara to lt_mara.
ls_mara-matnr = '000000000000002562'.
ls_mara-concat = '20251'.
append ls_mara to lt_mara.
ls_mara-matnr = '000000000000002562'.
ls_mara-concat = '20221'.
append ls_mara to lt_mara.
sort lt_mara by matnr concat descending.
clear ls_mara.
loop at lt_mara assigning field-symbol(<lfs_mara>).
write :/ <lfs_mara>-matnr .
write : <lfs_mara>-concat.
endloop.
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |