SAP Bilgi Merkezi
Ana Sayfa  ABAP   FI   CO   MM   SD   PP   QM   HR   BW 
ABAP Destek
Muhasebe Belgesi At

Sisteme muhasebe belgesi atabilmek için aşağıdaki programı kopyalayabilirsiniz.

Örnek Program:

*&---------------------------------------------------------------------
*& Created Date : 1.11.2006                                            *
*& Created By   : Yavuz KOMUT                                          *
*&---------------------------------------------------------------------*
REPORT  zco_otomatik_fis_kaydi.

TYPE-POOLS : slis.
TABLES : bkpf, bseg, t001, ckmlprkeph, mbew, ckmlpp, t001k,
  zco_fis_hesap.

*----------------------------------------------------------------------*
*   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_poper    TYPE poper      OBLIGATORY,
                 p_gjahr    TYPE gjahr      OBLIGATORY.
SELECT-OPTIONS : s_bukrs FOR bseg-bukrs MEMORY ID buk OBLIGATORY
  NO-EXTENSION NO INTERVALS,
                 s_matnr FOR bseg-matnr MEMORY ID mat.
SELECTION-SCREEN END OF BLOCK bl1.
SELECTION-SCREEN BEGIN OF BLOCK bl2 WITH FRAME TITLE text-010.
PARAMETERS :     p_gsber LIKE bseg-gsber MEMORY ID gsb OBLIGATORY,
                 p_budat LIKE bkpf-budat DEFAULT sy-datum OBLIGATORY.
SELECTION-SCREEN END OF BLOCK bl2.

* DATA DECLERATIONS
DATA : BEGIN OF gt_alv OCCURS 10,
         markx,
         index LIKE sy-tabix,
         bschl LIKE bseg-bschl,
         hkont LIKE bseg-hkont,
         txt20 LIKE skat-txt20,
         bsch2 LIKE bseg-bschl,
         hkon2 LIKE bseg-hkont,
         txt22 LIKE skat-txt20,
         matnr LIKE bseg-matnr,
         menge LIKE bseg-menge,
         meins LIKE bseg-meins,
         wrbtr LIKE bseg-wrbtr,
         waers LIKE bkpf-waers,
         bukrs LIKE bseg-bukrs,
         werks LIKE bseg-werks,
         gsber LIKE bseg-gsber,
         kostl LIKE bseg-kostl,
         budat LIKE bkpf-budat,
         xblnr LIKE bkpf-xblnr,
         lifnr LIKE bseg-lifnr,
       END OF gt_alv.

DATA : gt_tmp LIKE gt_alv OCCURS 10 WITH HEADER LINE .

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

* 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,
       gv_kostl LIKE zco_fis_kostl-kostl,
       gv_index LIKE sy-tabix.

RANGES : r_budat FOR bkpf-budat.

START-OF-SELECTION.
  PERFORM init_data.
  PERFORM read_data.

END-OF-SELECTION.
  PERFORM display.

*&---------------------------------------------------------------------*
*&      Form  display
*&---------------------------------------------------------------------*
FORM display .
  PERFORM fill_fcat.
  PERFORM display_itab.
ENDFORM.                    " display
*&---------------------------------------------------------------------*
*&      Form  fill_fcat
*&---------------------------------------------------------------------*
FORM fill_fcat .
  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      i_program_name         = gv_repid
      i_internal_tabname     = 'GT_ALV'
      i_inclname             = gv_repid
    CHANGING
      ct_fieldcat            = gt_fcat[]
    EXCEPTIONS
      inconsistent_interface = 1
      program_error          = 2
      OTHERS                 = 3.

  gs_lout-zebra = 'X'.
  gs_lout-colwidth_optimize = 'X'.
  gs_lout-box_tabname = 'GT_ALV'.
  gs_lout-box_fieldname = 'MARKX'.
  READ TABLE gt_fcat WITH KEY fieldname = 'MARKX'.
  gt_fcat-checkbox = 'X'.
  gt_fcat-edit = 'X'.
  gt_fcat-tech = 'X'.
  MODIFY gt_fcat INDEX sy-tabix.

*  LOOP AT gt_fcat.
*    CASE gt_fcat-fieldname.
*      WHEN 'VBELN'.
*        gt_fcat-key = 'X'.
*      WHEN 'B_103' OR 'MEINS' OR 'B_105' OR 'MARK'.
*        gt_fcat-tech = 'X'.
*      WHEN 'Q_103'.
*        gt_fcat-seltext_s = gt_fcat-seltext_m .
*        gt_fcat-seltext_l = text-006.
*        gt_fcat-do_sum    = 'X'.
*      WHEN 'Q_105'.
*        gt_fcat-seltext_s = gt_fcat-seltext_m .
*        gt_fcat-seltext_l = text-007.
*        gt_fcat-do_sum    = 'X'.
*      WHEN 'Q_DIF'.
*        gt_fcat-seltext_s = gt_fcat-seltext_m .
*        gt_fcat-seltext_l = text-008.
*        gt_fcat-do_sum    = 'X'.
*      WHEN 'DAYS'.
*        gt_fcat-seltext_s = gt_fcat-seltext_m .
*        gt_fcat-seltext_l = text-009.
*    ENDCASE.
*    MODIFY gt_fcat.
*  ENDLOOP.
ENDFORM.                    " fill_fcat

*&---------------------------------------------------------------------*
*&      Form  top_of_page
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM top_of_page.

  REFRESH gt_hdr.
  MOVE : 'H' TO gt_hdr-typ,
       text-002 TO gt_hdr-info.
  APPEND gt_hdr. CLEAR gt_hdr.

  MOVE : 'S' TO gt_hdr-typ,
         text-003 TO gt_hdr-key.
  CONCATENATE p_poper '/' p_gjahr INTO gt_hdr-info.
  APPEND gt_hdr. CLEAR gt_hdr.

  MOVE : 'S' TO gt_hdr-typ,
         text-004 TO gt_hdr-key.
  IF s_bukrs[] IS NOT INITIAL.
    IF s_bukrs-high IS NOT INITIAL.
      CONCATENATE s_bukrs-low ' - ' s_bukrs-high INTO gt_hdr-info.
    ELSE.
      WRITE s_bukrs-low TO gt_hdr-info.
    ENDIF.
  ENDIF.
  APPEND gt_hdr. CLEAR gt_hdr.

*  MOVE : 'S' TO gt_hdr-typ,
*         text-005 TO gt_hdr-key.
*  IF s_gsber[] IS NOT INITIAL.
*    IF s_gsber-high IS NOT INITIAL.
*      CONCATENATE s_gsber-low ' - ' s_gsber-high INTO gt_hdr-info.
*    ELSE.
*      WRITE s_gsber-low TO gt_hdr-info.
*    ENDIF.
*  ENDIF.
*  APPEND gt_hdr. CLEAR gt_hdr.

  MOVE : 'S' TO gt_hdr-typ,
         text-006 TO gt_hdr-key.
  IF s_matnr[] IS NOT INITIAL.
    IF s_matnr-high IS NOT INITIAL.
      CONCATENATE s_matnr-low ' - ' s_matnr-high INTO gt_hdr-info.
    ELSE.
      WRITE s_matnr-low TO gt_hdr-info.
    ENDIF.
  ENDIF.
  APPEND gt_hdr. CLEAR gt_hdr.


  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = gt_hdr[]
