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

Создание доп.дебетования для учета фрахтовых расходов



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ММ
View previous topic :: View next topic  
Author Message
John Doe
Модератор
Модератор


Age: 46
Joined: 05 Nov 2007
Posts: 725
Location: КраснАдар

PostPosted: Mon Oct 27, 2008 1:29 pm    Post subject: Создание доп.дебетования для учета фрахтовых расходов Reply with quote

Постановка: Была нужна программа (like MIRO) для распределения фрахтовых расходов по входящей поставке не только пропорционально стоимости, но и пропорционально весу и объему (берем из основной записи материала). Перераспределение затрат создал через промежуточную (эталонную) меру измерения.

Для функционирования программы необходимо создать гуи-статус MAIN на основе статуса ALV STANDARD_FULLSCREEN с добавлением своих кнопок: CALC и POST
Текстовые элементы: из словаря +
Quote:
001 Данные проводки
002 Метод распределения
003 Данные поставки
004 Ввод единицы пересчета объема
005 Ввод единицы пересчета массы


GEWEI Единица массы
METH1 По объему
METH2 По массе
METH3 По количеству
METH4 По стоимости
TAXTR Код налога
VOLEH Единица объема
WRBTR Сумма фрахтовых расходов


Доп.дебетование реализовано через BAPI_INCOMINGINVOICE_CREATE (в позициях установлен индикатор DE_CRE_IND = 'X').

Code:
*&---------------------------------------------------------------------*
*& Report  ZMMA_MIRO_FREIGHT
*&
*&---------------------------------------------------------------------*
*& Created 22.09.2008
*& Program create incoming invoice for freight cost like MIRO
*& Algorythm of redistribution of costs should be considerate
*& material characterisics from master data: volume, mass, weight
*& and cost. User can set only one base for redistribution cost.
*& Costs should be calculate in proportion.
*&---------------------------------------------------------------------*

REPORT  ZMMA_MIRO_FREIGHT.

* Data definition
TYPE-POOLS: SLIS.

TABLES: RBKP, T007A.

DATA: BEGIN OF WA,
        BSTNR TYPE BSTNR,
        EBELP TYPE EBELP,
        MATNR TYPE MATNR,
        TXZ01 TYPE TXZ01,
        WRBTR TYPE WRBTR,
        WAERS TYPE WAERS,
        LFIMG TYPE LFIMG,
        MENGE TYPE MENGE_D,
        BSTME TYPE BSTME,
        MENG1 TYPE MENGE_D,
        BSTM1 TYPE BSTME,
        MWSKZ TYPE MWSKZ,
        FRBTR TYPE WRBTR,
        FWSTE TYPE FWSTE,
        MBLNR TYPE MBLNR,
        MJAHR TYPE MJAHR,
        ZEILE TYPE MBLPO,
      END OF WA,
      ITAB LIKE WA OCCURS 0.

DATA: BEGIN OF LS_EKBE,
        EBELN TYPE EBELN,
        EBELP TYPE EBELP,
        MENGE TYPE MENGE_D,
        SHKZG TYPE SHKZG,
      END OF LS_EKBE,
      LT_EKBE LIKE LS_EKBE OCCURS 0.

DATA: L_MENGE TYPE MENGE_D,
      FWSTE TYPE FWSTE.

DATA: LT_MARA TYPE TABLE OF MARA,
      LS_MARA TYPE MARA.

DATA: GRID TYPE REF TO CL_GUI_ALV_GRID,
      FCAT TYPE LVC_T_FCAT,
      HCAT TYPE LVC_S_FCAT,
      LAYO TYPE LVC_S_LAYO,
      METHOD TYPE STRING.

DATA: TPOOL TYPE TABLE OF TEXTPOOL WITH HEADER LINE.

DATA: INFO TYPE REF TO CL_DD_DOCUMENT,
      CONT TYPE REF TO CL_GUI_DOCKING_CONTAINER.

