2011年3月31日 星期四

The Unit Conversion of Layout Set

The following conversion factors apply

Units of measurement: The following units of measurement may be used:

  • TW (twip)
  • PT (point)
  • IN (inch)
  • MM (millimeter)
  • CM (centimeter)
  • LN (line)
  • CH (character).

The following conversion factors apply:

  • 1 TW = 1/20 PT
  • 1 PT = 1/72 IN
  • 1 IN = 2.54 CM
  • 1 CM = 10 MM
  • 1 CH = height of a character relative to the CPI specification in the form header
  • 1 LN = height of a line relative to the LPI specification in the form header

System Bar Code and using it in SAPscript

A documentation on creating System Bar Code and using it in SAPscript layout for printing.

[Link] Smartforms - FAQ

Smartforms: Frequently Asked Questions

[Link] SAPScripts - FAQ

SAPScripts: Frequently Asked Questions

[Manual] Application Platform

SAP Web Application Server provides a complete development infrastructure on which you can develop, distribute, and execute platform-independent, robust, and scalable Web services and business applications. SAP Web Application Server supports ABAP, Java, and Web services.

COOIS 的報表


COOIS 裡面 submit 到底下這些報表:

PPIOA000                       訂單資訊系統﹕初始報表
PPIOB000                       訂單資訊系統﹕撿貨報表
PPIOC000                       訂單資訊系統﹕選擇報表
PPIOD000                       訂單資訊系統﹕詳細的清單報表 - 物料異動
PPIOE000                       訂單資訊系統﹕細節清單報表 - 觸發點
PPIOF000                       訂單資訊系統﹕PRT 明細清單報表
PPIOG000                       訂單資訊系統﹕自動貨物移動的明細清單報表
PPIOH000                       訂單資訊系統﹕訂單表頭的明細清單報表
PPIOI000                        訂單資訊系統﹕項目的明細清單報表
PPIOK000                       訂單資訊系統﹕產能明細清單報表
PPIOM000                       訂單資訊系統﹕元件的明細清單報表
PPIOO000                       訂單資訊系統﹕作業的明細清單報表
PPIOR000                       訂單資訊系統﹕確認的明細清單報表
PPIOS000                       訂單資訊系統﹕順序的明細清單報表
PPIOW000                      訂單資訊系統﹕錯誤貨物移動的明細清單報表

Enhance standard SM30 table maintain screen and flow


How to enhance standard SM30 table maintain screen and flow.
We known the SE11 can create table maintain screen, but the screen maybe too small, or maybe we did like to fulfill value to some fields automatically. If required you can follow these steps:
1:
If you propose to include extend fields from other table in the screen , and your table didn't store the value. ex., you only store customer number(KUNNR) but no customer name(NAME1). Then you need to create maintenance view.
Before you create maintenance view, don't forget to create foreign key to link your add-on table field and external table. ex., in case was customer number field(KUNNR) v.s KNA1.
2:
You can to go to create maintenance view use your add-on table as primary table. When you want to add other table into your maintenance view, you can do that in Tables/Join conditions tab page.
Place the cursor on the primary table and choose Relationships below. All existing foreign key relationships of the primary table are displayed. Select the required foreign key and choose Copy.
The secondary table used in such a foreign key is included in the view. The join conditions derived from the foreign keys are displayed.
3:
When you completed above actions, now you can create the maintenance view's maintain screen. At menu:
Unitilies->Table Maintenance Generator
4:
To be continue ... ]

SE16 Delete All


How can you to delete all records that whats you selected in se16 when that table disable maintenance ?
Follow the steps:
  1. Fulfill selection criteria of se16.
  2. Entry debug mode ( /h )
  3. Set break-point:
    • Subroutine: pf_status_liste
    • Subroutine:autho_check
  4. Set watch-point:
    • excl_tab-code = DEL5, DEL2
      • DEL5: Delete ALL
      • DEL2: Delete
    • dd02l-mainflag
  5. Press [F8] to Run program
  6. Delete records for internal table excl_tab what code eq DEL5 and DEL2 When got watchpoint, than can enable Delete ALL & Delete in menu item.
  7. Press [F8] to go.
  8. List records what match your criteria, then press select all 
  9. And entry debug mode (/h)
  10. Press [F8] to go.
  11. Modify the field dd02l-mainflag = ANYTHING to replace of space when you got break-point.

Comparing two ABAP Program


How to comparing two ABAP programs and show you the differences in both ABAP.

Transaction SE39 will do this.

2011年3月30日 星期三

[Link] Display images (like company logo) on the selection-screen

By Gaurab Banerji, Capgemini India (Example Program: SAP_PICTURE_DEMO, SAP_PICTURE_DEMO_DRAG_DROP, SAP_PICTURE_DEMO_ICON )

[Code] SubScreen

Defines the selection screen as tabbed views as subscreen
* ----------------
* SELECTION-SCREEN
* ----------------
SELECTION-SCREEN BEGIN OF SCREEN 100 AS SUBSCREEN.
  <put parameters or select-options in here>
SELECTION-SCREEN END OF SCREEN 100.

SELECTION-SCREEN BEGIN OF SCREEN 200 AS SUBSCREEN.
  <put parameters or select-options in here>
