You are on page 1of 32

************************************************************************

* Smart Form Print Program *


************************************************************************
*----------------------------------------------------------------------*
*Data
*----------------------------------------------------------------------*
*INCLUDE /SMBA0/AA_FM06TOP.
*&---------------------------------------------------------------------*
*& Include /SMBA0/AA_FM06TOP
*&---------------------------------------------------------------------*
************************************************************************
*& Author: User ID / Name /Company *
*& Date Started: 05/01/2017 *
*& Change Request: IWDK903232 *
*& Description: 1. Change the subject of the email *
*& *
*& *
*&---------------------------------------------------------------------*

PROGRAM ybus_fm06p MESSAGE-ID me.

TYPE-POOLS: addi, meein,


mmpur.
TABLES: nast, "Messages
*nast, "Messages
tnapr, "Programs & Forms
itcpo, "Communicationarea for Spool
arc_params, "Archive parameters
toa_dara, "Archive parameters
addr_key. "Adressnumber for ADDRESS

TYPE-POOLS szadr.
TABLES : varposr,
rwerter,
mtxh.
CONSTANTS lc_bsart_co TYPE bsart VALUE 'CO'. "+ RBARMAN/IWDK903232

DATA umbruch TYPE i VALUE 4.


DATA headerflag.
DATA BEGIN OF vartab OCCURS 15.
INCLUDE STRUCTURE varposr.
DATA END OF vartab.
DATA tabn TYPE i.
DATA taba TYPE i.
DATA ebelph LIKE ekpo-ebelp.
DATA bis TYPE i.
DATA xmax TYPE i.
DATA tab LIKE varposr-yzeile.
DATA diff TYPE i.
DATA ldat_sam LIKE eket-eindt.

DATA: s, v TYPE i.
DATA: sampr LIKE pekpov-netpr, varpr LIKE pekpov-netpr.

***Begin of changes ticket # 125732


DATA:
lt_return TYPE STANDARD TABLE OF bapiret2,
ls_return LIKE LINE OF lt_return,
ls_address TYPE bapiaddr3,
lv_requisitioner TYPE bapibname-bapibname.

***end of changes ticket # 125732

* Struktur zur Variantenbildung

DATA: BEGIN OF wertetab OCCURS 30.


INCLUDE STRUCTURE rwerter.
DATA: atzhl LIKE econf_out-atzhl,
END OF wertetab.

* Interne Tabelle fuer Konditionen


DATA: BEGIN OF kond OCCURS 30.
INCLUDE STRUCTURE komvd.
DATA: END OF kond.
* Hilfsfelder
DATA:
merknamex(15) TYPE c, "Merkmalname x-Achse
merknamey(15) TYPE c, "Merkmalname y-Achse
merknrx LIKE rwerter-nr, "Int. Merkmal x-Achse
merknry LIKE rwerter-nr, "Int. Merkmal y-Achse
i TYPE i VALUE 1,
nr LIKE cawn-atinn.
DATA: inserterror(1),sum TYPE i,menge TYPE i,gsumh TYPE i, xmaxh TYPE i.
DATA: gsumv TYPE i.
* Matrixflag
DATA: m_flag VALUE 'x'.

*- Tabellen -----------------------------------------------------------*
TABLES: cpkme,
ekvkp,
ekko,
pekko,
rm06p,
ekpo,
pekpo,
pekpov,
pekpos,
eket,
ekek,
ekes,
ekeh,
ekkn,
ekpa,
ekbe,
eine, *eine,
lfa1,
likp,
*lfa1,
kna1,
komk,
komp,
komvd,
ekomd,
econf_out,
thead, *thead,
sadr,
mdpa,
mdpm,
mkpf,
tinct,
ttxit,
tmsi2,
tq05,
tq05t,
t001,
t001w,
t006, *t006,
t006a, *t006a,
t024,
t024e,
t027a,
t027b,
t052,
t161n,
t163d,
t166a,
t165p,
t166c,
t166k,
t166p,
t166t,
t166u,
t165m,
t165a,
tmamt,
*mara, "HTN 4.0C
mara,
marc,
mt06e,
makt,
vbak,
vbkd,
*vbkd,
vbap.
TABLES: drad,
drat.
TABLES: addr1_sel,
addr1_val.
TABLES: v_htnm, rampl,tmppf. "HTN-Abwicklung

TABLES: stxh. "schnellerer Zugriff auf Texte Dienstleistung

TABLES: t161. "Abgebotskennzeichen f�r Dienstleistung

*- INTERNE TABELLEN ---------------------------------------------------*


*- Tabelle der Positionen ---------------------------------------------*
DATA: BEGIN OF xekpo OCCURS 10.
INCLUDE STRUCTURE ekpo.
DATA: bsmng LIKE ekes-menge,
END OF xekpo.
*- Key f�r xekpo ------------------------------------------------------*
DATA: BEGIN OF xekpokey,
mandt LIKE ekpo-mandt,
ebeln LIKE ekpo-ebeln,
ebelp LIKE ekpo-ebelp,
END OF xekpokey.

*- Tabelle der Einteilungen -------------------------------------------*


DATA: BEGIN OF xeket OCCURS 10.
INCLUDE STRUCTURE eket.
DATA: fzete LIKE pekpo-wemng,
END OF xeket.

*- Tabelle der Einteilungen tempor?r ----------------------------------*


DATA: BEGIN OF teket OCCURS 10.
INCLUDE STRUCTURE beket.
DATA: END OF teket.

DATA: BEGIN OF zeket.


INCLUDE STRUCTURE eket.
DATA: END OF zeket.

*- Tabelle der Positionszusatzdaten -----------------------------------*


DATA: BEGIN OF xpekpo OCCURS 10.
INCLUDE STRUCTURE pekpo.
DATA: END OF xpekpo.

*- Tabelle der Positionszusatzdaten -----------------------------------*


DATA: BEGIN OF xpekpov OCCURS 10.
INCLUDE STRUCTURE pekpov.
DATA: END OF xpekpov.

*- Tabelle der Zahlungbedingungen--------------------------------------*


DATA: BEGIN OF zbtxt OCCURS 5,
line(50),
END OF zbtxt.

*- Tabelle der Merkmalsauspr?gungen -----------------------------------*


DATA: BEGIN OF tconf_out OCCURS 50.
INCLUDE STRUCTURE econf_out.
DATA: END OF tconf_out.

*- Tabelle der Konditionen --------------------------------------------*


DATA: BEGIN OF tkomv OCCURS 50.
INCLUDE STRUCTURE komv.
DATA: END OF tkomv.

DATA: BEGIN OF tkomk OCCURS 1.


INCLUDE STRUCTURE komk.
DATA: END OF tkomk.

DATA: BEGIN OF tkomvd OCCURS 50. "Belegkonditionen


INCLUDE STRUCTURE komvd.
DATA: END OF tkomvd.

DATA: BEGIN OF tekomd OCCURS 50. "Stammkonditionen


INCLUDE STRUCTURE ekomd.
DATA: END OF tekomd.
*- Tabelle der Bestellentwicklung -------------------------------------*
DATA: BEGIN OF xekbe OCCURS 10.
INCLUDE STRUCTURE ekbe.
DATA: END OF xekbe.

*- Tabelle der Bezugsnebenkosten --------------------------------------*


DATA: BEGIN OF xekbz OCCURS 10.
INCLUDE STRUCTURE ekbz.
DATA: END OF xekbz.

*- Tabelle der WE/RE-Zuordnung ----------------------------------------*


DATA: BEGIN OF xekbez OCCURS 10.
INCLUDE STRUCTURE ekbez.
DATA: END OF xekbez.

*- Tabelle der Positionssummen der Bestellentwicklung -----------------*


DATA: BEGIN OF tekbes OCCURS 10.
INCLUDE STRUCTURE ekbes.
DATA: END OF tekbes.

*- Tabelle der Bezugsnebenkosten der Bestandsf�hrung ------------------*


DATA: BEGIN OF xekbnk OCCURS 10.
INCLUDE STRUCTURE ekbnk.
DATA: END OF xekbnk.

*- Tabelle f�r Kopieren Positionstexte (hier wegen Infobestelltext) ---*


DATA: BEGIN OF xt165p OCCURS 10.
INCLUDE STRUCTURE t165p.
DATA: END OF xt165p.

*- Tabelle der Kopftexte ----------------------------------------------*


DATA: BEGIN OF xt166k OCCURS 10.
INCLUDE STRUCTURE t166k.
DATA: END OF xt166k.

