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: 

ALV SUBTOTALS

Former Member
0 Kudos

Hi all,

how to find subtotals in ALV.

VKR.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

HI,

Here is the complete program for your reference.

REPORT ZYFI_REPT007

NO STANDARD PAGE HEADING

LINE-SIZE 300

LINE-COUNT 50

MESSAGE-ID ZYFI.

************************************************************************

  • Prog name : ZYFI_REPT007

  • Description : Commitment Line Items for Orders Report

  • Incident No : 31314 *

  • AUTHOR : Mahesh Raganmoni

  • Created On : 06/13/2005

----


  • MODIFICATION LOG (latest change first): *

----


  • Date Author Incident No Request No *

  • Description *

----


************************************************************************

************************************************************************

TABLES : COOI, " Commitments Management: Line Items

LFA1, " Vendor master (general section)

VBEP,

RKPLN.

************************************************************************

  • TABLE TYPES AND INTERNAL TABLES *

************************************************************************

DATA : BEGIN OF TYP_COOI ,

OBJNR LIKE COOI-OBJNR,

SAKTO LIKE COOI-SAKTO,

MEGBTR LIKE COOI-MEGBTR,

MEINH LIKE COOI-MEINH,

WKGBTR LIKE COOI-WKGBTR,

REFBN LIKE COOI-REFBN,

RFPOS LIKE COOI-RFPOS,

SGTXT LIKE COOI-SGTXT,

BUDAT LIKE COOI-BUDAT,

LIFNR LIKE COOI-LIFNR,

END OF TYP_COOI.

DATA : BEGIN OF TYP_LFA1 ,

LIFNR LIKE LFA1-LIFNR,

NAME1 LIKE LFA1-NAME1,

END OF TYP_LFA1.

DATA : BEGIN OF IT_OUTTAB OCCURS 0,

OBJNR LIKE COOI-OBJNR,

SAKTO LIKE COOI-SAKTO,

MEGBTR LIKE COOI-MEGBTR,

MEINH LIKE COOI-MEINH,

WKGBTR LIKE COOI-WKGBTR,

REFBN LIKE COOI-REFBN,

RFPOS LIKE COOI-RFPOS,

SGTXT LIKE COOI-SGTXT,

BUDAT LIKE COOI-BUDAT,

LIFNR LIKE COOI-LIFNR,

NAME1 LIKE LFA1-NAME1,

END OF IT_OUTTAB.

DATA : IT_COOI LIKE TYP_COOI OCCURS 0 WITH HEADER LINE,

IT_LFA1 LIKE TYP_LFA1 OCCURS 0 WITH HEADER LINE.

*-- ALV Declarations

TYPE-POOLS SLIS.

DATA: IT_EVENTS TYPE SLIS_T_EVENT,

GS_EVENT TYPE SLIS_ALV_EVENT,

wa_fldcat type slis_fieldcat_alv.

DATA: S_LAYOUT TYPE SLIS_LAYOUT_ALV,

GT_PRINT TYPE SLIS_PRINT_ALV.

DATA: IT_FLDCAT TYPE SLIS_T_FIELDCAT_ALV.

DATA: IT_SORT TYPE SLIS_T_SORTINFO_ALV.

DATA: V_REPID LIKE SY-REPID.

************************************************************************

  • SELECTION SCREEN *

************************************************************************

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

SELECT-OPTIONS : S_KOKRS FOR COOI-KOKRS NO-EXTENSION NO INTERVALS,

" Controlling Area

S_BUKRS FOR COOI-BUKRS NO-EXTENSION NO INTERVALS,

" Company code

S_GJAHR FOR COOI-GJAHR NO-EXTENSION NO INTERVALS,

" Fiscal Year

S_OBJNR FOR RKPLN-AUFNR MATCHCODE OBJECT ORDE,

" Internal order

S_SAKTO FOR COOI-SAKTO MATCHCODE OBJECT KART,

" Cost Element

S_BUDAT FOR COOI-BUDAT, " Debit Date

S_LIFNR FOR COOI-LIFNR. " Vendor

SELECTION-SCREEN END OF BLOCK B1.

************************************************************************

  • S T A R T O F S E L E C T I O N *

************************************************************************

START-OF-SELECTION.

*-- Read data

PERFORM GET_DATA.

************************************************************************

  • E N D O F S E L E C T I O N *

************************************************************************

END-OF-SELECTION.

*-- Process the data and prepare the output data

PERFORM CALCULATE_FINAL_INFO.

*--Display Report output

PERFORM DISPLAY_REPORT.

----


  • FORM CALCULATE_FINAL_INFO *

----


  • Process the data and prepare final internal table *

----


FORM CALCULATE_FINAL_INFO.

DATA : L_OBJNR LIKE COOI-OBJNR.

SORT IT_LFA1 BY LIFNR.

DELETE ADJACENT DUPLICATES FROM IT_LFA1 COMPARING LIFNR.

LOOP AT IT_COOI.

L_OBJNR = IT_COOI-OBJNR+2(20).

SHIFT L_OBJNR LEFT DELETING LEADING '0'.

IF L_OBJNR IN S_OBJNR.

READ TABLE IT_LFA1 WITH KEY LIFNR = IT_COOI-LIFNR.

IF SY-SUBRC EQ 0.

IT_OUTTAB-NAME1 = IT_LFA1-NAME1.

ENDIF.

