SAP Bilgi Merkezi
Ana Sayfa  ABAP   FI   CO   MM   SD   PP   QM   HR   BW 
ABAP Destek
Generate İle Kodlama

Generate program içerisinden yeni program oluşturmak için kullanılan bir ABAP komutudur. Kod örneğini aşağıda bulabilirsiniz.

Aşağıdaki program örneğinde farklı tablolar için seçim ekranları oluşturan ve bunları kendi içerisine include eden bir program örneği bulabilirsiniz. Aşağıdaki iki program hariç diğer include ları boş olarak oluşturup kaydedin.

Bu program sistemdeki 'A' ile başlayan programlar için seçim ekranı oluşturu

Örnek Program:

*&---------------------------------------------------------------------
*& Created Date : 3.6.2006                                             *
*& Created By   : Yavuz KOMUT                                          *
*&---------------------------------------------------------------------*
REPORT  yu_a.
TYPE-POOLS : slis.
*----------------------------------------------------------------------*
*   S E L E C T I O N   S C R E E N                                    *
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK bl1 WITH FRAME TITLE text-000.
PARAMETERS: p_table LIKE dd02l-tabname MEMORY ID dtb.
SELECTION-SCREEN END OF BLOCK bl1.

INCLUDE YU_A00.

INCLUDE YU_A01.

DATA : gv_repid LIKE sy-repid VALUE 'YU_A' .

* ALV DATA DECLERATION
DATA : gt_fcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
       gt_hdr  TYPE slis_t_listheader   WITH HEADER LINE,
       gt_sort TYPE slis_t_sortinfo_alv WITH HEADER LINE,
       gs_lout TYPE slis_layout_alv.

START-OF-SELECTION.

  PERFORM texts_modify.
  DO 50 TIMES.
    PERFORM call_selection.
    IF sy-subrc EQ 0.
      PERFORM read_data.
      PERFORM display.
    ELSE.
      EXIT.
    ENDIF.
  ENDDO.

*&---------------------------------------------------------------------*
*&      Form  display
*&---------------------------------------------------------------------*
FORM display .
  PERFORM fill_fcat.
  PERFORM display_itab.
ENDFORM.                    " display
*&---------------------------------------------------------------------*
*&      Form  set_pf_status
*&---------------------------------------------------------------------*
FORM set_pf_status USING rt_extab TYPE slis_t_extab.
  SET PF-STATUS 'ZMMSTAT'.
ENDFORM.                    "set_pf_status
*&---------------------------------------------------------------------*
*&      Form  user_command
*&---------------------------------------------------------------------*
FORM user_command  USING r_ucomm     LIKE sy-ucomm
                         rs_selfield TYPE slis_selfield.
  IF r_ucomm EQ 'HEDE'.
  ENDIF.

ENDFORM.                    "user_command
*&---------------------------------------------------------------------*
*&      Form  get_dd04t
*&---------------------------------------------------------------------*
FORM get_dd04t  USING    lv_rol LIKE dd04t-rollname
                CHANGING lv_key LIKE gt_hdr-key.
      SELECT SINGLE scrtext_m FROM dd04t INTO lv_key
        WHERE ddlanguage EQ sy-langu
          AND rollname EQ lv_rol.
      IF sy-subrc NE 0.
        SELECT SINGLE scrtext_m FROM dd04t INTO lv_key
          WHERE ddlanguage EQ 'E '
            AND rollname EQ lv_rol.
      ENDIF.