SELECTION-SCREEN END OF SCREEN 200.

SELECTION-SCREEN: BEGIN OF TABBED BLOCK mytab FOR 6 LINES,
                  TAB (20) text-t02 USER-COMMAND push1
                                   DEFAULT SCREEN 100,
                  TAB (20) text-t03 USER-COMMAND push2
                                   DEFAULT SCREEN 200,
                  END OF BLOCK mytab.

* --------------
* INITIALIZATION
* --------------
INITIALIZATION.
  IMPORT gv_flag FROM MEMORY ID 'ZPROGRAM'.
  IF gv_flag = '2'.
    mytab-dynnr = 200.
    mytab-activetab = 'PUSH2'.
  ELSE.
    gv_flag = '1'.
    mytab-dynnr = 100.
    mytab-activetab = 'PUSH1'.
  ENDIF.

* -------------------
* AT SELECTION-SCREEN
* -------------------
AT SELECTION-SCREEN.
  IF sscrfields-ucomm = 'PUSH1'.
    gv_flag = '1'.
  ELSEIF sscrfields-ucomm = 'PUSH2'.
    gv_flag = '2'.
  ENDIF.
  EXPORT gv_flag TO MEMORY ID 'ZPROGRAM'.

[Code] RADIOBUTTON

SELECTION-SCREEN RADIOBUTTON Example code
Example:
SELECTION-SCREEN BEGIN  OF LINE.
PARAMETERS: R_1A RADIOBUTTON GROUP RG1.
SELECTION-SCREEN COMMENT 6(30) FOR FIELD R_1A .
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: R_1B RADIOBUTTON GROUP RG1.
SELECTION-SCREEN COMMENT 6(30) FOR FIELD R_1B .
SELECTION-SCREEN END OF LINE.

[Code] Search Help For KSCHL

Customizing KSCHL search help with your request in report.

Defination:
DATA: BEGIN OF gt_t685 OCCURS 0,
kschl LIKE t685-kschl,
vtext LIKE t685t-vtext,
END OF gt_t685 .

DATA gw_dfies LIKE dfies .

DATA BEGIN OF gt_dfies OCCURS 0.
INCLUDE STRUCTURE dfies .
DATA END OF gt_dfies .

DATA BEGIN OF gt_dfies2 OCCURS 0.
INCLUDE STRUCTURE dfies .
DATA END OF gt_dfies2 .

DATA gv_repid LIKE sy-repid .
INITIALIZATION:
SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_t685
FROM t685t
WHERE spras = sy-langu
AND kvewe = 'A'
AND kappl = 'V'
AND kschl IN gr_kschl.

gv_repid = sy-repid .

CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = 'T685T'
fieldname = 'KSCHL'
langu = sy-langu
TABLES
dfies_tab = gt_dfies
EXCEPTIONS
not_found = 1
internal_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

LOOP AT gt_dfies INTO gw_dfies .
gw_dfies-position = 1 .
gw_dfies-offset = 0 .
APPEND gw_dfies TO gt_dfies2 .
ENDLOOP .

CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = 'T685T'
fieldname = 'VTEXT'
langu = sy-langu
TABLES
dfies_tab = gt_dfies
EXCEPTIONS
not_found = 1
internal_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

LOOP AT gt_dfies INTO gw_dfies .
gw_dfies-position = 2 .
gw_dfies-offset = 4 .
APPEND gw_dfies TO gt_dfies2 .
ENDLOOP .
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_kschl-low:
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'KSCHL'
dynpprog = gv_repid
dynpnr = '1000'
dynprofield = 'S_KSCHL-LOW'
value_org = 'S'
TABLES
value_tab = gt_t685[]
field_tab = gt_dfies2[]
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_kschl-high:
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'KSCHL'
dynpprog = gv_repid
dynpnr = '1000'
dynprofield = 'S_KSCHL-HIGH'
value_org = 'S'
TABLES
value_tab = gt_t685[]
field_tab = gt_dfies2[]
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.



Multi-Selection Search Help:
DATA: gt_return LIKE ddshretval OCCURS 0 WITH HEADER LINE,
gt_dfies LIKE dfies OCCURS 0 WITH HEADER LINE,
gt_dfies2 LIKE dfies OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF gt_brsch OCCURS 0,
brsch LIKE t016t-brsch,
brtxt LIKE t016t-brtxt,
kunnr LIKE komg-kunnr,
END OF gt_brsch.

DEFINE append_brsch.
clear: gt_brsch.
gt_brsch-brsch = &1.
gt_brsch-brtxt = &2.
gt_brsch-kunnr = &3.
append: gt_brsch.
END-OF-DEFINITION.



SELECT-OPTIONS:
s_brsch FOR komg-brsch NO INTERVALS.



*----------------
* INITIALIZATION
*----------------
INITIALIZATION.
gv_vrm_id = 'P_BRSCH'.
append_brsch 'K001' '中華' 'C1'.
append_brsch 'K002' '台哥大' 'C2'.
append_brsch 'K003' '遠傳' 'C3'.

* 設定產業碼 F4
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = 'T016T'
fieldname = 'BRSCH'
langu = sy-langu
TABLES
dfies_tab = gt_dfies
EXCEPTIONS
not_found = 1
internal_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

