‎2020 Sep 16 8:46 AM
Hi Gurus,
I need a lil help in my code. The scenario is that my report is showing a single specification against a single inspection lot although in the QAMV table there are multiple specifications of a given inspection lots. I need help there where i might need tweaking in my code. I have also come up to the deduction that the loop it_data has a single record that's why it's not looping all the specifications. Need a little bit of help from the experts in this regards.
FORM get_itab_data .
SELECT * INTO TABLE @DATA(it_data)
FROM qals
WHERE prueflos IN @s_insp.
SELECT matnr, maktx
FROM makt INTO TABLE @DATA(lt_maktx)
FOR ALL ENTRIES IN @it_data
WHERE matnr EQ @it_data-matnr.
select prueflos,vorglfnr,merknr,kurztext
FROM qamv INTO TABLE @DATA(lt_kurztext)
FOR ALL ENTRIES IN @it_data
WHERE prueflos eq @it_data-prueflos.
* and vorglfnr eq @it_data-vorglfnr
* and merknr eq @it_data-merknr.
*-------Specification-------------------*
SELECT prueflos,GRUPPE1,vorglfnr,merknr
from qamr INTO TABLE @DATA(lt_gruppe1)
FOR ALL ENTRIES IN @it_data
WHERE prueflos eq @it_data-prueflos.
if sy-subrc = 0.
select AUSWAHLMGE,CODEGRUPPE
from qpac into TABLE @DATA(lt_auswahlmge)
for ALL ENTRIES IN @lt_gruppe1
where codegruppe eq @lt_gruppe1-gruppe1.
SELECT AUSWAHLMGE,ktx01
from qpam INTO TABLE @data(lt_ktx01)
FOR ALL ENTRIES IN @lt_auswahlmge
where auswahlmge eq @lt_auswahlmge-auswahlmge.
ENDIF.
loop at it_data INTO DATA(ls_data).
CLEAR ls_output.
ls_output-prueflos = ls_data-prueflos.
ls_output-matnr = ls_data-matnr.
ls_output-charg = ls_data-charg.
READ TABLE lt_maktx REFERENCE INTO DATA(ld_maktx)
WITH KEY matnr = ls_data-matnr.
IF sy-subrc = 0.
ls_output-maktx = ld_maktx->maktx.
ENDIF.
READ TABLE lt_kurztext REFERENCE INTO DATA(ld_kurztext)
WITH KEY prueflos = ls_data-prueflos.
IF sy-subrc = 0.
ls_output-kurztext = ld_kurztext->kurztext.
ENDIF.
sort lt_gruppe1 BY merknr.
READ TABLE lt_gruppe1 REFERENCE INTO DATA(ld_gruppe1)
with key prueflos = ls_data-prueflos .
if sy-subrc = 0.
read TABLE lt_auswahlmge REFERENCE INTO DATA(ld_auswahlmge)
with key codegruppe = ld_gruppe1->gruppe1.
if sy-subrc = 0.
READ TABLE lt_ktx01 REFERENCE INTO DATA(ld_ktx01)
with KEY auswahlmge = ld_auswahlmge->auswahlmge.
if sy-subrc = 0.
ls_output-ktx01 = ld_ktx01->ktx01.
endif.
endif.
endif.
append ls_output to it_output.
endloop.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form build_layout
*&---------------------------------------------------------------------*
* Set Layout For ALV Display
*----------------------------------------------------------------------*
FORM display_alv.
*/.. Set field catalogs for alv
PERFORM get_fieldcatalog.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_callback_top_of_page = 'TOP-OF-PAGE'
is_layout = gs_layout
it_fieldcat = gt_fcat
i_save = 'A'
TABLES
t_outtab = it_output
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM.
**&---------------------------------------------------------------------*
**& Form GET_FIELDCATALOG
**&---------------------------------------------------------------------*
** Create field catalog from dictionary structure
**----------------------------------------------------------------------*
** --> p_struc_name Stucture Name
** --> p_rtname Reference Table Name
** --> p_repid Program Name
** <-> c_fcat Field Catalog
**----------------------------------------------------------------------*
FORM get_fieldcatalog.
CLEAR: gs_fcat.
REFRESH: gt_fcat.
gs_fcat-col_pos = 1.
gs_fcat-fieldname = 'PRUEFLOS'.
gs_fcat-tabname = 'IT_OUTPUT'.
gs_fcat-seltext_m = 'Inspection Lot'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.
gs_fcat-col_pos = 2.
gs_fcat-fieldname = 'MATNR'.
gs_fcat-tabname = 'IT_OUTPUT'.
gs_fcat-seltext_m = 'Material'.
gs_fcat-outputlen = '12'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.
gs_fcat-col_pos = 3.
gs_fcat-fieldname = 'MAKTX'.
gs_fcat-tabname = 'IT_OUTPUT'.
gs_fcat-seltext_m = 'Material Description'.
gs_fcat-outputlen = '12'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.
gs_fcat-col_pos = 4.
gs_fcat-fieldname = 'CHARG'.
gs_fcat-tabname = 'IT_OUTPUT'.
gs_fcat-seltext_m = 'Batch'.
gs_fcat-outputlen = '12'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.
gs_fcat-col_pos = 5.
gs_fcat-fieldname = 'KURZTEXT'.
gs_fcat-tabname = 'IT_OUTPUT'.
gs_fcat-seltext_m = 'Test Parameter'.
gs_fcat-outputlen = '12'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.
gs_fcat-col_pos = 6.
gs_fcat-fieldname = 'KTX01'.
gs_fcat-tabname = 'IT_OUTPUT'.
gs_fcat-seltext_m = 'Specification'.
gs_fcat-outputlen = '12'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.
‎2020 Sep 16 9:28 AM
humza_immi,
You have clearly mentioned that the Table at which the LOOP is applied has only one entry. In that case watch closely how the table is being filled.
First Check the below Query, check the number of entries you get in debugging and in backend:
SELECT matnr, maktx
FROM makt INTO TABLE @DATA(lt_maktx)
FOR ALL ENTRIES IN @it_data
WHERE matnr EQ @it_data-matnr.Then proceed to check the next query similarly both in debugging and in back end.
select prueflos,vorglfnr,merknr,kurztext
FROM qamv INTOTABLE@DATA(lt_kurztext)FORALLENTRIESIN@it_data
WHERE prueflos eq@it_data-prueflos.This should definitely be a data issue, kindly check and let us know.
Regards!
‎2020 Sep 16 9:33 AM
I've checked these queries and data is absolutely fine in these queries when i checked it from the debugger but i'm not getting it that why is it not looping against the selected inspection lot. the following query is showing 5 specifications results but showing a single record in the alv as it is looping only once.
select prueflos,vorglfnr,merknr,kurztext
FROM qamv INTOTABLE@DATA(lt_kurztext)FORALLENTRIESIN@it_data
WHERE prueflos eq@it_data-prueflos.
‎2020 Sep 16 9:39 AM
‎2020 Sep 16 9:49 AM
humza_immi,,
Your final entries purely dependent on the entries in IT_DATA, tell us what is the number of entries in IT_DATA.
Regards!
‎2020 Sep 16 10:27 AM
‎2020 Sep 16 11:09 AM
humza_immi,
That is the answer for you.
You are actually looping a table with one entry and that means the Loop iteration will run only once, thus the output will yield only one entry irrespective of the entries in other table.
In case you wanted to display all the five entries of table lt_kurztext then you can follow any of the below method:
1) Simply loop at the table lt_kurztext instead of IT_DATA. (Recommended)
2) You can also write a loop of lt_kurztext inside the loop of IT_DATA. (This Would reduce the performance -> Not Recommended unless the business requirement demands).
Hope this solves your issue!
Regards!
‎2020 Sep 23 12:35 PM
satishkumarbalasubramanian i tried both your methods but still it didn't solved the problem for me. looping at lt_kurztext was giving me alot of errors and looping it inside it_data wasn't giving me my desired results.