Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Smart forms and print program needed

Can anyone provide me with the following print programs and smart forms? I can't find it in my SAP. Thanks.

Print Program:

/SMB40/M07DR

Smart Forms:

/SMB40/MMGR1_A

/SMB40/MMGR3_A

/SMB40/MMGI1_A

Please kindly email me at yeannean@yahoo.com

Former Member
Former Member replied

Hi

I appreciate for your sincierty i cant send through mail but i'm sending directly plz copy all the programs

INCLUDE /SMB40/M07DRTOP.

 
PROGRAM /BPR3PF/m07dr MESSAGE-ID m7.

DATA  lgortsplit LIKE am07m-xselk.
DATA  ladr LIKE sadr.
DATA  *ladr LIKE sadr.

CONSTANTS: a TYPE c VALUE 'A',
           b TYPE c VALUE 'B',
           c TYPE c VALUE 'C',
           d TYPE c VALUE 'D',
           e TYPE c VALUE 'E',
           f TYPE c VALUE 'F',
           g TYPE c VALUE 'G',
           h TYPE c VALUE 'H',
           i TYPE c VALUE 'I',
           j TYPE c VALUE 'J',
           k TYPE c VALUE 'K',
           l TYPE c VALUE 'L',
           m TYPE c VALUE 'M',
           n TYPE c VALUE 'N',
           o TYPE c VALUE 'O',
           p TYPE c VALUE 'P',
           q TYPE c VALUE 'Q',
           r TYPE c VALUE 'R',
           s TYPE c VALUE 'S',
           t TYPE c VALUE 'T',
           u TYPE c VALUE 'U',
           v TYPE c VALUE 'V',
           w TYPE c VALUE 'W',
           x TYPE c VALUE 'X',
           y TYPE c VALUE 'Y',
           z TYPE c VALUE 'Z'.

CONSTANTS: plus  TYPE c VALUE '+',
           minus TYPE c VALUE '-',
           punkt TYPE c VALUE '.',
           null  TYPE c VALUE '0',
           eins  TYPE c VALUE '1',
           zwei  TYPE c VALUE '2',
           drei  TYPE c VALUE '3',
           vier  TYPE c VALUE '4',
           fuenf TYPE c VALUE '5',
           sechs TYPE c VALUE '6',
          sieben TYPE c VALUE '7',
           acht  TYPE c VALUE '8',
           neun  TYPE c VALUE '9',
           einsi TYPE i VALUE '1',
           zweii TYPE i VALUE '2',
           dreii TYPE i VALUE '3',
           vieri TYPE i VALUE '4',
           nzwei TYPE i VALUE '02',
           ndrei TYPE i VALUE '03'.

CONSTANTS: actvt01 LIKE tact-actvt VALUE '01',
           actvt02 LIKE tact-actvt VALUE '02',
           actvt03 LIKE tact-actvt VALUE '03',
           actvt04 LIKE tact-actvt VALUE '04',
           actvt06 LIKE tact-actvt VALUE '06',
           actvt65 LIKE tact-actvt VALUE '65',
           actvt70 LIKE tact-actvt VALUE '70'.

CONSTANTS: maximum     TYPE f VALUE 9999999999999,
           minimum     TYPE f VALUE -9999999999999,
           maximum_gld TYPE f VALUE  99999999999,
           minimum_gld TYPE f VALUE  -99999999999,
           maxvalue LIKE am07m-maxvalue VALUE 9999999999999,
           minvalue LIKE am07m-maxvalue VALUE -9999999999999,
           cnull(18)   TYPE c VALUE '000000000000000000',
           pf02(4)     TYPE c VALUE 'PF02',
           pf15(4)     TYPE c VALUE 'PF15',
           stern       TYPE c VALUE '*',
           doublestar(2) TYPE c VALUE '**',
           underscore  TYPE c VALUE '_',
           slasch      TYPE c VALUE '/',
           dpunkt      TYPE c VALUE ':',
           curtp00     LIKE smbew-curtp VALUE '00', "Transaktionswährung
           curtp10     LIKE smbew-curtp VALUE '10', "ML in Hauswährung
           auto_best   LIKE mseg-ebeln  VALUE '9999999999',
           modulpool   LIKE sy-repid    VALUE 'SAPMM07M'.

CONSTANTS: BEGIN OF hlp,
             b(4) TYPE c VALUE 'HLPB',
             f(4) TYPE c VALUE 'HLPF',
             g(4) TYPE c VALUE 'HLPG',
             m(4) TYPE c VALUE 'HLPM',
             r(4) TYPE c VALUE 'HLPR',
             v(4) TYPE c VALUE 'HLPV',
           END OF hlp.
                                       "Equates für Alphabet

TABLES:
   afko,
   aufk,
   itcpo,
   mkpf,
  *mkpf,
   mseg,
  *mseg,
   ekko,
   ekkn,
  *ekko,
  arc_params,
   ekpo,
   ekbe,
   lfa1,
  *lfa1,
   thead,
   toa_dara,
   am07m,
  *am07m,
   t001,
   t001w,
  *t001w,
   t027b,
   t027c,
   t027d,
   t156,
   t156t,
   t157e,
  *t157e,
   t159m,
   t159n,
   t159o,
   t159p,
   t159s,
   t159e,
   t024,
   t024d,
  *t024,
   t064b,
   nast,
  *nast,
  tnapr.

TABLES: mabdr,
        mtcom,
        mtcor,
        twlad.


*---------------------------------------------------------------------*
* Reportinterne Daten                                                 *
*---------------------------------------------------------------------*

*--- Strukturen ------------------------------------------------------*
DATA: x_protab TYPE c,
      x_bwart TYPE c,
      bwart LIKE mseg-bwart,
      eintraege LIKE sy-tfill,
      anzahl LIKE mseg-weanz,
      anzahl1(7) TYPE n,
      x_kont TYPE c,                   "Mehrfachkontierung
      x_kont1 TYPE c,              "Einfache Kontierung (WE unbewertet)
      x_form TYPE c,
      x_open TYPE c.

DATA: BEGIN OF jahr,
        jahr(4) TYPE n,
        monat(2) TYPE n,
        tag(2) TYPE n,
      END OF jahr.
DATA:
   BEGIN OF we,
     version1 VALUE '1',               "Standardversion
     version2 VALUE '2',               "Version mit Prüftext
     version3 VALUE '3',               "WE-Sammelschein
   END OF we,

   BEGIN OF alt,
      matnr LIKE mseg-matnr,
      bwart LIKE mseg-bwart,
      ebeln LIKE mseg-ebeln,
      usnam LIKE mkpf-usnam,
   END OF alt,

   BEGIN OF kunde,
      kdauf LIKE mseg-kdauf,
      kdpos LIKE mseg-kdpos,
      kdein LIKE mseg-kdein,
   END OF kunde,

   BEGIN OF anlage,
      anln1 LIKE mseg-anln1,
      anln2 LIKE mseg-anln2,
   END OF anlage,

   BEGIN OF belpos,
      mblnr LIKE mseg-mblnr,
      zeile LIKE mseg-zeile,
   END OF belpos,

    xskkz,
    xpsty,

    xkdanr    VALUE 'C',
    xkde      VALUE 'E',
    xfert     VALUE 'F',
    xrvkdanr  VALUE 'A',
    xanlage   VALUE 'A',
    xanln1    VALUE 'I',
    xkostl    VALUE 'K',
    xprojn    VALUE 'P',
    xmunbw    VALUE 'M',
    xumlag    VALUE 'U',
    xvbelg    VALUE 'V',
    xnplan    VALUE 'N',
    xkonsi(2) VALUE 'KB',
    xwabel(2) VALUE 'WA',
    xwibel(2) VALUE 'WI',
    xwebel(2) VALUE 'WE',

     xsele,                            "Position selektiert
     xkont,                            "Kontierungswechsel
     xsamm,                            "Sammel-WE-Schein
     xanha.                            "Mehrfachkontierung

DATA BEGIN OF theader.
        INCLUDE STRUCTURE thead.
DATA END OF theader.


*--- Interne Tabellen -------------------------------------------------*
DATA:
   BEGIN OF dummy OCCURS 0,
     dummy,
   END OF dummy.

DATA:
   BEGIN OF ausgabe OCCURS 20,
      mblnr LIKE mseg-mblnr,
   END OF ausgabe.

DATA: BEGIN OF xekkn OCCURS 50.
        INCLUDE STRUCTURE ekkn.
DATA: END OF xekkn.

DATA: BEGIN OF xmseg OCCURS 50.
        INCLUDE STRUCTURE mseg.
DATA: END OF xmseg.

DATA: BEGIN OF dtext OCCURS 1.
        INCLUDE STRUCTURE tline.
DATA: END OF dtext.

DATA: BEGIN OF dktext OCCURS 1.
        INCLUDE STRUCTURE tline.
DATA: END OF dktext.

DATA: BEGIN OF dptext OCCURS 1.
        INCLUDE STRUCTURE thead.
DATA: END OF dptext.

DATA: BEGIN OF nast_key,
        mblnr LIKE mkpf-mblnr,
        mjahr LIKE mkpf-mjahr,
        zeile LIKE mseg-zeile,
      END OF nast_key.

DATA: BEGIN OF beltab OCCURS 20.
        INCLUDE STRUCTURE mseg.
DATA: vgart LIKE mkpf-vgart,
      blart LIKE mkpf-blart,
      blaum LIKE mkpf-blaum,
      bldat LIKE mkpf-bldat,
      budat LIKE mkpf-budat,
      cpudt LIKE mkpf-cpudt,
      cputm LIKE mkpf-cputm,
      aedat LIKE mkpf-aedat,
      usnam LIKE mkpf-usnam,
      tcode LIKE mkpf-tcode,
      xblnr LIKE mkpf-xblnr,
      bktxt LIKE mkpf-bktxt,
      frath LIKE mkpf-frath,
      frbnr LIKE mkpf-frbnr,
      wever LIKE mkpf-wever,
      kzdru LIKE t156-kzdru,
      END OF beltab.

DATA: BEGIN OF traptab OCCURS 50.
        INCLUDE STRUCTURE mseg.
DATA:   vgart LIKE mkpf-vgart,
        blart LIKE mkpf-blart,
        blaum LIKE mkpf-blaum,
        bldat LIKE mkpf-bldat,
        budat LIKE mkpf-budat,
        cpudt LIKE mkpf-cpudt,
        cputm LIKE mkpf-cputm,
        aedat LIKE mkpf-aedat,
        usnam LIKE mkpf-usnam,
        tcode LIKE mkpf-tcode,
        xblnr LIKE mkpf-xblnr,
        bktxt LIKE mkpf-bktxt,
        frath LIKE mkpf-frath,
        frbnr LIKE mkpf-frbnr,
        wever LIKE mkpf-wever,
      END OF traptab.

DATA: BEGIN OF inthead OCCURS 50.
        INCLUDE STRUCTURE thead.
DATA: END OF inthead.

DATA: BEGIN OF intline OCCURS 50.
        INCLUDE STRUCTURE tline.
DATA: END OF intline.

DATA: BEGIN OF intline1 OCCURS 50.
        INCLUDE STRUCTURE tline.
DATA: END OF intline1.
*-------- Hilfsfelder -------------------------------------------------*
DATA: index_z LIKE sy-tabix,
      drucker LIKE rm07m-ldest,
      old_tdform LIKE t159o-tdform,
      r_werks LIKE t001w-werks,
      r_name1 LIKE t001w-name1,
      x_form3 TYPE c,
      x_nopdest TYPE c,
      language LIKE t001w-spras,
      zaehler_m LIKE sy-tabix,
      edruck  TYPE c.

DATA: old_mkpf LIKE mkpf-usnam,
      old_budat LIKE mkpf-budat,
      old_cpudt LIKE mkpf-cpudt,
      old_werks LIKE t001w-werks,
      old_name1 LIKE t001w-name1,
      old_mblnr LIKE mkpf-mblnr,
      old_lifnr LIKE ekko-lifnr,
      old_ebeln LIKE ekko-ebeln,
      old_ekgrp LIKE ekko-ekgrp,
      old_reswk LIKE ekko-reswk,
      old_linam LIKE am07m-name1,
      old_lina2 LIKE am07m-name2,
      old_eknam LIKE t024-eknam,
      old_ektel LIKE t024-ektel,
      old_ematn LIKE mseg-ematn,
      old_lfa1  LIKE lfa1,
      old_lgort LIKE mseg-lgort,
      old_ladr LIKE ladr,

      save_mkpf LIKE mkpf-usnam,
      save_budat LIKE mkpf-budat,
      save_cpudt LIKE mkpf-cpudt,
      save_werks LIKE t001w-werks,
      save_name1 LIKE t001w-name1,
      save_mblnr LIKE mkpf-mblnr,
      save_lifnr LIKE ekko-lifnr,
      save_reswk LIKE ekko-reswk,
      save_ebeln LIKE ekko-ebeln,
      save_ekgrp LIKE ekko-ekgrp,
      save_linam LIKE am07m-name1,
      save_lina2 LIKE am07m-name2,
      save_eknam LIKE t024-eknam,
      save_ektel LIKE t024-ektel,
      save_ematn LIKE mseg-ematn,
      save_lfa1  LIKE lfa1,
      save_lgort LIKE mseg-lgort,
      save_ladr LIKE ladr,

      offwhile TYPE c,
      & TYPE c VALUE '&',
      blank TYPE c VALUE ' ',
      fenster(5) TYPE c VALUE 'WIN  ',
      fcount(2) TYPE c,
      text1(21) TYPE c VALUE 'INTLINE-TDLINE+  (  )',
      text2(22) TYPE c VALUE 'INTLINE1-TDLINE+  (  )',
      text5(22) TYPE c VALUE 'INTLINE1-TDLINE+  (  )',
      hifeld1(21) TYPE c VALUE 'INTLINE-TDLINE+  (10)',
      shift(2) TYPE n,
      fpage LIKE sy-pagno,
      xscreen(1) TYPE c,
      retco LIKE sy-subrc,
      mblnr LIKE mkpf-mblnr,
      zeile LIKE mseg-zeile,
      new_page,
      xkopfdr,                         "Kopf bereits gedruckt
      n_vornr LIKE resb-vornr.         "Netzplanvorgang

INCLUDE /SMB40/M07DRMTA.

 *------Lesen Tabelle T001----------------------------------------------*
FORM TAB001_LESEN.
  IF NOT T001-BUKRS = MSEG-BUKRS.
    SELECT SINGLE * FROM T001 WHERE BUKRS = MSEG-BUKRS.
  ENDIF.
ENDFORM.

*-------Lesen Tabelle T001w--------------------------------------------*
FORM TAB001W_LESEN.
  IF NOT T001W-WERKS = MSEG-WERKS.
    SELECT SINGLE * FROM T001W WHERE WERKS = MSEG-WERKS.
  ENDIF.
    R_WERKS = T001W-WERKS.
    R_NAME1 = T001W-NAME1.
* Sprache für Formular aus Kondition, sonst aus Werk
  IF NOT NAST-SPRAS IS INITIAL.
    LANGUAGE = NAST-SPRAS.
  ELSE.
    LANGUAGE = T001W-SPRAS.
  ENDIF.
  SET LANGUAGE LANGUAGE.
ENDFORM.

*-------Lesen Tabelle T001w bei Werkswechsel --------------------------*
FORM TAB001W_LESEN_2.
  IF NOT MSEG-WERKS = T001W-WERKS.
    SELECT SINGLE * FROM T001W WHERE WERKS = MSEG-WERKS.
  ENDIF.
ENDFORM.
*--------Lesen Tabelle T156--------------------------------------------*
FORM TAB156_LESEN.
  IF NOT T156-BWART = MSEG-BWART.
    SELECT SINGLE * FROM T156 WHERE BWART = MSEG-BWART.
  ENDIF.
ENDFORM.

*-------Lesen Tabelle T156t--------------------------------------------*
FORM TAB156T_LESEN.
  SELECT SINGLE * FROM T156T WHERE SPRAS = LANGUAGE
                             AND   BWART = MSEG-BWART
                             AND   SOBKZ = MSEG-SOBKZ
                             AND   KZBEW = MSEG-KZBEW
                             AND   KZZUG = MSEG-KZZUG
                             AND   KZVBR = MSEG-KZVBR.

ENDFORM.

*------Lesen Tabelle T024----------------------------------------------*
FORM TAB024_LESEN.
   IF NOT T024-EKGRP = EKKO-EKGRP.
     SELECT SINGLE * FROM T024 WHERE EKGRP = EKKO-EKGRP.
   ENDIF.
ENDFORM.
*------Lesen Tabelle T024D---------------------------------------------*
FORM TAB024D_LESEN.
   SELECT SINGLE * FROM T024D WHERE WERKS = MSEG-WERKS
                              AND   DISPO = AFKO-DISPO.

ENDFORM.

