SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

ALV Demo ALV_BLOCK_LIST_APPEND



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ALV Grid / ALV Tree / ALV List
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Sat Jan 26, 2008 5:11 pm    Post subject: ALV Demo ALV_BLOCK_LIST_APPEND Reply with quote

Code:
REPORT z_alv_list_block.
*---------------------------------------------------------------------*
* Demo of FM ALV_BLOCK_LIST_APPEND                                    *
*---------------------------------------------------------------------*
* Author : Michel PIOUD - Updated 21-Dec-07                           *
* HomePage : http://www.geocities.com/mpioud                          *
*---------------------------------------------------------------------*
CONSTANTS :
  c_x VALUE 'X'.
*---------------------------------------------------------------------*
TYPE-POOLS: slis.                      " ALV Global types

TYPES:
* 1st Table
  BEGIN OF ty_kna1,
    kunnr TYPE kna1-kunnr,             " Customer number
    ernam TYPE kna1-ernam,             " Name of Person who Created
    erdat TYPE kna1-erdat,             " Creation date
    name1 TYPE kna1-name1,             " Name 1                    .
  END OF ty_kna1,

* 2nd Table
  BEGIN OF ty_mara,
    matnr TYPE mara-matnr,             " Material number
    ernam TYPE mara-ernam,             " Name of Person who Created
    ersda TYPE mara-ersda,             " Creation date
    mtart TYPE mara-mtart,             " Material type
    matkl TYPE mara-matkl,             " Material group
  END OF ty_mara,

* 3rd Table
  BEGIN OF ty_vbak,
    vbeln TYPE vbak-vbeln,             " Sales document
    vkorg TYPE vbak-vkorg,             " Sales organization
    vtweg TYPE vbak-vtweg,             " Distribution channel
    kunnr TYPE vbak-kunnr,             " Sold-to party
    erdat TYPE vbak-erdat,             " Creation date
  END OF ty_vbak.
*---------------------------------------------------------------------*
DATA:
  gt_kna1 TYPE TABLE OF ty_kna1,
  gt_mara TYPE TABLE OF ty_mara,
  gt_vbak TYPE TABLE OF ty_vbak.

*---------------------------------------------------------------------*
SELECTION-SCREEN :
  SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max.    "#EC NEEDED
PARAMETERS p_max(2) TYPE n DEFAULT '02' OBLIGATORY.
SELECTION-SCREEN END OF LINE.

*---------------------------------------------------------------------*
INITIALIZATION.

  v_1 = 'Maximum of records to read'.

*---------------------------------------------------------------------*
START-OF-SELECTION.

* Read data
  SELECT kunnr ernam erdat name1
    FROM kna1
   UP TO p_max ROWS
    INTO TABLE gt_kna1.

  SELECT matnr ernam ersda mtart matkl
    FROM mara
   UP TO p_max ROWS
    INTO TABLE gt_mara.

  SELECT vbeln vkorg vtweg kunnr erdat
    FROM vbak
   UP TO p_max ROWS
    INTO TABLE gt_vbak.

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
    EXPORTING
      i_callback_program      = sy-cprog
      i_callback_user_command = 'USER_COMMAND'.

  PERFORM list_append TABLES gt_kna1
                       USING '1'
                             'GT_KNA1'.

  PERFORM list_append TABLES gt_mara
                       USING '2'
                             'GT_MARA'.

  PERFORM list_append TABLES gt_vbak
                      USING '3'
                            'GT_VBAK'.

*---------------------------------------------------------------------*
END-OF-SELECTION.

  PERFORM f_list_display.

*---------------------------------------------------------------------*
*       FORM USER_COMMAND                                             *
*---------------------------------------------------------------------*
FORM user_command USING u_ucomm     TYPE sy-ucomm
                        us_selfield TYPE slis_selfield.     "#EC CALLED

  DATA:
    ls_vbak TYPE ty_vbak.

  CASE u_ucomm.
    WHEN '&IC1'.                       " Pick
      CASE us_selfield-tabname.
        WHEN 'GT_MARA'.
        WHEN 'GT_KNA1'.
        WHEN 'GT_VBAK'.
          READ TABLE gt_vbak INDEX us_selfield-tabindex INTO ls_vbak.
          IF sy-subrc EQ 0.
*           Sales order number
            SET PARAMETER ID 'AUN' FIELD ls_vbak-vbeln.
*           Display Sales Order
            CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
          ENDIF.
      ENDCASE.
  ENDCASE.

ENDFORM.                               " USER_COMMAND
*---------------------------------------------------------------------*
*       Form  list_append
*---------------------------------------------------------------------*
FORM list_append TABLES ut_table  TYPE table
                  USING u_no      TYPE numc1
                        u_tabname TYPE slis_tabname.