*- Tabelle der Positionstexte -----------------------------------------*


DATA: BEGIN OF xt166p OCCURS 10.
INCLUDE STRUCTURE t166p.
DATA: END OF xt166p.

*- Tabelle der Anahngstexte -------------------------------------------*


DATA: BEGIN OF xt166a OCCURS 10.
INCLUDE STRUCTURE t166a.
DATA: END OF xt166a.

*- Tabelle der Textheader ---------------------------------------------*


DATA: BEGIN OF xthead OCCURS 10.
INCLUDE STRUCTURE thead.
DATA: END OF xthead.

DATA: BEGIN OF xtheadkey,


tdobject LIKE thead-tdobject,
tdname LIKE thead-tdname,
tdid LIKE thead-tdid,
END OF xtheadkey.

DATA: BEGIN OF qm_text_key OCCURS 5,


tdobject LIKE thead-tdobject,
tdname LIKE thead-tdname,
tdid LIKE thead-tdid,
tdtext LIKE ttxit-tdtext,
END OF qm_text_key.

*- Tabelle der Nachrichten alt/neu ------------------------------------*


DATA: BEGIN OF xnast OCCURS 10.
INCLUDE STRUCTURE nast.
DATA: END OF xnast.

DATA: BEGIN OF ynast OCCURS 10.


INCLUDE STRUCTURE nast.
DATA: END OF ynast.

*------ Struktur zur �bergabe der Adressdaten --------------------------


DATA: BEGIN OF addr_fields.
INCLUDE STRUCTURE sadrfields.
DATA: END OF addr_fields.

*------ Struktur zur �bergabe der Adressreferenz -----------------------


DATA: BEGIN OF addr_reference.
INCLUDE STRUCTURE addr_ref.
DATA: END OF addr_reference.

*------ Tabelle zur �bergabe der Fehler -------------------------------


DATA: BEGIN OF error_table OCCURS 10.
INCLUDE STRUCTURE addr_error.
DATA: END OF error_table.

*------ Tabelle zur �bergabe der Adressgruppen ------------------------


DATA: BEGIN OF addr_groups OCCURS 3.
INCLUDE STRUCTURE adagroups.
DATA: END OF addr_groups.

*- Tabelle der Aenderungsbescheibungen --------------------------------*


DATA: BEGIN OF xaend OCCURS 10,
ebelp LIKE ekpo-ebelp,
zekkn LIKE ekkn-zekkn,
etenr LIKE eket-etenr,
ctxnr LIKE t166c-ctxnr,
rounr LIKE t166c-rounr,
insert,
flag_adrnr,
END OF xaend.

DATA: BEGIN OF xaendkey,


ebelp LIKE ekpo-ebelp,
zekkn LIKE ekkn-zekkn,
etenr LIKE eket-etenr,
ctxnr LIKE t166c-ctxnr,
rounr LIKE t166c-rounr,
insert,
flag_adrnr,
END OF xaendkey.

*- Tabelle der Text?nderungen -----------------------------------------*


DATA: BEGIN OF xaetx OCCURS 10,
ebelp LIKE ekpo-ebelp,
textart LIKE cdshw-textart,
chngind LIKE cdshw-chngind,
END OF xaetx.

*- Tabelle der ge?nderten Adressen ------------------------------------*


DATA: BEGIN OF xadrnr OCCURS 5,
adrnr LIKE sadr-adrnr,
tname LIKE cdshw-tabname,
fname LIKE cdshw-fname,
END OF xadrnr.

*- Tabelle der gerade bearbeiteten aktive Komponenten -----------------*


DATA BEGIN OF mdpmx OCCURS 10.
INCLUDE STRUCTURE mdpm.
DATA END OF mdpmx.

*- Tabelle der gerade bearbeiteten Sekund?rbedarfe --------------------*


DATA BEGIN OF mdsbx OCCURS 10.
INCLUDE STRUCTURE mdsb.
DATA END OF mdsbx.

*- Struktur des Archivobjekts -----------------------------------------*


DATA: BEGIN OF xobjid,
objky LIKE nast-objky,
arcnr LIKE nast-optarcnr,
END OF xobjid.

* Struktur f�r zugeh?rigen Sammelartikel


DATA: BEGIN OF sekpo.
INCLUDE STRUCTURE ekpo.
DATA: first_varpos,
END OF sekpo.

*- Struktur f�r Ausgabeergebnis zB Spoolauftragsnummer ----------------*


DATA: BEGIN OF result.
INCLUDE STRUCTURE itcpp.
DATA: END OF result.

*- Struktur f�r Internet NAST -----------------------------------------*


DATA: BEGIN OF intnast.
INCLUDE STRUCTURE snast.
DATA: END OF intnast.

*- HTN-Abwicklung
DATA: BEGIN OF htnmat OCCURS 0.
INCLUDE STRUCTURE v_htnm.
DATA: revlv LIKE rampl-revlv,
END OF htnmat.

DATA htnamp LIKE rampl OCCURS 0 WITH HEADER LINE.

*- Hilfsfelder --------------------------------------------------------*
DATA: hadrnr(8), "Key TSADR
elementn(30), "Name des Elements
save_el(30), "Rettfeld f�r Element
retco LIKE sy-subrc, "Returncode Druck
insert, "Kz. neue Position
h-ind LIKE sy-tabix, "Hilfsfeld Index
h-ind1 LIKE sy-tabix, "Hilfsfeld Index
f1 TYPE f, "Rechenfeld
h-menge LIKE ekpo-menge, "Hilfsfeld Mengenumrechnung
h-meng1 LIKE ekpo-menge, "Hilfsfeld Mengenumrechnung
h-meng2 LIKE ekpo-menge, "Hilfsfeld Mengenumrechnung
ab-menge LIKE ekes-menge, "Hilfsfeld best?tigte Menge
kzbzg LIKE konp-kzbzg, "Staffeln vorhanden?
hdatum LIKE eket-eindt, "Hilfsfeld Datum
hmahnz LIKE ekpo-mahnz, "Hilfsfeld Mahnung
addressnum LIKE ekpo-adrn2, "Hilfsfeld Adressnummer
tablines LIKE sy-tabix, "Z?hler Tabelleneintr?ge
entries LIKE sy-tfill, "Z?hler Tabelleneintr?ge
hstap, "statistische Position
hsamm, "Positionen mit Sammelartikel
hloep, "Gel?schte Positionen im Spiel
hkpos, "Kondition zu l?schen
kopfkond, "Kopfkonditionen vorhanden
no_zero_line, "keine Nullzeilen
xdrflg LIKE t166p-drflg, "Hilfsfeld Textdruck
xprotect, "Kz. protect erfolgt
archiv_object LIKE toa_dara-ar_object, "f�r opt. Archivierung
textflag, "Kz. druckrel. Positionstexte
flag, "allgemeines Kennzeichen
spoolid(10), "Spoolidnummer
xprogram LIKE sy-repid, "Programm
lvs_recipient LIKE swotobjid, "Internet
lvs_sender LIKE swotobjid, "Internet
timeflag, "Kz. Uhrzeit bei mind. 1 Eint.
h_vbeln LIKE vbak-vbeln,
h_vbelp LIKE vbap-posnr.

*- Drucksteuerung -----------------------------------------------------*
DATA: aendernsrv.
DATA: xdruvo. "Druckvorgang
DATA: neu VALUE '1', "Neudruck
aend VALUE '2', "?nderungsdruck
mahn VALUE '3', "Mahnung
absa VALUE '4', "Absage
lpet VALUE '5', "Lieferplaneinteilung
lpma VALUE '6', "Mahnung Lieferplaneinteilung
aufb VALUE '7', "Auftragsbest?tigung
lpae VALUE '8', "?nderung Lieferplaneinteilung
lphe VALUE '9', "Historisierte Einteilungen
preisdruck, "Kz. Gesamtpreis drucken
kontrakt_preis, "Kz. Kontraktpreise drucken
we VALUE 'E'. "Wareneingangswert

*- Hilfsfelder Lieferplaneinteilung -----------------------------------*


DATA:
xlpet, "Lieferplaneinteilung
xfz, "Fortschrittszahlendarstellung
xoffen, "offene WE-Menge
xlmahn, "Lieferplaneinteilungsmahnung
fzflag, "KZ. Abstimmdatum erreicht
xnoaend, "keine ?nderungsbelege da LPET
xetdrk, "Druckrelevante Positionen da LPET
xetefz LIKE eket-menge, "Einteilungsfortschrittszahl
xwemfz LIKE eket-menge, "Lieferfortschrittszahl
xabruf LIKE ekek-abruf, "Alter Abruf
p_abart LIKE ekek-abart. "Abrufart

