cancel
Showing results for 
Search instead for 
Did you mean: 

Error in Report

Former Member
0 Kudos
109

Hello All,

Can Any body explain what went wrong with my code, which i have given below.

if i enter material no and plant in input i am able to get the corect out put. But i f enter only plant no (eg1000) i am not getting all the correct details. Similarly if i enter both storage location, mrp controls in input i am getting the correct results.

if iommitted MRP Control and endtered all the details i am not getting the correct results.

thanks and regards

Madhavi

REPORT Y_MATERIAL_EXTRACTION_2 LINE-SIZE 172

LINE-COUNT 37(5)

NO STANDARD PAGE HEADING.

***********************************************************************

                          • T A B L E S *******************

***********************************************************************

TABLES: mara, "GENERAL MASTER DATA

marc, "PLANT DATA FOR MATERIAL

mard, "STORAGE LOCATION DATA FOR MATERIAL

mvke, "SALES DATA FOR MATERIAL

makt. "MATERIAL DESCRIPTION

DATA: r_labst_total LIKE mard-labst VALUE '0'.

***********************************************************************

                          • I N T E R N A L T A B L E S *******************

***********************************************************************

DATA:BEGIN OF i_marc OCCURS 0,

matnr LIKE marc-matnr,

werks LIKE marc-werks,

dispo LIKE marc-dispo,

END OF i_marc.

DATA:BEGIN OF i_mard OCCURS 0,

matnr LIKE mard-matnr,

lgort LIKE mard-lgort,

labst LIKE mard-labst,

END OF i_mard.

DATA: BEGIN OF i_mvke OCCURS 0,

matnr LIKE mvke-matnr,

vkorg LIKE mvke-vkorg,

vtweg LIKE mvke-vtweg,

END OF i_mvke.

DATA: BEGIN OF i_out occurs 0,

matnr LIKE marc-matnr,

werks LIKE marc-werks,

dispo LIKE marc-dispo,

mbrsh LIKE mara-mbrsh,

meins LIKE mara-meins,

matkl LIKE mara-matkl,

vkorg LIKE mvke-vkorg,

vtweg LIKE mvke-vtweg,

spras LIKE makt-spras,

maktx LIKE makt-maktx,

lgort LIKE mard-lgort,

labst LIKE mard-labst,

labst_total LIKE mard-labst,

END OF i_out.

***********************************************************************

                          • S T A R T - O F - S E L EC T I O N *******************

***********************************************************************

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-100.

SELECT-OPTIONS: s_matnr FOR marc-matnr, "OBLIGATORY,

s_lgort FOR mard-lgort,

s_dispo FOR marc-dispo.

PARAMETERS: p_werks LIKE marc-werks. "OBLIGATORY.

SELECTION-SCREEN END OF BLOCK b1.

***********************************************************************

                          • S T A R T - O F - S E L EC T I O N *******************

***********************************************************************

START-OF-SELECTION.

SELECT matnr werks dispo

FROM marc

INTO TABLE i_marc

WHERE matnr IN s_matnr

AND werks EQ p_werks

AND dispo IN s_dispo.

IF i_marc[] IS INITIAL.

WRITE:/'NO MATCHING DATA IS FOUND FROM TABLE MARC'.

EXIT.

ENDIF.

SELECT matnr lgort labst

FROM mard

INTO TABLE i_mard

FOR ALL ENTRIES IN i_marc

WHERE matnr = i_marc-matnr

AND werks EQ p_werks

AND lgort IN s_lgort.

IF i_mard[] IS INITIAL.

WRITE:/ 'NO MATCHING DATA IS SELECTED FROM TABLE MARD'.

EXIT.

ENDIF.

SELECT matnr vkorg vtweg

FROM mvke

INTO TABLE i_mvke

FOR ALL ENTRIES IN i_marc

WHERE matnr = i_marc-matnr.

IF i_mvke[] IS INITIAL.

WRITE:/ 'NO MATCHING DATA IS SELECTED FROM TABLE MVKE'.

EXIT.

ENDIF.

LOOP AT i_marc.

MOVE-CORRESPONDING i_marc TO i_out.

CLEAR marc.

SELECT SINGLE matnr mbrsh meins matkl

FROM mara

INTO CORRESPONDING FIELDS OF mara

WHERE matnr = i_out-matnr.

IF SY-SUBRC = 0.

MOVE-CORRESPONDING mara TO i_out.

ELSE.

CONTINUE.

ENDIF.

SELECT SINGLE matnr spras maktx

FROM makt

INTO CORRESPONDING FIELDS OF makt

WHERE matnr = i_out-matnr

AND spras = SY-LANGU.

IF SY-SUBRC = 0.