LOOP AT gt_dfies.
gt_dfies-position = 1 . " 第一個欄位
gt_dfies-offset = 0 .
APPEND gt_dfies TO gt_dfies2 .
ENDLOOP .

CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = 'T016T'
fieldname = 'BRTXT'
langu = sy-langu
TABLES
dfies_tab = gt_dfies
EXCEPTIONS
not_found = 1
internal_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

LOOP AT gt_dfies.
gt_dfies-position = 2 . " 第二個欄位
gt_dfies-offset = 4 . " 位置
APPEND gt_dfies TO gt_dfies2 .
ENDLOOP .


*--------------------
* AT SELECTION-SCREEN
*--------------------
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_brsch-low.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'BRSCH'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'S_BRSCH'
value_org = 'S'
multiple_choice = 'X' " 多重選取
TABLES
value_tab = gt_brsch
field_tab = gt_dfies2
return_tab = gt_return.
READ TABLE gt_return INDEX 1.
IF sy-subrc = 0.
CLEAR: s_brsch, s_brsch[].
s_brsch-sign = 'I'.
s_brsch-option = 'EQ'.
SORT gt_return DESCENDING.
LOOP AT gt_return.
s_brsch-low = gt_return-fieldval.
APPEND s_brsch.
ENDLOOP.
SORT s_brsch.
ENDIF.

[Code] Dropdown list field in ALV

How to create dropdown list field in ALV grid report.
DATA DEFINITION
TYPE-POOLS: slis, abap, icon.
INCLUDE <icons>.

CONSTANTS: icon_wd_radio_button_empty TYPE icon_l2 VALUE '@SR@'.

DATA: ok_code LIKE sy-ucomm,
save_ok LIKE sy-ucomm,
alv_container TYPE scrfname VALUE 'ALV_GRID_5000',
alv_grid TYPE REF TO cl_gui_alv_grid,
alv_custom_container TYPE REF TO cl_gui_custom_container,
alv_layout TYPE lvc_s_layo,
alv_field TYPE lvc_s_fcat,
alv_t_field TYPE lvc_t_fcat,
alv_exclude TYPE ui_functions,
alv_dropdown TYPE lvc_t_drop,
alv_variant TYPE disvariant.
INITIALIZATION:
* --------------
* INITIALIZATION
* --------------
INITIALIZATION.
alv_repid = sy-repid.
PERFORM alvdropdown.
Form - alvdropdown:
*&---------------------------------------------------------------------*
*& Form alvdropdown
*&---------------------------------------------------------------------*
FORM alvdropdown .
DATA: ls_dropdown TYPE lvc_s_drop.

* First listbox (handle '1').
ls_dropdown-handle = '1'.
ls_dropdown-value = gt_duty-duty = 'Sales'.
APPEND: ls_dropdown TO alv_dropdown, gt_duty.
ls_dropdown-value = gt_duty-duty = 'SD'.
APPEND: ls_dropdown TO alv_dropdown, gt_duty.
ls_dropdown-value = gt_duty-duty = 'PM'.
APPEND: ls_dropdown TO alv_dropdown, gt_duty.
ls_dropdown-value = gt_duty-duty = 'Shipping'.
APPEND: ls_dropdown TO alv_dropdown, gt_duty.
ls_dropdown-value = gt_duty-duty = 'Customer'.
APPEND: ls_dropdown TO alv_dropdown, gt_duty.
* Secend listbox (handle '2').
ls_dropdown-handle = '2'.
ls_dropdown-value = gt_reason-reason = '01.Order Cancel'.
APPEND: ls_dropdown TO alv_dropdown, gt_reason.
ls_dropdown-value = gt_reason-reason = '02.Reture Cancel'.
APPEND: ls_dropdown TO alv_dropdown, gt_reason.
ls_dropdown-value = gt_reason-reason = '03.Data Change(Typo)'.
APPEND: ls_dropdown TO alv_dropdown, gt_reason.
ls_dropdown-value = gt_reason-reason = '04.Channel Change'.
APPEND: ls_dropdown TO alv_dropdown, gt_reason.
ls_dropdown-value = gt_reason-reason = '05.Shipping Date Change'.
APPEND: ls_dropdown TO alv_dropdown, gt_reason.
ls_dropdown-value = gt_reason-reason = '06.Price Change'.
APPEND: ls_dropdown TO alv_dropdown, gt_reason.
ls_dropdown-value = gt_reason-reason = '07.Others'.
APPEND: ls_dropdown TO alv_dropdown, gt_reason.

ENDFORM. " alvdropdown
Print
*&---------------------------------------------------------------------*
*& Form data_print
*&---------------------------------------------------------------------*
FORM data_print.

CREATE OBJECT alv_custom_container
EXPORTING container_name = alv_container.
CREATE OBJECT alv_grid
EXPORTING i_parent = alv_custom_container.

PERFORM alvfield.
*
CALL METHOD alv_grid->set_drop_down_table
EXPORTING
it_drop_down = alv_dropdown.
* Alv_layout
alv_layout-box_fname = 'SELEC'.
alv_layout-cwidth_opt = 'X'.
alv_layout-stylefname = 'CELLTAB'.
alv_layout-info_fname = 'ROWCOLOR'.
* ALV_Variant
alv_variant-report = alv_repid.
alv_variant-username = sy-uname.