*---------------------- T027B,C lesen ---------------------------------*
FORM T027_LESEN.
  SELECT SINGLE * FROM T027B WHERE SPRAS = LANGUAGE
                             AND   EVERS = MSEG-EVERS.

  CHECK NOT MSEG-EVERE IS INITIAL.

  SELECT SINGLE * FROM T027C WHERE EVERS = MSEG-EVERS
                             AND   EVERE = MSEG-EVERE.

  IF NOT T027C-EVDRK IS INITIAL.
    SELECT SINGLE * FROM T027D WHERE SPRAS = LANGUAGE
                               AND   EVERS = MSEG-EVERS
                               AND   EVERE = MSEG-EVERE.
  ENDIF.

ENDFORM.
*------------ Lesen der Tabelle T159P Barcode oder Mehrfachdruck ------*
*----------------------- gewünscht ? ----------------------------------*
FORM LESEN_T159P.
  IF NOT T159P-TDDEST = NAST-LDEST.
    SELECT SINGLE * FROM T159P WHERE TDDEST = NAST-LDEST.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  T064B_LESEN
*&---------------------------------------------------------------------*
*       Lesen Text zur Bestandsart Qualität/Gesperrt bei WE
*----------------------------------------------------------------------*
FORM T064B_LESEN.
  DATA: BSTAR LIKE T064B-BSTAR.
  CASE MSEG-INSMK.
    WHEN SPACE.
      CLEAR T064B.
      EXIT.
    WHEN F.
      CLEAR T064B.
      EXIT.
    WHEN X.
      BSTAR = ZWEI.
    WHEN ZWEI.
      BSTAR = ZWEI.
    WHEN S.
      BSTAR = VIER.
    WHEN DREI.
      BSTAR = VIER.
  ENDCASE.
  IF NOT T064B-BSTAR = BSTAR.
    SELECT SINGLE * FROM T064B WHERE SPRAS = LANGUAGE
                               AND   BSTAR = BSTAR.
  ENDIF.
ENDFORM.                    " T064B_LESEN

INCLUDE /SMB40/M07DRMMA.

 *---------Material lesen-----------------------------------------------*
FORM MATERIAL_LESEN.
  CLEAR MTCOM.
  MTCOM-KENNG = 'MABDR'.
  MTCOM-MATNR = MSEG-MATNR.
  MTCOM-WERKS = MSEG-WERKS.
  MTCOM-LGORT = MSEG-LGORT.
  MTCOM-SPRAS = LANGUAGE.
  MTCOM-NOMUS = 'X'.
  CALL FUNCTION 'MATERIAL_LESEN'
       EXPORTING
            SCHLUESSEL = MTCOM
       IMPORTING
            MATDATEN   = MABDR
            RETURN     = MTCOR
       TABLES
            SEQMAT01   = DUMMY.
  IF NOT T156-KZMHD IS INITIAL.
    IF NOT MABDR-MHDLP IS INITIAL.
      IF T001W-VLFKZ = B.              "Zentrale ?
        PERFORM MHD_BERECHNEN.
      ENDIF.
    ENDIF.
  ENDIF.
ENDFORM.
*----------------- Mindesthaltbarkeit berechnen  ---------------------*
FORM MHD_BERECHNEN.
  IF NOT EKPO-MHDRZ IS INITIAL.
    AM07M-MHDAT = MSEG-VFDAT - ( EKPO-MHDRZ * MABDR-MHDLP / 100 ).
  ELSEIF NOT MABDR-MHDRZ IS INITIAL.
    AM07M-MHDAT = MSEG-VFDAT - ( MABDR-MHDRZ * MABDR-MHDLP / 100 ).
  ENDIF.
ENDFORM.
*----------------- Prueftext lesen-------------------------------------*
FORM PRUEFTEXT_LESEN.
  CLEAR  DPTEXT.
  CLEAR  THEADER.
  REFRESH DPTEXT.
  THEADER-TDID             = 'PRUE'.
  THEADER-TDSPRAS          = LANGUAGE.
  THEADER-TDNAME           = MSEG-MATNR.
  THEADER-TDOBJECT         = 'MATERIAL '.
  CALL FUNCTION 'SELECT_TEXT'
       EXPORTING
            ID         = THEADER-TDID
            LANGUAGE   = THEADER-TDSPRAS
            NAME       = THEADER-TDNAME
            OBJECT     = THEADER-TDOBJECT
       IMPORTING
            ENTRIES    = EINTRAEGE
       TABLES
            SELECTIONS = DPTEXT.
ENDFORM.
*----------------------------------------------------------------------*
*                Lesen der Herstellerteilenummer                       *
*----------------------------------------------------------------------*
FORM LESEN_HTN.
  SELECT SINGLE MFRPN FROM MARA
           INTO (AM07M-MFRPN) WHERE MATNR = MSEG-EMATN.
ENDFORM.

INCLUDE /SMB40/M07DRMBE.

 *-------------Bestellung lesen-----------------------------------------*
FORM BESTELLUNG_LESEN."ORDER READING

  DATA: NAME1 LIKE ADDR1_VAL-NAME1.
  DATA: OLD_LIFNR LIKE EKKO-LIFNR.
  CLEAR AM07M-NAME1.
  CLEAR AM07M-NAME2.
  IF EKKO-EBELN NE MSEG-EBELN.
    SELECT SINGLE * FROM EKKO WHERE EBELN = MSEG-EBELN.
  ENDIF.
  SELECT SINGLE * FROM EKPO WHERE EBELN = MSEG-EBELN
                            AND   EBELP = MSEG-EBELP.
* Purchase order history because of XBLNR read, since from MKPF can
*deviate
  SELECT SINGLE * FROM EKBE WHERE EBELN = MSEG-EBELN
                            AND   EBELP = MSEG-EBELP
                            AND   VGABE = '1'
                            AND   GJAHR = MSEG-MJAHR
                            AND   BELNR = MSEG-MBLNR
                            AND   BUZEI = MSEG-ZEILE.
  IF NOT SY-SUBRC IS INITIAL.
    CLEAR EKBE.
  ELSE.
    IF NOT EKBE-XBLNR IS INITIAL.
      MKPF-XBLNR = EKBE-XBLNR.
    ENDIF.
  ENDIF.

  CALL FUNCTION 'MM_ADDRESS_GET'
       EXPORTING  I_EKKO    = EKKO
       IMPORTING  E_NAME1   = NAME1
       EXCEPTIONS OTHERS    = 1.
  AM07M-NAME1 = NAME1.
  IF NOT EKKO-LLIEF IS INITIAL.
    OLD_LIFNR = EKKO-LIFNR.
    EKKO-LIFNR = EKKO-LLIEF.
    CALL FUNCTION 'MM_ADDRESS_GET'
         EXPORTING  I_EKKO    = EKKO
         IMPORTING  E_NAME1   = NAME1
         EXCEPTIONS OTHERS    = 1.
    AM07M-NAME2 = NAME1.
    EKKO-LIFNR = OLD_LIFNR.
  ENDIF.
  XPSTY = EKPO-KNTTP.
  CASE XPSTY.
    WHEN B.
      XPSTY = XKDE.
    WHEN D.
      XPSTY = XKDE.
    WHEN G.
      XPSTY = XPROJN.
    WHEN O.
      XPSTY = XPROJN.
    WHEN Q.
      XPSTY = XPROJN.
  ENDCASE.
ENDFORM.

*----------Bestelltext lesen, wenn Matnr. = 0--------------------------*
FORM BESTELLTEXT_LESEN.
   CLEAR:   THEADER,
            THEAD,
            DTEXT.
   REFRESH
            DTEXT.
   THEADER-TDID          = 'F01 '.
   THEADER-TDSPRAS       = EKKO-SPRAS.
   THEADER-TDNAME(10)    = MSEG-EBELN.
   THEADER-TDNAME+10(5)  = MSEG-EBELP.
   THEADER-TDOBJECT      = 'EKPO      '.

   CALL FUNCTION 'READ_TEXT'
      EXPORTING ID          = THEADER-TDID
                LANGUAGE    = THEADER-TDSPRAS
                NAME        = THEADER-TDNAME
                OBJECT      = THEADER-TDOBJECT
     IMPORTING  HEADER      = THEAD
     TABLES     LINES       = DTEXT
     EXCEPTIONS ID          = 1
                LANGUAGE    = 2
                NAME        = 3
                NOT_FOUND   = 4
                OBJECT      = 5.
ENDFORM.

*------------Bestellkopf lesen für WE-Version 2.-----------------------*
FORM BESTELLKOPF_LESEN.
   CLEAR:   THEADER,
            THEAD,
            DKTEXT.
   REFRESH:
            DKTEXT.
   THEADER-TDID           = 'F01 '.
   THEADER-TDSPRAS        = EKKO-SPRAS.
   THEADER-TDNAME(10)     = MSEG-EBELN.
   THEADER-TDOBJECT       = 'EKKO      '.

   CALL FUNCTION 'READ_TEXT'
      EXPORTING ID        = THEADER-TDID
                LANGUAGE  = THEADER-TDSPRAS
                NAME      = THEADER-TDNAME
                OBJECT    = THEADER-TDOBJECT
     IMPORTING  HEADER    = THEAD
     TABLES     LINES     = DKTEXT
     EXCEPTIONS ID        = 1
                LANGUAGE  = 2
                NAME      = 3
                NOT_FOUND = 4
                OBJECT    = 5.

ENDFORM.

INCLUDE /SMB40/M07DRMFA.

*------ Auftragskopf lesen --------------------------------------------*
FORM AUFTRAG_LESEN.
  SELECT SINGLE * FROM AFKO WHERE AUFNR = MSEG-AUFNR.
  IF MSEG-MATNR IS INITIAL.
    SELECT SINGLE * FROM AUFK WHERE AUFNR = MSEG-AUFNR.
    IF NOT SY-SUBRC IS INITIAL.
      MESSAGE E001 WITH 'AUFK' MSEG-AUFNR.
    ELSE.
      MABDR-MAKTX = AUFK-KTEXT.
    ENDIF.
  ENDIF.
ENDFORM.

INCLUDE /SMB40/M07DRKON.

 
FORM KONTIERUNG_LESEN.
   REFRESH XEKKN. CLEAR XEKKN.
   SELECT * FROM EKKN WHERE EBELN = EKPO-EBELN
                      AND   EBELP = EKPO-EBELP.
     MOVE-CORRESPONDING EKKN TO XEKKN.
     APPEND XEKKN.
*    x_kont = x.
   ENDSELECT.
   DESCRIBE TABLE XEKKN LINES INDEX_Z.
   IF INDEX_Z GT 1.
     X_KONT = X.
   ELSE.
     X_KONT1 = X.
   ENDIF.
ENDFORM.

* Network plan process determine.
FORM NW_VORGANG_LESEN USING F_AUFPL F_APLZL.
  CALL FUNCTION 'READ_NETWORK_NPLNR_VORNR'
       EXPORTING
            APLZL     = F_APLZL
            AUFPL     = F_AUFPL
       IMPORTING
            VORNR     = N_VORNR
       EXCEPTIONS
            NOT_FOUND = 01.
ENDFORM.

*----------------------------------------------------------------------*
*       FORM PSP_CONVERT                                               *
*----------------------------------------------------------------------*
*       Konvertierung des internen Felds PS_PSP_PNR zur Ausgabe        *
*----------------------------------------------------------------------*
FORM PSP_CONVERT USING PSPNR LIKE MSEG-PS_PSP_PNR.
  CALL FUNCTION 'CJPN_INTERN_TO_EXTERN_CONV'
       EXPORTING
            INT_NUM = PSPNR
       IMPORTING
            EXT_NUM = AM07M-KONTIERUNG.
ENDFORM.

INCLUDE /SMB40/M07DRF01.

FORM WF01_DRUCK.
   CALL FUNCTION 'START_FORM'
      EXPORTING FORM = TNAPR-FONAM
            LANGUAGE = LANGUAGE.
      BELPOS-MBLNR = MKPF-MBLNR.
      BELPOS-ZEILE = MSEG-ZEILE.
      CONDENSE BELPOS NO-GAPS.
      AM07M-BELPOS = BELPOS.
      IF T156-SHKZG = H.
        AM07M-HDLNE = TEXT-020.
      ELSE.
        AM07M-HDLNE = TEXT-010.
      ENDIF.
      IF NOT T159P-BACOD IS INITIAL.
        CALL FUNCTION 'WRITE_FORM'
             EXPORTING ELEMENT = 'W1BACOKOPF'.
      ELSE.
         CALL FUNCTION 'WRITE_FORM'
             EXPORTING ELEMENT = 'W1KOPF'.
      ENDIF.
      IF XPSTY       IS INITIAL.
         IF MSEG-XBLVS IS INITIAL.
            PERFORM WF1_LAGERMATERIAL.             "Lagermaterial
         ELSE.
            PERFORM WF1_LVSMATERIAL.               "LVS-Material
         ENDIF.
      ELSE.
         PERFORM WF1_VERBRAUCHSMATERIAL.
      ENDIF.
   CALL FUNCTION 'END_FORM'.
   PERFORM MKTO_DRUCK.
ENDFORM.
*------------ Drucken Lagermaterial ---------------------------------*
 FORM WF1_LAGERMATERIAL.
   CALL FUNCTION 'WRITE_FORM'
      EXPORTING ELEMENT = 'W1LGMAT'.
   IF T156-SHKZG = H AND
     NOT MSEG-GRUND IS INITIAL.
     SELECT SINGLE * FROM T157E WHERE BWART = MSEG-BWART
                                AND   GRUND = MSEG-GRUND
                                AND   SPRAS = LANGUAGE.
     CALL FUNCTION 'WRITE_FORM'
          EXPORTING ELEMENT = 'RUELGGRUND'.
   ENDIF.
   CALL FUNCTION 'WRITE_FORM'
        EXPORTING ELEMENT = 'LGAUSST'.
 ENDFORM.

 FORM WF1_LVSMATERIAL.
   CALL FUNCTION 'WRITE_FORM'
      EXPORTING ELEMENT = 'W1LVSMAT'.
   IF T156-SHKZG = H AND
     NOT MSEG-GRUND IS INITIAL.
     SELECT SINGLE * FROM T157E WHERE BWART = MSEG-BWART
                                AND   GRUND = MSEG-GRUND
                                AND   SPRAS = LANGUAGE.
     CALL FUNCTION 'WRITE_FORM'
          EXPORTING ELEMENT = 'RUELVSGRUND'.
   ENDIF.
   CALL FUNCTION 'WRITE_FORM'
        EXPORTING ELEMENT = 'LVSAUSST'.
 ENDFORM.

*-------------Drucken Verbrauchsmaterial------------------------------*
 FORM WF1_VERBRAUCHSMATERIAL.

   CASE XPSTY.

     WHEN XKDANR.                             "Kundenauftrag
       MOVE SPACE TO KUNDE.
       CLEAR AM07M-KOTXT.
       AM07M-KOTXT = TEXT-030.
       KUNDE-KDAUF = MSEG-KDAUF.
       KUNDE-KDPOS = MSEG-KDPOS.
       KUNDE-KDEIN = MSEG-KDEIN.
       MOVE SPACE TO AM07M-KONTIERUNG.
       CONDENSE KUNDE NO-GAPS.
       AM07M-KONTIERUNG = KUNDE.
     WHEN XANLAGE.                            "Anlage
       MOVE SPACE TO ANLAGE.
       CLEAR AM07M-KOTXT.
       AM07M-KOTXT = TEXT-040.
       ANLAGE-ANLN1 = MSEG-ANLN1.
       ANLAGE-ANLN2 = MSEG-ANLN2.
       MOVE SPACE TO AM07M-KONTIERUNG.
       CONDENSE ANLAGE NO-GAPS.
       AM07M-KONTIERUNG = ANLAGE.
     WHEN XKOSTL.                             "Kostenstelle
       CLEAR AM07M-KOTXT.
       AM07M-KOTXT = TEXT-050.
       AM07M-KONTIERUNG = MSEG-KOSTL.

     WHEN XPROJN.                             "Projekt/Netzplan
       CLEAR AM07M-KOTXT.
       IF MSEG-NPLNR IS INITIAL.
         AM07M-KOTXT = TEXT-060.
         PERFORM PSP_CONVERT USING MSEG-PS_PSP_PNR.
       ELSE.
         AM07M-KOTXT = TEXT-061.
         AM07M-KONTIERUNG = MSEG-NPLNR.
         PERFORM NW_VORGANG_LESEN USING MSEG-AUFPL MSEG-APLZL.
         IF NOT N_VORNR IS INITIAL.
           MOVE '/'     TO AM07M-KONTIERUNG+12.
           MOVE N_VORNR TO AM07M-KONTIERUNG+13.
         ENDIF.
       ENDIF.
   ENDCASE.

   CALL FUNCTION 'WRITE_FORM'
     EXPORTING ELEMENT = 'W1VERBRMAT'.
   IF T156-SHKZG = H AND
     NOT MSEG-GRUND IS INITIAL.
     SELECT SINGLE * FROM T157E WHERE BWART = MSEG-BWART
                                AND   GRUND = MSEG-GRUND
                                AND   SPRAS = LANGUAGE.
     CALL FUNCTION 'WRITE_FORM'
          EXPORTING ELEMENT = 'RUELVERBRGRUND'.
   ENDIF.
   CALL FUNCTION 'WRITE_FORM'
        EXPORTING ELEMENT = 'VERBRAUSST'.
 ENDFORM.

