nangnangchuai / sap

0 stars 0 forks source link

代码备份 #28

Open nangnangchuai opened 5 years ago

nangnangchuai commented 5 years ago
`*&---------------------------------------------------------------------*
*& Report  ZKSCMM0001_LTT4
*&
*&---------------------------------------------------------------------*
*&alvとbapi一括更新実現
*&
*&---------------------------------------------------------------------*

REPORT  ZKSCMM0001_LTT4 MESSAGE-ID z0h.

TABLES: ekko,ekpo,eket.
TYPE-POOLS slis.

TYPES:
  BEGIN OF gts_data ,
    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 ,     " Plnt
    name1                              TYPE      adrc-name1 ,     " 名称
    maktx                              TYPE      makt-maktx ,     " 品目テキスト
    checkbox                           TYPE      c          ,     "選択ボックス
  END OF gts_data ,

  BEGIN OF gts_lfa1,                                             "仕入先マスタ"
    adrnr                              TYPE      lfa1-adrnr ,     "住所番号
    lifnr                              TYPE      lfa1-lifnr ,     "仕入先または債権者の勘定コード
    name1                              TYPE      adrc-name1 ,     "名称
  END OF gts_lfa1,

  BEGIN OF gts_adrc,
    name1                              TYPE      adrc-name1 ,    "名称
    addrnumber                         TYPE      adrc-addrnumber,"アドレス番号
  END OF gts_adrc,

  BEGIN OF gts_makt,
    maktx                              TYPE      makt-maktx ,    "品目テキスト
    matnr                              TYPE      makt-matnr ,    "品目コード
   END OF gts_makt,

  BEGIN OF gts_t024e,
    ekotx                              TYPE      t024e-ekotx ,   "購買組織テキスト
    ekorg                              TYPE      t024e-ekorg ,   "購買組織
  END OF gts_t024e.

DATA:
  gdt_fieldcat                         TYPE      slis_t_fieldcat_alv ,
  gds_fieldcat                         TYPE      slis_fieldcat_alv ,
  gds_layout                           TYPE      slis_layout_alv ,
*******alv eventで使用された設定値の定義***********************
  gdt_event                            TYPE      slis_t_event,
  gds_event                            TYPE      slis_alv_event,
********alv展示画面で使用されたデータの定義********************
  gdt_all                              TYPE TABLE OF gts_data ,
  gds_all                              TYPE      gts_data ,
********データバンク為に、 gdt_allと同じ構造データの定義********
  gdt_allbackup                        TYPE TABLE OF gts_data ,
  gds_allbackup                        TYPE          gts_data ,
***********仕入先マスタ(lfa1)の定義*****************************
  gdt_lfa1                             TYPE TABLE OF gts_lfa1 ,
  gds_lfa1                             TYPE       gts_lfa1 ,
**********アドレス(adrc)の定義**********************************
  gdt_adrc                             TYPE TABLE OF gts_adrc ,
  gds_adrc                             TYPE          gts_adrc ,
***********品目テキスト(makt)の定義*****************************
  gdt_makt                             TYPE TABLE OF gts_makt ,
  gds_makt                             TYPE          gts_makt ,
***********購買組織 (T024E)の定義*******************************
  gdt_t024e                            TYPE TABLE OF gts_t024e ,
  gds_t024e                            TYPE          gts_t024e ,
**********BAPIで使用されたデータの定義**************************
  gdf_grid                             TYPE REF TO            cl_gui_alv_grid ,
  gdt_item                             TYPE STANDARD TABLE OF bapimepoitem ,
  gds_item                             TYPE                   bapimepoitem ,
  gdt_xitemx                           TYPE STANDARD TABLE OF bapimepoitemx ,
  gds_xitemx                           TYPE                   bapimepoitemx ,
  gdf_ponumber                         TYPE                   bapimepoheader .

SELECTION-SCREEN BEGIN OF BLOCK bk1 WITH FRAME TITLE text-001.

PARAMETERS    : po_ekorg               TYPE      ekko-ekorg OBLIGATORY MEMORY ID eko.       " 購買組織
SELECT-OPTIONS: so_bedat               FOR       ekko-bedat,                                " 購買伝票日付
                so_ekgrp               FOR       ekko-ekgrp,                                " 購買グループ
                so_lifnr               FOR       ekko-lifnr,                                " 仕入先
                so_ebeln               FOR       ekko-ebeln,                                " 購買伝票番号
                so_matnr               FOR       ekpo-matnr,                                " 品目コード
                so_werks               FOR       ekpo-werks.                                " プラント

SELECTION-SCREEN END OF BLOCK bk1.

AT SELECTION-SCREEN.

  PERFORM frm_check_ekorg.                                                                   "購買組織 入力値存在チェック

START-OF-SELECTION.

  PERFORM frm_set_data.                                                                      "購買発注データ取得
  PERFORM frm_alv.                                                                           "購買発注伝票一覧及び更新画面出力

*&---------------------------------------------------------------------*
*& Form FRM_CHECK_EKORG
*&---------------------------------------------------------------------*
*&    購買組織 入力値存在チェック
*&---------------------------------------------------------------------*
FORM frm_check_ekorg .

  SELECT ekotx               "購買組織テキスト
         ekorg               "購買組織
    FROM t024e
    INTO TABLE gdt_t024e
    WHERE ekorg = po_ekorg.

  IF sy-subrc <> 0.
    MESSAGE e001(z0h) WITH po_ekorg .
  ENDIF.

ENDFORM.                    "frm_check_ekorg
*&---------------------------------------------------------------------*
*& Form FRM_SET_DATA
*&---------------------------------------------------------------------*
*&    購買発注データ取得
*&---------------------------------------------------------------------*
FORM frm_set_data .

*********************購買発注データの取得*******************************
  SELECT
      ekko~ebeln                              "購買伝票番号
      ekko~lifnr                              "仕入先
      ekpo~matnr                              "品目コード
      ekpo~menge                              "購買発注数量
      ekpo~meins                              "発注単位
      ekpo~ebelp                              "購買伝票の明細番号
      ekpo~werks                              "プラント
    FROM ekko                                 "購買伝票ヘッダ ekko
    INNER JOIN ekpo                           "購買伝票明細 ekpo
    ON            ekko~ebeln  = ekpo~ebeln
    INNER JOIN eket
    ON            ekpo~ebeln  = eket~ebeln    "分納契約納入日程行eket
    AND           ekpo~ebelp  = eket~ebelp
    INTO TABLE gdt_all
    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.
    MESSAGE e002(z0h).
  ELSE.
    SORT gdt_all BY ebeln.
  ENDIF.

**********************アドレス番号の取得************************

DATA: ldt_temp LIKE gdt_all.

  CHECK gdt_all IS NOT INITIAL.
  ldt_temp = gdt_all.
  SORT ldt_temp BY lifnr.
  DELETE ADJACENT DUPLICATES FROM ldt_temp COMPARING lifnr.

  SELECT adrnr                             "住所
         lifnr                             "仕入先または債権者の勘定コード
    FROM lfa1                              "仕入先マスタ  LFA1
    INTO TABLE gdt_lfa1
    FOR ALL ENTRIES IN ldt_temp
    WHERE lifnr =  ldt_temp-lifnr.

  IF sy-subrc = 0.
      SORT gdt_adrc BY addrnumber ASCENDING.
  ELSE.
  ENDIF.

********************仕入先名称の取得****************

DATA: ldt_lfa1_temp LIKE gdt_lfa1.

  CHECK gdt_lfa1 IS NOT INITIAL.
  ldt_lfa1_temp = gdt_lfa1.
  SORT ldt_lfa1_temp BY lifnr.
  DELETE ADJACENT DUPLICATES FROM ldt_lfa1_temp COMPARING adrnr.

  SELECT name1                            "名称
         addrnumber                       "アドレス番号
    FROM adrc                             "住所
    INTO TABLE gdt_adrc
    FOR ALL ENTRIES IN ldt_lfa1_temp
    WHERE addrnumber = ldt_lfa1_temp-adrnr "アドレス番号
    AND   date_from  = '00010101'          "有効開始日付
    AND   nation     = space.              "国際アドレスのバージョン ID

  IF sy-subrc = 0.
    SORT gdt_adrc BY addrnumber ASCENDING.
  ELSE.
  ENDIF.

****************品目テキストの取得**************************

DATA: ldt_makt_temp LIKE gdt_all.

  CHECK gdt_makt IS NOT INITIAL.
  ldt_makt_temp = gdt_all.
  SORT ldt_makt_temp BY matnr.
  DELETE ADJACENT DUPLICATES FROM ldt_makt_temp COMPARING matnr.

  SELECT maktx                            "品目テキスト
         matnr                            "品目コード
    FROM makt
    INTO TABLE gdt_makt
    FOR ALL ENTRIES IN  ldt_makt_temp
    WHERE matnr =  ldt_makt_temp-matnr
    AND   spras = sy-langu.

  IF sy-subrc = 0.
    SORT gdt_makt BY matnr.
  ELSE.
  ENDIF.

*******  仕入先マスタ とアドレス(ADRC)から 仕入先名称取得****************

  LOOP AT gdt_lfa1 INTO gds_lfa1.
    READ TABLE gdt_adrc INTO gds_adrc WITH KEY addrnumber = gds_lfa1-adrnr BINARY SEARCH.
    IF sy-subrc = 0 .
      gds_lfa1-name1 = gds_adrc-name1.
      MODIFY gdt_lfa1 FROM gds_lfa1.
    ELSE.
    ENDIF.
  ENDLOOP.

  LOOP AT gdt_all INTO gds_all.
*****************************最後のデータに仕入先名称を追加******************************************
    READ TABLE gdt_lfa1 INTO gds_lfa1 WITH KEY lifnr = gds_all-lifnr BINARY SEARCH.
    IF sy-subrc = 0.
      gds_all-name1 = gds_lfa1-name1.

    ELSE.
    ENDIF.
*   **************************最後のデータに品目テキストを追加************************
    READ TABLE gdt_makt INTO gds_makt WITH KEY matnr = gds_all-matnr BINARY SEARCH.
    IF sy-subrc = 0.
      gds_all-maktx = gds_makt-maktx.
    ELSE.
    ENDIF.
    MODIFY gdt_all FROM gds_all.
  ENDLOOP.

  gdt_allbackup = gdt_all.                               "データフィードバック実現

ENDFORM.                    "frm_set_data
*&---------------------------------------------------------------------*
*& Form frm_alv
*&---------------------------------------------------------------------*
*&     ALVを利用して購買発注伝票一覧
*&---------------------------------------------------------------------*
FORM frm_alv .

  PERFORM frm_fieldcat.                            "フィールドカタログの作成
  PERFORM frm_layout.
  PERFORM frm_events.
  PERFORM frm_alv_display.

ENDFORM.                    "frm_alv
*&---------------------------------------------------------------------*
*&      Form  FRM_FIELDCAT
*&---------------------------------------------------------------------*
*       ALVフィールドカタログでフィールド名前設定
*----------------------------------------------------------------------*
FORM frm_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' 'MEINS' 'EKPO' 'MENGE' 'EKPO'.
  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_fieldcat

*&---------------------------------------------------------------------*
*&      form  frm_set_fieldcat
*&---------------------------------------------------------------------*
*       ALVフィールドカタログの作成
*----------------------------------------------------------------------*
FORM frm_set_fieldcat  USING p_field                "フィールド名前
                             p_name                 "出力フィールドテキスト
                             p_edit                 "編集可能設定値
                             p_qfield               "フィールド
                             p_qtablename           "テーブル名前
                             p_ref_field           "参照フィールド名前
                             p_ref_tablename.      "参照テーブル名前
  DATA: ldf_col TYPE i.                            "例の位置設定値

  gds_fieldcat-col_pos          = ldf_col.
  gds_fieldcat-fieldname        = p_field.
  gds_fieldcat-seltext_m        = p_name.
  gds_fieldcat-edit             = p_edit.
  gds_fieldcat-outputlen        = 16.
  gds_fieldcat-qfieldname       = p_qfield.
  gds_fieldcat-qtabname         = p_qtablename.
  gds_fieldcat-ref_fieldname    = p_ref_field.
  gds_fieldcat-ref_tabname      = p_ref_tablename.

  APPEND gds_fieldcat TO gdt_fieldcat.
  ldf_col = ldf_col + 1.
  CLEAR gds_fieldcat.

ENDFORM.                    " FRM_SET_FIELDCAT

*&---------------------------------------------------------------------*
*&      Form  FRM_LAYOUT
*&---------------------------------------------------------------------*
*        ALV展示画面様子の設定
*----------------------------------------------------------------------*
FORM frm_layout .

  gds_layout-zebra = 'X'.
  gds_layout-colwidth_optimize = 'X'.
  gds_layout-box_fieldname = 'CHECKBOX'.
  gds_layout-box_tabname = 'gdt_all'.
  gds_layout-key_hotspot = 'X'.

ENDFORM.                    " frm_layout
*&---------------------------------------------------------------------*
*&      Form  FRM_ALV_DISPLAY
*&---------------------------------------------------------------------*
*       ALV 明細の出力
*----------------------------------------------------------------------*
FORM frm_alv_display .

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program     = sy-cprog
      i_callback_top_of_page = 'frm_top_of_page '
      is_layout              = gds_layout
      it_fieldcat            = gdt_fieldcat
      it_events              = gdt_event
    TABLES
      t_outtab               = gdt_all
    EXCEPTIONS
      program_error          = 1
      OTHERS                 = 2.
  IF sy-subrc <> 0.
    MESSAGE s005(z0h) DISPLAY LIKE 'E' .
  ENDIF.

ENDFORM.                    " frm_alv_display
*&---------------------------------------------------------------------*
*&      Form  frm_events
*&---------------------------------------------------------------------*
*       ユーザー動作とalvイベント設定
*----------------------------------------------------------------------*
FORM frm_events.
  CLEAR gds_event.
  gds_event-name = 'PF_STATUS_SET'.
  gds_event-form = 'SET_STATUS'.
  APPEND gds_event TO gdt_event.

  CLEAR gds_event.
  gds_event-name = 'USER_COMMAND'.
  gds_event-form = 'FRM_USER_COMMAND'.
  APPEND gds_event TO gdt_event.

  CLEAR gds_event.
  gds_event-name = 'TOP_OF_PAGE'.
  gds_event-form = 'FRM_TOP_OF_PAGE'.
  APPEND gds_event TO gdt_event.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  SET_STATUS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM set_status USING rt_extab TYPE slis_t_extab.

  SET PF-STATUS  'STATUS'  EXCLUDING rt_extab.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_USER_COMMAND
*&---------------------------------------------------------------------*
*        購買伝票更新
*----------------------------------------------------------------------*
FORM frm_user_command USING r_ucomm    LIKE sy-ucomm
                      rs_selfield TYPE slis_selfield.

***************リフレッシュalv画面(ALV oo )***************************
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      e_grid = gdf_grid.
  CALL METHOD gdf_grid->check_changed_data.           "変更されたデータは内テーブルに更新する
  CALL METHOD gdf_grid->refresh_table_display.        "リフレッシュalv画面は、alv画面に値を再設定する.
***************選択行をダブルクリック時、該当の購買発注の照会画面に遷移する。***
  CASE r_ucomm.
    WHEN '&IC1'.
      READ TABLE gdt_all INTO gds_all INDEX rs_selfield-tabindex.
      CALL FUNCTION 'ME_DISPLAY_PURCHASE_DOCUMENT'
        EXPORTING
          i_ebeln = gds_all-ebeln.
*************バーコード設定************************************************
    WHEN 'BACK'.
      LEAVE TO SCREEN 0.
    WHEN 'EXIT'OR 'CANCEL'.
      LEAVE PROGRAM.
    WHEN 'RENEW'.                                      "更新バタンをクリックする。
      PERFORM  use_bapi.
  ENDCASE.

  rs_selfield = 'X'.                                    "grid alv リフレッシュ

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_TOP_OF_PAGE
*&---------------------------------------------------------------------*
*       ALVヘッダの出力
*----------------------------------------------------------------------*
FORM frm_top_of_page.

  DATA: text1                          TYPE string,                 "作成日
        text2                          TYPE string,                 "作成時刻
        text3                          TYPE string,                 "購買組織
        text4                          TYPE string,                 "購買組織テキスト
        lt_header                      TYPE slis_t_listheader,
        ls_header                      TYPE slis_listheader.
************"出力時間表示設定**************
  CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
    EXPORTING
      date_internal                     = sy-datum
    IMPORTING
      date_external                     = text1
    EXCEPTIONS
      date_internal_is_invalid          = 1
      OTHERS                            = 2.

  text2 = sy-uzeit.
  text3 = po_ekorg.

  LOOP AT gdt_t024e INTO gds_t024e.
    IF sy-subrc = 0.
      text4 = gds_t024e-ekotx.
    ENDIF.
  ENDLOOP.

*  *************ALVヘッダデータ************************
  CLEAR ls_header.
  ls_header-typ = 'H'." H = Header, S = Selection, A = Action
  ls_header-key = space.
  ls_header-info = '購買発注数量一括更新'.
  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 = space.
  ls_header-info = text4.
  APPEND ls_header TO lt_header.

  CLEAR ls_header.
  ls_header-typ = 'S'.
  ls_header-key = '作成日'.
  ls_header-info = text1.
  APPEND ls_header TO lt_header.

  CLEAR ls_header.
  ls_header-typ = 'S'.
  ls_header-key = '作成時刻'.
  ls_header-info = text2.
  APPEND ls_header TO lt_header.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = lt_header.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV_DOUBLECLICK
*&---------------------------------------------------------------------*
*       同時に選択されたデータ条数について判断
*----------------------------------------------------------------------*
FORM use_bapi.

  DATA lv_cont TYPE i.
  LOOP AT  gdt_all INTO gds_all WHERE checkbox = 'X'.
    lv_cont = lv_cont + 1.
  ENDLOOP.

  IF lv_cont = 0.
    MESSAGE s005(z0h).
  ELSEIF lv_cont > 3.
    MESSAGE s006(z0h).
  ELSE.
    PERFORM frm_popoup.
  ENDIF.

ENDFORM .                    "FRM_UCOMM
*&---------------------------------------------------------------------*
*&      Form  FRM_POPOUP
*&---------------------------------------------------------------------*
*       ・ポップアップを表示し、更新処理を継続するかの確認を行う
*----------------------------------------------------------------------*
FORM frm_popoup .

  DATA:ldp_return  TYPE  c.
  CALL FUNCTION 'POPUP_TO_CONFIRM'
     EXPORTING
       titlebar              = '購買発注数量更新確認 '
       text_question         = '購買発注数量の更新を行います。継続しますか?'
       text_button_1         = 'はい'
       text_button_2         = 'いいえ'
       default_button        = '1'
       display_cancel_button = ''
     IMPORTING
       answer                = ldp_return  "リターンコード
     EXCEPTIONS
       text_not_found        = 1
       OTHERS                = 2.

  IF ldp_return <> 1.
    MESSAGE s009(z0h) DISPLAY LIKE '  E'.
  ELSE.
    CLEAR gds_all.
    LOOP AT  gdt_all INTO gds_all WHERE   checkbox = 'X'.
      gdf_ponumber-po_number = gds_all-ebeln.
      gds_item-po_item              = gds_all-ebelp.
      gds_item-quantity             = gds_all-menge.
      gds_xitemx-po_item            = gds_all-ebelp.
      gds_xitemx-quantity           = 'X'.
      APPEND  gds_item  TO gdt_item.        "明細データ
      APPEND  gds_xitemx TO gdt_xitemx.     "明細データ (変更ツールバー)

      CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
        IMPORTING
          e_grid = gdf_grid.          "alv可编辑字段同步到内表ALV List Viewer
      CALL METHOD gdf_grid->check_changed_data.
********************変更前の購買発注数量、一覧画面で変更された購買発注数量と比較する******
      LOOP AT gdt_allbackup INTO gds_allbackup WHERE ebelp = gds_item-po_item
                                                AND  ebeln = gdf_ponumber-po_number
                                                AND  menge = gds_item-quantity.
      ENDLOOP.

      IF sy-subrc = 0.
        LEAVE LIST-PROCESSING.
        MESSAGE e008(z0h).
      ELSE.
        PERFORM frm_bapi_change.
      ENDIF.
    ENDLOOP.
  ENDIF.
ENDFORM.                    " FRM_POPOUP
*&---------------------------------------------------------------------*
*&      Form  FRM_BAPI_CHANGE
*&---------------------------------------------------------------------*
*       BAPIを利用して複数のデータ更新実現
*----------------------------------------------------------------------*
FORM frm_bapi_change .

  DATA: ldf_return                     TYPE bapiret2,
        ldt_return                     TYPE TABLE OF bapiret2,
        lds_return                     TYPE bapiret2.

  CALL FUNCTION 'BAPI_PO_CHANGE'                    "購買発注変更
    EXPORTING
      purchaseorder = gdf_ponumber-po_number        "購買伝票番号
    TABLES
      return        = ldt_return                    "リターンパラメータ
      poitem        = gdt_item                      "明細データ
      poitemx       = gdt_xitemx.                   "明細データ (変更ツールバー)

   gdt_allbackup = gdt_all.

  LOOP AT ldt_return INTO lds_return .
    IF lds_return-type = 'E' OR  lds_return-type = 'A' .
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'         "更新失敗場合
        IMPORTING
          return = ldf_return.

      LOOP AT gdt_all INTO gds_all.                     "データバンクから前のデータが内テーブルに書き込む
       READ TABLE gdt_allbackup INTO gds_allbackup WITH KEY  ebeln = gds_all-ebeln
                                                             ebelp = gds_all-ebelp.
        gds_all-menge = gds_allbackup-menge        .
        MODIFY gdt_all FROM gds_all.
      ENDLOOP.

      CALL METHOD gdf_grid->refresh_table_display.       "ALV画面のリフレッシュ
    ELSE.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'            "更新成功
        EXPORTING
          wait = 'X'.

      COMMIT WORK AND WAIT.
      IF sy-subrc = 0.
        MESSAGE s010(z0h).
        LEAVE LIST-PROCESSING.              "選択画面に戻る
      ENDIF.
    ENDIF.
  ENDLOOP.

ENDFORM.                    " FRM_BAPI_CHANGE`
nangnangchuai commented 5 years ago
*&---------------------------------------------------------------------*
*& Report  ZISS011_LTT2
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ziss011_ltt2 MESSAGE-ID zmes.
TABLES:disvariant ,vbak,rseumod,konv.
TYPE-POOLS sscr.
TYPE-POOLS slis.
TYPES:
  BEGIN OF gts_alv_item,

    state  TYPE string ,           "処理ステータス
    kunnr  TYPE vbak-kunnr,        "受注先
    name1  TYPE adrc-name1,       "受注先名称
    auart  TYPE vbak-auart,       "販売伝票タイプ
    vdatu  TYPE vbak-vdatu,       "指定納入期日
    vbeln  TYPE vbak-vbeln,       "販売伝票
    posnr  TYPE vbap-posnr,       "販売伝票明細
    vbeln2 TYPE lips-vbeln,      "出荷伝票
    posnr2  TYPE lips-posnr,      "出荷明細
    matnr  TYPE vbap-matnr,      "品目コード
    arktx  TYPE vbap-arktx,      "品目テキスト
    werks  TYPE lips-werks,      "プラント
    lgort  TYPE lips-lgort,      "保管場所
    lfimg  TYPE lips-lfimg,      "出荷数量実績 (販売単位)
    vrkme  TYPE lips-vrkme,      "販売単位
    lfimg2 TYPE lips-lfimg,      "出荷数量実績 (基本数量単位)
    meins  TYPE lips-meins,      "基本数量単位
    kwert  TYPE konv-kwert,      "金額
    waers  TYPE konv-waers,      "通貨コード
    cancel  TYPE string,                             "出庫取消理由
    message TYPE string,                          "メッセージ

  END OF gts_alv_item,