*data: sum-euro-price like komk-fkwrt. "302203


DATA: sum-euro-price LIKE komk-fkwrt_euro. "302203
DATA: euro-price LIKE ekpo-effwr.

*- Hilfsfelder f�r Ausgabemedium --------------------------------------*


DATA: xdialog, "Kz. POP-UP
xscreen, "Kz. Probeausgabe
xformular LIKE tnapr-fonam, "Formular
xdevice(10). "Ausgabemedium

*- Hilfsfelder f�r QM -------------------------------------------------*


DATA: qv_text_i LIKE tq09t-kurztext, "Bezeichnung Qualit?tsvereinb.
tl_text_i LIKE tq09t-kurztext, "Bezeichnung Technische Lieferb.
zg_kz. "Zeugnis erforderlich

*- Hilfsfelder f�r ?nderungsbeleg -------------------------------------*


DATA: objectid LIKE cdhdr-objectid,
tcode LIKE cdhdr-tcode,
planned_change_number LIKE cdhdr-planchngnr,
utime LIKE cdhdr-utime,
udate LIKE cdhdr-udate,
username LIKE cdhdr-username,
cdoc_planned_or_real LIKE cdhdr-change_ind,
cdoc_upd_object LIKE cdhdr-change_ind VALUE 'U',
cdoc_no_change_pointers LIKE cdhdr-change_ind.

*- Common-Part f�r ?nderungsbeleg -------------------------------------*


*include zzfm06lccd.
DATA: BEGIN OF COMMON PART fm06lccd.

*------- Tabelle der ?nderunsbelegzeilen (tempor?r) -------------------*


DATA: BEGIN OF edit OCCURS 50. "?nderungsbelegzeilen temp.
INCLUDE STRUCTURE cdshw.
DATA: END OF edit.

DATA: BEGIN OF editd OCCURS 50. "?nderungsbelegzeilen temp.


INCLUDE STRUCTURE cdshw. "f�r Dienstleistungen
DATA: END OF editd.

*------- Tabelle der ?nderunsbelegzeilen (Ausgabeform) ----------------*


DATA: BEGIN OF ausg OCCURS 50. "?nderungsbelegzeilen
INCLUDE STRUCTURE cdshw.
DATA: changenr LIKE cdhdr-changenr,
udate LIKE cdhdr-udate,
utime LIKE cdhdr-utime,
END OF ausg.

*------- Tabelle der ?nderunsbelegk?pfe -------------------------------*


DATA: BEGIN OF icdhdr OCCURS 50. "?nderungbelegk?pfe
INCLUDE STRUCTURE cdhdr.
DATA: END OF icdhdr.

*------- Key Tabelle der ?nderunsbelegk?pfe --------------------------*


DATA: BEGIN OF hkey, "Key f�r ICDHDR
mandt LIKE cdhdr-mandant,
objcl LIKE cdhdr-objectclas,
objid LIKE cdhdr-objectid,
chang LIKE cdhdr-changenr,
END OF hkey.

*------- Key der ge?nderten Tabelle f�r Ausgabe ----------------------*


DATA: BEGIN OF ekkey, "Tabellenkeyausgabe
ebeln LIKE ekko-ebeln,
ebelp LIKE ekpo-ebelp,
zekkn LIKE ekkn-zekkn,
etenr LIKE eket-etenr,
abruf LIKE ekek-abruf,
ekorg LIKE ekpa-ekorg, "?nderungsbelege Partner
ltsnr LIKE ekpa-ltsnr, "?nderungsbelege Partner
werks LIKE ekpa-werks, "?nderungsbelege Partner
parvw LIKE ekpa-parvw, "?nderungsbelege Partner
parza LIKE ekpa-parza, "?nderungsbelege Partner
consnumber LIKE adr2-consnumber, "?nderungsbelege Adressen
comm_type LIKE adrt-comm_type, "?nderungsbelege Adressen
END OF ekkey.

DATA: END OF COMMON PART.


*- Direktwerte --------------------------------------------------------*
************************************************************************
* Direktwerte *
************************************************************************
*------- Werte zu Trtyp und Aktyp:
CONSTANTS: hin VALUE 'H', "Hinzufuegen
ver VALUE 'V', "Veraendern
anz VALUE 'A', "Anzeigen
erw VALUE 'E'. "Bestellerweiterung

CONSTANTS:
* BSTYP
bstyp-info VALUE 'I',
bstyp-ordr VALUE 'W',
bstyp-banf VALUE 'B',
bstyp-best VALUE 'F',
bstyp-anfr VALUE 'A',
bstyp-kont VALUE 'K',
bstyp-lfpl VALUE 'L',
bstyp-lerf VALUE 'Q',

* BSAKZ
bsakz-norm VALUE ' ',
bsakz-tran VALUE 'T',
bsakz-rahm VALUE 'R',
* BSAKZ-BEIS VALUE 'B', "not used
* BSAKZ-KONS VALUE 'K', "not used
* BSAKZ-LOHN VALUE 'L', "not used
* BSAKZ-STRE VALUE 'S', "not used
* BSAKZ-MENG VALUE 'M', "not used
* BSAKZ-WERT VALUE 'W', "not used
* PSTYP
pstyp-lagm VALUE '0',
pstyp-blnk VALUE '1',
pstyp-kons VALUE '2',
pstyp-lohn VALUE '3',
pstyp-munb VALUE '4',
pstyp-stre VALUE '5',
pstyp-text VALUE '6',
pstyp-umlg VALUE '7',
pstyp-wagr VALUE '8',
pstyp-dien VALUE '9',

* Kzvbr
kzvbr-anla VALUE 'A',
kzvbr-unbe VALUE 'U',
kzvbr-verb VALUE 'V',
kzvbr-einz VALUE 'E',
kzvbr-proj VALUE 'P',

* ESOKZ
esokz-pipe VALUE 'P',
esokz-lohn VALUE '3',
esokz-konsi VALUE '2', "konsi
esokz-charg VALUE '1', "sc-jp
esokz-norm VALUE '0'.

CONSTANTS:
* Handling von Unterpositionsdaten
sihan-nix VALUE ' ', "keine eigenen Daten
sihan-anz VALUE '1', "Daten aus Hauptposition kopiert, nicht ?nd
sihan-kop VALUE '2', "Daten aus Hauptposition kopiert, aber ?nde
sihan-eig VALUE '3'. "eigene Daten (nicht aus Hauptposition kopi

* Unterpositionstypen
CONSTANTS:
uptyp-hpo VALUE ' ', "Hauptposition
uptyp-var VALUE '1', "Variante
uptyp-nri VALUE '2', "Naturalrabatt Inklusive (=Dreingabe)
uptyp-ler VALUE '3', "Leergut
uptyp-nre VALUE '4', "Naturalrabatt Exklusive (=Draufgabe)
uptyp-lot VALUE '5', "Lot Position
uptyp-dis VALUE '6', "Display Position
uptyp-vks VALUE '7', "VK-Set Position
uptyp-mpn VALUE '8', "Austauschposition (A&D)
uptyp-sls VALUE '9', "Vorkommisionierungsposition (retail)
uptyp-div VALUE 'X'. "HP hat UP's mit verschiedenen Typen

* Artikeltypen
CONSTANTS:
attyp-sam(2) VALUE '01', "Sammelartikel
attyp-var(2) VALUE '02', "Variante
attyp-we1(2) VALUE '20', "Wertartikel
attyp-we2(2) VALUE '21', "Wertartikel
attyp-we3(2) VALUE '22', "Wertartikel
attyp-vks(2) VALUE '10', "VK-Set
attyp-lot(2) VALUE '11', "Lot-Artikel
attyp-dis(2) VALUE '12'. "Display

* Konfigurationsherkunft
CONSTANTS:
kzkfg-fre VALUE ' ', "Konfiguration sonst woher
kzkfg-kan VALUE '1', "noch nicht konfiguriert
kzkfg-eig VALUE '2'. "Eigene Konfiguration