INCLUDE /SMB40/M07DRF02.

 FORM WF02_DRUCK.
   T001W-WERKS = R_WERKS.
   T001W-NAME1 = R_NAME1.
   CALL FUNCTION 'START_FORM'
        EXPORTING FORM = TNAPR-FONAM
              LANGUAGE = LANGUAGE.
   PERFORM PRUEFTEXT_LESEN.
      IF T156-SHKZG = 'H'.           "Kennzeichen Haben ?
        AM07M-HDLNE = TEXT-020.
      ELSE.
        AM07M-HDLNE = TEXT-010.
      ENDIF.
      IF NOT T159P-BACOD IS INITIAL.
        BELPOS-MBLNR = MKPF-MBLNR.
        BELPOS-ZEILE = MSEG-ZEILE.
        CONDENSE BELPOS NO-GAPS.
        AM07M-BELPOS = BELPOS.
        CALL FUNCTION 'WRITE_FORM'
             EXPORTING ELEMENT = 'WE2BACOKOPF'.
      ELSE.
        CALL FUNCTION 'WRITE_FORM'
             EXPORTING ELEMENT = 'WE2KOPF'.
      ENDIF.
      IF XPSTY       IS INITIAL.        "Lagermaterial ?
         PERFORM W2_LAGERMATERIAL.
      ELSE.
         PERFORM W2_VERBRAUCHSMATERIAL.
      ENDIF.
   CALL FUNCTION 'END_FORM'.
   PERFORM MKTO_DRUCK.
ENDFORM.

*-------------- Lagermaterial WE-Version 2 ---------------------------*
FORM WF2_LAGERMATERIAL.
  CALL FUNCTION 'WRITE_FORM'
       EXPORTING ELEMENT = 'WE2LGMAT'.
  IF T156-SHKZG = H AND
     NOT MSEG-GRUND IS INITIAL.
    SELECT SINGLE * FROM T157E WHERE BWART = MSEG-BWART
                               AND   GRUND = MSEG-GRUND
                               AND   SPRAS = LANGUAGE.
    CALL FUNCTION 'WRITE_FORM'
         EXPORTING ELEMENT = 'RUELGGRUND'.
  ENDIF.
    THEAD-TDID     = THEADER-TDID.
    THEAD-TDNAME   = THEADER-TDNAME.
    THEAD-TDOBJECT = THEADER-TDOBJECT.
    THEAD-TDSPRAS  = THEADER-TDSPRAS.
    CALL FUNCTION 'WRITE_FORM'
        EXPORTING ELEMENT = 'PRTXTLGMAT'.

ENDFORM.

*------------ Verbrauchsmaterial WE-Version 2 ----------------------*
 FORM WF2_VERBRAUCHSMATERIAL.
    CASE XPSTY.
       WHEN XKDANR.
          MOVE SPACE TO KUNDE.
          CLEAR AM07M-KOTXT.
          AM07M-KOTXT = TEXT-030.
          KUNDE-KDAUF = MSEG-KDAUF.
          KUNDE-KDPOS = MSEG-KDPOS.
          KUNDE-KDEIN = MSEG-KDEIN.
          MOVE SPACE TO AM07M-KONTIERUNG.
          CONDENSE KUNDE NO-GAPS.
          AM07M-KONTIERUNG = KUNDE.
       WHEN XANLAGE.
          MOVE SPACE TO ANLAGE.
          CLEAR AM07M-KOTXT.
          AM07M-KOTXT = TEXT-040.
          ANLAGE-ANLN1 = MSEG-ANLN1.
          ANLAGE-ANLN2 = MSEG-ANLN2.
          MOVE SPACE TO AM07M-KONTIERUNG.
          CONDENSE ANLAGE NO-GAPS.
          AM07M-KONTIERUNG = ANLAGE.
       WHEN XKOSTL.
          CLEAR AM07M-KOTXT.
          AM07M-KOTXT = TEXT-050.
          AM07M-KONTIERUNG = MSEG-KOSTL.

       WHEN XPROJN.
          CLEAR AM07M-KOTXT.
          IF MSEG-NPLNR IS INITIAL.
            AM07M-KOTXT = TEXT-060.
            PERFORM PSP_CONVERT USING MSEG-PS_PSP_PNR.
          ELSE.
            AM07M-KOTXT = TEXT-061.
            AM07M-KONTIERUNG = MSEG-NPLNR.
            PERFORM NW_VORGANG_LESEN USING MSEG-AUFPL MSEG-APLZL.
            IF NOT N_VORNR IS INITIAL.
              MOVE '/'     TO AM07M-KONTIERUNG+12.
              MOVE N_VORNR TO AM07M-KONTIERUNG+13.
            ENDIF.
          ENDIF.
    ENDCASE.

  CALL FUNCTION 'WRITE_FORM'
       EXPORTING ELEMENT = 'WE2VERBRMAT'.
   IF T156-SHKZG = H AND
     NOT MSEG-GRUND IS INITIAL.
     SELECT SINGLE * FROM T157E WHERE BWART = MSEG-BWART
                                AND   GRUND = MSEG-GRUND
                                AND   SPRAS = LANGUAGE.
     CALL FUNCTION 'WRITE_FORM'
          EXPORTING ELEMENT = 'RUEVERBRGRUND'.
   ENDIF.
     THEAD-TDID     = THEADER-TDID.
     THEAD-TDNAME   = THEADER-TDNAME.
     THEAD-TDOBJECT = THEADER-TDOBJECT.
     THEAD-TDSPRAS  = THEADER-TDSPRAS.
     CALL FUNCTION 'WRITE_FORM'
          EXPORTING ELEMENT = 'PRTXTVERBRMAT'.
ENDFORM.

INCLUDE /SMB40/M07DRE01.

 FORM WE01_DRUCK.
   T001W-WERKS = R_WERKS.
   T001W-NAME1 = R_NAME1.
ENDFORM.
*------------ Drucken Lagermaterial ---------------------------------*
 FORM W1_LAGERMATERIAL.
   CALL FUNCTION 'WRITE_FORM'
      EXPORTING ELEMENT = 'W1LGMAT'.
   IF T156-SHKZG = H AND
     NOT MSEG-GRUND IS INITIAL.
     SELECT SINGLE * FROM T157E WHERE BWART = MSEG-BWART
                                AND   GRUND = MSEG-GRUND
                                AND   SPRAS = LANGUAGE.
     CALL FUNCTION 'WRITE_FORM'
          EXPORTING ELEMENT = 'RUELGGRUND'.
   ENDIF.
   CALL FUNCTION 'WRITE_FORM'
        EXPORTING ELEMENT = 'LGAUSST'.
 ENDFORM.

 FORM W1_LVSMATERIAL.
   CALL FUNCTION 'WRITE_FORM'
      EXPORTING ELEMENT = 'W1LVSMAT'.
   IF T156-SHKZG = H AND
     NOT MSEG-GRUND IS INITIAL.
     SELECT SINGLE * FROM T157E WHERE BWART = MSEG-BWART
                                AND   GRUND = MSEG-GRUND
                                AND   SPRAS = LANGUAGE.
     CALL FUNCTION 'WRITE_FORM'
          EXPORTING ELEMENT = 'RUELVSGRUND'.
   ENDIF.
   CALL FUNCTION 'WRITE_FORM'
        EXPORTING ELEMENT = 'LVSAUSST'.
 ENDFORM.

*-------------Drucken Verbrauchsmaterial------------------------------*
 FORM W1_VERBRAUCHSMATERIAL.
   CLEAR: AM07M-KOTXT, AM07M-KONTIERUNG.
   CASE XPSTY.
     WHEN XFERT.                            "Fertigungsauftrag
       AM07M-KOTXT = TEXT-062.
       IF X_KONT1 IS INITIAL.
         AM07M-KONTIERUNG = MSEG-AUFNR.
       ELSE.
         AM07M-KONTIERUNG = EKKN-AUFNR.
       ENDIF.

     WHEN XKDE.                             "Kundeneinzelbest.
       MOVE SPACE TO KUNDE.
       AM07M-KOTXT = TEXT-030.
       IF X_KONT1 IS INITIAL.
         KUNDE-KDAUF = MSEG-KDAUF.
         KUNDE-KDPOS = MSEG-KDPOS.
        ELSE.
         KUNDE-KDAUF = EKKN-VBELN.
         KUNDE-KDPOS = EKKN-VBELP.
        ENDIF.
       MOVE SPACE TO AM07M-KONTIERUNG.
       CONDENSE KUNDE NO-GAPS.
       AM07M-KONTIERUNG = KUNDE.
     WHEN XKDANR.                             "Kundenauftrag
       MOVE SPACE TO KUNDE.
       AM07M-KOTXT = TEXT-030.
       IF X_KONT1 IS INITIAL.
         KUNDE-KDAUF = MSEG-KDAUF.
         KUNDE-KDPOS = MSEG-KDPOS.
         KUNDE-KDEIN = MSEG-KDEIN.
        ELSE.
         KUNDE-KDAUF = EKKN-VBELN.
         KUNDE-KDPOS = EKKN-VBELP.
         KUNDE-KDEIN = EKKN-VETEN.
        ENDIF.
       MOVE SPACE TO AM07M-KONTIERUNG.
       CONDENSE KUNDE NO-GAPS.
       AM07M-KONTIERUNG = KUNDE.
     WHEN XANLAGE.                            "Anlage
       MOVE SPACE TO ANLAGE.
       AM07M-KOTXT = TEXT-040.
       IF X_KONT1 IS INITIAL.
         ANLAGE-ANLN1 = MSEG-ANLN1.
         ANLAGE-ANLN2 = MSEG-ANLN2.
       ELSE.
         ANLAGE-ANLN1 = EKKN-ANLN1.
         ANLAGE-ANLN2 = EKKN-ANLN2.
       ENDIF.
       MOVE SPACE TO AM07M-KONTIERUNG.
       CONDENSE ANLAGE NO-GAPS.
       AM07M-KONTIERUNG = ANLAGE.
     WHEN XKOSTL.                             "Kostenstelle
       AM07M-KOTXT = TEXT-050.
       IF X_KONT1 IS INITIAL.
         AM07M-KONTIERUNG = MSEG-KOSTL.
       ELSE.
         AM07M-KONTIERUNG = EKKN-KOSTL.
       ENDIF.

     WHEN XPROJN.                             "Projekt/Netzplan
       IF X_KONT1 IS INITIAL.
         IF MSEG-NPLNR IS INITIAL.
           AM07M-KOTXT = TEXT-060.
           PERFORM PSP_CONVERT USING MSEG-PS_PSP_PNR.
         ELSE.
           AM07M-KOTXT = TEXT-061.
           AM07M-KONTIERUNG = MSEG-NPLNR.
           PERFORM NW_VORGANG_LESEN USING MSEG-AUFPL MSEG-APLZL.
           IF NOT N_VORNR IS INITIAL.
             MOVE '/'     TO AM07M-KONTIERUNG+12.
             MOVE N_VORNR TO AM07M-KONTIERUNG+13.
           ENDIF.
         ENDIF.
       ELSE.
         IF EKKN-NPLNR IS INITIAL.
           AM07M-KOTXT = TEXT-060.
           PERFORM PSP_CONVERT USING EKKN-PS_PSP_PNR.
         ELSE.
           AM07M-KOTXT = TEXT-061.
           AM07M-KONTIERUNG = EKKN-NPLNR.
           PERFORM NW_VORGANG_LESEN USING EKKN-AUFPL EKKN-APLZL.
           IF NOT N_VORNR IS INITIAL.
             MOVE '/'     TO AM07M-KONTIERUNG+12.
             MOVE N_VORNR TO AM07M-KONTIERUNG+13.
           ENDIF.
         ENDIF.
       ENDIF.
   ENDCASE.
   CLEAR X_KONT1.
* User-Exit über Erweiterung MBCF0005
   CALL CUSTOMER-FUNCTION '001'
        EXPORTING
             I_MKPF  = MKPF
             I_MSEG  = MSEG
             I_EKKO  = EKKO
             I_EKPO  = EKPO
             I_NAST  = NAST
             I_TNAPR = TNAPR
        TABLES
             I_EKKN  = XEKKN
        CHANGING
             C_AM07M = AM07M
        EXCEPTIONS
             OTHERS  = 0.

   CALL FUNCTION 'WRITE_FORM'
     EXPORTING ELEMENT = 'W1VERBRMAT'.
   IF T156-SHKZG = H AND
     NOT MSEG-GRUND IS INITIAL.
     SELECT SINGLE * FROM T157E WHERE BWART = MSEG-BWART
                                AND   GRUND = MSEG-GRUND
                                AND   SPRAS = LANGUAGE.
     CALL FUNCTION 'WRITE_FORM'
          EXPORTING ELEMENT = 'RUELVERBRGRUND'.
   ENDIF.
   CALL FUNCTION 'WRITE_FORM'
        EXPORTING ELEMENT = 'VERBRAUSST'.
 ENDFORM.

INCLUDE /SMB40/M07DRE02.

 *---------------------------------------------------------------------*
*       FORM WE02_DRUCK                                               *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM WE02_DRUCK.
  T001W-WERKS = R_WERKS.
  T001W-NAME1 = R_NAME1.
  CALL FUNCTION 'START_FORM'
       EXPORTING
            FORM     = TNAPR-FONAM
            LANGUAGE = LANGUAGE.
  PERFORM PRUEFTEXT_LESEN.
  IF NOT MSEG-VFDAT IS INITIAL.
    AM07M-MHTXT = TEXT-105.
  ENDIF.
  IF NOT AM07M-MHDAT IS INITIAL.
    AM07M-MHZTX = TEXT-106.
  ENDIF.
  IF EKKO-BSART = 'UB'.
    AM07M-LITXT = TEXT-101.
    AM07M-LIBZG = EKKO-RESWK.
  ELSE.
    AM07M-LITXT = TEXT-100.
    AM07M-LIBZG = EKKO-LIFNR.
    IF NOT EKKO-LLIEF IS INITIAL.
      AM07M-LIBZ2 = EKKO-LLIEF.
    ELSE.
      AM07M-LIBZ2 = EKKO-LIFNR.
    ENDIF.
  ENDIF.
  IF T156-SHKZG = 'H'.                 "Kennzeichen Haben ?
    AM07M-HDLNE = TEXT-020.
  ELSE.
    AM07M-HDLNE = TEXT-010.
  ENDIF.
  IF NOT T159P-BACOD IS INITIAL.
    BELPOS-MBLNR = MKPF-MBLNR.
    BELPOS-ZEILE = MSEG-ZEILE.
    CONDENSE BELPOS NO-GAPS.
    AM07M-BELPOS = BELPOS.
    CALL FUNCTION 'WRITE_FORM'
         EXPORTING
              ELEMENT = 'WE2BACOKOPF'.
  ELSE.
    CALL FUNCTION 'WRITE_FORM'
         EXPORTING
              ELEMENT = 'WE2KOPF'.
  ENDIF.
  IF XPSTY       IS INITIAL.           "Lagermaterial ?
* User-Exit über Erweiterung MBCF0005
    CALL CUSTOMER-FUNCTION '001'
         EXPORTING
              I_MKPF  = MKPF
              I_MSEG  = MSEG
              I_EKKO  = EKKO
              I_EKPO  = EKPO
              I_NAST  = NAST
              I_TNAPR = TNAPR
         TABLES
              I_EKKN  = XEKKN
         CHANGING
              C_AM07M = AM07M
         EXCEPTIONS
              OTHERS  = 0.

    IF MSEG-XBLVS IS INITIAL.
       PERFORM W2_LAGERMATERIAL.             "Lagermaterial
    ELSE.
       PERFORM W2_LVSMATERIAL.               "LVS-Material
    ENDIF.
  ELSE.
    PERFORM W2_VERBRAUCHSMATERIAL.
  ENDIF.

  CALL FUNCTION 'END_FORM'.
  PERFORM MKTO_DRUCK.
ENDFORM.

*-------------- Lagermaterial WE-Version 2 ---------------------------*
FORM W2_LAGERMATERIAL.
  CALL FUNCTION 'WRITE_FORM'
       EXPORTING
            ELEMENT = 'WE2LGMAT'.
  IF T156-SHKZG = H AND
     NOT MSEG-GRUND IS INITIAL.
    SELECT SINGLE * FROM T157E WHERE BWART = MSEG-BWART
                               AND   GRUND = MSEG-GRUND
                               AND   SPRAS = LANGUAGE.
    CALL FUNCTION 'WRITE_FORM'
         EXPORTING
              ELEMENT = 'RUELGGRUND'.
  ENDIF.
  THEAD-TDID     = THEADER-TDID.
  THEAD-TDNAME   = THEADER-TDNAME.
  THEAD-TDOBJECT = THEADER-TDOBJECT.
  THEAD-TDSPRAS  = THEADER-TDSPRAS.
  CALL FUNCTION 'WRITE_FORM'
       EXPORTING
            ELEMENT = 'PRTXTLGMAT'.

