Erstellen einer SD-Faktura mithilfe der allg. Fakturaschnittstelle
Das nachfolgende Coding ist ein Aufruf der allg. Fakturaschnittstelle. Hieraus lassen sich alle Felder entnehmen, die zur Erzeugung einer SD-Faktura über den FuBa GN_INVOICE_CREATE erforderlich sind.
*&---------------------------------------------------------------------*
*& Report YTESTINVOICE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
report ytestinvoice message-id vf.
tables: komfkgn, komv, vbsk, rv50s, tvsa.
parameters: e_vbeln like likp-vbeln obligatory.
type-pools: slis.
constants: gc_probclass type char01 value '4', "Problem class
gc_info type char01 value 'I'. "Message : Information
data: gs_display_profile type bal_s_prof,"Application Log: Log Output
"Format Profile
gs_log_handle type balloghndl,"Application Log: Log handle
gs_log type bal_s_log. "Application Log: Log header data
data: gv_free_text type text132, "Report title
gv_count(4) type c.
* ---------- Tabellen der GN_INVOICE_CREATE-Schnittstelle, -------
* ------------- die an die Schnittstelle übergeben werden ----------
data: begin of xkomfkgn occurs 2.
include structure komfkgn.
data: end of xkomfkgn.
data: begin of xkomfkko occurs 2.
include structure komv.
data: end of xkomfkko.
data: begin of xkomfktx occurs 50.
include structure komfktx.
data: end of xkomfktx.
* ---------- Tabellen der GN_INVOICE_CREATE-Schnittstelle, -------
* ------------- die von der Schnittstelle gefüllt werden -----------
data: begin of xkomfk occurs 2.
include structure komfk.
data: end of xkomfk.
data: begin of xkomv occurs 50.
include structure komv.
data: end of xkomv.
data: begin of xthead occurs 50. "aktueller Tabellenstand
include structure thead.
data: txpfl like ttxern-txpfl.
data: tdtext like ttxit-tdtext.
data: lfdtx like ttxern-lfdtx.
data: updkz.
data: end of xthead.
data: begin of xvbfs occurs 20.
include structure vbfs.
data: end of xvbfs.
data: begin of xvbpa occurs 5.
include structure vbpavb.
data: end of xvbpa.
data: begin of xvbrk occurs 10.
include structure vbrkvb.
data: end of xvbrk.
data: begin of xvbrp occurs 100.
include structure vbrpvb.
data: end of xvbrp.
data: begin of xvbss occurs 10.
include structure vbss.
data: end of xvbss.
* ---------------------------------------------------------------------
* Tabelle der Belegunvollständigkeiten: neuer Stand
data: begin of xvbuv occurs 9.
include structure vbuv.
data: updkz(1) type c.
data: end of xvbuv.
* Aktueller Tabellenstand
data: begin of xvbadr occurs 5.
include structure sadrvb.
data: end of xvbadr.
data: xvbfs_count(2) type p.
data: xvbss_count(2) type p.
data: sammelgangsart type c value 'F'. "Sammelgangstyp
refresh xkomfkgn.
clear xkomfkgn.
* --- Muß-Felder der Fakturaschnittstellenstruktur XKOMFKGN füllen ----
* --------- Kundenstamm und Materialstamm wird gelesen ----------------
* 1. Satz
xkomfkgn-mandt = sy-mandt. "Mandant
xkomfkgn-auart = 'TA'. "Verkaufsbelegart
xkomfkgn-vkorg = '1102'. "Verkaufsorganisation
xkomfkgn-vtweg = '50'. "Vertriebsweg
xkomfkgn-spart = '00'. "Sparte
xkomfkgn-fkdat = sy-datum. "Fakturadatum
xkomfkgn-kunag = '0080001101'. "Auftraggeber
xkomfkgn-matnr = '000000000000000103'. "Materialnummer
xkomfkgn-pstyv = 'DLN'. "Positionstyp Vertr.beleg
xkomfkgn-kwmeng = 1. "Auftragsmenge
xkomfkgn-land1 = 'CH'. "Werk
xkomfkgn-vgbel = e_vbeln. "Bel.nummer des Vorg.belegs
xkomfkgn-vgpos = 10. "Vertriebsbelegtyp
xkomfkgn-fkara = 'FX'. "Vorschlag Fakturaart
* nur Muß-Felder wenn kein Kundenstamm lesen
* XKOMFKGN-NO_KNA1 = 'X'. "kein Kundenstamm lesen
* XKOMFKGN-land1 = 'DE'. "Land Warenempfänger
* XKOMFKGN-TAXK1 = '1'. "St.klassifikation 1 Kunde
* nur Muß-Felder wenn kein Materialstamm lesen
xkomfkgn-no_mara = 'X'. "kein Materialstamm lesen
xkomfkgn-taxm1 = '1'. "St.klassifikation 1 Material
xkomfkgn-arktx = 'Testmaterial 1'. "Kurztext Material
xkomfkgn-vrkme = 'ST'. "Verk.mengeneinheit
xkomfkgn-waerk = 'CHF' . "Währung
xkomfkgn-ktgrm = '55'.
append xkomfkgn.
clear xkomfkko.
xkomfkko-mandt = sy-mandt. "Mandant
xkomfkko-knumv = xkomfkgn-vgbel. "Bel.nummer des Vorg.belegs
xkomfkko-kposn = xkomfkgn-vgpos. "Vertriebsbelegtyp
xkomfkko-kschl = 'PR00'. "Konditionsart
xkomfkko-kbetr = 400. "Betrag
append xkomfkko.
* Positionstexte
clear xkomfktx.
xkomfktx-mandt = sy-mandt.
xkomfktx-vgbel = xkomfkgn-vgbel.
xkomfktx-vgpos = xkomfkgn-vgpos.
xkomfktx-tdobject = 'VBBP'.
xkomfktx-tdid = '0001'.
xkomfktx-tdspras = sy-langu.
xkomfktx-tdformat = '*'.
xkomfktx-tdline = 'Das ist ein Pos.Text'.
append xkomfktx.
* --- Muß-Felder der Fakturaschnittstellenstruktur XKOMFKGN füllen ----
* ----- Kundenstamm und Materialstamm wird nicht gelesen --------------
** 2. Satz
*CLEAR xkomfkgn.
*xkomfkgn-mandt = sy-mandt. "Mandant
*xkomfkgn-auart = 'TA'. "Verkaufsbelegart
*xkomfkgn-vkorg = '1102'. "Verkaufsorganisation
*xkomfkgn-vtweg = '50'. "Vertriebsweg
*xkomfkgn-spart = '00'. "Sparte
*xkomfkgn-fkdat = sy-datum. "Fakturadatum
*xkomfkgn-kunag = '0080001101'. "Auftraggeber
*xkomfkgn-matnr = '000000000000000103'. "Materialnummer
*xkomfkgn-pstyv = 'DLN'. "Positionstyp Vertr.beleg
*xkomfkgn-kwmeng = 1. "Auftragsmenge
*xkomfkgn-land1 = 'DE'. "Werk
*xkomfkgn-vgbel = e_vbeln. "Bel.nummer des Vorg.belegs
*xkomfkgn-vgpos = 20. "Vertriebsbelegtyp
*xkomfkgn-fkara = 'FX'. "Vorschlag Fakturaart
*
**xkomfkgn-no_kna1 = 'X'. "kein Kundenstamm lesen
**xkomfkgn-kunwe = '0000000119'. "Warenempfänger
**xkomfkgn-kunrg = '0000000119'. "Regulierer
**xkomfkgn-land1 = 'DE'. "Empfangsland des WE
**xkomfkgn-taxk1 = '1'. "St.klassifikation 1 Kunde
**
*xkomfkgn-no_mara = 'X'. "kein Materialstamm lesen
*xkomfkgn-taxm1 = '1'. "St.klassifikation 1 Material
*xkomfkgn-arktx = 'Testmaterial 2'. "Kurztext Material
*xkomfkgn-vrkme = 'ST'. "Verk.mengeneinheit
*xkomfkgn-waerk = 'EUR' . "Währung
*xkomfkgn-ktgrm = '55'.
*APPEND xkomfkgn.
*
*CLEAR xkomfkko.
*xkomfkko-mandt = sy-mandt. "Mandant
*xkomfkko-knumv = xkomfkgn-vgbel. "Bel.nummer des Vorg.belegs
*xkomfkko-kposn = xkomfkgn-vgpos. "Vertriebsbelegtyp
*xkomfkko-kschl = 'PR00'. "Konditionsart
*xkomfkko-kbetr = 200. "Betrag
*APPEND xkomfkko.
* Füllen Sammelgangsverwaltungssatz
clear vbsk.
vbsk-mandt = sy-mandt. "Mandant
vbsk-ernam = sy-uname. "Name des Sachbearbeiters
vbsk-erdat = sy-datum. "Datum des Hinzufügens
vbsk-uzeit = sy-uzeit. "Uhrzeit -"-
vbsk-smart = 'F'. "Gruppenart
vbsk-sammg = space. "Gruppennummer
*---------------------------------------------------------------------*
* Ermitteln Sammelgangsnummer *
*---------------------------------------------------------------------*
* Sammelgangsnummer, unter der das Protokoll für den Fakturalauf *
* abgespeichert ist *
*---------------------------------------------------------------------*
check rv50s-sammg is initial.
select single * from tvsa where smart = 'F'.
if sy-subrc = 0.
call function 'NUMBER_GET_NEXT'
exporting
nr_range_nr = tvsa-numki
object = 'RV_SAMMG'
importing
number = rv50s-sammg.
else.
message e417 with sammelgangsart.
endif.
*
vbsk-sammg = rv50s-sammg.
*
* Kopftext
clear xkomfktx.
xkomfktx-mandt = sy-mandt.
xkomfktx-vgbel = xkomfkgn-vgbel.
xkomfktx-tdobject = 'VBBK'.
xkomfktx-tdid = '0002'.
xkomfktx-tdspras = sy-langu.
xkomfktx-tdformat = '*'.
xkomfktx-tdline = 'Das ist ein Kopftext'.
append xkomfktx.
*break xrohde.
* ----------- Aufruf der Faktura über allg. Fakturaschnittstelle ------
call function 'GN_INVOICE_CREATE'
exporting
* DELIVERY_DATE = SY-DATUM
* INVOICE_DATE = SY-DATUM
* INVOICE_TYPE = LIKP-FKARV
* PRICING_DATE = SY-DATUM
vbsk_i = vbsk
with_posting = 'B'
id_no_dialog = 'X'
importing
vbsk_e = vbsk
tables
xkomfkgn = xkomfkgn
xkomfkko = xkomfkko
xkomfktx = xkomfktx
xkomfk = xkomfk
xkomv = xkomv
xthead = xthead
xvbfs = xvbfs
xvbpa = xvbpa
xvbrk = xvbrk
xvbrp = xvbrp
xvbss = xvbss.
*
describe table xvbfs lines xvbfs_count.
describe table xvbss lines xvbss_count.
perform create_log using gs_log
changing gs_log_handle.
concatenate text-001 vbsk-sammg into gv_free_text separated by space.
perform add_free_text_message using gv_free_text.
write xvbfs_count to gv_count.
concatenate text-002 gv_count into gv_free_text separated by space.
perform add_free_text_message using gv_free_text.
write xvbss_count to gv_count.
concatenate text-003 gv_count into gv_free_text separated by space.
perform add_free_text_message using gv_free_text.
perform log_create_profile changing gs_display_profile.
perform log_show using gs_display_profile.
*&---------------------------------------------------------------------*
*& Form create_log
*&---------------------------------------------------------------------*
* create Handle for Log
*----------------------------------------------------------------------*
* -->us_log Log header data
* <--xs_log_handle Log Output Format Profile
*----------------------------------------------------------------------*
form create_log using is_log type bal_s_log
changing xs_log_handle type balloghndl.
call function 'BAL_LOG_CREATE'
exporting
i_s_log = is_log
importing
e_log_handle = xs_log_handle
exceptions
log_header_inconsistent = 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. " log_create
*&---------------------------------------------------------------------*
*& Form add_free_text_message
*&---------------------------------------------------------------------*
* this subroutine adds Free text to the log using
* FM 'BAL_LOG_MSG_ADD_FREE_TEXT'
*----------------------------------------------------------------------*
* -->IV_TEXT message text
*----------------------------------------------------------------------*
form add_free_text_message using iv_text. "#EC *
call function 'BAL_LOG_MSG_ADD_FREE_TEXT'
exporting
i_log_handle = gs_log_handle
i_msgty = gc_info
i_probclass = gc_probclass
i_text = iv_text
exceptions
log_not_found = 1
msg_inconsistent = 2
log_is_full = 3
others = 4.
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. " add_free_text_message
*&---------------------------------------------------------------------*
*& Form log_create_profile
*&---------------------------------------------------------------------*
* create a self defined profile
*----------------------------------------------------------------------*
* <-->XS_DISPLAY_PROFILE Log Output Format Profile
*----------------------------------------------------------------------*
form log_create_profile changing xs_display_profile type bal_s_prof.
call function 'BAL_DSP_PROFILE_NO_TREE_GET'
importing
e_s_display_profile = xs_display_profile
exceptions
others = 1.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
* use grid for display if wanted
xs_display_profile-use_grid = 'X'.
* xs_display_profile-no_toolbar = 'X'.
endform. " log_create_profile
*&---------------------------------------------------------------------*
*& Form log_show
*&---------------------------------------------------------------------*
* display the LOG messages
*----------------------------------------------------------------------*
* -->is_display_profile Profile structure
*----------------------------------------------------------------------*
form log_show using is_display_profile type bal_s_prof.
data: lv_log_handle type bal_t_logh.
* Handle
append gs_log_handle to lv_log_handle.
if sy-batch ne 'X'.
* call display function module
call function 'BAL_DSP_LOG_DISPLAY'
exporting
i_s_display_profile = is_display_profile
i_t_log_handle = lv_log_handle
exceptions
others = 1.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
else.
* call print function module
call function 'BAL_DSP_LOG_PRINT'
exporting
i_s_display_profile = is_display_profile
i_t_log_handle = lv_log_handle
exceptions
profile_inconsistent = 1
internal_error = 2
no_data_available = 3
no_authority = 4
others = 5.
if sy-subrc <> 0. "#EC *
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endif.
endform. " log_show
/image%2F1473637%2F20170207%2Fob_adae32_profilbild.png)