Google Search - Blog...........

ABAP - ALV Interactive (Double Clicking)

interactive alv ( double clicking )
REPORT Z_INTERACTIVE_ALV.

TYPE-POOLS SLIS.

TYPES: BEGIN OF TY_VBAK,
VBELN TYPE VBAK-VBELN,
VKORG TYPE VBAK-VKORG,
VKGRP TYPE VBAK-VKGRP,
ERNAM TYPE VBAK-ERNAM,
NETWR TYPE VBAK-NETWR,
WAERK TYPE VBAK-WAERK,
END OF TY_VBAK.

TYPES: BEGIN OF TY_VBAP,
VBELN TYPE VBAK-VBELN,
MATNR TYPE VBAP-MATNR,
POSNR TYPE VBAP-POSNR,
END OF TY_VBAP.

*&---------------------------------------------------------------------*
*& Data Declarations *
*&---------------------------------------------------------------------*
DATA: T_VBAK TYPE TABLE OF TY_VBAK,
W_VBAK TYPE TY_VBAK,

T_VBAP TYPE TABLE OF TY_VBAP,
W_VBAP TYPE TY_VBAP,

T_FCAT TYPE SLIS_T_FIELDCAT_ALV,
W_FCAT TYPE SLIS_FIELDCAT_ALV,

T_FCAT1 TYPE SLIS_T_FIELDCAT_ALV,
W_FCAT1 TYPE SLIS_FIELDCAT_ALV,

W_DISVARIANT TYPE DISVARIANT, "variant

W_LAYOUT TYPE SLIS_LAYOUT_ALV, "Layout

T_SORTINFO TYPE SLIS_T_SORTINFO_ALV, " sorting
W_SORT TYPE SLIS_SORTINFO_ALV,

T_EVENT TYPE SLIS_T_EVENT,
W_EVENT TYPE SLIS_ALV_EVENT,

T_LISTHEADER TYPE SLIS_T_LISTHEADER,
W_LISTHEADER TYPE SLIS_LISTHEADER.

DATA: V_FIELD(30) TYPE C,
V_VALUE(10) TYPE C.

*&---------------------------------------------------------------------*
*& Selection Screen
*&---------------------------------------------------------------------*
SELECT-OPTIONS: S_VBELN FOR W_VBAK-VBELN.
*&---------------------------------------------------------------------*
*& Initialization *
*&---------------------------------------------------------------------*
INITIALIZATION.

PERFORM SUB_BUILD_FCAT.
PERFORM SUB_BUILD_EVENT.

*&---------------------------------------------------------------------*
*& Start Of Selection *
*&---------------------------------------------------------------------*
START-OF-SELECTION.

SET PF-STATUS 'ABC'.
PERFORM SUB_GET_VBAK.

*&---------------------------------------------------------------------*
*& End Of Selection
*&---------------------------------------------------------------------*
END-OF-SELECTION.

PERFORM SUB_DISPLAY.

*&---------------------------------------------------------------------*
*& Form sub_build_fcat
*&---------------------------------------------------------------------*
FORM SUB_BUILD_FCAT .

CLEAR: W_FCAT,T_FCAT[].

W_FCAT-COL_POS = 1.
W_FCAT-FIELDNAME = 'VBELN'.
W_FCAT-TABNAME = 'T_VBAK'.
W_FCAT-SELTEXT_L = 'S.Order'.
W_FCAT-KEY = 'X'.
W_FCAT-HOTSPOT = 'X'.
APPEND W_FCAT TO T_FCAT.

CLEAR W_FCAT.
W_FCAT-COL_POS = 2.
W_FCAT-FIELDNAME = 'VKORG'.
W_FCAT-TABNAME = 'T_VBAK'.
W_FCAT-SELTEXT_L = 'S.Org'.
APPEND W_FCAT TO T_FCAT.

CLEAR W_FCAT.
W_FCAT-COL_POS = 3.
W_FCAT-FIELDNAME = 'VKGRP'.
W_FCAT-TABNAME = 'T_VBAK'.
W_FCAT-SELTEXT_L = 'S.Grp'.
APPEND W_FCAT TO T_FCAT.

CLEAR W_FCAT.
W_FCAT-COL_POS = 4.
W_FCAT-FIELDNAME = 'NETWR'.
W_FCAT-TABNAME = 'T_VBAK'.
W_FCAT-REF_FIELDNAME = 'NETWR'.
W_FCAT-REF_TABNAME = 'VBAK'.
W_FCAT-DO_SUM = 'X'.
APPEND W_FCAT TO T_FCAT.

CLEAR W_FCAT.
W_FCAT-COL_POS = 5.
W_FCAT-FIELDNAME = 'WAERK'.
W_FCAT-TABNAME = 'T_VBAK'.
W_FCAT-SELTEXT_L = 'Doc. Cur'.
APPEND W_FCAT TO T_FCAT.

* layout
W_LAYOUT-WINDOW_TITLEBAR = 'Interactive ALV Report'.
W_LAYOUT-ZEBRA = 'X'.
W_LAYOUT-TOTALS_TEXT = 'Total Document Value'.

* sortinfo
CLEAR W_SORT.
W_SORT-FIELDNAME = 'VKORG'.
W_SORT-TABNAME = 'T_VBAK'.
W_SORT-UP = 'X'.
APPEND W_SORT TO T_SORTINFO.