CONSTANTS:
c_ja TYPE c VALUE 'X',
c_nein TYPE c VALUE ' '.
* Vorgangsart, welche Anwendung den Fkt-Baustein aufruft
CONSTANTS:
cva_ab(1) VALUE 'B', "Automatische bestellung (aus banfen)
cva_we(1) VALUE 'C', "Wareneingang
cva_bu(1) VALUE 'D', "�bernahme bestellungen aus fremdsystem
cva_au(1) VALUE 'E', "Aufteiler
cva_kb(1) VALUE 'F', "Kanban
cva_fa(1) VALUE 'G', "Filialauftrag
cva_dr(1) VALUE 'H', "DRP
cva_en(1) VALUE '9', "Enjoy
cva_ap(1) VALUE '1', "APO
cva_ed(1) VALUE 'T'. "EDI-Eingang Auftragsbest?tigung Update Preis

* Status des Einkaufsbeleges (EKKO-STATU)


CONSTANTS:
cks_ag(1) VALUE 'A', "Angebot vorhanden f�r Anfrage
cks_ab(1) VALUE 'B', "Automatische Bestellung (aus Banfen) ME59
cks_we(1) VALUE 'C', "Bestellung aus Wareneingang
cks_bu(1) VALUE 'D', "Bestellung aus Daten�bernahme
cks_au(1) VALUE 'E', "Bestellung aus Aufteiler (IS-Retail)
cks_kb(1) VALUE 'F', "Bestellung aus Kanban
cks_fa(1) VALUE 'G', "Bestellung aus Filialauftrag (IS-Retail)
cks_dr(1) VALUE 'H', "Bestellung aus DRP
cks_ba(1) VALUE 'I', "Bestellung aus BAPI
cks_al(1) VALUE 'J', "Bestellung aus ALE-Szenario
cks_sb(1) VALUE 'S', "Sammelbestellung (IS-Retail)
cks_ap(1) VALUE '1', "APO
cks_en(1) VALUE '9', "Enjoy Bestellung
cks_fb(1) VALUE 'X'. "Bestellung aus Funktionsbaustein

* Vorgang aus T160


CONSTANTS:
vorga-angb(2) VALUE 'AG', "Angebot zur Anfrage ME47, ME48
vorga-lpet(2) VALUE 'LE', "Lieferplaneinteilung ME38, ME39
vorga-frge(2) VALUE 'EF', "Einkaufsbelegfreigabe ME28, ME35, ME45
vorga-frgb(2) VALUE 'BF', "Banffreigabe ME54, ME55
vorga-bgen(2) VALUE 'BB', "Best. Lief.unbekannt ME25
vorga-anha(2) VALUE 'FT', "Textanhang ME24, ME26,...
vorga-banf(2) VALUE 'B ', "Banf ME51, ME52, ME53
vorga-anfr(2) VALUE 'A ', "Anfrage ME41, ME42, ME43
vorga-best(2) VALUE 'F ', "Bestellung ME21, ME22, ME23
vorga-kont(2) VALUE 'K ', "Kontrakt ME31, ME32, ME33
vorga-lfpl(2) VALUE 'L ', "Lieferplan ME31, ME32, ME33
vorga-mahn(2) VALUE 'MA', "Liefermahnung ME91
vorga-aufb(2) VALUE 'AB'. "Best?tigungsmahnung ME92

* Felder f�r Feldauswahl (fr�her FMMEXCOM)


DATA: endmaske(210) TYPE c,
kmaske(140) TYPE c,
auswahl0 TYPE brefn,
auswahl1 TYPE brefn,
auswahl2 TYPE brefn,
auswahl3 TYPE brefn,
auswahl4 TYPE brefn,
auswahl5 TYPE brefn,
auswahl6 TYPE brefn.

* Sonderbestandskennzeichen
CONSTANTS:
sobkz-kdein VALUE 'E', "Kundeneinzel
sobkz-prein VALUE 'Q', "Projekteinzel
sobkz-lohnb VALUE 'O'. "Lohnbearbeiterbeistell

* Min-/Maxwerte f�r Datenelemente


CONSTANTS:
* offener Rechnungseingangswert / Feldl?nge: 13 / Dezimalstellen: 2
c_max_orewr LIKE rm06a-orewr VALUE '99999999999.99',
c_max_orewr_f TYPE f VALUE '99999999999.99',
c_max_orewr_x(15) TYPE c VALUE '**************',

c_max_proz_p(3) TYPE p DECIMALS 2 VALUE '999.99', "@80545


c_max_proz_x(6) TYPE c VALUE '******', "@80545

c_max_menge LIKE ekpo-menge VALUE '9999999999.999', "@83886


c_max_menge_f TYPE f VALUE '9999999999.999', "@83886

c_max_netwr LIKE ekpo-netwr VALUE '99999999999.99', "@83886


c_max_netwr_f TYPE f VALUE '99999999999.99'. "@83886

* Distribution Indicator Account assignment


CONSTANTS:
c_dist_ind-single VALUE ' ', "no multiple = single
c_dist_ind-quantity VALUE '1', "quantity distribution
c_dist_ind-percent VALUE '2'. "percentag

* Datendefinitionen f�r Dienstleistungen


TABLES: eslh,
esll,
ml_esll,
rm11p.

DATA BEGIN OF gliederung OCCURS 50.


INCLUDE STRUCTURE ml_esll.
DATA END OF gliederung.

DATA BEGIN OF leistung OCCURS 50.


INCLUDE STRUCTURE ml_esll.
DATA END OF leistung.

DATA return.

*- interne Tabelle f�r Abrufk?pfe -------------------------------------*


DATA: BEGIN OF xekek OCCURS 20.
INCLUDE STRUCTURE iekek.
DATA: END OF xekek.

*- interne Tabelle f�r Abrufk?pfe alt----------------------------------*


DATA: BEGIN OF pekek OCCURS 20.
INCLUDE STRUCTURE iekek.
DATA: END OF pekek.

*- interne Tabelle f�r Abrufeinteilungen ------------------------------*


DATA: BEGIN OF xekeh OCCURS 20.
INCLUDE STRUCTURE iekeh.
DATA: END OF xekeh.

*- interne Tabelle f�r Abrufeinteilungen ------------------------------*


DATA: BEGIN OF tekeh OCCURS 20.
INCLUDE STRUCTURE iekeh.
DATA: END OF tekeh.

*- Zusatztabelle Abruf nicht vorhanden XEKPO---------------------------*


DATA: BEGIN OF xekpoabr OCCURS 20,
mandt LIKE ekpo-mandt,
ebeln LIKE ekpo-ebeln,
ebelp LIKE ekpo-ebelp,
END OF xekpoabr.

*-- Daten Hinweis 39234 -----------------------------------------------*


*- Hilfstabelle Einteilungen ------------------------------------------*
DATA: BEGIN OF heket OCCURS 10.
INCLUDE STRUCTURE eket.
DATA: tflag LIKE sy-calld,
END OF heket.

*- Key f�r HEKET ------------------------------------------------------*


DATA: BEGIN OF heketkey,
mandt LIKE eket-mandt,
ebeln LIKE eket-ebeln,
ebelp LIKE eket-ebelp,
etenr LIKE eket-etenr,
END OF heketkey.

DATA: h_subrc LIKE sy-subrc,


h_tabix LIKE sy-tabix,
h_field LIKE cdshw-f_old,
h_eindt LIKE rvdat-extdatum.
DATA z TYPE i.

* Defintionen f�r Formeln

TYPE-POOLS msfo.

DATA: variablen TYPE msfo_tab_variablen WITH HEADER LINE.

DATA: formel TYPE msfo_formel.

* Definition f�r Rechnungsplan

DATA: tfpltdr LIKE fpltdr OCCURS 0 WITH HEADER LINE.

DATA: fpltdr LIKE fpltdr.

* Definiton Defaultschema f�r Dienstleistung

CONSTANTS: default_kalsm LIKE t683-kalsm VALUE 'MS0000',


default_kalsm_stamm LIKE t683-kalsm VALUE 'MS0001'.

DATA: bstyp LIKE ekko-bstyp,


bsart LIKE ekko-bsart.

DATA dkomk LIKE komk.

* Defintion f�r Wartungsplan


TABLES: rmipm.
DATA: mpos_tab LIKE mpos OCCURS 0 WITH HEADER LINE,
zykl_tab LIKE mmpt OCCURS 0 WITH HEADER LINE.

DATA: print_schedule.

DATA: BEGIN OF d_tkomvd OCCURS 50.


INCLUDE STRUCTURE komvd.
DATA: END OF d_tkomvd.
DATA: BEGIN OF d_tkomv OCCURS 50.
INCLUDE STRUCTURE komv.
DATA: END OF d_tkomv.

* Definition Drucktabellen blockweises Lesen

DATA: leistung_thead LIKE stxh OCCURS 1 WITH HEADER LINE.


DATA: gliederung_thead LIKE stxh OCCURS 1 WITH HEADER LINE. "HS

