abesehat

Wednesday, May 15, 2013

ABAP : Dynamic ITAB for Ranges

Example of ABAP Code Dynamic Internal Table - Ranges
*---------------------------------------------------------------------*
*      Form  f_ranges_str

*      By Oka Wirasatha
*---------------------------------------------------------------------*


form F_RANGES_STR
  using FV_FIELD
        FV_SIGN FV_OPTION FV_LOW FV_HIGH.
  type-pools:
    ABAP.

  data:
    GR_STRUCTDESCR    type ref to CL_ABAP_STRUCTDESCR,
    GR_TABLEDESCR     type ref to CL_ABAP_TABLEDESCR,
    GR_DATADESCR      type ref to CL_ABAP_DATADESCR,
    GR_TYPEDESCR      type ref to CL_ABAP_TYPEDESCR,
    GT_COMPONENTS     type ABAP_COMPONENT_TAB,
    GW_COMPONENT      type line of ABAP_COMPONENT_TAB,
    GR_WA             type ref to DATA,
    GR_TAB            type ref to DATA,
    LV_TEXT(20).

  field-symbols: <fs_wa> type any,
                 <fs_val> type any,
                 <fs_tab> type TABLE.
* determine components of structure -> GT_COMPONENTS
  move 'SIGN' to GW_COMPONENT-NAME.
  GW_COMPONENT-TYPE ?= CL_ABAP_ELEMDESCR=>GET_C( P_LENGTH = 1 ).
  insert GW_COMPONENT into table GT_COMPONENTS.

  move 'OPTION' to GW_COMPONENT-NAME.
  GW_COMPONENT-TYPE ?= CL_ABAP_ELEMDESCR=>GET_C( P_LENGTH = 2 ).
  insert GW_COMPONENT into table GT_COMPONENTS.

  move 'LOW' to GW_COMPONENT-NAME.
  GW_COMPONENT-TYPE ?= CL_ABAP_ELEMDESCR=>DESCRIBE_BY_NAME( FV_FIELD ).
  insert GW_COMPONENT into table GT_COMPONENTS.

  move 'HIGH' to GW_COMPONENT-NAME.
  GW_COMPONENT-TYPE ?= CL_ABAP_ELEMDESCR=>DESCRIBE_BY_NAME( FV_FIELD ).
  insert GW_COMPONENT into table GT_COMPONENTS.

* get structure descriptor -> GR_STRUCTDESCR
  GR_STRUCTDESCR ?= CL_ABAP_STRUCTDESCR=>CREATE( GT_COMPONENTS ).

* create work area of structure GR_STRUCTDESCR -> GR_WA
  create data GR_WA type handle GR_STRUCTDESCR.
  assign GR_WA->* to <fs_wa>.

  GR_DATADESCR ?= GR_STRUCTDESCR.
  GR_TABLEDESCR ?= CL_ABAP_TABLEDESCR=>CREATE( GR_DATADESCR ).

* Create dynmaic internal table
  create data GR_TAB type handle GR_TABLEDESCR.
  assign GR_TAB->* to <fs_tab>.

  assign component 'SIGN' of structure <fs_wa> to <fs_val>.
  = FV_SIGN.
  assign component 'OPTION' of structure <fs_wa> to <fs_val>.
  = FV_OPTION.
  assign component 'LOW' of structure <fs_wa> to <fs_val>.
  = FV_LOW.
  assign component 'HIGH' of structure <fs_wa> to <fs_val>.
  = FV_HIGH.

  insert <fs_wa> into table <fs_tab>.

  loop at T_ITEM.
    concatenate 'T_ITEM-' FV_FIELD into LV_TEXT.
    assign (LV_TEXT) to <fs_val>.
    if not <fs_val> in <fs_tab>.
      delete T_ITEM.
    endif.
  endloop.
endform.                    "f_ranges_str

ABAP Dialog Programming : Set Filter data of Table Control


Example ABAP code for Filter data of table control

*---------------------------------------------------------------------*
*      Form  F_filter_data
*---------------------------------------------------------------------*
*  By Oka Wirasatha
*---------------------------------------------------------------------*
form F_FILTER_DATA .
  field-symbols :
    <selected_col> type CXTAB_COLUMN.
  data : LW_COLS like TC_ITEM-COLS.
  data : GT_FIELDCAT type LVC_T_FCAT.
  data LAYO type LVC_S_LAYO.
  data : GT_FILTER_INDEX type LVC_T_FIDX,
         LT_SELCOL type table of LVC_S_COL with header line.
  data : LT_FILT type LVC_T_FILT,
         LW_FILT type LVC_S_FILT,
         LT_LAYOUT type LVC_S_LAYO.

