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

subtotal logic is wrong...please help...

Former Member
0 Likes
618

Hi,

I am trying to generate subtotal of dmbtr based on txjcd. I can feel that my logic here is wrong but not able to trace the issue. Can anyone please help...

I want output like this

txjcd material qty local curr amt(dmbtr)

CA0000 1 15.50

CA0000 2 45.00

subtotal 55.50

CR0000 1 15.50

CR0000 2 30.00

subtotal 45.50

Total 101.00

My code is

loop at migo_data.

move-corresponding migo_data to migo_data_alv.

append migo_data_alv.

at end of txjcd.

sum.

migo_data_alv-dmbtr = migo_data-dmbtr.

append migo_data_alv.

endat.

at last.

sum.

migo_data_alv-dmbtr = migo_data-dmbtr.

append migo_data_alv.

endat.

endloop.

thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
597

Hi,

The SUM Statement will never work between AT (FIRST/NEW/END/LAST) and ENDAT statements. If you want to get the sum then use a counter and increment it .

This is only way you can achieve this.

The SUM command will have effect only in between the LOOP and ENDLOOP statements.

Regards,

Vara

6 REPLIES 6
Read only

Former Member
0 Likes
597

If you are using ALV,it has the variable which you can set it for totals & sub-totals.

DATA: GS_SORT TYPE SLIS_SORTINFO_ALV.

DATA: GS_SORT TYPE SLIS_SORTINFO_ALV.

CLEAR GS_SORT.

GS_SORT-FIELDNAME = 'EBELN'.

GS_SORT-SUBTOT = 'X'.

APPEND GS_SORT TO GT_SORT.

Read only

0 Likes
597

instead of EBELN use TXJCD.

Read only

Former Member
0 Likes
598

Hi,

The SUM Statement will never work between AT (FIRST/NEW/END/LAST) and ENDAT statements. If you want to get the sum then use a counter and increment it .

This is only way you can achieve this.

The SUM command will have effect only in between the LOOP and ENDLOOP statements.

Regards,

Vara

Read only

Former Member
0 Likes
597

Thanks to all for the information.

I was able to use the slis_sortinfo_alv type and solve my problem.

regards

Read only

0 Likes
597

pl award points to those who helped you & close this thread..

have fun,

Suresh Datti

Read only

Former Member
0 Likes
597

Hi,

U can do like this also

  SORT migo_data BY txjcd dmbtr.
  LOOP AT migo_data.
<b>    AT END OF txjcd.
      SUM.</b>
*      migo_data_alv-txjcd = migo_data-txjcd.
      migo_data_alv-dmbtr = migo_data-dmbtr.
      APPEND migo_data_alv.
      CLEAR migo_data_alv.
    ENDAT.
  ENDLOOP.

The above logic will work. I have tried that in a report.

Next way is


DATA: i_sort_fcat    TYPE lvc_t_sort,
  struct_gridsort TYPE lvc_t_sort WITH HEADER LINE.

 FORM sort_outtable CHANGING p_i_sort_fcat.
  struct_gridsort-fieldname = 'TXJCD'.
  struct_gridsort-up       = 'X'.
  APPEND struct_gridsort TO i_sort_fcat.
  CLEAR struct_gridsort.

  struct_gridsort-fieldname = 'DMBTR'.
  struct_gridsort-up       = 'X'.
  struct_gridsort-subtot    = 'X'.
  APPEND struct_gridsort TO i_sort_fcat.
  CLEAR struct_gridsort.

ENDFORM.                    " sort_outtable

Hope this helps u.

Kindly reward points and close the thread if ur problem got solved.