ENDFORM.                    "get_dd04t
*&---------------------------------------------------------------------*
*&      Form  texts_modify
*&---------------------------------------------------------------------*
FORM texts_modify .
  DATA: lt_seltext TYPE TABLE OF rsseltexts WITH HEADER LINE,
        lv_rollname LIKE dd03l-rollname,
        lv_index(6) TYPE n.

  DATA: BEGIN OF lt_texts OCCURS 0.
          INCLUDE STRUCTURE rsseltexts.
  DATA: tabname   LIKE dd02l-tabname,
        fieldname LIKE dd03l-fieldname,
        rollname  LIKE dd04l-rollname,
        END OF lt_texts.

  INCLUDE YU_A02.

  LOOP AT lt_texts WHERE tabname EQ p_table.
    SELECT SINGLE rollname FROM dd03l INTO lt_texts-rollname
      WHERE tabname   EQ p_table
        AND fieldname EQ lt_texts-fieldname.
    SELECT SINGLE scrtext_m FROM dd04t INTO lt_texts-text
      WHERE rollname   EQ lt_texts-rollname
        AND ddlanguage EQ sy-langu.
    IF sy-subrc NE 0.
      SELECT SINGLE ddtext FROM dd04t INTO lt_texts-text
        WHERE rollname   EQ lt_texts-rollname
          AND ddlanguage EQ 'E '.
    ENDIF.
    MOVE-CORRESPONDING lt_texts TO lt_seltext.
    APPEND lt_seltext.
    MODIFY lt_texts.
  ENDLOOP.

  CALL FUNCTION 'SELECTION_TEXTS_MODIFY'
    EXPORTING
      program                     = sy-repid
    TABLES
      seltexts                    = lt_seltext
    EXCEPTIONS
      program_not_found           = 1
      program_cannot_be_generated = 2
      OTHERS                      = 3.
ENDFORM.                    " texts_modify

INCLUDE YU_A03.

INCLUDE YU_A04.


**** Diğer Program ****

*&---------------------------------------------------------------------*
*& Report  YU_GENERATE
*&---------------------------------------------------------------------*
REPORT  yu_generate.
DATA:
  BEGIN OF gt_tables OCCURS 0,
    tabname LIKE dd03l-tabname,
  END OF gt_tables,

  BEGIN OF gt_code OCCURS 0,
    line LIKE rssource-line,
  END OF gt_code.
DATA: code TYPE TABLE OF rssource-line.
DATA: gt_seltext TYPE TABLE OF rsseltexts WITH HEADER LINE,
      gv_rollname LIKE dd03l-rollname,
      gv_index(6) TYPE n,
      gv_first.

DATA: BEGIN OF gt_texts OCCURS 0.
        INCLUDE STRUCTURE rsseltexts.
DATA: tabname   LIKE dd02l-tabname,
      fieldname LIKE dd03l-fieldname,
      keyflag   LIKE dd03l-keyflag,
      rollname  LIKE dd04l-rollname,
      memoryid  LIKE dd04l-memoryid,
      END OF gt_texts.

SELECTION-SCREEN BEGIN OF BLOCK bl1 WITH FRAME TITLE text-000.
PARAMETERS: p_table LIKE dd02l-tabname MEMORY ID dtb.
SELECTION-SCREEN END OF BLOCK bl1.

START-OF-SELECTION.

  READ REPORT 'YU_A00' INTO gt_code.
  READ TABLE gt_code WITH KEY line+1(4) = p_table.

  IF sy-subrc NE 0.
    PERFORM add_to_yu_a00.
    PERFORM add_to_yu_a01.
    PERFORM add_to_yu_a02.
    PERFORM add_to_yu_a03.
    PERFORM add_to_yu_a04.
    GENERATE REPORT 'YU_A'.
  ENDIF.

  SET PARAMETER ID 'DTB' FIELD p_table.
  CALL TRANSACTION 'YU_A' AND SKIP FIRST SCREEN.
*&---------------------------------------------------------------------*
*&      Form  add_to_YU_A00
*&---------------------------------------------------------------------*
FORM add_to_yu_a00 .
  CONCATENATE '*' p_table INTO gt_code.
  APPEND gt_code.
  INSERT REPORT 'YU_A00' FROM gt_code.

  LOOP AT gt_code.
    gt_tables-tabname = gt_code-line+1(4).
    APPEND gt_tables.
  ENDLOOP.

  PERFORM texts_modify.
