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

Control Break help needed.

Former Member
0 Likes
1,082

Hi All,

I need help in writing the code. I have a requirement where I need to sum up all items-entries in the sample codes below that has same split batch indicator of a particular document.

And not to sum up if split_batch fields are initial and not of a particular document type. How should I go ahead. Should I use At new at end of or on change of?

For eg: if      belnr                   buzei                          split_batch                   wrbtr                blart

                   1000010               001                               '   '                           1.75                   NC

                   1000010              002                                '  '                            2.0                    VR

                   1000011              001                                 1                            2.0                     IC

                    1000011             002                                 1                            3.0                     IC

                     1000012            001                                  2                           4.0                     IC

                    1000012              002                                 2                           5.0                     IC

Then my output expected is :-

belnr               buzei                      split_batch               wrbtr            blart

                   1000010               001                               '   '                           1.75                   NC      " No change as no split indicator and doc type ne IC

                   1000010              002                                '  '                            2.0                    VR       " No change as no split indicator and doc type ne IC

                   1000011              001/ or 002                      1                            5.0                    IC         " After sum 2.0 + 3.0

                   1000012            001/ or 002                         2                           9.0                    IC          " After sum 4.0 + 5.0

                  

Please see the code below and suggest if the code below is good or some one can sugggest better ways of doing so .......

Thanks,

MS.

types: begin of typ.

belnr type bseg-belnr,

buzei type bseg-buzei,

split_batch type bseg-fm_batch_split,

wrbtr type bseg-wrbtr,

blart type bkpf-blart,

end of typ.

data: itab type table of typ.

data: wa type typ.

sort itab by belnr buzei split_batch.

loop at itab into wa.

if wa-split_batch is not initial and if wa-blart = 'IC'.

on change of split_batch.

sum (wrbtr).

else.

continue.

endon.

endif.

write:/ wa-belnr, wa-buzei, wa-wrbtr.... etc.

endloop.

8 REPLIES 8
Read only

gouravkumar64
Active Contributor
0 Likes
1,052

hi,

telling some difference between at new & on change of.which approach u will use depends on u.

When we use At new for a field, it will trigger whenever there is any change in al lthe fields from the left to that of the particular field. But when we use On change of it triggers only when there is any change in the particular field.

At new can only be used inside loop. On change of can used outside the loop.

No logical Expressions can be added with at new. Logical expressions like AND OR can be used with on change of.

When AT NEW occurs, the alpha-numeric fields have * in their value,where as in case of On Change, the alphanumeric fields have their Corresponding value, of that particular record, where the Event gets fired.

On Change of executes for the first value of field too, this is not the case with At New.

On change of cannot be used in ABAP objects At new can be used in this.

1.at new is always followed by single field.
    eg: AT NEW MATNR.
     if any changes in matnr occurs at new event triggers.
at this case right side fields of matnr appears like
this.right side character fields appears like **** &
numeric field become null in work area.

2.on change of follows by single or more fields.
  eg: ON CHANGE OF MATNR OR LABST OR WERKS.
        here any change in any field on change of event
triggers.here we can see all fields in work area.

Gourav.

Read only

gouravkumar64
Active Contributor
0 Likes
1,052

Hi,

But on change of is obsolete now.

The pseudo control structure ON CHANGE OF - ENDON is not allowed in ABAP Objects.

Error message in ABAP Objects if the following syntax is used:

ON CHANGE OF f.

...

ENDON.

Correct syntax:

DATA g LIKE f.

IF f <> g.

...

g = f.

ENDIF.

Reason:

A global invisible work field over which the program has no control is created internally. A separate work field should be declared and processed using the IF control structure.

Read only

Former Member
0 Likes
1,052

Hi

I think so you should avoid OnCHANGE command here for your scenario it does not required actually it is used when ever you change at field level or any values it is used at runtime also

Read only

0 Likes
1,052

Hi,

first reorganize line structure as

belnr  split_batch buzei 
wrbtr 
blart

Then

  sort itab.

  delete itab where split_batch is initial or blart <> 'IC'.

loop at itab into wa_itab.

  at end of split_batch."Make extended use of F1 on AT !!!

    sum.

    write: 'document', wa_itab-belnr, 'Amount', wa_itab-wrbtr.

  endat.

endloop.

Regards,

Clemens

Read only

0 Likes
1,052

Hi,

Thanks for the reply.

In the code above can you write a perform like:-

loop at itab into wa_itab.

  at end of split_batch."Make extended use of F1 on AT !!!

    sum.

    Perform mapping using wa_itab.

  endat.

endloop.

And can anyone explain the problem with the codes that I wrote with on change of. Because if I write my codes that way it helps me in not brraking the loop. It can handle both the scenario of doc types = 'IC' with batch_split and other doc types without batch_split.

But in the codes that you suggested, I will have to separate my tables into two, one with IC and batch split and one without.

And in this case also after sum I need to perform a very long mapping for both....... so can I use perform as asked above?

Thanks,

MS.

Read only

0 Likes
1,052

Hi,

How about writing it this way:- Is it okay to write an if between at end and endat?

loop at itab into wa_itab.

if batch_split is initial.

perform mapping using wa_ita.

endif.


  at end of split_batch.

    sum.

   if if batch_split is not initial.

    Perform mapping using wa_itab.

    endif.

  endat.

endloop.

Read only

0 Likes
1,052

Hi Manoj,

you can do what ever suits your need.

Between AT END OF and ENDAT you can use all abap you want.

AT END OF is a control break event that operates with the control break structure of the table. This structure is defined by all character fields starting with the leftmost- That's why I suggested a re-ordering of fields to BELNR SPLIT_BATCH ....

This means AT END OF split_batch is processed each time the field split_batch or any field left of it (here belnr) chages it's values.

The statement SUM calculates the sums of the components with numerical data type of all rows in the current group level and assigns the sums to the components of the work area.

I don't understand what you mean by 'mapping'. Your original post said "not to sum up if split_batch fields are initial and not of a particular document type". That's why I just deleted those records.

For transparency reasons, it is a reasonable idea to use more that one internal table. If you do not process several million records, you will not have any performance or memory problem.

If you modify any values of the internal table, please note that the fields of the control break structure must not be changed, other fields need the MODIFY statement.

Just try!

Regards

Clemens

Read only

0 Likes
1,052

Thanks Clemens.

This was very helpful. I said "not to sum up if split_batch fields are initial and not of a particular document type". Which meant I need not sum those values but I do need to display those.

But anyways looks like my problems are solved. My internal table has three blocks....

Loop at itab.

Block 1 some field modificaations.

Block2 where I was planning to use Control break.

Block 3  All summed valued being mapped and appended to a new table.

Modify itab transporting block1 values.

endloop.

But it was  a good thing that you pointed out, control break cant be used in a loop that has a modify operations. So finally I have a lot of reasons to take new loops. And thanks for the rest of my questions.

This post is answered.

Thanks,

Manoj.