nangnangchuai / sap

0 stars 0 forks source link

代码备份2 #36

Open nangnangchuai opened 5 years ago

nangnangchuai commented 5 years ago
*&---------------------------------------------------------------------*
*& Report  ZISS011_LTT2
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ziss011_ltt2.
TABLES:disvariant ,vbak,rseumod.
TYPE-POOLS sscr.
DATA: restrict TYPE sscr_restrict,
      optlist TYPE sscr_opt_list,
      ass TYPE sscr_ass.

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_var                 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.
nangnangchuai commented 5 years ago
*&---------------------------------------------------------------------*
*& Report  ZISS011_LTT2
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ziss011_ltt2.
TABLES:disvariant ,vbak,rseumod.
TYPE-POOLS sscr.
DATA: restrict TYPE sscr_restrict,
      optlist TYPE sscr_opt_list,
      ass TYPE sscr_ass.

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. 選択画面表題の設定  

*&---------------------------------------------------------------------*
*&      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
nangnangchuai commented 5 years ago

*&---------------------------------------------------------------------*
*& Report  ZISS011_LTT2
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ziss011_ltt2 MESSAGE-ID zmes.
TABLES:disvariant ,vbak,rseumod,konv.
TYPE-POOLS sscr.

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_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  V_LINES TYPE I. 

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. データ編集処理

*&---------------------------------------------------------------------*
*&      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(z000).
  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(z000).
  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.

ENDFORM.                    " FRM_EDIT_DATA