* Selection creen dedinition
SELECTION-SCREEN BEGIN OF BLOCK MAIN WITH FRAME TITLE TEXT-001.
PARAMETERS: BUKRS TYPE BUKRS OBLIGATORY,
            BLDAT TYPE RBKP-BLDAT OBLIGATORY,
            BUDAT TYPE RBKP-BUDAT OBLIGATORY,
            ZFBDT TYPE RBKP-ZFBDT OBLIGATORY,
            WAERS TYPE WAERS MATCHCODE OBJECT ICL_WAERS OBLIGATORY,
            WRBTR TYPE WRBTR OBLIGATORY.
SELECTION-SCREEN END OF BLOCK MAIN.
SELECTION-SCREEN BEGIN OF BLOCK DLVR WITH FRAME TITLE TEXT-003.
PARAMETERS: VBELN TYPE VBELN_VL MATCHCODE OBJECT VMVM,
            BSTNR TYPE BSTNR MATCHCODE OBJECT MEKK_C NO-DISPLAY,
            FULTR TYPE WRBTR NO-DISPLAY,
*            KALSM TYPE KALSM_D DEFAULT 'TAXRU',
            TAXTR TYPE MWSKZ MATCHCODE OBJECT ZMMA_SH_T007A OBLIGATORY.
SELECTION-SCREEN END OF BLOCK DLVR.

SELECTION-SCREEN BEGIN OF SCREEN 9100.
SELECTION-SCREEN BEGIN OF BLOCK METH WITH FRAME TITLE TEXT-002.
PARAMETERS: METH1 RADIOBUTTON GROUP METH,  " Volume
            METH2 RADIOBUTTON GROUP METH,  " Mass
            METH3 RADIOBUTTON GROUP METH,  " Quantity
            METH4 RADIOBUTTON GROUP METH.  " Cost
SELECTION-SCREEN END OF BLOCK METH.
SELECTION-SCREEN END OF SCREEN 9100.

SELECTION-SCREEN BEGIN OF SCREEN 9300.
SELECTION-SCREEN BEGIN OF BLOCK MASS WITH FRAME TITLE TEXT-004.
PARAMETERS: VOLEH TYPE MARA-VOLEH.
SELECTION-SCREEN END OF BLOCK MASS.
SELECTION-SCREEN END OF SCREEN 9300.

SELECTION-SCREEN BEGIN OF SCREEN 9200.
SELECTION-SCREEN BEGIN OF BLOCK VOL WITH FRAME TITLE TEXT-005.
PARAMETERS: GEWEI TYPE MARA-GEWEI.
SELECTION-SCREEN END OF BLOCK VOL.
SELECTION-SCREEN END OF SCREEN 9200.

DEFINE SHLP_MEINS.
  CALL FUNCTION 'UNIT_OF_MEASUREMENT_HELP'
    EXPORTING
      DIMID       = &1
    IMPORTING
      SELECT_UNIT = &2.
END-OF-DEFINITION.

DEFINE CONV_MEINS_IN.
  CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
    EXPORTING
      INPUT          = &1
    IMPORTING
      OUTPUT         = &1
    EXCEPTIONS
      UNIT_NOT_FOUND = 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.
END-OF-DEFINITION.

DEFINE CONV_MEINS_OUT.
  CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT'
    EXPORTING
      INPUT          = &1
    IMPORTING
      OUTPUT         = &1
    EXCEPTIONS
      UNIT_NOT_FOUND = 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.
END-OF-DEFINITION.

DEFINE CALC_MEINS.
  CONV_MEINS_IN &2.
  CONV_MEINS_IN &3.

  CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'
    EXPORTING
      INPUT                = &1
      ROUND_SIGN           = 'X'
      UNIT_IN              = &2
      UNIT_OUT             = &3
    IMPORTING
      OUTPUT               = &4
    EXCEPTIONS
      CONVERSION_NOT_FOUND = 01
      DIVISION_BY_ZERO     = 02
      INPUT_INVALID        = 03
      OVERFLOW             = 04
      OUTPUT_INVALID       = 05
      UNITS_MISSING        = 06
      UNIT_IN_NOT_FOUND    = 07
      UNIT_OUT_NOT_FOUND   = 08.

  CONV_MEINS_OUT &2.
  CONV_MEINS_OUT &3.