DATA: BEGIN OF thead_key,


mandt LIKE sy-mandt,
tdobject LIKE stxh-tdobject,
tdname LIKE stxh-tdname,
tdid LIKE stxh-tdid,
tdspras LIKE stxh-tdspras.
DATA: END OF thead_key.

RANGES: r1_tdname FOR stxh-tdname,


r2_tdname FOR stxh-tdname.

DATA: BEGIN OF doktab OCCURS 0.


INCLUDE STRUCTURE drad.
DATA dktxt LIKE drat-dktxt.
DATA: END OF doktab.

* Additionals Tabelle (CvB/4.0c)


DATA: l_addis_in_orders TYPE LINE OF addi_buying_print_itab
OCCURS 0 WITH HEADER LINE.
* Die Additionals-Strukturen m�ssen bekannt sein
TABLES: wtad_buying_print_addi, wtad_buying_print_extra_text.

DATA: ls_print_data_to_read TYPE lbbil_print_data_to_read.


DATA: ls_bil_invoice TYPE lbbil_invoice.
DATA: lf_fm_name TYPE rs38l_fnam.
DATA: ls_control_param TYPE ssfctrlop.
DATA: ls_composer_param TYPE ssfcompop.
DATA: ls_recipient TYPE swotobjid.
DATA: ls_sender TYPE swotobjid.
DATA: lf_formname TYPE tdsfname.
DATA: ls_addr_key LIKE addr_key,
dunwitheket TYPE xfeld.

DATA: l_zekko LIKE ekko,


l_xpekko LIKE pekko,
l_xekpo LIKE TABLE OF ekpo,
l_wa_xekpo LIKE ekpo.

DATA: l_xekpa LIKE ekpa OCCURS 0,


l_wa_xekpa LIKE ekpa.
DATA: l_xpekpo LIKE pekpo OCCURS 0,
l_wa_xpekpo LIKE pekpo,
l_xeket LIKE TABLE OF eket WITH HEADER LINE,
l_xekkn LIKE TABLE OF ekkn WITH HEADER LINE,
l_xekek LIKE TABLE OF ekek WITH HEADER LINE,
l_xekeh LIKE TABLE OF ekeh WITH HEADER LINE,
l_xkomk LIKE TABLE OF komk WITH HEADER LINE,
l_xtkomv TYPE komv OCCURS 0,
l_wa_xtkomv TYPE komv.

DATA ls_ssfcompop TYPE ssfcompop.


*----------------------------------------------------------------------*
* Subroutines for the Print Program
*----------------------------------------------------------------------*
*INCLUDE /SMBA0/AA_FM06PE02.
*&---------------------------------------------------------------------*
*& Include /SMBA0/AA_FM06PE02
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form GET_PLANT_ADDRESS
*&---------------------------------------------------------------------*
FORM get_plant_address USING p_werks LIKE t001w-werks
CHANGING p_adrnr
p_sadr LIKE sadr.
* parameter P_ADRNR without type since there are several address
* fields with different domains

DATA: l_ekko LIKE ekko,


l_address LIKE addr1_val.

CHECK NOT p_werks IS INITIAL.


l_ekko-reswk = p_werks.
l_ekko-bsakz = 'T'.
CALL FUNCTION 'MM_ADDRESS_GET'
EXPORTING
i_ekko = l_ekko
IMPORTING
e_address = l_address
e_sadr = p_sadr.
p_adrnr = l_address-addrnumber.

ENDFORM. " GET_PLANT_ADDRESS

*&---------------------------------------------------------------------*
*& Form GET_CUSTOMER_ADDRESS
*&---------------------------------------------------------------------*
FORM get_customer_address USING p_kunnr LIKE ekpo-kunnr
CHANGING p_adrnr.
* parameter P_ADRNR without type since there are several address
* fields with different domains

DATA: l_adrnr LIKE kna1-adrnr.

CHECK NOT p_kunnr IS INITIAL.


SELECT SINGLE adrnr FROM kna1 INTO (l_adrnr)
WHERE kunnr = p_kunnr.
IF sy-subrc EQ 0.
p_adrnr = l_adrnr.
ELSE.
CLEAR p_adrnr.
ENDIF.

ENDFORM. " GET_CUSTOMER_ADDRESS

*&---------------------------------------------------------------------*
*& Form GET_VENDOR_ADDRESS
*&---------------------------------------------------------------------*
FORM get_vendor_address USING p_emlif LIKE lfa1-lifnr
CHANGING p_adrnr.
* parameter P_ADRNR without type since there are several address
* fields with different domains

DATA: l_lfa1 LIKE lfa1.

CHECK NOT p_emlif IS INITIAL.


CALL FUNCTION 'VENDOR_MASTER_DATA_SELECT_00'
EXPORTING
i_lfa1_lifnr = p_emlif
i_data = 'X'
i_partner = ' '
IMPORTING
a_lfa1 = l_lfa1
EXCEPTIONS
vendor_not_found = 1.
IF sy-subrc EQ 0.
p_adrnr = l_lfa1-adrnr.
ELSE.
CLEAR p_adrnr.
ENDIF.

ENDFORM. " GET_VENDOR_ADDRESS


*&---------------------------------------------------------------------*
*& Form get_addr_key
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_CS_BIL_INVOICE_HD_ADR text
* <--P_CS_ADDR_KEY text
*----------------------------------------------------------------------*
FORM get_addr_key
USING l_xekko LIKE ekko
CHANGING l_addr_key.

DATA: l_lfa1 LIKE lfa1.

IF l_xekko-lifnr NE space.
CALL FUNCTION 'MM_ADDRESS_GET'
EXPORTING
i_ekko = l_xekko
IMPORTING
e_sadr = sadr
EXCEPTIONS
OTHERS = 1.
MOVE-CORRESPONDING sadr TO l_lfa1.
IF sy-subrc = 0.
MOVE l_lfa1-adrnr TO l_addr_key.
ENDIF.
ENDIF.
ENDFORM. " get_addr_key
*&---------------------------------------------------------------------*
*& Form protocol_update_I
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM protocol_update_i.
CHECK xscreen = space.
CALL FUNCTION 'NAST_PROTOCOL_UPDATE'
EXPORTING
msg_arbgb = syst-msgid
msg_nr = syst-msgno
msg_ty = syst-msgty
msg_v1 = syst-msgv1
msg_v2 = syst-msgv2
msg_v3 = syst-msgv3
msg_v4 = syst-msgv4
EXCEPTIONS
OTHERS = 1.
ENDFORM. " protocol_update_I
*&---------------------------------------------------------------------*
*& Form add_smfrm_prot
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM add_smfrm_prot.
DATA: lt_errortab TYPE tsferror.
DATA: lf_msgnr TYPE sy-msgno.
DATA: l_s_log TYPE bal_s_log,
p_loghandle TYPE balloghndl,
l_s_msg TYPE bal_s_msg.
FIELD-SYMBOLS: <fs_errortab> TYPE LINE OF tsferror.
* get smart form protocoll
CALL FUNCTION 'SSF_READ_ERRORS'
IMPORTING
errortab = lt_errortab.
SORT lt_errortab.
* delete adjacent duplicates from lt_errortab comparing errnumber.
* add smartform protocoll to nast protocoll
LOOP AT lt_errortab ASSIGNING <fs_errortab>.
CLEAR lf_msgnr.
lf_msgnr = <fs_errortab>-errnumber.
CALL FUNCTION 'NAST_PROTOCOL_UPDATE'
EXPORTING
msg_arbgb = <fs_errortab>-msgid
msg_nr = lf_msgnr
msg_ty = <fs_errortab>-msgty
msg_v1 = <fs_errortab>-msgv1
msg_v2 = <fs_errortab>-msgv2
msg_v3 = <fs_errortab>-msgv3
msg_v4 = <fs_errortab>-msgv4
EXCEPTIONS
OTHERS = 1.
ENDLOOP.

* open the application log


l_s_log-extnumber = sy-uname.

CALL FUNCTION 'BAL_LOG_CREATE'


EXPORTING
i_s_log = l_s_log
IMPORTING
e_log_handle = p_loghandle
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
ENDIF.

LOOP AT lt_errortab ASSIGNING <fs_errortab>.


MOVE-CORRESPONDING <fs_errortab> TO l_s_msg.
CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = p_loghandle
i_s_msg = l_s_msg
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
ENDIF.
ENDLOOP.

** Function module to display error logs during