MOVE-CORRESPONDING makt TO i_out.

ENDIF.

LOOP AT i_mard WHERE matnr = i_marc-matnr.

MOVE:i_mard-lgort TO i_out-lgort,

i_mard-labst TO i_out-labst.

  • APPEND i_out.

  • ENDLOOP.

LOOP AT i_mvke WHERE matnr = i_marc-matnr.

MOVE:i_mvke-vkorg TO i_out-vkorg,

i_mvke-vtweg TO i_out-vtweg.

APPEND i_out.

ENDLOOP.

CLEAR i_out.

ENDLOOP.

ENDLOOP.

************************************************************************

                        • DISPLAYIING FROM I-OUT ********************************

************************************************************************

SORT i_out BY matnr.

LOOP AT i_out.

WRITE: SY-VLINE, 5 i_out-matnr,SY-VLINE,

25 i_out-werks,SY-VLINE,

31 i_out-dispo,SY-VLINE,

36 i_out-mbrsh,SY-VLINE,

40 i_out-meins,SY-VLINE,

45 i_out-matkl,SY-VLINE,

60 i_out-vkorg,SY-VLINE,

70 i_out-vtweg,SY-VLINE,

80 i_out-maktx,SY-VLINE,

125 i_out-lgort,SY-VLINE,

132 i_out-labst,SY-VLINE.

r_labst_total = r_labst_total + i_out-labst.

AT END OF labst.

WRITE: r_labst_total COLOR 6,

SY-VLINE.

WRITE:/ SY-ULINE.

ENDAT.

AT LAST.

SKIP 2.

WRITE: /50 'Total Stock = ' COLOR 3,r_labst_total COLOR 4.

ENDAT.

ENDLOOP.

***********************************************************************

                          • E N D - O F - S E L EC T I O N ***********************

***********************************************************************

END-OF-SELECTION.

***********************************************************************

                                • T O P - O F - P A G E ************************

***********************************************************************

TOP-OF-PAGE.

WRITE: 60 'MATERIAL MASTER EXTRACTION REPORT' COLOR COL_GROUP,

SY-ULINE.

WRITE: /6 'MATERIAL_NO',

25 'PLANT',

31 'MRP',

35 'IND',

39 'BUOM',

46 'GROUP',

56 'SALES_ORG',

67 'D_CHNL',

82 'DESCRIPTION',

124 'S_LOC',

137 'STOCK',

153 'CUMULATIVE STOCK'.

WRITE SY-ULINE.

***********************************************************************

                                • E N D - O F - P A G E ************************

***********************************************************************

END-OF-PAGE.

WRITE: /85 'PAGNO: ',SY-PAGNO,

SY-ULINE.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello Madhavi,

This may be due to the PARAMETER declaration of the P_WERKS.

If a field is declared as Parameter and no values is entered in that fiedl then the select stme will search for the balnk value for that field.

So in ur case if the palnt is not entered in the sel. scr then MARC table will search for the blank value ifor plant which will not be available due to key functionality.

Whereas if a field is declared as a select-options and empty from the sel. scr then SAP will search for all records from the table.

So hereafetr whenever u r coding keep this in mind .

Vasanth

Answers (4)

Answers (4)

Former Member
0 Kudos

hi

u have 3 select-options and 1 parameters...so, you will have to fetch your data taking into consideration all your input fields...u haven't considered your s_lgort input here...so change your first select like this..

SELECT matnr werks dispo

FROM marc

INTO TABLE i_marc

WHERE matnr IN s_matnr

AND werks EQ p_werks

and lgort in s_lgort "include this

AND dispo IN s_dispo.

cheers,

Sathish. R

Former Member
0 Kudos
SELECT matnr werks dispo
FROM marc
INTO TABLE i_marc
WHERE matnr IN s_matnr
AND werks EQ p_werks
AND dispo IN s_dispo.

IF i_marc[] IS INITIAL.
WRITE:/'NO MATCHING DATA IS FOUND FROM TABLE MARC'.
EXIT.
ENDIF.

SELECT matnr lgort labst
FROM mard
INTO TABLE i_mard
FOR ALL ENTRIES IN i_marc
WHERE matnr = i_marc-matnr

<b>AND werks = i_marc-werks</b>

AND lgort IN s_lgort.

IF i_mard[] IS INITIAL.
WRITE:/ 'NO MATCHING DATA IS SELECTED FROM TABLE MARD'.
EXIT.
ENDIF.

SELECT matnr vkorg vtweg
FROM mvke
INTO TABLE i_mvke
FOR ALL ENTRIES IN i_marc
WHERE matnr = i_marc-matnr.

IF i_mvke[] IS INITIAL.
WRITE:/ 'NO MATCHING DATA IS SELECTED FROM TABLE MVKE'.
EXIT.
ENDIF.