*     I_LOGO             =
*     I_END_OF_LIST_GRID =
*     I_ALV_FORM         =
    .
ENDFORM.                    "top_of_page
*&---------------------------------------------------------------------*
*&      Form  display_itab
*&---------------------------------------------------------------------*
FORM display_itab .
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program       = gv_repid
      i_callback_pf_status_set = 'SET_PF_STATUS'
      i_callback_user_command  = 'USER_COMMAND'
      i_callback_top_of_page   = 'TOP_OF_PAGE'
      is_layout                = gs_lout
      it_fieldcat              = gt_fcat[]
      it_sort                  = gt_sort[]
    TABLES
      t_outtab                 = gt_alv
    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.                    " display_itab

*&---------------------------------------------------------------------*
*&      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 'SAV'.
    PERFORM save_data.
  ENDIF.
ENDFORM.                    "user_command

*&---------------------------------------------------------------------*
*&      Form  read_material_text
*&---------------------------------------------------------------------*
FORM read_material_text .
*  SELECT SINGLE arktx FROM lips
*                      INTO itab-maktx
*                      WHERE vbeln EQ itab-vbeln AND
*                            posnr EQ itab-posnr.
ENDFORM.                    " read_material_text
*&---------------------------------------------------------------------*
*&      Form  read_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM read_data .

  DATA: lv_wrbtr LIKE gt_alv-wrbtr,
        lv_index LIKE sy-tabix.

  CLEAR: lv_index.

  RANGES: r_hkont FOR bseg-hkont,
          r_bwkey FOR mbew-bwkey.

  DATA: BEGIN OF lt_smm OCCURS 10,
         belnr LIKE bseg-belnr,
         gjahr LIKE bseg-gjahr,
         bschl LIKE bseg-bschl,
         hkont LIKE bseg-hkont,
         matnr LIKE bseg-matnr,
         dmbtr LIKE bseg-dmbtr,
         menge LIKE bseg-menge,
         meins LIKE bseg-meins,
         bukrs LIKE bseg-bukrs,
         werks LIKE bseg-werks,
         gsber LIKE bseg-gsber,
         verpr LIKE mbew-verpr,
         peinh LIKE mbew-peinh,
         waers LIKE t001-waers,
         kaln1 LIKE mbew-kaln1,
         lifnr LIKE bseg-lifnr,
         verp1 LIKE mbew-verpr,
         verp2 LIKE mbew-verpr,
         verp3 LIKE mbew-verpr,
        END OF lt_smm.

  DATA: BEGIN OF lt_sdk OCCURS 10,
         matnr LIKE mbew-matnr,
         kaln1 LIKE mbew-kaln1,
         bwkey LIKE mbew-bwkey,
         lbkum LIKE ckmlpp-lbkum,
         meins LIKE ckmlpp-meins,
         verp1 LIKE mbew-verpr,
         verp2 LIKE mbew-verpr,
         verp3 LIKE mbew-verpr,
        END OF lt_sdk.

  DATA: lv_hkont LIKE bseg-hkont.

  DATA : lt_account_list
        LIKE TABLE OF bapi3006_1 WITH HEADER LINE.
  DATA : lt_balance LIKE  bapi3006_4 OCCURS 0 WITH HEADER LINE.

  DATA : w_return LIKE bapireturn,
         lv_711 LIKE lt_balance-per_sales,
         lv_736 LIKE lt_balance-per_sales.

* Satılan Malın Maliyeti Kaydı 1

  CLEAR: lt_smm, lt_smm[], r_hkont, r_hkont[].
  CLEAR: lt_account_list, lt_account_list[],
         lv_711, lv_736.

  READ TABLE s_bukrs INDEX 1.
  SELECT SINGLE * FROM t001 WHERE bukrs EQ s_bukrs-low.

  CALL FUNCTION 'BAPI_GL_ACC_GETLIST'
    EXPORTING
      companycode  = s_bukrs-low
    TABLES
      account_list = lt_account_list[].

  r_hkont = 'IBT'.
  r_hkont-low = '7100000000'.
  r_hkont-high = '7106999999'.
  APPEND r_hkont.

  r_hkont = 'IBT'.
  r_hkont-low = '7350000000'.
  r_hkont-high = '7356999999'.
  APPEND r_hkont.

  DELETE lt_account_list WHERE gl_account NOT IN r_hkont.

  LOOP AT lt_account_list.

    CLEAR: lt_balance, lt_balance[].

    CALL FUNCTION 'BAPI_GL_ACC_GETPERIODBALANCES'
      EXPORTING
        companycode             = s_bukrs-low
        glacct                  = lt_account_list-gl_account
        fiscalyear              = p_gjahr
        currencytype            = '10'
      IMPORTING
*       BALANCE_CARRIED_FORWARD =
        return                  = w_return
      TABLES
        account_balances        = lt_balance.

    READ TABLE lt_balance WITH KEY fis_period = p_poper+1(2).
    IF sy-subrc EQ 0.
      IF lt_balance-gl_account(3) EQ '710'.
        lv_711 = lv_711 + lt_balance-per_sales.
      ELSEIF lt_balance-gl_account(3) EQ '735'.
        lv_736 = lv_736 + lt_balance-per_sales.
      ENDIF.
    ENDIF.
  ENDLOOP.

  IF lv_711 > 0 OR lv_736 > 0.

    lv_index = lv_index + 1.
    SELECT SINGLE * FROM t001 WHERE bukrs EQ s_bukrs-low.
    CLEAR: gt_alv.
    gt_alv-bschl = '40'.
*    gt_alv-hkon2 = '6208521000'.
*    gt_alv-matnr = lt_smm-matnr.
*    gt_alv-menge = lt_smm-menge.
*    gt_alv-meins = lt_smm-meins.
*    gt_alv-werks = lt_smm-werks.
    gt_alv-bukrs = s_bukrs-low.
    gt_alv-waers = t001-waers.
    gt_alv-gsber = p_gsber.
    gt_alv-kostl = gv_kostl.
    gt_alv-budat = p_budat.
    gt_alv-wrbtr = lv_711 + lv_736.
*    CONCATENATE lt_smm-gjahr lt_smm-belnr INTO gt_alv-xblnr.
    gt_alv-hkont = '8900000102'.
    SELECT SINGLE txt20 FROM skat INTO gt_alv-txt20
      WHERE spras EQ sy-langu AND
            ktopl EQ 'CATR' AND
            saknr EQ gt_alv-hkont.
    IF sy-subrc NE 0.
      SELECT SINGLE txt20 FROM skat INTO gt_alv-txt20
        WHERE ktopl EQ 'CATR' AND
              saknr EQ gt_alv-hkont.
    ENDIF.
    gt_alv-index = lv_index.
    APPEND gt_alv.

    CLEAR: gt_alv.
    gt_alv-bsch2 = '50'.
