SAP Bilgi Merkezi
Ana Sayfa  ABAP   FI   CO   MM   SD   PP   QM   HR   BW 
ABAP Destek
Dinamik Tablo ve Katalog

Dinamik tablo ve ALV kataloğunu aynı anda oluşturmak için aşağıdaki kodu kullanabilirsiniz:

Örnek Program:

*&---------------------------------------------------------------------*
*& Report  YU_GENERATE2
*&---------------------------------------------------------------------*
 report  yu_generate2.
  TYPE-POOLS : slis.
* Generate Table Data
  DATA: dy_table TYPE REF TO data,
        dy_line  TYPE REF TO data.
  FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
                 <dyn_wa>.
  FIELD-SYMBOLS: <fs> TYPE ANY.
  DATA: gs_source TYPE string.
  DATA: gt_source LIKE STANDARD TABLE OF gs_source WITH HEADER LINE,
        gt_vars LIKE STANDARD TABLE OF gs_source WITH HEADER LINE.
  DATA: gv_subid LIKE sy-repid VALUE 'Y_SUB_POOL',
        gv_repid LIKE sy-repid VALUE sy-repid.
  DATA: gt_fcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.
  DATA: gv_message(240) TYPE c,
        gv_line TYPE i,
        gv_word(72) TYPE c.
  DATA: gv_create(30) TYPE c VALUE 'TABLE_CREATE',
        gv_fcat(30) TYPE c VALUE 'GET_FCAT'.
*.....................................................................
  START-OF-SELECTION.
* Populate gt_vars as you wish
    APPEND 'DATA: MATNR LIKE MARA-MATNR.' TO gt_vars.
    APPEND 'DATA: MAKTX LIKE MAKT-MAKTX.' TO gt_vars.
    PERFORM populate_pool.
* Generate Subroutine
    CATCH SYSTEM-EXCEPTIONS generate_subpool_dir_full = 9.
      GENERATE SUBROUTINE POOL gt_source NAME gv_subid
        MESSAGE gv_message LINE gv_line WORD gv_word.
    ENDCATCH.
* Error handling
    IF NOT gv_message IS INITIAL.
      MESSAGE e000(0k) WITH gv_message gv_line gv_word.
    ENDIF.
* data reference
    ASSIGN dy_table TO <fs>.
* Call the subroutine
    PERFORM (gv_create) IN PROGRAM (gv_subid) USING <fs>.
* Get the reference of the data and assign to field symbol
    ASSIGN dy_table->* TO <dyn_table>.
* Create dynamic work area and assign to FS
    CREATE DATA dy_line LIKE LINE OF <dyn_table>.
    ASSIGN dy_line->* TO <dyn_wa>.
    PERFORM (gv_fcat) IN PROGRAM (gv_subid)
      TABLES gt_fcat USING gv_subid.

    SELECT mara~matnr makt~maktx UP TO 20 ROWS FROM mara JOIN makt
      ON mara~matnr EQ makt~matnr
      INTO CORRESPONDING FIELDS OF TABLE <dyn_table>.

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
      EXPORTING
        i_callback_program = gv_repid
        it_fieldcat        = gt_fcat[]
      TABLES
        t_outtab           = <dyn_table>
      EXCEPTIONS
        program_error      = 1
        OTHERS             = 2.

    CLEAR: <dyn_wa>.
*&---------------------------------------------------------------------*
*&      Form  populate_pool
*&---------------------------------------------------------------------*
  FORM populate_pool.

    APPEND 'REPORT Y_SUB_POOL.' TO gt_source.
    APPEND 'DATA: BEGIN OF LT_TAB OCCURS 0.' TO gt_source.
    APPEND LINES OF gt_vars TO gt_source.
    APPEND 'DATA: END OF LT_TAB.' TO gt_source.
    APPEND 'FORM  TABLE_CREATE USING I_FS TYPE ANY.' TO gt_source.
    APPEND 'DATA: PTR TYPE REF TO DATA.' TO gt_source.
    APPEND 'CREATE DATA PTR LIKE STANDARD TABLE OF LT_TAB.' TO gt_source.
    APPEND 'I_FS = PTR.' TO gt_source.
    APPEND 'ENDFORM.' TO gt_source.
    APPEND 'FORM  GET_FCAT TABLES lt_fcat USING lv_name.' TO gt_source.
    APPEND 'CALL FUNCTION ''REUSE_ALV_FIELDCATALOG_MERGE''' TO gt_source.
    APPEND 'EXPORTING' TO gt_source.
    APPEND 'i_program_name               = lv_name' TO gt_source.
    APPEND 'i_internal_tabname           = ''LT_TAB''' TO gt_source.
    APPEND 'i_inclname                   = lv_name' TO gt_source.
    APPEND 'CHANGING' TO gt_source.
    APPEND 'ct_fieldcat                  = lt_fcat[]' TO gt_source.
    APPEND 'EXCEPTIONS' TO gt_source.
    APPEND 'OTHERS                       = 1.' TO gt_source.
    APPEND 'ENDFORM.' TO gt_source.

  ENDFORM.                    " populate_pool
ABAP Programlar
SAP Chain
SAP NetWeaver
ticket sistemimize katılın ve ücretsiz
10 adam gün kazanın >>
 Ana Sayfa  |  ABAP  |  FI  |  CO  |  MM  |  SD  |  PP  |  QM  |  HR  |  BW 
ykomut@gmail.com