** smart form processing
** Notice , the function 'BAL_DSP_LOG_DISPLAY' can
** not be used when you using output dispatch time
** 4 (Send immediately), so the statement is comment
** out by default.

** You can enable the function call statement


** if your form can not be output and you want to
** see the error log. Set output dispatch time to 3
** before save your order, then print or preview the
** output.
DATA lv_debug.
IF NOT lv_debug IS INITIAL.
CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'.
ENDIF.

ENDFORM. " add_smfrm_prot

*&--------------------------------------------------------------------*
*& Form ENTRY_NEU
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->ENT_RETCO text
* -->ENT_SCREEN text
*---------------------------------------------------------------------*

FORM entry_neu USING ent_retco ent_screen.


DATA: l_druvo LIKE t166k-druvo.
DATA: ls_xfz TYPE char1.

xscreen = ent_screen.

CLEAR ent_retco.
IF nast-aende EQ space.
l_druvo = '1'.
ELSE.
l_druvo = '2'.
ENDIF.

*>>> Start of Insertion >>> OSS 754573 (Liu Ke)


IF xscreen EQ 'X' AND ( nast-tdarmod EQ '2' OR nast-tdarmod EQ '3').
nast-tdarmod = '1'.
ENDIF.
*<<< End of Insertion <<<

PERFORM processing_po USING nast ls_xfz


CHANGING ent_retco ent_screen l_druvo.

ENDFORM. "entry_neu

*&--------------------------------------------------------------------*
*& Form ENTRY_MAHN
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->ENT_RETCO text
* -->ENT_SCREEN text
*---------------------------------------------------------------------*
FORM entry_mahn USING ent_retco ent_screen.

DATA: l_druvo LIKE t166k-druvo.


DATA: ls_xfz TYPE char1.

xscreen = ent_screen.

l_druvo = '3'.

*>>> Start of Insertion >>> OSS 754573 (Liu Ke)


IF xscreen EQ 'X' AND ( nast-tdarmod EQ '2' OR nast-tdarmod EQ '3').
nast-tdarmod = '1'.
ENDIF.
*<<< End of Insertion <<<

PERFORM processing_po USING nast ls_xfz


CHANGING ent_retco ent_screen l_druvo.

ENDFORM. "entry_mahn
*&--------------------------------------------------------------------*
*& Form ENTRY_AUFB
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->ENT_RETCO text
* -->ENT_SCREEN text
*---------------------------------------------------------------------*
FORM entry_aufb USING ent_retco ent_screen.

DATA: l_druvo LIKE t166k-druvo.


DATA: ls_xfz TYPE char1.

xscreen = ent_screen.

l_druvo = '7'.

*>>> Start of Insertion >>> OSS 754573 (Liu Ke)


IF xscreen EQ 'X' AND ( nast-tdarmod EQ '2' OR nast-tdarmod EQ '3').
nast-tdarmod = '1'.
ENDIF.
*<<< End of Insertion <<<

PERFORM processing_po USING nast ls_xfz


CHANGING ent_retco ent_screen l_druvo.

ENDFORM. "entry_aufb

*&--------------------------------------------------------------------*
*& Form ENTRY_ABSA
*&--------------------------------------------------------------------*
* RFQ: Quotation Rejection
* Angebotsabsage
*----------------------------------------------------------------------*
FORM entry_absa USING ent_retco ent_screen.

*********************************************
DATA: l_druvo LIKE t166k-druvo.
DATA: ls_xfz TYPE char1.

xscreen = ent_screen.
l_druvo = '4'.

*>>> Start of Insertion >>> OSS 754573 (Liu Ke)


IF xscreen EQ 'X' AND ( nast-tdarmod EQ '2' OR nast-tdarmod EQ '3').
nast-tdarmod = '1'.
ENDIF.
*<<< End of Insertion <<<
PERFORM processing_po
USING nast
ls_xfz
CHANGING ent_retco
ent_screen
l_druvo.

ENDFORM. "entry_absa

*&--------------------------------------------------------------------*
*& Form ENTRY_LPET
*&--------------------------------------------------------------------*
* Delivery Schedule: Traditional DLS type, without forecast or JIT
* Lieferplaneinteilung
*----------------------------------------------------------------------*
FORM entry_lpet USING ent_retco ent_screen.

DATA: l_druvo LIKE t166k-druvo.


DATA: ls_xfz TYPE char1.
CLEAR ent_retco.
CLEAR ls_xfz.

IF nast-aende EQ space.
l_druvo = '5'.
ELSE.
l_druvo = '8'.
ENDIF.

xscreen = ent_screen.

*>>> Start of Insertion >>> OSS 754573 (Liu Ke)


IF xscreen EQ 'X' AND ( nast-tdarmod EQ '2' OR nast-tdarmod EQ '3').
nast-tdarmod = '1'.
ENDIF.
*<<< End of Insertion <<<

PERFORM processing_po
USING nast
ls_xfz
CHANGING ent_retco
ent_screen
l_druvo.

ENDFORM. "entry_lpet

*&--------------------------------------------------------------------*
*& Form ENTRY_LPMA
*&--------------------------------------------------------------------*
* Dlivery Schedule: Urging/Reminder
* Mahnung
FORM entry_lpma USING ent_retco ent_screen.

DATA: l_druvo LIKE t166k-druvo.


DATA: ls_xfz TYPE char1.

CLEAR ent_retco.
l_druvo = '6'.

xscreen = ent_screen.

*>>> Start of Insertion >>> OSS 754573 (Liu Ke)


IF xscreen EQ 'X' AND ( nast-tdarmod EQ '2' OR nast-tdarmod EQ '3').
nast-tdarmod = '1'.
ENDIF.
*<<< End of Insertion <<<

PERFORM processing_po
USING nast
ls_xfz
CHANGING ent_retco
ent_screen
l_druvo.

ENDFORM. "entry_lpma
*&--------------------------------------------------------------------*
*& Form ENTRY_LPHE_CD
*&--------------------------------------------------------------------*
* Delivery Schedule: Forecast delivery without accumnlation value
FORM entry_lphe_cd USING ent_retco ent_screen.

DATA: l_druvo LIKE t166k-druvo.


DATA: ls_xfz TYPE char1.

CLEAR ent_retco.
l_druvo = '9'.

xscreen = ent_screen.
*>>> Start of Insertion >>> OSS 754573 (Liu Ke)
IF xscreen EQ 'X' AND ( nast-tdarmod EQ '2' OR nast-tdarmod EQ '3').
nast-tdarmod = '1'.
ENDIF.
*<<< End of Insertion <<<

PERFORM processing_po
USING nast
ls_xfz
CHANGING ent_retco
ent_screen
l_druvo.

ENDFORM. "entry_lphe_cd

*&--------------------------------------------------------------------*
*& Form ENTRY_LPJE_CD
*&--------------------------------------------------------------------*
* Delivery Schedule: JIT delivery without accumnlation value
FORM entry_lpje_cd USING ent_retco ent_screen.

DATA: l_druvo LIKE t166k-druvo.


DATA: ls_xfz TYPE char1.

CLEAR ent_retco.
l_druvo = 'A'.

** Get print preview indicator from import parameter


xscreen = ent_screen.

** if it is print preview, Print Archiving mode should be set to


** "Print Only"
IF xscreen EQ 'X' AND ( nast-tdarmod EQ '2' OR nast-tdarmod EQ '3').
nast-tdarmod = '1'.
ENDIF.

PERFORM processing_po
USING nast
ls_xfz
CHANGING ent_retco
ent_screen
l_druvo.

ENDFORM. "entry_lpje_cd

*&--------------------------------------------------------------------*
*& Form PROCESSING_PO
*&--------------------------------------------------------------------*
* Purchase Order Processing Subroutine
FORM processing_po
USING iv_nast TYPE nast
iv_xfz TYPE char1
CHANGING ent_retco
ent_screen
iv_druvo TYPE t166k-druvo.
DATA: ls_print_data_to_read TYPE lbbil_print_data_to_read.
DATA: ls_bil_invoice TYPE lbbil_invoice.
DATA: lf_fm_name TYPE rs38l_fnam.
DATA: ls_control_param TYPE ssfctrlop.
DATA: ls_composer_param TYPE ssfcompop.
DATA: ls_recipient TYPE swotobjid.
DATA: ls_sender TYPE swotobjid.
DATA: lf_formname TYPE tdsfname.
DATA: ls_addr_key LIKE addr_key.
DATA: ls_job_info TYPE ssfcrescl.
DATA: l_spoolid TYPE rspoid.
DATA: lv_receiver TYPE so_recname.

