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

at new statement problem

Former Member
0 Likes
3,710

HI,

I am making a report in which i want to use the at new statement so that i can perform the calculation for it but it is not performing the calculation. plzz provide me guidelines to solve this problem.

SORT ITAB1 BY ITEMID.

LOOP AT ITAB1.

AT NEW ITEMID.

ITPL-MATNR = ITAB1-ITEMID.

ITPL-GSMNG = 0.

APPEND ITPL.

ENDAT.

ENDLOOP.

LOOP AT ITPL.

LOOP AT ITAB1 WHERE ITEMID = ITPL-MATNR.

ITPL-GSMNG = ITPL-GSMNG + ITAB1-GSMNG.

ENDLOOP.

MODIFY ITPL.

ENDLOOP.

LOOP AT ITPL.

WRITE: / ITPL-MATNR,ITPL-GSMNG.

ENDLOOP.

29 REPLIES 29
Read only

Former Member
0 Likes
2,928

Hi,

You can have control staments within the loop only for C, N, D, T, X type fields.

Is ITEMID any of these data types?

Regards,

Subramanian

Read only

Former Member
0 Likes
2,928

hi give the total code then that will be easy for us to review

Read only

Former Member
0 Likes
2,928

hi,

The problem is that while using AT NEW the other Variable svalue is replaced by '*'. So Before AT New Statement store the variable in some other Variables and use new Variables in the Calculation.

Regards

Sumit Agarwal

Read only

rajesh_akarte2
Active Participant
0 Likes
2,928

hi,

Check the position of the field ITEMID in ur internal table declaration . Try making it as first field in ur internal table.

Regards,

Rajesh Akarte

Read only

Former Member
0 Likes
2,928

Can u post full program

Read only

Former Member
0 Likes
2,928

hi,

this is the code which i am using right now:-

TABLES: VBAK,VBAP,MARA.

************BEGIN - DATA DECLARATION IN ITAB*****************

DATA: BEGIN OF ITAB OCCURS 0,

MATNR LIKE VBAP-MATNR, "Material Number

VBELN LIKE VBAK-VBELN, "Sales Document

ERDAT LIKE VBAK-ERDAT, "Date on Which Record Was Created

WERKS LIKE VBAP-WERKS, "Plant (Own or External)

POSNR LIKE VBAP-POSNR, "Sales Document Item

SPART LIKE MARA-SPART, "Division

MEINS LIKE MARA-MEINS, "Unit Of Measurment

MTART LIKE MARA-MTART, "Material Type

NTGEW LIKE MARA-NTGEW, "Net Weight

GEWEI LIKE MARA-GEWEI, "Weight Unit

PLNUM LIKE PLAF-PLNUM, "Planned order number

GSMNG LIKE PLAF-GSMNG, "Total planned order quantity

KDAUF LIKE PLAF-KDAUF, "Sales Order Number

KDPOS LIKE PLAF-KDPOS, "Item Number in Sales Order

AUFNR LIKE AFPO-AUFNR, "Order Number

PSMNG LIKE AFPO-PSMNG, "Order item quantity

ITEMDESC LIKE MAKT-MAKTX, "Item Description

TOTWT1 LIKE PLAF-GSMNG, "Calculation 1

TOTWT2 LIKE AFPO-PSMNG, "Calculation 2

WTKG LIKE MARA-NTGEW, "Net Weight

TOT LIKE PLAF-GSMNG, "

END OF ITAB.

DATA: BEGIN OF ITAB1 OCCURS 0,

MATNR LIKE VBAP-MATNR, "Material Number

VBELN LIKE VBAK-VBELN, "Sales Document

ERDAT LIKE VBAK-ERDAT, "Date on Which Record Was Created

WERKS LIKE VBAP-WERKS, "Plant (Own or External)

POSNR LIKE VBAP-POSNR, "Sales Document Item

SPART LIKE MARA-SPART, "Division

MEINS LIKE MARA-MEINS, "Unit Of Measurment

MTART LIKE MARA-MTART, "Material Type

NTGEW LIKE MARA-NTGEW, "Net Weight

GEWEI LIKE MARA-GEWEI, "Weight Unit

PLNUM LIKE PLAF-PLNUM, "Planned order number

GSMNG LIKE PLAF-GSMNG, "Total planned order quantity

KDAUF LIKE PLAF-KDAUF, "Sales Order Number

KDPOS LIKE PLAF-KDPOS, "Item Number in Sales Order

AUFNR LIKE AFPO-AUFNR, "Order Number

PSMNG LIKE AFPO-PSMNG, "Order item quantity

ITEMDESC LIKE MAKT-MAKTX, "Item Description

TOTWT1 LIKE PLAF-GSMNG, "Calculation 1

TOTWT2 LIKE AFPO-PSMNG, "Calculation 2

WTKG LIKE MARA-NTGEW, "Net Weight

TOT LIKE PLAF-GSMNG, "

END OF ITAB1.

**********END - DATA DECLARATION IN ITAB*****************

************BEGIN - ITAB FOR PL.ORDR********************

DATA: BEGIN OF ITPL OCCURS 0,

MATNR LIKE AFPO-MATNR, "Material Number

KDAUF LIKE PLAF-KDAUF, "Sales Order Number

KDPOS LIKE PLAF-KDPOS, "Item Number in Sales Order

PLNUM LIKE AFPO-PLNUM, "Planned order number

GSMNG LIKE PLAF-GSMNG, "Total planned order quantity

AUFNR LIKE AFPO-AUFNR, "Order Number

TOT LIKE PLAF-GSMNG, "

END OF ITPL.

************END - ITAB FOR PL.ORDR***********************

