Application Development 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: 

Subtotals doubling in ALV OOPs method

Former Member
0 Kudos

Hi,

When i do a subtotal by vendor on my ALV output,

all totals for a particular vendor should be added up and shown , say for example 90 for matnr1 and 90 for matnr2

but my ALV is displaying 360 instead of 180 for a vendor

say vendor1.

I have passed ls_fcat-do_sum = 'X' for total value in field catalog.

Can anyone let me know what im missing?

Thanks,

Anita

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Anitha,

You will have to pass the SORT table also, to the SET_TABLE method. In that you can specify the SUB TOTAL flag.

IT_SORT TYPE LVC_T_SORT will be the table.

Regards,

Ravi

Note : Please mark the helpful answers

6 REPLIES 6

Former Member
0 Kudos

Anitha,

You will have to pass the SORT table also, to the SET_TABLE method. In that you can specify the SUB TOTAL flag.

IT_SORT TYPE LVC_T_SORT will be the table.

Regards,

Ravi

Note : Please mark the helpful answers

0 Kudos

Hi ,

Im passing gt_sort also .

DATA: ls_sort TYPE lvc_s_sort occurs 0 with header line.

  • ls_sort-spos = '1' .

ls_sort-fieldname = 'MATNR'.

ls_sort-up = 'X'.

ls_sort-subtot = 'X'.

ls_sort-expa ='X'.

ls_sort-group = 'UL'.

append ls_sort TO gt_sort.

I also want to add Vendor to this sort.

Can i add vendor also as a second sorting option after matnr? How do i do that?

Regards,

Anitha

0 Kudos

Anitha

Just add one more record exactly like the MATNR one.

However, you cannot use with header line in this code as we are dealing with OOPS.

DATA : gt_sort type lvc_t_sort.

DATA: ls_sort TYPE lvc_s_sort

Regards,

Ravi

Note : Please mark all the helpful answers

0 Kudos

Hi Ravi,

I added vendor also in my code but still im getting double totals displayed for vendor.

if g_grid1 is initial.

perform f_create_objects.

perform f_build_field_catalog changing gt_fieldcat.

perform f_prepare_layout changing gs_layout.

perform f_sort_sub_total changing gt_sort.

CALL METHOD G_GRID1->GET_SORT_CRITERIA

IMPORTING

ET_SORT = gt_sort[] .

*ALV Display - Specify Sorting,Filtering Criteria

if gt_output[] is initial.

message i015.

endif.

CALL METHOD G_GRID1->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE =

  • I_CONSISTENCY_CHECK =

  • I_STRUCTURE_NAME =

  • IS_VARIANT =

  • I_SAVE =

  • I_DEFAULT = 'X'

IS_LAYOUT = gs_layout

  • IS_PRINT =

  • IT_SPECIAL_GROUPS =

  • IT_TOOLBAR_EXCLUDING =

  • IT_HYPERLINK =

  • IT_ALV_GRAPHICS =

  • IT_EXCEPT_QINFO =

CHANGING

IT_OUTTAB = gt_output[]

IT_FIELDCATALOG = gt_fieldcat

IT_SORT = gt_sort[]

  • IT_FILTER =

EXCEPTIONS

INVALID_PARAMETER_COMBINATION = 1

PROGRAM_ERROR = 2

TOO_MANY_LINES = 3

others = 4 .

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

else.

CALL METHOD G_GRID1->REFRESH_TABLE_DISPLAY

  • EXPORTING

  • IS_STABLE =

  • I_SOFT_REFRESH =

EXCEPTIONS

FINISHED = 1

others = 2 .

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

endif.

FORM f_sort_sub_total CHANGING P_GT_SORT.

DATA : gt_sort type lvc_t_sort.

DATA: ls_sort TYPE lvc_s_sort.

ls_sort-spos = '1' .

ls_sort-fieldname = 'MATNR'.

ls_sort-up = 'X'.

ls_sort-subtot = 'X'.

ls_sort-expa ='X'.

ls_sort-group = 'UL'.

append ls_sort TO gt_sort.

ls_sort-spos = '2'.

ls_sort-fieldname = 'LIFNR'.

ls_sort-up = 'X'.

ls_sort-subtot = 'X'.

ls_sort-expa ='X'.

ls_sort-group = 'UL'.

append ls_sort TO gt_sort.

ENDFORM. " f_sort_sub_total

The values passed to field catalog is below

*Total Value

ls_fcat-fieldname = 'TOTVAL'.

ls_fcat-TABNAME = 'GT_OUTPUT'.

if g_curr eq 10.

ls_fcat-cfieldname = 'LC_CURRENCY'.

ls_fcat-currency = 'USD'.

else.

ls_fcat-cfieldname = 'GC_CURRENCY'.

ls_fcat-currency = 'CAD'.

endif.

ls_fcat-coltext = 'Total Value'.

ls_fcat-seltext = 'Total Value'.

ls_fcat-col_pos = '13'.

ls_fcat-do_sum = 'X'.

append ls_fcat to pt_fieldcat.

clear ls_fcat.

Total Value field is a Currency field, length 15 decimals 2 of type CURR.

Im getting only TOTAL VALUE field's SUBTOTAL wrongly, but my TOTAL STOCK field is added correctly.

I really dont know where im missing?

Regards,

Anitha

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Can you post your code?

Regards,

Rich Heilman

Former Member
0 Kudos

Hi,

You have to add vendor in the sort table, and pass 'X' to subtotal for vendor field too in order to get the proper result.