<b>* Define i_mara

SELECT matnr mbrsh meins matkl

FROM mara

INTO TABLE i_mara

FOR ALL ENTRIES IN i_marc

WHERE matnr = i_marc-matnr.</b>

<b>SELECT matnr spras maktx

FROM i_makt

INTO TABLE i_makt

FOR ALL ENTRIES IN i_marc

WHERE matnr = i_marc-matnr

AND spras = SY-LANGU.</b>

LOOP AT i_marc.

<b>READ TABLE i_mara WITH KEY matnr = i_marc-matnr.</b>

IF SY-SUBRC = 0.
MOVE-CORRESPONDING i_mara TO i_out.
ELSE.
CONTINUE.
ENDIF.

<b>READ TABLE i_makt WITH KEY matnr = i_marc-matnr.</b>

IF SY-SUBRC = 0.
MOVE-CORRESPONDING i_makt TO i_out.
ENDIF.

<b>READ TABLE i_mard WITH KEY matnr = i_marc-matnr.</b>

*LOOP AT i_mard WHERE matnr = i_marc-matnr.

<b>IF sy-subrc = 0.</b>

MOVE:i_mard-lgort TO i_out-lgort,
i_mard-labst TO i_out-labst.

ENDIF.</b>

  • APPEND i_out.

  • ENDLOOP.

<b>READ TABLE i_mvke WITH KEY matnr = i_marc-matnr.</b>

*LOOP AT i_mvke WHERE matnr = i_marc-matnr.

<b>IF sy-subrc = 0.</b>

MOVE:i_mvke-vkorg TO i_out-vkorg,
i_mvke-vtweg TO i_out-vtweg.

<b>ENDIF.</b>

APPEND i_out.

*ENDLOOP.

CLEAR i_out.

*ENDLOOP.


ENDLOOP.

hope thsi will solve ur problem.

reward if this helsp.

Former Member
0 Kudos

hi madhavi,

check the changes i made..marked in bold, and seee if ur able to get the right output.

&----


*& Report ZTEST15

*&

&----


*&

*&

&----


REPORT ZTEST15.

***********************************************************************

                          • T A B L E S *******************

***********************************************************************

TABLES: mara, "GENERAL MASTER DATA

marc, "PLANT DATA FOR MATERIAL

mard, "STORAGE LOCATION DATA FOR MATERIAL

mvke, "SALES DATA FOR MATERIAL

makt. "MATERIAL DESCRIPTION

DATA: r_labst_total LIKE mard-labst VALUE '0'.

***********************************************************************

                          • I N T E R N A L T A B L E S *******************

***********************************************************************

DATA:BEGIN OF i_marc OCCURS 0,

matnr LIKE marc-matnr,

werks LIKE marc-werks,

dispo LIKE marc-dispo,

END OF i_marc.

DATA:BEGIN OF i_mard OCCURS 0,

matnr LIKE mard-matnr,

lgort LIKE mard-lgort,

labst LIKE mard-labst,

END OF i_mard.

DATA: BEGIN OF i_mvke OCCURS 0,

matnr LIKE mvke-matnr,

vkorg LIKE mvke-vkorg,

vtweg LIKE mvke-vtweg,

END OF i_mvke.

DATA: BEGIN OF i_out occurs 0,

matnr LIKE marc-matnr,

werks LIKE marc-werks,

dispo LIKE marc-dispo,

mbrsh LIKE mara-mbrsh,

meins LIKE mara-meins,

matkl LIKE mara-matkl,

vkorg LIKE mvke-vkorg,

vtweg LIKE mvke-vtweg,

spras LIKE makt-spras,

maktx LIKE makt-maktx,

lgort LIKE mard-lgort,

labst LIKE mard-labst,

labst_total LIKE mard-labst,

END OF i_out.

***********************************************************************

                          • S T A R T - O F - S E L EC T I O N *******************

***********************************************************************

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-100.

SELECT-OPTIONS: s_matnr FOR marc-matnr, "OBLIGATORY,

s_lgort FOR mard-lgort,

s_dispo FOR marc-dispo.

PARAMETERS: p_werks LIKE marc-werks. "OBLIGATORY.

SELECTION-SCREEN END OF BLOCK b1.

***********************************************************************

                          • S T A R T - O F - S E L EC T I O N *******************

***********************************************************************

START-OF-SELECTION.

SELECT matnr werks dispo

FROM marc

INTO TABLE i_marc

WHERE matnr IN s_matnr

AND werks EQ p_werks

AND dispo IN s_dispo.

IF i_marc[] IS INITIAL.

WRITE:/'NO MATCHING DATA IS FOUND FROM TABLE MARC'.

