Tuesday, April 7, 2015

109.ABAP Tip - Dynamic Selection screen

Chapter 109
Dynamic Selection screen

출처 : http://www.sapjoy.co.kr  by e-abap(김성준)


Let's develop a program which can expand/close the columns in selection screen when user click the button.



*&---------------------------------------------------------------------*
*& Report  ZDYNAMIC_SEL
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zdynamic_sel.

INCLUDE <icon>.
TABLES: sscrfields, scarr.

DATA: v_stat_cr  TYPE char1.   " O-Open, C-Closed, V-Closed with Value.
DATA: v_value  TYPE flag.
DATA : gt_scarr TYPE TABLE OF scarr WITH HEADER LINE.

CONSTANTS:  c_on  TYPE char1 VALUE '1',
            c_off TYPE char1 VALUE '0'.

CONSTANTS:
  BEGIN OF c_stat,
    open          TYPE char1 VALUE 'O',
    close         TYPE char1 VALUE 'C',
    close_val   TYPE char1 VALUE 'V',
  END   OF c_stat.


SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON (4) pb_cr USER-COMMAND u_cr.
SELECTION-SCREEN COMMENT 6(25) v_cr.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN: BEGIN OF BLOCK blk1 WITH FRAME TITLE text-t01.
SELECT-OPTIONS: s_carrid FOR scarr-carrid MODIF ID cr.

SELECTION-SCREEN: END   OF BLOCK blk1.


INITIALIZATION.
  v_cr  = 'Carrier ID'.

  MOVE c_stat-close TO: v_stat_cr.


  PERFORM set_icon USING v_stat_cr CHANGING pb_cr.


AT SELECTION-SCREEN OUTPUT.
  LOOP AT SCREEN.
    CASE screen-group1.
      WHEN 'CR'.
        IF v_stat_cr = c_stat-open.
          screen-active = c_on.
        ELSE.
          screen-active = c_off.
        ENDIF.
    ENDCASE.
    MODIFY SCREEN.
  ENDLOOP.
  PERFORM set_icon  USING v_stat_cr CHANGING pb_cr.


AT SELECTION-SCREEN.
  CASE sscrfields-ucomm.
    WHEN 'U_CR'.
      CLEAR v_value.
      IF s_carrid[] IS NOT INITIAL.
        v_value = 'X'.
      ENDIF.

      PERFORM set_stat USING v_value CHANGING v_stat_cr.

  ENDCASE.


START-OF-SELECTION.

  SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_scarr
    FROM scarr
    WHERE carrid IN s_carrid.

  LOOP AT gt_scarr.
    WRITE :/ gt_scarr-carrid, gt_scarr-carrname.
  ENDLOOP.


*&---------------------------------------------------------------------*
*&      Form  SET_ICON
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_V_STAT_CR  text
*      <--P_PB_CR  text
*----------------------------------------------------------------------*
FORM set_icon  USING    pv_stat
               CHANGING pb_cr.

  CASE pv_stat.
    WHEN c_stat-close.        pb_cr =  icon_data_area_expand.
    WHEN c_stat-open.         pb_cr =  icon_data_area_collapse.
    WHEN c_stat-close_val.  pb_cr =  icon_view_create. " ICON_status_best.
  ENDCASE.


ENDFORM.                    " SET_ICON
*&---------------------------------------------------------------------*
*&      Form  SET_STAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_v_value  text
*      <--P_V_STAT_CR  text
*----------------------------------------------------------------------*
FORM set_stat  USING    pv_value
               CHANGING pv_stat.

  IF pv_stat = c_stat-open.
    IF pv_value IS INITIAL.
      pv_stat = c_stat-close.
    ELSE.
      pv_stat = c_stat-close_val.
    ENDIF.
  ELSEIF ( pv_stat = c_stat-close
       OR  pv_stat = c_stat-close_val ).
    pv_stat = c_stat-open.
  ENDIF.


ENDFORM.                    " SET_STAT


No comments:

Post a Comment