*    gt_alv-hkon2 = '6208521000'.
*    gt_alv-matnr = lt_smm-matnr.
*    gt_alv-menge = lt_smm-menge.
*    gt_alv-meins = lt_smm-meins.
*    gt_alv-werks = lt_smm-werks.
    gt_alv-bukrs = s_bukrs-low.
    gt_alv-waers = t001-waers.
    gt_alv-gsber = p_gsber.
    gt_alv-kostl = gv_kostl.
    gt_alv-budat = p_budat.
    gt_alv-wrbtr = lv_711.
*    CONCATENATE lt_smm-gjahr lt_smm-belnr INTO gt_alv-xblnr.
    SELECT SINGLE hkon2 FROM zco_fis_hesap
      INTO gt_alv-hkon2
     WHERE hkont LIKE '710%' AND
           typex EQ 'YANSITMA'.
    SELECT SINGLE txt20 FROM skat INTO gt_alv-txt22
      WHERE spras EQ sy-langu AND
            ktopl EQ 'CATR' AND
            saknr EQ gt_alv-hkon2.
    IF sy-subrc NE 0.
      SELECT SINGLE txt20 FROM skat INTO gt_alv-txt22
        WHERE ktopl EQ 'CATR' AND
              saknr EQ gt_alv-hkon2.
    ENDIF.
    gt_alv-index = lv_index.
    APPEND gt_alv.

    CLEAR: gt_alv.
    gt_alv-bsch2 = '50'.
*    gt_alv-hkon2 = '6208521000'.
*    gt_alv-matnr = lt_smm-matnr.
*    gt_alv-menge = lt_smm-menge.
*    gt_alv-meins = lt_smm-meins.
*    gt_alv-werks = lt_smm-werks.
    gt_alv-bukrs = s_bukrs-low.
    gt_alv-waers = t001-waers.
    gt_alv-gsber = p_gsber.
    gt_alv-kostl = gv_kostl.
    gt_alv-budat = p_budat.
    gt_alv-wrbtr = lv_736.
*    CONCATENATE lt_smm-gjahr lt_smm-belnr INTO gt_alv-xblnr.
    SELECT SINGLE hkon2 FROM zco_fis_hesap
      INTO gt_alv-hkon2
     WHERE hkont LIKE '735%' AND
           typex EQ 'YANSITMA'.
    SELECT SINGLE txt20 FROM skat INTO gt_alv-txt22
      WHERE spras EQ sy-langu AND
            ktopl EQ 'CATR' AND
            saknr EQ gt_alv-hkon2.
    IF sy-subrc NE 0.
      SELECT SINGLE txt20 FROM skat INTO gt_alv-txt22
        WHERE ktopl EQ 'CATR' AND
              saknr EQ gt_alv-hkon2.
    ENDIF.

    gt_alv-index = lv_index.
    APPEND gt_alv.
  ENDIF.

* Satılan Malın Maliyeti Kaydı 2

  CLEAR: lt_smm, lt_smm[], r_hkont, r_hkont[].

  SELECT hkont AS low FROM zco_fis_hesap
    INTO CORRESPONDING FIELDS OF TABLE r_hkont
    WHERE typex EQ space.

  LOOP AT r_hkont.
    r_hkont-sign = 'I'.
    r_hkont-option = 'EQ'.
    MODIFY r_hkont.
  ENDLOOP.

  SELECT * FROM bkpf
    WHERE bukrs IN s_bukrs AND
          bstat EQ space   AND
          budat IN r_budat AND
          blart EQ 'WA'.
    SELECT * FROM bseg
      WHERE bukrs EQ bkpf-bukrs AND
            belnr EQ bkpf-belnr AND
            gjahr EQ bkpf-gjahr AND
*            gsber IN s_gsber AND
            matnr IN s_matnr AND
            hkont IN r_hkont.
      MOVE-CORRESPONDING bkpf TO lt_smm.
      MOVE-CORRESPONDING bseg TO lt_smm.
      APPEND lt_smm.
    ENDSELECT.
  ENDSELECT.

  DELETE lt_smm WHERE matnr IS INITIAL.

  LOOP AT lt_smm.
    SELECT SINGLE verpr peinh FROM mbew
      INTO (lt_smm-verpr, lt_smm-peinh )
      WHERE matnr EQ lt_smm-matnr AND
            bwkey EQ lt_smm-werks.
    MODIFY lt_smm.
  ENDLOOP.

  SORT lt_smm.

  LOOP AT lt_smm.

    lv_index = lv_index + 1.
    CLEAR: lv_wrbtr.
    lv_wrbtr = lt_smm-dmbtr.
*    lv_wrbtr = lt_smm-verpr * lt_smm-menge / lt_smm-peinh.
    SELECT SINGLE * FROM t001 WHERE bukrs EQ lt_smm-bukrs.
    CLEAR: gt_alv.
    gt_alv-bschl = '40'.
    SELECT SINGLE hkon2 FROM zco_fis_hesap
      INTO gt_alv-hkont
     WHERE hkont EQ lt_smm-hkont AND
           typex EQ space.
    gt_alv-matnr = lt_smm-matnr.
    gt_alv-menge = lt_smm-menge.
    gt_alv-meins = lt_smm-meins.
    gt_alv-werks = lt_smm-werks.
    gt_alv-bukrs = lt_smm-bukrs.
    gt_alv-waers = t001-waers.
    gt_alv-wrbtr = lv_wrbtr.
    gt_alv-gsber = lt_smm-gsber. "p_gsber.
    SELECT SINGLE kostl FROM zco_fis_kostl INTO gt_alv-kostl
      WHERE gsber EQ lt_smm-gsber.
    IF sy-subrc NE 0.
*      gt_alv-gsber = p_gsber.
      gt_alv-kostl = gv_kostl.
    ENDIF.
    gt_alv-budat = p_budat.
    CONCATENATE lt_smm-gjahr lt_smm-belnr INTO gt_alv-xblnr.
    SELECT SINGLE txt20 FROM skat INTO gt_alv-txt20
      WHERE spras EQ sy-langu AND
            ktopl EQ 'CATR' AND
            saknr EQ gt_alv-hkont.
    IF sy-subrc NE 0.
      SELECT SINGLE txt20 FROM skat INTO gt_alv-txt20
        WHERE ktopl EQ 'CATR' AND
              saknr EQ gt_alv-hkont.
    ENDIF.
    gt_alv-index = lv_index.
    APPEND gt_alv.
    CLEAR: gt_alv.
    gt_alv-bsch2 = '50'.
    gt_alv-hkon2 = lt_smm-hkont.
    gt_alv-matnr = lt_smm-matnr.
    gt_alv-menge = lt_smm-menge.
    gt_alv-meins = lt_smm-meins.
    gt_alv-werks = lt_smm-werks.
    gt_alv-bukrs = lt_smm-bukrs.
    gt_alv-waers = t001-waers.
    gt_alv-wrbtr = lv_wrbtr.
    gt_alv-gsber = lt_smm-gsber. "p_gsber.
    SELECT SINGLE kostl FROM zco_fis_kostl INTO gt_alv-kostl
      WHERE gsber EQ lt_smm-gsber.
    IF sy-subrc NE 0.