END-OF-DEFINITION.

AT SELECTION-SCREEN.
  CALL FUNCTION 'RS_TEXTPOOL_READ'
    EXPORTING
      OBJECTNAME           = SY-CPROG
      ACTION               = 'DISPLAY'
    TABLES
      TPOOL                = TPOOL
    EXCEPTIONS
      OBJECT_NOT_FOUND     = 1
      PERMISSION_FAILURE   = 2
      INVALID_PROGRAM_TYPE = 3
      ERROR_OCCURED        = 4
      ACTION_CANCELLED     = 5
      OTHERS               = 6.
  IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR VOLEH.
  SHLP_MEINS 'VOLUME' VOLEH.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR GEWEI.
  SHLP_MEINS 'MASS' GEWEI.


START-OF-SELECTION.
  IF VBELN IS INITIAL AND BSTNR IS INITIAL.
    MESSAGE 'Введите номер заказа либо поставки'
      TYPE 'S' DISPLAY LIKE 'E'.
    EXIT.
  ELSEIF VBELN IS NOT INITIAL AND BSTNR IS NOT INITIAL.
    MESSAGE 'Введите только один номер заказа или поставки'
      TYPE 'S' DISPLAY LIKE 'E'.
    EXIT.
  ENDIF.

* Check tax code - may be only incoming
  SELECT SINGLE * FROM T007A
    WHERE MWART = 'V'
    AND   MWSKZ = TAXTR.
  IF SY-SUBRC <> 0.
    MESSAGE 'Введите предварительный код налога'
      TYPE 'S' DISPLAY LIKE 'E'.
    EXIT.
  ENDIF.

* Get DB data
  IF VBELN IS NOT INITIAL.
    SELECT  vgbel AS bstnr vgpos AS ebelp lfimg AS menge posnr
      FROM lips INTO CORRESPONDING FIELDS OF wa
      WHERE vbeln = vbeln.
      SELECT SINGLE waers FROM ekko INTO wa-waers
        WHERE ebeln = wa-bstnr.
      SELECT SINGLE matnr meins AS bstme
                    mwskz netwr AS wrbtr txz01
        FROM ekpo INTO CORRESPONDING FIELDS OF wa
        WHERE ebeln = wa-bstnr
        AND   ebelp = wa-ebelp
        AND   webre = 'X'.
      SELECT mblnr mjahr zeile FROM mseg
        INTO CORRESPONDING FIELDS OF wa
        WHERE ebeln = wa-bstnr
        AND   ebelp = wa-ebelp
        AND   bwart = '101'.
        IF sy-subrc = 0.
          DATA: check_storno TYPE mblnr.
          SELECT SINGLE mblnr FROM mseg INTO check_storno
            WHERE smbln = wa-mblnr.
          IF sy-subrc <> 0.
            APPEND wa TO itab.
          ENDIF.
        ENDIF.
      ENDSELECT.
    ENDSELECT.


  ELSE.
* Get history data
    SELECT EBELN AS BSTNR EBELP MENGE SHKZG WRBTR WAERS FROM EKBE
      INTO CORRESPONDING FIELDS OF TABLE ITAB
      WHERE EBELN = BSTNR
      AND   BEWTP IN ('Q','R').
    IF SY-SUBRC <> 0.

    ELSE.
      LOOP AT ITAB INTO WA.
        SELECT SINGLE MATNR MEINS AS BSTME TXZ01
          FROM EKPO INTO CORRESPONDING FIELDS OF WA
          WHERE EBELN = WA-BSTNR
          AND   EBELP = WA-EBELP
          AND   REPOS = 'X'.
        MODIFY ITAB FROM WA.
      ENDLOOP.
    ENDIF.

  ENDIF.
  IF SY-SUBRC <> 0.
    MESSAGE 'Данные не найдены по условию' TYPE 'S'.
    EXIT.
  ENDIF.