BEGIN OF gts_alv_sort,    "TB-『ALVソート情報』

    kunnr  TYPE vbak-kunnr,        "受注先
    auart  TYPE vbak-auart,       "販売伝票タイプ
    vdatu  TYPE vbak-vdatu,       "指定納入期日
    vbeln  TYPE vbak-vbeln,       "販売伝票
    posnr  TYPE vbap-posnr,       "販売伝票明細

  END OF gts_alv_sort,

BEGIN OF gts_vbak,                                   "TB-『販売伝票データ』
  vbeln                            TYPE    vbak-vbeln, "購買伝票
  ernam                            TYPE    vbak-ernam, "オブジェクト登録者名
  kunnr                            TYPE    vbak-kunnr, "受注先
  vkorg                            TYPE    vbak-kunnr, "販売組織
  auart                            TYPE    vbak-auart, "販売伝票タイプ
  vdatu                            TYPE    vbak-vdatu,  "指定納入期日
  knumv                            TYPE    vbak-knumv,  "伝票条件番号
  posnr                            TYPE    vbap-posnr,  "販売明細
  matnr                            TYPE    vbap-matnr,  "品目コード
  arktx                            TYPE    vbap-arktx, "受注明細のテキスト (短)
END OF gts_vbak,

BEGIN OF gts_vbfa,
  vbelv                              TYPE   vbfa-vbelv,  "先行販売管理伝票 (VBELV)
  posnv                              TYPE   vbfa-posnv,  "販売管理伝票前明細(POSNV)
  vbeln                              TYPE   vbfa-vbeln,  "後続の販売管理伝票(VBELN )
  posnn                              TYPE   vbfa-posnn,   "販売管理伝票次明細(POSNN )
