Contents
1 BAdI List 2
2 Implementation Example. 5
Copyright 16
This BAdI contains 2 methods:
GET_SELLER_BANK_DETAIL
This method could be used to set the payee's bank account.
GET_BUYER_BANK_DETAIL
If the default payer's bank account is insufficient, you can use this method to set the payer's bank account based on customer number.
This BAdI contains 3 methods:
GET_CUSTOMER_ADDRESS
If the default payer's address is insufficient, you can use this method to set the payer's address based on customer number.
SET_CUSTOMER_TYPE
This method is created to set customer type based on customer number. The exporting field 'ES_IS_SMALL_TAX_PAYER' has two values:
'X' - Small Scale Tax Payer, invoices of this customer will be printed as 'Normal invoice'.
' ' - Ordinary VAT taxpayer, invoices of this customer will be printed as 'Special invoice'.
GET_CUSTOMER_NAME
If the default payer's name is insufficient, you can use this method to set the payer's name based on customer number.
This BAdI contains 2 methods:
GET_MATERIAL_SPEC
If the default material specification is insufficient, you can use this method to set new specification.
GET_MATERIAL_DESC
If the default material description is insufficient, you can use this method to set new description.
This BAdI contains 1 method:
GET_SELLER_ADDRESS
This method could be used to set the Payee's address
This BAdI contains 1 method:
BILLING_CHECK
By using this BAdI, you can define your own logic to check whether a document should be displayed in outbound search result. E.g.:
This BAdI contains 1 method:
CHANGE_OUTPUT_LINES
You can use this BAdI to include discount data in the outbound file for the Golden Tax Interface. In addition, this BAdI enables you to remove a line item from the output ALV list and subsequently the outbound file.
You can also use this BAdI to make necessary changes of contents which are selected from source documents. Please be noticed that abuse of this BAdI will cause data inconsistency between SAP and Golden Tax System
This method contains 1 method:
CHECK_COMBINE
You can use this BAdI to create additional check rule for combination. It will be called after you select several documents and click 'Combine' button.
If selected documents should not be combined, you can append message with type 'E' into the return table 'ET_RETURN'. Then the combine event will be terminated and message will be displayed on your screen.
If selected documents can be combined, you do not need to change anything in your BAdI implementation.
This method contains 1 method:
CHANGE_VAT_LINES
This method could be used to change fields of VAT invoice after GTI generate VAT data. E.g. you can implement this BAdI to replace 'Note' field. Please be noticed that abuse of this method will cause data inconsistency between SAP and Golden Tax System
This BAdI contains 1 method:
MODIFY_FILE_CONTENT
This method could be used to make necessary changes on the header and Items of outbound file before downloaded. E.g. payer name/payer address/Unit price/ discount rate etc.
Please be noticed that abuse of this method will cause data inconsistency between SAP and Golden Tax System
This method contains 1 method:
WRITEBACK
In inbound application, you can use this BAdI to write VAT invoice information back to SAP documents.
Case1: You need to change the default material specification to the new specification .
BAdI Name: IDGTCN_MATNR_SPEC
METHOD IF_EX_MATNR_SPEC~GET_MATERIAL_SPEC.
IF IS_MATNR_PARAMS = 'GTS_RAW_MM01'.
ES_MATNR_SPEC = 'GTS_RAW_MM01_SPEC'.
ENDIF.
ENDMETHOD.
Case2: You need to change the default material description to the new description .
BAdI Name: IDGTCN_MATNR_SPEC
METHOD IF_EX_MATNR_SPEC~GET_MATERIAL_DESC.
IF IS_MATNR_PARAMS = 'GTS_RAW_MM01'.
ES_MATNR_DESC = 'GTS_RAW_MM01_DESC'.
ENDIF.
ENDMETHOD.
Case3: You need to get Pro Forma invoices data in GTI and send them to Golden Tax System.
BAdI Name: IDGTCN_BILLING_CHECK
METHOD if_ex_billing_check~billing_check.
DATA: ls_tvfk TYPE tvfk.
CHECK is_vbrk-fkart IS NOT INITIAL.
SELECT SINGLE * INTO ls_tvfk
FROM tvfk
WHERE fkart = is_vbrk-fkart.
CHECK sy-subrc EQ 0.
IF ls_tvfk-vbtyp EQ 'U' "SD document categ. -Pro forma invoice
AND ls_tvfk-trvog EQ '8'. "Transaction group -Proforma invoices
cv_oper = '1'. "Billing
ENDIF.
ENDMETHOD.
Case4: Only billing documents with posting status ‘C’(Posting document has been created) could be displayed and sent.
METHOD if_ex_billing_check~billing_check.
IF is_vbrk-rfbsk NE 'C'.
cv_oper = '3'. "will not be displayed in output list
ENDIF.
ENDMETHOD.
Case5: If discount with tax is used in your billing condition. You need to add discount info into data selected.
BAdI Name: IDGTCN_LINES
METHOD if_ex_lines~change_output_lines.
DATA:ls_item TYPE idgt_s_item,
ls_konv TYPE konv,
ls_konv_tax TYPE konv,
ls_vbrk TYPE vbrk.
DATA:lt_vbrk TYPE SORTED TABLE OF vbrk WITH NON-UNIQUE KEY vbeln,
lt_konv TYPE SORTED TABLE OF konv WITH NON-UNIQUE KEY knumv kposn.
CHECK ct_header IS NOT INITIAL AND ct_item IS NOT INITIAL.
SELECT vbeln knumv fkart vtweg
FROM vbrk
INTO CORRESPONDING FIELDS OF TABLE lt_vbrk
FOR ALL ENTRIES IN ct_header
WHERE vbeln = ct_header-vbeln.
CHECK sy-subrc EQ 0.
CLEAR:lt_konv.
SELECT knumv kposn kschl kbetr kwert mwsk1 kawrt
FROM konv
INTO CORRESPONDING FIELDS OF TABLE lt_konv
FOR ALL ENTRIES IN lt_vbrk
WHERE knumv = lt_vbrk-knumv
AND kschl = 'ZD01'. "Discount Condition type
SELECT knumv kposn kschl kbetr kwert mwsk1 kawrt
FROM konv
APPENDING CORRESPONDING FIELDS OF TABLE lt_konv
FOR ALL ENTRIES IN lt_vbrk
WHERE knumv = lt_vbrk-knumv
AND kschl = 'MWST'. "VAT Condition type
LOOP AT ct_item INTO ls_item.
READ TABLE lt_vbrk INTO ls_vbrk WITH KEY vbeln = ls_item-vbeln.
READ TABLE lt_konv INTO ls_konv WITH KEY knumv = ls_vbrk-knumv
kposn = ls_item-vfpos
kschl = 'ZD01'.
IF sy-subrc = 0.
READ TABLE lt_konv INTO ls_konv_tax WITH KEY knumv = ls_vbrk-knumv
kposn = ls_item-vfpos
kschl = 'MWST'.
"Discount Amount(w/o tax) = Discount amount(w/ tax) / ( 1 + tax rate )
ls_konv-kbetr = abs( ls_konv-kbetr ).
ls_konv_tax-kbetr = ( ls_konv_tax-kbetr + 1000 ) / 1000.
ls_item-disc = ls_konv-kbetr / ls_konv_tax-kbetr.
" Discount tax = Total Discount amount - Discount Amount(w/o tax)
ls_item-disctax = abs( ls_konv-kbetr ) - ls_item-disc.
IF ls_item-fkimg < 0.
ls_item-disc = ls_item-disc * ( -1 ).
ls_item-disctax = ls_item-disctax * ( -1 ).
ENDIF.
"Billing Net Value(before discount) = Billing Net Value(after discount) +
" Discount Amount(w/o tax)
ls_item-netwr = ls_item-netwr + ls_item-disc.
"Billing Tax Amount(before discount) = Billing Tax Amount(after discount+
" Discount Tax
ls_item-taxamt = ls_item-taxamt + ls_item-disctax.
MODIFY ct_item FROM ls_item TRANSPORTING disc disctax netwr taxamt.
ENDIF.
CLEAR:ls_item,ls_vbrk,ls_konv,ls_konv_tax.
ENDLOOP.
ENDMETHOD.
Case6: You need to combine with the same business area
BAdI Name: IDGTCN_CHECK_COMBINE
METHOD if_check_combine~check_combine.
DATA:ls_header LIKE LINE OF it_header,
lt_vbrp TYPE TABLE OF vbrp,
ls_vbrp TYPE vbrp,
lv_gsber TYPE vbrp-gsber,
lv_gsber1 TYPE vbrp-gsber,
lv_flag TYPE char1,
ls_return TYPE bapiret2.
CHECK it_header IS NOT INITIAL.
SELECT *
FROM vbrp
INTO TABLE lt_vbrp
FOR ALL ENTRIES IN it_header
WHERE vbeln = it_header-vbeln.
SORT lt_vbrp ASCENDING.
LOOP AT it_header INTO ls_header.
READ TABLE lt_vbrp INTO ls_vbrp WITH KEY vbeln = ls_header-vbeln
BINARY SEARCH.
IF sy-subrc = 0.
lv_gsber = ls_vbrp-gsber.
IF lv_gsber IS NOT INITIAL.
IF lv_gsber1 IS INITIAL.
lv_gsber1 = lv_gsber.
ELSEIF lv_gsber1 <> lv_gsber.
lv_flag = 'X'.
EXIT.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
IF lv_flag = 'X'.
ls_return-type = 'E'.
APPEND ls_return TO et_return.
ENDIF.
Case7: You need to add customer purchase order number into the note field of VAT invoice.
BAdI Name: IDGTCN_VAT_LINES
METHOD if_ex_lines~change_output_lines.
DATA: ls_vat_header LIKE LINE OF ct_vat_header,
ls_item LIKE LINE OF it_item.
DATA: BEGIN OF ls_so,
refvbeln LIKE ls_vat_header-refvbeln,
aubel LIKE ls_item-aubel,
bstnk TYPE vbak-bstnk,
END OF ls_so.
DATA: lt_so LIKE STANDARD TABLE OF ls_so,
lv_bstnk TYPE vbak-bstnk,
lv_tabix LIKE sy-tabix.
CHECK ct_vat_header[] IS NOT INITIAL.
LOOP AT it_item INTO ls_item.
IF ls_item-aubel IS NOT INITIAL.
ls_so-refvbeln = ls_item-refvbeln.
ls_so-aubel = ls_item-aubel.
APPEND ls_so TO lt_so.
ENDIF.
ENDLOOP.
LOOP AT ct_vat_item INTO ls_item.
IF ls_item-aubel IS NOT INITIAL.
ls_so-refvbeln = ls_item-refvbeln.
ls_so-aubel = ls_item-aubel.
APPEND ls_so TO lt_so.
ENDIF.
ENDLOOP.
SORT lt_so ASCENDING BY refvbeln aubel.
DELETE ADJACENT DUPLICATES FROM lt_so COMPARING refvbeln aubel.
LOOP AT lt_so INTO ls_so.
AT NEW aubel.
SELECT SINGLE bstnk INTO lv_bstnk
FROM vbak
WHERE vbeln = ls_so-aubel.
IF sy-subrc NE 0.
CLEAR lv_bstnk.
ENDIF.
ENDAT.
ls_so-bstnk = lv_bstnk.
MODIFY lt_so FROM ls_so TRANSPORTING bstnk.
ENDLOOP.
LOOP AT ct_vat_header INTO ls_vat_header.
READ TABLE lt_so TRANSPORTING NO FIELDS
WITH KEY refvbeln = ls_vat_header-refvbeln BINARY SEARCH.
IF sy-subrc EQ 0.
lv_tabix = sy-tabix.
ELSE.
CONTINUE.
ENDIF.
LOOP AT lt_so INTO ls_so FROM lv_tabix.
IF ls_so-refvbeln NE ls_vat_header-refvbeln.
EXIT.
ENDIF.
IF sy-tabix = lv_tabix.
CONCATENATE ls_vat_header-note ' Purchase Order:'
ls_so-bstnk INTO ls_vat_header-note.
ELSE.
CONCATENATE ls_vat_header-note '/' ls_so-bstnk INTO ls_vat_header-note.
ENDIF.
ENDLOOP.
MODIFY ct_vat_header FROM ls_vat_header TRANSPORTING note.
ENDLOOP.
ENDMETHOD.
Case8: You need to merge line items according to the material type.
BAdI Name: IDGTCN_VAT_LINES
METHOD IF_EX_VAT_LINES~CHANGE_VAT_LINES.
DATA: lt_mara TYPE TABLE OF mara,
ls_mara TYPE mara,
ls_item LIKE LINE OF it_item.
CHECK ct_vat_item IS NOT INITIAL.
SELECT *
FROM mara
INTO TABLE lt_mara
FOR ALL ENTRIES IN ct_vat_item
WHERE matnr = ct_vat_item-matnr.
SORT lt_mara ASCENDING.
LOOP AT ct_vat_item INTO ls_item.
READ TABLE lt_mara INTO ls_mara WITH KEY matnr = ls_item-matnr
BINARY SEARCH.
IF sy-subrc = 0.
ls_item-customfield1 = ls_mara-mtart.
MODIFY ct_vat_item FROM ls_item TRANSPORTING customfield1.
ENDIF.
ENDLOOP.
Case9: You need to merge line items according to the material and unit price.
BAdI Name: IDGTCN_LINES
METHOD if_ex_lines~change_output_lines.
* Local Work Area Definition
DATA: ls_item TYPE idgt_s_item.
* Local Variant Definition
DATA: lv_unit_price TYPE string.
* Below we need to change customer field2 of line item
LOOP AT ct_item INTO ls_item.
lv_unit_price = ls_item-unitpe.
ls_item-customfield2+0(12) = ls_item-matnr.
ls_item-customfield2+12(8) = lv_unit_price.
MODIFY ct_item FROM ls_item.
ENDLOOP.
ENDMETHOD.
Case10: You need to add new content into GTI outbound file. E.g. add ‘Tax Rate’ in outbound file
BAdI Name: IDGTCN_MODIFY_FILE_CONTENT
METHOD if_ex_lines~change_output_lines.
DATA: BEGIN OF ls_header,
refvbeln TYPE c LENGTH 20, "GT document number
tlines TYPE c LENGTH 4, "Total lines
kname1 TYPE c LENGTH 100, "Payer name
kstcd5 TYPE c LENGTH 15, "Customer register number
kstras TYPE c LENGTH 80, "Payer address
kbanka TYPE c LENGTH 80, "Payer band account
note TYPE c LENGTH 160, "Note
vusnam TYPE c LENGTH 8, "Verified by
cusnam TYPE c LENGTH 8, "Collected by
goodslist TYPE c LENGTH 60, "Goods list name(obsolete)
sentdate TYPE c LENGTH 8, "send date
vbanka TYPE c LENGTH 80, "Payee bank account
vstras TYPE c LENGTH 80, "Payee address
END OF ls_header.
DATA: BEGIN OF ls_item,
maktx TYPE c LENGTH 60, "goods discription
mseht TYPE c LENGTH 16, "UOM description
mspec TYPE c LENGTH 30, "Material Specification
invquan TYPE string, " Quantity
netvalue TYPE string, "Net value
taxrate TYPE string, "Tax rate
taxcod TYPE c LENGTH 4, "Tax code
discamt TYPE string, "Discount Amount
taxamt TYPE string, "Tax amount
disctax TYPE string, "Discount Tax
discrate TYPE string, "Discount Rate
unitpric TYPE string, "Unit Price
price_mode TYPE c, "Price Mode
END OF ls_item.
DATA: lt_item LIKE STANDARD TABLE OF ls_item,
ls_line LIKE LINE OF ct_content,
lv_disc_rate TYPE p DECIMALS 3,
lv_lines TYPE i.
*Step1: Split string into fields
LOOP AT ct_content INTO ls_line.
IF sy-tabix EQ 1. "Header line in SJJK0101
SPLIT ls_line-line AT '~~' INTO ls_header-refvbeln ls_header-tlines
ls_header-kname1 ls_header-kstcd5
ls_header-kstras ls_header-kbanka
ls_header-note ls_header-vusnam
ls_header-cusnam ls_header-goodslist
ls_header-sentdate ls_header-vbanka
ls_header-vstras.
ENDIF.
IF sy-tabix GT 1. "Item line in SJJK0101
SPLIT ls_line-line AT '~~' INTO ls_item-maktx ls_item-mseht
ls_item-mspec ls_item-invquan
ls_item-netvalue ls_item-taxrate
ls_item-taxcod ls_item-discamt
ls_item-taxamt ls_item-disctax
ls_item-discrate ls_item-unitpric
ls_item-price_mode.
APPEND ls_item TO lt_item.
CLEAR ls_item.
ENDIF.
ENDLOOP.
*Step2: Change header or item content
LOOP AT lt_item INTO ls_item.
lv_disc_rate = ls_item-discamt / ls_item-netvalue.
ls_item-discrate = lv_disc_rate.
MODIFY lt_item FROM ls_item TRANSPORTING discrate.
ENDLOOP.
*Step3: Re-generate file lines
DESCRIBE TABLE ct_content LINES lv_lines.
DELETE ct_content FROM 2 TO lv_lines.
CONCATENATE ls_header-refvbeln ls_header-tlines
ls_header-kname1 ls_header-kstcd5
ls_header-kstras ls_header-kbanka
ls_header-note ls_header-vusnam
ls_header-cusnam ls_header-goodslist
ls_header-sentdate ls_header-vbanka
ls_header-vstras INTO ls_line-line SEPARATED BY '~~'.
APPEND ls_line TO ct_content.
CLEAR ls_line.
LOOP AT lt_item INTO ls_item.
CONCATENATE ls_item-maktx ls_item-mseht
ls_item-mspec ls_item-invquan
ls_item-netvalue ls_item-taxrate
ls_item-taxcod ls_item-discamt
ls_item-taxamt ls_item-disctax
ls_item-discrate ls_item-unitpric
ls_item-price_mode INTO ls_line-line SEPARATED BY '~~'.
APPEND ls_line TO ct_content.
CLEAR ls_line.
ENDLOOP.
ENDMETHOD.
Case11: You need to writeback the invoice number to table VBRK.
BAdI Name: IDGTCN_WRITEBACK
METHOD if_ex_writeback~writeback.
DATA: lv_flag_db TYPE xfeld,
ls_idgt_gtdm TYPE idgt_gtdm,
ls_vbrk TYPE vbrk,
ls_idgt_merge_info TYPE idgt_merge_info,
ls_idgt_info TYPE idgt_info,
lv_redvbeln TYPE char10.
CALL METHOD cl_idgt_utility=>get_db_config
IMPORTING
ev_flag = lv_flag_db.
* Assuming the same billing, there is only one business area.
* New DB
IF lv_flag_db = 'X'.
SELECT SINGLE *
FROM idgt_gtdm
INTO ls_idgt_gtdm
WHERE vbeln_gtd = p_idgt_info-refvbeln
AND posnr_gtd = p_idgt_info-posnr.
IF sy-subrc = 0 AND ls_idgt_gtdm-gtotype IS INITIAL.
SELECT SINGLE *
FROM vbrk
INTO ls_vbrk
WHERE vbeln = ls_idgt_gtdm-vbeln.
ls_vbrk-xblnr = p_idgt_info-gtvbeln.
UPDATE vbrk FROM ls_vbrk.
ENDIF.
* Old DB
ELSE.
lv_redvbeln = p_idgt_info-refvbeln.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = lv_redvbeln
IMPORTING
output = lv_redvbeln.
SELECT SINGLE *
FROM idgt_merge_info
INTO ls_idgt_merge_info
WHERE vbeln = lv_redvbeln
AND vfpos = p_idgt_info-posnr.
IF sy-subrc = 0.
SELECT SINGLE *
FROM vbrk
INTO ls_vbrk
WHERE vbeln = ls_idgt_merge_info-vbeln.
ls_vbrk-xblnr = p_idgt_info-gtvbeln.
UPDATE vbrk FROM ls_vbrk.
ELSE.
SELECT SINGLE *
FROM idgt_info
INTO ls_idgt_info
WHERE vbeln = lv_redvbeln.
IF sy-subrc = 0.
SELECT SINGLE *
FROM vbrk
INTO ls_vbrk
WHERE vbeln = ls_idgt_info-vbeln.
ls_vbrk-xblnr = p_idgt_info-gtvbeln.
UPDATE vbrk FROM ls_vbrk.
ENDIF.
ENDIF.
ENDIF.
ENDMETHOD.
Case12: The standard function does not merge different items into one item by default. If you want to merge items by material automatically, you could implement the implicit enhancement at the beginning of the method ‘BUILD_VAT_DATA’ of Class ‘CL_IDGT_OUTBOUND’.
For example, there are three items of a billing document which contains two materials. The standard function will generate three items as a default result. User can push the "Merge by material" to generate two items as a result. After the enhancment, the result will be two items (two materials) by default.
Class: CL_IDGT_OUTBOUND
METHOD: BUILD_VAT_DATA
Example:
DATA: lt_callstack TYPE sys_callst,
ls_cur_item TYPE idgt_s_item,
lv_flag_pos TYPE char1,
lv_flag_neg TYPE char1.
IF cv_mrg_typ IS INITIAL.
CALL FUNCTION 'SYSTEM_CALLSTACK'
EXPORTING
max_level = 0
IMPORTING
et_callstack = lt_callstack.
LOOP AT lt_callstack TRANSPORTING NO FIELDS
WHERE progname = 'CL_IDGT_OUTBOUND==============CP'
AND ( eventname = 'COMBINE_DOCUMENTS' OR eventname = 'SEND_TO_GT' ).
CLEAR: lv_flag_pos,
lv_flag_neg.
LOOP AT mt_cur_item into ls_cur_item.
IF ls_cur_item-netwr > 0.
lv_flag_pos = 'X'.
ELSEIF ls_cur_item-netwr < 0.
lv_flag_neg = 'X'.
ENDIF.
ENDLOOP.
IF lv_flag_pos is initial or lv_flag_neg is initial.
cv_mrg_typ = 'M'.
ENDIF.
EXIT.
ENDLOOP.
ENDIF.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
7 | |
6 | |
6 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 |