MOVE-CORRESPONDING IT_COOI TO IT_OUTTAB.

CLEAR IT_OUTTAB-OBJNR.

IT_OUTTAB-OBJNR = L_OBJNR.

APPEND IT_OUTTAB.

CLEAR IT_OUTTAB.

CLEAR IT_LFA1.

CLEAR L_OBJNR.

ENDIF.

ENDLOOP.

ENDFORM.

&----


*& Form GET_DATA

&----


  • Fetch the Data from the table COOI and LFA1

----


FORM GET_DATA.

SELECT OBJNR

SAKTO

MEGBTR

MEINH

WKGBTR

REFBN

RFPOS

SGTXT

BUDAT

LIFNR

FROM COOI

INTO TABLE IT_COOI

WHERE BUDAT IN S_BUDAT

AND LIFNR IN S_LIFNR

AND KOKRS IN S_KOKRS

AND BUKRS IN S_BUKRS

AND GJAHR IN S_GJAHR

AND SAKTO IN S_SAKTO.

IF SY-SUBRC EQ 0 .

  • Get the Vendor name from LFA1

SELECT LIFNR

NAME1

FROM LFA1

INTO TABLE IT_LFA1

FOR ALL ENTRIES IN IT_COOI

WHERE LIFNR EQ IT_COOI-LIFNR.

ELSE.

MESSAGE I999 WITH TEXT-013.

ENDIF.

ENDFORM. " GET_DATA

&----


*& Form DISPLAY_REPORT

&----


  • Display the output

----


FORM DISPLAY_REPORT.

PERFORM BUILD_CATALOG.

PERFORM FRM_PREPARE_EVENT_LIST TABLES IT_EVENTS.

IF NOT IT_OUTTAB[] IS INITIAL.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = V_REPID

I_CALLBACK_USER_COMMAND = 'USER_COMMAND'

IT_FIELDCAT = IT_FLDCAT

IT_SORT = IT_SORT

IT_EVENTS = IT_EVENTS

TABLES

T_OUTTAB = IT_OUTTAB

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2.

ELSE.

MESSAGE I999 WITH TEXT-013.

ENDIF.

ENDFORM. " DISPLAY_REPORT

&----


*& Form BUILD_CATALOG

&----


  • Build the Field catalog for the ALV Report

----


FORM BUILD_CATALOG.

DATA: V_INDEX LIKE SY-TABIX.

V_REPID = SY-REPID.

DATA: LS_SORT TYPE SLIS_SORTINFO_ALV.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = V_REPID

I_INTERNAL_TABNAME = 'IT_OUTTAB'

I_INCLNAME = V_REPID

CHANGING

CT_FIELDCAT = IT_FLDCAT

EXCEPTIONS

INCONSISTENT_INTERFACE = 1

PROGRAM_ERROR = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

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

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

ENDIF.

READ TABLE IT_FLDCAT WITH KEY FIELDNAME = 'WKGBTR'

TABNAME = 'IT_OUTTAB' INTO WA_FLDCAT.

IF SY-SUBRC EQ 0.

WA_FLDCAT-DO_SUM = 'X'.

MODIFY IT_FLDCAT FROM WA_FLDCAT INDEX SY-TABIX.

ENDIF.

READ TABLE IT_FLDCAT WITH KEY FIELDNAME = 'OBJNR'

TABNAME = 'IT_OUTTAB' INTO WA_FLDCAT.

IF SY-SUBRC EQ 0.

WA_FLDCAT-SELTEXT_L = 'Order'.

WA_FLDCAT-COL_POS = 1.

WA_FLDCAT-DDICTXT = 'L'.

MODIFY IT_FLDCAT FROM WA_FLDCAT INDEX SY-TABIX.

ENDIF.

LS_SORT-FIELDNAME = 'OBJNR'.

LS_SORT-SPOS = 1.

LS_SORT-UP = 'X'.

LS_SORT-SUBTOT = 'X'.

APPEND LS_SORT TO IT_SORT.

ENDFORM. " BUILD_CATALOG

&----


*& Form FRM_PREPARE_EVENT_LIST

&----


  • Build the Events

----


FORM FRM_PREPARE_EVENT_LIST TABLES IT_EVENTS TYPE SLIS_T_EVENT.

CLEAR GS_EVENT.

GS_EVENT-NAME = SLIS_EV_TOP_OF_PAGE.

GS_EVENT-FORM = 'TOP_OF_PAGE_REPORT'.

APPEND GS_EVENT TO IT_EVENTS.

ENDFORM. " FRM_PREPARE_EVENT_LIST

************************************************************************

  • TOP OF PAGE

************************************************************************

FORM TOP_OF_PAGE_REPORT.

CALL FUNCTION 'Z_YREPORT_HEADER'

EXPORTING

DL_TITLE = SY-TITLE

DL_REPID = SY-CPROG

DL_LINSZ = SY-LINSZ

EXCEPTIONS

OTHERS = 1.

ENDFORM. " FRM_TOP_OF_PAGE_REPORT

&----


*& Form USER_COMMAND

&----


  • Drill Down Functionality to Call the Transaction ME23

----


FORM USER_COMMAND USING P_UCOMM LIKE SY-UCOMM

P_SELFIELD TYPE SLIS_SELFIELD.

DATA : L_INDEX LIKE SY-INDEX,

L_REFBN LIKE COOI-REFBN.

L_INDEX = P_SELFIELD-TABINDEX. " holds the selected table index

