2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

(初)第四弾 ABAPー訓練「ALV/クエリ」

Last updated at Posted at 2018-11-02

:writing_hand_tone1:第三弾
:writing_hand_tone1:SAP 訓練目次
#1.ALV
構築図:
alv_cmm_001.gif
##1.1種類

  • REUSE_ALV_GRID_DISPLAY
  • REUSE_ALV_LIST_DISPLAY

##1.2実装順序(例:REUSE_ALV_GRID_DISPLAY)

1.3.3<REUSE_ALV_GRID_DISPLAY>
    👇
  1.3.4<LAYOUT>
    👇
  1.3.5<FIELDCAT>
    👇
  1.3.6<VARIANT>
    👇
  1.3.7<OUTTAB>

##1.3実装
###1.3.1データ型グループ

ABAP

TYPE-POOLS:slis

###1.3.2ソーステンプレート

ABAP
REPORT レポート名.
TYPE-POOLS:slis.

************************************************************************
* 内部テーブル
************************************************************************

************************************************************************
* 構造
************************************************************************

************************************************************************
* 変数
************************************************************************

************************************************************************
* 選択画面
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK b01 WITH FRAME TITLE text-t01.
SELECT-OPTIONS     s_ FOR v_ OBLIGATORY.
SELECT-OPTIONS     s_ FOR v_.
SELECTION-SCREEN END OF BLOCK b01.

************************************************************************
* 初期化
************************************************************************
INITIALIZATION.
  CLEAR: 内部テーブル

************************************************************************
* 主処理
************************************************************************
START-OF-SELECTION.

*- データ取得

*- データ編集

*- バリアント設定

*- レイアウト設定 

*- フィールドカタログ

*- ALV表示

###1.3.3<REUSE_ALV_GRID_DISPLAY>

ABAP
*- テンプレートの上にどんどん実装します。
*- ALV表示
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = sy-repid
      is_layout          = gw_***   "レイアウト
      it_fieldcat        = gi_***   "フィールドカタログ
      is_variant         = gw_***   "バリアント
    TABLES
      t_outtab           = gi_***    "表示データ
* EXCEPTIONS
*     PROGRAM_ERROR      = 1
*     OTHERS             = 2
    .
  IF sy-subrc <> 0.
*- 失敗の場合は該当的な処理を追加してください。
  ENDIF.

###1.3.4<LAYOUT>

ABAP
*-  ALV
DATA: gw_layout   TYPE slis_layout_alv.      "レイアウト

gw_layout-zebra  = 'X'.                    "縞模様
gw_layout-colwidth_optimize = 'X'.         "項目長にあわせる
gw_layout-window_titlebar   = sy-title.    "ALV枠のタイトル

###1.3.5<FIELDCAT>

ABAP

*- ALV
 DATA: gi_fieldcat TYPE slis_t_fieldcat_alv.  "フィールドカタログ

  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      i_program_name     = sy-repid
*      i_internal_tabname =
      I_STRUCTURE_NAME   = 'ZSTU_GRADE'
*     I_CLIENT_NEVER_DISPLAY       = 'X'
*     I_INCLNAME         =
*     I_BYPASSING_BUFFER =
*     I_BUFFER_ACTIVE    =
    CHANGING
      ct_fieldcat        = gi_fieldcat
* EXCEPTIONS
*     INCONSISTENT_INTERFACE       = 1
*     PROGRAM_ERROR      = 2
*     OTHERS             = 3
    .
  IF sy-subrc <> 0.
*- 失敗の場合は該当的な処理を追加してください。
  ENDIF.

###1.3.6<VARIANT>

ABAP
*- ALV
DATA: gw_variant  TYPE disvariant.           "バリアント
gw_variant-report    = sy-cprog.
gw_variant-username  = sy-uname.

###1.3.7<OUTTAB>

ABAP

DATA: gi_ZSTU_GRADE TYPE TABLE OF ZSTU_GRADE.

  SELECT * INTO TABLE gi_ZSTU_GRADE
    FROM ZSTU_GRADE
   WHERE ZSTUD_NO IN s_stud_no
     AND ZGRADE IN s_grade.

*- s_stud_no
*- SELECT-OPTIONS     s_stud_no FOR v_stud_no OBLIGATORY.
*- SELECT-OPTIONS     s_grade FOR v_grade.