***********BEGIN - ITAB FOR PRD.ORDR********************

DATA: BEGIN OF ITPO OCCURS 0,

MATNR LIKE AFPO-MATNR, "Material Number

KDAUF LIKE AFPO-KDAUF, "Sales Order Number

KDPOS LIKE AFPO-KDPOS, "Item Number in Sales Order

PLNUM LIKE AFPO-PLNUM, "Planned order number

PSMNG LIKE AFPO-PSMNG, "Order item quantity

AUFNR LIKE AFPO-AUFNR, "Order Number

TOT LIKE PLAF-GSMNG, "

END OF ITPO.

***********END - ITAB FOR PRD.ORDR********************

***********BEGIN - SELECTION SCREEN AND PARAMETERS AND VARIABLES**********

PARAMETERS : PLANT LIKE VBAP-WERKS OBLIGATORY.

SELECT-OPTIONS: SO_ORD FOR VBAK-VBELN,

DIV FOR MARA-SPART,

SO_DATE FOR VBAK-ERDAT,

P_MATNR FOR VBAP-MATNR.

***********END - SELECTION SCREEN AND PARAMETERS**********

**********BEGIN - DATA RETERIVAL FROM TABLES**************************

SELECT BMATNR AVBELN AERDAT BWERKS BPOSNR CSPART CMEINS CMTART CNTGEW CGEWEI

FROM VBAK AS A

INNER JOIN VBAP AS B ON BVBELN = AVBELN

INNER JOIN MARA AS C ON CMATNR = BMATNR AND CSPART = BSPART

INTO TABLE ITAB WHERE CMTART = 'FERT' AND BWERKS = PLANT AND AVBELN IN SO_ORD AND CSPART IN DIV AND AERDAT IN SO_DATE AND BMATNR IN P_MATNR.

ITAB1[] = ITAB[].

SORT ITAB1 BY MATNR.

**********END - DATA RETERIVAL FROM TABLES**************************

******BEGIN - TAKING DATA FROM TABLE TO ITPL AND ITPO********

LOOP AT ITAB.

REFRESH ITPL.

SELECT MATNR KDAUF KDPOS PLNUM GSMNG AUFNR FROM PLAF INTO TABLE ITPL WHERE

KDAUF = ITAB-VBELN AND

KDPOS = ITAB-POSNR.

LOOP AT ITPL.

ITAB-PLNUM = ITPL-PLNUM.

ITAB-GSMNG = ITPL-GSMNG.

ITAB-MATNR = ITPL-MATNR.

ENDLOOP.

REFRESH ITPO.

SELECT MATNR KDAUF KDPOS PLNUM PSMNG AUFNR FROM AFPO INTO TABLE ITPO WHERE

KDAUF = ITAB-VBELN AND

KDPOS = ITAB-POSNR .

LOOP AT ITPO.

ITAB-AUFNR = ITPO-AUFNR.

ITAB-PSMNG = ITPO-PSMNG.

ITAB-MATNR = ITPL-MATNR.

ENDLOOP.

SELECT SINGLE MAKTG FROM MAKT INTO ITAB1-ITEMDESC WHERE MATNR = ITAB1-MATNR.

MODIFY ITAB.

ENDLOOP.

APPEND LINES OF ITPO TO ITPL.

SORT ITAB1 BY MATNR.

LOOP AT ITAB1.

AT NEW MATNR.

ITPL-MATNR = ITAB-MATNR.

ITPL-GSMNG = 0.

APPEND ITPL.

ENDAT.

ENDLOOP.

LOOP AT ITPL.

LOOP AT ITAB1 WHERE MATNR = ITPL-MATNR.

ITPL-GSMNG = ITPL-GSMNG + ITAB1-GSMNG.

ENDLOOP.

MODIFY ITPL.

ENDLOOP.

LOOP AT ITPL.

WRITE: / ITPL-MATNR,ITPL-GSMNG.

ENDLOOP.

Read only

Former Member
0 Likes
2,928

Hi Ricx



SORT ITAB1 BY ITEMID.

LOOP AT ITAB1.

ITPL-MATNR = ITAB1-ITEMID.
ITPL-GSMNG = 0.

AT NEW ITEMID.
APPEND ITPL.
ENDAT.

ENDLOOP.

LOOP AT ITPL.
LOOP AT ITAB1 WHERE ITEMID = ITPL-MATNR.

ITPL-GSMNG = ITPL-GSMNG + ITAB1-GSMNG.

ENDLOOP.

MODIFY ITPL.

ENDLOOP.

LOOP AT ITPL.

WRITE: / ITPL-MATNR,ITPL-GSMNG.

ENDLOOP.

In AT NEW control statement the problem is if the Right side fields of ITEMID will be '*' check this in Debugging... so thats why assign them before.

Hope this would solve your issue..

If any queries revert back..

Regards

Narin Nandivada

Read only

0 Likes
2,928

hi,

I had changed the code as us said but still it is not giving the desired result. here are the changes:-

TABLES: VBAK,VBAP,MARA.

************BEGIN - DATA DECLARATION IN ITAB*****************

DATA: BEGIN OF ITAB OCCURS 0,

MATNR LIKE VBAP-MATNR, "Material Number

VBELN LIKE VBAK-VBELN, "Sales Document

ERDAT LIKE VBAK-ERDAT, "Date on Which Record Was Created

WERKS LIKE VBAP-WERKS, "Plant (Own or External)

POSNR LIKE VBAP-POSNR, "Sales Document Item

SPART LIKE MARA-SPART, "Division

MEINS LIKE MARA-MEINS, "Unit Of Measurment

MTART LIKE MARA-MTART, "Material Type

NTGEW LIKE MARA-NTGEW, "Net Weight