CALL METHOD alv_grid->set_table_for_first_display
EXPORTING
is_variant = alv_variant
i_save = 'A'
is_layout = alv_layout
it_toolbar_excluding = alv_exclude
CHANGING
it_fieldcatalog = alv_t_field
it_outtab = alv_itab[].

* Set editable cells to ready for input initially
CALL METHOD alv_grid->set_ready_for_input
EXPORTING
i_ready_for_input = 1.

ENDFORM. " data_print

*&---------------------------------------------------------------------*
*& Form alvfield
*&---------------------------------------------------------------------*
FORM alvfield .
DATA: lv_tabix LIKE sy-tabix,
it_fieldcat TYPE slis_t_fieldcat_alv.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = alv_repid
i_internal_tabname = 'ALV_ITAB'
i_inclname = alv_repid
CHANGING
ct_fieldcat = it_fieldcat.

CALL FUNCTION 'LVC_TRANSFER_FROM_SLIS'
EXPORTING
it_fieldcat_alv = it_fieldcat
IMPORTING
et_fieldcat_lvc = alv_t_field
TABLES
it_data = alv_itab.

LOOP AT alv_t_field INTO alv_field.
lv_tabix = sy-tabix.
CASE alv_field-fieldname.
WHEN 'DUTY'.
alv_field-scrtext_s = alv_field-scrtext_m =
alv_field-scrtext_l =
alv_field-reptext = 'Duty'.
alv_field-edit = 'X'.
alv_field-drdn_hndl = '1'.
alv_field-outputlen = 8 .
WHEN 'REASON'.
alv_field-scrtext_s = alv_field-scrtext_m =
alv_field-scrtext_l =
alv_field-reptext = 'Reason'.
alv_field-edit = 'X'.
alv_field-drdn_hndl = '2'.
alv_field-outputlen = 21 .
ENDCASE.
MODIFY alv_t_field FROM alv_field INDEX lv_tabix.
ENDLOOP.

ENDFORM. " alvfield

[Code] RadioButton in ALV

How to create radio button in alv grid report
DATA DEFINITION
TYPE-POOLS: slis, abap, icon.
INCLUDE <icons>.

CONSTANTS: icon_wd_radio_button_empty TYPE icon_l2 VALUE '@SR@'.

DATA: ok_code LIKE sy-ucomm,
save_ok LIKE sy-ucomm,
alv_container TYPE scrfname VALUE 'ALV_GRID_5000',
alv_grid TYPE REF TO cl_gui_alv_grid,
alv_custom_container TYPE REF TO cl_gui_custom_container,
alv_layout TYPE lvc_s_layo,
alv_field TYPE lvc_s_fcat,
alv_t_field TYPE lvc_t_fcat,
alv_exclude TYPE ui_functions,
alv_dropdown TYPE lvc_t_drop,
alv_variant TYPE disvariant.
Handler
*---------------------------------------------------------------------*
* CLASS alv_event_handler DEFINITION
*---------------------------------------------------------------------*
CLASS alv_event_handler DEFINITION.
PUBLIC SECTION.
METHODS: handle_hotspot_click
FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING
e_row_id
e_column_id
es_row_no.

ENDCLASS. "alv_event_handler

*---------------------------------------------------------------------*
* CLASS alv_event_handler IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS alv_event_handler IMPLEMENTATION.
* For Radio Button
METHOD handle_hotspot_click.
DATA fieldname TYPE lvc_fname.
DATA index LIKE sy-tabix.
DATA alv_s_itab LIKE alv_itab.
DATA ls_stable TYPE lvc_s_stbl.

fieldname = e_column_id-fieldname.
index = es_row_no-row_id.
READ TABLE alv_itab INDEX index INTO alv_s_itab.

CASE fieldname.
WHEN 'SHIPY'.
IF alv_s_itab-shipy = icon_wd_radio_button_empty.
alv_s_itab-shipy = icon_radiobutton.
alv_s_itab-shipn = icon_wd_radio_button_empty.
ENDIF.
WHEN 'SHIPN'.
IF alv_s_itab-shipn = icon_wd_radio_button_empty.
alv_s_itab-shipn = icon_radiobutton.
alv_s_itab-shipy = icon_wd_radio_button_empty.
ENDIF.
ENDCASE.
MODIFY alv_itab FROM alv_s_itab INDEX index.

CLEAR ls_stable.
ls_stable-col = 'X'.
CALL METHOD alv_grid->refresh_table_display
EXPORTING
is_stable = ls_stable.
ENDMETHOD. "handle_hotspot_click

ENDCLASS. "alv_event_handler IMPLEMENTATION
Event - INITIALIZATION:
* --------------
* INITIALIZATION
* --------------
INITIALIZATION.
alv_repid = sy-repid.
Print
*&---------------------------------------------------------------------*
*& Form data_print
*&---------------------------------------------------------------------*
FORM data_print.