ENDFORM.

*-------------- LVS-Daten     WE-Version 2 ---------------------------*
FORM W2_LVSMATERIAL.
  CALL FUNCTION 'WRITE_FORM'
       EXPORTING
            ELEMENT = 'W1LVSMAT'.
  IF T156-SHKZG = H AND
     NOT MSEG-GRUND IS INITIAL.
    SELECT SINGLE * FROM T157E WHERE BWART = MSEG-BWART
                               AND   GRUND = MSEG-GRUND
                               AND   SPRAS = LANGUAGE.
    CALL FUNCTION 'WRITE_FORM'
         EXPORTING
              ELEMENT = 'RUELVSGRUND'.
  ENDIF.
  THEAD-TDID     = THEADER-TDID.
  THEAD-TDNAME   = THEADER-TDNAME.
  THEAD-TDOBJECT = THEADER-TDOBJECT.
  THEAD-TDSPRAS  = THEADER-TDSPRAS.
  CALL FUNCTION 'WRITE_FORM'
       EXPORTING
            ELEMENT = 'PRTXTLVSMAT'.

ENDFORM.

*------------ Verbrauchsmaterial WE-Version 2 ----------------------*
FORM W2_VERBRAUCHSMATERIAL.
  CLEAR: AM07M-KOTXT, AM07M-KONTIERUNG.
  CASE XPSTY.
    WHEN XFERT.                        "Fertigungsauftrag
      AM07M-KOTXT = TEXT-062.
      IF X_KONT1 IS INITIAL.
        AM07M-KONTIERUNG = MSEG-AUFNR.
      ELSE.
        AM07M-KONTIERUNG = EKKN-AUFNR.
      ENDIF.
    WHEN XKDE.
      MOVE SPACE TO KUNDE.
      AM07M-KOTXT = TEXT-030.
      IF X_KONT1 IS INITIAL.
        KUNDE-KDAUF = MSEG-KDAUF.
        KUNDE-KDPOS = MSEG-KDPOS.
      ELSE.
        KUNDE-KDAUF = EKKN-VBELN.
        KUNDE-KDPOS = EKKN-VBELP.
      ENDIF.
      MOVE SPACE TO AM07M-KONTIERUNG.
      CONDENSE KUNDE NO-GAPS.
      AM07M-KONTIERUNG = KUNDE.
    WHEN XKDANR.
      MOVE SPACE TO KUNDE.
      AM07M-KOTXT = TEXT-030.
      IF X_KONT1 IS INITIAL.
        KUNDE-KDAUF = MSEG-KDAUF.
        KUNDE-KDPOS = MSEG-KDPOS.
        KUNDE-KDEIN = MSEG-KDEIN.
      ELSE.
        KUNDE-KDAUF = EKKN-VBELN.
        KUNDE-KDPOS = EKKN-VBELP.
        KUNDE-KDEIN = EKKN-VETEN.
      ENDIF.
      MOVE SPACE TO AM07M-KONTIERUNG.
      CONDENSE KUNDE NO-GAPS.
      AM07M-KONTIERUNG = KUNDE.
    WHEN XANLAGE.
      MOVE SPACE TO ANLAGE.
      AM07M-KOTXT = TEXT-040.
      IF X_KONT1 IS INITIAL.
        ANLAGE-ANLN1 = MSEG-ANLN1.
        ANLAGE-ANLN2 = MSEG-ANLN2.
      ELSE.
        ANLAGE-ANLN1 = EKKN-ANLN1.
        ANLAGE-ANLN2 = EKKN-ANLN2.
      ENDIF.
      MOVE SPACE TO AM07M-KONTIERUNG.
      CONDENSE ANLAGE NO-GAPS.
      AM07M-KONTIERUNG = ANLAGE.
    WHEN XKOSTL.
      AM07M-KOTXT = TEXT-050.
      IF X_KONT1 IS INITIAL.
        AM07M-KONTIERUNG = MSEG-KOSTL.
      ELSE.
        AM07M-KONTIERUNG = EKKN-KOSTL.
      ENDIF.

    WHEN XPROJN.
      IF X_KONT1 IS INITIAL.
        IF MSEG-NPLNR IS INITIAL.
          AM07M-KOTXT = TEXT-060.
          PERFORM PSP_CONVERT USING MSEG-PS_PSP_PNR.
        ELSE.
          AM07M-KOTXT = TEXT-061.
          AM07M-KONTIERUNG = MSEG-NPLNR.
          PERFORM NW_VORGANG_LESEN USING MSEG-AUFPL MSEG-APLZL.
          IF NOT N_VORNR IS INITIAL.
            MOVE '/'     TO AM07M-KONTIERUNG+12.
            MOVE N_VORNR TO AM07M-KONTIERUNG+13.
          ENDIF.
        ENDIF.
      ELSE.
        IF EKKN-NPLNR IS INITIAL.
          AM07M-KOTXT = TEXT-060.
          PERFORM PSP_CONVERT USING EKKN-PS_PSP_PNR.
        ELSE.
          AM07M-KOTXT = TEXT-061.
          AM07M-KONTIERUNG = EKKN-NPLNR.
          PERFORM NW_VORGANG_LESEN USING EKKN-AUFPL EKKN-APLZL.
          IF NOT N_VORNR IS INITIAL.
            MOVE '/'     TO AM07M-KONTIERUNG+12.
            MOVE N_VORNR TO AM07M-KONTIERUNG+13.
          ENDIF.
        ENDIF.
      ENDIF.
  ENDCASE.
  CLEAR X_KONT1.
* User-Exit über Erweiterung MBCF0005
  CALL CUSTOMER-FUNCTION '001'
       EXPORTING
            I_MKPF  = MKPF
            I_MSEG  = MSEG
            I_EKKO  = EKKO
            I_EKPO  = EKPO
            I_NAST  = NAST
            I_TNAPR = TNAPR
       TABLES
            I_EKKN  = XEKKN
       CHANGING
            C_AM07M = AM07M
       EXCEPTIONS
            OTHERS  = 0.

  CALL FUNCTION 'WRITE_FORM'
       EXPORTING
            ELEMENT = 'WE2VERBRMAT'.
  IF T156-SHKZG = H AND
    NOT MSEG-GRUND IS INITIAL.
    SELECT SINGLE * FROM T157E WHERE BWART = MSEG-BWART
                               AND   GRUND = MSEG-GRUND
                               AND   SPRAS = LANGUAGE.
    CALL FUNCTION 'WRITE_FORM'
         EXPORTING
              ELEMENT = 'RUEVERBRGRUND'.
  ENDIF.
  THEAD-TDID     = THEADER-TDID.
  THEAD-TDNAME   = THEADER-TDNAME.
  THEAD-TDOBJECT = THEADER-TDOBJECT.
  THEAD-TDSPRAS  = THEADER-TDSPRAS.
  CALL FUNCTION 'WRITE_FORM'
       EXPORTING
            ELEMENT = 'PRTXTVERBRMAT'.
ENDFORM.

INCLUDE /SMB40/M07DRE03.

 *---------------------------------------------------------------------*
*       FORM WE03_AUSGABE                                             *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM WE03_AUSGABE using lgortsplit.
*----------------Drucken WE-Version 3 Überschrift---------------------*
  if lgortsplit is initial.
     ON CHANGE OF MKPF-MBLNR OR MSEG-EBELN OR MSEG-BWART
                             OR NAST-KSCHL OR MSEG-WERKS.
     CLEAR XKOPFDR.
     endon.
  else.
     ON CHANGE OF MKPF-MBLNR OR MSEG-EBELN OR MSEG-BWART
                             OR NAST-KSCHL OR MSEG-WERKS
                             OR MSEG-LGORT.
     CLEAR XKOPFDR.
     endon.
  endif.
  IF XKOPFDR IS INITIAL.
    XKOPFDR = X.
    IF NEW_PAGE = X.
      CALL FUNCTION 'CONTROL_FORM'
           EXPORTING
                COMMAND = 'NEW-PAGE'.
    ENDIF.
    IF EKKO-BSART = 'UB'.
      AM07M-LITXT = TEXT-101.
      AM07M-LIBZG = EKKO-RESWK.
    ELSE.
      AM07M-LITXT = TEXT-100.
      AM07M-LIBZG = EKKO-LIFNR.
      IF NOT EKKO-LLIEF IS INITIAL.
        AM07M-LIBZ2 = EKKO-LLIEF.
      ELSE.
        AM07M-LIBZ2 = EKKO-LIFNR.
      ENDIF.
    ENDIF.
    IF T156-SHKZG = H.
      AM07M-HDLNE = TEXT-020.
    ELSE.
      AM07M-HDLNE = TEXT-010.
    ENDIF.
    IF XPSTY       IS INITIAL.         "Lagermaterial ?
      IF MSEG-XBLVS IS INITIAL.
        IF T156-SHKZG = H AND
           NOT MSEG-GRUND IS INITIAL.
          IF NOT T159P-BACOD IS INITIAL.
            CALL FUNCTION 'WRITE_FORM'
                 EXPORTING
                      ELEMENT = 'WE3BACOKOPF'
                      WINDOW  = 'RÜKOPF'.
            NEW_PAGE = X.
          ELSE.
            CALL FUNCTION 'WRITE_FORM'
                 EXPORTING
                      ELEMENT = 'WE3KOPF'
                      WINDOW  = 'RÜKOPF'.
            NEW_PAGE = X.
          ENDIF.
        ELSE.
          IF NOT T159P-BACOD IS INITIAL.
            CALL FUNCTION 'WRITE_FORM'
                 EXPORTING
                      ELEMENT = 'WE3BACOKOPF'
                      WINDOW  = 'KOPF'.
            NEW_PAGE = X.
          ELSE.
            CALL FUNCTION 'WRITE_FORM'
                 EXPORTING
                      ELEMENT = 'WE3KOPF'
                      WINDOW  = 'KOPF'.
            NEW_PAGE = X.
          ENDIF.
        ENDIF.
      ELSE.
        IF T156-SHKZG = H AND
           NOT MSEG-GRUND IS INITIAL.
          IF NOT T159P-BACOD IS INITIAL.
            CALL FUNCTION 'WRITE_FORM'
                 EXPORTING
                      ELEMENT = 'WE3BACOLVSKOPF'
                      WINDOW  = 'RÜKOPF'.
            NEW_PAGE = X.
          ELSE.
            CALL FUNCTION 'WRITE_FORM'
                 EXPORTING
                      ELEMENT = 'WE3LVSKOPF'  "RL-Material
                      WINDOW  = 'RÜKOPF'.
            NEW_PAGE = X.
          ENDIF.
        ELSE.
          IF NOT T159P-BACOD IS INITIAL.
            CALL FUNCTION 'WRITE_FORM'
                 EXPORTING
                      ELEMENT = 'WE3BACOLVSKOPF'
                      WINDOW  = 'KOPF'.
            NEW_PAGE = X.
          ELSE.
            CALL FUNCTION 'WRITE_FORM'
                 EXPORTING
                      ELEMENT = 'WE3LVSKOPF'  "RL-Material
                      WINDOW  = 'KOPF'.
            NEW_PAGE = X.
          ENDIF.
        ENDIF.
      ENDIF.
    ELSE.
      IF T156-SHKZG = H AND
         NOT MSEG-GRUND IS INITIAL.
        IF NOT T159P-BACOD IS INITIAL.
          CALL FUNCTION 'WRITE_FORM'
               EXPORTING
                    ELEMENT = 'WE3BACOKOPF1'
                    WINDOW  = 'RÜKOPF'.
          NEW_PAGE = X.
        ELSE.
          CALL FUNCTION 'WRITE_FORM'
               EXPORTING
                    ELEMENT = 'WE3KOPF1'
                    WINDOW  = 'RÜKOPF'.
          NEW_PAGE = X.
        ENDIF.
      ELSE.
        IF NOT T159P-BACOD IS INITIAL.
          CALL FUNCTION 'WRITE_FORM'
               EXPORTING
                    ELEMENT = 'WE3BACOKOPF1'
                    WINDOW  = 'KOPF'.
          NEW_PAGE = X.
        ELSE.
          CALL FUNCTION 'WRITE_FORM'
               EXPORTING
                    ELEMENT = 'WE3KOPF1'
                    WINDOW  = 'KOPF'.
          NEW_PAGE = X.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.
*------------- Drucken WE-Version 3 Position --------------------------*

**perform w3_lieferplan.                  "Routine Lieferplan
  CLEAR T157E.
  IF T156-SHKZG = H AND
     NOT MSEG-GRUND IS INITIAL.
    SELECT SINGLE * FROM T157E WHERE BWART = MSEG-BWART
                               AND   GRUND = MSEG-GRUND
                               AND   SPRAS = LANGUAGE.
  ENDIF.
  IF MSEG-EBELN IS INITIAL.
    IF NOT MABDR-MAKTX IS INITIAL.
      EKPO-TXZ01 = MABDR-MAKTX.
    ENDIF.
  ENDIF.
  IF MABDR-WERTU IS INITIAL AND
     MABDR-MENGU = X   OR              "Bestandsfuehrung = UNBW oder
     XPSTY       IS INITIAL.           "Lagermaterial ?
* User-Exit über Erweiterung MBCF0005
    CALL CUSTOMER-FUNCTION '001'
         EXPORTING
              I_MKPF  = MKPF
              I_MSEG  = MSEG
              I_EKKO  = EKKO
              I_EKPO  = EKPO
              I_NAST  = NAST
              I_TNAPR = TNAPR
         TABLES
              I_EKKN  = XEKKN
         CHANGING
              C_AM07M = AM07M
         EXCEPTIONS
              OTHERS  = 0.

    IF MSEG-XBLVS IS INITIAL.
      PERFORM W3_LAGERMATERIAL.        "Routine Lagermaterial
    ELSE.
      PERFORM W3_LVSMATERIAL.          "Routine RL-Material
    ENDIF.
  ELSE.
    PERFORM W3_VERBRAUCHSMATERIAL.     "Routine Verbrauchsmaterial
  ENDIF.

*-------------- Drucken WE-Version 3 Seitenfuss ----------------------*
  CALL FUNCTION 'WRITE_FORM'
       EXPORTING
            ELEMENT  = 'WE3FUSS'
            WINDOW   = 'FUSS'
            FUNCTION = 'APPEND'.
ENDFORM.