GEWEI LIKE MARA-GEWEI, "Weight Unit

PLNUM LIKE PLAF-PLNUM, "Planned order number

GSMNG LIKE PLAF-GSMNG, "Total planned order quantity

KDAUF LIKE PLAF-KDAUF, "Sales Order Number

KDPOS LIKE PLAF-KDPOS, "Item Number in Sales Order

AUFNR LIKE AFPO-AUFNR, "Order Number

PSMNG LIKE AFPO-PSMNG, "Order item quantity

ITEMDESC LIKE MAKT-MAKTX, "Item Description

TOTWT1 LIKE PLAF-GSMNG, "Calculation 1

TOTWT2 LIKE AFPO-PSMNG, "Calculation 2

WTKG LIKE MARA-NTGEW, "Net Weight

TOT LIKE PLAF-GSMNG, "

END OF ITAB.

DATA: BEGIN OF ITAB1 OCCURS 0,

MATNR LIKE VBAP-MATNR, "Material Number

VBELN LIKE VBAK-VBELN, "Sales Document

ERDAT LIKE VBAK-ERDAT, "Date on Which Record Was Created

WERKS LIKE VBAP-WERKS, "Plant (Own or External)

POSNR LIKE VBAP-POSNR, "Sales Document Item

SPART LIKE MARA-SPART, "Division

MEINS LIKE MARA-MEINS, "Unit Of Measurment

MTART LIKE MARA-MTART, "Material Type

NTGEW LIKE MARA-NTGEW, "Net Weight

GEWEI LIKE MARA-GEWEI, "Weight Unit

PLNUM LIKE PLAF-PLNUM, "Planned order number

GSMNG LIKE PLAF-GSMNG, "Total planned order quantity

KDAUF LIKE PLAF-KDAUF, "Sales Order Number

KDPOS LIKE PLAF-KDPOS, "Item Number in Sales Order

AUFNR LIKE AFPO-AUFNR, "Order Number

PSMNG LIKE AFPO-PSMNG, "Order item quantity

ITEMDESC LIKE MAKT-MAKTX, "Item Description

TOTWT1 LIKE PLAF-GSMNG, "Calculation 1

TOTWT2 LIKE AFPO-PSMNG, "Calculation 2

WTKG LIKE MARA-NTGEW, "Net Weight

TOT LIKE PLAF-GSMNG, "

END OF ITAB1.

**********END - DATA DECLARATION IN ITAB*****************

************BEGIN - ITAB FOR PL.ORDR********************

DATA: BEGIN OF ITPL OCCURS 0,

MATNR LIKE AFPO-MATNR, "Material Number

KDAUF LIKE PLAF-KDAUF, "Sales Order Number

KDPOS LIKE PLAF-KDPOS, "Item Number in Sales Order

PLNUM LIKE AFPO-PLNUM, "Planned order number

GSMNG LIKE PLAF-GSMNG, "Total planned order quantity

AUFNR LIKE AFPO-AUFNR, "Order Number

TOT LIKE PLAF-GSMNG, "

END OF ITPL.

************END - ITAB FOR PL.ORDR***********************

***********BEGIN - ITAB FOR PRD.ORDR********************

DATA: BEGIN OF ITPO OCCURS 0,

MATNR LIKE AFPO-MATNR, "Material Number

KDAUF LIKE AFPO-KDAUF, "Sales Order Number

KDPOS LIKE AFPO-KDPOS, "Item Number in Sales Order

PLNUM LIKE AFPO-PLNUM, "Planned order number

PSMNG LIKE AFPO-PSMNG, "Order item quantity

AUFNR LIKE AFPO-AUFNR, "Order Number

TOT LIKE PLAF-GSMNG, "

END OF ITPO.

***********END - ITAB FOR PRD.ORDR********************

***********BEGIN - SELECTION SCREEN AND PARAMETERS AND VARIABLES**********

PARAMETERS : PLANT LIKE VBAP-WERKS OBLIGATORY.

SELECT-OPTIONS: SO_ORD FOR VBAK-VBELN,

DIV FOR MARA-SPART,

SO_DATE FOR VBAK-ERDAT,

P_MATNR FOR VBAP-MATNR.

***********END - SELECTION SCREEN AND PARAMETERS**********

**********BEGIN - DATA RETERIVAL FROM TABLES**************************

SELECT BMATNR AVBELN AERDAT BWERKS BPOSNR CSPART CMEINS CMTART CNTGEW CGEWEI

FROM VBAK AS A

INNER JOIN VBAP AS B ON BVBELN = AVBELN

INNER JOIN MARA AS C ON CMATNR = BMATNR AND CSPART = BSPART

INTO TABLE ITAB WHERE CMTART = 'FERT' AND BWERKS = PLANT AND AVBELN IN SO_ORD AND CSPART IN DIV AND AERDAT IN SO_DATE AND BMATNR IN P_MATNR.

ITAB1[] = ITAB[].

SORT ITAB1 BY MATNR.

**********END - DATA RETERIVAL FROM TABLES**************************

******BEGIN - TAKING DATA FROM TABLE TO ITPL AND ITPO********

LOOP AT ITAB.

REFRESH ITPL.

SELECT MATNR KDAUF KDPOS PLNUM GSMNG AUFNR FROM PLAF INTO TABLE ITPL WHERE

KDAUF = ITAB-VBELN AND

KDPOS = ITAB-POSNR.

LOOP AT ITPL.

ITAB-PLNUM = ITPL-PLNUM.

ITAB-GSMNG = ITPL-GSMNG.

ITAB-MATNR = ITPL-MATNR.

ENDLOOP.

REFRESH ITPO.