CREATE OBJECT alv_custom_container
EXPORTING container_name = alv_container.
CREATE OBJECT alv_grid
EXPORTING i_parent = alv_custom_container.

PERFORM alvfield.
PERFORM alvevent.
* Alv_layout
alv_layout-box_fname = 'SELEC'.
alv_layout-cwidth_opt = 'X'.
alv_layout-stylefname = 'CELLTAB'.
alv_layout-info_fname = 'ROWCOLOR'.
* ALV_Variant
alv_variant-report = alv_repid.
alv_variant-username = sy-uname.

CALL METHOD alv_grid->set_table_for_first_display
EXPORTING
is_variant = alv_variant
i_save = 'A'
it_toolbar_excluding = alv_exclude
is_layout = alv_layout
CHANGING
it_fieldcatalog = alv_t_field
it_outtab = alv_itab[].

* Set editable cells to ready for input initially
CALL METHOD alv_grid->set_ready_for_input
EXPORTING
i_ready_for_input = 1.

ENDFORM. " data_print

*&---------------------------------------------------------------------*
*& Form alvfield
*&---------------------------------------------------------------------*
FORM alvfield .
DATA: lv_tabix LIKE sy-tabix,
it_fieldcat TYPE slis_t_fieldcat_alv.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = alv_repid
i_internal_tabname = 'ALV_ITAB'
i_inclname = alv_repid
CHANGING
ct_fieldcat = it_fieldcat.

CALL FUNCTION 'LVC_TRANSFER_FROM_SLIS'
EXPORTING
it_fieldcat_alv = it_fieldcat
IMPORTING
et_fieldcat_lvc = alv_t_field
TABLES
it_data = alv_itab.

LOOP AT alv_t_field INTO alv_field.
lv_tabix = sy-tabix.
CASE alv_field-fieldname.
WHEN 'SHIPY'.
alv_field-scrtext_s = alv_field-scrtext_m =
alv_field-scrtext_l =
alv_field-reptext = 'Shipped'.
alv_field-outputlen = 6.
alv_field-icon = 'X'.
alv_field-hotspot = 'X'.
WHEN 'SHIPN'.
alv_field-scrtext_s = alv_field-scrtext_m =
alv_field-scrtext_l =
alv_field-reptext = 'Non-ship'.
alv_field-outputlen = 6.
alv_field-icon = 'X'.
alv_field-hotspot = 'X'.
ENDCASE.
MODIFY alv_t_field FROM alv_field INDEX lv_tabix.
ENDLOOP.

ENDFORM. " alvfield

*&---------------------------------------------------------------------*
*& Form alvevent
*&---------------------------------------------------------------------*
FORM alvevent .
IF alv_t_events IS INITIAL.
CREATE OBJECT alv_t_events.
ENDIF.

SET HANDLER alv_t_events->handle_hotspot_click FOR alv_grid.
ENDFORM. " alvevent

[Link] Dropdowns in ALV

Simple code for creating dropdown lists for columns in ALV grid outputREPORT zalv_dropdowns

[Link] Radio Buttons in ALV GRID REPORT

Usage of Radio buttons in ALV Report output

[Code] Double Click

雙擊在一行中的任一欄位上:

FORM user_command USING i_ucomm     TYPE syucomm
                         is_selfield TYPE slis_selfield.    "#EC CALLED
  DATA: lv_datum LIKE sy-datum.

  CASE i_ucomm.
    WHEN '&IC1'.             " double click
      READ TABLE gt_itab INDEX is_selfield-tabindex.
      SET PARAMETER ID 'VF'   FIELD gt_itab-vbeln.
      CALL TRANSACTION 'VF03' AND SKIP FIRST SCREEN.
  ENDCASE.

ENDFORM.                               " USER_COMMAND

判斷雙擊在哪一個欄位上:

CASE I_UCOMM.
  WHEN '&IC1'.             " double click
    CASE IS_SELFIELD-SEL_TAB_FIELD.
      WHEN 'GT_ITAB-VGBEL'.
        IF IS_SELFIELD-VALUE IS INITIAL.
        ELSE.
          SET PARAMETER ID 'AUN' FIELD IS_SELFIELD-VALUE.
          CALL TRANSACTION 'VA02' AND SKIP FIRST SCREEN.
        ENDIF.
    ENDCASE.
ENDCASE.

Non-ALV Use Event - AT LINE-SELECTION

DATA: gv_field(20),
      gv_value(18).

* -----------------
* AT LINE-SELECTION
* -----------------
AT LINE-SELECTION.
  GET CURSOR FIELD gv_field VALUE gv_value.
  CASE gv_field.
    WHEN 'GT_ITAB-VBELN'.
      SET PARAMETER ID 'VF' FIELD gv_value.
      CALL TRANSACTION 'VF03' AND SKIP FIRST SCREEN.
    WHEN 'GT_ITAB-VGBEL'.
      SET PARAMETER ID 'VL' FIELD gv_value.
      CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN.
  ENDCASE.

------------------------------------------------------
※ Reference HIDE:

Basic form

  HIDE f.

Effect

  The contents of f related to the current output line are stored. If this line is selected,
  f is filled automatically with the stored value.

常用 Transation