CLEAR L_REFBN.

CASE P_UCOMM.

*-- On Double Click

WHEN '&IC1'.

CLEAR L_REFBN.

*-- Read the Current Line

READ TABLE IT_OUTTAB INDEX L_INDEX.

IF SY-SUBRC EQ 0.

L_REFBN = IT_OUTTAB-REFBN.

IF NOT L_REFBN IS INITIAL.

*-- Set the BES Paramater Id to the Current line Purchase Order Number

SET PARAMETER ID 'BES' FIELD L_REFBN.

*-- Call the Transaction Purchase Order Display with the above PO Number

CALL TRANSACTION 'ME23' AND SKIP FIRST SCREEN.

ENDIF.

ELSE.

MESSAGE E999 WITH TEXT-014.

ENDIF.

ENDCASE.

ENDFORM. " USER_COMMAND

thanks,

Mahesh

5 REPLIES 5

Former Member
0 Kudos

Hi VKR,

you need to build the IT_SORT table and pass that to ALV FM

Data: I_SORT TYPE SLIS_T_SORTINFO_ALV,

WA_SORT TYPE SLIS_SORTINFO_ALV.

*---Sort

WA_SORT-SPOS = '1'.

WA_SORT-FIELDNAME = 'LINE'.

WA_SORT-UP = 'X'.

WA_SORT-SUBTOT = 'X'.

APPEND WA_SORT TO I_SORT.

CLEAR WA_SORT.

Pass this in FM,

IT_SORT = I_SORT

Former Member
0 Kudos

ADD st_layout-numc_sum = 'X'.

Regards

varma_narayana
Active Contributor
0 Kudos

Hi

Check this code:

**********SUBTOTAL IN ALV

REPORT zf14 NO STANDARD PAGE HEADING LINE-SIZE 138. .

TABLES: bkpf,bseg,lfa1,t001,rbkp.

TYPE-POOLS:slis.

TYPES : BEGIN OF x_bkpf,

bukrs TYPE bkpf-bukrs, " Company Code

belnr TYPE bkpf-belnr, " Document Number

gjahr TYPE bkpf-gjahr, " Fiscal year

awkey TYPE bkpf-awkey, " Object Key

bldat TYPE bkpf-bldat,

budat TYPE bkpf-budat,

END OF x_bkpf.

TYPES : BEGIN OF x_final,

lifnr TYPE lfa1-lifnr,

sl_no TYPE sy-tabix,

bukrs TYPE bkpf-bukrs, " Company Code

belnr TYPE bkpf-belnr, " Document Number

gjahr TYPE bkpf-gjahr, " Fiscal year

blart TYPE bkpf-blart, " Document Type

awkey TYPE bkpf-awkey, " Object Key

awkey1 TYPE bkpf-awkey,

bldat TYPE rbkp-bldat,

budat TYPE bkpf-budat,

witht TYPE with_item-witht,

wt_qsshh TYPE with_item-wt_qsshh,

wt_qbshh TYPE with_item-wt_qbshh,

wt_acco TYPE with_item-wt_acco,

name1 TYPE lfa1-name1, "vendor Name

ort01 TYPE lfa1-ort01, "City

j_1icstno TYPE j_1imovend-j_1icstno, "CST

j_1ilstno TYPE j_1imovend-j_1ilstno ,"LST

*Start of changes by Kiran.K dated 17072007.

j_1ipanno TYPE j_1imovend-j_1ipanno, "PAN No.

*End of changes by Kiran.K dated 17072007.

END OF x_final.

DATA : itbkpf TYPE x_bkpf OCCURS 0 WITH HEADER LINE.

DATA : itfinal TYPE x_final OCCURS 0 WITH HEADER LINE.

DATA : month_names LIKE t247 OCCURS 0 WITH HEADER LINE.

DATA :i(2), "month

y TYPE int4, "year

c(4),

v_bill LIKE bseg-dmbtr. " bill value

DATA : pos TYPE sy-tabix,

month(99),

month1(99).

DATA:sl_no(3) VALUE 0.

DATA:string1(100),

date1(10),

date2(10),

title(65).

*Declarations for ALV

DATA:itfieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.

DATA:itrepid TYPE sy-repid.

itrepid = sy-repid.

DATA:itevent TYPE slis_t_event.

DATA:itlistheader TYPE slis_t_listheader.

DATA:walistheader LIKE LINE OF itlistheader.

DATA:itlayout TYPE slis_layout_alv.

DATA:top TYPE slis_formname.

DATA:itsort TYPE slis_t_sortinfo_alv WITH HEADER LINE.

DATA:itprintparams TYPE slis_print_alv.

DATA:itvariant TYPE disvariant.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

PARAMETERS : p_bukrs LIKE t001-bukrs OBLIGATORY. "Company code

SELECT-OPTIONS : s_lifnr FOR lfa1-lifnr, "Vendor name

s_budat FOR sy-datum OBLIGATORY,

s_gjahr FOR bseg-gjahr NO-DISPLAY.

SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.

PARAMETERS: r1 RADIOBUTTON GROUP g1,

r2 RADIOBUTTON GROUP g1.

SELECTION-SCREEN END OF BLOCK b2.

WRITE:S_BUDAT-LOW TO DATE1,

S_BUDAT-HIGH TO DATE2.

AT SELECTION-SCREEN.

SELECT SINGLE bukrs

