訂單交貨狀態檢查
*&---------------------------------------------------------------------*
*& Report ZSDF002A
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zsdf002a.
DATA: gt_fieldcat TYPE TABLE OF slis_fieldcat_alv.
DATA: gs_fieldcat TYPE slis_fieldcat_alv.
DATA: gs_layout TYPE slis_layout_alv .
DATA: g_fm_name TYPE rs38l_fnam.
DATA: gw_options TYPE ssfcompop,
gw_control TYPE ssfctrlop.
TABLES vbak .
SELECT-OPTIONS s_vbeln FOR vbak-vbeln .
SELECT-OPTIONS s_ernam FOR vbak-ernam .
SELECT-OPTIONS s_erdat FOR vbak-erdat .
PARAMETERS : cb_1 AS CHECKBOX DEFAULT 'X' .
PARAMETERS : cb_2 AS CHECKBOX .
DATA: BEGIN OF gs_vbap ,
vbeln LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
matnr LIKE vbap-matnr,
kwmeng LIKE vbap-kwmeng,
END OF gs_vbap .
DATA: gt_vbap LIKE TABLE OF gs_vbap .
SELECT a~vbeln b~posnr b~matnr b~kwmeng
INTO TABLE gt_vbap
FROM vbak AS a
JOIN vbap AS b ON a~vbeln = b~vbeln
WHERE a~vbeln IN s_vbeln
AND a~ernam IN s_ernam
AND a~erdat IN s_erdat
* AND gbstk EQ 'B' .
AND lfgsk EQ 'B' .
IF CB_2 EQ 'X'.
SELECT a~vbeln b~posnr b~matnr b~kwmeng
INTO TABLE gt_vbap
FROM vbak AS a
JOIN vbap AS b ON a~vbeln = b~vbeln
WHERE a~vbeln IN s_vbeln
AND a~ernam IN s_ernam
AND a~erdat IN s_erdat .
ENDIF .
DATA: BEGIN OF gs_lips,
matnr LIKE lips-matnr,
lfimg LIKE lips-lfimg,
vgbel LIKE lips-vgbel,
vgpos LIKE lips-vgpos,
END OF gs_lips.
DATA: gt_lips LIKE TABLE OF gs_lips .
IF gt_vbap IS NOT INITIAL .
SELECT matnr lfimg vgbel vgpos
INTO TABLE gt_lips
FROM lips
FOR ALL ENTRIES IN gt_vbap
WHERE vgbel = gt_vbap-vbeln
AND vgpos = gt_vbap-posnr .
ENDIF .
DATA: BEGIN OF ls_lips ,
matnr LIKE lips-matnr,
lfimg LIKE lips-lfimg,
vgbel LIKE lips-vgbel,
vgpos TYPE c LENGTH 6,
END OF ls_lips .
DATA: lt_lips LIKE TABLE OF ls_lips .
LOOP AT gt_lips INTO gs_lips .
ls_lips-matnr = gs_lips-matnr .
ls_lips-lfimg = gs_lips-lfimg .
ls_lips-vgbel = gs_lips-vgbel.
ls_lips-vgpos = gs_lips-vgpos.
COLLECT ls_lips INTO lt_lips .
CLEAR gs_lips .
ENDLOOP .
DATA: BEGIN OF gs_out,
matnr LIKE lips-matnr,
lfimg LIKE lips-lfimg,
vgbel LIKE lips-vgbel,
vgpos TYPE c LENGTH 6,
kwmeng LIKE vbap-kwmeng, "訂單數量
ernam LIKE vbak-ernam,
erdat LIKE vbak-erdat,
vtweg LIKE vbak-vtweg, "渠道
maktx LIKE makt-maktx,
light(4),
END OF gs_out .
DATA: gt_out LIKE TABLE OF gs_out .
SORT lt_lips BY vgbel vgpos .
LOOP AT gt_vbap INTO gs_vbap .
gs_out-matnr = gs_vbap-matnr.
gs_out-vgbel = gs_vbap-vbeln.
gs_out-vgpos = gs_vbap-posnr.
gs_out-kwmeng = gs_vbap-kwmeng.
CLEAR ls_lips .
READ TABLE lt_lips INTO ls_lips WITH KEY vgbel = gs_vbap-vbeln
vgpos = gs_vbap-posnr
BINARY SEARCH .
IF sy-subrc EQ 0 .
gs_out-lfimg = ls_lips-lfimg.
ELSE .
IF cb_2 EQ 'X'.
gs_out-lfimg = 0 .
ENDIF .
ENDIF.
IF gs_out-lfimg <> gs_out-kwmeng .
gs_out-light = '@
ELSE .
gs_out-light = '@[email protected]'.
ENDIF .
SELECT SINGLE ernam erdat vtweg INTO (gs_out-ernam,gs_out-erdat, gs_out-vtweg)
FROM vbak
WHERE vbeln = gs_out-vgbel.
SELECT SINGLE maktx INTO gs_out-maktx
FROM makt
WHERE matnr = gs_out-matnr .
IF cb_1 EQ 'X'.
IF gs_out-light EQ '@
APPEND gs_out TO gt_out .
ENDIF .
ELSE .
APPEND gs_out TO gt_out .
ENDIF .
CLEAR gs_out .
ENDLOOP .
SORT gt_out BY vgbel vgpos.
DEFINE append_field.
gs_fieldcat-fieldname = &1.
gs_fieldcat-seltext_l = &2.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR: gs_fieldcat.
END-OF-DEFINITION.
append_field: 'LIGHT' '指示燈' .
append_field: 'VGBEL' '訂單號' .
append_field: 'ERDAT' '建立日期' .
append_field: 'ERNAM' '建立人' .
append_field: 'VTWEG' '渠道' .
append_field: 'VGPOS' '行專案' .
append_field: 'MATNR' '物料' .
append_field: 'MAKTX' '物料描述' .
append_field: 'KWMENG' '訂單數量' .
append_field: 'LFIMG' '交貨單數量' .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
* i_callback_pf_status_set = 'FRM_STATUS_SET3'
* i_callback_user_command = 'FRM_USER_COMMAND3'
*
* I_GRID_SETTINGS =
is_layout = gs_layout
it_fieldcat = gt_fieldcat
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = gt_out[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.