END OF   gts_vbfa,

BEGIN OF gts_lips,
  vbeln                              TYPE lips-vbeln,   "出荷伝票
  posnr                              TYPE lips-posnr,   "出荷明細
  werks                              TYPE lips-werks,   "プラント
  lgort                              TYPE lips-lgort,   "保管場所
  lfimg                              TYPE lips-lfimg,   "出荷数量実績
  vrkme                              TYPE lips-vrkme,   "販売単位
  umvkz                              TYPE lips-umvkz,   "販売数量単位から基本数量,単位への変換係数の分子
  umvkn                              TYPE lips-umvkn,   "販売数量を在庫単位に換算する
  meins                              TYPE lips-meins,   "基本数量単位
  wbsta                              TYPE vbup-wbsta,   "在庫移動ステータス
END OF gts_lips,

BEGIN OF gts_konv,
  knumv                              TYPE konv-knumv,  "伝票条件番号(KNUMV)
  kposn                              TYPE konv-kposn,   "条件明細番号(KPOSN)
  kwert                              TYPE konv-kwert,   "条件金額(KWERT)
  waers                              TYPE konv-waers,    "通貨コード(WAERS)
END OF gts_konv,

BEGIN OF gts_vbpa,
   kunnr                             TYPE vbpa-kunnr,      "受注先(VBPA-KUNNR )
   nmae1                             TYPE adrc-name1,       "名称 1(ADRC-NAME1 )