* Get material info
  SELECT * FROM MARA INTO TABLE LT_MARA
    FOR ALL ENTRIES IN ITAB
    WHERE MATNR = ITAB-MATNR.
  SORT LT_MARA BY MATNR.
  DELETE ADJACENT DUPLICATES FROM LT_MARA COMPARING MATNR.

END-OF-SELECTION.
* Calculate invoice values
  LOOP AT ITAB INTO WA.
    WA-MWSKZ = TAXTR.
    MODIFY ITAB FROM WA.
  ENDLOOP.

* Output only positive entries
  DELETE ITAB WHERE MENGE <= 0.

* Create fieldcatalog
  PERFORM CREATE_FIELDCATALOG.

* Create info header
  PERFORM CREATE_INFOHEADER.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      I_CALLBACK_PROGRAM       = SY-CPROG
      I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'
      I_CALLBACK_USER_COMMAND  = 'USER_COMMAND'
      IS_LAYOUT_LVC            = LAYO
      IT_FIELDCAT_LVC          = FCAT
    TABLES
      T_OUTTAB                 = ITAB
    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.


*&---------------------------------------------------------------------*
*&      Form  CREATE_FIELDCATALOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM CREATE_FIELDCATALOG .
  DATA: LT_COMPONENTS TYPE TABLE OF RSTRUCINFO,
        LS_COMPONENT TYPE RSTRUCINFO,
        LS_DD04V TYPE DD04V.

  CALL FUNCTION 'GET_COMPONENT_LIST'
    EXPORTING
      PROGRAM    = SY-CPROG
      FIELDNAME  = 'WA'
    TABLES
      COMPONENTS = LT_COMPONENTS.

  LOOP AT LT_COMPONENTS INTO LS_COMPONENT.
    CLEAR HCAT.
    HCAT-FIELDNAME = LS_COMPONENT-COMPNAME.
    HCAT-OUTPUTLEN = LS_COMPONENT-OLEN.

    CALL FUNCTION 'DDIF_DTEL_GET'
      EXPORTING
        NAME          = LS_COMPONENT-COMPNAME
        STATE         = 'A'
        LANGU         = SY-LANGU
      IMPORTING
        DD04V_WA      = LS_DD04V
      EXCEPTIONS
        ILLEGAL_INPUT = 1
        OTHERS        = 2.
    IF SY-SUBRC <> 0.
      CONTINUE.
    ENDIF.

    HCAT-SCRTEXT_M = LS_DD04V-SCRTEXT_M.
    HCAT-COLTEXT   = LS_DD04V-SCRTEXT_M.

    CASE HCAT-FIELDNAME.
      WHEN 'MATNR'.
        HCAT-EDIT_MASK = '==ALPHA'.
      WHEN 'BSTM1'.
        HCAT-SCRTEXT_M = HCAT-COLTEXT = 'ЕИ (пересчет)'.
      WHEN 'MENG1'.
        HCAT-SCRTEXT_M = HCAT-COLTEXT = 'База (пересчет)'.
      WHEN 'MENGE'.
        HCAT-SCRTEXT_M = HCAT-COLTEXT = 'Количество'.
      WHEN 'FRBTR'.
        HCAT-SCRTEXT_M = HCAT-COLTEXT = 'Фрахт'.
      WHEN 'MWSKZ'.
*        HCAT-EDIT = 'X'.
      WHEN 'LFIMG' OR 'GJAHR' OR 'BELNR' OR 'BUZEI'.
        HCAT-NO_OUT = 'X'.
      WHEN 'FWSTE'.
        HCAT-SCRTEXT_M = HCAT-COLTEXT = 'НДС'.
    ENDCASE.
    APPEND HCAT TO FCAT.
  ENDLOOP.

ENDFORM.                    " CREATE_FIELDCATALOG


*&---------------------------------------------------------------------*
*&      Form  SET_PF_STATUS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->EXTAB      text
*----------------------------------------------------------------------*
FORM SET_PF_STATUS USING EXTAB TYPE SLIS_T_EXTAB.
  SET PF-STATUS 'MAIN' EXCLUDING EXTAB.
