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

problem in Control Break Statement

Former Member
0 Likes
2,207

Hi everybody,

i am having same material no 4 to 5 times in the table MSEG with different qty. now in my output i have to display the material and the total qty .

so i am using the control break statements and adding the qty here.

but when i am using teh control break statement AT NEW MATNR, it is not triggering for me once, AT NEW command is triggering for every loop and for the same material.

this is the code which i have written, can anybody correct me in this where i have written the wrong.

TYPES : BEGIN OF TY_MSEG,

MBLNR TYPE MBLNR,

MJAHR TYPE MJAHR,

MATNR TYPE MATNR,

MEINS TYPE MEINS,

MENGE TYPE MENGE_D,

BWART TYPE BWART,

WERKS TYPE WERKS_D,

END OF TY_MSEG.

TYPES : BEGIN OF TY_MSEG1,

MJAHR TYPE MJAHR,

MATNR TYPE MATNR,

MEINS TYPE MEINS,

MENGE TYPE MENGE_D,

END OF TY_MSEG1.

TYPES: BEGIN OF TY_COLLECT,

MATNR TYPE MATNR,

MENGE TYPE MENGE_D,

END OF TY_COLLECT.

DATA : GT_MSEG TYPE STANDARD TABLE OF TY_MSEG,

GT_MSEG1 TYPE STANDARD TABLE OF TY_MSEG1,

GT_COLLECT TYPE STANDARD TABLE OF TY_COLLECT.

DATA : WA_MSEG TYPE TY_MSEG,

WA_MSEG1 TYPE TY_MSEG1,

WA_COLLECT TYPE TY_COLLECT.

***********code using the control break statements******

LOOP AT GT_MSEG INTO WA_MSEG.

AT NEW MATNR.

WA_MSEG1-MJAHR = WA_MSEG-MJAHR.

WA_MSEG1-MATNR = WA_MSEG-MATNR.

WA_MSEG1-MEINS = WA_MSEG-MEINS.

ENDAT.

MOVE-CORRESPONDING WA_MSEG TO WA_COLLECT.

COLLECT WA_COLLECT INTO GT_COLLECT.

AT LAST MATNR.

WA_MSEG1-MENGE = WA_COLLECT-MENGE.

ENDAT.

APPEND WA_MSEG1 TO GT_MSEG1.

ENDLOOP.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,616

Hi

The event AT NEW <field> is triggered if the value of field <field> is changed or if a value of a field at the left of <field> is changed too.

Your internal table GT_MSEG is like the type TY_MSEG, here there are the fiellds MBLNR and MJAHR before MATNR, so

AT NEW MATNR is triggered if a value of MBLNR, MJAHR and MATNR is changed.

If you want the event is trggiered for MATNR only, you need to place MATNR as first field:

TYPES : BEGIN OF TY_MSEG,
   MANTNR TYPE MATNR,
   MBLNR TYPE MBLNR,
   MJAHR TYPE MJAHR,
   MEINS TYPE MEINS,
   MENGE TYPE MENGE_D,
   BWART TYPE BWART,
   WERKS TYPE WERKS_D,
END OF TY_MSEG.

Max

10 REPLIES 10
Read only

Former Member
0 Likes
1,617

Hi

The event AT NEW <field> is triggered if the value of field <field> is changed or if a value of a field at the left of <field> is changed too.

Your internal table GT_MSEG is like the type TY_MSEG, here there are the fiellds MBLNR and MJAHR before MATNR, so

AT NEW MATNR is triggered if a value of MBLNR, MJAHR and MATNR is changed.

If you want the event is trggiered for MATNR only, you need to place MATNR as first field:

TYPES : BEGIN OF TY_MSEG,
   MANTNR TYPE MATNR,
   MBLNR TYPE MBLNR,
   MJAHR TYPE MJAHR,
   MEINS TYPE MEINS,
   MENGE TYPE MENGE_D,
   BWART TYPE BWART,
   WERKS TYPE WERKS_D,