VA02:
SET PARAMETER ID 'AUN' FIELD IS_SELFIELD-VALUE.
CALL TRANSACTION 'VA02' AND SKIP FIRST SCREEN.
VA43:
SET PARAMETER ID 'KTN' FIELD IS_SELFIELD-VALUE.
CALL TRANSACTION 'VA43' AND SKIP FIRST SCREEN.
VL03N:
SET PARAMETER ID 'VL'   FIELD IS_SELFIELD-VALUE.
CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN.
VF03:
SET PARAMETER ID 'VF'   FIELD gt_itab-vbeln.
CALL TRANSACTION 'VF03' AND SKIP FIRST SCREEN.
VB23:
SET PARAMETER ID 'VK1' FIELD gv_knuma_ag.
CALL TRANSACTION 'VB23' AND SKIP FIRST SCREEN.
FB03:
SET PARAMETER ID 'BLN'  FIELD GV_BELNR.
SET PARAMETER ID 'BUK'  FIELD '1000'.
SET PARAMETER ID 'GJR'  FIELD P_MJAHR.
CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.
FK02:
SET PARAMETER ID 'LIF' FIELD V_LIFNR.
SET PARAMETER ID 'BUK' FIELD P_BUKRS.
CALL TRANSACTION 'FK02'.
FK03:
SET PARAMETER ID 'LIF' FIELD V_LIFNR.
SET PARAMETER ID 'BUK' FIELD P_BUKRS.
CALL TRANSACTION 'FK03'.
FK05:
SET PARAMETER ID 'LIF' FIELD V_LIFNR.
SET PARAMETER ID 'BUK' FIELD P_BUKRS.
CALL TRANSACTION 'FK05' AND SKIP FIRST SCREEN.
FK01:
SET PARAMETER ID 'LIF' FIELD V_LIFNR.
SET PARAMETER ID 'BUK' FIELD P_BUKRS.
SET PARAMETER ID 'KGK' FIELD V_KOTKK.
CALL TRANSACTION 'FK01' AND SKIP FIRST SCREEN.
MB03:
SET PARAMETER ID 'MBN'  FIELD is_selfield-value.
SET PARAMETER ID 'MJA'  FIELD gt_itab-budat(4).
CALL TRANSACTION 'MB03' AND SKIP FIRST SCREEN.
ME03:
SET PARAMETER ID 'MAT' FIELD MATNR.
SET PARAMETER ID 'WRK' FIELD WERKS.
CALL TRANSACTION 'ME03' AND SKIP FIRST SCREEN.
ME13:
SET PARAMETER ID 'INF' FIELD XEINE-INFNR.
SET PARAMETER ID 'MAT' FIELD XEINE-MATNR.
SET PARAMETER ID 'LIF' FIELD XEINE-LIFNR.
SET PARAMETER ID 'ESO' FIELD XEINE-ESOKZ.
SET PARAMETER ID 'EKO' FIELD XEINE-EKORG.
SET PARAMETER ID 'WRK' FIELD XEINE-WERKS.
SET PARAMETER ID 'EIB' FIELD SPACE.
CALL TRANSACTION 'ME13' AND SKIP FIRST SCREEN.
ME15:
SET PARAMETER ID 'INF' FIELD XEINE-INFNR.
SET PARAMETER ID 'MAT' FIELD XEINE-MATNR.
SET PARAMETER ID 'LIF' FIELD XEINE-LIFNR.
SET PARAMETER ID 'ESO' FIELD XEINE-ESOKZ.
SET PARAMETER ID 'EKO' FIELD XEINE-EKORG.
SET PARAMETER ID 'WRK' FIELD XEINE-WERKS.
SET PARAMETER ID 'EIB' FIELD 'L'.
CALL TRANSACTION 'ME15' AND SKIP FIRST SCREEN.
ME23:
SET PARAMETER ID 'BES' FIELD EBELN.
CALL TRANSACTION 'ME23' AND SKIP FIRST SCREEN.
ME23N:
READ TABLE gt_itab INDEX is_selfield-tabindex.
SET PARAMETER ID 'BES'   FIELD is_selfield-value.
CALL FUNCTION 'ME_DISPLAY_PURCHASE_DOCUMENT'
  EXPORTING
    i_ebeln gt_itab-ebeln
    i_ebelp gt_itab-ebelp
    i_enjoy 'X'
  EXCEPTIONS
    OTHERS  1.   