INTO t001-bukrs

FROM t001

WHERE bukrs = p_bukrs.

IF sy-subrc <> 0.

MESSAGE e000(z_ma) WITH 'Invalid Company Code'.

ENDIF.

IF NOT s_lifnr[] IS INITIAL.

SELECT SINGLE lifnr

INTO lfa1-lifnr

FROM lfa1

WHERE lifnr IN s_lifnr.

IF sy-subrc <> 0.

MESSAGE e000(z_ma) WITH 'Invalid Vendor'.

ENDIF.

ENDIF.

START-OF-SELECTION.

IF s_budat IS NOT INITIAL.

IF s_budat-high IS NOT INITIAL.

WHILE s_budat-low LE s_budat-high.

i = s_budat+7(2).

IF i > 3.

s_gjahr = s_budat+3(4).

APPEND s_gjahr.

ELSE.

c = s_budat+3(4).

s_gjahr = c - 1.

APPEND s_gjahr.

ENDIF.

s_budat-low = s_budat-low + 1.

ENDWHILE.

ELSE.

i = s_budat+7(2).

IF i > 3.

s_gjahr = s_budat+3(4).

APPEND s_gjahr.

ELSE.

c = s_budat+3(4).

s_gjahr = c - 1.

APPEND s_gjahr.

ENDIF.

ENDIF.

ENDIF.

IF r1 = 'X'.

PERFORM getdata.

PERFORM alv.

ELSE.

PERFORM getdata.

PERFORM classical.

ENDIF.

&----


*& Form getdata

&----


  • text

----


FORM getdata.

SELECT bukrs

belnr

awkey

budat

gjahr

blart

FROM bkpf INTO CORRESPONDING FIELDS OF TABLE itbkpf

WHERE bukrs = p_bukrs

AND budat IN s_budat

AND bstat = space

AND gjahr = s_gjahr.

IF sy-subrc NE 0.

MESSAGE 'No Values exist for the Selection.' TYPE 'S'.

ENDIF.

*Tax details.

LOOP AT itbkpf.

MOVE-CORRESPONDING itbkpf TO itfinal.

SELECT SINGLE belnr

gjahr

witht

wt_qsshh

wt_qbshh

wt_acco "vendor

FROM with_item INTO CORRESPONDING FIELDS OF itfinal

WHERE bukrs = p_bukrs

AND gjahr = itbkpf-gjahr

AND belnr = itbkpf-belnr

AND witht = 'T1'.

APPEND itfinal.

CLEAR itfinal.

CLEAR itbkpf.

ENDLOOP.

LOOP AT itbkpf.

MOVE-CORRESPONDING itbkpf TO itfinal.

SELECT SINGLE belnr

gjahr

witht

wt_qsshh

wt_qbshh

wt_acco "vendor

FROM with_item INTO CORRESPONDING FIELDS OF itfinal

WHERE bukrs = p_bukrs

AND gjahr = itbkpf-gjahr

AND belnr = itbkpf-belnr

AND witht = 'T2'.

APPEND itfinal.

CLEAR itfinal.

CLEAR itbkpf.

ENDLOOP.

LOOP AT itfinal.

IF NOT ( itfinal-witht = 'T1' OR itfinal-witht = 'T2' ) OR ( itfinal-wt_qsshh = '0.00' ).

DELETE itfinal.

ENDIF.

ENDLOOP.

LOOP AT itfinal.

itfinal-awkey1 = itfinal-awkey+0(10).

SELECT SINGLE lifnr

name1

ort01

FROM lfa1 INTO CORRESPONDING FIELDS OF itfinal

WHERE lifnr = itfinal-wt_acco.

SELECT SINGLE j_1icstno

j_1ilstno

*Start of changes by Kiran.K dated 17072007.

j_1ipanno

*End of changes by Kiran.K dated 17072007.

FROM j_1imovend INTO CORRESPONDING FIELDS OF itfinal

WHERE lifnr = itfinal-wt_acco.

SELECT SINGLE bldat

from rbkp INTO CORRESPONDING FIELDS of itfinal

where belnr = itfinal-awkey1

and gjahr = itfinal-gjahr.

MODIFY itfinal.

ENDLOOP.

ENDFORM. "getdata

&----


*& Form alv

&----


  • Fieldcatalog for ALV Report

----


FORM alv.

DATA:NO_SUBTOTAL(1) TYPE C.

SORT ITFINAL BY LIFNR.

LOOP AT itfinal.

itfinal-awkey1 = itfinal-awkey+0(10).

itfinal-sl_no = sy-tabix.

MODIFY itfinal.

ENDLOOP.

IF itfinal[] IS INITIAL.

MESSAGE 'No Values exist for the Selection.' TYPE 'S'.

STOP.

ENDIF.

DEFINE m_fieldcat.

itfieldcat-fieldname = &1.

itfieldcat-col_pos = &2.

itfieldcat-seltext_l = &3.

itfieldcat-do_sum = &4.

itfieldcat-outputlen = &5.

append itfieldcat to itfieldcat.

clear itfieldcat.

END-OF-DEFINITION.

m_fieldcat 'SL_NO' '' 'SL. NO' '' 03 .

m_fieldcat 'BUKRS' '' 'COMPANY CODE' '' 12 .

  • Start of Changes made by Kiran.K dated 17072007.

m_fieldcat 'BELNR' '' 'FI Doc.No.' '' 12 .

  • End of changes made by Kiran.K dated 17072007