*--------------Unteroutinen für Positionsdruck -----------------------*
FORM W3_LAGERMATERIAL.
  CALL FUNCTION 'WRITE_FORM'
       EXPORTING
            ELEMENT = 'WE3LGMAT'.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM W3_LVSMATERIAL                                           *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM W3_LVSMATERIAL.
  CALL FUNCTION 'WRITE_FORM'
       EXPORTING
            ELEMENT = 'WE3LVSMAT'.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM W3_VERBRAUCHSMATERIAL                                    *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM W3_VERBRAUCHSMATERIAL.
  CLEAR: AM07M-KONTIERUNG.
  AM07M-RSTYP = XPSTY.
  CASE XPSTY.
    WHEN XFERT.                        "Fertigungsauftrag
      IF X_KONT1 IS INITIAL.
        AM07M-KONTIERUNG = MSEG-AUFNR.
      ELSE.
        AM07M-KONTIERUNG = EKKN-AUFNR.
      ENDIF.
    WHEN XANLAGE.
      MOVE SPACE TO ANLAGE.
      IF X_KONT1 IS INITIAL.
        ANLAGE-ANLN1 = MSEG-ANLN1.
        ANLAGE-ANLN2 = MSEG-ANLN2.
      ELSE.
        ANLAGE-ANLN1 = EKKN-ANLN1.
        ANLAGE-ANLN2 = EKKN-ANLN2.
      ENDIF.
      MOVE SPACE TO AM07M-KONTIERUNG.
      CONDENSE ANLAGE NO-GAPS.
      AM07M-KONTIERUNG = ANLAGE.

    WHEN   XKDE.                     "Kundeneinzelbestand?
      MOVE SPACE TO KUNDE.
      IF X_KONT1 IS INITIAL.
        KUNDE-KDAUF = MSEG-KDAUF.
        KUNDE-KDPOS = MSEG-KDPOS.
      ELSE.
        KUNDE-KDAUF = EKKN-VBELN.
        KUNDE-KDPOS = EKKN-VBELP.
      ENDIF.
      MOVE SPACE TO AM07M-KONTIERUNG.
      CONDENSE KUNDE NO-GAPS.
      AM07M-KONTIERUNG = KUNDE.

    WHEN   XKDANR.                     "Kundenauftrag ?
      MOVE SPACE TO KUNDE.
      IF X_KONT1 IS INITIAL.
        KUNDE-KDAUF = MSEG-KDAUF.
        KUNDE-KDPOS = MSEG-KDPOS.
        KUNDE-KDEIN = MSEG-KDEIN.
      ELSE.
        KUNDE-KDAUF = EKKN-VBELN.
        KUNDE-KDPOS = EKKN-VBELP.
        KUNDE-KDEIN = EKKN-VETEN.
      ENDIF.
      MOVE SPACE TO AM07M-KONTIERUNG.
      CONDENSE KUNDE NO-GAPS.
      AM07M-KONTIERUNG = KUNDE.

    WHEN   XKOSTL.                     "auf Kostenstelle kontiert
      IF X_KONT1 IS INITIAL.
        AM07M-KONTIERUNG = MSEG-KOSTL.
      ELSE.
        AM07M-KONTIERUNG = EKKN-KOSTL.
      ENDIF.

    WHEN   XPROJN.                     "auf Projekt/Netzplan
      IF X_KONT1 IS INITIAL.
        IF MSEG-NPLNR IS INITIAL.
          PERFORM PSP_CONVERT USING MSEG-PS_PSP_PNR.
        ELSE.
          AM07M-KONTIERUNG = MSEG-NPLNR.
          PERFORM NW_VORGANG_LESEN USING MSEG-AUFPL MSEG-APLZL.
          IF NOT N_VORNR IS INITIAL.
            MOVE '/'     TO AM07M-KONTIERUNG+12.
            MOVE N_VORNR TO AM07M-KONTIERUNG+13.
          ENDIF.
        ENDIF.
      ELSE.
        IF EKKN-NPLNR IS INITIAL.
          PERFORM PSP_CONVERT USING EKKN-PS_PSP_PNR.
        ELSE.
          AM07M-KONTIERUNG = EKKN-NPLNR.
          PERFORM NW_VORGANG_LESEN USING EKKN-AUFPL EKKN-APLZL.
          IF NOT N_VORNR IS INITIAL.
            MOVE '/'     TO AM07M-KONTIERUNG+12.
            MOVE N_VORNR TO AM07M-KONTIERUNG+13.
          ENDIF.
        ENDIF.
      ENDIF.
  ENDCASE.
  CLEAR X_KONT1.
* User-Exit über Erweiterung MBCF0005
  CALL CUSTOMER-FUNCTION '001'
       EXPORTING
            I_MKPF  = MKPF
            I_MSEG  = MSEG
            I_EKKO  = EKKO
            I_EKPO  = EKPO
            I_NAST  = NAST
            I_TNAPR = TNAPR
       TABLES
            I_EKKN  = XEKKN
       CHANGING
            C_AM07M = AM07M
       EXCEPTIONS
            OTHERS  = 0.

  CALL FUNCTION 'WRITE_FORM'
       EXPORTING
            ELEMENT = 'WE3VERBRMAT'.

ENDFORM.

INCLUDE /SMB40/M07DRA01.

 FORM WA01_DRUCK.
  CALL FUNCTION 'START_FORM'
       EXPORTING FORM = TNAPR-FONAM
             LANGUAGE = LANGUAGE.
    IF NOT T159P-BACOD IS INITIAL.
      BELPOS-MBLNR = MKPF-MBLNR.
      BELPOS-ZEILE = MSEG-ZEILE.
      CONDENSE BELPOS NO-GAPS.
      AM07M-BELPOS = BELPOS.
      CALL FUNCTION 'WRITE_FORM'
           EXPORTING ELEMENT = 'BACOKOPF'.
    ELSE.
      CALL FUNCTION 'WRITE_FORM'
           EXPORTING ELEMENT = 'KOPF'.
    ENDIF.
*------------- Drucken Belegposition ---------------------------------*
  CLEAR: AM07M-KOTXT, AM07M-KONTIERUNG.
  CASE XSKKZ.
    WHEN XFERT.                            "Fertigungsauftrag
      AM07M-KOTXT = TEXT-062.
      AM07M-KONTIERUNG = MSEG-AUFNR.
*   when xkdanr.
    WHEN XVBELG.
      MOVE SPACE TO KUNDE.
      AM07M-KOTXT = TEXT-030.
      KUNDE-KDAUF = MSEG-KDAUF.
      KUNDE-KDPOS = MSEG-KDPOS.
      KUNDE-KDEIN = MSEG-KDEIN.
      MOVE SPACE TO AM07M-KONTIERUNG.
      CONDENSE KUNDE NO-GAPS.
      AM07M-KONTIERUNG = KUNDE.
    WHEN XANLAGE.                            "Anlage
      MOVE SPACE TO ANLAGE.
      AM07M-KOTXT = TEXT-040.
      ANLAGE-ANLN1 = MSEG-ANLN1.
      ANLAGE-ANLN2 = MSEG-ANLN2.
      MOVE SPACE TO AM07M-KONTIERUNG.
      CONDENSE ANLAGE NO-GAPS.
      AM07M-KONTIERUNG = ANLAGE.
    WHEN XKOSTL.                             "Kostenstelle
      AM07M-KOTXT = TEXT-050.
      AM07M-KONTIERUNG = MSEG-KOSTL.
    WHEN XPROJN OR XNPLAN.                   "Projekt/Netzplan
      IF MSEG-NPLNR IS INITIAL.
        AM07M-KOTXT = TEXT-060.
        PERFORM PSP_CONVERT USING MSEG-PS_PSP_PNR.
      ELSE.
        AM07M-KOTXT = TEXT-061.
        AM07M-KONTIERUNG = MSEG-NPLNR.
        PERFORM NW_VORGANG_LESEN USING MSEG-AUFPL MSEG-APLZL.
        IF NOT N_VORNR IS INITIAL.
          MOVE '/'     TO AM07M-KONTIERUNG+12.
          MOVE N_VORNR TO AM07M-KONTIERUNG+13.
        ENDIF.
      ENDIF.
  ENDCASE.
* User-Exit über Erweiterung MBCF0005
  CALL CUSTOMER-FUNCTION '001'
       EXPORTING
            I_MKPF  = MKPF
            I_MSEG  = MSEG
            I_NAST  = NAST
            I_TNAPR = TNAPR
       CHANGING
            C_AM07M = AM07M
       EXCEPTIONS
            OTHERS  = 0.

  CALL FUNCTION 'WRITE_FORM'
       EXPORTING ELEMENT = 'POS_ZEILE'.

*--------------- Drucken Belegfuß -------------------------------------*
  PERFORM TAB156T_LESEN.

  CALL FUNCTION 'WRITE_FORM'
       EXPORTING ELEMENT  = 'FUSS'
                 WINDOW   = 'FUSS'
                 FUNCTION = 'APPEND'.

  CALL FUNCTION 'END_FORM'.

ENDFORM.

INCLUDE /SMB40/M07DRA02.

 FORM WA02_DRUCK.
  CALL FUNCTION 'START_FORM'
       EXPORTING FORM = TNAPR-FONAM
             LANGUAGE = LANGUAGE.
  ON CHANGE OF MSEG-MATNR.
    PERFORM PRUEFTEXT_LESEN.
  ENDON.
    IF NOT T159P-BACOD IS INITIAL.
      BELPOS-MBLNR = MKPF-MBLNR.
      BELPOS-ZEILE = MSEG-ZEILE.
      CONDENSE BELPOS NO-GAPS.
      AM07M-BELPOS = BELPOS.
      CALL FUNCTION 'WRITE_FORM'
           EXPORTING ELEMENT = 'BACOKOPF'.
    ELSE.
      CALL FUNCTION 'WRITE_FORM'
           EXPORTING ELEMENT = 'KOPF'.
    ENDIF.
*--------------- Drucken Belegposition --------------------------------*
  CLEAR: AM07M-KOTXT, AM07M-KONTIERUNG.
  CASE XSKKZ.
    WHEN XFERT.                            "Fertigungsauftrag
      AM07M-KOTXT = TEXT-062.
      AM07M-KONTIERUNG = MSEG-AUFNR.
*   when xkdanr.
    WHEN XVBELG.
      MOVE SPACE TO KUNDE.
      AM07M-KOTXT = TEXT-030.
      KUNDE-KDAUF = MSEG-KDAUF.
      KUNDE-KDPOS = MSEG-KDPOS.
      KUNDE-KDEIN = MSEG-KDEIN.
      MOVE SPACE TO AM07M-KONTIERUNG.
      CONDENSE KUNDE NO-GAPS.
      AM07M-KONTIERUNG = KUNDE.
    WHEN XANLAGE.
      MOVE SPACE TO ANLAGE.
      AM07M-KOTXT = TEXT-040.
      ANLAGE-ANLN1 = MSEG-ANLN1.
      ANLAGE-ANLN2 = MSEG-ANLN2.
      MOVE SPACE TO AM07M-KONTIERUNG.
      CONDENSE ANLAGE NO-GAPS.
      AM07M-KONTIERUNG = ANLAGE.
    WHEN XKOSTL.
      AM07M-KOTXT = TEXT-050.
      AM07M-KONTIERUNG = MSEG-KOSTL.
    WHEN XPROJN OR XNPLAN.
      IF MSEG-NPLNR IS INITIAL.
        AM07M-KOTXT = TEXT-060.
        PERFORM PSP_CONVERT USING MSEG-PS_PSP_PNR.
      ELSE.
        AM07M-KOTXT = TEXT-061.
        AM07M-KONTIERUNG = MSEG-NPLNR.
        PERFORM NW_VORGANG_LESEN USING MSEG-AUFPL MSEG-APLZL.
        IF NOT N_VORNR IS INITIAL.
          MOVE '/'     TO AM07M-KONTIERUNG+12.
          MOVE N_VORNR TO AM07M-KONTIERUNG+13.
        ENDIF.
      ENDIF.
  ENDCASE.
* User-Exit über Erweiterung MBCF0005
  CALL CUSTOMER-FUNCTION '001'
       EXPORTING
            I_MKPF  = MKPF
            I_MSEG  = MSEG
            I_NAST  = NAST
            I_TNAPR = TNAPR
       CHANGING
            C_AM07M = AM07M
       EXCEPTIONS
            OTHERS  = 0.

  CALL FUNCTION 'WRITE_FORM'
       EXPORTING ELEMENT = 'POS_ZEILE'.
  IF EINTRAEGE > 0.
    THEAD-TDID     = THEADER-TDID.
    THEAD-TDNAME   = THEADER-TDNAME.
    THEAD-TDOBJECT = THEADER-TDOBJECT.
    THEAD-TDSPRAS  = THEADER-TDSPRAS.
    CALL FUNCTION 'WRITE_FORM'
         EXPORTING ELEMENT = 'PRTXTLGMAT'.
  ENDIF.

*------------------ Drucken Fußzeile ---------------------------------*
  PERFORM TAB156T_LESEN.

  CALL FUNCTION 'WRITE_FORM'
       EXPORTING ELEMENT  = 'FUSS'
                  WINDOW  = 'FUSS'
                 FUNCTION = 'APPEND'.

  CALL FUNCTION 'END_FORM'.

ENDFORM.

INCLUDE /SMB40/M07DRA03.

FORM WA03_AUSGABE using lgortsplit.
   if LGORTSPLIT is initial.
     ON CHANGE OF MKPF-MBLNR OR MSEG-EBELN OR MSEG-BWART OR MSEG-WERKS.
        CLEAR XKOPFDR.
     ENDON.
   else.
     ON CHANGE OF MKPF-MBLNR OR MSEG-EBELN OR MSEG-BWART OR MSEG-WERKS
                             OR MSEG-LGORT.
        CLEAR XKOPFDR.
     ENDON.
   endif.
   IF XKOPFDR IS INITIAL.
     XKOPFDR = X.
     IF NEW_PAGE = X.
        CALL FUNCTION 'CONTROL_FORM'
             EXPORTING COMMAND = 'NEW-PAGE'.
     ENDIF.
     IF NOT T159P-BACOD IS INITIAL.
       CALL FUNCTION 'WRITE_FORM'
            EXPORTING ELEMENT = 'BACOKOPF'
            WINDOW            = 'KOPF'.
       NEW_PAGE = X.
     ELSE.
       CALL FUNCTION 'WRITE_FORM'
            EXPORTING ELEMENT = 'KOPF'
            WINDOW            = 'KOPF'.
       NEW_PAGE = X.
     ENDIF.
   ENDIF.
*--------------Drucken WA-Positionen-----------------------------------*
  CLEAR: AM07M-KONTIERUNG.
  AM07M-RSTYP = XSKKZ.
  CASE XSKKZ.                               "Kontierungsarten ?
     WHEN XFERT.                            "Fertigungsauftrag
       AM07M-KONTIERUNG = MSEG-AUFNR.
     WHEN XANLAGE.                          "auf Anlage kontiert?
       MOVE SPACE TO ANLAGE.
       ANLAGE-ANLN1 = MSEG-ANLN1.
       ANLAGE-ANLN2 = MSEG-ANLN2.
       MOVE SPACE TO AM07M-KONTIERUNG.
       CONDENSE ANLAGE NO-GAPS.
       AM07M-KONTIERUNG = ANLAGE.          "Anlagennummer
      WHEN   XVBELG.                       "Kundenauftrag ?
         MOVE SPACE TO KUNDE.
         KUNDE-KDAUF = MSEG-KDAUF.
         KUNDE-KDPOS = MSEG-KDPOS.
         KUNDE-KDEIN = MSEG-KDEIN.
         MOVE SPACE TO AM07M-KONTIERUNG.
         CONDENSE KUNDE NO-GAPS.
         AM07M-KONTIERUNG = KUNDE.           "Kundennummer
      WHEN   XKOSTL.                        "auf Kostenstelle kontiert?
        AM07M-KONTIERUNG = MSEG-KOSTL.      "Anlagennummer
      WHEN   XPROJN OR XNPLAN.              "auf Projekt/Netzplan?
        IF MSEG-NPLNR IS INITIAL.
          PERFORM PSP_CONVERT USING MSEG-PS_PSP_PNR.
        ELSE.
          AM07M-KONTIERUNG = MSEG-NPLNR.
          PERFORM NW_VORGANG_LESEN USING MSEG-AUFPL MSEG-APLZL.
          IF NOT N_VORNR IS INITIAL.
            MOVE '/'     TO AM07M-KONTIERUNG+12.
            MOVE N_VORNR TO AM07M-KONTIERUNG+13.
          ENDIF.
        ENDIF.
      WHEN XUMLAG.                         "Umlagerung
        IF MSEG-MATNR NE MSEG-UMMAT.
          MOVE MSEG-UMMAT TO AM07M-KONTIERUNG.
        ELSE.
          MOVE MSEG-UMWRK TO AM07M-KONTIERUNG.
          MOVE '/'        TO AM07M-KONTIERUNG+4.
          MOVE MSEG-UMLGO TO AM07M-KONTIERUNG+5.
        ENDIF.
      WHEN OTHERS.                          "keine Kontierung ?
        IF NOT MSEG-UMMAT IS INITIAL.
          IF MSEG-MATNR NE MSEG-UMMAT.
            MOVE MSEG-UMMAT TO AM07M-KONTIERUNG.
          ELSEIF MSEG-WERKS NE MSEG-UMWRK.
            MOVE MSEG-UMWRK TO AM07M-KONTIERUNG.
            MOVE '/'        TO AM07M-KONTIERUNG+4.
            MOVE MSEG-UMLGO TO AM07M-KONTIERUNG+5.
          ELSEIF MSEG-LGORT NE MSEG-UMLGO.
            MOVE MSEG-UMWRK TO AM07M-KONTIERUNG.
            MOVE '/'        TO AM07M-KONTIERUNG+4.
            MOVE MSEG-UMLGO TO AM07M-KONTIERUNG+5.
          ENDIF.
        ENDIF.
  ENDCASE.

* User-Exit über Erweiterung MBCF0005
  CALL CUSTOMER-FUNCTION '001'
       EXPORTING
            I_MKPF  = MKPF
            I_MSEG  = MSEG
            I_NAST  = NAST
            I_TNAPR = TNAPR
       CHANGING
            C_AM07M = AM07M
       EXCEPTIONS
            OTHERS  = 0.

  CALL FUNCTION 'WRITE_FORM'
       EXPORTING ELEMENT = 'POS_ZEILE'.



*--------------Drucken WA-Seitenfuss-----------------------------------*

  PERFORM TAB156T_LESEN.
    CALL FUNCTION 'WRITE_FORM'
       EXPORTING ELEMENT = 'FUSS'
            WINDOW       = 'FUSS'
            FUNCTION     = 'APPEND'.

ENDFORM.

INCLUDE /SMB40/M07DRLB3.

 *--------------Drucken WA-Ueberschrift---------------------------------*