END OF gts_vbpa.

DATA: restrict                        TYPE sscr_restrict,
      optlist                         TYPE sscr_opt_list,
      ass                             TYPE sscr_ass,
      gst_variant                     TYPE disvariant,                                   "
      gwk_calluser                    TYPE c.

DATA:  gdt_vbak                       TYPE TABLE OF gts_vbak ,
       gds_vbak                       TYPE      gts_vbak .

DATA:  gdt_vbfa                       TYPE TABLE OF gts_vbfa ,
       gds_vbfa                       TYPE      gts_vbfa .

DATA:  gdt_lips                       TYPE TABLE OF gts_lips ,
       gds_lips                       TYPE      gts_lips .

DATA:  gdt_lips_backup                TYPE TABLE OF gts_lips ,
       gds_lips_backup                TYPE      gts_lips .

DATA:  gdt_konv                       TYPE TABLE OF gts_konv ,
       gds_konv                       TYPE          gts_konv .
DATA:  gdt_konv_backup                TYPE TABLE OF gts_konv ,
       gds_konv_backup                TYPE          gts_konv .

DATA:  gdt_vbpa                       TYPE TABLE OF gts_vbpa,
       gds_vbpa                       TYPE          gts_vbpa.
DATA:  gdt_vbpa_backup                TYPE TABLE OF gts_vbpa,  "取得した名称 1を受注先名称として退避するWK-『受注先名称』.
       gds_vbpa_backup                TYPE          gts_vbpa.   " WK-『受注先名称』