m_fieldcat 'GJAHR' '' 'FISCAL YEAR' '' 11.

m_fieldcat 'WT_QSSHH' '' 'TAX BASE AMT.' 'X' 13 .

m_fieldcat 'WT_QBSHH' '' 'TAX' 'X' 13 .

m_fieldcat 'AWKEY1' '' 'INVOICE No.' '' 13 .

m_fieldcat 'BLDAT' '' 'DOCUMENT DATE' '' 08 .

m_fieldcat 'BUDAT' '' 'POSTING DATE' '' 08 .

m_fieldcat 'LIFNR' '' 'VENDOR CODE' '' 10 .

m_fieldcat 'NAME1' '' 'VENDOR NAME' '' 35 .

m_fieldcat 'ORT01' '' 'CITY' '' 35 .

m_fieldcat 'J_1ICSTNO' '' 'CST No.' '' 40 .

  • Start of changes by Kiran.K dated 17072007.

m_fieldcat 'J_1ILSTNO' '' 'TIN NUMBER.' '' 40.

m_fieldcat 'J_1IPANNO' '' 'PERMANENT A/C No.' '' 40.

  • End of changes by Kiran.K dated 17072007.

itlayout-zebra = 'X'.

itlayout-colwidth_optimize = 'X'.

data : itsort TYPE slis_t_sortinfo_alv with header line.

DATA :itsort1 TYPE slis_sortinfo_alv.

CLEAR itsort.

itsort1-spos = 10."column position

itsort1-fieldname = 'LIFNR'."field name

itsort1-tabname = 'ITFINAL'."internal table

*itsort1-up = 'X'.

*itsort1-group = 'UL'.

*itsort1-subtot = 'X'.

APPEND itsort1 TO itsort.

CLEAR itsort.

itsort1-spos = 5."column position

itsort1-fieldname = 'WT_QSSHH'."field name

itsort1-tabname = 'ITFINAL'."internal table

*itsort1-up = 'X'.

*itsort1-group = 'UL'.

itsort1-subtot = 'X'.

APPEND itsort1 TO itsort.

**

*CLEAR itsort.

*itsort1-spos = 4. "column position

*itsort1-fieldname = 'WT_QBSHH'."field name

*itsort1-tabname = 'ITFINAL'."internal table

**itsort1-up = 'X'.

**itsort1-group = 'UL'.

*itsort1-subtot = 'X'.

*APPEND itsort1 TO itsort. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = sy-repid

is_layout = itlayout

i_callback_user_command = 'LIST1'

i_callback_top_of_page = 'TOP'

it_fieldcat = itfieldcat[]

i_save = 'A'

  • is_variant = ITVARIANT

it_events = itevent[]

  • is_print = ITPRINTPARAMS

it_sort = itsort[]

TABLES

t_outtab = itfinal

EXCEPTIONS

program_error = 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.

ENDFORM. "alv

&----


*& Form list1

&----


  • ALV Interactive-

----


  • -->R_UCOMM text

  • -->RS_SELFIELDtext

----


FORM list1 USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield.

CASE r_ucomm.

WHEN '&IC1'.

IF rs_selfield-fieldname = 'BELNR'.

READ TABLE itfinal INDEX rs_selfield-tabindex.

SET PARAMETER ID 'BLN' FIELD itfinal-belnr.

  • start of changes made by Kiran.K dated 18072007.

SET PARAMETER ID 'BUK' FIELD ITFINAL-BUKRS.

SET PARAMETER ID 'GJR' FIELD ITFINAL-GJAHR.

*End of changes made by Kiran.K dated 18072007.

CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.

ENDIF.

ENDCASE.

ENDFORM. "list1

&----


*& Form TOP

&----


  • Top of page for ALV Report

----


FORM top.

DATA : name1(60),

month_text(250),

string1(100),

date3(10),

date4(10),

title(65).

WRITE: DATE1 TO date3,

DATE2 TO date4.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = itevent

  • EXCEPTIONS

  • LIST_TYPE_WRONG = 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.

string1 = 'TDS on Work Contracts for'.

CONCATENATE string1 itfinal-bukrs date3 'to' date4 INTO title SEPARATED BY space.

walistheader-typ = 'H'.

walistheader-info = title.

APPEND walistheader TO itlistheader.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = itlistheader

  • I_LOGO = ''.

  • I_END_OF_LIST_GRID =

.

  • ENDIF.

CLEAR itlistheader.

  • ENDIF.

ENDFORM. "TOP

&----


*& Form classical

&----


  • Form to display the values in Classical Report

----


FORM classical.

FORMAT RESET.

FORMAT COLOR COL_NORMAL.

sort itfinal by lifnr.

LOOP AT itfinal.

sl_no = sl_no + 1.

itfinal-awkey1 = itfinal-awkey+0(10).

WRITE:/ sy-vline,

2 sl_no,

7 sy-vline,

10 itfinal-bukrs,

21 sy-vline,

23 itfinal-belnr hotspot,

35 sy-vline,

38 itfinal-gjahr,

47 sy-vline,

48 itfinal-wt_qsshh,

69 sy-vline,

70 itfinal-wt_qbshh,

91 sy-vline,

94 itfinal-awkey1,

108 sy-vline,

110 itfinal-budat,

125 sy-vline,

*Start of changes made by Kiran.K dated 18072007.

