Skip to Content
author's profile photo Former Member
Former Member

Secondary List in REUSE_ALV_GRID_DISPLAY

Hi Experts,

I have made an REUSE_ALV_GRID_DISPLAY ALV Report in PP Module..it working fine ...

I want the functionality of secondary list i.e. when i double click on any line on the report it should show the detail list may be in a popup screen.

For reference The report has all the operations in it. If i select any line then i should be able to get the Split Quantities for that particular Operation.

For Ref. i am already having 6 buttons lined up...si i require the popup functionality for making report simpler. Currently if i double click on any line i get a popup which has the details of that particular line itself(i need to replace this).

FORM user_command USING ucomm LIKE sy-ucomm

selfield TYPE slis_selfield .

IF NOT ucomm IS INITIAL.

READ TABLE i_mat INDEX selfield-tabindex.

IF sy-subrc EQ 0.

SET PARAMETER ID 'ANR' FIELD i_mat-aufnr.

SET PARAMETER ID 'MAT' FIELD i_mat-matnr.

SET PARAMETER ID 'WRK' FIELD i_mat-werks.

SET PARAMETER ID 'RES' FIELD i_mat-rsnum.

SET PARAMETER ID 'RCK' FIELD i_mat-rueck.

SET PARAMETER ID 'RZL' FIELD i_mat-rmzhl.

SET PARAMETER ID 'AGR' FIELD i_mat-arbpl.

SET PARAMETER ID 'CAG' FIELD i_mat-plnnr.

ENDIF.

CASE ucomm.

WHEN 'CO02'.

CALL TRANSACTION 'CO02' AND SKIP FIRST SCREEN.

WHEN 'CM01'.

CALL TRANSACTION 'CM01' AND SKIP FIRST SCREEN.

WHEN 'CO13'.

CALL TRANSACTION 'CO13' AND SKIP FIRST SCREEN.

WHEN 'CO14'.

CALL TRANSACTION 'CO14' AND SKIP FIRST SCREEN.

WHEN 'CA03'.

CALL TRANSACTION 'CA03'.

WHEN 'MB23'.

CALL TRANSACTION 'MB23' AND SKIP FIRST SCREEN.

ENDCASE.

ENDIF.

ENDFORM.

Pls let me know if further light is required.

Regards,

