‎2006 Jan 04 9:32 AM
Hi Experts,
This is Prabhakar
The following requirement is giving littlebit trouble to me. Here I don't know how to use Select single for selecting maktx field from MAKT table and how to link it to MARC and MBEW tables. How i will write code using without headerline.
<b>Requirement is :</b>
What this is asking is to create a report that contains the following fields in both the Selection Screen and in the report output:
Material Number - MARC-MATNR
Material Description - *
Warehouse Cycle Count Indicator - MARC-ABCIN
Standard Cost - MBEW-STPRS**
Profit Center - MARC-PRCTR
Use the following code to get Material Description (RESULT is the material that results from selecting from MARC):
FORM GET_MATERIAL_DESCRIPTION.
CLEAR MAKT.
SELECT SINGLE MAKTX INTO MAKT-MAKTX FROM MAKT
WHERE MATNR = RESULT-MATNR
AND SPRAS = SY-LANGU.
ENDFORM. " GET_MATERIAL_DESCRIPTION
For now, select standard price with the following criteria:
SELECT SINGLE STPRS
FROM MBEW
WHERE MATNR = RESULT-MATNR
AND BWTAR = SPACE.
There is another field in the key to MBEW it is BWKEY, and it is related to plant.
So, first select from MARC, and with the results of MARC, select from MBEW
‎2006 Jan 04 9:39 AM
Hi
The select of MAKT is right you need to decide the language and it usually uses the language of logon.
To read the table MARC and MBEW you need to know the plant, if you can't know it you can't do a select single.
So or you insert the plant in your selction-screen:
SELECT SIGNLE * FROM MARC WHERE MATNR = P_MATNR
AND WERKS = P_WERKS.
IF SY-SUBRC = 0.
SELECT SINGLE * FROM MBEW WHERE MATNR = P_MATNR
AND BWKEY = MARC-WERKS
AND BWTAR = SPACE.
or you use a constant (if there is only one plant in your organization).
DATA: MY_PLANT TYPE WERKSD VALUE 'Z001'.
SELECT SIGNLE * FROM MARC WHERE MATNR = P_MATNR
AND WERKS = MY_PLANT.
IF SY-SUBRC = 0.
SELECT SINGLE * FROM MBEW WHERE MATNR = P_MATNR
AND BWKEY = MARC-WERKS
AND BWTAR = SPACE.
......
Max
Message was edited by: max bianchi
‎2006 Jan 04 9:39 AM
Hi
The select of MAKT is right you need to decide the language and it usually uses the language of logon.
To read the table MARC and MBEW you need to know the plant, if you can't know it you can't do a select single.
So or you insert the plant in your selction-screen:
SELECT SIGNLE * FROM MARC WHERE MATNR = P_MATNR
AND WERKS = P_WERKS.
IF SY-SUBRC = 0.
SELECT SINGLE * FROM MBEW WHERE MATNR = P_MATNR
AND BWKEY = MARC-WERKS
AND BWTAR = SPACE.
or you use a constant (if there is only one plant in your organization).
DATA: MY_PLANT TYPE WERKSD VALUE 'Z001'.
SELECT SIGNLE * FROM MARC WHERE MATNR = P_MATNR
AND WERKS = MY_PLANT.
IF SY-SUBRC = 0.
SELECT SINGLE * FROM MBEW WHERE MATNR = P_MATNR
AND BWKEY = MARC-WERKS
AND BWTAR = SPACE.
......
Max
Message was edited by: max bianchi
‎2006 Jan 04 9:44 AM
Hi max
Thanks for immediate response.
Here i don't want Plant in Selection Screen, and first i have to select matnr,abcin,prctr from MARC table and later i have to get maktx field from MAKT table by using Select Single statment. Pls provide me detail code with TYPES usage. and also let me know where the maktx and stprs fields are going to validate by input.
Pls soove these.
thanks
prabhakar
‎2006 Jan 04 9:56 AM
Hi Max,
I hope that you got my problem.
I am waiting for your earlier reply.
Thanks
prabhakar
‎2006 Jan 04 10:04 AM
REPORT ztest.
PARAMETER: p_matnr LIKE mara-matnr.
DATA: BEGIN OF t_marc,
matnr LIKE mara-matnr,
werks LIKE marc-werks,
prctr LIKE marc-prctr,
END OF t_marc.
data: begin of t_mbew ,
STPRS like mbew-STPRS,
end of t_mbew.
data: l_maktx type makt-maktx.
SELECT SINGLE MAKTX INTO l_MAKTX FROM MAKT
WHERE MATNR = p_matnr
AND SPRAS = SY-LANGU.
SELECT SINGLE
matnr
werks
prctr
FROM marc
INTO t_marc
WHERE matnr = p_matnr.
IF sy-subrc = 0.
select single stprs from mbew
into t_mbew
where matnr = p_matnr
AND bwkey = t_marc-werks
AND bwtar = space.
ENDIF.check this.
thanks
vijay
‎2006 Jan 04 10:07 AM
Hi,
It is advisable that dont include Material Description(MAKTX_ and Cost(STPRS), as, if you miss a single letter in material description in the selection screen you will not get your required data, Cost is also same like that so many materials will having same cost and validating will become difficult. If you include these two unnessesarily you are increasing your program complexity. See the code below which satisfy your requirement with good performance.
Hope This Info Helps YOU.
<i>Reward Points If It Helps YOU.</i>
Regards,
Raghav
TABLES : mara,marc,mbew,makt.
DATA : BEGIN OF itab OCCURS 0,
matnr LIKE marc-matnr,
prctr LIKE marc-prctr ,
abcin LIKE marc-abcin,
maktx LIKE makt-maktx,
stprs LIKE mbew-stprs,
END OF itab.
DATA : BEGIN OF itab1 OCCURS 0,
matnr LIKE marc-matnr,
stprs LIKE mbew-stprs ,
END OF itab1.
DATA : BEGIN OF itab2 OCCURS 0,
matnr LIKE mara-matnr,
maktx LIKE makt-maktx,
END OF itab2.
*Selection Screen
SELECTION-SCREEN BEGIN OF BLOCK b1.
SELECT-OPTIONS : s_matnr FOR marc-matnr,
s_prctr FOR marc-prctr,
s_abcin FOR marc-abcin.
SELECTION-SCREEN END OF BLOCK b1.
*Validations of the selection-screen
AT SELECTION-SCREEN.
PERFORM selection_screen_validation.
START-OF-SELECTION.
SELECT matnr
prctr
abcin
INTO TABLE itab
FROM marc
WHERE matnr IN s_matnr
AND abcin IN s_abcin
AND prctr IN s_prctr.
if not itab[] is initial.
SELECT matnr
maktx
INTO TABLE itab2
FROM makt
for all entries in itab
WHERE matnr = itab-matnr
AND spras = sy-langu.
endif.
if not itab[] is initial.
SELECT matnr
stprs
INTO TABLE itab1
FROM mbew
for all entries in itab
WHERE matnr = itab-matnr.
endif.
sort itab by matnr.
sort itab1 by matnr.
sort itab2 by matnr.
clear : itab, itab1, itab2.
LOOP AT itab.
READ TABLE itab2 WITH KEY matnr = itab-matnr BINARY SEARCH .
if sy-subrc eq 0.
itab-maktx = itab2-maktx.
endif.
READ TABLE itab1 WITH KEY matnr = itab-matnr BINARY SEARCH .
if sy-subrc eq 0.
itab-stprs = itab1-stprs.
endif.
MODIFY itab.
clear: itab, itab1, itab2.
ENDLOOP.
END-OF-SELECTION.
LOOP AT itab.
WRITE : / itab-matnr,
itab-maktx,
itab-abcin,
itab-stprs,
itab-prctr.
ENDLOOP.
*&---------------------------------------------------------------------*
*& Form selection_screen_validation
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form selection_screen_validation .
data : v_matnr type mara-matnr,
v_prctr type cepc-prctr,
v_abcin type t159c-abcin.
** validations for material number
if not s_matnr[] is initial.
select matnr from mara
into v_matnr
up to 1 rows
where matnr in s_matnr.
endselect.
if sy-subrc = 0.
message e001 with ' Material '.
endif.
endif.
** validations for Profit Center
if not s_prctr[] is initial.
select prctr from cepc
into v_prctr
up to 1 rows
where prctr in s_prctr.
endselect.
if sy-subrc = 0.
message e001 with ' Profit Center '.
endif.
endif.
** validations for Cycle Count Indicator
if not s_abcin is initial.
select abcin from t159c
into v_abcin
up to 1 rows
where abcin in s_abcin.
endselect.
if sy-subrc = 0.
message e001 with ' Count Indicator '.
endif.
endif.
endform. " selection_screen_validation
‎2006 Jan 04 10:11 AM
Hi
You need only to know the material code to read MAKT table, but I can't how you can decide which record of MARC you need to read if you don't know the plant.
Anyway if you want to load the description on your selection screen, you should do the select in AT SELECTION-SCREEN or AT SELECTION-SCREEN OUTPUT event.
TABLE MAKT.
PARAMETERS: P_MATNR LIKE MARC-MATNR.
PARAMETERS: P_MAKTX LIKE MAKT-MAKTX MODIF ID 001.
AT SELECTION-SCREEN OUTPUT.
SELECT SINGLE * FROM MAKT WHERE MATNR = P_MATNR
AND SPRAS = SY-LANGU.
IF SY-SUBRC = 0.
MOVE MAKT-MAKTX TO P_MAKTX.
ELSE.
CLEAR P_MAKTX.
ENDIF.
Max