Sunday, September 11, 2016

111. Dynamic function call abap program






REPORT zdynamic_call.

TYPE-POOLS : abap.

PARAMETER p_func TYPE c LENGTH 30.

DATA : gt_tab TYPE abap_func_parmbind_tab.
DATA : gs_line LIKE LINE OF gt_tab.
DATA : gs_import_para TYPE rsfbpara.
DATA : day_in TYPE d.
DATA : last_day_of_month TYPE d.

FIELD-SYMBOLS <fs> TYPE any.

GET REFERENCE OF day_in INTO gs_line-value.

day_in = '20160910'.
gs_line-name = 'DAY_IN'.
gs_line-kind = abap_func_exporting.
INSERT gs_line INTO TABLE gt_tab.


GET REFERENCE OF last_day_of_month INTO gs_line-value.
gs_line-name = 'LAST_DAY_OF_MONTH'.
gs_line-kind = abap_func_importing.
INSERT gs_line INTO TABLE gt_tab.

CAL FUNCTION p_func PARAMETER-TABLE gt_tab.
BREAK-POINT.

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


Friday, March 13, 2015

108. ABAP TIP - Popup Screen





Chapter 108
ABAP TIP - Popup Screen
Source : http://abapjoy.blogspot.com


Normally, we use the function POPUP_GET_VALUES to implement popup, but there is a limitation when adding a radio button, checkbox like a below screen. For this demands, you can make it using the class cl_ci_query_attributes.



REPORT zpopup_screen.

START-OF-SELECTION.
  PERFORM call_popup.


FORM call_popup.

  TABLES : sflight.

  DATA: lv_carrid TYPE s_carr_id,
        lt_werks TYPE gds_selrange_werks_tab,
        lv_check TYPE xfeld,
        lv_radio1 TYPE xfeld,
        lv_radio2 TYPE xfeld.

  DATA : lt_att TYPE sci_atttab ,
         ls_att TYPE sci_attent.

  DATA : l_ref TYPE REF TO data.

  CREATE DATA l_ref TYPE REF TO xfeld.


* parameters
  GET REFERENCE OF lv_carrid INTO l_ref.
  ls_att-kind = 'S'.
  ls_att-text = 'Parameter'.
  ls_att-obligatory = 'Y'.
  ls_att-ref = l_ref.
  APPEND ls_att TO lt_att.

* SELECT-OPTIONS
  GET REFERENCE OF lt_werks INTO l_ref.
  ls_att-kind = 'S'.
  ls_att-text = 'Select Option'.
  ls_att-ref = l_ref.
  APPEND ls_att TO lt_att.

* Check box
  GET REFERENCE OF lv_check INTO l_ref.
  ls_att-kind = 'C'.
  ls_att-text = 'Check box'.
  ls_att-ref = l_ref.
  APPEND ls_att TO lt_att.


* Radio button
  GET REFERENCE OF lv_radio1 INTO l_ref.
  ls_att-kind = 'R'.
  ls_att-text = 'Radio 1'.
  ls_att-button_group = 'MOD'.
  ls_att-ref = l_ref.
  APPEND ls_att TO lt_att.

  GET REFERENCE OF lv_radio2 INTO l_ref.
  ls_att-kind = 'R'.
  ls_att-text = 'Radio 2'.
  ls_att-button_group = 'MOD'.
  ls_att-ref = l_ref.
  APPEND ls_att TO lt_att.


  CALL METHOD cl_ci_query_attributes=>generic
    EXPORTING
      p_name       = 'TEST'
      p_title      = 'TEST2'
      p_attributes = lt_att
*    p_message    =
      p_display    = ''
*  receiving
*    p_break      =
      .

  BREAK-POINT.


ENDFORM.                   

After execution program, enter the value like below.

And you can see the variable value in debugger. That is, the data you entered in the popup screen.

Please, note that you should create range table type first for select-options.

Lets see the structure in T-CODE:SE11

gds_selrange_werks_tab





Monday, March 9, 2015

107.ABAP TIP - Field Exit





Chapter 107
ABAP TIP - Field Exit
Source : http://abapjoy.blogspot.com


Field Exit enables individual column of standard program to add extra logic.
For example, You can customize the some column in T-CODE:MK02(VENDOR MASTER).
Especially, its very useful you need to enable only the corresponding table when occurring error.
But, simply if you want to restrict the values in column, you can use the feather of domain fixed value append.



Lets find out the data element name in the technical information of the column we want to customize.


Perform T-CODE:SE38 and enter 'RSMODPRF'.


Enter the data element name you already checked before.
Note that if it is first time to create field exit for the column, you should not enter the number of field exit.

Now we can program for the field exit and activate.


Re-execute program leaving all columns blank.

Choose the line and push the menu : field exit -> assign prog/screen.

Enter the program name and screen name that we want to customize. You can figure out in menu : SYSTEM -> STATUS.


And, activate the field exit.



Now, once you input the unavailable value in column, you can see the error message like below.