ABAP ALV Report Template2

Program No Comments »

*&———————————————————————*
*& Report  ZJACKTEST
*&
*&———————————————————————*
*&
*&
*&———————————————————————*

REPORT  ZJACKTEST.

*========================== Global definitions  =======================*

**
* Data Types
**

TYPE-pools: slis.

TYPES: BEGIN OF tp_data,
  ebeln LIKE ekko-ebeln,
  aedat LIKE ekko-aedat,
  lifnr LIKE ekko-lifnr,
  ebelp LIKE ekpo-ebelp,
  txz01 LIKE ekpo-txz01,
  menge LIKE ekpo-menge,
  netpr LIKE ekpo-netpr,
  peinh LIKE ekpo-peinh,
  __mark,

END OF tp_data,
tp_tbl_data TYPE STANDARD TABLE OF tp_data.

**
* Constants
**

**
* Data objects (variable declarations and definitions)
**

* Report data to be shown.
DATA: it_data TYPE STANDARD TABLE OF tp_data.

* Heading of the report.
DATA: t_heading TYPE slis_t_listheader.

*========================== Selection Screen ==========================*

selection-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-t01.
  DATA: w_aux_ebeln LIKE ekko-ebeln.
  SELECT-OPTIONS s_ebeln FOR w_aux_ebeln .
  DATA: w_aux_aedat LIKE ekko-aedat.
  SELECT-OPTIONS s_aedat FOR w_aux_aedat .
  DATA: w_aux_name1 LIKE lfa1-name1.
  SELECT-OPTIONS s_name1 FOR w_aux_name1 .
selection-SCREEN: END OF BLOCK b1.

*=========================== Event Blocks =============================*
AT selection-SCREEN.

start-OF-selection.
PERFORM get_data USING it_data.

END-OF-selection.
PERFORM build_alv USING it_data t_heading.

*=========================== Subroutines ==============================*

*&———————————————————————*
*&      Form  get_data
*&———————————————————————*
*       Gets the information to be shown in the report.
*———————————————————————-*
FORM get_data USING t_data TYPE tp_tbl_data.

  SELECT e~lifnr
  e~ebeln
  e~aedat
  p~ebelp
  p~txz01
  p~menge
  p~netpr
  p~peinh
  INTO CORRESPONDING FIELDS OF TABLE t_data
  FROM ekko AS e
  inner JOIN lfa1 AS l ON e~lifnr = l~lifnr
  inner JOIN ekpo AS p ON p~ebeln = e~ebeln
  WHERE e~ebeln IN s_ebeln
  AND e~aedat IN s_aedat
  AND l~name1 IN s_name1
  .

ENDFORM.                    " get_data

*&———————————————————————*
*&      Form  build_alv
*&———————————————————————*
*       Builds and display the ALV Grid.
*———————————————————————-*
FORM build_alv USING t_data TYPE tp_tbl_data
      t_heading  TYPE slis_t_listheader.

* ALV required data objects.
  DATA: w_title   TYPE lvc_title,
        w_comm    TYPE slis_formname,
        w_status  TYPE slis_formname,
        x_layout  TYPE slis_layout_alv,
        t_event    TYPE slis_t_event,
        t_fieldcat TYPE slis_t_fieldcat_alv,
        t_sort     TYPE slis_t_sortinfo_alv.

  REFRESH t_fieldcat.
  REFRESH t_event.
  REFRESH t_sort.
  CLEAR x_layout.
  CLEAR w_title.

* Field Catalog
  PERFORM set_fieldcat2 USING:
        1 ‘__MARK’ ‘XFELD’ space space space ‘Select’ ‘Select this row’ ‘Sel’ ‘Select this row’ space space space ‘X’ ‘X’ space t_fieldcat,
        2 ‘LIFNR’ ‘LIFNR’ ‘EKKO’ space space space space space space space space space space space space t_fieldcat ,
        3 ‘EBELN’ ‘EBELN’ ‘EKKO’ space space space space space space space ‘X’ space space space space t_fieldcat ,
        4 ‘AEDAT’ ‘AEDAT’ ‘EKKO’ space space space space space space space space space space space space t_fieldcat ,
        5 ‘EBELP’ ‘EBELP’ ‘EKPO’ space space space space space space space space space space space space t_fieldcat ,
        6 ‘TXZ01′ ‘TXZ01′ ‘EKPO’ space space space space space space space space space space space space t_fieldcat ,
        7 ‘MENGE’ ‘MENGE’ ‘EKPO’ space space space space space space space space space space space ‘X’ t_fieldcat ,
        8 ‘NETPR’ ‘NETPR’ ‘EKPO’ space space space space space space space space space space space space t_fieldcat ,
        9 ‘PEINH’ ‘PEINH’ ‘EKPO’ space space space space space space space space space space space space t_fieldcat .