DATA gst_vbfa                         TYPE TABLE OF gts_vbfa. "ST-『販売伝票フローデータ』
DATA gwa_vbfa                         TYPE gts_vbfa.

DATA gst_lips                         TYPE TABLE OF gts_lips. "ST-『出荷伝票データ』
DATA gwa_lips                         TYPE gts_lips.
DATA gdt_alv_item                     TYPE TABLE OF gts_alv_item.
DATA gds_alv_item                     TYPE gts_alv_item.
DATA gdt_alv_sort                     TYPE TABLE OF gts_alv_sort.  "TB-『ALVソート情報』
DATA gds_alv_sort                     TYPE gts_alv_sort.

DATA  v_lines TYPE i.
*DATA  gdt_fieldcat                   TYPE slis_t_fieldcat_alv.
DATA: gdt_fieldcat                    TYPE      slis_t_fieldcat_alv ,
      gds_fieldcat                     TYPE      slis_fieldcat_alv ,
      gds_layout                      TYPE      slis_layout_alv .

SELECTION-SCREEN BEGIN OF BLOCK bk1 WITH FRAME TITLE text-001.

PARAMETERS: rb1 RADIOBUTTON GROUP g1 DEFAULT 'X',"未出庫データ
            rb2 RADIOBUTTON GROUP g1."出庫確認済みデータ
SELECTION-SCREEN END OF BLOCK bk1.

PARAMETERS    : p_vkorg               TYPE vbak-vkorg ."OBLIGATORY .                 "販売組織
SELECT-OPTIONS: s_kunnr               FOR  vbak-kunnr .                           "受注先
PARAMETERS    : p_ernam               TYPE vbak-ernam.                          "オブジェクト登録者名
SELECT-OPTIONS: s_vbeln               FOR  vbak-vbeln.                           "販売伝票
PARAMETERS    : p_vari                TYPE disvariant-variant.                     "表示バリアント
PARAMETERS    : p_tbmax               TYPE rseumod-tbmaxsel.                      "最大表示件数

INITIALIZATION.

  CLEAR optlist.
  CLEAR ass.
  optlist-name = 'EQ'.                                                         "1-2-1.OPTIONの制限の設定
  optlist-options-eq = 'X'.
  optlist-options-bt = ''.
  APPEND optlist TO restrict-opt_list_tab.                                     "1-2-2.属性の制限の設定
  ass-kind = 'S'.
  ass-name = 's_kunnr'.
  ass-sg_main = 'I'.
  ass-op_main = 'EQ'.
  APPEND ass TO restrict-ass_tab.

  CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'                                      "1-2-3.セレクトオプションの指定制限設定
    EXPORTING
      program                = sy-cprog
      restriction            = restrict
    EXCEPTIONS
      too_late               = 1
      repeated               = 2
      selopt_without_options = 3
      selopt_without_signs   = 4
      invalid_sign           = 5
      empty_option_list      = 6
      invalid_kind           = 7
      repeated_kind_a        = 8
      OTHERS                 = 9.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  "1-3. 販売組織のデフォルト値設定-########

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_vari.                             "2. バリアントの検索ヘルプの作成
  PERFORM f4_variant.

AT SELECTION-SCREEN OUTPUT.                                                  "3. 選択画面表題の設定

AT SELECTION-SCREEN.
  PERFORM frm_check.                                                          "4. 選択画面入力値チェック

START-OF-SELECTION.

  PERFORM frm_get_data.                                                       "5. データ取得処理
  PERFORM frm_edit_data.                                                       "6. データ編集処理
  PERFORM frm_display_alv.                                                      "7. 一覧画面出力処理

*&---------------------------------------------------------------------*
*&      Form  F4_VARIANT
*&---------------------------------------------------------------------*
*       2. バリアントの検索ヘルプの作成
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f4_variant .

  DATA: lst_variant   TYPE disvariant,                                    "
        lwk_calluser  TYPE c.

  lst_variant-report = sy-cprog.                                       "2-1.バリアント情報の設定

  CALL FUNCTION 'REUSE_ALV_VARIANT_F4'                                 "2-2.バリアント情報入力可能値の表示
    EXPORTING
      is_variant    = lst_variant                                      ""ST-『バリアント入力情報』
      i_save        = 'A'
    IMPORTING
      e_exit        = lwk_calluser                                        "WK-『コールユーザ』
      es_variant    = lst_variant                                       "ST-『バリアント出力情報』
    EXCEPTIONS
      not_found     = 1
      program_error = 2
      OTHERS        = 3.

  IF sy-subrc <> 0 OR  lwk_calluser = 'X'.
    EXIT.
  ENDIF.
  IF lwk_calluser = ''.
    p_vari = lst_variant-variant.
  ENDIF.

ENDFORM.                    " F4_VARIANT
*&---------------------------------------------------------------------*
*&      Form  FRM_CHECK
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_check .
  SELECT SINGLE COUNT(*) FROM tvko                                            "4-1.販売組織の妥当性チェック
      WHERE vkorg = p_vkorg.
  IF sy-subrc <> 0.
    MESSAGE e001(zmes).
    LEAVE LIST-PROCESSING.
  ENDIF.

  SELECT SINGLE COUNT(*) FROM usr01                                              "4-2.オブジェクト登録者名の妥当性チェック
      WHERE bname = p_ernam.
  IF sy-subrc <> 0.
    MESSAGE e002(zmes).
    LEAVE LIST-PROCESSING.
  ENDIF.
  "4-3.バリアントの妥当性チェック
  gst_variant-report = sy-cprog.                                                 "4-3-1.バリアント情報の設定
  gst_variant-variant = p_vari.
  CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
    EXPORTING
      i_save        = 'A'                                                   "4-3-2.バリアントの存在チェック
    CHANGING
      cs_variant    = gst_variant
    EXCEPTIONS
      wrong_input   = 1
      not_found     = 2
      program_error = 3
      OTHERS        = 4.
  IF sy-subrc <> 0.
    MESSAGE e003(zmes).
    LEAVE LIST-PROCESSING.
  ENDIF.