*      gt_alv-gsber = p_gsber.
      gt_alv-kostl = gv_kostl.
    ENDIF.
    gt_alv-budat = p_budat.
    CONCATENATE lt_smm-gjahr lt_smm-belnr INTO gt_alv-xblnr.
    SELECT SINGLE txt20 FROM skat INTO gt_alv-txt22
      WHERE spras EQ sy-langu AND
            ktopl EQ 'CATR' AND
            saknr EQ gt_alv-hkon2.
    IF sy-subrc NE 0.
      SELECT SINGLE txt20 FROM skat INTO gt_alv-txt22
        WHERE ktopl EQ 'CATR' AND
              saknr EQ gt_alv-hkon2.
    ENDIF.
    gt_alv-index = lv_index.
    APPEND gt_alv.
  ENDLOOP.

* Dahili Transfer
  CLEAR: lt_smm, lt_smm[], r_hkont, r_hkont[].

  SELECT DISTINCT hkont AS low FROM zco_fis_hesap
    INTO CORRESPONDING FIELDS OF TABLE r_hkont
   WHERE typex EQ 'AMORTISMAN' OR
         typex EQ 'DEGISKEN' OR
         typex EQ 'SABIT'.

  LOOP AT r_hkont.
    r_hkont-sign = 'I'.
    r_hkont-option = 'EQ'.
    MODIFY r_hkont.
  ENDLOOP.

  SELECT * FROM bkpf
    WHERE bukrs IN s_bukrs AND
          bstat EQ space   AND
          budat IN r_budat AND
          blart EQ 'WA'.
    SELECT * FROM bseg
      WHERE bukrs EQ bkpf-bukrs AND
            belnr EQ bkpf-belnr AND
            gjahr EQ bkpf-gjahr AND
*            gsber IN s_gsber AND
            matnr IN s_matnr AND
            hkont IN r_hkont.
      MOVE-CORRESPONDING bkpf TO lt_smm.
      MOVE-CORRESPONDING bseg TO lt_smm.
      APPEND lt_smm.
    ENDSELECT.
  ENDSELECT.

  DELETE lt_smm WHERE matnr IS INITIAL.

  LOOP AT lt_smm.
    CLEAR: ckmlprkeph.
    SELECT SINGLE kaln1 FROM mbew
      INTO lt_smm-kaln1
      WHERE matnr EQ lt_smm-matnr AND
            bwkey EQ lt_smm-werks.
    SELECT SINGLE * FROM ckmlprkeph
      WHERE kalnr EQ lt_smm-kaln1 AND
            bdatj EQ p_gjahr AND
            poper EQ p_poper AND
            keart EQ 'H' AND
            prtyp EQ 'V' AND
            curtp EQ '10'.
    lt_smm-verp1 =
      ckmlprkeph-kst001 + ckmlprkeph-kst003 + ckmlprkeph-kst005 +
      ckmlprkeph-kst007 + ckmlprkeph-kst009 + ckmlprkeph-kst011 +
      ckmlprkeph-kst013 + ckmlprkeph-kst015 + ckmlprkeph-kst017 +
      ckmlprkeph-kst019 + ckmlprkeph-kst021 + ckmlprkeph-kst023 +
      ckmlprkeph-kst025 + ckmlprkeph-kst027 + ckmlprkeph-kst029.
    lt_smm-verp2 =
      ckmlprkeph-kst031 + ckmlprkeph-kst033 + ckmlprkeph-kst035 +
      ckmlprkeph-kst037.
    lt_smm-verp3 =
      ckmlprkeph-kst039.
    MODIFY lt_smm.
  ENDLOOP.

  SORT lt_smm.

  LOOP AT lt_smm.
    lv_index = lv_index + 1.
    CLEAR: lv_wrbtr.
    lv_wrbtr = lt_smm-verp1 + lt_smm-verp2 + lt_smm-verp3.
    SELECT SINGLE * FROM t001 WHERE bukrs EQ lt_smm-bukrs.
    CLEAR: gt_alv.
    gt_alv-bschl = '40'.
*    gt_alv-hkon2 = '6208521000'.
    gt_alv-matnr = lt_smm-matnr.
    gt_alv-menge = lt_smm-menge.
    gt_alv-meins = lt_smm-meins.
    gt_alv-werks = lt_smm-werks.
    gt_alv-bukrs = lt_smm-bukrs.
    gt_alv-waers = t001-waers.
    gt_alv-gsber = lt_smm-gsber. "p_gsber.
    SELECT SINGLE kostl FROM zco_fis_kostl INTO gt_alv-kostl
      WHERE gsber EQ lt_smm-gsber.
    IF sy-subrc NE 0.
*      gt_alv-gsber = p_gsber.
      gt_alv-kostl = gv_kostl.
    ENDIF.
    gt_alv-budat = p_budat.
    gt_alv-wrbtr = lv_wrbtr * gt_alv-menge.
    CONCATENATE lt_smm-gjahr lt_smm-belnr INTO gt_alv-xblnr.
    SELECT SINGLE hkon2 FROM zco_fis_hesap
      INTO gt_alv-hkont
     WHERE hkont EQ lt_smm-hkont AND
           typex EQ 'TOPLAM'.
    SELECT SINGLE txt20 FROM skat INTO gt_alv-txt20
      WHERE spras EQ sy-langu AND
            ktopl EQ 'CATR' AND
            saknr EQ gt_alv-hkont.
    IF sy-subrc NE 0.
      SELECT SINGLE txt20 FROM skat INTO gt_alv-txt20
        WHERE ktopl EQ 'CATR' AND
              saknr EQ gt_alv-hkont.
    ENDIF.
    gt_alv-index = lv_index.
    APPEND gt_alv.
    CLEAR: gt_alv.
    gt_alv-bsch2 = '50'.
    gt_alv-matnr = lt_smm-matnr.
    gt_alv-menge = lt_smm-menge.
    gt_alv-meins = lt_smm-meins.
    gt_alv-werks = lt_smm-werks.
    gt_alv-bukrs = lt_smm-bukrs.
    gt_alv-waers = t001-waers.
    gt_alv-wrbtr = lv_wrbtr * lt_smm-menge.
    gt_alv-gsber = lt_smm-gsber. "p_gsber.
    SELECT SINGLE kostl FROM zco_fis_kostl INTO gt_alv-kostl
      WHERE gsber EQ lt_smm-gsber.
    IF sy-subrc NE 0.