ENDFORM. " sub_build_fcat
*&---------------------------------------------------------------------*
*& Form sub_get_vbak
*&---------------------------------------------------------------------*
FORM SUB_GET_VBAK .

REFRESH T_VBAK.

SELECT VBELN
VKORG
VKGRP
ERNAM
NETWR
WAERK
FROM VBAK
INTO TABLE T_VBAK
WHERE VBELN IN S_VBELN.

ENDFORM. " sub_get_vbak
*&---------------------------------------------------------------------*
*& Form sub_display
*&---------------------------------------------------------------------*
FORM SUB_DISPLAY .

W_DISVARIANT-REPORT = SY-REPID.
W_DISVARIANT-VARIANT = 'ZLAYOUT'.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT = W_LAYOUT
IT_FIELDCAT = T_FCAT
IT_SORT = T_SORTINFO
I_SAVE = 'A' "for saving layouts
IS_VARIANT = W_DISVARIANT
IT_EVENTS = T_EVENT
TABLES
T_OUTTAB = T_VBAK
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.

IF SY-SUBRC <> 0.
ENDIF.

ENDFORM. " sub_display
*&---------------------------------------------------------------------*
*& Form sub_build_event
*&---------------------------------------------------------------------*
FORM SUB_BUILD_EVENT .

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
IMPORTING
ET_EVENTS = T_EVENT
EXCEPTIONS
LIST_TYPE_WRONG = 1
OTHERS = 2.

IF SY-SUBRC <> 0.
ENDIF.

CLEAR W_EVENT.
W_EVENT-FORM = 'SUB_USER_COMMAND'.
MODIFY T_EVENT FROM W_EVENT TRANSPORTING FORM
WHERE NAME = 'USER_COMMAND'.
CLEAR W_EVENT.
W_EVENT-FORM = 'SUB_TOP_PAGE'.
MODIFY T_EVENT FROM W_EVENT TRANSPORTING FORM
WHERE NAME = 'TOP_OF_PAGE'.

ENDFORM. " sub_build_event
*&---------------------------------------------------------------------*
*& Form sub_user_command
*&---------------------------------------------------------------------*
FORM SUB_USER_COMMAND USING P_UCOMM TYPE SY-UCOMM
P_SELTAB TYPE SLIS_SELFIELD.

GET CURSOR FIELD V_FIELD VALUE V_VALUE.
PERFORM SUB_GET_VBAP.
PERFORM SUB_BUILD_FCAT1.
PERFORM DISPLAY_VBAP.

ENDFORM. " sub_user_command
*&---------------------------------------------------------------------*
*& Form sub_top_page
*&---------------------------------------------------------------------*
FORM SUB_TOP_PAGE .

CLEAR: T_LISTHEADER[].
W_LISTHEADER-TYP = 'H'.
W_LISTHEADER-INFO = 'ALV TOP OF PAGE'.
APPEND W_LISTHEADER TO T_LISTHEADER.

W_LISTHEADER-TYP = 'S'.
W_LISTHEADER-INFO = SY-DATUM.
APPEND W_LISTHEADER TO T_LISTHEADER.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = T_LISTHEADER.

ENDFORM. " sub_top_page
*&---------------------------------------------------------------------*
*& Form sub_get_vbap
*&---------------------------------------------------------------------*
FORM SUB_GET_VBAP .

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = V_VALUE
IMPORTING
OUTPUT = V_VALUE.

REFRESH T_VBAP.

SELECT VBELN
POSNR
MATNR
FROM VBAP
INTO CORRESPONDING FIELDS OF TABLE T_VBAP
WHERE VBELN = V_VALUE.

ENDFORM. " sub_get_vbap
*&---------------------------------------------------------------------*
*& Form SUB_BUILD_FCAT1
*&---------------------------------------------------------------------*
FORM SUB_BUILD_FCAT1 .

CLEAR: W_FCAT1,T_FCAT1[].

CLEAR W_FCAT1.
W_FCAT1-COL_POS = 1.
W_FCAT1-FIELDNAME = 'VBELN'.
W_FCAT1-TABNAME = 'T_VBAP'.
W_FCAT1-SELTEXT_L = 'S.Order'.
W_FCAT1-KEY = 'X'.
W_FCAT1-HOTSPOT = 'X'.
APPEND W_FCAT1 TO T_FCAT1.

CLEAR W_FCAT1.
W_FCAT1-COL_POS = 2.
W_FCAT1-FIELDNAME = 'POSNR'.
W_FCAT1-TABNAME = 'T_VBAP'.
W_FCAT1-SELTEXT_L = 'S.Item'.
APPEND W_FCAT1 TO T_FCAT1.

CLEAR W_FCAT1.
W_FCAT1-COL_POS = 3.
W_FCAT1-FIELDNAME = 'MATNR'.
W_FCAT1-TABNAME = 'T_VBAP'.
W_FCAT1-SELTEXT_L = 'Material'.
APPEND W_FCAT1 TO T_FCAT1.

ENDFORM. " SUB_BUILD_FCAT1
*&---------------------------------------------------------------------*
*& Form display_vbap
*&---------------------------------------------------------------------*
FORM DISPLAY_VBAP .

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IT_FIELDCAT = T_FCAT1
TABLES
T_OUTTAB = T_VBAP.

IF SY-SUBRC <> 0.
ENDIF.

ENDFORM. " display_vbap


..... Back To Index On ALV List/ Grid Display.

..... Back To MAIN INDEX.


No comments:

Post a Comment