ENDFORM.                    " FRM_CHECK
*&---------------------------------------------------------------------*
*&      Form  FRM_GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_get_data .

  IF p_ernam IS NOT INITIAL.                                                        "5-1.オブジェクト登録者名のRANGEテーブルの作成

    RANGES gtb_ernam FOR vbak-ernam.                                                "TB-『レンジテーブル情報』
    DATA   gts_ernam LIKE LINE OF gtb_ernam.                                        "ST-『レンジテーブル』

    CLEAR  gts_ernam.

    gts_ernam-sign   = 'I'.
    gts_ernam-option = 'EQ'.
    gts_ernam-low    = p_ernam.
    APPEND  gts_ernam TO gtb_ernam.
  ENDIF.

*  5-2.販売伝票データの取得
  SELECT
      a~vbeln                              "購買伝票
      a~ernam                              "オブジェクト登録者名
      a~kunnr                              "受注先
      a~vkorg                              "販売組織
      a~auart                              "販売伝票タイプ
      a~vdatu                              "指定納入期日
      a~knumv                              "伝票条件番号
      b~posnr                              "販売明細
      b~matnr                              "品目コード
      b~arktx                              "受注明細のテキスト (短)
    INTO TABLE gdt_vbak
    FROM vbak  AS a                          "DB『販売伝票: ヘッダデータ』
    INNER JOIN vbap  AS b                    "DB『販売伝票: 明細データ』
    ON    a~vbeln    = b~vbeln

*    FOR ALL ENTRIES IN gtb_ernam
    WHERE a~vbeln IN s_vbeln               "販売伝票(VBAK-VBELN )
    AND   a~ernam IN gtb_ernam              "オブジェクト登録者名(VBAK-ERNAM )
    AND   a~lifsk = space                 "出荷ブロック(伝票ヘッダ)(VBAK-LIFSK)
    AND   a~vkorg = p_vkorg               "販売組織(VBAK-VKORG)
    AND   a~kunnr IN s_kunnr.             "受注先(VBAK-KUNNR)
  IF sy-subrc <> 0.
    MESSAGE e004(zmes).
    LEAVE LIST-PROCESSING.
  ENDIF.

*SELECT b~vbeln b~posnr a~waerk a~erdat auart bstnk pernr kzwi1 kwmeng  "5-3.販売伝票フローの取得
*  INTO CORRESPONDING FIELDS OF TABLE ivbap
*  FROM vbak AS a
*  INNER JOIN vbap AS b
*  ON a~vbeln = b~vbeln
*  INNER JOIN vbpa AS c
*  ON a~vbeln = c~vbeln
*  AND c~parvw = 'VE'
*  FOR ALL ENTRIES IN itab
*  WHERE b~vbeln = itab-vgbel AND b~posnr = itab-vgpos.

*  "5-3.販売伝票フローの取得

  SELECT vbelv                "先行販売管理伝票
         posnv                "販売管理伝票前明細
         vbeln                "後続の販売管理伝票
         posnn                "販売管理伝票次明細XX
  INTO TABLE gdt_vbfa
  FROM vbfa
  FOR ALL ENTRIES IN gdt_vbak
  WHERE vbelv = gdt_vbak-vbeln
  AND   posnv = gdt_vbak-posnr
  AND   posnv = 'J'.

  IF sy-subrc <> 0.
    MESSAGE e004(zmes).
  ENDIF.

  IF NOT gdt_vbak[] IS  INITIAL.                                               "5-3-1.重複レコード削除
*    SORT gdt_vbak BY vbeln posnn ASCENDING.
*    DELETE ADJACENT DUPLICATES FROM gdt_vbak COMPARING vbeln posnn.
  ENDIF.

  .
  "5-4.販売伝票: 出荷伝票:明細データの取得
  CHECK gdt_lips IS NOT INITIAL.
  DATA ldt_temp_lips LIKE gdt_lips.
  SORT ldt_temp_lips BY vbeln.
  DELETE ADJACENT DUPLICATES FROM ldt_temp_lips COMPARING vbeln posnr.

  SELECT
         b~vbeln           "出荷明細
         b~posnr          "プラント
         b~werks          "プラント
         b~lgort          "保管場所
         b~lfimg          "出荷数量実績
         b~vrkme          "販売単位
         b~umvkz          "販売数量単位から基本数量,単位への変換係数の分子
         b~umvkn          "販売数量を在庫単位に換算する
         b~meins          "基本数量単位
         a~wbsta           "在庫移動ステータス
  INTO TABLE gdt_lips
  FROM vbup AS a
  INNER JOIN lips AS b
  ON  a~vbeln = b~vbeln
  AND a~posnr = b~posnr
  FOR ALL ENTRIES IN ldt_temp_lips
  WHERE b~vbeln = ldt_temp_lips-vbeln
  AND   b~posnr = ldt_temp_lips-posnr
  AND   b~ernam = gtb_ernam.

  IF sy-subrc <> 0.
    MESSAGE e004(zmes).
  ENDIF.
*  5-4-1.未出庫データ、出庫確認済みデータの選出
*  5-5.条件 (トランザクションデータ)の取得
  CHECK gdt_vbak[] IS NOT INITIAL.
  DATA ldt_temp_vbak LIKE gdt_vbak.
  SORT ldt_temp_vbak BY vbeln.
  DELETE ADJACENT DUPLICATES FROM ldt_temp_vbak COMPARING vbeln.

  SELECT knumv           "伝票条件番号
         kposn            "条件明細番号
         kwert            "条件金額
         waers            "通貨コード
INTO TABLE gdt_konv
FROM  konv AS a
FOR ALL ENTRIES IN ldt_temp_vbak
WHERE a~knumv = ldt_temp_vbak-knumv
AND   a~kposn = ldt_temp_vbak-posnr
AND   a~kschl = 'ZPR0'.

*5-6.受注先名称の取得

  CHECK gdt_vbak[] IS NOT INITIAL.
  ldt_temp_vbak = gdt_vbak.
  SORT  ldt_temp_vbak BY vbeln posnr.
  DELETE ADJACENT DUPLICATES FROM ldt_temp_vbak COMPARING vbeln posnr.

  SELECT a~kunnr"受注先
         b~name1"名称1
  INTO TABLE gdt_vbpa
  FROM  vbpa AS a
  INNER JOIN adrc AS b
  ON    a~adrnr = b~addrnumber
  FOR ALL ENTRIES IN ldt_temp_vbak
  WHERE a~vbeln =  ldt_temp_vbak-vbeln
  AND   a~kunnr = ldt_temp_vbak-kunnr.

ENDFORM.                    " FRM_GET_DATA
*&---------------------------------------------------------------------*
*&      Form  FRM_EDIT_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_edit_data .
  "6-1. 内部テーブル事前ソート処理
  IF NOT gdt_vbfa[] IS INITIAL.                         "TB-『販売伝票フローデータ』
    SORT gdt_vbfa BY vbelv posnv.
  ENDIF.

  IF NOT gdt_lips[] IS INITIAL.                         "TB-『出荷伝票データ』
    SORT gdt_lips BY vbeln posnr.
  ENDIF.

  IF NOT gdt_konv[] IS INITIAL.                        "TB-『条件データ』
    SORT gdt_konv BY knumv kposn.
  ENDIF.

  IF NOT gdt_vbpa[] IS INITIAL.                        "TB-『受注先名称データ』
    SORT gdt_vbpa BY kunnr.
  ENDIF.