*      gt_alv-gsber = p_gsber.
      gt_alv-kostl = gv_kostl.
    ENDIF.
    gt_alv-budat = p_budat.
    CONCATENATE lt_smm-gjahr lt_smm-belnr INTO gt_alv-xblnr.

    SELECT SINGLE hkon2 FROM zco_fis_hesap
      INTO gt_alv-hkon2
     WHERE hkont EQ lt_smm-hkont AND
           typex EQ 'DEGISKEN'.
    gt_alv-wrbtr = lt_smm-verp1 * lt_smm-menge.
    SELECT SINGLE txt20 FROM skat INTO gt_alv-txt22
      WHERE spras EQ sy-langu AND
            ktopl EQ 'CATR' AND
            saknr EQ gt_alv-hkon2.
    IF sy-subrc NE 0.
      SELECT SINGLE txt20 FROM skat INTO gt_alv-txt22
        WHERE ktopl EQ 'CATR' AND
              saknr EQ gt_alv-hkon2.
    ENDIF.
    gt_alv-index = lv_index.
    APPEND gt_alv.
    SELECT SINGLE hkon2 FROM zco_fis_hesap
      INTO gt_alv-hkon2
     WHERE hkont EQ lt_smm-hkont AND
           typex EQ 'SABIT'.
    gt_alv-wrbtr = lt_smm-verp2 * lt_smm-menge.
    SELECT SINGLE txt20 FROM skat INTO gt_alv-txt22
      WHERE spras EQ sy-langu AND
            ktopl EQ 'CATR' AND
            saknr EQ gt_alv-hkon2.
    IF sy-subrc NE 0.
      SELECT SINGLE txt20 FROM skat INTO gt_alv-txt22
        WHERE ktopl EQ 'CATR' AND
              saknr EQ gt_alv-hkon2.
    ENDIF.
    gt_alv-index = lv_index.
    APPEND gt_alv.
    SELECT SINGLE hkon2 FROM zco_fis_hesap
      INTO gt_alv-hkon2
     WHERE hkont EQ lt_smm-hkont AND
           typex EQ 'AMORTISMAN'.
    gt_alv-wrbtr = lt_smm-verp3 * lt_smm-menge.
    SELECT SINGLE txt20 FROM skat INTO gt_alv-txt22
      WHERE spras EQ sy-langu AND
            ktopl EQ 'CATR' AND
            saknr EQ gt_alv-hkon2.
    IF sy-subrc NE 0.
      SELECT SINGLE txt20 FROM skat INTO gt_alv-txt22
        WHERE ktopl EQ 'CATR' AND
              saknr EQ gt_alv-hkon2.
    ENDIF.
    gt_alv-index = lv_index.
    APPEND gt_alv.
  ENDLOOP.

* Stok Değişim Kayıtları

  CLEAR: r_bwkey, r_bwkey[], lt_sdk, lt_sdk[].

  SELECT bwkey AS low FROM t001k
    INTO CORRESPONDING FIELDS OF TABLE r_bwkey
    WHERE bukrs NOT IN s_bukrs.

  LOOP AT r_bwkey.
    r_bwkey-sign = 'E'.
    r_bwkey-option = 'EQ'.
    MODIFY r_bwkey.
  ENDLOOP.

  SELECT matnr kaln1 bwkey FROM mbew
    INTO CORRESPONDING FIELDS OF TABLE lt_sdk
   WHERE bwkey IN r_bwkey AND
       ( bklas EQ '7900' OR
         bklas EQ '7920' ).

  LOOP AT lt_sdk.
    SELECT SINGLE * FROM ckmlpp
      WHERE kalnr EQ lt_sdk-kaln1 AND
            bdatj EQ p_gjahr AND
            poper EQ p_poper AND
            status EQ '70'.
    IF sy-subrc EQ 0.
      lt_sdk-lbkum = ckmlpp-lbkum - ckmlpp-umkumo - ckmlpp-abkumo.
      lt_sdk-meins = ckmlpp-meins.
      IF lt_sdk-lbkum IS NOT INITIAL.
        CLEAR: ckmlprkeph.
        SELECT SINGLE * FROM ckmlprkeph
          WHERE kalnr EQ lt_smm-kaln1 AND
                bdatj EQ p_gjahr AND
                poper EQ p_poper AND
                keart EQ 'H' AND
                prtyp EQ 'V' AND
                curtp EQ '10'.
        lt_sdk-verp1 =
          ckmlprkeph-kst001 + ckmlprkeph-kst003 + ckmlprkeph-kst005 +
          ckmlprkeph-kst007 + ckmlprkeph-kst009 + ckmlprkeph-kst011 +
          ckmlprkeph-kst013 + ckmlprkeph-kst015 + ckmlprkeph-kst017 +
          ckmlprkeph-kst019 + ckmlprkeph-kst021 + ckmlprkeph-kst023 +
          ckmlprkeph-kst025 + ckmlprkeph-kst027 + ckmlprkeph-kst029.
        lt_sdk-verp2 =
          ckmlprkeph-kst031 + ckmlprkeph-kst033 + ckmlprkeph-kst035 +
          ckmlprkeph-kst037.
        lt_sdk-verp3 =
          ckmlprkeph-kst039.
      ENDIF.
    ENDIF.
  ENDLOOP.

  SORT lt_sdk.

  LOOP AT lt_sdk.
    lv_index = lv_index + 1.
    CLEAR: lv_wrbtr.
    lv_wrbtr = lt_sdk-verp1 + lt_sdk-verp2 + lt_sdk-verp3.
    SELECT SINGLE * FROM t001k WHERE bwkey EQ lt_sdk-bwkey.
    SELECT SINGLE * FROM t001 WHERE bukrs EQ t001k-bukrs.
    IF lt_sdk-lbkum LT 0.

      CLEAR: gt_alv.
      gt_alv-bschl = '40'.
      gt_alv-matnr = lt_sdk-matnr.
      gt_alv-menge = -1 * lt_sdk-lbkum.
      gt_alv-meins = lt_sdk-meins.
      gt_alv-werks = lt_sdk-bwkey.
      gt_alv-bukrs = t001k-bukrs.
      gt_alv-waers = t001-waers.
      gt_alv-gsber = p_gsber.
      gt_alv-kostl = gv_kostl.
      gt_alv-budat = p_budat.
      gt_alv-wrbtr = lv_wrbtr * gt_alv-menge.
*    CONCATENATE lt_smm-gjahr lt_smm-belnr INTO gt_alv-xblnr.
      SELECT SINGLE hkon2 FROM zco_fis_hesap
        INTO gt_alv-hkont
       WHERE typex EQ 'DEGISKEN2'.
      SELECT SINGLE txt20 FROM skat INTO gt_alv-txt20
        WHERE spras EQ sy-langu AND
              ktopl EQ 'CATR' AND
              saknr EQ gt_alv-hkont.
      IF sy-subrc NE 0.
        SELECT SINGLE txt20 FROM skat INTO gt_alv-txt20
          WHERE ktopl EQ 'CATR' AND
                saknr EQ gt_alv-hkont.
      ENDIF.
      gt_alv-index = lv_index.
      APPEND gt_alv.

      CLEAR: gt_alv.
      gt_alv-bsch2 = '50'.
      gt_alv-matnr = lt_sdk-matnr.
      gt_alv-menge = -1 * lt_sdk-lbkum.
      gt_alv-meins = lt_sdk-meins.
      gt_alv-werks = lt_sdk-bwkey.
      gt_alv-bukrs = t001k-bukrs.
      gt_alv-waers = t001-waers.
      gt_alv-gsber = p_gsber.
      gt_alv-kostl = gv_kostl.
      gt_alv-budat = p_budat.