* find out if a column is selected.
  loop at TC_ITEM-COLS assigning <selected_col>.
    if <selected_col>-SELECTED = 'X'.
      LT_SELCOL-FIELDNAME = <selected_col>-SCREEN-NAME+7(10).
      append LT_SELCOL.
    endif.
  endloop.

  call function 'LVC_FIELDCATALOG_MERGE'
    exporting
      I_STRUCTURE_NAME       = 'ZSMM_GRDM'
    changing
      CT_FIELDCAT            = GT_FIELDCAT
    exceptions
      INCONSISTENT_INTERFACE = 1
      PROGRAM_ERROR          = 2
      others                 = 99.

  if SY-SUBRC = 0 and not LT_SELCOL[] is initial.
    call function 'LVC_FILTER'
      exporting
        IT_FIELDCAT      = GT_FIELDCAT
        IT_SELECTED_COLS = LT_SELCOL[]
        IS_LAYOUT        = LT_LAYOUT
      importing
        ET_FILTER_INDEX  = GT_FILTER_INDEX
      tables
        IT_DATA          = T_ITEM "gt_subitems
      changing
        CT_FILTER        = LT_FILT
      exceptions
        others           = 0.
    if SY-SUBRC = 0.
      loop at LT_FILT into LW_FILT.
*     Filter data with dynamic Selected col
        perform F_RANGES_STR
          using LW_FILT-FIELDNAME
                LW_FILT-SIGN
                LW_FILT-OPTION
                LW_FILT-LOW
                LW_FILT-HIGH.
      endloop.
      if SY-SUBRC ne 0.
*        Fill default data to list
      endif.
    endif.
  endif.

endform.                    " F_filter_data

ABAP Dialog Programming : Sorting selected column in Table Control

This is example of abap code for sorting selected table control.

*---------------------------------------------------------------------*
*      Form  F_SORT_TABLE
*---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      By Oka Wirasatha
*----------------------------------------------------------------------*
form F_SORT_TABLE using FV_CODE.
  field-symbols :
    <lfs1>,
    <selected_col> type CXTAB_COLUMN.

  data : LW_COLS like TC_ITEM-COLS.
  data : LV_TXT1(20),
         LV_INDEX(2) type N.
  data : begin of W_SORT,
          SORT01(20),
          SORT02(20),
          SORT03(20),
          SORT04(20),
          SORT05(20),
          SORT06(20),
          SORT07(20),
    end of W_SORT.

* find out if a column is selected.
  LV_INDEX = 0.
  clear W_SORT.
  loop at TC_ITEM-COLS assigning <selected_col>.
    if <selected_col>-SELECTED = 'X'.
      LV_INDEX = LV_INDEX + 1.
      concatenate 'w_sort-sort' LV_INDEX into LV_TXT1.
      assign (LV_TXT1) to <lfs1>.
      <lfs1> = <selected_col>-SCREEN-NAME+7(10).
    endif.
  endloop.

  if not W_SORT is initial.
    if FV_CODE = 'ASC'.
      sort T_ITEM by (W_SORT-SORT01).
    else.
      sort T_ITEM descending by (W_SORT-SORT01).
    endif.
  else.
    message S000(ZMM) with 'No column is selected'.
  endif.

endform.                    " sort_table

Thursday, November 15, 2012

Problem SAP-SCRIPT line command too long

Sometimes your sap scripts command too long, how to covered this ?
Easy way is press shift+F8.


Wednesday, April 25, 2012

Dynamic Selection Screen Base on TCODE


SELECTION-SCREEN BEGIN OF BLOCK SO WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN,"Sales order number   
               S_VBELND FOR LIKP-VBELN,"Delivery number     
               S_VBELNI FOR VBRK-VBELN,"Invoice number      
               S_VBELNP FOR VBKD-BSTKD."PO number           
SELECTION-SCREEN END OF BLOCK SO.                            

*--- EVENT AT SCREEN OUTPUT -------------------------------
AT SELECTION-SCREEN OUTPUT.                                       
  CASE SY-TCODE.                                                  
    WHEN 'ZEDI6'.                                                 
      LOOP AT SCREEN.                                             
        CASE SCREEN-GROUP4.                                       
          WHEN '001'.                  "Sales order select        
            SCREEN-ACTIVE = '1'.       "1=Active, 0=Don't display 
            MODIFY SCREEN.                                        
          WHEN '002'.                  "Delivery select           
            SCREEN-ACTIVE = '0'.       "1=Active, 0=Don't display 
            MODIFY SCREEN.                                        
          WHEN '003'.                  "Invoice select             
            SCREEN-ACTIVE = '0'.       "1=Active, 0=Don't display 
            MODIFY SCREEN.                                        
          WHEN '004'.                  "PO Select                 
            SCREEN-ACTIVE = '0'.       "1=Active, 0=Don't display 
            MODIFY SCREEN.                                        
        ENDCASE.                                                  
      ENDLOOP.                                                    
   

Dynamic selection screens based on user input parameters

Dynamic selection screens based on user input parameters with dropdowns and execute button disabled.
The selection screen  push button does the functionality of the disabled execute button
REPORT  zsscr.

*TYPE POOLS DECLARATIONS FOR VALUE REQUEST MANAGER AND ICONS

TYPE-POOLS : vrm,
             icon.

*SELECTION SCREEN FIELDS
TABLES : sscrfields.

*GLOBAL DECLARATIONS

DATA : flag TYPE c,
      tablename(10),
      mmtable LIKE dd02l-tabname,
      sdtable LIKE dd02l-tabname,
      hrtable LIKE dd02l-tabname.

*DECLARATIONS FOR SELECTION SCREEN STATUS

DATA it_ucomm TYPE TABLE OF sy-ucomm.

**********SELECTION-SCREENS*********************