Abhishek

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jan 10, 2007 at 02:56 PM

    Hi abhisheik,

    check out this Program , which is as per your requirement.

    ----


    • Type pools

    ----


    TYPE-POOLS : SLIS.

    ----


    • Tables

    ----


    TABLES: VBAK,VBAP,ICON.

    ----


    • DATA Declaration

    ----


    *--Table to hold the Header Sales data

    DATA: BEGIN OF TB_VBAK OCCURS 0,

    INDICAT LIKE ICON-ID, " Icon

    VBELN LIKE VBAK-VBELN, " Sales Document

    AUDAT LIKE VBAK-AUDAT, " Document date

    VBTYP LIKE VBAK-VBTYP, " SD document category

    AUART LIKE VBAK-AUART, " Sales Document Type

    AUGRU LIKE VBAK-AUGRU, " Order reason

    NETWR LIKE VBAK-NETWR, " Net Value

    WAERK LIKE VBAK-WAERK, " SD document currency

    END OF TB_VBAK.

    *--Table to hold the Icons

    DATA: BEGIN OF TB_ICON OCCURS 0,

    ID TYPE ICON-ID, " Icon

    NAME TYPE ICON-NAME, " Name of an Icon

    END OF TB_ICON.

    *--Table to hold the Item Sales data

    DATA: BEGIN OF TB_VBAP OCCURS 0,

    VBELN LIKE VBAP-VBELN, " Sales Document

    POSNR LIKE VBAP-POSNR, " Sales Document Item

    MATNR LIKE VBAP-MATNR, " Material Number

    END OF TB_VBAP.

    *--Declaration of ALV Tables

    DATA : TB_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV, " Field Catalog

    TB_FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV, " Field Catalog

    TB_EVENTS TYPE SLIS_T_EVENT, " ALV Events

    TB_SORT_ALV TYPE SLIS_T_SORTINFO_ALV, " ALV Sort

    TB_COMMENTS TYPE SLIS_T_LISTHEADER. " Comment

    *--Declaration of Local Variables

    DATA : G_REPID LIKE SY-REPID. " For Program name

    DATA : L_TABIX TYPE SY-TABIX.

    ----


    • STRUCTURES

    ----


    *-- Declaration of ALV structures

    DATA : X_FIELDCAT TYPE SLIS_FIELDCAT_ALV, " For Field Catalog

    X_LAYOUT TYPE SLIS_LAYOUT_ALV, " For Layout

    X_EVENTS TYPE SLIS_ALV_EVENT, " For Events

    X_SORT TYPE SLIS_SORTINFO_ALV, " For Sort

    X_COMMENTS TYPE SLIS_LISTHEADER. " For Comments

    ----


    • C O N S T A N T S

    ----


    *--Declaration of Constants

    CONSTANTS : C_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE',

    C_PF_STATUS TYPE SLIS_FORMNAME VALUE 'FRM_PF_STATUS',

    C_USER_COMMAND TYPE SLIS_FORMNAME VALUE 'FRM_USER_COMMAND',

    C_GREEN(40) TYPE C VALUE 'ICON_GREEN_LIGHT',

    C_RED(40) TYPE C VALUE 'ICON_RED_LIGHT',

    C_YELLOW(40) TYPE C VALUE 'ICON_YELLOW_LIGHT',

    C_X TYPE C VALUE 'X', " Flag

    C_H TYPE C VALUE 'H', " For Commenet-Type

    C_S TYPE C VALUE 'S'. " For Commenet-Type

    ----


    • INITIALIZATION

    ----


    *--Intialization.

    INITIALIZATION.

    G_REPID = SY-REPID.

    ----


    • SELECTION SCREEN

    ----


    *--Block 1.

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

    PARAMETER: P_AUDAT LIKE VBAK-AUDAT

    DEFAULT '20050101'(003). " doc date.

    SELECTION-SCREEN: END OF BLOCK B1.

    *--bLOCK 2.

    SELECTION-SCREEN : BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.

    PARAMETER :P_ALVDIS AS CHECKBOX. " For List/Grid

    SELECTION-SCREEN : END OF BLOCK B2.

    ----


    • START OF SELECTION

    ----


    START-OF-SELECTION.

    *--Populating the header data from VBAK

    PERFORM POPULATE_VBAK.

    *--Populating all icons from ICON table

    PERFORM POPULATE_ICONS.

    *--Populating the final dispaly table

    PERFORM FINAL_POPULATION.

    ----


    • END OF SELECTION

    ----


    END-OF-SELECTION.

    IF NOT TB_VBAK[] IS INITIAL.

    *--Populating the field catalog for final display table

    PERFORM BUILD-FIELDCATALOG.

    *--Modifying the field catalog table

    PERFORM MODIFY_FIELDCATALOG.

    *--Generating all the events into the table

    PERFORM GET_EVENTS.

    *--sorting the Final table

    PERFORM SORT_TABLE.

    *--Dispalying the Fianl ALV Table

    PERFORM DISPLAY_TABLE.

    ELSE.

    MESSAGE I999 WITH 'No Records found for the selection criteria'(006)

    .

    ENDIF.

    &----


    *& Form build-fieldcatalog

    &----


    • Populating the fieldcatalog table for the Final display

    ----


    FORM BUILD-FIELDCATALOG .

    DATA :L_TABNAME TYPE SLIS_TABNAME. " Table Name

    L_TABNAME = 'TB_VBAK'.

    REFRESH : TB_FIELDCAT.

    CLEAR : TB_FIELDCAT.

    *--calling a function to build fieldcatalog for header data

    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

    EXPORTING

    I_PROGRAM_NAME = G_REPID

    I_INTERNAL_TABNAME = L_TABNAME

    I_INCLNAME = G_REPID

    CHANGING

    CT_FIELDCAT = TB_FIELDCAT

    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.

    ENDFORM. " build-fieldcatalog

    &----


    *& Form display_table

    &----


    • Module to display the ALV Grid/List

    ----


    FORM DISPLAY_TABLE .

    *--Layout settings

    CLEAR X_LAYOUT.

    X_LAYOUT-ZEBRA = C_X.

    X_LAYOUT-COLWIDTH_OPTIMIZE = C_X.

    X_LAYOUT-NO_COLHEAD = SPACE.

    *--for list format settings

    IF P_ALVDIS = C_X.

    X_LAYOUT-NO_VLINE = C_X.

    X_LAYOUT-NO_HLINE = C_X.

    ENDIF.

    *--Displaying the ALV

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    I_CALLBACK_PROGRAM = G_REPID

    I_CALLBACK_PF_STATUS_SET = C_PF_STATUS

    IS_LAYOUT = X_LAYOUT

    IT_EVENTS = TB_EVENTS

    IT_FIELDCAT = TB_FIELDCAT

    IT_SORT = TB_SORT_ALV

    TABLES

    T_OUTTAB = TB_VBAK

    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. " display_table

    &----


    *& Form get_events

    &----


    • Module to GET EVENTS for ALV Dispaly

    ----


    FORM GET_EVENTS .

    REFRESH : TB_EVENTS.

    CLEAR : TB_EVENTS.

    *--functin to get events

    CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

    EXPORTING

    I_LIST_TYPE = 0

    IMPORTING

    ET_EVENTS = TB_EVENTS

    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.

    • Modifing Top of Page event

    READ TABLE TB_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGE

    INTO X_EVENTS.

    CLEAR L_TABIX.

    L_TABIX = SY-TABIX.

    IF SY-SUBRC = 0.

    X_EVENTS-FORM = C_TOP_OF_PAGE.

    MODIFY TB_EVENTS FROM X_EVENTS INDEX L_TABIX.

    CLEAR X_EVENTS.

    ENDIF.

    • Modifing User comand event

    READ TABLE TB_EVENTS WITH KEY NAME = SLIS_EV_USER_COMMAND

    INTO X_EVENTS.

    CLEAR L_TABIX.

    L_TABIX = SY-TABIX.

    IF SY-SUBRC = 0.

    X_EVENTS-FORM = C_USER_COMMAND.

    MODIFY TB_EVENTS FROM X_EVENTS INDEX L_TABIX.

    CLEAR X_EVENTS.

    ENDIF.

    ENDFORM. " get_events

    &----


    *& Form TOP_OF_PAGE

    &----


    • Top Of Page for the ALV format

    ----


    FORM TOP_OF_PAGE.

    DATA : L_DATE(02) TYPE C, "Date

    L_MONTH(02) TYPE C, "Month

    L_YEAR(04) TYPE C, "Year

    L_DATE_INFO(10) TYPE C, "DATE

    L_TEMP1(100) TYPE C, "temp

    L_TEMP(100) TYPE C, "temp

    L_TITLE(50) TYPE C. "title

    CLEAR : TB_COMMENTS,

    TB_COMMENTS[].

    • Filling Comments for Top of Page

    X_COMMENTS-TYP = C_H.

    L_TITLE = SY-TITLE.

    X_COMMENTS-INFO = L_TITLE.

    APPEND X_COMMENTS TO TB_COMMENTS.

    CLEAR X_COMMENTS.

    CLEAR :L_TEMP,L_TEMP1.

    X_COMMENTS-TYP = C_S.

    • date

    L_DATE = SY-DATUM+6(2).

    L_MONTH = SY-DATUM+4(2).

    L_YEAR = SY-DATUM+0(4).

    L_TEMP = 'Date :'(005).

    CONCATENATE L_YEAR '-' L_MONTH '-' L_DATE INTO L_DATE_INFO.

    CONCATENATE L_TEMP L_DATE_INFO

    INTO L_TEMP1 SEPARATED BY SPACE.

    X_COMMENTS-INFO = L_TEMP1.

    APPEND X_COMMENTS TO TB_COMMENTS.

    *--Function to write Comments

    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

    EXPORTING

    IT_LIST_COMMENTARY = TB_COMMENTS.

    ENDFORM. " TOP_OF_PAGE

    &----


    *& Form FINAL_POPULATION

    &----


    • Populating the FINAL table

    ----


    FORM FINAL_POPULATION .

    CLEAR SY-TABIX.

    LOOP AT TB_VBAK.

    L_TABIX = SY-TABIX.

    IF TB_VBAK-NETWR <= 10.

    READ TABLE TB_ICON WITH KEY NAME = C_GREEN BINARY SEARCH.

    IF SY-SUBRC = 0.

    TB_VBAK-INDICAT = TB_ICON-ID.

    MODIFY TB_VBAK INDEX L_TABIX.

    CLEAR TB_ICON.

    ENDIF.

    ELSEIF TB_VBAK-NETWR > 10 AND TB_VBAK-NETWR < 100.

    READ TABLE TB_ICON WITH KEY NAME = C_YELLOW BINARY SEARCH.

    IF SY-SUBRC = 0.

    TB_VBAK-INDICAT = TB_ICON-ID.

    MODIFY TB_VBAK INDEX L_TABIX.

    CLEAR TB_ICON.

    ENDIF.

    ELSEIF TB_VBAK-NETWR => 100.

    READ TABLE TB_ICON WITH KEY NAME = C_RED BINARY SEARCH.

    IF SY-SUBRC = 0.

    TB_VBAK-INDICAT = TB_ICON-ID.

    MODIFY TB_VBAK INDEX L_TABIX.

    CLEAR TB_ICON.

    ENDIF.

    ENDIF.

    ENDLOOP.

    ENDFORM. " FINAL_POPULATION

    &----


    *& Form MODIFY_FIELDCATALOG

    &----


    • Modifying the FIELD CATALOG

    ----


    FORM MODIFY_FIELDCATALOG .

    DATA: L_DDICTXT TYPE C VALUE 'L'. "FLAG

    LOOP AT TB_FIELDCAT INTO X_FIELDCAT.

    CLEAR L_TABIX.

    L_TABIX = SY-TABIX.

    CASE X_FIELDCAT-FIELDNAME.

    WHEN 'INDICAT'. " icon

    X_FIELDCAT-SELTEXT_L = 'Status indicator'(008).

    X_FIELDCAT-DDICTXT = L_DDICTXT.

    WHEN 'VBELN'. " sales doc

    X_FIELDCAT-SELTEXT_L = 'Sales Doc #'(009).

    X_FIELDCAT-DDICTXT = L_DDICTXT.

    WHEN 'AUDAT'. " doc date

    X_FIELDCAT-SELTEXT_L = 'Document Date'(010).

    X_FIELDCAT-DDICTXT = L_DDICTXT.

    WHEN 'VBTYP'. " doc category

    X_FIELDCAT-SELTEXT_L = 'Category'(011).

    X_FIELDCAT-DDICTXT = L_DDICTXT.

    WHEN 'AUART'. " doc type

    X_FIELDCAT-SELTEXT_L = 'Doc Type'(012).

    X_FIELDCAT-DDICTXT = L_DDICTXT.

    WHEN 'AUGRU'. " reason

    X_FIELDCAT-SELTEXT_L = 'Reason'(013).

    X_FIELDCAT-DDICTXT = L_DDICTXT.

    WHEN 'WAERK'. " Currency unit

    X_FIELDCAT-SELTEXT_L = 'Unit'(014).

    X_FIELDCAT-DDICTXT = L_DDICTXT.

    WHEN 'NETWR' . " Amount

    X_FIELDCAT-SELTEXT_L = 'Net Value'(015).

    X_FIELDCAT-DDICTXT = L_DDICTXT.

    *-- TO display the total sum at the end.

    X_FIELDCAT-DO_SUM = C_X.

    ENDCASE.

    MODIFY TB_FIELDCAT FROM X_FIELDCAT INDEX L_TABIX.

    ENDLOOP.

    ENDFORM. " MODIFY_FIELDCATALOG

    &----


    *& Form SORT_TABLE

    &----


    • SORTING the ALV

    ----


    FORM SORT_TABLE .

    *--sorting the fields

    CLEAR X_SORT.

    X_SORT-SPOS = '1'.

    X_SORT-FIELDNAME = 'AUART'.

    X_SORT-TABNAME = 'TB_VBAK'.

    X_SORT-UP = C_X.

    APPEND X_SORT TO TB_SORT_ALV.

    CLEAR X_SORT.

    X_SORT-SPOS = '2'.

    X_SORT-FIELDNAME = 'VBTYP'.

    X_SORT-TABNAME = 'TB_VBAK'.

    X_SORT-UP = C_X.

    APPEND X_SORT TO TB_SORT_ALV.

    CLEAR X_SORT.

    X_SORT-SPOS = '3'.

    X_SORT-FIELDNAME = 'WAERK'.

    X_SORT-TABNAME = 'TB_VBAK'.

    X_SORT-UP = C_X.

    X_SORT-SUBTOT = C_X.

    APPEND X_SORT TO TB_SORT_ALV.

    ENDFORM. " SORT_TABLE

    &----


    *& Form FRM_PF_STATUS

    &----


    • Customizing the PF-STATUS

    ----


    FORM FRM_PF_STATUS USING EXTAB TYPE SLIS_T_EXTAB .

    DATA: L_EXTAB TYPE SLIS_EXTAB.

    CLEAR EXTAB[].

    L_EXTAB-FCODE = '&EB9'.

    APPEND L_EXTAB TO EXTAB.

    L_EXTAB-FCODE = '&SUM'.

    APPEND L_EXTAB TO EXTAB.

    L_EXTAB-FCODE = '&OAD'.

    APPEND L_EXTAB TO EXTAB.

    L_EXTAB-FCODE = '&UMC'.

    APPEND L_EXTAB TO EXTAB.

    L_EXTAB-FCODE = '&AVE'.

    APPEND L_EXTAB TO EXTAB.

    L_EXTAB-FCODE = '&RNT'.

    APPEND L_EXTAB TO EXTAB.

    *--excluding some the tool buttons from the PF status

    SET PF-STATUS 'PRACTICE_ALV' EXCLUDING EXTAB.

    ENDFORM. " FRM_PF_STATUS

    &----


    *& Form FRM_USER_COMMAND

    &----


    • USER COMMAND for the ALV event

    ----


    FORM FRM_USER_COMMAND USING R_UCOMM LIKE SY-UCOMM

    RS_SELFIELD TYPE SLIS_SELFIELD .

    CASE R_UCOMM.

    WHEN '&IC1'.

    READ TABLE TB_VBAK INDEX RS_SELFIELD-TABINDEX.

    IF SY-SUBRC = 0.

    *--selecting the line items for the selected VBELN

    SELECT VBELN POSNR MATNR

    FROM VBAP

    INTO TABLE TB_VBAP

    WHERE VBELN = TB_VBAK-VBELN.

    IF SY-SUBRC = 0.

    *--Perforrming the field catalog for line item table

    PERFORM FIELDCAT_ITEM.

    PERFORM DISPLAY_POPUP.

    ELSE.

    MESSAGE I999 WITH 'NO item data existing for the record'(007).

    ENDIF.

    ENDIF.

    ENDCASE.

    ENDFORM. " FRM_USER_COMMAND

    &----


    *& Form FIELDCAT_ITEM

    &----


    • Build field catalog for the line items

    ----


    FORM FIELDCAT_ITEM .

    DATA : L_TABNAME TYPE SLIS_TABNAME.

    L_TABNAME = 'TB_VBAP'.

    CLEAR : TB_FIELDCAT1,TB_FIELDCAT1[].

    *-- building catalog for line items

    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

    EXPORTING

    I_PROGRAM_NAME = G_REPID

    I_INTERNAL_TABNAME = L_TABNAME

    I_INCLNAME = G_REPID

    CHANGING

    CT_FIELDCAT = TB_FIELDCAT1

    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.

    ENDFORM. " FIELDCAT_ITEM

    &----


    *& Form POPULATE_VBAK

    &----


    • Populating the Sales header data

    ----


    FORM POPULATE_VBAK .

    *-- selecting from VBAK

    SELECT VBELN

    AUDAT

    VBTYP

    AUART

    AUGRU

    NETWR

    WAERK

    INTO CORRESPONDING FIELDS OF TABLE TB_VBAK

    FROM VBAK

    WHERE AUDAT > P_AUDAT AND

    NETWR > 0.

    IF SY-SUBRC <> 0.

    SORT TB_VBAK BY AUART VBTYP WAERK .

    ENDIF.

    ENDFORM. " POPULATE_VBAK

    &----


    *& Form POPULATE_ICONS

    &----


    • Populating the ICON table

    ----


    FORM POPULATE_ICONS .

    *--selecting from ICON table

    SELECT ID

    NAME

    INTO TABLE TB_ICON

    FROM ICON.

    IF SY-SUBRC = 0.

    SORT TB_ICON BY NAME .

    ENDIF.

    ENDFORM. " POPULATE_ICONS

    &----


    *& Form DISPLAY_POPUP

    &----


    • Displaying the POP UP with line item details

    ----


    FORM DISPLAY_POPUP .

    DATA: L_TITLE(40) TYPE C . " For pop up title

    L_TITLE = 'Sales document Item Data'(004).

    *--Function to display the pop up with line item details

    CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'

    EXPORTING

    I_TITLE = L_TITLE

    I_TABNAME = 'TB_VBAP'

    IT_FIELDCAT = TB_FIELDCAT1

    I_CALLBACK_PROGRAM = G_REPID

    TABLES

    T_OUTTAB = TB_VBAP

    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. " DISPLAY_POPUP

    regards,

    sateesh.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 10, 2007 at 03:03 PM

    ----


    • Type pools

    ----


    TYPE-POOLS : SLIS.

    ----


    • Tables

    ----


    TABLES: VBAK,VBAP,ICON.

    ----


    • DATA Declaration

    ----


    *--Table to hold the Header Sales data

    DATA: BEGIN OF TB_VBAK OCCURS 0,

    INDICAT LIKE ICON-ID, " Icon

    VBELN LIKE VBAK-VBELN, " Sales Document

    AUDAT LIKE VBAK-AUDAT, " Document date

    VBTYP LIKE VBAK-VBTYP, " SD document category

    AUART LIKE VBAK-AUART, " Sales Document Type

    AUGRU LIKE VBAK-AUGRU, " Order reason

    NETWR LIKE VBAK-NETWR, " Net Value

    WAERK LIKE VBAK-WAERK, " SD document currency

    END OF TB_VBAK.

    *--Table to hold the Icons

    DATA: BEGIN OF TB_ICON OCCURS 0,

    ID TYPE ICON-ID, " Icon

    NAME TYPE ICON-NAME, " Name of an Icon

    END OF TB_ICON.

    *--Table to hold the Item Sales data

    DATA: BEGIN OF TB_VBAP OCCURS 0,

    VBELN LIKE VBAP-VBELN, " Sales Document

    POSNR LIKE VBAP-POSNR, " Sales Document Item

    MATNR LIKE VBAP-MATNR, " Material Number

    END OF TB_VBAP.

    *--Declaration of ALV Tables

    DATA : TB_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV, " Field Catalog

    TB_FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV, " Field Catalog

    TB_EVENTS TYPE SLIS_T_EVENT, " ALV Events

    TB_SORT_ALV TYPE SLIS_T_SORTINFO_ALV, " ALV Sort

    TB_COMMENTS TYPE SLIS_T_LISTHEADER. " Comment

    *--Declaration of Local Variables

    DATA : G_REPID LIKE SY-REPID. " For Program name

    DATA : L_TABIX TYPE SY-TABIX.

    ----


    • STRUCTURES

    ----


    *-- Declaration of ALV structures

    DATA : X_FIELDCAT TYPE SLIS_FIELDCAT_ALV, " For Field Catalog

    X_LAYOUT TYPE SLIS_LAYOUT_ALV, " For Layout

    X_EVENTS TYPE SLIS_ALV_EVENT, " For Events

    X_SORT TYPE SLIS_SORTINFO_ALV, " For Sort

    X_COMMENTS TYPE SLIS_LISTHEADER. " For Comments

    ----


    • C O N S T A N T S

    ----


    *--Declaration of Constants

    CONSTANTS : C_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE',

    C_PF_STATUS TYPE SLIS_FORMNAME VALUE 'FRM_PF_STATUS',

    C_USER_COMMAND TYPE SLIS_FORMNAME VALUE 'FRM_USER_COMMAND',

    C_GREEN(40) TYPE C VALUE 'ICON_GREEN_LIGHT',

    C_RED(40) TYPE C VALUE 'ICON_RED_LIGHT',

    C_YELLOW(40) TYPE C VALUE 'ICON_YELLOW_LIGHT',

    C_X TYPE C VALUE 'X', " Flag

    C_H TYPE C VALUE 'H', " For Commenet-Type

    C_S TYPE C VALUE 'S'. " For Commenet-Type

    ----


    • INITIALIZATION

    ----


    *--Intialization.

    INITIALIZATION.

    G_REPID = SY-REPID.

    ----


    • SELECTION SCREEN

    ----


    *--Block 1.

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

    PARAMETER: P_AUDAT LIKE VBAK-AUDAT

    DEFAULT '20050101'(003). " doc date.

    SELECTION-SCREEN: END OF BLOCK B1.

    *--bLOCK 2.

    SELECTION-SCREEN : BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.

    PARAMETER :P_ALVDIS AS CHECKBOX. " For List/Grid

    SELECTION-SCREEN : END OF BLOCK B2.

    ----


    • START OF SELECTION

    ----


    START-OF-SELECTION.

    *--Populating the header data from VBAK

    PERFORM POPULATE_VBAK.

    *--Populating all icons from ICON table

    PERFORM POPULATE_ICONS.

    *--Populating the final dispaly table

    PERFORM FINAL_POPULATION.

    ----


    • END OF SELECTION

    ----


    END-OF-SELECTION.

    IF NOT TB_VBAK[] IS INITIAL.

    *--Populating the field catalog for final display table

    PERFORM BUILD-FIELDCATALOG.

    *--Modifying the field catalog table

    PERFORM MODIFY_FIELDCATALOG.

    *--Generating all the events into the table

    PERFORM GET_EVENTS.

    *--sorting the Final table

    PERFORM SORT_TABLE.

    *--Dispalying the Fianl ALV Table

    PERFORM DISPLAY_TABLE.

    ELSE.

    MESSAGE I999 WITH 'No Records found for the selection criteria'(006)

    .

    ENDIF.

    &----


    *& Form build-fieldcatalog

    &----


    • Populating the fieldcatalog table for the Final display

    ----


    FORM BUILD-FIELDCATALOG .

    DATA :L_TABNAME TYPE SLIS_TABNAME. " Table Name

    L_TABNAME = 'TB_VBAK'.

    REFRESH : TB_FIELDCAT.

    CLEAR : TB_FIELDCAT.

    *--calling a function to build fieldcatalog for header data

    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

    EXPORTING

    I_PROGRAM_NAME = G_REPID

    I_INTERNAL_TABNAME = L_TABNAME

    I_INCLNAME = G_REPID

    CHANGING

    CT_FIELDCAT = TB_FIELDCAT

    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.

    ENDFORM. " build-fieldcatalog

    &----


    *& Form display_table

    &----


    • Module to display the ALV Grid/List

    ----


    FORM DISPLAY_TABLE .

    *--Layout settings

    CLEAR X_LAYOUT.

    X_LAYOUT-ZEBRA = C_X.

    X_LAYOUT-COLWIDTH_OPTIMIZE = C_X.

    X_LAYOUT-NO_COLHEAD = SPACE.

    *--for list format settings

    IF P_ALVDIS = C_X.

    X_LAYOUT-NO_VLINE = C_X.

    X_LAYOUT-NO_HLINE = C_X.

    ENDIF.

    *--Displaying the ALV

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    I_CALLBACK_PROGRAM = G_REPID

    I_CALLBACK_PF_STATUS_SET = C_PF_STATUS

    IS_LAYOUT = X_LAYOUT

    IT_EVENTS = TB_EVENTS

    IT_FIELDCAT = TB_FIELDCAT

    IT_SORT = TB_SORT_ALV

    TABLES

    T_OUTTAB = TB_VBAK

    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. " display_table

    &----


    *& Form get_events

    &----


    • Module to GET EVENTS for ALV Dispaly

    ----


    FORM GET_EVENTS .

    REFRESH : TB_EVENTS.

    CLEAR : TB_EVENTS.

    *--functin to get events

    CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

    EXPORTING

    I_LIST_TYPE = 0

    IMPORTING

    ET_EVENTS = TB_EVENTS

    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.

    • Modifing Top of Page event

    READ TABLE TB_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGE

    INTO X_EVENTS.

    CLEAR L_TABIX.

    L_TABIX = SY-TABIX.

    IF SY-SUBRC = 0.

    X_EVENTS-FORM = C_TOP_OF_PAGE.

    MODIFY TB_EVENTS FROM X_EVENTS INDEX L_TABIX.

    CLEAR X_EVENTS.

    ENDIF.

    • Modifing User comand event

    READ TABLE TB_EVENTS WITH KEY NAME = SLIS_EV_USER_COMMAND

    INTO X_EVENTS.

    CLEAR L_TABIX.

    L_TABIX = SY-TABIX.

    IF SY-SUBRC = 0.

    X_EVENTS-FORM = C_USER_COMMAND.

    MODIFY TB_EVENTS FROM X_EVENTS INDEX L_TABIX.

    CLEAR X_EVENTS.

    ENDIF.

    ENDFORM. " get_events

    &----


    *& Form TOP_OF_PAGE

    &----


    • Top Of Page for the ALV format

    ----


    FORM TOP_OF_PAGE.

    DATA : L_DATE(02) TYPE C, "Date

    L_MONTH(02) TYPE C, "Month

    L_YEAR(04) TYPE C, "Year

    L_DATE_INFO(10) TYPE C, "DATE

    L_TEMP1(100) TYPE C, "temp

    L_TEMP(100) TYPE C, "temp

    L_TITLE(50) TYPE C. "title

    CLEAR : TB_COMMENTS,

    TB_COMMENTS[].

    • Filling Comments for Top of Page

    X_COMMENTS-TYP = C_H.

    L_TITLE = SY-TITLE.

    X_COMMENTS-INFO = L_TITLE.

    APPEND X_COMMENTS TO TB_COMMENTS.

    CLEAR X_COMMENTS.

    CLEAR :L_TEMP,L_TEMP1.

    X_COMMENTS-TYP = C_S.

    • date

    L_DATE = SY-DATUM+6(2).

    L_MONTH = SY-DATUM+4(2).

    L_YEAR = SY-DATUM+0(4).

    L_TEMP = 'Date :'(005).

    CONCATENATE L_YEAR '-' L_MONTH '-' L_DATE INTO L_DATE_INFO.

    CONCATENATE L_TEMP L_DATE_INFO

    INTO L_TEMP1 SEPARATED BY SPACE.

    X_COMMENTS-INFO = L_TEMP1.

    APPEND X_COMMENTS TO TB_COMMENTS.

    *--Function to write Comments

    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

    EXPORTING

    IT_LIST_COMMENTARY = TB_COMMENTS.

    ENDFORM. " TOP_OF_PAGE

    &----


    *& Form FINAL_POPULATION

    &----


    • Populating the FINAL table

    ----


    FORM FINAL_POPULATION .

    CLEAR SY-TABIX.

    LOOP AT TB_VBAK.

    L_TABIX = SY-TABIX.

    IF TB_VBAK-NETWR <= 10.

    READ TABLE TB_ICON WITH KEY NAME = C_GREEN BINARY SEARCH.

    IF SY-SUBRC = 0.

    TB_VBAK-INDICAT = TB_ICON-ID.

    MODIFY TB_VBAK INDEX L_TABIX.

    CLEAR TB_ICON.

    ENDIF.

    ELSEIF TB_VBAK-NETWR > 10 AND TB_VBAK-NETWR < 100.

    READ TABLE TB_ICON WITH KEY NAME = C_YELLOW BINARY SEARCH.

    IF SY-SUBRC = 0.

    TB_VBAK-INDICAT = TB_ICON-ID.

    MODIFY TB_VBAK INDEX L_TABIX.

    CLEAR TB_ICON.

    ENDIF.

    ELSEIF TB_VBAK-NETWR => 100.

    READ TABLE TB_ICON WITH KEY NAME = C_RED BINARY SEARCH.

    IF SY-SUBRC = 0.

    TB_VBAK-INDICAT = TB_ICON-ID.

    MODIFY TB_VBAK INDEX L_TABIX.

    CLEAR TB_ICON.

    ENDIF.

    ENDIF.

    ENDLOOP.

    ENDFORM. " FINAL_POPULATION

    &----


    *& Form MODIFY_FIELDCATALOG

    &----


    • Modifying the FIELD CATALOG

    ----


    FORM MODIFY_FIELDCATALOG .

    DATA: L_DDICTXT TYPE C VALUE 'L'. "FLAG

    LOOP AT TB_FIELDCAT INTO X_FIELDCAT.

    CLEAR L_TABIX.

    L_TABIX = SY-TABIX.

    CASE X_FIELDCAT-FIELDNAME.

    WHEN 'INDICAT'. " icon

    X_FIELDCAT-SELTEXT_L = 'Status indicator'(008).

    X_FIELDCAT-DDICTXT = L_DDICTXT.

    WHEN 'VBELN'. " sales doc

    X_FIELDCAT-SELTEXT_L = 'Sales Doc #'(009).

    X_FIELDCAT-DDICTXT = L_DDICTXT.

    WHEN 'AUDAT'. " doc date

    X_FIELDCAT-SELTEXT_L = 'Document Date'(010).

    X_FIELDCAT-DDICTXT = L_DDICTXT.

    WHEN 'VBTYP'. " doc category

    X_FIELDCAT-SELTEXT_L = 'Category'(011).

    X_FIELDCAT-DDICTXT = L_DDICTXT.

    WHEN 'AUART'. " doc type

    X_FIELDCAT-SELTEXT_L = 'Doc Type'(012).

    X_FIELDCAT-DDICTXT = L_DDICTXT.

    WHEN 'AUGRU'. " reason

    X_FIELDCAT-SELTEXT_L = 'Reason'(013).

    X_FIELDCAT-DDICTXT = L_DDICTXT.

    WHEN 'WAERK'. " Currency unit

    X_FIELDCAT-SELTEXT_L = 'Unit'(014).

    X_FIELDCAT-DDICTXT = L_DDICTXT.

    WHEN 'NETWR' . " Amount

    X_FIELDCAT-SELTEXT_L = 'Net Value'(015).

    X_FIELDCAT-DDICTXT = L_DDICTXT.

    *-- TO display the total sum at the end.

    X_FIELDCAT-DO_SUM = C_X.

    ENDCASE.

    MODIFY TB_FIELDCAT FROM X_FIELDCAT INDEX L_TABIX.

    ENDLOOP.

    ENDFORM. " MODIFY_FIELDCATALOG

    &----


    *& Form SORT_TABLE

    &----


    • SORTING the ALV

    ----


    FORM SORT_TABLE .

    *--sorting the fields

    CLEAR X_SORT.

    X_SORT-SPOS = '1'.

    X_SORT-FIELDNAME = 'AUART'.

    X_SORT-TABNAME = 'TB_VBAK'.

    X_SORT-UP = C_X.

    APPEND X_SORT TO TB_SORT_ALV.

    CLEAR X_SORT.

    X_SORT-SPOS = '2'.

    X_SORT-FIELDNAME = 'VBTYP'.

    X_SORT-TABNAME = 'TB_VBAK'.

    X_SORT-UP = C_X.

    APPEND X_SORT TO TB_SORT_ALV.

    CLEAR X_SORT.

    X_SORT-SPOS = '3'.

    X_SORT-FIELDNAME = 'WAERK'.

    X_SORT-TABNAME = 'TB_VBAK'.

    X_SORT-UP = C_X.

    X_SORT-SUBTOT = C_X.

    APPEND X_SORT TO TB_SORT_ALV.

    ENDFORM. " SORT_TABLE

    &----


    *& Form FRM_PF_STATUS

    &----


    • Customizing the PF-STATUS

    ----


    FORM FRM_PF_STATUS USING EXTAB TYPE SLIS_T_EXTAB .

    DATA: L_EXTAB TYPE SLIS_EXTAB.

    CLEAR EXTAB[].

    L_EXTAB-FCODE = '&EB9'.

    APPEND L_EXTAB TO EXTAB.

    L_EXTAB-FCODE = '&SUM'.

    APPEND L_EXTAB TO EXTAB.

    L_EXTAB-FCODE = '&OAD'.

    APPEND L_EXTAB TO EXTAB.

    L_EXTAB-FCODE = '&UMC'.

    APPEND L_EXTAB TO EXTAB.

    L_EXTAB-FCODE = '&AVE'.

    APPEND L_EXTAB TO EXTAB.

    L_EXTAB-FCODE = '&RNT'.

    APPEND L_EXTAB TO EXTAB.

    *--excluding some the tool buttons from the PF status

    SET PF-STATUS 'PRACTICE_ALV' EXCLUDING EXTAB.

    ENDFORM. " FRM_PF_STATUS

    &----


    *& Form FRM_USER_COMMAND

    &----


    • USER COMMAND for the ALV event

    ----


    FORM FRM_USER_COMMAND USING R_UCOMM LIKE SY-UCOMM

    RS_SELFIELD TYPE SLIS_SELFIELD .

    CASE R_UCOMM.

    WHEN '&IC1'.

    READ TABLE TB_VBAK INDEX RS_SELFIELD-TABINDEX.

    IF SY-SUBRC = 0.

    *--selecting the line items for the selected VBELN

    SELECT VBELN POSNR MATNR

    FROM VBAP

    INTO TABLE TB_VBAP

    WHERE VBELN = TB_VBAK-VBELN.

    IF SY-SUBRC = 0.

    *--Perforrming the field catalog for line item table

    PERFORM FIELDCAT_ITEM.

    PERFORM DISPLAY_POPUP.

    ELSE.

    MESSAGE I999 WITH 'NO item data existing for the record'(007).

    ENDIF.

    ENDIF.

    ENDCASE.

    ENDFORM. " FRM_USER_COMMAND

    &----


    *& Form FIELDCAT_ITEM

    &----


    • Build field catalog for the line items

    ----


    FORM FIELDCAT_ITEM .

    DATA : L_TABNAME TYPE SLIS_TABNAME.

    L_TABNAME = 'TB_VBAP'.

    CLEAR : TB_FIELDCAT1,TB_FIELDCAT1[].

    *-- building catalog for line items

    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

    EXPORTING

    I_PROGRAM_NAME = G_REPID

    I_INTERNAL_TABNAME = L_TABNAME

    I_INCLNAME = G_REPID

    CHANGING

    CT_FIELDCAT = TB_FIELDCAT1

    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.

    ENDFORM. " FIELDCAT_ITEM

    &----


    *& Form POPULATE_VBAK

    &----


    • Populating the Sales header data

    ----


    FORM POPULATE_VBAK .

    *-- selecting from VBAK

    SELECT VBELN

    AUDAT

    VBTYP

    AUART

    AUGRU

    NETWR

    WAERK

    INTO CORRESPONDING FIELDS OF TABLE TB_VBAK

    FROM VBAK

    WHERE AUDAT > P_AUDAT AND

    NETWR > 0.

    IF SY-SUBRC <> 0.

    SORT TB_VBAK BY AUART VBTYP WAERK .

    ENDIF.

    ENDFORM. " POPULATE_VBAK

    &----


    *& Form POPULATE_ICONS

    &----


    • Populating the ICON table

    ----


    FORM POPULATE_ICONS .

    *--selecting from ICON table

    SELECT ID

    NAME

    INTO TABLE TB_ICON

    FROM ICON.

    IF SY-SUBRC = 0.

    SORT TB_ICON BY NAME .

    ENDIF.

    ENDFORM. " POPULATE_ICONS

    &----


    *& Form DISPLAY_POPUP

    &----


    • Displaying the POP UP with line item details

    ----


    FORM DISPLAY_POPUP .

    DATA: L_TITLE(40) TYPE C . " For pop up title

    L_TITLE = 'Sales document Item Data'(004).

    *--Function to display the pop up with line item details

    CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'

    EXPORTING

    I_TITLE = L_TITLE

    I_TABNAME = 'TB_VBAP'

    IT_FIELDCAT = TB_FIELDCAT1

    I_CALLBACK_PROGRAM = G_REPID

    TABLES

    T_OUTTAB = TB_VBAP

    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. " DISPLAY_POPUP

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.