*    CONCATENATE lt_smm-gjahr lt_smm-belnr INTO gt_alv-xblnr.

      SELECT SINGLE hkont FROM zco_fis_hesap
        INTO gt_alv-hkon2
       WHERE typex EQ 'DEGISKEN2'.
      gt_alv-wrbtr = lt_sdk-verp1 * gt_alv-menge.
      SELECT SINGLE txt20 FROM skat INTO gt_alv-txt22
        WHERE spras EQ sy-langu AND
              ktopl EQ 'CATR' AND
              saknr EQ gt_alv-hkon2.
      IF sy-subrc NE 0.
        SELECT SINGLE txt20 FROM skat INTO gt_alv-txt22
          WHERE ktopl EQ 'CATR' AND
                saknr EQ gt_alv-hkon2.
      ENDIF.
      gt_alv-index = lv_index.
      APPEND gt_alv.
      SELECT SINGLE hkont FROM zco_fis_hesap
        INTO gt_alv-hkon2
       WHERE typex EQ 'SABIT2'.
      gt_alv-wrbtr = lt_smm-verp2 * gt_alv-menge.
      SELECT SINGLE txt20 FROM skat INTO gt_alv-txt22
        WHERE spras EQ sy-langu AND
              ktopl EQ 'CATR' AND
              saknr EQ gt_alv-hkon2.
      IF sy-subrc NE 0.
        SELECT SINGLE txt20 FROM skat INTO gt_alv-txt22
          WHERE ktopl EQ 'CATR' AND
                saknr EQ gt_alv-hkon2.
      ENDIF.
      gt_alv-index = lv_index.
      APPEND gt_alv.
      SELECT SINGLE hkont FROM zco_fis_hesap
        INTO gt_alv-hkon2
       WHERE typex EQ 'AMORTISMA2'.
      gt_alv-wrbtr = lt_smm-verp3 * gt_alv-menge.
      SELECT SINGLE txt20 FROM skat INTO gt_alv-txt22
        WHERE spras EQ sy-langu AND
              ktopl EQ 'CATR' AND
              saknr EQ gt_alv-hkon2.
      IF sy-subrc NE 0.
        SELECT SINGLE txt20 FROM skat INTO gt_alv-txt22
          WHERE ktopl EQ 'CATR' AND
                saknr EQ gt_alv-hkon2.
      ENDIF.
      gt_alv-index = lv_index.
      APPEND gt_alv.
    ELSE.

      CLEAR: gt_alv.
      gt_alv-bschl = '40'.
      gt_alv-matnr = lt_sdk-matnr.
      gt_alv-menge = lt_sdk-lbkum.
      gt_alv-meins = lt_sdk-meins.
      gt_alv-werks = lt_sdk-bwkey.
      gt_alv-bukrs = t001k-bukrs.
      gt_alv-waers = t001-waers.
      gt_alv-gsber = p_gsber.
      gt_alv-kostl = gv_kostl.
      gt_alv-budat = p_budat.
*    CONCATENATE lt_smm-gjahr lt_smm-belnr INTO gt_alv-xblnr.

      SELECT SINGLE hkont FROM zco_fis_hesap
        INTO gt_alv-hkont
       WHERE typex EQ 'DEGISKEN2'.
      gt_alv-wrbtr = lt_sdk-verp1 * gt_alv-menge.
      SELECT SINGLE txt20 FROM skat INTO gt_alv-txt20
        WHERE spras EQ sy-langu AND
              ktopl EQ 'CATR' AND
              saknr EQ gt_alv-hkont.
      IF sy-subrc NE 0.
        SELECT SINGLE txt20 FROM skat INTO gt_alv-txt20
          WHERE ktopl EQ 'CATR' AND
                saknr EQ gt_alv-hkont.
      ENDIF.
      gt_alv-index = lv_index.
      APPEND gt_alv.
      SELECT SINGLE hkont FROM zco_fis_hesap
        INTO gt_alv-hkont
       WHERE typex EQ 'SABIT2'.
      gt_alv-wrbtr = lt_smm-verp2 * gt_alv-menge.
      SELECT SINGLE txt20 FROM skat INTO gt_alv-txt20
        WHERE spras EQ sy-langu AND
              ktopl EQ 'CATR' AND
              saknr EQ gt_alv-hkont.
      IF sy-subrc NE 0.
        SELECT SINGLE txt20 FROM skat INTO gt_alv-txt20
          WHERE ktopl EQ 'CATR' AND
                saknr EQ gt_alv-hkont.
      ENDIF.
      gt_alv-index = lv_index.
      APPEND gt_alv.
      SELECT SINGLE hkont FROM zco_fis_hesap
        INTO gt_alv-hkont
       WHERE typex EQ 'AMORTISMA2'.
      gt_alv-wrbtr = lt_smm-verp3 * gt_alv-menge.
      SELECT SINGLE txt20 FROM skat INTO gt_alv-txt20
        WHERE spras EQ sy-langu AND
              ktopl EQ 'CATR' AND
              saknr EQ gt_alv-hkont.
      IF sy-subrc NE 0.
        SELECT SINGLE txt20 FROM skat INTO gt_alv-txt20
          WHERE ktopl EQ 'CATR' AND
                saknr EQ gt_alv-hkont.
      ENDIF.
      gt_alv-index = lv_index.
      APPEND gt_alv.

      CLEAR: gt_alv.
      gt_alv-bsch2 = '50'.
      gt_alv-matnr = lt_sdk-matnr.
      gt_alv-menge = lt_sdk-lbkum.
      gt_alv-meins = lt_sdk-meins.
      gt_alv-werks = lt_sdk-bwkey.
      gt_alv-bukrs = t001k-bukrs.
      gt_alv-waers = t001-waers.
      gt_alv-gsber = p_gsber.
      gt_alv-kostl = gv_kostl.
      gt_alv-budat = p_budat.
      gt_alv-wrbtr = lv_wrbtr * gt_alv-menge.
*    CONCATENATE lt_smm-gjahr lt_smm-belnr INTO gt_alv-xblnr.
      SELECT SINGLE hkon2 FROM zco_fis_hesap
        INTO gt_alv-hkon2
       WHERE typex EQ 'DEGISKEN2'.
      SELECT SINGLE txt20 FROM skat INTO gt_alv-txt22
        WHERE spras EQ sy-langu AND
              ktopl EQ 'CATR' AND
              saknr EQ gt_alv-hkon2.
      IF sy-subrc NE 0.
        SELECT SINGLE txt20 FROM skat INTO gt_alv-txt22
          WHERE ktopl EQ 'CATR' AND
                saknr EQ gt_alv-hkon2.
      ENDIF.
      gt_alv-index = lv_index.
      APPEND gt_alv.

    ENDIF.
  ENDLOOP.