FORM LB03_AUSGABE.
     ON CHANGE OF MKPF-MBLNR OR MSEG-EBELN OR MSEG-BWART OR MSEG-LIFNR.
       CLEAR XKOPFDR.
     ENDON.
     IF XKOPFDR IS INITIAL.
       XKOPFDR = X.
       IF NEW_PAGE = X.
          CALL FUNCTION 'CONTROL_FORM'
               EXPORTING COMMAND = 'NEW-PAGE'.
       ENDIF.

       IF NOT T159P-BACOD IS INITIAL.
         CALL FUNCTION 'WRITE_FORM'
              EXPORTING ELEMENT = 'BACOKOPF'
              WINDOW            = 'KOPF'.
         NEW_PAGE = X.
       ELSE.
         CALL FUNCTION 'WRITE_FORM'
              EXPORTING ELEMENT = 'KOPF'
              WINDOW            = 'KOPF'.
         NEW_PAGE = X.
       ENDIF.
     ENDIF.
*--------------Drucken WA-Positionen-----------------------------------*

  CASE XSKKZ.                               "Kontierungsarten ?

      WHEN   XANLN1.                        "auf Anlage kontiert?
         MOVE SPACE TO ANLAGE.
         ANLAGE-ANLN1 = MSEG-ANLN1.
         ANLAGE-ANLN2 = MSEG-ANLN2.
         MOVE SPACE TO AM07M-KONTIERUNG.
         CONDENSE ANLAGE NO-GAPS.
         AM07M-KONTIERUNG = ANLAGE.          "Anlagennummer
         AM07M-RSTYP      = XSKKZ.           "Kontierungskennzeichen

      WHEN   XRVKDANR.                       "Kundenauftrag ?
         MOVE SPACE TO KUNDE.
         KUNDE-KDAUF = MSEG-KDAUF.
         KUNDE-KDPOS = MSEG-KDPOS.
         KUNDE-KDEIN = MSEG-KDEIN.
         MOVE SPACE TO AM07M-KONTIERUNG.
         CONDENSE KUNDE NO-GAPS.
         AM07M-KONTIERUNG = KUNDE.           "Kundennummer
         AM07M-RSTYP      = XSKKZ.           "Kontierungskennzeichen

      WHEN   XKOSTL.                        "auf Kostenstelle kontiert?
        AM07M-KONTIERUNG = MSEG-KOSTL.      "Anlagennummer
        AM07M-RSTYP      = XSKKZ.           "Kontierungskennzeichen

      WHEN   XPROJN.                        "auf Projekt/Netzplan?
        AM07M-RSTYP      = XSKKZ.           "Kontierungskennzeichen
        IF MSEG-NPLNR IS INITIAL.
          PERFORM PSP_CONVERT USING MSEG-PS_PSP_PNR.
        ELSE.
          AM07M-KONTIERUNG = MSEG-NPLNR.
          PERFORM NW_VORGANG_LESEN USING MSEG-AUFPL MSEG-APLZL.
          IF NOT N_VORNR IS INITIAL.
            MOVE '/'     TO AM07M-KONTIERUNG+12.
            MOVE N_VORNR TO AM07M-KONTIERUNG+13.
          ENDIF.
        ENDIF.
      WHEN OTHERS.                          "keine Kontierung ?
        CLEAR AM07M-KONTIERUNG.             "löschen Ausgabefelder für
        CLEAR AM07M-RSTYP.                  "Kontierung

  ENDCASE.

  CALL FUNCTION 'WRITE_FORM'
       EXPORTING ELEMENT = 'POS_ZEILE'.



*--------------Drucken WA-Seitenfuss-----------------------------------*

  PERFORM TAB156T_LESEN.
    CALL FUNCTION 'WRITE_FORM'
       EXPORTING ELEMENT = 'FUSS'
            WINDOW       = 'FUSS'
            FUNCTION     = 'APPEND'.

ENDFORM.
 

INCLUDE /SMB40/M07DRETI.

 
FORM ETI_DRUCK.

  DATA: ENDFORM TYPE C.
  DATA: NULLDREI(3) TYPE N VALUE 000.
  DATA: RC_T159O LIKE SY-SUBRC.
  FIELD-SYMBOLS: <F>.

  SELECT SINGLE * FROM T159O WHERE TDOBJECT = TNAPR-FONAM.
  IF NOT SY-SUBRC IS INITIAL OR T159O-TDID IS INITIAL
                             OR T159O-TDNAME IS INITIAL
                             OR T159O-TDFORM IS INITIAL.
    RC_T159O = 4.
  ENDIF.
  IF NOT RC_T159O IS INITIAL AND SY-TCODE = 'MB90'.
    MESSAGE I811.
  ENDIF.
  CHECK RC_T159O IS INITIAL.

  PERFORM ETIKETTENTEXT_LESEN.

  IF ENDFORM IS INITIAL.
    CALL FUNCTION 'START_FORM'
         EXPORTING FORM = T159O-TDFORM.
    ENDFORM = X.
    OLD_TDFORM = T159O-TDFORM.
  ELSE.
    IF OLD_TDFORM NE T159O-TDFORM.
      CALL FUNCTION 'END_FORM'.
      CALL FUNCTION 'START_FORM'
           EXPORTING FORM = T159O-TDFORM.
      OLD_TDFORM = T159O-TDFORM.
    ENDIF.
  ENDIF.
  SELECT * FROM T159E WHERE ETIFO = MABDR-ETIFO
                      AND   ETIAR = MABDR-ETIAR.
  ASSIGN (T159E-FELDN) TO <F>.
  IF <F> NE NULLDREI.
  ANZAHL1 = <F> - 1.
    DO ANZAHL1 TIMES.
      PERFORM WRITE_LINES.
    ENDDO.
      PERFORM WRITE_LAST.
  ENDIF.
  ENDSELECT.
  CALL FUNCTION 'END_FORM'.
ENDFORM.

*---------------- Formroutinen für Etikettendruck ---------------------*
 FORM WRITE_LINES.
   CALL FUNCTION 'WRITE_FORM'
        EXPORTING ELEMENT = 'ETIKETT'.
   CALL FUNCTION 'CONTROL_FORM'
        EXPORTING COMMAND = 'NEW-WINDOW'.
 ENDFORM.

 FORM WRITE_LAST.
   CALL FUNCTION 'WRITE_FORM'
        EXPORTING ELEMENT = 'ETIKETT'.
 ENDFORM.

 FORM ETIKETTENTEXT_LESEN.
   CLEAR DPTEXT.
   CLEAR THEADER.
   REFRESH DPTEXT.
   THEADER-TDID             = T159O-TDID.
   THEADER-TDSPRAS          = LANGUAGE.
   THEADER-TDNAME           = T159O-TDNAME.
   THEADER-TDOBJECT         = T159O-TDOBJECT.
   CALL FUNCTION 'SELECT_TEXT'
        EXPORTING ID         = THEADER-TDID
                  LANGUAGE   = THEADER-TDSPRAS
                  NAME       = THEADER-TDNAME
                  OBJECT     = THEADER-TDOBJECT
       IMPORTING  ENTRIES    = EINTRAEGE
       TABLES     SELECTIONS = DPTEXT .

   THEAD-TDID     = THEADER-TDID.
   THEAD-TDNAME   = THEADER-TDNAME.
   THEAD-TDOBJECT = THEADER-TDOBJECT.
   THEAD-TDSPRAS  = THEADER-TDSPRAS.

 ENDFORM.

INCLUDE /SMB40/M07DRKTO.

 
FORM mkto_druck.
   DATA: zekkn LIKE ekkn.
   CHECK not x_kont is initial.
   t001w-werks = r_werks.
   t001w-name1 = r_name1.
   SELECT SINGLE * FROM t159n WHERE repid = 'M07DRKTO'
                              AND   wever = space
                              AND   vgart = space
                              AND   kzdru = space
                              AND   xguel = x.
   IF sy-subrc is initial.
     CALL FUNCTION 'START_FORM'
          EXPORTING form = t159n-tdform.
   ELSE.
     CALL FUNCTION 'START_FORM'
          EXPORTING form = 'MB_MFKTO'.
   ENDIF.
   IF ekko-bsart = 'UB'.
     am07m-litxt = text-101.
     am07m-libzg = ekko-reswk.
   ELSE.
     am07m-litxt = text-100.
     am07m-libzg = ekko-lifnr.
     IF not ekko-llief is initial.
       am07m-libz2 = ekko-llief.
     ELSE.
       am07m-libz2 = ekko-lifnr.
     ENDIF.
   ENDIF.
   am07m-hdlne = text-110.
   belpos-mblnr = mkpf-mblnr.
   belpos-zeile = mseg-zeile.
   CONDENSE belpos NO-GAPS.
   am07m-belpos = belpos.
   IF not t159p-bacod is initial.
     CALL FUNCTION 'WRITE_FORM'
          EXPORTING element = 'W1BACOKOPF'.
   ELSE.
      CALL FUNCTION 'WRITE_FORM'
          EXPORTING element = 'W1KOPF'.
   ENDIF.
   LOOP AT xekkn.
     MOVE-CORRESPONDING xekkn TO zekkn.
     MOVE-CORRESPONDING xekkn TO ekkn.
     CLEAR: am07m-kontierung.
     am07m-rstyp = xpsty.
     CASE xpsty.
       WHEN   xanlage.                      "auf Anlage kontiert?
         MOVE space TO anlage.
         anlage-anln1 = ekkn-anln1.
         anlage-anln2 = ekkn-anln2.
         MOVE space TO am07m-kontierung.
         CONDENSE anlage NO-GAPS.
         am07m-kontierung = anlage.

*      Kundenauftrag

       WHEN   xkostl.                       "auf Kostenstelle kontiert
        am07m-kontierung = ekkn-kostl.      "Kostenstelle

       WHEN   xprojn.                       "auf Projekt kontiert
        IF ekkn-nplnr is initial.
          PERFORM psp_convert USING ekkn-ps_psp_pnr.
        ELSE.
          am07m-kontierung = ekkn-nplnr.    "Netzplannummer
          PERFORM nw_vorgang_lesen USING ekkn-aufpl ekkn-aplzl.
          IF not n_vornr is initial.
            MOVE '/'     TO am07m-kontierung+12.
            MOVE n_vornr TO am07m-kontierung+13.
          ENDIF.
        ENDIF.
       WHEN   xfert.
        am07m-kontierung = ekkn-aufnr.
     ENDCASE.

     CALL FUNCTION 'EXIT_SAPM07DR_002'
         EXPORTING
             i_mkpf  = mkpf
             i_mseg  = mseg
             i_ekko  = ekko
             i_ekpo  = ekpo
             i_nast  = nast
             i_tnapr = tnapr
             i_ekkn  = zekkn
         CHANGING
             c_am07m = am07m.

     CALL FUNCTION 'WRITE_FORM'
          EXPORTING element = 'KONTIERUNG'.
   ENDLOOP.
   CLEAR xekkn.
   REFRESH xekkn.
   CLEAR x_kont.
   CALL FUNCTION 'END_FORM'.
ENDFORM.

INCLUDE /SMB40/M07DRENT.

 *----------------------------------------------------------------------*
*----------- Wareneingangsschein Version 1 ----------------------------*
FORM entry_we01 USING ent_retco ent_screen.
  xscreen = ent_screen.
  CLEAR ent_retco.
  PERFORM lesen USING nast-objky.
  ent_retco = retco.
  PERFORM ausgabe_we01.
ENDFORM.                                                    "entry_we01
*----------- Wareneingangsschein Version 2 ----------------------------*
FORM entry_we02 USING ent_retco ent_screen.
  xscreen = ent_screen.
  CLEAR ent_retco.
  PERFORM lesen USING nast-objky.
  ent_retco = retco.
  PERFORM bestellkopf_lesen.
  PERFORM ausgabe_we02.
ENDFORM.                                                    "entry_we02
*----------- Wareneingangsschein Version 3 ----------------------------*
FORM entry_we03 USING ent_retco ent_screen.

  xscreen = ent_screen.
  CLEAR ent_retco.
  CLEAR lgortsplit.
  PERFORM lesen USING nast-objky.
  ent_retco = retco.
  PERFORM print_smartform..
  ent_retco = retco.
ENDFORM.                                                    "entry_we03
*----------- Wareneingangsschein Version 3 mit Lagerortsplitt ---------*
FORM entry_we03l USING ent_retco ent_screen.
  xscreen = ent_screen.
  CLEAR ent_retco.
  lgortsplit = 'X'.
  PERFORM lesen_wes USING nast-objky lgortsplit.
  ent_retco = retco.
ENDFORM.                    "entry_we03l
*----------- Kanbankarte bei WE ---------------------------------------*
FORM entry_wek1 USING ent_retco ent_screen.
  xscreen = ent_screen.
  CLEAR ent_retco.
  PERFORM lesen USING nast-objky.
  PERFORM ausgabe_wek1.
ENDFORM.                                                    "entry_wek1
*----------------------------------------------------------------------*
*--------------- Warenausgangsscheine ---------------------------------*
*----------------------------------------------------------------------*
*---------------- Warenausgangsschein Version 1 -----------------------*
FORM entry_wa01 USING ent_retco ent_screen.
  xscreen = ent_screen.
  CLEAR ent_retco.
  PERFORM lesen_wa USING nast-objky.
  ent_retco = retco.
  PERFORM ausgabe_we01.
ENDFORM.                                                    "entry_wa01
*---------------- Warenausgangsschein Version 2 -----------------------*
FORM entry_wa02 USING ent_retco ent_screen.
  xscreen = ent_screen.
  CLEAR ent_retco.
  PERFORM lesen_wa USING nast-objky.
  ent_retco = retco.
  PERFORM ausgabe_we02.
ENDFORM.                                                    "entry_wa02
*---------------- Warenausgangsschein Version 3 -----------------------*
FORM entry_wa03 USING ent_retco ent_screen.
  xscreen = ent_screen.
  CLEAR ent_retco.
  CLEAR lgortsplit.
  PERFORM lesen_was USING nast-objky lgortsplit.
  ent_retco = retco.
  PERFORM print_smartform..
ENDFORM.                                                    "entry_wa03
*---------------- Warenausgangsschein Version 3 mit Lagerortsplit------*
FORM entry_wa03l USING ent_retco ent_screen.
  xscreen = ent_screen.
  CLEAR ent_retco.
  lgortsplit = 'X'.
  PERFORM lesen_was USING nast-objky lgortsplit.
  ent_retco = retco.
ENDFORM.                    "entry_wa03l
*----------------------------------------------------------------------*
*--------------- Etikettendruck beim Warenausgang ---------------------*
*----------------------------------------------------------------------*
FORM entry_etia USING ent_retco ent_screen.
  xscreen = ent_screen.
  CLEAR ent_retco.
  PERFORM lesen_wa USING nast-objky.
  ent_retco = retco.
  PERFORM ausgabe_eti.
ENDFORM.                    "entry_etia
*----------------------------------------------------------------------*
*---------- Etikettendruck beim Wareneingang --------------------------*
*----------------------------------------------------------------------*
FORM entry_etie USING ent_retco ent_screen.
  xscreen = ent_screen.
  CLEAR ent_retco.
  PERFORM lesen USING nast-objky.
  ent_retco = retco.
  PERFORM bestellkopf_lesen.
  PERFORM ausgabe_eti.
ENDFORM.                    "entry_etie
*----------------------------------------------------------------------*
*------ Etikettendruck beim Wareneingang Version 3 --------------------*
*----------------------------------------------------------------------*
FORM entry_eties USING ent_retco ent_screen.
  xscreen = ent_screen.
  CLEAR ent_retco.
  PERFORM lesen_wese USING nast-objky.
  ent_retco = retco.
ENDFORM.                    "entry_eties
*----------------------------------------------------------------------*
*----- Etikettendruck beim Warenausgang Version 3 ---------------------*
*----------------------------------------------------------------------*
FORM entry_etias USING ent_retco ent_screen.
  xscreen = ent_screen.
  CLEAR ent_retco.
  PERFORM lesen_wase USING nast-objky.
  ent_retco = retco.
ENDFORM.                    "entry_etias
*----------------------------------------------------------------------*
*--------------- Warenausgangsscheine ---------------------------------*
*----------------------------------------------------------------------*
*------ Warenausgangsschein Lohnbearbeiter Vers1. ---------------------*
FORM entry_wlb1 USING ent_retco ent_screen.
  xscreen = ent_screen.
  CLEAR ent_retco.
  PERFORM lesen_wlb USING nast-objky.
  ent_retco = retco.
  PERFORM ausgabe_wlb1.
ENDFORM.                                                    "entry_wlb1
*----------------------------------------------------------------------*
*--------------- Warenausgangsscheine ---------------------------------*
*----------------------------------------------------------------------*
*------ Warenausgangsschein Lohnbearbeiter Vers2. ---------------------*
FORM entry_wlb2 USING ent_retco ent_screen.
  xscreen = ent_screen.
  CLEAR ent_retco.
  PERFORM lesen_wlb USING nast-objky.
  ent_retco = retco.
  PERFORM ausgabe_wlb2.