ME33:
SET PARAMETER ID 'VRT' FIELD EBELN.
CALL TRANSACTION 'ME33' AND SKIP FIRST SCREEN.
ME43:
SET PARAMETER ID 'ANF' FIELD HIDK-EBELN.
CALL TRANSACTION 'ME43' AND SKIP FIRST SCREEN.
MIR4:
SET PARAMETER ID 'RBN'  FIELD is_selfield-value.
SET PARAMETER ID 'GJR'  FIELD gt_itab-wadat_ist(4).
CALL TRANSACTION 'MIR4' AND SKIP FIRST SCREEN.
MM03:
SET PARAMETER ID 'MXX' FIELD 'KD'. " Table T132: Status definition
SET PARAMETER ID 'WRK' FIELD p_werks.
SET PARAMETER ID 'MAT' FIELD KABT-MATNR.
CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
MMBE:
SET PARAMETER ID 'MAT' FIELD LIST-MATNR.
SET PARAMETER ID 'WRK' FIELD LIST-WERKS.
SET PARAMETER ID 'LAG' FIELD ''.
CALL TRANSACTION 'MMBE' AND SKIP FIRST SCREEN.
KOB1:
SET PARAMETER ID 'ANR' FIELD V_AUFNR.
SET PARAMETER ID 'KAG' FIELD V_KAGRU.
CALL TRANSACTION 'KOB1'. "AND SKIP FIRST SCREEN.
KO88:
SET PARAMETER ID 'ANR' FIELD V_AUFNR.
CALL TRANSACTION 'KO88'.
CO02:
SET PARAMETER ID 'ANR' FIELD V_AUFNR.
CALL TRANSACTION 'CO02' AND SKIP FIRST SCREEN.
CS03:
SET PARAMETER ID 'MAT' FIELD gt_itab-idnrk.
SET PARAMETER ID 'WRK' FIELD p_werks.
SET PARAMETER ID 'CSV' FIELD gt_itab-stlan.
CALL TRANSACTION 'CS03' AND SKIP FIRST SCREEN.

[Code] Quick Reference for ALV_LIST report.

快速建立 ALV_LIST 報表
以下分為幾個段落,可以快速的建立 ALV_LIST 的報表。

Define

TYPE-POOLS: slis.

* Global variables for handling ALV functionality
CONSTANTS: alv_status   TYPE slis_formname VALUE 'SET_STATUS',
           alv_ucommd   TYPE slis_formname VALUE 'USER_COMMAND'.
DATA:      alv_repid    LIKE sy-repid,
           alv_field    TYPE slis_fieldcat_alv,
           alv_event    TYPE slis_alv_event,
           alv_layout   TYPE slis_layout_alv,
           alv_sort     TYPE slis_sortinfo_alv,
           alv_print    TYPE slis_print_alv,
           alv_t_field  TYPE slis_t_fieldcat_alv,
           alv_t_events TYPE slis_t_event,
           alv_t_sort   TYPE slis_t_sortinfo_alv.

INITIALIZATION

*----------------
* INITIALIZATION
*----------------
INITIALIZATION.
  alv_repid = sy-repid.

Data_Print

報表顯示的資料請放在 gt_itab 的 Internal table 裡面。
FORM data_print.
  PERFORM alvevent.
  PERFORM alvfield.
  PERFORM alvsort.

  alv_layout-colwidth_optimize = 'X'.
  alv_layout-get_selinfos      = 'X'.
  alv_layout-zebra             = 'X'.
*  alv_layout-numc_sum          = 'X'
*  alv_layout-box_fieldname     = 'SELEC'.
*  alv_layout-box_tabname       = 'GT_VBRK'.
*  alv_layout-f2code            = '&F2C'.
*  alv_layout-no_totalline      = 'X'.
*  alv_layout-group_change_edit = 'X'.

  alv_print-no_print_listinfos = 'X'.
  alv_print-no_print_selinfos  = 'X'.
  alv_print-no_coverpage       = 'X'.

  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
      i_callback_program       = alv_repid
      i_callback_pf_status_set = alv_status
      i_callback_user_command  = alv_ucommd
      it_fieldcat              = alv_t_field
      i_save                   = 'A'
      it_events                = alv_t_events
      is_layout                = alv_layout
      it_sort                  = alv_t_sort
      is_print                 = alv_print
    TABLES
      t_outtab                 = gt_itab
    EXCEPTIONS
      program_error            = 1
      OTHERS                   = 2.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

ENDFORM.

ALV_EVENT

*&---------------------------------------------------------------------*
*&      Form  alvevent
*&---------------------------------------------------------------------*
*       ALV Event
*----------------------------------------------------------------------*
FORM alvevent .
  CLEAR alv_event.
  alv_event-name = slis_ev_top_of_page.
  alv_event-form = 'LIST_HEADER'.
  APPEND alv_event TO alv_t_events.
ENDFORM.                    "alvevent

ALV_FIELDS

Fields 也有 Function 可以直接建立,只是手動建立的自主性較高。
*&---------------------------------------------------------------------*
*&      Form  alvfield
*&---------------------------------------------------------------------*
*       ALV Fields
*----------------------------------------------------------------------*
FORM alvfield .
  DATA: l_count TYPE i.
*
  CLEAR alv_field.
  l_count = l_count + 1.
  alv_field-col_pos       = l_count.
  alv_field-fieldname     = 'FKDAT'.
  alv_field-seltext_s     = 'DATE'.
  alv_field-key           = 'X'.             " define field as key
  APPEND alv_field TO alv_t_field.
*
  CLEAR alv_field.
  l_count = l_count + 1.
  alv_field-col_pos       = l_count.
  alv_field-fieldname     = 'FKIMG'.
  alv_field-seltext_s     = 'Quantity'.
  alv_field-decimals_out  = '0'.
  alv_field-do_sum        = 'X'.
  APPEND alv_field TO alv_t_field.
