REPORT zkscmm0001_ltt5 MESSAGE-ID z0h .
TABLES : ekko,ekpo,eket.
TYPE-POOLS slis.
DATA:
gt_fieldcat TYPE slis_t_fieldcat_alv,
gs_fieldcat TYPE slis_fieldcat_alv,
gs_layout TYPE slis_layout_alv,
gv_col TYPE i .
DATA gt_event TYPE slis_t_event. "イベント変数宣言
DATA gs_event TYPE slis_alv_event.
TYPES : BEGIN OF ty_data, "gts类型定义gdt gds
ebeln TYPE ekko-ebeln ,
lifnr TYPE ekko-lifnr ,
matnr TYPE ekpo-matnr ,
menge TYPE ekpo-menge ,
meins TYPE ekpo-meins ,
ebelp TYPE ekpo-ebelp ,
werks TYPE ekpo-werks ,
name1 TYPE adrc-name1 ,
maktx TYPE makt-maktx ,
checkbox TYPE c LENGTH 1, "選択欄追加
END OF ty_data.
DATA : gt_data TYPE TABLE OF ty_data,
gs_data TYPE ty_data.
*---------------データバックアップ始まり-----------
TYPES : BEGIN OF ty_databackup, "gts类型定义gdt gds
ebeln TYPE ekko-ebeln ,
lifnr TYPE ekko-lifnr ,
matnr TYPE ekpo-matnr ,
menge TYPE ekpo-menge ,
meins TYPE ekpo-meins ,
ebelp TYPE ekpo-ebelp ,
werks TYPE ekpo-werks ,
name1 TYPE adrc-name1 ,
maktx TYPE makt-maktx ,
checkbox TYPE c LENGTH 1 ,
END OF ty_databackup.
DATA : gt_databackup TYPE TABLE OF ty_databackup,
gs_databackup TYPE ty_databackup.
*---------------データバックアップ終わり-----------
*&&----------------------------------------------------------&&*
* *
*&&----------------------------------------------------------&&*
TYPES : BEGIN OF ty_lfa1,
adrnr TYPE lfa1-adrnr ,
lifnr TYPE lfa1-lifnr ,
name1 TYPE adrc-name1 ,
END OF ty_lfa1.
DATA : gt_lfa1 TYPE TABLE OF ty_lfa1,
gs_lfa1 TYPE ty_lfa1.
*&&----------------------------------------------------------&&*
* *
*&&----------------------------------------------------------&&*
TYPES : BEGIN OF ty_adrc,
name1 TYPE adrc-name1 ,
addrnumber TYPE adrc-addrnumber ,
END OF ty_adrc.
DATA : gt_adrc TYPE TABLE OF ty_adrc,
gs_adrc TYPE ty_adrc.
*&&----------------------------------------------------------&&*
* *
*&&----------------------------------------------------------&&*
TYPES : BEGIN OF ty_makt,
maktx TYPE makt-maktx ,
matnr TYPE makt-matnr ,
END OF ty_makt.
DATA : gt_makt TYPE TABLE OF ty_makt,
gs_makt TYPE ty_makt.
*&&----------------------------------------------------------&&*
* *
*&&----------------------------------------------------------&&*
TYPES : BEGIN OF ty_t024e,
ekotx TYPE t024e-ekotx ,
ekorg TYPE t024e-ekorg ,
END OF ty_t024e.
DATA : gt_t024e TYPE TABLE OF ty_t024e,
gs_t024e TYPE ty_t024e.
*&&----------------------------------------------------------&&*
* *
*&&----------------------------------------------------------&&*
DATA: g_grid TYPE REF TO cl_gui_alv_grid.
DATA lt_return TYPE TABLE OF bapiret2.
DATA ls_return TYPE bapiret2.
DATA lt_item TYPE STANDARD TABLE OF bapimepoitem.
DATA ls_item TYPE bapimepoitem.
DATA lt_itemx TYPE STANDARD TABLE OF bapimepoitemx."必须kaiguan
DATA ls_itemx TYPE bapimepoitemx.
DATA g_return TYPE c.
SELECTION-SCREEN BEGIN OF BLOCK bk1 WITH FRAME TITLE text-001.
PARAMETERS : po_ekorg TYPE ekko-ekorg OBLIGATORY MEMORY ID eko. " Purchasing organization
SELECT-OPTIONS: so_bedat FOR ekko-bedat . " Date of purchase document
SELECT-OPTIONS: so_ekgrp FOR ekko-ekgrp. " Purchasing Group
SELECT-OPTIONS: so_lifnr FOR ekko-lifnr. " supplier
SELECT-OPTIONS: so_ebeln FOR ekko-ebeln. " Purchase document number
SELECT-OPTIONS: so_matnr FOR ekpo-matnr. " Item code
SELECT-OPTIONS: so_werks FOR ekpo-werks. " plant
SELECTION-SCREEN END OF BLOCK bk1.
AT SELECTION-SCREEN.
PERFORM frm_check_ekorg.
START-OF-SELECTION.
PERFORM frm_set_data.
PERFORM frm_display_alc.
*&---------------------------------------------------------------------*
*& Form FRM_CHECK_EKORG
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_check_ekorg .
SELECT ekotx
ekorg
FROM t024e
INTO TABLE gt_t024e
WHERE ekorg = po_ekorg.
IF sy-subrc = 0.
ELSE.
MESSAGE s001(z0h) WITH po_ekorg .
ENDIF.
ENDFORM. "frm_check_ekorg
*&---------------------------------------------------------------------*
*& Form FRM_SET_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_set_data .
SELECT
ekko~ebeln
ekko~lifnr
ekpo~matnr
ekpo~menge
ekpo~meins
ekpo~ebelp
ekpo~werks
FROM ekko
INNER JOIN ekpo
ON ekko~ebeln = ekpo~ebeln
INNER JOIN eket
ON ekpo~ebeln = eket~ebeln
AND ekpo~ebelp = eket~ebelp
INTO TABLE gt_data
WHERE ekko~ekorg = po_ekorg
AND ekko~bedat IN so_bedat
AND ekko~ekgrp IN so_ekgrp
AND ekko~lifnr IN so_lifnr
AND ekko~ebeln IN so_ebeln
AND ekpo~matnr IN so_matnr
AND ekpo~werks IN so_werks.
IF sy-subrc = 0.
SORT gt_data
BY lifnr.
ELSE.
* MESSAGE '対象データが存在しません' TYPE 'S' DISPLAY LIKE 'E' .
MESSAGE s002(z0h) DISPLAY LIKE 'E' .
LEAVE LIST-PROCESSING. "選択画面に戻る
ENDIF.
******アドレス番号の取得*******
SELECT adrnr
lifnr
FROM lfa1
INTO TABLE gt_lfa1
FOR ALL ENTRIES IN gt_data
WHERE lifnr = gt_data-lifnr.
IF sy-subrc = 0.
ELSE.
ENDIF.
********仕入先名称の取得**********
SELECT name1
addrnumber
FROM adrc
INTO TABLE gt_adrc
FOR ALL ENTRIES IN gt_lfa1
WHERE addrnumber = gt_lfa1-adrnr
AND date_from = '00010101'
AND nation = space.
IF sy-subrc = 0.
ELSE.
ENDIF.
********品目テキストの取得**********
SELECT maktx
matnr
FROM makt
INTO TABLE gt_makt
FOR ALL ENTRIES IN gt_data
WHERE matnr = gt_data-matnr
AND spras = sy-langu.
LOOP AT gt_lfa1 INTO gs_lfa1.
READ TABLE gt_adrc INTO gs_adrc WITH KEY addrnumber = gs_lfa1-adrnr.
IF sy-subrc = 0 .
gs_lfa1-name1 = gs_adrc-name1.
MODIFY gt_lfa1 FROM gs_lfa1.
ELSE.
ENDIF.
ENDLOOP.
LOOP AT gt_data INTO gs_data.
* CLEAR gs_lfa1-name1.防止覆盖值出错
READ TABLE gt_lfa1 INTO gs_lfa1 WITH KEY lifnr = gs_data-lifnr.
IF sy-subrc = 0.
gs_data-name1 = gs_lfa1-name1.
ELSE.
ENDIF.
READ TABLE gt_makt INTO gs_makt WITH KEY matnr = gs_data-matnr.
IF sy-subrc = 0.
gs_data-maktx = gs_makt-maktx.
ELSE.
ENDIF.
MODIFY gt_data FROM gs_data.
ENDLOOP.
gt_databackup = gt_data. "データフィードバック実現
ENDFORM. "frm_set_data
*&---------------------------------------------------------------------*
*& Form FRM_DISPLAY_ALC
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_display_alc .
PERFORM frm_init_fieldcat.
PERFORM frm_init_layout.
PERFORM build_events.
PERFORM frm_init_alv.
ENDFORM. "frm_display_alc
*& Form FRM_INIT_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_init_fieldcat .
PERFORM frm_set_fieldcat USING 'EBELN' '購買伝票' '' .
PERFORM frm_set_fieldcat USING 'EBELP' '明細 ' '' .
PERFORM frm_set_fieldcat USING 'MATNR' '品目コード ' '' .
PERFORM frm_set_fieldcat USING 'MAKTX' '品目テキスト ' '' .
PERFORM frm_set_fieldcat USING 'MENGE' '購買発注数数量 ' 'X' .
PERFORM frm_set_fieldcat USING 'MEINS' '発注単位 ' '' .
PERFORM frm_set_fieldcat USING 'LIFNR' '仕入先 ' '' .
PERFORM frm_set_fieldcat USING 'NAME1' '名称 ' '' .
PERFORM frm_set_fieldcat USING 'WERKS' 'Plnt ' '' .
ENDFORM. " FRM_INIT_FIELDCAT
*&---------------------------------------------------------------------*
*& Form FRM_SET_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
FORM frm_set_fieldcat USING p_field p_name p_edit ."p_rtable p_rfield.
gs_fieldcat-col_pos = gv_col. "列
gs_fieldcat-fieldname = p_field. "字段名
IF p_field = 'MENGE'.
***********ここで画面の数字表示問題を解決************
gs_fieldcat-qfieldname = 'MEINS'.
gs_fieldcat-qtabname = 'EKPO'.
gs_fieldcat-ref_fieldname = 'MENGE'.
gs_fieldcat-ref_tabname = 'EKPO'.
*******************************************************
ENDIF.
gs_fieldcat-seltext_m = p_name.
gs_fieldcat-edit = p_edit. "是否可编辑
gs_fieldcat-outputlen = 16. "设定输出的长度
APPEND gs_fieldcat TO gt_fieldcat.
gv_col = gv_col + 1.
CLEAR gs_fieldcat.
ENDFORM. " FRM_SET_FIELDCAT
*&---------------------------------------------------------------------*
*& Form FRM_INIT_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_init_layout .
gs_layout-zebra = 'X'. "斑马线效果输出
gs_layout-colwidth_optimize = 'X'.
gs_layout-box_fieldname = 'CHECKBOX'.
gs_layout-box_tabname = 'gt_data'.
gs_layout-key_hotspot = 'X'.
ENDFORM. " FRM_INIT_LAYOUT
*&---------------------------------------------------------------------*
*& Form FRM_INIT_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_init_alv .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-cprog
i_callback_top_of_page = 'FM_TOP_OF_PAGE '
is_layout = gs_layout
it_fieldcat = gt_fieldcat
it_events = gt_event
TABLES
t_outtab = gt_data
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE s005(z0h) DISPLAY LIKE 'E' .
ENDIF.
ENDFORM. " FRM_INIT_ALV
*------------------イベント宣言定義-----
FORM build_events.
CLEAR gs_event.
gs_event-name = 'PF_STATUS_SET'.
gs_event-form = 'SET_STATUS'.
APPEND gs_event TO gt_event.
CLEAR gs_event.
gs_event-name = 'USER_COMMAND'.
gs_event-form = 'FM_USER_COMMAND'.
APPEND gs_event TO gt_event.
CLEAR gs_event.
gs_event-name = 'TOP_OF_PAGE'.
gs_event-form = 'FM_TOP_OF_PAGE'.
APPEND gs_event TO gt_event.
ENDFORM.
FORM set_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'STATUS' EXCLUDING rt_extab.
ENDFORM.
"光标的位置行
FORM fm_user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = g_grid.
CALL METHOD g_grid->check_changed_data.
CALL METHOD g_grid->refresh_table_display.
CASE r_ucomm.
WHEN '&IC1'. "单击事件必须提前设定好热点,单击和双击都是一个码
* CASE rs_selfield-fieldname.
* when 'MATNR'. "网上实现品目的跳转
* set PARAMETER ID 'LIF' FIELD RS_SELFIELD-VALUE.
* call transaction 'ME23N'.
*
* ENDCASE.
READ TABLE gt_data INTO gs_data INDEX rs_selfield-tabindex.
CALL FUNCTION 'ME_DISPLAY_PURCHASE_DOCUMENT'
EXPORTING
i_ebeln = gs_data-ebeln.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'EXIT'OR 'CANCEL'.
LEAVE PROGRAM.
WHEN 'RENEW'.
PERFORM use_bapi.
ENDCASE.
ENDFORM.
FORM fm_top_of_page.
DATA: text1 TYPE string,
text2 TYPE string,
text3 TYPE string.
CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL' "日期格式修改
EXPORTING
date_internal = sy-datum
IMPORTING
date_external = text2 "根据用户日期格式参数输出:YYYY.MM.DD
EXCEPTIONS
date_internal_is_invalid = 1
OTHERS = 2.
text1 = '作成日:'.
text3 = text1 && text2.
DATA: text4 TYPE string,
text5 TYPE string,
text6 TYPE string.
text4 = '作成時刻:'.
text5 = sy-uzeit.
text6 = text4 && text5.
*时间的格式输出成hh:mm:ss还没有完成
DATA: text7 TYPE string,
text8 TYPE string,
text9 TYPE string.
text7 = '購買組織:'.
text8 = po_ekorg.
text9 = text7 && text8.
DATA: text10 TYPE string.
LOOP AT gt_t024e INTO gs_t024e.
IF sy-subrc = 0.
text10 = gs_t024e-ekotx.
ENDIF.
ENDLOOP.
DATA lt_header TYPE slis_t_listheader.
DATA ls_header TYPE slis_listheader.
CLEAR ls_header.
ls_header-typ = 'H'.
* LS_HEADER-KEY = 可不填
ls_header-info = '購買発注数量一括更新'.
APPEND ls_header TO lt_header.
CLEAR ls_header.
ls_header-typ = 'S'.
ls_header-key = '購買組織'.
ls_header-info = text9.
APPEND ls_header TO lt_header.
CLEAR ls_header. "格式跟图片不符
ls_header-typ = 'S'.
ls_header-key = space.
ls_header-info = text10.
APPEND ls_header TO lt_header.
CLEAR ls_header.
ls_header-typ = 'S'.
ls_header-key = '作成日'.
ls_header-info = text3.
APPEND ls_header TO lt_header.
CLEAR ls_header.
ls_header-typ = 'S'.
ls_header-key = '作成時刻'.
ls_header-info = text6.
APPEND ls_header TO lt_header.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = lt_header.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_DOUBLECLICK
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM use_bapi.
DATA ls_purchaseorder TYPE bapimepoheader.
DATA ld_return TYPE bapiret2 .
DATA lv_cont TYPE i.
*****選択された条数判断追加*********
LOOP AT gt_data INTO gs_data WHERE checkbox = 'X'.
lv_cont = lv_cont + 1.
ENDLOOP.
IF lv_cont = 0.
MESSAGE s005(z0h).
ELSEIF lv_cont > 100.
MESSAGE s006(z0h).
ENDIF.
***********選択された条数判断追加終わり********************************
*********確認画面をパップアップ***************
CALL FUNCTION 'POPUP_TO_CONFIRM' "弹窗
EXPORTING
titlebar = '購買発注数量更新確認 '
text_question = '購買発注数量の更新を行います。継続しますか?'
text_button_1 = 'はい'
text_button_2 = 'いいえ'
default_button = '1'
display_cancel_button = 'X'
IMPORTING
answer = g_return "リターンコード
EXCEPTIONS
text_not_found = 1
OTHERS = 2.
IF g_return <> 1.
* MESSAGE s010(z0h) DISPLAY LIKE ' E'.
ELSE.
CLEAR gs_data.
LOOP AT gt_data INTO gs_data WHERE checkbox = 'X'.
ls_purchaseorder-po_number = gs_data-ebeln. "購買伝票
ls_item-po_item = gs_data-ebelp. "明細
ls_item-quantity = gs_data-menge. "購買発注数数量
ls_itemx-po_item = gs_data-ebelp. "明細
ls_itemx-quantity = 'X'.
APPEND ls_item TO lt_item.
APPEND ls_itemx TO lt_itemx.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = g_grid.
CALL METHOD g_grid->check_changed_data.
CALL METHOD g_grid->refresh_table_display.
******************前と後ろの更新するかどうか判断*******************
LOOP AT gt_databackup INTO gs_databackup WHERE ebelp = ls_item-po_item
AND ebeln = ls_purchaseorder-po_number
AND menge = ls_item-quantity.
ENDLOOP.
IF sy-subrc = 0.
LEAVE LIST-PROCESSING.
MESSAGE s008(z0h).
******************前と後ろのデータが違い、後で更新操作続きます*******************
ELSE.
CALL FUNCTION 'BAPI_PO_CHANGE'
EXPORTING
purchaseorder = ls_purchaseorder-po_number
TABLES
return = lt_return
poitem = lt_item
poitemx = lt_itemx.
*********メッセージ書き込み *********
IF sy-subrc <> 0.
MESSAGE s004(z0h).
ENDIF.
*********メッセージ書き込み 終わり*********
* READ TABLE gt_return into gs_return.
LOOP AT lt_return INTO ls_return .
IF ls_return-type = 'E' OR ls_return-type = 'A' .
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
IMPORTING
return = ld_return. " BAPI_TRANSACTION_ROLLBACK
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
COMMIT WORK AND WAIT.
* IF sy-subrc = 0.
* MESSAGE s003(z0h).
*
* ENDIF.
ENDIF.
ENDLOOP.
ENDIF.
ENDLOOP.
ENDIF.
ENDFORM . "FRM_UCOMM