ENDFORM.                    "SET_PF_STATUS


*&---------------------------------------------------------------------*
*&      Form  USER_COMMAND
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->OKCODE     text
*      -->SELFIELD   text
*----------------------------------------------------------------------*
FORM USER_COMMAND USING OKCODE TYPE SY-UCOMM
                        SELFIELD TYPE SLIS_SELFIELD.

  CASE OKCODE.
    WHEN '&IC1'.
      CASE SELFIELD-FIELDNAME.
        WHEN 'BSTNR'.

        WHEN 'MATNR'.
          DATA: MATNR TYPE MATNR.
          MOVE SELFIELD-VALUE TO MATNR.
          CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
            EXPORTING
              INPUT        = MATNR
            IMPORTING
              OUTPUT       = MATNR
            EXCEPTIONS
              LENGTH_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.

          CALL FUNCTION 'BAPI_MATERIAL_DISPLAY'
            EXPORTING
              MATERIAL = MATNR.

      ENDCASE.

    WHEN 'CALC'.
      PERFORM CALCULATE_COST_DERIVE.
    WHEN 'POST'.
      PERFORM POST_DOCUMENT.
  ENDCASE.

ENDFORM.                    "USER_COMMAND


*&---------------------------------------------------------------------*
*&      Form  CREATE_INFOHEADER
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM CREATE_INFOHEADER .
  DATA: L_TEXT TYPE SDYDO_TEXT_ELEMENT.

  CREATE OBJECT CONT
    EXPORTING
      REPID                       = 'SAPLSLVC_FULLSCREEN'
      DYNNR                       = '0500'
      SIDE                        = CONT->DOCK_AT_TOP
      RATIO                       = 15
    EXCEPTIONS
      CNTL_ERROR                  = 1
      CNTL_SYSTEM_ERROR           = 2
      CREATE_ERROR                = 3
      LIFETIME_ERROR              = 4
      LIFETIME_DYNPRO_DYNPRO_LINK = 5
      OTHERS                      = 6.
  IF SY-SUBRC <> 0.
  ENDIF.

  CREATE OBJECT INFO.

  PERFORM SET_TEXT_INFORMATION.

ENDFORM.                    " CREATE_INFOHEADER


*&---------------------------------------------------------------------*
*&      Form  CALCULATE_COST_DERIVE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM CALCULATE_COST_DERIVE .
  DATA: SUMMARY TYPE MENGE_D,
        QUANNOT.
  CALL SELECTION-SCREEN 9100 STARTING AT 5 5.

  CLEAR: GEWEI, VOLEH.
  IF METH1 IS NOT INITIAL.
    METHOD = 'METH1'.
    WHILE VOLEH IS INITIAL.
      CALL SELECTION-SCREEN 9300 STARTING AT 5 5.
      IF VOLEH IS INITIAL.
        MESSAGE 'Введите единицу пересчета объема' TYPE 'S'.
      ENDIF.
    ENDWHILE.
  ELSEIF METH2 IS NOT INITIAL.
    METHOD = 'METH2'.
    WHILE GEWEI IS INITIAL.
      CALL SELECTION-SCREEN 9200 STARTING AT 5 5.
      IF GEWEI IS INITIAL.
        MESSAGE 'Введите единицу пересчета массы' TYPE 'S'.
      ENDIF.
    ENDWHILE.
  ELSEIF METH3 IS NOT INITIAL.
    METHOD = 'METH3'.
    CLEAR QUANNOT.
    LOOP AT ITAB INTO WA
      WHERE ( BSTME NE 'ST' AND BSTME NE 'ШТ' ).
      QUANNOT = 'X'.
      EXIT.
    ENDLOOP.
    IF QUANNOT EQ 'X'.
      MESSAGE 'Пересчет по количеству не возможен' TYPE 'S'.
      EXIT.
    ENDIF.

  ELSEIF METH4 IS NOT INITIAL.
    METHOD = 'METH4'.
  ENDIF.

  PERFORM SET_TEXT_INFORMATION.

  LOOP AT ITAB INTO WA.
    READ TABLE LT_MARA INTO LS_MARA WITH KEY MATNR = WA-MATNR.
    IF SY-SUBRC <> 0.
      CONTINUE.
    ENDIF.
    CASE METHOD.
      WHEN 'METH1'.
        CONV_MEINS_IN: WA-BSTME, VOLEH.
        IF LS_MARA-VOLUM IS INITIAL OR LS_MARA-VOLEH IS INITIAL.
          MESSAGE 'Нет единиц объема для материала' TYPE 'E'.
        ELSEIF WA-BSTME EQ VOLEH.
          WA-MENG1 = WA-MENGE.
          WA-BSTM1 = VOLEH.
        ELSE.
          CALC_MEINS LS_MARA-VOLUM LS_MARA-VOLEH VOLEH LS_MARA-VOLUM.
          CATCH SYSTEM-EXCEPTIONS ARITHMETIC_ERRORS = 4
                        OTHERS = 8.
            WA-MENG1 = WA-MENGE * LS_MARA-VOLUM.
          ENDCATCH.
          IF SY-SUBRC <> 0.
            MESSAGE 'Арифметическое переполнение' TYPE 'S'.
            EXIT.
          ENDIF.
          WA-BSTM1 = VOLEH.
        ENDIF.