SELECT MATNR KDAUF KDPOS PLNUM PSMNG AUFNR FROM AFPO INTO TABLE ITPO WHERE

KDAUF = ITAB-VBELN AND

KDPOS = ITAB-POSNR .

LOOP AT ITPO.

ITAB-AUFNR = ITPO-AUFNR.

ITAB-PSMNG = ITPO-PSMNG.

ITAB-MATNR = ITPL-MATNR.

ENDLOOP.

SELECT SINGLE MAKTG FROM MAKT INTO ITAB1-ITEMDESC WHERE MATNR = ITAB1-MATNR.

MODIFY ITAB.

ENDLOOP.

APPEND LINES OF ITPO TO ITPL.

SORT ITAB1 BY MATNR.

LOOP AT ITAB1.

ITPL-MATNR = ITAB1-MATNR.

ITPL-GSMNG = 0.

AT NEW MATNR.

APPEND ITPL.

ENDAT.

ENDLOOP.

LOOP AT ITPL.

LOOP AT ITAB1 WHERE MATNR = ITPL-MATNR.

ITPL-GSMNG = ITPL-GSMNG + ITAB1-GSMNG.

ENDLOOP.

MODIFY ITPL.

ENDLOOP.

LOOP AT ITPL.

WRITE: / ITPL-MATNR,ITPL-GSMNG.

ENDLOOP.

Read only

Former Member
0 Likes
2,928

Hi,

In yuor program check this code ,

LOOP AT ITPO.
ITAB-AUFNR = ITPO-AUFNR.
ITAB-PSMNG = ITPO-PSMNG.
ITAB-MATNR = ITPL-MATNR.    " If this is the value you are 
" using in below SELECT statement then deffinately there it is 
" ITAB-MATNR   not  ITAB1-MATNR

ENDLOOP.

*SELECT SINGLE MAKTG FROM MAKT INTO ITAB1-ITEMDESC WHERE MATNR =
ITAB1-MATNR.   " Here you are fetching data matnr = ITAB1-MATNR 
" but within the loop there is no value corresponding to that 
"  TAB1-MATNR . So you will not get any value. I think it is  
"   ITAB-MATNR   instead of   ITAB1-MATNR   Check this .
MODIFY ITAB.
ENDLOOP.

APPEND LINES OF ITPO TO ITPL.

SORT ITAB1 BY MATNR.

LOOP AT ITAB1.

AT NEW MATNR.

ITPL-MATNR = ITAB-MATNR.
ITPL-GSMNG = 0.

APPEND ITPL.

ENDAT.
ENDLOOP.

Regards,

Rajitha.

Edited by: Rajitha Muthineni on Jul 19, 2008 12:54 PM

Read only

0 Likes
2,928

HI,

I had tried to change the code but it is displaying the same result set .

tell me what should i do?

Read only

Former Member
0 Likes
2,928

Hi,

First main thing is in your program the first SELECT statement

is returning SY-SUBRC = 4.

Chek the select statement . If There is no records in any

internal table then how can you get the output ?

Go to Debugging and see values in ITAB . Nothing is there in

that internal table . Because SY-SUBRC NE 0.

check your code , you are selecting MAKTG into ITAB1-ITEMDESC and then you are modifying ITAB.

You need to modify ITAB1.

And also in your

SELECT SINGLE MAKTG FROM MAKT INTO ITAB1-ITEMDESC WHERE MATNR = ITAB1-MATNR.

MODIFY ITAB.

Regards,

Rajitha.

Read only

Former Member
0 Likes
2,928

Hi Ricx,

Use the keyword SUM inside the at statement...

SORT ITAB1 BY ITEMID.

LOOP AT ITAB1.

AT NEW ITEMID.

ITPL-MATNR = ITAB1-ITEMID.

ITPL-GSMNG = 0.

APPEND ITPL.

ENDAT.

ENDLOOP.

LOOP AT ITPL.

LOOP AT ITAB1 WHERE ITEMID = ITPL-MATNR.

at first.

sum. "( all numeric field willl be summed up inside this statement.)

endat.

ITPL-GSMNG = ITPL-GSMNG + ITAB1-GSMNG.

ENDLOOP.

MODIFY ITPL.

ENDLOOP.

LOOP AT ITPL.

WRITE: / ITPL-MATNR,ITPL-GSMNG.

ENDLOOP.

With luck,

Pritam.

Read only

0 Likes
2,928

HI PRITAM,

I had added the code of sum statement and it is still not working .i had checked in the debug mode and there when last loop starts after modifying ITPL the error occurs and the output is displayed as it is without performing calculation.

here's d code i am using now:-

TABLES: VBAK,VBAP,MARA.

************BEGIN - DATA DECLARATION IN ITAB*****************

DATA: BEGIN OF ITAB OCCURS 0,

MATNR LIKE VBAP-MATNR, "Material Number

VBELN LIKE VBAK-VBELN, "Sales Document

ERDAT LIKE VBAK-ERDAT, "Date on Which Record Was Created

WERKS LIKE VBAP-WERKS, "Plant (Own or External)

POSNR LIKE VBAP-POSNR, "Sales Document Item

SPART LIKE MARA-SPART, "Division

MEINS LIKE MARA-MEINS, "Unit Of Measurment

MTART LIKE MARA-MTART, "Material Type

NTGEW LIKE MARA-NTGEW, "Net Weight

GEWEI LIKE MARA-GEWEI, "Weight Unit

PLNUM LIKE PLAF-PLNUM, "Planned order number

GSMNG LIKE PLAF-GSMNG, "Total planned order quantity

KDAUF LIKE PLAF-KDAUF, "Sales Order Number

KDPOS LIKE PLAF-KDPOS, "Item Number in Sales Order