###1.3.8実装サンプル

ABAP
*&---------------------------------------------------------------------*
*& Report  ZALV_STUD_LIST01
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZALV_STUD_LIST01.
TYPE-POOLS:slis.

************************************************************************
*  宣言定義 
************************************************************************
DATA:
    GW_STUD     TYPE ZSTUDENT01,
*- ALV
    gw_variant  TYPE disvariant,           "バリアント
*- ALV
    gi_fieldcat TYPE slis_t_fieldcat_alv,  "項目設定
*-  ALV
    gw_layout   TYPE slis_layout_alv,      "レイアウト
    gi_stu      TYPE TABLE OF ZSTUDENT01.

************************************************************************
* 内部テーブル
************************************************************************

************************************************************************
* 定数
************************************************************************

************************************************************************
* スクリーン選択
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK b01 WITH FRAME TITLE text-t01.
SELECT-OPTIONS     s_class FOR GW_STUD-ZCLASS01 OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b01.

************************************************************************
* 初期化処理
************************************************************************
INITIALIZATION.
  CLEAR: GW_STUD.

************************************************************************
*メイン処理
************************************************************************
START-OF-SELECTION.

*- データ取得
PERFORM FRM_DATA_GET.
*- データ編集

*- バリアント設定
  PERFORM FRM_ALV_VAR.
*- レイアウト設定
  PERFORM FRM_ALV_LAYOUT.
*- 項目設定
  PERFORM FRM_ALV_FIELDCAT.
*- ALV出力
  PERFORM FRM_ALV_OUTPUT.