* 6-2. 内部テーブル編集処理

*6-2-1. 販売伝票フローデータの読込処理

  LOOP AT gdt_vbak INTO gds_vbak.
    READ TABLE gdt_vbfa INTO gds_vbfa WITH KEY vbelv = gds_vbak-vbeln posnv = gds_vbak-posnr.
    IF sy-subrc = 0 .
      APPEND gds_vbfa TO gst_vbfa.   "ST-『販売伝票フローデータ』
    ENDIF.

    CLEAR gds_vbfa.
  ENDLOOP.

*6-2-2. 出荷伝票:明細データの読込処理

  LOOP AT gst_vbfa INTO gwa_vbfa.
    READ TABLE gdt_lips INTO gds_lips WITH KEY vbeln = gwa_vbfa-vbeln posnr = gwa_vbfa-posnn .
    IF sy-subrc = 0 .
      APPEND gds_lips TO gst_lips.      "ST-『出荷伝票データ』
    ENDIF.
    CLEAR gds_lips.

  ENDLOOP.
*
**6-2-3. 受注先名称データの読込処理

  LOOP AT gdt_vbak INTO gds_vbak.
    READ TABLE gdt_vbpa INTO gds_vbpa WITH KEY kunnr = gds_vbak-kunnr.
    IF sy-subrc = 0.
      gds_vbpa_backup-nmae1 = gds_vbpa-nmae1.
      APPEND gds_vbpa_backup TO gdt_vbpa_backup.
    ENDIF.
  ENDLOOP.

**6-2-4. 条件データの読込処理

  LOOP AT gdt_vbak INTO gds_vbak.
    READ TABLE gdt_konv INTO gds_konv WITH KEY knumv = gds_vbak-knumv kposn = gds_vbak-posnr .
    IF sy-subrc = 0.
      gds_konv_backup-kwert = gds_konv-kwert.    "条件金額、 通貨コードを退避する                     "
      gds_konv_backup-waers = gds_konv-waers.
      APPEND gds_konv_backup TO gdt_konv_backup.
    ENDIF.
  ENDLOOP.

*6-2-5. 出荷数量実績 (基本数量単位)編集処理

  LOOP AT gdt_lips INTO gds_lips.
    gds_lips_backup-lfimg = gds_lips-lfimg * gds_lips-umvkz / gds_lips-meins .
    APPEND  gds_lips_backup TO gdt_lips_backup.
  ENDLOOP.

*6-3. ALV出力用内部テーブル編集処理を行う

  LOOP AT gdt_alv_item INTO gds_alv_item.
*処理ステータス state
    READ TABLE gdt_vbak INTO gds_vbak INDEX sy-tabix.    "TB-『販売伝票データ』
    IF sy-subrc = 0.
      gds_alv_item-kunnr = gds_vbak-kunnr."受注先
      gds_alv_item-auart = gds_vbak-auart ."販売伝票タイプ
      gds_alv_item-vdatu = gds_vbak-vdatu."指定納入期日
      gds_alv_item-vbeln = gds_vbak-vbeln."販売伝票
      gds_alv_item-posnr = gds_vbak-posnr."販売伝票明細
      gds_alv_item-matnr  = gds_vbak-matnr.      "品目コード
      gds_alv_item-arktx  = gds_vbak-arktx.      "品目テキスト

    ENDIF.

    READ TABLE gst_lips INTO gwa_lips INDEX sy-tabix. "ST-『出荷伝票データ』
    IF sy-subrc = 0.
      gds_alv_item-vbeln2 = gwa_lips-vbeln."出荷伝票
      gds_alv_item-posnr2 = gwa_lips-posnr."出荷明細
      gds_alv_item-lgort = gwa_lips-lgort."保管場所
      gds_alv_item-vrkme = gwa_lips-vrkme.  "販売単位
      gds_alv_item-meins = gwa_lips-meins.  "基本数量単位
      gds_alv_item-werks = gwa_lips-werks.   "プラント
    ENDIF.

    gds_alv_item-name1 = gds_vbpa_backup-nmae1. "wk受注先名称
    gds_alv_item-lfimg2 = gds_lips_backup-lfimg . "WK-『出荷数量実績 (基本数量単位)』
    gds_alv_item-kwert = gds_konv_backup-kwert.  "WK-『条件金額』
    gds_alv_item-waers = gds_konv_backup-waers. "WK-『通貨コード』

    gds_alv_item-cancel = space.
    gds_alv_item-message = space.

    APPEND gds_alv_item TO gdt_alv_item.

  ENDLOOP.

*7. 一覧画面出力処理

*7-1. TB-『ALV出力データ』のソート処理

  SORT gdt_alv_item BY kunnr auart vdatu vbeln posnr.

  DESCRIBE TABLE gdt_alv_item  LINES v_lines.
  IF v_lines >= p_tbmax .
    MESSAGE e006(zmes).
*・メッセージを出力し、一覧画面に遷移する (→メッセージ一覧№006)
*TB-『ALV出力データ』レコードがSC-『最大表示件数』以上のデータを削除する
    DELETE  gdt_alv_item INDEX p_tbmax.
  ENDIF.

**7-2. フィールドカタログ作成の処理.
*  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
*    EXPORTING
*      i_program_name         = sy-cprog
*      i_internal_tabname     = gdt_alv_item
*      i_inclname             = sy-cprog
*    CHANGING
*      ct_fieldcat            = gdt_fieldcat
*    EXCEPTIONS
*      inconsistent_interface = 1
*      program_error          = 2
*      OTHERS                 = 3.
*  IF sy-subrc <> 0.
*     MESSAGE e0067(zmes).
*      LEAVE LIST-PROCESSING.
*  ENDIF.

ENDFORM.                    " FRM_EDIT_DATA

*&---------------------------------------------------------------------*
*&      Form  FRM_DISPLAY_ALV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_display_alv .

**7-3. フィールドカタログテーブル編集処理

*
  PERFORM frm_fieldcat.                            "フィールドカタログの作成
  PERFORM frm_layout.
  PERFORM frm_alv_data_sort.                       "7-4-3. ALVソート設定処理
**  PERFORM frm_events.
  PERFORM frm_alv_display.                          "7-4-4. ALV出力処理
*

ENDFORM.                    " FRM_DISPLAY_ALV