AUFNR LIKE AFPO-AUFNR, "Order Number

PSMNG LIKE AFPO-PSMNG, "Order item quantity

ITEMDESC LIKE MAKT-MAKTX, "Item Description

TOTWT1 LIKE PLAF-GSMNG, "Calculation 1

TOTWT2 LIKE AFPO-PSMNG, "Calculation 2

WTKG LIKE MARA-NTGEW, "Net Weight

TOT LIKE PLAF-GSMNG, "

END OF ITAB.

DATA: BEGIN OF ITAB1 OCCURS 0,

MATNR LIKE VBAP-MATNR, "Material Number

VBELN LIKE VBAK-VBELN, "Sales Document

ERDAT LIKE VBAK-ERDAT, "Date on Which Record Was Created

WERKS LIKE VBAP-WERKS, "Plant (Own or External)

POSNR LIKE VBAP-POSNR, "Sales Document Item

SPART LIKE MARA-SPART, "Division

MEINS LIKE MARA-MEINS, "Unit Of Measurment

MTART LIKE MARA-MTART, "Material Type

NTGEW LIKE MARA-NTGEW, "Net Weight

GEWEI LIKE MARA-GEWEI, "Weight Unit

PLNUM LIKE PLAF-PLNUM, "Planned order number

GSMNG LIKE PLAF-GSMNG, "Total planned order quantity

KDAUF LIKE PLAF-KDAUF, "Sales Order Number

KDPOS LIKE PLAF-KDPOS, "Item Number in Sales Order

AUFNR LIKE AFPO-AUFNR, "Order Number

PSMNG LIKE AFPO-PSMNG, "Order item quantity

ITEMDESC LIKE MAKT-MAKTX, "Item Description

TOTWT1 LIKE PLAF-GSMNG, "Calculation 1

TOTWT2 LIKE AFPO-PSMNG, "Calculation 2

WTKG LIKE MARA-NTGEW, "Net Weight

TOT LIKE PLAF-GSMNG, "

END OF ITAB1.

**********END - DATA DECLARATION IN ITAB*****************

************BEGIN - ITAB FOR PL.ORDR********************

DATA: BEGIN OF ITPL OCCURS 0,

MATNR LIKE PLAF-MATNR, "Material Number

KDAUF LIKE PLAF-KDAUF, "Sales Order Number

KDPOS LIKE PLAF-KDPOS, "Item Number in Sales Order

PLNUM LIKE PLAF-PLNUM, "Planned order number

GSMNG LIKE PLAF-GSMNG, "Total planned order quantity

AUFNR LIKE PLAF-AUFNR, "Order Number

END OF ITPL.

************END - ITAB FOR PL.ORDR***********************

***********BEGIN - ITAB FOR PRD.ORDR********************

DATA: BEGIN OF ITPO OCCURS 0,

MATNR LIKE AFPO-MATNR, "Material Number

KDAUF LIKE AFPO-KDAUF, "Sales Order Number

KDPOS LIKE AFPO-KDPOS, "Item Number in Sales Order

PLNUM LIKE AFPO-PLNUM, "Planned order number

PSMNG LIKE AFPO-PSMNG, "Order item quantity

AUFNR LIKE AFPO-AUFNR, "Order Number

END OF ITPO.

***********END - ITAB FOR PRD.ORDR********************

***********BEGIN - SELECTION SCREEN AND PARAMETERS AND VARIABLES**********

PARAMETERS : PLANT LIKE VBAP-WERKS OBLIGATORY.

SELECT-OPTIONS: SO_ORD FOR VBAK-VBELN,

DIV FOR MARA-SPART,

SO_DATE FOR VBAK-ERDAT,

P_MATNR FOR VBAP-MATNR.

***********END - SELECTION SCREEN AND PARAMETERS**********

**********BEGIN - DATA RETERIVAL FROM TABLES**************************

SELECT BMATNR AVBELN AERDAT BWERKS BPOSNR CSPART CMEINS CMTART CNTGEW CGEWEI

FROM VBAK AS A

INNER JOIN VBAP AS B ON BVBELN = AVBELN

INNER JOIN MARA AS C ON CMATNR = BMATNR AND CSPART = BSPART

INTO TABLE ITAB WHERE CMTART = 'FERT' AND BWERKS = PLANT AND AVBELN IN SO_ORD AND CSPART IN DIV AND AERDAT IN SO_DATE AND BMATNR IN P_MATNR.

ITAB1[] = ITAB[].

SORT ITAB1 BY VBELN MATNR.

**********END - DATA RETERIVAL FROM TABLES**************************

******BEGIN - TAKING DATA FROM TABLE TO ITPL AND ITPO********

LOOP AT ITAB.

REFRESH ITPL.

SELECT MATNR KDAUF KDPOS PLNUM GSMNG AUFNR FROM PLAF INTO TABLE ITPL WHERE

KDAUF = ITAB-VBELN AND

KDPOS = ITAB-POSNR.

LOOP AT ITPL.

ITAB-PLNUM = ITPL-PLNUM.

ITAB-GSMNG = ITPL-GSMNG.

ITAB-MATNR = ITPL-MATNR.

ENDLOOP.

REFRESH ITPO.

SELECT MATNR KDAUF KDPOS PLNUM PSMNG AUFNR FROM AFPO INTO TABLE ITPO WHERE

KDAUF = ITAB-VBELN AND

KDPOS = ITAB-POSNR.

LOOP AT ITPO.

ITAB-AUFNR = ITPO-AUFNR.

ITAB-PSMNG = ITPO-PSMNG.

ITAB-MATNR = ITPO-MATNR.

ENDLOOP.