* Layout
  x_layout-zebra = ‘X’.

* Top of page heading
  PERFORM set_top_page_heading USING t_heading t_event.

* Events
  PERFORM set_events USING t_event.

* GUI Status
  w_status = ”.

* User commands
  w_comm   = ‘USER_COMMAND’.

* Order
* Example
*  PERFORM set_order USING ‘<field>’ ‘IT_DATA’ ‘X’ space space t_sort.
  PERFORM set_order USING ‘LIFNR’ ‘IT_DATA’ ‘X’ space ‘X’ t_sort.
  PERFORM set_order USING ‘EBELN’ ‘IT_DATA’ ‘X’ space ‘X’ t_sort.
  PERFORM set_order USING ‘EBELP’ ‘IT_DATA’ ‘X’ space space t_sort.

* Displays the ALV grid
  CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
  EXPORTING
    i_callback_program       = sy-repid
    it_fieldcat              = t_fieldcat
    is_layout                = x_layout
    it_sort                  = t_sort
    i_callback_pf_status_set = w_status
    i_callback_user_command  = w_comm
    i_save                   = ‘X’
    it_events                = t_event
    i_grid_title             = w_title
  TABLES
    t_outtab                 = t_data
  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.                    " build_alv.

*&———————————————————————*
*&      Form  set_top_page_heading
*&———————————————————————*
*       Creates the report headings.
*———————————————————————-*
FORM set_top_page_heading USING t_heading TYPE slis_t_listheader
      t_events  TYPE slis_t_event.

  DATA: x_heading TYPE slis_listheader,
        x_event   TYPE LINE OF slis_t_event.

* Report title
  CLEAR t_heading[].
  CLEAR x_heading.
  x_heading-typ = ‘H’.
  x_heading-info = ‘Reporte Prueba’(001).
  APPEND x_heading TO t_heading.

* Program name
  CLEAR x_heading.
  x_heading-typ = ‘S’.
  x_heading-KEY = ‘Program: ‘.
  x_heading-info = sy-repid.
  APPEND x_heading TO t_heading.

* User who is running the report
  CLEAR x_heading.
  x_heading-typ = ‘S’.
  x_heading-KEY = ‘User: ‘.
  x_heading-info = sy-uname.
  APPEND x_heading TO t_heading.

* Date of execution
  CLEAR x_heading.
  x_heading-typ = ‘S’.
  x_heading-KEY = ‘Date: ‘.
  WRITE sy-datum TO x_heading-info.
  APPEND x_heading TO t_heading.

* Time of execution
  CLEAR x_heading.
  x_heading-typ = ‘S’.
  x_heading-KEY = ‘Time: ‘.
  WRITE sy-uzeit TO x_heading-info.
  APPEND x_heading TO t_heading.

* Top of page event
  x_event-name = slis_ev_top_of_page.
  x_event-FORM = ‘TOP_OF_PAGE’.
  APPEND x_event TO t_events.

ENDFORM.

*&———————————————————————*
*&      Form  set_events
*&———————————————————————*
*       Sets the events for ALV.
*       The TOP_OF_PAGE event is alredy being registered in
*       the set_top_page_heading subroutine.
*———————————————————————-*
FORM set_events USING t_events TYPE slis_t_event.

  DATA: x_event   TYPE LINE OF slis_t_event.

**
* Example
* ——-
*  clear x_event.
*  x_event-name = .
*  x_event-form = .
*  append x_event to t_event.
**

ENDFORM.

*&———————————————————————*
*&      Form  set_order
*&———————————————————————*
*       Adds an entry to the order table.
*———————————————————————-*
FORM set_order USING p_fieldname p_tabname p_up p_down p_subtot
      t_sort TYPE slis_t_sortinfo_alv.

  DATA: x_sort TYPE slis_sortinfo_alv.

  CLEAR x_sort.
  x_sort-fieldname = p_fieldname.
  x_sort-tabname   = p_tabname.
  x_sort-UP = p_up.
  x_sort-down = p_down.
  x_sort-subtot = p_subtot.
  APPEND x_sort TO t_sort.

ENDFORM.                    "set_order

*&———————————————————————*
*&      Form  set_fieldcat2
*&———————————————————————*
*       Adds an entry to the field catalog.
*———————————————————————-*
FORM set_fieldcat2 USING p_colpos p_fieldname p_ref_fieldname p_ref_tabname
      p_outputlen p_noout
      p_seltext_m p_seltext_l p_seltext_s p_reptext_ddic p_ddictxt
      p_hotspot p_showasicon p_checkbox p_edit
      p_dosum
      t_fieldcat TYPE slis_t_fieldcat_alv.

  DATA: wa_fieldcat TYPE slis_fieldcat_alv.

  CLEAR wa_fieldcat.