ENDFORM.                                                    "entry_wlb2
*eject
*------------- Warenausgangsschein LB Version 3 -----------------------*
FORM entry_wlb3 USING ent_retco ent_screen.
  xscreen = ent_screen.
  CLEAR ent_retco.
  PERFORM lesen_wlbs USING nast-objky.
  ent_retco = retco.
ENDFORM.                                                    "entry_wlb3
*------- Wareneingangsscheine für Fertigungsaufträge ------------------*
*----------------------------------------------------------------------*
*----------- Wareneingangsschein Version 1 ----------------------------*
FORM entry_wf01 USING ent_retco ent_screen.
  xscreen = ent_screen.
  CLEAR ent_retco.
  PERFORM lesen_wf USING nast-objky.
  ent_retco = retco.
  PERFORM ausgabe_wf01.
ENDFORM.                                                    "entry_wf01
*----------- Wareneingangsschein Version 2 ----------------------------*
FORM entry_wf02 USING ent_retco ent_screen.
  xscreen = ent_screen.
  CLEAR ent_retco.
  PERFORM lesen_wf USING nast-objky.
  ent_retco = retco.
  PERFORM bestellkopf_lesen.
  PERFORM ausgabe_wf02.
ENDFORM.                                                    "entry_wf02
*eject
 


INCLUDE /SMB40/M07DRLOB.

 
FORM READ_ADDRESS.
  SELECT SINGLE * FROM LFA1 WHERE LIFNR = MSEG-LIFNR.
ENDFORM.


INCLUDE /SMB40/M07DRAUS.


*------------- Wareneingangsschein Version 1 --------------------------*
FORM ausgabe_we01.
  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.

  PERFORM lesen_t159p.
  PERFORM itcpo_fuellen.
  IF NOT t159p-xmehr IS INITIAL.
    IF mseg-weanz GT 0.
      anzahl = mseg-weanz.
    ELSE.
      anzahl = 1.
    ENDIF.
  ELSE.
    anzahl = 1.
  ENDIF.
  PERFORM set_print_param USING      ls_addr_key
                            CHANGING ls_control_param
                                     ls_composer_param
                                     ls_recipient
                                     ls_sender
                                     retco.

*Get the Smart Form name.
  IF NOT tnapr-sform IS INITIAL.
    lf_formname = tnapr-sform.
  ELSE.
    MESSAGE e001(/smb40/ssfcomposer).
  ENDIF.

* determine smartform function module for invoice
  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
       EXPORTING  formname           = lf_formname
*                 variant            = ' '
*                 direct_call        = ' '
       IMPORTING  fm_name            = lf_fm_name
       EXCEPTIONS no_form            = 1
                  no_function_module = 2
                  OTHERS             = 3.
  IF sy-subrc <> 0.
*   error handling
    retco = sy-subrc.
    IF sy-subrc = 1.
      MESSAGE e001(/smb40/ssfcomposer).
    ENDIF.
    IF sy-subrc = 2.
      MESSAGE e002(/smb40/ssfcomposer).
    ENDIF.
    PERFORM protocol_update_i.
  ENDIF.
  DO anzahl TIMES.
    CALL FUNCTION lf_fm_name
      EXPORTING
         archive_index              = toa_dara
*   ARCHIVE_INDEX_TAB          =
         archive_parameters         = arc_params
         control_parameters         = ls_control_param
*   MAIL_APPL_OBJ              =
         mail_recipient             = ls_recipient
         mail_sender                = ls_sender
         output_options             = ls_composer_param
         user_settings              = ' '
         mseg                       = mseg
         ekpo                       = ekpo
         t157e                      = t157e
         am07m                      = am07m
         mkpf                       = mkpf
         nast                       = nast
         t159p                      =  t159p
         t001w                      = t001w
         ekko                       = ekko
         t024                       = t024
* IMPORTING
*   DOCUMENT_OUTPUT_INFO       =
*   JOB_OUTPUT_INFO            =
*   JOB_OUTPUT_OPTIONS         =
 EXCEPTIONS
   formatting_error           = 1
   internal_error             = 2
   send_error                 = 3
   user_canceled              = 4
   OTHERS                     = 5
              .
    IF sy-subrc <> 0.
      retco = sy-subrc.
      PERFORM protocol_update_i.
* get SmartForm protocoll and store it in the NAST protocoll
      PERFORM add_smfrm_prot.

    ENDIF.
  ENDDO.
ENDFORM.                    "ausgabe_we01
*eject.
*------------- Wareneingangsschein Version 2 --------------------------*
FORM ausgabe_we02.
*smartform input parameters
  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.
  PERFORM lesen_t159p.
  PERFORM itcpo_fuellen.
  IF NOT t159p-xmehr IS INITIAL.
    IF mseg-weanz GT 0.
      anzahl = mseg-weanz.
    ELSE.
      anzahl = 1.
    ENDIF.
  ELSE.
    anzahl = 1.
  ENDIF.
  PERFORM set_print_param USING      ls_addr_key
                          CHANGING ls_control_param
                                   ls_composer_param
                                   ls_recipient
                                   ls_sender
                                   retco.

*Get the Smart Form name.
  IF NOT tnapr-sform IS INITIAL.
    lf_formname = tnapr-sform.
  ELSE.
    MESSAGE e001(/smb40/ssfcomposer).
  ENDIF.

* determine smartform function module for invoice
  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
       EXPORTING  formname           = lf_formname
*                 variant            = ' '
*                 direct_call        = ' '
       IMPORTING  fm_name            = lf_fm_name
       EXCEPTIONS no_form            = 1
                  no_function_module = 2
                  OTHERS             = 3.
  IF sy-subrc <> 0.
*   error handling
    retco = sy-subrc.
    IF sy-subrc = 1.
      MESSAGE e001(/smb40/ssfcomposer).
    ENDIF.
    IF sy-subrc = 2.
      MESSAGE e002(/smb40/ssfcomposer).
    ENDIF.
    PERFORM protocol_update_i.
  ENDIF.

  DO anzahl TIMES.
    CALL FUNCTION lf_fm_name
      EXPORTING
         archive_index              = toa_dara
*   ARCHIVE_INDEX_TAB          =
         archive_parameters         = arc_params
         control_parameters         = ls_control_param
*   MAIL_APPL_OBJ              =
         mail_recipient             = ls_recipient
         mail_sender                = ls_sender
         output_options             = ls_composer_param
         user_settings              = ' '
         mseg                       = mseg
         ekpo                       = ekpo
         t157e                      = t157e
         am07m                      = am07m
         mkpf                       = mkpf
         nast                       = nast
         t159p                      =  t159p
         t001w                      = t001w
         ekko                       = ekko
         t024                       = t024
   EXCEPTIONS
     formatting_error           = 1
     internal_error             = 2
     send_error                 = 3
     user_canceled              = 4
     OTHERS                     = 5
              .
    IF sy-subrc <> 0.
      retco = sy-subrc.
      PERFORM protocol_update_i.
* get SmartForm protocoll and store it in the NAST protocoll
      PERFORM add_smfrm_prot.
    ENDIF.
  ENDDO.
ENDFORM.                    "ausgabe_we02
*------------- Kanbankarte bei WE -------------------------------------*
FORM ausgabe_wek1.
  TABLES pkps.
  IF NOT mseg-aufnr IS INITIAL.
    pkps-aufnr = mseg-aufnr.
  ELSEIF NOT mseg-ebeln IS INITIAL.
    pkps-ebeln = mseg-ebeln.
    pkps-ebelp = mseg-ebelp.
  ELSEIF NOT mseg-rsnum IS INITIAL.
    pkps-rsnum = mseg-rsnum.
  ENDIF.
  PERFORM itcpo_fuellen.
  CALL FUNCTION 'PK_PRINT_KANBAN_GR'
    EXPORTING
      ipkps   = pkps
      iitcpo  = itcpo
      itdform = tnapr-fonam
      imblnr  = mseg-mblnr.
ENDFORM.                    "ausgabe_wek1
*eject.
*------------- Warenausgangsschein Version 1 --------------------------*
FORM ausgabe_wa01.
  PERFORM open_form.
  PERFORM wa01_druck.
  PERFORM close_form.
ENDFORM.                    "ausgabe_wa01
*eject.
*------------- Warenausgangsschein Version 2 --------------------------*
FORM ausgabe_wa02.
  PERFORM open_form.
  PERFORM wa02_druck.
  PERFORM close_form.
ENDFORM.                    "ausgabe_wa02
*eject.
*------------- Lesen und Ausgabe für WE-Sammelschein ------------------*
FORM lesen_wes USING objky lgortsplit.
  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.

  REFRESH traptab.
  CLEAR retco.
  CLEAR: xkopfdr, new_page.
  nast_key = objky.
  PERFORM lesen_t159p.
  PERFORM itcpo_fuellen.
  IF NOT t159p-xmehr IS INITIAL.
    IF mseg-weanz GT 0.
      anzahl = mseg-weanz.
    ELSE.
      anzahl = 1.
    ENDIF.
  ELSE.
    anzahl = 1.
  ENDIF.

  PERFORM set_print_param USING      ls_addr_key
                          CHANGING ls_control_param
                                   ls_composer_param
                                   ls_recipient
                                   ls_sender
                                   retco.
  lf_formname = tnapr-fonam.
* determine smartform function module for invoice
  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
       EXPORTING  formname           = lf_formname
*                 variant            = ' '
*                 direct_call        = ' '
       IMPORTING  fm_name            = lf_fm_name
       EXCEPTIONS no_form            = 1
                  no_function_module = 2
                  OTHERS             = 3.
  IF sy-subrc <> 0.
*   error handling
    retco = sy-subrc.
    PERFORM protocol_update_i.
  ENDIF.


  DO anzahl TIMES.
    CALL FUNCTION lf_fm_name
      EXPORTING
         archive_index              = toa_dara
*   ARCHIVE_INDEX_TAB          =
         archive_parameters         = arc_params
         control_parameters         = ls_control_param
*   MAIL_APPL_OBJ              =
         mail_recipient             = ls_recipient
         mail_sender                = ls_sender
         output_options             = ls_composer_param
         user_settings              = 'X'
         nast                       = nast
* IMPORTING
*   DOCUMENT_OUTPUT_INFO       =
*   JOB_OUTPUT_INFO            =
*   JOB_OUTPUT_OPTIONS         =
 EXCEPTIONS
   formatting_error           = 1
   internal_error             = 2
   send_error                 = 3
   user_canceled              = 4
   OTHERS                     = 5
              .
    IF sy-subrc <> 0.
      retco = sy-subrc.
      PERFORM protocol_update_i.
* get SmartForm protocoll and store it in the NAST protocoll
      PERFORM add_smfrm_prot.
    ENDIF.
  ENDDO.
ENDFORM.                    "lesen_wes
**eject.
**-------------- Lesen und  Ausgabe Warenausgangssammelschein
*----------*
FORM lesen_was USING objky lgortsplit.
  REFRESH traptab.
  nast_key = objky.
  CLEAR retco.
  CLEAR: xkopfdr, new_page.
  SELECT SINGLE * FROM mkpf WHERE mblnr = nast_key-mblnr
                            AND   mjahr = nast_key-mjahr.
  MOVE-CORRESPONDING mkpf TO traptab.
  zaehler_m = 1.
  SELECT * FROM mseg WHERE mblnr = mkpf-mblnr
                     AND   mjahr = mkpf-mjahr.
    IF sy-subrc NE 0.
      retco = sy-subrc.
      EXIT.
    ENDIF.
    CHECK mseg-xauto IS INITIAL.
    IF zaehler_m = 1.
      CLEAR zaehler_m.
      PERFORM tab001w_lesen.
    ENDIF.
    MOVE-CORRESPONDING mseg TO traptab.
    APPEND traptab.
  ENDSELECT.
*  perform open_form_sammel.
*  sort traptab by werks lgort zeile.
*  loop at traptab.
*    move-corresponding traptab to mkpf.
*    move-corresponding traptab to mseg.
*    perform tab156_lesen.
*    check not t156-kzdru is initial.                        " 108942
*    xskkz = t156-rstyp.
*    perform tab001w_lesen_2.
*    if not mseg-matnr is initial.
*      perform material_lesen.
*    endif.
*    perform ladr_lesen.
*    perform helpdata1.
*    perform wa03_ausgabe using lgortsplit.
*    perform helpdata2.
*  endloop.
*  perform close_form.
ENDFORM.                    "lesen_was
*eject.
*------------------- Ausgabe Etiketten --------------------------------*
FORM ausgabe_eti.
  PERFORM open_form.
  PERFORM eti_druck.
  PERFORM close_form.
ENDFORM.                    "ausgabe_eti
*eject.
*------------- Etikettendruck bei Version 3 Wareneingang --------------*
FORM lesen_wese USING objky.
  CLEAR retco.
  nast_key = objky.
  zaehler_m = 1.
  SELECT SINGLE * FROM mkpf WHERE mblnr = nast_key-mblnr
                            AND   mjahr = nast_key-mjahr.
  SELECT * FROM mseg WHERE mblnr = mkpf-mblnr
                     AND   mjahr = mkpf-mjahr.
    IF sy-subrc NE 0.
      retco = sy-subrc.
      EXIT.
    ENDIF.
    IF zaehler_m = 1.
      CLEAR zaehler_m.
      PERFORM tab001w_lesen.
      PERFORM open_form.
    ENDIF.
    PERFORM tab156_lesen.
    CHECK NOT t156-kzdru IS INITIAL.
    xskkz = t156-rstyp.
    IF NOT mseg-evers IS INITIAL.      "Versandvorschriften lesen.
      PERFORM t027_lesen.
    ENDIF.
    PERFORM bestellung_lesen.
    IF mseg-matnr IS INITIAL.
      mseg-menge = mseg-bpmng.
      mseg-meins = mseg-bprme.
      PERFORM bestelltext_lesen.
    ELSE.
      PERFORM material_lesen.
    ENDIF.
    PERFORM tab024_lesen.
    PERFORM tab001w_lesen_2.
    PERFORM helpdata1.
    PERFORM eti_druck.
    PERFORM helpdata2.
  ENDSELECT.
  PERFORM close_form.
ENDFORM.                    "lesen_wese
*eject.
*------------ Etikettendruck Warenausgang Version 3 -------------------*
FORM lesen_wase USING objky.
  nast_key = objky.
  CLEAR retco.
  zaehler_m = 1.
  SELECT SINGLE * FROM mkpf WHERE mblnr = nast_key-mblnr
                            AND   mjahr = nast_key-mjahr.
  SELECT * FROM mseg WHERE mblnr = mkpf-mblnr
                     AND   mjahr = mkpf-mjahr.

    IF sy-subrc NE 0.
      retco = sy-subrc.
      EXIT.
    ENDIF.
    IF zaehler_m = 1.
      CLEAR zaehler_m.
      PERFORM tab001w_lesen.
      PERFORM open_form.
    ENDIF.
    PERFORM tab156_lesen.
    CHECK NOT t156-kzdru IS INITIAL.                        " 108942
    xskkz = t156-rstyp.
    PERFORM tab001w_lesen_2.
    IF NOT mseg-matnr IS INITIAL.
      PERFORM material_lesen.
    ENDIF.
    PERFORM helpdata1.
    PERFORM eti_druck.
    PERFORM helpdata2.
  ENDSELECT.
  PERFORM close_form.
ENDFORM.                    "lesen_wase
*eject.
*------------- Warenausgangsschein LB Version 1 -----------------------*
FORM ausgabe_wlb1.
  PERFORM open_form.
  PERFORM wa01_druck.
  PERFORM close_form.
ENDFORM.                    "ausgabe_wlb1
*eject.
*------------- Warenausgangsschein LB Version 2 -----------------------*
FORM ausgabe_wlb2.
  PERFORM open_form.
  PERFORM wa02_druck.
  PERFORM close_form.
ENDFORM.                    "ausgabe_wlb2
*eject.
*------- Lesen und Ausgabe Warenausgangssammelsch. LB -----------------*
FORM lesen_wlbs USING objky.
  nast_key = objky.
  CLEAR retco.
  CLEAR: xkopfdr, new_page.
  zaehler_m = 1.
  SELECT SINGLE * FROM mkpf WHERE mblnr = nast_key-mblnr
                            AND   mjahr = nast_key-mjahr.
  SELECT * FROM mseg INTO TABLE xmseg
                     WHERE mblnr = mkpf-mblnr
                     AND   mjahr = mkpf-mjahr.
  LOOP AT xmseg.
    mseg = xmseg.
    CHECK mseg-sobkz IS INITIAL OR
          ( mseg-sobkz = o AND mseg-xauto IS INITIAL ).
    IF sy-subrc NE 0.
      retco = sy-subrc.
      EXIT.
    ENDIF.
    IF zaehler_m = 1.
      CLEAR zaehler_m.
      PERFORM tab001w_lesen.
      PERFORM open_form_sammel.
    ENDIF.
    PERFORM tab156_lesen.
    xskkz = t156-rstyp.
    IF NOT mseg-matnr IS INITIAL.
      PERFORM material_lesen.
    ENDIF.
    ON CHANGE OF mseg-lifnr.
      PERFORM read_address.
    ENDON.
    PERFORM tab001w_lesen_2.
    PERFORM helpdata1.
    PERFORM lb03_ausgabe.
    PERFORM helpdata2.
  ENDLOOP.
  PERFORM close_form.