DATA: l_from_memory,
l_doc TYPE meein_purchase_doc_print,
lt_ekpo TYPE TABLE OF ekpo,
ls_ekpo TYPE ekpo,
l_nast LIKE nast,
lv_lifnr TYPE lfa1-lifnr,
i_email TYPE TABLE OF bapiadsmtp,
i_return TYPE TABLE OF bapiret2,
wa_return TYPE bapiret2,
wa_email TYPE bapiadsmtp.

***********************************************************************************
***********************
* Internal Table declarations
DATA: i_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,
i_tline TYPE TABLE OF tline WITH HEADER LINE,
i_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE,
i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,
* Objects to send mail.
i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
i_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,
i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,
i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
* Work Area declarations
wa_objhead TYPE soli_tab,
w_return TYPE ssfcrescl,
wa_doc_chng TYPE sodocchgi1,
w_data TYPE sodocchgi1,
wa_buffer TYPE string, "To convert from 132 to 255
* Variables declarations
v_form_name TYPE rs38l_fnam,
v_len_in LIKE sood-objlen,
v_len_out LIKE sood-objlen,
v_len_outn TYPE i,
v_lines_txt TYPE i,
v_lines_bin TYPE i.
***********************************************************************************
***********************
CALL FUNCTION 'ME_READ_PO_FOR_PRINTING'
EXPORTING
ix_nast = iv_nast
ix_screen = ent_screen
IMPORTING
ex_retco = ent_retco
ex_nast = l_nast
doc = l_doc
CHANGING
cx_druvo = iv_druvo
cx_from_memory = l_from_memory.
CHECK ent_retco EQ 0.

l_nast-aende = iv_nast-aende.

***********************
DATA lv_nast LIKE nast.
IF iv_druvo EQ aend OR iv_druvo EQ lpae.
SELECT datvr uhrvr INTO (lv_nast-datvr, lv_nast-uhrvr) FROM nast
WHERE kappl EQ iv_nast-kappl
AND kschl EQ iv_nast-kschl
AND objky EQ iv_nast-objky
AND vstat EQ '1'
ORDER BY datvr DESCENDING uhrvr DESCENDING.
EXIT.
ENDSELECT.

* If no NEU-Message could be found above, we read any NEU-message of


* that purchase document and use the latest timestamp of these messages
* for the fields *nast-datvr and *nast-uhrvr.
IF sy-subrc NE 0. "Begin of 549924
DATA: neu_messagetypes LIKE t161m OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF time_tab OCCURS 0,
datvr LIKE nast-datvr,
uhrvr LIKE nast-uhrvr,
END OF time_tab.

* Read all messagetypes that are allowed for NEU-Messages


SELECT * FROM t161m INTO TABLE neu_messagetypes
WHERE kvewe EQ 'B'
AND kappl EQ iv_nast-kappl
AND kschl NE iv_nast-kschl
AND druvo EQ neu.
IF sy-subrc EQ 0.
LOOP AT neu_messagetypes.
SELECT datvr uhrvr INTO time_tab FROM nast
WHERE kappl EQ iv_nast-kappl
AND kschl EQ neu_messagetypes-kschl
AND objky EQ iv_nast-objky
AND vstat EQ '1'
ORDER BY datvr DESCENDING uhrvr DESCENDING.
EXIT.
ENDSELECT.
IF sy-subrc EQ 0.
APPEND time_tab.
ENDIF.
ENDLOOP.
SORT time_tab BY datvr DESCENDING uhrvr DESCENDING.
READ TABLE time_tab INDEX 1.
IF sy-subrc EQ 0.
lv_nast-datvr = time_tab-datvr.
lv_nast-uhrvr = time_tab-uhrvr.
ENDIF.
ENDIF.
ENDIF.
l_nast-datvr = lv_nast-datvr.
l_nast-uhrvr = lv_nast-uhrvr.
ENDIF.
***********************
IF iv_nast-adrnr IS INITIAL.
PERFORM get_addr_key
USING l_doc-xekko
CHANGING ls_addr_key.
ELSE.
ls_addr_key = iv_nast-adrnr.
ENDIF.

* IF iv_nast-kschl = 'ZEML'. "Email only


* CLEAR i_reclist.
* SELECT SINGLE smtp_addr FROM adr6 INTO i_reclist-receiver WHERE
* addrnumber = sadr-adrnr.
* if i_reclist-receiver is initial.
* message i000(zmc_mm_enh) with 'email address not found'.
* endif.
* ENDIF.

* Fill up pricing condition table if calling from ME9F


IF l_doc-xtkomv IS INITIAL.
SELECT * INTO TABLE l_doc-xtkomv FROM konv
WHERE knumv = l_doc-xekko-knumv.
ENDIF.

*Set the print Parameters


PERFORM set_print_param USING ls_addr_key
CHANGING ls_control_param
ls_composer_param
ls_recipient
ls_sender
ent_retco.

*Get the Smart Form name.


IF NOT tnapr-sform IS INITIAL.
lf_formname = tnapr-sform.
ELSE.
MESSAGE e001(ssfcomposer).
ENDIF.

* Determine smartform function module for purchase document


CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = lf_formname
IMPORTING
fm_name = lf_fm_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc <> 0.
* error handling
ent_retco = sy-subrc.
IF sy-subrc = 1.
MESSAGE e001(ssfcomposer).
ENDIF.
IF sy-subrc = 2.
MESSAGE e002(ssfcomposer) WITH tnapr-sform.
ENDIF.
PERFORM protocol_update_i.
ENDIF.

* if it is faxed, changed its title to PO number


IF ls_control_param-device = 'TELEFAX'.
ls_composer_param-tdtitle = l_doc-xekko-ebeln.
ENDIF.

"+ BEGIN RBARMAN/IWDK903232


* if it is mail, changed its title to PO number
IF ls_control_param-device = 'MAIL'.
ls_control_param-getotf = 'X'.
ls_control_param-no_dialog = 'X'.
IF l_doc-xekko-bsart = lc_bsart_co.
CONCATENATE 'Ironwood Pharma PO#'(001) l_doc-xekko-ebeln 'for contract'(002)
INTO ls_composer_param-tdtitle SEPARATED BY space.
ELSE.
CONCATENATE 'Ironwood Pharma PO#'(001) l_doc-xekko-ebeln 'for goods
purchase'(003)
INTO ls_composer_param-tdtitle SEPARATED BY space.
ENDIF.

CLEAR i_reclist.
CLEAR lv_receiver.
* SELECT SINGLE smtp_addr FROM adr6 INTO lv_receiver WHERE
* addrnumber = iv_nast-adrnr AND
* consnumber = '002'.
* IF sy-subrc = 0.
* ELSE.
* SELECT SINGLE smtp_addr FROM adr6 INTO lv_receiver WHERE
* addrnumber = iv_nast-adrnr.
* ENDIF.
***Begin of comment tiket # 125732
* i_reclist-receiver = lv_receiver.
* CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
* EXPORTING
* input = l_doc-xekko-lifnr
* IMPORTING
* output = lv_lifnr.
* CALL FUNCTION 'BAPI_BUPA_ADDRESS_GETDETAIL'
* EXPORTING
* businesspartner = lv_lifnr
* TABLES
* bapiadsmtp = i_email
* return = i_return.
* READ TABLE i_return INTO wa_return WITH KEY type = 'E'.
* IF sy-subrc = 0.
* SELECT SINGLE smtp_addr FROM adr6 INTO lv_receiver WHERE
* addrnumber = iv_nast-adrnr.
* i_reclist-receiver = lv_receiver.
* ELSE.
* READ TABLE i_email INTO wa_email INDEX 1.
* i_reclist-receiver = wa_email-e_mail.
** READ TABLE i_email INTO wa_email WITH KEY consnumber = '002'.
** IF sy-subrc = 0.
** i_reclist-receiver = wa_email-e_mail.
** ELSE.
** SELECT SINGLE smtp_addr FROM adr6 INTO lv_receiver WHERE
** addrnumber = iv_nast-adrnr.
** i_reclist-receiver = lv_receiver.
** ENDIF.
* ENDIF.
****END of commmet 127732

***Begin of changes ticket # 125732


