2
1

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 5 years have passed since last update.

(初)第二弾 ABAPー言語

Last updated at Posted at 2018-10-27

:writing_hand_tone1:第一弾
:writing_hand_tone1:SAP 訓練目次
#1.実例ニーズ

  • 学生登録画面

番号[ ] 名前[    ]
性別 ○男性 ●女性
生年月日[2019/02/17]
住所[ ]
連絡情報[ ]
※実行[F8]を押下すると結果

  • 学生検索ヘルプ画面
    表示項目
    番号 名前 性別 生年月日

※新規登録と移送依頼
image.png

image.png

#2. イベント

  • AT SELECTION-SCREEN.
  • SELECTION-SCREEN OUT.
  • START-OF-SELECTION.
  • END-OF-SELECTION.

#3. ロジック

  • 条件分析
    IF < 条件1>.
    < 命令ブロック>
    ELSEIF < 条件2>
    < 命令ブロック>.
    ELSEIF < 条件3>.
    < 命令ブロック>
    .....
    ELSE.
    < 命令ブロック>
    ENDIF.

  • CASE 制御構造

CASE .
WHEN [OR OR ...].
< 命令ブロック>
WHEN .[OR OR ...]
< 命令ブロック>
WHEN [OR OR ...].
< 命令ブロック>
WHEN ...
......
WHEN OTHERS.
< 命令ブロック>
ENDCASE.

  • ループ
     DO 命令を使用した無条件ループ
ABAP
  DO 2 TIMES.
    WRITE / SY-INDEX.
  ENDDO.

 WHILE 命令を使用した条件ループ

ABAP

  DATA:ldf_index TYPE int1.

  WHILE ldf_index < 10.
    ldf_index = ldf_index + 1.
  ENDWHILE.

 LOOP 命令を使用した、内部テーブルおよび抽出データセットに対するループ

ABAP
  DATA:
      LDT_ZSTUD TYPE TABLE OF ZSTUDENT001,
      LDS_ZSTUD LIKE LINE OF LDT_ZSTUD.
  
  LOOP AT ZSTUDENT001 INTO LDS_ZSTUD.
    WRITE / LDS_ZSTUD-ZNM001.
  ENDLOOP.

#4. 宣言

  • CONSTANTS:

  • TYPES:

  • DATA:
    image.png

  • SELECT-OPTIONS:

  • PARAMETERS:

#5. 内部テーブル&構造

image.png

image.png

##OPEN SQL
###1.データ読込
h-00100100000_SELECT.gif

ABAP

REPORT Z_SEL001.

DATA wa TYPE ZSTUDENT.

SELECT  *
  INTO  CORRESPONDING FIELDS OF wa
  FROM  ZSTUDENT
  WHERE ZNO001 EQ 'LH'.

  WRITE: / sy-dbcnt,
           wa-zno001, wa-znm001, wa-zsex001, wa-ZADDRESS001.

ENDSELECT.

###2.INSERT

ABAP
DATA: itab TYPE HASHED TABLE OF ZSTUDENT001
                WITH UNIQUE KEY zno001,
      wa LIKE LINE OF itab.

wa-zno001 = '100'. 
wa-znm001 = '田中太郎'. 

INSERT wa INTO TABLE itab.

wa-zno001 = '101'. 
wa-znm001 = '井上花子'. 

INSERT wa INTO TABLE itab.


INSERT ZSTUDENT001 FROM TABLE itab ACCEPTING DUPLICATE KEYS.

IF sy-subrc = 0.
  ...
ELSEIF sy-subrc = 4.
  ...
ENDIF.

###3.UPDATE

ABAP
UPDATE ZSTUDENT001 SET znm001 = '田中太郎1'
               WHERE zno001 = '100'.

###4.DELETE

ABAP
DELETE FROM ZSTUDENT001 WHERE zno001 = '100'.

###5.データの整合性

詳細

#ABAPサンプル

ABAP
*&---------------------------------------------------------------------*
*& Report  Z_STUD_001
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  Z_STUD_001.

DATA:
      GDW_ZSTUD TYPE ZSTUDENT001.

CONSTANTS:
  CNS_ON_FLG TYPE FLAG VALUE 'X',
  CNS_MAN    TYPE CHAR1 VALUE 'M',
  CNS_WOMAN  TYPE CHAR1 VALUE 'F'.

PARAMETERS:
  P_ZNO TYPE ZSTUDENT001-ZNO001 OBLIGATORY,
  P_ZNM TYPE ZSTUDENT001-ZNM001,
  P_ZSEX_F RADIOBUTTON GROUP GR1 DEFAULT 'X' USER-COMMAND COMMAND,
  P_ZSEX_M RADIOBUTTON GROUP GR1,
  P_ZCLASS TYPE ZSTUDENT001-ZCLASS001 NO-DISPLAY,
  P_ZBIRTH TYPE ZSTUDENT001-ZBIRTHDAY_DT001,
  P_ZADDR TYPE ZSTUDENT001-ZADDRESS001,
  P_ZCONT TYPE ZSTUDENT001-ZCONTACT001.

***********************************************************************
* 初期化
***********************************************************************
INITIALIZATION.


***********************************************************************
* 入力チェック
***********************************************************************
AT SELECTION-SCREEN.

***********************************************************************
* 実行(F8)
***********************************************************************
START-OF-SELECTION.


  PERFORM F_INPUT.

  PERFORM F_INSERT.


  WRITE  / GDW_ZSTUD.
***********************************************************************
* 終了
***********************************************************************
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*&      Form  F_INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM F_INPUT .
  IF P_ZSEX_F = CNS_ON_FLG.
    GDW_ZSTUD-ZSEX001 = CNS_WOMAN.
  ELSE.
    GDW_ZSTUD-ZSEX001 = CNS_MAN.
  ENDIF.

  GDW_ZSTUD-ZNO001 = P_ZNO.
  GDW_ZSTUD-ZNO001 = P_ZNO.
  GDW_ZSTUD-ZNM001 = P_ZNM.
  GDW_ZSTUD-ZBIRTHDAY_DT001 = P_ZBIRTH.
  GDW_ZSTUD-ZADDRESS001 = P_ZADDR.
  GDW_ZSTUD-ZCONTACT001 = P_ZCONT.
  GDW_ZSTUD-ZCREATE_DT001 = SY-DATUM.
  GDW_ZSTUD-ZCREATER001 = SY-UNAME.
  GDW_ZSTUD-ZUPDATE_DT001 = SY-DATUM.
  GDW_ZSTUD-ZUPDATER001 = SY-UNAME.
ENDFORM.                    " F_INPUT
*&---------------------------------------------------------------------*
*&      Form  F_INSERT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM F_INSERT .

  INSERT INTO ZSTUDENT001 VALUES GDW_ZSTUD.

ENDFORM.                    " F_INSERT

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

2
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?