*        CONV_MEINS_OUT: WA-BSTME, VOLEH.
      WHEN 'METH2'.
        CONV_MEINS_IN: WA-BSTME, GEWEI.
        IF LS_MARA-BRGEW IS INITIAL OR LS_MARA-GEWEI IS INITIAL.
          MESSAGE 'Нет единиц веса для материала' TYPE 'E'.
        ELSEIF WA-BSTME EQ GEWEI.
          WA-MENG1 = WA-MENGE.
          WA-BSTM1 = LS_MARA-GEWEI.
        ELSE.
          CALC_MEINS LS_MARA-BRGEW LS_MARA-GEWEI GEWEI LS_MARA-BRGEW.
          CATCH SYSTEM-EXCEPTIONS ARITHMETIC_ERRORS = 4
                        OTHERS = 8.
            WA-MENG1 = WA-MENGE * LS_MARA-BRGEW.
          ENDCATCH.
          IF SY-SUBRC <> 0.
            MESSAGE 'Арифметическое переполнение' TYPE 'S'.
            EXIT.
          ENDIF.
          WA-BSTM1 = GEWEI.
        ENDIF.
*        CONV_MEINS_OUT: WA-BSTME, GEWEI.
      WHEN 'METH3'.
        WA-MENG1 = WA-MENGE.
        WA-BSTM1 = WA-BSTME.
      WHEN 'METH4'.
        WA-MENG1 = WA-WRBTR.
        WA-BSTM1 = WA-WAERS.
    ENDCASE.

    SUMMARY = SUMMARY + WA-MENG1.
    MODIFY ITAB FROM WA.
  ENDLOOP.

  CLEAR FWSTE.
  LOOP AT ITAB INTO WA.

    WA-FRBTR = WRBTR * WA-MENG1 / SUMMARY.

    DATA: TAX_ITEM_IN TYPE TABLE OF RTAX1U38,
          TAX_ITEM_OUT TYPE TABLE OF RTAX1U38,
          TAX_ITEM TYPE RTAX1U38.

    REFRESH: TAX_ITEM_IN, TAX_ITEM_OUT.
    CLEAR: TAX_ITEM.
    TAX_ITEM-BUKRS = BUKRS.
    TAX_ITEM-MWSKZ = WA-MWSKZ.
    TAX_ITEM-WRBTR = WA-FRBTR.
    APPEND TAX_ITEM TO TAX_ITEM_IN.

    CALL FUNCTION 'CALCULATE_TAXES_NET'
      TABLES
        TAX_ITEM_IN             = TAX_ITEM_IN
        TAX_ITEM_OUT            = TAX_ITEM_OUT
      EXCEPTIONS
        BUKRS_NOT_FOUND         = 1
        MWSKZ_NOT_DEFINED       = 2
        MWSKZ_NOT_VALID         = 3
        KALSM_NOT_FOUND         = 4
        ACCOUNT_NOT_FOUND       = 5
        COUNTRY_NOT_FOUND       = 6
        DIFFERENT_DISCOUNT_BASE = 7
        DIFFERENT_TAX_BASE      = 8
        TXJCD_NOT_VALID         = 9
        KALSM_NOT_VALID         = 10
        OTHER_ERROR             = 11
        KTOSL_NOT_FOUND         = 12
        KSCHL_NOT_FOUND         = 13
        KNUMH_NOT_FOUND         = 14
        OTHERS                  = 15.
    IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    READ TABLE TAX_ITEM_OUT INTO TAX_ITEM INDEX 1.
    WA-FWSTE = TAX_ITEM-FWSTE.
    FWSTE = FWSTE + WA-FWSTE.
    MODIFY ITAB FROM WA.
  ENDLOOP.

  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      E_GRID = GRID.

  CALL METHOD GRID->REFRESH_TABLE_DISPLAY.

