본문 바로가기
ABAP

ALV F4 (Possible entry)

by clode 2023. 2. 21.
728x90
반응형

ALV에 F4 등록

alv first display 이전에 perform해준다.

PERFORM SET_F4_FIELD_0100.

FORM SET_F4_FIELD_0100 .

  DATA(LT_F4) = VALUE LVC_T_F4( REGISTER = GC_X ( FIELDNAME = 'INSPCHAR' )
                               ).

  CALL METHOD GO_GRID_100->REGISTER_F4_FOR_FIELDS
    EXPORTING
      IT_F4 = LT_F4[].

ENDFORM.

Method 등록

    METHODS: HANDLE_ON_F4
      FOR EVENT ONF4 OF CL_GUI_ALV_GRID
      IMPORTING E_FIELDNAME   E_FIELDVALUE ES_ROW_NO
                ER_EVENT_DATA ET_BAD_CELLS E_DISPLAY.
  METHOD HANDLE_ON_F4.
    PERFORM HANDLE_ON_F4 USING E_FIELDNAME
                               E_FIELDVALUE
                               ES_ROW_NO
                               ER_EVENT_DATA
                               ET_BAD_CELLS
                               E_DISPLAY.
  ENDMETHOD.          

핸들러 등록

  SET HANDLER LO_EVENT->HANDLE_ON_F4         FOR PO_GRID. 

필드카탈로그에 F4 사용하겠다고 값 넣기

LS_FCAT-F4AVAILABL = GC_X.

이벤트 구현

FORM HANDLE_ON_F4  USING PV_FIELDNAME   TYPE LVC_FNAME
                         PV_FIELDVALUE  TYPE LVC_VALUE
                         PS_ROW_NO      TYPE LVC_S_ROID
                         PO_EVENT_DATA  TYPE REF TO CL_ALV_EVENT_DATA
                        PT_BAD_CELLS TYPE LVC_T_MODI
                         PV_DISPLAY     TYPE CHAR01.

  DATA : LV_OUTPUT(10).

  FIELD-SYMBOLS : <FS_F4> TYPE LVC_T_MODI. "data changed를 위해
  ASSIGN PO_EVENT_DATA->M_DATA->* TO <FS_F4>.

  DATA : LT_RETURN TYPE TABLE OF DDSHRETVAL WITH HEADER LINE.

  CLEAR : LT_RETURN[], LV_OUTPUT.

  CASE PV_FIELDNAME.
    WHEN 'INSPCHAR'.

      SELECT DISTINCT INSPCHAR, INSPCHART
        INTO TABLE @DATA(LT_INSPCHAR)
        FROM ZQMAT1200
        ORDER BY INSPCHAR.

      CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
        EXPORTING
          RETFIELD   = GC_INSPCHAR
          DYNPPROG   = SY-REPID
          DYNPNR     = SY-DYNNR
          VALUE_ORG  = GC_S
        TABLES
          VALUE_TAB  = LT_INSPCHAR
          RETURN_TAB = LT_RETURN.

    "자릿수 변환
      READ TABLE LT_RETURN INDEX 1.
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          INPUT  = LT_RETURN-FIELDVAL
        IMPORTING
          OUTPUT = LV_OUTPUT.

      "ALV에 적용
        READ TABLE GT_S0100 INTO DATA(LS_S0100)  INDEX PS_ROW_NO-ROW_ID.
        IF SY-SUBRC = 0.
          LS_S0100-INSPCHAR = LV_OUTPUT.
          MODIFY GT_S0100 FROM LS_S0100 INDEX PS_ROW_NO-ROW_ID TRANSPORTING INSPCHAR.

        DATA(LS_MODI) = VALUE LVC_S_MODI( ROW_ID = PS_ROW_NO-ROW_ID
                                                                                                    FIELDNAME = GC_INSPCHAR
                                                                                                    VALUE = LT_RETURN-FIELDVAL ).

          APPEND LS_MODI TO <FS_F4>.
        ENDIF.

  ENDCASE.

  PO_EVENT_DATA->M_EVENT_HANDLED =  GC_X. "꼭 써주어야 함

ENDFORM.

data changed 부분

F4로 값을 선택하자마자 ALV 필드에 값이 들어가야 하기때문

FIELD-SYMBOLS <fs_f4>.
lt_mod[] = p_data_changed->mt_mod_cells[].
728x90
반응형

'ABAP' 카테고리의 다른 글

Dynamic table Calculation  (0) 2023.02.21
RANGES 변수  (0) 2023.02.21
Maintenance View Call Function  (0) 2023.02.21
OLE  (0) 2023.02.21
금액 텍스트 변환 Function  (0) 2023.02.21

댓글