*&---------------------------------------------------------------------*
*&      Form  FRM_ALV_OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_ALV_OUTPUT .
*- ・ニ・ラ・・`・ネ、ホノマ、ヒ、ノ、ノ、gラー、キ、゙、ケ。」
*- ALV表示
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = sy-repid
      is_layout          = gw_layout    "レイアウト
      it_fieldcat        = gi_fieldcat  "項目設定
      is_variant         = gw_variant   "バリアント
    TABLES
      t_outtab           = gi_stu    "表示用内部テーブル
    EXCEPTIONS
      PROGRAM_ERROR      = 1
      OTHERS             = 2.
  IF sy-subrc <> 0.
*- 例外処理
  ENDIF.
ENDFORM.                    " FRM_ALV_OUTPUT
*&---------------------------------------------------------------------*
*&      Form  FRM_ALV_LAYOUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_ALV_LAYOUT .

  gw_layout-zebra  = 'X'.                    "シマウマ表示可否
  gw_layout-colwidth_optimize = 'X'.         "列サイズ自動可否
  gw_layout-window_titlebar   = sy-title.    "ALVタイトル

ENDFORM.                    " FRM_ALV_LAYOUT
*&---------------------------------------------------------------------*
*&      Form  FRM_ALV_FIELDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_ALV_FIELDCAT .

  PERFORM FRM_SET_FIELDCAT.


ENDFORM.                    " FRM_ALV_FIELDCAT
*&---------------------------------------------------------------------*
*&      Form  FRM_ALV_VAR
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_ALV_VAR .

gw_variant-report    = sy-cprog.
gw_variant-username  = sy-uname.
ENDFORM.                    " FRM_ALV_VAR
*&---------------------------------------------------------------------*
*&      Form  FRM_SET_FIELDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_SET_FIELDCAT .

  DATA: LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
  CLEAR gi_fieldcat.

*
  CLEAR LS_FIELDCAT.

  LS_FIELDCAT-FIELDNAME    = 'ZNO01'.
  LS_FIELDCAT-TABNAME      = 'ZSTUDENT01'.
  LS_FIELDCAT-SELTEXT_S = text-t02.

  APPEND LS_FIELDCAT TO gi_fieldcat.

  CLEAR LS_FIELDCAT.

  LS_FIELDCAT-FIELDNAME    = 'ZNM01'.
  LS_FIELDCAT-TABNAME      = 'ZSTUDENT01'.
  LS_FIELDCAT-SELTEXT_S = text-t03.

  APPEND LS_FIELDCAT TO gi_fieldcat.


  CLEAR LS_FIELDCAT.

  LS_FIELDCAT-FIELDNAME    = 'ZBIRTHDAY_DT01'.
  LS_FIELDCAT-TABNAME      = 'ZSTUDENT01'.
  LS_FIELDCAT-SELTEXT_S = text-t05.

  APPEND LS_FIELDCAT TO gi_fieldcat.

  CLEAR LS_FIELDCAT.

  LS_FIELDCAT-FIELDNAME    = 'ZADDRESS01'.
  LS_FIELDCAT-TABNAME      = 'ZSTUDENT01'.
  LS_FIELDCAT-SELTEXT_S = text-t06.

  APPEND LS_FIELDCAT TO gi_fieldcat.
  CLEAR LS_FIELDCAT.

  LS_FIELDCAT-FIELDNAME    = 'ZCONTACT01'.
  LS_FIELDCAT-TABNAME      = 'ZSTUDENT01'.
  LS_FIELDCAT-SELTEXT_S = text-t07.

  APPEND LS_FIELDCAT TO gi_fieldcat.
  CLEAR LS_FIELDCAT.

  LS_FIELDCAT-FIELDNAME    = 'ZCLASS01'.
  LS_FIELDCAT-TABNAME      = 'ZSTUDENT01'.
  LS_FIELDCAT-SELTEXT_S = text-t04.

  APPEND LS_FIELDCAT TO gi_fieldcat.

    CLEAR LS_FIELDCAT.

  LS_FIELDCAT-FIELDNAME    = 'ZCREATE_DT01'.
  LS_FIELDCAT-TABNAME      = 'ZSTUDENT01'.
  LS_FIELDCAT-SELTEXT_S = text-t08.

  APPEND LS_FIELDCAT TO gi_fieldcat.

      CLEAR LS_FIELDCAT.

  LS_FIELDCAT-FIELDNAME    = 'ZCREATER01'.
  LS_FIELDCAT-TABNAME      = 'ZSTUDENT01'.
  LS_FIELDCAT-SELTEXT_S = text-t09.

  APPEND LS_FIELDCAT TO gi_fieldcat.

        CLEAR LS_FIELDCAT.

  LS_FIELDCAT-FIELDNAME    = 'ZUPDATE_DT01'.
  LS_FIELDCAT-TABNAME      = 'ZSTUDENT01'.
  LS_FIELDCAT-SELTEXT_S = text-t10.

  APPEND LS_FIELDCAT TO gi_fieldcat.

          CLEAR LS_FIELDCAT.

  LS_FIELDCAT-FIELDNAME    = 'ZUPDATER01'.
  LS_FIELDCAT-TABNAME      = 'ZSTUDENT01'.
  LS_FIELDCAT-SELTEXT_S = text-t11.

  APPEND LS_FIELDCAT TO gi_fieldcat.
ENDFORM.                    " FRM_SET_FIELDCAT
*&---------------------------------------------------------------------*
*&      Form  FRM_DATA_GET
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_DATA_GET .
  SELECT * INTO TABLE gi_stu
    FROM ZSTUDENT01
   WHERE ZCLASS01 IN s_class.
ENDFORM.                    " FRM_DATA_GET

#2.クエリ
##2.1実装順序
2.2クエリ領域
   👇
2.3ユーザグループ
   👇
2.4インフォセット
   👇
2.5クエリおよびインフォセットクエリ

##2.2クエリ領域の設定(グローバル・ローカル)

  • メニューから設定する

##2.3ユーザグループの設定

  • Tr-Cd:SQ03
  • ZSTU_GRPを作る

##2.4インフォセット

  • Tr-Cd:SQ02

  • InfoSet:ZSTUDENT_LIST「インフォセット:表題およびデータベース」

    • 基本テーブル使用テーブル結合:ZSTUDENT ⇒全項目
    • テーブル直接読込
  • ⇒「結合」ボタンでZSTU_GRADEを追加する

  • 赤〇を実行すると「インフォセット ZSTUDENT_LIST が生成されました」

  • 「ロール/ユーザグループ割当」ボタン
      ⇒ZSTU_GRPにZSTUDENT_LISTを割当する

##2.5クエリおよびインフォセットクエリ

  • Tr-Cd:SQ01
    -選択項目と出力項目を設定する
    -「出力」ボタンでクエリを作る
  • [実行(F8)]を押下する

:writing_hand_tone1:第五弾
:writing_hand_tone1:SAP 訓練目次

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?