2007 Oct 01 11:37 AM
Hi,
I have created one report with ALV_grid_display.
when i execute this report it would show output with less detail.
I have a one checkbox at selection-screen also. My requirement is when i select this checkbox then report should show output with more detail i.e different output.
I have heared we can create variant for this.
Pls tell me how can i do this.
Correct answear will be rewarded by maximum points.
Thanks & Regards,
Gaurav.
2007 Oct 01 2:32 PM
Hi Gaurav,
leave ur id i will send u the screen shot how to create the variant after getting the output list.
This is the sample programe
just go through the bold one in the coding and do modifications in ur programe,
REPORT ZVRI4E04 LINE-SIZE 250 NO STANDARD PAGE HEADING
MESSAGE-ID MSG.
TYPE-POOLS : SLIS.
----
TABLES DECLARATION *
----
TABLES: VBRK, VBRP, VBKD, KONV, KNA1.
----
V A R I A B L E S *
----
DATA : W_FIELD TYPE SLIS_FIELDCAT_ALV.
DATA : F_FIELD TYPE SLIS_T_FIELDCAT_ALV.
DATA : WA_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA : V_POS TYPE I,
LS_SORT TYPE SLIS_T_SORTINFO_ALV,
W_SORT TYPE SLIS_SORTINFO_ALV.
<b>DATA : IS_VARIANT LIKE DISVARIANT.</b>
<b>IS_VARIANT-REPORT = SY-CPROG.</b>
DATA : BEGIN OF T_VBRK OCCURS 0,
VBELN LIKE VBRK-VBELN,
FKDAT LIKE VBRK-FKDAT,
KNUMV LIKE VBRK-KNUMV,
KUNAG LIKE VBRK-KUNAG,
VKORG LIKE VBRK-VKORG,
VTWEG LIKE VBRK-VTWEG,
SPART LIKE VBRK-SPART,
END OF T_VBRK.
DATA : BEGIN OF T_VBRP OCCURS 0,
VBELN LIKE VBRP-VBELN,
POSNR LIKE VBRP-POSNR,
FKIMG LIKE VBRP-FKIMG,
NTGEW LIKE VBRP-NTGEW,
BRGEW LIKE VBRP-BRGEW,
VOLUM LIKE VBRP-VOLUM,
AUBEL LIKE VBRP-AUBEL,
END OF T_VBRP.
DATA : BEGIN OF T_VBKD OCCURS 0,
VBELN LIKE VBKD-VBELN,
BSTKD LIKE VBKD-BSTKD,
END OF T_VBKD.
DATA : BEGIN OF T_KONV OCCURS 0,
KNUMV LIKE KONV-KNUMV,
KPOSN LIKE KONV-KPOSN,
STUNR LIKE KONV-STUNR,
KSCHL LIKE KONV-KSCHL,
KBETR LIKE KONV-KBETR,
KWERT LIKE KONV-KWERT,
END OF T_KONV.
DATA : BEGIN OF T_KNA1 OCCURS 0,
KUNNR LIKE KNA1-KUNNR,
NAME1 LIKE KNA1-NAME1,
END OF T_KNA1.
DATA : BEGIN OF T_FINAL OCCURS 0,
VKORG LIKE VBRK-VKORG,
VTWEG LIKE VBRK-VTWEG,
SPART LIKE VBRK-SPART,
FKDAT LIKE VBRK-FKDAT,
VBELN LIKE VBRK-VBELN,
POSNR LIKE VBRP-POSNR,
NAME1 LIKE KNA1-NAME1,
BSTKD LIKE VBKD-BSTKD,
FKIMG LIKE VBRP-FKIMG,
NTGEW LIKE VBRP-NTGEW,
BRGEW LIKE VBRP-BRGEW,
VOLUM LIKE VBRP-VOLUM,
BASIC LIKE KONV-KWERT,
EXDUTY LIKE KONV-KWERT,
ED LIKE KONV-KWERT,
CST LIKE KONV-KWERT,
VAT LIKE KONV-KWERT,
SALTAX LIKE KONV-KWERT,
FREIGHT LIKE KONV-KWERT,
TCS LIKE KONV-KWERT,
SRG LIKE KONV-KWERT,
RATE LIKE KONV-KBETR,
END OF T_FINAL.
----
S E L E C T I O N - S C R E E N *
----
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-000.
SELECT-OPTIONS: S_KUNAG FOR T_VBRK-KUNAG,
S_FKDAT FOR T_VBRK-FKDAT,
S_VKORG FOR T_VBRK-VKORG,
S_VTWEG FOR T_VBRK-VTWEG,
S_SPART FOR T_VBRK-SPART.
SELECTION-SCREEN END OF BLOCK B1.
AT SELECTION-SCREEN .
SELECT SINGLE KUNAG FKDAT VKORG VTWEG SPART FROM VBRK INTO T_VBRK
WHERE KUNAG IN S_KUNAG
AND FKDAT IN S_FKDAT
AND VKORG IN S_VKORG
AND VTWEG IN S_VTWEG
AND SPART IN S_SPART.
IF SY-SUBRC <> 0.
MESSAGE E000 WITH 'THERE IS NO RECORDS FOR THIS SELECTION CRITERIA'.
ENDIF.
START-OF-SELECTION.
SELECT VBELN FKDAT KNUMV KUNAG VKORG VTWEG SPART
FROM VBRK INTO TABLE T_VBRK
WHERE KUNAG IN S_KUNAG
AND FKDAT IN S_FKDAT
AND VKORG IN S_VKORG
AND VTWEG IN S_VTWEG
AND SPART IN S_SPART.
IF NOT T_VBRK[] IS INITIAL.
SELECT VBELN POSNR FKIMG NTGEW BRGEW VOLUM AUBEL
FROM VBRP INTO TABLE T_VBRP
FOR ALL ENTRIES IN T_VBRK
WHERE VBELN = T_VBRK-VBELN.
ENDIF.
IF NOT T_VBRP[] IS INITIAL .
SELECT VBELN BSTKD FROM VBKD
INTO TABLE T_VBKD
FOR ALL ENTRIES IN T_VBRP
WHERE VBELN = T_VBRP-AUBEL.
ENDIF.
IF NOT T_VBRK[] IS INITIAL.
SELECT KNUMV KPOSN STUNR KSCHL KBETR KWERT
FROM KONV
INTO TABLE T_KONV
FOR ALL ENTRIES IN T_VBRK
WHERE KNUMV = T_VBRK-KNUMV.
ENDIF.
IF NOT T_VBRK[] IS INITIAL.
SELECT KUNNR NAME1 FROM KNA1 INTO TABLE T_KNA1
FOR ALL ENTRIES IN T_VBRK
WHERE KUNNR = T_VBRK-KUNAG.
ENDIF.
----
Populating the final data *
----
LOOP AT T_VBRP.
READ TABLE T_VBRK WITH KEY VBELN = T_VBRP-VBELN.
READ TABLE T_VBKD WITH KEY VBELN = T_VBRP-AUBEL.
READ TABLE T_KNA1 WITH KEY KUNNR = T_VBRK-KUNAG.
T_FINAL-VKORG = T_VBRK-VKORG.
T_FINAL-VTWEG = T_VBRK-VTWEG.
T_FINAL-SPART = T_VBRK-SPART.
T_FINAL-FKDAT = T_VBRK-FKDAT.
T_FINAL-VBELN = T_VBRK-VBELN.
T_FINAL-POSNR = T_VBRP-POSNR.
T_FINAL-NAME1 = T_KNA1-NAME1.
T_FINAL-BSTKD = T_VBKD-BSTKD.
T_FINAL-FKIMG = T_VBRP-FKIMG.
T_FINAL-NTGEW = T_VBRP-NTGEW.
T_FINAL-BRGEW = T_VBRP-BRGEW.
T_FINAL-VOLUM = T_VBRP-VOLUM.
LOOP AT T_KONV WHERE KNUMV = T_VBRK-KNUMV AND
KPOSN = T_VBRP-POSNR.
IF T_KONV-KSCHL = 'ZIBP' OR T_KONV-KSCHL = 'ZIPR'.
T_FINAL-BASIC = T_FINAL-BASIC + T_KONV-KWERT.
IF NOT T_KONV-KBETR IS INITIAL.
T_FINAL-RATE = T_KONV-KBETR.
ENDIF.
ENDIF.
IF T_KONV-KSCHL = 'ZIED'.
T_FINAL-EXDUTY = T_FINAL-EXDUTY + T_KONV-KWERT.
ENDIF.
IF T_KONV-KSCHL = 'ZIEC'.
T_FINAL-ED = T_FINAL-ED + T_KONV-KWERT.
ENDIF.
IF T_KONV-KSCHL = 'ZIVA'.
T_FINAL-SALTAX = T_FINAL-SALTAX + T_KONV-KWERT.
ENDIF.
IF T_KONV-KSCHL = 'ZIFD' OR T_KONV-KSCHL = 'ZID0'.
T_FINAL-FREIGHT = T_FINAL-FREIGHT + T_KONV-KWERT.
ENDIF.
IF T_KONV-KSCHL = 'ZITC'.
T_FINAL-TCS = T_FINAL-TCS + T_KONV-KWERT.
ENDIF.
IF T_KONV-KSCHL = 'ZITS'.
T_FINAL-SRG = T_FINAL-SRG + T_KONV-KWERT.
ENDIF.
IF T_KONV-KSCHL = 'ZICS'.
T_FINAL-CST = T_FINAL-CST + T_KONV-KWERT.
ENDIF.
IF T_KONV-KSCHL = 'ZIVA'.
T_FINAL-VAT = T_FINAL-VAT + T_KONV-KWERT.
ENDIF.
ENDLOOP.
APPEND T_FINAL.
CLEAR T_FINAL.
CLEAR T_KONV.
CLEAR : T_VBRK, T_VBRP, T_VBKD, T_KNA1.
ENDLOOP.
----
POSITION DECLARATION FOR ALV OUTPUT *
----
V_POS = 0.
V_POS = V_POS + 1.
W_FIELD-COL_POS = V_POS.
W_FIELD-FIELDNAME = 'VKORG' .
W_FIELD-TABNAME = 'T_FINAL'.
W_FIELD-SELTEXT_M = 'SORG'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
V_POS = V_POS + 1.
W_FIELD-COL_POS = V_POS.
W_FIELD-FIELDNAME = 'VTWEG' .
W_FIELD-TABNAME = 'T_FINAL'.
W_FIELD-SELTEXT_M = 'DCHL'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
V_POS = V_POS + 1.
W_FIELD-COL_POS = V_POS.
W_FIELD-FIELDNAME = 'SPART' .
W_FIELD-TABNAME = 'T_FINAL'.
W_FIELD-SELTEXT_M = 'DVS'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
V_POS = V_POS + 1.
W_FIELD-COL_POS = V_POS.
W_FIELD-FIELDNAME = 'FKDAT' .
W_FIELD-TABNAME = 'T_FINAL'.
W_FIELD-SELTEXT_M = 'Date'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
V_POS = V_POS + 1.
W_FIELD-COL_POS = V_POS.
W_FIELD-FIELDNAME = 'VBELN' .
W_FIELD-TABNAME = 'T_FINAL'.
W_FIELD-SELTEXT_M = 'Inv No'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
V_POS = V_POS + 1.
W_FIELD-COL_POS = V_POS.
W_FIELD-FIELDNAME = 'POSNR' .
W_FIELD-TABNAME = 'T_FINAL'.
W_FIELD-SELTEXT_M = 'Item No'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
V_POS = V_POS + 1.
W_FIELD-COL_POS = V_POS.
W_FIELD-FIELDNAME = 'NAME1' .
W_FIELD-TABNAME = 'T_FINAL'.
W_FIELD-SELTEXT_M = 'Name'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
V_POS = V_POS + 1.
W_FIELD-COL_POS = V_POS.
W_FIELD-FIELDNAME = 'BSTKD' .
W_FIELD-TABNAME = 'T_FINAL'.
W_FIELD-SELTEXT_M = 'PO No'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
V_POS = V_POS + 1.
W_FIELD-COL_POS = V_POS.
W_FIELD-FIELDNAME = 'FKIMG' .
W_FIELD-TABNAME = 'T_FINAL'.
W_FIELD-DO_SUM = 'X'.
W_FIELD-SELTEXT_M = 'Quantity'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
V_POS = V_POS + 1.
W_FIELD-COL_POS = V_POS.
W_FIELD-FIELDNAME = 'NTGEW' .
W_FIELD-TABNAME = 'T_FINAL'.
W_FIELD-DO_SUM = 'X'.
W_FIELD-SELTEXT_M = 'NT WG'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
V_POS = V_POS + 1.
W_FIELD-COL_POS = V_POS.
W_FIELD-FIELDNAME = 'BRGEW' .
W_FIELD-TABNAME = 'T_FINAL'.
W_FIELD-DO_SUM = 'X'.
W_FIELD-SELTEXT_M = 'GR WG'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
V_POS = V_POS + 1.
W_FIELD-COL_POS = V_POS.
W_FIELD-FIELDNAME = 'VOLUM' .
W_FIELD-TABNAME = 'T_FINAL'.
W_FIELD-DO_SUM = 'X'.
W_FIELD-SELTEXT_M = 'Volume'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
V_POS = V_POS + 1.
W_FIELD-COL_POS = V_POS.
W_FIELD-FIELDNAME = 'RATE'.
W_FIELD-TABNAME = 'T_FINAL'.
W_FIELD-DO_SUM = 'X'.
W_FIELD-SELTEXT_M = 'Rate'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
V_POS = V_POS + 1.
W_FIELD-COL_POS = V_POS.
W_FIELD-FIELDNAME = 'BASIC'.
W_FIELD-TABNAME = 'T_FINAL'.
W_FIELD-DO_SUM = 'X'.
W_FIELD-SELTEXT_M = 'BASIC'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
V_POS = V_POS + 1.
W_FIELD-COL_POS = V_POS.
W_FIELD-FIELDNAME = 'EXDUTY'.
W_FIELD-TABNAME = 'T_FINAL'.
W_FIELD-DO_SUM = 'X'.
W_FIELD-SELTEXT_M = 'EX Duty'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
V_POS = V_POS + 1.
W_FIELD-COL_POS = V_POS.
W_FIELD-FIELDNAME = 'ED' .
W_FIELD-TABNAME = 'T_FINAL'.
W_FIELD-DO_SUM = 'X'.
W_FIELD-SELTEXT_M = 'EDUCATION'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
V_POS = V_POS + 1.
W_FIELD-COL_POS = V_POS.
W_FIELD-FIELDNAME = 'SALTAX'.
W_FIELD-TABNAME = 'T_FINAL'.
W_FIELD-DO_SUM = 'X'.
W_FIELD-SELTEXT_M = 'SALTAX'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
V_POS = V_POS + 1.
W_FIELD-COL_POS = V_POS.
W_FIELD-FIELDNAME = 'CST'.
W_FIELD-TABNAME = 'T_FINAL'.
W_FIELD-DO_SUM = 'X'.
W_FIELD-SELTEXT_M = 'CST'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
V_POS = V_POS + 1.
W_FIELD-COL_POS = V_POS.
W_FIELD-FIELDNAME = 'VAT'.
W_FIELD-TABNAME = 'T_FINAL'.
W_FIELD-DO_SUM = 'X'.
W_FIELD-SELTEXT_M = 'VAT'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
V_POS = V_POS + 1.
W_FIELD-COL_POS = V_POS.
W_FIELD-FIELDNAME = 'FREIGHT' .
W_FIELD-TABNAME = 'T_FINAL'.
W_FIELD-DO_SUM = 'X'.
W_FIELD-SELTEXT_M = 'FREIGHT'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
V_POS = V_POS + 1.
W_FIELD-COL_POS = V_POS.
W_FIELD-FIELDNAME = 'TCS' .
W_FIELD-TABNAME = 'T_FINAL'.
W_FIELD-DO_SUM = 'X'.
W_FIELD-SELTEXT_M = 'TCS'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
V_POS = V_POS + 1.
W_FIELD-COL_POS = V_POS.
W_FIELD-FIELDNAME = 'SRG' .
W_FIELD-TABNAME = 'T_FINAL'.
W_FIELD-DO_SUM = 'X'.
W_FIELD-SELTEXT_M = 'SRG'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
<b> I_CALLBACK_PROGRAM = SY-CPROG</b>
I_STRUCTURE_NAME
IS_LAYOUT = WA_LAYOUT
IT_FIELDCAT = F_FIELD
<b> IS_VARIANT = IS_VARIANT</b>
<b> I_SAVE = 'X'</b>
IT_SORT = LS_SORT
TABLES
T_OUTTAB = T_FINAL
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.
Reward points if helpful
Thanks
Message was edited by:
Pattan Naveen