Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

MATKL

Former Member
0 Likes
3,292

Hi all

In the below program i need to select the MATKL field from MARA Table and MATNR is the only common field in both MARA and S026 tables.Please help.

Vijay

REPORT ZCO_OVERHEAD_TEST1.

TABLES:S026,MARA.

DATA:IT_S026 TYPE STANDARD TABLE OF S026 WITH HEADER LINE.

DATA:IT_MARA TYPE STANDARD TABLE OF MARA WITH HEADER LINE.

DATA:IT_REPORT TYPE STANDARD TABLE OF S026 WITH HEADER LINE.

PARAMETERS:p_werks type S026-WERKS.

SELECT-OPTIONS:p_sptag FOR S026-SPTAG.

  • OBLIGATORY.

DATA:x TYPE i.

SELECT * FROM S026 INTO CORRESPONDING FIELDS OF TABLE

IT_S026 WHERE WERKS = P_WERKS AND

SPTAG IN p_sptag .

LOOP AT IT_S026.

WRITE:/ IT_S026-ENMNG,IT_S026-WERKS,IT_S026-SPTAG,IT_S026-MATNR.

IT_REPORT-ENMNG = IT_S026-ENMNG .

SELECT * FROM MARA INTO CORRESPONDING FIELDS OF TABLE

IT_MARA WHERE ERSDA IN p_sptag.

ADD IT_S026-ENMNG TO X.

ENDLOOP.

WRITE:/ 'Material Group::',IT_MARA-MATKL.

WRITE:/ 'TOTAL::',x.

5 REPLIES 5
Read only

Former Member
0 Likes
2,710

You can use joins on both table or use For All entries .

Let me know if you need examples on this.

Read only

Former Member
0 Likes
2,710

Hi..Vijay!!!

What is the final output you want.

I dint understand your code.

For what you are writing this code.

And I can give one suggestion for this.

Create a view with required fields.

And select from view.

But tell me the requirement indetail, So that I can help you out.

Regards

Sandeep.

Read only

Former Member
0 Likes
2,710

Hi vijay,

Try this and Reward points if useful.

*&----


**& Report ZTEST

**&

*&----


**&

**&

*&----


*

REPORT ZCO_OVERHEAD_TEST1.

TABLES:S026,MARA.

DATA: begin of IT_S026 OCCURS 0,

matnr like mara-matnr,

WERKS like S026-WERKS,

enmng like S026-enmng,

end of IT_S026.

DATA: BEGIN OF IT_MARA OCCURS 0,

matnr like mara-matnr,

matkl like mara-matkl,

END OF IT_MARA.

DATA: BEGIN OF IT_REPORT OCCURS 0,

matnr like mara-matnr,

WERKS like S026-WERKS,

matkl like MARA-matkl,

enmng like S026-enmng,

end of IT_REPORT.

PARAMETERS:p_werks type S026-WERKS.

SELECT-OPTIONS:p_sptag FOR S026-SPTAG.

DATA:x TYPE i VALUE 0.

SELECT matnr werks enmng FROM S026 INTO CORRESPONDING FIELDS OF TABLE IT_S026 WHERE WERKS EQ P_WERKS AND SPTAG IN p_sptag.

SELECT matnr matkl FROM MARA INTO CORRESPONDING FIELDS OF TABLE IT_MARA WHERE ERSDA IN p_sptag.

loop at IT_S026.

MOVE-CORRESPONDING IT_S026 to IT_REPORT.

ENDLOOP.

LOOP AT IT_REPORT.

read TABLE IT_MARA WITH key matnr = IT_REPORT-MATNR.

if sy-subrc = 0.

IT_REPORT-matkl = IT_MARA-MATKL.

endif.

ENDLOOP.

WRITE:/(30) 'Material Group::' , (15) 'Total'.

loop at IT_REPORT.

WRITE:/ IT_REPORT-MATKL , IT_REPORT-ENMNG.

ENDLOOP.

REgards,

Bhavin P Shah

Read only

Former Member
0 Likes
2,710

HI,

write this query

SELECT m~MATKL

INTO CORRESPONDING FIELDS OF TABLE xxxx

FROM MARA AS M

INNER JOIN S026 AS S WHERE SMATNR = MMATNR.

This will ensure that the matkl field will be selected from MARA for the records which material is same in MARA and S026.

Reward if it helps.

Regards,

Sunny

Read only

Former Member
0 Likes
2,710

Hi,

REPORT zstemp_qty2_ .

TABLES:s026,mara.

DATA: BEGIN OF it_s026 OCCURS 0,

matnr LIKE mara-matnr,

werks LIKE s026-werks,

enmng LIKE s026-enmng,

END OF it_s026.

DATA: BEGIN OF it_mara OCCURS 0,

matnr LIKE mara-matnr,

matkl LIKE mara-matkl,

END OF it_mara.

PARAMETERS:p_werks TYPE s026-werks.

SELECT-OPTIONS:s_sptag FOR s026-sptag.

DATA:x TYPE i VALUE 0.

START-OF-SELECTION.

SELECT matnr werks enmng

FROM s026 INTO CORRESPONDING FIELDS OF TABLE it_s026

WHERE werks EQ p_werks AND

sptag IN s_sptag .

IF NOT it_s026[] IS INITIAL.

SELECT matnr matkl INTO CORRESPONDING FIELDS OF TABLE it_mara

FROM mara FOR ALL ENTRIES IN it_s026

WHERE matnr = it_s026-matnr AND

ersda IN s_sptag .

ENDIF.

SORT it_mara BY matkl.

LOOP AT it_mara.

READ TABLE it_s026 WITH KEY matnr = it_mara-matnr.

IF sy-subrc = 0.

x = x + it_s026-enmng.

ENDIF.

ENDLOOP.

***************************you can use control break stmt as shown below if you want sum for every matkl ***

sort ..

LOOP AT it_mara.

AT END OF matkl.

SUM.

*write :

ENDAT.

ENDLOOP.

WRITE:/,x, 'Total'.

&************************************

Regds

Sivaparvathi

Please reward points if helpful..