* Macro definition
  DEFINE m_fieldcat.
    ls_fieldcat-fieldname = &1.
    ls_fieldcat-ref_tabname = &2.
    append ls_fieldcat to lt_fieldcat.
  END-OF-DEFINITION.

  DEFINE m_sort.
    ls_sort-fieldname = &1.
    ls_sort-up        = c_x.
    append ls_sort to lt_sort.
  END-OF-DEFINITION.

  DATA :
    ls_fieldcat TYPE slis_fieldcat_alv,
    lt_fieldcat TYPE slis_t_fieldcat_alv, " Field catalog
    ls_sort     TYPE slis_sortinfo_alv,
    lt_sort     TYPE slis_t_sortinfo_alv. " Sort table

  DATA:
    lt_events TYPE slis_t_event,
    ls_event  TYPE slis_alv_event,
    ls_layout TYPE slis_layout_alv.

  ls_layout-group_change_edit = c_x.
  ls_layout-colwidth_optimize = c_x.
  ls_layout-zebra             = c_x.
  ls_layout-cell_merge        = c_x.
  ls_layout-detail_popup      = c_x.
  ls_layout-get_selinfos      = c_x.
  ls_layout-max_linesize      = '200'.

  CASE u_no.
    WHEN '1'.
* Build field catalog and sort table
      m_fieldcat  'KUNNR' 'KNA1'.
      m_fieldcat  'ERNAM' 'KNA1'.
      m_fieldcat  'ERDAT' 'KNA1'.
      m_fieldcat  'NAME1' 'KNA1'.
      m_sort  'KUNNR'.
    WHEN '2'.
      m_fieldcat 'MATNR' 'MARA'.
      m_fieldcat 'ERNAM' 'MARA'.
      m_fieldcat 'ERSDA' 'MARA'.
      m_fieldcat 'MTART' 'MARA'.
      m_fieldcat 'MATKL' 'MARA'.
      m_sort 'MATNR'.
    WHEN '3'.
      m_fieldcat 'VBELN' 'VBAK'.
      m_fieldcat 'VKORG' 'VBAK'.
      m_fieldcat 'VTWEG' 'VBAK'.
      m_fieldcat 'KUNNR' 'VBAK'.
      m_fieldcat 'ERDAT' 'VBAK'.
      m_sort 'VBELN'.
  ENDCASE.

  IF u_no CA '13'.
    MOVE        'TOP_OF_PAGE'        TO ls_event-name.
    CONCATENATE 'TOP_OF_PAGE' u_no INTO ls_event-form.
    APPEND ls_event TO lt_events.
  ELSE.
    MOVE        'TOP_OF_LIST'        TO ls_event-name.
    CONCATENATE 'TOP_OF_LIST' u_no INTO ls_event-form.
    APPEND ls_event TO lt_events.
  ENDIF.

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
    EXPORTING
      it_fieldcat                = lt_fieldcat
      is_layout                  = ls_layout
      i_tabname                  = u_tabname
      it_events                  = lt_events
      it_sort                    = lt_sort
    TABLES
      t_outtab                   = ut_table
    EXCEPTIONS
      program_error              = 1
      maximum_of_appends_reached = 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.

ENDFORM.                               " LIST_APPEND
*---------------------------------------------------------------------*
*       Form  f_list_display
*---------------------------------------------------------------------*
FORM f_list_display.

  DATA ls_print TYPE slis_print_alv.

  ls_print-no_print_selinfos  = c_x.   " Display no selection infos
  ls_print-no_print_listinfos = c_x.   " Display no listinfos
  ls_print-reserve_lines      = 2.     " Lines reserved for end of page

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
    EXPORTING
      i_interface_check = ' '
      is_print          = ls_print
    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.                               " F_LIST_DISPLAY
*---------------------------------------------------------------------*
*       FORM top_of_page1                                             *
*---------------------------------------------------------------------*
FORM top_of_page1.                                          "#EC CALLED

  PERFORM top_of_page.

ENDFORM.                    "TOP_OF_PAGE1
*---------------------------------------------------------------------*
*       FORM top_of_page3                                             *
*---------------------------------------------------------------------*
FORM top_of_page3.                                          "#EC CALLED

  PERFORM top_of_page.

ENDFORM.                    "TOP_OF_PAGE3
*---------------------------------------------------------------------*
*       FORM top_of_page                                              *
*---------------------------------------------------------------------*
FORM top_of_page.

  ULINE.
  WRITE : sy-uname, sy-title(56) CENTERED, sy-datum.
  ULINE.

ENDFORM.                    "TOP_OF_PAGE
*---------------------------------------------------------------------*
*       FORM top_of_list2                                             *
*---------------------------------------------------------------------*
FORM top_of_list2.                                          "#EC CALLED

  WRITE 'TOP OF LIST2'.

ENDFORM.                    "TOP_OF_LIST2
************** END OF PROGRAM Z_ALV_LIST_BLOCK ***********************
 
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ALV Grid / ALV Tree / ALV List All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.