EXIT.

<b>else.</b>

SELECT matnr lgort labst

FROM mard

INTO TABLE i_mard

FOR ALL ENTRIES IN i_marc

WHERE matnr = i_marc-matnr

AND werks EQ p_werks

AND lgort IN s_lgort.

IF i_mard[] IS INITIAL.

WRITE:/ 'NO MATCHING DATA IS SELECTED FROM TABLE MARD'.

EXIT.

ENDIF.

SELECT matnr vkorg vtweg

FROM mvke

INTO TABLE i_mvke

FOR ALL ENTRIES IN i_marc

WHERE matnr = i_marc-matnr.

IF i_mvke[] IS INITIAL.

WRITE:/ 'NO MATCHING DATA IS SELECTED FROM TABLE MVKE'.

EXIT.

ENDIF.

<b>endif.</b>

LOOP AT i_marc.

MOVE-CORRESPONDING i_marc TO i_out.

CLEAR marc.

SELECT SINGLE matnr mbrsh meins matkl

FROM mara

INTO CORRESPONDING FIELDS OF mara

WHERE matnr = i_out-matnr.

IF SY-SUBRC = 0.

MOVE-CORRESPONDING mara TO i_out.

ELSE.

CONTINUE.

ENDIF.

SELECT SINGLE matnr spras maktx

FROM makt

INTO CORRESPONDING FIELDS OF makt

WHERE matnr = i_out-matnr

AND spras = SY-LANGU.

IF SY-SUBRC = 0.

MOVE-CORRESPONDING makt TO i_out.

ENDIF.

LOOP AT i_mard WHERE matnr = i_marc-matnr.

MOVE:i_mard-lgort TO i_out-lgort,

i_mard-labst TO i_out-labst.

  • APPEND i_out.

  • ENDLOOP.

LOOP AT i_mvke WHERE matnr = i_marc-matnr.

MOVE:i_mvke-vkorg TO i_out-vkorg,

i_mvke-vtweg TO i_out-vtweg.

ENDLOOP.

CLEAR i_out.

ENDLOOP.

<b>APPEND i_out.

CLEAR i_out.</b>

ENDLOOP.

************************************************************************

                        • DISPLAYIING FROM I-OUT ********************************

************************************************************************

SORT i_out BY matnr.

LOOP AT i_out.

WRITE: SY-VLINE, 5 i_out-matnr,SY-VLINE,

25 i_out-werks,SY-VLINE,

31 i_out-dispo,SY-VLINE,

36 i_out-mbrsh,SY-VLINE,

40 i_out-meins,SY-VLINE,

45 i_out-matkl,SY-VLINE,

60 i_out-vkorg,SY-VLINE,

70 i_out-vtweg,SY-VLINE,

80 i_out-maktx,SY-VLINE,

125 i_out-lgort,SY-VLINE,

132 i_out-labst,SY-VLINE.

r_labst_total = r_labst_total + i_out-labst.

AT END OF labst.

WRITE: r_labst_total COLOR 6,

SY-VLINE.

WRITE:/ SY-ULINE.

ENDAT.

AT LAST.

SKIP 2.

WRITE: /50 'Total Stock = ' COLOR 3,r_labst_total COLOR 4.

ENDAT.

ENDLOOP.

***********************************************************************

                          • E N D - O F - S E L EC T I O N ***********************

***********************************************************************

END-OF-SELECTION.

***********************************************************************

                                • T O P - O F - P A G E ************************

***********************************************************************

TOP-OF-PAGE.

WRITE: 60 'MATERIAL MASTER EXTRACTION REPORT' COLOR COL_GROUP,

SY-ULINE.

WRITE: /6 'MATERIAL_NO',

25 'PLANT',

31 'MRP',

35 'IND',

39 'BUOM',

46 'GROUP',

56 'SALES_ORG',

67 'D_CHNL',

82 'DESCRIPTION',

124 'S_LOC',

137 'STOCK',

153 'CUMULATIVE STOCK'.

WRITE SY-ULINE.

***********************************************************************

                                • E N D - O F - P A G E ************************

***********************************************************************

END-OF-PAGE.

WRITE: /85 'PAGNO: ',SY-PAGNO,

SY-ULINE.

do reward if it helps,

priya.

Former Member
0 Kudos

Hi Madhavi,

In the select statement u have give both conditions by AND, so check

with

if sales org is initial.

select .........where werks EQ p_werks.

endif.

SELECT matnr lgort labst

FROM mard

INTO TABLE i_mard

FOR ALL ENTRIES IN i_marc

WHERE matnr = i_marc-matnr

AND werks EQ p_werks

<b>AND lgort IN s_lgort.</b>

Regards

Kannaiah