127 itfinal-bldat,

138 sy-vline.

*End of changes made by Kiran.K dated 18072007.

hide itfinal-belnr.

at end of lifnr.

uline.

new-page.

clear: sl_no.

endat.

ENDLOOP.

write:/ sy-vline.

ENDFORM. "classical

at line-selection.

set parameter id 'BLN' field itfinal-belnr.

call transaction 'FB03' AND SKIP FIRST SCREEN.

*********************

TOP-OF-PAGE.

DATA : name1(60).

DATA : month_text(127),

string(99).

FORMAT RESET.

FORMAT COLOR COL_POSITIVE.

string1 = 'TDS on Work Contracts for'.

CONCATENATE string1 itfinal-bukrs date1 'to' date2 INTO title SEPARATED BY space.

WRITE 😕 title.

SKIP 1.

CONCATENATE itfinal-name1 ',' itfinal-ort01

INTO name1 SEPARATED BY space.

WRITE 😕 'Vendor Code :', itfinal-lifnr.

WRITE 😕 'Vendor Name and City :', name1.

SKIP 1.

*Start of changes by Kiran.K dated 17072007.

*Changed TNGST as TIN and PAN No is added.

WRITE 😕 'TIN No :', itfinal-j_1ilstno,

/ 'CST Registration No :', itfinal-j_1icstno,

/ 'PERMANENT A/C No. :',itfinal-j_1ipanno.

*End of changes by Kiran.K dated 17072007.

SKIP 1.

  • Display the coloumn headings

FORMAT RESET.

FORMAT COLOR COL_HEADING.

WRITE 😕 sy-uline.

WRITE:/ sy-vline,

2 'SI.No',

7 sy-vline,

10 'Comp.Code',

21 sy-vline,

22 'FI.Doc.No',

35 sy-vline,

37 'Fiscal Yr.',

47 sy-vline,

49 'Tax Base Amt.',

69 sy-vline,

71 'Tax Amt.',

91 sy-vline,

94 'Invoice No.' ,

108 sy-vline,

110 'Posting Date',

125 sy-vline,

127 'Doc.Date',

138 sy-vline,

***Solution

Just add SUBTOTAL in the fieldcatalog of the particular field.

I_FIELDCAT-DO_SUM = 'X'.

Or Tey This:

-


Data: I_SORT TYPE SLIS_T_SORTINFO_ALV,

WA_SORT TYPE SLIS_SORTINFO_ALV.

*---Sort

WA_SORT-SPOS = '1'.

WA_SORT-FIELDNAME = 'LINE'.

WA_SORT-UP = 'X'.

WA_SORT-SUBTOT = 'X'.

APPEND WA_SORT TO I_SORT.

CLEAR WA_SORT.

Pass this in FM,

IT_SORT = I_SORT

Or Tey This:

-


Use FM REUSE_ALV_EVENTS_GET to get all events in ur ALV report.then use event SUBTOTAL_TEXT to print subtotal.

following are the events that u can use in ALV :

CALLER_EXIT

USER_COMMAND

TOP_OF_PAGE

TOP_OF_COVERPAGE

END_OF_COVERPAGE

FOREIGN_TOP_OF_PAGE

FOREIGN_END_OF_PAGE

PF_STATUS_SET

LIST_MODIFY

TOP_OF_LIST

END_OF_PAGE

END_OF_LIST

AFTER_LINE_OUTPUT

BEFORE_LINE_OUTPUT

REPREP_SEL_MODIFY

SUBTOTAL_TEXT

GROUPLEVEL_CHANGE

********************

<b>

Reward if helpful</b>

Former Member
0 Kudos

HI,

Here is the complete program for your reference.

REPORT ZYFI_REPT007

NO STANDARD PAGE HEADING

LINE-SIZE 300

LINE-COUNT 50

MESSAGE-ID ZYFI.

************************************************************************

  • Prog name : ZYFI_REPT007

  • Description : Commitment Line Items for Orders Report

  • Incident No : 31314 *

  • AUTHOR : Mahesh Raganmoni

  • Created On : 06/13/2005

----


  • MODIFICATION LOG (latest change first): *

----


  • Date Author Incident No Request No *

  • Description *

----


************************************************************************

************************************************************************

TABLES : COOI, " Commitments Management: Line Items

LFA1, " Vendor master (general section)

VBEP,

RKPLN.

************************************************************************

  • TABLE TYPES AND INTERNAL TABLES *

************************************************************************

DATA : BEGIN OF TYP_COOI ,

OBJNR LIKE COOI-OBJNR,

SAKTO LIKE COOI-SAKTO,

MEGBTR LIKE COOI-MEGBTR,

MEINH LIKE COOI-MEINH,

WKGBTR LIKE COOI-WKGBTR,

REFBN LIKE COOI-REFBN,

RFPOS LIKE COOI-RFPOS,

SGTXT LIKE COOI-SGTXT,

BUDAT LIKE COOI-BUDAT,

LIFNR LIKE COOI-LIFNR,

END OF TYP_COOI.

DATA : BEGIN OF TYP_LFA1 ,

LIFNR LIKE LFA1-LIFNR,

NAME1 LIKE LFA1-NAME1,

END OF TYP_LFA1.

DATA : BEGIN OF IT_OUTTAB OCCURS 0,

OBJNR LIKE COOI-OBJNR,

SAKTO LIKE COOI-SAKTO,