* General settings
  wa_fieldcat-fieldname = p_fieldname.
  wa_fieldcat-col_pos = p_colpos.
  wa_fieldcat-no_out = p_noout.
  wa_fieldcat-HOTSPOT = p_hotspot.
  wa_fieldcat-CHECKBOX = p_checkbox.
  wa_fieldcat-ICON = p_showasicon.
  wa_fieldcat-do_sum = p_dosum.

* Set reference fieldname, tablenam and rollname.
* If p_ref_tabname is not given, the ref_fieldname given is a data element.
* If p_ref_tabname is given, the ref_fieldname given is a field of a table. In case ref_fieldname is not given, it is copied from the fieldname.
  IF p_ref_tabname IS INITIAL.
    wa_fieldcat-rollname =   p_ref_fieldname.
  ELSE.
    wa_fieldcat-ref_tabname = p_ref_tabname.
    IF p_ref_fieldname EQ space.
      wa_fieldcat-ref_fieldname =   wa_fieldcat-fieldname.
    ELSE.
      wa_fieldcat-ref_fieldname =   p_ref_fieldname.
    ENDIF.
  ENDIF.

* Set output length.
  IF NOT p_outputlen IS INITIAL.
    wa_fieldcat-outputlen = p_outputlen.
  ENDIF.

* Set text headers.
  IF NOT p_seltext_m IS INITIAL.
    wa_fieldcat-seltext_m = p_seltext_m.
  ENDIF.

  IF NOT p_seltext_l IS INITIAL.
    wa_fieldcat-seltext_l = p_seltext_l.
  ENDIF.

  IF NOT p_seltext_s IS INITIAL.
    wa_fieldcat-seltext_s = p_seltext_s.
  ENDIF.

  IF NOT p_reptext_ddic IS INITIAL.
    wa_fieldcat-reptext_ddic = p_reptext_ddic.
  ENDIF.

  IF NOT p_ddictxt IS INITIAL.
    wa_fieldcat-ddictxt = p_ddictxt.
  ENDIF.

* Set as editable or not.
  IF p_edit IS NOT INITIAL.
    wa_fieldcat-INPUT     = ‘X’.
    wa_fieldcat-EDIT     = ‘X’.
  ENDIF.

  APPEND wa_fieldcat TO t_fieldcat.

ENDFORM.                   "set_fieldcat2

*=========================== Subroutines called by ALV ================*

*&———————————————————————*
*&      Form  top_of_page
*&———————————————————————*
*       Called on top_of_page ALV event.
*       Prints the heading.
*———————————————————————-*
FORM top_of_page.
  CALL FUNCTION ‘REUSE_ALV_COMMENTARY_WRITE’
  EXPORTING
*     i_logo             = ‘XXXXX’
    it_list_commentary = t_heading.
ENDFORM.                    " alv_top_of_page

*&———————————————————————*
*&      Form  user_command
*&———————————————————————*
*       Called on user_command ALV event.
*       Executes custom commands.
*———————————————————————-*
FORM user_command USING r_ucomm     LIKE sy-ucomm
      rs_selfield TYPE slis_selfield.

**
* Example Code
*
* Executes a command considering the sy-ucomm.
*  CASE r_ucomm.
*    WHEN ‘&IC1′.
*
*      Set your "double click action" response here.
*
*      Example code: Create and display a status message.
*      DATA: w_msg TYPE string,
*            w_row(4) TYPE n.
*      w_row = rs_selfield-tabindex.
*      CONCATENATE ‘You have clicked row’ w_row
*                  ‘field’ rs_selfield-fieldname
*                  ‘with value’ rs_selfield-value
*                  INTO w_msg SEPARATED BY space.
*      MESSAGE w_msg TYPE ‘S’.
*
*  ENDCASE.
*
*  End of example code.
**

Result

alv_template2

via web

ABAP ALV Report Template

Program No Comments »

*&———————————————————————*
*& Report  ZJACKTEST
*&
*&———————————————————————*
*&
*&
*&———————————————————————*

REPORT  ZJACKTEST.

TYPE-POOLS: slis.

* >> field catalog 사용을 위한 data 선언
DATA: fieldcat TYPE slis_t_fieldcat_alv,
      fieldcat_ln LIKE LINE OF fieldcat.

DATA: col_pos TYPE i.

* >> t_outtab internal table 정의
DATA: BEGIN OF alv_it_mara OCCURS 0,
      matnr LIKE mara-matnr,
      ersda LIKE mara-ersda,
      ernam LIKE mara-ernam,
     END OF alv_it_mara.

* >> selection : ALV 초기화면에 보일 해당 필드만 지정해서 넣는다.
SELECT matnr ersda ernam
       INTO CORRESPONDING FIELDS OF TABLE alv_it_mara
       FROM mara.

* >> 구조화 프로그래밍을 위한 PERFORM 문 들….
PERFORM build_fieldcat.
PERFORM build_fieldcat2.
PERFORM build_fieldcat3.
PERFORM start_list_viewer.