ENDFORM.                    " CALCULATE_COST_DERIVE


*&---------------------------------------------------------------------*
*&      Form  SET_TEXT_INFORMATION
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM SET_TEXT_INFORMATION .
  DATA: L_TEXT TYPE SDYDO_TEXT_ELEMENT.

  CALL METHOD INFO->INITIALIZE_DOCUMENT
    EXPORTING
      BACKGROUND_COLOR = INFO->COL_BACKGROUND_LEVEL2.

  CLEAR L_TEXT. WRITE BLDAT TO L_TEXT.
  CALL METHOD:
    INFO->ADD_TEXT EXPORTING TEXT = 'Дата счета:'
                             SAP_EMPHASIS = INFO->STRONG,
    INFO->ADD_GAP EXPORTING WIDTH = 28,
    INFO->ADD_TEXT EXPORTING TEXT = L_TEXT,
    INFO->NEW_LINE.

  CLEAR L_TEXT. WRITE BUDAT TO L_TEXT.
  CALL METHOD:
    INFO->ADD_TEXT EXPORTING TEXT = 'Дата проводки:'
                             SAP_EMPHASIS = INFO->STRONG,
    INFO->ADD_GAP EXPORTING WIDTH = 20,
    INFO->ADD_TEXT EXPORTING TEXT = L_TEXT,
    INFO->NEW_LINE.

  CLEAR L_TEXT. WRITE ZFBDT TO L_TEXT.
  CALL METHOD:
    INFO->ADD_TEXT EXPORTING TEXT = 'Базовая дата:'
                             SAP_EMPHASIS = INFO->STRONG,
    INFO->ADD_GAP EXPORTING WIDTH = 23,
    INFO->ADD_TEXT EXPORTING TEXT = L_TEXT,
    INFO->NEW_LINE.

  CLEAR L_TEXT.
  DATA: TMP TYPE STRING.
  MOVE WRBTR TO TMP.
  CONCATENATE TMP WAERS INTO L_TEXT SEPARATED BY SPACE.
  CALL METHOD:
    INFO->ADD_TEXT EXPORTING TEXT = 'Сумма фрахта:'
                             SAP_EMPHASIS = INFO->STRONG,
    INFO->ADD_GAP EXPORTING WIDTH = 22,
    INFO->ADD_TEXT EXPORTING TEXT = L_TEXT,
    INFO->NEW_LINE.

  CLEAR L_TEXT.
  IF METHOD IS NOT INITIAL.
    READ TABLE TPOOL WITH KEY KEY = METHOD.
    MOVE TPOOL-ENTRY TO L_TEXT.
  ENDIF.
  CALL METHOD:
    INFO->ADD_TEXT EXPORTING TEXT = 'Метод распределения:'
                             SAP_EMPHASIS = INFO->STRONG,
    INFO->ADD_GAP EXPORTING WIDTH = 5,
    INFO->ADD_TEXT EXPORTING TEXT = L_TEXT,
    INFO->NEW_LINE.

  CALL METHOD:
    INFO->MERGE_DOCUMENT,
    INFO->DISPLAY_DOCUMENT EXPORTING PARENT = CONT
                                     REUSE_CONTROL    = 'X'.