MEGBTR LIKE COOI-MEGBTR,

MEINH LIKE COOI-MEINH,

WKGBTR LIKE COOI-WKGBTR,

REFBN LIKE COOI-REFBN,

RFPOS LIKE COOI-RFPOS,

SGTXT LIKE COOI-SGTXT,

BUDAT LIKE COOI-BUDAT,

LIFNR LIKE COOI-LIFNR,

NAME1 LIKE LFA1-NAME1,

END OF IT_OUTTAB.

DATA : IT_COOI LIKE TYP_COOI OCCURS 0 WITH HEADER LINE,

IT_LFA1 LIKE TYP_LFA1 OCCURS 0 WITH HEADER LINE.

*-- ALV Declarations

TYPE-POOLS SLIS.

DATA: IT_EVENTS TYPE SLIS_T_EVENT,

GS_EVENT TYPE SLIS_ALV_EVENT,

wa_fldcat type slis_fieldcat_alv.

DATA: S_LAYOUT TYPE SLIS_LAYOUT_ALV,

GT_PRINT TYPE SLIS_PRINT_ALV.

DATA: IT_FLDCAT TYPE SLIS_T_FIELDCAT_ALV.

DATA: IT_SORT TYPE SLIS_T_SORTINFO_ALV.

DATA: V_REPID LIKE SY-REPID.

************************************************************************

  • SELECTION SCREEN *

************************************************************************

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

SELECT-OPTIONS : S_KOKRS FOR COOI-KOKRS NO-EXTENSION NO INTERVALS,

" Controlling Area

S_BUKRS FOR COOI-BUKRS NO-EXTENSION NO INTERVALS,

" Company code

S_GJAHR FOR COOI-GJAHR NO-EXTENSION NO INTERVALS,

" Fiscal Year

S_OBJNR FOR RKPLN-AUFNR MATCHCODE OBJECT ORDE,

" Internal order

S_SAKTO FOR COOI-SAKTO MATCHCODE OBJECT KART,

" Cost Element

S_BUDAT FOR COOI-BUDAT, " Debit Date

S_LIFNR FOR COOI-LIFNR. " Vendor

SELECTION-SCREEN END OF BLOCK B1.

************************************************************************

  • S T A R T O F S E L E C T I O N *

************************************************************************

START-OF-SELECTION.

*-- Read data

PERFORM GET_DATA.

************************************************************************

  • E N D O F S E L E C T I O N *

************************************************************************

END-OF-SELECTION.

*-- Process the data and prepare the output data

PERFORM CALCULATE_FINAL_INFO.

*--Display Report output

PERFORM DISPLAY_REPORT.

----


  • FORM CALCULATE_FINAL_INFO *

----


  • Process the data and prepare final internal table *

----


FORM CALCULATE_FINAL_INFO.

DATA : L_OBJNR LIKE COOI-OBJNR.

SORT IT_LFA1 BY LIFNR.

DELETE ADJACENT DUPLICATES FROM IT_LFA1 COMPARING LIFNR.

LOOP AT IT_COOI.

L_OBJNR = IT_COOI-OBJNR+2(20).

SHIFT L_OBJNR LEFT DELETING LEADING '0'.

IF L_OBJNR IN S_OBJNR.

READ TABLE IT_LFA1 WITH KEY LIFNR = IT_COOI-LIFNR.

IF SY-SUBRC EQ 0.

IT_OUTTAB-NAME1 = IT_LFA1-NAME1.

ENDIF.

MOVE-CORRESPONDING IT_COOI TO IT_OUTTAB.

CLEAR IT_OUTTAB-OBJNR.

IT_OUTTAB-OBJNR = L_OBJNR.

APPEND IT_OUTTAB.

CLEAR IT_OUTTAB.

CLEAR IT_LFA1.

CLEAR L_OBJNR.

ENDIF.

ENDLOOP.

ENDFORM.

&----


*& Form GET_DATA

&----


  • Fetch the Data from the table COOI and LFA1

----


FORM GET_DATA.

SELECT OBJNR

SAKTO

MEGBTR

MEINH

WKGBTR

REFBN

RFPOS

SGTXT

BUDAT

LIFNR

FROM COOI

INTO TABLE IT_COOI

WHERE BUDAT IN S_BUDAT

AND LIFNR IN S_LIFNR

AND KOKRS IN S_KOKRS

AND BUKRS IN S_BUKRS

AND GJAHR IN S_GJAHR

AND SAKTO IN S_SAKTO.

IF SY-SUBRC EQ 0 .

  • Get the Vendor name from LFA1

SELECT LIFNR

NAME1

FROM LFA1

INTO TABLE IT_LFA1

FOR ALL ENTRIES IN IT_COOI

WHERE LIFNR EQ IT_COOI-LIFNR.

ELSE.

MESSAGE I999 WITH TEXT-013.

ENDIF.

ENDFORM. " GET_DATA

&----


*& Form DISPLAY_REPORT

&----


  • Display the output

----


FORM DISPLAY_REPORT.

PERFORM BUILD_CATALOG.

PERFORM FRM_PREPARE_EVENT_LIST TABLES IT_EVENTS.

IF NOT IT_OUTTAB[] IS INITIAL.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = V_REPID

I_CALLBACK_USER_COMMAND = 'USER_COMMAND'

IT_FIELDCAT = IT_FLDCAT

IT_SORT = IT_SORT

IT_EVENTS = IT_EVENTS