*—————————————————————-*
*       FORM build_fieldcat1                                     *
*—————————————————————-*
*       첫번째 보여줄 필드                                       *
*—————————————————————-*
FORM build_fieldcat.
  ADD 1 TO col_pos.
  fieldcat_ln-ref_tabname = ‘MARA’.
  fieldcat_ln-fieldname = ‘MATNR’.
  fieldcat_ln-key = space.
  fieldcat_ln-do_sum = space.
  fieldcat_ln-col_pos = col_pos.
  fieldcat_ln-no_out = space.
  fieldcat_ln-qfieldname = space.
  fieldcat_ln-hotspot = space.
*—————————————————————-*
* 칼라지정시에는 ‘Cxyz’순으로 쓰임, 여기서 C는 Default이고
* x : color number
* y,z : 0 = ‘off’, 1 = ‘on’ 의 의미를 가집니다.
* y : intensified display on/off, z : inverse display on / off
*—————————————————————-*
  fieldcat_ln-emphasize = ‘C300′.
  APPEND fieldcat_ln TO fieldcat.
ENDFORM.

*—————————————————————-*
*       FORM build_fieldcat2                                     *
*—————————————————————-*
*      두번째 보여줄 필드                                        *
*—————————————————————-*
FORM build_fieldcat2.
  ADD 2 TO col_pos.
  fieldcat_ln-ref_tabname = ‘MARA’.
  fieldcat_ln-fieldname = ‘ERSDA’.
  fieldcat_ln-key = space.
  fieldcat_ln-do_sum = space.
  fieldcat_ln-col_pos = col_pos.
  fieldcat_ln-no_out = space.
  fieldcat_ln-qfieldname = space.
  fieldcat_ln-hotspot = space.
  fieldcat_ln-emphasize = ‘C600′.
  APPEND fieldcat_ln TO fieldcat.
ENDFORM.

*—————————————————————-*
*       FORM build_fieldcat3                                     *
*—————————————————————-*
*       세번째 보여줄 필드                                       *
*—————————————————————-*
FORM build_fieldcat3.
  ADD 3 TO col_pos.
  fieldcat_ln-ref_tabname = ‘MARA’.
  fieldcat_ln-fieldname = ‘ERNAM’.
  fieldcat_ln-key = space.
  fieldcat_ln-do_sum = space.
  fieldcat_ln-col_pos = col_pos.
  fieldcat_ln-no_out = space.
  fieldcat_ln-qfieldname = space.
  fieldcat_ln-hotspot = space.
  fieldcat_ln-emphasize = ‘C701′.
  APPEND fieldcat_ln TO fieldcat.
ENDFORM.

*—————————————————————-*
*       FORM START_LIST_VIEWER                                   *
*—————————————————————-*
*       ……..                                                 *
*—————————————————————-*
FORM start_list_viewer.
  DATA: pgm LIKE sy-repid.
  pgm = sy-repid.

  CALL FUNCTION ‘REUSE_ALV_LIST_DISPLAY’
      EXPORTING
         i_callback_program       = pgm
*        I_CALLBACK_USER_COMMAND  = ‘USER_COMMAND’
         it_fieldcat              = fieldcat
*        IT_SORT                  = SORTCAT
         i_save                   = ‘A’    "select & save layout

      TABLES
         t_outtab                 = alv_it_mara.
*        EXCEPTIONS
*           program_error            = 1
*           OTHERS                   = 2.

 

Result

alv_template

SAP Table Relations(PDF File Download)

SAP No Comments »

Maybe you have this SAP Table Relations,if you do not have this PDF  file,pls download it.

saptables

SAP Table Relations PDF file Download

SAP ABAP ALV Knowledge

ABAP Tips No Comments »

Below Word document is SAP ABAP ALV Knowledge. I got this document from web. In my opinion this document is very useful for someone who wants to know about ALV.

Download ABAP ALV Knowledge(Chinese Version)

ABAP Syntax Update

ABAP Syntax No Comments »

Update: Move some data

1. Using Primary Key

   Method: UPDATE <database> FROM <wa>

   Example:

       TABLES SPFLI.

       DATA WA LIKE SPFLI.

       WA-NO=’34051920′.

       WA-COMPANY=’DELTA’.

       UPDATE SPFLI FROM WA.

如 SPFLI 的 Primary Key是 NO, 則會找到 NO=’34051920′
的記錄, 將其 COMPANY欄位異動為 DELTA

2. Using Condition

Method:

        UPDATE  <database>  SET  < f1>=<values>…  WHERE  <condition>

Example:
                 UPDATE  SPFLI  SET  NO=’34051920′
                                        COMPANY = ‘DELTA’
                                  WHERE  TEL=’4526107′.

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in