*Table Declaration
TABLES : vbak, vbap.
*Type-Pools
TYPE-POOLS : slis.
*Types Declaration
TYPES : BEGIN OF ty_vbak,
vbeln TYPE vbak-vbeln,
erdat TYPE vbak-erdat,
ernam TYPE vbak-ernam,
auart TYPE vbak-auart,
vkorg TYPE vbak-vkorg,
vtweg TYPE vbak-vtweg,
spart TYPE vbak-spart,
vkgrp TYPE vbak-vkgrp,
kunnr TYPE vbak-kunnr,
END OF ty_vbak.
TYPES : BEGIN OF ty_vbap,
vbeln TYPE vbap-vbeln,
posnr TYPE vbap-posnr,
matnr TYPE vbap-matnr,
matkl TYPE vbap-matkl,
arktx TYPE vbap-arktx,
netwr TYPE vbap-netwr,
waerk TYPE vbap-waerk,
klmeng TYPE vbap-klmeng,
vrkme TYPE vbap-vrkme,
END OF ty_vbap.
*Data Declaration
DATA : gt_vbak TYPE STANDARD TABLE OF ty_vbak,
wa_vbak TYPE ty_vbak,
gt_vbap TYPE STANDARD TABLE OF ty_vbap,
wa_vbap TYPE ty_vbap.
*Field Catalog and Layout Declaration
DATA: gt_fcat TYPE slis_t_fieldcat_alv,
gt_fcat1 TYPE slis_t_fieldcat_alv,
wa_fcat LIKE LINE OF gt_fcat,
wa_fcat1 LIKE LINE OF gt_fcat1,
gt_layout TYPE slis_layout_alv.
*Selection Screen
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
SELECT-OPTIONS : so_vbeln FOR vbap-vbeln.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM FIELD_CATLOG.
PERFORM SET_LAYOUT.
PERFORM DISPLAY_OUTPUT.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DATA .
SELECT VBELN
ERDAT
ERNAM
AUART
VKORG
VTWEG
SPART
VKGRP
KUNNR
FROM VBAK
INTO TABLE GT_VBAK
WHERE VBELN IN SO_VBELN.
IF SY-SUBRC EQ 0.
SORT GT_VBAK.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FIELD_CATLOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FIELD_CATLOG .
REFRESH : gt_fcat.
CLEAR : wa_fcat.
wa_fcat-col_pos = 1.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-seltext_m = 'Sales No.'.
wa_fcat-key = 'X'.
wa_fcat-hotspot = 'X'.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = 2.
wa_fcat-fieldname = 'ERDAT'.
wa_fcat-seltext_m = 'Created On'.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = 3.
wa_fcat-fieldname = 'ERNAM'.
wa_fcat-seltext_m = 'Created by'.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = 4.
wa_fcat-fieldname = 'AUART'.
wa_fcat-seltext_m = 'Doc. type'.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = 5.
wa_fcat-fieldname = 'VKORG'.
wa_fcat-seltext_m = 'Sales Organization'.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = 6.
wa_fcat-fieldname = 'VTWEG'.
wa_fcat-seltext_m = 'D.channel'.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = 7.
wa_fcat-fieldname = 'SPART'.
wa_fcat-seltext_m = 'Division'.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = 8.
wa_fcat-fieldname = 'VKGRP'.
wa_fcat-seltext_m = 'Sales Group'.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = 9.
wa_fcat-fieldname = 'KUNNR'.
wa_fcat-seltext_m = 'Customer'.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form SET_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SET_LAYOUT .
gt_layout-colwidth_optimize = 'X'.
gt_layout-ZEBRA = 'X'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form DISPLAY_OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DISPLAY_OUTPUT .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
* i_callback_pf_status_set = 'SET_PF_STATUS'
i_callback_user_command = 'USER_COMMAND'
is_layout = gt_layout
it_fieldcat = gt_fcat
TABLES
t_outtab = gt_vbak.
ENDFORM.
form USER_COMMAND USING r_ucomm type sy-ucomm
rs_selfield TYPE slis_selfield.
case r_ucomm.
when '&IC1'.
data: lv_vbeln type vbap-vbeln.
lv_vbeln = RS_SELFIELD-value.
SELECT vbeln
posnr
matnr
matkl
arktx
netwr
waerk
klmeng
vrkme
FROM vbap
INTO TABLE gt_vbap
WHERE vbeln eq lv_vbeln.
if sy-subrc eq 0.
PERFORM fcat_vbap.
PERFORM display_vbap.
endif.
ENDCASE.
endform.
*&---------------------------------------------------------------------*
*& Form FCAT_VBAP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FCAT_VBAP .
REFRESH : gt_fcat1.
CLEAR : wa_fcat1.
wa_fcat1-col_pos = 1.
wa_fcat1-fieldname = 'VBELN'.
wa_fcat1-seltext_m = 'Sales Order NO.'.
wa_fcat1-key = 'X'.
wa_fcat1-hotspot = 'X'.
APPEND wa_fcat1 TO gt_fcat1.
CLEAR wa_fcat1.
wa_fcat1-col_pos = 2.
wa_fcat1-fieldname = 'POSNR'.
wa_fcat1-seltext_m = 'Item no'.
APPEND wa_fcat1 TO gt_fcat1.
CLEAR wa_fcat1.
wa_fcat1-col_pos = 3.
wa_fcat1-fieldname = 'MATNR'.
wa_fcat1-seltext_m = 'Material NO.'.
APPEND wa_fcat1 TO gt_fcat1.
CLEAR wa_fcat1.
wa_fcat1-col_pos = 4.
wa_fcat1-fieldname = 'MATKL'.
wa_fcat1-seltext_m = 'Material group'.
APPEND wa_fcat1 TO gt_fcat1.
CLEAR wa_fcat1.
wa_fcat1-col_pos = 5.
wa_fcat1-fieldname = 'ARKTX'.
wa_fcat1-seltext_m = 'Description'.
APPEND wa_fcat1 TO gt_fcat1.
CLEAR wa_fcat1.
wa_fcat1-col_pos = 6.
wa_fcat1-fieldname = 'NETWR'.
wa_fcat1-seltext_m = 'Amount'.
APPEND wa_fcat1 TO gt_fcat1.
CLEAR wa_fcat1.
wa_fcat1-col_pos = 7.
wa_fcat1-fieldname = 'WAERK'.
wa_fcat1-seltext_m = 'Currency'.
APPEND wa_fcat1 TO gt_fcat1.
CLEAR wa_fcat1.
wa_fcat1-col_pos = 8.
wa_fcat1-fieldname = 'KLMENG'.
wa_fcat1-seltext_m = 'Quantity'.
APPEND wa_fcat1 TO gt_fcat1.
CLEAR wa_fcat1.
wa_fcat1-col_pos = 9.
wa_fcat1-fieldname = 'VRKME'.
wa_fcat1-seltext_m = 'Sales unit'.
APPEND wa_fcat1 TO gt_fcat1.
CLEAR wa_fcat1.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form DISPLAY_VBAP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DISPLAY_VBAP .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
is_layout = gt_layout
it_fieldcat = gt_fcat1
TABLES
t_outtab = gt_vbap.
ENDFORM.
No comments:
Post a Comment