ENDFORM.                    " add_to_YU_A00
*&---------------------------------------------------------------------*
*&      Form  add_to_YU_A01
*&---------------------------------------------------------------------*
FORM add_to_yu_a01 .
  CLEAR: gt_code, gt_code[].
  LOOP AT gt_tables.

    CONCATENATE '*SCREEN FOR' gt_tables-tabname INTO gt_code
      SEPARATED BY space.
    APPEND gt_code.

    CONCATENATE 'TABLES:' gt_tables-tabname '.' INTO gt_code
      SEPARATED BY space.
    APPEND gt_code.

    CONCATENATE
      'SELECTION-SCREEN BEGIN OF SCREEN 2' gt_tables-tabname+1(3) '.'
      INTO gt_code.
    APPEND gt_code.

    CONCATENATE
      'SELECTION-SCREEN BEGIN OF BLOCK' gt_tables-tabname
      'WITH FRAME TITLE text-000.'
      INTO gt_code SEPARATED BY space.
    APPEND gt_code.

    APPEND 'SELECT-OPTIONS :' TO gt_code.

    gv_first = 'X'.

    LOOP AT gt_texts WHERE tabname EQ gt_tables-tabname.
      IF gv_first EQ 'X'.
        CLEAR: gv_first.
        CONCATENATE gt_texts-tabname '-' gt_texts-fieldname
          INTO gt_code.
        IF gt_texts-memoryid IS NOT INITIAL.
          CONCATENATE gt_texts-name 'FOR' gt_code 'MEMORY ID'
            gt_texts-memoryid
            INTO gt_code SEPARATED BY space.
        ELSE.
          CONCATENATE gt_texts-name 'FOR' gt_code
            INTO gt_code SEPARATED BY space.
        ENDIF.
        APPEND gt_code.
      ELSE.
        CONCATENATE gt_texts-tabname '-' gt_texts-fieldname
          INTO gt_code.
        IF gt_texts-memoryid IS NOT INITIAL.
          CONCATENATE ',' gt_texts-name 'FOR' gt_code
            'MEMORY ID' gt_texts-memoryid
            INTO gt_code SEPARATED BY space.
        ELSE.
          CONCATENATE ',' gt_texts-name 'FOR' gt_code
            INTO gt_code SEPARATED BY space.
        ENDIF.
        APPEND gt_code.
      ENDIF.
    ENDLOOP.

    APPEND '.' TO gt_code.

    CONCATENATE
      'SELECTION-SCREEN END OF BLOCK' gt_tables-tabname '.'
      INTO gt_code SEPARATED BY space.
    APPEND gt_code.

    CONCATENATE
      'SELECTION-SCREEN END OF SCREEN 2' gt_tables-tabname+1(3) '.'
      INTO gt_code.
    APPEND gt_code.

    CLEAR gt_code.
    APPEND gt_code.

    APPEND '* DATA DECLERATIONS' TO gt_code.

    CONCATENATE 'DATA : BEGIN OF gt_' gt_tables-tabname INTO gt_code.
    CONCATENATE gt_code 'OCCURS 10,'
      INTO gt_code SEPARATED BY space.
    APPEND gt_code.

    LOOP AT gt_texts WHERE tabname EQ gt_tables-tabname.
      CONCATENATE gt_texts-tabname '-' gt_texts-fieldname INTO gt_code.
      CONCATENATE gt_texts-fieldname 'LIKE' gt_code ','
        INTO gt_code SEPARATED BY space.
      APPEND gt_code.
    ENDLOOP.

    CONCATENATE 'END OF gt_' gt_tables-tabname '.' INTO gt_code.
    APPEND gt_code.

    CLEAR gt_code.
    APPEND gt_code.
  ENDLOOP.
  INSERT REPORT 'YU_A01' FROM gt_code.