* Satıcı Kapama Kayıtları
  CLEAR: lt_smm, lt_smm[], r_hkont, r_hkont[], lv_hkont.

  SELECT DISTINCT hkont AS low FROM zco_fis_hesap
    INTO CORRESPONDING FIELDS OF TABLE r_hkont
   WHERE typex EQ 'CIM_HAZ' OR
         typex EQ 'AGR_HAZ' OR
         typex EQ 'AGR_CIM'.

  LOOP AT r_hkont.
    r_hkont-sign = 'I'.
    r_hkont-option = 'EQ'.
    MODIFY r_hkont.
  ENDLOOP.

  SELECT * FROM bkpf
    WHERE bukrs IN s_bukrs AND
          bstat EQ space   AND
          budat IN r_budat AND
          blart EQ 'RE'.
    SELECT * FROM bseg
      WHERE bukrs EQ bkpf-bukrs AND
            belnr EQ bkpf-belnr AND
            gjahr EQ bkpf-gjahr AND
            bschl EQ '31' AND
*            gsber IN s_gsber AND
*            matnr IN s_matnr AND
            hkont EQ '3201010000'.
      MOVE-CORRESPONDING bkpf TO lt_smm.
      MOVE-CORRESPONDING bseg TO lt_smm.
      APPEND lt_smm.
    ENDSELECT.
  ENDSELECT.

  LOOP AT lt_smm.

    lv_hkont = lt_smm-lifnr.
    SELECT SINGLE hkont FROM zco_fis_hesap
      INTO lv_hkont
     WHERE hkont EQ lv_hkont.

    CHECK sy-subrc EQ 0.

    lv_index = lv_index + 1.

    SELECT SINGLE * FROM t001 WHERE bukrs EQ lt_smm-bukrs.
    CLEAR: gt_alv.
    gt_alv-bschl = '40'.
*    gt_alv-matnr = lt_smm-matnr.
*    gt_alv-menge = lt_smm-menge.
*    gt_alv-meins = lt_smm-meins.
    gt_alv-werks = lt_smm-werks.
    gt_alv-bukrs = lt_smm-bukrs.
    gt_alv-hkont = '3201010000'.
    gt_alv-lifnr = lt_smm-lifnr.
    gt_alv-waers = t001-waers.
    gt_alv-gsber = lt_smm-gsber. "p_gsber.
    SELECT SINGLE kostl FROM zco_fis_kostl INTO gt_alv-kostl
      WHERE gsber EQ lt_smm-gsber.
    IF sy-subrc NE 0.
*      gt_alv-gsber = p_gsber.
      gt_alv-kostl = gv_kostl.
    ENDIF.
    gt_alv-budat = p_budat.
    gt_alv-wrbtr = lt_smm-dmbtr.
    CONCATENATE lt_smm-gjahr lt_smm-belnr INTO gt_alv-xblnr.
*    SELECT SINGLE hkont FROM zco_fis_hesap
*      INTO gt_alv-hkont
*     WHERE hkont EQ lt_smm-hkont AND
*           typex EQ 'TOPLAM'.
    SELECT SINGLE txt20 FROM skat INTO gt_alv-txt20
      WHERE spras EQ sy-langu AND
            ktopl EQ 'CATR' AND
            saknr EQ gt_alv-hkont.
    IF sy-subrc NE 0.
      SELECT SINGLE txt20 FROM skat INTO gt_alv-txt20
        WHERE ktopl EQ 'CATR' AND
              saknr EQ gt_alv-hkont.
    ENDIF.
    gt_alv-index = lv_index.
    APPEND gt_alv.
    CLEAR: gt_alv.
    gt_alv-bsch2 = '50'.
*    gt_alv-matnr = lt_smm-matnr.
*    gt_alv-menge = lt_smm-menge.
*    gt_alv-meins = lt_smm-meins.
    gt_alv-werks = lt_smm-werks.
    gt_alv-bukrs = lt_smm-bukrs.
*    gt_alv-lifnr = lt_smm-lifnr.
    gt_alv-waers = t001-waers.
    gt_alv-gsber = lt_smm-gsber. "p_gsber.
    SELECT SINGLE kostl FROM zco_fis_kostl INTO gt_alv-kostl
      WHERE gsber EQ lt_smm-gsber.
    IF sy-subrc NE 0.
*      gt_alv-gsber = p_gsber.
      gt_alv-kostl = gv_kostl.
    ENDIF.
    gt_alv-budat = p_budat.
    gt_alv-wrbtr = lt_smm-dmbtr.
    CONCATENATE lt_smm-gjahr lt_smm-belnr INTO gt_alv-xblnr.

    lv_hkont = lt_smm-lifnr.
    SELECT SINGLE hkon2 FROM zco_fis_hesap
      INTO gt_alv-hkon2
     WHERE hkont EQ lv_hkont.

    SELECT SINGLE txt20 FROM skat INTO gt_alv-txt22
      WHERE spras EQ sy-langu AND
            ktopl EQ 'CATR' AND
            saknr EQ gt_alv-hkon2.
    IF sy-subrc NE 0.
      SELECT SINGLE txt20 FROM skat INTO gt_alv-txt22
        WHERE ktopl EQ 'CATR' AND
              saknr EQ gt_alv-hkon2.
    ENDIF.
    gt_alv-index = lv_index.
    APPEND gt_alv.
  ENDLOOP.

  DELETE gt_alv WHERE wrbtr IS INITIAL.

  LOOP AT gt_alv.
    gt_alv-markx = 'X'.
    MODIFY gt_alv.
  ENDLOOP.

  gv_index = lv_index.

ENDFORM.                    " read_data
*&---------------------------------------------------------------------*
*&      Form  INIT_DATA
*&---------------------------------------------------------------------*
FORM init_data .

  CLEAR: r_budat, r_budat[].
  r_budat = 'IBT'.
  CONCATENATE p_gjahr p_poper+1(2) '01' INTO r_budat-low.
  CALL FUNCTION 'LAST_DAY_OF_MONTHS'
    EXPORTING
      day_in            = r_budat-low
    IMPORTING
      last_day_of_month = r_budat-high
    EXCEPTIONS
      day_in_no_date    = 1
      OTHERS            = 2.
  IF sy-subrc <> 0.
    r_budat-high = r_budat-low.
  ENDIF.
  APPEND r_budat.

  SELECT SINGLE kostl FROM zco_fis_kostl INTO gv_kostl
    WHERE gsber EQ p_gsber.

ENDFORM.                    " INIT_DATA
*&---------------------------------------------------------------------*
*&      Form  SAVE_DATA
*&---------------------------------------------------------------------*
FORM save_data .

  DATA : ls_documentheader TYPE  bapiache09.
  DATA : lv_objkey LIKE bapiache09-obj_key.
  DATA : lv_itemno         TYPE posnr_acc.
  DATA : lv_error.
  DATA : lt_accountgl      LIKE bapiacgl09 OCCURS 0 WITH HEADER LINE.
  DATA : lt_accountpayable LIKE bapiacap09 OCCURS 0 WITH HEADER LINE.
  DATA : lt_bapiaccr09     LIKE bapiaccr09 OCCURS 0 WITH HEADER LINE.
  DATA : lt_return         LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
*  DATA : lt_bapiparex      LIKE bapiparex OCCURS 0 WITH HEADER LINE.

  CLEAR: lv_error.
  CALL FUNCTION 'MESSAGES_INITIALIZE'.

  DO gv_index TIMES.

    CLEAR: ls_documentheader,
           lt_accountgl, lt_accountgl[],