*
  CLEAR alv_field.
  l_count = l_count + 1.
  alv_field-col_pos       = l_count.
  alv_field-fieldname     = 'AMOU0'.
  alv_field-seltext_s     = 'Amount'.
  alv_field-currency      = 'TWD'.
  " alv_field-cfieldname    = 'WAERK'.
  APPEND alv_field TO alv_t_field.
*
  CLEAR alv_field.
  l_count = l_count + 1.
  alv_field-col_pos       = l_count.
  alv_field-fieldname     = 'VRKME'.
  alv_field-seltext_s     = 'UoM'.
  alv_field-ref_tabname   'T006'.      " Reference Table
  alv_field-ref_fieldname 'MSEHI'.     " Reference Field
*
  CLEAR alv_field.
  l_count = l_count + 1.
  alv_field-col_pos       = l_count.
  alv_field-fieldname     = 'VKBUR'.
  alv_field-seltext_s     = 'OFFICE'.
  alv_field-no_out        = 'X'.          " No Output direct
  APPEND alv_field TO alv_t_field.
*
* .... Enter ALL of your fields at here.

ENDFORM.                    "alvfield
用 Function 建立的範例:
DATA: lv_tabix LIKE sy-tabix.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
  EXPORTING
    i_program_name         = alv_repid
    i_internal_tabname     = 'GT_ITAB'
    i_inclname             = alv_repid
  CHANGING
    ct_fieldcat            = alv_t_field
  EXCEPTIONS
    inconsistent_interface = 1
    program_error          = 2
    OTHERS                 = 3.
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

LOOP AT alv_t_field INTO alv_field.
  lv_tabix = sy-tabix.
  CASE alv_field-fieldname.
    WHEN 'FKDAT'.
      alv_field-seltext_s     = 'DATE'.
      alv_field-ddictxt       = 'S'.
    WHEN 'FKIMG'.
      alv_field-seltext_s     = 'Quantity'.
      alv_field-ddictxt       = 'S'.
      alv_field-decimals_out  = '0'.
      alv_field-do_sum        = 'X'.
    WHEN 'AMOU0'.
      alv_field-seltext_s     = 'Amount'.
      alv_field-ddictxt       = 'S'.
      alv_field-currency      = 'TWD'.
    WHEN 'VKBUR'.
      alv_field-seltext_s     = 'OFFICE'.
      alv_field-ddictxt       = 'S'.
      alv_field-no_out        = 'X'.          " No Output direct
  ENDCASE.
  MODIFY alv_t_field FROM alv_field INDEX lv_tabix.
ENDLOOP.

ALV_SORT

*&---------------------------------------------------------------------*
*&      Form  alvsort
*&---------------------------------------------------------------------*
*       ALV Sort
*----------------------------------------------------------------------*
FORM alvsort .
  DATA lv_counter TYPE i.

  CLEAR alv_sort.
  lv_counter         = lv_counter + 1.
  alv_sort-spos      = lv_counter.
  alv_sort-fieldname = 'KUNSP'.
  alv_sort-tabname   = 'GT_ITAB'.
  alv_sort-subtot    = 'X'.
  alv_sort-up        = 'X'.
  alv_sort-group     = 'UL'.       " UL : Split by Line,
                                   " *  : Split by Page.
  APPEND alv_sort TO alv_t_sort.

  CLEAR alv_sort.
  lv_counter         = lv_counter + 1.
  alv_sort-spos      = lv_counter.
  alv_sort-fieldname = 'FKDAT'.
  alv_sort-tabname   = 'GT_ITAB'.
  alv_sort-up        = 'X'.
  alv_sort-group     = ' '.
  APPEND alv_sort TO alv_t_sort.

ENDFORM.                    "alvsort

Set_Status

*&---------------------------------------------------------------------*
*&      Form  set_status
*&---------------------------------------------------------------------*
*       Set Status
*----------------------------------------------------------------------*
FORM set_status USING rt_extab TYPE slis_t_extab.
  SET PF-STATUS 'STANDARD' EXCLUDING rt_extab.
ENDFORM.                    "set_status

User_Command

*---------------------------------------------------------------------*
*       FORM USER_COMMAND                                             *
*---------------------------------------------------------------------*
FORM user_command USING i_ucomm     TYPE syucomm
                         is_selfield TYPE slis_selfield.    "#EC CALLED
  DATA: lv_datum LIKE sy-datum.

  CASE i_ucomm.
    WHEN '&IC1'.             " double click
      READ TABLE gt_itab INDEX is_selfield-tabindex.
      SET PARAMETER ID 'VF'   FIELD gt_itab-vbeln.
      CALL TRANSACTION 'VF03' AND SKIP FIRST SCREEN.
  ENDCASE.

ENDFORM.                               " USER_COMMAND

List_Header

*&---------------------------------------------------------------------*
*&      Form  list_header
*&---------------------------------------------------------------------*
*       List Header
*----------------------------------------------------------------------*
FORM list_header.
  DATA: lv_linsz LIKE sy-linsz.
  lv_linsz = sy-linsz - 20.
  WRITE:   /001(sy-linsz)  'XXX sheet'  CENTERED,
           /001            'Date :'  ,sy-datum.
  WRITE AT: lv_linsz       'Page No :'  ,(4) sy-pagno.
  ULINE.
ENDFORM.                    "list_header