ABAP New open SQL

気まぐれですが、現在お仕事で使っているABAPについて、メモを残していこうと思います。
基本コンセプトとして、「モダンなソース」を書くように心がけようと思っています。

ABAPのバージョンも7.4になったし、
SAP提唱の「Code to Data」「Code Pushdown」(つまり、Databaaeに負荷をかける)を意識します。

私が使っている「ちょっとSQLを試し書きして動かす」ツールを紹介します。
※SAP HANA環境だと、HDB StudioのSQL Consoleが使えるから助かるんだけれど、
→TRCD:DB01っていうのがありますね。
  あれ入れるほどでもないし、Non HANA環境だと使えないし、権限設定とかいろいろ...

少しプログラムを改変しました。(20171018)
少しプログラムを改変しました。(20170926)
少しプログラムを改変しました。(20181022)


L001:*&---------------------------------------------------------------------*
L002:*& Report Y_SQL_CONSOLE
L003:*&---------------------------------------------------------------------*
L004:*&
L005:*&---------------------------------------------------------------------*
L006:REPORT Y_SQL_CONSOLE.
L007:
L008:*-----------------------------------------------------------------------
L009:* GLOBAL VARIABLE
L010:*-----------------------------------------------------------------------
L011:DATA GDF_SUBRC TYPE SY-SUBRC.
L012:
L013:*-----------------------------------------------------------------------
L014:* CONDITION VIEW
L015:*-----------------------------------------------------------------------
L017:DATA GDF_CHAR1 TYPE CHAR10.
L018:TYPES GTR_CHAR1 LIKE RANGE OF GDF_CHAR1.
L019:SELECT-OPTIONS S_CHAR1 FOR GDF_CHAR1.
L020:
L021:DATA GDF_CHAR2 TYPE CHAR10.
L022:TYPES GTR_CHAR2 LIKE RANGE OF GDF_CHAR2.
L023:SELECT-OPTIONS S_CHAR2 FOR GDF_CHAR2.
L024:
L025:DATA GDF_NUMC1 TYPE NUMC08.
L026:TYPES GTR_NUMC1 LIKE RANGE OF GDF_NUMC1.
L027:SELECT-OPTIONS S_NUMC1 FOR GDF_NUMC1.
L028:
L029:DATA GDF_NUMC2 TYPE NUMC08.
L030:TYPES GTR_NUMC2 LIKE RANGE OF GDF_NUMC2.
L031:SELECT-OPTIONS S_NUMC2 FOR GDF_NUMC2.
L032:
L033:DATA GDF_DATS1 TYPE DATS.
L034:TYPES GTR_DATS1 LIKE RANGE OF GDF_DATS1.
L035:SELECT-OPTIONS S_DATS1 FOR GDF_DATS1.
L036:
L037:DATA GDF_DATS2 TYPE DATS.
L038:TYPES GTR_DATS2 LIKE RANGE OF GDF_DATS2.
L039:SELECT-OPTIONS S_DATS2 FOR GDF_DATS2.
L040:
L041:DATA GDF_TIMS1 TYPE TIMS.
L042:TYPES GTR_TIMS1 LIKE RANGE OF GDF_TIMS1.
L043:SELECT-OPTIONS S_TIMS1 FOR GDF_TIMS1.
L044:
L045:DATA GDF_TIMS2 TYPE TIMS.
L046:TYPES GTR_TIMS2 LIKE RANGE OF GDF_TIMS2.
L047:SELECT-OPTIONS S_TIMS2 FOR GDF_TIMS2.
L048:
L049:*-----------------------------------------------------------------------
L050:* START-OF-SELECTION
L051:*-----------------------------------------------------------------------
L052:START-OF-SELECTION.
L053: PERFORM START_OF_SELECTION
L054: USING
L055: S_CHAR1[]
L056: S_CHAR2[]
L057: S_NUMC1[]
L058: S_NUMC2[]
L059: S_DATS1[]
L060: S_DATS2[]
L061: S_TIMS1[]
L062: S_TIMS2[]
L063: CHANGING
L064: GDF_SUBRC.
L065:
L066:*-----------------------------------------------------------------------
L067:* SUBROUTINE
L068:*-----------------------------------------------------------------------
L069:FORM START_OF_SELECTION
L070: USING
L071: PIR_CHAR1 TYPE GTR_CHAR1
L072: PIR_CHAR2 TYPE GTR_CHAR2
L073: PIR_NUMC1 TYPE GTR_NUMC1
L074: PIR_NUMC2 TYPE GTR_NUMC2
L075: PIR_DATS1 TYPE GTR_DATS1
L076: PIR_DATS2 TYPE GTR_DATS2
L077: PIR_TIMS1 TYPE GTR_TIMS1
L078: PIR_TIMS2 TYPE GTR_TIMS2
L079: CHANGING
L080: POF_SUBRC TYPE SY-SUBRC.
L081:*-----------------------------------------------------------------------
L082:* Please write the SQL statement here ☆
L083:* Set the internal table to be stored to LDT_DATA ☆
L084:* Inline definition of LDT_DATA is fun ☆
L085: SELECT * FROM T001 INTO TABLE @DATA(LDT_DATA).
L086:*-----------------------------------------------------------------------
L087: TRY.
L088: CL_SALV_TABLE=>FACTORY(
L089: IMPORTING
L090: R_SALV_TABLE = DATA(LDO_ALV)
L091: CHANGING
L092: T_TABLE = LDT_DATA ).
L093: CATCH CX_SALV_MSG INTO DATA(LDX_SALV_MSG).
L094: POF_SUBRC = 8.
L095: RETURN.
L096: ENDTRY.
L097: DATA(LDO_FUNCTIONS) = LDO_ALV->GET_FUNCTIONS( ).
L098: LDO_FUNCTIONS->SET_ALL( ).
L099: DATA(LDO_SELECTIONS) = LDO_ALV->GET_SELECTIONS( ).
L100: LDO_SELECTIONS->SET_SELECTION_MODE(
L101: EXPORTING
L102: VALUE = IF_SALV_C_SELECTION_MODE=>MULTIPLE ).
L103: LDO_ALV->DISPLAY( ).
L104:
L105: POF_SUBRC = 0.
L106:ENDFORM.
おまけ
息苦しいほどタイトな演奏です。

Brian Culbertson- Back in the Day & So Good

検索キーワード
ABAP
ABAP 7.4
ABAP 7.40
ABAP 7.5
ABAP 7.50
SQL
Open SQL
New Open SQL
SAP HANA
Code to Data
Code Pushdown

以上