*&---------------------------------------------------------------------*
*&      Form  FRM_FIELDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_fieldcat .

  PERFORM frm_set_fieldcat USING  'state'  '処理ステータス' '' '' '' '' ''.
  PERFORM frm_set_fieldcat USING  'kunnr'   '受注先' '' '' '' '' ''.
  PERFORM frm_set_fieldcat USING   'name1'  '受注先名称' '' '' '' '' ''.
  PERFORM frm_set_fieldcat USING   'auart'  '販売伝票タイプ' '' '' '' '' ''.
  PERFORM frm_set_fieldcat USING   'vdatu'   '指定納入期日' '' '' '' '' ''.
  PERFORM frm_set_fieldcat USING   'vbeln'   '販売伝票' '' '' '' '' ''.
  PERFORM frm_set_fieldcat USING   'posnr'   '販売伝票明細' '' '' '' '' ''.
  PERFORM frm_set_fieldcat USING   'vbeln2'   '出荷伝票' '' '' '' '' ''.
  PERFORM frm_set_fieldcat USING   'posnr2'   '出荷明細' '' '' '' '' ''.
  PERFORM frm_set_fieldcat USING   'matnr'    '品目コード' '' '' '' '' ''.
  PERFORM frm_set_fieldcat USING   'arktx'    '品目テキスト' '' '' '' '' ''.
  PERFORM frm_set_fieldcat USING   'werks'     'プラント' '' '' '' '' ''.
  PERFORM frm_set_fieldcat USING   'lgort'      '保管場所' '' '' '' '' ''.
  PERFORM frm_set_fieldcat USING   'lfimg'     '出荷数量実績 (販売単位)' '' '' '' '' ''.
  PERFORM frm_set_fieldcat USING   'vrkme'     '販売単位' '' '' '' '' ''.
  PERFORM frm_set_fieldcat USING   'lfimg2'    '出荷数量実績 (基本数量単位)' '' '' '' '' ''.
  PERFORM frm_set_fieldcat USING   'meins'    '基本数量単位' '' '' '' '' ''.
  PERFORM frm_set_fieldcat USING   'kwert'   '金額' '' '' '' '' ''.
  PERFORM frm_set_fieldcat USING   'waers'   '通貨コード' '' '' '' '' ''.
  PERFORM frm_set_fieldcat USING  'cancel'   '出庫取消理由' '' '' '' '' ''.
  PERFORM frm_set_fieldcat USING   'message'  'メッセージ' '' '' '' '' ''.

ENDFORM.                    " FRM_FIELDCAT
*&---------------------------------------------------------------------*
*&      Form  FRM_SET_FIELDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_1319   text
*      -->P_1320   text
*      -->P_1321   text
*      -->P_1322   text
*      -->P_1323   text
*      -->P_1324   text
*----------------------------------------------------------------------*
FORM frm_set_fieldcat  USING    p_field                "フィールド名前
                                 p_name                 "出力フィールドテキスト
                                 p_edit                 "編集可能設定値
                                 p_qfield               "フィールド
                                 p_qtablename           "テーブル名前
                                 p_ref_field           "参照フィールド名前
                                 p_ref_tablename.      "参照テーブル名前

  DATA: ldf_col TYPE i.

  gds_fieldcat-col_pos          = ldf_col.
  gds_fieldcat-fieldname        = p_field.
  gds_fieldcat-seltext_m        = p_name.
  gds_fieldcat-edit             = p_edit.
  gds_fieldcat-outputlen        = 16.
  gds_fieldcat-qfieldname       = p_qfield.
  gds_fieldcat-qtabname         = p_qtablename.
  gds_fieldcat-ref_fieldname    = p_ref_field.
  gds_fieldcat-ref_tabname      = p_ref_tablename.

  APPEND gds_fieldcat TO gdt_fieldcat.
  ldf_col = ldf_col + 1.
  CLEAR gds_fieldcat.

**********************1選択画面で「出庫確認済みデータ」が選択されている場合のみ表示する*********8

ENDFORM.                    " FRM_SET_FIELDCAT

*&---------------------------------------------------------------------*
*&      Form  FRM_LAYOUT
*&---------------------------------------------------------------------*
*  7-4. ALV一覧画面出力処理
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_layout .

*7-4-1. レイアウト設定処理
  gds_layout-box_fieldname = 'SEL'.
  gds_layout-lights_fieldname = 'STATUS'.

*7-4-2. バリアント設定処理
  gst_variant-report = sy-repid.
  gst_variant-username  = sy-uname.
  gst_variant-variant = p_vari .

ENDFORM.                    " FRM_LAYOUT
*&---------------------------------------------------------------------*
*&      Form  FRM_ALV_DATA_SORT
*&---------------------------------------------------------------------*
*       7-4-3. ALVソート設定処理
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_alv_data_sort .
*受注先、販売伝票タイプ、指定納入期日、販売伝票、販売伝票明細
*  sort gdt_alv_item by kunnr auart  vdatu vbeln posnr.
  LOOP AT gdt_alv_item INTO gds_alv_item.
    READ TABLE gdt_alv_sort INTO gds_alv_sort INDEX sy-tabix .
    IF sy-subrc = 0.
      gds_alv_sort-kunnr = gds_alv_item-kunnr."受注先
      gds_alv_sort-auart = gds_alv_item-auart."販売伝票タイプ
      gds_alv_sort-vdatu = gds_alv_item-vdatu."指定納入期日
      gds_alv_sort-vbeln = gds_alv_item-vbeln."販売伝票
      gds_alv_sort-posnr = gds_alv_item-posnr."販売伝票明細

    ENDIF.
    APPEND  gds_alv_sort TO gdt_alv_sort.
  ENDLOOP.

ENDFORM.                    " FRM_ALV_DATA_SORT
*&---------------------------------------------------------------------*
*&      Form  FRM_ALV_DISPLAY
*&---------------------------------------------------------------------*
*       7-4-4. ALV出力処理
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_alv_display .

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
 EXPORTING

   i_callback_program                = sy-repid
   i_callback_pf_status_set          = 'FRM_SET_STATUS'
   i_callback_user_command           = 'FRM_USER_COMMAND'
*   I_CALLBACK_TOP_OF_PAGE            = ' '
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
*   I_STRUCTURE_NAME                  =
*   I_BACKGROUND_ID                   = ' '
*   I_GRID_TITLE                      =
*   I_GRID_SETTINGS                   =
    is_layout                        =  gds_layout
    it_fieldcat                      =   gdt_fieldcat
*   IT_EXCLUDING                      =
*   IT_SPECIAL_GROUPS                 =
    it_sort                          = gdt_alv_sort
*   IT_FILTER                         =
*   IS_SEL_HIDE                       =
*   I_DEFAULT                         = 'X'
   i_save                            = 'A '
   is_variant                        = gst_variant
*   IT_EVENTS                         =
*   IT_EVENT_EXIT                     =
*   IS_PRINT                          =
*   IS_REPREP_ID                      =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE                 = 0
*   I_HTML_HEIGHT_TOP                 = 0
*   I_HTML_HEIGHT_END                 = 0
*   IT_ALV_GRAPHICS                   =
*   IT_HYPERLINK                      =
*   IT_ADD_FIELDCAT                   =
*   IT_EXCEPT_QINFO                   =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
 TABLES
   t_outtab                          = gdt_alv_item
 EXCEPTIONS
   program_error                     = 1
   OTHERS                            = 2
            .
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.

ENDFORM.                    " FRM_ALV_DISPLAY
*7-5. ALVのステータス設定処理ルーチン