ENDFORM.                    "lesen_wlbs
*eject.
*----------------------------------------------------------------------*
*------------------ Ausgaberoutinen -----------------------------------*
*----------------------------------------------------------------------*
*------------- WE Schein Für Fert.Auftr Vers. 1 -----------------------*
FORM ausgabe_wf01.
  PERFORM open_form.
  IF NOT t159p-xmehr IS INITIAL.
    IF mseg-weanz GT 0.
      anzahl = mseg-weanz.
    ELSE.
      anzahl = 1.
    ENDIF.
  ELSE.
    anzahl = 1.
  ENDIF.
  DO anzahl TIMES.
    PERFORM wf01_druck.
  ENDDO.
  PERFORM close_form.
ENDFORM.                    "ausgabe_wf01
*eject.
*------------- WE Schein für Fert.Auftrag Vers 2.----------------------*
FORM ausgabe_wf02.
  PERFORM open_form.
  IF NOT t159p-xmehr IS INITIAL.
    IF mseg-weanz GT 0.
      anzahl = mseg-weanz.
    ELSE.
      anzahl = 1.
    ENDIF.
  ELSE.
    anzahl = 1.
  ENDIF.
  DO anzahl TIMES.
    PERFORM wf02_druck.
  ENDDO.
  PERFORM close_form.
ENDFORM.                    "ausgabe_wf02


INCLUDE /SMB40/M07DRSON.

 *----------------------------------------------------------------------*
*---------------- diverse Subroutines --------------------------------*
*----------------------------------------------------------------------*
FORM lesen USING objky.
  nast_key = objky.
  CLEAR retco.
  SELECT SINGLE * FROM mkpf WHERE mblnr = nast_key-mblnr
                            AND   mjahr = nast_key-mjahr.
  SELECT SINGLE * FROM mseg WHERE mblnr = mkpf-mblnr
                            AND   zeile = nast_key-zeile
                            AND   mjahr = mkpf-mjahr.
  IF sy-subrc NE 0.
    retco = sy-subrc.
    EXIT.
  ENDIF.
  PERFORM tab156_lesen.
  xskkz = t156-rstyp.
  PERFORM tab001w_lesen.
  IF NOT mseg-evers IS INITIAL.        "Versandvorschriften lesen.
    PERFORM t027_lesen.
  ENDIF.
  PERFORM bestellung_lesen.
  IF NOT ekpo-knttp IS INITIAL AND NOT
         ekpo-weunb IS INITIAL.
    PERFORM kontierung_lesen.          "für multikontierte Bestellungen
  ENDIF.
  IF NOT mseg-ematn IS INITIAL.
    PERFORM lesen_htn.
  ELSE.                                "111277/PH
    CLEAR am07m-mfrpn.                 "111277/PH
  ENDIF.
  IF mseg-matnr IS INITIAL.
    mseg-menge = mseg-bpmng.
    mseg-meins = mseg-bprme.
    PERFORM bestelltext_lesen.
    CLEAR mabdr.
  ELSE.
    PERFORM material_lesen.
  ENDIF.
  PERFORM tab024_lesen.
  PERFORM t064b_lesen.
  PERFORM ladr_lesen.
ENDFORM.
*--------------- Lesen für WE-Schein Fert.Auftrag ---------------------*
FORM lesen_wf USING objky.
  nast_key = objky.
  CLEAR retco.
  SELECT SINGLE * FROM mkpf WHERE mblnr = nast_key-mblnr
                            AND   mjahr = nast_key-mjahr.
  SELECT SINGLE * FROM mseg WHERE mblnr = mkpf-mblnr
                            AND   zeile = nast_key-zeile
                            AND   mjahr = mkpf-mjahr.
  IF sy-subrc NE 0.
    retco = sy-subrc.
    EXIT.
  ENDIF.
  PERFORM tab156_lesen.
  xskkz = t156-rstyp.
  PERFORM tab001w_lesen.
  PERFORM auftrag_lesen.
  IF NOT mseg-matnr IS INITIAL.
    PERFORM material_lesen.
  ELSE.
    mseg-menge = mseg-erfmg.
    mseg-meins = mseg-erfme.
  ENDIF.
  PERFORM tab024d_lesen.
  PERFORM t064b_lesen.
  PERFORM ladr_lesen.
ENDFORM.
*-------------- Lesen für Warenausgang --------------------------------*
FORM lesen_wa USING objky.
  nast_key = objky.
  CLEAR retco.
  SELECT SINGLE * FROM mkpf WHERE mblnr = nast_key-mblnr
                            AND   mjahr = nast_key-mjahr.
  SELECT SINGLE * FROM mseg WHERE mblnr = mkpf-mblnr
                            AND   zeile = nast_key-zeile
                            AND   mjahr = mkpf-mjahr.
  IF sy-subrc NE 0.
    retco = sy-subrc.
    EXIT.
  ENDIF.
  PERFORM tab156_lesen.
  xskkz = t156-rstyp.
  PERFORM tab001w_lesen.
  IF NOT mseg-matnr IS INITIAL.
    PERFORM material_lesen.
  ENDIF.
  PERFORM ladr_lesen.
ENDFORM.
*-------------- Druck Vorbereiten -------------------------------------*
FORM open_form.
  PERFORM itcpo_fuellen.
*  CALL FUNCTION 'OPEN_FORM'
*  EXPORTING device = 'PRINTER'
*          language = language
*           options =  itcpo
*            dialog = ' '.
  PERFORM lesen_t159p.
  x_open = x.
ENDFORM.
*-------------- Druck Vorbereiten Sammelscheine -----------------------*
FORM open_form_sammel.
  PERFORM lesen_t159p.
  PERFORM itcpo_fuellen.
*  CALL FUNCTION 'OPEN_FORM'
*  EXPORTING device = 'PRINTER'
*          language = language
*           options = itcpo
*              form = tnapr-fonam
*            dialog = ' '.
*  x_open = x.
ENDFORM.
*-------------- Druck schließen ---------------------------------------*
FORM close_form.
  CHECK NOT x_open IS INITIAL.
*  CALL FUNCTION 'CLOSE_FORM'.
  CLEAR x_open.
ENDFORM.
*------------- Hilfsfelder versorgen für Sammelscheindruck ------------*
FORM helpdata1.
   *mkpf = mkpf.
   *mseg-lgort = mseg-lgort.
   *ladr = ladr.
  save_mkpf = *mkpf-usnam.
  save_mblnr = *mkpf-mblnr.
  save_budat = *mkpf-budat.
  save_cpudt = *mkpf-cpudt.
  save_ematn = *mseg-ematn.
  save_lgort = *mseg-lgort.
  save_ladr = *ladr.
   *t001w = t001w.
  save_werks = *t001w-werks.
  save_name1 = *t001w-name1.
   *ekko = ekko.
   *am07m = am07m.
  save_lifnr = *ekko-lifnr.
  save_ebeln = *ekko-ebeln.
  save_ekgrp = *ekko-ekgrp.
  save_linam = *am07m-name1.
  save_lina2 = *am07m-name2.
   *t024 = t024.
  save_eknam = *t024-eknam.
  save_ektel = *t024-ektel.
   *mkpf-usnam = old_mkpf.
   *mkpf-mblnr = old_mblnr.
   *mkpf-cpudt = old_cpudt.
   *mkpf-budat = old_budat.
   *mseg-ematn = old_ematn.
   *mseg-lgort = old_lgort.
   *ladr = old_ladr.
   *t001w-werks = old_werks.
   *t001w-name1 = old_name1.
   *t024-eknam = old_eknam.
   *t024-ektel = old_ektel.
   *ekko-lifnr = old_lifnr.
   *ekko-ebeln = old_ebeln.
   *ekko-ekgrp = old_ekgrp.
   *am07m-name1 = old_linam.
   *am07m-name2 = old_lina2.
  save_lfa1  = lfa1.
  IF NOT old_lfa1 IS INITIAL.
    lfa1  = old_lfa1.
  ENDIF.
ENDFORM.
*--- Versorgung der Hilfsfelder vor CLOSE_FORM bei Sammelscheindruck --*
FORM helpdata2.
  old_lfa1 = save_lfa1.
  lfa1     = save_lfa1.
  old_mkpf = save_mkpf.
  old_lgort = save_lgort.
  old_ladr = save_ladr.
  old_budat = save_budat.
  old_cpudt = save_cpudt.
  old_werks = save_werks.
  old_name1 = save_name1.
  old_mblnr = save_mblnr.
  old_lifnr = save_lifnr.
  old_linam = save_linam.
  old_lina2 = save_lina2.
  old_ebeln = save_ebeln.
  old_ekgrp = save_ekgrp.
  old_eknam = save_eknam.
  old_ektel = save_ektel.
  old_ematn = save_ematn.
   *mkpf-usnam = save_mkpf.
   *mkpf-mblnr = save_mblnr.
   *mkpf-budat = save_budat.
   *mkpf-cpudt = save_cpudt.
   *mseg-ematn = save_ematn.
   *mseg-lgort = save_lgort.
   *ladr = save_ladr.
   *t001w-werks = save_werks.
   *t001w-name1 = save_name1.
   *t024-eknam  = save_eknam.
   *t024-ektel  = save_ektel.
   *ekko-lifnr  = save_lifnr.
   *ekko-ebeln  = save_ebeln.
   *ekko-ekgrp  = save_ekgrp.
   *am07m-name1 = save_linam.
   *am07m-name2 = save_lina2.
ENDFORM.
*----------- Form Lesen Warenausgang Lohnbearbeiter -------------------*
FORM lesen_wlb USING objky.
  nast_key = objky.
  CLEAR retco.
  SELECT SINGLE * FROM mkpf WHERE mblnr = nast_key-mblnr
                            AND   mjahr = nast_key-mjahr.
  SELECT SINGLE * FROM mseg WHERE mblnr = mkpf-mblnr
                            AND   zeile = nast_key-zeile
                            AND   mjahr = mkpf-mjahr.
  IF sy-subrc NE 0.
    retco = sy-subrc.
    EXIT.
  ENDIF.
  PERFORM tab156_lesen.
  xskkz = t156-rstyp.
  PERFORM tab001w_lesen.
  IF NOT mseg-matnr IS INITIAL.
    PERFORM material_lesen.
  ENDIF.
  ON CHANGE OF mseg-lifnr.
    PERFORM read_address.
  ENDON.
ENDFORM.
*eject
*---------------------- Fuellen der ITCPO -----------------------------*
FORM itcpo_fuellen.
  IF xscreen NE space.
*- Testausgabe auf Bildschirm ----------------------------------------
    itcpo-tdpreview = 'X'.
    itcpo-tdnoprint = 'X'.
  ELSE.
    CLEAR: itcpo-tdpreview,
           itcpo-tdnoprint.
  ENDIF.
  MOVE-CORRESPONDING nast TO itcpo.
  itcpo-tdcover   = nast-tdocover.
  itcpo-tddest    = nast-ldest.
  itcpo-tddataset = nast-dsnam.
  itcpo-tdsuffix1 = nast-dsuf1.
  itcpo-tdsuffix2 = nast-dsuf2.
  itcpo-tdimmed   = nast-dimme.
  itcpo-tddelete  = nast-delet.
  itcpo-tdcopies  = nast-anzal.
  itcpo-tdprogram = sy-repid.
* ITCPO-TDTELELAND = US_COUNTRY.
  itcpo-tdsenddate = nast-vsdat.
  itcpo-tdsendtime = nast-vsura.
  itcpo-tdnewid   = x.
ENDFORM.
*eject.

* ------------ FORM lesen der Lagerortadr. ---------------------------*
FORM ladr_lesen.
  DATA:    BEGIN OF addr_sel.
          INCLUDE STRUCTURE addr1_sel.
  DATA:    END OF addr_sel.
  CLEAR ladr.
  SELECT SINGLE * FROM twlad WHERE werks = mseg-werks
                       AND  lgort = mseg-lgort
                       AND  lfdnr = '001'.
  IF NOT twlad-adrnr IS INITIAL AND sy-subrc IS INITIAL.
    MOVE twlad-adrnr TO addr_sel-addrnumber.
  ENDIF.
  CALL FUNCTION 'ADDR_GET'
       EXPORTING
            address_selection = addr_sel
       IMPORTING
            sadr              = ladr
       EXCEPTIONS
            OTHERS            = 1.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  set_print_param
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LS_ADDR_KEY  text
*      <--P_LS_CONTROL_PARAM  text
*      <--P_LS_COMPOSER_PARAM  text
*      <--P_LS_RECIPIENT  text
*      <--P_LS_SENDER  text
*      <--P_ENT_RETCO  text
*----------------------------------------------------------------------*
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_CONTROL_PARAM-NO_OPEN
*   CS_CONTROL_PARAM-NO_CLOSE
    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.
*   CS_CONTROL_PARAM-REPLANGU1
*   CS_CONTROL_PARAM-REPLANGU2
*   CS_CONTROL_PARAM-REPLANGU3
*   CS_CONTROL_PARAM-STARTPAGE
  ENDIF.

ENDFORM.                               " set_print_param
*&---------------------------------------------------------------------*
*&      Form  get_addr_key
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_LS_ADDR_KEY  text
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      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.

* 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.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  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.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
  ENDLOOP.

  CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'.
  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_smfrm_prot
*&---------------------------------------------------------------------*
*&      Form  print_smartform
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM print_smartform.
  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: it_ekpo LIKE ekpo OCCURS 0.

  REFRESH traptab.
  CLEAR retco.
  CLEAR: xkopfdr, new_page.
*  nast_key = objky.
  PERFORM lesen_t159p.
  PERFORM itcpo_fuellen.
  SELECT * FROM ekpo INTO TABLE it_ekpo WHERE
                          ebeln = ekko-ebeln.
  IF NOT t159p-xmehr IS INITIAL.
    IF mseg-weanz GT 0.
      anzahl = mseg-weanz.
    ELSE.
      anzahl = 1.
    ENDIF.
  ELSE.
    anzahl = 1.
  ENDIF.

  PERFORM set_print_param USING      ls_addr_key
                          CHANGING ls_control_param
                                   ls_composer_param
                                   ls_recipient
                                   ls_sender
                                   retco.
*Get the Smart Form name.
  IF NOT tnapr-sform IS INITIAL.
    lf_formname = tnapr-sform.
  ELSE.
    MESSAGE e001(/smb40/ssfcomposer).
  ENDIF.

* determine smartform function module for invoice
  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
       EXPORTING  formname           = lf_formname
*                 variant            = ' '
*                 direct_call        = ' '
       IMPORTING  fm_name            = lf_fm_name
       EXCEPTIONS no_form            = 1
                  no_function_module = 2
                  OTHERS             = 3.
  IF sy-subrc <> 0.
*   error handling
    retco = sy-subrc.
    IF sy-subrc = 1.
      MESSAGE e001(/smb40/ssfcomposer).
    ENDIF.
    IF sy-subrc = 2.
      MESSAGE e002(/smb40/ssfcomposer).
    ENDIF.
    PERFORM protocol_update_i.
  ENDIF.


  DO anzahl TIMES.
    CALL FUNCTION lf_fm_name
      EXPORTING
         archive_index              = toa_dara
*   ARCHIVE_INDEX_TAB          =
         archive_parameters         = arc_params
         control_parameters         = ls_control_param
*   MAIL_APPL_OBJ              =
         mail_recipient             = ls_recipient
         mail_sender                = ls_sender
         output_options             = ls_composer_param
         user_settings              = ' '
         mseg                       = mseg
         ekpo                       = ekpo
         t157e                      = t157e
         am07m                      = am07m
         mkpf                       = mkpf
         nast                       = nast
         t159p                      =  t159p
         t001w                      = t001w
         ekko                       = ekko
         t024                       = t024
         TABLES
         it_ekpo                    = it_ekpo
* IMPORTING
*   DOCUMENT_OUTPUT_INFO       =
*   JOB_OUTPUT_INFO            =
*   JOB_OUTPUT_OPTIONS         =
 EXCEPTIONS
   formatting_error           = 1
   internal_error             = 2
   send_error                 = 3
   user_canceled              = 4
   OTHERS                     = 5
              .
    IF sy-subrc <> 0.
      retco = sy-subrc.
      PERFORM protocol_update_i.
* get SmartForm protocoll and store it in the NAST protocoll
      PERFORM add_smfrm_prot.
    ENDIF.
  ENDDO.

ENDFORM.                               " print_smartform

Regards

Pavan

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question