Age: 46 Joined: 05 Nov 2007 Posts: 725 Location: КраснАдар
Posted: Mon Oct 27, 2008 1:29 pm Post subject: Создание доп.дебетования для учета фрахтовых расходов
Постановка: Была нужна программа (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.
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.
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.
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.
*&---------------------------------------------------------------------*
*& 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.
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.
*&---------------------------------------------------------------------*
*& 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.
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
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.