ALV Template - docking

1nsoo·2021년 8월 1일
0

ABAP

목록 보기
3/3

자주 사용하는 ALV의 템플릿을 만들어 놓자.

기본적인 INCLUDE는 생략하고, 메인 로직을 작성해보자

PBO에 ALV관련 로직을 모듈로 만들어 준다.

MODULE SET_ALV_0100 OUTPUT.

  IF GO_DOCKING IS INITIAL.
* INSTANCE 생성
    PERFORM CREATE_OBJECT.

* 출력필드 셋팅
    PERFORM SET_FIELDCAT.

* LAYOUT 셋팅
    PERFORM SET_LAYOUT.

* ALV 호출
    PERFORM DISPLAY_ALV.

  ELSE.
    "REFRESH
    PERFORM REFRESH_ALV.

  ENDIF.

ENDMODULE.

INSTANCE구현 로직

FORM CREATE_OBJECT .

  CREATE OBJECT GO_DOCKING
    EXPORTING
*      SIDE                        = GO_DOCKING->DOCK_AT_LEFT
      SIDE                        = CL_GUI_DOCKING_CONTAINER=>DOCK_AT_LEFT
      EXTENSION                   = CL_GUI_DOCKING_CONTAINER=>WS_MAXIMIZEBOX.

  CREATE OBJECT GO_GRID
    EXPORTING
      I_PARENT = GO_DOCKING.

ENDFORM.

출력하고자 하는 필드카탈로그 생성

FORM SET_FIELDCAT .

  CLEAR GT_FIELDCAT.

  CLEAR GS_FIELDCAT.
  GS_FIELDCAT-FIELDNAME = 'MATNR'.
  GS_FIELDCAT-COLTEXT   = '자재코드'.
  GS_FIELDCAT-KEY       = 'X'.
  GS_FIELDCAT-REF_TABLE = 'MARA'.
  APPEND GS_FIELDCAT TO GT_FIELDCAT.

  CLEAR GS_FIELDCAT.
  GS_FIELDCAT-FIELDNAME = 'MTART'.
  GS_FIELDCAT-COLTEXT   = '자재유형'.
  GS_FIELDCAT-REF_TABLE = 'MARA'.
  APPEND GS_FIELDCAT TO GT_FIELDCAT.

  CLEAR GS_FIELDCAT.
  GS_FIELDCAT-FIELDNAME = 'MATKL'.
  GS_FIELDCAT-COLTEXT   = '자재그룹'.
  GS_FIELDCAT-REF_TABLE = 'MARA'.
  APPEND GS_FIELDCAT TO GT_FIELDCAT.

ENDFORM.

사용하고자 하는 ALV 특성 세팅

FORM SET_LAYOUT .

  CLEAR GS_LAYOUT.

  GS_LAYOUT-CWIDTH_OPT = 'A'.   "열너비 최적화
  GS_LAYOUT-SEL_MODE   = 'D'.   "멀티행선택, 셀값 드래그 가능
  GS_LAYOUT-ZEBRA      = 'X'.   "행별 색상전화

ENDFORM.

ALV호출 로직

FORM DISPLAY_ALV .

  CALL METHOD GO_GRID->SET_TABLE_FOR_FIRST_DISPLAY
    EXPORTING
*     I_BUFFER_ACTIVE =
*     I_BYPASSING_BUFFER            =
*     I_CONSISTENCY_CHECK           =
*     I_STRUCTURE_NAME              =
*     IS_VARIANT      =
*     I_SAVE          =
*     I_DEFAULT       = 'X'
      IS_LAYOUT       = GS_LAYOUT
*     IS_PRINT        =
*     IT_SPECIAL_GROUPS             =
*     IT_TOOLBAR_EXCLUDING          =
*     IT_HYPERLINK    =
*     IT_ALV_GRAPHICS =
*     IT_EXCEPT_QINFO =
*     IR_SALV_ADAPTER =
    CHANGING
      IT_OUTTAB       = GT_DISP
      IT_FIELDCATALOG = GT_FIELDCAT
*     IT_SORT         =
*     IT_FILTER       =
*    EXCEPTIONS
*     INVALID_PARAMETER_COMBINATION = 1
*     PROGRAM_ERROR   = 2
*     TOO_MANY_LINES  = 3
*     OTHERS          = 4
    .
  IF SY-SUBRC <> 0.
*   Implement suitable error handling here
  ENDIF.

ENDFORM.

자주 사용하는 REFRESH 기능

FORM REFRESH_ALV .

  CALL METHOD GO_GRID->REFRESH_TABLE_DISPLAY.

ENDFORM.
profile
Junior Developer

0개의 댓글