*           lt_bapiparex, lt_bapiparex[],
           lt_bapiaccr09, lt_bapiaccr09[],
           lt_accountpayable, lt_accountpayable[],
           lt_return, lt_return[].

    LOOP AT gt_alv WHERE index EQ sy-index.

      IF gt_alv-markx IS INITIAL.
        EXIT.
      ENDIF.

      ls_documentheader-username     = sy-uname.
      ls_documentheader-header_txt   = 'Otomatik Fiş Kaydı'.
      ls_documentheader-doc_date     = sy-datum.
      ls_documentheader-pstng_date   = p_budat.
      ls_documentheader-comp_code    = gt_alv-bukrs.
      ls_documentheader-fisc_year    = p_budat+0(4).
      ls_documentheader-fis_period   = p_budat+4(2).
      ls_documentheader-doc_type     = 'SB'.
      ls_documentheader-ref_doc_no   = gt_alv-xblnr.

      IF gt_alv-lifnr IS INITIAL.

        ADD 10 TO lv_itemno.
        lt_accountgl-itemno_acc = lv_itemno.
        lt_accountgl-doc_type   = 'SB'.
        lt_accountgl-comp_code  = gt_alv-bukrs.
        lt_accountgl-fis_period = p_budat+4(2).
        lt_accountgl-fisc_year  = p_budat+0(4).
        lt_accountgl-costcenter = gt_alv-kostl.
        IF gt_alv-hkont IS NOT INITIAL.
          lt_accountgl-gl_account = gt_alv-hkont.
        ELSE.
          lt_accountgl-gl_account = gt_alv-hkon2.
        ENDIF.
*        lt_accountgl-vendor_no  = gt_alv-lifnr.
        lt_accountgl-item_text  = 'Otomatik Fiş Kaydı'.
        lt_accountgl-bus_area   = gt_alv-gsber.
*        lt_accountgl-tax_code   = 'V0'.
*        lt_accountgl-acct_key   = gt_alv-kostl.
        APPEND lt_accountgl.

*        lt_bapiparex-structure  = 'POSTING_KEY'.
*        lt_bapiparex-valuepart1 = lv_itemno.
*        IF gt_alv-hkont IS NOT INITIAL.
*          lt_bapiparex-valuepart2 = gt_alv-bschl.
*        ELSE.
*          lt_bapiparex-valuepart2 = gt_alv-bsch2.
*        ENDIF.
*        APPEND lt_bapiparex.

*        lt_bapiparex-structure  = 'ZUONR'.
*        lt_bapiparex-valuepart1 = lv_itemno.
*        lt_bapiparex-valuepart2 = p_budat.
*        APPEND lt_bapiparex.
*
*        lt_bapiparex-structure  = 'ZFBDT'.
*        lt_bapiparex-valuepart1 = lv_itemno.
*        lt_bapiparex-valuepart2 = p_budat.
*        APPEND lt_bapiparex.

        lt_bapiaccr09-itemno_acc = lv_itemno.
        lt_bapiaccr09-currency   = gt_alv-waers.
        lt_bapiaccr09-amt_doccur = gt_alv-wrbtr.
        IF gt_alv-bschl EQ '50' OR gt_alv-bsch2 EQ '50'.
          lt_bapiaccr09-amt_doccur = -1 * lt_bapiaccr09-amt_doccur.
        ENDIF.
        APPEND lt_bapiaccr09.
      ELSE.
        ADD 10 TO lv_itemno.
        lt_accountpayable-itemno_acc = lv_itemno.
        lt_accountpayable-comp_code  = gt_alv-bukrs.
        IF gt_alv-hkont IS NOT INITIAL.
          lt_accountpayable-gl_account = gt_alv-hkont.
        ELSE.
          lt_accountpayable-gl_account = gt_alv-hkon2.
        ENDIF.
        lt_accountpayable-item_text  = 'Otomatik Fiş Kaydı'.
        lt_accountpayable-bus_area   = gt_alv-gsber.
*        lt_accountpayable-tax_code   = 'V0'.
        APPEND lt_accountpayable.

*        lt_bapiparex-structure  = 'POSTING_KEY'.
*        lt_bapiparex-valuepart1 = lv_itemno.
*        IF gt_alv-hkont IS NOT INITIAL.
*          lt_bapiparex-valuepart2 = gt_alv-bschl.
*        ELSE.
*          lt_bapiparex-valuepart2 = gt_alv-bsch2.
*        ENDIF.
*        APPEND lt_bapiparex.
*
*        lt_bapiparex-structure  = 'ZUONR'.
*        lt_bapiparex-valuepart1 = lv_itemno.
*        lt_bapiparex-valuepart2 = p_budat.
*        APPEND lt_bapiparex.
*
*        lt_bapiparex-structure  = 'ZFBDT'.
*        lt_bapiparex-valuepart1 = lv_itemno.
*        lt_bapiparex-valuepart2 = p_budat.
*        APPEND lt_bapiparex.

        lt_bapiaccr09-itemno_acc = lv_itemno.
        lt_bapiaccr09-currency   = gt_alv-waers.
        lt_bapiaccr09-amt_doccur = gt_alv-wrbtr.
        IF gt_alv-bschl EQ '50' OR gt_alv-bsch2 EQ '50'.
          lt_bapiaccr09-amt_doccur = -1 * lt_bapiaccr09-amt_doccur.
        ENDIF.
        APPEND lt_bapiaccr09.
      ENDIF.
    ENDLOOP.

    CHECK gt_alv-markx IS NOT INITIAL AND
          ls_documentheader IS NOT INITIAL AND
          ( lt_accountgl[] IS NOT INITIAL OR
            lt_accountpayable[] IS NOT INITIAL ).

    CALL FUNCTION 'MESSAGE_STORE'
      EXPORTING
        arbgb = 'CK'
        msgty = 'S'
        msgv1 = gt_alv-index
        msgv2 = 'Numaralı kayıt işleniyor.'
        msgv3 = ''
        msgv4 = ''
        txtnr = 999.

    CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
      EXPORTING
        documentheader = ls_documentheader
      IMPORTING
        obj_key        = lv_objkey
      TABLES
        accountgl      = lt_accountgl
        accountpayable = lt_accountpayable
        currencyamount = lt_bapiaccr09
        return         = lt_return.
*        extension2     = lt_bapiparex.

    LOOP AT lt_return WHERE type EQ 'E' OR type EQ 'A'.
      CALL FUNCTION 'MESSAGE_STORE'
        EXPORTING
          arbgb = lt_return-id
          msgty = lt_return-type
          msgv1 = lt_return-message_v1
          msgv2 = lt_return-message_v2
          msgv3 = lt_return-message_v3
          msgv4 = lt_return-message_v4
          txtnr = lt_return-number.
      lv_error = 'X'.
    ENDLOOP.

    IF sy-subrc IS INITIAL.
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    ELSE.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait = 'X'.
    ENDIF.

  ENDDO.

  IF lv_error EQ 'X'.
    CALL FUNCTION 'MESSAGES_SHOW'.
  ELSE.
    MESSAGE 'Dokümanlar hatasız gönderildi.' TYPE 'S'.
  ENDIF.

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