END OF TY_MSEG.

Max

Read only

0 Likes
1,616

Hi Max

thanks for replying. i have changed the type declaration as u said, and it is working now. and i have written the sort command before the loop using matnr got the internal table and then i have started the loop.

now the at new command is triggering correctly,

but there some prob still lies here,

before coming to the at new command i am checking the values of these fields

WA_MSEG-MJAHR, WA_MSEG-MEINS. the values are present but after the at new command triggered there is no values in it, it is coming of in ***.

so can you please guide in this.....

Read only

0 Likes
1,616

Hi

But you can't use AT NEW for all fields, it doesn't make a sense......you need to think another logic,

Just as I said before....AT NEW <field> is triggered is a value of a field on the left of <field> is changing.

In generally this event is usedt nested

WHat do you want to do?

Max

Read only

0 Likes
1,616

Acutally in my final output, i have display the material, total qty, year, unit of measure.

Read only

0 Likes
1,616

Hi,

If you write any field value between AT NEW statement the value will be * only. Only the MATNR contains the value other field contains only * value only. suppose before MATNR any field you declare in Types that field contain some value. Correct the code like that.


clear lv_menge.
LOOP AT GT_MSEG INTO WA_MSEG.

AT NEW MATNR.
Flag = 'X'.
ENDAT.

if Flag = 'X'.
WA_MSEG1-MJAHR = WA_MSEG-MJAHR.
WA_MSEG1-MATNR = WA_MSEG-MATNR.
WA_MSEG1-MEINS = WA_MSEG-MEINS.
Endif.

lv_menge = lv_menge + WA_MSEG-menge.

AT LAST MATNR.
WA_MSEG1-MENGE = lv_menge.
append wa_mseg1 TO GT_MSEG1."append here 
ENDAT.

Endloop.

Now try this code.. it will work..

Regards,

Dhina..

Edited by: Dhina DMD on Sep 24, 2011 12:06 PM

Read only

0 Likes
1,616

Thanks Dina, for helping....

Now still there some more logic have to been added now....

now i have to calculate the quantity of each material by the monthly wise and send it to the final internal table.....

Read only

0 Likes
1,616

Hi everyone,

can anybody let me now how to calculate the each material total qty for a monthly wise. i am taking the data from the table mkpf where we can find out the document no, year and the date. with that i have to go to mseg take and collect the material as per the budat monthly wise and calculate the each material's total qty montly wise and have to display in output from jan to dec....

so can anyone help me out in this to write the logic...

Thanks in advance...

Read only

0 Likes
1,616

Hi mhyderali,

if you need monthly aggregation, you should have a period field, move the material document date to a period field (Type ACCP - Accounting period YYYYMM).

The forget about all you AT NEW AT LAST and so on but create output using (S)ALV. Everything you mentionend is built-in ALV functionality. And you need not special column sequence for SORTS, TOTAL and SUBTOTAL.

Regards,

Clemens

Read only

0 Likes
1,616

Hi,

What you could have done is, you could have joined MKPF and MSEG based on Material document number and Calender year to get all data in a single internal table. The sequence of fields could have been,


TYPES: BEGIN OF ty_getdata,
       month TYPE t54c6-smont,
       matnr TYPE mseg-matnr,
       .
       .
       ... Rest of the fields,
       END OF ty_get_data.

While looping your internal table you could have transferred the month of posting date to the field month of your internal table. Then you could have used AT NEW MATNR to calculate the total quantity for each material for every month.

Regards,

Danish.

Read only

Former Member
0 Likes
1,616

Hi,

The Only resone I feel for this problem may be,you did not sort the IT before using At New .

Since your internal table have MBLNR as first field and may be data is sorted according to that field.

Try this out

SORT IT by MATNR. 

 your code for LOOP and Control Break Stat 

.

Write keyword SUM in AT NEW to get the total for all the Numberic fields.

Thanks,

Anmol.

Edited by: anmol112 on Sep 26, 2011 1:36 AM