[9기 SAP방] ABAP으로 ALV 조회하는법 따라하기

ORACLE virtual 머신을 구동시켜 sap trial server로 abap 프로그램 공부 가능합니다.

링크 https://wikidocs.net/229943 클릭

상세한 내용은 교재에 나와있습니다. 교재를보시고 그대로 따라하시면 됩니다.

se38 티코드를 입력하고 zedu19_0020 명으로 프로그램을 생성한후

다음 소스코드를 복사해서 붙여넣기 하면 됩니다.


*주의 -SAP 버전마다 다르니 SELECT 소스코드는 각버전에 맞게 수정바랍니다.

CopySELECT * FROM SFLIGHT WHERE CARRID IN @S_CARRID
*  INTO TABLE @DATA(LT_ITAB).
INTO CORRESPONDING FIELDS OF TABLE @GT_ITAB[].

"위에 SELECT 조회가 안되면 아래와 같이 소스코드 변경바랍니다.
"SAP 버전 또는 사용하는 DB마다 다르다보니 ORACLE DB, MYSQL DB 따라 
"차이가 있습니다.

*SELECT * FROM SFLIGHT
*  INTO CORRESPONDING FIELDS OF TABLE GT_ITAB
*  WHERE CARRID IN S_CARRID .


*&---------------------------------------------------------------------*
*& Report ZEDU19_0020_2
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*


TABLES : scarr.
TABLES : SSCRFIELDS.

"ALV
DATA : GO_ALV TYPE REF TO CL_GUI_ALV_GRID. "ALV
DATA : GO_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER. "DETAL

DATA : GS_LAYOUT TYPE LVC_S_LAYO. "LAYOUT
*DATA : GS_FACT TYPE LVC_T_FCAT. "FIELD OPTION
DATA : GT_FCAT TYPE LVC_T_FCAT. "FIELD OPTION
DATA : GS_VARIANT TYPE DISVARIANT. "DEFAULT, USER VARIANCT
DATA: L_ABAP_SOURCE(132) TYPE C.  " 너비를 132자로 확장


DATA : OK_CODE TYPE SY-UCOMM.

DATA : GT_ITAB LIKE SFLIGHT OCCURS 0 WITH HEADER LINE. "ITAB AND STRUCT
"WORK AREA   "LVC 필트카다로그 펑션사용시 LIKE사용해야함




SELECTION-SCREEN FUNCTION KEY 1.

SELECTION-SCREEN BEGIN OF BLOCK b1.
  SELECT-OPTIONS : s_carrid for scarr-carrid.
  SElection-SCREEN end of block b1.

"PAI
AT SELECTION-SCREEN.
  IF SSCRFIELDS-UCOMM EQ 'FC01'.
    MESSAGE I001(ZABAP) WITH 'CLICK'.
    ENDIF.


"PBO
AT SELECTION-SCREEN OUTPUT.

  LOOP AT SCREEN.
IF SCREEN-NAME EQ 'S_CARRID-LOW'.
  SCREEN-INPUT = 1. "0 INACTIVE 1 ACTIVE
MODIFY SCREEN.
ENDIF.
  ENDLOOP.


INITIALIZATION.
s_carrid-low = 'aa'.
append s_carrid.

sscrfields-functxt_01 = icon_xls && 'EXCE'.

START-OF-SELECTION.
"SQL
SELECT * FROM SFLIGHT WHERE CARRID IN @S_CARRID
*  INTO TABLE @DATA(LT_ITAB).
INTO CORRESPONDING FIELDS OF TABLE @GT_ITAB[].

end-of-SELECTION.

IF GT_ITAB[] IS INITIAL.
  MESSAGE S001(ZABAP) WITH 'NODATA'.
  ELSE.
*    CL_DEMO_OUTPUT=>DISPLAY( LT_ITAB[] ).

    CALL SCREEN 100.

  ENDIF.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
  "PBO
MODULE STATUS_0100 OUTPUT.
 SET PF-STATUS 'PBO_0100'.  "STANDARD , APPLICATION TOOLBAR
 SET TITLEBAR 'PBO_0100'. "ALV TITLE BAR
ENDMODULE.

*&---------------------------------------------------------------------*
*& Module ALV_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE ALV_0100 OUTPUT.
* SET PF-STATUS 'xxxxxxxx'.
* SET TITLEBAR 'xxx'.

  DATA: LT_FCAT TYPE SLIS_T_FIELDCAT_ALV.

  "SCREED PBO

  "CONTAINER SETTING
  CREATE OBJECT GO_CONTAINER
  EXPORTING
    CONTAINER_NAME = 'CON100'.

  "ALV GRID SETTING
  CREATE OBJECT GO_ALV
  EXPORTING
    I_PARENT = GO_CONTAINER.

  "FIELD CATALOG
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
 EXPORTING
   I_PROGRAM_NAME               = SY-REPID
   I_INTERNAL_TABNAME           = 'GT_ITAB'
*   I_STRUCTURE_NAME             =
*   I_CLIENT_NEVER_DISPLAY       = 'X'
   I_INCLNAME                   = SY-REPID
*   I_BYPASSING_BUFFER           =
*   I_BUFFER_ACTIVE              =
  CHANGING
    CT_FIELDCAT                  = LT_FCAT[]
 EXCEPTIONS
   INCONSISTENT_INTERFACE       = 1
   PROGRAM_ERROR                = 2
   OTHERS                       = 3
          .
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

  "FUNCTION ALV - FIELD CATA -> CLASS ALV - FIELD CATA 변환

  CALL FUNCTION 'LVC_TRANSFER_FROM_SLIS'
  EXPORTING
    IT_FIELDCAT_ALV       = LT_FCAT
*   IT_SORT_ALV           =
*   IT_FILTER_ALV         =
*   IS_LAYOUT_ALV         =
 IMPORTING
   ET_FIELDCAT_LVC       = GT_FCAT
*   ET_SORT_LVC           =
*   ET_FILTER_LVC         =
*   ES_LAYOUT_LVC         =
  TABLES
    IT_DATA               = GT_ITAB
 EXCEPTIONS
   IT_DATA_MISSING       = 1
   OTHERS                = 2
.

  "ALV LAYOUT
  GS_LAYOUT-SEL_MODE = 'A'.

  "ALV PRINT


  CALL METHOD GO_ALV->SET_TABLE_FOR_FIRST_DISPLAY
    EXPORTING                                      "FIEDL CAT 사용시 주석처리
*      I_BUFFER_ACTIVE               =
*      I_BYPASSING_BUFFER            =
*      I_CONSISTENCY_CHECK           =
*      I_STRUCTURE_NAME              = 'sflight'     "FIEDL CAT 사용시 주석처리
      IS_VARIANT                    = GS_VARIANT
      I_SAVE                        = 'A'
      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_ITAB[]
      IT_FIELDCATALOG               = GT_FCAT[]
*      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.





ENDMODULE.
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
"PAI
MODULE USER_COMMAND_0100 INPUT.
  CASE OK_CODE.
    WHEN 'BACK' OR 'EXIT' OR 'CANC'.
      LEAVE TO SCREEN 0.
*    WHEN .
    WHEN OTHERS.
  ENDCASE.

ENDMODULE.

cx_sy_read_src_line_too_long sap abap 에러메세지

혹시나 에러가 날수있습니다. 에러가 나면 아래 내용대로 조치하시면 됩니다.


에러 내용은 챗지피티에 물어보았습니다. 그래서 오류를 해결하였습니다.

이상입니다.


#9기 SAP방

2
2개의 답글

👉 이 게시글도 읽어보세요

모집 중인 AI 스터디