MODIFY ITAB.

ENDLOOP.

APPEND LINES OF ITPO TO ITPL.

SORT ITPO BY MATNR.

LOOP AT ITAB1.

AT NEW MATNR.

ITPL-MATNR = ITAB1-MATNR.

ITPL-GSMNG = 0.

APPEND ITPL.

ENDAT.

ENDLOOP.

LOOP AT ITPL.

LOOP AT ITAB1 WHERE MATNR = ITPL-MATNR.

AT FIRST.

SUM.

ITPL-GSMNG = ITPL-GSMNG + ITAB1-GSMNG.

ENDAT.

ENDLOOP.

MODIFY ITPL.

ENDLOOP.

LOOP AT ITPL.

WRITE: / ITPL-MATNR,ITPL-GSMNG.

ENDLOOP.

Edited by: ricx .s on Jul 19, 2008 11:40 AM

Read only

0 Likes
2,928

Hi Ricx,

i am not getting your requirement , however either display the value inside the AT statement where you are doing the SUM or store the value of of summation in another variable inside the AT.

With luck,

Pritam.

Read only

0 Likes
2,928

hi,

the output which i am getting right now is:-

200637 204.000

220644 100.000

220644 304.000

200637 100.000

200637 100.000

but i want to have output:-

200637 404

220644 404

these vales are ciming from the ITPL and i am not able to display the desiered result ,plzz provide me guidelines for it ...

Edited by: ricx .s on Jul 22, 2008 6:06 AM

Read only

0 Likes
2,928

Hi,

Try this code,

LOOP AT ITPL.

Read Table ITAB1 with Key MATNR = ITPL-MATNR.

ITPL-GSMNG = ITPL-GSMNG + ITAB1-GSMNG.

modify itpl index sy-tabix.

ENDLOOP.

LOOP AT ITPL.

WRITE: / ITPL-MATNR,ITPL-GSMNG.

ENDLOOP.

Thanks & Regards,

Nagaraj Kalbavi

Read only

0 Likes
2,928

Hi Nagraj and Keshu,

i had tried the code u had told but it is giving the run time error.. at endloop after the line:- " modify itpl index sy-tabix."

the full code which i am using after the modification told by you is:-

TABLES: VBAK,VBAP,MARA.

************BEGIN - DATA DECLARATION IN ITAB*****************

DATA: BEGIN OF ITAB OCCURS 0,

MATNR LIKE VBAP-MATNR, "Material Number

VBELN LIKE VBAK-VBELN, "Sales Document

ERDAT LIKE VBAK-ERDAT, "Date on Which Record Was Created

WERKS LIKE VBAP-WERKS, "Plant (Own or External)

POSNR LIKE VBAP-POSNR, "Sales Document Item

SPART LIKE MARA-SPART, "Division

MEINS LIKE MARA-MEINS, "Unit Of Measurment

MTART LIKE MARA-MTART, "Material Type

NTGEW LIKE MARA-NTGEW, "Net Weight

GEWEI LIKE MARA-GEWEI, "Weight Unit

PLNUM LIKE PLAF-PLNUM, "Planned order number

GSMNG LIKE PLAF-GSMNG, "Total planned order quantity

KDAUF LIKE PLAF-KDAUF, "Sales Order Number

KDPOS LIKE PLAF-KDPOS, "Item Number in Sales Order

AUFNR LIKE AFPO-AUFNR, "Order Number

PSMNG LIKE AFPO-PSMNG, "Order item quantity

ITEMDESC LIKE MAKT-MAKTX, "Item Description

TOTWT1 LIKE PLAF-GSMNG, "Calculation 1

TOTWT2 LIKE AFPO-PSMNG, "Calculation 2

WTKG LIKE MARA-NTGEW, "Net Weight

TOT LIKE PLAF-GSMNG, "

END OF ITAB.

DATA: BEGIN OF ITAB1 OCCURS 0,

MATNR LIKE VBAP-MATNR, "Material Number

VBELN LIKE VBAK-VBELN, "Sales Document

ERDAT LIKE VBAK-ERDAT, "Date on Which Record Was Created

WERKS LIKE VBAP-WERKS, "Plant (Own or External)

POSNR LIKE VBAP-POSNR, "Sales Document Item

SPART LIKE MARA-SPART, "Division

MEINS LIKE MARA-MEINS, "Unit Of Measurment

MTART LIKE MARA-MTART, "Material Type

NTGEW LIKE MARA-NTGEW, "Net Weight

GEWEI LIKE MARA-GEWEI, "Weight Unit

PLNUM LIKE PLAF-PLNUM, "Planned order number

GSMNG LIKE PLAF-GSMNG, "Total planned order quantity

KDAUF LIKE PLAF-KDAUF, "Sales Order Number

KDPOS LIKE PLAF-KDPOS, "Item Number in Sales Order

AUFNR LIKE AFPO-AUFNR, "Order Number

PSMNG LIKE AFPO-PSMNG, "Order item quantity

ITEMDESC LIKE MAKT-MAKTX, "Item Description

TOTWT1 LIKE PLAF-GSMNG, "Calculation 1

TOTWT2 LIKE AFPO-PSMNG, "Calculation 2

WTKG LIKE MARA-NTGEW, "Net Weight

TOT LIKE PLAF-GSMNG, "

END OF ITAB1.

**********END - DATA DECLARATION IN ITAB*****************

************BEGIN - ITAB FOR PL.ORDR********************

DATA: BEGIN OF ITPL OCCURS 0,

MATNR LIKE PLAF-MATNR, "Material Number

KDAUF LIKE PLAF-KDAUF, "Sales Order Number

KDPOS LIKE PLAF-KDPOS, "Item Number in Sales Order