lt_ekpo = l_doc-xekpo.
READ TABLE lt_ekpo INTO ls_ekpo INDEX 1.
lv_requisitioner = ls_ekpo-afnam.
IF lv_requisitioner IS NOT INITIAL.
***Get requisitoner email from user profile
CALL FUNCTION 'BAPI_USER_GET_DETAIL'
EXPORTING
username = lv_requisitioner
cache_results = 'X'
IMPORTING
address = ls_address
TABLES
return = lt_return.
IF i_reclist-receiver IS INITIAL.
* message i000(zmc_mm_enh) with 'email address not found'.
ENDIF.
READ TABLE lt_return INTO ls_return WITH KEY type = 'E'.
IF sy-subrc = 0.
ELSE.
i_reclist-receiver = ls_address-e_mail.
ENDIF.
ELSE.
ENDIF.
ENDIF.
***End of changes 125732

*>>>>> Change of Parameters <<<<<<<<<<<<<<<<<<<<<<<


CALL FUNCTION lf_fm_name
EXPORTING
archive_index = toa_dara
archive_parameters = arc_params
control_parameters = ls_control_param
mail_recipient = ls_recipient
mail_sender = ls_sender
output_options = ls_composer_param
is_ekko = l_doc-xekko
user_settings = ' ' "Disable User Printer
is_pekko = l_doc-xpekko
is_nast = l_nast
iv_from_mem = l_from_memory
iv_druvo = iv_druvo
iv_xfz = iv_xfz
IMPORTING
job_output_info = w_return
TABLES
it_ekpo = l_doc-xekpo[]
it_ekpa = l_doc-xekpa[]
it_pekpo = l_doc-xpekpo[]
it_eket = l_doc-xeket[]
it_tkomv = l_doc-xtkomv[]
it_ekkn = l_doc-xekkn[]
it_ekek = l_doc-xekek[]
it_komk = l_xkomk[]
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.

IF sy-subrc <> 0.
ent_retco = sy-subrc.
PERFORM protocol_update_i.

* get SmartForm protocoll and store it in the NAST protocoll


PERFORM add_smfrm_prot.

ELSE.

*>> Begin -Logic for EMail body


i_otf[] = w_return-otfdata[].
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = v_len_in
TABLES
otf = i_otf
lines = i_tline
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
OTHERS = 4.
IF sy-subrc EQ 0.
LOOP AT i_tline.
TRANSLATE i_tline USING '~'.
CONCATENATE wa_buffer i_tline INTO wa_buffer.
ENDLOOP.
TRANSLATE wa_buffer USING '~'.
DO.
i_record = wa_buffer.
APPEND i_record.
SHIFT wa_buffer LEFT BY 255 PLACES.
IF wa_buffer IS INITIAL.
EXIT.
ENDIF.
ENDDO.
* Attachment
REFRESH:
i_objtxt,
i_objbin,
i_objpack.
CLEAR wa_objhead.
i_objbin[] = i_record[].
* Create Message Body Title and Description
CONCATENATE 'Attached here find PO#'(004) l_doc-xekko-ebeln INTO i_objtxt.
APPEND i_objtxt.
IF l_doc-xekko-bsart = lc_bsart_co.
i_objtxt = 'Please reference this number when invoicing against the
contract number in the attached purchase order.'(005).
APPEND i_objtxt.
i_objtxt = 'The contract number can be found under the Description field.
If you have any questions, contact purchasing@ironwoodpharma.com.'(006).
APPEND i_objtxt.
ELSE.
i_objtxt = 'Please reference this number when invoicing. If you have any
questions, contact purchasing@ironwoodpharma.com.'(007).
APPEND i_objtxt.
ENDIF.
DESCRIBE TABLE i_objtxt LINES v_lines_txt.
READ TABLE i_objtxt INDEX v_lines_txt.
wa_doc_chng-obj_name = 'Ironwood Purchase Order'(008).
wa_doc_chng-expiry_dat = sy-datum + 10.
IF l_doc-xekko-bsart = lc_bsart_co.
CONCATENATE 'Ironwood Pharma PO#'(001) l_doc-xekko-ebeln 'for
contract'(002)
INTO wa_doc_chng-obj_descr SEPARATED BY space.
ELSE.
CONCATENATE 'Ironwood Pharma PO#'(001) l_doc-xekko-ebeln 'for goods
purchase'(003)
INTO wa_doc_chng-obj_descr SEPARATED BY space.
ENDIF.
* wa_doc_chng-obj_descr = 'Ironwood Purchase Order'.
wa_doc_chng-sensitivty = 'F'.
wa_doc_chng-doc_size = v_lines_txt * 255.
* Main Text
CLEAR i_objpack-transf_bin.
i_objpack-head_start = 1.
i_objpack-head_num = 0.
i_objpack-body_start = 1.
i_objpack-body_num = v_lines_txt.
i_objpack-doc_type = 'RAW'.
APPEND i_objpack.
* Attachment (pdf-Attachment)
i_objpack-transf_bin = 'X'.
i_objpack-head_start = 1.
i_objpack-head_num = 0.
i_objpack-body_start = 1.
DESCRIBE TABLE i_objbin LINES v_lines_bin.
READ TABLE i_objbin INDEX v_lines_bin.
i_objpack-doc_size = v_lines_bin * 255 .
i_objpack-body_num = v_lines_bin.
i_objpack-doc_type = 'PDF'.
i_objpack-obj_name = 'smart'.
i_objpack-obj_descr = 'Ironwood PO_Form'.
APPEND i_objpack.

i_reclist-rec_type = 'U'.
APPEND i_reclist.
* CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
* EXPORTING
* document_data = wa_doc_chng
* put_in_outbox = 'X'
* commit_work = ' '
* TABLES
* packing_list = i_objpack
* object_header = wa_objhead
* contents_bin = i_objbin
* contents_txt = i_objtxt
* receivers = i_reclist
* EXCEPTIONS
* too_many_receivers = 1
* document_not_sent = 2
* document_type_not_exist = 3
* operation_no_authorization = 4
* parameter_error = 5
* x_error = 6
* enqueue_error = 7
* OTHERS = 8.

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'


EXPORTING
document_data = wa_doc_chng
put_in_outbox = 'X'
sender_address = 'purchasing@ironwoodpharma.com'
sender_address_type = 'SMTP'
commit_work = ' '
TABLES
packing_list = i_objpack
object_header = wa_objhead
contents_bin = i_objbin
contents_txt = i_objtxt
receivers = i_reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.

ENDIF.
*<< End
* required for Discrete Manufacturing scenario 230
**<<<< Start of insertion >>>>*
IF l_nast-kappl EQ 'EL' AND ent_screen IS INITIAL
AND l_from_memory IS INITIAL AND l_nast-sndex IS INITIAL.
IF sy-ucomm NE '9ANZ' AND sy-ucomm NE '9DPR'.
PERFORM update_release(saplmedruck)
TABLES l_doc-xekpo l_doc-xekek l_doc-xekeh
USING iv_druvo l_nast-kschl.
ENDIF.
ENDIF.
*<<<< End of insertion >>>>*
READ TABLE ls_job_info-spoolids INTO l_spoolid INDEX 1.
IF sy-subrc IS INITIAL.
EXPORT spoolid = l_spoolid TO MEMORY ID 'KYK_SPOOLID'.
ENDIF.

ENDIF.
ENDFORM. "PROCESSING_PO

*&---------------------------------------------------------------------*
*& Form set_print_param
*&---------------------------------------------------------------------*
FORM set_print_param USING is_addr_key LIKE addr_key
CHANGING cs_control_param TYPE ssfctrlop
cs_composer_param TYPE ssfcompop
cs_recipient TYPE swotobjid
cs_sender TYPE swotobjid
cf_retcode TYPE sy-subrc.

DATA: ls_itcpo TYPE itcpo.


DATA: lf_repid TYPE sy-repid.
DATA: lf_device TYPE tddevice.
DATA: ls_recipient TYPE swotobjid.
DATA: ls_sender TYPE swotobjid.

lf_repid = sy-repid.

CALL FUNCTION 'WFMC_PREPARE_SMART_FORM'


EXPORTING
pi_nast = nast
pi_addr_key = is_addr_key
pi_repid = lf_repid
IMPORTING
pe_returncode = cf_retcode
pe_itcpo = ls_itcpo
pe_device = lf_device
pe_recipient = cs_recipient
pe_sender = cs_sender.

IF cf_retcode = 0.
MOVE-CORRESPONDING ls_itcpo TO cs_composer_param.
* cs_composer_param-tdnoprint = 'X'. "Note 591576
cs_control_param-device = lf_device.
cs_control_param-no_dialog = 'X'.
cs_control_param-preview = xscreen.
cs_control_param-getotf = ls_itcpo-tdgetotf.
cs_control_param-langu = nast-spras.
ENDIF.
ENDFORM. "set_print_param