ENDFORM.                    " add_to_YU_A01
*&---------------------------------------------------------------------*
*&      Form  add_to_YU_A02
*&---------------------------------------------------------------------*
FORM add_to_yu_a02 .
  CLEAR: gt_code, gt_code[].
  LOOP AT gt_texts.
    CONCATENATE 'lt_texts-name = ''' gt_texts-name '''.'
      INTO gt_code.
    APPEND gt_code.
    CONCATENATE 'lt_texts-tabname = ''' gt_texts-tabname '''.'
      INTO gt_code.
    APPEND gt_code.
    CONCATENATE 'lt_texts-fieldname = ''' gt_texts-fieldname '''.'
      INTO gt_code.
    APPEND gt_code.
    CONCATENATE 'lt_texts-kind = ''' gt_texts-kind '''.'
      INTO gt_code.
    APPEND gt_code.
    APPEND 'APPEND lt_texts.'
      TO gt_code.
    CLEAR gt_code.
    APPEND gt_code.
  ENDLOOP.
  INSERT REPORT 'YU_A02' FROM gt_code.
ENDFORM.                    " add_to_YU_A02
*&---------------------------------------------------------------------*
*&      Form  add_to_YU_A03
*&---------------------------------------------------------------------*
FORM add_to_yu_a03 .
  CLEAR: gt_code, gt_code[].
  PERFORM add_form
    USING 'call_selection' gt_tables-tabname.
  PERFORM add_form
    USING 'fill_fcat' gt_tables-tabname.
  PERFORM add_form
    USING 'read_data' gt_tables-tabname.
  PERFORM add_form
    USING 'display_itab' gt_tables-tabname.
  INSERT REPORT 'YU_A03' FROM gt_code.
ENDFORM.                    " add_to_YU_A03
*&---------------------------------------------------------------------*
*&      Form  add_to_YU_A04
*&---------------------------------------------------------------------*
FORM add_to_yu_a04 .
  CLEAR: gt_code, gt_code[].
  LOOP AT gt_tables.

*&      Form  call_selection_a000

    CONCATENATE 'FORM call_selection_' gt_tables-tabname '.'
      INTO gt_code.
    APPEND gt_code.

    CONCATENATE 'CALL SELECTION-SCREEN 2' gt_tables-tabname+1(3) '.'
      INTO gt_code.
    APPEND gt_code.

    APPEND 'ENDFORM.' TO gt_code.

*&      Form  fill_fcat_a000

    CONCATENATE 'FORM fill_fcat_' gt_tables-tabname '.'
      INTO gt_code.
    APPEND gt_code.

    APPEND 'CALL FUNCTION ''REUSE_ALV_FIELDCATALOG_MERGE'''
      TO gt_code.

    APPEND 'EXPORTING'
      TO gt_code.

    APPEND 'i_program_name         = gv_repid'
      TO gt_code.

    CONCATENATE 'i_internal_tabname = ''GT_' gt_tables-tabname ''''
      INTO gt_code.
    APPEND gt_code.

    APPEND 'i_inclname = gv_repid'
      TO gt_code.

    APPEND 'CHANGING'
      TO gt_code.

    APPEND 'ct_fieldcat = gt_fcat[]'
      TO gt_code.

    APPEND 'EXCEPTIONS'
      TO gt_code.

    APPEND 'inconsistent_interface = 1'
      TO gt_code.

    APPEND 'program_error = 2'
      TO gt_code.

    APPEND 'OTHERS = 3.'
      TO gt_code.

    APPEND 'gs_lout-zebra = ''X''.'
      TO gt_code.

    APPEND 'ENDFORM.' TO gt_code.

*&      Form  top_of_page_a000

    CONCATENATE 'FORM top_of_page_' gt_tables-tabname '.'
      INTO gt_code.
    APPEND gt_code.

    CLEAR gt_code.
    APPEND gt_code.

    APPEND 'DATA: lv_low(20),'
      TO gt_code.

    APPEND 'lv_high(20).'
      TO gt_code.

    CLEAR gt_code.
    APPEND gt_code.

    APPEND 'REFRESH gt_hdr.'
      TO gt_code.

    APPEND 'MOVE : ''H'' TO gt_hdr-typ.'
      TO gt_code.

    APPEND 'SELECT SINGLE ddtext FROM dd02t INTO gt_hdr-info'
      TO gt_code.

    CONCATENATE 'WHERE tabname EQ ''' gt_tables-tabname ''''
      INTO gt_code.
    APPEND gt_code.

    APPEND 'AND ddlanguage EQ sy-langu.'
      TO gt_code.

    APPEND 'IF sy-subrc NE 0.'
      TO gt_code.

    APPEND 'SELECT SINGLE ddtext FROM dd02t INTO gt_hdr-info'
      TO gt_code.

    CONCATENATE 'WHERE tabname EQ ''' gt_tables-tabname ''''
      INTO gt_code.
    APPEND gt_code.

    APPEND 'AND ddlanguage EQ ''E ''.'
      TO gt_code.

    APPEND 'ENDIF.'
      TO gt_code.

    CLEAR gt_code.
    APPEND gt_code.

    APPEND 'APPEND gt_hdr. CLEAR gt_hdr.'
      TO gt_code.

    CLEAR gt_code.
    APPEND gt_code.

    LOOP AT gt_texts WHERE tabname EQ gt_tables-tabname.

      CONCATENATE 'PERFORM get_dd04t USING ''' gt_texts-rollname
       ''' CHANGING gt_hdr-key.' INTO gt_code.
      APPEND gt_code.

      APPEND 'MOVE : ''S'' TO gt_hdr-typ.' TO gt_code.

      CONCATENATE 'WRITE :' gt_texts-name
        INTO gt_code SEPARATED BY space.
      CONCATENATE gt_code '-low TO lv_low,'
        INTO gt_code.
      APPEND gt_code.

      CONCATENATE gt_texts-name '-high TO lv_high.'
        INTO gt_code.
      APPEND gt_code.

      APPEND 'CONCATENATE lv_low '' - '' lv_high INTO gt_hdr-info.'
        TO gt_code.

      APPEND 'APPEND gt_hdr. CLEAR gt_hdr.'
        TO gt_code.

      CLEAR gt_code.
      APPEND gt_code.
    ENDLOOP.


    APPEND 'CALL FUNCTION ''REUSE_ALV_COMMENTARY_WRITE'''
      TO gt_code.

    APPEND 'EXPORTING'
      TO gt_code.

    APPEND 'it_list_commentary       = gt_hdr[]'
      TO gt_code.

    APPEND '.'
      TO gt_code.

    APPEND 'ENDFORM.' TO gt_code.

