2007 Jul 19 8:08 AM
hi experts
Again I am facing the same problem, which we discussed yesterday.
actually my requirement is to read the duplicate matnr also.
before the form, i had the following query.
select matnr stlal STLAN from mast
into corresponding fields of table ITAB1
for all entries in ITAB
where matnr = itab-matnr.
then i corrected my coding as per our friend suggetion.
LOOP AT itab INTO wa.
l_index = sy-tabix.
SELECT SINGLE stlal stlan matnr
into corresponding fields of wa
FROM mast
WHERE matnr = wa-matnr.
if sy-subrc = 0.
MODIFY itab FROM wa INDEX l_index.
endif.
ENDLOOP.
now my problem is, am not able to read all the value of STLAL.
how can we read all STLAL , shall i remove single from the query.
Thanks in advance.
Regards
Rajaram
hi experts
Again I am facing the same problem, which we discussed yesterday.
actually my requirement is to read the duplicate matnr also.
before the form, i had the following query.
select matnr stlal STLAN from mast
into corresponding fields of table ITAB1
for all entries in ITAB
where matnr = itab-matnr.
then i corrected my coding as per our friend suggetion.
LOOP AT itab INTO wa.
l_index = sy-tabix.
SELECT SINGLE stlal stlan matnr
into corresponding fields of wa
FROM mast
WHERE matnr = wa-matnr.
if sy-subrc = 0.
MODIFY itab FROM wa INDEX l_index.
endif.
ENDLOOP.
now my problem is, am not able to read all the value of STLAL.
how can we read all STLAL , shall i remove single from the query.
Thanks in advance.
Regards
Rajaram
2007 Jul 19 8:13 AM
better options is to change ur query to:
select <b>*</b> from mast
into corresponding fields of table ITAB1
for all entries in ITAB
where matnr = itab-matnr.
for this u will have to change the structure of itab1 to have all the fields from MAST table.
After this query you can separate out all the fields required from ITAB1.
other options is as you said remove SINGLE from the query and append all the records from MAST to ITAB1.
LOOP AT ITAB.
SELECT (required fields) <b>APPENDING</b> CORRESPONDING FIELDS OF ITAB1 FROM MAST
WHERE MATNR = ITAB-MATNR.
ENDLOOP.
2007 Jul 19 8:14 AM
Hi
What data you have in ITAB.
Related to Material Data..
first write the select statment for MAST table into ITAB.
Then modify this MAST data with other data
In the given code as you are using select Single and in the where class you are giving a single material, where as for a single material there will be multiple STLAL fields. so this is wrong.
<b>Reward points for useful Answers</b>
Regards
Anji
2007 Jul 19 8:15 AM
hi,
dont use select inside the loop statement..
your first query is correct
<b>select matnr stlal STLAN from mast
into corresponding fields of table ITAB1
for all entries in ITAB
where matnr = itab-matnr.</b>
try to remove into coresponding values of table itab1
you can difine the itab1 with three fields-- matnr stlal stlan
<b>select matnr stlal STLAN from mast
into table ITAB1
for all entries in ITAB
where matnr = itab-matnr.</b>
you will get all the values present in database for your selection
rewards if useful,
regards,
nazeer
2007 Jul 19 9:02 AM
hi nazeer
i can get all the values when using for all entries but it will delete the duplicate matnr.
but i want the duplicate matnr also.
that's why i went for the above code.
Regards
Rajaram
2007 Jul 19 9:19 AM
Hey raja ram,
At least once try my suggestion which i have mentioned above:
select * from mast
into corresponding fields of table ITAB1
for all entries in ITAB
where matnr = itab-matnr.
this will get all the matnr.
Make sure ITAB1 has same structure as MAST.
because if you specify field names it will eliminate duplicate entries in the final results but if you select whole record then there will not be a problem because each record in table is always unique
2007 Jul 19 9:35 AM
hi shah
it is working something, just wait i will check and tell u.
Regards
Rajaram
2007 Jul 19 10:34 AM
No yar
select * from mast
into corresponding fields of table ITAB1
for all entries in ITAB
where matnr = itab-matnr.
this is the code i written, but it is not taking the duplicate matnr.
Regards
Rajaram
2007 Jul 19 10:39 AM
did you made changes to your code as i suggested, i think it will solve your purpose, after the code ITAB_NEW will contain the required records, see to my previous post
2007 Jul 19 8:20 AM
Hi Raja
I want to know what are the values u have passed to internal tables. Ok Can i have you part of coding please
Regards
Pavan
2007 Jul 19 8:57 AM
hi pavan
this is my code, do something.
REPORT ZSAB_BOM.
TABLES : vbep,VBAP,stpo,mara,stpox,STKO,MAST.
TYPE-POOLS : slis.
Data Declarations
DATA : fcat TYPE slis_t_fieldcat_alv,
it_sort TYPE SLIS_T_SORTINFO_ALV ,
wa_sort type slis_sortinfo_alv,
ls_fcat LIKE LINE OF fcat,
fheader TYPE TABLE OF slis_listheader WITH NON-UNIQUE DEFAULT KEY
WITH HEADER LINE INITIAL SIZE 0.
DATA :i_repid LIKE sy-repid,
gs_layout TYPE slis_layout_alv,
week type n.
DATA: l_index TYPE sy-tabix.
*Internal Tables
DATA : BEGIN OF itab OCCURS 0,
VBELN like vbap-VBELN, "SALE ORDER
posnr LIKE vbap-POSNR, "LINE ITEM
STLNR1 like vbap-STLNR,
STLNR like STPO-STLNR,
MATNR LIKE VBAP-MATNR,
ARKTX LIKE VBAP-ARKTX,
MEINS LIKE VBAP-MEINS,
IDNRK LIKE STPO-IDNRK,
werks like vbap-werks,
MAKTX LIKE MAKT-MAKTX,
KWMENG LIKE VBAP-KWMENG,
MENG LIKE VBAP-ABLFZ,
STLAL LIKE MAST-STLAL,
STLAN LIKE MAST-STLAN,
CAPID LIKE TC04-CAPID,
UMVKZ LIKE VBAP-UMVKZ,
VRKME LIKE VBAP-VRKME,
END OF itab.
DATA: wa LIKE LINE OF itab.
DATA : BEGIN OF it_final OCCURS 0,
VBELN like vbap-VBELN, "SALE ORDER
posnr LIKE vbap-POSNR, "LINE ITEM
STLNR1 like vbap-STLNR,"BOM
STLNR like STPO-STLNR, "BOM no
MATNR LIKE VBAP-MATNR, "MATERIAL
ARKTX LIKE VBAP-ARKTX, "DESC
MEINS LIKE VBAP-MEINS, "BUn
IDNRK LIKE STPO-IDNRK, "COMPONENT
werks like vbap-werks, "PLANT
MAKTX LIKE MAKT-MAKTX, "DESC
MNGKO LIKE STPO-MENGE, "CONSUMPTION
ROANZ LIKE STPO-ROANZ, "BASE QTY
MEINS1 LIKE STPO-MEINS, " Un
KWMENG LIKE VBAP-KWMENG, "ORDER QTY
STLAL LIKE MAST-STLAL,
STLAN LIKE MAST-STLAN,
CAPID LIKE TC04-CAPID,
END OF it_final.
data : begin of itab1 occurs 0,
VBELN like vbap-VBELN, "SALE ORDER
posnr LIKE vbap-POSNR, "LINE ITEM
STLNR1 like vbap-STLNR,
STLNR like STPO-STLNR,
MATNR LIKE VBAP-MATNR,
ARKTX LIKE VBAP-ARKTX,
MEINS LIKE VBAP-MEINS,
IDNRK LIKE STPO-IDNRK,
werks like vbap-werks,
MAKTX LIKE MAKT-MAKTX,
KWMENG LIKE VBAP-KWMENG,
MENG LIKE VBAP-ABLFZ,
STLAL LIKE MAST-STLAL,
STLAN LIKE MAST-STLAN,
CAPID LIKE TC04-CAPID,
END OF itab1.
DATA: wa2 LIKE mast.
data : ibom1 like stpox occurs 0 with header line,
ibom2 like stpox occurs 0 with header line.
Selection Screen
SELECTION-SCREEN BEGIN OF BLOCK bk1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: zso FOR vbep-vbeln OBLIGATORY.
SELECT-OPTIONS: zli FOR vbep-posnr.
SELECT-OPTIONS: ZPL FOR VBAP-WERKS.
PARAMETERS ZQTY TYPE STKO-BMENG.
SELECTION-SCREEN END OF BLOCK bk1.
gs_layout-colwidth_optimize = 'X'.
Select query to read all the materials from sales order
select vbeln
posnr
MATNR
ARKTX
STLNR
WERKS
KWMENG
MEINS
UMVKZ
VRKME
from vbap
into corresponding fields of table itab
where Vbeln in zso and
posnr in zli and
werks in zpl.
loop at itab.
if itab-VRKME = 'PAC' or itab-VRKME = 'PAK'.
itab-kwmeng = itab-kwmeng * itab-UMVKZ.
modify itab.
endif.
endloop.
Select all the alternative BOM against the material
LOOP AT itab INTO wa.
l_index = sy-tabix.
SELECT single stlal stlan matnr
into corresponding fields of wa
FROM mast
WHERE matnr = wa-matnr.
if sy-subrc = 0.
MODIFY itab FROM wa INDEX l_index.
endif.
ENDLOOP.
loop at itab.
move-corresponding itab to itab1.
append itab1.
endloop.
sort itab1 by matnr.
Assigning the order quantity if required qunatity zero
loop at itab1 where vbeln = itab-vbeln.
read table itab with key posnr = itab1-posnr.
and posnr = itab1-posnr.
if zqty is initial.
itab1-meng = itab-KWMENG.
modify itab1.
endif.
ENDLOOP.
Assigning required quantity as the base quantity
loop at itab1.
if zqty is not initial.
move zqty to itab1-meng.
modify itab1.
endif.
endloop.
Assigning all the corresponding fields from itab to itab1.
loop at itab1.
read table itab with key matnr = itab1-matnr.
if sy-subrc = 0.
IF ITAB1-STLAN = '1'.
ITAB1-CAPID = 'PP01'.
ELSEIF ITAB1-STLAN = '5'.
ITAB1-CAPID = 'SD01'.
ELSEIF ITAB1-STLAN = '6'.
ITAB1-CAPID = 'PC01'.
ELSEIF ITAB1-STLAN = '4'.
ITAB1-CAPID = 'INST'.
ELSEif itab1-stlan <> 1
and itab1-stlan <> 5
and itab1-stlan <> 6
AND ITAB1-STLAN <> 4.
itab1-capid = ' '.
ENDIF.
if zqty is initial.
itab1-MENG = itab1-meng.
else.
itab1-meng = itab1-meng.
itab1-kwmeng = zqty.
endif.
if zqty is initial.
itab1-KWMENG = itab1-KWMENG.
endif.
itab1-STLAL = itab1-STLAL.
endif.
modify itab1.
clear : itab.
endloop.
Calling the function module for collecting the bom components
loop at itab1.
if itab1-capid = ' '.
delete itab1.
endif.
endloop.
loop at itab1.
clear : ibom1[].
CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
EXPORTING
capid = ITAB1-CAPID
datuv = sy-datum
emeng = itab1-meng
mehrs = 'X'
mtnrv = itAB1-matnr
stlal = ITAB1-stlal
werks = itAB1-werks
TABLES
stb = ibom1
EXCEPTIONS
alt_not_found = 1
call_invalid = 2
material_not_found = 3
missing_authorization = 4
no_bom_found = 5
no_plant_data = 6
no_suitable_bom_found = 7
conversion_error = 8
OTHERS = 9.
IF sy-subrc <> 0.
ENDIF.
Moving all the fields to IT_FINAL.
LOOP AT IBOM1.
MOVE-CORRESPONDING ITAB1 TO IT_FINAL.
MOVE IBOM1-IDNRK TO IT_FINAL-IDNRK.
MOVE IBOM1-OJTXP TO IT_FINAL-MAKTX.
IF IT_FINAL-KWMENG LE 0.
MOVE 0 TO IT_FINAL-MNGKO.
ELSE.
MOVE IBOM1-MNGKO TO IT_FINAL-MNGKO.
ENDIF.
MOVE IBOM1-MEINS TO IT_FINAL-MEINS1.
APPEND IT_FINAL.
ENDLOOP.
ENDLOOP.
Calling the fieldcatelog
PERFORM EDIT_MASK.
i_repid = sy-repid.
PERFORM fieldcat.
wa_sort-fieldname = 'VBELN'.
wa_sort-tabname = 'IT_FINAL'.
wa_sort-up = 'X'.
APPEND wa_sort TO it_sort.
wa_sort-fieldname = 'POSNR'.
wa_sort-tabname = 'IT_FINAL'.
wa_sort-up = 'X'.
APPEND wa_sort TO it_sort.
wa_sort-fieldname = 'MATNR'.
wa_sort-tabname = 'IT_FINAL'.
wa_sort-up = 'X'.
APPEND wa_sort TO it_sort.
wa_sort-fieldname = 'ARKTX'.
wa_sort-tabname = 'IT_FINAL'.
wa_sort-up = 'X'.
APPEND wa_sort TO it_sort.
wa_sort-fieldname = 'KWMENG'.
wa_sort-tabname = 'IT_FINAL'.
wa_sort-up = 'X'.
APPEND wa_sort TO it_sort.
wa_sort-fieldname = 'STLAL'.
wa_sort-tabname = 'IT_FINAL'.
wa_sort-up = 'X'.
APPEND wa_sort TO it_sort.
wa_sort-fieldname = 'CAPID'.
wa_sort-tabname = 'IT_FINAL'.
wa_sort-up = 'X'.
APPEND wa_sort TO it_sort.
Calling ALV GRID
*SORT IT_FINAL ASCENDING BY VBELN POSNR MATNR.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = i_repid
is_layout = gs_layout
it_fieldcat = fcat
IT_SORT = it_sort
i_save = 'A'
TABLES
t_outtab = it_final
EXCEPTIONS
program_error = 1
OTHERS = 2.
&----
*& Form fieldcat
&----
text
----
FORM fieldcat.
MOVE sy-repid TO i_repid.
ls_fcat-tabname = 'IT_FINAL'.
ls_fcat-fieldname = 'VBELN'.
ls_fcat-outputlen = 10.
ls_fcat-seltext_m = 'Sales order'.
APPEND ls_fcat TO fcat.
ls_fcat-tabname = 'IT_FINAL'.
ls_fcat-fieldname = 'POSNR'.
ls_fcat-outputlen = 2.
ls_fcat-seltext_m = 'Item'.
APPEND ls_fcat TO fcat.
ls_fcat-tabname = 'IT_FINAL'.
ls_fcat-fieldname = 'MATNR'.
ls_fcat-outputlen = 20.
ls_fcat-seltext_m = 'Material'.
APPEND ls_fcat TO fcat.
ls_fcat-tabname = 'IT_FINAL'.
ls_fcat-fieldname = 'ARKTX'.
ls_fcat-outputlen = 30.
ls_fcat-seltext_m = 'Description'.
APPEND ls_fcat TO fcat.
ls_fcat-tabname = 'IT_FINAL'.
ls_fcat-fieldname = 'MEINS'.
ls_fcat-outputlen = 30.
ls_fcat-seltext_m = 'BUn'.
APPEND ls_fcat TO fcat.
ls_fcat-tabname = 'IT_FINAL'.
ls_fcat-outputlen = 5.
ls_fcat-fieldname = 'KWMENG'.
IF ZQTY IS INITIAL.
ls_fcat-seltext_m = 'Order Qty'.
ELSE.
ls_fcat-seltext_m = 'Required Qty'.
endif.
APPEND ls_fcat TO fcat.
ls_fcat-tabname = 'IT_FINAL'.
ls_fcat-fieldname = 'STLAL'.
ls_fcat-outputlen = 3.
ls_fcat-seltext_l = 'Alternative BOM'.
ls_fcat-seltext_m = 'Alt.BOM'.
ls_fcat-seltext_s = 'A.BOM'.
APPEND ls_fcat TO fcat.
ls_fcat-tabname = 'IT_FINAL'.
ls_fcat-fieldname = 'CAPID'.
ls_fcat-outputlen = 3.
ls_fcat-seltext_l = 'BOM Application'.
ls_fcat-seltext_m = 'BOM Appl.'.
ls_fcat-seltext_s = 'BOM Ap.'.
APPEND ls_fcat TO fcat.
ls_fcat-tabname = 'IT_FINAL'.
ls_fcat-fieldname = 'IDNRK'.
ls_fcat-outputlen = 15.
ls_fcat-seltext_l = 'Component'.
ls_fcat-seltext_m = 'Component'.
ls_fcat-seltext_s = 'Component'.
APPEND ls_fcat TO fcat.
ls_fcat-tabname = 'IT_FINAL'.
ls_fcat-fieldname = 'MAKTX'.
ls_fcat-outputlen = 15.
ls_fcat-seltext_l = 'Description'.
ls_fcat-seltext_m = 'Description'.
ls_fcat-seltext_s = 'Description'.
APPEND ls_fcat TO fcat.
ls_fcat-tabname = 'IT_FINAL'.
ls_fcat-fieldname = 'MNGKO'.
ls_fcat-outputlen = 5.
ls_fcat-seltext_l = 'Comp.Qty'.
ls_fcat-seltext_s = 'Comp.Qty'.
ls_fcat-seltext_m = 'Comp.Qty'.
APPEND ls_fcat TO fcat.
ls_fcat-tabname = 'IT_FINAL'.
ls_fcat-fieldname = 'MEINS1'.
ls_fcat-outputlen = 2.
ls_fcat-seltext_l = 'Un'.
ls_fcat-seltext_s = 'Un'.
ls_fcat-seltext_m = 'Un'.
APPEND ls_fcat TO fcat.
endform. "fieldcat
&----
*& Form EDIT_MASK
&----
text
----
--> p1 text
<-- p2 text
----
FORM EDIT_MASK .
loop at it_final.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = it_final-vbeln
IMPORTING
OUTPUT = it_final-vbeln.
modify it_final.
endloop.
ENDFORM.
2007 Jul 19 8:30 AM
Hi,
solution1)
recheck the definition of ITAB1 and ITAB,if ok then multiple entries will get populated based on Matnr captured in ITAB
Please use the old query
select matnr stlal STLAN from mast
into corresponding fields of table ITAB1
for all entries in ITAB
where matnr = itab-matnr.
solution 2)
Avoid using select inside loops...and if you planning to use the code with select inside the loop you need to append data rather than modify after using select * instead of select single.
solution 3)
If you are not still able to figure out get a proper data for MATNR.then pass hardcoded matnr present in ITAB and set a break point after the select for all entries....
eg:
MATNR : 1099 present in ITAB having multiple records for the STLAL
select matnr stlal STLAN from mast
into corresponding fields of table ITAB1
for all entries in ITAB
where matnr = 1099. ** Hardcode based on value in database
if sy-subrc = 0.
*BREAK_POINT.
else.
endif.
you can analyse the problem and come to a solution if you debug for a material with available data rather than trying to analyse the whole data at a single stretch..
Once you found the error change to the old code with corrections.
reward points if suggestion found useful
Regards
Byju
2007 Jul 19 8:45 AM
U have to create a new table and insert records into it for all STLAL values
use the code below, i have made corrections.....
data:
itab_new like table of itab.
LOOP AT itab INTO wa.
*l_index = sy-tabix.
SELECT stlal stlan matnr
into corresponding fields of wa
FROM mast
WHERE matnr = wa-matnr.
append wa to itab_new.
endselect.
*if sy-subrc = 0.
*MODIFY itab FROM wa INDEX l_index.
*endif.
ENDLOOP.
Reward points if useful.
Get back in case of a query....
2007 Jul 19 9:44 AM
Hi,
You can see from the following coding duplicate matnr also will come in output.But again there are possiblities for more than one stlal appear for one matnr, werks and stlnr.
data : itab1 type standard table of vbap,
itab2 type standard table of mast,
wa2 type mast.
select * from vbap into table itab1.
if sy-subrc eq 0.
select * from mast into table itab2 for all entries in itab1 where matnr = itab1-matnr
and werks = itab1-werks and stlnr = itab1-stlnr.
endif.
loop at itab2 into wa2.
write : / wa2-matnr, wa2-stlnr, wa2-stlal.
endloop.