ENDFORM.                    " SET_TEXT_INFORMATION


*&---------------------------------------------------------------------*
*&      Form  POST_DOCUMENT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM POST_DOCUMENT .
  DATA: HEADERDATA TYPE BAPI_INCINV_CREATE_HEADER,
        ITEMDATA TYPE TABLE OF BAPI_INCINV_CREATE_ITEM,
        ITEM TYPE BAPI_INCINV_CREATE_ITEM,
        TAXDATA TYPE TABLE OF BAPI_INCINV_CREATE_TAX,
        TAX TYPE BAPI_INCINV_CREATE_TAX,
        RETURN TYPE TABLE OF BAPIRET2,
        MESSAGE TYPE BAPIRET2,
        N TYPE I,
        INVOICE TYPE RE_BELNR.

* Check calculated values
  LOOP AT ITAB INTO WA.
    N = N + WA-FRBTR.
  ENDLOOP.
  IF N <> WRBTR.
    MESSAGE 'Распределите фрахтовые расходы до проводки'
      TYPE 'S' DISPLAY LIKE 'E'.
    EXIT.
  ENDIF.

* Fill header
  headerdata-invoice_ind = 'X'.
  headerdata-comp_code = bukrs.
  headerdata-doc_type = 'RE'.
  headerdata-doc_date = bldat.
  headerdata-pstng_date = budat.
  headerdata-bline_date = zfbdt.
  headerdata-currency = waers.
  headerdata-calc_tax_ind = 'X'.
  headerdata-gross_amount  = wrbtr + fwste.
  headerdata-ref_doc_no = 'ZMIRO'.

* Fill items
  LOOP AT itab INTO wa.
    item-invoice_doc_item = item-invoice_doc_item + 10.
    item-po_number = wa-bstnr.
    item-po_item = wa-ebelp.
    item-de_cre_ind = 'X'.
    item-tax_code = taxtr.
    item-item_amount = wa-frbtr.
    item-quantity = '1'.
    item-po_unit = wa-bstme.
    item-ref_doc = wa-mblnr.
    item-ref_doc_year = wa-mjahr.
    item-ref_doc_it = wa-zeile.
    APPEND item TO itemdata.
  ENDLOOP.


  SORT ITEMDATA BY INVOICE_DOC_ITEM PO_NUMBER PO_ITEM.

  CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE'
    EXPORTING
      HEADERDATA       = HEADERDATA
    IMPORTING
      INVOICEDOCNUMBER = INVOICE
    TABLES
      ITEMDATA         = ITEMDATA
      RETURN           = RETURN.

  READ TABLE RETURN INTO MESSAGE WITH KEY TYPE = 'E'.
  IF SY-SUBRC IS INITIAL.
    ROLLBACK WORK.
    CALL FUNCTION 'C14ALD_BAPIRET2_SHOW'
      TABLES
        I_BAPIRET2_TAB = RETURN.
  ELSE.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' .
    MESSAGE S030(ZSDA) WITH INVOICE.
    LEAVE PROGRAM.
  ENDIF.

ENDFORM.                    " POST_DOCUMENT


Last edited by John Doe on Fri Dec 19, 2008 3:51 pm; edited 2 times in total
Back to top
View user's profile Send private message Blog
El Mario
Участник
Участник



Joined: 20 Nov 2007
Posts: 14
Location: г.Новоуральск, Свердловская обл.

PostPosted: Tue Oct 28, 2008 4:36 pm    Post subject: Reply with quote

Не осилил, много букв Laughing
Back to top
View user's profile Send private message Send e-mail
John Doe
Модератор
Модератор


Age: 46
Joined: 05 Nov 2007
Posts: 725
Location: КраснАдар

PostPosted: Tue Oct 28, 2008 4:43 pm    Post subject: Reply with quote

Всегда рад конструктивным оценкам.
Back to top
View user's profile Send private message Blog
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ММ 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 cannot 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.