*&      Form  call_selection_a000

    CONCATENATE 'FORM read_data_' gt_tables-tabname '.'
      INTO gt_code.
    APPEND gt_code.

    CONCATENATE 'SELECT * FROM' gt_tables-tabname
      INTO gt_code SEPARATED BY space.
    APPEND gt_code.

    CONCATENATE 'INTO CORRESPONDING FIELDS OF TABLE gt_'
                gt_tables-tabname
      INTO gt_code.
    APPEND gt_code.

    APPEND 'WHERE' TO gt_code.

    gv_first = 'X'.

    LOOP AT gt_texts WHERE tabname EQ gt_tables-tabname.

      IF gv_first EQ 'X'.
        CLEAR: gv_first.
        CONCATENATE gt_texts-fieldname 'IN' gt_texts-name
          INTO gt_code SEPARATED BY space.
        APPEND gt_code.
      ELSE.
        CONCATENATE 'AND' gt_texts-fieldname 'IN' gt_texts-name
          INTO gt_code SEPARATED BY space.
        APPEND gt_code.
      ENDIF.
    ENDLOOP.

    APPEND '.' TO gt_code.

    APPEND 'ENDFORM.' TO gt_code.

*&      Form  display_itab_a000

    CONCATENATE 'FORM display_itab_' gt_tables-tabname '.'
      INTO gt_code.
    APPEND gt_code.

    APPEND 'CALL FUNCTION ''REUSE_ALV_GRID_DISPLAY''' TO gt_code.

    APPEND 'EXPORTING' TO gt_code.
    APPEND 'i_callback_program       = gv_repid' TO gt_code.
    APPEND 'i_callback_pf_status_set = ''SET_PF_STATUS''' TO gt_code.
    APPEND 'i_callback_user_command  = ''USER_COMMAND''' TO gt_code.

    CONCATENATE 'i_callback_top_of_page   = ''TOP_OF_PAGE_'
      gt_tables-tabname ''''
      INTO gt_code.
    APPEND gt_code.

    APPEND 'is_layout                = gs_lout' TO gt_code.
    APPEND 'it_fieldcat              = gt_fcat[]' TO gt_code.
    APPEND 'it_sort                  = gt_sort[]' TO gt_code.
    APPEND 'TABLES' TO gt_code.

    CONCATENATE 't_outtab                 = gt_' gt_tables-tabname
      INTO gt_code.
    APPEND gt_code.

    APPEND 'EXCEPTIONS' TO gt_code.
    APPEND 'program_error            = 1' TO gt_code.
    APPEND 'OTHERS                   = 2.' TO gt_code.
    APPEND 'ENDFORM.' TO gt_code.

  ENDLOOP.
  INSERT REPORT 'YU_A04' FROM gt_code.
ENDFORM.                    " add_to_YU_A04
*&---------------------------------------------------------------------*
*&      Form  texts_modify
*&---------------------------------------------------------------------*
FORM texts_modify .
  SELECT tabname fieldname rollname keyflag FROM dd03l
    INTO CORRESPONDING FIELDS OF TABLE gt_texts
    FOR ALL ENTRIES IN gt_tables
    WHERE tabname   EQ gt_tables-tabname
      AND fieldname NE 'MANDT'
      AND keyflag   EQ 'X'.

  SORT gt_texts.
  DELETE ADJACENT DUPLICATES FROM gt_texts.

  LOOP AT gt_texts.
    gv_index = sy-tabix.
    CONCATENATE 'S_' gv_index INTO gt_texts-name.
    gt_texts-kind = 'S'.
    SELECT SINGLE memoryid FROM dd04l INTO gt_texts-memoryid
      WHERE rollname   EQ gt_texts-rollname.
    SELECT SINGLE scrtext_m FROM dd04t INTO gt_texts-text
      WHERE rollname   EQ gt_texts-rollname
        AND ddlanguage EQ sy-langu.
    IF sy-subrc NE 0.
      SELECT SINGLE ddtext FROM dd04t INTO gt_texts-text
        WHERE rollname   EQ gt_texts-rollname
          AND ddlanguage EQ 'E '.
    ENDIF.
    MODIFY gt_texts.
  ENDLOOP.
ENDFORM.                    " texts_modify
*&---------------------------------------------------------------------*
*&      Form  add_form
*&---------------------------------------------------------------------*
FORM add_form  USING lv_form TYPE char20
                     lv_table LIKE dd03l-tabname.

  CONCATENATE 'FORM' lv_form '.' INTO gt_code SEPARATED BY space.
  APPEND gt_code.
  APPEND 'CASE p_table.' TO gt_code.
  LOOP AT gt_tables.
    CONCATENATE 'WHEN ''' gt_tables-tabname '''.' INTO gt_code.
    APPEND gt_code.
    CONCATENATE lv_form '_' gt_tables-tabname '.' INTO gt_code.
    CONCATENATE 'PERFORM' gt_code  INTO gt_code SEPARATED BY space.
    APPEND gt_code.
  ENDLOOP.
  APPEND 'ENDCASE.' TO gt_code.
  APPEND 'ENDFORM.' TO gt_code.
  CLEAR gt_code.
  APPEND gt_code.

ENDFORM.                    " add_form
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