PLNUM LIKE PLAF-PLNUM, "Planned order number

GSMNG LIKE PLAF-GSMNG, "Total planned order quantity

AUFNR LIKE PLAF-AUFNR, "Order Number

VQTY LIKE PLAF-GSMNG,

END OF ITPL.

************END - ITAB FOR PL.ORDR***********************

***********BEGIN - ITAB FOR PRD.ORDR********************

DATA: BEGIN OF ITPO OCCURS 0,

MATNR LIKE AFPO-MATNR, "Material Number

KDAUF LIKE AFPO-KDAUF, "Sales Order Number

KDPOS LIKE AFPO-KDPOS, "Item Number in Sales Order

PLNUM LIKE AFPO-PLNUM, "Planned order number

PSMNG LIKE AFPO-PSMNG, "Order item quantity

AUFNR LIKE AFPO-AUFNR, "Order Number

VQTY LIKE PLAF-GSMNG,

END OF ITPO.

***********END - ITAB FOR PRD.ORDR********************

***********BEGIN - SELECTION SCREEN AND PARAMETERS AND VARIABLES**********

PARAMETERS : PLANT LIKE VBAP-WERKS OBLIGATORY.

SELECT-OPTIONS: SO_ORD FOR VBAK-VBELN,

DIV FOR MARA-SPART,

SO_DATE FOR VBAK-ERDAT,

P_MATNR FOR VBAP-MATNR.

***********END - SELECTION SCREEN AND PARAMETERS**********

**********BEGIN - DATA RETERIVAL FROM TABLES**************************

SELECT BMATNR AVBELN AERDAT BWERKS BPOSNR CSPART CMEINS CMTART CNTGEW CGEWEI

FROM VBAK AS A

INNER JOIN VBAP AS B ON BVBELN = AVBELN

INNER JOIN MARA AS C ON CMATNR = BMATNR AND CSPART = BSPART

INTO TABLE ITAB WHERE CMTART = 'FERT' AND BWERKS = PLANT AND AVBELN IN SO_ORD AND CSPART IN DIV AND AERDAT IN SO_DATE AND BMATNR IN P_MATNR.

ITAB1[] = ITAB[].

SORT ITAB1 BY VBELN MATNR.

**********END - DATA RETERIVAL FROM TABLES**************************

******BEGIN - TAKING DATA FROM TABLE TO ITPL AND ITPO********

LOOP AT ITAB.

REFRESH ITPL.

SELECT MATNR KDAUF KDPOS PLNUM GSMNG AUFNR FROM PLAF INTO TABLE ITPL WHERE

KDAUF = ITAB-VBELN AND

KDPOS = ITAB-POSNR.

LOOP AT ITPL.

ITAB-PLNUM = ITPL-PLNUM.

ITAB-GSMNG = ITPL-GSMNG.

ITAB-MATNR = ITPL-MATNR.

ENDLOOP.

REFRESH ITPO.

SELECT MATNR KDAUF KDPOS PLNUM PSMNG AUFNR FROM AFPO INTO TABLE ITPO WHERE

KDAUF = ITAB-VBELN AND

KDPOS = ITAB-POSNR.

LOOP AT ITPO.

ITAB-AUFNR = ITPO-AUFNR.

ITAB-PSMNG = ITPO-PSMNG.

ITAB-MATNR = ITPO-MATNR.

ENDLOOP.

MODIFY ITAB.

ENDLOOP.

APPEND LINES OF ITPO TO ITPL.

SORT ITPO BY MATNR.

LOOP AT ITPL.

READ TABLE ITAB1 WITH KEY MATNR = ITPL-MATNR.

ITPL-GSMNG = ITPL-GSMNG + ITAB1-GSMNG.

modify itpl index sy-tabix.

ENDLOOP.

LOOP AT ITPL.

WRITE: / ITPL-MATNR,ITPL-gsmng.

ENDLOOP.

Edited by: ricx .s on Jul 22, 2008 7:15 AM

Read only

0 Likes
2,928

Hi Rich,

Remove Index sy-tabix from Modify ITPL and let me know does it work.

or use Modify ITPL transporting field name.

Thanks & Regards,

Nagaraj Kalbavi

Edited by: Nagaraj Kalbavi on Jul 22, 2008 7:21 AM

Read only

0 Likes
2,928

hi,

LOOP AT ITPL.

READ TABLE ITAB1 WITH KEY MATNR = ITPL-MATNR.

ITPL-GSMNG = ITPL-GSMNG + ITAB1-GSMNG.
modify itpl index sy-tabix.
ENDLOOP.

here the sy-tabix will be referring to READ's sy-tabix.

jus replace the above modify with this:

modify itpl transporting gsmng.

or

LOOP AT ITPL.
v_tabix = sy-tabix.
READ TABLE ITAB1 WITH KEY MATNR = ITPL-MATNR.
ITPL-GSMNG = ITPL-GSMNG + ITAB1-GSMNG.
modify itpl index v_tabix.
ENDLOOP.

Read only

0 Likes
2,928

hi madhumita n nagraj,

i had done the modification as u had said and dere is no run-time error but 1 problem is still there that the calculation is not performed i.e. which is the thing i want to do:-

the output which i am getting right now is:-

200637 204.000

220644 100.000

220644 304.000

200637 100.000

200637 100.000

but i want to have output:-

200637 404

220644 404

how should i do this .....

Read only

0 Likes
2,928

hi,

populate the desired output in to another table as you might have to delete the duplicate matnrs after finding the total.