TABLES

T_OUTTAB = IT_OUTTAB

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2.

ELSE.

MESSAGE I999 WITH TEXT-013.

ENDIF.

ENDFORM. " DISPLAY_REPORT

&----


*& Form BUILD_CATALOG

&----


  • Build the Field catalog for the ALV Report

----


FORM BUILD_CATALOG.

DATA: V_INDEX LIKE SY-TABIX.

V_REPID = SY-REPID.

DATA: LS_SORT TYPE SLIS_SORTINFO_ALV.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = V_REPID

I_INTERNAL_TABNAME = 'IT_OUTTAB'

I_INCLNAME = V_REPID

CHANGING

CT_FIELDCAT = IT_FLDCAT

EXCEPTIONS

INCONSISTENT_INTERFACE = 1

PROGRAM_ERROR = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

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

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

ENDIF.

READ TABLE IT_FLDCAT WITH KEY FIELDNAME = 'WKGBTR'

TABNAME = 'IT_OUTTAB' INTO WA_FLDCAT.

IF SY-SUBRC EQ 0.

WA_FLDCAT-DO_SUM = 'X'.

MODIFY IT_FLDCAT FROM WA_FLDCAT INDEX SY-TABIX.

ENDIF.

READ TABLE IT_FLDCAT WITH KEY FIELDNAME = 'OBJNR'

TABNAME = 'IT_OUTTAB' INTO WA_FLDCAT.

IF SY-SUBRC EQ 0.

WA_FLDCAT-SELTEXT_L = 'Order'.

WA_FLDCAT-COL_POS = 1.

WA_FLDCAT-DDICTXT = 'L'.

MODIFY IT_FLDCAT FROM WA_FLDCAT INDEX SY-TABIX.

ENDIF.

LS_SORT-FIELDNAME = 'OBJNR'.

LS_SORT-SPOS = 1.

LS_SORT-UP = 'X'.

LS_SORT-SUBTOT = 'X'.

APPEND LS_SORT TO IT_SORT.

ENDFORM. " BUILD_CATALOG

&----


*& Form FRM_PREPARE_EVENT_LIST

&----


  • Build the Events

----


FORM FRM_PREPARE_EVENT_LIST TABLES IT_EVENTS TYPE SLIS_T_EVENT.

CLEAR GS_EVENT.

GS_EVENT-NAME = SLIS_EV_TOP_OF_PAGE.

GS_EVENT-FORM = 'TOP_OF_PAGE_REPORT'.

APPEND GS_EVENT TO IT_EVENTS.

ENDFORM. " FRM_PREPARE_EVENT_LIST

************************************************************************

  • TOP OF PAGE

************************************************************************

FORM TOP_OF_PAGE_REPORT.

CALL FUNCTION 'Z_YREPORT_HEADER'

EXPORTING

DL_TITLE = SY-TITLE

DL_REPID = SY-CPROG

DL_LINSZ = SY-LINSZ

EXCEPTIONS

OTHERS = 1.

ENDFORM. " FRM_TOP_OF_PAGE_REPORT

&----


*& Form USER_COMMAND

&----


  • Drill Down Functionality to Call the Transaction ME23

----


FORM USER_COMMAND USING P_UCOMM LIKE SY-UCOMM

P_SELFIELD TYPE SLIS_SELFIELD.

DATA : L_INDEX LIKE SY-INDEX,

L_REFBN LIKE COOI-REFBN.

L_INDEX = P_SELFIELD-TABINDEX. " holds the selected table index

CLEAR L_REFBN.

CASE P_UCOMM.

*-- On Double Click

WHEN '&IC1'.

CLEAR L_REFBN.

*-- Read the Current Line

READ TABLE IT_OUTTAB INDEX L_INDEX.

IF SY-SUBRC EQ 0.

L_REFBN = IT_OUTTAB-REFBN.

IF NOT L_REFBN IS INITIAL.

*-- Set the BES Paramater Id to the Current line Purchase Order Number

SET PARAMETER ID 'BES' FIELD L_REFBN.

*-- Call the Transaction Purchase Order Display with the above PO Number

CALL TRANSACTION 'ME23' AND SKIP FIRST SCREEN.

ENDIF.

ELSE.

MESSAGE E999 WITH TEXT-014.

ENDIF.

ENDCASE.

ENDFORM. " USER_COMMAND

thanks,

Mahesh

Former Member
0 Kudos

hi,

tables : zemployee,zdepartment.

type-pools : slis,icon.

data : d_fieldcat type slis_t_fieldcat_alv,

d_fieldcat_wa type slis_fieldcat_alv.

data : gd_repid like sy-repid.

data : begin of itab_emp occurs 0,

empid like zemployee-empid,

salary like zemployee-salary,

detid like zemployee-detid,

end of itab_emp.

select empid salary from zemployee into table itab_emp

where detid = zdepartment-detid.

gd_repid = sy-repid.

d_fieldcat_wa-fieldname = 'SALARY'.

d_fieldcat_wa-seltext_l = 'salary'.

d_fieldcat_wa-col_pos = 1.

d_fieldcat_wa-do_sum = 'X'.

append d_fieldcat_wa to d_fieldcat.

call function module reuse_alv_grid_display.

expoting.

call_back_program = gd_repid.

t_fieldcat = d_fieldcat.

importing.

t_outtab = itab_emp.

exceptions.

Reward with points if helpful.