sort itpl by matnr.
LOOP AT ITPL.
v_tabix = sy-tabix.
READ TABLE ITAB1 WITH KEY MATNR = ITPL-MATNR.
it_final-GSMNG = ITPL-GSMNG + ITAB1-GSMNG.
at end of matnr.
 modify itpl index v_tabix.
endat.
ENDLOOP.
sort itpl by matnr gsmng descending.
delete adjacent duplicates comparing matnr gsmng.

or

data: it_final like itpl occurs 0 with header line.
sort itpl by matnr.
LOOP AT ITPL.
v_tabis = sy-tabix.
at new matnr.
read table itpl index v_tabix.
if sy-subrc = 0.
  move-corresponding itpl to it_final.
endif.
endat.
READ TABLE ITAB1 WITH KEY MATNR = ITPL-MATNR.
it_final-GSMNG = ITPL-GSMNG + ITAB1-GSMNG.
at end of matnr.
append it_final.
clear it_final.
endat.
ENDLOOP.

regards,

madhu

Read only

0 Likes
2,928

Hi Ricx,

Could you please do me favor,

Put a break point at ITPL-GSMNG = ITPL-GSMNG + ITAB1-GSMNG. and tell me what data it is picking up in this line and what it is modifying.

I have doubt at this statement.

Thanks & Regards,

Nagaraj Kalbavi

Read only

0 Likes
2,928

HI Nagraj and Madhu,

Nagraj --> I had put a break point on that calculation field it is just taking the values when i check in the debug mode.. no calculation is performed i.e. in the table ITPL i had addpended the lines of ITPO so that in the end i can display the calculated values of quantity in the output.

Madumita --> I had done the modification as u said but it is just picking up the 1 value of each matnr nothing else.

Read only

0 Likes
2,928

Try this :

* Changes made
DATA: V_GSMNG LIKE PLAF-GSMNG,
      V_TABIX LIKE SY-TABIX.
SORT ITPL BY MATNR.
LOOP AT ITPL.
V_TABIX = SY-TABIX.
READ TABLE ITAB1 WITH KEY MATNR = ITPL-MATNR.
V_GSMNG = ITPL-GSMNG + ITAB1-GSMNG.

AT END OF MATNR.
ITPL-GSMNG = V_GSMNG.
MODIFY ITPL TRANSPORTING GSMNG.
ENDAT.
ENDLOOP.
SORT ITPL BY MATNR GSMNG DESCENDING.
DELETE ADJACENT DUPLICATES FROM ITPL COMPARING MATNR GSMNG.
LOOP AT ITPL.
WRITE: / ITPL-MATNR,ITPL-gsmng.
ENDLOOP.

Read only

0 Likes
2,928

hi nagraj and madhumita,

i am closing this thread i had changed the way of doing this problem but i am assigning you both 6 points each for helping me to solve this problem.

i will now post new thread for my new code where i am facing a problem.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
2,928

ur appendng itpl....

as per ur code itpl consists of matnr first...then how can u append itpl instead of modify....

just keep a bupoint while appending ITPL...there will be a problem...just check it out...

ur process logic is incorrect....

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
2,928

its just a matter of debugging....

also check whether item id has any left dependant fields...if any fields to the left of it changes before the end of a item...this wont work..

try putting the itemid as the first field of itab1

ckeck this


sort itab1 by itemid

LOOP AT ITAB1.
at end of ITEMID.
sum.
write / ITAB1-itemid
write  ITAB1-GSMNG.
endat.
ENDLOOP.

Read only

former_member70391
Contributor
0 Likes
2,928

hi,

Check this code,

REPORT ZTEST01.

DATA: BEGIN OF ITAB1 OCCURS 0,

MATNR(18) TYPE C,

GSMNG TYPE I,

END OF ITAB1.

DATA: BEGIN OF ITPL OCCURS 0,

MATNR(18) TYPE C,

GSMNG TYPE I,

END OF ITPL.

ITAB1-MATNR = '200637'.

ITAB1-GSMNG = '204.000'.

APPEND ITAB1.

ITAB1-MATNR = '220644'.

ITAB1-GSMNG = '100.000'.

APPEND ITAB1.

ITAB1-MATNR = '220644'.

ITAB1-GSMNG = '304.000'.

APPEND ITAB1.

ITAB1-MATNR = '200637'.

ITAB1-GSMNG = '100.000'.

APPEND ITAB1.

ITAB1-MATNR = '200637'.

ITAB1-GSMNG = '100.000'.

APPEND ITAB1.

*----


ITPL-MATNR = '200637'.

APPEND ITPL.

ITPL-MATNR = '220644'.

APPEND ITPL.

WRITE: 'ITAB1'.

LOOP AT ITAB1.

WRITE: / ITAB1-MATNR, ITAB1-GSMNG.

ENDLOOP.

SKIP 1.

WRITE: 'ITPL'.

LOOP AT ITPL.

WRITE: / ITPL-MATNR, ITPL-GSMNG.

ENDLOOP.

CLEAR: ITPL.

LOOP AT ITPL.

LOOP AT ITAB1 WHERE MATNR = ITPL-MATNR.

ITPL-GSMNG = ITPL-GSMNG + ITAB1-GSMNG.

MODIFY ITPL TRANSPORTING GSMNG.

ENDLOOP.

ENDLOOP.

SKIP 1.

WRITE: 'FINAL ITPL'.

LOOP AT ITPL.

WRITE: / ITPL-MATNR, ITPL-GSMNG.

ENDLOOP.

Output:

-


ITAB1

200637 204

220644 100

220644 304

200637 100

200637 100

ITPL

200637 0

220644 0

FINAL ITPL

200637 404

220644 404

Read only

Former Member
0 Likes
2,928

i am closing this thread as i had to change the requirement and i had awarded the main users who help me in trying to solve this problem.