Skip to end of metadata
Go to start of metadata

List of all pages

Pages at first level

List of all pages

Pages at first level

REPORT  zmmr_post_account .
TABLES : t030a,t030w,t030r,t030b,t030.
DATA: g_first(1),
      g_texth(20),
      g_texts(20).
*Text:Chart of Accounts
PARAMETERS p_ktopl LIKE t030-ktopl  DEFAULT 'CB00' OBLIGATORY.
*Text: Transaction Key
SELECT-OPTIONS: s_ktosl FOR t030a-ktosl.
*If set 'X',program will output all transaction key which configured Account.
*Text: Display No Account Transaction Key
PARAMETERS p_output AS CHECKBOX .
RANGES  r_ktosl FOR t030a-ktosl.
REFRESH r_ktosl.
r_ktosl-sign =  'I'.
r_ktosl-option = 'EQ'.
SELECT  * FROM t030a WHERE grupp = 'RMK'.
  SELECT SINGLE * FROM t030w WHERE spras = sy-langu AND  ktosl = t030a-ktosl.
  g_first = 'X'.
  SELECT * FROM t030 WHERE ktopl = p_ktopl AND ktosl = t030a-ktosl.
    IF g_first = 'X'.
      FORMAT COLOR COL_KEY INTENSIFIED OFF.
      HIDE:    t030a-ktosl.
      WRITE:/(16) 'Transaction Key:',
            29(6) t030a-ktosl,
            41(30) t030w-ltext.
      SELECT SINGLE * FROM t030r WHERE  ktopl = p_ktopl AND ktosl = t030a-ktosl.
      IF sy-subrc = 0 .
        IF t030r-xkomo = 'X'.
        ENDIF.
        IF t030r-xbwmo = 'X'.
        ENDIF.
        IF t030r-xbkla = 'X'.
        ENDIF.
        IF t030r-xdiko = 'X'.
        ENDIF.
      ENDIF.
      SELECT SINGLE * FROM t030b WHERE ktosl = t030a-ktosl.
      IF sy-subrc = 0 .
        FORMAT COLOR COL_BACKGROUND.
        WRITE:/(10) ' '.
        FORMAT COLOR COL_TOTAL INTENSIFIED ON.
        WRITE:10(16) 'Post Key:',
              28(2) '',
              29(2) 'De',
              62(1) '|',
              63(2) 'Cr',
              97(1) '|'.
        CLEAR:g_texts,g_texth.
        IF t030b-bschs NE space.
          SELECT SINGLE ltext INTO (g_texts) FROM tbslt WHERE spras = sy-langu AND bschl = t030b-bschs.
        ENDIF.
        IF t030b-bschh NE space.
          SELECT SINGLE ltext INTO (g_texth) FROM tbslt WHERE spras = sy-langu AND bschl = t030b-bschh.
        ENDIF.
        FORMAT COLOR COL_BACKGROUND.
        WRITE:/(27) ' '.
        FORMAT COLOR COL_TOTAL INTENSIFIED ON.
        WRITE:28(2) '|',
              29(2) t030b-bschs,
              41(20) g_texts,
              62(1) '|',
              63(2) t030b-bschh,
              75(20) g_texth,
              97(1) '|'.
      ENDIF.
      FORMAT COLOR COL_BACKGROUND.
      WRITE:/(10) ' '.
      FORMAT COLOR COL_KEY INTENSIFIED ON.
      WRITE:10(16) 'Post Account:',
            28(2) '|',
            29(2) 'De',
            41(20) 'Text',
            62(1) '|',
            63(2) 'Cr',
            75(20) 'Text',
            97(1) '|'.
      g_first = space.
    ENDIF.
    CLEAR:g_texts,g_texth.
    IF t030-konts NE space.
      SELECT SINGLE txt20 INTO (g_texts) FROM skat WHERE spras = sy-langu AND ktopl = p_ktopl
         AND  saknr = t030-konts.
    ENDIF.
    IF t030-konts NE space.
      SELECT SINGLE txt20 INTO (g_texth) FROM skat WHERE spras = sy-langu AND ktopl = p_ktopl
      AND saknr = t030-konth.
    ENDIF.
    FORMAT COLOR COL_BACKGROUND.
    WRITE:/(12) ' '.
    FORMAT COLOR COL_KEY INTENSIFIED ON.
    WRITE:12(4) t030-bwmod,'|',
          18(3) t030-komok,'|',
          23(4) t030-bklas ,
          28(1) '|',
          29(10) t030-konts,
          41(20) g_texts,
          62(1) '|'.
    IF t030r-xdiko = 'X'.
      WRITE:63(10) t030-konth,
            75(20) g_texth.
    ENDIF.
    WRITE:97(1) '|'.
  ENDSELECT.
  IF sy-subrc NE 0.
    r_ktosl-low =  t030a-ktosl.
    APPEND r_ktosl.
  ENDIF.
ENDSELECT.
*Get No Used Transaction Key
IF ( r_ktosl IS NOT INITIAL ) AND p_output = 'X'.
  FORMAT COLOR COL_NEGATIVE INTENSIFIED OFF.
  WRITE:/(97) 'UnConfigure Transaction Key:'.
  SELECT  * FROM t030a WHERE grupp = 'RMK' AND  ktosl IN r_ktosl.
    FORMAT COLOR COL_KEY INTENSIFIED OFF.
    WRITE:/(16) 'Transaction Key:',
          29(6) t030a-ktosl,
          41(30) t030w-ltext.
    SELECT SINGLE * FROM t030b WHERE ktosl = t030a-ktosl.
    IF sy-subrc = 0 .
      FORMAT COLOR COL_BACKGROUND.
      WRITE:/(10) ' '.
      FORMAT COLOR COL_TOTAL INTENSIFIED ON.
      WRITE:10(16) 'Post Key:',
            28(2) '|',
            29(2) 'De',
            62(1) '|',
            63(2) 'Cr',
            97(1) '|'.
      CLEAR:g_texts,g_texth.
      IF t030b-bschs NE space.
        SELECT SINGLE ltext INTO (g_texts) FROM tbslt WHERE spras = sy-langu AND bschl = t030b-bschs.
      ENDIF.
      IF t030b-bschh NE space.
        SELECT SINGLE ltext INTO (g_texth) FROM tbslt WHERE spras = sy-langu AND bschl = t030b-bschh.
      ENDIF.
      FORMAT COLOR COL_BACKGROUND.
      WRITE:/(27) ' '.
      FORMAT COLOR COL_TOTAL INTENSIFIED ON.
      WRITE:28(2) '|',
            29(2) t030b-bschs,
            41(20) g_texts,
            62(1) '|',
            63(2) t030b-bschh,
            75(20) g_texth,
            97(1) '|'.
    ENDIF.
    FORMAT COLOR COL_BACKGROUND.
    WRITE:/(10) ' '.
    FORMAT COLOR COL_KEY INTENSIFIED ON.
    WRITE:10(16) 'Post Account:',
          28(2) '|',
          29(2) 'De',
          41(20) 'Text',
          62(1) '|',
          63(2) 'Cr',
          75(20) 'Text',
          97(1) '|'.
  ENDSELECT.
ENDIF.

AT LINE-SELECTION.
  CALL TRANSACTION  'OBYC'.
 

In the table LIPOV we have an append structure LIPOVZ, we can add custom fields that needs to be viewed in the final output screen.

In this LIPOVZ structure you can add fields from LIKP/LIPS/VBUP. These fields will be populated automatically as below.

SE11 - LIPOV ---- LIPOVZ (Append structure is opened) - Double click it -> CHANGE

Component                        Component Type

VGBEL                                   VGBEL - This is an LIPS field that is automatically populated.

If we need to output a field that is not in LIKP/LIPS/VBUP, then we can write our own custom code inside the exit.

BSTNK                                   BSTNK - Customer purchase order number

User Exit SMOD --> Create a ZPROJECT

Under the Enhancement Assignment give the Enhancement name - V50Q0001 ---> use the componenet - EXIT_SAPLV50Q_001.

Add the code inside the  INCLUDE ZXV50QU01.

Code Below :

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*&---------------------------------------------------------------------*
*&  Include           ZXV50QU01
*&---------------------------------------------------------------------*
DATA : lv_bstnk TYPE bstnk.

LOOP AT ct_postab.

*- Passing the Customer PO Number
  SELECT SINGLE bstnk FROM vbak
          INTO lv_bstnk
    WHERE vbeln = lv_vbelv.
  IF sy-subrc IS INITIAL.
    ct_postab-bstnk = lv_bstnk.
  ENDIF.
  MODIFY ct_postab.
ENDLOOP.

 To see more details, see note 128150.

Author: name as link to Business Card
Submitted: 19.03.2008
Related Links:

  • www.sap-img.com/>

Description

/* For adding a new field no more configuration is required.  Any additional field in table LIPOVZ will be reflected in the worklist. */

To add a field in the worklist, insert the field in customer specific table :-

LIPOVZ - Customer modification division for Table LIPOV

SE12 - Database Table - LIPOVZ
Click Display -> Change

You can delete away the Component DUMMY.
e.g. to insert the Bill of lading in the worklist
Component    Component Type
BOLNR             BOLNR

After this, you have to execute program BALVBUFDEL (note 122975) to reset the ALV buffer.

Table you can use for VL06O
LIKP - SD Document: Delivery Header Data
LIPS - SD document: Delivery: Item data
VBUP - Sales Document: Item Status

Once completed, you should be able to see the new fields in Settings -> Layout -> Change

In this case, the system will automaticly fill the fields.

 In some cases, you will need to create fields that are not in the tables above (like sales order type VBAK-AUART).

To create new fields, you need to change the structure LIPOVZ adding your custom fields.

After do this,  you need to fill the fields with user exit V50Q0001.

To more details, see note 128150.

This is a little ABAP which calls BAPI_OUTB_DELIVERY_CONFIRM_DEC. It helps to explore and understand what this BAPI does.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
REPORT  zz_bapi_outb_delivery_conf_dec.

DATA header_data LIKE bapiobdlvhdrcon.
DATA header_control LIKE bapiobdlvhdrctrlcon.
DATA delivery LIKE bapiobdlvhdrcon-deliv_numb.
DATA handling_unit_header_cross TYPE TABLE OF bapidlvhdunhdr.
DATA gs_handling_unit_header_cross TYPE bapidlvhdunhdr.
DATA return TYPE TABLE OF bapiret2.

PARAMETERS:
* Delivery number
p_deliv LIKE bapiobdlvhdrcon-deliv_numb DEFAULT '0080015271',
* External Handling Unit Identifikation
p_hunr LIKE bapidlvhdunhdr-hdl_unit_exid DEFAULT '60000000000000000000',
* Handling Unit Material Number
p_humat LIKE bapidlvhdunhdr-ship_mat DEFAULT '000000000000002387'.

* Work on clean data. Allways.
CLEAR:
header_data,
header_control,
delivery,
gs_handling_unit_header_cross.
REFRESH:
handling_unit_header_cross.

* set data values
header_data-deliv_numb = p_deliv.
header_control-deliv_numb = p_deliv.
delivery = p_deliv.
gs_handling_unit_header_cross-deliv_numb = p_deliv.
gs_handling_unit_header_cross-hdl_unit_exid = p_hunr.
gs_handling_unit_header_cross-ship_mat = p_humat.
APPEND gs_handling_unit_header_cross TO handling_unit_header_cross.
* Call Function
CALL FUNCTION 'BAPI_OUTB_DELIVERY_CONFIRM_DEC'
  EXPORTING
    header_data                = header_data
    header_control             = header_control
    delivery                   = p_deliv
  TABLES
    return                     = return
    handling_unit_header_cross = handling_unit_header_cross.
COMMIT WORK.
WRITE: 'Finished'.

I was trying here to put more then one delivery into one HU without using a shipment and without using EWM. This does not work, because the FORM x_hu_active_check in Include /SPE/XHU_LV51SF01 checks if EWM is active. You can read more about this under http://www.scribd.com/doc/19837595/Usingbapi-Outb-Delivery-Confirm-Deccrosshu.

Author: Aveek Ghose
Submitted: December 12, 2006

 Bill of Material Program

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*&---------------------------------------------------------------------*
*& Include ZCONINC3
*&---------------------------------------------------------------------*

* Source Name is ZCONINC3
FORM status-line-msg USING tmp-text.
* Put a Message at BOTTOM OF SCREEN - to let person executing
* Interactively Know WHAT RECORD IS BEING PROCESSED
  DATA: msg_line(100).
  MOVE tmp-text TO msg_line.
  CONDENSE msg_line.
  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
      text = msg_line.
ENDFORM.                    "STATUS-LINE-MSG
*&---------------------------------------------------------------------*
*&      Form  STATUS-LINE-MESSAGE
*&---------------------------------------------------------------------*
FORM status-line-message USING tmp-recno tmp-total-recno.
* Put a Message at BOTTOM OF SCREEN - to let person executing
* Interactively Know WHAT RECORD IS BEING PROCESSED
* also Show TOTAL NUMBER OF RECORDS IN THE FILE - only know
* that is we are Processing a PC File
  DATA: msg_line(100).
  CLEAR msg_line.
  MOVE 'Processed Record' TO msg_line.
  WRITE tmp-recno TO msg_line+20(20).
  IF NOT tmp-total-recno IS INITIAL.
    MOVE 'of' TO msg_line+45(2).
    WRITE tmp-total-recno TO msg_line+60(20).
  ENDIF.
  CONDENSE msg_line.
  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
      text = msg_line.

ENDFORM.                    "STATUS-LINE-MESSAGE
*---------------------------------------------------------------------*
* FORM LEFT-ALIGN-FLD *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> TMP-FLD-AL *
*---------------------------------------------------------------------*
FORM left-align-fld USING tmp-fld-al.

********************************************************************
* Purpose - left align all data in fields **************************
********************************************************************
  IF NOT tmp-fld-al IS INITIAL.
    SHIFT tmp-fld-al LEFT DELETING LEADING ' '.
  ENDIF.
ENDFORM.                    "LEFT-ALIGN-FLD
*---------------------------------------------------------------------*
* FORM MAK-NUM *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> TMP-FLD *
*---------------------------------------------------------------------*
FORM mak-num USING tmp-fld.
* If Data Contains Numerics and Spaces - make it a Number for the
* Defned Length of the Field - need the Full Numeric Value in Cases
* Where we are Reading a Data Base
  DATA: len1 TYPE i.
  DATA: tmp-fld-max(30) TYPE n.
  IF NOT tmp-fld IS INITIAL
  AND tmp-fld CO ' 0123456789'.
    DESCRIBE FIELD tmp-fld LENGTH len1 IN BYTE MODE.
    CLEAR tmp-fld-max.
    MOVE tmp-fld TO tmp-fld-max(len1).
    MOVE tmp-fld-max(len1) TO tmp-fld.
  ENDIF.
ENDFORM.                    "MAK-NUM
*---------------------------------------------------------------------*
* FORM CONVERT-TO-MATH-NUMBER *
*---------------------------------------------------------------------*
FORM convert-to-math-number USING fldxx.
* Convert a Number - so Math Can be Done Against it
  TABLES: *usr01.
  CLEAR *usr01.
  SELECT SINGLE * FROM *usr01 WHERE bname EQ sy-uname.
  IF *usr01-dcpfm EQ 'X'.
    WHILE fldxx CS ','. " '.' is a Decimal Point
      REPLACE ',' WITH '' INTO fldxx.
      CONDENSE fldxx NO-GAPS.
    ENDWHILE.
  ELSE.
    WHILE fldxx CS '.'. " ',' is a Decimal Point
      REPLACE '.' WITH '' INTO fldxx.
      CONDENSE fldxx NO-GAPS.
    ENDWHILE.
  ENDIF.
ENDFORM.                    "CONVERT-TO-MATH-NUMBER
*---------------------------------------------------------------------*
* FORM CHECK-TCODE-AUTHORITY *
*---------------------------------------------------------------------*
FORM check-tcode-authority USING t-tcode.
  CALL FUNCTION 'AUTHORITY_CHECK_TCODE'"Only People that
    EXPORTING " have access to
      tcode = t-tcode " Transaction t-tcode
    EXCEPTIONS " are ALLOWED to execute
      ok = 1 " this Program
      not_ok = 2.
  IF sy-subrc NE 1.
    MESSAGE a999(zz) WITH 'YOU Do Not Have Authority to Execute'.
  ENDIF.
ENDFORM.                    "CHECK-TCODE-AUTHORITY

TOP-OF-PAGE.
* General Purpose - Page Heading Routine
* Programming NOTE - keep this at BOTTOM OF THIS INCLUDE
* Other Programs USE THIS - and HAVE 'COLUMN HEADING INFORMATION'
* after this INCLUDE
  CALL FUNCTION 'ZGEN_REP_LISTHEADER01'
    EXPORTING
      im_text1 = 'Routing Operation Number'
      im_text2 = 'WorkCenter'.

  TABLES: *varit.
  DATA: zconinc3-onetime.
  DATA: now-sy-pagno LIKE sy-pagno.
  FORMAT INTENSIFIED OFF.
  ADD 1 TO now-sy-pagno.
* WRITE: /01 SY-PRABT, "Department Receiving Report
** 35 'EXAMPLE COMPANY NAME', "Name This Customer
** 35 'SAPLABS DEMO SYSTEM', "Name This Customer
* 'Page', NOW-SY-PAGNO.
* WRITE: / SY-REPID,
* 'Run by', SY-UNAME(8), 'on', SY-DATUM, SY-UZEIT,
* 'System', SY-SYSID(4), 'Client', SY-MANDT.
* WRITE: / SY-TITLE centered.
* If Variant Used to EXECUTE THIS PROGRAM - put in Variant Description
* into Page Headings
  IF NOT sy-slset IS INITIAL.
    IF zconinc3-onetime IS INITIAL.
      CLEAR *varit.
      MOVE 'N' TO zconinc3-onetime.
      SELECT * FROM *varit
        WHERE langu EQ sy-langu
          AND report EQ sy-repid
          AND variant EQ sy-slset.
        EXIT.
      ENDSELECT.
    ENDIF.
    IF NOT *varit-vtext IS INITIAL.
      WRITE: / 'Variant', sy-slset, *varit-vtext.
    ENDIF.
  ENDIF.
  FORMAT INTENSIFIED ON.

Author: Sujeet Mishra
Submitted: 20/8/2013
Description: This report is just a sample template to display PR, PO, GR and IR details.

TYPE-POOLS : slis.
\*\- Tables
TABLES : eban, " Purchase Requisition
 ekko, " Purchasing Document Header
 ekpo, " Purchasing Document Item
 cdhdr,  " Change Document Header
 cdpos, " Change document items
 lfa1, " Vendor master (general section)
 eket, " Scheduling Agreements delivery schedules
 ekbe, " History of Purchasing Document
 mseg, " Document Segment: Material
 dd07v,
 t163y, " Texts for Item Categories
 m_mekke, " Generated View for Matchcode ID MEKK
 rbkp,
rseg,
t001w,
konv,
ekkn . " Account Assignment in Purchasing Document
\*\- Data decalartions
DATA : BEGIN OF wa_tab OCCURS 0,
 slno     LIKE syst-index,
 bednr_pr    LIKE eban-bednr,    " Tracking Number
 banfn    LIKE eban-banfn,    " PR Number
 bnfpo    LIKE eban-bnfpo,    " PR Item Number
 frgkz    LIKE eban-frgkz,    " Release Indicator
 erdat    LIKE eban-erdat,    " PR LAST CHG date
 badat    LIKE eban-badat,    " PR Date
          frgdt    LIKE eban-frgdt,    " PR Rel. date
          statu    LIKE eban-statu,    " PR/RFQ Status
          ekgrp    LIKE eban-ekgrp,    " Pur. grp
          matkl    LIKE eban-matkl,    " Mat. grp
          matnr_pr    LIKE eban-matnr,    " Mat. Code
          pstyp_pr    LIKE eban-pstyp,    " Item Cat.
          knttp_pr    LIKE eban-knttp,    " Acc. assign Cat.
          afnam_pr    LIKE eban-afnam,
          txz01_pr    LIKE eban-txz01,    " Short text Desc.
          menge_pr    LIKE eban-menge,    " PR qty
          meins_pr    LIKE eban-meins,    " PR Units
          release_pr(10) TYPE c,          " Text for PR Release
          udate_pr LIKE cdhdr-udate,      " UPDATED DATE FOR pr
          epstp    LIKE t163y-epstp,   " Item Cat. text
          ebeln    LIKE ekpo-ebeln,    " PO Number
          ebeln1   LIKE ekko-ebeln,    " PO Number
          ebelp    LIKE ekpo-ebelp,    " Purchase order item number
          bedat    LIKE ekko-bedat,    " PO date
          release_po(10) TYPE c,       " Text for PO Release
          udate_po LIKE cdhdr-udate,   " UDATE FOR po RELEASE
          lifnr    LIKE ekko-lifnr,    " Vendor Code
          name1    LIKE lfa1-name1,    " Vendor name
          frgke    LIKE ekko-frgke,    " Release Indicator
          matnr_po LIKE ekpo-matnr,
          txz01_po    LIKE ekpo-txz01,    " Short text Desc.
          menge_po LIKE ekpo-menge,    " PO qty
          meins_po LIKE ekpo-meins,    " PO Units
          bprme    LIKE ekpo-bprme,    " Order Price Unit (Purchasing)
          eindt    LIKE eket-eindt,    " PO Delivery date
          menge_gr LIKE ekbe-menge,    " GR qty
          belnr    LIKE ekbe-belnr,    " GR Number
          bwart    LIKE mseg-bwart,    " Movement type
          mjahr    LIKE mseg-mjahr,    " Mat Doc Year
          zeile    LIKE mseg-zeile,    " Item in Mat. Doc
          budat    LIKE ekbe-budat,    " GR date
          gv_txt3(10) TYPE c,
          color TYPE slis_t_specialcol_alv,
          irno     LIKE rbkp-belnr,    "Ir No
          irit     LIKE rseg-buzei,    "Item No
          irdt     LIKE rbkp-budat,    "Ir Date
          irval    LIKE rbkp-rmwwr,    "ir Vlalue
          irtx     LIKE rbkp-wmwst1,   "It Tax Amt
          rfqno    LIKE ekko-ebeln,    "RFQ No
          rfqdt    LIKE ekko-bedat,    "RFQ Date
          rfqit    LIKE ekpo-anfps,    "RFQ Item No
bsart LIKE ekko-bsart,   " Purchasing Document Type
netpr LIKE ekpo-netpr,   "Net price in PO (in document currency)
poamt LIKE ekpo-netpr,   "PO Amount for line item
disc1 LIKE komv-kbetr,   "  Discount Per
disc2 LIKE komv-kwert,   "  Discount value
tax LIKE komv-kwert ,     " Tax amount
vbeln LIKE ekkn-vbeln,    " Sales and Distribution Document Number
vbelp LIKE ekkn-vbelp ,   " Sales document item
mblnr LIKE mseg-mblnr,    " Material Doc No
grnamt LIKE komv-kwert,    " GRN Amount
grntax LIKE j_1iexcdtl-exbed, "total grnTAx
saltax LIKE rbkp-wmwst1,  " sales tax value
cst LIKE rbkp-wmwst1,     " CST VALUE
irqty LIKE rseg-menge,   " ir menge
irnetpr LIKE rseg-wrbtr,  " netprice
anln1 LIKE ekkn-anln1,  " Asset ID
iramt LIKE rbkp-rmwwr, " Invoice Amount
knumv LIKE konv-knumv,   "Number of the document condition
waers  LIKE tcurc-waers,
excur  LIKE j_1iexcdtl-excur ,
exaed   LIKE j_1iexcdtl-exaed .
DATA:   END OF wa_tab.
DATA : wa_iramt(21). " type p decimals 3.
DATA : wa_grntax LIKE j_1iexcdtl-exbed. "total grnTAx
DATA : itab LIKE wa_tab OCCURS 0 WITH HEADER LINE.
DATA : iekko LIKE ekko OCCURS 0 WITH HEADER LINE,
       iekpo LIKE ekpo OCCURS 0 WITH HEADER LINE,
       ieban LIKE eban OCCURS 0 WITH HEADER LINE,
       imkpf LIKE mkpf OCCURS 0 WITH HEADER LINE,
       imseg LIKE mseg OCCURS 0 WITH HEADER LINE,
       iekbe LIKE ekbe OCCURS 0 WITH HEADER LINE,
       icdhdr LIKE cdhdr OCCURS 0 WITH HEADER LINE,
       icdpos LIKE cdpos OCCURS 0 WITH HEADER LINE,
       ikomv LIKE komv OCCURS 0 WITH HEADER LINE .
DATA : BEGIN OF iekkn OCCURS 0,
       ebeln    LIKE ekpo-ebeln,    " PO Number
       ebelp    LIKE ekpo-ebelp,    " Purchase order item number
        vbeln LIKE ekkn-vbeln,    " Sales and Distribution Document Number
        vbelp LIKE ekkn-vbelp,   " Sales document item
        anln1 LIKE ekkn-anln1.
DATA : END OF iekkn.
DATA : ikonv LIKE konv OCCURS 0 WITH HEADER LINE,
       ij_1iexcdtl LIKE j_1iexcdtl OCCURS 0 WITH HEADER LINE.
DATA : waers TYPE ekko-waers .
\*\- ALV Declarations
DATA : v_pos TYPE i.
DATA : gt_fieldcat TYPE slis_t_fieldcat_alv.
DATA : gt_item LIKE itab OCCURS 0 WITH HEADER LINE.
DATA: fieldtab TYPE slis_t_fieldcat_alv,
       heading  TYPE slis_t_listheader,
       layout   TYPE slis_layout_alv,
       events   TYPE slis_t_event,
       repname  LIKE sy-repid,
       f2code   LIKE sy-ucomm VALUE  '&ETA',
       g_save(1) TYPE c       VALUE  'A',
       g_variant LIKE disvariant,
       gx_variant LIKE disvariant,
       g_exit(1) TYPE c.
DATA: keyinfo  TYPE slis_keyinfo_alv.
DATA : gt_sort TYPE slis_t_sortinfo_alv.
DATA : gt_sp_group TYPE slis_t_sp_group_alv,
       temp_qty TYPE int4 ,
       temp TYPE konv-kbetr ,
       v_fact TYPE tcurf-ffact,
       exrate  TYPE bapi1093_0 ,
        exrate1 TYPE bapi1093_0 ,
        value_in TYPE p DECIMALS 5,
        value_out TYPE p DECIMALS 2 .
DATA: linecolor TYPE slis_specialcol_alv OCCURS 0 WITH HEADER LINE.
CONSTANTS: formname_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE'.
DATA: alv_print        TYPE slis_print_alv.
DATA: alv_detail_func(30).
DATA : alv_fieldcat    TYPE                 slis_t_fieldcat_alv,
       lt_alv_cat      TYPE TABLE OF        lvc_s_fcat,
       it_fieldcat     LIKE LINE  OF        lt_alv_cat.
SELECTION-SCREEN : BEGIN OF BLOCK gen WITH FRAME TITLE text-100.
PARAMETERS       : pr_werks LIKE ekpo-werks OBLIGATORY DEFAULT EBAN-WERKS.
SELECT-OPTIONS   : s_badat  FOR sy-datum MODIF ID gen OBLIGATORY
                                 DEFAULT sy-datum,
                   pr_matnr FOR eban-matnr,
                   pr_bsart FOR eban-bsart.
PARAMETERS : p_pr RADIOBUTTON GROUP pur.
PARAMETERS : p_po RADIOBUTTON GROUP pur.
SELECTION-SCREEN : END OF BLOCK gen.
SELECTION-SCREEN : BEGIN OF BLOCK pr WITH FRAME TITLE text-010.
SELECT-OPTIONS   : pr_bednr FOR eban-bednr MODIF ID pr,
                   pr_banfn FOR eban-banfn MODIF ID pr,
                   pr_afnam FOR eban-afnam MODIF ID pr,
                   pr_pstyp FOR eban-pstyp MODIF ID pr,
                   pr_knttp FOR eban-knttp MODIF ID pr,
                   pr_lifnr FOR eban-lifnr MODIF ID pr.
SELECTION-SCREEN : END OF BLOCK pr.
SELECTION-SCREEN : BEGIN OF BLOCK po WITH FRAME TITLE text-020.
SELECT-OPTIONS   : po_ebeln FOR ekko-ebeln MODIF ID po,
                   po_matkl FOR ekpo-matkl MODIF ID po,
                   po_pstyp FOR ekpo-pstyp MODIF ID po,
                   po_knttp FOR ekpo-knttp MODIF ID po,
                   po_bednr FOR ekpo-bednr MODIF ID po,
                   po_afnam FOR ekpo-afnam MODIF ID po,
                   po_lifnr FOR ekko-lifnr MODIF ID po.
SELECTION-SCREEN : END OF BLOCK po.
SELECTION-SCREEN BEGIN OF BLOCK s2 WITH FRAME TITLE text-003 .
PARAMETERS: p_vari LIKE disvariant-variant. " ALV Variant
SELECTION-SCREEN END  OF BLOCK s2 .
INITIALIZATION.
INITIALIZATION.
  repname = sy-repid.
  g_variant-report = sy-repid.
  PERFORM build_comment USING heading\[\].
  PERFORM build_eventtab USING events\[\].
  PERFORM build_layout .
START-OF-SELECTION.
  IF p_pr = 'X'.
    PERFORM get_pr.
    PERFORM process_pr_data.
    PERFORM field_cat_fill USING gt_fieldcat\[\].
    PERFORM write_alv.
  ELSE.
    PERFORM get_po.
    PERFORM process_po_data.
    PERFORM field_cat_fill USING gt_fieldcat\[\].
    PERFORM write_alv.
  ENDIF.
END-OF-SELECTION.
\*&---------------------------------------------------------------------\*
\*&      Form  get_PR
\*&---------------------------------------------------------------------\*
\*       text
\*----------------------------------------------------------------------\*
\*  -->  p1        text
\* &nbsp;<-\- &nbsp;p2 &nbsp; &nbsp; &nbsp; &nbsp;text
\*----------------------------------------------------------------------\*
FORM get_pr .
&nbsp; SELECT * FROM eban
&nbsp; &nbsp; INTO TABLE ieban
&nbsp; &nbsp; WHERE banfn IN pr_banfn AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; badat IN s_badat AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bsart IN pr_bsart AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bednr IN pr_bednr AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; afnam IN pr_afnam AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pstyp IN pr_pstyp AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; knttp IN pr_knttp AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; matnr IN pr_matnr AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lifnr IN pr_lifnr AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; werks EQ pr_werks AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loekz EQ space &nbsp; &nbsp;AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bstyp NE 'A' &nbsp; &nbsp; &nbsp; &nbsp;AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; frgkz NE '1'. &nbsp; &nbsp; &nbsp;"AND
&nbsp; IF ieban\[\] IS NOT INITIAL.
&nbsp; &nbsp; SELECT * FROM ekpo
&nbsp; &nbsp; &nbsp; INTO TABLE iekpo
&nbsp; &nbsp; &nbsp; FOR ALL ENTRIES IN ieban
&nbsp; &nbsp; &nbsp; WHERE banfn = ieban-banfn AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bnfpo = ieban-bnfpo AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loekz = space.
&nbsp; &nbsp; IF iekpo\[\] IS NOT INITIAL.
&nbsp; &nbsp; &nbsp; SELECT * FROM ekko
&nbsp; &nbsp; &nbsp; &nbsp; INTO TABLE iekko
&nbsp; &nbsp; &nbsp; &nbsp; FOR ALL ENTRIES IN iekpo
&nbsp; &nbsp; &nbsp; &nbsp; WHERE ebeln = iekpo-ebeln AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loekz EQ &nbsp;space.
&nbsp; &nbsp; &nbsp; SELECT * FROM ekbe
&nbsp; &nbsp; &nbsp; &nbsp; INTO TABLE iekbe
&nbsp; &nbsp; &nbsp; &nbsp; FOR ALL ENTRIES IN iekpo
&nbsp; &nbsp; &nbsp; &nbsp; WHERE ebeln = iekpo-ebeln AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ebelp = iekpo-ebelp AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bewtp = 'E' AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bwart = '101'. " just take 101, cancelled doc delete later
&nbsp; &nbsp; &nbsp; SELECT ebeln ebelp vbeln vbelp anln1 FROM ekkn INTO TABLE iekkn FOR ALL ENTRIES&nbsp;
IN iekpo
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHERE ebeln = iekpo-ebeln AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ebelp = iekpo-ebelp .
&nbsp; &nbsp; &nbsp; SORT iekkn.
&nbsp; &nbsp; ENDIF.
&nbsp; ENDIF.
\*\- delete cancelled and original docs.
&nbsp; LOOP AT iekbe.
&nbsp; &nbsp; SELECT SINGLE * FROM mseg
&nbsp; &nbsp; &nbsp; WHERE smbln = iekbe-belnr AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; smblp = iekbe-buzei AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sjahr = iekbe-gjahr.
&nbsp; &nbsp; IF sy-subrc = 0.
&nbsp; &nbsp; &nbsp; DELETE iekbe.
&nbsp; &nbsp; &nbsp; CONTINUE.
&nbsp; &nbsp; ENDIF.
&nbsp; ENDLOOP.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" get_PR
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;get_po
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
\* &nbsp;--> &nbsp;p1 &nbsp; &nbsp; &nbsp; &nbsp;text
\* &nbsp;<-\- &nbsp;p2 &nbsp; &nbsp; &nbsp; &nbsp;text
\*----------------------------------------------------------------------\*
FORM get_po .
&nbsp; SELECT * FROM ekko
&nbsp; &nbsp; INTO TABLE iekko WHERE
&nbsp; &nbsp; ebeln IN po_ebeln AND
&nbsp; &nbsp; bsart IN pr_bsart AND
&nbsp; &nbsp; bedat IN s_badat AND
&nbsp; &nbsp; lifnr IN po_lifnr.
&nbsp; IF NOT iekko\[\] IS INITIAL.
&nbsp; &nbsp; SELECT * FROM ekpo
&nbsp; &nbsp; &nbsp; INTO TABLE iekpo
&nbsp; &nbsp; &nbsp; FOR ALL ENTRIES IN iekko
&nbsp; &nbsp; &nbsp; WHERE ebeln = iekko-ebeln AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; matnr IN pr_matnr AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; afnam IN po_afnam AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bednr IN po_bednr AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; knttp IN po_knttp AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pstyp IN po_pstyp AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; werks EQ pr_werks.
&nbsp; &nbsp; SELECT * FROM eban
&nbsp; &nbsp; &nbsp; INTO TABLE ieban
&nbsp; &nbsp; &nbsp; FOR ALL ENTRIES IN iekpo
&nbsp; &nbsp; &nbsp; WHERE banfn = iekpo-banfn AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bnfpo = iekpo-bnfpo.
&nbsp; &nbsp; SELECT * FROM ekbe
&nbsp; &nbsp; &nbsp; INTO TABLE iekbe
&nbsp; &nbsp; &nbsp; FOR ALL ENTRIES IN iekpo
&nbsp; &nbsp; &nbsp; WHERE ebeln = iekpo-ebeln AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ebelp = iekpo-ebelp AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bewtp = 'E'.
&nbsp; &nbsp; SELECT ebeln ebelp vbeln vbelp anln1 FROM ekkn INTO TABLE iekkn FOR ALL ENTRIES&nbsp;
IN iekpo
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHERE ebeln = iekpo-ebeln AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ebelp = iekpo-ebelp .
&nbsp; &nbsp; SORT iekkn.
&nbsp; ENDIF.
\*\- delete cancelled and original docs.
&nbsp; LOOP AT iekbe.
&nbsp; &nbsp; SELECT SINGLE * FROM mseg
&nbsp; &nbsp; &nbsp; WHERE smbln = iekbe-belnr AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; smblp = iekbe-buzei AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sjahr = iekbe-gjahr .
&nbsp; &nbsp; IF sy-subrc EQ 0.
&nbsp; &nbsp; &nbsp; DELETE iekbe.
&nbsp; &nbsp; &nbsp; DELETE iekbe WHERE bwart EQ '102'.
&nbsp; &nbsp; &nbsp; CONTINUE.
&nbsp; &nbsp; ENDIF.
&nbsp; ENDLOOP.
&nbsp; SELECT * FROM j_1iexcdtl INTO TABLE ij_1iexcdtl
&nbsp; FOR ALL ENTRIES IN iekbe
&nbsp; WHERE rdoc1 = iekbe-ebeln
&nbsp; AND &nbsp; rdoc2 &nbsp;= iekbe-belnr .
&nbsp; SELECT * FROM konv
&nbsp; &nbsp; INTO TABLE ikonv
&nbsp; &nbsp; FOR ALL ENTRIES IN iekko
&nbsp; &nbsp; WHERE knumv = iekko-knumv.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" get_po
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;process_po_data
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
\* &nbsp;--> &nbsp;p1 &nbsp; &nbsp; &nbsp; &nbsp;text
\* &nbsp;<-\- &nbsp;p2 &nbsp; &nbsp; &nbsp; &nbsp;text
\*----------------------------------------------------------------------\*
FORM process_po_data .
&nbsp; SORT iekko.
&nbsp; SORT iekpo.
&nbsp; SORT ieban.
&nbsp; SORT iekbe.
&nbsp; LOOP AT iekpo.
&nbsp; &nbsp; CLEAR itab.
&nbsp; &nbsp; READ TABLE iekbe
&nbsp; &nbsp; &nbsp; WITH KEY ebeln = iekpo-ebeln
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ebelp = iekpo-ebelp.
&nbsp; &nbsp; IF sy-subrc = 0.
&nbsp; &nbsp; &nbsp; LOOP AT iekbe WHERE ebeln = iekpo-ebeln AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ebelp = iekpo-ebelp .
&nbsp; &nbsp; &nbsp; &nbsp; PERFORM populate_po_gr_data.
&nbsp; &nbsp; &nbsp; ENDLOOP.
&nbsp; &nbsp; ELSE.
&nbsp; &nbsp; &nbsp; PERFORM populate_po_data.
&nbsp; &nbsp; ENDIF.
&nbsp; ENDLOOP.
&nbsp; CLEAR : itab.
&nbsp; LOOP AT itab.
&nbsp; &nbsp; CLEAR : iekko,temp.
&nbsp; &nbsp; READ TABLE iekko WITH KEY ebeln = itab-ebeln.
&nbsp; &nbsp; IF sy-subrc EQ 0.
&nbsp; &nbsp; &nbsp; LOOP AT ikonv WHERE knumv = iekko-knumv
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND &nbsp; kposn = itab-ebelp.
&nbsp; &nbsp; &nbsp; &nbsp; CASE ikonv-kschl.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 'ZRA0'.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IF ikonv-waers IS INITIAL.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IF ikonv-kbetr < 0.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ikonv-kbetr = &nbsp;ikonv-kbetr * \-1 .
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp = &nbsp; ikonv-kbetr / 10 .
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; itab-disc1 = &nbsp;itab-disc1 + temp .
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; itab-disc2 = itab-disc2 + ikonv-kwert.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 'ZRA1'.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IF ikonv-waers IS INITIAL.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IF ikonv-kbetr < 0.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ikonv-kbetr = &nbsp;ikonv-kbetr * \-1 .
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp = &nbsp; ikonv-kbetr / 10 .
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; itab-disc1 = &nbsp;itab-disc1 + temp .
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; itab-disc2 = itab-disc2 + ikonv-kwert.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 'ZRB0'.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IF ikonv-waers IS INITIAL.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IF ikonv-kbetr < 0.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ikonv-kbetr = &nbsp;ikonv-kbetr * \-1 .
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp = &nbsp; ikonv-kbetr / 10 .
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; itab-disc1 = &nbsp;itab-disc1 + temp .
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; itab-disc2 = itab-disc2 + ikonv-kwert.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 'ZRC0'.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IF ikonv-waers IS INITIAL.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IF ikonv-kbetr < 0.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ikonv-kbetr = &nbsp;ikonv-kbetr * \-1 .
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp = &nbsp; ikonv-kbetr / 10 .
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; itab-disc1 = &nbsp;itab-disc1 + temp .
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; itab-disc2 = itab-disc2 + ikonv-kwert.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 'ZTAX'.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; itab-tax = itab-tax + ikonv-kwert.
&nbsp; &nbsp; &nbsp; &nbsp; ENDCASE.
&nbsp; &nbsp; &nbsp; ENDLOOP.
&nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; itab-disc2 = itab-disc2 * \-1 .
&nbsp; &nbsp; MODIFY itab TRANSPORTING disc1 disc2 tax .
&nbsp; &nbsp; CLEAR itab.
&nbsp; ENDLOOP.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" process_po_data
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;get_pr_details
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
\* &nbsp;--> &nbsp;p1 &nbsp; &nbsp; &nbsp; &nbsp;text
\* &nbsp;<-\- &nbsp;p2 &nbsp; &nbsp; &nbsp; &nbsp;text
\*----------------------------------------------------------------------\*
FORM get_pr_details .
&nbsp; DATA : v_tabkey LIKE cdpos-tabkey.
&nbsp; CLEAR v_tabkey.
&nbsp; READ TABLE ieban
&nbsp; &nbsp; WITH KEY banfn = iekpo-banfn
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bnfpo = iekpo-bnfpo
&nbsp; &nbsp; BINARY SEARCH.
&nbsp; IF sy-subrc = 0.
&nbsp; &nbsp; MOVE ieban-bednr TO itab-bednr_pr.
&nbsp; &nbsp; MOVE ieban-banfn TO itab-banfn.
&nbsp; &nbsp; MOVE ieban-bnfpo TO itab-bnfpo.
&nbsp; &nbsp; MOVE ieban-badat TO itab-badat.
&nbsp; &nbsp; MOVE ieban-ekgrp TO itab-ekgrp.
&nbsp; &nbsp; MOVE ieban-matkl TO itab-matkl.
&nbsp; &nbsp; MOVE ieban-matnr TO itab-matnr_pr.
&nbsp; &nbsp; MOVE ieban-txz01 TO itab-txz01_pr.
&nbsp; &nbsp; MOVE ieban-pstyp TO itab-pstyp_pr.
&nbsp; &nbsp; MOVE ieban-knttp TO itab-knttp_pr.
&nbsp; &nbsp; MOVE ieban-menge TO itab-menge_pr.
&nbsp; &nbsp; MOVE ieban-meins TO itab-meins_pr.
&nbsp; &nbsp; CASE ieban-frgkz.
&nbsp; &nbsp; &nbsp; WHEN 'S'.
&nbsp; &nbsp; &nbsp; &nbsp; CLEAR v_tabkey.
&nbsp; &nbsp; &nbsp; &nbsp; CONCATENATE sy-mandt ieban-banfn ieban-bnfpo INTO v_tabkey.
&nbsp; &nbsp; &nbsp; &nbsp; SELECT SINGLE * FROM cdpos
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE objectclas = 'BANF' AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; objectid = ieban-banfn AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tabname = 'EBAN' AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tabkey = v_tabkey AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fname = 'FRGKZ' AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value_new = 'S'.
&nbsp; &nbsp; &nbsp; &nbsp; IF sy-subrc = 0.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SELECT SINGLE * FROM cdhdr
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHERE &nbsp;objectclas EQ cdpos-objectclas AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; objectid &nbsp; EQ cdpos-objectid &nbsp; AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; changenr EQ cdpos-changenr &nbsp; &nbsp; AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ( tcode EQ 'ME54' OR
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tcode EQ 'ME54N').
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IF sy-subrc = 0.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MOVE 'Blocked' TO itab-release_pr.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp; WHEN 'F' OR 'C'.
&nbsp; &nbsp; &nbsp; &nbsp; CLEAR v_tabkey.
&nbsp; &nbsp; &nbsp; &nbsp; CONCATENATE sy-mandt ieban-banfn ieban-bnfpo INTO v_tabkey.
&nbsp; &nbsp; &nbsp; &nbsp; SELECT SINGLE * FROM cdpos
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE objectclas = 'BANF' AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; objectid = ieban-banfn AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tabname = 'EBAN' AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tabkey = v_tabkey AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fname = 'FRGKZ' AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value_new = 'F'.
&nbsp; &nbsp; &nbsp; &nbsp; IF sy-subrc = 0.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SELECT SINGLE * FROM cdhdr
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHERE &nbsp;objectclas EQ cdpos-objectclas AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; objectid &nbsp; EQ cdpos-objectid &nbsp; AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; changenr EQ cdpos-changenr &nbsp; &nbsp; AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ( tcode EQ 'ME54' OR
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tcode EQ 'ME54N').
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IF sy-subrc = 0.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MOVE 'Forwarded' TO itab-release_pr.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MOVE cdhdr-udate TO itab-udate_pr.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; ENDCASE.
&nbsp; ENDIF.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" get_pr_details
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;process_pr_data
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
\* &nbsp;--> &nbsp;p1 &nbsp; &nbsp; &nbsp; &nbsp;text
\* &nbsp;<-\- &nbsp;p2 &nbsp; &nbsp; &nbsp; &nbsp;text
\*----------------------------------------------------------------------\*
FORM process_pr_data .
&nbsp; SORT ieban.
&nbsp; SORT iekko.
&nbsp; SORT iekpo BY banfn bnfpo.
&nbsp; SORT iekbe.
&nbsp; SORT iekkn.
&nbsp; LOOP AT ieban.
&nbsp; &nbsp; CLEAR itab.
\*\- Check at least one PO item is created for this PR item else populate
\*just PR data.
&nbsp; &nbsp; READ TABLE iekpo
&nbsp; &nbsp; &nbsp; WITH KEY banfn = ieban-banfn
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bnfpo = ieban-bnfpo
&nbsp; &nbsp; &nbsp; BINARY SEARCH.
&nbsp; &nbsp; IF sy-subrc = 0.
&nbsp; &nbsp; &nbsp; LOOP AT iekpo WHERE banfn = ieban-banfn AND bnfpo = ieban-bnfpo.
\*\- Read table iekbe if at least 1 GR happened for PO item else populate
\*PO data only.
&nbsp; &nbsp; &nbsp; &nbsp; READ TABLE iekbe
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WITH KEY ebeln = iekpo-ebeln
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ebelp = iekpo-ebelp
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BINARY SEARCH.
&nbsp; &nbsp; &nbsp; &nbsp; IF sy-subrc = 0.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOOP AT iekbe WHERE ebeln = iekpo-ebeln AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ebelp = iekpo-ebelp.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PERFORM populate_data_pr_po_gr.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ENDLOOP.
&nbsp; &nbsp; &nbsp; &nbsp; ELSE.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PERFORM populate_data_pr_po.
&nbsp; &nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp; ENDLOOP.
&nbsp; &nbsp; ELSE.
&nbsp; &nbsp; &nbsp; PERFORM populate_data_pr.
&nbsp; &nbsp; ENDIF.
&nbsp; ENDLOOP.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" process_pr_data
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;get_PO_release_status
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
\* &nbsp;--> &nbsp;p1 &nbsp; &nbsp; &nbsp; &nbsp;text
\* &nbsp;<-\- &nbsp;p2 &nbsp; &nbsp; &nbsp; &nbsp;text
\*----------------------------------------------------------------------\*
FORM get_po_release_status .
&nbsp; DATA : v_tabkey LIKE cdpos-tabkey.
&nbsp; CLEAR v_tabkey.
&nbsp; CONCATENATE sy-mandt iekko-ebeln INTO v_tabkey.
&nbsp; CASE iekko-frgke.
&nbsp; &nbsp; WHEN '3'.
&nbsp; &nbsp; &nbsp; REFRESH icdpos.
&nbsp; &nbsp; &nbsp; SELECT * FROM cdpos
&nbsp; &nbsp; &nbsp; &nbsp; INTO TABLE icdpos
&nbsp; &nbsp; &nbsp; &nbsp; WHERE objectclas = 'EINKBELEG' AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; objectid = iekko-ebeln AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tabname = 'EKKO' AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tabkey = v_tabkey AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fname = 'FRGKE' AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value_new = '3'.
&nbsp; &nbsp; &nbsp; SORT icdpos BY changenr DESCENDING.
&nbsp; &nbsp; &nbsp; READ TABLE icdpos INDEX 1.
&nbsp; &nbsp; &nbsp; SELECT SINGLE * FROM cdhdr
&nbsp; &nbsp; &nbsp; &nbsp; WHERE &nbsp;objectclas EQ icdpos-objectclas AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;objectid &nbsp; EQ icdpos-objectid &nbsp; AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;changenr EQ icdpos-changenr &nbsp; &nbsp; AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;( tcode EQ 'ME22'
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OR tcode EQ 'ME28'
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OR tcode EQ 'ME29N' ).
&nbsp; &nbsp; &nbsp; WRITE cdhdr-udate TO itab-release_po.
&nbsp; &nbsp; WHEN 'S'.
&nbsp; &nbsp; &nbsp; MOVE 'Not Rel' TO itab-release_po.
&nbsp; &nbsp; WHEN OTHERS.
&nbsp; &nbsp; &nbsp; MOVE 'Forwarded' TO itab-release_po.
&nbsp; ENDCASE.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" get_PO_release_status
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;build_comment
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp;-->P_HEADING\[\] &nbsp;text
\*----------------------------------------------------------------------\*
FORM build_comment USING p_heading TYPE slis_t_listheader.
&nbsp; DATA: hline TYPE slis_listheader.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" build_comment
\**&--------------------------------------------------------------------\*
\**& &nbsp; &nbsp; &nbsp;Form &nbsp;top_of_page
\**&--------------------------------------------------------------------\*
\*\* &nbsp; &nbsp; &nbsp; text
\**---------------------------------------------------------------------\*
FORM top_of_page.
&nbsp; CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
&nbsp; &nbsp; EXPORTING
&nbsp; &nbsp; &nbsp; it_list_commentary = heading.
&nbsp; DATA: plant LIKE ekpo-werks,
&nbsp; &nbsp; &nbsp; &nbsp; matnum LIKE eban-matnr,
&nbsp; &nbsp; &nbsp; &nbsp; plantname(50).
&nbsp; SELECT SINGLE werks FROM ekpo INTO plant &nbsp;WHERE werks = pr_werks.
&nbsp; SELECT SINGLE matnr FROM eban INTO matnum WHERE matnr = pr_matnr-low.
&nbsp; SELECT SINGLE name1 FROM t001w INTO plantname WHERE werks = pr_werks.
&nbsp; IF p_pr = 'X'.
&nbsp; &nbsp; WRITE: &nbsp;/5 'PR to IR List',
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /5 'Plant &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: ', pr_werks,plantname,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /5 'For the Period : ', s_badat-low, &nbsp;' To ',s_badat-high.
&nbsp; ELSE.
&nbsp; &nbsp; WRITE: &nbsp;/5 'PR - PO - GR - IR Tracking Report',
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /5 'Plant &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: - ', pr_werks,plantname,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /5 'For the Period : - ', s_badat-low, &nbsp;' To ',s_badat-high.
&nbsp; ENDIF.
&nbsp; SKIP.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"top_of_page
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;build_eventtab
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp;-->P_EVENTS\[\] &nbsp;text
\*----------------------------------------------------------------------\*
FORM build_eventtab USING p_events TYPE slis_t_event.
&nbsp; DATA: ls_event TYPE slis_alv_event.
&nbsp; CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
&nbsp; &nbsp; EXPORTING
&nbsp; &nbsp; &nbsp; i_list_type = 0
&nbsp; &nbsp; IMPORTING
&nbsp; &nbsp; &nbsp; et_events &nbsp; = p_events.
&nbsp; READ TABLE p_events WITH KEY name = slis_ev_top_of_page
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;INTO ls_event.
&nbsp; IF sy-subrc = 0.
&nbsp; &nbsp; MOVE formname_top_of_page TO ls_event-form.
&nbsp; &nbsp; APPEND ls_event TO p_events.
&nbsp; ENDIF.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" build_eventtab
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;build_layout
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
\* &nbsp;--> &nbsp;p1 &nbsp; &nbsp; &nbsp; &nbsp;text
\* &nbsp;<-\- &nbsp;p2 &nbsp; &nbsp; &nbsp; &nbsp;text
\*----------------------------------------------------------------------\*
FORM build_layout .
&nbsp; layout-zebra &nbsp; &nbsp; &nbsp; &nbsp;= 'X'.
&nbsp; layout-detail_popup = 'X'.
&nbsp; layout-coltab_fieldname = 'COLOR'.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" build_layout
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;field_cat_fill
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp;-->P_GT_FIELDCAT\[\] &nbsp;text
\*----------------------------------------------------------------------\*
FORM field_cat_fill USING gt_fieldcat TYPE slis_t_fieldcat_alv.
&nbsp; DATA: vl_pos TYPE i,
&nbsp; &nbsp; &nbsp; &nbsp; ls_fieldcat TYPE slis_fieldcat_alv.
&nbsp; CLEAR : ls_fieldcat.
&nbsp; ls_fieldcat-key = 'X'.
&nbsp; ls_fieldcat-fieldname = 'SLNO'.
&nbsp; ls_fieldcat-ref_fieldname = 'SLNO'.
&nbsp; ls_fieldcat-seltext_m = 'SL.NO'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'BANFN'.
&nbsp; ls_fieldcat-ref_fieldname = 'BANFN'.
&nbsp; ls_fieldcat-ref_tabname = 'EBAN'.
&nbsp; ls_fieldcat-seltext_m = 'PReq.No'.
&nbsp; ls_fieldcat-hotspot = 'X' .
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'BNFPO'.
&nbsp; ls_fieldcat-ref_fieldname = 'BNFPO'.
&nbsp; ls_fieldcat-ref_tabname = 'EBAN'.
&nbsp; ls_fieldcat-seltext_m = 'PR ItemNo'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'BADAT'.
&nbsp; ls_fieldcat-ref_fieldname = 'BADAT'.
&nbsp; ls_fieldcat-ref_tabname = 'EBAN'.
&nbsp; ls_fieldcat-seltext_m = 'PR Date'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'FRGDT'.
&nbsp; ls_fieldcat-ref_fieldname = 'FRGDT'.
&nbsp; ls_fieldcat-ref_tabname = 'EBAN'.
&nbsp; ls_fieldcat-seltext_m = 'Relase Date'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'EKGRP'.
&nbsp; ls_fieldcat-ref_fieldname = 'EKGRP'.
&nbsp; ls_fieldcat-ref_tabname = 'EBAN'.
&nbsp; ls_fieldcat-seltext_m = 'PGrp'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'MATKL'.
&nbsp; ls_fieldcat-ref_fieldname = 'MATKL'.
&nbsp; ls_fieldcat-ref_tabname = 'EBAN'.
&nbsp; ls_fieldcat-seltext_m = 'MGrp'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'MATNR_PR'.
&nbsp; ls_fieldcat-ref_fieldname = 'MATNR'.
&nbsp; ls_fieldcat-ref_tabname = 'EBAN'.
&nbsp; ls_fieldcat-seltext_m = 'Material'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'EPSTP'.
&nbsp; ls_fieldcat-ref_fieldname = 'EPSTP'.
&nbsp; ls_fieldcat-ref_tabname = 'EBAN'.
&nbsp; ls_fieldcat-seltext_m = 'IC'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'TXZ01_PR'.
&nbsp; ls_fieldcat-ref_fieldname = 'TXZ01'.
&nbsp; ls_fieldcat-ref_tabname = 'EBAN'.
&nbsp; ls_fieldcat-seltext_m = 'PR MAT Description'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'MENGE_PR'.
&nbsp; ls_fieldcat-ref_fieldname = 'MENGE'.
&nbsp; ls_fieldcat-ref_tabname = 'EBAN'.
&nbsp; ls_fieldcat-seltext_m = 'PR Qty'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'MEINS_PR'.
&nbsp; ls_fieldcat-ref_fieldname = 'MEINS'.
&nbsp; ls_fieldcat-ref_tabname = 'EBAN'.
&nbsp; ls_fieldcat-seltext_m = 'UoM'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'EBELN'.
&nbsp; ls_fieldcat-ref_fieldname = 'EBELN'.
&nbsp; ls_fieldcat-ref_tabname = 'EKPO'.
&nbsp; ls_fieldcat-seltext_m = 'PO Number'.
&nbsp; ls_fieldcat-hotspot = 'X' .
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'EBELP'.
&nbsp; ls_fieldcat-ref_fieldname = 'EBELP'.
&nbsp; ls_fieldcat-ref_tabname = 'EKPO'.
&nbsp; ls_fieldcat-seltext_m = 'PO Item'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'BEDAT'.
&nbsp; ls_fieldcat-ref_fieldname = 'BEDAT'.
&nbsp; ls_fieldcat-ref_tabname = 'EKKO'.
&nbsp; ls_fieldcat-seltext_m = 'PO Date'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'RELEASE_PO'.
&nbsp; ls_fieldcat-seltext_m = 'Rel.Status'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'NAME1'.
&nbsp; ls_fieldcat-ref_fieldname = 'NAME1'.
&nbsp; ls_fieldcat-ref_tabname = 'LFA1'.
&nbsp; ls_fieldcat-seltext_m = 'Vendor Name'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'MATNR_PO'.
&nbsp; ls_fieldcat-ref_fieldname = 'MATNR'.
&nbsp; ls_fieldcat-ref_tabname = 'EKPO'.
&nbsp; ls_fieldcat-seltext_s =
&nbsp; ls_fieldcat-seltext_m =
&nbsp; ls_fieldcat-seltext_l = 'PO Material Code'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'TXZ01_PO'.
&nbsp; ls_fieldcat-ref_fieldname = 'TXZ01'.
&nbsp; ls_fieldcat-ref_tabname = 'EKPO'.
&nbsp; ls_fieldcat-seltext_m = 'PO MAT Description'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'MENGE_PO'.
&nbsp; ls_fieldcat-ref_fieldname = 'MENGE_PO'.
&nbsp; ls_fieldcat-ref_tabname = 'EKPO'.
&nbsp; ls_fieldcat-seltext_m = 'OrdQty'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'MEINS_PO'.
&nbsp; ls_fieldcat-ref_fieldname = 'MEINS_PO'.
&nbsp; ls_fieldcat-ref_tabname = 'EKPO'.
&nbsp; ls_fieldcat-seltext_m = 'UoM'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'EINDT'.
&nbsp; ls_fieldcat-ref_fieldname = 'EINDT'.
&nbsp; ls_fieldcat-ref_tabname = 'EKET'.
&nbsp; ls_fieldcat-seltext_m = 'DeliveryDate'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'BELNR'.
&nbsp; ls_fieldcat-ref_fieldname = 'BELNR'.
&nbsp; ls_fieldcat-ref_tabname = 'EKBE'.
&nbsp; ls_fieldcat-seltext_m = 'GR No'.
&nbsp; ls_fieldcat-hotspot = 'X' .
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'BUDAT'.
&nbsp; ls_fieldcat-ref_fieldname = 'BUDAT'.
&nbsp; ls_fieldcat-ref_tabname = 'EKBE'.
&nbsp; ls_fieldcat-seltext_m = 'GR Date'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'MENGE_GR'.
&nbsp; ls_fieldcat-ref_fieldname = 'MENGE'.
&nbsp; ls_fieldcat-ref_tabname = 'EKBE'.
&nbsp; ls_fieldcat-seltext_m = 'GR Qty'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'IRNO'.
&nbsp; ls_fieldcat-seltext_m = 'IR No.'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'IRDT'.
&nbsp; ls_fieldcat-ref_fieldname = 'BUDAT'.
&nbsp; ls_fieldcat-ref_tabname = 'RBKP'.
&nbsp; ls_fieldcat-seltext_m = 'IR Date.'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'IRIT'.
&nbsp; ls_fieldcat-ref_fieldname = 'BUZEI'.
&nbsp; ls_fieldcat-ref_tabname = 'RSEG'.
&nbsp; ls_fieldcat-seltext_m = 'IR Item'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-tabname = 'itab'.
&nbsp; ls_fieldcat-fieldname = 'IRVAL'.
&nbsp; ls_fieldcat-seltext_m = 'IR Value'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'RFQNO'.
&nbsp; ls_fieldcat-seltext_m = 'RFQ No.'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'RFQDT'.
&nbsp; ls_fieldcat-seltext_m = 'RFQ Date'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'RFQIT'.
&nbsp; ls_fieldcat-seltext_m = 'RFQ Item'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'BSART'.
&nbsp; ls_fieldcat-seltext_l = 'PO Type'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-tabname = 'itab'.
&nbsp; ls_fieldcat-fieldname = 'NETPR' .
&nbsp; ls_fieldcat-seltext_l = 'PO Rate'.
&nbsp; ls_fieldcat-cfieldname &nbsp;= 'WAERS' .
&nbsp; ls_fieldcat-ctabname = 'EKKO' .
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-tabname = 'itab'.
&nbsp; ls_fieldcat-fieldname = 'POAMT' .
&nbsp; ls_fieldcat-seltext_l = 'PO Amount'.
&nbsp; ls_fieldcat-cfieldname &nbsp;= 'WAERS' .
&nbsp; ls_fieldcat-ctabname = 'EKKO' .
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-tabname = 'itab'.
&nbsp; ls_fieldcat-fieldname = 'WAERS' .
&nbsp; ls_fieldcat-ref_fieldname = 'WAERS'.
&nbsp; ls_fieldcat-ref_tabname = 'TCURC'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'VBELN' .
&nbsp; ls_fieldcat-seltext_l = 'SD Document'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'VBELP' .
&nbsp; ls_fieldcat-seltext_l = 'SD Item'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'DISC1' .
&nbsp; ls_fieldcat-ref_fieldname = 'KONV'.
&nbsp; ls_fieldcat-ref_tabname = 'KBETR'.
&nbsp; ls_fieldcat-seltext_l = 'Discount Per'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-tabname = 'itab'.
&nbsp; ls_fieldcat-fieldname = 'DISC2' .
&nbsp; ls_fieldcat-ref_fieldname = 'KONV'.
&nbsp; ls_fieldcat-ref_tabname = 'KWERT'.
&nbsp; ls_fieldcat-seltext_l = 'Discount Value'.
&nbsp; ls_fieldcat-cfieldname &nbsp;= 'WAERS' .
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-tabname = 'itab'.
&nbsp; ls_fieldcat-fieldname = 'TAX' .
&nbsp; ls_fieldcat-ref_fieldname = 'KONV'.
&nbsp; ls_fieldcat-ref_tabname = 'KWERT'.
&nbsp; ls_fieldcat-seltext_l = 'Tax Amount'.
&nbsp; ls_fieldcat-cfieldname &nbsp;= 'WAERS' .
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-tabname = 'itab'.
&nbsp; ls_fieldcat-fieldname = 'GRNAMT' .
&nbsp; ls_fieldcat-seltext_l = 'Grn Amount'.
&nbsp; ls_fieldcat-cfieldname &nbsp;= 'EXCUR' .
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-tabname = 'itab'.
&nbsp; ls_fieldcat-fieldname = 'EXAED' .
&nbsp; ls_fieldcat-seltext_l = 'AED'.
&nbsp; ls_fieldcat-cfieldname &nbsp;= 'EXCUR' .
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-tabname = 'itab'.
&nbsp; ls_fieldcat-fieldname = 'GRNTAX' .
&nbsp; ls_fieldcat-ref_fieldname = 'EXBED'.
&nbsp; ls_fieldcat-ref_tabname = 'J_1IEXCDTL'.
&nbsp; ls_fieldcat-seltext_l = 'Total GRN Tax'.
&nbsp; ls_fieldcat-cfieldname &nbsp;= 'EXCUR' .
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'IRQTY' .
&nbsp; ls_fieldcat-seltext_l = 'IR qty'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-tabname = 'itab'.
&nbsp; ls_fieldcat-fieldname = 'IRNETPR' .
&nbsp; ls_fieldcat-ref_fieldname = 'WRBTR'.
&nbsp; ls_fieldcat-ref_tabname = 'RSEG'.
&nbsp; ls_fieldcat-seltext_l = 'Invoice Rate'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-tabname = 'itab'.
&nbsp; ls_fieldcat-fieldname = 'IRAMT' .
&nbsp; ls_fieldcat-ref_fieldname = 'RMWWR'.
&nbsp; ls_fieldcat-ref_tabname = 'RBKP'.
&nbsp; ls_fieldcat-seltext_l = 'Invoice Tax'. "'Invoice Amount'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-tabname = 'itab'.
&nbsp; ls_fieldcat-fieldname = 'SALTAX' .
&nbsp; ls_fieldcat-seltext_m = 'Sales Tax (VAT)'.
&nbsp; ls_fieldcat-cfieldname &nbsp;= 'WAERS' .
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-tabname = 'itab'.
&nbsp; ls_fieldcat-fieldname = 'CST' .
&nbsp; ls_fieldcat-just = 'C' .
&nbsp; ls_fieldcat-seltext_m = 'CST'.
&nbsp; ls_fieldcat-cfieldname &nbsp;= 'WAERS' .
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
&nbsp; ls_fieldcat-fieldname = 'ANLN1' .
&nbsp; ls_fieldcat-ref_fieldname = 'ANLN1'.
&nbsp; ls_fieldcat-ref_tabname = 'EKKN'.
&nbsp; ls_fieldcat-seltext_l = 'Asset Id'.
&nbsp; APPEND ls_fieldcat TO gt_fieldcat.
&nbsp; CLEAR ls_fieldcat.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" field_cat_fill
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;write_ALV
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
\* &nbsp;--> &nbsp;p1 &nbsp; &nbsp; &nbsp; &nbsp;text
\* &nbsp;<-\- &nbsp;p2 &nbsp; &nbsp; &nbsp; &nbsp;text
\*----------------------------------------------------------------------\*
FORM write_alv .
&nbsp; LOOP AT itab.
&nbsp; &nbsp; itab-slno = sy-tabix.
&nbsp; &nbsp; IF itab-pstyp_pr IS NOT INITIAL.
&nbsp; &nbsp; &nbsp; CALL FUNCTION 'ME_ITEM_CATEGORY_OUTPUT'
&nbsp; &nbsp; &nbsp; &nbsp; EXPORTING
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pstyp &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = itab-pstyp_pr
&nbsp; &nbsp; &nbsp; &nbsp;IMPORTING
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;epstp &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = itab-epstp
\* &nbsp; &nbsp; &nbsp;PTEXT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp; &nbsp; &nbsp; &nbsp;EXCEPTIONS
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;not_found &nbsp; &nbsp; &nbsp; = 1
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OTHERS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 2.
&nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT'
&nbsp; &nbsp; &nbsp; EXPORTING
&nbsp; &nbsp; &nbsp; &nbsp; input &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= itab-meins_po
&nbsp; &nbsp; &nbsp; &nbsp;language &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = sy-langu
&nbsp; &nbsp; &nbsp;IMPORTING
\* &nbsp; &nbsp; &nbsp; LONG_TEXT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=
&nbsp; &nbsp; &nbsp; &nbsp;output &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = itab-meins_po
\* &nbsp; &nbsp; &nbsp; SHORT_TEXT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp; &nbsp; &nbsp;EXCEPTIONS
&nbsp; &nbsp; &nbsp; &nbsp;unit_not_found &nbsp; &nbsp; &nbsp; = 1
&nbsp; &nbsp; &nbsp; &nbsp;OTHERS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 2.
&nbsp; &nbsp; PERFORM get_irdetail.
&nbsp; &nbsp; IF NOT itab-lifnr IS INITIAL.
&nbsp; &nbsp; &nbsp; CLEAR lfa1.
&nbsp; &nbsp; &nbsp; SELECT SINGLE name1 FROM lfa1 INTO itab-name1
&nbsp; &nbsp; &nbsp; &nbsp; WHERE lifnr = itab-lifnr.
&nbsp; &nbsp; ELSE.
&nbsp; &nbsp; &nbsp; CLEAR t001w.
&nbsp; &nbsp; &nbsp; READ TABLE iekko WITH KEY ebeln = itab-ebeln.
&nbsp; &nbsp; &nbsp; SELECT SINGLE name1 FROM t001w INTO itab-name1
&nbsp; &nbsp; &nbsp; &nbsp; WHERE werks = iekko-reswk.
&nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; SELECT SINGLE matnr FROM ekpo
&nbsp; &nbsp; &nbsp; INTO itab-matnr_po
&nbsp; &nbsp; &nbsp; WHERE ebeln EQ itab-ebeln
&nbsp; &nbsp; &nbsp; AND &nbsp; ebelp EQ itab-ebelp.
&nbsp; &nbsp; MODIFY itab.
&nbsp; &nbsp; CLEAR itab.
&nbsp; ENDLOOP.
&nbsp; CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
&nbsp; &nbsp; EXPORTING
&nbsp; &nbsp; &nbsp; i_callback_program &nbsp; &nbsp; &nbsp;= repname
&nbsp; &nbsp; &nbsp; i_buffer_active &nbsp; &nbsp; &nbsp; &nbsp; = ' '
&nbsp; &nbsp; &nbsp; i_callback_user_command = 'USER_COMMAND'
&nbsp; &nbsp; &nbsp; is_layout &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = layout
&nbsp; &nbsp; &nbsp; it_fieldcat &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = gt_fieldcat\[\]
&nbsp; &nbsp; &nbsp; i_default &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 'X'
&nbsp; &nbsp; &nbsp; i_save &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= g_save
&nbsp; &nbsp; &nbsp; is_variant &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= g_variant
&nbsp; &nbsp; &nbsp; it_events &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = events\[\]
&nbsp; &nbsp; &nbsp; is_print &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= alv_print
&nbsp; &nbsp; TABLES
&nbsp; &nbsp; &nbsp; t_outtab &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= itab
&nbsp; &nbsp; EXCEPTIONS
&nbsp; &nbsp; &nbsp; program_error &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 1
&nbsp; &nbsp; &nbsp; OTHERS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 2.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" write_ALV
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;Populate_data_PR_PO_GR
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
\* &nbsp;--> &nbsp;p1 &nbsp; &nbsp; &nbsp; &nbsp;text
\* &nbsp;<-\- &nbsp;p2 &nbsp; &nbsp; &nbsp; &nbsp;text
\*----------------------------------------------------------------------\*
FORM populate_data_pr_po_gr .
&nbsp; CLEAR itab.
&nbsp; MOVE ieban-bednr TO itab-bednr_pr.
&nbsp; MOVE ieban-banfn TO itab-banfn.
&nbsp; MOVE ieban-bnfpo TO itab-bnfpo.
&nbsp; MOVE ieban-badat TO itab-badat.
&nbsp; MOVE ieban-frgdt TO itab-frgdt.
&nbsp; MOVE ieban-ekgrp TO itab-ekgrp.
&nbsp; MOVE ieban-matkl TO itab-matkl.
&nbsp; MOVE ieban-matnr TO itab-matnr_pr.
&nbsp; MOVE ieban-pstyp TO itab-pstyp_pr.
&nbsp; MOVE ieban-knttp TO itab-knttp_pr.
&nbsp; MOVE ieban-txz01 TO itab-txz01_pr.
&nbsp; MOVE ieban-menge TO itab-menge_pr.
&nbsp; MOVE ieban-meins TO itab-meins_pr.
&nbsp; MOVE iekpo-ebeln TO itab-ebeln .
&nbsp; MOVE iekpo-ebelp TO itab-ebelp.
&nbsp; READ TABLE iekko WITH KEY ebeln = iekpo-ebeln BINARY SEARCH.
&nbsp; MOVE iekko-bedat TO itab-bedat.
&nbsp; MOVE &nbsp;iekko-waers TO itab-waers.
&nbsp; PERFORM get_po_release_status.
&nbsp; MOVE iekko-lifnr TO itab-lifnr.
&nbsp; MOVE iekpo-txz01 TO itab-txz01_po.
&nbsp; MOVE iekpo-menge TO itab-menge_po.
&nbsp; MOVE iekpo-meins TO itab-meins_po.
&nbsp; MOVE iekko-bsart TO itab-bsart.
&nbsp; MOVE iekpo-netpr TO itab-netpr.
&nbsp; temp_qty = itab-menge_po .
&nbsp; itab-poamt &nbsp;= temp_qty * itab-netpr .
&nbsp; READ TABLE iekkn WITH KEY ebeln = iekpo-ebeln
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ebelp = iekpo-ebelp BINARY SEARCH.
&nbsp; IF sy-subrc EQ 0 .
&nbsp; &nbsp; itab-vbeln = iekkn-vbeln.
&nbsp; &nbsp; itab-vbelp = iekkn-vbelp.
&nbsp; &nbsp; itab-anln1 = iekkn-anln1.
&nbsp; ENDIF.
&nbsp; CLEAR eket.
&nbsp; SELECT SINGLE * FROM eket
&nbsp; &nbsp; WHERE ebeln = iekpo-ebeln AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ebelp = iekpo-ebelp.
&nbsp; MOVE eket-eindt TO itab-eindt.
&nbsp; SELECT SINGLE * FROM lfa1
&nbsp; &nbsp; WHERE lifnr = iekko-lifnr.
&nbsp; MOVE lfa1-name1 TO itab-name1.
&nbsp; MOVE iekbe-belnr TO itab-belnr.
&nbsp; MOVE iekbe-budat TO itab-budat.
&nbsp; MOVE iekbe-menge TO itab-menge_gr.
&nbsp; APPEND itab.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" Populate_data_PR_PO_GR
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;populate_data_PR_PO
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
\* &nbsp;--> &nbsp;p1 &nbsp; &nbsp; &nbsp; &nbsp;text
\* &nbsp;<-\- &nbsp;p2 &nbsp; &nbsp; &nbsp; &nbsp;text
\*----------------------------------------------------------------------\*
FORM populate_data_pr_po .
&nbsp; CLEAR itab.
&nbsp; MOVE ieban-bednr TO itab-bednr_pr.
&nbsp; MOVE ieban-banfn TO itab-banfn.
&nbsp; MOVE ieban-bnfpo TO itab-bnfpo.
&nbsp; MOVE ieban-badat TO itab-badat.
&nbsp; MOVE ieban-frgdt TO itab-frgdt.
&nbsp; MOVE ieban-ekgrp TO itab-ekgrp.
&nbsp; MOVE ieban-matkl TO itab-matkl.
&nbsp; MOVE ieban-matnr TO itab-matnr_pr.
&nbsp; MOVE ieban-pstyp TO itab-pstyp_pr.
&nbsp; MOVE ieban-knttp TO itab-knttp_pr.
&nbsp; MOVE ieban-txz01 TO itab-txz01_pr.
&nbsp; MOVE ieban-menge TO itab-menge_pr.
&nbsp; MOVE ieban-meins TO itab-meins_pr.
&nbsp; MOVE iekpo-ebeln TO itab-ebeln.
&nbsp; MOVE iekpo-ebelp TO itab-ebelp.
&nbsp; READ TABLE iekko WITH KEY ebeln = iekpo-ebeln BINARY SEARCH.
&nbsp; MOVE iekko-bedat TO itab-bedat.
&nbsp; MOVE &nbsp;iekko-waers TO itab-waers.
&nbsp; PERFORM get_po_release_status.
&nbsp; MOVE iekko-lifnr TO itab-lifnr.
&nbsp; MOVE iekpo-txz01 TO itab-txz01_po.
&nbsp; MOVE iekpo-menge TO itab-menge_po.
&nbsp; MOVE iekpo-meins TO itab-meins_po.
&nbsp; MOVE iekko-bsart TO itab-bsart.
&nbsp; MOVE iekpo-netpr TO itab-netpr.
&nbsp; itab-poamt &nbsp;= itab-menge_po * itab-netpr .
&nbsp; READ TABLE iekkn WITH KEY ebeln = iekpo-ebeln
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ebelp = iekpo-ebelp BINARY SEARCH.
&nbsp; IF sy-subrc EQ 0 .
&nbsp; &nbsp; itab-vbeln = iekkn-vbeln.
&nbsp; &nbsp; itab-vbelp = iekkn-vbelp.
&nbsp; &nbsp; itab-anln1 = iekkn-anln1.
&nbsp; ENDIF.
&nbsp; CLEAR eket.
&nbsp; SELECT SINGLE * FROM eket
&nbsp; &nbsp; WHERE ebeln = iekpo-ebeln AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ebelp = iekpo-ebelp.
&nbsp; MOVE eket-eindt TO itab-eindt.
&nbsp; SELECT SINGLE * FROM lfa1
&nbsp; &nbsp; WHERE lifnr = iekko-lifnr.
&nbsp; MOVE lfa1-name1 TO itab-name1.
&nbsp; APPEND itab.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" populate_data_PR_PO
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;populate_data_PR
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
\* &nbsp;--> &nbsp;p1 &nbsp; &nbsp; &nbsp; &nbsp;text
\* &nbsp;<-\- &nbsp;p2 &nbsp; &nbsp; &nbsp; &nbsp;text
\*----------------------------------------------------------------------\*
FORM populate_data_pr .
&nbsp; CLEAR itab.
&nbsp; MOVE ieban-bednr TO itab-bednr_pr.
&nbsp; MOVE ieban-banfn TO itab-banfn.
&nbsp; MOVE ieban-bnfpo TO itab-bnfpo.
&nbsp; MOVE ieban-badat TO itab-badat.
&nbsp; MOVE ieban-frgdt TO itab-frgdt.
&nbsp; MOVE ieban-ekgrp TO itab-ekgrp.
&nbsp; MOVE ieban-matkl TO itab-matkl.
&nbsp; MOVE ieban-matnr TO itab-matnr_pr.
&nbsp; MOVE ieban-pstyp TO itab-pstyp_pr.
&nbsp; MOVE ieban-knttp TO itab-knttp_pr.
&nbsp; MOVE ieban-txz01 TO itab-txz01_pr.
&nbsp; MOVE ieban-menge TO itab-menge_pr.
&nbsp; MOVE ieban-meins TO itab-meins_pr.
&nbsp; APPEND itab.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" populate_data_PR
\*---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; FORM USER_COMMANd &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *
\*---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; ........ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\*
\*---------------------------------------------------------------------\*
\* &nbsp;--> &nbsp;R_UCOMM &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *
\* &nbsp;--> &nbsp;RS_SELFIELD &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *
\*---------------------------------------------------------------------\*
FORM user_command USING r_ucomm LIKE sy-ucomm
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rs_selfield TYPE slis_selfield.
&nbsp; READ TABLE itab INDEX rs_selfield-tabindex.
&nbsp; CASE rs_selfield-fieldname.
&nbsp; &nbsp; WHEN 'EBELN'.
&nbsp; &nbsp; &nbsp; SET PARAMETER ID 'BES' FIELD itab-ebeln.
&nbsp; &nbsp; &nbsp; CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
&nbsp; &nbsp; WHEN 'BANFN'.
&nbsp; &nbsp; &nbsp; SET PARAMETER ID 'BAN' FIELD itab-banfn.
&nbsp; &nbsp; &nbsp; CALL TRANSACTION 'ME53N' AND SKIP FIRST SCREEN.
&nbsp; &nbsp; WHEN 'BELNR'.
&nbsp; &nbsp; &nbsp; SET PARAMETER ID 'MBN' FIELD itab-belnr.
&nbsp; &nbsp; &nbsp; CALL TRANSACTION 'MIGO' AND SKIP FIRST SCREEN.
&nbsp; ENDCASE.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"user_command
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;populate_po_GR_data
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
\* &nbsp;--> &nbsp;p1 &nbsp; &nbsp; &nbsp; &nbsp;text
\* &nbsp;<-\- &nbsp;p2 &nbsp; &nbsp; &nbsp; &nbsp;text
\*----------------------------------------------------------------------\*
FORM populate_po_gr_data .
&nbsp; CLEAR itab.
&nbsp; READ TABLE ieban
&nbsp; &nbsp; WITH KEY banfn = iekpo-banfn
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bnfpo = iekpo-bnfpo.
&nbsp; IF sy-subrc = 0.
&nbsp; &nbsp; MOVE ieban-bednr TO itab-bednr_pr.
&nbsp; &nbsp; MOVE ieban-banfn TO itab-banfn.
&nbsp; &nbsp; MOVE ieban-bnfpo TO itab-bnfpo.
&nbsp; &nbsp; MOVE ieban-badat TO itab-badat.
&nbsp; &nbsp; MOVE ieban-frgdt TO itab-frgdt.
&nbsp; &nbsp; MOVE ieban-ekgrp TO itab-ekgrp.
&nbsp; &nbsp; MOVE ieban-matkl TO itab-matkl.
&nbsp; &nbsp; MOVE ieban-matnr TO itab-matnr_pr.
&nbsp; &nbsp; MOVE ieban-pstyp TO itab-pstyp_pr.
&nbsp; &nbsp; MOVE ieban-knttp TO itab-knttp_pr.
&nbsp; &nbsp; MOVE ieban-txz01 TO itab-txz01_pr.
&nbsp; &nbsp; MOVE ieban-menge TO itab-menge_pr.
&nbsp; &nbsp; MOVE ieban-meins TO itab-meins_pr.
&nbsp; ENDIF.
&nbsp; MOVE iekpo-ebeln TO itab-ebeln.
&nbsp; MOVE iekpo-ebelp TO itab-ebelp.
&nbsp; MOVE iekpo-anfnr TO itab-rfqno.
&nbsp; MOVE iekpo-anfps TO itab-rfqit.
&nbsp; PERFORM get_rfqdetail.
&nbsp; READ TABLE iekko WITH KEY ebeln = iekpo-ebeln BINARY SEARCH.
&nbsp; MOVE iekko-bedat TO itab-bedat.
&nbsp; PERFORM get_po_release_status.
&nbsp; MOVE &nbsp;iekko-waers TO itab-waers.
&nbsp; MOVE iekko-lifnr TO itab-lifnr.
&nbsp; MOVE iekpo-txz01 TO itab-txz01_po.
&nbsp; MOVE iekko-bsart TO itab-bsart.
&nbsp; MOVE iekpo-menge TO itab-menge_po.
&nbsp; MOVE iekpo-meins TO itab-meins_po.
&nbsp; MOVE iekpo-netpr TO itab-netpr .
&nbsp; itab-poamt &nbsp;= itab-menge_po * itab-netpr .
&nbsp; READ TABLE iekkn WITH KEY ebeln = iekpo-ebeln
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ebelp = iekpo-ebelp BINARY SEARCH.
&nbsp; IF sy-subrc EQ 0 .
&nbsp; &nbsp; itab-vbeln = iekkn-vbeln.
&nbsp; &nbsp; itab-vbelp = iekkn-vbelp.
&nbsp; &nbsp; itab-anln1 = iekkn-anln1.
&nbsp; ENDIF.
&nbsp; CLEAR eket.
&nbsp; SELECT SINGLE * FROM eket
&nbsp; &nbsp; WHERE ebeln = iekpo-ebeln AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ebelp = iekpo-ebelp.
&nbsp; MOVE eket-eindt TO itab-eindt.
&nbsp; SELECT SINGLE * FROM lfa1
&nbsp; &nbsp; WHERE lifnr = iekko-lifnr.
&nbsp; MOVE lfa1-name1 TO itab-name1.
&nbsp; MOVE iekbe-belnr TO itab-belnr.
&nbsp; MOVE iekbe-budat TO itab-budat.
&nbsp; MOVE iekbe-menge TO itab-menge_gr.
&nbsp; CLEAR ij_1iexcdtl.
&nbsp; SELECT SINGLE &nbsp;dmbtr bnbtr INTO (itab-grnamt ,wa_grntax)
&nbsp; FROM mseg WHERE ebeln EQ iekbe-ebeln AND
&nbsp; ebelp EQ iekbe-ebelp &nbsp;AND
&nbsp; mblnr EQ iekbe-belnr AND
&nbsp; mjahr EQ iekbe-gjahr.
&nbsp; READ TABLE ij_1iexcdtl WITH KEY rdoc1 = iekbe-ebeln
&nbsp; &nbsp; ritem1 = iekbe-ebelp
&nbsp; &nbsp; rdoc2 = iekbe-belnr
&nbsp; &nbsp; ryear2 = iekbe-gjahr
&nbsp; &nbsp; ritem2 = iekbe-buzei.
&nbsp; IF sy-subrc EQ 0.
&nbsp; &nbsp; itab-grntax = ij_1iexcdtl-exbed &nbsp;\+ ij_1iexcdtl-ecs + ij_1iexcdtl-exaddtax1 \+&nbsp;
ij_1iexcdtl-exaed + ij_1iexcdtl-nccd .
&nbsp; &nbsp; MOVE ij_1iexcdtl-exaed TO itab-exaed .
&nbsp; &nbsp; MOVE ij_1iexcdtl-excur TO itab-excur .
&nbsp; ELSE.
&nbsp; &nbsp; itab-grntax = wa_grntax .
&nbsp; ENDIF.
&nbsp; APPEND itab.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" populate_po_GR_data
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;populate_po_data
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
\* &nbsp;--> &nbsp;p1 &nbsp; &nbsp; &nbsp; &nbsp;text
\* &nbsp;<-\- &nbsp;p2 &nbsp; &nbsp; &nbsp; &nbsp;text
\*----------------------------------------------------------------------\*
FORM populate_po_data .
&nbsp; CLEAR itab.
&nbsp; READ TABLE ieban
&nbsp; &nbsp; WITH KEY banfn = iekpo-banfn
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bnfpo = iekpo-bnfpo.
&nbsp; IF sy-subrc = 0.
&nbsp; &nbsp; MOVE ieban-bednr TO itab-bednr_pr.
&nbsp; &nbsp; MOVE ieban-banfn TO itab-banfn.
&nbsp; &nbsp; MOVE ieban-bnfpo TO itab-bnfpo.
&nbsp; &nbsp; MOVE ieban-badat TO itab-badat.
&nbsp; &nbsp; MOVE ieban-frgdt TO itab-frgdt.
&nbsp; &nbsp; MOVE ieban-ekgrp TO itab-ekgrp.
&nbsp; &nbsp; MOVE ieban-matkl TO itab-matkl.
&nbsp; &nbsp; MOVE ieban-matnr TO itab-matnr_pr.
&nbsp; &nbsp; MOVE ieban-pstyp TO itab-pstyp_pr.
&nbsp; &nbsp; MOVE ieban-knttp TO itab-knttp_pr.
&nbsp; &nbsp; MOVE ieban-txz01 TO itab-txz01_pr.
&nbsp; &nbsp; MOVE ieban-menge TO itab-menge_pr.
&nbsp; &nbsp; MOVE ieban-meins TO itab-meins_pr.
&nbsp; ENDIF.
&nbsp; MOVE iekpo-ebeln TO itab-ebeln.
&nbsp; MOVE iekpo-ebelp TO itab-ebelp.
&nbsp; MOVE iekpo-anfnr TO itab-rfqno.
&nbsp; MOVE iekpo-anfps TO itab-rfqit.
&nbsp; PERFORM get_rfqdetail.
&nbsp; READ TABLE iekko WITH KEY ebeln = iekpo-ebeln BINARY SEARCH.
&nbsp; MOVE iekko-bedat TO itab-bedat.
&nbsp; MOVE &nbsp;iekko-waers TO itab-waers.
&nbsp; PERFORM get_po_release_status.
&nbsp; MOVE iekko-lifnr TO itab-lifnr.
&nbsp; MOVE iekpo-txz01 TO itab-txz01_po.
&nbsp; MOVE iekpo-menge TO itab-menge_po.
&nbsp; MOVE iekpo-meins TO itab-meins_po.
&nbsp; MOVE iekko-bsart TO itab-bsart.
&nbsp; MOVE iekko-waers TO itab-waers .
&nbsp; MOVE iekpo-netpr TO itab-netpr .
&nbsp; itab-poamt &nbsp;= itab-menge_po * itab-netpr .
&nbsp; READ TABLE iekkn WITH KEY ebeln = iekpo-ebeln
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ebelp = iekpo-ebelp BINARY SEARCH.
&nbsp; IF sy-subrc EQ 0 .
&nbsp; &nbsp; itab-vbeln = iekkn-vbeln.
&nbsp; &nbsp; itab-vbelp = iekkn-vbelp.
&nbsp; &nbsp; itab-anln1 = iekkn-anln1.
&nbsp; ENDIF.
&nbsp; CLEAR eket.
&nbsp; SELECT SINGLE * FROM eket
&nbsp; &nbsp; WHERE ebeln = iekpo-ebeln AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ebelp = iekpo-ebelp.
&nbsp; MOVE eket-eindt TO itab-eindt.
&nbsp; SELECT SINGLE * FROM lfa1
&nbsp; &nbsp; WHERE lifnr = iekko-lifnr.
&nbsp; MOVE lfa1-name1 TO itab-name1.
&nbsp; APPEND itab.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" populate_po_data
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;get_irDetail
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
FORM get_irdetail.
&nbsp; SELECT SINGLE * FROM rseg
&nbsp; &nbsp; &nbsp; &nbsp; WHERE ebeln = itab-ebeln
&nbsp; &nbsp; &nbsp; &nbsp; AND ebelp = itab-ebelp.
&nbsp; IF sy-subrc EQ 0.
&nbsp; &nbsp; SELECT SINGLE * FROM rbkp
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE belnr = rseg-belnr
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND gjahr = rseg-gjahr.
&nbsp; &nbsp; IF sy-subrc EQ 0.
&nbsp; &nbsp; &nbsp; MOVE rbkp-belnr TO itab-irno.
&nbsp; &nbsp; &nbsp; MOVE rseg-buzei TO itab-irit.
&nbsp; &nbsp; &nbsp; MOVE rbkp-budat TO itab-irdt.
&nbsp; &nbsp; &nbsp; MOVE rseg-wrbtr TO itab-irtx.
&nbsp; &nbsp; &nbsp; CALL FUNCTION 'ZCALCULATE_TAX_PO_ITEM'
&nbsp; &nbsp; &nbsp; &nbsp; EXPORTING
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ebeln &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= itab-ebeln
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ebelp &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= itab-ebelp
&nbsp; &nbsp; &nbsp; &nbsp; TABLES
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.
&nbsp; &nbsp; &nbsp; IF sy-subrc <> 0.
\* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
\* &nbsp; &nbsp; &nbsp; &nbsp; WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
&nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp; READ &nbsp;TABLE ikomv WITH KEY kschl = 'JIP5' .
&nbsp; &nbsp; &nbsp; IF sy-subrc EQ 0 .
&nbsp; &nbsp; &nbsp; &nbsp; MOVE ikomv-kwert TO itab-cst ." CST
&nbsp; &nbsp; &nbsp; &nbsp; CLEAR ikomv .
&nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp; READ &nbsp;TABLE ikomv WITH KEY kschl = 'JIP6' .
&nbsp; &nbsp; &nbsp; IF sy-subrc EQ 0 .
&nbsp; &nbsp; &nbsp; &nbsp; MOVE ikomv-kwert TO itab-saltax ." sales tax
&nbsp; &nbsp; &nbsp; &nbsp; CLEAR ikomv .
&nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp; MOVE rseg-menge TO itab-irqty. &nbsp;" ir quantity
&nbsp; &nbsp; &nbsp; IF &nbsp;itab-irqty > 0 .
&nbsp; &nbsp; &nbsp; &nbsp; itab-irnetpr = itab-poamt / itab-irqty .
&nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp; CALL FUNCTION 'BAPI_EXCHANGERATE_GETDETAIL'
&nbsp; &nbsp; &nbsp; &nbsp; EXPORTING
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rate_type &nbsp;= 'M'
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; from_curr &nbsp;= iekko-waers
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; to_currncy = 'INR'
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; date &nbsp; &nbsp; &nbsp; = iekko-bedat
&nbsp; &nbsp; &nbsp; &nbsp; IMPORTING
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exch_rate &nbsp;= exrate.
&nbsp; &nbsp; &nbsp; IF sy-subrc EQ 0.
&nbsp; &nbsp; &nbsp; &nbsp; itab-irnetpr = itab-irnetpr * exrate-exch_rate .
&nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp;MOVE rbkp-rmwwr TO itab-iramt ." ir doc amount
&nbsp; &nbsp; &nbsp; CALL FUNCTION 'BAPI_EXCHANGERATE_GETDETAIL'
&nbsp; &nbsp; &nbsp; &nbsp; EXPORTING
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rate_type &nbsp;= 'M'
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; from_curr &nbsp;= iekko-waers
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; to_currncy = 'INR'
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; date &nbsp; &nbsp; &nbsp; = iekko-bedat
&nbsp; &nbsp; &nbsp; &nbsp; IMPORTING
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exch_rate &nbsp;= exrate1.
&nbsp; &nbsp; &nbsp; IF sy-subrc EQ 0.
&nbsp; &nbsp; &nbsp; &nbsp; itab-iramt &nbsp;= itab-iramt * exrate1-exch_rate .
&nbsp; &nbsp; &nbsp; ENDIF .
&nbsp; &nbsp; &nbsp; itab-irval = itab-irnetpr * itab-irqty.
&nbsp; &nbsp; ENDIF.
&nbsp; ENDIF.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"get_irDetail
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;get_rfqdetail
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
FORM get_rfqdetail.
&nbsp; SELECT SINGLE * FROM ekko
&nbsp; &nbsp; WHERE ebeln = iekpo-anfnr.
&nbsp; MOVE ekko-bedat TO itab-rfqdt.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"get_rfqdetail

List of all pages

Pages at first level

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*&---------------------------------------------------------------------*
* Create MARD segments in Retail
*&---------------------------------------------------------------------*

REPORT .

TYPES BEGIN OF typ1.
INCLUDE TYPE mard.
TYPES END OF typ1.

TYPE-POOLS:
  slis.

DATA:
  BEGIN OF g,
    t     TYPE STANDARD TABLE OF typ1,
    l     LIKE LINE OF g-t, "needed for the select options
    tret1 TYPE STANDARD TABLE OF bapireturn1,
    dummy TYPE mara-attyp,
  END OF g.

*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
*----------------------------------------------------------------------*
SELECT-OPTIONS:
  s_matnr FOR g-l-matnr,
  s_attyp FOR g-dummy DEFAULT '02'.

PARAMETERS:
  p_werks TYPE mard-werks OBLIGATORY,
  p_lgort TYPE mard-lgort OBLIGATORY DEFAULT '0001',
  p_test  AS CHECKBOX.

*----------------------------------------------------------------------*
SELECTION-SCREEN END OF BLOCK b1.
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
START-OF-SELECTION.
*----------------------------------------------------------------------*
  PERFORM:
    select,
    workup,
    output1,
    output.

*&---------------------------------------------------------------------*
*&      Form  select
*&---------------------------------------------------------------------*
FORM select .

  DATA:
    t TYPE HASHED TABLE OF typ1 WITH UNIQUE KEY matnr,
    p TYPE REF TO typ1.

* read Material Numbers
  SELECT mandt matnr FROM mara INTO TABLE g-t
    WHERE matnr IN s_matnr
    AND   attyp IN s_attyp.

* read Marde segments
  SELECT * FROM mard INTO TABLE t
    WHERE matnr IN s_matnr
    AND   werks EQ p_werks
    AND   lgort EQ p_lgort.

* mix up
  LOOP AT g-t REFERENCE INTO p.
    READ TABLE t WITH TABLE KEY matnr = p->matnr INTO p->*.
  ENDLOOP.

ENDFORM.                    " select
*&---------------------------------------------------------------------*
*&      Form  workup
*&---------------------------------------------------------------------*
FORM workup .

  DATA:
    lhead TYPE bapie1mathead,
    lstor TYPE bapie1mardrt,
    lstox TYPE bapie1mardrtx,
    tstor TYPE STANDARD TABLE OF bapie1mardrt,
    tstox TYPE STANDARD TABLE OF bapie1mardrtx,
    lret1 LIKE LINE OF g-tret1,
    p     TYPE REF TO typ1.

  IF p_test IS INITIAL.

* maintain MARD
    LOOP AT g-t REFERENCE INTO p WHERE lgort IS INITIAL.

      lhead-function = '004'.
      lhead-material = p->matnr.

      CLEAR tstor.
      CLEAR tstox.

      lstox-function = lstor-function = '004'.
      lstox-material = lstor-material = p->matnr.
      lstox-plant    = lstor-plant    = p_werks.
      lstox-stge_loc = lstor-stge_loc = p_lgort.
      APPEND lstor TO tstor.
      APPEND lstox TO tstox.

      CALL FUNCTION 'BAPI_MATERIAL_MAINTAINDATA_RT'
        EXPORTING
          headdata             = lhead
        IMPORTING
          return               = lret1
        TABLES
          storagelocationdata  = tstor
          storagelocationdatax = tstox.

      APPEND lret1 TO g-tret1.

    ENDLOOP.
  ENDIF.

ENDFORM.                    " workup
*&---------------------------------------------------------------------*
*&      Form  output
*&---------------------------------------------------------------------*
FORM output1 .

  DATA:
    tfcat TYPE slis_t_fieldcat_alv.

  IF g-tret1 IS INITIAL.
    RETURN.
  ENDIF.

  READ TABLE g-tret1 WITH KEY type = 'E' TRANSPORTING NO FIELDS.
  IF sy-subrc <> 0.
    RETURN.
  ENDIF.

* get the field catalog
  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      i_structure_name = 'BAPIRETURN1'
    CHANGING
      ct_fieldcat      = tfcat.

* Grid
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_screen_start_column = 20
      i_screen_start_line   = 10
      i_screen_end_column   = 150
      i_screen_end_line     = 30
      i_callback_program    = sy-repid
      it_fieldcat           = tfcat
    TABLES
      t_outtab              = g-tret1.

ENDFORM.                    " output
*&---------------------------------------------------------------------*
*&      Form  output
*&---------------------------------------------------------------------*
FORM output .

  DATA:
    tfcat  TYPE slis_t_fieldcat_alv.

* get the field catalog
  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      i_structure_name = 'mard'
    CHANGING
      ct_fieldcat      = tfcat.

* Grid
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = sy-repid
      it_fieldcat        = tfcat
    TABLES
      t_outtab           = g-t.

ENDFORM.                    " output

Author: Dileep Kumar Chunnaiah
Submitted: 13th Feb 2009

Description : This Program Explains a simple way to retrieve the BOM Materials & its Quantities  with their Texts.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
TYPES : BEGIN OF ty_mast,
          matnr TYPE mast-matnr, "Main Material (Parent)
          werks TYPE mast-werks,
          stlan TYPE mast-stlan,
          stlnr TYPE mast-stlnr,
          stlal TYPE mast-stlal,
       END OF ty_mast.
TYPES : BEGIN OF ty_stko,
          stlnr TYPE stko-stlnr,
          stlal TYPE stko-stlal,
          datuv TYPE stko-datuv,
          bmein TYPE stko-bmein,
          bmeng TYPE stko-bmeng,
        END OF ty_stko.
TYPES : BEGIN OF ty_stpo,
          stlnr TYPE stpo-stlnr,
          datuv TYPE stpo-datuv,
          idnrk TYPE stpo-idnrk, "Material Component (Child)
          posnr TYPE stpo-posnr,
          meins TYPE stpo-meins,
          menge TYPE stpo-menge, "Bom Material Req Qty.
        END OF ty_stpo.
TYPES : BEGIN OF ty_makt,
          matnr TYPE makt-matnr,
          maktx TYPE makt-maktx,
        END OF ty_makt.

DATA : it_mast TYPE TABLE OF ty_mast, wa_mast LIKE LINE OF it_mast.
DATA : it_makt TYPE TABLE OF ty_makt, wa_makt LIKE LINE OF it_makt.
DATA : it_stko TYPE TABLE OF ty_stko, wa_stko LIKE LINE OF it_stko.
DATA : it_stpo TYPE TABLE OF ty_stpo, wa_stpo LIKE LINE OF it_stpo.

PARAMETERS : p_matnr TYPE mara-matnr,
             p_werks TYPE mseg-werks.

SELECT matnr werks stlan stlnr stlal
       FROM mast INTO TABLE it_mast
       WHERE matnr = p_matnr AND
             werks = p_werks AND
             stlan = '1'.

IF NOT it_mast IS INITIAL.
  SELECT stlnr stlal datuv bmein bmeng
         FROM stko INTO TABLE it_stko
         FOR ALL ENTRIES IN it_mast
         WHERE stlnr = it_mast-stlnr AND
               stlal = it_mast-stlal .
ENDIF.
IF NOT it_stko IS INITIAL.
  SELECT stlnr datuv idnrk posnr meins menge
         FROM stpo INTO TABLE it_stpo
         FOR ALL ENTRIES IN it_mast
         WHERE stlnr = it_mast-stlnr.
ENDIF.
IF NOT it_stpo IS INITIAL.
  SELECT matnr maktx
         FROM makt INTO TABLE it_makt
         FOR ALL ENTRIES IN it_stpo
         WHERE matnr = it_stpo-idnrk AND
               spras = 'EN'.
ENDIF.


" Rest You can move to a Final Table as per the requirement and display it.

Addition of customised view to the material Master

 - SPRO

- Logistics

- Material master

- additonal customised views

- Add or modify

Author: Dheeraj Soni

Submitted: 12/03/2008

The goal of this conversation is to find the BADI for MM02 transaction and implement the BADI as to change the material description. 

Introduction

BADI implementation in the MM02 transaction to change the material description.When the customer needs more functionality in the SAP standard Program (Functionality) then we can add extra functionality to standard SAP functionality through BADI. BADI can't disturb the original (standard) code.
Adding extra functionality to the standard is nothing but Add-in.
BADI are not created in the program itself. They are created and maintained separately and called when we need the BADI.
In the given tutorial BADI implantation of transaction MM02 is done as to change the description of the material number, for that I have explained the way to find the appropriate BADI according to the requirement.
Than we will learn to see all the methods associated with that BADI name and finally implement that BADI to add extra features.

Steps to find BADI

Run the transaction SE24. Under object type put the class name 'CL_EXITHANDLER'.

Click on display button. 


                                         
 

Under this class 'CL_EXITHANDLER' select the method 'GET_INSTANCE' and double click on it.

              

Under the method 'GET_INSTANCE' put break point on a function module called

'CALL METHOD CL_EXITHANDLER=>GET_CLASS_NAME_BY_INTERFACE' 


              

Place the cursor over here and give a break point.

Then according to the requirement run the transaction. In this example transaction code is MM02.

Run the transaction MM02. As in 1st step we have put a break point, that function module will give all BADI used by the

transaction in each screen and activity on the application (MM02).  

Now double click on the changing parameter EXIT_NAME of the function module to get the name of BADI used in this transaction.
             

Now press F8 to again and again to get the list of all the BADI.

We will get following BADI as shown below.

BADI_SCREEN_LOGIC_RT

W_RETAILSYSTEM_IDENT

BADI_MATN1

Than again pressing F8 key the initial screen of transaction MM02 will appear.
                                                

Get a material number using F4 help and press enter.

BADI name after calling the main screen of MM02. 
                                   

BADI_MATERIAL_OD.

Now press F8 you will get the following screen.

Choose the basic data and press enter to proceed.


Press F8.


Press F8.


ECM_EXIT (Customer Exits for Engineering Change Management)
Press F8.
BADI_LAYER (Layer Value Management for BADIs)
Press F8.
BADI_MATERIAL_OD (Integration of New Objects in Material or Article Master)
Press F8.
BADI_MAT_F_SPEC_SEL (BADI for Material Special Field Selection)
Press F8.
Change material window will come. In this change the material description.


            

And savethe changes.You will get the following BADI.


BADI_GTIN_VARIANT (User Exit for Customer-Specific GTIN Variant Check)
Press F8.


BADI_MATERIAL_CHEK (Enhanced Checks for Material Master Tables)
Press F8.


BADI_MAT_F_SPEC_SEL (BADI for Material Special Field Selection)
Press F8.


EHSS_SPEC_CHECKS (BADI: Extended Checks for Specifications)
BADI name: 
BADI_GTIN_VARIANT
BADI_MATERIAL_CHECK
BADI_MAT_SPEC_SEL
EHSS_SPEC_CHECKS 

Step to check all the methods associated with that BADI

Run the transaction SE18 to see the details of BADI. 


Click on display button to see the methods declared in that.
Click on the interface tab to see the details of all the methods associated with the BADI name as shown below.

Method CHECK_DATA is used to give the material description. Choose the method where the material description is defined. 

Steps to implement the BADI

Run the transaction SE19 (BADI Builder) and create an implementation for the corresponding BADI. Click on create button to create an implementation.


Give a name for the implementation.

              \

Give the BADI description as shown below.


Double click on method CHECK_DATA. On double clicking system will provide you the editor to write the code.

                

Write the code in the editor window as shown below.

            

The entire code is written as shown below

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
CONSTANTS: wl_prefix(6) TYPE c        VALUE 'LT_BD_',
           wl_uname     TYPE sy-uname VALUE 'EI6DEV'.
DATA: int_stext TYPE TABLE OF short_desc.
DATA: wa_stext  TYPE short_desc.
DATA: wf_idx    TYPE sy-tabix.
DATA: wa1 TYPE short_desc.
DATA: wa TYPE short_desc.

wa-maktx = 'HELLO'.
LOOP AT stext INTO wa1.
  CONCATENATE wa1-maktx wa-maktx INTO wa1-maktx.
  MODIFY stext FROM wa1.
ENDLOOP.
IF sy-uname = wl_uname.            "and sy-tcode = 'MM02'
  int_stext[] = stext[].
  READ TABLE int_stext INTO wa_stext WITH KEY spras = sy-langu.
  IF sy-subrc = 0.
    wf_idx = sy-tabix.
    IF wa_stext-maktx+0(6) = wl_prefix OR wa_stext-maktx IS INITIAL.
      EXIT.
    ELSE.
      CONCATENATE wl_prefix wa_stext-maktx INTO wa_stext-maktx.
      MODIFY int_stext FROM wa_stext INDEX wf_idx.
      stext[] = int_stext[].
    ENDIF.
  ENDIF.
ENDIF.

Save the changes and activate the program. Than activate the BADI implementation.
The output of the BADI implementation is as shown below. The material description has been changed with the prefix LT_BD_.

          

This is how we can change the standard material description using BADI.

Thanks & regards.

Dheeraj

Creating a BDC of the MM02 will not be an easy task. As soon as we enter the material and hit enter it will ask us to choose the required Material master views. This popup contains the available material master views and they are not constant. Sometimes MRP1 comes at the 12th line and sometimes it comes to 6th line. This dynamic of the views are solely depended on the Status (MARA-VPSTA).
To overcome of this dynamics we need to get to know where exactly our required view will appear e.g. line 6 or line 10 or line 15. We will use the FM SELECTION_VIEWS_FIND to find out which view will come at which position.


In our BDC, we will follow these steps:
1. Always select the Basic Data 1
2. Get the respective user command for the tab by Executing the FM SELECTION_VIEWS_FIND.

Status (MARA-VPSTA) contains the combination of the View indicator. You can find the relation of the status indicator and view name in the documentation of the data element PSTAT_D or follow this table:

User department Maintenance status 
 
Work scheduling                                                    A
Accounting                                                               B
Classification                                                           C
MRP                                                                            D
Purchasing                                                               E
Production resources/tools                                 F
Costing                                                                      G
Basic data                                                                 K
Storage                                                                      L
Forecasting                                                               P
Quality management                                              Q
Warehouse management                                     S
Sales                                                                          V
Plant stocks                                                             X
Storage location stocks                                        Z


In this my test BDC, I want to update the MRP type. MRP type comes under the “MRP 1″ view of the material master. So, I will first select the Basic Data and than move to MRP 1 view and update the MRP type.
Code Snippet to Select View in MM02

 

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
* Local data
DATA:   messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
DATA:   bdcdata LIKE bdcdata    OCCURS 0 WITH HEADER LINE.
*
* Selection Screen
PARAMETERS: p_matnr TYPE mara-matnr OBLIGATORY,
            p_werks TYPE marc-werks OBLIGATORY,
            p_lgort TYPE rmmg1-lgort OBLIGATORY,
            p_dismm TYPE marc-dismm OBLIGATORY.
*
*
START-OF-SELECTION.
*
* Material views ....................................................
  DATA:  l_vpsta LIKE t130m-pstat.
*
  SELECT SINGLE vpsta
         INTO   l_vpsta
         FROM   mara
         WHERE  matnr = p_matnr.
*
* Get View sequence .................................................
  DATA: l_bild  LIKE t133a-bilds,
        lt_bild LIKE mbildtab OCCURS 0 WITH HEADER LINE.
*
* Screen Sequence for Standard Industry tab pages in material master
  l_bild = '21'.
*
* Get screen sequence
  CALL FUNCTION 'SELECTION_VIEWS_FIND'
    EXPORTING
      bildsequenz     = l_bild
      pflegestatus    = l_vpsta
    TABLES
      bildtab         = lt_bild
    EXCEPTIONS
      call_wrong      = 1
      empty_selection = 2
      OTHERS          = 3.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
*
* Get the Tab page for MRP1 .........................................
  DATA: l_tab_mrp1 TYPE sy-ucomm.
*
* reading table with MRP view
  READ TABLE lt_bild WITH KEY pstat = 'D'.
  IF sy-subrc = 0.
    l_tab_mrp1 = lt_bild-guifu.
  ENDIF.
*
* make ok code for the MRP1
  CONCATENATE '=' l_tab_mrp1 INTO l_tab_mrp1.
*
* BDC ...............................................................
  PERFORM bdc_dynpro      USING 'SAPLMGMM' '0060'.
  PERFORM bdc_field       USING 'RMMG1-MATNR'
                                 p_matnr.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '=ENTR'.
*
  PERFORM bdc_dynpro      USING 'SAPLMGMM' '0070'.
  PERFORM bdc_field       USING 'MSICHTAUSW-KZSEL(01)'
                                'X'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '=ENTR'.
*
  PERFORM bdc_dynpro      USING 'SAPLMGMM' '4004'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                l_tab_mrp1.
*
  PERFORM bdc_dynpro      USING 'SAPLMGMM' '0081'.
  PERFORM bdc_field       USING 'RMMG1-WERKS'
                                p_werks.
  PERFORM bdc_field       USING 'RMMG1-LGORT'
                                p_lgort.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '=ENTR'.
*
  PERFORM bdc_dynpro      USING 'SAPLMGMM' '4000'.
  PERFORM bdc_field       USING 'MARC-DISMM'
                                p_dismm.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '=BU'.
*
  PERFORM bdc_transaction USING 'MM02'.
*
*&---------------------------------------------------------------------*
*&      Form  BDC_DYNPRO
*&---------------------------------------------------------------------*
FORM bdc_dynpro USING p_program
                      p_screen.
*
  MOVE: p_program TO bdcdata-program,
        p_screen  TO bdcdata-dynpro,
        'X'       TO bdcdata-dynbegin.
*
  APPEND bdcdata.
  CLEAR  bdcdata.
*
ENDFORM.                    " BDC_DYNPRO
*
*&---------------------------------------------------------------------*
*&      Form  BDC_FIELD
*&---------------------------------------------------------------------*
FORM bdc_field USING p_field_name
                     p_field_value.
*
  MOVE: p_field_name  TO bdcdata-fnam,
        p_field_value TO bdcdata-fval.
*
  APPEND bdcdata.
  CLEAR  bdcdata.
*
ENDFORM.                    " BDC_FIELD
*
*
*&---------------------------------------------------------------------*
*&      Form  BDC_TRANSACTION
*&---------------------------------------------------------------------*
FORM bdc_transaction USING tcode.
  DATA: l_mstring(480).
  DATA: l_subrc LIKE sy-subrc.
* batch input session
  REFRESH messtab.
  CALL TRANSACTION tcode USING bdcdata
                   MODE   'A'
                   "A: show all dynpros
                   "E: show dynpro on error only
                   "N: do not display dynpro
*
                   UPDATE 'L'
                   MESSAGES INTO messtab.
  REFRESH bdcdata.
ENDFORM.                    "BDC_TRANSACTION

 

 

 

Author: Abir Biswas
Submitted: 03-10-2007
Related Links:

Tutorial - BDC Program to Upload Material Master Data (MM01)

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
REPORT  zimmc001.
************************************************************************
*  D A T A   D E C L A R A T I O N                                     *
************************************************************************
*------------------------------------
*  Type Declaration of the Structure.
*------------------------------------
TYPES:  BEGIN  OF  ty_save_index,
          idno  TYPE  i,                   "  SAVE Index
        END    OF  ty_save_index.
TYPES:  BEGIN  OF  ty_tabdata,
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*         Create Material (Initial Screen).
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
          matnr(18)      TYPE    c,        "  Material Number.
          mbrsh(01)      TYPE    c,        "  Industry Sector.
          mtart(04)      TYPE    c,        "  Material Type.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*         Organizational Levels.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
          werks(04)      TYPE    c,        "  Plant.
          lgort(04)      TYPE    c,        "  Storage Location.
          vkorg(04)      TYPE    c,        "  Sales Organization.
          vtweg(02)      TYPE    c,        "  Distribution Channel.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*         Sales Org. 1 : Tax Classification.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
          taxkm1(01)     TYPE    c,        "  Tax classification material 1.
          taxkm2(01)     TYPE    c,        "  Tax classification material 2.
          taxkm3(01)     TYPE    c,        "  Tax classification material 3.
          taxkm4(01)     TYPE    c,        "  Tax classification material 4.
          taxkm5(01)     TYPE    c,        "  Tax classification material 5.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*         Additional Data - UoM.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
          umren1(06)     TYPE    c,        "  Denominator for Conversion to Base Units of Measure 1.
          meinh1(03)     TYPE    c,        "  Alternative Unit of Measure for Stockkeeping Unit   1.
          umrez1(06)     TYPE    c,        "  Numerator for Conversion to Base Units of Measure   1.
*         ..........................................................................................
          umren2(06)     TYPE    c,        "  Denominator for Conversion to Base Units of Measure 2.
          meinh2(03)     TYPE    c,        "  Alternative Unit of Measure for Stockkeeping Unit   2.
          umrez2(06)     TYPE    c,        "  Numerator for Conversion to Base Units of Measure   2.
*         ..........................................................................................
          umren3(06)     TYPE    c,        "  Denominator for Conversion to Base Units of Measure 3.
          meinh3(03)     TYPE    c,        "  Alternative Unit of Measure for Stockkeeping Unit   3.
          umrez3(06)     TYPE    c,        "  Numerator for Conversion to Base Units of Measure   3.
*         ..........................................................................................
          umren4(06)     TYPE    c,        "  Denominator for Conversion to Base Units of Measure 4.
          meinh4(03)     TYPE    c,        "  Alternative Unit of Measure for Stockkeeping Unit   4.
          umrez4(06)     TYPE    c,        "  Numerator for Conversion to Base Units of Measure   4.
*         ..........................................................................................
          umren5(06)     TYPE    c,        "  Denominator for Conversion to Base Units of Measure 5.
          meinh5(03)     TYPE    c,        "  Alternative Unit of Measure for Stockkeeping Unit   5.
          umrez5(06)     TYPE    c,        "  Numerator for Conversion to Base Units of Measure   5.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*         Sales Org. 1
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
          vrkme(03)      TYPE    c,        "  Sales unit.
          dwerk(04)      TYPE    c,        "  Delivering Plant (Own or External).
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*         Sales Org. 2
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
          versg(01)      TYPE    c,        "  Material statistics group.
          ktgrm(02)      TYPE    c,        "  Account assignment group for this material.
          mtpos(04)      TYPE    c,        "  Item category group from material master.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*         General/Plant.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
          brgew(17)      TYPE    c,        "  Gross weight.
          ntgew(17)      TYPE    c,        "  Net weight.
          mtvfp(02)      TYPE    c,        "  Checking Group for Availability Check.
          tragr(04)      TYPE    c,        "  Transportation group
          ladgr(04)      TYPE    c,        "  Loading group.
          prctr(10)      TYPE    c,        "  Profit Center.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*         Foreign Trade Export.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
          herkl(03)      TYPE    c,        "  Country of origin of the material.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*         Purchasing.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
          bstme(03)      TYPE    c,        "  Order unit.
          kautb(01)      TYPE    c,        "  Indicator: "automatic purchase order allowed".
          xchpf(01)      TYPE    c,        "  Batch management requirement indicator.
          ekgrp(03)      TYPE    c,        "  Purchasing Group.
          webaz(03)      TYPE    c,        "  Goods receipt processing time in days.
          ekwsl(04)      TYPE    c,        "  Purchasing Value Key.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*         Purch.Order Text.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
          ptext(40)      TYPE    c,        "  Purchase Order Text.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*         MRP 1
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
          disgr(04)      TYPE    c,        "  MRP Group.
          dismm(02)      TYPE    c,        "  MRP Type.
          minbe(17)      TYPE    c,        "  Reorder point.
          dispo(03)      TYPE    c,        "  MRP Controller.
          disls(02)      TYPE    c,        "  Lot size (materials planning).
          bstfe(17)      TYPE    c,        "  Fixed lot size.
          bstmi(17)      TYPE    c,        "  Minimum lot size.
          bstma(17)      TYPE    c,        "  Maximum lot size.
          ausss(06)      TYPE    c,        "  Assembly scrap in percent.
          bstrf(17)      TYPE    c,        "  Rounding value for purchase order quantity.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*         MRP 2
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
          beskz(01)      TYPE    c,        "  Procurement Type.
          sobsl(02)      TYPE    c,        "  Special procurement type.
          lgpro(04)      TYPE    c,        "  Issue Storage Location.
          rgekz(01)      TYPE    c,        "  Indicator: Backflush.
          lgfsb(04)      TYPE    c,        "  Default storage location for external procurement.
          dzeit(03)      TYPE    c,        "  In-house production time.
          plifz(03)      TYPE    c,        "  Planned delivery time in days.
          mrppp(03)      TYPE    c,        "  PPC planning calendar.
          fhori(03)      TYPE    c,        "  Scheduling Margin Key for Floats.
          eisbe(17)      TYPE    c,        "  Safety stock.
          webaz1(03)     TYPE    c,        "  Goods receipt processing time in days.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*         MRP 3
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
          strgr(02)      TYPE    c,        "  Planning strategy group.
          vrmod(01)      TYPE    c,        "  Consumption mode.
          vint1(03)      TYPE    c,        "  Consumption period: backward.
          vint2(03)      TYPE    c,        "  Consumption period: forward.
          miskz(01)      TYPE    c,        "  Mixed MRP indicator.
          mtvfp1(02)     TYPE    c,        "  Checking Group for Availability Check.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*         MRP 4
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
          altsl(01)      TYPE    c,        "  Method for Selecting Alternative Bills of Material.
          kausf(06)      TYPE    c,        "  Component scrap in percent.
          sbdkz(01)      TYPE    c,        "  Dependent requirements ind. for individual and coll. reqmts.
          sauft(01)      TYPE    c,        "  Ind.: Repetitive mfg allowed.
          sfepr(04)      TYPE    c,        "  Repetitive manufacturing profile.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*         Work Scheduling.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
          frtme(03)      TYPE    c,        "  Production unit.
          fevor(03)      TYPE    c,        "  Production scheduler.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*         Plant Data / Stor. 1
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
          ausme(03)      TYPE    c,        "  Unit of issue.
          mhdrz(05)      TYPE    c,        "  Minimum remaining shelf life.
          mhdhb(05)      TYPE    c,        "  Total shelf life.
          iprkz(01)      TYPE    c,        "  Period indicator for shelf life expiration date.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*         Quality Management.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
          webaz2(03)     TYPE    c,        "  Goods receipt processing time in days.
          qmpur(01)      TYPE    c,        "  QM in Procurement is Active.
          ssqss(08)      TYPE    c,        "  Control Key for Quality Management in Procurement.
          qzgtp(04)      TYPE    c,        "  Certificate Type.
          qmatv(01)      TYPE    c,        "  Inspection Setup Exists for Material/Plant.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*         Inspection Setup Data.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
          art1(08)       TYPE    c,        "  Inspection Type 1.
          aktiv1(01)     TYPE    c,        "  Inspection Type - Material Combination is Active 1.
          art2(08)       TYPE    c,        "  Inspection Type 2.
          aktiv2(01)     TYPE    c,        "  Inspection Type - Material Combination is Active 2.
          art3(08)       TYPE    c,        "  Inspection Type 3.
          aktiv3(01)     TYPE    c,        "  Inspection Type - Material Combination is Active 3.
          art4(08)       TYPE    c,        "  Inspection Type 4.
          aktiv4(01)     TYPE    c,        "  Inspection Type - Material Combination is Active 4.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*         Accounting 1.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
          bklas(04)      TYPE    c,        "  Valuation Class.
          vprsv(01)      TYPE    c,        "  Price Control Indicator.
          peinh(06)      TYPE    c,        "  Price Unit.
          stprs(15)      TYPE    c,        "  Standard Price.
          verpr(15)      TYPE    c,        "  Moving Average Price/Periodic Unit Price.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*         Cost Estimate 1.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
          ekalr(01)      TYPE    c,        "  Material Is Costed with Quantity Structure.
          hkmat(01)      TYPE    c,        "  Material Origin.
          awsls(06)      TYPE    c,        "  Variance Key.
          prctr1(10)     TYPE    c,        "  Profit Center.
          losgr(17)      TYPE    c,        "  Lot Size for Product Costing.
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
          rowcnt         TYPE    i,        "  Normal Row Count.
          row            TYPE    i,        "  Row Count --> Line Items
*         ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
        END  OF  ty_tabdata.
*------------------------------------------------
*  Declaration of the Internal Table & Work Area.
*------------------------------------------------
DATA:   it_save_index      TYPE  STANDARD  TABLE  OF  ty_save_index,
        wa_save_index      TYPE                       ty_save_index.
DATA:   it_tabdata         TYPE  STANDARD  TABLE  OF  ty_tabdata,
        wa_tabdata         TYPE                       ty_tabdata.
*-------------------------------------------------------------------------------------
*  Declaration of the Internal Table with Header Line comprising of the uploaded data.
*-------------------------------------------------------------------------------------
DATA:  BEGIN  OF  it_file_upload  OCCURS  0.
INCLUDE  STRUCTURE  alsmex_tabline.  "  Rows for Table with Excel Data
DATA:  END  OF  it_file_upload.
*-------------------------------
*  Global Variable Declarations.
*-------------------------------
DATA:  gv_ans  TYPE  c.
*--------------------------------------------
*  Batch Input Data for a single Transaction.
*  Message of Call Transaction.
*--------------------------------------------
DATA:  bdcdata  LIKE  bdcdata     OCCURS  0  WITH  HEADER  LINE,
       msgtab   LIKE  bdcmsgcoll  OCCURS  0  WITH  HEADER  LINE.
************************************************************************
*  S E L E C T I O N - S C R E E N                                     *
************************************************************************
SELECTION-SCREEN:  BEGIN  OF  BLOCK  b1  WITH  FRAME,
                     BEGIN  OF  BLOCK  b2  WITH  FRAME.
PARAMETERS:            p_fname  LIKE  rlgrap-filename  OBLIGATORY.
SELECTION-SCREEN:    END  OF  BLOCK  b2,
                   END  OF  BLOCK  b1.
************************************************************************
*  E V E N T : AT    S E L E C T I O N - S C R E E N                   *
************************************************************************
AT  SELECTION-SCREEN  ON  VALUE-REQUEST  FOR  p_fname.
  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
   EXPORTING
*       PROGRAM_NAME        = SYST-REPID
*       DYNPRO_NUMBER       = SYST-DYNNR
*       FIELD_NAME          = ' '
     static              = 'X'
*       MASK                = '.'
    CHANGING
      file_name           = p_fname
*     EXCEPTIONS
*       MASK_TOO_LONG       = 1
*       OTHERS              = 2
            .
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*           WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
************************************************************************
*  E V E N T : S T A R T - O F - S E L E C T I O N                     *
************************************************************************
START-OF-SELECTION.
* --------------------------------------
* Upload Excel file into Internal Table.
* --------------------------------------
  PERFORM  upload_excel_file.
  IF  NOT  it_file_upload  IS  INITIAL.
*   ----------------------------------------------------
*   Confirm whether you want to proceed with the Upload.
*   ----------------------------------------------------
    PERFORM  confirm_upload.
    IF  gv_ans  EQ  '1'.
*     -------------------------------------------------------
*     Organize the uploaded data into another Internal Table.
*     -------------------------------------------------------
      PERFORM  organize_uploaded_data.
*     -----------------------------------
*     Modify Row No. for Line Item Count.
*     -----------------------------------
      PERFORM  modify_row_number.
*     -----------------
*     Open BDC Session.
*     -----------------
*      PERFORM  OPEN_BDC_SESSION.
*     ------------------------
*     Kick-start BDC Operation
*     ------------------------
      PERFORM  bdc_operation.
*     ------------------
*     Close BDC Session.
*     ------------------
*      PERFORM  CLOSE_BDC_SESSION.
    ENDIF.
  ENDIF.
************************************************************************
*  E V E N T : E N D - O F - S E L E C T I O N                         *
************************************************************************
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*&      Form  UPLOAD_EXCEL_FILE
*&---------------------------------------------------------------------*
FORM upload_excel_file .
  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      filename                = p_fname
      i_begin_col             = 1
      i_begin_row             = 4
      i_end_col               = 107
      i_end_row               = 32000
    TABLES
      intern                  = it_file_upload
    EXCEPTIONS
      inconsistent_parameters = 1
      upload_ole              = 2
      OTHERS                  = 3.
  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.                    " UPLOAD_EXCEL_FILE
*&---------------------------------------------------------------------*
*&      Form  CONFIRM_UPLOAD
*&---------------------------------------------------------------------*
FORM confirm_upload .
  CALL FUNCTION 'POPUP_TO_CONFIRM'
    EXPORTING
      titlebar       = 'Pop-Up to Confirm'
      text_question  = 'Do you like to proceed with the Upload ???'
    IMPORTING
      answer         = gv_ans
    EXCEPTIONS
      text_not_found = 1
      OTHERS         = 2.

ENDFORM.                    " CONFIRM_UPLOAD
*&---------------------------------------------------------------------*
*&      Form  ORGANIZE_UPLOADED_DATA
*&---------------------------------------------------------------------*
FORM organize_uploaded_data .
  DATA:  lv_row_cnt  TYPE  i.
  CLEAR: lv_row_cnt.
  SORT  it_file_upload  BY  row
                            col.
  LOOP  AT  it_file_upload.
    CASE  it_file_upload-col.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*     Create Material (Initial Screen).
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      WHEN  1.
        wa_tabdata-matnr        =  it_file_upload-value.
      WHEN  2.
        wa_tabdata-mbrsh        =  it_file_upload-value.
      WHEN  3.
        wa_tabdata-mtart        =  it_file_upload-value.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*     Organizational Levels.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      WHEN  4.
        wa_tabdata-werks        =  it_file_upload-value.
      WHEN  5.
        wa_tabdata-lgort        =  it_file_upload-value.
      WHEN  6.
        wa_tabdata-vkorg        =  it_file_upload-value.
      WHEN  7.
        wa_tabdata-vtweg        =  it_file_upload-value.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*     Sales Org. 1 : Tax Classification.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      WHEN  8.
        wa_tabdata-taxkm1       =  it_file_upload-value.
      WHEN  9.
        wa_tabdata-taxkm2       =  it_file_upload-value.
      WHEN  10.
        wa_tabdata-taxkm3       =  it_file_upload-value.
      WHEN  11.
        wa_tabdata-taxkm4       =  it_file_upload-value.
      WHEN  12.
        wa_tabdata-taxkm5       =  it_file_upload-value.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*     Additional Data - UoM.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      WHEN  13.
        wa_tabdata-umren1       =  it_file_upload-value.
      WHEN  14.
        wa_tabdata-meinh1       =  it_file_upload-value.
      WHEN  15.
        wa_tabdata-umrez1       =  it_file_upload-value.
*     ...........................................................
      WHEN  16.
        wa_tabdata-umren2       =  it_file_upload-value.
      WHEN  17.
        wa_tabdata-meinh2       =  it_file_upload-value.
      WHEN  18.
        wa_tabdata-umrez2       =  it_file_upload-value.
*     ...........................................................
      WHEN  19.
        wa_tabdata-umren3       =  it_file_upload-value.
      WHEN  20.
        wa_tabdata-meinh3       =  it_file_upload-value.
      WHEN  21.
        wa_tabdata-umrez3       =  it_file_upload-value.
*     ...........................................................
      WHEN  22.
        wa_tabdata-umren4       =  it_file_upload-value.
      WHEN  23.
        wa_tabdata-meinh4       =  it_file_upload-value.
      WHEN  24.
        wa_tabdata-umrez4       =  it_file_upload-value.
*     ...........................................................
      WHEN  25.
        wa_tabdata-umren5       =  it_file_upload-value.
      WHEN  26.
        wa_tabdata-meinh5       =  it_file_upload-value.
      WHEN  27.
        wa_tabdata-umrez5       =  it_file_upload-value.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*     Sales Org. 1
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      WHEN  28.
        wa_tabdata-vrkme        =  it_file_upload-value.
      WHEN  29.
        wa_tabdata-dwerk        =  it_file_upload-value.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*     Sales Org. 2
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      WHEN  30.
        wa_tabdata-versg        =  it_file_upload-value.
      WHEN  31.
        wa_tabdata-ktgrm        =  it_file_upload-value.
      WHEN  32.
        wa_tabdata-mtpos        =  it_file_upload-value.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*     General/Plant.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      WHEN  33.
        wa_tabdata-brgew        =  it_file_upload-value.
      WHEN  34.
        wa_tabdata-ntgew        =  it_file_upload-value.
      WHEN  35.
        wa_tabdata-mtvfp        =  it_file_upload-value.
      WHEN  36.
        wa_tabdata-tragr        =  it_file_upload-value.
      WHEN  37.
        wa_tabdata-ladgr        =  it_file_upload-value.
      WHEN  38.
        wa_tabdata-prctr        =  it_file_upload-value.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*     Foreign Trade Export.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      WHEN  39.
        wa_tabdata-herkl       =  it_file_upload-value.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*     Purchasing.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      WHEN  40.
        wa_tabdata-bstme       =  it_file_upload-value.
      WHEN  41.
        wa_tabdata-kautb       =  it_file_upload-value.
      WHEN  42.
        wa_tabdata-xchpf       =  it_file_upload-value.
      WHEN  43.
        wa_tabdata-ekgrp       =  it_file_upload-value.
      WHEN  44.
        wa_tabdata-webaz       =  it_file_upload-value.
      WHEN  45.
        wa_tabdata-ekwsl       =  it_file_upload-value.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*     Purch.Order Text.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      WHEN  46.
        wa_tabdata-ptext       =  it_file_upload-value.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*     MRP 1
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      WHEN  47.
        wa_tabdata-disgr       =  it_file_upload-value.
      WHEN  48.
        wa_tabdata-dismm       =  it_file_upload-value.
      WHEN  49.
        wa_tabdata-minbe       =  it_file_upload-value.
      WHEN  50.
        wa_tabdata-dispo       =  it_file_upload-value.
      WHEN  51.
        wa_tabdata-disls       =  it_file_upload-value.
      WHEN  52.
        wa_tabdata-bstfe       =  it_file_upload-value.
      WHEN  53.
        wa_tabdata-bstmi       =  it_file_upload-value.
      WHEN  54.
        wa_tabdata-bstma       =  it_file_upload-value.
      WHEN  55.
        wa_tabdata-ausss       =  it_file_upload-value.
      WHEN  56.
        wa_tabdata-bstrf       =  it_file_upload-value.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*     MRP 2
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      WHEN  57.
        wa_tabdata-beskz       =  it_file_upload-value.
      WHEN  58.
        wa_tabdata-sobsl       =  it_file_upload-value.
      WHEN  59.
        wa_tabdata-lgpro       =  it_file_upload-value.
      WHEN  60.
        wa_tabdata-rgekz       =  it_file_upload-value.
      WHEN  61.
        wa_tabdata-lgfsb       =  it_file_upload-value.
      WHEN  62.
        wa_tabdata-dzeit       =  it_file_upload-value.
      WHEN  63.
        wa_tabdata-plifz       =  it_file_upload-value.
      WHEN  64.
        wa_tabdata-mrppp       =  it_file_upload-value.
      WHEN  65.
        wa_tabdata-fhori       =  it_file_upload-value.
      WHEN  66.
        wa_tabdata-eisbe       =  it_file_upload-value.
      WHEN  67.
        wa_tabdata-webaz1      =  it_file_upload-value.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*     MRP 3
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      WHEN  68.
        wa_tabdata-strgr       =  it_file_upload-value.
      WHEN  69.
        wa_tabdata-vrmod       =  it_file_upload-value.
      WHEN  70.
        wa_tabdata-vint1       =  it_file_upload-value.
      WHEN  71.
        wa_tabdata-vint2       =  it_file_upload-value.
      WHEN  72.
        wa_tabdata-miskz       =  it_file_upload-value.
      WHEN  73.
        wa_tabdata-mtvfp1      =  it_file_upload-value.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*     MRP 4
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      WHEN  74.
        wa_tabdata-altsl       =  it_file_upload-value.
      WHEN  75.
        wa_tabdata-kausf       =  it_file_upload-value.
      WHEN  76.
        wa_tabdata-sbdkz       =  it_file_upload-value.
      WHEN  77.
        wa_tabdata-sauft       =  it_file_upload-value.
      WHEN  78.
        wa_tabdata-sfepr       =  it_file_upload-value.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*     Work Scheduling.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      WHEN  79.
        wa_tabdata-frtme       =  it_file_upload-value.
      WHEN  80.
        wa_tabdata-fevor       =  it_file_upload-value.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*     Plant Data / Stor. 1
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      WHEN  81.
        wa_tabdata-ausme       =  it_file_upload-value.
      WHEN  82.
        wa_tabdata-mhdrz       =  it_file_upload-value.
      WHEN  83.
        wa_tabdata-mhdhb       =  it_file_upload-value.
      WHEN  84.
        wa_tabdata-iprkz       =  it_file_upload-value.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*     Quality Management.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      WHEN  85.
        wa_tabdata-webaz2      =  it_file_upload-value.
      WHEN  86.
        wa_tabdata-qmpur       =  it_file_upload-value.
      WHEN  87.
        wa_tabdata-ssqss       =  it_file_upload-value.
      WHEN  88.
        wa_tabdata-qzgtp       =  it_file_upload-value.
      WHEN  89.
        wa_tabdata-qmatv       =  it_file_upload-value.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*     Inspection Setup Data.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      WHEN  90.
        wa_tabdata-art1        =  it_file_upload-value.
      WHEN  91.
        wa_tabdata-aktiv1      =  it_file_upload-value.
*     ...........................................................
      WHEN  92.
        wa_tabdata-art2        =  it_file_upload-value.
      WHEN  93.
        wa_tabdata-aktiv2      =  it_file_upload-value.
*     ...........................................................
      WHEN  94.
        wa_tabdata-art3        =  it_file_upload-value.
      WHEN  95.
        wa_tabdata-aktiv3      =  it_file_upload-value.
*     ...........................................................
      WHEN  96.
        wa_tabdata-art4        =  it_file_upload-value.
      WHEN  97.
        wa_tabdata-aktiv4      =  it_file_upload-value.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*     Accounting 1.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      WHEN  98.
        wa_tabdata-bklas       =  it_file_upload-value.
      WHEN  99.
        wa_tabdata-vprsv       =  it_file_upload-value.
      WHEN  100.
        wa_tabdata-peinh       =  it_file_upload-value.
      WHEN  101.
        wa_tabdata-stprs       =  it_file_upload-value.
      WHEN  102.
        wa_tabdata-verpr       =  it_file_upload-value.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*     Cost Estimate 1.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      WHEN  103.
        wa_tabdata-ekalr       =  it_file_upload-value.
      WHEN  104.
        wa_tabdata-hkmat       =  it_file_upload-value.
      WHEN  105.
        wa_tabdata-awsls       =  it_file_upload-value.
      WHEN  106.
        wa_tabdata-prctr1      =  it_file_upload-value.
      WHEN  107.
        wa_tabdata-losgr       =  it_file_upload-value.
*     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    ENDCASE.
    AT  END  OF  row.
      lv_row_cnt          =  lv_row_cnt  +  1.
      wa_tabdata-rowcnt   =  lv_row_cnt.
      APPEND  wa_tabdata  TO  it_tabdata.
      CLEAR:  wa_tabdata.
    ENDAT.
  ENDLOOP.
ENDFORM.                    " ORGANIZE_UPLOADED_DATA
*&---------------------------------------------------------------------*
*&      Form  MODIFY_ROW_NUMBER
*&---------------------------------------------------------------------*
FORM modify_row_number .
  DATA:  lv_row  TYPE  i.
  LOOP  AT  it_tabdata  INTO  wa_tabdata.
    IF  wa_tabdata-matnr  NE  space.
      CLEAR: lv_row.
    ENDIF.
    lv_row          =  lv_row  +  1.
    wa_tabdata-row  =  lv_row.
    MODIFY  it_tabdata  FROM  wa_tabdata
                        TRANSPORTING  row.
  ENDLOOP.
ENDFORM.                    " MODIFY_ROW_NUMBER
*&---------------------------------------------------------------------*
*&      Form  OPEN_BDC_SESSION
*&---------------------------------------------------------------------*
FORM open_bdc_session .
  DATA:  lv_session  TYPE  apq_grpn.
  lv_session  =  'MATMAST_1'.
  CALL FUNCTION 'BDC_OPEN_GROUP'
    EXPORTING
      client              = sy-mandt
      group               = lv_session
      keep                = 'X'
      user                = sy-uname
    EXCEPTIONS
      client_invalid      = 1
      destination_invalid = 2
      group_invalid       = 3
      group_is_locked     = 4
      holddate_invalid    = 5
      internal_error      = 6
      queue_error         = 7
      running             = 8
      system_lock_error   = 9
      user_invalid        = 10
      OTHERS              = 11.

ENDFORM.                    " OPEN_BDC_SESSION
*&---------------------------------------------------------------------*
*&      Form  BDC_OPERATION
*&---------------------------------------------------------------------*
FORM bdc_operation .
  LOOP  AT  it_tabdata  INTO  wa_tabdata.
    IF  wa_tabdata-matnr  NE  ''.
*     ------------------------------------------------------------
*     Transaction Code - MM01    Create Material : Initial Screen.
*     ------------------------------------------------------------
      PERFORM  bdc_dynpro  USING  'SAPLMGMM'               '0060'.
      PERFORM  bdc_field   USING  'BDC_CURSOR'             'RMMG1-MTART'.
      PERFORM  bdc_field   USING  'BDC_OKCODE'             '=ENTR'.
      PERFORM  bdc_field   USING  'RMMG1-MATNR'            wa_tabdata-matnr.
      PERFORM  bdc_field   USING  'RMMG1-MBRSH'            wa_tabdata-mbrsh.
      PERFORM  bdc_field   USING  'RMMG1-MTART'            wa_tabdata-mtart.
      IF  wa_tabdata-mtart  NE  'ROH'.
*       ------------------------------------------------------------
*       Transaction Code - MM01    Views Selection Screen (not ROH).
*       ------------------------------------------------------------
        PERFORM  bdc_dynpro  USING  'SAPLMGMM'              '0070'.
        PERFORM  bdc_field   USING  'BDC_CURSOR'            'MSICHTAUSW-DYTXT(17)'.
        PERFORM  bdc_field   USING  'BDC_OKCODE'            '=P+'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(04)'  'X'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(05)'  'X'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(06)'  'X'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(07)'  'X'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(09)'  'X'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(11)'  'X'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(12)'  'X'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(13)'  'X'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(14)'  'X'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(15)'  'X'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(16)'  'X'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(17)'  'X'.
        PERFORM  bdc_dynpro  USING  'SAPLMGMM'              '0070'.
        PERFORM  bdc_field   USING  'BDC_CURSOR'            'MSICHTAUSW-DYTXT(07)'.
        PERFORM  bdc_field   USING  'BDC_OKCODE'            '=ENTR'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(04)'  'X'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(05)'  'X'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(07)'  'X'.
      ELSE.
*       ------------------------------------------------------------
*       Transaction Code - MM01    Views Selection Screen ( = ROH).
*       ------------------------------------------------------------
        PERFORM  bdc_dynpro  USING  'SAPLMGMM'              '0070'.
        PERFORM  bdc_field   USING  'BDC_CURSOR'            'MSICHTAUSW-DYTXT(16)'.
        PERFORM  bdc_field   USING  'BDC_OKCODE'            '=P+'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(04)'  'X'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(05)'  'X'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(06)'  'X'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(07)'  'X'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(09)'  'X'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(11)'  'X'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(12)'  'X'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(13)'  'X'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(14)'  'X'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(15)'  'X'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(16)'  'X'.
        PERFORM  bdc_dynpro  USING  'SAPLMGMM'              '0070'.
        PERFORM  bdc_field   USING  'BDC_CURSOR'            'MSICHTAUSW-DYTXT(07)'.
        PERFORM  bdc_field   USING  'BDC_OKCODE'            '=ENTR'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(03)'  'X'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(04)'  'X'.
        PERFORM  bdc_field   USING  'MSICHTAUSW-KZSEL(06)'  'X'.
      ENDIF.
*     --------------------------------------------------------
*     Transaction Code - MM01    Organizational Levels Screen.
*     --------------------------------------------------------
      PERFORM  bdc_dynpro  USING  'SAPLMGMM'              '0080'.
      PERFORM  bdc_field   USING  'BDC_CURSOR'            'RMMG1-VTWEG'.
      PERFORM  bdc_field   USING  'BDC_OKCODE'            '=ENTR'.
      PERFORM  bdc_field   USING  'RMMG1-WERKS'           wa_tabdata-werks.
      PERFORM  bdc_field   USING  'RMMG1-LGORT'           wa_tabdata-lgort.
      PERFORM  bdc_field   USING  'RMMG1-VKORG'           wa_tabdata-vkorg.
      PERFORM  bdc_field   USING  'RMMG1-VTWEG'           wa_tabdata-vtweg.
*     ---------------------------------------------------------------------
*     Transaction Code - MM01    Sales Organization 1 - Tax Classification.
*     ---------------------------------------------------------------------
      PERFORM  bdc_dynpro  USING  'SAPLMGMM'              '4000'.
      PERFORM  bdc_field   USING  'BDC_OKCODE'            '/00'.
      PERFORM  bdc_field   USING  'BDC_CURSOR'            'MG03STEUER-TAXKM(02)'.
      PERFORM  bdc_field   USING  'MG03STEUER-TAXKM(01)'  wa_tabdata-taxkm1.
      PERFORM  bdc_field   USING  'MG03STEUER-TAXKM(02)'  wa_tabdata-taxkm2.
      PERFORM  bdc_dynpro  USING  'SAPLMGMM'              '4200'.
      PERFORM  bdc_field   USING  'BDC_OKCODE'            '/00'.
      PERFORM  bdc_field   USING  'BDC_CURSOR'            'MG03STEUER-TAXKM(05)'.
      PERFORM  bdc_field   USING  'MG03STEUER-TAXKM(03)'  wa_tabdata-taxkm3.
      PERFORM  bdc_field   USING  'MG03STEUER-TAXKM(04)'  wa_tabdata-taxkm4.
      PERFORM  bdc_field   USING  'MG03STEUER-TAXKM(05)'  wa_tabdata-taxkm5.
*     -------------------------------------------------
*     Transaction Code - MM01    Additional Data - UoM.
*     -------------------------------------------------
      PERFORM  bdc_dynpro  USING  'SAPLMGMM'              '4000'.
      PERFORM  bdc_field   USING  'BDC_OKCODE'            '=ZU01'.
      PERFORM  bdc_field   USING  'BDC_CURSOR'            'MAKT-MAKTX'.
      PERFORM  bdc_dynpro  USING  'SAPLMGMM'              '4300'.
      PERFORM  bdc_field   USING  'BDC_OKCODE'            '=ZU02'.
      PERFORM  bdc_field   USING  'BDC_CURSOR'            'RMMG1-MATNR'.
      PERFORM  bdc_dynpro  USING  'SAPLMGMM'              '4300'.
      PERFORM  bdc_field   USING  'BDC_OKCODE'            '/00'.
      PERFORM  bdc_field   USING  'BDC_CURSOR'            'SMEINH-UMREZ(06)'.
      PERFORM  bdc_field   USING  'SMEINH-UMREN(02)'      wa_tabdata-umren1.
      PERFORM  bdc_field   USING  'SMEINH-MEINH(02)'      wa_tabdata-meinh1.
      PERFORM  bdc_field   USING  'SMEINH-UMREZ(02)'      wa_tabdata-umrez1.
      PERFORM  bdc_field   USING  'SMEINH-UMREN(03)'      wa_tabdata-umren2.
      PERFORM  bdc_field   USING  'SMEINH-MEINH(03)'      wa_tabdata-meinh2.
      PERFORM  bdc_field   USING  'SMEINH-UMREZ(03)'      wa_tabdata-umrez2.
      PERFORM  bdc_field   USING  'SMEINH-UMREN(04)'      wa_tabdata-umren3.
      PERFORM  bdc_field   USING  'SMEINH-MEINH(04)'      wa_tabdata-meinh3.
      PERFORM  bdc_field   USING  'SMEINH-UMREZ(04)'      wa_tabdata-umrez3.
      PERFORM  bdc_field   USING  'SMEINH-UMREN(05)'      wa_tabdata-umren4.
      PERFORM  bdc_field   USING  'SMEINH-MEINH(05)'      wa_tabdata-meinh4.
      PERFORM  bdc_field   USING  'SMEINH-UMREZ(05)'      wa_tabdata-umrez4.
      PERFORM  bdc_field   USING  'SMEINH-UMREN(06)'      wa_tabdata-umren5.
      PERFORM  bdc_field   USING  'SMEINH-MEINH(06)'      wa_tabdata-meinh5.
      PERFORM  bdc_field   USING  'SMEINH-UMREZ(06)'      wa_tabdata-umrez5.
      PERFORM  bdc_dynpro  USING  'SAPLMGMM'              '4300'.
      PERFORM  bdc_field   USING  'BDC_OKCODE'            '=MAIN'.
      PERFORM  bdc_field   USING  'BDC_CURSOR'            'MAKT-MAKTX'.
*     ------------------------------------------------
*     Transaction Code - MM01    Sales Organization 1.
*     ------------------------------------------------
      PERFORM  bdc_dynpro  USING  'SAPLMGMM'              '4000'.
      PERFORM  bdc_field   USING  'BDC_OKCODE'            '/00'.
      PERFORM  bdc_field   USING  'BDC_CURSOR'            'MVKE-DWERK'.
      PERFORM  bdc_field   USING  'MVKE-VRKME'            wa_tabdata-vrkme.
      PERFORM  bdc_field   USING  'MVKE-DWERK'            wa_tabdata-dwerk.
*     ------------------------------------------------
*     Transaction Code - MM01    Sales Organization 2.
*     ------------------------------------------------
      PERFORM  bdc_dynpro  USING  'SAPLMGMM'              '4000'.
      PERFORM  bdc_field   USING  'BDC_OKCODE'            '/00'.
      PERFORM  bdc_field   USING  'BDC_CURSOR'            'MVKE-MTPOS'.
      PERFORM  bdc_field   USING  'MVKE-VERSG'            wa_tabdata-versg.
      PERFORM  bdc_field   USING  'MVKE-KTGRM'            wa_tabdata-ktgrm.
      PERFORM  bdc_field   USING  'MVKE-MTPOS'            wa_tabdata-mtpos.
*     -------------------------------------------
*     Transaction Code - MM01    General / Plant.
*     -------------------------------------------
      PERFORM  bdc_dynpro  USING  'SAPLMGMM'              '4000'.
      PERFORM  bdc_field   USING  'BDC_OKCODE'            '/00'.
      PERFORM  bdc_field   USING  'MARA-BRGEW'            wa_tabdata-brgew.
      PERFORM  bdc_field   USING  'MARA-NTGEW'            wa_tabdata-ntgew.
      PERFORM  bdc_field   USING  'MARC-MTVFP'            wa_tabdata-mtvfp.
      PERFORM  bdc_field   USING  'MARA-TRAGR'            wa_tabdata-tragr.
      PERFORM  bdc_field   USING  'MARC-LADGR'            wa_tabdata-ladgr.
      PERFORM  bdc_field   USING  'BDC_CURSOR'            'MARC-PRCTR'.
      PERFORM  bdc_field   USING  'MARC-PRCTR'            wa_tabdata-prctr.
*     ------------------------------------------------
*     Transaction Code - MM01    Foreign Trade Export.
*     ------------------------------------------------
      PERFORM  bdc_dynpro  USING  'SAPLMGMM'              '4004'.
      PERFORM  bdc_field   USING  'BDC_OKCODE'            '/00'.
      PERFORM  bdc_field   USING  'BDC_CURSOR'            'MARC-HERKL'.
      PERFORM  bdc_field   USING  'MARC-HERKL'            wa_tabdata-herkl.
*     --------------------------------------
*     Transaction Code - MM01    Purchasing.
*     --------------------------------------
      PERFORM  bdc_dynpro  USING  'SAPLMGMM'              '4000'.
      PERFORM  bdc_field   USING  'BDC_OKCODE'            '/00'.
      PERFORM  bdc_field   USING  'BDC_CURSOR'            'MARC-EKGRP'.
      PERFORM  bdc_field   USING  'MARA-BSTME'            wa_tabdata-bstme.
      PERFORM  bdc_field   USING  'MARC-KAUTB'            wa_tabdata-kautb.
      PERFORM  bdc_field   USING  'MARC-XCHPF'            wa_tabdata-xchpf.
      PERFORM  bdc_field   USING  'MARC-EKGRP'            wa_tabdata-ekgrp.
      PERFORM  bdc_field   USING  'MARC-WEBAZ'            wa_tabdata-webaz.
      PERFORM  bdc_field   USING  'MARA-EKWSL'            wa_tabdata-ekwsl.
*     -----------------------------------------------
*     Transaction Code - MM01    Purchase Order Text.
*     -----------------------------------------------
*      PERFORM  BDC_DYNPRO  USING  'SAPLMGMM'              '4040'.
*      PERFORM  BDC_FIELD   USING  'BDC_OKCODE'            '=LTEX'.
*
*      PERFORM  BDC_DYNPRO  USING  'SAPLSTXX'              '1100'.
*      PERFORM  BDC_FIELD   USING  'BDC_CURSOR'            'RSTXT-TXLINE(02)'.
*      PERFORM  BDC_FIELD   USING  'BDC_OKCODE'            '=TXBA'.
*      PERFORM  BDC_FIELD   USING  'RSTXT-TXLINE(02)'      WA_TABDATA-PTEXT.
*
*      PERFORM  BDC_DYNPRO  USING  'SAPLSPO1'              '0100'.
*      PERFORM  BDC_FIELD   USING  'BDC_OKCODE'            '=YES'.
      PERFORM  bdc_dynpro  USING  'SAPLMGMM'              '4040'.
      PERFORM  bdc_field   USING  'BDC_OKCODE'            '=SP12'.
*     ---------------------------------
*     Transaction Code - MM01    MRP 1.
*     ---------------------------------
      PERFORM  bdc_dynpro  USING  'SAPLMGMM'              '4000'.
      PERFORM  bdc_field   USING  'BDC_OKCODE'            '/00'.
      PERFORM  bdc_field   USING  'MARC-DISGR'            wa_tabdata-disgr.
      PERFORM  bdc_field   USING  'MARC-DISMM'            wa_tabdata-dismm.
      PERFORM  bdc_field   USING  'MARC-MINBE'            wa_tabdata-minbe.
      PERFORM  bdc_field   USING  'MARC-DISPO'            wa_tabdata-dispo.
      PERFORM  bdc_field   USING  'BDC_CURSOR'            'MARC-BSTRF'.
      PERFORM  bdc_field   USING  'MARC-DISLS'            wa_tabdata-disls.
      PERFORM  bdc_field   USING  'MARC-BSTFE'            wa_tabdata-bstfe.
      PERFORM  bdc_field   USING  'MARC-BSTMI'            wa_tabdata-bstmi.
      PERFORM  bdc_field   USING  'MARC-BSTMA'            wa_tabdata-bstma.
      PERFORM  bdc_field   USING  'MARC-AUSSS'            wa_tabdata-ausss.
      PERFORM  bdc_field   USING  'MARC-BSTRF'            wa_tabdata-bstrf.
*     ---------------------------------
*     Transaction Code - MM01    MRP 2.
*     ---------------------------------
      PERFORM  bdc_dynpro  USING  'SAPLMGMM'              '4000'.
      PERFORM  bdc_field   USING  'BDC_OKCODE'            'SP14'.
      PERFORM  bdc_field   USING  'MARC-BESKZ'            wa_tabdata-beskz.
      PERFORM  bdc_field   USING  'MARC-SOBSL'            wa_tabdata-sobsl.
      PERFORM  bdc_field   USING  'MARC-LGPRO'            wa_tabdata-lgpro.
      PERFORM  bdc_field   USING  'MARC-RGEKZ'            wa_tabdata-rgekz.
      PERFORM  bdc_field   USING  'MARC-LGFSB'            wa_tabdata-lgfsb.
      PERFORM  bdc_field   USING  'MARC-DZEIT'            wa_tabdata-dzeit.
      PERFORM  bdc_field   USING  'MARC-PLIFZ'            wa_tabdata-plifz.
      PERFORM  bdc_field   USING  'MARC-MRPPP'            wa_tabdata-mrppp.
      PERFORM  bdc_field   USING  'MARC-FHORI'            wa_tabdata-fhori.
      PERFORM  bdc_field   USING  'MARC-EISBE'            wa_tabdata-eisbe.
      IF  wa_tabdata-webaz  EQ  ''.
        PERFORM  bdc_field   USING  'MARC-WEBAZ'            wa_tabdata-webaz1.
      ENDIF.
*     ---------------------------------
*     Transaction Code - MM01    MRP 3.
*     ---------------------------------
      PERFORM  bdc_dynpro  USING  'SAPLMGMM'              '4000'.
      PERFORM  bdc_field   USING  'BDC_OKCODE'            'SP15'.
      PERFORM  bdc_field   USING  'MARC-STRGR'            wa_tabdata-strgr.
      PERFORM  bdc_field   USING  'MARC-VRMOD'            wa_tabdata-vrmod.
      PERFORM  bdc_field   USING  'MARC-VINT1'            wa_tabdata-vint1.
      PERFORM  bdc_field   USING  'MARC-VINT2'            wa_tabdata-vint2.
      PERFORM  bdc_field   USING  'MARC-MISKZ'            wa_tabdata-miskz.
      PERFORM  bdc_field   USING  'BDC_CURSOR'            'MARC-MTVFP'.
      IF  wa_tabdata-mtvfp  EQ  ''.
        PERFORM  bdc_field   USING  'MARC-MTVFP'            wa_tabdata-mtvfp1.
      ENDIF.
*     ---------------------------------
*     Transaction Code - MM01    MRP 4.
*     ---------------------------------
      PERFORM  bdc_dynpro  USING  'SAPLMGMM'              '4000'.
      PERFORM  bdc_field   USING  'BDC_OKCODE'            '/00'.
      PERFORM  bdc_field   USING  'MARC-ALTSL'            wa_tabdata-altsl.
      PERFORM  bdc_field   USING  'MARC-KAUSF'            wa_tabdata-kausf.
      PERFORM  bdc_field   USING  'MARC-SBDKZ'            wa_tabdata-sbdkz.
      PERFORM  bdc_field   USING  'BDC_CURSOR'            'MARC-SFEPR'.
      PERFORM  bdc_field   USING  'MARC-SAUFT'            wa_tabdata-sauft.
      PERFORM  bdc_field   USING  'MARC-SFEPR'            wa_tabdata-sfepr.
      IF  wa_tabdata-mtart  NE  'ROH'.
*       -------------------------------------------
*       Transaction Code - MM01    Work Scheduling.
*       -------------------------------------------
        PERFORM  bdc_dynpro  USING  'SAPLMGMM'              '4000'.
        PERFORM  bdc_field   USING  'BDC_OKCODE'            '/00'.
        PERFORM  bdc_field   USING  'BDC_CURSOR'            'MARC-FEVOR'.
        PERFORM  bdc_field   USING  'MARC-FRTME'            wa_tabdata-frtme.
        PERFORM  bdc_field   USING  'MARC-FEVOR'            wa_tabdata-fevor.
      ENDIF.
*     ------------------------------------------------
*     Transaction Code - MM01    Plant Data / Stor. 1.
*     ------------------------------------------------
      PERFORM  bdc_dynpro  USING  'SAPLMGMM'              '4000'.
      PERFORM  bdc_field   USING  'BDC_OKCODE'            '/00'.
      PERFORM  bdc_field   USING  'MARC-AUSME'            wa_tabdata-ausme.
      PERFORM  bdc_field   USING  'BDC_CURSOR'            'MARA-IPRKZ'.
      PERFORM  bdc_field   USING  'MARA-MHDRZ'            wa_tabdata-mhdrz.
      PERFORM  bdc_field   USING  'MARA-MHDHB'            wa_tabdata-mhdhb.
      PERFORM  bdc_field   USING  'MARA-IPRKZ'            wa_tabdata-iprkz.
*     ----------------------------------------------
*     Transaction Code - MM01    Quality Management.
*     ----------------------------------------------
      PERFORM  bdc_dynpro  USING  'SAPLMGMM'              '4000'.
      PERFORM  bdc_field   USING  'BDC_OKCODE'            '=PB01'.
      PERFORM  bdc_field   USING  'BDC_CURSOR'            'MARC-QZGTP'.
      PERFORM  bdc_field   USING  'MARC-WEBAZ'            wa_tabdata-webaz2.
      PERFORM  bdc_field   USING  'MARA-QMPUR'            wa_tabdata-qmpur.
      PERFORM  bdc_field   USING  'MARC-SSQSS'            wa_tabdata-ssqss.
      PERFORM  bdc_field   USING  'MARC-QZGTP'            wa_tabdata-qzgtp.
      IF  wa_tabdata-qmatv  EQ  'X'.
*       -------------------------------------------------
*       Transaction Code - MM01    Inspection Setup Data.
*       -------------------------------------------------
        PERFORM  bdc_dynpro  USING  'SAPLQPLS'              '0100'.
        PERFORM  bdc_field   USING  'BDC_CURSOR'            'RMQAM-ARGUMENT'.
        PERFORM  bdc_field   USING  'BDC_OKCODE'            '=NEU'.
        PERFORM  bdc_dynpro  USING  'SAPLQPLS'              '0100'.
        PERFORM  bdc_field   USING  'BDC_CURSOR'            'RMQAM-AKTIV(04)'.
        PERFORM  bdc_field   USING  'BDC_OKCODE'            '=WEIT'.
        PERFORM  bdc_field   USING  'RMQAM-ART(01)'         wa_tabdata-art1.
        PERFORM  bdc_field   USING  'RMQAM-AKTIV(01)'       wa_tabdata-aktiv1.
        PERFORM  bdc_field   USING  'RMQAM-ART(02)'         wa_tabdata-art2.
        PERFORM  bdc_field   USING  'RMQAM-AKTIV(02)'       wa_tabdata-aktiv2.
        PERFORM  bdc_field   USING  'RMQAM-ART(03)'         wa_tabdata-art3.
        PERFORM  bdc_field   USING  'RMQAM-AKTIV(03)'       wa_tabdata-aktiv3.
        PERFORM  bdc_field   USING  'RMQAM-ART(04)'         wa_tabdata-art4.
        PERFORM  bdc_field   USING  'RMQAM-AKTIV(04)'       wa_tabdata-aktiv4.
        PERFORM  bdc_dynpro  USING  'SAPLMGMM'              '4000'.
        PERFORM  bdc_field   USING  'BDC_OKCODE'            '/00'.
        PERFORM  bdc_field   USING  'BDC_CURSOR'            'MAKT-MAKTX'.
      ENDIF.
*     ----------------------------------------
*     Transaction Code - MM01    Accounting 1.
*     ----------------------------------------
      PERFORM  bdc_dynpro  USING  'SAPLMGMM'              '4000'.
      PERFORM  bdc_field   USING  'BDC_OKCODE'            '=SP26'.
      PERFORM  bdc_field   USING  'BDC_CURSOR'            'MBEW-BKLAS'.
      PERFORM  bdc_field   USING  'MBEW-BKLAS'            wa_tabdata-bklas.
      PERFORM  bdc_field   USING  'MBEW-VPRSV'            wa_tabdata-vprsv.
      PERFORM  bdc_field   USING  'MBEW-PEINH'            wa_tabdata-peinh.
      PERFORM  bdc_field   USING  'MBEW-STPRS'            wa_tabdata-stprs.
      PERFORM  bdc_field   USING  'MBEW-VERPR'            wa_tabdata-verpr.
*     -------------------------------------------
*     Transaction Code - MM01    Cost Estimate 1.
*     -------------------------------------------
      PERFORM  bdc_dynpro  USING  'SAPLMGMM'              '4000'.
      PERFORM  bdc_field   USING  'BDC_OKCODE'            '/00'.
      PERFORM  bdc_field   USING  'MBEW-EKALR'            wa_tabdata-ekalr.
      PERFORM  bdc_field   USING  'MBEW-HKMAT'            wa_tabdata-hkmat.
      IF  wa_tabdata-mtart  NE  'ROH'.
        PERFORM  bdc_field   USING  'MARC-AWSLS'            wa_tabdata-awsls.
      ENDIF.
      PERFORM  bdc_field   USING  'MARC-PRCTR'            wa_tabdata-prctr1.
      PERFORM  bdc_field   USING  'BDC_CURSOR'            'MARC-LOSGR'.
      PERFORM  bdc_field   USING  'MARC-LOSGR'            wa_tabdata-losgr.
*     ------------------------------------------
*     Transaction Code - MM01    Saving of Data.
*     ------------------------------------------
      PERFORM  bdc_dynpro  USING  'SAPLSPO1'           '0300'.
      PERFORM  bdc_field   USING  'BDC_OKCODE'         '=YES'.
*     ------------------------------------------
*     Call Transaction - MM01 to create Routing.
*     ------------------------------------------
      CALL  TRANSACTION  'MM01'  USING  bdcdata
                                 MODE   'E'
                                 UPDATE 'A'
                                 MESSAGES  INTO  msgtab.
      CLEAR:   bdcdata.
      REFRESH  bdcdata.
    ENDIF.
  ENDLOOP.
ENDFORM.                    " BDC_OPERATION
*&---------------------------------------------------------------------*
*&      Form  CLOSE_BDC_SESSION
*&---------------------------------------------------------------------*
FORM close_bdc_session .
  CALL FUNCTION 'BDC_CLOSE_GROUP'
    EXCEPTIONS
      not_open    = 1
      queue_error = 2
      OTHERS      = 3.

ENDFORM.                    " CLOSE_BDC_SESSION
*&---------------------------------------------------------------------*
*&      Form  BDC_DYNPRO
*&---------------------------------------------------------------------*
FORM bdc_dynpro  USING    program
                          dynpro.
  CLEAR:  bdcdata.
  bdcdata-program   =  program.
  bdcdata-dynpro    =  dynpro.
  bdcdata-dynbegin  =  'X'.
  APPEND  bdcdata.
ENDFORM.                    " BDC_DYNPRO
*&---------------------------------------------------------------------*
*&      Form  BDC_FIELD
*&---------------------------------------------------------------------*
FORM bdc_field  USING    fnam
                         fval.
  CLEAR:  bdcdata.
  bdcdata-fnam  =  fnam.
  bdcdata-fval  =  fval.
  APPEND  bdcdata.
ENDFORM.                    " BDC_FIELD
REPORT zbdcdemo
       NO STANDARD PAGE HEADING LINE-SIZE 255.

DATA: BEGIN OF it_data OCCURS 0,
      matnr TYPE mara-matnr,
      desc(35),
      END OF it_data.

DATA: it_bdcdata TYPE STANDARD TABLE OF bdcdata WITH HEADER LINE.

START-OF-SELECTION.

  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename = 'D:\BDC.TXT'
    TABLES
      data_tab = it_data[].
  IF sy-subrc <> 0.
  ENDIF.

  PERFORM open_group.

  LOOP AT it_data.
    REFRESH it_bdcdata.

    PERFORM bdc_dynpro      USING 'SAPLMGMM' '0060'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'RMMG1-MATNR'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  'AUSW'.
    PERFORM bdc_field       USING 'RMMG1-MATNR'
                                  it_data-matnr.
    PERFORM bdc_dynpro      USING 'SAPLMGMM' '0070'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'MSICHTAUSW-DYTXT(01)'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=ENTR'.
    PERFORM bdc_field       USING 'MSICHTAUSW-KZSEL(01)'
                                  'X'.
    PERFORM bdc_dynpro      USING 'SAPLMGMM' '4004'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=BU'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'MAKT-MAKTX'.
    PERFORM bdc_field       USING 'MAKT-MAKTX'
                                  it_data-desc.
*perform bdc_field       using 'MARA-MEINS'
*                              'EA'.
*perform bdc_field       using 'MARA-BEGRU'
*                              'SA'.
*perform bdc_field       using 'MARA-ZPLC_CD'
*                              '0'.
*perform bdc_field       using 'MARA-ZPAO_CD'
*                              '7A'.
*perform bdc_field       using 'MARA-ZPROD_LN_ID'
*                              '7X2144C'.
*perform bdc_field       using 'MARA-ZVALUED_PROD_FLG'
*                              'X'.
*perform bdc_field       using 'MARA-ZCOMP_TYPE_CD'
*                              'RS'.
*perform bdc_field       using 'MARA-ZLEGACY_DSC'
*                              'TEST'.
    PERFORM bdc_transaction USING 'MM02'.

  ENDLOOP.

  PERFORM close_group.

*&---------------------------------------------------------------------*
*&      Form  CLOSE_GROUP
*&---------------------------------------------------------------------*
FORM close_group.
  CALL FUNCTION 'BDC_CLOSE_GROUP'
    .
ENDFORM.                    "CLOSE_GROUP
*&---------------------------------------------------------------------*
*&      Form  bdc_dynpro
*&---------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
  CLEAR it_bdcdata.

  it_bdcdata-program = program.
  it_bdcdata-dynpro = dynpro.
  it_bdcdata-dynbegin = 'X'.
  APPEND it_bdcdata.
ENDFORM.                    "bdc_dynpro
*&---------------------------------------------------------------------*
*&      Form  BDC_FIELD
*&---------------------------------------------------------------------*
FORM bdc_field USING fnam fval.

  CLEAR it_bdcdata.

  it_bdcdata-fnam = fnam.
  it_bdcdata-fval = fval.

  APPEND it_bdcdata.
ENDFORM.                    "BDC_FIELD
*&---------------------------------------------------------------------*
*&      Form  open_group
*&---------------------------------------------------------------------*
FORM open_group.
  CALL FUNCTION 'BDC_OPEN_GROUP'
    EXPORTING
      client = sy-mandt
      group  = 'SESSION'
      keep   = 'X'
      user   = sy-uname.
  IF sy-subrc <> 0.
  ENDIF.
ENDFORM.                    "open_group
*&---------------------------------------------------------------------*
*&      Form  BDC_TRANSACTION
*&---------------------------------------------------------------------*
FORM bdc_transaction USING tcode.
  CALL FUNCTION 'BDC_INSERT'
    EXPORTING
      tcode     = 'MM02'
    TABLES
      dynprotab = it_bdcdata[].
  IF sy-subrc <> 0.
  ENDIF.
ENDFORM.                    "BDC_TRANSACTION
 

Following code is simple to get the complex services functionality involved in Service Master when you have Purchase Order and its line item:

This code not only brings the Services under PO but also from Contracts.

DATA: BEGIN OF i_esll OCCURS 0,
        ebeln LIKE ekpo-ebeln,
        ebelp LIKE ekpo-ebelp,
        srvpos LIKE esll-srvpos,
        menge LIKE esll-menge,
        meins LIKE esll-meins,
        peinh LIKE esll-peinh,
        brtwr LIKE esll-brtwr,
        old_meins LIKE esll-meins,
      END OF i_esll.
DATA: l_packno LIKE ekpo-packno,
      BEGIN OF it_esuc_esll OCCURS 0,
        sub_packno LIKE esll-sub_packno,
        package LIKE esll-package,
      END OF it_esuc_esll,
      it_pack LIKE it_esuc_esll OCCURS 0 WITH HEADER LINE.

CLEAR: l_packno, i_esll, i_esll[], it_esuc_esll,
        it_esuc_esll[].

* Get the Package No. from EKPO
SELECT SINGLE packno FROM ekpo
  INTO l_packno
  WHERE ebeln = i_ebeln
    AND ebelp = i_ebelp
    AND loekz = ' '.
IF NOT l_packno IS INITIAL.
* For the Package #, check whether sub packages are for Contract items?
  SELECT sub_packno FROM esuc
    INTO TABLE it_esuc_esll
    WHERE packno = l_packno
      AND del = space.
  IF sy-subrc <> 0.
* For the Package #,if sub packages are in not Contract items,go to ESLL
    SELECT sub_packno package FROM esll
      INTO TABLE it_esuc_esll
      WHERE packno = l_packno
        AND del = space.
  ENDIF.
ENDIF.
* Get the Subpackages which are one level above Service items
CLEAR: it_pack, it_pack[].
LOOP AT it_esuc_esll.
  IF NOT it_esuc_esll-sub_packno IS INITIAL
     AND it_esuc_esll-package = 'X'.
    MOVE it_esuc_esll TO it_pack.
    APPEND it_pack.
    CLEAR it_pack.
    DELETE it_esuc_esll.
  ELSEIF NOT it_esuc_esll-sub_packno IS INITIAL
  AND it_esuc_esll-package = ' '.
* This select will drill down and get all the hierarchial subpackages
    SELECT sub_packno package FROM esll
      APPENDING TABLE it_esuc_esll
      WHERE packno = it_esuc_esll-sub_packno
        AND del = space.
  ENDIF.
ENDLOOP.
* Get the Service Items for all the Subpackages
LOOP AT it_pack.
  SELECT srvpos menge meins peinh brtwr
    FROM esll
    APPENDING CORRESPONDING FIELDS OF TABLE i_esll
    WHERE packno = it_pack-sub_packno
      AND del = space.
ENDLOOP.
IF sy-subrc <> 0.
* If there are no sub packages, but direct link to Services from package
* go to ESLL with Package derived from EKPO for the PO Item
  SELECT srvpos menge meins peinh brtwr
    FROM esll
    INTO CORRESPONDING FIELDS OF TABLE i_esll
    WHERE packno = l_packno
      AND del = space.
ENDIF.
 
*Report to fetch Material classifications with characteristics.
REPORT zmaterial_classification.

TABLES:klah,
       mara,
       cabn,
       makt.

TYPE-POOLS:abap,
           slis.

*Types declarations

TYPES:BEGIN OF type_class1,
      class TYPE klah-class,
      klart TYPE klah-klart,
      END OF type_class1.

TYPES:BEGIN OF type_makt,
      matnr TYPE makt-matnr,
      maktx TYPE makt-maktx,
      END OF type_makt.

TYPES:BEGIN OF type_ksml,
      imerk TYPE ksml-imerk,
      clint TYPE ksml-clint,
      klart TYPE ksml-klart,
      END OF type_ksml.

TYPES:BEGIN OF type_charclass,
      atnam TYPE atnam,
      objek1_internal TYPE objnum,
      objek1 TYPE objnum,
      objek1_text TYPE clobjtxt,
      klart TYPE klah-klart,
      END OF type_charclass.

TYPES:BEGIN OF type_status,
       klart TYPE tclut-klart,
       status TYPE tclut-status,
       stext  TYPE tclut-stext,
      END OF type_status.

TYPES:BEGIN OF type_obtab,
      klart TYPE tcla-klart,
      obtab TYPE tabelle,
      END OF type_obtab.

TYPES:BEGIN OF type_final,
      matnr TYPE  clobjekte-objekt,
      class TYPE  klah-class,
      klart TYPE klah-klart,
      status TYPE sclass-statu,
      maktx TYPE makt-maktx,
      atnam TYPE clobjdat-atnam,
      atwrt TYPE clobjdat-ausp1,
      atbez TYPE clobjdat-smbez,
      stext TYPE tclut-stext,
      END OF type_final.

*Ranges
DATA:ra_matnr TYPE RANGE OF makt-matnr.

*Work Areas
DATA:wa_final TYPE type_final.
DATA:wa_class1 TYPE type_class1.
DATA:wa_makt1 TYPE type_makt.
DATA:wa_ksml TYPE type_ksml.
DATA:wa_charclass TYPE type_charclass.
DATA:wa_tcla1 TYPE type_obtab.
DATA:wa_status TYPE type_status.
DATA:wa_fieldcat  TYPE slis_fieldcat_alv.
DATA:wa_layout TYPE slis_layout_alv.
DATA:wa_matnr LIKE LINE OF ra_matnr.

*Internal tables
DATA:i_final TYPE TABLE OF type_final.
DATA:i_class1  TYPE STANDARD TABLE OF type_class1.
DATA:i_makt1   TYPE STANDARD TABLE OF type_makt.
DATA:i_ksml    TYPE STANDARD TABLE OF type_ksml.
DATA:i_ksml_te TYPE STANDARD TABLE OF type_ksml.
DATA:i_tcla1   TYPE STANDARD  TABLE OF type_obtab.
DATA:i_charclass TYPE STANDARD TABLE OF type_charclass.
DATA:i_status    TYPE STANDARD TABLE OF type_status.
DATA:i_fieldcat TYPE TABLE OF slis_fieldcat_alv.

*Variables
DATA:wf_initial_char TYPE rmclm-basisd.

*selection screen
SELECT-OPTIONS: s_klart FOR klah-klart,"Class type
        	  s_class FOR klah-class OBLIGATORY MATCHCODE OBJECT clas."Class name
SELECT-OPTIONS: s_maktx FOR makt-maktx NO INTERVALS NO-EXTENSION. "Material Decsription
SELECT-OPTIONS: s_matnr FOR  mara-matnr.  "Material No
SELECT-OPTIONS: s_prdha  FOR mara-prdha.  "Product heirarchy
SELECT-OPTIONS: s_atinn  FOR cabn-atinn.  "characteristics
SELECTION-SCREEN  SKIP 1.
PARAMETER p_disch AS CHECKBOX.  "Skip characteristics with initial value

START-OF-SELECTION.

  IF s_matnr[] IS NOT INITIAL OR s_maktx[] IS NOT INITIAL.
    IF s_maktx[] IS NOT INITIAL.
      LOOP AT s_maktx.
        CALL FUNCTION 'TERM_TRANSLATE_TO_UPPER_CASE'
          EXPORTING
            langu               = sy-langu
            text                = s_maktx-low
          IMPORTING
            text_uc             = s_maktx-low
          EXCEPTIONS
            no_locale_available = 1
            OTHERS              = 2.
        IF sy-subrc = 0.
          MODIFY s_maktx INDEX sy-tabix TRANSPORTING low.
        ENDIF.
      ENDLOOP.
    ENDIF.

    SELECT matnr maktx FROM makt INTO TABLE i_makt1
                WHERE  matnr IN s_matnr AND
                       spras = sy-langu AND
                       maktg IN s_maktx .
    IF i_makt1[] IS INITIAL.
      MESSAGE 'No records found' TYPE 'E'.
      EXIT.
    ELSE.
      LOOP AT i_makt1 INTO wa_makt1.
        wa_matnr-sign = 'I'.
        wa_matnr-option = 'EQ'.
        wa_matnr-low = wa_makt1-matnr.
        APPEND wa_matnr TO ra_matnr.
      ENDLOOP.
    ENDIF.
  ENDIF.

   SELECT class klart FROM klah INTO TABLE i_class1
          WHERE class IN s_class
          AND   klart IN s_klart.

  IF i_class1[] IS INITIAL.
    MESSAGE 'No records found' TYPE 'E'.
    EXIT.
  ENDIF.

  IF s_atinn[] IS NOT INITIAL.
    IF i_class1[] IS NOT INITIAL.
      SELECT imerk clint klart
                INTO TABLE i_ksml
                FROM ksml FOR ALL ENTRIES IN i_class1
                WHERE klart = i_class1-klart
                AND imerk IN s_atinn
                AND lkenz = space.
    ENDIF.

    IF i_ksml[] IS NOT INITIAL.
      SORT i_ksml BY imerk ASCENDING.
      i_ksml_te[] = i_ksml[].
      LOOP AT i_ksml_te INTO wa_ksml.
        AT NEW imerk.
          PERFORM get_classes USING wa_ksml-imerk
                                    wa_ksml-klart
                                    wa_ksml-clint.
        ENDAT.
      ENDLOOP.
      IF i_charclass[] IS INITIAL.
        MESSAGE 'No records found' TYPE 'E'.
        EXIT.
      ENDIF.
    ENDIF.
  ENDIF.

  IF i_class1[] IS NOT INITIAL.
    SELECT  klart
            status
            stext
            INTO  TABLE i_status
            FROM tclut
            FOR ALL ENTRIES IN i_class1
            WHERE klart = i_class1-klart
            AND   spras = sy-langu.
    SELECT klart obtab
          INTO TABLE i_tcla1
          FROM tcla
          FOR ALL ENTRIES IN i_class1
          WHERE klart = i_class1-klart.
  ENDIF.

  IF p_disch IS INITIAL.
    wf_initial_char = abap_true..
  ENDIF.

  IF s_atinn[] IS NOT INITIAL.
*Process the classes retrieved for the characteristics entered
    LOOP AT i_charclass INTO wa_charclass.
      PERFORM get_objects USING wa_charclass-objek1
                                wa_charclass-klart.
    ENDLOOP.
  ELSE.
*Process for all the classes entered
    LOOP AT i_class1 INTO wa_class1.
      PERFORM get_objects USING wa_class1-class
                                wa_class1-klart.
    ENDLOOP.
  ENDIF.

  IF i_final[] IS NOT INITIAL.
    PERFORM build_field_catalouge.
    PERFORM display_data.
  ELSE.
    MESSAGE 'No records found' TYPE 'E'.
    EXIT.

  ENDIF.

*&---------------------------------------------------------------------*
*&      Form  GET_CLASSES
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_<FS_KSML>_IMERK  text
*----------------------------------------------------------------------*
FORM get_classes  USING    p_imerk TYPE ksml-imerk
                           p_klart TYPE ksml-klart
                           p_clint TYPE ksml-clint.

  DATA:i_classes TYPE tt_ctwul_output.
  DATA:wa_classes TYPE ctwul_output.
  DATA:wa_ksmltemp TYPE type_ksml.

  DATA:wf_atnam TYPE atnam.

  CLEAR i_classes[].
  WRITE p_imerk TO wf_atnam USING EDIT MASK '==ATINN'.
  PERFORM get_characteristics TABLES i_classes
                              USING  wf_atnam
                                     p_klart.
  CHECK sy-subrc = 0.
  LOOP AT i_classes INTO wa_classes WHERE objek1 IN s_class.
    READ TABLE i_ksml WITH KEY clint = wa_classes-objek1_internal
                               klart =  wa_classes-klart
                               TRANSPORTING NO FIELDS.
    IF sy-subrc = 0.
      MOVE : wa_classes-objek1 TO wa_charclass-objek1,
             wa_classes-objek1_internal TO
             wa_charclass-objek1_internal,
             wa_classes-klart TO  wa_charclass-klart,
             wa_classes-objek1_text TO wa_charclass-objek1_text.
      wa_charclass-atnam = wf_atnam.
      APPEND wa_charclass TO i_charclass.
      CLEAR wa_charclass.
    ENDIF.
  ENDLOOP.

ENDFORM.                    " GET_CLASSES
*&---------------------------------------------------------------------*
*&      Form  GET_CHARACTERISTICS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_I_CLASSES  text
*      -->P_WF_ATNAM  text
*      -->P_P_KLART  text
*----------------------------------------------------------------------*
FORM get_characteristics  TABLES   p_classes TYPE tt_ctwul_output
                          USING    p_atnam TYPE atnam
                                   p_klart  TYPE klah-klart.

  CALL FUNCTION 'CTWUL_CHARACT_USAGE'
    EXPORTING
      charact_name      = p_atnam
      class_type        = p_klart
      classes           = 'X'
    IMPORTING
      et_classes        = p_classes[]
    EXCEPTIONS
      charact_not_found = 1
      value_conversion  = 2
      no_authority      = 3
      OTHERS            = 4.

ENDFORM.                    " GET_CHARACTERISTICS
*&---------------------------------------------------------------------*
*&      Form  GET_OBJECTS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_WA_CLASS1_CLASS  text
*      -->P_WA_CLASS1_KLART  text
*----------------------------------------------------------------------*
FORM get_objects  USING    p_wf_class TYPE any
                           p_klart TYPE klah-klart.

  DATA:i_objclass TYPE TABLE OF sclass.
  DATA:i_objectdata TYPE TABLE OF clobjdat.
  DATA:i_objects TYPE TABLE OF clobjekte.

  DATA:wa_objclass TYPE sclass.
  DATA:wa_objects TYPE clobjekte.
  DATA:wa_object_data TYPE clobjdat.


  DATA:wf_class TYPE klah-class.
  DATA:wf_node_l TYPE i.
  DATA:wf_node_h TYPE i.
  DATA:wf_obtab TYPE tcla-obtab.

  wf_class = p_wf_class.

  READ TABLE i_tcla1 INTO wa_tcla1 WITH KEY klart =  wa_class1-klart.
  IF sy-subrc = 0.
    wf_obtab = wa_tcla1-obtab.
  ENDIF.

  CALL FUNCTION 'CLAF_OBJECTS_OF_CLASS'
    EXPORTING
      class              = wf_class
      classes            = abap_true
      classtext          = abap_true
      classtype          = p_klart
      language           = sy-langu
      key_date           = sy-datum
      objecttable        = wf_obtab
      initial_charact    = wf_initial_char
    TABLES
      t_class            = i_objclass
      t_objectdata       = i_objectdata
      t_objects          = i_objects
    EXCEPTIONS
      no_classification  = 1
      invalid_class_type = 2
      OTHERS             = 3.
  IF sy-subrc = 0.

    LOOP AT i_objects INTO wa_objects.
      IF sy-tabix EQ 1.
        wf_node_l = sy-tabix.
        wf_node_h = wa_objects-anzaus.
      ELSE.
        wf_node_l = wf_node_h + 1.
        wf_node_h = wf_node_h + wa_objects-anzaus.
      ENDIF.

      IF ra_matnr[] IS NOT INITIAL.
        IF wa_objects-objekt NOT IN ra_matnr[].
          CONTINUE.
        ENDIF.
      ENDIF.

      READ TABLE i_objclass INTO wa_objclass
                   WITH KEY class = wf_class.
      IF sy-subrc NE 0.
        CLEAR wa_objclass.
      ENDIF.

      IF s_atinn[] IS NOT INITIAL.
        LOOP AT i_objectdata INTO wa_object_data FROM wf_node_l TO wf_node_h
                                                      WHERE atnam EQ wa_charclass-atnam.
          PERFORM build_data USING  wa_object_data
                                    wa_objects
                                    wa_objclass
                                    p_klart
                                    wf_class.
        ENDLOOP.
      ELSE.
        LOOP AT i_objectdata INTO wa_object_data FROM wf_node_l TO wf_node_h.
          PERFORM build_data USING  wa_object_data
                                    wa_objects
                                    wa_objclass
                                    p_klart
                                    wf_class.

        ENDLOOP.
      ENDIF.
    ENDLOOP.
  ENDIF.
ENDFORM.                    " GET_OBJECTS
*&---------------------------------------------------------------------*
*&      Form  BUILD_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_WA_OBJECTDATA  text
*      -->P_WA_OBJECTS  text
*      -->P_P_KLART  text
*      -->P_WF_CLASS  text
*----------------------------------------------------------------------*
FORM build_data  USING    p_wa_objectdata TYPE clobjdat
                          p_wa_objects TYPE clobjekte
                          p_wa_class TYPE sclass
                          p_p_klart TYPE klah-klart
                          p_wf_class TYPE klah-class.

  wa_final-matnr =  p_wa_objects-objekt.
  wa_final-klart = p_p_klart.
  wa_final-class = p_wf_class.
  wa_final-status = p_wa_class-statu.
  IF wa_makt1-matnr <> p_wa_objects-objekt.
    READ TABLE i_makt1 INTO wa_makt1
               WITH KEY matnr = p_wa_objects-objekt BINARY SEARCH
               TRANSPORTING maktx.
    IF sy-subrc <> 0.
      CLEAR wa_makt1.
    ENDIF.
 ENDIF.
  wa_final-maktx = wa_makt1-maktx.
  wa_final-atnam = p_wa_objectdata-atnam.
  wa_final-atwrt = p_wa_objectdata-ausp1.
  wa_final-atbez = p_wa_objectdata-smbez.
  IF p_wa_class-statu <> wa_status-status.
    READ TABLE i_status INTO wa_status
               WITH KEY status = p_wa_class-statu.
    IF sy-subrc <> 0.
      CLEAR  wa_status.
    ENDIF.
  ENDIF.
  wa_final-stext = wa_status-stext.
  APPEND wa_final TO i_final.
ENDFORM.                    " BUILD_DATA
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELD_CATALOUGE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM build_field_catalouge .

  wa_layout-colwidth_optimize = abap_true.
  wa_layout-zebra = abap_true.

  wa_fieldcat-fieldname = 'MATNR'.
  wa_fieldcat-seltext_m = 'Material No'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname = 'MAKTX'.
  wa_fieldcat-seltext_m = 'Description'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname = 'CLASS'.
  wa_fieldcat-seltext_m = 'Class Name'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname = 'KLART'.
  wa_fieldcat-seltext_m = 'Class Type'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname = 'ATNAM'.
  wa_fieldcat-seltext_m = 'Characteristic Name'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname = 'ATBEZ'.
  wa_fieldcat-seltext_m = 'Characteristic Text'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname = 'ATWRT'.
  wa_fieldcat-seltext_m = 'Characteristic Value'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname = 'STATUS'.
  wa_fieldcat-seltext_m = 'Status'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname = 'STEXT'.
  wa_fieldcat-seltext_m = 'Status Text'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.

ENDFORM.                    " BUILD_FIELD_CATALOUGE
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM display_data .

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = sy-repid
      i_grid_title       = 'Material classification and Characteristics'
      is_layout          = wa_layout
      it_fieldcat        = i_fieldcat[]
    TABLES
      t_outtab           = i_final[]
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.
ENDFORM.                    " DISPLAY_DATA

Here is the code snippet by which you can find the raw material against any finished material assigned in the BOM .

Matnr ->finished material

Raw_Mat-> Raw material

TYPES:
BEGIN OF idnrk,
  menge TYPE stpo-menge,
  idnrk TYPE stpo-idnrk,
END OF idnrk.
DATA: stlnr TYPE mast-stlnr,
      it_idnrk TYPE TABLE OF idnrk,
      wa_idnrk TYPE idnrk,
      matnr TYPE matnr,
      raw_mat TYPE matnr.

matnr = finished_material. "Here assign the finished material to MATNR variable.
DO.

  SELECT SINGLE stlnr  FROM mast INTO stlnr WHERE matnr = matnr
    AND werks = 'SP01' AND stlan = '1' AND stlal = '01'.

  SELECT idnrk FROM stpo INTO CORRESPONDING FIELDS OF TABLE it_idnrk
    WHERE stlnr = stlnr
      AND stlty = 'M'.
  IF it_idnrk IS NOT INITIAL.

    LOOP AT it_idnrk INTO wa_idnrk.
      IF sy-tabix = 1.
        IF matnr NE wa_idnrk-idnrk.
          CLEAR matnr.
          matnr = wa_idnrk-idnrk.
        ELSEIF matnr EQ wa_idnrk-idnrk.
          raw_mat = matnr.
          EXIT.
        ENDIF.
      ELSE.
        EXIT.
      ENDIF.
    ENDLOOP.
    IF raw_mat IS INITIAL.
      CONTINUE.
    ELSE.
      EXIT.
    ENDIF.
  ELSE.
    EXIT.
  ENDIF.
ENDDO.
 

Author: https://www.sdn.sap.com/irj/scn/bc?u=TisjBOXjd1g%3D

Submitted: 02 Jan 2009
How to append MARA & call BAPI_MATERIAL_SAVEDATA

How to append the table structure MARA, BAPI_TE_MARA & BAPI_TE_MARAX.

Append the MARA structure in SE11 using "Append Structure" button.

When we activate the new structure it adjusts the MARA table & it may take few minutes to activate
Append BAPI_TE_MARA with exact same field names as appended in MARA table. Structure name will be different but field names & length should be same.

Append BAPI_TE_MARAX with exact same field names as appended in MARA table. Structure name will be different but field names should be same. Make sure that component type is BAPIUPDATE (Char 1)

Add records in table T130F for all the appended fields.

Sample code to populate EXTENSIONIN & EXTENSIONINX tables & call BAPI_MATERIAL_SAVEDATA.

*&---------------------------------------------------------------------*
*& Report  Z_VMA_MARA_EXT
*& written by : Vivek Amrute.Tested on ECC6 : 20/11/2008
*& Updating values of custom fields added to MARA.
*--------------------------------------------------------------------*
REPORT  z_vma_mara_ext.
TABLES : mara, marc.
DATA: rex LIKE bapiparex OCCURS 0 WITH HEADER LINE,
      rexx LIKE bapiparexx OCCURS 0 WITH HEADER LINE,
      header LIKE bapimathead OCCURS 0 WITH HEADER LINE,
      makt1 LIKE bapi_makt OCCURS 0 WITH HEADER LINE,
      zbapiret2 LIKE bapiret2 OCCURS 0 WITH HEADER LINE.

PARAMETERS: material LIKE mara-matnr,
            val1 TYPE aktvt,
            val2 TYPE actname_kk,
            val3 TYPE aktvt,
            new_desc TYPE maktx.
            header-material = material.

rex-structure = 'BAPI_TE_MARA'.
CONCATENATE material val1 val2 val3 INTO  rex-valuepart1 RESPECTING BLANKS.
APPEND rex.
rexx-structure = 'BAPI_TE_MARAX'.
CONCATENATE material 'XXX' INTO  rexx-valuepart1 RESPECTING BLANKS.
APPEND rexx.
makt1-langu = 'E'.
makt1-langu_iso = 'EN'.
makt1-matl_desc = new_desc.
APPEND makt1.

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
  EXPORTING
    headdata            = header
  IMPORTING
    return              = zbapiret2
  TABLES
    materialdescription = makt1
    extensionin         = rex
    extensioninx        = rexx.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
 

Currently I am working on one application in which I need to load material master label data. I could not load this using BDC so I have tried different ways and finally I found few function modules to do this. We can use below FMs to achieve this.

FM CBGL_LB01_RECN_GET_NEXT to get next record number

FM CBGL_LB20_MTLS_READ to read existing labels for material

FM CBGL_LB20_MTLS_UPDATE to update labels

FM CBGL_LB20_MTLS_DELETE to delete labels for a particular material and UoM

FM CBGL_LB20_MTLV_UPDATE to update reference areas

Sample Code as follows

PARAMETERS:
  p_matnr TYPE matnr,
  p_lineno TYPE i,
  p_uom TYPE ccglc_puom-msehi,
  p_ltyp TYPE ccgls_mtlsiot-ltyp,
  p_gen TYPE ccgls_mtlsiot-ldepid.

DATA:
wa_label TYPE ccgls_mtlsiot.
DATA:
i_label LIKE TABLE OF wa_label.

SELECT SINGLE msehi
  INTO p_uom
  FROM ccglc_puom
  WHERE msehi = p_uom.
IF sy-subrc NE 0.
  MESSAGE e202(cbgl00).
ENDIF.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
  EXPORTING
    input        = p_matnr
  IMPORTING
    output       = p_matnr
  EXCEPTIONS
    length_error = 1
    OTHERS       = 2.
IF sy-subrc EQ 0.
ENDIF.
wa_label-matnr = p_matnr.
SELECT recn
  INTO wa_label-recnroot
  UP TO 1 ROWS
  FROM ccglt_mtld
  WHERE matnr EQ p_matnr
    AND delflg EQ space.
ENDSELECT.
* To get next record number for label for material&UoM
CALL FUNCTION 'CBGL_LB01_RECN_GET_NEXT'
  IMPORTING
    number = wa_label-recn.
wa_label-linemod = 'I'.
wa_label-puom = p_uom.
wa_label-lineno = p_lineno.
wa_label-ltyp = p_ltyp.
wa_label-ldepid = p_gen.
wa_label-num_lbls = 1.
APPEND wa_label TO i_label.
* To update Labels
CALL FUNCTION 'CBGL_LB20_MTLS_UPDATE'
  TABLES
    i_ccgls_mtlsiot = i_label
  EXCEPTIONS
    no_lock         = 1
    no_authority    = 2
    update_error    = 3
    OTHERS          = 4.
IF sy-subrc NE 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
* Move to DB
  CALL FUNCTION 'CBGL_LB20_SAVE_TO_DB'
    EXCEPTIONS
      commit_not_successful = 1
      update_error          = 2
      insert_error          = 3
      delete_error          = 4
      OTHERS                = 5.
  IF sy-subrc NE 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
    WRITE 'success'.
  ENDIF.
ENDIF.
 

Author: Asis Mohanty
Submitted: 22/01/2008

Description

This program reports retest date, expiration date, stock status, quantity and other necessary information for IM managed material with batch management either at material level or at plant level.

REPORT zqxx0078 NO STANDARD PAGE HEADING
                LINE-SIZE 133
                MESSAGE-ID zq.
*eject
* definition of database tables --------------------------------------+
TABLES: mchb,
        ma06v.
* Definition of internal tables --------------------------------------+
DATA: BEGIN OF t_entries OCCURS 1,
       werks      LIKE mchb-werks,
       matnr      LIKE mchb-matnr,
       charg      LIKE mchb-charg,
       lgort      LIKE mchb-lgort,
       clabs      LIKE mchb-clabs,
       cinsm      LIKE mchb-cinsm,
       cspem      LIKE mchb-cspem,
       dispo      LIKE ma06v-dispo,
       mtart      LIKE ma06v-mtart,
       vfdat      LIKE mch1-vfdat,
       qndat      LIKE mch1-qndat,
       maktx      LIKE makt-maktx,
       slabs      LIKE mkol-slabs,
       sinsm      LIKE mkol-sinsm,
       sspem      LIKE mkol-sspem,
       resvd(1)   TYPE c,
      END OF t_entries.
* Definition of data -------------------------------------------------+
DATA:
  w_lowdate       LIKE sy-datlo,
  w_highdate      LIKE sy-datlo,
  w_matnr         LIKE mchb-matnr,
  w_maktx         LIKE makt-maktx,
  w_resvd(1)      TYPE c.
* Range --------------------------------------------------------------+
RANGES:
  r_daterange      FOR sy-datum,
  r_pastrange      FOR sy-datum.
* Constants ----------------------------------------------------------+
DATA:
  c_x(1)           TYPE c     VALUE 'X',
  c_k(1)           TYPE c     VALUE 'K',
  c_ur(2)          TYPE c     VALUE 'UR',
  c_qi(2)          TYPE c     VALUE 'QI',
  c_s(1)           TYPE c     VALUE 'S',
  c_y(1)           TYPE c     VALUE 'Y',
  c_n(1)           TYPE c     VALUE 'N',
  c_i(1)           TYPE c     VALUE 'I',
*  c_e(1)           type c     value 'E',
  c_bt(2)          TYPE c     VALUE 'BT',
  c_pastdate       TYPE i     VALUE 60.
* Definition of selection screen -------------------------------------+
SELECTION-SCREEN BEGIN OF BLOCK main WITH FRAME TITLE text-001.
PARAMETER:      p_werks LIKE mchb-werks OBLIGATORY  " plant #
                      MEMORY ID wrk.
SELECT-OPTIONS: s_matnr FOR mchb-matnr,             " material #
                s_mtart FOR ma06v-mtart,            " material type
                s_lgort FOR mchb-lgort,             " storage Loc
                s_dispo FOR ma06v-dispo.            " MRP controller
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (10) text-p01.
PARAMETER     : p_lead(3) TYPE n DEFAULT 000   "lead time in days
                                 OBLIGATORY.
SELECTION-SCREEN COMMENT (15) text-p02.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN COMMENT /1(12) text-011.
SELECTION-SCREEN ULINE /1(12).
PARAMETERS: p_unres    AS CHECKBOX DEFAULT 'X',      "unrestricted stock
            p_block    AS CHECKBOX,                  " blocked stock
            p_qual     AS CHECKBOX,                  " QI stock
            p_kstock   AS CHECKBOX.                  " K-stock
SELECTION-SCREEN SKIP.
SELECTION-SCREEN COMMENT /1(16) text-012.
SELECTION-SCREEN ULINE /1(33).
PARAMETERS: p_bmmat  RADIOBUTTON GROUP r01.         "material level
PARAMETERS: p_bmwrk RADIOBUTTON GROUP r01.          "plant level
SELECTION-SCREEN END OF BLOCK main.
*---------------------------------------------------------------------+
*       Start of main program
*---------------------------------------------------------------------+
START-OF-SELECTION.
  PERFORM f0000_house_keeping.
* Get data - if batch mgmt at material level
  IF p_bmmat EQ c_x.
    PERFORM f1100_get_mch1_urqis_stock.
*   Get additional data for special stock
    IF p_kstock EQ c_x.
      PERFORM f1200_get_mch1_k_stock.
    ENDIF.
*   Error if no valid enries found for selection criteria
    IF t_entries[] IS INITIAL.
      MESSAGE s999 WITH
              'No valid entries found for selection criteria.'(020).
      EXIT.
    ENDIF.
* Get data if batch mgmt at plant level
  ELSEIF p_bmwrk EQ c_x.
    PERFORM f2100_get_mcha_urqis_stock.
*   Get additional data for special stock
    IF p_kstock EQ c_x.
      PERFORM f2200_get_mcha_k_stock.
    ENDIF.
*   Error if no valid enries found for selection criteria
    IF t_entries[] IS INITIAL.
      MESSAGE s999 WITH
              'No valid entries found for selection criteria.'(020).
      EXIT.
    ENDIF.
  ENDIF.
  PERFORM f3000_delete_entries.
  IF t_entries[] IS INITIAL.
    MESSAGE s999 WITH
            'No valid entries found for selection criteria.'(020).
    EXIT.
  ENDIF.
* Get Material text and check if the material is reserved
  SORT t_entries BY matnr.
  LOOP AT t_entries.
    IF w_matnr NE t_entries-matnr.
      MOVE t_entries-matnr TO w_matnr.
      PERFORM f3100_get_matnr_text.
      PERFORM f3200_get_reserved_matnr.
    ENDIF.
    MOVE: w_maktx TO t_entries-maktx,
w_resvd TO t_entries-resvd.
    MODIFY t_entries.
  ENDLOOP.
* Display report
  PERFORM f4000_display_report.

END-OF-SELECTION.
*eject
*&---------------------------------------------------------------------*
*&      Form  F0000_HOUSE_KEEPING
*&---------------------------------------------------------------------*
*   This subroutine:
*     1) clears the contents of all the work area variables and
*        internal tables used by the program
*     2) checks for authorization of user for the specified plant
*     3) checks if at least one stock status checkbox was selected
*     4) defines the search date range (r_daterange)
*     5) defines the past date range (r_pastrange)
*----------------------------------------------------------------------*
FORM f0000_house_keeping.
* Do authorization  check
  AUTHORITY-CHECK OBJECT 'M_MATE_WRK'
        ID 'ACTVT'       FIELD   '03'
        ID 'WERKS'       FIELD   p_werks.            "plant
  IF sy-subrc NE 0.
    MESSAGE s999 WITH 'Authorization Error.'(008).
    STOP.
  ENDIF.
  IF     p_unres IS INITIAL
  AND    p_block IS INITIAL
  AND    p_qual  IS INITIAL.
    MESSAGE s999 WITH
            'Selection error: Check at least one stock status.'(051).
    STOP.
  ENDIF.
* Clear-up
  CLEAR: w_lowdate,
         w_highdate,
         w_matnr,
         w_maktx,
         w_resvd,
         t_entries,
         r_daterange,
         r_pastrange.
  REFRESH: t_entries[],
  r_daterange,
  r_pastrange.
* Calculate future date to which the report checks
  w_lowdate = sy-datlo - c_pastdate.
* Calculate future date to which the report checks
  w_highdate = sy-datlo + p_lead.
* Set the date range for searching
  MOVE: c_i        TO r_daterange-sign,
        c_bt       TO r_daterange-option,
        w_lowdate  TO r_daterange-low,
        w_highdate TO r_daterange-high.
  APPEND r_daterange.
* Set the date range for past dates
  MOVE: c_i          TO r_pastrange-sign,
        c_bt         TO r_pastrange-option,
        w_lowdate    TO r_pastrange-low.
  r_pastrange-high = sy-datlo - 1.
  APPEND r_pastrange.
ENDFORM.                    " F0000_HOUSE_KEEPING
*eject
*&---------------------------------------------------------------------*
*&      Form  F1100_GET_MCH1_URQIS_STOCK
*&---------------------------------------------------------------------*
*   This subroutine selects stock status UR, QI and S for batch mgt
*   at material level by joining tables MCH1, MCHB, and MA06V.
*   All valid entries are stored in itab T_ENTRIES.
*----------------------------------------------------------------------*
FORM f1100_get_mch1_urqis_stock.
  SELECT a~matnr
         a~werks
         a~charg
         a~lgort
         a~clabs
         a~cinsm
         a~cspem
         b~dispo
         b~mtart
         c~vfdat
         c~qndat
    APPENDING CORRESPONDING FIELDS OF TABLE t_entries
    FROM ( (
            mchb AS a INNER JOIN ma06v AS b
            ON  a~matnr EQ b~matnr
            AND a~werks EQ b~werks
           )
           INNER JOIN mch1 AS c
           ON  c~matnr EQ a~matnr
           AND c~charg EQ a~charg
         )
    WHERE a~werks EQ p_werks
      AND a~matnr IN s_matnr
      AND a~lgort IN s_lgort
      AND b~dispo IN s_dispo
      AND b~mtart IN s_mtart
      AND (   c~qndat IN r_daterange
           OR c~vfdat IN r_daterange
          )
      AND (   a~clabs GT 0
           OR a~cinsm GT 0
           OR a~cspem GT 0
          ).
  IF sy-subrc NE 0.
*   No entries for P&G stock at Batch Mgt at Material Level
  ENDIF.
ENDFORM.                    " F1100_GET_MCH1_URQIS_STOCK
*eject
*&---------------------------------------------------------------------*
*&      Form  F1200_GET_MCH1_K_STOCK
*&---------------------------------------------------------------------*
*   This subroutine selects stock type K (vendor-owned stocks)
*   for stock status UR, QI and S for batch mgt
*   at material level by joining tables MCH1, MKOL, and MA06V.
*   All valid entries are stored in itab T_ENTRIES.
*----------------------------------------------------------------------*
FORM f1200_get_mch1_k_stock.
  SELECT a~matnr
         a~werks
         a~charg
         a~lgort
         a~slabs
         a~sinsm
         a~sspem
         b~dispo
         b~mtart
         c~vfdat
         c~qndat
  APPENDING CORRESPONDING FIELDS OF TABLE t_entries
  FROM ( (
           mkol AS a INNER JOIN ma06v AS b
           ON  a~matnr EQ b~matnr
           AND a~werks EQ b~werks
          )
        INNER JOIN mch1 AS c
        ON  c~matnr EQ a~matnr
        AND c~charg EQ a~charg
       )
  WHERE a~werks EQ p_werks
    AND a~matnr IN s_matnr
    AND a~lgort IN s_lgort
    AND b~dispo IN s_dispo
    AND b~mtart IN s_mtart
    AND (   c~qndat IN r_daterange
         OR c~vfdat IN r_daterange
        )
    AND a~sobkz EQ c_k
    AND (   a~slabs GT 0
         OR a~sinsm GT 0
         OR a~sspem GT 0
        ).
  IF sy-subrc NE 0.
*   No entries found for K-stock at batch mgt at Material Level
  ENDIF.
ENDFORM.                    " F1200_GET_MCH1_K_STOCK
*eject
*&---------------------------------------------------------------------*
*&      Form  F2100_GET_MCHA_URQIS_STOCK
*&---------------------------------------------------------------------*
*   This subroutine selects stock status UR, QI and S for batch mgt
*   at material level by joining tables MCHA, MCHB, and MA06V.
*   All valid entries are stored in itab T_ENTRIES.
*----------------------------------------------------------------------*
FORM f2100_get_mcha_urqis_stock.
  SELECT a~matnr
         a~werks
         a~charg
         a~lgort
         a~clabs
         a~cinsm
         a~cspem
         b~dispo
         b~mtart
         c~vfdat
         c~qndat
    APPENDING CORRESPONDING FIELDS OF TABLE t_entries
    FROM ( (
            mchb AS a INNER JOIN ma06v AS b
            ON  a~matnr EQ b~matnr
            AND a~werks EQ b~werks
           )
           INNER JOIN mcha AS c
           ON  c~matnr EQ a~matnr
           AND c~werks EQ a~werks
           AND c~charg EQ a~charg
         )
    WHERE a~werks EQ p_werks
      AND a~matnr IN s_matnr
      AND a~lgort IN s_lgort
      AND b~dispo IN s_dispo
      AND b~mtart IN s_mtart
      AND (   c~qndat IN r_daterange
           OR c~vfdat IN r_daterange
          )
      AND (   a~clabs GT 0
           OR a~cinsm GT 0
           OR a~cspem GT 0
          ).
  IF sy-subrc NE 0.
*   No entries found for P&G stock at batch mgt at Plant Level
  ENDIF.
ENDFORM.                    " F2100_GET_MCHA_URQIS_STOCK
*eject
*&---------------------------------------------------------------------*
*&      Form  F2200_GET_MCHA_K_STOCK
*&---------------------------------------------------------------------*
*   This subroutine selects stock type K (vendor-owned stocks)
*   for stock status UR, QI and S for batch mgt
*   at material level by joining tables MCHA, MKOL, and MA06V.
*   All valid entries are stored in itab T_ENTRIES.
*----------------------------------------------------------------------*
FORM f2200_get_mcha_k_stock.
  SELECT a~matnr
         a~werks
         a~charg
         a~lgort
         a~slabs
         a~sinsm
         a~sspem
         b~dispo
         b~mtart
         c~vfdat
         c~qndat
  APPENDING CORRESPONDING FIELDS OF TABLE t_entries
  FROM ( (
           mkol AS a INNER JOIN ma06v AS b
           ON  a~matnr EQ b~matnr
           AND a~werks EQ b~werks
          )
        INNER JOIN mcha AS c
        ON         c~matnr EQ a~matnr
        AND        c~werks EQ a~werks
        AND        c~charg EQ a~charg
       )
  WHERE a~werks EQ p_werks
    AND a~matnr IN s_matnr
    AND a~lgort IN s_lgort
    AND b~dispo IN s_dispo
    AND b~mtart IN s_mtart
    AND (   c~qndat IN r_daterange
         OR c~vfdat IN r_daterange
        )
    AND a~sobkz EQ c_k
    AND (   a~slabs GT 0
         OR a~sinsm GT 0
         OR a~sspem GT 0
        ).
  IF sy-subrc NE 0.
*   No entries found for K-stock at batch mgt at Plant Level
  ENDIF.
ENDFORM.                    " F2200_GET_MCHA_K_STOCK
*eject
*&---------------------------------------------------------------------*
*&      Form  F3000_DELETE_ENTRIES
*&---------------------------------------------------------------------*
*   This subroutine deletes all records in T_ENTRIES with zero stock
*   stock quantity for the selected stock statuses.
*   [text]
*---------------------------------------------------------------------+
FORM f3000_delete_entries.
  IF  p_unres EQ c_x
  AND p_qual  EQ space
  AND p_block EQ space.
    DELETE t_entries WHERE clabs EQ 0
                       AND slabs EQ 0.
  ENDIF.
  IF  p_unres EQ space
AND p_qual  EQ c_x
AND p_block EQ space.
    DELETE t_entries WHERE cinsm EQ 0
                       AND sinsm EQ 0.
  ENDIF.
  IF  p_unres EQ space
AND p_qual  EQ space
AND p_block EQ c_x.
    DELETE t_entries WHERE cspem EQ 0
                       AND sspem EQ 0.
  ENDIF.
  IF  p_unres EQ c_x
AND p_qual  EQ c_x
AND p_block EQ space.
    DELETE t_entries WHERE clabs EQ 0
                       AND slabs EQ 0
                       AND cinsm EQ 0
                       AND sinsm EQ 0.
  ENDIF.
  IF  p_unres EQ c_x
AND p_qual  EQ space
AND p_block EQ c_x.
    DELETE t_entries WHERE clabs EQ 0
                       AND slabs EQ 0
                       AND cspem EQ 0
                       AND sspem EQ 0.
  ENDIF.
  IF  p_unres EQ space
AND p_qual  EQ c_x
AND p_block EQ c_x.
    DELETE t_entries WHERE cinsm EQ 0
                       AND sinsm EQ 0
                       AND cspem EQ 0
                       AND sspem EQ 0.
  ENDIF.
ENDFORM.                    " F3000_DELETE_ENTRIES
*eject
*&---------------------------------------------------------------------*
*&      Form  F3100_GET_MATNR_TEXT
*&---------------------------------------------------------------------*
*   This subroutine selects the material text (MAKTX) from table MAKT
*   for all the entries in the internal table T_ENTRIES. The field for
*   material text in the internal table T_ENTRIES will be updated.
*----------------------------------------------------------------------*
FORM f3100_get_matnr_text.
  SELECT SINGLE maktx
    INTO w_maktx
    FROM makt
   WHERE matnr EQ t_entries-matnr
     AND spras EQ sy-langu.
  IF sy-subrc NE 0.
*   material is not in makt
    EXIT.
  ENDIF.
ENDFORM.                    " F3100_GET_MATNR_TEXT
*eject
*&---------------------------------------------------------------------*
*&      Form  F3200_GET_RESERVED_MATNR
*&---------------------------------------------------------------------*
*   This subroutine if the material in internal table T_ENTRIES has a
*   valid reservation in table RESB.  If there is a valid reservation
*   for this material, then the field RSVD in internal table T_ENTRIES
*   will be marked as 'X'. Otherwise, it will be left blank (no value).
*----------------------------------------------------------------------*
FORM f3200_get_reserved_matnr.
  DATA l_matnr LIKE resb-matnr.
  SELECT  matnr
    FROM  resb
    INTO  l_matnr
    UP TO 1 ROWS
   WHERE  xloek EQ space           " Indicator: item has been deleted
     AND  matnr EQ t_entries-matnr
     AND  werks EQ t_entries-werks
     AND  bdter GE sy-datlo        " Reserve date
     AND  bdmng GT 0.              " Quantity reserved
  ENDSELECT.
  IF  sy-subrc EQ 0.                    "valid reservation found
    MOVE c_x TO w_resvd.
  ELSE.                                  "no valid reservation
    MOVE space TO w_resvd.
  ENDIF.
  MOVE l_matnr TO l_matnr.               "remove ext. check warning
ENDFORM.                    " F3200_GET_RESERVED_MATNR
*eject
*&---------------------------------------------------------------------*
*&      Form  F4000_DISPLAY_REPORT
*&---------------------------------------------------------------------*
*   This subroutine display the report output to the SAP screen:
*     1) Report header is printed (F4100_PRINT_HEADER)
*     2) T_ENTRIES sorted by MRP controller, SLoc, Next Insp. Date
*     3) Eachline entry of itab T_ENTRIES will be printed.
*----------------------------------------------------------------------*
FORM f4000_display_report.
  DATA: l_dispo         LIKE ma06v-dispo,
        l_lgort         LIKE mkol-lgort,
        l_mrpnullprt(1) TYPE c.
  CLEAR: l_lgort,
   l_dispo.
  SORT t_entries BY dispo lgort qndat.
* Print report header
  PERFORM f4100_print_header.
  SORT t_entries BY dispo lgort qndat.
  l_mrpnullprt = c_n.
  LOOP AT t_entries.
*   Print MRP Controller headline
*     - for 1st instance of MRP controller that is blank
    IF  t_entries-dispo IS INITIAL
    AND l_mrpnullprt    EQ c_n.
      PERFORM f4200_print_mrp_ctrlr.
      MOVE c_y TO l_mrpnullprt.
      CLEAR l_lgort.
    ENDIF.
*   Print MRP Controller headline
    IF t_entries-dispo NE l_dispo.
      PERFORM f4200_print_mrp_ctrlr.
      MOVE t_entries-dispo TO l_dispo.
      CLEAR l_lgort.
    ENDIF.
*   Print Storage Location headline
    IF t_entries-lgort NE l_lgort.
      PERFORM f4300_print_sloc.
      MOVE t_entries-lgort TO l_lgort.
      PERFORM f4400_print_field_header.
    ENDIF.
*   UNRESTRICTED - P&G owned stock
    IF  p_unres         EQ c_x
    AND t_entries-clabs GT 0.
      PERFORM f4500_print_line_entry USING  t_entries-clabs
                                            c_ur
                                            space.
    ENDIF.
*   QI - P&G owned stock
    IF  p_qual          EQ c_x
    AND t_entries-cinsm GT 0.
      PERFORM f4500_print_line_entry USING   t_entries-cinsm
                                             c_qi
                                             space.
    ENDIF.
*   BLOCKED - P&G owned stock
    IF  p_block         EQ c_x
    AND t_entries-cspem GT 0.
      PERFORM f4500_print_line_entry USING t_entries-cspem
                                           c_s
                                           space.
    ENDIF.
*   UNRESTRICTED - vendor owned stock (stock type K)
    IF  p_unres         EQ c_x
    AND t_entries-slabs GT 0.
      PERFORM f4500_print_line_entry USING  t_entries-slabs
                                            c_ur
                                            c_k.
    ENDIF.
*   QI  - vendor owned stock (stock type K)
    IF  p_qual          EQ c_x
    AND t_entries-sinsm GT 0.
      PERFORM f4500_print_line_entry USING  t_entries-sinsm
                                            c_qi
                                            c_k.
    ENDIF.
*   BLOCKED  - vendor owned stock (stock type K)
    IF  p_block         EQ c_x
    AND t_entries-sspem GT 0.
      PERFORM f4500_print_line_entry USING  t_entries-sspem
                                            c_s
                                            c_k.
    ENDIF.
  ENDLOOP.
ENDFORM.                    " F4000_DISPLAY_REPORT
*eject
*&---------------------------------------------------------------------*
*&      Form  F4100_PRINT_HEADER
*&---------------------------------------------------------------------*
*   This subroutine prints the selection screen input
*   on the header of the report.
*   The date the report was run will also be printed out.
*----------------------------------------------------------------------*
FORM f4100_print_header.
  WRITE: text-002.
* skip 1.
  ULINE (132).
  WRITE: /001 'Date'(003),
          018 ': '(021),
              sy-datlo.
* Print plant
  WRITE: /001 'Plant'(004),
          018 ': '(021),
              p_werks.
* Print material range
  WRITE: /001 'Material'(009),
          018 ': '(021).
  LOOP AT s_matnr.
    IF NOT s_matnr-high IS INITIAL.
      WRITE: s_matnr-low,
             '-'(010),
             s_matnr-high.
    ELSE.
      WRITE  s_matnr-low.
    ENDIF.
    IF sy-tabix LT sy-tfill.
      WRITE: ','(023).
    ENDIF.
  ENDLOOP.
* Print material type range
  WRITE: /001 'Material Type'(005),
          018 ': '(021).
  LOOP AT s_mtart.
    IF NOT s_mtart-high IS INITIAL.
      WRITE: s_mtart-low,
             '-'(010),
             s_mtart-high.
    ELSE.
      WRITE  s_mtart-low.
    ENDIF.
    IF sy-tabix LT sy-tfill.
      WRITE: ','(023).
    ENDIF.
  ENDLOOP.
* Print storage location range
  WRITE: /001 'Storage Location'(006),
          018 ': '(021).
  LOOP AT s_lgort.
    IF NOT s_lgort-high IS INITIAL.
      WRITE: s_lgort-low,
             '-'(010),
             s_lgort-high.
    ELSE.
      WRITE  s_lgort-low.
    ENDIF.
    IF sy-tabix LT sy-tfill.
      WRITE: ','(023).
    ENDIF.
  ENDLOOP.
* Print MRP Controller range
  WRITE: /001 'MRP Controller'(007),
          018 ': '(021).
  LOOP AT s_dispo.
    IF NOT s_dispo-high IS INITIAL.
      WRITE: s_dispo-low,
             '-'(010),
             s_dispo-high.
    ELSE.
      WRITE  s_dispo-low.
    ENDIF.
    IF sy-tabix LT sy-tfill.
      WRITE: ','(023).
    ENDIF.
  ENDLOOP.
* Print Lead Time
  WRITE: /001 'Lead Time'(p01),
          018 ': '(021),
              p_lead,
          027 'days'(p02).
ENDFORM.                    " F4100_PRINT_HEADER
*eject
*&---------------------------------------------------------------------*
*&      Form  F4200_PRINT_MRP_CTRLR
*&---------------------------------------------------------------------*
*   This subroutine will print the MRP Controller header
*   whenever a new MRP controller in T_ENTRIES comes out.
*   [text]
*----------------------------------------------------------------------*
FORM f4200_print_mrp_ctrlr.
  SKIP 1.
  ULINE 001(133).
  FORMAT COLOR COL_KEY INTENSIFIED ON.
  WRITE: /003   'MRP Controller'(007),
          020   ': '(021),
          025   t_entries-dispo,
          001   sy-vline,
          133   sy-vline.
  FORMAT RESET.
  ULINE /001(133).
ENDFORM.                    " F4200_PRINT_MRP_CTRLR
*eject
*&---------------------------------------------------------------------*
*&      Form  F4300_PRINT_SLOC
*&---------------------------------------------------------------------*
*   This subroutine will print the Storage Location header
*   whenever a new MRP controller in T_ENTRIES comes out.
*   [text]
*----------------------------------------------------------------------*
FORM f4300_print_sloc.
  FORMAT COLOR COL_KEY INTENSIFIED OFF.
  WRITE: /003   'Storage Location'(006),              "Storage Location
          020   ': '(021),
          025   t_entries-lgort,
          001   sy-vline,
          133   sy-vline.
  ULINE /001(133).
  FORMAT RESET.
ENDFORM.                    " F4300_PRINT_SLOC
*eject
*&---------------------------------------------------------------------*
*&      Form  F4400_PRINT_FIELD_HEADER
*&---------------------------------------------------------------------*
*   This subroutine prints the the field headers for each of the
*   columns of the data output.
*   [text]
*----------------------------------------------------------------------*
FORM f4400_print_field_header.
  FORMAT COLOR COL_GROUP INTENSIFIED ON.                    "color 7
  WRITE: /002 'Material'(009),
          021 'Material Description'(013),
          062 'Batch'(014),
          073 'Quantity'(015),
          091 'Rsvd'(016),
          096 'Retest Date'(017),
          109 'Exp. Date'(018),
          119 'Status'(019),
          126 'K-Stock'(022).
  FORMAT RESET.
  PERFORM f4450_print_vline.
  ULINE  /001(133).
ENDFORM.                    " F4400_PRINT_FIELD_HEADER
*eject
*&---------------------------------------------------------------------*
*&      Form  F4450_PRINT_VLINE
*&---------------------------------------------------------------------*
*   This subroutine will print the vertical lines that separates
*   one column from another.
*   [text]
*----------------------------------------------------------------------*
FORM f4450_print_vline.
  WRITE:
           001 sy-vline,
           020 sy-vline,
           061 sy-vline,
           072 sy-vline,
           090 sy-vline,
           095 sy-vline,
           107 sy-vline,
           118 sy-vline,
           125 sy-vline,
           133 sy-vline.
ENDFORM.                    " F4450_PRINT_VLINE
*eject
*&---------------------------------------------------------------------*
*&      Form  F4500_PRINT_LINE_ENTRY
*&---------------------------------------------------------------------*
*   This subroutine will print the individual line entries from itab
*   T_ENTRIES.  Retest dates that are in the past for UR & QI stocks
*   will be highlighted in red.  Expiration dates that are in the
*   past for UR stocks will be highlighted in red.
*----------------------------------------------------------------------*
* Change of code from here SNH070706
*FORM F4500_PRINT_LINE_ENTRY USING    P_VALUE
*                                     P_STATUS
*                                     P_KSTOCK.
FORM f4500_print_line_entry USING    p_value  TYPE mchb-clabs
                                     p_status TYPE c
                                     p_kstock TYPE c.
* Change of code from till SNH070706
  WRITE: /002 t_entries-matnr,
            021 t_entries-maktx,
            062 t_entries-charg,
            073 p_value,
            093 t_entries-resvd,
            094 space.
  IF  t_entries-qndat IN r_pastrange
AND (   p_status EQ c_ur
OR p_status EQ c_qi ).
    FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.    "red highlight
    WRITE: 097 t_entries-qndat.
    FORMAT RESET.
  ELSE.
    WRITE 097 t_entries-qndat.
  ENDIF.
  IF  t_entries-vfdat IN r_pastrange
AND p_status        EQ c_ur.
    FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.    "red highlight
    WRITE: 108 t_entries-vfdat.
    FORMAT RESET.
  ELSE.
    WRITE: 108 t_entries-vfdat.
  ENDIF.
  WRITE:  121 p_status,
  129 p_kstock.
  PERFORM f4450_print_vline.
  ULINE /001(133).
ENDFORM.                    " F4500_PRINT_LINE_ENTRY
 
*-----------------------------------------------------------------------
* Here is an interface program to create the required no of jobs
* automatically with the given path in the application server by
* specifying filename no of files to be created and sites and
* article range
*-----------------------------------------------------------------------
REPORT zmio_manu_onhand_extr LINE-SIZE 180
    LINE-COUNT 65
    NO STANDARD PAGE HEADING
    MESSAGE-ID zr.
*-----------------------------------------------------------------------
* database tables
*-----------------------------------------------------------------------
TABLES: t001w ,
        mard .
*-----------------------------------------------------------------------
* variables
*-----------------------------------------------------------------------
DATA: g_lines LIKE sy-tabix,
      g_read LIKE sy-tabix,
      g_filename LIKE edi_path-pthnam,
      g_records TYPE sy-tabix,
      g_total_rec TYPE i,
      g_fileno TYPE i,
      v_records TYPE i,
      v_fileno(3) TYPE c .
*-----------------------------------------------------------------------
* internal tables
*-----------------------------------------------------------------------
*---table for sites
TYPES: BEGIN OF ty_t001w ,
  werks TYPE werks_d,
END OF ty_t001w.
*--types for plant store
TYPES:BEGIN OF ty_mard ,
  matnr LIKE mard-matnr,
  werks LIKE mard-werks,
  lgort LIKE mard-lgort,
END OF ty_mard.
TYPES: BEGIN OF t_varinfo,
  flag TYPE c,
  olength TYPE x,
  line LIKE raldb-infoline,
END OF t_varinfo.
*---database tables
DATA: it_t001w TYPE STANDARD TABLE OF ty_t001w WITH HEADER LINE,
      it_exp_t001w TYPE STANDARD TABLE OF ty_t001w WITH HEADER LINE,
      it_mard TYPE STANDARD TABLE OF ty_mard WITH HEADER LINE ,
      tables TYPE trdir-name OCCURS 0 WITH HEADER LINE ,
      infotab TYPE t_varinfo OCCURS 0 WITH HEADER LINE,
      variant_info TYPE rsvaradmin OCCURS 0 WITH HEADER LINE ,
      variant_names TYPE rsvarrange OCCURS 0 WITH HEADER LINE .
*-----------------------------------------------------------------------
* selection screen
*-----------------------------------------------------------------------
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME .
SELECT-OPTIONS: s_matnr FOR mard-matnr, "articles
                s_werks FOR t001w-werks. "plant
PARAMETERS: p_file1 LIKE rlgrap-filename , "filename
            p_numjob(3) TYPE n . "no of jobs to be created
SELECTION-SCREEN: END OF BLOCK b1.
*-----------------------------------------------------------------------
* ranges
*-----------------------------------------------------------------------
*--ranges for plant
RANGES: r_werks FOR t001w-werks.
*----------------------------------------------------------------------*
* AT SELECTION SCREEN
*----------------------------------------------------------------------*
AT SELECTION-SCREEN .
*---if there is no message raise a message to enter file name
  IF p_file1 IS INITIAL.
    MESSAGE e001 WITH 'Enter File Name'.
  ENDIF.
*---if the no of jobs to be create field
* is initial raise a message to enter a value
  IF p_numjob EQ space.
    MESSAGE e001 WITH 'Enter a valid no of files to be created'.
  ENDIF.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file1.
  CALL FUNCTION 'F4_DXFILENAME_4_DYNP'
    EXPORTING
      dynpfield_filename = 'P_FILE1'
      dyname             = sy-cprog
      dynumb             = sy-dynnr
      filetype           = 'P'
      location           = 'A'
      server             = ''.
*-----------------------------------------------------------------------
* start of selection
*-----------------------------------------------------------------------
START-OF-SELECTION.
*---write the header of the output with filename
* and no of records downloaded
  PERFORM header_name.
*--get the data for the plants
  PERFORM get_data.
*--process the data for creating the file in application server
  PERFORM process_data .
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
FORM get_data .
  REFRESH:it_t001w.
*---get data for plants
  SELECT werks
    FROM t001w
    INTO TABLE it_t001w
    WHERE werks IN s_werks.
  IF NOT it_t001w[] IS INITIAL.
    SORT it_t001w BY werks.
*---count the no of records from plant table
    DESCRIBE TABLE it_t001w LINES g_lines.
  ENDIF.
ENDFORM. " get_data
*&---------------------------------------------------------------------*
*& Form process_data
*&---------------------------------------------------------------------*
FORM process_data .
*---get the no of plant records per job
  g_read = g_lines / p_numjob.
*---this is to avoid the short dump
  IF g_read = 0.
    g_read = 1.
  ENDIF.
  CLEAR g_lines.
  g_lines = p_numjob.
*--processing of the job
  DO.
*---if the number of jobs to be create is greate than one
    IF g_lines > 1.
*---send some of the records to the first job to process
      APPEND LINES OF it_t001w FROM 1 TO g_read TO it_exp_t001w.
      REFRESH r_werks.
*---fill the records into the ranges to be processed for first job
      PERFORM fill_range.
*---get the the file no
      ADD 1 TO g_fileno.
      v_fileno = g_fileno.
      CONCATENATE p_file1 '\test' v_fileno INTO g_filename.
*---get the filename with path
      CONDENSE g_filename NO-GAPS.
*---get the no articles from the plants selected in the ranes
      PERFORM get_mard_data.
      CLEAR: it_exp_t001w, it_exp_t001w[].
*---decrease the no of jobs by one
      g_lines = g_lines - 1.
*---check for further processing
      IF it_t001w[] IS INITIAL.
        g_lines = 0.
      ENDIF.
*---if the no of jobs to be created is one
    ELSEIF g_lines = 1.
*---send all the records to one internal table
      APPEND LINES OF it_t001w TO it_exp_t001w.
      REFRESH r_werks.
*---get the records in ranges
      PERFORM fill_range.
      REFRESH it_mard.
      PERFORM get_mard_data.
      CLEAR: it_exp_t001w, it_exp_t001w[], it_t001w[].
*--check for further processing
      CHECK it_t001w[] IS INITIAL.
      EXIT.
    ELSE.
      CHECK it_t001w[] IS INITIAL.
      EXIT.
    ENDIF.
  ENDDO.
ENDFORM. " process_data
*&---------------------------------------------------------------------*
*& Form get_mard_data
*&---------------------------------------------------------------------*
FORM get_mard_data .
  REFRESH: it_mard.
  SELECT matnr
          werks
          lgort
    FROM mard INTO TABLE it_mard
    FOR ALL ENTRIES IN it_t001w
    WHERE werks = it_t001w-werks.
  IF NOT it_mard[] IS INITIAL.
    SORT it_mard BY werks.
*----write the file into application server
    PERFORM write_file.
  ENDIF.
ENDFORM. " get_mard_data
*&---------------------------------------------------------------------*
*& Form write_file
*&---------------------------------------------------------------------*
FORM write_file .
  DATA: outrec(100) TYPE c.
*---get the no of records from the mard table
  DESCRIBE TABLE it_mard LINES v_records.
*---open file in appilication server to write these records
  OPEN DATASET g_filename FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
  IF sy-subrc NE 0.
    EXIT.
  ENDIF.
  LOOP AT it_mard.
    outrec+0(18) = it_mard-matnr.
    outrec+25(4) = it_mard-werks.
    outrec+40(16) = it_mard-lgort.
    TRANSFER outrec TO g_filename .
  ENDLOOP.
*---write the file name and no of records downloaded
  PERFORM file_name.
*---close the file in application server
  CLOSE DATASET g_filename.
ENDFORM. " write_file
*&---------------------------------------------------------------------*
*& Form fill_range
*&---------------------------------------------------------------------*
FORM fill_range .
  LOOP AT it_exp_t001w.
    r_werks-low = it_exp_t001w-werks.
    r_werks-sign = 'I'.
    r_werks-option = 'EQ'.
    APPEND r_werks.
  ENDLOOP.
  DELETE it_t001w FROM 1 TO g_read.
ENDFORM. " fill_range
*&---------------------------------------------------------------------*
*& Form header_name
*----------------------------------------------------------------------*
FORM header_name .
  CALL FUNCTION 'RS_VARIANT_ADMIN_DATA'
    EXPORTING
      curr_report   = sy-repid
    TABLES
      variant_info  = variant_info
      variant_names = variant_names
    EXCEPTIONS
      no_variants   = 1
      OTHERS        = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
  CALL FUNCTION 'PRINT_SELECTIONS'
    EXPORTING
      mode      = tables
      rname     = sy-repid "program name
      rvariante = variant_info-variant "varient name
    TABLES
      infotab   = infotab.
  LOOP AT infotab.
    WRITE / infotab-line.
  ENDLOOP.
  WRITE:/1(130) sy-uline .
  WRITE:/1 sy-vline,
        2 'CREATED FILENAME' COLOR 7,
        62 sy-vline,
        64 'NO OF SUCCESSFUL RECORDS IN THIS FILE ' COLOR 7 ,
        130 sy-vline.
  WRITE:/1(130) sy-uline .
ENDFORM. " header_name
*&---------------------------------------------------------------------*
*& Form FILE_NAME
*&---------------------------------------------------------------------*
FORM file_name .
  WRITE:/1(130) sy-uline .
  WRITE:/1 sy-vline,
        2 g_filename,
        62 sy-vline,
        64 v_records,
        130 sy-vline.
  WRITE:/1(130) sy-uline .
ENDFORM. " FILE_NAME
 

Hi Below logic is to retrive the Class and SUbclass names of a Material in material clasification.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*Data declarations
 TYPES : BEGIN OF tt_kssk,
         clint TYPE kssk-objek,
        END OF tt_kssk. 

DATA : it_klah TYPE STANDARD TABLE OF klah,
       wa_klah TYPE klah,
       it_kssk TYPE STANDARD TABLE OF kssk,
       wa_kssk TYPE kssk,
       it_kssk2 TYPE STANDARD TABLE OF kssk,
       wa_kssk2 TYPE kssk,
       it_kssk1 TYPE STANDARD TABLE OF tt_kssk,
       wa_kssk1 TYPE tt_kssk.
*Selection screen design
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS p_matnr TYPE mara-matnr.
SELECTION-SCREEN END OF BLOCK b1.
*Material number will be there in KSSK-OBJEK
SELECT *
    FROM kssk
  INTO TABLE it_kssk
  WHERE objek = p_matnr.
*Again Sub class clint name will be there in KSSK
LOOP AT it_kssk INTO wa_kssk.
  MOVE : wa_kssk-clint TO wa_kssk1-clint.
  APPEND wa_kssk1 TO it_kssk1.
  CLEAR wa_kssk1.
ENDLOOP.
IF it_kssk1 IS NOT INITIAL.
*Get the OBJECK of subclass from KSSK table based on above KSSK clint
  SELECT *
     FROM kssk
    INTO TABLE it_kssk2
    FOR ALL ENTRIES IN it_kssk1
   WHERE objek = it_kssk1-clint.
ENDIF.
APPEND LINES OF it_kssk2 TO it_kssk.
*Get the name of the class and subclass from KLAH based on clint values in kssk.
SELECT *
   FROM klah
  INTO TABLE it_klah
 FOR ALL ENTRIES IN it_kssk
  WHERE clint = it_kssk-clint.
LOOP AT it_klah INTO wa_klah.
  IF wa_klah-klagr = 'MAT_PRIME'.  "primary class
    WRITE :/  wa_klah-class.
  ELSE.
    WRITE :/ wa_klah-class.   "sub class
  ENDIF.
ENDLOOP.


 

Thanks

Naresh

REPORT zmm_materialconv NO STANDARD PAGE HEADING
MESSAGE-ID zmm.
*----------------------------------------------------------------------
* Data declaration *
*----------------------------------------------------------------------
CONSTANTS: c_map LIKE mbew-vprsv VALUE 'V', "Moving average price
c_stnp LIKE mbew-vprsv VALUE 'S', "Standard price
c_logicalfile LIKE filename-fileintern VALUE 'ZMATERIAL'.
TABLES: mara.
DATA: BEGIN OF it_upload OCCURS 0,
  matnr LIKE mara-matnr, "material no
  mbrsh LIKE mara-mbrsh, "industry sector
  mtart LIKE mara-mtart, "material type
  werks LIKE marc-werks, "plant
  lgort LIKE mard-lgort, "storage location
  maktx LIKE makt-maktx, "material desc.
  meins LIKE mara-meins, "base UOM
  matkl LIKE mara-matkl, "material grp
  bismt LIKE mara-bismt, "old material no
  spart LIKE mara-spart, "division
  brgew LIKE mara-brgew, "gross weight
  ntgew LIKE mara-ntgew, "net weight
  gewei LIKE mara-gewei, "weight unit
  volum LIKE mara-volum, "volume
  voleh LIKE mara-voleh, "volume unit
  ekgrp LIKE marc-ekgrp, "purchasing grp
  xchpf LIKE mara-xchpf, "batch mgmt
  ekwsl LIKE mara-ekwsl, "purchasing value key
  webaz LIKE marc-webaz, "GR processing time
  disgr LIKE marc-disgr, "MRP group
  dismm LIKE marc-dismm, "MRP type
  dispo LIKE marc-dispo, "MRP controller
  minbe LIKE marc-minbe, "reorder point
  disls LIKE marc-disls, "lot size
  bstrf LIKE marc-bstrf, "rounding value
  sobsl LIKE marc-sobsl, "special procurement
  lgpro LIKE marc-lgpro, "issue stor. loc
  lgfsb LIKE marc-lgfsb, "stoc. loc for EP
  plifz LIKE marc-plifz, "planned delivery time
  fhori LIKE marc-fhori, "scheduling margin key
  eisbe LIKE marc-eisbe, "safety stock
  perkz LIKE marc-perkz, "period indicator
  mtvfp LIKE marc-mtvfp, "availability check
  lgpbe LIKE mard-lgpbe, "storage bin
  abcin LIKE marc-abcin, "CC physical inventory ind
  bwtty LIKE mbew-bwtty, "valuation category
  bklas LIKE mbew-bklas, "valuation class
  bwtar LIKE mbew-bwtar, "valuation type
  vprsv LIKE mbew-vprsv, "price control
  verpr LIKE mbew-verpr, "price (MAP/Standard)
END OF it_upload.
DATA: BEGIN OF it_error OCCURS 0,
  tabix(10) TYPE n,
  matnr LIKE mara-matnr,
  ermsg(255) TYPE c,
END OF it_error.
DATA: v_fieldtext(60) TYPE c,
      v_filename LIKE rlgrap-filename,
      v_tabix LIKE sy-tabix.
DATA: w_bgr00 LIKE bgr00,
      w_bmm00 LIKE bmm00,
      w_bmmh1 LIKE bmmh1.
*----------------------------------------------------------------------
* Selection-Screen *
*----------------------------------------------------------------------
* SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-S01.
PARAMETERS: p_pcfile LIKE rlgrap-filename OBLIGATORY,
            p_type LIKE rlgrap-filetype DEFAULT 'ASC',
            p_test AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK b1.
*----------------------------------------------------------------------
* At Selection-Screen *
*----------------------------------------------------------------------
* AT SELECTION-SCREEN.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_pcfile.
*BEGIN SYDK978748
  DATA: l_file TYPE string,
        t_files TYPE filetable,
        l_subrc TYPE i,
        l_title TYPE string VALUE 'File System for Pres. Server'.
  l_file = p_pcfile.
  CALL METHOD cl_gui_frontend_services=%gtfile_open_dialog
    EXPORTING
      window_title            = l_title
      default_filename        = l_file
    CHANGING
      file_table              = t_files
      rc                      = l_subrc
    EXCEPTIONS
      file_open_dialog_failed = 1
      cntl_error              = 2
      error_no_gui            = 3
      OTHERS                  = 4.
  READ TABLE t_files INDEX 1 INTO p_pcfile.
  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    EXPORTING
      mask      = ',txt,.txt'
      static    = 'X'
    CHANGING
      file_name = p_pcfile.
*END SYDK978748
*----------------------------------------------------------------------
* START OF SELECTION *
*----------------------------------------------------------------------
START-OF-SELECTION.
*  upload file
  PERFORM upload_pc_file.
*    checking master data
  PERFORM data_checking.
*if actual run and if no mapping errors, upload the data
  CHECK ( p_test IS INITIAL AND
  it_error[] IS INITIAL ).
  PERFORM upload_data.
*----------------------------------------------------------------------
* END OF SELECTION *
*----------------------------------------------------------------------
* END-OF-SELECTION.
  PERFORM print_mapping_errors.
*&---------------------------------------------------------------------
*& Form UPLOAD_PC_FILE
*&---------------------------------------------------------------------
FORM upload_pc_file.
  DATA: it_temp(4096) TYPE c OCCURS 0.
*BEGIN SYDK978748
  DATA: l_file TYPE string.
  DATA: l_sepa TYPE c.
  IF p_type = 'DAT'.
    l_sepa = 'X'.
  ELSE.
    l_sepa = ' '.
  ENDIF.
  l_file = p_pcfile.
  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                = l_file
      filetype                = 'ASC'
      has_field_separator     = l_sepa
    TABLES
      data_tab                = it_temp
    EXCEPTIONS
      file_open_error         = 1
      file_read_error         = 2
      no_batch                = 3
      gui_refuse_filetransfer = 4
      invalid_type            = 5
      no_authority            = 6
      unknown_error           = 7
      bad_data_format         = 8
      header_not_allowed      = 9
      separator_not_allowed   = 10
      header_too_long         = 11
      unknown_dp_error        = 12
      access_denied           = 13
      dp_out_of_memory        = 14
      disk_full               = 15
      dp_timeout              = 16
      OTHERS                  = 17.
  CALL FUNCTION 'WS_UPLOAD'
    EXPORTING
      filename            = p_pcfile
      filetype            = p_type
    TABLES
      data_tab            = it_temp
    EXCEPTIONS
      conversion_error    = 1
      invalid_table_width = 2
      invalid_type        = 3
      no_batch            = 4
      unknown_error       = 5
      file_open_error     = 6
      file_read_error     = 7
      OTHERS              = 8.
  IF sy-subrc NE 0.
    MESSAGE s318 WITH text-e01 p_pcfile.
  ENDIF.
  CALL FUNCTION 'TEXT_CONVERT_TEX_TO_SAP'
    EXPORTING
      i_field_seperator    = ','
      i_line_header        = i_tab_raw_data
      =
      it_temp
      i_filename           = p_pcfile
    TABLES
      i_tab_converted_data = it_upload
    EXCEPTIONS
      conversion_failed    = 1
      OTHERS               = 2.
  IF sy-subrc NE 0.
    MESSAGE s318 WITH text-e04 p_pcfile.
  ENDIF.
ENDFORM. " UPLOAD_PC_FILE
*&---------------------------------------------------------------------
*& Form DATA_CHECKING
*&---------------------------------------------------------------------
FORM data_checking.
  LOOP AT it_upload.
    v_tabix = sy-tabix.
    PERFORM check_mara.
    PERFORM check_t137.
    PERFORM check_t134.
    PERFORM check_t001w.
    PERFORM check_t001l.
    PERFORM check_t006.
    PERFORM check_t023.
    PERFORM check_tspa.
    PERFORM check_t024.
    PERFORM check_t438m.
    PERFORM check_t438a.
    PERFORM check_t024d.
    PERFORM check_t439a.
    PERFORM check_t460a.
    PERFORM check_t436a.
    PERFORM check_tmvf.
    PERFORM check_t159c.
    PERFORM check_t149.
    PERFORM check_t025.
    PERFORM check_price_ctrl.
  ENDLOOP.
ENDFORM. " DATA_CHECKING
*&---------------------------------------------------------------------
*& Form get_field_description
*&---------------------------------------------------------------------
FORM get_field_description USING value(p_fieldname)
CHANGING p_text.
  CLEAR p_text.
  CALL FUNCTION 'TB_DATAELEMENT_GET_TEXTS'
    EXPORTING
      name        = p_fieldname
    IMPORTING
      description = p_text
    EXCEPTIONS
      not_found   = 1
      OTHERS      = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
ENDFORM. " get_field_description
*&---------------------------------------------------------------------
*& Form check_t137
*&---------------------------------------------------------------------
FORM check_t137.
  TABLES: t137.
  SELECT SINGLE * FROM t137 WHERE mbrsh = it_upload-mbrsh.
  IF sy-subrc <> 0.
    PERFORM keep_data_error USING 'MBRSH'
    it_upload-mbrsh
    space.
  ENDIF.
ENDFORM. " check_t137
*&---------------------------------------------------------------------
*& Form check_t134
*&---------------------------------------------------------------------
FORM check_t134.
  TABLES: t134.
  SELECT SINGLE * FROM t134 WHERE mtart = it_upload-mtart.
  IF sy-subrc <> 0.
    PERFORM keep_data_error USING 'MTART'
    it_upload-mtart
    space.
  ENDIF.
ENDFORM. " check_t134
*&---------------------------------------------------------------------
*& Form keep_data_error
*&---------------------------------------------------------------------
FORM keep_data_error USING value(p_fieldname)
p_fieldvalue
p_werks.
  MOVE v_tabix TO it_error-tabix.
  MOVE it_upload-matnr TO it_error-matnr.
  PERFORM get_field_description USING p_fieldname
  CHANGING v_fieldtext.
  CONCATENATE text-t01 v_fieldtext ':' p_werks p_fieldvalue
  INTO it_error-ermsg SEPARATED BY space.
  APPEND it_error.
ENDFORM. " keep_data_error
*&---------------------------------------------------------------------
*& Form check_t001w
*&---------------------------------------------------------------------
FORM check_t001w.
  TABLES: t001w.
  SELECT SINGLE * FROM t001w WHERE werks = it_upload-werks.
  IF sy-subrc <> 0.
    PERFORM keep_data_error USING 'WERKS_D'
    it_upload-werks
    space.
  ENDIF.
ENDFORM. " check_t001w
*&---------------------------------------------------------------------
*& Form check_t001l
*&---------------------------------------------------------------------
FORM check_t001l.
*  storage location
  PERFORM check_stor_loc USING 'LGORT_D'
  it_upload-lgort.
*  issue stor. location
  IF NOT it_upload-lgpro IS INITIAL.
    PERFORM check_stor_loc USING 'LGPRO'
    it_upload-lgpro.
  ENDIF.
*stor. loc for ep
  IF NOT it_upload-lgfsb IS INITIAL.
    PERFORM check_stor_loc USING 'LGFSB'
    it_upload-lgfsb.
  ENDIF.
ENDFORM. " check_t001l
*&---------------------------------------------------------------------
*& Form check_t006
*&---------------------------------------------------------------------
FORM check_t006.
*  base uom
  PERFORM check_uom USING 'MEINS'
  it_upload-meins.
*  weight unit
  IF NOT it_upload-gewei IS INITIAL.
    PERFORM check_uom USING 'GEWEI'
    it_upload-gewei.
  ENDIF.
*  volume unit
  IF NOT it_upload-voleh IS INITIAL.
    PERFORM check_uom USING 'VOLEH'
    it_upload-voleh.
  ENDIF.
ENDFORM. " check_t006
*&---------------------------------------------------------------------
*& Form check_UOM
*&---------------------------------------------------------------------
FORM check_uom USING value(p_fieldname)
p_fieldvalue.
  TABLES: t006.
  SELECT SINGLE * FROM t006 WHERE msehi = p_fieldvalue.
  IF sy-subrc <> 0.
    PERFORM keep_data_error USING p_fieldname
    p_fieldvalue
    space.
  ENDIF.
ENDFORM. " check_UOM
*&---------------------------------------------------------------------
*& Form check_t023
*&---------------------------------------------------------------------
FORM check_t023.
  TABLES: t023.
  SELECT SINGLE * FROM t023 WHERE matkl = it_upload-matkl.
  IF sy-subrc <> 0.
    PERFORM keep_data_error USING 'MATKL'
    it_upload-matkl
    space.
  ENDIF.
ENDFORM. " check_t023
*&---------------------------------------------------------------------
*& Form check_tspa
*&---------------------------------------------------------------------
FORM check_tspa.
  TABLES: tspa.
  CHECK NOT it_upload-spart IS INITIAL.
  SELECT SINGLE * FROM tspa WHERE spart = it_upload-spart.
  IF sy-subrc <> 0.
    PERFORM keep_data_error USING 'SPART'
    it_upload-spart
    space.
  ENDIF.
ENDFORM. " check_tspa
*&---------------------------------------------------------------------
*& Form check_t024
*&---------------------------------------------------------------------
FORM check_t024.
  TABLES: t024.
  SELECT SINGLE * FROM t024 WHERE ekgrp = it_upload-ekgrp.
  IF sy-subrc <> 0.
    PERFORM keep_data_error USING 'EKGRP'
    it_upload-ekgrp
    space.
  ENDIF.
ENDFORM. " check_t024
*&---------------------------------------------------------------------
*& Form check_t438m
*&---------------------------------------------------------------------
FORM check_t438m.
  TABLES: t438m.
  CHECK NOT it_upload-disgr IS INITIAL.
  SELECT SINGLE * FROM t438m WHERE werks = it_upload-werks
  AND mtart = it_upload-disgr.
  IF sy-subrc <> 0.
    PERFORM keep_data_error USING 'DISGR'
    it_upload-disgr
    it_upload-werks.
  ENDIF.
ENDFORM. " check_t438m
*&---------------------------------------------------------------------
*& Form check_t438a
*&---------------------------------------------------------------------
FORM check_t438a.
  TABLES: t438a.
  SELECT SINGLE * FROM t438a WHERE dismm = it_upload-dismm.
  IF sy-subrc <> 0.
    PERFORM keep_data_error USING 'DISMM'
    it_upload-dismm
    space.
  ENDIF.
ENDFORM. " check_t438a
*&---------------------------------------------------------------------
*& Form check_t024d
*&---------------------------------------------------------------------
FORM check_t024d.
  TABLES: t024d.
  SELECT SINGLE * FROM t024d WHERE werks = it_upload-werks
  AND dispo = it_upload-dispo.
  IF sy-subrc <> 0.
    PERFORM keep_data_error USING 'DISPO'
    it_upload-dispo
    it_upload-werks.
  ENDIF.
ENDFORM. " check_t024d
*&---------------------------------------------------------------------
*& Form check_t460a
*&---------------------------------------------------------------------
FORM check_t460a.
  TABLES: t460a.
  CHECK NOT it_upload-sobsl IS INITIAL.
  SELECT SINGLE * FROM t460a WHERE werks = it_upload-werks
  AND sobsl = it_upload-sobsl.
  IF sy-subrc <> 0.
    PERFORM keep_data_error USING 'SOBSL'
    it_upload-sobsl
    it_upload-werks.
  ENDIF.
ENDFORM. " check_t460a
*&---------------------------------------------------------------------
*& Form check_stor_loc
*&---------------------------------------------------------------------
FORM check_stor_loc USING value(p_fieldname)
p_fieldvalue.
  TABLES: t001l.
  SELECT SINGLE * FROM t001l WHERE werks = it_upload-werks
  AND lgort = p_fieldvalue.
  IF sy-subrc <> 0.
    PERFORM keep_data_error USING p_fieldname
    p_fieldvalue
    it_upload-werks.
  ENDIF.
ENDFORM. " check_stor_loc
*&---------------------------------------------------------------------
*& Form check_t436a
*&---------------------------------------------------------------------
FORM check_t436a.
  TABLES: t436a.
  SELECT SINGLE * FROM t436a WHERE werks = it_upload-werks
  AND fhori = it_upload-fhori.
  IF sy-subrc <> 0.
    PERFORM keep_data_error USING 'FHORI'
    it_upload-fhori
    it_upload-werks.
  ENDIF.
ENDFORM. " check_t436a
*&---------------------------------------------------------------------
*& Form check_tmvf
*&---------------------------------------------------------------------
FORM check_tmvf.
  TABLES: tmvf.
  SELECT SINGLE * FROM tmvf WHERE mtvfp = it_upload-mtvfp.
  IF sy-subrc <> 0.
    PERFORM keep_data_error USING 'MTVFP'
    it_upload-mtvfp
    space.
  ENDIF.
ENDFORM. " check_tmvf
*&---------------------------------------------------------------------
*& Form check_t159c
*&---------------------------------------------------------------------
FORM check_t159c.
  TABLES: t159c.
  CHECK NOT it_upload-abcin IS INITIAL.
  SELECT SINGLE * FROM t159c WHERE werks = it_upload-werks
  AND abcin = it_upload-abcin.
  IF sy-subrc <> 0.
    PERFORM keep_data_error USING 'ABCIN'
    it_upload-abcin
    it_upload-werks.
  ENDIF.
ENDFORM. " check_t159c
*&---------------------------------------------------------------------
*& Form check_t149
*&---------------------------------------------------------------------
FORM check_t149.
  TABLES: t149.
  CHECK NOT it_upload-bwtty IS INITIAL.
  SELECT SINGLE * FROM t149 WHERE bwkey = it_upload-werks
  AND bwtty = it_upload-bwtty.
  IF sy-subrc <> 0.
    PERFORM keep_data_error USING 'BWTTY_D'
    it_upload-bwtty
    it_upload-werks.
  ENDIF.
ENDFORM. " check_t149
*&---------------------------------------------------------------------
*& Form check_t025
*&---------------------------------------------------------------------
FORM check_t025.
  TABLES: t025.
  SELECT SINGLE * FROM t025 WHERE bklas = it_upload-bklas.
  IF sy-subrc <> 0.
    PERFORM keep_data_error USING 'BKLAS'
    it_upload-bklas
    space.
  ENDIF.
ENDFORM. " check_t025
*&---------------------------------------------------------------------
*& Form check_price_ctrl
*&---------------------------------------------------------------------
FORM check_price_ctrl.
  IF ( it_upload-vprsv <> c_map AND
  it_upload-vprsv <> c_stnp ).
    PERFORM keep_data_error USING 'VPRSV'
    it_upload-vprsv
    space.
  ENDIF.
ENDFORM. " check_price_ctrl
*&---------------------------------------------------------------------
*& Form upload_data
*&---------------------------------------------------------------------
FORM upload_data.
*open file in UNIX for output
  PERFORM open_unix_file.
*header record
  w_bgr00-stype = '0'.
  w_bgr00-group = 'MATERIAL_MASTER_UPLOAD'.
  w_bgr00-mandt = sy-mandt.
  w_bgr00-usnam = sy-uname.
  TRANSFER w_bgr00 TO v_filename.
*load data into the direct input structures
*in the UNIX file
  LOOP AT it_upload.
    w_bmm00-stype = '1'.
    w_bmm00-tcode = 'MM01'.
    w_bmm00-xeik1 = 'X'.
    w_bmm00-xeie1 = 'X'.
    w_bmm00-xeid1 = 'X'.
    w_bmm00-xeid2 = 'X'.
    w_bmm00-xeid3 = 'X'.
    w_bmm00-xeil1 = 'X'.
    w_bmm00-xeib1 = 'X'.
    SELECT SINGLE * FROM mara WHERE matnr EQ it_upload-matnr.
    IF sy-subrc EQ 0.
      CLEAR w_bmm00-xeik1.
    ENDIF.
*End of addition
    MOVE-CORRESPONDING it_upload TO w_bmm00.
    TRANSFER w_bmm00 TO v_filename.
    w_bmmh1-stype = '2'.
    MOVE-CORRESPONDING it_upload TO w_bmmh1.
    IF it_upload-vprsv = 'S'.
      CLEAR w_bmmh1-verpr.
      MOVE it_upload-verpr TO w_bmmh1-stprs.
    ENDIF.
    TRANSFER w_bmmh1 TO v_filename.
    CLEAR : w_bmm00, w_bmmh1.
  ENDLOOP.
*call direct input program to create the materials
*from the UNIX file
  SUBMIT rmdatind AND RETURN
  WITH lds_name = c_logicalfile
  WITH sperr = 'E'.
ENDFORM. " upload_data
*&---------------------------------------------------------------------
*& Form open_unix_file
*&---------------------------------------------------------------------
FORM open_unix_file.
  CALL FUNCTION 'FILE_GET_NAME'
    EXPORTING
      logical_filename = c_logicalfile
    IMPORTING
      file_name        = v_filename
    EXCEPTIONS
      file_not_found   = 1
      OTHERS           = 2.
  IF sy-subrc <> 0.
    MESSAGE e318 WITH text-e02 c_logicalfile.
  ELSE.
*BEGIN SYDK978748
    OPEN DATASET v_filename FOR OUTPUT IN TEXT MODE.
    OPEN DATASET v_filename FOR OUTPUT IN LEGACY TEXT MODE.
*END SYDK978748
    IF sy-subrc EQ 0.
*delete existing file and create new one
      DELETE DATASET v_filename.
*BEGIN SYDK978748
      OPEN DATASET v_filename FOR OUTPUT IN TEXT MODE.
      OPEN DATASET v_filename FOR OUTPUT IN LEGACY TEXT MODE.
*END ASYDK978748
    ENDIF.
  ENDIF.
ENDFORM. " open_unix_file
*&---------------------------------------------------------------------
*& Form print_mapping_errors
*&---------------------------------------------------------------------
FORM print_mapping_errors.
  DATA: v_tabix LIKE it_error-tabix.
  IF it_error[] IS INITIAL AND p_test = 'X'.
    MESSAGE s105 WITH text-s01.
  ENDIF.
  CHECK NOT it_error[] IS INITIAL.
  WRITE: / text-h01.
  ULINE.
  LOOP AT it_error.
    IF v_tabix <> it_error-tabix.
      v_tabix = it_error-tabix.
      WRITE: / text-r01 INTENSIFIED OFF,
      it_error-tabix INTENSIFIED ON,
      text-r02 INTENSIFIED OFF,
      it_error-matnr INTENSIFIED ON.
    ELSE.
      CONTINUE.
    ENDIF.
    FORMAT COLOR COL_NEGATIVE INTENSIFIED OFF.
    LOOP AT it_error WHERE tabix = v_tabix.
      WRITE: /12 it_error-ermsg.
    ENDLOOP.
    FORMAT COLOR OFF.
  ENDLOOP.
ENDFORM. " print_mapping_errors
*&---------------------------------------------------------------------
*& Form check_t439a
*&---------------------------------------------------------------------
FORM check_t439a.
  TABLES: t439a.
  SELECT SINGLE * FROM t439a WHERE disls = it_upload-disls.
  IF sy-subrc <> 0.
    PERFORM keep_data_error USING 'DISLS'
    it_upload-disls
    space.
  ENDIF.
ENDFORM. " check_t439a
*&---------------------------------------------------------------------
*& Form check_mara
*&---------------------------------------------------------------------
FORM check_mara.
  TABLES: mara.
  SELECT SINGLE * FROM mara WHERE matnr = it_upload-matnr.
  IF sy-subrc = 0.
    MOVE v_tabix TO it_error-tabix.
    MOVE it_upload-matnr TO it_error-matnr.
    CONCATENATE text-t02 it_upload-matnr text-t03
    INTO it_error-ermsg SEPARATED BY space.
    APPEND it_error.
  ENDIF.
ENDFORM. " check_mara
*Selection texts
*----------------------------------------------------------
*P_PCFILE Presentation Server File
*P_TEST Test
*P_TYPE File Type
*Messages
*----------------------------------------------------------
*
*Message class: ZMM
*105
*318
*Selection texts
*----------------------------------------------------------
*P_PCFILE PC File
*P_TEST Test
*P_TYPE Type
*Messages
*----------------------------------------------------------
*
*Message class: ZMM
*105
*318
 
REPORT zrmm_material_master LINE-SIZE 132
    NO STANDARD PAGE HEADING.
*$*$--------------------------------------------------------------------
*$*$ Include programs
*$*$--------------------------------------------------------------------
INCLUDE zcommon_forms.
*$*$--------------------------------------------------------------------
*$*$ Data Declarations
*$*$--------------------------------------------------------------------
*$*$ Constants
* Constants for ALV Events declaration
CONSTANTS: BEGIN OF c_alv_events,
  top_of_page(12) TYPE c VALUE 'TOP_OF_PAGE', "Top Of Page
  end_of_page(12) TYPE c VALUE 'END_OF_PAGE', "End Of Page
END OF c_alv_events.
* Constants for yes Flag
CONSTANTS c_check(1) TYPE c VALUE 'X'. "Flag
*$*$ Types
* Structure for storing final output data
TYPES: BEGIN OF ty_outdata,
  werks TYPE marc-werks, "Plant
  matkl TYPE mara-matkl, "Material group
  prctr TYPE marc-prctr, "Profit Center
  mtart TYPE mara-mtart, "Material type
  matnr TYPE mara-matnr, "Material number
  maktx TYPE makt-maktx, "Mat Description
  disls TYPE marc-disls, "Lot size
  beskz TYPE marc-beskz, "Procurement Typ
  fxhor TYPE marc-fxhor, "Planning time
END OF ty_outdata.
* Structure for select from table MARC MARA MAKT
TYPES: BEGIN OF ty_marc_mara_makt,
  werks TYPE marc-werks, "Plant
  matnr TYPE marc-matnr, "testMaterial
  prctr TYPE marc-prctr, "Profit Center
  disls TYPE marc-disls, "Lot size
  beskz TYPE marc-beskz, "Procurement
  fxhor TYPE marc-fxhor, "Plng time fence
  mtart TYPE mara-mtart, "Material Type
  matkl TYPE mara-matkl, "Material Group
  maktx TYPE makt-maktx, "Description
END OF ty_marc_mara_makt.
* Structure for select from table KNA1
TYPES: BEGIN OF ty_kna1,
  kunnr TYPE kna1-kunnr, "Customer
END OF ty_kna1.
*$*$ Internal Tables
* Internal table for output data
DATA i_outdata TYPE STANDARD TABLE OF ty_outdata INITIAL SIZE 0.
* Internal table for data from table MARC_MARA_MAKT
DATA i_marc_mara_makt TYPE STANDARD TABLE
OF ty_marc_mara_makt INITIAL SIZE 0.
* Internal table for data from table KNA1
DATA i_kna1 TYPE STANDARD TABLE OF ty_kna1 INITIAL SIZE 0.
* Internal table for ALV Field Catalog
DATA i_fieldcat TYPE slis_t_fieldcat_alv.
* Internal table for ALV field Sort Catalog
DATA i_sortcat TYPE slis_t_sortinfo_alv.
* Internal table for ALV Field Events
DATA i_event TYPE slis_t_event.
* Internal table for ALV Header declarations
DATA i_alv_header TYPE slis_t_listheader.
* Error Internal table
DATA i_errors TYPE STANDARD TABLE OF bapiret2 INITIAL SIZE 0.
*$*$ Workareas
* Work area for output data
DATA wa_outdata TYPE ty_outdata.
* Work area for structure TY_MARC_MARA_MAKT
DATA wa_marc_mara_makt TYPE ty_marc_mara_makt.
* Work area for structure TY_KNA1
DATA wa_kna1 TYPE ty_kna1.
* Work area for ALV Field layout
DATA wa_layout TYPE slis_layout_alv.
* Work area for Variant data for ALV
DATA wa_variant TYPE disvariant.
* Error Work area
DATA wa_errors TYPE bapiret2.
*$*$ Variables
* Variable declaration for Select-Option: S_WERKS
DATA g_werks TYPE marc-werks.
* Variable declaration for Select-Option: S_MTART
DATA g_mtart TYPE mara-mtart.
* Variable declaration for Select-Option: S_MATKL
DATA g_matkl TYPE mara-matkl.
* Variable declaration for Select-Option: S_MATNR
DATA g_matnr TYPE mara-matnr.
*$*$ Flags
*$*$--------------------------------------------------------------------
*$*$ Selection criteria
*$*$--------------------------------------------------------------------
SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME TITLE text-001.
* Select Options: S_WERKS
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(22) text-002.
SELECT-OPTIONS s_werks FOR g_werks OBLIGATORY.
SELECTION-SCREEN END OF LINE.
* Select Options: S_MTART
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(22) text-004.
SELECT-OPTIONS s_mtart FOR g_mtart OBLIGATORY.
SELECTION-SCREEN END OF LINE.
* Select Options: S_MATKL
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(22) text-006.
SELECT-OPTIONS s_matkl FOR g_matkl OBLIGATORY.
SELECTION-SCREEN END OF LINE.
* Select Options: S_MATNR
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(22) text-008.
SELECT-OPTIONS s_matnr FOR g_matnr.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK a.
SELECTION-SCREEN BEGIN OF BLOCK h WITH FRAME TITLE text-010.
* Parameter: ALV Display Variant
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(25) text-011.
PARAMETER p_alvv TYPE disvariant-variant.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK h.
*$*$--------------------------------------------------------------------
*$*$ INITIALIZATION Event
*$*$--------------------------------------------------------------------
INITIALIZATION.
* Get default variant for ALV
  wa_variant-report = sy-repid.
  CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
    EXPORTING
      i_save     = 'A'
    CHANGING
      cs_variant = wa_variant
    EXCEPTIONS
      not_found  = 2.
  IF sy-subrc = 0.
    p_alvv = wa_variant-variant.
  ENDIF.
*$*$--------------------------------------------------------------------
*$*$ AT SELECTION SCREEN ON Event
*$*$--------------------------------------------------------------------
*$*$ Validate Plant
AT SELECTION-SCREEN ON s_werks.
  PERFORM validate_werks.
*$*$ Validate Material type
AT SELECTION-SCREEN ON s_mtart.
  PERFORM validate_mtart.
*$*$ Validate Material group
AT SELECTION-SCREEN ON s_matkl.
  PERFORM validate_matkl.
*$*$ Validate Material number
AT SELECTION-SCREEN ON s_matnr.
  PERFORM validate_matnr.
*$*$ Validate ALV Display Variant
AT SELECTION-SCREEN ON p_alvv.
* Check the existence of Variant
  PERFORM alv_variant_check USING wa_variant p_alvv.
*$*$ F4 help on Screen field P_ALVV
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_alvv.
  PERFORM f4_for_variant USING wa_variant p_alvv.
*$*$--------------------------------------------------------------------
*$*$ TOP OF PAGE Event
*$*$--------------------------------------------------------------------
TOP-OF-PAGE.
* Subroutine for Top of Page event.
* perform top_of_page.
*$*$--------------------------------------------------------------------
*$*$ END OF PAGE Event
*$*$--------------------------------------------------------------------
END-OF-PAGE.
* Subroutine for End of Page event.
* perform end_of_page.
*$*$--------------------------------------------------------------------
*$*$ START OF SELECTION Event
*$*$--------------------------------------------------------------------
START-OF-SELECTION.
* Perform selects and populate internal tables
  PERFORM load_internal_tables.
* Process the internal table table
  PERFORM process_data.
* Populate the final output table for display
  PERFORM final_statistics.
*$*$--------------------------------------------------------------------
*$*$ END OF SELECTION Event
*$*$--------------------------------------------------------------------
END-OF-SELECTION.
* Display the report output using ALV
  PERFORM write_report.
*$*$--------------------------------------------------------------------
*$*$ Form Validate_WERKS
*$*$--------------------------------------------------------------------
FORM validate_werks.
  DATA l_werks TYPE t001w-werks.
* Check for initial value before validating
  CHECK NOT s_werks IS INITIAL.
* Select Plant for validation
  SELECT werks UP TO 1 ROWS
    FROM t001w INTO l_werks
    WHERE werks IN s_werks.
  ENDSELECT.
* Stop processing and issue error message in case of error
  IF sy-subrc NE 0.
    MESSAGE e398(00) WITH 'Incorrect entry for'(e02)
    'Plant'(003) space space.
  ENDIF.
ENDFORM. " FORM VALIDATE_WERKS
*$*$--------------------------------------------------------------------
*$*$ Form Validate_MTART
*$*$--------------------------------------------------------------------
FORM validate_mtart.
  DATA l_mtart TYPE t134-mtart.
* Check for initial value before validating
  CHECK NOT s_mtart IS INITIAL.
* Select Material type for validation
  SELECT mtart UP TO 1 ROWS
    FROM t134 INTO l_mtart
    WHERE mtart IN s_mtart.
  ENDSELECT.
* Stop processing and issue error message in case of error
  IF sy-subrc NE 0.
    MESSAGE e398(00) WITH 'Incorrect entry for'(e02)
    'Material type'(005) space space.
  ENDIF.
ENDFORM. " FORM VALIDATE_MTART
*$*$--------------------------------------------------------------------
*$*$ Form Validate_MATKL
*$*$--------------------------------------------------------------------
FORM validate_matkl.
  DATA l_matkl TYPE t023-matkl.
* Check for initial value before validating
  CHECK NOT s_matkl IS INITIAL.
* Select Material group for validation
  SELECT matkl UP TO 1 ROWS
    FROM t023 INTO l_matkl
    WHERE matkl IN s_matkl.
  ENDSELECT.
* Stop processing and issue error message in case of error
  IF sy-subrc NE 0.
    MESSAGE e398(00) WITH 'Incorrect entry for'(e02)
    'Material group'(007) space space.
  ENDIF.
ENDFORM. " FORM VALIDATE_MATKL
*$*$--------------------------------------------------------------------
*$*$ Form Validate_MATNR
*$*$--------------------------------------------------------------------
FORM validate_matnr.
  DATA l_matnr TYPE mara-matnr.
* Check for initial value before validating
  CHECK NOT s_matnr IS INITIAL.
* Select Material number for validation
  SELECT matnr UP TO 1 ROWS
    FROM mara INTO l_matnr
    WHERE matnr IN s_matnr.
  ENDSELECT.
* Stop processing and issue error message in case of error
  IF sy-subrc NE 0.
    MESSAGE e398(00) WITH 'Incorrect entry for'(e02)
    'Material number'(009) space space.
  ENDIF.
ENDFORM. " FORM VALIDATE_MATNR
*$*$--------------------------------------------------------------------
*$*$ Form LOAD_INTERNAL_TABLES
*$*$--------------------------------------------------------------------
FORM load_internal_tables.
* Select data from table MARC MARA MAKT
  PERFORM select_marc_mara_makt.
* Select data from table KNA1
  PERFORM select_data_kna1.
ENDFORM. " FORM LOAD_INTERNAL_TABLES
*$*$--------------------------------------------------------------------
*$*$ Form SELECT_MARC_MARA_MAKT
*$*$--------------------------------------------------------------------
FORM select_marc_mara_makt.
* Select data from table
  SELECT marc~werks
          marc~matnr
          marc~prctr
          marc~disls
          marc~beskz
          marc~fxhor
          mara~mtart
          mara~matkl
          makt~maktx
    FROM marc
    JOIN mara
    ON marc~matnr EQ mara~matnr
    JOIN makt
    ON mara~matnr EQ makt~matnr
    INTO TABLE i_marc_mara_makt
    WHERE marc~werks IN s_werks "Plant
      AND mara~mtart IN s_mtart "Material Type
      AND mara~matkl IN s_matkl "Material Group
      AND mara~matnr IN s_matnr. "testMaterial
* Issue error message if the select fails
  IF sy-subrc NE 0.
    MESSAGE i398(00) WITH 'No data selected from table'(e03)
    'MARC'(012) 'MARA'(013) 'MAKT'(014).
    LEAVE LIST-PROCESSING.
  ENDIF.
ENDFORM. " FORM SELECT_MARC_MARA_MAKT
*$*$--------------------------------------------------------------------
*$*$ Form SELECT_DATA_KNA1
*$*$--------------------------------------------------------------------
FORM select_data_kna1.
* Select data from table
  SELECT kunnr
    FROM kna1
    INTO TABLE i_kna1.
* Issue error message if the select fails
  IF sy-subrc NE 0.
    MESSAGE i398(00) WITH 'No data selected from table'(e03)
    'KNA1'(015) space space.
    LEAVE LIST-PROCESSING.
  ENDIF.
ENDFORM. " FORM SELECT_DATA_KNA1
*$*$--------------------------------------------------------------------
*$*$ Form PROCESS_DATA
*$*$--------------------------------------------------------------------
FORM process_data.
* Populate data into final output internal table
  LOOP AT i_kna1 INTO wa_kna1.
* WA_outdata-WERKS =
* WA_outdata-MATKL =
* WA_outdata-PRCTR =
* WA_outdata-MTART =
* WA_outdata-MATNR =
* WA_outdata-MAKTX =
* WA_outdata-DISLS =
* WA_outdata-BESKZ =
* WA_outdata-FXHOR =
    APPEND wa_outdata TO i_outdata.
  ENDLOOP. " LOOP AT I_KNA1
ENDFORM. " FORM PROCESS_DATA
*$*$--------------------------------------------------------------------
*$*$ Form FINAL_STATISTICS
*$*$--------------------------------------------------------------------
FORM final_statistics.
ENDFORM. " FORM FINAL_STATISTICS
*$*$--------------------------------------------------------------------
*$*$ Form WRITE_REPORT
*$*$--------------------------------------------------------------------
FORM write_report.
* Write the final report depending on error or success
  IF NOT i_errors[] IS INITIAL.
* Write Report Header
    PERFORM write_report_header
      USING 'Company code description'
            'prog short description'
            'prog description'.
* Write Error Report
    PERFORM write_error_report TABLES i_errors.
* Else write the report data
  ELSE.
* If no ALV output is required
    IF i_outdata[] IS INITIAL.
* Write Report Header
      PERFORM write_report_header
        USING 'Company code description'
              'prog short description'
              'prog description'.
******* Add your own custom message here for display
    ELSE.
* Write report header
      PERFORM write_alv_header USING i_alv_header[]
        'prog short description'.
* Prepare layout for the ALV display
      PERFORM prepare_layout USING wa_layout
        c_check "Column Optimize
        space "No Column Heading
        c_check "Zebra layout
        space "No Vertical line
        space "No Key Fix
        c_check "No Input
        space "Window Titlebar
        space "No Sumchoice
        space "No total line
        space "No subchoice
        space "No subtotals
        space "Totals only
        space "Totals text
        space "No scrolling
        space "Detail popup
        space. "Detail Titlebar
* Prepare Event table for the ALV display
      PERFORM populate_events TABLES i_event
        USING c_alv_events-top_of_page
              'TOP_OF_PAGE'.
* Prepare field catalog for the ALV display
      PERFORM create_fieldcatalog.
* Display report output
      PERFORM display_report TABLES i_outdata
        USING sy-cprog "Callback program
              wa_layout "Display layout
              i_fieldcat "Field Catalog
              i_sortcat "Sort details
              c_check "Variant(A, ,U,X)
              wa_variant "Display Variant
              i_event "Events
              'I_outdata' "Output itab name
              space. "List/Grid display
    ENDIF.
  ENDIF.
ENDFORM. " FORM WRITE_REPORT
*$*$--------------------------------------------------------------------
*$*$ Form CREATE_FIELDCATALOG
*$*$--------------------------------------------------------------------
FORM create_fieldcatalog.
  PERFORM build_fieldcat_tab TABLES i_fieldcat USING:
      'I_OUTDATA' 'WERKS' ' ' 'MARC' ' ' ' ' 'PLANT'
      ' ' ' ' ' ' 'L',
      'I_OUTDATA' 'MATKL' ' ' 'MARA' ' ' ' ' 'MATERIAL GROUP'
      ' ' ' ' ' ' 'L',
      'I_OUTDATA' 'PRCTR' ' ' 'MARC' ' ' ' ' 'PROFIT CENTER'
      ' ' ' ' ' ' 'L',
      'I_OUTDATA' 'MTART' ' ' 'MARA' ' ' ' ' 'MATERIAL TYPE'
      ' ' ' ' ' ' 'L',
      'I_OUTDATA' 'MATNR' ' ' 'MARA' ' ' ' ' 'MATERIAL NUMBER'
      ' ' ' ' ' ' 'L',
      'I_OUTDATA' 'MAKTX' ' ' 'MAKT' ' ' ' ' 'MAT DESCRIPTION'
      ' ' ' ' ' ' 'L',
      'I_OUTDATA' 'DISLS' ' ' 'MARC' ' ' ' ' 'LOT SIZE'
      ' ' ' ' ' ' 'L',
      'I_OUTDATA' 'BESKZ' ' ' 'MARC' ' ' ' ' 'PROCUREMENT TYP'
      ' ' ' ' ' ' 'L',
      'I_OUTDATA' 'FXHOR' ' ' 'MARC' ' ' ' ' 'PLANNING TIME'
      ' ' ' ' ' ' 'L'.
ENDFORM. " FORM CREATE_FIELDCATALOG
*$*$--------------------------------------------------------------------
*$*$ Form TOP_OF_PAGE
*$*$--------------------------------------------------------------------
FORM top_of_page.
* Call the ALV function module for header top of page
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = i_alv_header.
ENDFORM. " FORM TOP_OF_PAGE
*$*$--------------------------------------------------------------------
*$*$ Form END_OF_PAGE
*$*$--------------------------------------------------------------------
FORM end_of_page.
** Write the logic for any End of Page display here
ENDFORM. " FORM END_OF_PAGE
*Text elements
*----------------------------------------------------------
* 001 Selection Parameters
* 002 Plant
* 003 Plant
* 004 Material type
* 005 Material type
* 006 Material group
* 007 Material group
* 008 Material number
* 009 Material number
* 010 ALV Variant
* 011 ALV Display Variant
* 012 MARC
* 013 MARA
* 014 MAKT
* 015 KNA1
* E02 Incorrect entry for
* E03 No data selected from table
*Messages
*----------------------------------------------------------
*
* Message class: 00
*398 & & & &
************************************************************************
*& Include ZCOMMON_FORMS
************************************************************************
************************************************************************
*& Include ZCOMMON_FORMS
************************************************************************
* TYPE POOLS
TYPE-POOLS: slis,
            kkblo.
* field-symbols.
FIELD-SYMBOLS: <f1> TYPE any, "Field Symbol 1
                <f2> TYPE any, "Field Symbol 2
                <f_source> TYPE any,
                <f_wa_filetab> TYPE any.
TYPES tab_epsfili TYPE STANDARD TABLE OF epsfili.
*&---------------------------------------------------------------------*
*& Form F4_LOCAL_UPLOADFILE
*&---------------------------------------------------------------------*
* This form provides the F4 file navigator on Selection screen
*----------------------------------------------------------------------*
* Called by.: Calling Programs
*----------------------------------------------------------------------*
* Parameters: Filepath --> Return value after navigation
*----------------------------------------------------------------------*
FORM f4_local_uploadfile USING filepath TYPE rlgrap-filename.
  DATA l_rc TYPE i.
  DATA l_filetab TYPE filetable.
  DATA l_filetab_wa TYPE file_table.
  DATA l_title TYPE string.
  l_title = 'Select local file'(i01).
  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
      window_title            = l_title
      file_filter             = ',.,..'
      initial_directory       = 'C:\'
    CHANGING
      file_table              = l_filetab
      rc                      = l_rc
    EXCEPTIONS
      file_open_dialog_failed = 1
      cntl_error              = 2
      error_no_gui            = 3
      not_supported_by_gui    = 4
      OTHERS                  = 5.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
    READ TABLE l_filetab INTO l_filetab_wa INDEX 1.
    IF sy-subrc EQ 0.
      filepath = l_filetab_wa-filename.
    ENDIF.
  ENDIF.
ENDFORM. " F4_LOCAL_UPLOADFILE
*&---------------------------------------------------------------------*
*& Form F4_LOCAL_DOWNLOADFILE
*&---------------------------------------------------------------------*
* This form provides the F4 file navigator on Selection screen
*----------------------------------------------------------------------*
* Called by.: Calling Programs
*----------------------------------------------------------------------*
* Parameters: Filepath --> Return value after navigation
*----------------------------------------------------------------------*
FORM f4_local_downloadfile USING filepath TYPE rlgrap-filename.
  DATA l_title TYPE string.
  DATA l_filename TYPE string.
  DATA l_filepath TYPE string.
  DATA l_fullpath TYPE string.
  l_title = 'Select local file'(i01).
  CALL METHOD cl_gui_frontend_services=>file_save_dialog
    EXPORTING
      window_title         = l_title
      file_filter          = ',.,..'
      initial_directory    = 'C:\'
      prompt_on_overwrite  = 'X'
    CHANGING
      filename             = l_filename
      path                 = l_filepath
      fullpath             = l_fullpath
    EXCEPTIONS
      cntl_error           = 1
      error_no_gui         = 2
      not_supported_by_gui = 3
      OTHERS               = 4.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
    filepath = l_fullpath.
  ENDIF.
ENDFORM. "f4_local_downloadfile
*&---------------------------------------------------------------------*
*& Form F4_APP_UPLOADFILE
*&---------------------------------------------------------------------*
* Get a navigator for filename on the application server
*----------------------------------------------------------------------*
* -->P_DIR Directory Path
* <--P_FILE File NamE
*----------------------------------------------------------------------*
FORM f4_app_uploadfile USING dir TYPE rlgrap-filename
file TYPE rlgrap-filename.
* If not DIR path provided is initial
  CHECK NOT dir IS INITIAL.
  CALL FUNCTION 'F4_FILENAME_SERVER'
    EXPORTING
      pfad              = dir
    EXCEPTIONS
      no_file_on_server = 1
      OTHERS            = 2.
  IF sy-subrc EQ 0.
    file = sy-lisel+2(68). "Filename
    CONDENSE file.
  ENDIF.
ENDFORM. " F4_APP_UPLOADFILE
*---------------------------------------------------------------------*
* FORM F4_FOR_VARIANT *
*---------------------------------------------------------------------*
* F4 help for the Layout variant names in ALV display
*---------------------------------------------------------------------*
FORM f4_for_variant USING p_wa_variant TYPE any
                          p_layout TYPE any.
  DATA l_exit(1) TYPE c.
  DATA l_wa_variant TYPE disvariant.
  CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
    EXPORTING
      is_variant = p_wa_variant
      i_save     = 'A'
    IMPORTING
      e_exit     = l_exit
      es_variant = l_wa_variant
    EXCEPTIONS
      not_found  = 2.
  IF sy-subrc EQ 0.
    IF l_exit = space.
      p_layout = l_wa_variant-variant.
    ENDIF.
  ENDIF.
ENDFORM. "F4_FOR_VARIANT
*&---------------------------------------------------------------------*
*& Form build_filename
*&---------------------------------------------------------------------*
* Build the complete file path from Directory and Path and
* Pass back as one variable
*----------------------------------------------------------------------*
* ---> DIR Directory path
* ---> PATH File path
* ---> FULL_PATH Full Path
*----------------------------------------------------------------------*
FORM build_filename USING dir TYPE rlgrap-filename
                          path TYPE rlgrap-filename
                          full_path TYPE any.
* Check if the Directory path has got a '/' at the end and add if not
  PERFORM format_directory USING dir.
* Build up the full file path
  CONCATENATE dir path INTO full_path.
ENDFORM. "build_filename
*&---------------------------------------------------------------------*
*& Form format_directory
*&---------------------------------------------------------------------*
* Format the directory path from the selection screen and
* adds a slash at the end (if available/not available)
*----------------------------------------------------------------------*
* ---> p_dir Directory path
*----------------------------------------------------------------------*
FORM format_directory USING p_dir TYPE rlgrap-filename.
  DATA l_dir_length TYPE i VALUE 0.
  DATA l_dir_length_less_1 TYPE i VALUE 0.
* Check last character of directory is '/'
  l_dir_length = strlen( p_dir ).
  l_dir_length_less_1 = l_dir_length - 1.
  IF p_dir+l_dir_length_less_1(1) NE '/'.
    CONCATENATE p_dir
    '/'
    INTO p_dir.
  ENDIF.
ENDFORM. "format_directory
*&---------------------------------------------------------------------*
* Form: READ_APPFILE
*&---------------------------------------------------------------------*
* This subroutine is used for reading the application server file
* and then splitting the file data into the internal table structure
* of the program
*----------------------------------------------------------------------*
* Parameters: <-- FILE_STRUCTURE: Itab for storing infile data
* <-- RETURN: Error table
* --> FILENAME: File name
* --> SEPARATOR: File separator
*&---------------------------------------------------------------------*
FORM read_appfile TABLES file_intab
                          return TYPE tt_bapiret2
                    USING filename TYPE any
                          separator TYPE any.
* DATA wa_file type line of file_intab.
* Temporary table structure for storing data after splitting
  TYPES: BEGIN OF l_ty_source_data,
    fieldval(150) TYPE c, "File contents
  END OF l_ty_source_data.
* Structure of the file for storing the data read
  TYPES: BEGIN OF l_ty_file,
    text(500) TYPE c, "File contents
  END OF l_ty_file.
* Internal table and Workarea structure for storing data after splitting
  DATA l_i_source_data TYPE STANDARD TABLE OF
                        l_ty_source_data INITIAL SIZE 0.
  DATA l_wa_source_data TYPE l_ty_source_data.
* Internal table and work area for storing the data read from file
  DATA l_i_file TYPE STANDARD TABLE OF l_ty_file INITIAL SIZE 0.
  DATA l_wa_file TYPE l_ty_file.
* Opens the file for reading
  OPEN DATASET filename FOR INPUT IN TEXT MODE ENCODING DEFAULT.
* File Open failed
  IF sy-subrc NE 0.
    PERFORM message_build TABLES return
      USING '00'
            'E'
            '398'
            'Unable to open file'(i02)
            filename
            'for reading'(i03)
            space.
    EXIT.
  ENDIF.
  DO.
* Read the current record of the source file
    READ DATASET filename INTO l_wa_file.
    IF sy-subrc EQ 4.
      EXIT.
    ENDIF.
    APPEND l_wa_file TO l_i_file .
  ENDDO.
* If the file has a separator
  IF separator NE space.
* Loop at file data and split into the internal table structure
    LOOP AT l_i_file INTO l_wa_file.
* Split file data at the separator
      SPLIT l_wa_file AT separator INTO TABLE l_i_source_data.
      LOOP AT l_i_source_data INTO l_wa_source_data.
        ASSIGN l_wa_source_data-fieldval TO <f1>.
        ASSIGN COMPONENT sy-tabix OF STRUCTURE file_intab TO <f2>.
        <f2> = <f1>.
      ENDLOOP.
      ASSIGN file_intab TO <f_wa_filetab>.
      APPEND <f_wa_filetab> TO file_intab.
      UNASSIGN <f_wa_filetab>.
    ENDLOOP.
* No file separator
  ELSE.
    file_intab[] = l_i_file[].
  ENDIF.
* Closes the file
  CLOSE DATASET filename.
* Error handling not reqd for closing
ENDFORM. "READ_APPFILE
*&---------------------------------------------------------------------*
* Form: READ_LOCALFILE
*&---------------------------------------------------------------------*
* This subroutine is used to read a local file and return the internal
* table with file data
*----------------------------------------------------------------------
* Parameters: <-- FILE_INTAB: Internal table for storing infile data
* <-- RETURN: Error table
* --> FILENAME: File name
* --> SEPARATOR: File separator
*&---------------------------------------------------------------------*
FORM read_localfile TABLES file_intab
                            return TYPE tt_bapiret2
                      USING filename TYPE any
                            separator TYPE any.
* Temporary table structure for storing data after splitting
  TYPES: BEGIN OF l_ty_source_data,
    fieldval(150) TYPE c, "File contents
  END OF l_ty_source_data.
* Structure of the file for storing the data read
  TYPES: BEGIN OF l_ty_file,
    text(500) TYPE c, "File contents
  END OF l_ty_file.
* Internal table and Workarea structure for storing data after splitting
  DATA l_i_source_data TYPE STANDARD TABLE OF
  l_ty_source_data INITIAL SIZE 0.
  DATA l_wa_source_data TYPE l_ty_source_data.
* Internal table and work area for storing the data read from file
  DATA l_i_file TYPE STANDARD TABLE OF l_ty_file INITIAL SIZE 0.
  DATA l_wa_file TYPE l_ty_file.
  DATA l_error_msg(40) TYPE c. "Error Message
  DATA l_filename TYPE string.
* Change the filename to a FM compatible type
  l_filename = filename.
* Read file from presentation layer
  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                = l_filename
    TABLES
      data_tab                = l_i_file
    EXCEPTIONS
      file_open_error         = 1
      file_read_error         = 2
      no_batch                = 3
      gui_refuse_filetransfer = 4
      invalid_type            = 5
      no_authority            = 6
      unknown_error           = 7
      bad_data_format         = 8
      header_not_allowed      = 9
      separator_not_allowed   = 10
      header_too_long         = 11
      unknown_dp_error        = 12
      access_denied           = 13
      dp_out_of_memory        = 14
      disk_full               = 15
      dp_timeout              = 16
      OTHERS                  = 17.
* File Open failed
  IF sy-subrc NE 0.
* Get the exact error parameter for the failure
    SELECT parameter FROM fupararef UP TO 1 ROWS
      INTO l_error_msg
      WHERE funcname EQ 'GUI_UPLOAD'
        AND r3state EQ 'A' "Active
        AND paramtype EQ 'X' "Exception
        AND pposition EQ sy-subrc.
    ENDSELECT.
    PERFORM message_build TABLES return
    USING '00'
          'E'
          '398'
          'Unable to open file'(i02)
          filename
          'for reading. Error:'(i40)
          l_error_msg.
    EXIT.
  ENDIF.
* If the file has a separator
  IF separator NE space.
* Loop at file data and split into the internal table structure
    LOOP AT l_i_file INTO l_wa_file.
      SPLIT l_wa_file AT separator INTO TABLE l_i_source_data.
      LOOP AT l_i_source_data INTO l_wa_source_data.
        ASSIGN l_wa_source_data-fieldval TO <f1>.
        ASSIGN COMPONENT sy-tabix OF STRUCTURE file_intab TO <f2>.
        <f2> = <f1>.
      ENDLOOP.
      ASSIGN file_intab TO <f_wa_filetab>.
      APPEND <f_wa_filetab> TO file_intab.
      UNASSIGN <f_wa_filetab>.
    ENDLOOP.
* No file separator
  ELSE.
    file_intab[] = l_i_file[].
  ENDIF.
ENDFORM. "READ_LOCALFILE
*&---------------------------------------------------------------------*
* Form: WRITE_LOCALFILE
*&---------------------------------------------------------------------*
* This subroutine is used to write a local file
*&---------------------------------------------------------------------*
* Parameters: <-- FILE_OUTTAB : Internal table containing download data
* <-- RETURN: Error table
* --> FILENAME: File name
* --> SEPARATOR: File separator
*&---------------------------------------------------------------------*
FORM write_localfile TABLES file_outtab
                            return TYPE tt_bapiret2
                      USING filename TYPE any
                            separator TYPE any.
  DATA l_error_msg(40) TYPE c. "Error Message
  DATA l_filename TYPE string.
* Internal table for storing the structure fields with seperator.
  TYPES l_v_text(2500) TYPE c.
  DATA l_i_text TYPE STANDARD TABLE OF l_v_text
  INITIAL SIZE 0. "SR with header line.
* Final string containing structure fields with seperator
  DATA: l_raw_data LIKE LINE OF l_i_text,
        l_max_field LIKE l_raw_data,
        l_len_separator TYPE i, "Length of seperator
        l_start_string TYPE i,
        l_len_string TYPE i,
        l_column_index LIKE sy-index.
* Change the filename to a FM compatible type
  l_filename = filename.
* Add separator in the file if required
  IF separator NE space. "No separator, fixed length file
    CLEAR: l_i_text.
    REFRESH: l_i_text.
    l_len_separator = strlen( separator ).
** If you output table contains any decimals (type P, Quan, Curr etc),
** then convert them into character fields and pass an output table
** containing all character fields. This i believe is standard practice
    LOOP AT file_outtab ASSIGNING <f_wa_filetab>.
      file_outtab = <f_wa_filetab>.
      CLEAR: l_column_index, l_raw_data, l_start_string.
      DO.
        l_column_index = l_column_index + 1.
        CLEAR l_len_string.
        ASSIGN COMPONENT l_column_index OF
        STRUCTURE file_outtab TO <f_source>.
        IF sy-subrc <> 0.
          EXIT.
        ELSE.
          IF l_column_index <> 1.
            l_max_field+l_len_string(l_len_separator) = separator.
            l_len_string = l_len_separator.
          ENDIF.
          l_max_field+l_len_string = <f_source>.
* check the remaining space of target structure
          l_len_string = strlen( l_max_field ).
          CHECK l_len_string <> 0.
          l_raw_data+l_start_string(l_len_string) = l_max_field.
          l_start_string = l_start_string + l_len_string.
        ENDIF.
      ENDDO.
      IF NOT l_raw_data IS INITIAL.
        APPEND l_raw_data TO l_i_text.
        CLEAR l_raw_data.
      ENDIF.
    ENDLOOP.
* Download the file
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        filename                = l_filename
      TABLES
        data_tab                = l_i_text
      EXCEPTIONS
        file_write_error        = 1
        no_batch                = 2
        gui_refuse_filetransfer = 3
        invalid_type            = 4
        no_authority            = 5
        unknown_error           = 6
        header_not_allowed      = 7
        separator_not_allowed   = 8
        filesize_not_allowed    = 9
        header_too_long         = 10
        dp_error_create         = 11
        dp_error_send           = 12
        dp_error_write          = 13
        unknown_dp_error        = 14
        access_denied           = 15
        dp_out_of_memory        = 16
        disk_full               = 17
        dp_timeout              = 18
        file_not_found          = 19
        dataprovider_exception  = 20
        control_flush_error     = 21
        OTHERS                  = 22.
  ELSE.
* Download the file without any separators
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        filename                = l_filename
      TABLES
        data_tab                = file_outtab
      EXCEPTIONS
        file_write_error        = 1
        no_batch                = 2
        gui_refuse_filetransfer = 3
        invalid_type            = 4
        no_authority            = 5
        unknown_error           = 6
        header_not_allowed      = 7
        separator_not_allowed   = 8
        filesize_not_allowed    = 9
        header_too_long         = 10
        dp_error_create         = 11
        dp_error_send           = 12
        dp_error_write          = 13
        unknown_dp_error        = 14
        access_denied           = 15
        dp_out_of_memory        = 16
        disk_full               = 17
        dp_timeout              = 18
        file_not_found          = 19
        dataprovider_exception  = 20
        control_flush_error     = 21
        OTHERS                  = 22.
  ENDIF.
* Report any errors
  IF sy-subrc NE 0.
* Get the exact error parameter for the failure
    SELECT parameter FROM fupararef UP TO 1 ROWS
      INTO l_error_msg
      WHERE funcname EQ 'GUI_DOWNLOAD'
        AND r3state EQ 'A' "Active
        AND paramtype EQ 'X' "Exception
        AND pposition EQ sy-subrc.
    ENDSELECT.
    PERFORM message_build TABLES return
      USING '00'
            'E'
            '398'
            'Unable to download file'(i04)
            filename
            'Error:'(i05)
            l_error_msg.
    EXIT.
  ENDIF.
ENDFORM. "WRITE_LOCALFILE
*&---------------------------------------------------------------------*
* Form: WRITE_APPFILE
*&---------------------------------------------------------------------*
* This subroutine is used to write a local file
*&---------------------------------------------------------------------*
* Parameters: <-- FILE_OUTTAB: Internal table containing download data
* <-- RETURN: Error table
* --> FILENAME: File name
* --> SEPARATOR: File separator
*&---------------------------------------------------------------------*
FORM write_appfile TABLES file_outtab
                          return TYPE tt_bapiret2
                    USING filename TYPE any
                          separator TYPE any.
*Internal table for storing the structure fields with seperator.
  TYPES l_v_text(2500) TYPE c.
  DATA l_i_text TYPE STANDARD TABLE OF l_v_text
  INITIAL SIZE 0. "SR with header line.
* Final string containing structure fields with seperator
  DATA: l_raw_data LIKE LINE OF l_i_text,
        l_max_field LIKE l_raw_data,
        l_len_separator TYPE i, "Length of seperator
        l_start_string TYPE i,
        l_len_string TYPE i,
        l_column_index LIKE sy-index,
        l_msg(50) TYPE c. "Error message
  CLEAR: l_i_text.
  REFRESH: l_i_text.
* Write file to app server with required separators
  IF separator NE space. "No separator, fixed length file
    l_len_separator = strlen( separator ).
** If you output table contains any decimals (type P, Quan, Curr etc),
** then convert them into character fields and pass an output table
** containing all character fields. This i believe is standard practice
    LOOP AT file_outtab ASSIGNING <f_wa_filetab>.
      file_outtab = <f_wa_filetab>.
      CLEAR: l_column_index, l_raw_data, l_start_string.
      DO.
        l_column_index = l_column_index + 1.
        CLEAR l_len_string.
        ASSIGN COMPONENT l_column_index OF
          STRUCTURE file_outtab TO <f_source>.
        IF sy-subrc <> 0.
          EXIT.
        ELSE.
          IF l_column_index <> 1.
            l_max_field+l_len_string(l_len_separator) = separator.
            l_len_string = l_len_separator.
          ENDIF.
          l_max_field+l_len_string = <f_source>.
* check the remaining space of target structure
          l_len_string = strlen( l_max_field ).
          CHECK l_len_string <> 0.
          l_raw_data+l_start_string(l_len_string) = l_max_field.
          l_start_string = l_start_string + l_len_string.
        ENDIF.
      ENDDO.
      IF NOT l_raw_data IS INITIAL.
        APPEND l_raw_data TO l_i_text.
        CLEAR l_raw_data.
      ENDIF.
    ENDLOOP.
  ENDIF.
* Write dataset on app server
  OPEN DATASET filename FOR OUTPUT IN TEXT MODE
    ENCODING DEFAULT MESSAGE l_msg.
* Report any errors for file creation
  IF sy-subrc NE 0.
    PERFORM message_build TABLES return
      USING '00'
            'E'
            '398'
            'Error creating file on the application server'(i06)
            filename
            'Error:'(i05)
            l_msg.
    EXIT.
  ENDIF.
  IF NOT l_i_text[] IS INITIAL.
    LOOP AT l_i_text INTO l_raw_data.
      TRANSFER l_raw_data TO filename.
    ENDLOOP.
  ELSE.
    LOOP AT file_outtab ASSIGNING <f_wa_filetab>.
      file_outtab = <f_wa_filetab>.
      TRANSFER file_outtab TO filename.
    ENDLOOP.
  ENDIF.
* Close file
  CLOSE DATASET filename.
ENDFORM. "WRITE_APPFILE
*&---------------------------------------------------------------------*
* Form: MESSAGE_BUILD
*&---------------------------------------------------------------------*
* This subroutine is used populate the messages in return structure
*&---------------------------------------------------------------------*
* Parameters: <--RETURN: Error table with message
* -->CLASS: Message Class
* -->TYPE: Message Type
* -->NUMBER: Message Number
* -->VAR1: Message Variable 1
* -->VAR2: Message Variable 2
* -->VAR3: Message Variable 3
* -->VAR4: Message Variable 4
***********************************************************************
FORM message_build TABLES return TYPE tt_bapiret2
                    USING value(class) TYPE symsgid
                          value(type) TYPE symsgty
                          value(number) TYPE symsgno
                          value(var1) TYPE any
                          value(var2) TYPE any
                          value(var3) TYPE any
                          value(var4) TYPE any.
  DATA: ld_par1 TYPE symsgv, "Variable for Msg
        ld_par2 TYPE symsgv, "Variable for Msg
        ld_par3 TYPE symsgv, "Variable for Msg
        ld_par4 TYPE symsgv, "Variable for Msg
        ls_return TYPE bapiret2. "Return structure
* Assign Message to variables
  ld_par1 = var1.
  ld_par2 = var2.
  ld_par3 = var3.
  ld_par4 = var4.
* Fills the return parameter
  CALL FUNCTION 'BALW_BAPIRETURN_GET2'
    EXPORTING
      type   = type
      cl     = class
      number = number
      par1   = ld_par1
      par2   = ld_par2
      par3   = ld_par3
      par4   = ld_par4
    IMPORTING
      return = ls_return.
  APPEND ls_return TO return.
ENDFORM. "MESSAGE_BUILD
*&---------------------------------------------------------------------*
*& Form bdcdynpro
*&---------------------------------------------------------------------*
* This form inserts a screen call into the bdcdata table
*----------------------------------------------------------------------*
* Parameters: --> PROG_NAME
* SCREEN_NO
*----------------------------------------------------------------------*
FORM bdcdynpro TABLES bdcdata TYPE tab_bdcdata
                USING prog_name TYPE bdcdata-program
                      screen_no TYPE bdcdata-dynpro.
  DATA l_wa_bdcdata LIKE bdcdata.
  l_wa_bdcdata-program = prog_name. " Program name
  l_wa_bdcdata-dynpro = screen_no. " Screen Number
  l_wa_bdcdata-dynbegin = 'X'. " X
* Append bdc table and clear work area
  APPEND l_wa_bdcdata TO bdcdata.
ENDFORM. " BDCDYNPRO
*&---------------------------------------------------------------------*
*& Form BDCFIELD
*&---------------------------------------------------------------------*
* This form fills the bdcdata table with the data required to
* populate a field.
*----------------------------------------------------------------------*
* Called by.: Calling Programs
*----------------------------------------------------------------------*
* Parameters: --> F_NAM " Field name
* F_VAL " Field value
*----------------------------------------------------------------------*
FORM bdcfield TABLES bdcdata TYPE tab_bdcdata
                USING f_nam TYPE any
                      f_val TYPE any.
  DATA l_wa_bdcdata LIKE bdcdata.
* Fill the fields in the dynpro called with the correct values
  l_wa_bdcdata-fnam = f_nam. " Field Name
  l_wa_bdcdata-fval = f_val. " Field Value
* Append bdc table and clear work area.
  APPEND l_wa_bdcdata TO bdcdata.
  CLEAR l_wa_bdcdata.
ENDFORM. " BDCFIELD
*&---------------------------------------------------------------------*
*& Form CALL_TRANSACTION
*&---------------------------------------------------------------------*
* This routine performs a CALL TRANSACTION statement *
*----------------------------------------------------------------------*
* -->BDC_MESSAGES Table for BDC return messages
* -->T_CODE Transaction that is called
* -->INPUT_METHOD Method A/E/N
* -->UPDATE_METHOD Update method (A/S)
*----------------------------------------------------------------------*
FORM call_transaction TABLES bdc_messages TYPE tab_bdcmsgcoll
                              bdcdata TYPE tab_bdcdata
                              return TYPE tt_bapiret2
                      USING t_code TYPE any
                            input_method TYPE any
                            update_method TYPE any.
  DATA l_bdc_messages TYPE bdcmsgcoll.
  DATA l_msgno(3) TYPE n.
  CLEAR bdc_messages.
  REFRESH bdc_messages.
  CALL TRANSACTION t_code USING bdcdata
      MODE input_method
      UPDATE update_method
      MESSAGES INTO bdc_messages.
* Add error handling logic and add populate Return table
* Report any errors for file creation
  IF sy-subrc NE 0.
    LOOP AT bdc_messages INTO l_bdc_messages 
        WHERE ( msgtyp EQ 'E'
             OR msgtyp EQ 'A' ).
      l_msgno = l_bdc_messages-msgnr.
      PERFORM message_build TABLES return
        USING l_bdc_messages-msgid
              l_bdc_messages-msgtyp
              l_msgno
              l_bdc_messages-msgv1
              l_bdc_messages-msgv2
              l_bdc_messages-msgv3
              l_bdc_messages-msgv4.
    ENDLOOP.
  ENDIF.
ENDFORM. " CALL_TRANSACTION
*----------------------------------------------------------------------*
* Form: OPEN_BDC_SESSION
*----------------------------------------------------------------------*
* This subroutine is used to open the BDC session
*----------------------------------------------------------------------*
* PARAMETERS: <--RETURN: Error Table
* -->SESSION: Session Name
*----------------------------------------------------------------------*
FORM open_bdc_session TABLES return TYPE tt_bapiret2
                        USING session TYPE apq_grpn.
  DATA l_error_msg(40) TYPE c. "Error Message
  CALL FUNCTION 'BDC_OPEN_GROUP'
    EXPORTING
      client              = sy-mandt
      group               = session
      keep                = 'X'
      user                = sy-uname
    EXCEPTIONS
      client_invalid      = 1
      destination_invalid = 2
      group_invalid       = 3
      group_is_locked     = 4
      holddate_invalid    = 5
      internal_error      = 6
      queue_error         = 7
      running             = 8
      system_lock_error   = 9
      user_invalid        = 10
      OTHERS              = 11.
  IF sy-subrc NE 0.
* Get the exact error parameter for the failure
    SELECT parameter FROM fupararef UP TO 1 ROWS
      INTO l_error_msg
      WHERE funcname EQ 'BDC_OPEN_GROUP'
        AND r3state EQ 'A' "Active
        AND paramtype EQ 'X' "Exception
        AND pposition EQ sy-subrc.
    ENDSELECT.
    PERFORM message_build TABLES return
      USING '00'
            'E'
            '398'
            'Unable to Open Session'(i07)
            session
            'Error:'(i05)
            l_error_msg.
    EXIT.
  ENDIF.
ENDFORM. "OPEN_BDC_SESSION
*----------------------------------------------------------------------*
* Form: INSERT_BDC_TAB
*----------------------------------------------------------------------*
* This subroutine is used to insert BDC session record
*----------------------------------------------------------------------*
* PARAMETERS: <-- RETURN: Error Table
* --> TCODE: Transaction Code
*----------------------------------------------------------------------*
FORM insert_bdc_tab TABLES bdcdata TYPE tab_bdcdata
                            return TYPE tt_bapiret2
                      USING tcode TYPE tcode.
  DATA l_error_msg(40) TYPE c. "Error Message
* Inserting into the BDC table
  CALL FUNCTION 'BDC_INSERT'
    EXPORTING
      tcode            = tcode
    TABLES
      dynprotab        = bdcdata
    EXCEPTIONS
      internal_error   = 1
      not_open         = 2
      queue_error      = 3
      tcode_invalid    = 4
      printing_invalid = 5
      posting_invalid  = 6
      OTHERS           = 7.
  IF sy-subrc NE 0.
* Get the exact error parameter for the failure
    SELECT parameter FROM fupararef UP TO 1 ROWS
      INTO l_error_msg
      WHERE funcname EQ 'BDC_INSERT'
        AND r3state EQ 'A' "Active
        AND paramtype EQ 'X' "Exception
        AND pposition EQ sy-subrc.
    ENDSELECT.
    PERFORM message_build TABLES return
      USING '00'
            'E'
            '398'
            'Unable to Insert Session'(i08)
            'Error:'(i05)
            l_error_msg
            space.
    EXIT.
  ENDIF.
ENDFORM. "INSERT_BDC_TAB
*----------------------------------------------------------------------*
* Form: CLOSE_BDC_TAB
*----------------------------------------------------------------------*
* This subroutine is used to close the BDC session
*----------------------------------------------------------------------*
* PARAMETERS: <-- RETURN: Error Table
* -->SESSION: Session Name
*----------------------------------------------------------------------*
FORM close_bdc_tab TABLES return TYPE tt_bapiret2
                    USING session TYPE any.
* Close the current batch input session
  CALL FUNCTION 'BDC_CLOSE_GROUP'
    EXCEPTIONS
      not_open    = 1
      queue_error = 2
      OTHERS      = 3.
* If BDC session closing fails
  IF sy-subrc NE 0.
    PERFORM message_build TABLES return
      USING '00'
            'E'
            '398'
            'Unable to close BDC session:'(i09)
            session
            space
            space.
  ENDIF.
ENDFORM. "CLOSE_BDC_TAB
*&---------------------------------------------------------------------*
*& Form ALV_VARIANT_CHECK
*&---------------------------------------------------------------------*
* Check the existence of ALV Variant and populate the variant table
*----------------------------------------------------------------------*
FORM alv_variant_check USING p_wa_variant TYPE disvariant
                              p_layout TYPE any.
  DATA l_wa_variant TYPE disvariant.
* If a layout has been entered on the screen, then validate the same
  IF NOT p_layout IS INITIAL.
    MOVE p_wa_variant TO l_wa_variant.
    MOVE p_layout TO l_wa_variant-variant.
    CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
      EXPORTING
        i_save     = 'A'
      CHANGING
        cs_variant = l_wa_variant.
    p_wa_variant = l_wa_variant.
  ELSE.
    p_wa_variant-report = sy-cprog.
  ENDIF.
ENDFORM. " ALV_VARIANT_CHECK
*&---------------------------------------------------------------------*
*& Form write_report_header
*&---------------------------------------------------------------------*
* Create the report header
*----------------------------------------------------------------------*
* Parameters: --> P_TEXT1: Company Code Description
* --> P_TEXT2: Report Description 1
* --> P_TEXT3: Report Description 2
*----------------------------------------------------------------------*
FORM write_report_header USING p_text1 TYPE any
                                p_text2 TYPE any
                                p_text3 TYPE any.
  CONSTANTS: c_hyphen(1) TYPE c VALUE '-'. " Hyphen
  DATA: l_pagno(5) TYPE c, " Page no
        l_page_len TYPE p, " String length of page no
        l_name_len TYPE p, " String length of company name
        l_hdr1_len TYPE p, " String length of header line 1
        l_hdr2_len TYPE p, " String length of header line 2
        l_line1_pos TYPE p, " Printing pos of company name
        l_line2_pos TYPE p, " Printing pos of header line 1
        l_line3_pos TYPE p, " Printing pos of header line 2
        l_right_pos1 TYPE p, " Position from right margin
        l_right_pos2 TYPE p, " Position from right margin
        l_center TYPE p. " Center of page
* Calculate string lengths and printing positions
  l_name_len = strlen( p_text1 ).
  l_hdr1_len = strlen( p_text2 ).
  l_hdr2_len = strlen( p_text3 ).
  l_center = ( sy-linsz / 2 ).
  l_line1_pos = l_center - ( l_name_len / 2 ).
  l_line2_pos = l_center - ( l_hdr1_len / 2 ).
  l_line3_pos = l_center - ( l_hdr2_len / 2 ).
  l_right_pos1 = sy-linsz - 10.
  l_right_pos2 = sy-linsz - 16.
  FORMAT COLOR COL_HEADING.
* Write 1st line of report header--------------------------------------*
  WRITE: 'Program:'(i00).
  WRITE 9 sy-repid.
  WRITE: AT l_line1_pos p_text1,
  AT l_right_pos2 'Page:'(i38).
  POSITION l_right_pos1.
* Left justify the page number
  l_pagno = sy-pagno.
  SHIFT l_pagno LEFT DELETING LEADING space.
  l_page_len = strlen( l_pagno ).
  IF l_page_len > 3.
    WRITE (12) l_pagno USING EDIT MASK ',__'.
  ELSE.
    WRITE (12) l_pagno.
  ENDIF.
* Write 2nd line of report header--------------------------------------*
  WRITE:/ 'System:'(i39), AT 9 sy-sysid,
        AT 12 c_hyphen,
        AT 13 sy-mandt.
  WRITE: AT l_line2_pos p_text2,
          AT l_right_pos2 'Date:'(i13).
  POSITION l_right_pos1.
  WRITE (11) sy-datum.
* Write 3rd line of report header--------------------------------------*
  WRITE:/ 'UserID:'(i20), AT 9 sy-uname.
  WRITE: AT l_line3_pos p_text3,
          AT l_right_pos2 'Time:'(i28).
  POSITION l_right_pos1.
  WRITE (11) sy-uzeit.
  FORMAT COLOR OFF.
  ULINE.
ENDFORM. " write_report_header
*&---------------------------------------------------------------------*
*& Form write_alv_header
*&---------------------------------------------------------------------*
* Create the report header for ALV
*----------------------------------------------------------------------*
* Parameters: --> P_TEXT1: Program Description
*----------------------------------------------------------------------*
FORM write_alv_header USING p_i_alv_header TYPE slis_t_listheader
                            p_text1 TYPE any.
  CONSTANTS: c_hyphen(1) TYPE c VALUE '-'. " Hyphen
  DATA l_wa_alv_header TYPE slis_listheader.
* Title for ALV
  l_wa_alv_header-typ = 'H'.
  l_wa_alv_header-info = p_text1.
  APPEND l_wa_alv_header TO p_i_alv_header.
  CLEAR l_wa_alv_header.
* First detail
  l_wa_alv_header-typ = 'S'.
  l_wa_alv_header-key = 'Program:'(i10).
  l_wa_alv_header-info = sy-repid.
  l_wa_alv_header-info+42 = 'System:'(i11).
  l_wa_alv_header-info+50 = sy-sysid.
  l_wa_alv_header-info+53 = c_hyphen.
  l_wa_alv_header-info+54 = sy-mandt.
  APPEND l_wa_alv_header TO p_i_alv_header.
  CLEAR l_wa_alv_header.
* Second Detail
  l_wa_alv_header-typ = 'S'.
  l_wa_alv_header-key = 'User ID:'(i12).
  l_wa_alv_header-info = sy-uname.
  l_wa_alv_header-info+22 = 'Date:'(i13).
  l_wa_alv_header-info+28 = sy-datum.
  l_wa_alv_header-info+42 = 'Time:'(i14).
  l_wa_alv_header-info+47 = sy-uzeit.
  APPEND l_wa_alv_header TO p_i_alv_header.
  CLEAR l_wa_alv_header.
ENDFORM. " write_alv_header
*&--------------------------------------------------------------------*
*& Form WRITE_ERROR_REPORT
*&--------------------------------------------------------------------*
* Format the Error report
*---------------------------------------------------------------------*
* PARAMETERS: --> I_ERRORS: Error Table
*----------------------------------------------------------------------*
FORM write_error_report TABLES i_errors TYPE tt_bapiret2.
* Internal table and Work area for Selection table
  DATA l_it_seltab TYPE TABLE OF rsparams INITIAL SIZE 0.
* Program name
  DATA l_repid TYPE sy-repid.
  DATA l_message(100) TYPE c.
  DATA l_wa_errors TYPE bapiret2.
  l_repid = sy-cprog.
* This function module selects the selection Screen contents
  CALL FUNCTION 'RS_REFRESH_FROM_SELECTOPTIONS'
    EXPORTING
      curr_report     = l_repid
    TABLES
      selection_table = l_it_seltab
    EXCEPTIONS
      not_found       = 1
      no_report       = 2
      OTHERS          = 3.
  IF sy-subrc EQ 0.
    WRITE:1 'Selection Criteria'(i21),
          /1 sy-uline(18),
          /1 'Variant Name'(i22),
          23 sy-slset.
* This function module lists the Selection Screen contents
    CALL FUNCTION 'RS_LIST_SELECTION_TABLE'
      EXPORTING
        report        = l_repid
        seltext       = 'X'
        newpage       = space
      TABLES
        sel_tab       = l_it_seltab
      EXCEPTIONS
        sel_tab_empty = 1
        OTHERS        = 2.
    IF sy-subrc <> 0.
* Error handling
    ENDIF.
  ENDIF.
* End of Page
  SKIP 1.
  FORMAT COLOR OFF INTENSIFIED ON.
  SKIP 2.
  WRITE: / 'Error Report'(i23),
        / '------------'.
  SKIP.
* Output all errors detected.
  ULINE AT /(120).
  FORMAT COLOR COL_HEADING.
  WRITE: / sy-vline, 'Msg Class'(i24), 20 sy-vline, 'Msg Number'(i25),
        40 sy-vline, 'Error Message'(i26).
  WRITE AT 120 sy-vline.
  ULINE AT /(120).
  FORMAT RESET.
* Display data Error
  LOOP AT i_errors INTO l_wa_errors.
    FORMAT INTENSIFIED ON.
* Get text for the message
    CALL FUNCTION 'FORMAT_MESSAGE'
      EXPORTING
        id        = l_wa_errors-id
        lang      = sy-langu
        no        = l_wa_errors-number
        v1        = l_wa_errors-message_v1
        v2        = l_wa_errors-message_v2
        v3        = l_wa_errors-message_v3
        v4        = l_wa_errors-message_v4
      IMPORTING
        msg       = l_message
      EXCEPTIONS
        not_found = 1
        OTHERS    = 2.
    IF sy-subrc <> 0.
* Error handling
    ENDIF.
    SHIFT l_message LEFT DELETING LEADING space.
    WRITE: / sy-vline, l_wa_errors-id, 20 sy-vline, l_wa_errors-number,
          40 sy-vline, 41 l_message.
    WRITE AT 120 sy-vline.
  ENDLOOP.
  ULINE AT /(120).
  SKIP 2.
  WRITE :/60 '** End of Report **'(i27).
ENDFORM. "write_error_report
*&---------------------------------------------------------------------*
*& Form prepare_layout
*&---------------------------------------------------------------------*
* Prepare the Layout of the Report Output List
*----------------------------------------------------------------------*
* -->P_WA_LAYOUT " Layout structure
* -->P_NO_COLHEAD " No Column Headings
* -->P_ZEBRA " Stripped Pattern
* -->P_NO_VLINE " Columns Separated by Space
* -->P_NO_KEYFIX " Do not fix key fields
* -->P_NO_INPUT " Display fields only
* -->P_WINDOW_TITLEBAR " Title of List
* -->P_NO_SUMCHOICE " No Summation Choice
* -->P_NO_TOTALLINE " Do not show total Line
* -->P_NO_SUBCHOICE " No Subtotal Choice
* -->P_NO_SUBTOTALS " Do not Show Subtotals
* -->P_TOTALS_ONLY " Show Totals only
* -->P_TOTALS_TEXT " Totals Text
* -->P_NO_SCROLLING " Allow no scrolling
* -->P_DETAIL_POPUP " Show details in a Popup
* -->P_DETAIL_TITLEBAR " Tile for the Detail window
*----------------------------------------------------------------------*
FORM prepare_layout USING p_wa_layout TYPE slis_layout_alv
                          p_col_optimize TYPE any
                          p_no_colhead TYPE any
                          p_zebra TYPE any
                          p_no_vline TYPE any
                          p_no_keyfix TYPE any
                          p_no_input TYPE any
                          p_window_titlebar TYPE any
                          p_no_sumchoice TYPE any
                          p_no_totalline TYPE any
                          p_no_subchoice TYPE any
                          p_no_subtotals TYPE any
                          p_totals_only TYPE any
                          p_totals_text TYPE any
                          p_no_scrolling TYPE any
                          p_detail_popup TYPE any
                          p_detail_titlebar TYPE any.
  p_wa_layout-colwidth_optimize = p_col_optimize.
  p_wa_layout-no_colhead = p_no_colhead.
  p_wa_layout-zebra = p_zebra.
  p_wa_layout-no_vline = p_no_vline.
  p_wa_layout-no_keyfix = p_no_keyfix.
  p_wa_layout-no_input = p_no_input.
  p_wa_layout-window_titlebar = p_window_titlebar.
  p_wa_layout-no_sumchoice = p_no_sumchoice.
  p_wa_layout-no_totalline = p_no_totalline.
  p_wa_layout-no_subchoice = p_no_subchoice.
  p_wa_layout-no_subtotals = p_no_subtotals.
  p_wa_layout-totals_only = p_totals_only.
  p_wa_layout-totals_text = p_totals_text.
  p_wa_layout-no_scrolling = p_no_scrolling.
  p_wa_layout-detail_popup = p_detail_popup.
  p_wa_layout-detail_titlebar = p_detail_titlebar.
ENDFORM. " prepare_layout
*&---------------------------------------------------------------------*
* Form build_fieldcat_tab
*&---------------------------------------------------------------------*
* This subroutine is used to build the field catalog table for
* generating an ALV report
*----------------------------------------------------------------------*
* Parameters:
* tablename --> Internal Table Name
* fieldname --> Internal Table Field Name
* key --> (X or space) to declare field as key
* referencetable --> Reference table
* outputactive --> Output active
* col_posn --> Cloumn Position
* col_hdng --> Column heading
* datatype --> Data Type
* outputlen --> Length of output
* description --> Desciption text
* justification --> Justification of output L, R etc
*----------------------------------------------------------------------*
FORM build_fieldcat_tab TABLES p_i_fieldcatalog
    USING tablename TYPE any
          fieldname TYPE any
          key TYPE any
          referencetable TYPE any
          outputactive TYPE any
          col_posn TYPE any
          col_hdng TYPE any
          datatype TYPE any
          outputlen TYPE any
          description TYPE any
          justification TYPE any.
  DATA l_fieldcat TYPE slis_fieldcat_alv.
  l_fieldcat-tabname = tablename. " Internal Table Name
  l_fieldcat-fieldname = fieldname. " Internal Table Field Name
  l_fieldcat-key = key. "(X or space) to declare field as key
  l_fieldcat-ref_tabname = referencetable. " Reference table
  l_fieldcat-no_out = outputactive. " Output active
  l_fieldcat-col_pos = col_posn. " Cloumn Position
  l_fieldcat-reptext_ddic = col_hdng. " Column heading
  l_fieldcat-datatype = datatype. " Data Type
  l_fieldcat-outputlen = outputlen. " Length of output
  l_fieldcat-seltext_m = description. " Desciption text
  l_fieldcat-just = justification. " Justification
  APPEND l_fieldcat TO p_i_fieldcatalog.
ENDFORM. " build_fieldcat_tab
*&---------------------------------------------------------------------*
*& Form populate_events
*&---------------------------------------------------------------------*
* Populate events for the ALV report
*----------------------------------------------------------------------*
* -->P_NAME Name of the Event
* -->P_FORM Name of the Subroutine to handle the Event
*----------------------------------------------------------------------*
FORM populate_events TABLES p_i_event
    USING p_name TYPE any
          p_form TYPE any.
  DATA l_wa_event TYPE slis_alv_event.
  l_wa_event-name = p_name.
  l_wa_event-form = p_form.
  APPEND l_wa_event TO p_i_event.
ENDFORM. " populate_events
*&---------------------------------------------------------------------*
*& Form alv_eventtab_build
*&---------------------------------------------------------------------*
* Event BUild
*The events table returned by this subroutine should be passed
*while calling the function module for list display
*----------------------------------------------------------------------*
* -->P_C_TOP_OF_PAGE TOP OF PAGE
* -->P_C_END_OF_LIST END OF LIST
* <--P_IT_EVENTS[] EVENTS
*----------------------------------------------------------------------*
FORM alv_eventtab_build USING id_top_of_page TYPE slis_formname
                              id_end_of_list TYPE slis_formname
                      CHANGING ct_event TYPE slis_t_event.
  DATA: ls_event TYPE slis_alv_event.
  REFRESH ct_event.
  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
      i_list_type = 0
    IMPORTING
      et_events   = ct_event.
* top of page
  READ TABLE ct_event WITH KEY name = slis_ev_top_of_page
    INTO ls_event.
  IF sy-subrc = 0.
    MOVE id_top_of_page TO ls_event-form.
    MODIFY ct_event FROM ls_event INDEX sy-tabix.
  ENDIF.
* end of list
  READ TABLE ct_event WITH KEY name = slis_ev_end_of_list
  INTO ls_event.
  IF sy-subrc = 0.
    MOVE id_end_of_list TO ls_event-form.
    MODIFY ct_event FROM ls_event INDEX sy-tabix.
  ENDIF.
ENDFORM. " ALV_EVENTTAB_BUILD
*&---------------------------------------------------------------------*
*& Form add_sort_field
*&---------------------------------------------------------------------*
* Add a Field to the Sort Catalog
*----------------------------------------------------------------------*
* -->P_SPOS " Sort Postion
* -->P_FIELDNAME " Sort Field
* -->P_TABNAME " Sort Table
* -->P_UP " Sort Ascending
* -->P_DOWN " Sort Descending
* -->P_SUBTOT " Sobtotal on the Field
*----------------------------------------------------------------------*
FORM add_sort_field TABLES p_i_sortcatalog
                      USING p_spos TYPE any
                            p_fieldname TYPE any
                            p_tabname TYPE any
                            p_up TYPE any
                            p_down TYPE any
                            p_subtot TYPE any.
* Internal table and Work area for ALV field Sort Catalog
  DATA l_wa_sortcat TYPE slis_sortinfo_alv .
  l_wa_sortcat-spos = p_spos.
  l_wa_sortcat-fieldname = p_fieldname.
  l_wa_sortcat-tabname = p_tabname.
  l_wa_sortcat-up = p_up.
  l_wa_sortcat-down = p_down.
  l_wa_sortcat-subtot = p_subtot.
  APPEND l_wa_sortcat TO p_i_sortcatalog.
ENDFORM. " add_sort_field
*&---------------------------------------------------------------------*
*& Form display_report
*&---------------------------------------------------------------------*
* Call the ALV Interface to Display the Report Output List
*----------------------------------------------------------------------*
* -->P_I_OUTTAB " Output List Internal Table
* -->P_I_CALLBACK_PROGRAM " Callback Program name
* -->P_IS_LAYOUT " Layout Defination
* -->P_IT_FIELDCAT " Field Catalog
* -->P_IT_SORT " Sort Catalog
* -->P_SAVE " Allow saving of User Variants
* -->P_IS_VARIANT " Variant Name
* -->P_IT_EVENTS " List Events
* -->P_FLAG " Flag determine LIST/GRID display
*----------------------------------------------------------------------*
FORM display_report TABLES p_i_outtab
    USING value(p_i_callback_program) TYPE any
          p_is_layout TYPE any
          p_it_fieldcat TYPE any
          p_it_sort TYPE any
          p_save TYPE any
          p_is_variant TYPE any
          p_it_events TYPE any
          p_itabname TYPE any
          p_flag TYPE any.
  DATA l_tabname(30) TYPE c.
  l_tabname = p_itabname.
  TRANSLATE l_tabname TO UPPER CASE.
* Merge field characteristics from Dictionary
  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      i_program_name     = p_i_callback_program
      i_internal_tabname = l_tabname
      i_inclname         = p_i_callback_program
    CHANGING
      ct_fieldcat        = p_it_fieldcat.
  IF p_flag EQ 'X'. "ALV List display
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
      EXPORTING
        i_callback_program = p_i_callback_program
        is_layout          = p_is_layout
        it_fieldcat        = p_it_fieldcat
        it_sort            = p_it_sort
        i_save             = p_save
        is_variant         = p_is_variant
        it_events          = p_it_events
      TABLES
        t_outtab           = p_i_outtab
      EXCEPTIONS
        program_error      = 1
        OTHERS             = 2.
    IF sy-subrc NE 0.
* Error handling
    ENDIF.
  ELSE.
* ALV Grid display
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
      EXPORTING
        i_callback_program = p_i_callback_program
        is_layout          = p_is_layout
        it_fieldcat        = p_it_fieldcat
        it_sort            = p_it_sort
        i_save             = p_save
        is_variant         = p_is_variant
        it_events          = p_it_events
      TABLES
        t_outtab           = p_i_outtab
      EXCEPTIONS
        program_error      = 1
        OTHERS             = 2.
    IF sy-subrc NE 0.
* Error handling
    ENDIF.
  ENDIF.
ENDFORM. " display_report
*&----------------------------------------------------------------------
* Form: POPULATE_CONTROL_RECORD
*&----------------------------------------------------------------------
* This subroutine is used to create the control record for IDOC
*-----------------------------------------------------------------------
FORM populate_control_record USING p_wa_edidc TYPE edidc
                                    p_msgtype TYPE any
                                    p_idoctype TYPE any
                                    p_rcvprt TYPE any
                                    p_rcvprn TYPE any
                                    p_rcvpor TYPE any
                                    p_sndprt TYPE any
                                    p_sndprn TYPE any
                                    p_sndpor TYPE any.
* Populate the control record for the IDoc
  p_wa_edidc-doctyp = p_idoctype.
  p_wa_edidc-mestyp = p_msgtype.
  p_wa_edidc-sndpor = p_sndpor.
  p_wa_edidc-sndprt = p_sndprt.
  p_wa_edidc-sndprn = p_sndprn.
  p_wa_edidc-rcvprt = p_rcvprt.
  p_wa_edidc-rcvprn = p_rcvprn.
  p_wa_edidc-rcvpor = p_rcvpor.
ENDFORM. "POPULATE_CONTROL_RECORD
*&----------------------------------------------------------------------
* Form: CREATE_IDOC_OUTBOUND
*&----------------------------------------------------------------------
* This subroutine is used to create Outbound IDoc
*-----------------------------------------------------------------------
FORM create_idoc_outbound TABLES p_i_edidd TYPE edidd_tt
                                  return
                            USING p_wa_edidc TYPE edidc.
  DATA l_error_msg(40) TYPE c. "Error Message
  DATA l_i_edidc TYPE STANDARD TABLE OF edidc INITIAL SIZE 0.
  APPEND p_wa_edidc TO l_i_edidc.
* Call standard SAP Function module to create Idocs
  CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'
    EXPORTING
      master_idoc_control            = p_wa_edidc
    TABLES
      communication_idoc_control     = l_i_edidc
      master_idoc_data               = p_i_edidd
    EXCEPTIONS
      error_in_idoc_control          = 1
      error_writing_idoc_status      = 2
      error_in_idoc_data             = 3
      sending_logical_system_unknown = 4
      OTHERS                         = 5.
  IF sy-subrc EQ 0.
    COMMIT WORK.
  ELSE.
* Get the exact error parameter for the failure
    SELECT parameter FROM fupararef UP TO 1 ROWS
      INTO l_error_msg
      WHERE funcname EQ 'MASTER_IDOC_DISTRIBUTE'
        AND r3state EQ 'A' "Active
        AND paramtype EQ 'X' "Exception
        AND pposition EQ sy-subrc.
    ENDSELECT.
    PERFORM message_build TABLES return
      USING '00'
            'E'
            '398'
            'Unable to Create IDoc'(i15)
            'Error:'(i05)
            l_error_msg
            space.
    EXIT.
  ENDIF.
* Clear Work Area
  REFRESH: p_i_edidd.
ENDFORM. "create_idoc_outbound
*&---------------------------------------------------------------------*
* Form: CREATE_IDOC_INBOUND
*&---------------------------------------------------------------------*
* This subroutine is used to create inbound idocs
*----------------------------------------------------------------------*
FORM create_idoc_inbound TABLES p_i_edidd TYPE edi_dd40_tt
                                return
                          USING p_wa_edidc TYPE edidc
                          CHANGING idoc_number TYPE edi_docnum.
  DATA l_edidc TYPE edi_dc40.
  MOVE-CORRESPONDING p_wa_edidc TO l_edidc.
  l_edidc-idoctyp = p_wa_edidc-doctyp.
* Call function to create IDoc
  CALL FUNCTION 'IDOC_INBOUND_SINGLE'
    EXPORTING
      pi_idoc_control_rec_40  = l_edidc
    IMPORTING
      pe_idoc_number          = idoc_number
    TABLES
      pt_idoc_data_records_40 = p_i_edidd
    EXCEPTIONS
      idoc_not_saved          = 1
      OTHERS                  = 2.
  IF sy-subrc NE 0.
    PERFORM message_build TABLES return
      USING '00'
            'E'
            '398'
            'Unable to Create Inbound IDoc'(i16)
            space
            space
            space.
    EXIT.
  ENDIF.
* Clear Work Area
  REFRESH: p_i_edidd.
ENDFORM. "create_idoc_inbound
*&---------------------------------------------------------------------*
*& Form convert_dec_to_user_setting
*&---------------------------------------------------------------------*
* Convert currency value according to user setting eg, decimal
* separator, thousand separator etc.
*----------------------------------------------------------------------*
* <-> L_VALUE External Value
*----------------------------------------------------------------------*
FORM conv_decima_user_setting CHANGING l_value TYPE any.
  DATA: l_dcpfm TYPE xudcpfm. "Decimal notation
  SELECT SINGLE dcpfm "Decimal format
    FROM usr01
    INTO (l_dcpfm)
    WHERE bname = sy-uname.
  IF sy-subrc = 0.
* Decimal Formatting
    IF l_dcpfm = 'X'.
* Do nothing
    ELSE.
      REPLACE ALL OCCURRENCES OF ',' IN l_value WITH space.
      CONDENSE l_value.
      REPLACE '.' IN l_value WITH ','.
    ENDIF.
  ENDIF.
ENDFORM. "convert_decimal_to_user_setting
*&--------------------------------------------------------------------*
*& Form convert_date_to_user_setting
*&--------------------------------------------------------------------*
* Format the date according to the user setting for the user
* mentioned in the BDC session
*---------------------------------------------------------------------*
* <-> L_VALUE date in format YYYYMMDD
* Comment: L_VALUE should be a CHAR10 variable.You need to take
* the date field to a CHAR10 variable and pass the
* CHAR10 variable to this perform to convert it to
* user format.
*---------------------------------------------------------------------*
FORM convert_date_to_user_setting CHANGING l_value TYPE any.
  DATA: l_datfm TYPE c, " of type xudatfm
        l_date TYPE sydatum.
  SELECT SINGLE datfm
    INTO (l_datfm)
    FROM usr01
    WHERE bname = sy-uname.
  IF sy-subrc = 0.
    CASE l_datfm.
      WHEN '1'. "DD.MM.YYYY format
        l_date = l_value.
        CONCATENATE l_date+6(2) "DD
        l_date+4(2) "MM
        l_date+0(4) "YYYY
        INTO l_value
        SEPARATED BY '.'.
      WHEN '2'.
        l_date = l_value. "MM/DD/YYYY format
        CONCATENATE l_date+4(2) "MM
        l_date+6(2) "DD
        l_date+0(4) "YYYY
        INTO l_value
        SEPARATED BY '/'.
      WHEN '3'.
        l_date = l_value. "MM-DD-YYYY format
        CONCATENATE l_date+4(2) "MM
        l_date+6(2) "DD
        l_date+0(4) "YYYY
        INTO l_value
        SEPARATED BY '-'.
      WHEN '4'.
        l_date = l_value. "YYYY.MM.DD format
        CONCATENATE l_date+0(4) "YYYY
        l_date+4(2) "MM
        l_date+6(2) "DD
        INTO l_value
        SEPARATED BY '.'.
      WHEN '5'.
        l_date = l_value. "YYYY/MM/DD format
        CONCATENATE l_date+0(4) "YYYY
        l_date+4(2) "MM
        l_date+6(2) "DD
        INTO l_value
        SEPARATED BY '/'.
      WHEN '6'.
        l_date = l_value. "YYYY-MM-DD format
        CONCATENATE l_date+0(4) "YYYY
        l_date+4(2) "MM
        l_date+6(2) "DD
        INTO l_value
        SEPARATED BY '-'.
      WHEN OTHERS.
    ENDCASE.
  ENDIF.
ENDFORM. "convert_date_to_user_setting
*&--------------------------------------------------------------------*
*& Form numeric_check
*&--------------------------------------------------------------------*
* Checks if the string contains non-numeric character
*---------------------------------------------------------------------*
* --> L_FIELD Field name
* --> L_VALUE Value of the field
* --> L_TABIX Record Index
* --> L_DEC Decimal Check flag
* <-- RETURNS Error Table
*---------------------------------------------------------------------*
FORM numeric_check TABLES return TYPE tt_bapiret2
  USING l_field TYPE any
        l_value TYPE any
        l_tabix TYPE any
        l_dec TYPE any.
  CONSTANTS c_number_string(11)
  TYPE c VALUE '0123456789 '. "Numbers only
  CONSTANTS c_numeric_string(12)
  TYPE c VALUE '0123456789. '."Numeric characters
  DATA l_message(50) TYPE c.
* If the decimal check is 'X' then
* If the field value is non-numeric then raise error
  IF l_dec = 'X'.
    IF l_value CN c_numeric_string. "0-9.SPACE
      CONCATENATE 'Field:'(i17) l_field 'Value:'(i18) l_value
          'Index:'(i19) l_tabix
          'should be numeric'
        INTO l_message SEPARATED BY space.
      PERFORM message_build TABLES return
        USING '00'
              'E'
              '398'
              l_message
              space
              space
              space.
    ENDIF.
  ELSE.
    IF l_value CN c_number_string. "0-9 SPACE
      CONCATENATE 'Field:'(i17) l_field 'Value:'(i18) l_value
          'Index:'(i19) l_tabix
          'should be numeric'
        INTO l_message SEPARATED BY space.
      PERFORM message_build TABLES return
        USING '00'
              'E'
              '398'
              l_message
              space
              space
              space.
    ENDIF.
  ENDIF.
ENDFORM. "numeric_check
*&---------------------------------------------------------------------*
*& Form convert_material
*&---------------------------------------------------------------------*
* Convert material number to SAP internal format
*----------------------------------------------------------------------*
* <-> L_MATNR Material number
* <-> L_SUBRC Status
*----------------------------------------------------------------------*
FORM convert_material CHANGING p_matnr TYPE any
                                p_subrc TYPE any.
* Call the conversion exit FM for MATNR
  CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
    EXPORTING
      input        = p_matnr
    IMPORTING
      output       = p_matnr
    EXCEPTIONS
      length_error = 1
      OTHERS       = 2.
  p_subrc = sy-subrc.
ENDFORM. "convert_material
*&---------------------------------------------------------------------*
*& Form convert_vendor
*&---------------------------------------------------------------------*
* Convert Vendon number to SAP internal format
*----------------------------------------------------------------------*
* <-> L_LIFNR Material number
*----------------------------------------------------------------------*
FORM convert_vendor CHANGING p_lifnr TYPE any.
* Call the conversion exit FM for vendor
  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
      input  = p_lifnr
    IMPORTING
      output = p_lifnr.
ENDFORM. "convert_vendor
*&--------------------------------------------------------------------*
*& Form convert_uom
*&--------------------------------------------------------------------*
* Convert Unit of Measure to SAP internal format
*---------------------------------------------------------------------*
* <-> L_MEINS Unit of Measure
* <-> L_SUBRC Status
*---------------------------------------------------------------------*
FORM convert_uom CHANGING p_meins TYPE any
p_subrc TYPE any.
* Call the conversion exit FM for UoM
  CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
    EXPORTING
      input          = p_meins
      language       = sy-langu
    IMPORTING
      output         = p_meins
    EXCEPTIONS
      unit_not_found = 1
      OTHERS         = 2.
  p_subrc = sy-subrc.
ENDFORM. "convert_uom
*&---------------------------------------------------------------------*
*& Form sub_send_mail
*&---------------------------------------------------------------------*
* Send mails from SAP to SAPuser or internet user
* Receiver type is 'B' for SAP user
* 'U' for Internet user
* 'C' for distribution list
*----------------------------------------------------------------------*
FORM sub_send_mail TABLES object_header TYPE srm_t_solisti1
                          object_content TYPE srm_t_solisti1
                          receivers TYPE bubas_t_receiver
                    USING subject_line TYPE char255
                          receiver_type TYPE so_escape
                          receiver_address TYPE so_rec_id.
**Declare these tables in your program before using this Subroutine
* Header details for the SAP Mail
* DATA i_object_hdr TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0.
* Body of SAP mail
* DATA i_obj_content TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0.
* Internal table for storing recipients of mail
* DATA i_receivers TYPE STANDARD TABLE OF somlreci1 INITIAL SIZE 0.
**
* Work area for mail recipients
  DATA l_wa_receivers TYPE somlreci1.
* Work area for sap mail
  DATA l_wa_object_hd_change TYPE sodocchgi1.
* Set SAPmail header data (object definition & attributes)
  l_wa_object_hd_change-obj_langu = sy-langu.
  l_wa_object_hd_change-obj_name = 'SAP'.
  l_wa_object_hd_change-sensitivty = 'F'.
  l_wa_object_hd_change-obj_descr = subject_line.
*Populate the receiver data
  l_wa_receivers-receiver = receiver_address.
  l_wa_receivers-rec_type = receiver_type.
  APPEND l_wa_receivers TO receivers.
  CLEAR l_wa_receivers.
  CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
    EXPORTING
      document_data              = l_wa_object_hd_change
      document_type              = 'RAW'
      put_in_outbox              = 'X'
      commit_work                = 'X' " COMMIT for SCOT
    TABLES
      object_header              = object_header
      object_content             = object_content
      receivers                  = receivers
    EXCEPTIONS
      too_many_receivers         = 1
      document_not_sent          = 2
      document_type_not_exist    = 3
      operation_no_authorization = 4
      parameter_error            = 5
      x_error                    = 6
      enqueue_error              = 7
      OTHERS                     = 8.
  IF sy-subrc NE 0.
* Error handling
  ENDIF.
ENDFORM. "sub_send_mail
*&---------------------------------------------------------------------*
* Form: DIRECTORY_SEARCH
*&---------------------------------------------------------------------*
* This subroutine is used get the file names from a directory
*----------------------------------------------------------------------*
* Parameters: <-- I_GET_FILES - File list
* --> P_PATH - File path
* --> P_MASK - File masking/extension
*----------------------------------------------------------------------*
FORM directory_search TABLES p_i_get_files TYPE tab_epsfili
    USING p_path TYPE epsdirnam
          p_mask TYPE epsfilnam.
* Get file names
  CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
    EXPORTING
      dir_name               = p_path
      file_mask              = p_mask
    TABLES
      dir_list               = p_i_get_files
    EXCEPTIONS
      invalid_eps_subdir     = 1
      sapgparam_failed       = 2
      build_directory_failed = 3
      no_authorization       = 4
      read_directory_failed  = 5
      too_many_read_errors   = 6
      empty_directory_list   = 7
      OTHERS                 = 8.
  IF sy-subrc NE 0.
* Error handling
  ENDIF.
ENDFORM. "F_DIRECTORY_SEARCH
 
REPORT zmhreport MESSAGE-ID zdev.
***************************************************************
* DATA DECLARATIONS
***************************************************************
DATA: okcode LIKE sy-ucomm.
DATA:
* Container Control...the parent...
  container_r TYPE REF TO cl_gui_custom_container,
  container_r1 TYPE REF TO cl_gui_custom_container,
* Define the Application Control (ALV) instance...
  grid_r TYPE REF TO cl_gui_alv_grid,
  grid_r1 TYPE REF TO cl_gui_alv_grid,
  gs_toolbar TYPE stb_button.
*--------------------- Type pools ----------------------------*
TYPE-POOLS: slis. "Type Pool for ALV
*------------------- Constants -------------------------------*
CONSTANTS: c_x(1) TYPE c VALUE 'X'. " Constant for X
*** SPECIFIES THE COLUMN POSITION OF THE REPORT'S FIELDS
CONSTANTS:
*COLUMN POSITION OF THE REPORT'S FIELDS DETAIL
c_dcl_pos1 TYPE sycucol VALUE '01' , " POSITION 1
c_dcl_pos2 TYPE sycucol VALUE '02' , " POSITION 2
c_dcl_pos3 TYPE sycucol VALUE '03' , " POSITION 3
c_dcl_pos4 TYPE sycucol VALUE '04' , " POSITION 4
c_dcl_pos5 TYPE sycucol VALUE '05' , " POSITION 5
c_dcl_pos6 TYPE sycucol VALUE '06' , " POSITION 6
c_dcl_pos7 TYPE sycucol VALUE '07' , " POSITION 7
c_dcl_pos8 TYPE sycucol VALUE '08' , " POSITION 8
c_dcl_pos9 TYPE sycucol VALUE '09' , " POSITION 9
c_dcl_pos10 TYPE sycucol VALUE '10' , " POSITION 10
c_dcl_pos11 TYPE sycucol VALUE '11' , " POSITION 11
c_dcl_pos12 TYPE sycucol VALUE '12' , " POSITION 12
c_dcl_pos13 TYPE sycucol VALUE '13' , " POSITION 13
c_dcl_pos14 TYPE sycucol VALUE '14' , " POSITION 14
c_dcl_pos15 TYPE sycucol VALUE '15' , " POSITION 15
c_dcl_pos16 TYPE sycucol VALUE '16' , " POSITION 16
c_dcl_pos17 TYPE sycucol VALUE '17' , " POSITION 17
c_dcl_pos18 TYPE sycucol VALUE '18' , " POSITION 18
c_dcl_pos19 TYPE sycucol VALUE '19' , " POSITION 19
c_dcl_pos20 TYPE sycucol VALUE '20' , " POSITION 20
c_dcl_pos21 TYPE sycucol VALUE '21' , " POSITION 21
c_dcl_pos22 TYPE sycucol VALUE '22' , " POSITION 22
c_dcl_pos23 TYPE sycucol VALUE '23' , " POSITION 23
c_dcl_pos24 TYPE sycucol VALUE '24' , " POSITION 24
c_dcl_pos25 TYPE sycucol VALUE '25' , " POSITION 25
c_dcl_pos26 TYPE sycucol VALUE '26' , " POSITION 26
*COLUMN POSITION OF THE REPORT'S FIELDS HEADER
c_hcl_pos1 TYPE sycucol VALUE '01' , " POSITION 01
c_hcl_pos2 TYPE sycucol VALUE '02' , " POSITION 02
c_hcl_pos3 TYPE sycucol VALUE '03' , " POSITION 03
c_hcl_pos4 TYPE sycucol VALUE '04' , " POSITION 04
*** FIELD NAME OF THE REPORTS DETAIL
c_fld_ctr TYPE slis_fieldname VALUE 'CTR',"Counter
c_fld_cur_werks TYPE slis_fieldname VALUE 'CUR_WERKS',"Curr Plant
c_fld_lgort TYPE slis_fieldname VALUE 'LGORT',"Storage Loc
c_fld_cur_lgnum TYPE slis_fieldname VALUE 'CUR_LGNUM',"Curr Ware
c_fld_rec_werks TYPE slis_fieldname VALUE 'REC_WERKS',"Rec Plant
* C_fld_im_movt TYPE slis_fieldname VALUE 'IM_MOVT',"IM Movt
* C_fld_wm_movt TYPE slis_fieldname VALUE 'WM_MOVT',"WM Movt
c_fld_in_trn TYPE slis_fieldname VALUE 'IN_TRN',"In Transit
c_fld_kunnr TYPE slis_fieldname VALUE 'KUNNR',"Customer
c_fld_kunnr_name1 TYPE slis_fieldname VALUE 'NAME1',"Customer Name
c_fld_load_no TYPE slis_fieldname VALUE 'LOAD_NO',"Load No
c_fld_lenum TYPE slis_fieldname VALUE 'LENUM',"SSCC Number
c_fld_act_menge TYPE slis_fieldname VALUE 'ACT_MENGE',"Quantity
c_fld_meins TYPE slis_fieldname VALUE 'MEINS',"UOM
* c_fld_bestq TYPE slis_fieldname VALUE 'BESTQ',"Blocking Reason
c_fld_text TYPE slis_fieldname VALUE 'TEXT',"Blocking Reason
c_fld_spgtx TYPE slis_fieldname VALUE 'SPGTX',"Blocking Text
c_fld_letyp TYPE slis_fieldname VALUE 'LETYP',"Storage Unit Type
c_fld_ebeln TYPE slis_fieldname VALUE 'EBELN',"Purchase Doc.No
c_fld_desp_date TYPE slis_fieldname VALUE 'DESP_DATE',
"Despatch Date
c_fld_desp_time TYPE slis_fieldname VALUE 'DESP_TIME',
"Despatch Time
c_fld_qproddat TYPE slis_fieldname VALUE 'QPRODDAT',"Prod Date
c_fld_qprodtime TYPE slis_fieldname VALUE 'QPRODTIME',"Prod Time
c_fld_bbd_vfdat TYPE slis_fieldname VALUE 'BBD_VFDAT',
"Best Before Date
c_fld_sed_vfdat TYPE slis_fieldname VALUE 'SED_VFDAT',
"Shelf life expiry date
c_fld_qplos TYPE slis_fieldname VALUE 'QPLOS',"Inspection Lot,
c_fld_color TYPE slis_fieldname VALUE 'COLOR',"Colour,
*** FIELD NAME OF THE REPORTS HEADER
c_fld_werks_plant TYPE slis_fieldname VALUE 'WERKS_PLANT',"Plant
c_fld_matnr TYPE slis_fieldname VALUE 'MATNR',"Material
c_fld_maktx TYPE slis_fieldname VALUE 'MAKTX',"Material Desc
c_fld_charg TYPE slis_fieldname VALUE 'CHARG',"Batch
*** SPECIFIES THE LENGTH OF COLUMN WITHIN THE REPORT'S FIELDS
c_1 TYPE outputlen VALUE '1', "OUTPUT LENGTH
c_2 TYPE outputlen VALUE '2', "OUTPUT LENGTH
c_3 TYPE outputlen VALUE '3',"OUTPUT LENGTH
*units(UOM),storage unit type
c_4 TYPE outputlen VALUE '4', "OUTPUT LENGTH
*producing plant,reciving plant
c_6 TYPE outputlen VALUE '6' ,"OUTPUT LENGTH
*desptime,production time
c_8 TYPE outputlen VALUE '8', "OUTPUT LENGTH
*desp date,production date,best before date,self expiry date,
*counter
c_10 TYPE outputlen VALUE '10',"OUTPUT LENGTH
c_15 TYPE outputlen VALUE '15',"OUTPUT LENGTH
*batch,purchasing doc
c_12 TYPE outputlen VALUE '12',"OUTPUT LENGTH
*inspection lot no
c_13 TYPE outputlen VALUE '13',"OUTPUT LENGTH
*Quantity
c_18 TYPE outputlen VALUE '18',"OUTPUT LENGTH
*material,movement desc
c_20 TYPE outputlen VALUE '20',"OUTPUT LENGTH
*SSCC NO
c_25 TYPE outputlen VALUE '25',"OUTPUT LENGTH
*reciving warehouse dec
c_35 TYPE outputlen VALUE '35',"OUTPUT LENGTH
c_40 TYPE outputlen VALUE '40',"OUTPUT LENGTH
*material desc
*** SPECIFIES THE EVENTS WITHIN THE REPORT
c_form1 TYPE slis_formname VALUE 'TOP_OF_PAGE',"EVENTS
c_form2 TYPE slis_formname VALUE 'END_OF_LIST',"EVENTS
*** INTERNAL TABLE WHCIH STORES THE REPORT AND THE SUMMARY REPORT
**** NAME OF INTERNAL TABLESTORING MAIN DATA OF REPORT PASSED TO ALV
c_tabname1 TYPE slis_tabname VALUE 'I_REPHDR' ," header
c_tabname2 TYPE slis_tabname VALUE 'I_REPDTL' ." detail
*--------------------- TABLES --------------------------------*
TABLES: mara,
        makt,
        lein,
        lqua,
        t320,
        zmccnn1,
        zmccnn2,
        ltap,
        ltak,
        likp,
        lips,
        mkpf,
        mseg.
*--------------------- TYPES ---------------------------------*
* Type for storing pallets and Outputting it in ALV
TYPES: BEGIN OF ty_ltap,
  lgort TYPE lgort_d,
  lgnum TYPE lgnum, "Warehouse Number / Warehouse Complex
  tanum TYPE tanum, "Transfer Order Number
  matnr TYPE matnr, "Material
  charg TYPE charg_d, "Batch
  werks TYPE werks_d,
  meins TYPE meins, "UoM
  altme TYPE lrmei, "Alternate UoM
  umrez TYPE umrez, "Numerator for UoN Conversion
  umren TYPE umren, "Denominator for UoN Conversion
  qdatu TYPE ltap_qdatu, "Confirmation Date
  qzeit TYPE ltap_qzeit, "Confirmation Time
  wdatu TYPE lvs_wdatu, "GR Date
  wenum TYPE lvs_wenum, "GR Number
  nltyp TYPE ltap_nltyp, "Destination storage type
  nista TYPE ltap_nista, "Quantity in Alt UoM
  maktx TYPE maktx, "Material Description
  vlenr TYPE ltap_vlenr, "Source storage unit number
  nlenr TYPE ltap_nlenr, "SSCC
  qplos TYPE qplos , "Inspection Lot Number
  vbeln TYPE vbeln_vl, "Delivery
  nlpla TYPE ltap_nlpla, " Delivery number
  bestq TYPE bestq, "Stock Type
  del_flag(1), "Delete flag
END OF ty_ltap.
* Type for Retrieving Material Document Number and Year from LTAK
TYPES: BEGIN OF ty_ltak,
  lgnum TYPE lgnum, "Warehouse Number / Warehouse Complex
  tanum TYPE tanum, "Transfer Order Number
  bwart TYPE bwart, "Movement Type (im)
  bwlvs TYPE bwlvs, "movement type (wm)
  mblnr TYPE mblnr, "Material Document
  mjahr TYPE mjahr, "Year
  del_flag(1), "Delete flag
END OF ty_ltak.
* Type for Retrieving Posting Date / Time from MKPF
TYPES: BEGIN OF ty_mkpf,
  mblnr TYPE mblnr, "Material Document
  mjahr TYPE mjahr, "Year
  vgart TYPE vgart, "Transaction/Event Type
  blart TYPE blart, "Document type
  budat TYPE budat, "Posting Date (Dummy Prod. Date)
  cputm TYPE cputm, "Time of Entry (Dummy Prod. Time)
END OF ty_mkpf.
* Type for Checking presence/absence in warehouse system
TYPES: BEGIN OF ty_lein,
  lenum TYPE lenum, "Storage Unit Number
  lgnum TYPE lgnum, "Warehouse Number / Warehouse Complex
END OF ty_lein.
* Type for Checking aufnr
TYPES: BEGIN OF ty_mseg,
  mblnr TYPE mblnr, "Material Document
  mjahr TYPE mjahr, "Year
  matnr TYPE matnr, "Material Number
  werks TYPE werks_d, "Plant
  charg TYPE charg_d, "Batch Number
  aufnr TYPE aufnr, "Order Number
  vfdat TYPE vfdat, "Shelf Life Expiration Date
END OF ty_mseg.
* Types for checking the plant.
TYPES: BEGIN OF ty_lqua,
  werks TYPE werks_d, "Plant
  lgort TYPE lgort_d, "Storage Location
  lgnum TYPE lgnum , "Warehouse Number / Warehouse Complex
  spgru TYPE lvs_spgru, "Blocking Reason,
  bestq TYPE bestq, "Stock indicator
  lenum TYPE lenum,
  spgtx TYPE lvs_spgtx, "Text for blocking reason
END OF ty_lqua.
* Types for checking the producing plant or DC
TYPES: BEGIN OF ty_t001w,
  werks TYPE werks_d, "Plant
  nodetype TYPE nodetype, "Node type: supply chain network
END OF ty_t001w.
*type declaration to hold the header info of the report.
TYPES:BEGIN OF ty_rephdr,
  werks_plant TYPE ckml_werk_prod,"plant
  matnr TYPE matnr, "material no
  maktx TYPE maktx, "material desc
  charg TYPE charg_d, "batch
END OF ty_rephdr.
*type declaration to hold data for likp.
TYPES: BEGIN OF ty_likp,
  vbeln TYPE vbeln,"delivery
  kunnr TYPE kunnr,"customer
END OF ty_likp.
TYPES: BEGIN OF ty_lips,
  matnr TYPE matnr,
  charg TYPE charg_d,
  werks TYPE werks_d,
  vbeln TYPE vbeln,
END OF ty_lips.
*type declaration to retrive /NESGLB/MCCNN1 & /NESGLB/MCCNN2
TYPES: BEGIN OF ty_mccnn1_2,
  load_no TYPE char35, "load no
  werks TYPE werks_d, "Plant
  desp_date TYPE sydatum, "desp date
  desp_time TYPE syuzeit, "desp time
  matnr TYPE matnr, "material Number
  gtin TYPE ean11, " International Article Number
  prod_variant TYPE char4, "Product Variant
  charg TYPE charg_d, " Batch Number
  meins TYPE meins, " Base Unit of Measure
  act_menge TYPE act_menge , "Actual Quantity
  exp_menge TYPE act_menge , "Actual Quantity,
  insmk TYPE insmk, "Stock type
  lenum TYPE lenum, " Storage Unit Number
  letyp TYPE lvs_letyp, "Storage Unit Type
  ebeln TYPE ebeln, "Purchasing Document Number
  ebelp TYPE ebelp, "Item Number of Pur Document
  werk_plant TYPE ckml_werk_prod, "Production Plant
  lgort TYPE lgort_d, "Storage Location
  qproddat TYPE qproddat, "Production Date
  qprodtime TYPE syuzeit, "Production Time
  qplos TYPE qplos, "Inspection Lot Number
  item_stat TYPE char4, "ASN Item Status
  mblnr TYPE mblnr, "Number of Material Document
  tanum TYPE tanum, "Transfer Order Number
END OF ty_mccnn1_2.
*type declaration to hold the detail info of the report.
TYPES:BEGIN OF ty_repdtl,
  ctr TYPE i, "counter
  cur_werks TYPE werks_d, "Current plant
  lgort TYPE lgort_d, "Current Storage Location
  cur_lgnum TYPE lgnum, "Current Warehouse
  lgnum TYPE lgnum , "reciving ware house no
  lnumt TYPE lvs_lnumt, "reciving ware house description
  rec_werks TYPE werks_d, "reciving plant
  im_movt TYPE bwart, "IM Movement,
  wm_movt TYPE bwlvs, "WM Movement,
  in_trn(1) TYPE c, "stock in transit
  kunnr TYPE kunnr, "customer
  name1 TYPE name1_gp, "Customer Description
  load_no TYPE char35, "load no
  lenum TYPE lenum, "storage unit no(SSCC No)
  act_menge TYPE act_menge,"quantity
  meins TYPE meins, "UOM
  bestq TYPE bestq, "Stock Indicator
  text(15) TYPE c, "Stock indicator text
  spgru TYPE lvs_spgru, "Blocking Reason,
  spgtx TYPE lvs_spgtx, "Text for blocking reason
  letyp TYPE lvs_letyp, "storage unit type
  ebeln TYPE ebeln, "purchasing doc no
  desp_date TYPE sydatum, "desp date
  desp_time TYPE syuzeit, "desp time
  qproddat TYPE qproddat, "production date
  qprodtime TYPE syuzeit, "production time
  bbd_vfdat TYPE vfdat, "best before date
  sed_vfdat TYPE vfdat, "shelf expiration date
  qplos TYPE qplos, "inspection lot no
  color TYPE slis_specialcol_alv OCCURS 3, "for cell color
END OF ty_repdtl.
TYPES:BEGIN OF ty_t3201,
  werks TYPE werks_d, "plant
  lgort TYPE lgort_d,
  lgnum TYPE lgnum,
END OF ty_t3201.
*------------------- Internal tables -----------------------*
* Internal table for storing pallets and Outputting it in ALV
DATA: i_ltap TYPE STANDARD TABLE OF ty_ltap
INITIAL SIZE 0 .
DATA: i_copy_ltap TYPE STANDARD TABLE OF ty_ltap
INITIAL SIZE 0 .
* Internal table for Retrieving Posting Date / Time from MKPF
DATA: i_copy_mkpf TYPE STANDARD TABLE OF ty_mkpf
INITIAL SIZE 0 .
DATA: i_copy_ltak TYPE STANDARD TABLE OF ty_ltak
INITIAL SIZE 0 .
DATA: wa_ltap TYPE ty_ltap.
DATA: wa_ltap_others TYPE ty_ltap.
* Internal Table to hold the header info of the report.
DATA:
i_rephdr TYPE STANDARD TABLE OF ty_rephdr INITIAL SIZE 0 ,
* Work Area to hold the header info of the report.
wa_rephdr TYPE ty_rephdr ,
*Internal table to hold output
i_repdtl TYPE STANDARD TABLE OF ty_repdtl WITH HEADER LINE,
** Internal Table to hold the detail info of the report
i_repdtl_itab TYPE STANDARD TABLE OF ty_repdtl INITIAL SIZE 0 ,
* Work Area to hold the detail info of the report
wa_repdtl TYPE ty_repdtl ,
wa_repdtl_itab TYPE ty_repdtl ,
wa_t3201 TYPE ty_t3201.
* Internal table for sort table
DATA: i_sort TYPE slis_t_sortinfo_alv, "Sort parameters
* Events Internal Table's
i_event TYPE slis_alv_event,"EVENTS
i_zevents TYPE slis_t_event. "EVENTS
DATA: i_pagetop TYPE slis_t_listheader. "ALV top of page header table
DATA:
* Field Catalogs...
i_fieldcat_l TYPE lvc_t_fcat WITH HEADER LINE, " LVC
* Layout Structure...
layout TYPE lvc_s_layo.
DATA:
* Field Catalogs...
i_fieldcat_l2 TYPE lvc_t_fcat WITH HEADER LINE, " LVC
* Layout Structure...
layout2 TYPE lvc_s_layo,
*Internal table for layout
i_layout TYPE slis_layout_alv.
DATA: s_layout TYPE lvc_s_layo,
i_fcode TYPE ui_functions WITH HEADER LINE,
col_pos TYPE i,
*Internal table for coloring cells
i_col_layout TYPE slis_t_specialcol_alv.
*-------------------Global variable---------------------------------*
DATA: v_repid LIKE sy-repid. " To store program name
*defination
CLASS lcl_event_reciver DEFINITION.
  PUBLIC SECTION.
    METHODS handle_double_click FOR EVENT double_click OF cl_gui_alv_grid
    IMPORTING e_row e_column.
ENDCLASS. "lcl_event_reciver DEFINITION
*declaration of an object type.
DATA: event_reciver TYPE REF TO lcl_event_reciver.
DATA: event_reciver1 TYPE REF TO lcl_event_reciver.
*implimentation
CLASS lcl_event_reciver IMPLEMENTATION.
  METHOD handle_double_click.
    IF e_column = 'MATNR'.
      LOOP AT i_rephdr INTO wa_rephdr.
        IF sy-tabix = e_row.
          EXIT.
        ENDIF.
      ENDLOOP.
      IF NOT wa_rephdr-matnr IS INITIAL.
        SET PARAMETER ID 'MAT' FIELD wa_rephdr-matnr.
        CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
      ENDIF.
    ELSEIF e_column = 'LENUM'.
      LOOP AT i_repdtl INTO wa_repdtl.
        IF sy-tabix = e_row.
          EXIT.
        ENDIF.
      ENDLOOP.
      IF NOT wa_repdtl-lenum IS INITIAL.
        SET PARAMETER ID 'LEN' FIELD wa_repdtl-lenum.
        CALL TRANSACTION 'LS33' AND SKIP FIRST SCREEN.
      ENDIF.
    ENDIF.
  ENDMETHOD. "handle_double_click
ENDCLASS. "lcl_event_reciver IMPLEMENTATION
*-------------------SELECTION SCREEN--------------------------------*
* Internal table for Retrieving Material Document and Year from LTAK
DATA: l_i_ltak TYPE STANDARD TABLE OF ty_ltak
INITIAL SIZE 0 .
* Internal table for Retrieving Posting Date / Time from MKPF
DATA: l_i_mkpf TYPE STANDARD TABLE OF ty_mkpf
INITIAL SIZE 0 .
* Internal table for Checking presence/absence in warehouse system
DATA: l_i_lein TYPE STANDARD TABLE OF ty_lein
INITIAL SIZE 0 .
DATA: l_wa_lien TYPE ty_lein.
* Internal table for Checking order no
DATA: l_i_mseg TYPE STANDARD TABLE OF ty_mseg
INITIAL SIZE 0 .
* Internal table for Checking plant
DATA: l_i_lqua TYPE STANDARD TABLE OF ty_lqua
INITIAL SIZE 0 .
DATA: l_i_t3201 TYPE STANDARD TABLE OF ty_t3201
INITIAL SIZE 0 .
* Internal table for Checking other plant and DC
DATA: l_i_t001w TYPE STANDARD TABLE OF ty_t001w
INITIAL SIZE 0 .
* Internal table for retriving customer info for deliveries to customer.
DATA: l_i_likp TYPE STANDARD TABLE OF ty_likp
INITIAL SIZE 0.
DATA: l_i_lips TYPE STANDARD TABLE OF ty_lips
INITIAL SIZE 0.
* Internal table for retriving data from mccnn1&2.
DATA: l_i_mccnn1_2 TYPE STANDARD TABLE OF ty_mccnn1_2
INITIAL SIZE 0.
* Work Area for Retrieving Posting Date / Time from MKPF
DATA: l_wa_mkpf TYPE ty_mkpf.
* Work Area for Retrieving order no
DATA: l_wa_mseg TYPE ty_mseg.
* Work Area for Retrieving order no
DATA: l_wa_ltak TYPE ty_ltak.
* Work Area for holding data from mccnn1&2.
DATA: l_wa_mccnn1_2 TYPE ty_mccnn1_2.
* Work Area for holding data from lein
DATA: l_wa_lein TYPE ty_lein.
* Work Area for holding data from t320
DATA: l_wa_lqua TYPE ty_lqua.
* Work Area for holding data from likp
DATA: l_wa_likp TYPE ty_likp.
DATA: l_wa_lips TYPE ty_lips.
* local variable.
DATA:l_ctr TYPE i ,
l_stock_it(1) TYPE c.

SELECTION-SCREEN: BEGIN OF BLOCK pallet WITH FRAME TITLE text-003.
*"'Pallet Trace'.
PARAMETERS: p_werks TYPE ckml_werk_prod MEMORY ID anr OBLIGATORY ,
"Production Plant
p_matnr TYPE matnr OBLIGATORY, " Material No.
p_charg TYPE charg_d OBLIGATORY. " Batch
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF LINE.
* Production Date / Time From
SELECTION-SCREEN COMMENT 1(42) text-001.
*'Production/Confirmation Date / Time From'.
SELECTION-SCREEN POSITION 43.
PARAMETERS: p_datefr TYPE sydatum OBLIGATORY DEFAULT sy-datum.
SELECTION-SCREEN POSITION 55.
PARAMETERS: p_timefr TYPE syuzeit OBLIGATORY DEFAULT '000000'.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
* Production Date / Time To
SELECTION-SCREEN COMMENT 1(42) text-002.
*'Production/Confirmation Date / Time To'.
SELECTION-SCREEN POSITION 43.
PARAMETERS: p_dateto TYPE sydatum OBLIGATORY DEFAULT sy-datum.
SELECTION-SCREEN POSITION 55.
PARAMETERS: p_timeto TYPE syuzeit OBLIGATORY DEFAULT '235959'.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN : SKIP.
SELECT-OPTIONS: s_lenum FOR lein-lenum. " Storage unit
SELECTION-SCREEN: END OF BLOCK pallet.
*------------ AT SELECTION-SCREEN --------------------------*
*Validation of Plant.
AT SELECTION-SCREEN ON p_werks.
  PERFORM validate_plant.
*Validation of Material Number.
AT SELECTION-SCREEN ON p_matnr.
  PERFORM validate_material.
*Validation of Batch.
AT SELECTION-SCREEN ON p_charg.
  PERFORM validate_batch.

AT SELECTION-SCREEN.
  PERFORM validate_others.
*Validation of Storage Unit.
AT SELECTION-SCREEN ON s_lenum.
* PERFORM validate_storageunit.
*---------------------- START-OF-SELECTION --------------------------*
START-OF-SELECTION.
* ASSIGNING V_REPID WITH SY-REPID
  v_repid = sy-repid.
* subroutine to populate data for report header.
  PERFORM populate_report_header.
* subroutine to populate data for report detail.
  PERFORM select_data.
* create field catalogue for header
  PERFORM create_header_fieldcat.
* create field catalogue for detail
  PERFORM create_detail_fieldcat.
*Build up layoutinfo for the fields to be displayed
* PERFORM layout_build USING i_layout.
  CALL SCREEN 100.
*------------------------- SUBROUTINES ------------------------------*
*&---------------------------------------------------------------------*
*& Form validate_plant
*&---------------------------------------------------------------------*
* SUBROUTINE TO VALIDATE PLANT
*----------------------------------------------------------------------*
FORM validate_plant .
  SELECT COUNT( * ) UP TO 1 ROWS
    FROM t001w
    WHERE werks = p_werks.
  IF sy-subrc <> 0.
* Issue error message and stop processing
    MESSAGE e060(/eur/rgbpt_dev) ."Invalid Plant.
  ELSE.
    wa_rephdr-werks_plant = p_werks.
  ENDIF.
ENDFORM. " validate_plant
*&---------------------------------------------------------------------*
*& Form validate_material
*&---------------------------------------------------------------------*
* Subroutine to validate material
*----------------------------------------------------------------------*
FORM validate_material .
  SELECT COUNT( * ) UP TO 1 ROWS
    FROM mara
    WHERE matnr = p_matnr.
  IF sy-subrc <> 0.
* Issue error message and stop processing
    MESSAGE e015. "Entered Material(s) is invalid
  ENDIF.
  SELECT COUNT( * ) UP TO 1 ROWS
    FROM marc
    WHERE matnr = p_matnr
      AND werks = p_werks.
  IF sy-subrc <> 0.
    MESSAGE e041 WITH p_werks.
    "Entered Material(s) do not exist for entered Plant
  ENDIF.
  SELECT maktx
    INTO makt-maktx
    FROM makt
    WHERE matnr = p_matnr.
  ENDSELECT.
  IF sy-subrc = 0.
    wa_rephdr-matnr = p_matnr.
    wa_rephdr-maktx = makt-maktx.
  ENDIF.
ENDFORM. " validate_material
*&---------------------------------------------------------------------*
*& Form validate_batch
*&---------------------------------------------------------------------*
* This subroutine validates the value of batch entered
*----------------------------------------------------------------------*
FORM validate_batch .
*Check if value is entered for Batch.
  SELECT COUNT( * ) UP TO 1 ROWS
    FROM mcha
    WHERE charg EQ p_charg.
  IF sy-subrc <> 0.
* Issue error message and stop processing
    MESSAGE e058(/eur/rgbpt_dev)." Invalid Batch.
  ELSE.
    wa_rephdr-charg = p_charg.
  ENDIF.
ENDFORM. " validate_batch
*&---------------------------------------------------------------------*
*& Form validate_others
*&---------------------------------------------------------------------*
* Subroutine to validate other things (date & time etc.)
*----------------------------------------------------------------------*
FORM validate_others.
* IF ( p_datefr > p_dateto ) OR
* ( ( p_datefr = p_dateto ) AND ( p_timefr > p_timeto ) ).
* MESSAGE e027. "To Date/Time lesser than From Date/Time
* ENDIF.
*
ENDFORM. " validate_others
*&---------------------------------------------------------------------*
*& Form validate_storageunit
*&---------------------------------------------------------------------*
* This subroutine validates the value of storage unit entered
*----------------------------------------------------------------------*
FORM validate_storageunit .
*Check if value is entered for storage unit.
  IF NOT s_lenum IS INITIAL.
    SELECT COUNT( * )
      UP TO 1 ROWS
      FROM lein
      WHERE lenum IN s_lenum.
    IF sy-subrc <> 0.
* Issue error message and stop processing
      MESSAGE e059(/eur/rgbpt_dev)."Invalid storage unit.
    ENDIF.
  ENDIF.
ENDFORM. " validate_storageunit
*&---------------------------------------------------------------------*
*& Form select_data
*&---------------------------------------------------------------------*
* Subroutine to select data
*----------------------------------------------------------------------*
FORM select_data .
* Type for declaring table I_detl
  TYPES: BEGIN OF ty_detl,
    matnr TYPE matnr,
    charg TYPE charg_d,
    werks TYPE werks_d,
    mblnr TYPE mblnr,
    mjahr TYPE mjahr,
    lgnum TYPE lgnum,
    tanum TYPE tanum,
    tapos TYPE tapos,
    bwlvs TYPE bwlvs,
    bwart TYPE bwart,
    betyp TYPE lvs_betyp,
    benum TYPE lvs_benum,
    bestq TYPE bestq,
    vltyp TYPE ltap_vltyp,
    vlpla TYPE ltap_vlpla,
    vlenr TYPE ltap_vlenr,
    nltyp TYPE ltap_nltyp,
    nlpla TYPE ltap_nlpla,
    nlenr TYPE ltap_nlenr,
    altme TYPE lrmei,
    vsola TYPE ltap_vsola,
    vsolm TYPE ltap_vsolm,
    nsola TYPE ltap_nsola,
    nsolm TYPE ltap_nsolm,
    vbeln TYPE vbeln,
  END OF ty_detl.
* Internal table to hold detail transfer order information
  DATA: i_detl TYPE STANDARD TABLE OF ty_detl WITH HEADER LINE.
*Work Area to hold the detail info of the report
  DATA: wa_detl TYPE ty_detl.
  DATA: BEGIN OF i_vbpa OCCURS 0.
          INCLUDE STRUCTURE vbpa.
  DATA: END OF i_vbpa.
* Selecting Transfer Orders (Pallets Indirectly) from LTAP
  SELECT lgort
          lgnum
          tanum
          matnr
          charg
          werks
          meins
          altme
          umrez
          umren
          qdatu
          qzeit
          wdatu
          wenum
          nltyp
          nista
          maktx
          vlenr
          nlenr
          qplos
          vbeln
          nlpla
          bestq
    INTO TABLE i_ltap
    FROM ltap
    WHERE matnr = p_matnr
      AND werks = p_werks
      AND charg = p_charg AND
          vlenr IN s_lenum.
  IF sy-subrc <> 0.
    MESSAGE s042. "No Pallets found for Selection Criteria
    LEAVE LIST-PROCESSING.
  ENDIF.
  SORT i_ltap BY nlenr.
  i_copy_ltap[] = i_ltap[].
* getting material document & year from ltak
  SELECT lgnum
          tanum
          bwart
          bwlvs
          mblnr
          mjahr
    INTO TABLE l_i_ltak
    FROM ltak
    FOR ALL ENTRIES IN i_ltap
    WHERE lgnum = i_ltap-lgnum
      AND tanum = i_ltap-tanum.
* AND BETYP = 'F'.
  IF sy-subrc = 0. "sy-subrc will always be zero
    SORT l_i_ltak BY lgnum tanum.
    i_copy_ltak[] = l_i_ltak[].
  ENDIF.
* Getting Storage Unit Number (Pallets) from Warehouse System
  SELECT lenum
          lgnum
    INTO TABLE l_i_lein
    FROM lein
    FOR ALL ENTRIES IN i_ltap
    WHERE lenum = i_ltap-nlenr.
  IF sy-subrc = 0.
    SORT l_i_lein BY lenum.
* Getting Plant from from T320(Assignment IM Storage Location to WM
* Warehouse Number)
* Getting current plant / storage location and warehouse from quants * *
* table
    SELECT werks
            lgort
            lgnum
            spgru
            bestq
            lenum
      INTO TABLE l_i_lqua
      FROM lqua
      FOR ALL ENTRIES IN l_i_lein
      WHERE lgnum = l_i_lein-lgnum.
    IF sy-subrc = 0.
      SORT l_i_lqua BY werks.
    ENDIF.
  ENDIF.
* Getting Production Date / Time (Dummy) from MKPF
  SELECT mblnr
          mjahr
          vgart
          blart
          budat
          cputm
    INTO TABLE l_i_mkpf
    FROM mkpf
    FOR ALL ENTRIES IN l_i_ltak
    WHERE mblnr = l_i_ltak-mblnr
      AND mjahr = l_i_ltak-mjahr.
  IF sy-subrc <> 0.
    MESSAGE s042. "No Pallets found for Selection Criteria
    LEAVE LIST-PROCESSING.
  ELSE.
* DELETE l_i_ltak WHERE bwart NE '101'
* OR bwlvs NE '103'.
    LOOP AT i_ltap INTO wa_ltap.
      READ TABLE l_i_ltak INTO l_wa_ltak 
          WITH KEY lgnum = wa_ltap-lgnum
                    tanum = wa_ltap-tanum BINARY SEARCH.
      IF sy-subrc NE 0.
        wa_ltap-del_flag = 'X'.
        MODIFY i_ltap FROM wa_ltap TRANSPORTING del_flag.
      ENDIF.
    ENDLOOP.
    DELETE i_ltap WHERE del_flag = 'X'.
    i_copy_mkpf = l_i_mkpf.
* DELETE l_i_mkpf WHERE vgart NE 'WF' OR
* blart NE 'WE'.
*
* DELETE l_i_mkpf WHERE budat < p_datefr OR
* budat > p_dateto OR
* ( budat = p_datefr AND cputm < p_timefr ) OR
* ( budat = p_dateto AND cputm > p_timeto ).
* IF l_i_mkpf IS INITIAL.
* MESSAGE s042. "No Pallets found for Selection Criteria
* LEAVE LIST-PROCESSING.
* ELSE.
* SORT l_i_mkpf BY mblnr mjahr.
* ENDIF.
  ENDIF.
* Getting shelf life expiry date & BBD date(vfdat) from MSEG
  SELECT mblnr
          mjahr
          matnr
          werks
          charg
          aufnr
          vfdat
    INTO TABLE l_i_mseg
    FROM mseg
    FOR ALL ENTRIES IN l_i_ltak
    WHERE mblnr = l_i_ltak-mblnr
      AND mjahr = l_i_ltak-mjahr.
  IF sy-subrc <> 0.
    MESSAGE s042. "No Pallets found for Selection Criteria
    LEAVE LIST-PROCESSING.
  ELSE.
    SORT l_i_mseg BY mblnr mjahr.
  ENDIF.
* SORT i_ltap BY matnr charg.
  SORT i_ltap BY lgnum tanum.
  LOOP AT i_ltap INTO wa_ltap WHERE NOT nlenr IS INITIAL.
    READ TABLE l_i_lein INTO l_wa_lein
    WITH KEY lenum = wa_ltap-nlenr BINARY SEARCH.
    IF sy-subrc = 0.
      SELECT SINGLE *
      FROM lqua
      WHERE lgnum = l_wa_lein-lgnum AND
******************************************** change DEVCR
      matnr = p_matnr AND
      werks = p_werks AND
      charg = p_charg AND
      lenum = wa_ltap-nlenr.
********************************************** chnage DEVCR
      IF sy-subrc = 0.
        PERFORM get_data.
        wa_repdtl-cur_werks = lqua-werks.
        wa_repdtl-lenum = l_wa_lein-lenum.
        wa_repdtl-act_menge = lqua-gesme.
**********************************************Change DEVCR
        wa_repdtl-meins = wa_ltap-meins.
**********************************************Change DEVCR
        wa_repdtl-letyp = lqua-letyp.
        wa_repdtl-lgort = lqua-lgort.
        wa_repdtl-cur_lgnum = lqua-lgnum.
        wa_repdtl-spgru = lqua-spgru.
        wa_repdtl-bestq = lqua-bestq.
        l_ctr = l_ctr + 1.
        wa_repdtl-ctr = l_ctr .
        APPEND wa_repdtl TO i_repdtl.
        wa_ltap-del_flag = 'X'.
        MODIFY i_ltap FROM wa_ltap TRANSPORTING del_flag.
      ENDIF.
    ENDIF.
  ENDLOOP.
  DELETE i_ltap WHERE del_flag = 'X'.
  SELECT a~mblnr " Material document no.
          a~mjahr " Material document year
          a~lgnum " Warehouse no.
          a~tanum " Transfer order no.
          b~matnr " Material no.
          b~charg
          b~werks
          b~tapos " Transfer order item
          a~bwlvs " Movement type for WM
          a~bwart " Movement type for IM
          a~betyp " Requirement type
          a~benum " Requirement tracking no.
          b~bestq " Stock Category in the WM
          b~vltyp " Source storage type
          b~vlpla " Source storage bin
          b~vlenr " Source storage unit
          b~nltyp " Destination storage type
          b~nlpla " Destination storage bin
          b~nlenr " Destination storage unit
          b~altme
          " Alternative Unit of Measure for Stockkeeping Unit
          b~vsola " Source target quantity in alternate unit
          b~vsolm " Source target quantity in stockkeeping unit
          b~nsola " Destination target quantity in alternative unit
          b~nsolm " Destination target quantity in stockkeeping unit
          b~vbeln
    INTO CORRESPONDING FIELDS OF TABLE i_detl
    FROM ltak AS a INNER JOIN ltap AS b
                      ON a~lgnum = b~lgnum
                    AND a~tanum = b~tanum
    FOR ALL ENTRIES IN i_ltap
    WHERE b~nlenr = i_ltap-nlenr AND
          a~betyp = 'F'.
* a~bwart IN ('601', '641').
  IF sy-subrc = 0.
    SORT i_detl BY tanum.
  ENDIF.
  SELECT matnr
        charg
        werks
        vbeln
    INTO TABLE l_i_lips
    FROM lips
    FOR ALL ENTRIES IN i_detl
    WHERE matnr = i_detl-matnr AND
          charg = i_detl-charg AND
          werks = i_detl-werks.
  IF sy-subrc = 0.
    SORT l_i_lips BY vbeln.
    SELECT vbeln
            kunnr
      INTO TABLE l_i_likp
      FROM likp
      FOR ALL ENTRIES IN l_i_lips
      WHERE vbeln = l_i_lips-vbeln.
    IF sy-subrc = 0.
      SORT l_i_likp BY vbeln.
    ENDIF.
  ENDIF.
  CLEAR: wa_repdtl.
  LOOP AT i_copy_ltap INTO wa_ltap.
    READ TABLE l_i_likp INTO l_wa_likp
    WITH KEY vbeln = wa_ltap-nlpla.
    IF sy-subrc = 0.
      wa_repdtl-kunnr = l_wa_likp-kunnr.
      SELECT SINGLE name1
        INTO wa_repdtl-name1
        FROM kna1
        WHERE kunnr = wa_repdtl-kunnr.
      SELECT SINGLE werks
        INTO wa_repdtl-rec_werks
        FROM t001w
        WHERE kunnr = wa_repdtl-kunnr.
      PERFORM get_data_ltak.
      l_ctr = l_ctr + 1.
      wa_repdtl-ctr = l_ctr .
      APPEND wa_repdtl TO i_repdtl.
      CLEAR: wa_repdtl, i_repdtl.
***********************************************Change DEVCR
      wa_ltap-del_flag = 'X'.
      MODIFY i_copy_ltap FROM wa_ltap TRANSPORTING del_flag.
***********************************************Change DEVCR
    ENDIF.
  ENDLOOP.
  CLEAR: wa_repdtl.
************************************Change DEVCR
  DELETE i_copy_ltap WHERE del_flag = 'X'.
  DELETE i_copy_ltap WHERE nlenr IS INITIAL.
************************************ Change DEVCR
  LOOP AT i_copy_ltap INTO wa_ltap WHERE nlenr IS NOT INITIAL.
* read table i_repdtl into wa_repdtl
* with key lenum = wa_ltap-nlenr binary search.
    LOOP AT i_repdtl INTO wa_repdtl
      WHERE lenum = wa_ltap-nlenr.
      IF sy-subrc NE 0.
        PERFORM get_data.
        l_ctr = l_ctr + 1.
        wa_repdtl-ctr = l_ctr .
        APPEND wa_repdtl TO i_repdtl.
        CLEAR: wa_repdtl, i_repdtl.
        EXIT.
      ELSE.
        EXIT.
      ENDIF.
    ENDLOOP.
  ENDLOOP.
  CLEAR: wa_repdtl, i_repdtl.
** Retriving data from /NESGLB/MCCNN1 & /NESGLB/MCCNN2
  SELECT a~load_no
          a~werks
          a~desp_date
          a~desp_time
          b~matnr
          b~gtin
          b~prod_variant
          b~charg
          b~meins
          b~act_menge
          b~exp_menge
          b~insmk
          b~lenum
          b~letyp
          b~ebeln
          b~ebelp
          b~werk_plant
          b~lgort
          b~qproddat
          b~qprodtime
          b~qplos
          b~item_stat
          b~mblnr
          b~tanum
    INTO TABLE l_i_mccnn1_2
    FROM zmccnn1 AS a INNER JOIN zmccnn2 AS b
                        ON a~lifnr = b~lifnr
                        AND a~load_no = b~load_no
    FOR ALL ENTRIES IN i_ltap
    WHERE b~lenum = i_ltap-nlenr.
  IF sy-subrc = 0.
    SORT l_i_mccnn1_2 BY lenum.
  ENDIF.
  CLEAR: wa_repdtl.
  LOOP AT i_repdtl INTO wa_repdtl.
    READ TABLE l_i_mccnn1_2 INTO l_wa_mccnn1_2
    WITH KEY lenum = wa_repdtl-lenum.
    IF sy-subrc = 0.
      PERFORM get_data.
      wa_repdtl-rec_werks = l_wa_mccnn1_2-werks .
      wa_repdtl-desp_date = l_wa_mccnn1_2-desp_date .
      wa_repdtl-desp_time = l_wa_mccnn1_2-desp_time .
      wa_repdtl-load_no = l_wa_mccnn1_2-load_no .
      wa_repdtl-ebeln = l_wa_mccnn1_2-ebeln .
      wa_repdtl-cur_werks = l_wa_mccnn1_2-werk_plant.
      wa_repdtl-meins = l_wa_mccnn1_2-meins.
      wa_repdtl-act_menge = l_wa_mccnn1_2-exp_menge.
      wa_repdtl-lenum = l_wa_mccnn1_2-lenum.
      wa_repdtl-letyp = l_wa_mccnn1_2-letyp.
      wa_repdtl-lgort = l_wa_mccnn1_2-lgort.
      wa_repdtl-qproddat = l_wa_mccnn1_2-qproddat.
      wa_repdtl-qprodtime = l_wa_mccnn1_2-qprodtime.
      wa_repdtl-qplos = l_wa_mccnn1_2-qplos.
      IF l_wa_mccnn1_2-item_stat = '01'.
        wa_repdtl-in_trn = 'Y'.
        wa_repdtl-cur_lgnum = ' '.
        wa_repdtl-cur_werks = ' '.
        wa_repdtl-lgort = ' '.
      ENDIF.
      MODIFY i_repdtl FROM wa_repdtl.
    ENDIF.
  ENDLOOP.
  LOOP AT i_repdtl INTO wa_repdtl.
    READ TABLE i_copy_ltap INTO wa_ltap
    WITH KEY nlenr = wa_repdtl-lenum BINARY SEARCH.
    IF sy-subrc = 0.
      CASE wa_ltap-bestq.
        WHEN ' '.
          wa_repdtl-text = 'Available'.
        WHEN 'Q'.
          wa_repdtl-text = 'Quality'.
        WHEN 'R'.
          wa_repdtl-text = 'Returns'.
        WHEN 'S'.
          wa_repdtl-text = 'Blocked'.
      ENDCASE.
      IF wa_ltap-bestq = 'S'.
        SELECT SINGLE *
        FROM ltak
        WHERE lgnum = wa_ltap-lgnum AND
        tanum = wa_ltap-tanum AND
        bwart IN ('344', 'Z44').
        IF sy-subrc = 0.
          SELECT SINGLE *
          FROM mseg
          WHERE mblnr = ltak-mblnr AND
          mjahr = ltak-mjahr.
          IF sy-subrc = 0.
            SELECT SINGLE grtxt
            INTO wa_repdtl-spgtx
            FROM t157e
            WHERE spras = 'EN' AND
            bwart IN ('344', 'Z44') AND
            grund = mseg-grund.
            IF sy-subrc = 0.
              wa_repdtl-bestq = wa_ltap-bestq.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDIF.
      MODIFY i_repdtl FROM wa_repdtl TRANSPORTING bestq spgtx text.
      CLEAR: wa_repdtl.
    ENDIF.
  ENDLOOP.
* delete i_repdtl where lenum is initial.
  DELETE i_ltap WHERE del_flag = 'X'.
  IF NOT i_repdtl IS INITIAL.
    SORT i_repdtl BY lenum.
    SORT i_repdtl BY ctr.
  ENDIF.
ENDFORM. " select_data
*&---------------------------------------------------------------------*
*& Form populate_report_header
*&---------------------------------------------------------------------*
* Subroutine to populate report header data.
*----------------------------------------------------------------------*
FORM populate_report_header .
  APPEND wa_rephdr TO i_rephdr.
  CLEAR wa_rephdr.
ENDFORM. " populate_report_header
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'MAIN'.
* exclude fcodes
  PERFORM exclude_fcodes.
  IF container_r IS INITIAL. " has the container been filled?...
* Create object that communicates with the container control...
    CREATE OBJECT container_r
      EXPORTING
        container_name = 'G_CONT'.
* Create object that communicates with the ALV Grid control...
    CREATE OBJECT grid_r
      EXPORTING
        i_parent = container_r.
* Create object that communicates with the event double click in
* ALV Grid control...
    CREATE OBJECT event_reciver.
    SET HANDLER event_reciver->handle_double_click FOR grid_r.
* Call the method that receives the content and structure of itab..
    CALL METHOD grid_r->set_table_for_first_display
      EXPORTING
        it_toolbar_excluding = i_fcode[]
        is_layout            = layout
        i_buffer_active      = space
        i_bypassing_buffer   = 'X'
      CHANGING
        it_outtab            = i_rephdr[]
        it_fieldcatalog      = i_fieldcat_l[].
    CALL METHOD grid_r->set_gridtitle
      EXPORTING
        i_gridtitle = 'Header Data'.
    CALL METHOD grid_r->set_visible
      EXPORTING
        visible = 'X'.
    CALL METHOD grid_r->set_toolbar_interactive.
  ENDIF.
  IF container_r1 IS INITIAL. " has the container been filled?...
* Create object that communicates with the container control...
    CREATE OBJECT container_r1
      EXPORTING
        container_name = 'G_CONT1'.
* Create object that communicates with the ALV Grid control...
    CREATE OBJECT grid_r1
      EXPORTING
        i_parent = container_r1.
* Create object that communicates with the event double click in
* ALV Grid control...
    CREATE OBJECT event_reciver1.
    SET HANDLER event_reciver1->handle_double_click FOR grid_r1.
* Call the method that receives the content and structure of itab..
    CALL METHOD grid_r1->set_table_for_first_display
      EXPORTING
        it_toolbar_excluding = i_fcode[]
        is_layout            = layout2
        i_buffer_active      = space
        i_bypassing_buffer   = 'X'
      CHANGING
        it_outtab            = i_repdtl[]
        it_fieldcatalog      = i_fieldcat_l2[].
    CALL METHOD grid_r1->set_gridtitle
      EXPORTING
        i_gridtitle = 'Detail Data'.
    CALL METHOD grid_r1->set_visible
      EXPORTING
        visible = 'X'.
    CALL METHOD grid_r1->set_toolbar_interactive.
  ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
  CASE okcode.
    WHEN 'BACK'.
      LEAVE TO SCREEN 0.
  ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form EXCLUDE_FCODES
*&---------------------------------------------------------------------*
FORM exclude_fcodes .
  i_fcode = cl_gui_alv_grid=>mc_fc_detail.
  APPEND i_fcode.
  i_fcode = cl_gui_alv_grid=>mc_fc_sort_dsc.
  APPEND i_fcode.
  i_fcode = cl_gui_alv_grid=>mc_mb_sum.
  APPEND i_fcode.
  i_fcode = cl_gui_alv_grid=>mc_fc_subtot.
  APPEND i_fcode.
  i_fcode = cl_gui_alv_grid=>mc_fc_loc_insert_row.
  APPEND i_fcode.
  i_fcode = cl_gui_alv_grid=>mc_fc_graph.
  APPEND i_fcode.
  i_fcode = cl_gui_alv_grid=>mc_fc_view_crystal.
  APPEND i_fcode.
  i_fcode = cl_gui_alv_grid=>mc_fc_loc_undo.
  APPEND i_fcode.
  i_fcode = cl_gui_alv_grid=>mc_fc_info.
  APPEND i_fcode.
  i_fcode = cl_gui_alv_grid=>mc_fc_print.
  APPEND i_fcode.
  i_fcode = cl_gui_alv_grid=>mc_fc_loc_copy.
  APPEND i_fcode.
  i_fcode = cl_gui_alv_grid=>mc_fc_loc_append_row.
  APPEND i_fcode.
  i_fcode = cl_gui_alv_grid=>mc_fc_loc_copy_row.
  APPEND i_fcode.
  i_fcode = cl_gui_alv_grid=>mc_fc_loc_insert_row.
  APPEND i_fcode.
  i_fcode = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
  APPEND i_fcode.
  i_fcode = cl_gui_alv_grid=>mc_fc_print_prev.
  APPEND i_fcode.
  i_fcode = cl_gui_alv_grid=>mc_fc_refresh.
  APPEND i_fcode.
  i_fcode = cl_gui_alv_grid=>mc_fc_loc_cut.
  APPEND i_fcode.
  i_fcode = cl_gui_alv_grid=>mc_fc_view_grid.
  APPEND i_fcode.
  i_fcode = cl_gui_alv_grid=>mc_fc_check.
  APPEND i_fcode.
  i_fcode = cl_gui_alv_grid=>mc_mb_paste.
  APPEND i_fcode.
  i_fcode = cl_gui_alv_grid=>mc_mb_view.
  APPEND i_fcode.
  i_fcode = cl_gui_alv_grid=>mc_fc_loc_delete_row.
  APPEND i_fcode.
ENDFORM. " EXCLUDE_FCODES
*&---------------------------------------------------------------------*
*& Form create_header_fieldcat
*&---------------------------------------------------------------------*
* Subroutine to populate field cat for header
*----------------------------------------------------------------------*
FORM create_header_fieldcat .
  PERFORM populate_feildcat_l USING:
  c_tabname1 c_hcl_pos1 c_fld_werks_plant 'Plant' ,"c_4,
  c_tabname1 c_hcl_pos2 c_fld_matnr 'Material No' ,"c_18,
  c_tabname1 c_hcl_pos3 c_fld_maktx 'Material Desc' ,"c_40,
  c_tabname1 c_hcl_pos4 c_fld_charg 'Batch' ."c_10.
  CLEAR layout.
  layout-zebra = 'X'. " Zebra print
  layout-cwidth_opt = 'X'.
ENDFORM. " create_header_fieldcat
*&---------------------------------------------------------------------*
*& Form create_detail_fieldcat
*&---------------------------------------------------------------------*
* Subroutine to populate field cat for detail
*----------------------------------------------------------------------*
FORM create_detail_fieldcat .
  PERFORM populate_feildcat_l2 USING:
  c_tabname2 c_dcl_pos1 c_fld_ctr 'Counter' ,"c_2,
  c_tabname2 c_dcl_pos2 c_fld_cur_werks 'Current Plant' ,"c_4,
  c_tabname2 c_dcl_pos3 c_fld_lgort 'Storage Loc' ,"c_4,
  c_tabname2 c_dcl_pos4 c_fld_cur_lgnum 'Current Ware' ,"c_3,
  c_tabname2 c_dcl_pos5 c_fld_rec_werks 'Reciving Plant' ,"c_4,
* c_tabname2 c_dcl_pos6 c_fld_im_movt 'IM Movement' ,"c_3,
* c_tabname2 c_dcl_pos7 c_fld_wm_movt 'WM Movement' ,"c_3,
  c_tabname2 c_dcl_pos8 c_fld_in_trn 'In Tran' ,"c_1,
  c_tabname2 c_dcl_pos9 c_fld_kunnr 'Customer No' ,"c_10,
  c_tabname2 c_dcl_pos10 c_fld_kunnr_name1 'Cust Name' ,"c_10,
  c_tabname2 c_dcl_pos11 c_fld_load_no 'Load No' ,"c_35,
  c_tabname2 c_dcl_pos12 c_fld_lenum 'SSCC' ,"c_20,
  c_tabname2 c_dcl_pos13 c_fld_act_menge 'Quantity' ,"c_13,
  c_tabname2 c_dcl_pos14 c_fld_meins 'UOM' ,"c_3,
* c_tabname2 c_dcl_pos15 c_fld_bestq 'Stock Type' ,"c_1,
  c_tabname2 c_dcl_pos15 c_fld_text 'Stock Type' ,"c_15,
  c_tabname2 c_dcl_pos16 c_fld_spgtx 'Blocking Reason' ,"c_20,
  c_tabname2 c_dcl_pos17 c_fld_letyp 'Storage Type' ,"c_3,
  c_tabname2 c_dcl_pos18 c_fld_ebeln 'Purchase Doc' ,"c_10,
  c_tabname2 c_dcl_pos19 c_fld_desp_date 'Despatch Dt' ,"c_8,
  c_tabname2 c_dcl_pos20 c_fld_desp_time 'Despatch Tm' ,"c_15,
  c_tabname2 c_dcl_pos21 c_fld_qproddat 'Production Dt' ,"c_8,
  c_tabname2 c_dcl_pos22 c_fld_qprodtime 'Production Tm' ,"c_15,
  c_tabname2 c_dcl_pos23 c_fld_bbd_vfdat 'Best Before Dt' ,"c_8,
  c_tabname2 c_dcl_pos24 c_fld_sed_vfdat 'ShelfLife ExpDt' ,"c_8,
  c_tabname2 c_dcl_pos25 c_fld_qplos 'Insp Lot No' ."c_12.
  CLEAR layout2.
  layout2-zebra = 'X'. " Zebra print
  layout2-cwidth_opt = 'X'.
ENDFORM. " create_detail_fieldcat
*&---------------------------------------------------------------------*
*& Form populate_feildcat_l
*&---------------------------------------------------------------------*
* SUbroutine to populate field cat for Header
*----------------------------------------------------------------------*
* -->P_REF_TABLE Table Name
* -->P_col_pos col position
* -->P_fieldname field name
* -->P_coltext col text
*----------------------------------------------------------------------*
FORM populate_feildcat_l USING p_ref_table
                                p_col_pos
                                p_fieldname
                                p_coltext.
  i_fieldcat_l-ref_table = p_ref_table.
  i_fieldcat_l-col_pos = p_col_pos.
  i_fieldcat_l-fieldname = p_fieldname.
  i_fieldcat_l-coltext = p_coltext.
  APPEND i_fieldcat_l.
  CLEAR i_fieldcat_l.
ENDFORM. " populate_feildcat_l
*&---------------------------------------------------------------------*
*& Form populate_feildcat_l2
*&---------------------------------------------------------------------*
* SUbroutine to populate field cat for detail
*----------------------------------------------------------------------*
* -->P_REF_TABLE Table Name
* -->P_col_pos col position
* -->P_fieldname field name
* -->P_coltext col text
*----------------------------------------------------------------------*
FORM populate_feildcat_l2 USING p_ref_table
                                p_col_pos
                                p_fieldname
                                p_coltext.
  i_fieldcat_l2-ref_table = p_ref_table.
  i_fieldcat_l2-col_pos = p_col_pos.
  i_fieldcat_l2-fieldname = p_fieldname.
  i_fieldcat_l2-coltext = p_coltext.
  APPEND i_fieldcat_l2.
  CLEAR i_fieldcat_l2.
ENDFORM. " populate_feildcat_l
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
FORM get_data .
  READ TABLE l_i_ltak INTO l_wa_ltak
    WITH KEY lgnum = wa_ltap-lgnum
              tanum = wa_ltap-tanum.
  IF sy-subrc = 0.
    READ TABLE l_i_mkpf INTO l_wa_mkpf
      WITH KEY mblnr = l_wa_ltak-mblnr
                mjahr = l_wa_ltak-mjahr.
    IF sy-subrc = 0.
      wa_repdtl-qproddat = l_wa_mkpf-budat."production date
      wa_repdtl-qprodtime = l_wa_mkpf-cputm."production time
      READ TABLE l_i_mseg INTO l_wa_mseg
        WITH KEY mblnr = l_wa_mkpf-mblnr
                  mjahr = l_wa_mkpf-mjahr
                  matnr = wa_ltap-matnr.
      IF sy-subrc = 0.
        wa_repdtl-bbd_vfdat = l_wa_mseg-vfdat."BBD
        wa_repdtl-sed_vfdat = l_wa_mseg-vfdat."SED
      ENDIF.
      wa_repdtl-im_movt = l_wa_ltak-bwart.
      wa_repdtl-wm_movt = l_wa_ltak-bwlvs.
      wa_repdtl-qplos = wa_ltap-qplos. "Inspection Lot Number
      wa_repdtl-lenum = wa_ltap-nlenr . "SSCC
      wa_repdtl-act_menge = wa_ltap-nista ."Quantity
      wa_repdtl-meins = wa_ltap-meins . "Unit Of Measure
      wa_repdtl-letyp = wa_ltap-nltyp . "storage unit type
    ENDIF.
  ENDIF.
ENDFORM. " GET_DATA
*&---------------------------------------------------------------------*
*& Form layout_build
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_I_LAYOUT text
*----------------------------------------------------------------------*
* This subroutine builds the layout for column optmise and color
* display.
*----------------------------------------------------------------------*
*FORM layout_build USING l_layout TYPE slis_layout_alv.
* DATA : lv_colno TYPE i.
*
* layout-cwidth_opt = 'X'.
* layout-ctab_fname = 'COLOR'.
*
* REFRESH: i_repdtl-color,
* i_col_layout.
*
* LOOP AT i_repdtl.
* IF i_repdtl-shkzg = c_h.
* lv_colno = 6. "color RED
*
* PERFORM sub_set_color USING i_col_layout
* c_field_erfmg "ERFMG
* c_field_erfme "ERFME
* c_field_meins "MEINS
* c_field_menge "MENGE
* lv_colno.
* ELSE.
* lv_colno = 5. "color GREEN
* PERFORM sub_set_color USING i_col_layout
* c_field_erfmg "ERFMG
* c_field_erfme "ERFME
* c_field_meins "MEINS
* c_field_menge "MENGE
* lv_colno.
* ENDIF.
* i_repdtl-color[] = i_col_layout[].
* MODIFY i_repdtl TRANSPORTING color.
* CLEAR: i_col_layout[].
*
* ENDLOOP.
*ENDFORM. " layout_build
*&---------------------------------------------------------------------*
*& Form sub_set_color
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_I_COL_LAYOUT text
* -->P_C_FIELD_ERFMG text
* -->P_C_FIELD_ERFME text
* -->P_C_FIELD_MEINS text
* -->P_C_FIELD_MENGE text
* -->P_LV_COLNO text
*----------------------------------------------------------------------*
*FORM sub_set_color USING ls_color LIKE i_col_layout
* p_fieldname1 type slis_fieldname
* p_fieldname2 type slis_fieldname
* p_fieldname3 type slis_fieldname
* p_fieldname4 type slis_fieldname
* p_colno type i.
*
* DATA: i_lfl_color TYPE slis_specialcol_alv.
*
* CLEAR i_lfl_color.
* i_lfl_color-fieldname = p_fieldname1.
* i_lfl_color-color-col = p_colno.
* i_lfl_color-nokeycol = 'X'.
* APPEND i_lfl_color TO ls_color.
*
* CLEAR i_lfl_color.
* i_lfl_color-fieldname = p_fieldname2.
* i_lfl_color-color-col = p_colno.
* i_lfl_color-nokeycol = 'X'.
* APPEND i_lfl_color TO ls_color.
*
* CLEAR i_lfl_color.
* i_lfl_color-fieldname = p_fieldname3.
* i_lfl_color-color-col = p_colno.
* i_lfl_color-nokeycol = 'X'.
* APPEND i_lfl_color TO ls_color.
*
* CLEAR i_lfl_color.
* i_lfl_color-fieldname = p_fieldname4.
* i_lfl_color-color-col = p_colno.
* i_lfl_color-nokeycol = 'X'.
* APPEND i_lfl_color TO ls_color.
*
*ENDFORM. " SUB_SET_COLOR
*&---------------------------------------------------------------------*
*& Form GET_DATA_LTAK
*&---------------------------------------------------------------------*
FORM get_data_ltak .
  READ TABLE i_copy_ltak INTO l_wa_ltak
    WITH KEY lgnum = wa_ltap-lgnum
              tanum = wa_ltap-tanum.
  IF sy-subrc = 0.
    wa_repdtl-qproddat = wa_ltap-qdatu. "production date
    wa_repdtl-qprodtime = wa_ltap-qzeit. "production time
    wa_repdtl-im_movt = l_wa_ltak-bwart.
    wa_repdtl-wm_movt = l_wa_ltak-bwlvs.
    wa_repdtl-qplos = wa_ltap-qplos. "Inspection Lot Number
    IF wa_ltap-nlenr IS NOT INITIAL.
      wa_repdtl-lenum = wa_ltap-nlenr . "SSCC
    ELSE.
      wa_repdtl-lenum = wa_ltap-vlenr . "SSCC
    ENDIF.
    wa_repdtl-act_menge = wa_ltap-nista ."Quantity
    wa_repdtl-meins = wa_ltap-meins . "Unit Of Measure
    wa_repdtl-letyp = wa_ltap-nltyp . "storage unit type
  ENDIF.
ENDFORM. " GET_DATA_LTAK
 

Call Transaction

REPORT zbdccalltransactionmm01 NO STANDARD PAGE HEADING LINE-SIZE 255.

TABLES:mara.
TYPES:BEGIN OF ty_mara,
      matnr LIKE mara-matnr,
      mbrsh LIKE mara-mbrsh,
      mtart LIKE mara-mtart,
      meins LIKE mara-meins,
      maktx LIKE makt-maktx,
      END OF ty_mara.

DATA: it_mara TYPE ty_mara OCCURS 0 WITH HEADER LINE.

DATA: it_bdcdata TYPE bdcdata OCCURS 0 WITH HEADER LINE      .
DATA:wa_bdcdata TYPE bdcdata .
DATA:file TYPE string.

PARAMETERS: p_file TYPE rlgrap-filename.
file = p_file.

CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    filename            = file
    filetype            = 'ASC'
    has_field_separator = 'X'
  TABLES
    data_tab            = it_mara.

START-OF-SELECTION.

*perform open_group.

  LOOP AT it_mara.

    REFRESH it_bdcdata.
    IF NOT it_mara IS INITIAL.
      PERFORM bdc_dynpro      USING 'SAPLMGMM' '0060'.
      PERFORM bdc_field       USING 'BDC_CURSOR'
                                    'RMMG1-MTART'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '/00'.
      PERFORM bdc_field       USING 'RMMG1-MATNR'
                                    it_mara-matnr.
      PERFORM bdc_field       USING 'RMMG1-MBRSH'
                                    it_mara-mbrsh.
      PERFORM bdc_field       USING 'RMMG1-MTART'
                                    it_mara-mtart.
      PERFORM bdc_dynpro      USING 'SAPLMGMM' '0070'.
      PERFORM bdc_field       USING 'BDC_CURSOR'
                                    'MSICHTAUSW-DYTXT(01)'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=MARK'.
      PERFORM bdc_dynpro      USING 'SAPLMGMM' '0070'.
      PERFORM bdc_field       USING 'BDC_CURSOR'
                                    'MSICHTAUSW-DYTXT(02)'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=MARK'.
      PERFORM bdc_dynpro      USING 'SAPLMGMM' '0070'.
      PERFORM bdc_field       USING 'BDC_CURSOR'
                                    'MSICHTAUSW-DYTXT(03)'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=ENTR'.
      PERFORM bdc_dynpro      USING 'SAPLMGMM' '4004'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '/00'.
      PERFORM bdc_field       USING 'MAKT-MAKTX'
                                    it_mara-maktx.
      PERFORM bdc_field       USING 'BDC_CURSOR'
                                    'MARA-MEINS'.
      PERFORM bdc_field       USING 'MARA-MEINS'
                                    it_mara-meins.
      PERFORM bdc_field       USING 'MARA-MTPOS_MARA'
                                    'NORM'.
      PERFORM bdc_dynpro      USING 'SAPLMGMM' '4004'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '/00'.
      PERFORM bdc_field       USING 'BDC_CURSOR'
                                    'MAKT-MAKTX'.
      PERFORM bdc_field       USING 'MAKT-MAKTX'
                                    'this  test material created by venkat'.
      PERFORM bdc_dynpro      USING 'SAPLSPO1' '0300'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=YES'.
      CALL TRANSACTION 'MM01' USING it_bdcdata
                              MODE 'A'
                              UPDATE 'A'.
    ENDIF.
  ENDLOOP.
*---------------------------------------------------
*        form for bdc dynpro
*---------------------------------------------------
FORM bdc_dynpro USING program
                      dynpro.
  CLEAR it_bdcdata.
  wa_bdcdata-program = program.
  wa_bdcdata-dynpro = dynpro.
  wa_bdcdata-dynbegin = 'X'.
  APPEND wa_bdcdata TO it_bdcdata.

ENDFORM.                    "bdc_dynpro
*---------------------------------------------------
*        form for bdc field
*---------------------------------------------------
FORM bdc_field  USING fnam
                      fval.
  wa_bdcdata-fnam = fnam.
  wa_bdcdata-fval = fval.
  APPEND wa_bdcdata TO it_bdcdata.

ENDFORM.                    "bdc_field
 

Session Method

REPORT zbdcmaterial01 NO STANDARD PAGE HEADING LINE-SIZE 255.

DATA:BEGIN OF itab OCCURS 0,
     matnr LIKE mara-matnr,
     mbrsh LIKE mara-mbrsh,
     mtart LIKE mara-mtart,
     maktx LIKE makt-maktx,
     meins LIKE mara-meins,
     END OF itab .

CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    filename            = 'D:\Documents and Settings\Administrator\Desktop\bdc.txt'
    has_field_separator = 'X'
  TABLES
    data_tab            = itab.

INCLUDE bdcrecx1.

START-OF-SELECTION.

  PERFORM open_group.

  LOOP AT itab.

    PERFORM bdc_dynpro      USING 'SAPLMGMM' '0060'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'RMMG1-MATNR'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '/00'.
    PERFORM bdc_field       USING 'RMMG1-MATNR'
                                  itab-matnr.
    PERFORM bdc_field       USING 'RMMG1-MBRSH'
                                  itab-mbrsh.
    PERFORM bdc_field       USING 'RMMG1-MTART'
                                  itab-mtart.
    PERFORM bdc_dynpro      USING 'SAPLMGMM' '0070'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'MSICHTAUSW-DYTXT(02)'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=ENTR'.
    PERFORM bdc_field       USING 'MSICHTAUSW-KZSEL(01)'
                                  'X'.
    PERFORM bdc_field       USING 'MSICHTAUSW-KZSEL(02)'
                                  'X'.
    PERFORM bdc_dynpro      USING 'SAPLMGMM' '4004'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '/00'.
    PERFORM bdc_field       USING 'MAKT-MAKTX'
                                  itab-maktx .
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'MARA-BISMT'.
    PERFORM bdc_field       USING 'MARA-MEINS'
                                  itab-meins.
    PERFORM bdc_field       USING 'MARA-MTPOS_MARA'
                                  'NORM'.
    PERFORM bdc_dynpro      USING 'SAPLMGMM' '4004'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '/00'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'MAKT-MAKTX'.
    PERFORM bdc_field       USING 'MAKT-MAKTX'
                                  'this is the test material by venkat'.
    PERFORM bdc_dynpro      USING 'SAPLSPO1' '0300'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=YES'.
    PERFORM bdc_transaction USING 'MM01'.
  ENDLOOP.
  PERFORM close_group.
 
TABLES : essr.
***********************************************************************
*Types Declaration
************************************************************************
TYPES: BEGIN OF ty_lblni,
lblni TYPE lblni,
END OF ty_lblni,
BEGIN OF ty_essr,
lblni TYPE lblni,
packno TYPE packno,
ebeln TYPE ebeln,
ebelp TYPE ebelp,
lzvon TYPE lzvon,
lzbis TYPE lzbis,
txz01 TYPE txz01_essr,
wempf TYPE wempf,
ktext1 TYPE sh_text1,
END OF ty_essr,
BEGIN OF ty_esll,
packno TYPE packno,
sub_packno TYPE sub_packno,
introw TYPE numzeile,
menge TYPE mengev,
userf1_txt TYPE userf1_txt,
ktext1 TYPE sh_text1,
wbse TYPE ps_psp_pnr,
material_no TYPE matnr,
matqty_bpo TYPE menge_pos,
scrap__bpo TYPE menge_pos,
unit TYPE meins,
lblni TYPE lblni,
END OF ty_esll,
BEGIN OF ty_esll1,
lblni TYPE lblni,
matqty_bpo TYPE menge_pos,
scrap__bpo TYPE menge_pos,
unit TYPE meins,
END OF ty_esll1,
BEGIN OF ty_ekkn,
ebeln TYPE ebeln,
ebelp TYPE ebelp,
ps_psp_pnr TYPE ps_psp_pnr,
END OF ty_ekkn,
BEGIN OF ty_ekko,
ebeln TYPE ebeln,
lifnr TYPE elifn,
END OF ty_ekko,
BEGIN OF ty_rkpf,
rsnum TYPE rsnum,
ps_psp_pnr TYPE ps_psp_pnr,
wempf TYPE wempf,
bwart TYPE bwart,
END OF ty_rkpf,
BEGIN OF ty_resb,
rsnum TYPE rsnum,
enmng TYPE enmng,
matnr TYPE matnr,
ablad TYPE ablad,
ktext1 TYPE sh_text1,
ps_psp_pnr TYPE ps_psp_pnr,
wempf TYPE wempf,
bwart TYPE bwart,
tkey(2),
treturn(1),
END OF ty_resb,
BEGIN OF ty_ablad,
ablad TYPE ablad,
matnr TYPE matnr,
ps_psp_pnr TYPE ps_psp_pnr,
ktext1 TYPE sh_text1,
enmng TYPE enmng,
END OF ty_ablad,
BEGIN OF ty_wempf,
matnr TYPE matnr,
ps_psp_pnr TYPE ps_psp_pnr,
enmng TYPE enmng,
END OF ty_wempf,
*CHANGES FOR Cash Flow Developmernt dated- 21st,07
BEGIN OF ty_eskl,
packno TYPE packno,
introw TYPE numzeile,
numkn TYPE numkn,
zekkn TYPE eskl_zekkn,
lfpos TYPE lfpos,
menge TYPE menge_pos,
ps_psp_pnr TYPE ps_psp_pnr,
END OF ty_eskl,
BEGIN OF ty_eskn,
packno TYPE packno,
zekkn TYPE dzekkn,
bekkn TYPE bekkn,
ps_psp_pnr TYPE ps_psp_pnr,
END OF ty_eskn,
BEGIN OF ty_resb_cons,
matnr TYPE matnr,
enmng TYPE enmng,
END OF ty_resb_cons.
TYPES: BEGIN OF ty_fim,
eindex TYPE zfim-eindex, "" "" ""
project_no TYPE ps_intnr,
wbse TYPE ps_posnr,
bpo TYPE extnr,
material_no TYPE matnr,
cdate TYPE zfim-cdate, "" "" ""
init TYPE zfim-init, "" "" ""
matqty_bpo TYPE menge_pos,
scrap__bpo TYPE menge_pos,
unit TYPE meins,
aquant_l TYPE menge_pos,
date_l TYPE zfim-date_l,
aquant_h TYPE zfim-aquant_h,
date_h TYPE zfim-date_h,
dflag TYPE zfim-dflag,
menge TYPE menge_pos,
lblni TYPE lblni,
END OF ty_fim.
TYPES: BEGIN OF ty_fim2,
material_no TYPE matnr,
lblni TYPE lblni,
wbse TYPE ps_posnr, " changes done here
matqty_bpo TYPE menge_pos,
scrap__bpo TYPE menge_pos,
unit TYPE meins,
END OF ty_fim2.
TYPES: BEGIN OF ty_recmvt.
        INCLUDE STRUCTURE zrecmvt.
TYPES: END OF ty_recmvt.
TYPES: BEGIN OF ty_final,
lblni TYPE lblni,
txz01 TYPE txz01_essr,
matnr TYPE matnr,
wbse TYPE ps_psp_pnr, "Changes done here
enmng TYPE enmng,
res_unit TYPE meins,
thquan TYPE enmng,
all_scrap TYPE enmng,
fim_unit TYPE meins,
tot_quan TYPE enmng,
diff TYPE enmng,
unit TYPE meins,
END OF ty_final,
BEGIN OF ty_final1,
matnr TYPE matnr,
wbse TYPE ps_psp_pnr,
enmng TYPE enmng,
END OF ty_final1,
BEGIN OF ty_fim1,
wbse TYPE ps_psp_pnr,
material_no TYPE matnr,
matqty_bpo TYPE enmng,
scrap__bpo TYPE enmng,
END OF ty_fim1.......
*************************************************************************
*Internal tables
************************************************************************
DATA: it_resb TYPE TABLE OF ty_resb,
it_eskl TYPE TABLE OF ty_eskl,
it_eskn TYPE TABLE OF ty_eskn,
it_fim2 TYPE TABLE OF ty_fim2,
it_resb_cons TYPE TABLE OF ty_resb_cons,
it_ablad TYPE TABLE OF ty_ablad,
it_wempf TYPE TABLE OF ty_wempf,
it_recmvt TYPE TABLE OF ty_recmvt,
it_rkpf TYPE TABLE OF ty_rkpf,
it_ekko TYPE TABLE OF ty_ekko,
it_ekkn TYPE TABLE OF ty_ekkn,
it_esll_pck TYPE TABLE OF ty_esll,
it_esll TYPE TABLE OF ty_esll,
it_esll2 TYPE TABLE OF ty_esll,
it_esll1 TYPE TABLE OF ty_esll1,
it_fim1 TYPE TABLE OF ty_fim1,
it_essr TYPE TABLE OF ty_essr,
it_lblni TYPE TABLE OF ty_lblni,
it_final TYPE TABLE OF ty_final,
it_final1 TYPE TABLE OF ty_final1,
it_fim TYPE TABLE OF ty_fim,
it_fim_up TYPE TABLE OF ty_fim,
it_fimc TYPE TABLE OF ty_fim,
it_fim_last TYPE TABLE OF ty_fim WITH HEADER LINE.
***********************************************************************
*Work areas
************************************************************************
DATA: wa_resb TYPE ty_resb,
wa_resb_cons TYPE ty_resb_cons,
wa_eskl TYPE ty_eskl,
wa_eskn TYPE ty_eskn,
wa_fim2 TYPE ty_fim2,
wa_ablad TYPE ty_ablad,
wa_wempf TYPE ty_wempf,
wa_recmvt TYPE ty_recmvt,
wa_esll_pck TYPE ty_esll,
wa_rkpf TYPE ty_rkpf,
wa_ekko TYPE ty_ekko,
wa_ekkn TYPE ty_ekkn,
wa_esll TYPE ty_esll,
wa_esll1 TYPE ty_esll1,
wa_esll2 TYPE ty_esll,
wa_essr TYPE ty_essr,
wa_fim TYPE ty_fim,
wa_fim_up TYPE ty_fim,
wa_fimc TYPE ty_fim,
wa_fim1 TYPE ty_fim1,
wa_lblni TYPE ty_lblni,
wa_final TYPE ty_final,
wa_final1 TYPE ty_final1.
************************************************************************
*Constants
************************************************************************
CONSTANTS: c_kste TYPE char4 VALUE 'KSTE',
c_1 TYPE char3 VALUE '001',
c_b TYPE char1 VALUE 'B',
c_m TYPE char1 VALUE 'M',
c_v TYPE char1 VALUE 'V',
c_retfield TYPE dfies-fieldname VALUE 'P_EBELN',
c_openq TYPE help_info-dynprofld VALUE 'LBLNI',
c_s TYPE ddbool_d VALUE 'S'.
CONSTANTS: c_221 TYPE char3 VALUE '221',
c_p TYPE char1 VALUE 'P',
c_x TYPE char1 VALUE 'X',
c_tp TYPE char2 VALUE 'TP',
c_lblni TYPE char5 VALUE 'LBLNI',
c_txz01 TYPE char5 VALUE 'TXZ01',
c_matnr TYPE char5 VALUE 'MATNR',
c_wbse TYPE char4 VALUE 'WBSE',
c_enmng TYPE char5 VALUE 'ENMNG',
c_thquan TYPE char6 VALUE 'THQUAN',
c_all_scrap TYPE char9 VALUE 'ALL_SCRAP',
c_tot_quan TYPE char8 VALUE 'TOT_QUAN',
c_periv TYPE t009b-periv VALUE 'V3',
c_diff TYPE char4 VALUE 'DIFF',
c_meins TYPE char4 VALUE 'UNIT',
c_project_no TYPE char10 VALUE 'PROJECT_NO',
c_lifnr TYPE char5 VALUE 'LIFNR',
c_maktx TYPE char5 VALUE 'MAKTX',
c_ebeln TYPE char5 VALUE 'EBELN',
c_qitv TYPE char4 VALUE 'QITV',
c_uom TYPE char3 VALUE 'UOM',
c_pq TYPE char6 VALUE 'PLAN_Q',
c_fim TYPE char8 VALUE 'FIM_UNIT',
c_res TYPE char8 VALUE 'RES_UNIT',
c_rq TYPE char8 VALUE 'REM_QUAN',
c_qcp TYPE char7 VALUE 'QUAN_CP',
c_unit TYPE char4 VALUE 'UNIT',
c_c TYPE char1 VALUE 'C',
c_i TYPE char1 VALUE 'I',
c_eq TYPE char2 VALUE 'EQ',
c_r TYPE char1 VALUE 'R',
c_l TYPE char1 VALUE 'L'.
***********************************************************************
*ALV INTERNAL TABLE DECLARATION
************************************************************************
DATA : gt_fieldcat TYPE lvc_t_fcat,
gt_fieldcat1 TYPE lvc_t_fcat,
gt_fieldcat3 TYPE lvc_t_fcat,
gd_layout TYPE lvc_s_layo,
gd_layout3 TYPE lvc_s_layo,
gdi_functions TYPE ui_functions,
gd_layout1 TYPE lvc_s_layo..
***********************************************************************
*DATA Declaration
************************************************************************
DATA: wa_toolbar TYPE stb_button,
w_date(2).
*for Modifying the Tool bar
CLASS lcl_event_receiver DEFINITION.
  PUBLIC SECTION.
    METHODS:
    handle_toolbar
    FOR EVENT toolbar OF cl_gui_alv_grid
    IMPORTING e_object e_interactive.
ENDCLASS. "lcl_event_receiver DEFINITION
*************************************************************************
*GRID and Container Declaration and
*Dynamic table declaration
*************************************************************************
DATA: g_container TYPE scrfname VALUE 'COINTAINER1',
g_container1 TYPE scrfname VALUE 'COINTAINER2',
g_container3 TYPE scrfname VALUE 'COINTAINER3',
grid1 TYPE REF TO cl_gui_alv_grid,
event_receiver TYPE REF TO lcl_event_receiver,
grid2 TYPE REF TO cl_gui_alv_grid,
grid3 TYPE REF TO cl_gui_alv_grid,
tool TYPE REF TO cl_gui_alv_grid,
g_custom_container TYPE REF TO cl_gui_custom_container,
g_custom_container1 TYPE REF TO cl_gui_custom_container,
g_custom_container3 TYPE REF TO cl_gui_custom_container...
DATA : gp_table TYPE REF TO data,
gp_table1 TYPE REF TO data,
gp_table3 TYPE REF TO data,
w_fiscal TYPE t009b-bdatj.
*************************************************************************
*FIELD-SYMBOLS
************************************************************************
FIELD-SYMBOLS: <gt_table> TYPE STANDARD TABLE,
<gt_table1> TYPE STANDARD TABLE,
<gt_table3> TYPE STANDARD TABLE..
***********************************************************************
*ALV WORK AREA DECLARATION
************************************************************************
DATA: ls_fieldcat TYPE lvc_s_fcat.
************************************************************************
*Selection Screen Elements
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS : p_ebeln LIKE rm11r-ebeln OBLIGATORY."EKPO-EBELN OBLIGATORY.
SELECT-OPTIONS : s_lblni FOR essr-lblni .
SELECTION-SCREEN END OF BLOCK b1.
************************************************************************
*Selection Screen Elements
************************************************************************
AT SELECTION-SCREEN ON p_ebeln.
*Validation for the Purchase order entered in the selection screen
  PERFORM f_purchase_order.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_lblni-low.
*Validation for the Entry sheet number entered in the selection screen
  PERFORM f_entrysheet_number.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_lblni-high.
*Validation for the Entry sheet number entered in the selection screen
  PERFORM f_entrysheet_number.
************************************************************************
*Start-of-Selection
************************************************************************
START-OF-SELECTION.
*get WBS (Work Breakdown Structure) Element Master Data data
  PERFORM f_actual_quantity.
*Moving the Corresponding Data into the Final Table
  PERFORM f_move_final.
  IF it_final[] IS NOT INITIAL.
* Displaying into the ALV Grid
    PERFORM f_display.
  ELSE.
*If no Data, then Display the error Message
    MESSAGE i015(zps) .
    LEAVE LIST-PROCESSING.
  ENDIF.
**&---------------------------------------------------------------------
*& Form F_WBS_DATA
**&---------------------------------------------------------------------
FORM f_actual_quantity .
  IF p_ebeln IS NOT INITIAL.
*Fetching the ENtry Sheet Data from ESSR TAble As per the Etnry sheet and PO number Entered in Selection SCRN
    SELECT lblni packno ebeln ebelp lzvon lzbis txz01 INTO TABLE it_essr
    FROM essr
    WHERE lblni IN s_lblni
    AND ebeln = p_ebeln.
  ELSE.
* Fetching the ENtry Sheet Data from ESSR TAble As per the Etnry sheet
    SELECT lblni packno ebeln ebelp lzvon lzbis txz01 INTO TABLE it_essr
    FROM essr
    WHERE lblni IN s_lblni.
  ENDIF.
  LOOP AT it_essr INTO wa_essr.
    s_lblni-sign = c_i.
    s_lblni-option = c_eq.
    s_lblni-low = wa_essr-lblni.
    APPEND s_lblni.
  ENDLOOP.
  SELECT packno zekkn
  bekkn ps_psp_pnr
  INTO TABLE it_eskn
  FROM eskn
  WHERE packno IN s_lblni.
  IF sy-subrc = 0.
    LOOP AT it_essr INTO wa_essr.
      wa_essr-wempf = wa_essr-ebeln.
      MODIFY it_essr INDEX sy-tabix FROM wa_essr TRANSPORTING wempf.
    ENDLOOP.
    SORT it_essr BY lblni.
    SELECT packno sub_packno
    INTO TABLE it_esll_pck
    FROM esll
    FOR ALL ENTRIES IN it_essr
    WHERE packno = it_essr-packno.
    IF sy-subrc = 0.
      SORT it_esll_pck BY packno sub_packno.
      SELECT packno sub_packno introw menge userf1_txt ktext1
      INTO TABLE it_esll
      FROM esll
      FOR ALL ENTRIES IN it_esll_pck
      WHERE packno = it_esll_pck-sub_packno.
      IF sy-subrc = 0.
        SORT it_esll BY packno sub_packno.
      ENDIF.
    ENDIF.
    IF it_esll[] IS NOT INITIAL.
      SELECT packno introw numkn
      zekkn lfpos menge
      INTO TABLE it_eskl
      FROM eskl
      FOR ALL ENTRIES IN it_esll
      WHERE packno = it_esll-packno .
    ENDIF.
    PERFORM f_vendor_name.
    LOOP AT it_essr INTO wa_essr.
      READ TABLE it_esll_pck INTO wa_esll_pck WITH KEY packno = wa_essr-packno.
      IF sy-subrc = 0.
        READ TABLE it_esll INTO wa_esll WITH KEY packno = wa_esll_pck-sub_packno.
        IF sy-subrc = 0.
          wa_essr-ktext1 = wa_esll-ktext1.
          MODIFY it_essr FROM wa_essr.
        ENDIF.
      ENDIF.
      PERFORM f_account_assingment .
      PERFORM f_total_quan_cons .
      LOOP AT it_esll INTO wa_esll.
        READ TABLE it_fim INTO wa_fim WITH KEY lblni = wa_esll-lblni.
        IF sy-subrc = 0.
          DELETE it_esll WHERE lblni = wa_esll-lblni.
        ENDIF.
      ENDLOOP.
      REFRESH: it_fim, it_ekkn .
    ENDLOOP.
    it_fim[] = it_fim_up.
*For the Reservation Data
    PERFORM f_get_resb.
  ENDIF.
ENDFORM. " F_WBS_DATA
**&---------------------------------------------------------------------
*& Form F_ACCOUNT_ASSINGMENT
**&---------------------------------------------------------------------
FORM f_account_assingment .
  SELECT ebeln ebelp ps_psp_pnr INTO TABLE it_ekkn
  FROM ekkn
  WHERE ebeln = wa_essr-ebeln
  AND ebelp = wa_essr-ebelp.
  IF sy-subrc = 0.
    SORT it_ekkn BY ebeln ebelp.
  ENDIF.
ENDFORM. " F_ACCOUNT_ASSINGMENT
*&---------------------------------------------------------------------
*& Form F_VENDOR_NAME
*&---------------------------------------------------------------------
FORM f_vendor_name .
  IF it_essr[] IS NOT INITIAL.
    SELECT ebeln lifnr INTO TABLE it_ekko
    FROM ekko
    FOR ALL ENTRIES IN it_essr
    WHERE ebeln = it_essr-ebeln.
    IF sy-subrc = 0.
      SORT it_ekko BY lifnr.
    ENDIF.
  ENDIF.
ENDFORM. " F_VENDOR_NAME
*&---------------------------------------------------------------------
*& Form F_TOTAL_QUAN_CONS
*&---------------------------------------------------------------------
FORM f_total_quan_cons .
  DATA : l_index LIKE sy-tabix.
  DATA : it_esll_m TYPE TABLE OF ty_esll.
  LOOP AT it_esll INTO wa_esll.
    READ TABLE it_esll_pck INTO wa_esll_pck WITH KEY sub_packno = wa_esll-packno.
    IF sy-subrc = 0.
      READ TABLE it_essr INTO wa_essr WITH KEY packno = wa_esll_pck-packno.
      IF sy-subrc = 0.
        LOOP AT it_eskl INTO wa_eskl WHERE packno = wa_esll-packno AND introw = wa_esll-introw .
          l_index = sy-tabix.
          IF sy-subrc = 0.
            READ TABLE it_eskn INTO wa_eskn WITH KEY packno = wa_essr-lblni zekkn = wa_eskl-zekkn.
            IF sy-subrc = 0.
              IF wa_eskn-ps_psp_pnr <> wa_esll-wbse .
                wa_esll-menge = wa_eskl-menge.
                wa_esll-wbse = wa_eskn-ps_psp_pnr .
              ENDIF.
              TRANSLATE wa_esll-userf1_txt TO UPPER CASE.
              IF l_index = 1.
                MODIFY it_esll FROM wa_esll.
              ELSE.
                APPEND wa_esll TO it_esll_m.
              ENDIF.
            ENDIF.
          ENDIF.
        ENDLOOP.
        CLEAR : l_index.
      ENDIF.
    ENDIF.
  ENDLOOP.
  LOOP AT it_esll_m INTO wa_esll.
    APPEND wa_esll TO it_esll.
  ENDLOOP.
  IF it_eskn[] IS NOT INITIAL.
    SELECT project_no
    wbse
    bpo
    material_no
    matqty_bpo
    scrap__bpo
    unit
    INTO TABLE it_fim
    FROM zfim
    FOR ALL ENTRIES IN it_eskn
    WHERE wbse = it_eskn-ps_psp_pnr.
    SELECT eindex
    project_no
    wbse
    bpo
    material_no
    cdate
    init
    matqty_bpo
    scrap__bpo
    unit
    aquant_l
    date_l
    aquant_h
    date_h
    dflag
    INTO TABLE it_fim
    FROM zfim
    FOR ALL ENTRIES IN it_eskn
    WHERE wbse = it_eskn-ps_psp_pnr.
    IF sy-subrc = 0.
      SORT it_fim BY wbse.
    ENDIF.
    LOOP AT it_fim INTO wa_fim.
      READ TABLE it_esll INTO wa_esll WITH KEY userf1_txt = wa_fim-bpo.
      IF sy-subrc <> 0.
        DELETE it_fim WHERE bpo = wa_fim-bpo.
      ENDIF.
    ENDLOOP.
    PERFORM f_consolidate.
  ENDIF.
ENDFORM. " F_TOTAL_QUAN_CONS
*&---------------------------------------------------------------------
*& Form F_MOVE_FINAL
*&---------------------------------------------------------------------
FORM f_move_final .
  DATA: l_menge TYPE menge_pos,
  l_check.
  SORT it_fim BY material_no.
  LOOP AT it_fim2 INTO wa_fim2 .
    wa_final-thquan = wa_fim2-matqty_bpo ."* wa_fim2-MENGE .
    wa_final-all_scrap = wa_fim2-scrap__bpo." * wa_fim2-MENGE .
    wa_final-matnr = wa_fim2-material_no.
    wa_final-lblni = wa_fim2-lblni.
    READ TABLE it_essr INTO wa_essr WITH KEY lblni = wa_final-lblni.
    wa_final-txz01 = wa_essr-txz01.
    wa_final-wbse = wa_fim2-wbse. "Changes Done here
    SELECT SINGLE unit INTO wa_final-fim_unit
    FROM zfim
    WHERE material_no = wa_fim2-material_no.
    SELECT SINGLE meins INTO wa_final-res_unit
    FROM resb
    WHERE matnr = wa_fim2-material_no.
    READ TABLE it_ablad INTO wa_ablad WITH KEY ablad = wa_fim2-lblni
    matnr = wa_fim2-material_no
    ps_psp_pnr = wa_fim2-wbse .
    IF sy-subrc = 0.
      wa_final-enmng = wa_ablad-enmng.
    ENDIF.
    wa_final-tot_quan = wa_final-all_scrap + wa_final-thquan .
    wa_final-diff = wa_final-enmng - wa_final-tot_quan .
    APPEND wa_final TO it_final.
    MOVE-CORRESPONDING wa_final TO wa_final1.
    COLLECT wa_final1 INTO it_final1.
    CLEAR: wa_final, wa_resb, wa_resb_cons, wa_fim2, wa_ekkn, wa_essr, wa_esll_pck ,
    wa_fim2, l_menge, wa_rkpf, wa_ablad, l_check, wa_fim2, wa_final1 . .
  ENDLOOP.
  SORT it_final BY matnr.
  DELETE it_final WHERE matnr IS INITIAL.
ENDFORM. " F_MOVE_FINAL
*&---------------------------------------------------------------------
*& Form F_DISPLAY
*&---------------------------------------------------------------------
FORM f_display .
  PERFORM f_auth_check.
  PERFORM f_fieldcatalog_build.
  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = gt_fieldcat
    IMPORTING
      ep_table        = gp_table.
  ASSIGN gp_table->* TO <gt_table>.
  PERFORM f_fieldcatalog_build1.
  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = gt_fieldcat1
    IMPORTING
      ep_table        = gp_table1.
  ASSIGN gp_table1->* TO <gt_table1>.
  PERFORM f_fieldcatalog_build3.
  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = gt_fieldcat3
    IMPORTING
      ep_table        = gp_table3.
  ASSIGN gp_table3->* TO <gt_table3>.
  PERFORM f_fill_data.
  PERFORM f_fill_data1.
  PERFORM f_fill_data3.
  CALL SCREEN 100.
ENDFORM. " F_DISPLAY
*&---------------------------------------------------------------------
*& Form F_FIELDCATALOG_BUILD
*&---------------------------------------------------------------------
FORM f_fieldcatalog_build .
  ls_fieldcat-fieldname = c_lblni.
  ls_fieldcat-inttype = c_c.
  ls_fieldcat-coltext = text-001.
  ls_fieldcat-outputlen = 20.
  APPEND ls_fieldcat TO gt_fieldcat.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = c_txz01.
  ls_fieldcat-inttype = c_c.
  ls_fieldcat-coltext = text-018.
  ls_fieldcat-outputlen = 20.
  APPEND ls_fieldcat TO gt_fieldcat.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = c_wbse.
  ls_fieldcat-inttype = c_c.
  ls_fieldcat-coltext = text-017.
  ls_fieldcat-outputlen = 20.
  APPEND ls_fieldcat TO gt_fieldcat.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = c_matnr.
  ls_fieldcat-inttype = c_c.
  ls_fieldcat-coltext = text-002.
  ls_fieldcat-outputlen = 20.
  APPEND ls_fieldcat TO gt_fieldcat.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = c_enmng.
  ls_fieldcat-inttype = c_c.
  ls_fieldcat-coltext = text-003.
  ls_fieldcat-outputlen = 20.
  APPEND ls_fieldcat TO gt_fieldcat.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = c_fim.
  ls_fieldcat-inttype = c_c.
  ls_fieldcat-coltext = text-016.
  ls_fieldcat-outputlen = 20.
  APPEND ls_fieldcat TO gt_fieldcat.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = c_thquan.
  ls_fieldcat-coltext = text-004.
  ls_fieldcat-datatype = 'QUAN'.
  ls_fieldcat-decimals_o = 2.
  ls_fieldcat-no_zero = 'X'.
  APPEND ls_fieldcat TO gt_fieldcat.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = c_all_scrap .
  ls_fieldcat-coltext = text-005.
  ls_fieldcat-outputlen = 20.
  ls_fieldcat-datatype = 'QUAN'.
  ls_fieldcat-decimals_o = '2'.
  ls_fieldcat-no_zero = 'X'..
  APPEND ls_fieldcat TO gt_fieldcat.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = c_res .
  ls_fieldcat-inttype = 'C'.
  ls_fieldcat-coltext = text-016.
  ls_fieldcat-outputlen = 20.
  APPEND ls_fieldcat TO gt_fieldcat.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = c_tot_quan .
  ls_fieldcat-coltext = text-006.
  ls_fieldcat-outputlen = 20.
  ls_fieldcat-no_sum = ' '.
  ls_fieldcat-datatype = 'QUAN'.
  ls_fieldcat-no_zero = 'X'.
  APPEND ls_fieldcat TO gt_fieldcat.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = c_diff .
  ls_fieldcat-coltext = text-007.
  ls_fieldcat-outputlen = 20.
  ls_fieldcat-datatype = 'QUAN'.
  ls_fieldcat-no_zero = 'X'.
  ls_fieldcat-decimals_o = '2'.
  APPEND ls_fieldcat TO gt_fieldcat.
  CLEAR ls_fieldcat.
ENDFORM. " F_FIELDCATALOG_BUILD
*&---------------------------------------------------------------------
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------
MODULE status_0100 OUTPUT.
  SET TITLEBAR 'ZFREE'.
  SET PF-STATUS 'ZPF'.
  DATA: obj TYPE REF TO lcl_event_receiver.
  gd_layout-grid_title = sy-title.
  gd_layout-zebra = c_x.
  gd_layout-sel_mode = c_b.
  gd_layout-cwidth_opt = c_x.
  gd_layout3-zebra = c_x.
  gd_layout3-sel_mode = c_b.
  gd_layout3-cwidth_opt = c_x.
  IF g_custom_container1 IS INITIAL.
    CREATE OBJECT g_custom_container1
      EXPORTING
        container_name = g_container1.
    CREATE OBJECT grid2
      EXPORTING
        i_parent = g_custom_container1.
    CREATE OBJECT obj.
    SET HANDLER obj->handle_toolbar FOR grid2.
    CALL METHOD grid2->set_table_for_first_display
      EXPORTING
        is_layout       = gd_layout
      CHANGING
        it_fieldcatalog = gt_fieldcat1
        it_outtab       = <gt_table1>.
  ENDIF.
  IF g_custom_container3 IS INITIAL.
    CREATE OBJECT g_custom_container3
      EXPORTING
        container_name = g_container3.
    CREATE OBJECT grid3
      EXPORTING
        i_parent = g_custom_container3.
    CREATE OBJECT obj.
    SET HANDLER obj->handle_toolbar FOR grid3.
    CALL METHOD grid3->set_table_for_first_display
      EXPORTING
        is_layout       = gd_layout3
      CHANGING
        it_fieldcatalog = gt_fieldcat3
        it_outtab       = <gt_table3>.
  ENDIF.
  IF g_custom_container IS INITIAL.
    CREATE OBJECT g_custom_container
      EXPORTING
        container_name = g_container.
    CREATE OBJECT grid1
      EXPORTING
        i_parent = g_custom_container.
    CREATE OBJECT obj.
    SET HANDLER obj->handle_toolbar FOR grid1.
    CALL METHOD grid1->set_table_for_first_display
      EXPORTING
        is_layout       = gd_layout3
      CHANGING
        it_fieldcatalog = gt_fieldcat
        it_outtab       = <gt_table>.
    SET SCREEN 100.
  ENDIF.
ENDMODULE. "STATUS_0100 OUTPUT
*&---------------------------------------------------------------------
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------
MODULE user_command_0100 INPUT.
  IF sy-ucomm = 'BACK' OR sy-ucomm = 'CANCEL'.
    LEAVE TO SCREEN 0 .
  ELSEIF sy-ucomm = 'CON'.
    IF grid1 IS INITIAL.
      CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
        IMPORTING
          e_grid = grid1.
    ENDIF.
    IF NOT grid1 IS INITIAL.
      CALL METHOD grid1->check_changed_data.
    ENDIF.
  ENDIF.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------
*& Form F_FIELDCATALOG_BUILD1
*&---------------------------------------------------------------------
FORM f_fieldcatalog_build1 .
  CLEAR ls_fieldcat.
  REFRESH gt_fieldcat1.
  ls_fieldcat-fieldname = c_project_no .
  ls_fieldcat-inttype = c_c.
  ls_fieldcat-coltext = text-008.
  ls_fieldcat-outputlen = 20.
  APPEND ls_fieldcat TO gt_fieldcat1.
  ls_fieldcat-fieldname = c_lifnr.
  ls_fieldcat-inttype = c_c.
  ls_fieldcat-coltext = text-009.
  ls_fieldcat-outputlen = 60.
  APPEND ls_fieldcat TO gt_fieldcat1.
  ls_fieldcat-fieldname = c_ebeln.
  ls_fieldcat-inttype = c_c.
  ls_fieldcat-coltext = text-010.
  ls_fieldcat-outputlen = 20.
  APPEND ls_fieldcat TO gt_fieldcat1.
ENDFORM. " F_FIELDCATALOG_BUILD1
*----------------------------------------------------------------------*
*       CLASS LCL_EVENT_RECEIVER IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
  METHOD handle_toolbar.
    DATA: ls_toolbar TYPE stb_button.
    LOOP AT e_object->mt_toolbar INTO ls_toolbar.
      IF ( ls_toolbar-quickinfo = 'Print') OR ( ls_toolbar-quickinfo = 'Display Graphic')
      OR ( ls_toolbar-quickinfo = 'Set Filter...'
      ) OR ( ls_toolbar-quickinfo = 'End User Docu.')
      OR ( ls_toolbar-quickinfo = 'Views').
        ls_toolbar-disabled = 'X'.
        MODIFY e_object->mt_toolbar FROM ls_toolbar.
        CLEAR ls_toolbar.
      ENDIF.
    ENDLOOP.
  ENDMETHOD. "handle_toolbar
ENDCLASS. "lcl_event_receiver IMPLEMENTATION
*&---------------------------------------------------------------------
*& Form F_FILL_DATA
*&---------------------------------------------------------------------
FORM f_fill_data .
  FIELD-SYMBOLS: <ls_table> TYPE any.
  FIELD-SYMBOLS: <l_field> TYPE any.
  DATA: str3 TYPE string.
  SORT it_final BY lblni.
  DELETE it_final WHERE lblni = ''.
  ASSIGN LOCAL COPY OF INITIAL LINE OF <gt_table> TO <ls_table>.
  LOOP AT it_final INTO wa_final.
    ASSIGN COMPONENT 1 OF STRUCTURE <ls_table> TO <l_field>.
    <l_field> = wa_final-lblni .
    ASSIGN COMPONENT 2 OF STRUCTURE <ls_table> TO <l_field>.
    <l_field> = wa_final-txz01 .
    ASSIGN COMPONENT 3 OF STRUCTURE <ls_table> TO <l_field>.
    CALL FUNCTION 'CONVERSION_EXIT_ABPSP_OUTPUT'
      EXPORTING
        input  = wa_final-wbse
      IMPORTING
        output = str3.
    <l_field> = str3.
    ASSIGN COMPONENT 4 OF STRUCTURE <ls_table> TO <l_field>.
    <l_field> = wa_final-matnr.
    ASSIGN COMPONENT 5 OF STRUCTURE <ls_table> TO <l_field>.
    <l_field> = wa_final-enmng.
    ASSIGN COMPONENT 6 OF STRUCTURE <ls_table> TO <l_field>.
    <l_field> = wa_final-res_unit.
    <l_field> = wa_final-fim_unit. "KINJAL
    ASSIGN COMPONENT 7 OF STRUCTURE <ls_table> TO <l_field>.
    str3 = wa_final-thquan.
    CONDENSE str3.
    <l_field> = str3.
    ASSIGN COMPONENT 8 OF STRUCTURE <ls_table> TO <l_field>.
    <l_field> = wa_final-all_scrap.
    ASSIGN COMPONENT 9 OF STRUCTURE <ls_table> TO <l_field>.
    <l_field> = wa_final-fim_unit.
    ASSIGN COMPONENT 10 OF STRUCTURE <ls_table> TO <l_field>.
    <l_field> = wa_final-tot_quan.
    ASSIGN COMPONENT 11 OF STRUCTURE <ls_table> TO <l_field>.
    <l_field> = wa_final-diff.
    APPEND <ls_table> TO <gt_table>.
    CLEAR <ls_table>.
  ENDLOOP.
ENDFORM. " F_FILL_DATA
*&---------------------------------------------------------------------
*& Form F_FILL_DATA1
*&---------------------------------------------------------------------
FORM f_fill_data1 .
  FIELD-SYMBOLS: <ls_table> TYPE any.
  FIELD-SYMBOLS: <l_field> TYPE any.
  DATA: str1 TYPE string,
  str2 TYPE string,
  str3 TYPE string,
  l_name TYPE name1_gp.
  ASSIGN LOCAL COPY OF INITIAL LINE OF <gt_table1> TO <ls_table>.
  READ TABLE it_fim INTO wa_fim INDEX 1.
  IF sy-subrc = 0.
    ASSIGN COMPONENT 1 OF STRUCTURE <ls_table> TO <l_field>.
    CALL FUNCTION 'CONVERSION_EXIT_KONPD_OUTPUT'
      EXPORTING
        input  = wa_fim-project_no
      IMPORTING
        output = str3.
    <l_field> = str3 .
  ENDIF.
  READ TABLE it_ekko INTO wa_ekko INDEX 1.
  SELECT SINGLE name1 INTO l_name
  FROM lfa1
  WHERE lifnr = wa_ekko-lifnr.
  IF sy-subrc = 0.
    str1 = wa_ekko-lifnr.
    CONCATENATE str1 l_name INTO str2 SEPARATED BY ':'.
    ASSIGN COMPONENT 2 OF STRUCTURE <ls_table> TO <l_field>.
    <l_field> = str2.
  ENDIF.
  READ TABLE it_essr INTO wa_essr INDEX 1.
  IF sy-subrc = 0.
    ASSIGN COMPONENT 3 OF STRUCTURE <ls_table> TO <l_field>.
    <l_field> = wa_essr-ebeln.
  ENDIF.
  APPEND <ls_table> TO <gt_table1>.
  CLEAR <ls_table>.
ENDFORM. " F_FILL_DATA1
*&---------------------------------------------------------------------
*& Form F_Purchase_order
*&---------------------------------------------------------------------
FORM f_purchase_order .
  DATA: l_ebeln TYPE ebeln.
  IF p_ebeln IS NOT INITIAL.
    SELECT SINGLE ebeln INTO l_ebeln
    FROM ekpo
    WHERE ebeln = p_ebeln
    AND knttp = c_p.
    IF sy-subrc <> 0.
      MESSAGE e016(zps) .
    ENDIF.
  ENDIF.
ENDFORM. " F_Purchase_order
*&---------------------------------------------------------------------
*& Form F_ENTRYSHEET_NUMBER
*&---------------------------------------------------------------------
FORM f_entrysheet_number .
  DATA: dynfields TYPE TABLE OF dynpread WITH HEADER LINE.
  dynfields-fieldname = 'P_EBELN'.
  APPEND dynfields.
  CALL FUNCTION 'DYNP_VALUES_READ'
    EXPORTING
      dyname               = sy-cprog
      dynumb               = sy-dynnr
      translate_to_upper   = c_x
    TABLES
      dynpfields           = dynfields
    EXCEPTIONS
      invalid_abapworkarea = 1
      invalid_dynprofield  = 2
      invalid_dynproname   = 3
      invalid_dynpronummer = 4
      invalid_request      = 5
      no_fielddescription  = 6
      invalid_parameter    = 7
      undefind_error       = 8
      double_conversion    = 9
      stepl_not_found      = 10
      OTHERS               = 11.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
    READ TABLE dynfields WITH KEY fieldname = 'P_EBELN'.
    p_ebeln = dynfields-fieldvalue.
    IF p_ebeln IS NOT INITIAL.
      SELECT lblni INTO TABLE it_lblni
      FROM essr
      WHERE ebeln = p_ebeln.
      IF it_lblni[] IS NOT INITIAL.
        CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
          EXPORTING
            retfield     = c_retfield
            dynprofield  = c_openq
            dynpprog     = sy-repid
            dynpnr       = sy-dynnr
            value_org    = c_s
            window_title = text-014
          TABLES
            value_tab    = it_lblni.
      ENDIF.
    ENDIF.
  ENDIF.
ENDFORM. " F_ENTRYSHEET_NUMBER
*&---------------------------------------------------------------------
*& Form F_FIELDCATALOG_BUILD3
*&---------------------------------------------------------------------
FORM f_fieldcatalog_build3 .
  CLEAR ls_fieldcat.
  REFRESH gt_fieldcat3.
  ls_fieldcat-fieldname = c_matnr .
  ls_fieldcat-inttype = c_c.
  ls_fieldcat-coltext = text-002.
  ls_fieldcat-outputlen = 20.
  APPEND ls_fieldcat TO gt_fieldcat3.
  ls_fieldcat-fieldname = c_wbse.
  ls_fieldcat-inttype = 'C'.
  ls_fieldcat-coltext = text-017.
  ls_fieldcat-outputlen = 20.
  APPEND ls_fieldcat TO gt_fieldcat3.
  ls_fieldcat-fieldname = c_maktx.
  ls_fieldcat-inttype = c_c.
  ls_fieldcat-coltext = text-011.
  ls_fieldcat-outputlen = 60.
  APPEND ls_fieldcat TO gt_fieldcat3.
  ls_fieldcat-fieldname = c_qitv.
  ls_fieldcat-inttype = 'P'.
  ls_fieldcat-coltext = text-012.
  ls_fieldcat-outputlen = 20.
  ls_fieldcat-datatype = 'DEC'.
  ls_fieldcat-decimals_o = '2'.
  ls_fieldcat-no_zero = 'X'.
  APPEND ls_fieldcat TO gt_fieldcat3.
  ls_fieldcat-fieldname = c_tot_quan.
  ls_fieldcat-inttype = 'P'.
  ls_fieldcat-coltext = text-003.
  ls_fieldcat-outputlen = 20.
  ls_fieldcat-datatype = 'DEC'.
  ls_fieldcat-decimals_o = '2'.
  ls_fieldcat-no_zero = 'X'.
  APPEND ls_fieldcat TO gt_fieldcat3.
  ls_fieldcat-fieldname = c_meins.
  ls_fieldcat-inttype = c_c.
  ls_fieldcat-coltext = text-016.
  ls_fieldcat-outputlen = 20.
  APPEND ls_fieldcat TO gt_fieldcat3.
ENDFORM. " F_FIELDCATALOG_BUILD3
*&---------------------------------------------------------------------
*& Form F_FILL_DATA3
*&---------------------------------------------------------------------
FORM f_fill_data3 .
  FIELD-SYMBOLS: <ls_table> TYPE any.
  FIELD-SYMBOLS: <l_field> TYPE any.
  DATA: l_maktx TYPE maktx,
  str3 TYPE string.
  break aab_kinjal.
  ASSIGN LOCAL COPY OF INITIAL LINE OF <gt_table3> TO <ls_table>.
  LOOP AT it_wempf INTO wa_wempf.
    ASSIGN COMPONENT 4 OF STRUCTURE <ls_table> TO <l_field>.
    <l_field> = wa_wempf-enmng .
*
    SORT it_final BY lblni.
    LOOP AT it_resb INTO wa_resb WHERE matnr = wa_wempf-matnr
    AND ps_psp_pnr = wa_wempf-ps_psp_pnr.
      ASSIGN COMPONENT 2 OF STRUCTURE <ls_table> TO <l_field>.
      CALL FUNCTION 'CONVERSION_EXIT_ABPSP_OUTPUT'
        EXPORTING
          input  = wa_wempf-ps_psp_pnr
        IMPORTING
          output = str3.
      <l_field> = str3.
      READ TABLE it_final1 INTO wa_final1 WITH KEY matnr = wa_resb-matnr
      wbse = wa_resb-ps_psp_pnr ."LBLNI = WA_RESB-ABLAD"KTEXT1 = WA_RESB-KTEXT1..
      IF sy-subrc = 0.
        ASSIGN COMPONENT 5 OF STRUCTURE <ls_table> TO <l_field>.
        <l_field> = wa_final1-enmng .
      ENDIF.
      ASSIGN COMPONENT 1 OF STRUCTURE <ls_table> TO <l_field>.
      <l_field> = wa_resb-matnr .
      SELECT SINGLE maktx INTO l_maktx FROM makt
      WHERE matnr = wa_resb-matnr.
      IF sy-subrc = 0.
        ASSIGN COMPONENT 3 OF STRUCTURE <ls_table> TO <l_field>.
        <l_field> = l_maktx .
      ENDIF.
      ASSIGN COMPONENT 6 OF STRUCTURE <ls_table> TO <l_field>.
      SELECT SINGLE meins INTO <l_field> FROM resb WHERE matnr = wa_resb-matnr.
    ENDLOOP.
    APPEND <ls_table> TO <gt_table3>.
    CLEAR: <ls_table>, wa_resb, wa_wempf, l_maktx, wa_resb_cons .
  ENDLOOP.
ENDFORM. " F_FILL_DATA3
*&---------------------------------------------------------------------
*& Form f_consolidate
*&---------------------------------------------------------------------
FORM f_consolidate .
  DATA: l_menge TYPE menge_pos,
  l_chk,
  l_meneg2 TYPE menge_pos.
  LOOP AT it_fim INTO wa_fim.
    READ TABLE it_esll INTO wa_esll WITH KEY userf1_txt = wa_fim-bpo wbse = wa_fim-wbse."changes done here
    IF sy-subrc = 0.
      READ TABLE it_esll_pck INTO wa_esll_pck WITH KEY sub_packno = wa_esll-packno.
      IF sy-subrc = 0.
        READ TABLE it_essr INTO wa_essr WITH KEY packno = wa_esll_pck-packno .
        IF sy-subrc = 0.
          wa_fim-lblni = wa_essr-lblni.
          MODIFY it_fim FROM wa_fim TRANSPORTING lblni.
        ENDIF.
      ENDIF.
    ENDIF.
    CLEAR: wa_fim, wa_esll_pck, wa_esll.
  ENDLOOP.
*Changes made by kinjal********************
  PERFORM f_actual_quantity_cal.
  LOOP AT it_esll INTO wa_esll.
    READ TABLE it_esll_pck INTO wa_esll_pck WITH KEY sub_packno = wa_esll-packno.
    IF sy-subrc = 0.
      READ TABLE it_essr INTO wa_essr WITH KEY packno = wa_esll_pck-packno.
      IF sy-subrc = 0.
        wa_esll-lblni = wa_essr-lblni.
        MODIFY it_esll FROM wa_esll ."TRANSPORTING LBLNI.
      ENDIF.
    ENDIF.
*
    READ TABLE it_fim INTO wa_fim WITH KEY bpo = wa_esll-userf1_txt wbse = wa_esll-wbse."changes done here
    IF sy-subrc = 0.
      wa_esll-material_no = wa_fim-material_no.
      MODIFY it_esll FROM wa_esll.
    ENDIF.
  ENDLOOP.
  it_fimc[] = it_fim[].
  LOOP AT it_esll INTO wa_esll .
    READ TABLE it_fim INTO wa_fim WITH KEY bpo = wa_esll-userf1_txt lblni = wa_esll-lblni wbse = wa_esll-wbse. "changes done here
    IF sy-subrc <> 0.
    ELSE.
      wa_fim-menge = wa_esll-menge.
      MODIFY it_fim INDEX sy-tabix FROM wa_fim TRANSPORTING menge..
    ENDIF.
  ENDLOOP.
  LOOP AT it_fim INTO wa_fim.
    READ TABLE it_fimc INTO wa_fimc WITH KEY bpo = wa_fim-bpo material_no = wa_fim-material_no wbse = wa_fim-wbse.
    IF sy-subrc = 0.
      wa_fim-matqty_bpo = wa_fimc-matqty_bpo.
      wa_fim-scrap_bpo = wa_fimc-scrap_bpo .
      MODIFY it_fim FROM wa_fim.
      CLEAR wa_fim.
    ENDIF.
  ENDLOOP.
  DATA : l_flag.
  l_flag = 'X'.
  LOOP AT it_fim INTO wa_fim .
    CLEAR: l_chk.
    l_flag = 'X'.
    LOOP AT it_esll INTO wa_esll
        WHERE userf1_txt = wa_fim-bpo AND
              lblni = wa_fim-lblni AND
              wbse = wa_fim-wbse."changes done her
      IF l_flag = 'X'.
        READ TABLE it_fim_last WITH KEY project_no = wa_fim-project_no .
        IF wa_esll-menge <> wa_fim-aquant_l AND wa_fim-init <> 'X'.
          MESSAGE e016(rp) WITH 'Actual Quantity is not maintained properly'.
        ENDIF.
        IF wa_fim-init = ' '.
          l_menge = wa_fim-aquant_h.
          l_meneg2 = wa_fim-scrap__bpo.
        ELSE.
          l_menge = l_menge + wa_esll-menge * wa_fim-matqty_bpo .
          l_meneg2 = l_meneg2 + wa_fim-scrap__bpo * wa_esll-menge.
        ENDIF.
      ENDIF.
      l_flag = ' '.
    ENDLOOP.
    IF wa_fim-init <> 'X'.
      IF l_menge <> wa_fim-aquant_h.
        MESSAGE e016(rp) WITH 'Actual Quantity is not maintained properly'.
      ENDIF.
    ENDIF.
    wa_fim-matqty_bpo = l_menge .
    wa_fim-scrap__bpo = l_meneg2.
    MODIFY it_fim FROM wa_fim.
    MOVE-CORRESPONDING wa_fim TO wa_fim2.
    COLLECT wa_fim2 INTO it_fim2.
    CLEAR: l_menge, l_meneg2.
  ENDLOOP.
  LOOP AT it_fim INTO wa_fim.
    wa_fim_up = wa_fim.
    APPEND wa_fim_up TO it_fim_up .
    CLEAR: wa_fim_up .
  ENDLOOP.
ENDFORM. " f_consolidate
*&---------------------------------------------------------------------
*& Form f_get_resb
*&---------------------------------------------------------------------
FORM f_get_resb .
  SELECT * FROM zrecmvt INTO TABLE it_recmvt.
  IF sy-subrc = 0.
    SORT it_recmvt BY tkey mvt.
  ENDIF.
  IF it_essr[] IS NOT INITIAL.
    SELECT rsnum ps_psp_pnr wempf bwart
    INTO TABLE it_rkpf
    FROM rkpf
    FOR ALL ENTRIES IN it_essr
    WHERE wempf = it_essr-wempf .
    IF sy-subrc = 0.
      SORT it_rkpf BY rsnum.
      LOOP AT it_rkpf INTO wa_rkpf.
        READ TABLE it_recmvt INTO wa_recmvt WITH KEY mvt = wa_rkpf-bwart.
        IF sy-subrc <> 0.
          DELETE it_rkpf WHERE bwart = wa_rkpf-bwart.
        ENDIF.
        CLEAR: wa_recmvt, wa_rkpf.
      ENDLOOP.
      SELECT rsnum enmng matnr ablad
      INTO TABLE it_resb
      FROM resb
      FOR ALL ENTRIES IN it_rkpf
      WHERE rsnum = it_rkpf-rsnum
      AND xloek <> c_x..
      IF sy-subrc = 0.
        DATA: l_enmng TYPE enmng,
        l_tkey(2).
        LOOP AT it_resb INTO wa_resb.
          READ TABLE it_rkpf INTO wa_rkpf WITH KEY rsnum = wa_resb-rsnum.
          IF sy-subrc = 0.
            wa_resb-wempf = wa_rkpf-wempf.
            wa_resb-bwart = wa_rkpf-bwart.
            wa_resb-ps_psp_pnr = wa_rkpf-ps_psp_pnr .
            READ TABLE it_recmvt INTO wa_recmvt WITH KEY mvt = wa_rkpf-bwart.
            IF sy-subrc = 0.
              wa_resb-tkey = wa_recmvt-tkey.
              wa_resb-treturn = wa_recmvt-treturn.
            ENDIF.
          ENDIF.
          READ TABLE it_essr INTO wa_essr WITH KEY lblni = wa_resb-ablad.
          IF sy-subrc = 0.
            wa_resb-ktext1 = wa_essr-ktext1.
          ENDIF.
          MODIFY it_resb FROM wa_resb.
          CLEAR: wa_resb, wa_rkpf, wa_recmvt.", WA_ESSR.
        ENDLOOP.
        LOOP AT it_resb INTO wa_resb .
          IF wa_resb-treturn = c_x.
            l_enmng = wa_resb-enmng * -1.
            wa_resb-enmng = l_enmng.
            MODIFY it_resb FROM wa_resb ."
            CLEAR: wa_resb, l_tkey, l_enmng.
          ENDIF.
        ENDLOOP.
        SORT it_resb BY rsnum.
        SORT it_fim BY material_no.
        LOOP AT it_resb INTO wa_resb.
          READ TABLE it_fim INTO wa_fim WITH KEY material_no = wa_resb-matnr.
          IF sy-subrc <> 0.
            DELETE it_resb WHERE matnr = wa_resb-matnr.
          ENDIF.
        ENDLOOP.
        LOOP AT it_resb INTO wa_resb.
          MOVE-CORRESPONDING wa_resb TO wa_resb_cons.
          COLLECT wa_resb_cons INTO it_resb_cons.
          IF wa_resb-tkey = c_tp.
            MOVE-CORRESPONDING wa_resb TO wa_wempf .
            COLLECT wa_wempf INTO it_wempf.
          ELSE.
            MOVE-CORRESPONDING wa_resb TO wa_ablad.
            COLLECT wa_ablad INTO it_ablad.
          ENDIF.
          CLEAR: wa_wempf, wa_resb, wa_ablad.
        ENDLOOP.
      ENDIF.
    ENDIF.
  ENDIF.
  SORT it_wempf BY matnr ps_psp_pnr .
  DELETE ADJACENT DUPLICATES FROM it_wempf COMPARING matnr ps_psp_pnr .
ENDFORM. " f_get_resb
*&---------------------------------------------------------------------
*& Form F_ACTUAL_QUANTITY_CAL
*&---------------------------------------------------------------------
FORM f_actual_quantity_cal .
  DATA : it_fim_c TYPE TABLE OF ty_fim.
  DATA : it_fim_c1 TYPE TABLE OF ty_fim.
  DATA : wa_fim_c TYPE ty_fim.
  DATA : wa_fim_c1 TYPE ty_fim,
  l_fim TYPE ty_fim,
  l_fim_c TYPE ty_fim,
  l_flag,
  l_flag1,
  l_flag2.
*Declaration to select last index*********************
  DATA : l_eindex TYPE zfim-eindex,
  l_project_no TYPE zfim-project_no,
  l_wbse TYPE zfim-wbse,
  l_bpo TYPE zfim-bpo,
  l_material_no TYPE zfim-material_no,
  l_cdate TYPE zfim-cdate,
  l_init TYPE zfim-init.
  DATA : l_index LIKE sy-tabix.
  DATA : l_date LIKE sy-datum,
  l_matqty_bpo LIKE zfim-matqty_bpo,
  l_scrap_bpo LIKE zfim-scrap_bpo,
  l_scrap_bpo_f LIKE zfim-scrap_bpo,
  l_matqty_bpo2 LIKE zfim-matqty_bpo,
  l_aquant_l LIKE zfim-aquant_l,
  l_aquant_h LIKE zfim-aquant_h.
  DATA : l_fim_last TYPE TABLE OF zfim WITH HEADER LINE.
  SORT it_fim BY project_no wbse bpo material_no cdate date_l.
  it_fim_c[] = it_fim[].
  SORT it_fim_c BY project_no wbse bpo material_no cdate.
  LOOP AT it_essr INTO wa_essr.
    LOOP AT it_fim INTO wa_fim_c WHERE init = ' '
    AND lblni = wa_essr-lblni.
      IF wa_fim_c-cdate <= wa_essr-lzvon.
        DELETE it_fim.
        IF wa_fim_c-cdate > wa_essr-lzbis AND wa_fim_c-cdate <> wa_essr-lzbis.
          DELETE it_fim.
        ENDIF.
*AND CDATE >= WA_ESSR-LZVON.
      ENDLOOP.
    ENDLOOP.
    LOOP AT it_fim INTO wa_fim.
      l_index = sy-tabix.
      READ TABLE it_essr INTO wa_essr WITH KEY lblni = wa_fim-lblni.
      ON CHANGE OF wa_fim-bpo OR wa_fim-material_no.
        READ TABLE it_fim INTO wa_fim_c1 WITH KEY project_no = wa_fim-project_no
        wbse = wa_fim-wbse
        bpo = wa_fim-bpo
        material_no = wa_fim-material_no
        init = ' '.
        IF sy-subrc <> 0.
          APPEND wa_fim TO it_fim_c1.
        ELSE.
          IF wa_fim_c1-cdate <= wa_essr-lzvon.
            wa_fim_c1-init = 'X'.
            APPEND wa_fim_c1 TO it_fim_c1.
            break aab_kinjal.
            l_flag2 = 'X'.
            CONTINUE.
          ENDIF.
          l_flag1 = 'X'.
          LOOP AT it_fim_c INTO wa_fim_c WHERE project_no = wa_fim-project_no
          AND wbse = wa_fim-wbse
          AND bpo = wa_fim-bpo
          AND material_no = wa_fim-material_no
          AND init = ' '
          AND cdate <= wa_essr-lzbis
          AND cdate >= wa_essr-lzvon
          AND dflag = ' '.
            l_fim_c = wa_fim_c.
            IF l_flag1 = 'X'.
              SELECT SINGLE MAX( eindex ) AS eindex
              project_no
              wbse
              bpo
              material_no
              cdate
              init
              INTO (l_eindex , l_project_no , l_wbse , l_bpo , l_material_no , l_cdate , l_init )
              FROM zfim
              WHERE project_no = l_fim_c-project_no
              AND wbse = l_fim_c-wbse
              AND bpo = l_fim_c-bpo
              AND material_no = l_fim_c-material_no
              AND cdate < wa_essr-lzvon
              GROUP BY project_no wbse bpo material_no cdate init.
              IF sy-subrc <> 0.
                SELECT SINGLE MAX( eindex ) AS eindex
                project_no
                wbse
                bpo
                material_no
                cdate
                init
                INTO (l_eindex , l_project_no , l_wbse , l_bpo , l_material_no , l_cdate , l_init )
                FROM zfim
                WHERE project_no = l_fim_c-project_no
                AND wbse = l_fim_c-wbse
                AND bpo = l_fim_c-bpo
                AND material_no = l_fim_c-material_no
                AND init = 'X'
                AND cdate < wa_essr-lzvon
                GROUP BY project_no wbse bpo material_no cdate init.
              ENDIF.
              IF sy-subrc = 0.
                SELECT SINGLE * FROM zfim INTO l_fim_last WHERE eindex = l_eindex
                AND project_no = l_project_no
                AND wbse = l_wbse
                AND bpo = l_bpo
                AND material_no = l_material_no
                AND cdate = l_cdate
                AND init = l_init.
                IF l_fim_last-dflag = 'X'.
                  l_matqty_bpo = 0.
                ELSE.
                  l_matqty_bpo = l_fim_last-matqty_bpo.
                  l_scrap_bpo = l_fim_last-scrap_bpo.
                ENDIF.
              ELSE.
                l_matqty_bpo = 0.
              ENDIF.
              l_aquant_l = l_matqty_bpo * l_fim_c-aquant_l.
              l_scrap_bpo_f = l_scrap_bpo * l_fim_c-aquant_l.
              l_aquant_h = l_fim_c-aquant_l.
              MOVE-CORRESPONDING l_fim_last TO it_fim_last .
              MOVE l_fim_c-lblni TO it_fim_last-lblni.
              APPEND it_fim_last.
              CLEAR l_fim_last.
              CLEAR l_flag1.
            ENDIF.
            l_aquant_l = l_aquant_l + l_fim_c-matqty_bpo * l_fim_c-aquant_h .
            l_scrap_bpo_f = l_scrapbpo_f + l_fim_c-scrap_bpo * l_fim_c-aquant_h.
            l_aquant_h = l_aquant_h + l_fim_c-aquant_h.
          ENDLOOP.
          l_fim_c-scrap_bpo = l_scrap_bpo_f.
          l_fim_c-aquant_h = l_aquant_l.
          l_fim_c-aquant_l = l_aquant_h.
          APPEND l_fim_c TO it_fim_c1.
          break aab_kinjal.
          CLEAR: l_aquant_l , l_aquant_h ,l_matqty_bpo ,l_scrap_bpo_f ,l_scrap_bpo.
          CLEAR l_fim_c.
          IF sy-subrc = 0.
          ELSE.
            l_flag = 'X'.
          ENDIF.
        ENDIF.
        IF l_flag = 'X' AND l_index <> 1.
          APPEND wa_fim TO it_fim_c1.
          break aab_kinjal.
        ENDIF.
      ENDON.
      l_fim = wa_fim.
    ENDLOOP.
    REFRESH it_fim.
    it_fim[] = it_fim_c1[].
  ENDFORM. " F_ACTUAL_QUANTITY_CAL
*&---------------------------------------------------------------------
*& Form F_AUTH_CHECK
*&---------------------------------------------------------------------
FORM f_auth_check .
  AUTHORITY-CHECK OBJECT 'C_PROJ_VNR'
  ID 'PS_VERNR' FIELD 'L_VERNR'
  ID 'PS_ACTVT' FIELD '03'.
  IF sy-subrc <> 0.
    MESSAGE e029(zps) .
  ENDIF.
  AUTHORITY-CHECK OBJECT 'Z_ZPLN_REC'
  ID 'ACTVT' FIELD '03'.
  IF sy-subrc <> 0.
    MESSAGE e029(zps) .
  ENDIF.
ENDFORM. " F_AUTH_CHECK
*GUI Texts
*----------------------------------------------------------
*ZFREE --> Reconciliation Report
*Text elements
*----------------------------------------------------------
*001 Enrtry Sheet Number
*002 Material
*003 Total Qty Consumed
*004 Theoretical Qty
*005 Allowable Scrap
*006 Total Allowable Qty
*007 Difference
*008 Project Definition
*009 Vendor
*010 P.O. Number
*011 Description
*012 Qty Issued to Vendor
*014 Entry Sheet Number
*015 Conversion
*016 Unit
*017 WBSE
*018 Entry Sheet Desc.
*Selection texts
*----------------------------------------------------------
*P_EBELN Purchase Order Number
*S_LBLNI Entry Sheet Number
*Messages
*----------------------------------------------------------
*
*Message class: RP
*016 & & & &
*
*Message class: ZPS
*015 No data to display
*016 PO is not assigned to Project
*029 You are not Authorized to perform this action
 

Author: Sujeet Mishra
Submitted: 16/08/2013
Description: Sample program to use CHANGEDOCUMENT_READ function module to display changes in Material.

REPORT ZMM_MMR_HISTORY NO STANDARD PAGE HEADING
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LINE-SIZE 195 LINE-COUNT 60.
TABLES:
&nbsp; &nbsp; &nbsp; &nbsp; CDHDR, CDPOS, MARA, MAKT, MARD.
FIELD-GROUPS: HEADER.
DATA: BEGIN OF CHGDOC OCCURS 50.
&nbsp; &nbsp; &nbsp; &nbsp; INCLUDE STRUCTURE CDRED.
DATA: END OF CHGDOC.
DATA:
&nbsp; &nbsp; &nbsp; CHGTYPE(1),
&nbsp; &nbsp; &nbsp; PLANT(4),
&nbsp; &nbsp; &nbsp; MATNR1 LIKE CHGDOC-OBJECTID.
SELECT-OPTIONS:
&nbsp; &nbsp; XMATNR &nbsp;FOR CDHDR-OBJECTID, &nbsp; &nbsp;"Material
&nbsp; &nbsp; XUDATE &nbsp;FOR CDHDR-UDATE, &nbsp; &nbsp; &nbsp; "Change Date
&nbsp; &nbsp; XUNAME &nbsp;FOR CDHDR-USERNAME, &nbsp; &nbsp;"User Name
&nbsp; &nbsp; XTCODE &nbsp;FOR CDHDR-TCODE, &nbsp; &nbsp; &nbsp; "Transaction Code
&nbsp; &nbsp; XWERKS &nbsp;FOR MARD-WERKS. &nbsp; &nbsp; &nbsp; &nbsp;"Plants
SELECTION-SCREEN SKIP.
\*Filter change type
SELECTION-SCREEN BEGIN OF BLOCK CHG0 WITH FRAME TITLE TEXT-001.
&nbsp; &nbsp;PARAMETERS : XCHG1 AS CHECKBOX DEFAULT 'X',
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; XCHG2 AS CHECKBOX DEFAULT 'X',
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; XCHG3 AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK CHG0.
START-OF-SELECTION.
INSERT:
&nbsp; &nbsp; &nbsp; &nbsp; CHGDOC-OBJECTID &nbsp; &nbsp; &nbsp; &nbsp;"Material
&nbsp; &nbsp; &nbsp; &nbsp; CHGTYPE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"Change type
&nbsp; &nbsp; &nbsp; &nbsp; PLANT
&nbsp; &nbsp; &nbsp; &nbsp; CHGDOC-CHANGENR
&nbsp; &nbsp; &nbsp; &nbsp; CHGDOC-USERNAME
&nbsp; &nbsp; &nbsp; &nbsp; CHGDOC-UDATE
&nbsp; &nbsp; &nbsp; &nbsp; CHGDOC-TCODE
&nbsp; &nbsp; &nbsp; &nbsp; CHGDOC-TABNAME
&nbsp; &nbsp; &nbsp; &nbsp; CHGDOC-TABKEY
&nbsp; &nbsp; &nbsp; &nbsp; CHGDOC-CHNGIND
&nbsp; &nbsp; &nbsp; &nbsp; CHGDOC-FNAME
&nbsp; &nbsp; &nbsp; &nbsp; CHGDOC-FTEXT
&nbsp; &nbsp; &nbsp; &nbsp; CHGDOC-TEXTART
&nbsp; &nbsp; &nbsp; &nbsp; CHGDOC-OUTLEN
&nbsp; &nbsp; &nbsp; &nbsp; CHGDOC-F_OLD
&nbsp; &nbsp; &nbsp; &nbsp; CHGDOC-F_NEW
INTO HEADER.
SELECT * FROM MARA WHERE MATNR IN XMATNR.
&nbsp; &nbsp;MATNR1 = MARA-MATNR.
&nbsp; &nbsp;CALL FUNCTION 'CHANGEDOCUMENT_READ'
&nbsp; &nbsp; &nbsp;EXPORTING
\* &nbsp; &nbsp; &nbsp; &nbsp; ARCHIVE_HANDLE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 0
\* &nbsp; &nbsp; &nbsp; &nbsp; CHANGENUMBER &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = ' '
\* &nbsp; &nbsp; &nbsp; &nbsp; DATE_OF_CHANGE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = '00000000'
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OBJECTCLASS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 'MATERIAL'
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OBJECTID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = MATNR1
\* &nbsp; &nbsp; &nbsp; &nbsp; TABLEKEY &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = ' '
\* &nbsp; &nbsp; &nbsp; &nbsp; TABLENAME &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= ' '
\* &nbsp; &nbsp; &nbsp; &nbsp; TIME_OF_CHANGE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = '000000'
\* &nbsp; &nbsp; &nbsp; &nbsp; USERNAME &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = ' '
\* &nbsp; &nbsp; &nbsp; &nbsp; LOCAL_TIME &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = ' '
&nbsp; &nbsp; &nbsp;TABLES
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EDITPOS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= CHGDOC
&nbsp; &nbsp; &nbsp;EXCEPTIONS
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NO_POSITION_FOUND &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 1
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WRONG_ACCESS_TO_ARCHIVE &nbsp; &nbsp;= 2
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TIME_ZONE_CONVERSION_ERROR = 3
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OTHERS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 4.
&nbsp; &nbsp;LOOP AT CHGDOC.
&nbsp; &nbsp; &nbsp; CHECK: &nbsp;CHGDOC-UDATE &nbsp; &nbsp;IN XUDATE,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CHGDOC-USERNAME IN XUNAME,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CHGDOC-TCODE &nbsp; &nbsp;IN XTCODE.
\* &nbsp; &nbsp; Chg type: 1. Part revision, 2. Price change, 3. Others
&nbsp; &nbsp; &nbsp; CASE CHGDOC-TCODE.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHEN 'MM01' OR 'MM02' OR 'MM03'. &nbsp;CHGTYPE = '1'.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHEN 'MR21'. &nbsp;CHGTYPE = '2'.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHEN OTHERS. &nbsp;CHGTYPE = '3'.
&nbsp; &nbsp; &nbsp; ENDCASE.
\* &nbsp; &nbsp; Filter chg type
&nbsp; &nbsp; &nbsp; IF ( CHGTYPE = '1' AND XCHG1 <> 'X' ) OR
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;( CHGTYPE = '2' AND XCHG2 <> 'X' ) OR
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;( CHGTYPE = '3' AND XCHG3 <> 'X' ).
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CONTINUE.
&nbsp; &nbsp; &nbsp; ENDIF.
\* &nbsp; &nbsp; Plant is a substring of tabkey
&nbsp; &nbsp; &nbsp; PLANT = CHGDOC-TABKEY+21(4).
&nbsp; &nbsp; &nbsp; IF NOT ( XWERKS IS INITIAL ) AND NOT ( PLANT IS INITIAL ).
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CHECK PLANT IN XWERKS.
&nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp; EXTRACT HEADER.
&nbsp; &nbsp;ENDLOOP.
ENDSELECT.
END-OF-SELECTION.
SORT.
LOOP.
\* &nbsp;Material
&nbsp; &nbsp;AT NEW CHGDOC-OBJECTID.
&nbsp; &nbsp; &nbsp; SELECT SINGLE * FROM MAKT &nbsp;WHERE MATNR = CHGDOC-OBJECTID.
&nbsp; &nbsp; &nbsp; FORMAT INTENSIFIED ON.
&nbsp; &nbsp; &nbsp; SKIP. &nbsp;SKIP.
&nbsp; &nbsp; &nbsp; WRITE:/' \**\* Material:', (18) CHGDOC-OBJECTID, MAKT-MAKTX.
&nbsp; &nbsp;ENDAT.
\* &nbsp;Change type
&nbsp; &nbsp;AT NEW CHGTYPE.
&nbsp; &nbsp; &nbsp; FORMAT INTENSIFIED ON.
&nbsp; &nbsp; &nbsp; SKIP.
&nbsp; &nbsp; &nbsp; CASE CHGTYPE.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHEN '1'. &nbsp; WRITE:/ ' &nbsp;*\* &nbsp;Change type: &nbsp;PARTS REVISION'.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHEN '2'. &nbsp; WRITE:/ ' &nbsp;*\* &nbsp;Change type: &nbsp;PRICE CHANGE'.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHEN '3'. &nbsp; WRITE:/ ' &nbsp;*\* &nbsp;Change type: &nbsp;OTHERS'.
&nbsp; &nbsp; &nbsp; ENDCASE.
&nbsp; &nbsp; &nbsp; SKIP.
&nbsp; &nbsp;ENDAT.
&nbsp; &nbsp;SHIFT CHGDOC-F_OLD LEFT DELETING LEADING SPACE.
&nbsp; &nbsp;SHIFT CHGDOC-F_NEW LEFT DELETING LEADING SPACE.
&nbsp; &nbsp;FORMAT INTENSIFIED OFF.
&nbsp; &nbsp;WRITE:
&nbsp; &nbsp; &nbsp;/ &nbsp; &nbsp; PLANT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;UNDER 'Plant',
&nbsp; &nbsp; &nbsp; (50) CHGDOC-FTEXT &nbsp; UNDER 'Field',
&nbsp; &nbsp; &nbsp; (45) CHGDOC-F_OLD &nbsp; UNDER 'Old value',
&nbsp; &nbsp; &nbsp; (45) CHGDOC-F_NEW &nbsp; UNDER 'New value'.
&nbsp; &nbsp;AT NEW CHGDOC-CHANGENR.
&nbsp; &nbsp; &nbsp; FORMAT INTENSIFIED OFF.
&nbsp; &nbsp; &nbsp; WRITE:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CHGDOC-CHANGENR &nbsp; UNDER 'Change doc',
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CHGDOC-TCODE &nbsp; &nbsp; &nbsp;UNDER 'Tcod',
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CHGDOC-USERNAME &nbsp; UNDER 'User name &nbsp; ',
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CHGDOC-UDATE &nbsp; &nbsp; &nbsp;UNDER 'Date &nbsp; &nbsp;' DD/MM/YY.
&nbsp; &nbsp;ENDAT.
&nbsp; &nbsp;AT END OF CHGDOC-OBJECTID.
&nbsp; &nbsp; &nbsp; SKIP.
&nbsp; &nbsp; &nbsp; ULINE.
&nbsp; &nbsp; &nbsp; SKIP.
&nbsp; &nbsp;ENDAT.
ENDLOOP.
TOP-OF-PAGE.
WRITE: / SY-DATUM, SY-UZEIT,
&nbsp; &nbsp; 50 'ABC PTE LTD',
&nbsp; &nbsp;100 'page', SY-PAGNO,
&nbsp; &nbsp; &nbsp; &nbsp;/ SY-REPID,
&nbsp; &nbsp; 48 'Change Documents Report',
&nbsp; &nbsp;100 SY-UNAME.
SKIP.
ULINE.
WRITE:/3
&nbsp; &nbsp; &nbsp; &nbsp; 'Change doc',
&nbsp; &nbsp; &nbsp; &nbsp; 'Tcod',
&nbsp; &nbsp; &nbsp; &nbsp; 'User name &nbsp; ',
&nbsp; &nbsp; &nbsp; &nbsp; 'Date &nbsp; &nbsp;',
&nbsp; &nbsp; &nbsp; &nbsp; 'Plant',
&nbsp; &nbsp;(50) 'Field',
&nbsp; &nbsp;(45) 'Old value',
&nbsp; &nbsp;(45) 'New value'.
ULINE.

Using BADI_MATERIAL_CHECK we can restrict the material shot text change to particular user and particular material type , please check below code .

BADI Name : BADI_MATERIAL_CHECK
Method Name : CHECK_DATA                     
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
METHOD if_ex_badi_material_check~check_data.
  DATA : ls_makt TYPE makt,
         ls_text TYPE short_desc.
  CHECK sy-tcode EQ 'MM02'.
  IF sy-uname <>  'SMRUTI' AND ( wmara-mtart EQ 'ZSPR' OR wmara-mtart EQ 'ZCON' ).
    SELECT SINGLE *
               FROM makt
               INTO ls_makt
               WHERE matnr EQ wmara-matnr AND
                     spras EQ 'EN'.
    READ TABLE stext INTO ls_text INDEX 1.
    IF sy-subrc EQ 0.
      IF ls_text-maktx <> ls_makt-maktx.
        MESSAGE 'Changes to Material Description is not permitted for the User' TYPE 'W' DISPLAY LIKE 'E'.
        LEAVE TO SCREEN sy-dynnr.
      ENDIF.
    ENDIF.
  ENDIF.
ENDMETHOD.
METHOD if_ex_badi_material_check~check_data.

 

Regard's
Smruti

Refer :  http://scn.sap.com/docs/DOC-45065
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
 FUNCTION YBAPI_MATERIAL_MASTER.
 *"----------------------------------------------------------------------
 *"*"Local Interface:
 *"  IMPORTING
 *"     VALUE(I_MBRSH) LIKE  MARA-MBRSH OPTIONAL
 *"     VALUE(I_MTART) LIKE  MARA-MTART OPTIONAL
 *"     VALUE(I_MATNR) LIKE  MARA-MATNR OPTIONAL
 *"     VALUE(I_MEINS) LIKE  T006A-MSEH3 OPTIONAL
 *"  EXPORTING
 *"     VALUE(E_MATNR) LIKE  BDCDATA-FVAL
 *"     VALUE(E_RETCD) LIKE  BDCDATA-FVAL
 *"     VALUE(E_ERROR) LIKE  BDCDATA-FVAL
 *"  TABLES
 *"      MATERIALDESCRIPTION STRUCTURE  BAPI_MAKT OPTIONAL
 *"----------------------------------------------------------------------

 *TABLES : YNUM_MAT.

 * Clear
   PERFORM CLEAR_STRUCT .
 * Clear
   CLEAR E_MATNR.
   CLEAR E_RETCD.

 * MATERIAL HEADER STRUCTURE
   MOVE I_MBRSH     TO MHEADER-IND_SECTOR.            " Industry
   MOVE I_MTART     TO MHEADER-MATL_TYPE.             " Mat Type
   MOVE  'X'        TO  MHEADER-BASIC_VIEW.           " Basic Data View


 * Uom Conversion Exit
   CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
     EXPORTING
       INPUT          = I_MEINS
     IMPORTING
       OUTPUT         = CUOM
     EXCEPTIONS
       UNIT_NOT_FOUND = 1
       OTHERS         = 2.
 *   CLIENTDATA Structure

   IF CUOM IS NOT INITIAL.
     MOVE CUOM        TO CLIENTDATA-BASE_UOM.     "UoM
     MOVE 'X'         TO CLIENTDATAX-BASE_UOM.     "UoM
   ENDIF.

 * CHECK INTERNAL NUMBER OR EXTERNAL NUMBER FOR MATERIAL.
   IF I_MATNR IS INITIAL.

 * GET INTERNAL NUMBER FOR MATERIAL .

     SELECT SINGLE MATNR INTO I_MATNR FROM YNUM_MAT
       WHERE MTART EQ I_MTART.
     IF SY-SUBRC EQ '0'.                 " SKIP INTERNAL MATERIAL NUMBER RANGE FROM YNUM_MAT
       MOVE I_MATNR TO MHEADER-MATERIAL.
       MOVE I_MATNR TO MAT_NR.
       DELETE FROM YNUM_MAT WHERE
       MATNR EQ I_MATNR AND MTART EQ I_MTART .
       COMMIT WORK AND WAIT .
     ELSE.

       MTYP = I_MTART.
       IND_SEC = I_MBRSH .
       PERFORM GET_INT_NUMBER  TABLES MAT USING MTYP IND_SEC.  " INTERNAL NUMBER RANGE
       READ TABLE MAT INDEX 1.
       MOVE MAT-MATERIAL TO MHEADER-MATERIAL.
       MOVE MAT-MATERIAL TO MAT_NR.
     ENDIF.
   ELSE.

 * GET EXTERNAL NUMBER FOR MATERIAL .

     SELECT SINGLE MATNR INTO MAT_NR FROM YNUM_MAT
     WHERE MTART EQ I_MATNR.
     IF SY-SUBRC EQ '0'.                " IF EXTERNAL NUMBER SAME AS SKIP NUMBER RANGE
       MOVE I_MATNR TO MHEADER-MATERIAL.
       MOVE I_MATNR TO MAT_NR.
       DELETE FROM YNUM_MAT WHERE
       MATNR EQ I_MATNR AND MTART EQ I_MTART .
       COMMIT WORK AND WAIT .
     ELSE.                               " IF EXTERNAL NUMBER NOT SAME AS SKIP NUMBER RANGE
       MOVE I_MATNR TO MHEADER-MATERIAL.
       MOVE I_MATNR TO MAT_NR.
     ENDIF.
   ENDIF.

 *  Short Text
   LOOP AT MATERIALDESCRIPTION.
     MOVE 'EN' TO  S_MAKT-LANGU.     "    MOVE MATERIALDESCRIPTION-LANGU_ISO TO  S_MAKT-LANGU.
     MOVE MATERIALDESCRIPTION-MATL_DESC TO  S_MAKT-MATL_DESC.
     APPEND S_MAKT.
     CLEAR: S_MAKT.
   ENDLOOP.


 * CALL MATERIAL CREATE BAPI
   CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
     EXPORTING
       HEADDATA            = MHEADER
       CLIENTDATA          = CLIENTDATA
       CLIENTDATAX         = CLIENTDATAX
     IMPORTING
       RETURN              = BAPIMSG
     TABLES
       MATERIALDESCRIPTION = S_MAKT.

   IF BAPIMSG-TYPE = 'E'.
     E_MATNR = MAT_NR.
     E_RETCD = '1'.

     ERROR-MATNR = MAT_NR .
     ERROR-MTART = I_MTART .
     ERROR-ERSDA = SY-UNAME.
     ERROR-ERNAM = SY-DATUM .
     ERROR-FLAG  = 'X' .

     APPEND ERROR .
     CONCATENATE E_ERROR BAPIMSG-MESSAGE INTO E_ERROR SEPARATED BY SPACE.
     ROLLBACK WORK.
     INSERT INTO YNUM_MAT VALUES ERROR .
     CLEAR: ERROR .
     EXIT.
   ELSE.
     E_MATNR = MAT_NR.
     E_RETCD = '0'.
     CONCATENATE E_ERROR BAPIMSG-MESSAGE  INTO E_ERROR SEPARATED BY SPACE.
     CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
       EXPORTING
         WAIT = 'X'.
   ENDIF.


 ENDFUNCTION.


***************************************************************************************************************************************************
* TOP INCLUDE CODE *
***************************************************************************************************************************************************
FUNCTION-POOL Z_MM_FUNTOP.             "MESSAGE-ID ..

TABLES: MARA,
        YNUM_MAT.   " Table Information http://scn.sap.com/docs/DOC-45065

* VARIABLES
DATA: MAT_NR(18), I_LANG TYPE SPRAS,
      CUOM(3),
      MTYP LIKE BAPIMATDOA-MATL_TYPE ,
      IND_SEC LIKE BAPIMATDOA-IND_SECTOR.

* STRUCTURES
DATA MHEADER LIKE BAPIMATHEAD.
DATA CLIENTDATA LIKE BAPI_MARA.
DATA CLIENTDATAX LIKE BAPI_MARAX.
DATA MATERIALDESCRIPTIONS LIKE BAPI_MAKT.

DATA: BAPIMSGCL LIKE BAPIRET2  OCCURS 0 WITH HEADER LINE,
      BAPIMSG   LIKE BAPIRET2  OCCURS 0 WITH HEADER LINE,
      BAPIMSGQ  LIKE BAPIRET2  OCCURS 0 WITH HEADER LINE .

DATA RT LIKE BAPIRETURN1.
* TABLES
DATA S_MAKT            LIKE BAPI_MAKT        OCCURS 0 WITH HEADER LINE.
DATA ERROR             LIKE YNUM_MAT         OCCURS 0 WITH HEADER LINE .
DATA MAT               LIKE BAPIMATINR       OCCURS 0 WITH HEADER LINE.
*&-------------------------------------------*
*&      Form  clear_struct
*&------------------------------------------------*
*       text
*---------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*------------------------------------------------*
FORM CLEAR_STRUCT.
  CLEAR: MHEADER,CLIENTDATA,CLIENTDATAX,S_MAKT,CUOM.
    REFRESH:S_MAKT.
ENDFORM.                    " clear_struct
*&---------------------------------------------------------------------*
*&      Form  GET_INT_NUMBER1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_MAT  text
*      -->P_MTYP  text
*      -->P_IND_SEC  text
*----------------------------------------------------------------------*
FORM GET_INT_NUMBER  TABLES     P_MAT STRUCTURE MAT
                               USING  P_MTYP P_IND_SEC.

  CALL FUNCTION 'BAPI_STDMATERIAL_GETINTNUMBER'
    EXPORTING
      MATERIAL_TYPE    = P_MTYP
      INDUSTRY_SECTOR  = P_IND_SEC
      REQUIRED_NUMBERS = 1
    IMPORTING
      RETURN           = RT
    TABLES
      MATERIAL_NUMBER  = P_MAT.

ENDFORM.                    " GET_INT_NUMBER1

Regard's

Smruti Ranjan Mohanty

*Top Include*
*&---------------------------------------------------------------------*
*&  Include           ZDR600_TOP                                       *
*&---------------------------------------------------------------------*
TABLES : mara, marc.
DATA: BEGIN OF i_upload OCCURS 0, "This is similar 2 MM_ALL_VIEWS.xls
      mat(18),   "Material No            
      indsec(1), "Industry Sector     |
      mattype(4),    "Material Type      |
      matdesc(40),    "Material Description        |  Basic Data1
      basuom(3),      "Base Unit of Measure     |
      matgroup(9),    "Material Group    |
      div(2)  ,    "Division        |
      grosswt(13),   "Gross Weight  |
      netwt(13),     "Net Weight    |
      unitwt(13),     "Weight Unit  |
      mindelvqt(13),     "Min Delivering Quantity |
      minordqt(13),      "Min Order Quantity   |
      taxclass(1),     "Tax classification     |Sales Org1
      matstatgrp(1),   "Mat Statistic Group      |Sales Org2
      matprgrp(2),  "Mat Pricing Group        |
      accassgrp(2), "Account assignment Group |
      itmcatgrp(4),  "Item Cat Group          |
      availchk(2),   "Avail check           |Sales General Plant
      transgrp(4),   "Transportation Group |
      loadgrp(4),    "Loading Group         |
      prctr(10),     "Profit Center        |
      salestext(132), "Sales Text /TextID   |
      plant(4),   "Plant      |
      purgrp(3),      "Purchasing Group     |
      batchman(1),      "Batch management      |
      potext(132),    "Pur Order Text / TextID      |
      sloc(4),    "Storage loc      |
      dwerk(4),     "Plant      |
      valclass(4),    "Valuation Class              |
      mavgprc(11),    "Moving Price             |Accounting User Inp
      valcat(1),      "Valuation Category           |
      END OF i_upload.
DATA: wa_upload LIKE i_upload.
DATA: wa_upload1(1000).
DATA: BEGIN OF i_mat OCCURS 0,
      mat(18),
END OF i_mat.
DATA:  p_ux(128).
*------------ Message log
DATA : BEGIN OF i_msglog OCCURS 0,
   string(150),
   END OF i_msglog.
* Data Declaration for BAPI Mat Master change
DATA: s_headdata    LIKE bapimathead.
DATA: s_clientdata  LIKE bapi_mara.
DATA: s_clientdatax LIKE bapi_marax.
DATA: s_plantdata   LIKE bapi_marc.
DATA: s_plantdatax  LIKE bapi_marcx.
DATA: s_sales       LIKE bapi_mvke.
DATA: s_salesx      LIKE bapi_mvkex.
DATA: s_forecast    LIKE bapi_mpop.
DATA: s_forecastx   LIKE bapi_mpopx.
DATA: s_whno        LIKE bapi_mlgn.
DATA: s_whnox       LIKE bapi_mlgnx.
DATA: s_stotyp      LIKE bapi_mlgt.
DATA: s_stotypx     LIKE bapi_mlgtx.
DATA: s_stoloc      LIKE bapi_mard.
DATA: s_stolocx     LIKE bapi_mardx.
DATA: s_valclass    LIKE bapi_mbew.
DATA: s_valclassx   LIKE bapi_mbewx.
DATA: s_return      LIKE bapiret2.
* DATA: I_RETURN LIKE S_RETURN OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF i_return OCCURS 0,
      mat(18),
      plant(4),
      stloc LIKE mard-lgort,
      vkorg LIKE vbak-vkorg,
      vtweg LIKE vbak-vtweg.
        INCLUDE STRUCTURE  bapiret2.
DATA: END OF i_return.
DATA : BEGIN OF i_common OCCURS 0,
     matnr LIKE mara-matnr,
    END OF i_common.
DATA: i_taxclass LIKE bapi_mlan OCCURS 0 WITH HEADER LINE.
DATA: i_uom LIKE bapi_marm OCCURS 0 WITH HEADER LINE.
DATA: i_uomx LIKE bapi_marmx OCCURS 0 WITH HEADER LINE.
DATA: i_matdesc LIKE bapi_makt OCCURS 0 WITH HEADER LINE.
DATA: i_longtext LIKE bapi_mltx OCCURS 0 WITH HEADER LINE.
** Constants
CONSTANTS: c_module(02) VALUE 'MM',
           c_itype      VALUE 'I',
           c_icode(02)  VALUE '01',
           c_flag VALUE 'X',
           c_delim VALUE  'X'.
*Variables
DATA: v_fname1 TYPE ibipparms-path."Filename
 
*Form Include*
*&---------------------------------------------------------------------*
*&  Include           ZDR005C_FORM                                     *
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  f_read_mm_all_views_excel
*&---------------------------------------------------------------------*
*include zbdcrex.form 1002_read_mm_all_views_excel .
DATA : v_subrc LIKE sy-tabix.
PERFORM f_upload_from_pr.
*----- update delivery plant , is user has entered it
LOOP AT i_upload.
*    IF p_dwerk IS NOT INITIAL  .
  i_upload-dwerk = p_werks.
*    ENDIF.
*---- for common material, take existing UOM
  SELECT SINGLE meins INTO mara-meins
    FROM mara
    WHERE matnr EQ i_upload-mat.
  IF sy-subrc EQ 0.
    i_upload-basuom = mara-meins.
    IF mara-meins = 'ST'.
      i_upload-basuom = 'PC'.
    ENDIF.
*      i_upload-matgroup = mara-matkl.
  ENDIF.
  MODIFY i_upload INDEX sy-tabix.
ENDLOOP.
*------ upload common material , if user wants
*  LOOP AT i_upload.
*    v_subrc = sy-tabix.
*    SELECT SINGLE matnr INTO marc-matnr
*      FROM marc
*      WHERE matnr EQ i_upload-mat AND
*            werks EQ 'CAR1'.
*    IF sy-subrc NE 0.
*      MOVE i_upload-mat TO i_common-matnr.
*      APPEND i_common. CLEAR : i_common.
*      DELETE i_upload INDEX v_subrc.
*    ENDIF.
*  ENDLOOP.**------ do not upload common material , if user wants*  LOOP AT i_upload.
*    v_subrc = sy-tabix.
*    SELECT SINGLE matnr INTO marc-matnr
*      FROM marc
*      WHERE matnr EQ i_upload-mat and
*            werks eq 'CAR1'.
*    IF sy-subrc EQ 0.
*       move i_upload-mat to i_common-matnr.
*       append i_common. clear : i_common.
*       delete i_upload index v_subrc.
*    ENDIF.
*  ENDLOOP.
*
*--- if material is already created in PART, do not upload it again*  LOOP AT i_upload.
*    v_subrc = sy-tabix.
*    SELECT SINGLE matnr INTO marc-matnr
*      FROM marc
*      WHERE matnr EQ i_upload-mat AND
*            werks EQ 'PART'.
*    IF sy-subrc EQ 0.
*      DELETE i_upload INDEX v_subrc.
*    ENDIF.
*  ENDLOOP.endform.                    " 1002_read_mm_all_views_excel
*&---------------------------------------------------------------------*
*&      Form  f_process_uploaded_data
*&---------------------------------------------------------------------*
FORM 1003_process_uploaded_data .
*Delete column heading and unnecessary lines-frist 4 lines
*  DELETE i_upload FROM 1 TO 10.
  DELETE i_upload WHERE mat IS INITIAL.
ENDFORM.                    " 1003_process_uploaded_data
*&---------------------------------------------------------------------*
*&      Form  f_prepare_bapi_data
*&---------------------------------------------------------------------*
FORM 1004_prepare_bapi_data .
  LOOP AT i_upload .
    wa_upload = i_upload.
    PERFORM f_initialise_bapi_tables.
    PERFORM f_fill_bapi_headdata.
    PERFORM f_fill_bapi_clientdata.
    PERFORM f_fill_bapi_plantdata.
    PERFORM f_fill_bapi_salesdata.
*    PERFORM f_fill_bapi_forcastdata.
    PERFORM f_fill_bapi_stlocdata.
    PERFORM f_fill_bapi_valclassdata.
    PERFORM f_fill_bapi_taxclassdata.
    PERFORM f_fill_bapi_uomdata.
    PERFORM f_fill_bapi_matdescdata.
    PERFORM f_fill_bapi_longtextdata.
    PERFORM f_call_bapi.
*    PERFORM f_update_gross_wt.
  ENDLOOP.
ENDFORM.                    " 1004_prepare_bapi_data
*&---------------------------------------------------------------------*
*&      Form  f_call_bapi
*&---------------------------------------------------------------------*
FORM f_call_bapi .
  CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
    EXPORTING
      headdata             = s_headdata
      clientdata           = s_clientdata
      clientdatax          = s_clientdatax
      plantdata            = s_plantdata
      plantdatax           = s_plantdatax
      forecastparameters   = s_forecast
      forecastparametersx  = s_forecastx
      storagelocationdata  = s_stoloc
      storagelocationdatax = s_stolocx
      valuationdata        = s_valclass
      valuationdatax       = s_valclassx
      warehousenumberdata  = s_whno
      warehousenumberdatax = s_whnox
      salesdata            = s_sales
      salesdatax           = s_salesx
      storagetypedata      = s_stotyp
      storagetypedatax     = s_stotypx
    IMPORTING
      return               = s_return
    TABLES
      materialdescription  = i_matdesc
      unitsofmeasure       = i_uom
      unitsofmeasurex      = i_uomx
      taxclassifications   = i_taxclass
      materiallongtext     = i_longtext.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
  PERFORM f_populate_result_table.
*------- Update process indicator
*        Perform f_update_process_ind.
ENDFORM.                    " f_call_bapi
*&---------------------------------------------------------------------*
*&      Form  F_WRITE_LOG
*&---------------------------------------------------------------------*
FORM 1005_write_log .
  DATA: l_message(220).
  FORMAT COLOR 1 ON.
  WRITE: / 'Material' ,
           19 'Plant',
           27 'St. Loc',
           35 'Sales Org',
           46 'Distr Chnl',
           58 'Message'.
  FORMAT COLOR OFF.
  LOOP AT i_return.
    CONCATENATE i_return-id '/' i_return-type '/' i_return-number
                '**' i_return-message INTO l_message.
    REPLACE '**' WITH ' ' INTO l_message .
    WRITE: / i_return-mat,
             19 i_return-plant,
             27 i_return-stloc,
             35 i_return-vkorg,
             46 i_return-vtweg,
             58 l_message.
  ENDLOOP.
ENDFORM.                    " 1005_WRITE_LOG
*&---------------------------------------------------------------------*
*&      Form  F_WRITE_LOG_to_file
*&---------------------------------------------------------------------*
FORM f_write_log_to_file .
  REFRESH : i_msglog.
  CLEAR : i_msglog.
*------- msg hdr
  MOVE
    '** Start Processing : Record type 53 - Create material master**'
    TO i_msglog-string.
  APPEND i_msglog.
  MOVE '*' TO i_msglog-string.
  APPEND i_msglog.
*----- collect msg log
  LOOP AT i_return.
    CONCATENATE i_return-type '-' i_return-message INTO
        i_msglog-string.
    APPEND i_msglog.
  ENDLOOP.
*----- footer
  MOVE '*' TO i_msglog-string.
  APPEND i_msglog.
  MOVE
    '** End Processing   : Record type 53 - Create material master**'
    TO i_msglog-string.
  APPEND i_msglog.
  WRITE sy-uline TO i_msglog.
  APPEND i_msglog.
*----- now write log to file
  LOOP AT i_msglog.
    TRANSFER i_msglog-string TO p_ux.
  ENDLOOP.
*------ close msg log
  CLOSE DATASET p_ux.
ENDFORM.                    " F_WRITE_LOG_to_file
*&---------------------------------------------------------------------*
*&      Form  open_msg_log
*&---------------------------------------------------------------------*
FORM open_msg_log .
*------ read path for message log on server
*  SELECT SINGLE message_folder FROM zpainterface_ctl INTO p_ux
*      WHERE  module_name    = c_module AND
*             interface_type = c_itype AND
*             interface_code = c_icode.
*  IF sy-subrc NE 0.
*    CLEAR : p_ux.
*  ENDIF.
*
  CONCATENATE p_ux 'message_log.txt' INTO p_ux.
  OPEN DATASET p_ux FOR APPENDING IN TEXT MODE ENCODING DEFAULT.
ENDFORM.                    " open_msg_log
*&---------------------------------------------------------------------*
*&      Form  f_update_process_ind
*&---------------------------------------------------------------------*
*FORM f_update_process_ind .
*  LOOP AT i_return.
*    IF i_return-type = 'E'.
*      UPDATE zpadata53 SET zprocess_mm = ''
**           where ersda = sy-datum
*             WHERE zprocess_mm NE 'X'
*            AND   matnr_sup = i_return-mat.
*    ELSE.
*      UPDATE zpadata53 SET zprocess_mm = 'X'
**           where ersda = sy-datum
*             WHERE zprocess_mm NE 'X'
*            AND   matnr_sup = i_return-mat.
*
*    ENDIF.
*  ENDLOOP.
*ENDFORM.                    " f_update_process_ind
*&---------------------------------------------------------------------*
*&      Form  f_populate_result_table
*&---------------------------------------------------------------------*
FORM f_populate_result_table .
  i_return-mat = i_upload-mat.
  i_return-plant  = p_werks.
  i_return-stloc  = p_lgort.
  i_return-vkorg  = p_vkorg.
  i_return-vtweg  = p_vtweg.
  MOVE-CORRESPONDING s_return TO i_return.
  APPEND i_return.
  CLEAR: i_return.
ENDFORM.                    " f_populate_result_table
*&---------------------------------------------------------------------*
*&      Form  f_fill_bapi_headdata
*&---------------------------------------------------------------------*
FORM f_fill_bapi_headdata .
  s_headdata-material       = wa_upload-mat.
  s_headdata-ind_sector     = 'M'.
  s_headdata-matl_type      = p_mtart."'CARC'.
  s_headdata-basic_view     = 'X'.
  s_headdata-sales_view     = 'X'.
  s_headdata-purchase_view  = 'X'.
*  s_headdata-mrp_view       = 'X'.
  s_headdata-forecast_view  = 'X'.
  s_headdata-storage_view   = 'X'.
  s_headdata-cost_view      = 'X'.
*  IF NOT p_werks = 'MUMB'.
*    s_headdata-warehouse_view = 'X'.
*  ENDIF.
*
  s_headdata-account_view   = 'X'.
ENDFORM.                    " f_fill_bapi_headdata
*&---------------------------------------------------------------------*
*&      Form  f_fill_bapi_clientdata
*&---------------------------------------------------------------------*
FORM f_fill_bapi_clientdata .
*  PERFORM f_check_uom_from_mara.
  PERFORM f_get_uom.
*  perform f_get_original_mtrlgroup.
  s_clientdatax-base_uom       = 'X'.
  s_clientdatax-matl_group     = 'X'.
  s_clientdatax-division       = 'X'.
*  s_clientdatax-std_descr      = 'X'.
*  s_clientdatax-hazmatprof     = 'X'.
*  s_clientdatax-document  = 'X'.
  s_clientdatax-item_cat       = 'X'.
  s_clientdatax-trans_grp      = 'X'.
  s_clientdatax-unit_of_wt     = 'X'.
  s_clientdatax-net_weight     = 'X'.
*  s_clientdatax-allowed_wt = 'X'.
*  s_clientdatax-pur_valkey     = 'X'.
*  s_clientdatax-minremlife     = 'X'.
*  s_clientdatax-shelf_life     = 'X'.
*  s_clientdatax-extmatlgrp     = 'X'.
*  s_clientdatax-pur_status     = 'X'.
  s_clientdatax-base_uom_iso    = 'X'.
  s_clientdatax-batch_mgmt    = 'X'.
*------ added by vitthal - start
*  s_clientdata-pur_status = wa_upload-xplant.
*----end
  s_clientdata-base_uom      = wa_upload-basuom.
  s_clientdata-base_uom_iso  = wa_upload-basuom.
  s_clientdata-matl_group = wa_upload-matgroup.
*  s_clientdata-matl_group = mara-matkl.
  s_clientdata-division   = wa_upload-div.
*  s_clientdata-std_descr  = wa_upload-indstdesc.
*  s_clientdata-hazmatprof = wa_upload-dgindprof.
*  s_clientdata-document   = wa_upload-document.
  s_clientdata-item_cat   = wa_upload-itmcatgrp.
  s_clientdata-trans_grp  = wa_upload-transgrp.
  s_clientdata-unit_of_wt = wa_upload-unitwt.
  s_clientdata-net_weight = wa_upload-netwt.
  s_clientdata-allowed_wt = wa_upload-grosswt.
*  s_clientdata-pur_valkey = wa_upload-purvalkey.
*  s_clientdata-minremlife = wa_upload-minrslife.
*  s_clientdata-shelf_life = wa_upload-totslife.
*  s_clientdata-extmatlgrp = wa_upload-extmatgp.
  s_clientdata-batch_mgmt = wa_upload-batchman.
ENDFORM.                    " f_fill_bapi_clientdata
*&---------------------------------------------------------------------*
*&      Form  f_fill_bapi_plantdata
*&---------------------------------------------------------------------*
FORM f_fill_bapi_plantdata .
  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
      input  = wa_upload-prctr
    IMPORTING
      output = wa_upload-prctr.
  s_plantdatax-plant      = p_werks.
  s_plantdatax-availcheck = 'X'.
  s_plantdatax-loadinggrp = 'X'.
  s_plantdatax-batch_mgmt = 'X'.
  s_plantdatax-pur_group  = 'X'.
  s_plantdatax-profit_ctr = 'X'.
*  s_plantdatax-gr_pr_time = 'X'.
*  s_plantdatax-ctrl_code  = 'X'.
*  s_plantdatax-abc_id    = 'X'.
*  s_plantdatax-mrp_type   = 'X'.
*  s_plantdatax-reorder_pt = 'X'.
*  s_plantdatax-mrp_ctrler = 'X'.
*  s_plantdatax-lotsizekey = 'X'.
*  s_plantdatax-minlotsize = 'X'.
*  s_plantdatax-proc_type  = 'X'.
*  s_plantdatax-sm_key     = 'X'.
*  s_plantdatax-plnd_delry = 'X'.
*  s_plantdatax-serv_level = 'X'.
*  s_plantdatax-period_ind = 'X'.
*  s_plantdatax-pur_status = 'X'.
*  s_plantdatax-mrp_group  = 'X'.
  s_plantdata-plant      = p_werks ."wa_upload-plant.
*  s_plantdata-plant1      = p_werks ."wa_upload-plant1.
  s_plantdata-availcheck = wa_upload-availchk.
  s_plantdata-loadinggrp = wa_upload-loadgrp.
  s_plantdata-batch_mgmt = wa_upload-batchman.
  s_plantdata-pur_group  = wa_upload-purgrp.
  s_plantdata-profit_ctr  = wa_upload-prctr.
*  s_plantdata-gr_pr_time = wa_upload-grproctim.
*  s_plantdata-ctrl_code  = wa_upload-ctrlcode.
*  s_plantdata-abc_id = wa_upload-abcind.
*  s_plantdata-mrp_type   = wa_upload-mrptyp.
*  s_plantdata-reorder_pt = wa_upload-reordpt.
*  s_plantdata-mrp_ctrler = wa_upload-mrpcont.
*  s_plantdata-lotsizekey = wa_upload-lotsize.
*  s_plantdata-minlotsize = wa_upload-minlotsize.
*  s_plantdata-proc_type  = wa_upload-proctype.
*  s_plantdata-sm_key     = wa_upload-schmarkey.
*  s_plantdata-plnd_delry = wa_upload-pladeltim.
*  s_plantdata-serv_level = wa_upload-servlev.
*  s_plantdata-period_ind = wa_upload-perind.
*  s_plantdata-pur_status = wa_upload-xplant.
*  s_plantdata-mrp_group   = '0000'.
ENDFORM.                    " f_fill_bapi_plantdata
*&---------------------------------------------------------------------*
*&      Form  f_fill_bapi_salesdata
*&---------------------------------------------------------------------*
FORM f_fill_bapi_salesdata .
  s_salesx-sales_org  = p_vkorg."wa_upload-sorg.
  s_salesx-distr_chan = p_vtweg."wa_upload-dc.
  s_salesx-delyg_plnt  = 'X'.
  s_salesx-mat_pr_grp = 'X'.
  s_salesx-matl_stats = 'X'.
  s_salesx-acct_assgt = 'X'.
  s_salesx-item_cat   = 'X'.
  s_salesx-min_order  = 'X'.
  s_salesx-min_dely   = 'X'.
*  s_salesx-matl_grp_1 = 'X'.
*  s_salesx-matl_grp_2 = 'X'.
*  s_salesx-matl_grp_3 = 'X'.
*  s_salesx-matl_grp_4 = 'X'.
*  s_salesx-matl_grp_5 = 'X'.
  s_sales-sales_org  = p_vkorg."wa_upload-sorg.
  s_sales-distr_chan = p_vtweg."wa_upload-dc
*  s_sales-delyg_plnt = wa_upload-dwerk.
  s_sales-mat_pr_grp = wa_upload-matprgrp.
  s_sales-matl_stats = wa_upload-matstatgrp.
  s_sales-acct_assgt = wa_upload-accassgrp.
  s_sales-item_cat   = wa_upload-itmcatgrp.
  s_sales-min_order  = wa_upload-minordqt.
  s_sales-min_dely   = wa_upload-mindelvqt.
*  s_sales-matl_grp_1 = wa_upload-matgrp1.
*  s_sales-matl_grp_2 = wa_upload-matgrp2.
*  s_sales-matl_grp_3 = wa_upload-matgrp3.
*  s_sales-matl_grp_4 = wa_upload-matgrp4.
*  s_sales-matl_grp_5 = wa_upload-matgrp5.
*      s_sales-prod_att_1 = wa_upload-prodatt1.
ENDFORM.                    " f_fill_bapi_salesdata
*&---------------------------------------------------------------------*
*&      Form  f_fill_bapi_forcastdata
*&---------------------------------------------------------------------*
*FORM f_fill_bapi_forcastdata .
*
*  s_forecastx-plant      = p_werks ."wa_upload-plant.
*  s_forecastx-fore_model = 'X'.
*  s_forecastx-hist_vals  = 'X'.
*  s_forecastx-init_pds   = 'X'.
*  s_forecastx-fore_pds   = 'X'.
*  s_forecastx-initialize = 'X'.
*
*
*  s_forecast-plant      = p_werks."wa_upload-plant.
*  s_forecast-fore_model = wa_upload-foremod.
*  s_forecast-hist_vals  = wa_upload-histperd.
*  s_forecast-init_pds   = wa_upload-initperd.
*  s_forecast-fore_pds   = wa_upload-forperd.
*  s_forecast-initialize = wa_upload-init.
*
*ENDFORM.                    " f_fill_bapi_forcastdata
*&---------------------------------------------------------------------*
*&      Form  f_fill_bapi_whdata
*&---------------------------------------------------------------------*
*FORM f_fill_bapi_whdata .
*
*  s_whnox-whse_no    = wa_upload-whno.
*  s_whnox-placement  = 'X'.
*  s_whnox-stgesector = 'X'.
*  s_whnox-withdrawal = 'X'.
*
*
*
*  s_whno-whse_no    = wa_upload-whno.
*  s_whno-placement  = wa_upload-stockplac.
*  s_whno-stgesector = wa_upload-stosec.
*  s_whno-withdrawal = wa_upload-stkremstra.
*
*ENDFORM.                    " f_fill_bapi_whdata
*&---------------------------------------------------------------------*
*&      Form  f_fill_bapi_stlocdata
*&---------------------------------------------------------------------*
FORM f_fill_bapi_stlocdata .
  s_stolocx-plant    = p_werks."wa_upload-plant.
*  s_stolocx-plant1    = p_werks."wa_upload-plant1.
  s_stolocx-stge_loc = p_lgort."wa_upload-sloc.
  s_stolocx-stge_bin = 'X'.
  s_stoloc-plant    = p_werks."wa_upload-plant.
*  s_stoloc-plant1    = p_werks."wa_upload-plant1.
  s_stoloc-stge_loc = p_lgort."wa_upload-sloc.
*  s_stoloc-stge_bin = wa_upload-stobin_i.
ENDFORM.                    " f_fill_bapi_stlocdata
*&---------------------------------------------------------------------*
*&      Form  f_fill_bapi_sttypdata
*&---------------------------------------------------------------------*
*FORM f_fill_bapi_sttypdata .
*
*  s_stotypx-whse_no   = wa_upload-whno.
*  s_stotypx-stge_type = wa_upload-stotype.
*  s_stotypx-stge_bin = 'X'.
*
*
*
*  s_stotyp-whse_no   = wa_upload-whno.
*  s_stotyp-stge_type = wa_upload-stotype.
*  s_stotyp-stge_bin = wa_upload-stobin.
*
*
*
*
*ENDFORM.                    " f_fill_bapi_sttypdata
*&---------------------------------------------------------------------*
*&      Form  f_fill_bapi_valclassdata
*&---------------------------------------------------------------------*
FORM f_fill_bapi_valclassdata .
  s_valclassx-val_area    = p_werks."wa_upload-plant.
  s_valclassx-val_class   = 'X'.
  s_valclassx-price_ctrl  = 'X'.
  s_valclassx-moving_pr   = 'X'.
  s_valclassx-val_cat      = 'X'.
  s_valclass-val_area    = p_werks."wa_upload-plant.
  s_valclass-val_class    = wa_upload-valclass.
  s_valclass-price_ctrl   = 'V'.
  s_valclass-moving_pr    = wa_upload-mavgprc.
  s_valclass-val_cat       = wa_upload-valcat.
ENDFORM.                    " f_fill_bapi_valclassdata
*&---------------------------------------------------------------------*
*&      Form  f_fill_bapi_taxclassdata
*&---------------------------------------------------------------------*
FORM f_fill_bapi_taxclassdata .
  i_taxclass-depcountry = 'AE'.
  i_taxclass-tax_type_1 = 'MWST'.
  i_taxclass-taxclass_1 = wa_upload-taxclass.
  APPEND i_taxclass.
  CLEAR: i_taxclass.
ENDFORM.                    " f_fill_bapi_taxclassdata
*&---------------------------------------------------------------------*
*&      Form  f_fill_bapi_uomdata
*&---------------------------------------------------------------------*
FORM f_fill_bapi_uomdata .
  i_uomx-alt_unit   = wa_upload-basuom.
  i_uomx-gross_wt   = 'X'.
  i_uomx-unit_of_wt = 'X'.
*  i_uomx-alt_unit_iso = 'X'.
*  i_uomx-numerator = 'X'.
*    i_uomx-denominatr = 'X'.
  APPEND i_uomx.
  CLEAR: i_uomx.
  i_uom-alt_unit   = wa_upload-basuom.
  i_uom-alt_unit   = wa_upload-unitwt.
  i_uom-gross_wt   = wa_upload-grosswt.
  i_uom-unit_of_wt = wa_upload-unitwt.
*  i_uom-alt_unit_iso = wa_upload-basuom.
*  i_uom-numerator = '1'.
*    i_uom-denominatr = '1'.
*
  APPEND i_uom.
  CLEAR: i_uom.
ENDFORM.                    " f_fill_bapi_uomdata
*&---------------------------------------------------------------------*
*&      Form  f_fill_bapi_matdescdata
*&---------------------------------------------------------------------*
FORM f_fill_bapi_matdescdata .
  i_matdesc-langu = sy-langu.
  i_matdesc-matl_desc = wa_upload-matdesc.
  APPEND i_matdesc.
  CLEAR: i_matdesc.
ENDFORM.                    " f_fill_bapi_matdescdata
*&---------------------------------------------------------------------*
*&      Form  f_get_filename
*&---------------------------------------------------------------------*
FORM 1000_get_filename .
  CALL FUNCTION 'F4_FILENAME'
    IMPORTING
      file_name = v_fname1.
  p_fname = v_fname1.
ENDFORM.                    " 1000_get_filename
*&---------------------------------------------------------------------*
*&      Form  f_initialise_bapi_tables
*&---------------------------------------------------------------------*
FORM f_initialise_bapi_tables .
  CLEAR : s_headdata,
          s_clientdatax,
          s_clientdata,
          s_plantdatax,
          s_plantdata,
          s_salesx,
          s_sales,
*          s_forecastx,
*          s_forecast,
*          s_whnox,
*          s_whno,
*          s_stolocx,
*          s_stoloc,
*          s_stotypx,
*          s_stotyp,
          i_longtext,
          s_valclassx,
          s_valclass.
  REFRESH: i_taxclass,
           i_matdesc,
          i_longtext,
           i_uom,
           i_uomx.
ENDFORM.                    " f_initialise_bapi_tables
*&---------------------------------------------------------------------*
*&      Form  f_update_gross_wt
*&---------------------------------------------------------------------*
FORM f_update_gross_wt .
  UPDATE mara SET brgew = wa_upload-grosswt WHERE matnr = wa_upload-mat.
  IF sy-subrc EQ 0.
    COMMIT WORK.
  ENDIF.
ENDFORM.                    " f_update_gross_wt
*&---------------------------------------------------------------------*
*&      Form  f_check_uom_from_mara
*&---------------------------------------------------------------------*
FORM f_check_uom_from_mara .
  SELECT SINGLE meins FROM mara INTO mara-meins
                      WHERE matnr = wa_upload-mat.
  IF sy-subrc EQ 0.
    IF mara-meins NE wa_upload-basuom.
      wa_upload-basuom = mara-meins.
    ENDIF.
  ELSE.
    CLEAR mara-meins.
  ENDIF.
ENDFORM.                    " f_check_uom_from_mara
*&---------------------------------------------------------------------*
*&      Form  display_common_mtrl
*&---------------------------------------------------------------------*
FORM display_common_mtrl .
  WRITE : / '**************** Common material *********'.
  LOOP AT i_common.
    WRITE : / i_common-matnr.
  ENDLOOP.
ENDFORM.                    " display_common_mtrl
*&---------------------------------------------------------------------*
*&      Form  f_get_original_mtrlgroup
*&---------------------------------------------------------------------*
FORM f_get_original_mtrlgroup .
  SELECT SINGLE matkl INTO mara-matkl
    FROM mara
    WHERE matnr EQ i_upload-mat.
  IF sy-subrc NE 0.
*    CLEAR : mara-matkl.
*Added by Urvashi on 6/11/03
    mara-matkl = wa_upload-matgroup.
*End Addition 6/11/03
  ENDIF.
*    IF sy-subrc EQ 0.
*      i_upload-basuom = mara-meins.
*      IF mara-meins = 'ST'.
*        i_upload-basuom = 'PC'.
*      ENDIF.
*     i_upload-matgroup = mara-MATKL.
*    ENDIF.
ENDFORM.                    " f_get_original_mtrlgroup
*&---------------------------------------------------------------------*
*&      Form  f_upload_from_pr
*&---------------------------------------------------------------------*
FORM f_upload_from_pr .
  CALL FUNCTION 'WS_UPLOAD'
    EXPORTING
      filename                = p_fname
      filetype                = 'DAT'
    TABLES
      data_tab                = i_upload
    EXCEPTIONS
      conversion_error        = 1
      file_open_error         = 2
      file_read_error         = 3
      invalid_type            = 4
      no_batch                = 5
      unknown_error           = 6
      invalid_table_width     = 7
      gui_refuse_filetransfer = 8
      customer_error          = 9
      no_authority            = 10
      OTHERS                  = 11.
  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.                    " f_upload_from_pr
*&---------------------------------------------------------------------*
*&      Form  f_upload_from_ap
*&---------------------------------------------------------------------*
FORM f_upload_from_ap .
*-------DCLK902489
*  constants : v_filepath like rlgrap-filename
*   value
*    '/usr/sap/MBL/DVEBMGS00/work/PA_INTERFACE/initial_upload/'.
**  '/usr/sap/DCL/DVEBMGS02/work/PA_INTERFACE/initial_upload/'.
*
*  data: v_filepath1 like rlgrap-filename.
*
**  concatenate v_filepath p_fn_ap into v_filepath1.
*
**Open Dataset for reading file data
*  open dataset v_filepath1
*  for input in text mode encoding default.
*
*  if sy-subrc eq 0.
*    do.
*      read dataset v_filepath1 into wa_upload1.
*      if sy-subrc >< 0.
*        exit.
*      else.
*        perform f_split_data.
*      endif.
*    enddo.
*  endif.
*
**Close dataset.
*  close dataset v_filepath1.
*
ENDFORM.                    " f_upload_from_ap
*&---------------------------------------------------------------------*
*&      Form  f_split_data
*&---------------------------------------------------------------------*
FORM f_split_data .
  DATA: v_junk(10).
  SPLIT wa_upload1 AT c_delim INTO
        i_upload-plant
        i_upload-mat
        i_upload-sloc
*        i_upload-sorg
*        i_upload-dc
*        i_upload-whno
*        i_upload-stotype
        i_upload-matdesc
        i_upload-basuom
        i_upload-matgroup
        i_upload-div
*        i_upload-xplant
*        i_upload-indstdesc
*        i_upload-dgindprof
*        i_upload-document
*        i_upload-taxcat
*        i_upload-xdisstat
*        i_upload-validfr
        i_upload-taxclass
        i_upload-dwerk
        i_upload-matprgrp
        i_upload-matstatgrp
        i_upload-accassgrp
*        i_upload-genitmcatgrp
        i_upload-itmcatgrp
        i_upload-mindelvqt
        i_upload-minordqt
*        i_upload-matgrp1
*        i_upload-matgrp2
*        i_upload-matgrp3
*        i_upload-matgrp4
*        i_upload-matgrp5
*        i_upload-extmatgp
        i_upload-availchk
        i_upload-transgrp
        i_upload-grosswt
        i_upload-unitwt
        i_upload-netwt
        i_upload-loadgrp
        i_upload-batchman
        i_upload-salestext
        i_upload-purgrp
        i_upload-prctr
*        i_upload-grproctim
*        i_upload-purvalkey
*        i_upload-ctrlcode
        i_upload-potext
*        i_upload-abcind
*        i_upload-mrptyp
*        i_upload-reordpt
*        i_upload-mrpcont
*        i_upload-lotsize
*        i_upload-minlotsize
*
*        i_upload-proctype
*        i_upload-schmarkey
*        i_upload-pladeltim
*        i_upload-servlev
*
*
*        i_upload-foremod
*        i_upload-histperd
*        i_upload-initperd
*        i_upload-forperd
*        i_upload-init
*        i_upload-perind
*        i_upload-stobin_i
*
*
*        i_upload-minrslife
*        i_upload-totslife
*        i_upload-pindsled
*
*        i_upload-stkremstra
*        i_upload-stockplac
*        i_upload-stosec
*        i_upload-stobin
        i_upload-valcat
        i_upload-valclass
*        i_upload-prctrl
        i_upload-mavgprc
        v_junk.
  REPLACE ALL OCCURRENCES OF c_delim IN i_upload-mavgprc WITH 'E'.
  IF i_upload-mavgprc(1) = 'E'.
    CLEAR i_upload-mavgprc.
  ENDIF.
  APPEND i_upload.
  CLEAR i_upload.
ENDFORM.                    " f_split_data
*&---------------------------------------------------------------------
*&      Form  f_get_uom
*&---------------------------------------------------------------------
FORM f_get_uom .
  CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
    EXPORTING
      input          = wa_upload-basuom
      language       = sy-langu
    IMPORTING
      output         = wa_upload-basuom
    EXCEPTIONS
      unit_not_found = 1
      OTHERS         = 2.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
ENDFORM.                    " f_get_uom
*&---------------------------------------------------------------------*
*&      Form  f_fill_bapi_longtextdata
*&---------------------------------------------------------------------*
FORM f_fill_bapi_longtextdata .
  DATA: BEGIN OF v_obj_key ,
      matnr LIKE mara-matnr,
      vkorg LIKE rmmg1-vkorg,
      vtweg LIKE rmmg1-vtweg,
  END OF v_obj_key.
  v_obj_key-matnr = wa_upload-mat.
  v_obj_key-vkorg = p_vkorg.
  v_obj_key-vtweg = p_vtweg.
*-------- Sales text
  i_longtext-text_name = v_obj_key.
  i_longtext-applobject = 'MVKE'.
  i_longtext-text_id   = '0001'.
  i_longtext-langu = 'EN'.
  i_longtext-text_line = wa_upload-salestext.
  APPEND i_longtext.
  CLEAR i_longtext.
*-------- Purchase text
  i_longtext-text_name = wa_upload-mat.
  i_longtext-text_id   = 'BEST'.
  i_longtext-applobject = 'MATERIAL'.
  i_longtext-langu = 'EN'.
  i_longtext-text_line = wa_upload-potext.
  APPEND i_longtext.
  CLEAR i_longtext.
ENDFORM.                    " f_fill_bapi_longtextdata
 
*Main Program
*   REPORT  zdr600 NO STANDARD PAGE HEADING LINE-SIZE 200.
INCLUDE zdr600_top.
*------------Selection Parameters
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-t01.
PARAMETERS: p_fname LIKE rlgrap-filename.
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-t02.
PARAMETERS:  p_werks LIKE marc-werks OBLIGATORY,
             p_lgort LIKE mard-lgort OBLIGATORY,
             p_vkorg LIKE vbak-vkorg OBLIGATORY,
"Sales Org
             p_vtweg LIKE vbak-vtweg OBLIGATORY,
             p_mtart LIKE mara-mtart OBLIGATORY,
             p_kokrs LIKE tka01-kokrs OBLIGATORY DEFAULT 'LNMM'
                 MEMORY ID cac.
"Channel
SELECTION-SCREEN END OF BLOCK b1.
*--------Selection Screen validations
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.
*--------------Drill Down(F4) Filename
  PERFORM 1000_get_filename.
*-------------Program Logic Begins
START-OF-SELECTION.
*------ main logic : start
  PERFORM 1002_read_mm_all_views_excel.
  PERFORM 1003_process_uploaded_data.
  PERFORM 1004_prepare_bapi_data.
*  Perform open_msg_log.
*  PERFORM F_WRITE_LOG_to_file.
*  Perform f_update_process_ind.
  PERFORM 1005_write_log.
*  Perform display_common_mtrl.
*------ main logic : end
END-OF-SELECTION.
  INCLUDE zdr600_forms.
 

Introduction and Purpose of the Topic 

Generally every business keeps focus on continuous product development and keeps changing and improvising the product specifications and features. How ever, for the existing customers, who are using the earlier version of the product, companies are compelled support, service spares requirement. In terms of inventory management, this means that a material, which used to be procured / manufactured with a nominal control on inventory, face a risk of obsolescence over a period of time. This calls for a very cautious inventory management. Hence, when we have to support such situation, Sourcing and inventory managers like to monitor the procurement strictly against a confirmed requirement, rather than procuring to stock

In most of the cases Business often procures the materials for stock and Some times due to business difficulties the procured stock will not get utilized either for production internally or for a external sale, there by piling of the stock .If the procured stock is of chemical in nature, after its Shelf life gets expires and which requires a quality check for deciding over its further utilization either for a scrap or for extension of its shelf life. In both the cases the valuable time of the Business users will get wasted at the same the money.

In some of the cases some materials which belong to the material types other than the material type UNBW will be with a standard cost zero with a notation to the users these materials need to be procured for consumption/for account assignment. However users often create Pos with out account assignment..

If users are restricted to procure the material for stock rather for a purpose?

The forth going paragraphs will depict how this can be achieved.

How to Achieve the Purpose:

In SAP the Material Types Non stock materials (UNBW) and Non Valuated Materials (NLAG) will ask for a account assignment category during the creation of PO there by the Buyer to enter the same and during its Goods Receipt system posts the documents against the consumption account.

However there are certain difficulties and functional short falls to change the material type of the material during the course of its existence.Hence the functonality of the above material types(UNBW,NLAG) can be brought to work with other material types (ROH,.. Etc) with this alternative process.

The same functionality has been utilized for the purpose to see that the costs are posted against the account assignment and no stocks are visible at MMBE there by causing problems at a later date.

Process of Achieving the Purpose: 
Using this particular scenario the users will be restricted to create the PO with account assignment for the materials in question, there by reducing the inventory related issues at a later date.

Let us now see how this particular purpose is achieved through the settings in SAP.

1. Creation of a Material status.

2. Insertion of the code in the function module MEX_PSTYP_KNTTP.

3.Assign the created material status in the material master of the materials identified for such inventoty control.

This piece of code will check for the new material status in the material master for the material which is being created for a PO and if the material status in the material is the new material status created , gives a error message for the user saying that 'Account assignment Category is mandatory for the item'. And which will not allow saving the PO unless the Account Assignment category details are provided.

The next paragraphs will give the technical details of the settings.

1.Creation of the material status.

At SPRO--Logistics General-Material Master-Settings for key fields--Define Material Status.Material status can be a two digit number like 09.

Here a new material status will be created with no controlling functions .The following is the screen shot for the same 1.jpg|thumbnail"/>
 

1.Insertion Of the code in the function Module MEX_PSTYP_KNTTP 
At SE37 for the above function module, the following code will be added at the relevant place. The below code only provides a guide line for the logic.

Code Details:

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
SELECT SINGLE * FROM marc
  INTO wa_marc WHERE matnr = im_matnr AND
                     werks = im_werks.

IF sy-subrc = 0.
  IF wa_marc-mmsta = '09'.
    MESSAGE e062(me) WITH im_matnr.
  ENDIF.
ENDIF.

Result of the Code: 

The above code during its execution while creation of the Purchase Order will check for the material status in the material and if it equals with the newly created material status defined for this purpose, it will initiates the error message to stop further creation of the PO and 'save' rather issue a Error Message 'E062' which is 'Account Assignment Category is Mandatory for the material.

Users will need to enter the Account Assignment Category details for creating the PO, which ensures that material is procured for Consumption and not to Stock.

Conclusion:  
Basically the above process will restrict the users to create the Pos only with account assignment category to those materials which have been assigned with the material status and acts as a controlling and preventive mechanism for procurement of materials there by reducing the inventories and their costs and time

Author: Sujeet Mishra
Submitted: 12/08/201

Description : This program is a sample program to update any fields in MMR. In below example , Program is updating ZXXX field using Function Module "MATERIAL_MAINTAIN_DARK", Program has functionality to upload excel file from desktop.

                    File Format : Material Number, Plant, ZXXX.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
REPORT  ZMM_MMR_UPDATE.
*&---------------------------------------------------------------------*
*&                   TYPE-POOLS                                        *
*&---------------------------------------------------------------------*
TYPE-POOLS: TRUXS.
*&---------------------------------------------------------------------*
*&                        Types                                        *
*&---------------------------------------------------------------------*
TYPES: BEGIN OF TY_DATATAB,
        MATNR      TYPE MATNR,
        WERKS      TYPE WERKS_D,
        ZXXXX      TYPE ZXXXX,
       END OF TY_DATATAB.
DATA:  GT_DATATAB TYPE STANDARD TABLE OF TY_DATATAB,
       GS_DATATAB TYPE TY_DATATAB.
DATA: GT_MARA_UEB TYPE STANDARD TABLE OF MARA_UEB,
      GS_MARA_UEB LIKE LINE OF GT_MARA_UEB,
      GT_MARC_UEB TYPE STANDARD TABLE OF MARC_UEB,
      GS_MARC_UEB LIKE LINE OF GT_MARC_UEB,
      GT_AMERRDAT TYPE STANDARD TABLE OF MERRDAT,
      GS_AMERRDAT LIKE LINE OF GT_AMERRDAT,
      GT_MSG_LOG  TYPE STANDARD TABLE OF MSG_LOG,
      GS_MSG_LOG  LIKE LINE OF GT_MSG_LOG,
      GT_MSG_TEXT TYPE STANDARD TABLE OF MSG_TEXT,
      GS_MSG_TEXT LIKE LINE OF GT_MSG_TEXT.
DATA: GT_RAW TYPE TRUXS_T_TEXT_DATA.
TYPES: BEGIN OF TY_MARA,
       MATNR TYPE MATNR,
       PSTAT TYPE PSTAT_D,
       END OF TY_MARA.

*&---------------------------------------------------------------------*
*&                 Constants Definitions                               *
*&---------------------------------------------------------------------*
CONSTANTS: C_TCODE TYPE TCODE       VALUE 'MM02',
           C_TRANC TYPE TRANSCOUNT  VALUE '0000000001'.
*&---------------------------------------------------------------------*
*&                 Variables Declaration                               *
*&---------------------------------------------------------------------*
DATA: PROGRAM_ID               LIKE SY-REPID ,
      REPORT_ID                LIKE SY-REPID ,
      GD_PERCENT TYPE I.
*&---------------------------------------------------------------------*
*&                 Selection Screen                                    *
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS:   P_FILE TYPE RLGRAP-FILENAME.
SELECTION-SCREEN END OF BLOCK B1.
*&---------------------------------------------------------------------*
*&                 Initialization                                      *
*&---------------------------------------------------------------------*
INITIALIZATION.
  PROGRAM_ID = SY-REPID .
  REPORT_ID  = SY-REPID .
*&---------------------------------------------------------------------*
*&                 F4 help on File                                     *
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
  PERFORM GET_FILE_NAME.
AT SELECTION-SCREEN ON P_FILE.
  PERFORM EXCEL_FILE.
START-OF-SELECTION.
*$Prepare data file
  PERFORM PREPARE_DATA_FILE.
*&Update Material Mater with current uploaded data
  PERFORM UPDATE_MATERIAL_MASTER.
*$ Display Error Record
  PERFORM ERROR_RECORD_DISPLAY.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*&      Form  get_file_name
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GET_FILE_NAME .
  CALL FUNCTION 'F4_FILENAME'
    IMPORTING
      FILE_NAME = P_FILE
    EXCEPTIONS
      OTHERS    = 1.
  IF SY-SUBRC <> 0.
  ENDIF.
ENDFORM.                    " get_file_name
*&---------------------------------------------------------------------*
*&      Form  excel_file
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM EXCEL_FILE .
  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
   EXPORTING
*     I_FIELD_SEPERATOR     =
*      i_line_header        =  'X'
     I_TAB_RAW_DATA         =  GT_RAW
     I_FILENAME             =  P_FILE
   TABLES
     I_TAB_CONVERTED_DATA   = GT_DATATAB[]
   EXCEPTIONS
     CONVERSION_FAILED      = 1
     OTHERS                 = 2.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
  SORT GT_DATATAB[] BY MATNR.
  DELETE ADJACENT DUPLICATES FROM GT_DATATAB COMPARING MATNR.
ENDFORM.                    " excel_file
*&---------------------------------------------------------------------*
*&      Form  prepare_data_file
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM PREPARE_DATA_FILE .
  DATA: LV_DATATAB_COUNT TYPE STRING.
  DELETE ADJACENT DUPLICATES FROM GT_DATATAB
                            COMPARING MATNR WERKS.
  CLEAR: GT_MARA_UEB[], GT_MARC_UEB[], GD_PERCENT.
  DESCRIBE TABLE GT_DATATAB LINES LV_DATATAB_COUNT.
  LOOP AT GT_DATATAB INTO GS_DATATAB.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        INPUT  = GS_DATATAB-MATNR
      IMPORTING
        OUTPUT = GS_DATATAB-MATNR.
    GS_MARA_UEB-MATNR    =  GS_DATATAB-MATNR.
    GS_MARA_UEB-TCODE    =  C_TCODE.
    GS_MARA_UEB-TRANC    =  SY-TABIX. "c_tranc.
    APPEND GS_MARA_UEB TO GT_MARA_UEB.
    GS_MARC_UEB-MATNR    =  GS_DATATAB-MATNR.
    GS_MARC_UEB-WERKS    =  GS_DATATAB-WERKS.
    GS_MARC_UEB-ZXXXX    =  GS_DATATAB-ZXXXX.
    GS_MARC_UEB-TRANC    =  SY-TABIX. "c_tranc.
    APPEND GS_MARC_UEB TO GT_MARC_UEB.
    CLEAR: GS_MARA_UEB, GS_MARC_UEB.
    PERFORM PROGRESS_BAR USING 'Retrieving data...'(001)
                              SY-TABIX
                              LV_DATATAB_COUNT.

  ENDLOOP.
ENDFORM.                    " prepare_data_file
*&---------------------------------------------------------------------*
*&      Form  update_material_master
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM UPDATE_MATERIAL_MASTER .
  DATA: LV_ERROR_TRANSACTION TYPE BIERRNUM,
        LV_COUNT_MARA TYPE STRING.
  DESCRIBE TABLE GT_MARA_UEB LINES LV_COUNT_MARA.
  SORT GT_MARA_UEB BY MATNR TRANC.
  SORT GT_MARC_UEB BY MATNR TRANC.
  CALL FUNCTION 'MATERIAL_MAINTAIN_DARK'
    EXPORTING
      SPERRMODUS                = 'E'
      MAX_ERRORS                = 0
      P_KZ_NO_WARN              = 'E'
      KZ_PRF                    = ' '
      KZ_VERW                   = 'X'
      KZ_AEND                   = 'X'
      USER                      = SY-UNAME
    IMPORTING
      NUMBER_ERRORS_TRANSACTION = LV_ERRORS_TRANSACTION
    TABLES
      AMARA_UEB                 = GT_MARA_UEB
      AMARC_UEB                 = GT_MARC_UEB
      AMERRDAT                  = GT_AMERRDAT.
*    EXCEPTIONS
*      kstatus_empty             = 1
*      tkstatus_empty            = 2
*      t130m_error               = 3
*      internal_error            = 4
*      too_many_errors           = 5
*      update_error              = 6
*      OTHERS                    = 7.
  IF SY-SUBRC <> 0.
*    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
*            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
    WRITE :  TEXT-002 , LV_COUNT_MARA,
           / TEXT-003 , LV_ERROR_TRANSACTION.
  ENDIF.
ENDFORM.                    " update_material_master
*&---------------------------------------------------------------------*
*&      Form  progress_bar
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_0222   text
*      -->P_SY_TABIX  text
*      -->P_LV_DATATAB_COUNT  text
*----------------------------------------------------------------------*
FORM PROGRESS_BAR  USING    VALUE(P_0222)
                            P_SY_TABIX
                            P_LV_DATATAB_COUNT.
  DATA:  W_TEXT(40),
         W_PERCENTAGE TYPE P,
         W_PERCENT_CHAR(3).
  W_PERCENTAGE = ( P_SY_TABIX / P_LV_DATATAB_COUNT ) * 100.
  W_PERCENT_CHAR = W_PERCENTAGE.
  SHIFT W_PERCENT_CHAR LEFT DELETING LEADING ' '.
  CONCATENATE P_0222 W_PERCENT_CHAR '% Complete'(002) INTO W_TEXT.
  IF W_PERCENTAGE GT GD_PERCENT OR P_SY_TABIX EQ 1.
    CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
      EXPORTING
        PERCENTAGE = W_PERCENTAGE
        TEXT       = W_TEXT.
    GD_PERCENT = W_PERCENTAGE.
  ENDIF.
ENDFORM.                    " progress_bar
*&---------------------------------------------------------------------*
*&      Form  error_record_display
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM ERROR_RECORD_DISPLAY .
  SORT GT_AMERRDAT BY MSGTY.
  DELETE GT_AMERRDAT WHERE MSGTY NE 'E'.
  IF NOT GT_AMERRDAT[] IS INITIAL.
    WRITE: /1 'Error Details'.
    ULINE:/1(100).
    WRITE:  /1 '|', TEXT-004, 25 '|', TEXT-005.
    ULINE:/1(100).
  ENDIF.

  LOOP AT GT_AMERRDAT INTO GS_AMERRDAT.
    GS_MSG_LOG-MSGID = GS_AMERRDAT-MSGID.
    GS_MSG_LOG-MSGNO = GS_AMERRDAT-MSGNO.
    GS_MSG_LOG-MSGTY = GS_AMERRDAT-MSGTY.
    GS_MSG_LOG-MSGV1 = GS_AMERRDAT-MSGV1.
    GS_MSG_LOG-MSGV2 = GS_AMERRDAT-MSGV2.
    GS_MSG_LOG-MSGV3 = GS_AMERRDAT-MSGV3.
    GS_MSG_LOG-MSGV4 = GS_AMERRDAT-MSGV4.

    CALL FUNCTION 'MESSAGE_TEXTS_READ'
      EXPORTING
        MSG_LOG_IMP     = GS_MSG_LOG
      TABLES
        T_MSG_TEXTS_EXP = GT_MSG_TEXT.
    IF SY-SUBRC = 0.
      READ TABLE GT_MSG_TEXT INTO GS_MSG_TEXT INDEX 1.
      IF SY-SUBRC = 0.
        WRITE: /1 '|', GS_AMERRDAT-MATNR, 25 '|' , GS_MSG_TEXT-MSGTX, '|'.
      ENDIF.
    ENDIF.
  ENDLOOP.
  ULINE:/1(100).
ENDFORM.                    " error_record_display*/

Author: Bjoern Panter
Submitted: 26. Nov 2008
Related Links: Blog

 

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*&---------------------------------------------------------------------\*
*& Report&nbsp; ZCREATE_ART_MASS
*&
*&---------------------------------------------------------------------\*
*& Report&nbsp; CREATE_ART_MASS                                         *
*&---------------------------------------------------------------------\*
*& Mit diesem Report ist es möglich einen existierenden Artikel als
*& Vorlage zu nehmen und auf Basis dieses Artikels neue Artikel
*& anzulegen. Für die neuen Artikel kann für den Postfix, der an die
*& Artikelnummer des Vorlageartikels drangehängt wird, eine Startzahl
*& vorgegeben werden und zusätzlich wird die Anzahl der anzulegenden
*& Artikelkopien benötigt.
*&---------------------------------------------------------------------\*


REPORT  ZCREATE_ART_MASS.

* Artikel, der als Vorlage dienen soll (MATNR sollte alphanum. sein
* und nicht länger als 10 Zeichen, damit noch Platz ist für den
* Postfix und für die laufende Nummer bei Varianten).
parameters: p_vorart(10).
* Startwert für den Postfix (laufende Nummer, die an die MATNR des
* Vorlageartikels angehängt wird)
parameters: p_art_nr   type i default 1.
* Alternativ: anstatt Postfix einen Präfix erzeugen
parameters: p_post RADIOBUTTON GROUP gr1,
            p_prae RADIOBUTTON GROUP gr1.
* Anzahl der Artikelkopien (nicht mehr als 99999, da Postfix nur
* 5-stellig)
parameters: p_anzart  type i default 10.
TABLES: BAPIE1MLTXRT,
        BAPIE1VARKEY,
        BAPIE1WRKKEY,
        BAPIE1MATHEAD,
        T001W,
        EDIDC,
        MARA,
        T100.
data: count type i.
data: char_count(5).
data: matnr_len type i.
data: vorl_matnr like mara-matnr.
data: new_matnr  like mara-matnr value '__________'.
data: hindex     like sy-index.
DATA: BEGIN OF HMARCKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMARCKEY.
DATA: END OF HMARCKEY.
check p_vorart cn '0123456789 '.   "keine rein numerischen Art.nr.
select single * from mara where matnr = p_vorart.
check sy-subrc = 0.
check p_anzart < 100000.    "höchstens 99999 Artikel
* Falls die MATNR des Vorlageartikels kürzer als 10 Stellen ist, wird
* mit '_' aufgefüllt.
matnr_len            = strlen( p_vorart ).
if not p_post is initial.
  new_matnr(matnr_len) = p_vorart.
elseif not p_prae is initial.
  shift new_matnr by 5 places right.
  new_matnr+5(matnr_len) = p_vorart.
endif.
vorl_matnr           = p_vorart.
count = p_art_nr.
do p_anzart times.
  hindex = sy-index.
  if count > 99999. exit. endif.
  move count to char_count.
  SHIFT char_count RIGHT DELETING TRAILING ' '.
  TRANSLATE char_count USING ' 0'.
  if not p_post is initial.
    new_matnr+10(5) = char_count.
  elseif not p_prae is initial.
    new_matnr(5) = char_count.
  endif.
  perform call_report_rbdartst using vorl_matnr new_matnr.
  write: / hindex, new_matnr.
  count = count + 1.
enddo.
*&---------------------------------------------------------------------*
*&      Form  call_report_rbdartst
*&---------------------------------------------------------------------*
*       Coding aus dem Report RBDARTST kopiert.
*       Damit das IDoc für die Kopiervorlage aus Performancegründen
*       nur einmal aufgebaut wird, konnte der Report RBDARTST nicht
*       mit SUBMIT aufgerufen werden.
*----------------------------------------------------------------------*
FORM call_report_rbdartst using P_MATNR  like mara-matnr  "Vorl.art.nr.
                                P_MATNRN like mara-matnr. "neue Art.nr.
STATICS: NOT_FIRST_CALL LIKE SY-DATAR.
INCLUDE MMMGXV37.
DATA: P_MESTY LIKE EDIDC-MESTYP VALUE 'ARTMAS'.
DATA: P_NUMALL(10).                     "nicht genutzt!
DATA: P_NUMACT(10).                     "nicht genutzt!
DATA: P_BEFORE(5).                      "nicht genutzt!
DATA: P_KEYLI LIKE SY-DATAR VALUE 'X'.  "Keylisten verwenden (Perf.)
DATA: P_NEWWRK TYPE I.                  "nicht genutzt!
RANGES: S_WERKS FOR T001W-WERKS.        "nicht genutzt!
DATA: P_NOLOG LIKE SY-DATAR VALUE 'X'.  "kein Anwendungslog
*ATA: P_NOBEL LIKE SY-DATAR VALUE 'X'.  "keine Änderungsbelege
DATA: P_NOBEL LIKE SY-DATAR VALUE ' '.  "Änderungsbelege wg. Änd.zeigern
DATA: P_SHLOG LIKE SY-DATAR.            "keinen Anwendungslog anzeigen
DATA: P_DETAIL LIKE SY-DATAR.           "nicht genutzt!
DATA: CR_IDOC LIKE SY-DATAR.            "nicht genutzt!
DATA: P_RUNTI LIKE SY-DATAR.            "nicht genutzt!
DATA: HMATNR LIKE MARA-MATNR.
DATA: BEGIN OF SEGMENTDATA,
      FUNCTION LIKE BAPIE1MARART-FUNCTION,
      MATERIAL LIKE BAPIE1MARART-MATERIAL,
      TAIL(979).                       " = 1000 - 3 - 18
DATA: END OF SEGMENTDATA.
* Data for the call of the function
DATA: BEGIN OF T_IDOC_DATA OCCURS 0.
        INCLUDE STRUCTURE EDIDD.
DATA: END OF T_IDOC_DATA.
DATA: H_IDOC_DATA like EDIDD.
DATA: TT001W      like t001w occurs 0 with header line.
DATA: BEGIN OF F_IDOC_HEADER.
        INCLUDE STRUCTURE EDIDC.
DATA: END OF F_IDOC_HEADER.
DATA: BEGIN OF T_EDIDC OCCURS 0.
        INCLUDE STRUCTURE EDIDC.
DATA: END OF T_EDIDC.
DATA: BEGIN OF T_SELECTED_EDIDC OCCURS 0.
        INCLUDE STRUCTURE EDIDC.
DATA: END OF T_SELECTED_EDIDC.
DATA: BEGIN OF T_STATUS OCCURS 0.
        INCLUDE STRUCTURE BDIDOCSTAT.
DATA: END OF T_STATUS.
DATA: BEGIN OF T_RETVARS OCCURS 0.
        INCLUDE STRUCTURE BDWFRETVAR.
DATA: END OF T_RETVARS.
DATA: BEGIN OF T_SER OCCURS 0.
        INCLUDE STRUCTURE BDI_SER.
DATA: END OF T_SER.
* Data for finding the keys of the material
DATA: BEGIN OF T_MARAKEY OCCURS 0.
        INCLUDE STRUCTURE BDIMARAKEY.
DATA: END OF T_MARAKEY.
DATA: IHEAD_MATNR LIKE PRE03-MATNR.
DATA: TVAR_TAB LIKE PRE03 OCCURS 0 WITH HEADER LINE.
DATA: TMARAKEY LIKE BDIMARAKEY OCCURS 0 WITH HEADER LINE.
DATA: TAUSPKEY LIKE BDIAUSPKEY OCCURS 0 WITH HEADER LINE.
DATA: TMAW1KEY LIKE BDIMAW1KEY OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF TMAKTKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMAKTKEY.
DATA: END OF TMAKTKEY.
DATA: BEGIN OF TMARCKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMARCKEY.
DATA: END OF TMARCKEY.
DATA: HREFPLANTS LIKE MREFPLANT OCCURS 20 WITH HEADER LINE.
DATA: BEGIN OF TMARDKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMARDKEY.
DATA: END OF TMARDKEY.
DATA: BEGIN OF TMFHMKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMFHMKEY.
DATA: END OF TMFHMKEY.
DATA: BEGIN OF TMPGDKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMPGDKEY.
DATA: END OF TMPGDKEY.
DATA: BEGIN OF TMPOPKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMPOPKEY.
DATA: END OF TMPOPKEY.
DATA: BEGIN OF TMPRWKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMPRWKEY.
DATA: END OF TMPRWKEY.
DATA: BEGIN OF TMVEGKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMVEGKEY.
DATA: END OF TMVEGKEY.
DATA: BEGIN OF TMVEUKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMVEUKEY.
DATA: END OF TMVEUKEY.
DATA: BEGIN OF TMKALKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMKALKEY.
DATA: END OF TMKALKEY.
DATA: BEGIN OF TMARMKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMARMKEY.
DATA: END OF TMARMKEY.
DATA: TMAMTKEY LIKE BDIMAMTKEY OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF TMEANKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMEANKEY.
DATA: END OF TMEANKEY.
DATA: TMLEAKEY LIKE BDIMLEAKEY OCCURS 0 WITH HEADER LINE.
DATA: TMALGKEY LIKE BDIMALGKEY OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF TMVKEKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMVKEKEY.
DATA: END OF TMVKEKEY.
DATA: TWLK2KEY LIKE BDIWLK2KEY OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF TMLANKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMLANKEY.
DATA: END OF TMLANKEY.
DATA: BEGIN OF TMBEWKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMBEWKEY.
DATA: END OF TMBEWKEY.
DATA: BEGIN OF TMLGNKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMLGNKEY.
DATA: END OF TMLGNKEY.
DATA: BEGIN OF TMLGTKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMLGTKEY.
DATA: END OF TMLGTKEY.
DATA: BEGIN OF TSTXHKEY OCCURS 10.
        INCLUDE STRUCTURE BDISTXHKEY.
DATA: END OF TSTXHKEY.
* Help-Data
DATA: STRING(400).
DATA: OUT_STRING(200).
* Interface data
DATA: IF_STATUS(200).
* Unterstützung Massenaufruf -> nur beim ersten Aufruf die Daten lesen
* -> danach das IDoc aus dem Memory verwenden
if not_first_call is initial.
  not_first_call = 'X'.
* Matnr auf Existenz prüfen
CALL FUNCTION 'MARA_SINGLE_READ'
     EXPORTING
*         KZRFB             = ' '
*         MAXTZ             = 0
          MATNR             = P_MATNR
*         SPERRMODUS        = ' '
*         STD_SPERRMODUS    = ' '
*    IMPORTING
*         WMARA             =
     EXCEPTIONS
          LOCK_ON_MATERIAL  = 1
          LOCK_SYSTEM_ERROR = 2
          WRONG_CALL        = 3
          NOT_FOUND         = 4
          OTHERS            = 5.
IF SY-SUBRC = 4.
  SY-MSGTY = 'I'.
  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
          WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  EXIT.
ENDIF.
* Select all the keys for the material to create idoc
REFRESH T_MARAKEY.
CLEAR T_MARAKEY.
T_MARAKEY-MANDT = SY-MANDT.
T_MARAKEY-MATNR = P_MATNR.
APPEND T_MARAKEY.
CALL FUNCTION 'MASTERIDOC_CREATE_REQ_ARTMAS'
     EXPORTING
          RCVPFC                      = ''
          RCVPRN                      = ''
          RCVPRT                      = ''
          SNDPFC                      = ''
          SNDPRN                      = ''
          SNDPRT                      = ''
          MESSAGE_TYPE                = P_MESTY
          FLAG_TESTMODE               = 'X'
*         SUPPRESS_PROGRESS_INDICATOR = ' '
*         SUPPRESS_BUFFER_REFRESH     = ' '
*         OUTPUT_TOTAL_INIT           = 0
*         OUTPUT_COUNTER_INIT         = 0
*    IMPORTING
*         CREATED_COMM_IDOCS          =
*         CREATED_MASTER_IDOCS        =
     TABLES
          MARAKEY                     = T_MARAKEY
     EXCEPTIONS
          OTHERS                      = 1.
IF SY-SUBRC <> 0.
  CHECK 0 = 1.
ENDIF.
* .....Import Key data from memory
IMPORT
  IHEAD_MATNR                          "  RT
  TVAR_TAB                             "  RT
  TMARAKEY                             "  RT
  TAUSPKEY                             "  RT
  TMAW1KEY                             "  RT
  TMAKTKEY
  TMARCKEY
  TMARDKEY
  TMARMKEY
  TMAMTKEY                             "  RT
  TMEANKEY
  TMLEAKEY                             "  RT
  TMALGKEY                             "  RT
  TMVKEKEY
  TWLK2KEY                             "  RT
  TMLANKEY
  TMBEWKEY
  TMLGNKEY
  TMLGTKEY
  TSTXHKEY
  TMFHMKEY
  TMPGDKEY
  TMPOPKEY
  TMPRWKEY
  TMVEGKEY
  TMVEUKEY
  TMKALKEY
FROM MEMORY
ID 'MGVDATA'.
* Create IDOC data
IF NOT P_KEYLI IS INITIAL.
* Vorlagebetriebe ermitteln
  CALL FUNCTION 'READ_REFERENCE_PLANTS'
*      EXPORTING
*           KZRFB     = ' '
       TABLES
            REFPLANT  = HREFPLANTS
       EXCEPTIONS
            NOT_FOUND = 1
            OTHERS    = 2
            .
  SORT HREFPLANTS BY WERKS.
* Keys zu Vorlagebetrieb und Nichtvorlagebetrieb extrahieren:
* - In den T....KEY-Tabellen nur die Vorlagebetriebe belassen
* - Die Nichtvorlagebetriebe auf Basis der MARC-Keys sammeln
  LOOP AT TMARCKEY.
    READ TABLE HREFPLANTS WITH KEY WERKS = TMARCKEY-WERKS
                          BINARY SEARCH.
    IF SY-SUBRC NE 0.
*     Kein Vorlagebetrieb
      DELETE TMARCKEY.
      APPEND TMARCKEY TO HMARCKEY.
    ENDIF.
  ENDLOOP.
  LOOP AT TMBEWKEY.
    READ TABLE HREFPLANTS WITH KEY WERKS = TMBEWKEY-BWKEY
                          BINARY SEARCH.
    IF SY-SUBRC NE 0.
*     Kein Vorlagebetrieb
      DELETE TMBEWKEY.
    ENDIF.
  ENDLOOP.
  LOOP AT TMARDKEY.
    READ TABLE HREFPLANTS WITH KEY WERKS = TMARDKEY-WERKS
                          BINARY SEARCH.
    IF SY-SUBRC NE 0.
*     Kein Vorlagebetrieb
      DELETE TMARDKEY.
    ENDIF.
  ENDLOOP.
  LOOP AT TMPOPKEY.
    READ TABLE HREFPLANTS WITH KEY WERKS = TMPOPKEY-WERKS
                          BINARY SEARCH.
    IF SY-SUBRC NE 0.
*     Kein Vorlagebetrieb
      DELETE TMPOPKEY.
    ENDIF.
  ENDLOOP.
  LOOP AT TMFHMKEY.
    READ TABLE HREFPLANTS WITH KEY WERKS = TMFHMKEY-WERKS
                          BINARY SEARCH.
    IF SY-SUBRC NE 0.
*     Kein Vorlagebetrieb
      DELETE TMFHMKEY.
    ENDIF.
  ENDLOOP.
  LOOP AT TMPGDKEY.
    READ TABLE HREFPLANTS WITH KEY WERKS = TMPGDKEY-WERKS
                          BINARY SEARCH.
    IF SY-SUBRC NE 0.
*     Kein Vorlagebetrieb
      DELETE TMPGDKEY.
    ENDIF.
  ENDLOOP.
  LOOP AT TMPRWKEY.
    READ TABLE HREFPLANTS WITH KEY WERKS = TMPRWKEY-WERKS
                          BINARY SEARCH.
    IF SY-SUBRC NE 0.
*     Kein Vorlagebetrieb
      DELETE TMPRWKEY.
    ENDIF.
  ENDLOOP.
  LOOP AT TMVEGKEY.
    READ TABLE HREFPLANTS WITH KEY WERKS = TMVEGKEY-WERKS
                          BINARY SEARCH.
    IF SY-SUBRC NE 0.
*     Kein Vorlagebetrieb
      DELETE TMVEGKEY.
    ENDIF.
  ENDLOOP.
  LOOP AT TMVEUKEY.
    READ TABLE HREFPLANTS WITH KEY WERKS = TMVEUKEY-WERKS
                          BINARY SEARCH.
    IF SY-SUBRC NE 0.
*     Kein Vorlagebetrieb
      DELETE TMVEUKEY.
    ENDIF.
  ENDLOOP.
  LOOP AT TMKALKEY.
    READ TABLE HREFPLANTS WITH KEY WERKS = TMKALKEY-WERKS
                          BINARY SEARCH.
    IF SY-SUBRC NE 0.
*     Kein Vorlagebetrieb
      DELETE TMKALKEY.
    ENDIF.
  ENDLOOP.
ENDIF.
CALL FUNCTION 'MASTERIDOC_CREATE_ARTMAS'
     EXPORTING
          HEAD_MATNR         = IHEAD_MATNR
          RCVPFC             = ''
          RCVPRN             = ''
          RCVPRT             = ''
          SNDPFC             = ''
          SNDPRN             = ''
          SNDPRT             = ''
          MESSAGE_TYPE       = P_MESTY
          FLAG_TESTMODE      = 'X'
*    IMPORTING
*         CREATED_COMM_IDOCS =
     TABLES
          VAR_TAB            = TVAR_TAB
          MARAKEY            = TMARAKEY
          AUSPKEY            = TAUSPKEY
          MAW1KEY            = TMAW1KEY
          MAKTKEY            = TMAKTKEY
          MARCKEY            = TMARCKEY
          MARDKEY            = TMARDKEY
          MARMKEY            = TMARMKEY
          MAMTKEY            = TMAMTKEY
          MEANKEY            = TMEANKEY
          MLEAKEY            = TMLEAKEY
          MALGKEY            = TMALGKEY
          MVKEKEY            = TMVKEKEY
          WLK2KEY            = TWLK2KEY
          MLANKEY            = TMLANKEY
          MBEWKEY            = TMBEWKEY
          MLGNKEY            = TMLGNKEY
          MLGTKEY            = TMLGTKEY
          STXHKEY            = TSTXHKEY
          MFHMKEY            = TMFHMKEY
          MPGDKEY            = TMPGDKEY
          MPOPKEY            = TMPOPKEY
          MPRWKEY            = TMPRWKEY
          MVEGKEY            = TMVEGKEY
          MVEUKEY            = TMVEUKEY
          MKALKEY            = TMKALKEY
     EXCEPTIONS
          OTHERS             = 1.
IF SY-SUBRC <> 0.
  CHECK 0 = 1.
ENDIF.
endif.     "not_first_call is initial
* .....Import IDOC data from memory
IMPORT
  F_IDOC_HEADER
  T_IDOC_DATA
FROM MEMORY
ID 'MGVIDOC'.

* Nun auch komplette Artikelnummer als Eingabe unterstützen -> Probleme
* gab es bisher bei Variantenartikelnummern, denn diese dürfen nicht
* 1:1 ersetzt werden wegen Suffix.
DATA: FLEN TYPE I.
FLEN = STRLEN( P_MATNR ).
* Change material number in all IDOC segments adding the new prefix
LOOP AT T_IDOC_DATA.
* Sonderlogik Langtexte, da keine Komponente 'MATERIAL'
* Vgl. FB: BAPI_MATERIAL_MAINTAINDATA_RT und Form FORM MLTX_UEBERGEBEN.
  IF T_IDOC_DATA-SEGNAM = 'E1BPE1MLTXRT'.
    BAPIE1MLTXRT = T_IDOC_DATA-SDATA.
    IF P_MATNRN IS INITIAL.
      STRING = '&&'.
      REPLACE '&' WITH P_BEFORE INTO STRING.
      CLEAR HMATNR.
      HMATNR = BAPIE1MLTXRT-TEXT_NAME. " schneidet korrekt ab ...
      REPLACE '&' WITH HMATNR INTO STRING.
    ELSE.
* JH/28.07.99/4.6C (Anfang)
*     STRING = P_MATNRN.
      STRING = BAPIE1MLTXRT-TEXT_NAME.
      REPLACE P_MATNR WITH P_MATNRN INTO STRING LENGTH FLEN.
* JH/28.07.99/4.6C (Ende)
    ENDIF.
    CONDENSE STRING NO-GAPS.
* cfo/4.6B-A
* AHE: 28.07.99 - A (4.6c)
* Modifikation getuned
    DATA: HNUM TYPE I.
    HNUM = STRLEN( STRING ).
    WHILE HNUM GT 18.
      REPLACE '0' WITH SPACE INTO STRING.
      HNUM = HNUM - 1.
    ENDWHILE.
    CONDENSE STRING NO-GAPS.
*   DATA: HNUM TYPE I.
*   HNUM = STRLEN( STRING ).
*   WHILE HNUM GT 18.
*     REPLACE '0' WITH SPACE INTO STRING.
*     CONDENSE STRING NO-GAPS.
*     HNUM = STRLEN( STRING ).
*   ENDWHILE.
* AHE: 28.07.99 - E
* cfo/4.6B-E
    CLEAR BAPIE1MLTXRT-TEXT_NAME.
    BAPIE1MLTXRT-TEXT_NAME = STRING(18).
    T_IDOC_DATA-SDATA = BAPIE1MLTXRT.
* Sonderlogik VARKEY's -> auch Variantennummern müssen ersetzt werden
  ELSEIF T_IDOC_DATA-SEGNAM = 'E1BPE1VARKEY'.
    BAPIE1VARKEY = T_IDOC_DATA-SDATA.
*   Sammelartikelnummer ersetzen
    IF P_MATNRN IS INITIAL.
      STRING = '&&'.
      REPLACE '&' WITH P_BEFORE INTO STRING.
      CLEAR HMATNR.
      HMATNR = BAPIE1VARKEY-MATERIAL.
      REPLACE '&' WITH HMATNR INTO STRING.
    ELSE.
* JH/28.07.99/4.6C (Anfang)
*     STRING = P_MATNRN.
      STRING = BAPIE1VARKEY-MATERIAL.
      REPLACE P_MATNR WITH P_MATNRN INTO STRING LENGTH FLEN.
* JH/28.07.99/4.6C (Ende)
    ENDIF.
    CONDENSE STRING NO-GAPS.
* cfo/4.6B-A
* AHE: 28.07.99 - A (4.6c)
* Modifikation getuned
    HNUM = STRLEN( STRING ).
    WHILE HNUM GT 18.
      REPLACE '0' WITH SPACE INTO STRING.
      HNUM = HNUM - 1.
    ENDWHILE.
    CONDENSE STRING NO-GAPS.
*   HNUM = STRLEN( STRING ).
*   WHILE HNUM GT 18.
*     REPLACE '0' WITH SPACE INTO STRING.
*     CONDENSE STRING NO-GAPS.
*     HNUM = STRLEN( STRING ).
*   ENDWHILE.
* AHE: 28.07.99 - E
* cfo/4.6B-E
    CLEAR BAPIE1VARKEY-MATERIAL.
    BAPIE1VARKEY-MATERIAL = STRING.
*   Variantennummer ersetzen
    IF P_MATNRN IS INITIAL.
      STRING = '&&'.
      REPLACE '&' WITH P_BEFORE INTO STRING.
      CLEAR HMATNR.
      HMATNR = BAPIE1VARKEY-VARIANT.
      REPLACE '&' WITH HMATNR INTO STRING.
    ELSE.
* JH/28.07.99/4.6C (Anfang)
*     STRING = P_MATNRN.
      STRING = BAPIE1VARKEY-VARIANT.
      REPLACE P_MATNR WITH P_MATNRN INTO STRING LENGTH FLEN.
* JH/28.07.99/4.6C (Ende)
    ENDIF.
    CONDENSE STRING NO-GAPS.
* cfo/4.6B-A
* AHE: 28.07.99 - A (4.6c)
* Modifikation getuned
    HNUM = STRLEN( STRING ).
    WHILE HNUM GT 18.
      REPLACE '0' WITH SPACE INTO STRING.
      HNUM = HNUM - 1.
    ENDWHILE.
    CONDENSE STRING NO-GAPS.
*   HNUM = STRLEN( STRING ).
*   WHILE HNUM GT 18.
*     REPLACE '0' WITH SPACE INTO STRING.
*     CONDENSE STRING NO-GAPS.
*     HNUM = STRLEN( STRING ).
*   ENDWHILE.
* AHE: 28.07.99 - E
* cfo/4.6B-E
    CLEAR BAPIE1VARKEY-VARIANT.
    BAPIE1VARKEY-VARIANT = STRING.
    T_IDOC_DATA-SDATA = BAPIE1VARKEY.
* JH/25.09.97 (Ende)
  ELSE.
*   Normalfall für alle anderen Segmente
    IF T_IDOC_DATA-SEGNAM = 'E1BPE1MATHEAD'.
      BAPIE1MATHEAD = T_IDOC_DATA-SDATA.
      BAPIE1MATHEAD-NO_APPL_LOG   = P_NOLOG.
      BAPIE1MATHEAD-NO_CHANGE_DOC = P_NOBEL.
      T_IDOC_DATA-SDATA = BAPIE1MATHEAD.
    ENDIF.
    CLEAR SEGMENTDATA.
    SEGMENTDATA = T_IDOC_DATA-SDATA.
    IF P_MATNRN IS INITIAL.
      STRING = '&&'.
      REPLACE '&' WITH P_BEFORE INTO STRING.
      REPLACE '&' WITH SEGMENTDATA-MATERIAL INTO STRING.
    ELSE.
*  (Anfang)
*     STRING = P_MATNRN.
      STRING = SEGMENTDATA-MATERIAL.
      REPLACE P_MATNR WITH P_MATNRN INTO STRING LENGTH FLEN.
*  (Ende)
    ENDIF.
    CONDENSE STRING NO-GAPS.
* cfo/4.6B-A
* AHE: 28.07.99 - A (4.6c)
* Modifikation getuned
    HNUM = STRLEN( STRING ).
    WHILE HNUM GT 18.
      REPLACE '0' WITH SPACE INTO STRING.
      HNUM = HNUM - 1.
    ENDWHILE.
    CONDENSE STRING NO-GAPS.
*   HNUM = STRLEN( STRING ).
*   WHILE HNUM GT 18.
*     REPLACE '0' WITH SPACE INTO STRING.
*     CONDENSE STRING NO-GAPS.
*     HNUM = STRLEN( STRING ).
*   ENDWHILE.
* AHE: 28.07.99 - E
* cfo/4.6B-E
    SEGMENTDATA-MATERIAL = STRING.
    T_IDOC_DATA-SDATA = SEGMENTDATA.
  ENDIF.
  MODIFY T_IDOC_DATA.
ENDLOOP.
*JH/02.03.99/4.6A (Anfang)
IF NOT P_KEYLI IS INITIAL.
* Keyliste aufbauen
  CLEAR BAPIE1WRKKEY.
  LOOP AT HMARCKEY.
    IF P_MATNRN IS INITIAL.
      STRING = '&&'.
      REPLACE '&' WITH P_BEFORE INTO STRING.
      REPLACE '&' WITH HMARCKEY-MATNR INTO STRING.
    ELSE.
* JH/22.03.00/5.0A (Anfang)
*     STRING = P_MATNRN.
      STRING = HMARCKEY-MATNR.
      REPLACE P_MATNR WITH P_MATNRN INTO STRING LENGTH FLEN.
* JH/22.03.00/5.0A (Ende)
    ENDIF.
    CONDENSE STRING NO-GAPS.
* JH/22.03.00/5.0A (Anfang)
    HNUM = STRLEN( STRING ).
    WHILE HNUM GT 18.
      REPLACE '0' WITH SPACE INTO STRING.
      HNUM = HNUM - 1.
    ENDWHILE.
    CONDENSE STRING NO-GAPS.
* JH/22.03.00/5.0A (Ende)
    BAPIE1WRKKEY-MATERIAL = STRING.
    BAPIE1WRKKEY-PLANT    = HMARCKEY-WERKS.
    CLEAR T_IDOC_DATA.
    T_IDOC_DATA-SEGNAM = 'E1BPE1WRKKEY'.
    T_IDOC_DATA-SDATA  = BAPIE1WRKKEY.
    APPEND T_IDOC_DATA.
  ENDLOOP.
ENDIF.
*JH/02.03.99/4.6A (Ende)
* (Anfang)
if p_newwrk > 0.
  select * from t001w into table tt001w up to p_newwrk rows
                      where werks in s_werks
                        and vlfkz <> ' '.
  CLEAR BAPIE1WRKKEY.
  loop at t_idoc_data into h_idoc_data where segnam = 'E1BPE1MARART'.
    SEGMENTDATA = H_IDOC_DATA-SDATA.
    loop at tt001w.
      BAPIE1WRKKEY-MATERIAL = SEGMENTDATA-MATERIAL.
      BAPIE1WRKKEY-PLANT    = tt001w-WERKS.
      CLEAR T_IDOC_DATA.
      T_IDOC_DATA-SEGNAM = 'E1BPE1WRKKEY'.
      T_IDOC_DATA-SDATA  = BAPIE1WRKKEY.
      APPEND T_IDOC_DATA.
    endloop.
  endloop.
endif.
*  (Ende)
* Call inbound module
OUT_STRING = '(& von &) Materialstamm wird eingebucht'(001).
REPLACE '&' WITH P_NUMACT INTO OUT_STRING.
REPLACE '&' WITH P_NUMALL INTO OUT_STRING.
CONDENSE OUT_STRING.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
     EXPORTING
          TEXT   = OUT_STRING
     EXCEPTIONS
          OTHERS = 1.
REFRESH T_EDIDC.
T_EDIDC = F_IDOC_HEADER.
APPEND T_EDIDC.
REFRESH T_STATUS.
*JH/02.03.99/4.6A Laufzeit messen (Anfang)
IF NOT P_RUNTI IS INITIAL.
  DATA RUN_TIME TYPE I.
  GET RUN TIME FIELD RUN_TIME.  "Laufzeit initialisieren -> RUN_TIME = 0
ENDIF.
*JH/02.03.99/4.6A Laufzeit messen (Ende)
IF CR_IDOC IS INITIAL.    "
* Einbuchen
CALL FUNCTION 'IDOC_INPUT_ARTMAS'
     EXPORTING
          INPUT_METHOD          = ' '
          MASS_PROCESSING       = ' '
*    IMPORTING
*         WORKFLOW_RESULT       =
*         APPLICATION_VARIABL   =
*         IN_UPDATE_TASK        =
*         CALL_TRANSACTION_DONE =
     TABLES
          IDOC_CONTRL           = T_EDIDC
          IDOC_DATA             = T_IDOC_DATA
          IDOC_STATUS           = T_STATUS
          RETURN_VARIABLES      = T_RETVARS
          SERIALIZATION_INFO    = T_SER
     EXCEPTIONS
          WRONG_FUNCTION_CALLED = 1
          OTHERS                = 2.
COMMIT WORK.
*  Laufzeit messen (Anfang)
IF NOT P_RUNTI IS INITIAL.
  GET RUN TIME FIELD RUN_TIME.   "seit dem Initialisierungszeitpunkt
                                       "verstrichene Zeit ermitteln
  WRITE / 'Laufzeit f. das reine Einbuchen der Daten:'.  "#EC NOTEXT
  WRITE: RUN_TIME USING EDIT MASK 'RR___.___,___' NO-GAP, ' ms '.
ENDIF.
*  Laufzeit messen (Ende)
* zur Zeit nicht ....
*CALL FUNCTION 'APPL_LOG_DISPLAY_INTERN'
*     EXPORTING
*          OBJECT                         = OBJECT_MATU
**         SUBOBJECT                      = ' '
**         TITLE_LIST_SCREEN              = ' '
**         COLUMN_SELECTION               = '11112221122   '
**         COLUMN_SELECTION_MSG_JUMP      = '1'
*          EXTERNAL_NUMBER_DISPLAY_LENGTH = 20
**    IMPORTING
**         NUMBER_OF_PROTOCOLS            =
**    EXCEPTIONS
**         object_not_found               = 1
**         subobject_not_found            = 2
**         others                         = 3
*     .
*  /4.0A
* Applikation Log anzeigen über direkten Report-Aufruf (TA MM90)
READ TABLE T_STATUS INDEX 1.
IF NOT T_STATUS-MSGV2 IS INITIAL.
  IF NOT P_SHLOG IS INITIAL.      "JH/22.03.00/5.0A
    SUBMIT RMVAPLSH WITH EXTNO = T_STATUS-MSGV2
                    AND RETURN.
  ENDIF.                          "JH/22.03.00/5.0A
ENDIF.
* Output data
*READ TABLE T_STATUS INDEX 1.
IF_STATUS = T_STATUS-STATUS.
IF_STATUS+2 = '|'.
IF_STATUS+3 = T_STATUS-MSGID.
IF_STATUS+8 = '|'.
IF_STATUS+9 = T_STATUS-MSGNO.
IF_STATUS+14 = '|'.
IF_STATUS+15 = STRING.
IF_STATUS+33 = '|'.
IF T_STATUS-STATUS <> '53'.
  IF_STATUS+34 = '&'.
  SELECT SINGLE * FROM T100 WHERE SPRSL = SY-LANGU
                              AND ARBGB = T_STATUS-MSGID
                              AND MSGNR = T_STATUS-MSGNO.
  REPLACE '&' WITH T100-TEXT INTO IF_STATUS.
  REPLACE '&' WITH T_STATUS-MSGV1 INTO IF_STATUS. CONDENSE IF_STATUS+34.
  REPLACE '&' WITH T_STATUS-MSGV2 INTO IF_STATUS. CONDENSE IF_STATUS+34.
  REPLACE '&' WITH T_STATUS-MSGV3 INTO IF_STATUS. CONDENSE IF_STATUS+34.
  REPLACE '&' WITH T_STATUS-MSGV4 INTO IF_STATUS. CONDENSE IF_STATUS+34.
ENDIF.
EXPORT IF_STATUS TO MEMORY
       ID 'MGVSTAT'.
CHECK P_DETAIL = 'X'.
IF T_STATUS-STATUS <> '53'.
  FORMAT COLOR 6.
ENDIF.
WRITE: /(100) IF_STATUS.
FORMAT RESET.
ULINE.
LOOP AT T_IDOC_DATA.
  WRITE: / T_IDOC_DATA-SEGNAM,
           '|',
          T_IDOC_DATA-SDATA(180).
ENDLOOP.
*   (Anfang)
ELSE.
  DATA: RECEIVERS     LIKE BDI_LOGSYS OCCURS 0 WITH HEADER LINE.
  DATA: IDOC_CONTROL  LIKE BDIDOCCONTROL.
  DATA: NEW_IDOCS     LIKE BDIDOCS    OCCURS 0 WITH HEADER LINE.
  MOVE-CORRESPONDING F_IDOC_HEADER TO IDOC_CONTROL.
  RECEIVERS-LOGSYS = 'DUMMY'.    "Dummy-Empfänger
  APPEND RECEIVERS.
  CALL FUNCTION 'ALE_IDOCS_CREATE'
       EXPORTING
            IDOC_CONTROL                = IDOC_CONTROL
       TABLES
            IDOC_DATA                   = T_IDOC_DATA
            RECEIVERS                   = RECEIVERS
            CREATED_IDOCS               = NEW_IDOCS
       EXCEPTIONS
            IDOC_INPUT_WAS_INCONSISTENT = 1
            OTHERS                      = 2.
  IF SY-SUBRC <> 0.
    ROLLBACK WORK.
    EXIT.
  ELSE.
    COMMIT WORK.
  ENDIF.
  IF NOT P_RUNTI IS INITIAL.
    GET RUN TIME FIELD RUN_TIME.   "seit dem Initialisierungszeitpunkt
                                   "verstrichene Zeit ermitteln
    WRITE / 'Runtime for pure data inbound:'.  "#EC NOTEXT
    WRITE: RUN_TIME USING EDIT MASK 'RR___.___,___' NO-GAP, ' ms '.
  ENDIF.
* Erzeugtes IDOC anzeigen
  READ TABLE NEW_IDOCS INDEX 1.
  IF SY-SUBRC = 0.
    SUBMIT RSEIDOC2 WITH DOCNUM = NEW_IDOCS-DOCNUM AND RETURN.
  ENDIF.
ENDIF.
*   (Ende)
ENDFORM.                    " call_report_rbdartst

Recording for MM01 :

                                         0000 T MM01                                                                                                                                 
SAPLMGMM                                 0060 X                                                                                                                                      
                                         0000   BDC_CURSOR                                                                                                                           RMMG1-MATNR
                                         0000   BDC_OKCODE                                                                                                                           /00
                                         0000   RMMG1-MATNR                                                                                                                          TEST  <<<<< Specify Material Name  
                                         0000   RMMG1-MBRSH                                                                                                                          M <<<<<<<<<<< Industry sector
                                         0000   RMMG1-MTART                                                                                                                          MODE <<< Material Type
SAPLMGMM                                 0070 X                                                                                                                                      
                                         0000   BDC_CURSOR                                                                                                                           MSICHTAUSW-DYTXT(01)
                                         0000   BDC_OKCODE                                                                                                                           =ENTR
                                         0000   MSICHTAUSW-KZSEL(01)                                                                                                                 X
SAPLMGMM                                 4004 X                                                                                                                                      
                                         0000   BDC_OKCODE                                                                                                                           /00
                                         0000   BDC_SUBSCR                                                                                                                           SAPLMGMM                                2004TABFRA1
                                         0000   BDC_SUBSCR                                                                                                                           SAPLMGD1                                1002SUB1
                                         0000   MAKT-MAKTX                                                                                                                           TESt wastage material   <<<<<<< Material Description
                                         0000   BDC_SUBSCR                                                                                                                           SAPLMGD1                                2001SUB2
                                         0000   BDC_CURSOR                                                                                                                           MARA-MEINS
                                         0000   MARA-MEINS                                                                                                                           BT <<<<< Base Unit of Measerment
                                         0000   MARA-MTPOS_MARA                                                                                                                      NORM << Standard item
                                         0000   BDC_SUBSCR                                                                                                                           SAPLMGD1                                2561SUB3
                                         0000   BDC_SUBSCR                                                                                                                           SAPLMGD1                                2007SUB4
                                         0000   BDC_SUBSCR                                                                                                                           SAPLMGD1                                2005SUB5
                                         0000   BDC_SUBSCR                                                                                                                           SAPLMGD1                                2011SUB6
                                         0000   BDC_SUBSCR                                                                                                                           SAPLMGD1                                2033SUB7
                                         0000   BDC_SUBSCR                                                                                                                           SAPLMGD1                                0001SUB8
                                         0000   BDC_SUBSCR                                                                                                                           SAPLMGD1                                0001SUB9
                                         0000   BDC_SUBSCR                                                                                                                           SAPLMGD1                                0001SUB10
SAPLSPO1                                 0300 X                                                                                                                                      
                                         0000   BDC_OKCODE                                                                                                                           =YES



List of all pages

Pages at first level

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*--------------------------------------------------------------------*
*Main Program: SAPLXF05
*Include       ZXF05U01
*Exit Name:    EXIT_SAPMF02K_001
*--- Raise event Z_EVENT_BLOCK_VENDOR to call program ZFRK026R.
*--------------------------------------------------------------------*
CALL FUNCTION 'BP_EVENT_RAISE'
  EXPORTING
    eventid                = 'Z_EVENT_BLOCK_VENDOR'
  EXCEPTIONS
    bad_eventid            = 1
    eventid_does_not_exist = 2
    eventid_missing        = 3
    raise_failed           = 4
    OTHERS                 = 5.
*--------------------------------------------------------------------*
* Program ZFRK026R
*--------------------------------------------------------------------*
FORM block_vendor  USING value(lifnr).
  CLEAR: lfa1.
  SELECT SINGLE sperr name1 INTO (lfa1-sperr, lfa1-name1) FROM lfa1
         WHERE lifnr = lifnr.
*--- Check vendor is not blocked.
  CHECK lfa1-sperr IS INITIAL.
  REFRESH: bdcdata.
*--- First Screen.
  PERFORM bdc_dynpro      USING 'SAPMF02K'          '0505'.
  PERFORM bdc_field       USING 'BDC_OKCODE'        '/00'.
  PERFORM bdc_field       USING 'RF02K-LIFNR'       lifnr.
*--- Second Screen.
  PERFORM bdc_dynpro      USING 'SAPMF02K'          '0510'.
  PERFORM bdc_field       USING 'BDC_OKCODE'        '=UPDA'.
  PERFORM bdc_field       USING 'LFA1-SPERR'        'X'.
  CALL TRANSACTION c_tcode USING bdcdata
                          MODE   ctumode
                          UPDATE cupdate.
  IF sy-subrc = 0.
    MESSAGE i020 WITH 'Call transaction FK05 to block vendor'.
  ELSE.
    MESSAGE i020 WITH 'Failure of calling FK05 to block vendor'.
  ENDIF.
ENDFORM.                    " block_vendor

Author: Brajvir Singh
Submitted: 04/02/2009

In this snippet use of BAPI_ACC_DOCUMENT_POST for posting vendor invoices will be displayed. This BAPI can also be used on the same lines for posting billing documents, goods movement and G/L account posting. Keep in mind that document total amount should be zero at the time of posting.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
**  Internal table declaration
DATA: lt_glacct  TYPE TABLE OF bapiacgl09,
      lt_vendact TYPE TABLE OF bapiacap09,
      lt_curramt TYPE TABLE OF bapiaccr09,
      lt_return  TYPE TABLE OF bapiret2.

** Workarea and variable declaration
DATA: lv_objtyp TYPE bapiache09-obj_type,
      lv_objkey TYPE bapiache09-obj_key,
      lv_objsys TYPE bapiache09-obj_sys,
      wa_docheader TYPE bapiache09,
      wa_glacct  LIKE LINE OF lt_glacct,
      wa_curramt LIKE LINE OF lt_curramt,
      wa_vendact LIKE LINE OF lt_vendact,
      wa_return  LIKE LINE OF lt_return.

**  All necessary fields for vendor invoices will be considerd.
* Populate header data of document
wa_docheader-obj_type = 'REACI'.
wa_docheader-obj_key = '$'.
wa_docheader-obj_sys = 'T90CLNT090'.
wa_docheader-bus_act = 'RMRP'.
wa_docheader-comp_code = '1000'.
wa_docheader-username = sy-uname.
wa_docheader-header_txt = 'Upload using BAPI'.
wa_docheader-doc_date = '20090331'.
wa_docheader-pstng_date = '20090331'.
wa_docheader-fisc_year = '2009'.
wa_docheader-doc_type = 'RE'.

* Account payable are maintained here
wa_vendact-itemno_acc = '0000000001'.
wa_vendact-vendor_no = '0000005200'.
wa_vendact-pmnttrms = '0001'.
wa_vendact-bline_date = '20090421'.
wa_vendact-item_text = 'Account payable'.
APPEND wa_vendact TO lt_vendact.

* Corresponding entry in GL Account
wa_glacct-itemno_acc = '0000000002'.
wa_glacct-gl_account = '0000089000'.
wa_glacct-item_text = 'GL account'.
APPEND wa_glacct TO lt_glacct.

*Make sure total amount balance for a document should be zero
wa_curramt-itemno_acc = '0000000001'.
wa_curramt-curr_type = '00'.
wa_curramt-currency = 'EUR'.
wa_curramt-amt_doccur = '-1000.00'.
APPEND wa_curramt TO lt_curramt.
CLEAR wa_curramt.

wa_curramt-itemno_acc = '0000000002'.
wa_curramt-curr_type = '00'.
wa_curramt-currency = 'EUR'.
wa_curramt-amt_doccur = '1000.00'.
APPEND wa_curramt TO lt_curramt.
CLEAR: wa_curramt,wa_glacct,wa_vendact.


CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
  EXPORTING
    documentheader = wa_docheader
  IMPORTING
    obj_type       = lv_objtyp
    obj_key        = lv_objkey
    obj_sys        = lv_objsys
  TABLES
    accountgl      = lt_glacct
    accountpayable = lt_vendact
    currencyamount = lt_curramt
    return         = lt_return.

IF sy-subrc EQ 0.
  WRITE:/ lv_objtyp.
  WRITE:/ lv_objkey.
  WRITE:/ lv_objsys.
  LOOP AT lt_return INTO wa_return.
    WRITE:/ wa_return-message.
    CLEAR wa_return.
  ENDLOOP.
  COMMIT WORK AND WAIT.
ENDIF.

Description There are many standard reports to calculate Vendor ageing based on open and clear items in Account payable accounting
FBL2N - Vendor line item
S_ALR_87012078 - Due date analysis for open items
S_ALR_87012084 - Open items - Vendor due date forecast
S_ALR_87012085 - Vendor appraisal with Open Item sorted list

Many features like reconciliation account as input, ageing based on the baseline date,  due days, item status as due or overdue, amount in 2nd local currency are not available in any single report.  Hence a customized report has been developed  where  calculation of ageing can be done on any one of options - Baseline Date/ Document Date  / Posting Date. Key date will also be provided to the end-user(s) for input, which will act as the ageing cut-off date outstanding days or are not available in any of these .  The Open & Cleared Items are represented in icons as Red & Green coloured respectively, Item status is displayed as icons to depict NOT DUE / DUE / OVERDUE line items.Relevant & proper Texts are also added in columns for the Icons used for the purpose to download the narrative of the symbols in Excel.

 

*&---------------------------------------------------------------------
*& Report   ZFI_VENDOR_AGEING_REPORT
*  Purpose            : Vendor Ageing report to calculate the outstanding days
*----------------------------------------------------------------------
REPORT zfi_vendor_ageing_report MESSAGE-ID fr.
TYPE-POOLS: icon,slis.
TABLES : bsik, bsak, lfa1, lfb1, skb1, t001, bapifvdexp_vzzbepp.
DATA : t_bsik LIKE bsik OCCURS 0 WITH HEADER LINE,
t_bsak LIKE bsak OCCURS 0 WITH HEADER LINE,
days LIKE bapifvdexp_vzzbepp-num4.
TYPES: BEGIN OF it_bsik2.
        INCLUDE STRUCTURE bsik.
TYPES: st_flag(1) TYPE c.
TYPES: END OF it_bsik2.
DATA : BEGIN OF t_lfa1 OCCURS 0,
lifnr LIKE lfa1-lifnr,
name1 LIKE lfa1-name1,
adrnr LIKE lfa1-adrnr,
END OF t_lfa1.
TYPES : BEGIN OF it_lfb1,
lifnr LIKE lfb1-lifnr,
bukrs LIKE lfb1-bukrs,
akont LIKE lfb1-akont,
END OF it_lfb1.
TYPES : BEGIN OF it_skb1,
bukrs LIKE skb1-bukrs,
saknr LIKE skb1-saknr,
END OF it_skb1.
DATA: t_lfb1 TYPE STANDARD TABLE OF it_lfb1 INITIAL SIZE 0,
t_skb1 TYPE STANDARD TABLE OF it_skb1 INITIAL SIZE 0,
t_bsik2 TYPE it_bsik2 OCCURS 0 WITH HEADER LINE,
wa_x001 LIKE x001.
DATA : BEGIN OF t_adrc OCCURS 0,
adrnr LIKE lfa1-adrnr,
street LIKE adrc-street,
city1 LIKE adrc-city1,
END OF t_adrc.
DATA : BEGIN OF it_bkpf OCCURS 0,
bukrs TYPE bukrs,
belnr TYPE belnr_d,
gjahr TYPE gjahr,
bldat TYPE bldat,
budat TYPE budat,
bktxt TYPE bktxt,
xblnr TYPE xblnr,
END OF it_bkpf.
DATA : BEGIN OF it_bseg OCCURS 0,
bukrs TYPE bukrs,
belnr TYPE belnr_d,
gjahr TYPE gjahr,
buzei TYPE buzei,
koart LIKE bseg-koart,
zfbdt LIKE bseg-zfbdt,
kostl LIKE bseg-kostl,
recid TYPE recid,
projk LIKE bseg-projk,
END OF it_bseg.
DATA : BEGIN OF t_prps OCCURS 0,
posid LIKE prps-posid,
objnr LIKE prps-objnr,
END OF t_prps.
DATA : t_kostl LIKE bseg-kostl,
t_projk LIKE bseg-projk,
t_recid LIKE bseg-recid,
text(15).
DATA : BEGIN OF t_output OCCURS 0,
lifnr TYPE lifnr,
name1 TYPE name1,
street TYPE ad_street,
city1 TYPE ad_city1,
belnr TYPE bsik-belnr,
bukrs TYPE bsik-bukrs,
gjahr TYPE gjahr,
budat TYPE budat,
bldat TYPE bldat,
zfbdt TYPE dzfbdt,
blart TYPE blart,
monat TYPE monat,
xblnr TYPE xblnr1,
xblnr2 TYPE xblnr, "BKPF
bschl TYPE bschl,
gsber TYPE gsber,
wrbtr TYPE wrbtr, "Amount in document currency
waers TYPE waers, " Currency
dmbtr TYPE dmbtr, "Amount in Local Currency
hwaer TYPE hwaer, "Local Currency
dmbe2 TYPE dmbe2, "Amount in Second Local Currency
hwae2 TYPE hwae2, "2nd Local Currency
dmbe3 TYPE dmbe2, "Amount in 3rd Local Currency
hwae3 TYPE hwae3, "3rd Local Currency
objnr TYPE prps-objnr,
posid TYPE prps-posid,
kostl TYPE kostl, " COST CENTER
prctr TYPE prctr,
umskz TYPE umskz,
hkont TYPE hkont,
zumsk TYPE dzumsk,
augbl TYPE augbl,
augdt TYPE augdt,
days TYPE bapifvdexp_vzzbepp-num4,
dif1  TYPE bsik-wrbtr,
dif2  TYPE bsik-wrbtr,
dif3  TYPE bsik-wrbtr,
dif4  TYPE bsik-wrbtr,
dif5  TYPE bsik-wrbtr,
d_flag TYPE text,
zterm TYPE dzterm, "Payment tems
zbd1t TYPE dzbd1t, "Cash discount days 1
zbd2t TYPE dzbd2t, "Cash discount days 2
zbd3t TYPE dzbd3t, "Net Payment Terms Period
zbd1p TYPE dzbd1p, "Cash Discount Percentage 1
zbd2p TYPE dzbd2p, "Cash Discount Percentage 2
vname TYPE jv_name,
egrup TYPE jv_egroup,
qsskz TYPE qsskz, "Withholding Tax Code
qsshb TYPE qsshb, "Withholding Tax Base Amount
qbshb TYPE qbshb, "Withholding Tax Amount (in Document Currency)
bktxt TYPE bktxt,
recid TYPE recid, " Recov Indicator
sgtxt TYPE sgtxt,
mwskz TYPE mwskz,
zuonr TYPE dzuonr,
ebeln TYPE ebeln,
ebelp TYPE ebelp,
due_status  TYPE text,
icon(4) TYPE c,
st_flag(1) TYPE c,
doc_status(5) TYPE c,
st_icon(4) TYPE c,
END OF t_output.
RANGES   ra_date   FOR bsak-budat .
*Alv data declaration
DATA :alv_fieldcat            TYPE slis_t_fieldcat_alv,
alv_fieldcat_line       LIKE LINE OF alv_fieldcat,
alv_sort                TYPE slis_t_sortinfo_alv,
ls_sort                 TYPE slis_sortinfo_alv,
alv_sort_line           LIKE LINE OF alv_sort,
alv_layout              TYPE slis_layout_alv,
g_repid                 LIKE sy-repid VALUE sy-repid,
alv_status_set          TYPE slis_formname VALUE 'ALV_STATUS_SET',
alv_user_comm           TYPE slis_formname VALUE 'ALV_USER_COMM',
grid_title              TYPE lvc_title,
alv_fieldcat_acty       TYPE slis_t_fieldcat_alv,
g_save,
gs_variant               TYPE disvariant,
w_variant                TYPE disvariant,
gs_variant_save(1)        TYPE c,
g_exit_caused_by_caller   TYPE c,
gs_exit_caused_by_user    TYPE slis_exit_by_user.
DATA: alv_fieldcat_line_acty  LIKE LINE OF alv_fieldcat_acty,
alv_layout_acty         TYPE slis_layout_alv,
gt_list_top_of_page     TYPE slis_t_listheader,
gt_events               TYPE slis_t_event,
message                 TYPE string,
r_ucomm     LIKE sy-ucomm,
rs_selfield TYPE slis_selfield.
DATA: lfdnr TYPE i,
waers_old LIKE t001-waers.
CONSTANTS: gc_formname_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE'.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS : s_lifnr FOR bsik-lifnr MEMORY ID lif MATCHCODE OBJECT kred,
s_bukrs FOR bsik-bukrs OBLIGATORY DEFAULT '999',
s_akont FOR lfb1-akont MATCHCODE OBJECT sako. " Reconciliation Account in General Ledger
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b11 WITH FRAME TITLE text-003.
PARAMETERS: p_open  RADIOBUTTON GROUP r1 USER-COMMAND r DEFAULT 'X', "User Command is required and always with first parameter
p_clear RADIOBUTTON GROUP r1,
p_all   RADIOBUTTON GROUP r1.
SELECTION-SCREEN SKIP 1.
SELECT-OPTIONS: s_open FOR bsak-budat  DEFAULT sy-datum NO INTERVALS NO-EXTENSION MODIF ID opn,
s_clear FOR bsak-augdt DEFAULT sy-datum NO-EXTENSION MODIF ID clr,
s_all FOR bsak-budat   DEFAULT sy-datum NO-EXTENSION MODIF ID all.
SELECTION-SCREEN END OF BLOCK b11.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS :rb_zfbdt RADIOBUTTON GROUP rb2 DEFAULT 'X'. " Base line date
PARAMETERS :rb_bldat RADIOBUTTON GROUP rb2 .            " Document Date
PARAMETERS :rb_budat RADIOBUTTON GROUP rb2 .            " Posting Date
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 01(31) text-020 FOR FIELD s_date1.
PARAMETERS: s_date1 LIKE rfpdo1-allgrogr DEFAULT '000'.
PARAMETERS: s_date2 LIKE rfpdo1-allgrogr DEFAULT '030'.
PARAMETERS: s_date3 LIKE rfpdo1-allgrogr DEFAULT '060'.
PARAMETERS: s_date4 LIKE rfpdo1-allgrogr DEFAULT '090'.
PARAMETERS: s_date5 LIKE rfpdo1-allgrogr DEFAULT '120'.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-025.
PARAMETERS: px_norm LIKE itemset-xnorm AS CHECKBOX DEFAULT 'X',
px_shbv LIKE itemset-xshbv AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK b3.
SELECTION-SCREEN BEGIN OF BLOCK list WITH FRAME TITLE text-030.
PARAMETERS: pa_vari TYPE slis_vari.
SELECTION-SCREEN END OF BLOCK list.
*----------------------------------------------------------------------
*              AT SELECTION SCREEN
*----------------------------------------------------------------------
AT SELECTION-SCREEN OUTPUT.
  PERFORM sub_screen.

INITIALIZATION.
*For variant
  PERFORM init_variant.
  PERFORM variant_default USING pa_vari.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR pa_vari.
  PERFORM alv_variant_f4 CHANGING pa_vari.

AT SELECTION-SCREEN ON s_bukrs.
  PERFORM check_bukrs.

AT SELECTION-SCREEN.
  PERFORM variant_fill.
*Checking for the input values of selection screen.
  PERFORM screen_check.
  IF NOT s_date5 IS INITIAL.
    IF  s_date5 GT s_date4
    AND s_date4 GT s_date3
    AND s_date3 GT s_date2
    AND s_date2 GT s_date1.
    ELSE.
      MESSAGE e379.
    ENDIF.
  ELSE.
    IF NOT s_date4 IS INITIAL.
      IF  s_date4 GT s_date3
      AND s_date3 GT s_date2
      AND s_date2 GT s_date1.
      ELSE.
        MESSAGE e379.
      ENDIF.
    ELSE.
      IF NOT s_date3 IS INITIAL.
        IF  s_date3 GT s_date2
        AND s_date2 GT s_date1.
        ELSE.
          MESSAGE e379.
        ENDIF.
      ELSE.
        IF NOT s_date2 IS INITIAL.
          IF  s_date2 GT s_date1.
          ELSE.
            MESSAGE e379.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.

START-OF-SELECTION.
*Authorization check for company code
  AUTHORITY-CHECK OBJECT 'F_BKPF_BUK'
  ID 'BUKRS' FIELD s_bukrs
  ID 'ACTVT' FIELD '03'.
  IF sy-subrc <> 0.
    MESSAGE e460(f5) WITH s_bukrs.
  ENDIF.
  IF p_open = 'X'.
    IF s_open IS INITIAL .
      MESSAGE 'Please enter any date' TYPE 'I'.
      LEAVE TO TRANSACTION 'ZVAGE'.
    ENDIF.
  ENDIF.
  IF p_clear = 'X'.
    IF s_clear IS INITIAL .
      MESSAGE 'Please enter any date' TYPE 'I'.
      LEAVE TO TRANSACTION 'ZVAGE'.
    ENDIF.
  ENDIF.
  IF p_all = 'X'.
    IF s_all IS INITIAL .
      MESSAGE 'Please enter any date' TYPE 'I'.
      LEAVE TO TRANSACTION 'ZVAGE'.
    ENDIF.
  ENDIF.
  PERFORM fetch_data.

END-OF-SELECTION.
  PERFORM display.
*&---------------------------------------------------------------------
*&      Form  fetch_data
*&---------------------------------------------------------------------
FORM fetch_data .
*Check Recoincilation account company code wise
  SELECT bukrs saknr FROM skb1 INTO TABLE t_skb1 WHERE bukrs IN s_bukrs
  AND saknr IN s_akont.
  IF NOT t_skb1 IS INITIAL.
    DELETE ADJACENT DUPLICATES FROM  t_skb1.
*Check vendor and its recoincilation account
    SELECT lifnr bukrs akont FROM lfb1 INTO TABLE t_lfb1 FOR ALL ENTRIES IN t_skb1
    WHERE lifnr IN s_lifnr
    AND bukrs = t_skb1-bukrs
    AND akont = t_skb1-saknr.
    IF NOT t_lfb1 IS INITIAL.
*     Fetch line item details from bsik/bsak
      PERFORM line_item_details.
      LOOP AT t_bsak.
        MOVE-CORRESPONDING t_bsak TO t_bsik2.
        APPEND t_bsik2.
        CLEAR t_bsik2.
      ENDLOOP.
*     Move Open line items to final table
      LOOP AT t_bsik.
        MOVE-CORRESPONDING t_bsik TO t_bsik2.
        MOVE 'O' TO t_bsik2-st_flag.
        APPEND t_bsik2.
        CLEAR t_bsik2.
      ENDLOOP.
      LOOP AT t_bsik2.
        IF t_bsik2-zfbdt IS INITIAL.
          t_bsik2-zfbdt = t_bsik2-bldat.
          MODIFY t_bsik2 TRANSPORTING zfbdt.
        ENDIF.
      ENDLOOP.
      SELECT lifnr name1 adrnr INTO TABLE t_lfa1 FROM lfa1 FOR ALL ENTRIES IN t_bsik2
      WHERE lifnr = t_bsik2-lifnr.
      IF sy-subrc = 0.
        SELECT addrnumber AS adrnr
        street
        city1
        INTO TABLE t_adrc
        FROM adrc
        FOR ALL ENTRIES IN t_lfa1
        WHERE addrnumber = t_lfa1-adrnr.
      ENDIF.
      SELECT bukrs belnr gjahr bldat budat bktxt xblnr INTO TABLE it_bkpf
      FROM bkpf FOR ALL ENTRIES IN t_bsik2
      WHERE bukrs = t_bsik2-bukrs
      AND   belnr = t_bsik2-belnr
      AND   gjahr = t_bsik2-gjahr.
      SELECT bukrs belnr gjahr buzei koart zfbdt  kostl recid projk
      INTO TABLE it_bseg
      FROM bseg FOR ALL ENTRIES IN t_bsik2
      WHERE bukrs = t_bsik2-bukrs
      AND   belnr = t_bsik2-rebzg
      AND   gjahr = t_bsik2-rebzj
      AND   koart IN ('K','S').
      LOOP AT t_bsik2.
        IF t_bsik2-shkzg = 'H'.
          t_bsik2-dmbtr = t_bsik2-dmbtr * -1.
          t_bsik2-wrbtr = t_bsik2-wrbtr * -1.
          t_bsik2-dmbe2 = t_bsik2-dmbe2 * -1.
          t_bsik2-dmbe3 = t_bsik2-dmbe3 * -1.
        ENDIF.
        IF t_bsik2-rebzg IS NOT INITIAL.
          LOOP AT it_bseg.
            IF it_bseg-koart = 'K' AND it_bseg-zfbdt IS NOT INITIAL.
              t_bsik2-zfbdt = it_bseg-zfbdt.
              MODIFY t_bsik2 TRANSPORTING zfbdt.
            ELSEIF it_bseg-koart = 'S'.
              t_kostl = it_bseg-kostl.
              t_projk = it_bseg-projk.
              t_recid = it_bseg-recid.
            ENDIF.
          ENDLOOP.
        ELSE.
          SELECT SINGLE kostl recid projk
          INTO (t_kostl, t_recid, t_projk)
          FROM bseg
          WHERE bukrs = t_bsik-bukrs
          AND   belnr = t_bsik-belnr
          AND   gjahr = t_bsik-gjahr
          AND   koart = 'S'.
        ENDIF.
        MOVE-CORRESPONDING t_bsik2 TO t_output.
        t_output-kostl = t_kostl.
        t_output-recid = t_recid.
        CONCATENATE 'PR' t_projk INTO t_output-objnr.
*       calculate no of days as per date selected and as per line item
*       For Base line date
        IF rb_zfbdt = 'X'.
          IF t_bsik2-st_flag IS INITIAL.
*           cleared items
            days = t_bsik2-augdt - t_bsik2-zfbdt.
          ELSE.
            days = ra_date-high - t_bsik2-zfbdt.
          ENDIF.
*       For Document date
        ELSEIF rb_bldat = 'X'.
          READ TABLE it_bkpf WITH KEY bukrs = t_bsik2-bukrs
          belnr = t_bsik2-belnr
          gjahr = t_bsik2-gjahr.
          IF t_bsik2-st_flag IS INITIAL.
*           cleared items
            days = t_bsik2-augdt - it_bkpf-bldat.
          ELSE.
            days = ra_date-high - it_bkpf-bldat.
          ENDIF.
        ELSEIF rb_budat = 'X'.
          READ TABLE it_bkpf WITH KEY bukrs = t_bsik2-bukrs
          belnr = t_bsik2-belnr
          gjahr = t_bsik2-gjahr.
          IF t_bsik2-st_flag IS INITIAL.
*           cleared items
            days = t_bsik2-augdt - it_bkpf-budat.
          ELSE.
            days = ra_date-high - it_bkpf-budat.
          ENDIF.
        ENDIF.
        t_output-bktxt = it_bkpf-bktxt.
        t_output-xblnr2 = it_bkpf-xblnr.
        READ TABLE t_lfa1 WITH KEY lifnr = t_output-lifnr.
        IF sy-subrc = 0.
          t_output-name1 = t_lfa1-name1.
          READ TABLE t_adrc WITH KEY adrnr = t_lfa1-adrnr.
          IF sy-subrc = 0.
            t_output-street = t_adrc-street.
            t_output-city1 = t_adrc-city1.
          ENDIF.
        ENDIF.
        t_output-days = days.
        IF days >= s_date1 AND days < s_date2.
          t_output-dif1 = t_bsik2-dmbtr.
          CONCATENATE ' DAYS ' s_date1 '-' s_date2 INTO text.
          t_output-d_flag = text.
        ELSEIF days >= s_date2 AND days < s_date3.
          t_output-dif2 = t_bsik2-dmbtr.
          CONCATENATE ' DAYS ' s_date2 '-' s_date3 INTO text.
          t_output-d_flag = text.
        ELSEIF days >= s_date3 AND days < s_date4.
          t_output-dif3 = t_bsik2-dmbtr.
          CONCATENATE ' DAYS ' s_date3 '-' s_date4 INTO text.
          t_output-d_flag = text.
        ELSEIF days >= s_date4 AND days < s_date5.
          t_output-dif4 = t_bsik2-dmbtr.
          CONCATENATE ' DAYS ' s_date4 '-' s_date5 INTO text.
          t_output-d_flag = text.
        ELSEIF days >= s_date5 .
          t_output-dif5 = t_bsik2-dmbtr.
          CONCATENATE ' DAYS' ' > ' s_date5 INTO text.
          t_output-d_flag = text.
        ENDIF.
*       Check whether open items
        IF t_output-st_flag = 'O'.
          t_output-doc_status = 'Open'.
          t_output-st_icon = ''. "icon_led_red
        ELSEIF  t_output-st_flag = ' '.
          t_output-doc_status = 'Close'.
          t_output-st_icon = ''. "ICON_LED_GREEN
        ENDIF.
*       Due status on the basis of Payment terms for open items
*       Due days LT 1st  part of term - Not Due
*       Due days lesser or EQ than 3rd  part of term & GT 1st  part of term - Due
*       Due days GT than 3rd  part of term- Over Due
        IF NOT t_output-st_flag IS INITIAL.
          IF t_output-days LT t_bsik2-zbd1t.
            t_output-due_status = 'Not due'.
            t_output-icon = ''. "ICON_RESUBMISSION
          ELSEIF t_output-days LE t_bsik2-zbd3t AND  t_output-days GT t_bsik2-zbd1t.
            t_output-due_status = 'Due'.
            t_output-icon = ''. "icon_alarm
          ELSEIF t_output-days GT t_bsik2-zbd3t.
            t_output-due_status = 'Overdue'.
            t_output-icon = ''. "ICON_ALERT
          ENDIF.
        ENDIF.
*       get local currency as per company code
        PERFORM currency_info.
        APPEND t_output.
        CLEAR: t_bsik2, it_bkpf, t_output, days, t_kostl, t_projk, t_recid.
      ENDLOOP.
      IF t_output[] IS NOT INITIAL.
        SELECT posid
        objnr
        INTO TABLE t_prps
        FROM prps
        FOR ALL ENTRIES IN t_output
        WHERE objnr = t_output-objnr.
      ENDIF.
      LOOP AT t_output.
        READ TABLE t_prps WITH KEY objnr = t_output-objnr.
        IF sy-subrc = 0.
          t_output-posid = t_prps-posid.
          MODIFY t_output TRANSPORTING posid.
        ENDIF.
      ENDLOOP.
    ENDIF.
  ENDIF.
ENDFORM.                    " fetch_data
*&---------------------------------------------------------------------
*&      Form  display
*&---------------------------------------------------------------------
FORM display .
  PERFORM build_alv_layout.
*  PERFORM s_sort_build USING alv_sort[].
  PERFORM build_field_catalogs.
  PERFORM eventtab_build CHANGING gt_events.
  g_save = 'A'.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program      = g_repid
      i_callback_user_command = alv_user_comm
      i_grid_title            = grid_title
      i_save                  = g_save
      is_variant              = gs_variant
      is_layout               = alv_layout
      it_fieldcat             = alv_fieldcat[]
      it_events               = gt_events[]
      it_sort                 = alv_sort[]
    IMPORTING
      e_exit_caused_by_caller = g_exit_caused_by_caller
      es_exit_caused_by_user  = gs_exit_caused_by_user
    TABLES
      t_outtab                = t_output.
  PERFORM alv_user_comm USING r_ucomm
  rs_selfield.
  IF sy-subrc = 0.
    IF g_exit_caused_by_caller = 'X'.
    ELSE.
      IF gs_exit_caused_by_user-back = 'X'.                 " F3
      ELSE.
        IF gs_exit_caused_by_user-exit = 'X'.               " F15
        ELSE.
          IF gs_exit_caused_by_user-cancel = 'X'.           " F12
          ELSE.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.
ENDFORM.                    " display
*&---------------------------------------------------------------------
*&      Form  build_alv_layout
*&---------------------------------------------------------------------
FORM build_alv_layout.
  CLEAR alv_layout.
  alv_layout-colwidth_optimize  = 'X'. "always display full columns
*  alv_layout-box_tabname        = 'T_OUTPUT'.
  alv_layout-info_fieldname     = 'COLOR'. "color a line
  alv_layout-detail_popup       = 'X'.
  alv_layout-zebra              = 'X'. "Zebra output
ENDFORM.                    " build_alv_layout
*---------------------------------------------------------------------
*       FORM s_sort_build                                             *
*---------------------------------------------------------------------
FORM s_sort_build USING lt_sort TYPE slis_t_sortinfo_alv.
  CLEAR  ls_sort.
  ls_sort-spos      =  1.
  ls_sort-fieldname =  'LIFNR'.
  ls_sort-up        =  'X'.
  ls_sort-group     =  'UL'.
  ls_sort-subtot       =  'X'.
  APPEND ls_sort TO lt_sort.
  CLEAR  ls_sort.
  ls_sort-spos      =  2.
  ls_sort-fieldname =  'BELNR'.
  ls_sort-up        =  'X'.
  ls_sort-subtot       =  'X'.
  ls_sort-group     =  'UL'.
  APPEND ls_sort TO lt_sort.
  CLEAR  ls_sort.
ENDFORM.                    "s_sort_build
*&---------------------------------------------------------------------
*&      Form  eventtab_build
*&---------------------------------------------------------------------
FORM eventtab_build CHANGING lt_events TYPE slis_t_event.
  FIELD-SYMBOLS: <lt_events> LIKE LINE OF lt_events.
  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
      i_list_type     = 0
    IMPORTING
      et_events       = lt_events
    EXCEPTIONS
      list_type_wrong = 1
      OTHERS          = 2.
*Define TOP_OF_PAGE event
  READ TABLE lt_events WITH KEY name = slis_ev_top_of_page
  ASSIGNING <lt_events>.
  IF sy-subrc EQ 0.
    MOVE gc_formname_top_of_page TO <lt_events>-form.
  ENDIF.
ENDFORM.                    " eventtab_build
*&---------------------------------------------------------------------
*&      Form  TOP_OF_PAGE
*&---------------------------------------------------------------------
FORM top_of_page.
  REFRESH gt_list_top_of_page.
  CLEAR gt_list_top_of_page.
  PERFORM comment_build USING gt_list_top_of_page.
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = gt_list_top_of_page.
ENDFORM.                    "top_of_page
*&---------------------------------------------------------------------
*&      Form  COMMENT_BUILD
*&---------------------------------------------------------------------
*Build comments at top of page
*----------------------------------------------------------------------
FORM comment_build CHANGING gt_top_of_page TYPE slis_t_listheader.
  DATA: gs_line TYPE slis_listheader.
  CLEAR gs_line.
  gs_line-typ  = 'H'.
  gs_line-info = 'Vendor Ageing Report'.
  APPEND gs_line TO gt_top_of_page.
  CLEAR gs_line.
  gs_line-typ  = 'S'.
  gs_line-key  = 'Key Date:'.
  WRITE ra_date-high TO gs_line-info MM/DD/YYYY.
  APPEND gs_line TO gt_top_of_page.
  CLEAR gs_line.
  gs_line-typ  = 'S'.
  gs_line-key  = 'Time:'.
  WRITE sy-uzeit TO gs_line-info USING EDIT MASK '_::_'.
  APPEND gs_line TO gt_top_of_page.
  CLEAR gs_line.
  gs_line-typ  = 'S'.
  gs_line-key  = ''.
  WRITE ' '.
  APPEND gs_line TO gt_top_of_page.
ENDFORM.                    "comment_build
*----------------------------------------------------------------------
*Build ALV Summary field catalog
*----------------------------------------------------------------------
*&---------------------------------------------------------------------
*&      Form  build_field_catalogs
*&---------------------------------------------------------------------
FORM build_field_catalogs.
  CLEAR: alv_fieldcat.
  REFRESH: alv_fieldcat.
*Vendor Number
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Vendor Number'.
  alv_fieldcat_line-fieldname  = 'LIFNR'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Vendor Name
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Vendor Name'.
  alv_fieldcat_line-fieldname  = 'NAME1'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Vendor Address
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Vendor Address'.
  alv_fieldcat_line-fieldname  = 'STREET'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*City
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'City'.
  alv_fieldcat_line-fieldname  = 'CITY1'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Document No.
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-hotspot = 'X'.
  alv_fieldcat_line-seltext_l = 'Document No.'.
  alv_fieldcat_line-fieldname  = 'BELNR'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Co Code
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Co Code'.
  alv_fieldcat_line-fieldname  = 'BUKRS'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Fiscal year
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Fiscal year'.
  alv_fieldcat_line-fieldname  = 'GJAHR'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Posting Date
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Posting Date'.
  alv_fieldcat_line-fieldname  = 'BUDAT'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Doc Date
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Doc Date'.
  alv_fieldcat_line-fieldname  = 'BLDAT'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Baseline Date
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Baseline Date'.
  alv_fieldcat_line-fieldname  = 'ZFBDT'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Document Type
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Document Type'.
  alv_fieldcat_line-fieldname  = 'BLART'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Fiscal Period
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Fiscal Period'.
  alv_fieldcat_line-fieldname  = 'MONAT'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Reference
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Reference'.
  alv_fieldcat_line-fieldname  = 'XBLNR'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Ref Document No.
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Ref Doc No.'.
  alv_fieldcat_line-fieldname  = 'XBLNR2'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Posting Key
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Posting Key'.
  alv_fieldcat_line-fieldname  = 'BSCHL'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Bus Area
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Business Area'.
  alv_fieldcat_line-fieldname  = 'GSBER'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Amount in Doc curr
  alv_fieldcat_line-tabname = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Amount in Doc curr'.
  alv_fieldcat_line-fieldname  = 'WRBTR'.
  alv_fieldcat_line-no_out  = 'X'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
*Currency
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Currency'.
  alv_fieldcat_line-fieldname  = 'WAERS'.
  alv_fieldcat_line-no_out  = 'X'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
*Amount in Local Currency
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Amount in LCurr'.
  alv_fieldcat_line-fieldname  = 'DMBTR'.
  alv_fieldcat_line-no_out  = 'X'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
*Local Currency
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Local Curr'.
  alv_fieldcat_line-fieldname  = 'HWAER'.
  alv_fieldcat_line-no_out  = 'X'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
*Amount in 2nd Local Currency
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Amount in S Lcurr'.
  alv_fieldcat_line-fieldname  = 'DMBE2'.
  alv_fieldcat_line-no_out  = 'X'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
*Local Currency
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Second LCurr'.
  alv_fieldcat_line-fieldname  = 'HWAE2'.
  alv_fieldcat_line-no_out  = 'X'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
*Amount in 2nd Local Currency
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Amount in third Lcurr'.
  alv_fieldcat_line-fieldname  = 'DMBE3'.
  alv_fieldcat_line-no_out  = 'X'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
*Local Currency
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Third LCurr'.
  alv_fieldcat_line-fieldname  = 'HWAE3'.
  alv_fieldcat_line-no_out  = 'X'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
*Object number #
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Object No'.
  alv_fieldcat_line-fieldname  = 'OBJNR'.
  alv_fieldcat_line-no_out  = 'X'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*WBS Element
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'WBS Element'.
  alv_fieldcat_line-fieldname = 'POSID'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
*Cost Center
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Cost Center'.
  alv_fieldcat_line-fieldname = 'KOSTL'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
*Profit Center
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Profit Center'.
  alv_fieldcat_line-fieldname = 'PRCTR'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
*GL Indicator
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'GL Indicator'.
  alv_fieldcat_line-fieldname = 'UMSKZ'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*General Ledger Account
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'G/L Account'.
  alv_fieldcat_line-fieldname = 'HKONT'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
*Special G/L Indicator
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Sp G/L Indicator'.
  alv_fieldcat_line-fieldname  = 'ZUMSK'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Clearing Doc
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Clearing Doc.'.
  alv_fieldcat_line-fieldname = 'AUGBL'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Clearing  Date
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Clearing Date'.
  alv_fieldcat_line-fieldname  = 'AUGDT'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Days
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Days'.
  alv_fieldcat_line-fieldname  = 'DAYS'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
*dif1
  CLEAR text.
  CONCATENATE ' DAYS ' s_date1 '-' s_date2 INTO text.
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = text.
  alv_fieldcat_line-fieldname = 'DIF1'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*dif2
  CLEAR text.
  CONCATENATE ' DAYS ' s_date2 '-' s_date3 INTO text.
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = text.
  alv_fieldcat_line-fieldname = 'DIF2'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*dif3
  CLEAR text.
  CONCATENATE 'DAYS ' s_date3 '-' s_date4 INTO text.
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = text.
  alv_fieldcat_line-fieldname = 'DIF3'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*dif4
  CLEAR text.
  CONCATENATE 'DAYS ' s_date4 '-' s_date5 INTO text.
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = text.
  alv_fieldcat_line-fieldname  = 'DIF4'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
*dif5
  CLEAR text.
  CONCATENATE ' DAYS' ' > ' s_date5 INTO text.
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = text.
  alv_fieldcat_line-fieldname  = 'DIF5'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
*No of Days
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'No of Days'.
  alv_fieldcat_line-fieldname = 'D_FLAG'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Payment terms
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Payment Terms'.
  alv_fieldcat_line-fieldname = 'ZTERM'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Cash discount days 1
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Cash Dis days 1'.
  alv_fieldcat_line-fieldname = 'ZBD1T'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Cash discount days 2
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Cash Dis days 2'.
  alv_fieldcat_line-fieldname = 'ZBD2T'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Net Payment Terms Period
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Net Payment Terms'.
  alv_fieldcat_line-fieldname = 'ZBD3T'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Cash Discount Percentage 1
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Cash Discount 1'. 2'.
  alv_fieldcat_line-fieldname = 'ZBD2P'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*  Assignment Number
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Assignment No'.
  alv_fieldcat_line-fieldname = 'ZUONR'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*  Header text
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Header Text'.
  alv_fieldcat_line-fieldname = 'BKTXT'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Item Text
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Item Text'.
  alv_fieldcat_line-fieldname = 'SGTXT'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*  Joint Venture
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Joint Venture'.
  alv_fieldcat_line-fieldname = 'VNAME'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*  Equity group
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Equity group'.
  alv_fieldcat_line-fieldname = 'EGRUP'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Recovery Indicator
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Recovery Indicator'.
  alv_fieldcat_line-fieldname  = 'RECID'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Withholding Tax Code
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Withholding Tax Code'.
  alv_fieldcat_line-fieldname = 'QSSKZ'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Withholding Tax Base Amount
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Withholding Tax Base Amount'.
  alv_fieldcat_line-fieldname = 'QSSHB'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Withholding Tax Base Amount
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Withholding Tax Amount'.
  alv_fieldcat_line-fieldname = 'QBSHB'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Purchasing Doc
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Purchasing Doc'.
  alv_fieldcat_line-fieldname = 'EBELN'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Purchasing Item
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Purchasing Item'.
  alv_fieldcat_line-fieldname = 'EBELP'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*  Due Status
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Due Status'.
  alv_fieldcat_line-fieldname = 'DUE_STATUS'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*  Due icon
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Due icon'.
  alv_fieldcat_line-fieldname = 'ICON'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Document Status
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Doc. Status'.
  alv_fieldcat_line-fieldname  = 'DOC_STATUS'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
*Document Status icon
  alv_fieldcat_line-tabname    = 'T_OUTPUT'.
  alv_fieldcat_line-seltext_l = 'Status icon'.
  alv_fieldcat_line-fieldname = 'ST_ICON'.
  APPEND alv_fieldcat_line TO alv_fieldcat.
  CLEAR alv_fieldcat_line.
ENDFORM.                    " build_field_catalogs
*&---------------------------------------------------------------------
*&      Form  ALV_USER_COMM
*&---------------------------------------------------------------------
*Process User Status
*----------------------------------------------------------------------
FORM alv_user_comm USING r_ucomm     LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
*Determine the main component beign viewed
  READ TABLE t_output INDEX rs_selfield-tabindex.
  CASE r_ucomm.
    WHEN '&IC1'.       " single / double click
      CASE rs_selfield-fieldname.
*       Display FI document
        WHEN 'BELNR'.
          SET PARAMETER ID 'BLN' FIELD t_output-belnr.
          SET PARAMETER ID 'BUK' FIELD t_output-bukrs.
          SET PARAMETER ID 'GJR' FIELD t_output-gjahr.
          CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.
      ENDCASE.
  ENDCASE.
ENDFORM.                    "alv_user_comm
*&---------------------------------------------------------------------
*&      Form  ALV_STATUS_SET
*&---------------------------------------------------------------------
*Set the status for the ALV screen
*----------------------------------------------------------------------
FORM alv_status_set USING rt_extab TYPE slis_t_extab.
  SET PF-STATUS 'STANDARD' EXCLUDING rt_extab.
ENDFORM.                    "alv_status_set
*&---------------------------------------------------------------------
*&      Form  ALV_VARIANT_F4
*&---------------------------------------------------------------------
FORM alv_variant_f4  CHANGING p_pa_vari.
  DATA nof4 TYPE c.
  CLEAR nof4.
  LOOP AT SCREEN.
    IF screen-name = 'PA_VARI'.
      IF screen-input = 0.
        nof4 = 'X'.
      ENDIF.
    ENDIF.
  ENDLOOP.
  gs_variant-report   = g_repid.
  gs_variant-username = sy-uname.
  CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
    EXPORTING
      is_variant = gs_variant
      i_save     = 'A'
    IMPORTING
      es_variant = gs_variant
    EXCEPTIONS
      OTHERS     = 1.
  IF sy-subrc = 0 AND nof4 EQ space.
    pa_vari = gs_variant-variant.
  ENDIF.
ENDFORM.                    " ALV_VARIANT_F4
*&---------------------------------------------------------------------
*&      Form  CHECK_BUKRS
*&---------------------------------------------------------------------
FORM check_bukrs .
  IF s_bukrs-low NE space.
    lfdnr = 0.
    waers_old = space.
    SELECT * FROM t001
    WHERE bukrs IN s_bukrs.
      lfdnr = lfdnr + 1.
      IF lfdnr = 1.
        waers_old = t001-waers.
      ENDIF.
      IF waers_old NE t001-waers.
        MESSAGE e181(fr).
      ENDIF.
    ENDSELECT.
    lfdnr = 0.
  ENDIF.
ENDFORM.                    " CHECK_BUKRS
*&---------------------------------------------------------------------
*&      Form  SCREEN_CHECK
*&---------------------------------------------------------------------
FORM screen_check .
*Validation of Vendor Number
  CLEAR lfa1-lifnr.
  IF NOT s_lifnr IS INITIAL.
    SELECT lifnr FROM lfa1 UP TO 1 ROWS
    INTO lfa1-lifnr
    WHERE lifnr IN s_lifnr.
    ENDSELECT.
    IF sy-subrc NE 0.
      MESSAGE e318.
    ENDIF.
  ENDIF.
*Validation of Company Code
  CLEAR t001-bukrs.
  IF NOT s_bukrs IS INITIAL.
    SELECT bukrs FROM t001 UP TO 1 ROWS
    INTO t001-bukrs
    WHERE bukrs IN s_bukrs.
    ENDSELECT.
    IF sy-subrc NE 0.
      MESSAGE 'Invalid Company Code' TYPE 'E'.
    ENDIF.
  ENDIF.
*Validation of Recoincilation Account
  IF NOT s_akont IS INITIAL.
    CLEAR skb1-saknr.
    SELECT saknr FROM skb1 UP TO 1 ROWS
    INTO skb1-saknr WHERE bukrs IN s_bukrs
    AND saknr IN s_akont.
    ENDSELECT.
    IF sy-subrc NE 0.
      MESSAGE 'Invalid Recoincilation Account' TYPE 'E'.
    ENDIF.
  ENDIF.
ENDFORM.                    " SCREEN_CHECK
*&---------------------------------------------------------------------
*&      Form  INIT_VARIANT
*&---------------------------------------------------------------------
FORM init_variant .
*set variant:
  REFRESH: alv_fieldcat,gt_events, gt_list_top_of_page.
  CLEAR: alv_fieldcat, gt_events, gt_list_top_of_page.
  CLEAR: gs_variant.
  g_repid = sy-repid.
  gs_variant-report = g_repid.
  gs_variant-username = sy-uname.
  gs_variant-variant  = pa_vari.
  gs_variant_save = 'A'.  " All type
ENDFORM.                    " INIT_VARIANT
*&---------------------------------------------------------------------
*&      Form  VARIANT_DEFAULT
*&---------------------------------------------------------------------
FORM variant_default  USING  p_variant.
  w_variant = gs_variant.
  CALL FUNCTION 'LVC_VARIANT_DEFAULT_GET'
    EXPORTING
      i_save        = gs_variant_save
    CHANGING
      cs_variant    = w_variant
    EXCEPTIONS
      wrong_input   = 1
      not_found     = 2
      program_error = 3
      OTHERS        = 4.
  CASE sy-subrc.
    WHEN 0.
      p_variant = w_variant-variant.
    WHEN 2.
      CLEAR p_variant.
  ENDCASE.
ENDFORM.                    " VARIANT_DEFAULT
*&---------------------------------------------------------------------
*&      Form  VARIANT_FILL
*&---------------------------------------------------------------------
FORM variant_fill .
  CLEAR gs_variant.
  IF pa_vari IS INITIAL.
    gs_variant-variant = 'STANDARD'.
    gs_variant-report = g_repid.
  ELSE.
    gs_variant-variant = pa_vari.
    gs_variant-report = g_repid.
    CALL FUNCTION 'LVC_VARIANT_EXISTENCE_CHECK'
      EXPORTING
        i_save     = gs_variant_save
      CHANGING
        cs_variant = gs_variant
      EXCEPTIONS
        OTHERS     = 01.
  ENDIF.
ENDFORM.                    " VARIANT_FILL
*&---------------------------------------------------------------------
*&      Form  SUB_SCREEN
*&---------------------------------------------------------------------
FORM sub_screen .
  LOOP AT SCREEN.
    IF p_open = 'X'.
      IF screen-group1 = 'CLR'.
        screen-active  = '0'.
        MODIFY SCREEN.
      ENDIF.
      IF screen-group1 = 'ALL'.
        screen-active  = '0'.
        MODIFY SCREEN.
      ENDIF.
    ELSEIF p_clear = 'X'.
      IF screen-group1 = 'OPN'.
        screen-active  = '0'.
        MODIFY SCREEN.
      ENDIF.
      IF screen-group1 = 'ALL'.
        screen-active  = '0'.
        MODIFY SCREEN.
      ENDIF.
    ELSEIF p_all = 'X'.
      IF screen-group1 = 'OPN'.
        screen-active  = '0'.
        MODIFY SCREEN.
      ENDIF.
      IF screen-group1 = 'CLR'.
        screen-active  = '0'.
        MODIFY SCREEN.
      ENDIF.
    ENDIF.
  ENDLOOP.
ENDFORM.                    " SUB_SCREEN
*&---------------------------------------------------------------------
*&      Form  LINE_ITEM_DETAILS
*&---------------------------------------------------------------------
FORM line_item_details .
*Fetch line item details as per status - Open/Clear/All
*For Open Items
  IF p_open = 'X' .
    ra_date-high    = s_open-low.
    IF px_shbv = 'X' AND px_norm = ''.
*     for sp G/L indicator
      SELECT * FROM bsik  INTO TABLE t_bsik
      WHERE bukrs IN s_bukrs
      AND   lifnr IN s_lifnr
      AND   umskz <> ''
      AND   budat LE ra_date-high
      AND   bstat NOT IN ('M' ,'S', 'V' ,'W' ,'Z').
    ELSEIF px_norm = 'X' AND px_shbv = '' .
*     for Normal items
      SELECT * FROM bsik  INTO TABLE t_bsik
      WHERE bukrs IN s_bukrs
      AND   lifnr IN s_lifnr
      AND   umskz = ''
      AND   budat LE ra_date-high
      AND   bstat NOT IN ('M' ,'S', 'V' ,'W' ,'Z').
    ELSEIF px_norm = 'X' AND px_shbv = 'X' .
*     for Normal items & Sp G/L indicator
      SELECT * FROM bsik  INTO TABLE t_bsik
      WHERE bukrs IN s_bukrs
      AND   lifnr IN s_lifnr
      AND   budat LE ra_date-high
      AND   bstat NOT IN ('M' ,'S', 'V' ,'W' ,'Z').
    ENDIF.
*For Clear Line Items
  ELSEIF p_clear = 'X' .
    IF s_clear-high IS INITIAL.
      ra_date-high    = s_clear-low.
    ELSE.
      ra_date-high    = s_clear-high.
    ENDIF.
    IF px_shbv = 'X' AND px_norm = ''.
      SELECT * FROM bsak INTO TABLE t_bsak  WHERE bukrs IN s_bukrs
      AND   lifnr IN s_lifnr
      AND   umskz <> ''
      AND   augdt IN s_clear
      AND   bstat NOT IN ('M' ,'S', 'V' ,'W' ,'Z').
    ELSEIF px_norm = 'X' AND px_shbv = '' .
      SELECT * FROM bsak INTO TABLE t_bsak  WHERE bukrs IN s_bukrs
      AND   lifnr IN s_lifnr
      AND   umskz = ''
      AND   augdt IN s_clear
      AND   bstat NOT IN ('M' ,'S', 'V' ,'W' ,'Z').
    ELSEIF px_norm = 'X' AND px_shbv = 'X' .
      SELECT * FROM bsak INTO TABLE t_bsak  WHERE bukrs IN s_bukrs
      AND   lifnr IN s_lifnr
      AND   augdt IN s_clear
      AND   bstat NOT IN ('M' ,'S', 'V' ,'W' ,'Z').
    ENDIF.
*For All Line Items
  ELSEIF p_all = 'X' .
    IF s_all-high IS INITIAL.
      ra_date-high    = s_all-low.
    ELSE.
      ra_date-high    = s_all-high.
    ENDIF.
    IF px_shbv = 'X' AND px_norm = ''.
      SELECT * FROM bsik INTO TABLE t_bsik  WHERE bukrs IN s_bukrs
      AND   lifnr IN s_lifnr
      AND   umskz <> ''
      AND   budat IN s_all
      AND   bstat NOT IN ('M' ,'S', 'V' ,'W' ,'Z').
      SELECT * FROM bsak INTO TABLE t_bsak WHERE bukrs IN s_bukrs
      AND   lifnr IN s_lifnr
      AND   umskz <> ''
      AND   augdt IN s_all
      AND   bstat NOT IN ('M' ,'S', 'V' ,'W' ,'Z').
    ELSEIF px_norm = 'X' AND px_shbv = '' .
      SELECT * FROM bsik INTO TABLE t_bsik  WHERE bukrs IN s_bukrs
      AND   lifnr IN s_lifnr
      AND   umskz = ''
      AND   budat IN s_all
      AND   bstat NOT IN ('M' ,'S', 'V' ,'W' ,'Z').
      SELECT * FROM bsak INTO TABLE t_bsak  WHERE bukrs IN s_bukrs
      AND   lifnr IN s_lifnr
      AND   umskz = ''
      AND   augdt IN s_all
      AND   bstat NOT IN ('M' ,'S', 'V' ,'W' ,'Z').
    ELSEIF px_norm = 'X' AND px_shbv = 'X' .
      SELECT * FROM bsik INTO TABLE t_bsik  WHERE bukrs IN s_bukrs
      AND   lifnr IN s_lifnr
      AND   budat IN s_all
      AND   bstat NOT IN ('M' ,'S', 'V' ,'W' ,'Z').
      SELECT * FROM bsak INTO TABLE t_bsak  WHERE bukrs IN s_bukrs
      AND   lifnr IN s_lifnr
      AND   augdt IN s_all
      AND   bstat NOT IN ('M' ,'S', 'V' ,'W' ,'Z').
    ENDIF.
  ENDIF.
ENDFORM.                    " LINE_ITEM_DETAILS
*&---------------------------------------------------------------------
*&      Form  CURRENCY_INFO
*&---------------------------------------------------------------------
FORM currency_info .
*get local currency - 2nd & 3rd currency
  SELECT SINGLE waers FROM t001 INTO t_output-hwaer
  WHERE bukrs = t_output-bukrs.
  CLEAR: wa_x001.
  CALL FUNCTION 'FI_CURRENCY_INFORMATION'
    EXPORTING
      i_bukrs                = t_output-bukrs
    IMPORTING
      e_x001                 = wa_x001
    EXCEPTIONS
      currency_2_not_defined = 1
      currency_3_not_defined = 2
      OTHERS                 = 3.
  t_output-hwae2 = wa_x001-hwae2.
  t_output-hwae3 = wa_x001-hwae3.
ENDFORM.                    " CURRENCY_INFO
 
*------------------------------------------------------*
* This is the program for getting the particular
* communication address details for the given vendor
* Here i am getting address type ADSMTP.
*------------------------------------------------------*
REPORT zaddress_mail.
TABLES: lfa1.
*----types for vendor data
TYPES: BEGIN OF ty_lfa1,
  lifnr LIKE lfa1-lifnr,
  adrnr LIKE lfa1-adrnr,
END OF ty_lfa1.
TYPES: BEGIN OF ty_email,
  adress TYPE char50,
END OF ty_email.
*---workares defined and internal table declaration
DATA: wa_lfa1 TYPE ty_lfa1 ,
      it_email TYPE STANDARD TABLE OF ty_email WITH HEADER LINE.

*----selection screen
PARAMETERS:p_lifnr LIKE lfa1-lifnr.
*--start of selection
START-OF-SELECTION.
*-get vendor address number
  SELECT SINGLE lifnr adrnr
    FROM lfa1
    INTO wa_lfa1
    WHERE lifnr = p_lifnr.
*--get particular address data
  CALL FUNCTION 'ADDR_PERS_COMP_COMM_GET'
    EXPORTING
      address_handle = ''
      address_number = wa_lfa1-adrnr"<---address number
      language       = sy-langu
      table_type     = 'ADSMTP' "<---address type
    TABLES
      comm_table     = it_email.
*---process the data
  LOOP AT it_email.
    WRITE:/ it_email-adress.
  ENDLOOP.
 
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
REPORT  zvendor1_3 MESSAGE-ID m7.

INCLUDE zvendor1_3top.
INCLUDE zvendor1_3sels.
INCLUDE zvendor1_3cls.
INCLUDE zvendor1_3form.

INCLUDE zvendor1_3main.

*&---------------------------------------------------------------------*
*&  Include           ZVENDOR1_3TOP
*&---------------------------------------------------------------------*
TYPE-POOLS: mbarc, slis.

INCLUDE <color>.

INCLUDE <icon>.
INCLUDE <symbol>.

TABLES: ekko,
        ekpo,
        eket,
        mara,
        mkpf,
        t147,
        t009b.    " mmim_rep_cust.

**********************************************************************
******   Types Definition
**********************************************************************
TYPES: BEGIN OF ty_scr_result,
       vendor TYPE lifnr ,
       vend_name TYPE name1_gp ,
       po_number TYPE ebeln ,
       po_item TYPE ebelp,
       disp_quan TYPE ekpo-menge ,
       calca TYPE erfmg ,
       calcb TYPE erfmg ,
       calc_score TYPE string ,
       eindt TYPE eindt,
       rdtt  TYPE eindt,
       t_color     TYPE lvc_t_scol,
       t_celltype  TYPE salv_t_int4_column,
       t_hyperlink TYPE salv_t_int4_column,
       t_dropdown  TYPE salv_t_int4_column,
       END OF ty_scr_result.
**********************************************************************
******   Constants Definition
**********************************************************************
CONSTANTS : gc_plant TYPE ewerk VALUE '4968',
            gc_purch_org TYPE ekorg VALUE '4968'.

**********************************************************************
******   Data Definition
**********************************************************************
DATA: gt_po_headers TYPE TABLE OF  bapiekkol,
      gt_po_items   TYPE TABLE OF  bapiekpoc,
      gt_return     TYPE TABLE OF  bapireturn,
      gt_goodsmvt_header  TYPE TABLE OF bapi2017_gm_head_02,
      gt_goodsmvt_items  TYPE TABLE OF  bapi2017_gm_item_show,
      gt_eket       TYPE TABLE OF  eket ,
      gt_screen_result TYPE TABLE OF  ty_scr_result,
      gv_srv_grp TYPE rfcgr,
      gv_max_wps TYPE i,
      gv_free_wps TYPE i,
      gv_task1 TYPE c VALUE space ,
      gv_task_guid TYPE /osp/dt_sapid.

**********************************************************************
******   New Alv Definition
**********************************************************************
CLASS lcl_handle_events DEFINITION DEFERRED .

DATA: gr_table TYPE REF TO cl_salv_table,
      "gr_functions TYPE REF TO cl_salv_functions,
      gr_functions TYPE REF TO cl_salv_functions_list,
      gr_display TYPE REF TO cl_salv_display_settings,
      gr_columns TYPE REF TO cl_salv_columns_table,
      gr_column TYPE REF TO cl_salv_column_table,
      event_handler TYPE REF TO lcl_handle_events,
      gr_events TYPE REF TO cl_salv_events_table,
      gr_selections TYPE REF TO cl_salv_selections,
      gr_sorts TYPE REF TO cl_salv_sorts,
      gs_color TYPE lvc_s_colo.

*&---------------------------------------------------------------------*
*&  Include           ZVENDOR1_3SELS
*&---------------------------------------------------------------------*

SELECTION-SCREEN BEGIN OF BLOCK sblck WITH FRAME TITLE text-001.

SELECT-OPTIONS lifnr FOR ekko-lifnr  MEMORY ID lif OBLIGATORY.
SELECT-OPTIONS matnr FOR mara-matnr  MEMORY ID mat MATCHCODE OBJECT mat1.

PARAMETER werks TYPE mseg-werks MEMORY ID wrk DEFAULT gc_plant.

SELECT-OPTIONS pohead FOR ekko-ebeln  MEMORY ID bes.
SELECT-OPTIONS poitem FOR ekpo-ebelp  MEMORY ID bsp.
SELECT-OPTIONS reqdate FOR eket-eindt OBLIGATORY.
SELECT-OPTIONS budat FOR mkpf-budat.

SELECTION-SCREEN END OF BLOCK sblck.

*&---------------------------------------------------------------------*
*&  Include           ZVENDOR1_3CLS
*&---------------------------------------------------------------------*
CLASS lcl_handle_events DEFINITION.
  PUBLIC SECTION.
    METHODS: on_user_command FOR EVENT added_function OF cl_salv_events IMPORTING e_salv_function,
           on_double_click FOR EVENT double_click OF cl_salv_events_table IMPORTING row column.
ENDCLASS.                    "lcl_handle_events DEFINITION

*----------------------------------------------------------------------*
*       CLASS lcl_handle_events IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_handle_events IMPLEMENTATION.
  METHOD on_user_command.
** get the selection rows data: lr_selections type ref to cl_salv_selections.
*    DATA: lr_selections TYPE REF TO cl_salv_selections.
*    DATA: lt_rows TYPE salv_t_row.
*    DATA: ls_rows TYPE i.
*    DATA: message TYPE string.
*
*    CASE e_salv_function.
*      WHEN 'MYFUNCTION'.
*        lr_selections = gr_table->get_selections( ).
*        lt_rows = lr_selections->get_selected_rows( ).
*        READ TABLE lt_rows INTO ls_rows INDEX 1.
**        READ TABLE ispfli INTO xspfli INDEX ls_rows.
**        CONCATENATE xspfli-carrid xspfli-connid xspfli-cityfrom xspfli-cityto
**         INTO message SEPARATED BY space.
*
*        MESSAGE i001(00) WITH 'You pushed the button!' message.
*    ENDCASE.
  ENDMETHOD. "on_user_command method on_double_click.
  METHOD on_double_click.
    FIELD-SYMBOLS : <lfs_scr_result> TYPE ty_scr_result .

    DATA : lv_form_name TYPE string VALUE 'EH_ON_'.

*    DATA: message TYPE string.
*    DATA: row_c(4) TYPE c.
*
*    row_c = row.
*    CONCATENATE 'Row' row_c 'Column' column INTO message SEPARATED BY space.
*    MESSAGE i001(00) WITH 'You double-clicked on ' message.

    CHECK column = 'PO_ITEM'
       OR column = 'PO_NUMBER'.

    READ TABLE gt_screen_result[] ASSIGNING <lfs_scr_result> INDEX row .

    CHECK <lfs_scr_result> IS ASSIGNED .

    CONCATENATE lv_form_name column INTO lv_form_name.

    PERFORM (lv_form_name) IN PROGRAM zvendor1_3 USING <lfs_scr_result>.

    UNASSIGN <lfs_scr_result>.
  ENDMETHOD.                    "on_double_click
ENDCLASS.                    "lcl_handle_events IMPLEMENTATION

*&---------------------------------------------------------------------*
*&  Include           ZVENDOR1_3FORM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  INITIALIZATION
*&---------------------------------------------------------------------*
FORM initialization .
  CALL FUNCTION 'SPBT_INITIALIZE'
    EXPORTING
      group_name                     = gv_srv_grp
    IMPORTING
      max_pbt_wps                    = gv_max_wps
      free_pbt_wps                   = gv_free_wps
    EXCEPTIONS
      invalid_group_name             = 1
      internal_error                 = 2
      pbt_env_already_initialized    = 3
      currently_no_resources_avail   = 4
      no_pbt_resources_found         = 5
      cant_init_different_pbt_groups = 6
      OTHERS                         = 7.

  CASE sy-subrc.
    WHEN 0. "ok
    WHEN 3.
      CALL FUNCTION 'SPBT_GET_CURR_RESOURCE_INFO'
        IMPORTING
          max_pbt_wps                 = gv_max_wps
          free_pbt_wps                = gv_free_wps
        EXCEPTIONS
          internal_error              = 1
          pbt_env_not_initialized_yet = 2
          OTHERS                      = 3.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    WHEN OTHERS.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDCASE.

ENDFORM.                    " INITIALIZATION
*&---------------------------------------------------------------------*
*&      Form  bapi_po_getitems
*&---------------------------------------------------------------------*
FORM bapi_po_getitems .
  CALL FUNCTION 'GUID_CREATE'
    IMPORTING
      ev_guid_32 = gv_task_guid.

* get data from function
  CALL FUNCTION 'BAPI_PO_GETITEMS'
    STARTING NEW TASK gv_task_guid
    DESTINATION IN GROUP DEFAULT
    PERFORMING delete_unnessacery_records ON END OF TASK
    EXPORTING
      purch_org       = gc_purch_org
      with_po_headers = 'X'
    TABLES
      po_headers      = gt_po_headers[]
      po_items        = gt_po_items[]
      return          = gt_return[].

ENDFORM .       "BAPI_PO_GETITEMS
*&---------------------------------------------------------------------*
*&      Form  delete_unnessacery_records
*&---------------------------------------------------------------------*
FORM delete_unnessacery_records USING taskname.
  DATA : lrt_po_num TYPE TABLE OF wpocs_ebeln_range ,
         lrs_po_num TYPE wpocs_ebeln_range ,
         lrt_items TYPE TABLE OF range_n5 ,
         lv_header_lines TYPE i .

  FIELD-SYMBOLS: <lfs_po_header> TYPE bapiekkol,
                 <lfs_po_items>  TYPE bapiekpoc.

  RECEIVE RESULTS FROM FUNCTION 'BAPI_PO_GETITEMS'
                             TABLES
                             po_headers      = gt_po_headers[]
                             po_items        = gt_po_items[]
                             return          = gt_return[].

* filter recrods by elimination method .
* mean that we delete the unnessacery records

  PERFORM get_planned_delivery_dates TABLES lrt_items[] lrt_po_num[].
*  APPEND LINES OF pohead TO lrt_po_num[].

  lv_header_lines = lines( gt_po_headers[] ).

  DELETE gt_po_headers[] WHERE NOT (  po_number IN pohead AND
                                      po_number IN lrt_po_num[]
                                      AND vendor IN lifnr ) .

  IF lines( gt_po_headers[] ) <> lv_header_lines .
    " CLEAR lrt_po_num[].

    lrs_po_num-sign = 'I'.
    lrs_po_num-option = 'EQ'.

    LOOP AT gt_po_headers[] ASSIGNING <lfs_po_header>.
      lrs_po_num-low = <lfs_po_header>-po_number.
      APPEND lrs_po_num TO lrt_po_num[].
    ENDLOOP .

    DELETE ADJACENT DUPLICATES FROM lrt_po_num[] COMPARING ALL FIELDS.
  ENDIF.

*  APPEND LINES OF poitem[] TO lrt_items[].
  DELETE gt_po_items[] WHERE  NOT ( po_number IN lrt_po_num[]
                                   AND po_item IN poitem
                                   AND po_item IN lrt_items[]
                                   AND material IN matnr
                                   AND plant = werks ).

  CHECK lines( matnr[] ) > 0 .  " if there's an material filtering
  " we need to update the header according to item
  CLEAR: lrs_po_num, lrt_po_num[].

  lrs_po_num-sign = 'I'.
  lrs_po_num-option = 'EQ'.

  LOOP AT gt_po_items[] ASSIGNING <lfs_po_items>.
    lrs_po_num-low = <lfs_po_items>-po_number.
    APPEND lrs_po_num TO lrt_po_num[].
  ENDLOOP .

  DELETE ADJACENT DUPLICATES FROM lrt_po_num[] COMPARING ALL FIELDS.
  DELETE gt_po_headers[] WHERE po_number NOT IN lrt_po_num[] .

  gv_task1 = 'X'.

ENDFORM.                    "delete_unnessacery_records
*&---------------------------------------------------------------------*
*&      Form  get_planned_delivery_dates
*&---------------------------------------------------------------------*
FORM get_planned_delivery_dates  TABLES ptr_items STRUCTURE range_n5
                                        ptr_header STRUCTURE wpocs_ebeln_range.
  FIELD-SYMBOLS : <lfs_eket> TYPE eket.

  DATA: lrt_items TYPE TABLE OF range_n5 ,
        lrs_items TYPE range_n5 ,
        lrt_po_num TYPE TABLE OF wpocs_ebeln_range ,
        lrs_po_num TYPE wpocs_ebeln_range .

* build ranges for filtering the records .
* we use the ranges for processing in the deletion phase of unnessacery recoeds .

  SELECT * FROM eket INTO TABLE gt_eket[]
    FOR ALL ENTRIES IN gt_po_items
     WHERE ebeln = gt_po_items-po_number
       AND ebelp = gt_po_items-po_item
       AND eindt IN reqdate.

  DELETE ADJACENT DUPLICATES FROM gt_eket COMPARING ebeln ebelp.

  lrs_po_num-sign = lrs_items-sign = 'I'.
  lrs_po_num-option = lrs_items-option = 'EQ'.

  LOOP AT gt_eket[] ASSIGNING <lfs_eket>.
    lrs_po_num-low = <lfs_eket>-ebeln.
    lrs_items-low = <lfs_eket>-ebelp.
    APPEND lrs_items TO ptr_items[].
    APPEND lrs_po_num TO ptr_header[].
  ENDLOOP.

  DELETE ADJACENT DUPLICATES FROM ptr_items[] COMPARING ALL FIELDS.
  DELETE ADJACENT DUPLICATES FROM ptr_header[] COMPARING ALL FIELDS.
ENDFORM .                    "get_planned_delivery_dates
*&---------------------------------------------------------------------*
*&      Form  BAPI_GOODSMVT_GETITEMS
*&---------------------------------------------------------------------*
FORM bapi_goodsmvt_getitems.
  DATA : lrt_plant TYPE TABLE OF bapi2017_gm_plant_ra ,
         lrs_plant TYPE  bapi2017_gm_plant_ra ,
         lrt_tr_ev_type_ra TYPE TABLE OF bapi2017_gm_tr_ev_type_ra,
         lrs_tr_ev_type_ra TYPE bapi2017_gm_tr_ev_type_ra,
         lt_return TYPE TABLE OF bapiret2 .

* get data for the reset of the process
* all the data wich should gather is by definition .

  lrs_plant-sign = lrs_tr_ev_type_ra-sign = 'I'.
  lrs_plant-option = lrs_tr_ev_type_ra-option = 'EQ'.

  lrs_plant-low = werks.
  lrs_tr_ev_type_ra-low = 'WE'.

  APPEND lrs_plant TO lrt_plant[].
  APPEND lrs_tr_ev_type_ra TO lrt_tr_ev_type_ra[].

  CALL FUNCTION 'BAPI_GOODSMVT_GETITEMS'
    TABLES
      plant_ra        = lrt_plant[]
      tr_ev_type_ra   = lrt_tr_ev_type_ra[]
      vendor_ra       = lifnr
      goodsmvt_header = gt_goodsmvt_header[]
      goodsmvt_items  = gt_goodsmvt_items[]
      return          = lt_return[].

ENDFORM .                    "BAPI_GOODSMVT_GETITEMS
*&---------------------------------------------------------------------*
*&      Form  gather_data_for_result
*&---------------------------------------------------------------------*
FORM gather_data_for_result.
  FIELD-SYMBOLS: <lfs_po_headers> TYPE bapiekkol,
                 <lfs_po_items> TYPE  bapiekpoc,
                 <lfs_eket> TYPE eket ,
                 <lfs_goodsmvt_items> TYPE bapi2017_gm_item_show,
                 <lfs_goodsmvt_header> TYPE bapi2017_gm_head_02,
                 <lfs_lfa1> TYPE lfa1 ,
                 <lfs_zvendeval_toler> TYPE zvendeval_toler.

  DATA : ls_scr TYPE ty_scr_result ,
         lt_lfa1 TYPE TABLE OF lfa1 ,
         lv_mdq  TYPE weprz ,
         lt_color TYPE lvc_t_scol,
         ls_color TYPE lvc_s_scol,
         lv_temp_any TYPE erfmg ,
         lt_ekbe TYPE TABLE OF ekbe ,
         lt_zvendeval_toler TYPE STANDARD TABLE OF zvendeval_toler .

*gather data for screen result & calculate
  SORT gt_po_headers[] BY po_number .
  SORT gt_po_items[] BY po_number po_item .
  SORT gt_eket[] BY ebeln ebelp.
  SORT lt_ekbe[] BY ebeln ebelp.
  SORT gt_goodsmvt_header[] BY mat_doc.
  SORT gt_goodsmvt_items[] BY po_number po_item .

  SELECT ebeln ebelp FROM ekbe INTO
    CORRESPONDING FIELDS OF TABLE lt_ekbe
    FOR ALL ENTRIES IN gt_po_items[]
    WHERE ebeln = gt_po_items-po_number
      AND ebelp = gt_po_items-po_item.

  SELECT SINGLE weprz FROM t147 INTO lv_mdq
     WHERE ekorg = gc_purch_org.

  SELECT  * FROM lfa1 INTO TABLE lt_lfa1
    FOR ALL ENTRIES IN gt_po_headers
     WHERE lifnr = gt_po_headers-vendor.

  DELETE ADJACENT DUPLICATES FROM lt_lfa1 COMPARING lifnr.
  SORT lt_lfa1[].

  SELECT * FROM zvendeval_toler INTO TABLE lt_zvendeval_toler
    FOR ALL ENTRIES IN lt_lfa1
    WHERE land1 = lt_lfa1-land1
      OR  land1 = '*'.

  SORT lt_zvendeval_toler[] .

  ls_color-fname     = 'PO_ITEM'.
  ls_color-color-col = 5.
  ls_color-color-int = 0.
  ls_color-color-inv = 0.
  APPEND ls_color TO lt_color[].

*  break tal_herzel .

  LOOP AT gt_po_headers[] ASSIGNING <lfs_po_headers> .
    ls_scr-vendor = <lfs_po_headers>-vendor .
    ls_scr-vend_name = <lfs_po_headers>-vend_name.

    READ TABLE lt_lfa1 ASSIGNING <lfs_lfa1>
       WITH KEY lifnr = <lfs_po_headers>-vendor BINARY SEARCH.

    IF <lfs_lfa1> IS ASSIGNED.
      READ TABLE lt_zvendeval_toler ASSIGNING <lfs_zvendeval_toler>
                                      WITH KEY werks = gc_purch_org
                                               land1 = <lfs_lfa1>-land1
                                               BINARY SEARCH.

      IF <lfs_zvendeval_toler> IS NOT ASSIGNED.
        READ TABLE lt_zvendeval_toler ASSIGNING <lfs_zvendeval_toler>
                                       WITH KEY werks = gc_purch_org
                                                land1 = '*'
                                                BINARY SEARCH.
      ENDIF.

      IF <lfs_zvendeval_toler> IS ASSIGNED .
        ls_scr-rdtt = <lfs_zvendeval_toler>-ztoler.
        UNASSIGN <lfs_zvendeval_toler>.
      ENDIF.
      UNASSIGN <lfs_lfa1>.
    ENDIF.

    LOOP AT gt_po_items[] ASSIGNING <lfs_po_items> WHERE po_number = <lfs_po_headers>-po_number.

      MOVE-CORRESPONDING <lfs_po_items> TO ls_scr.
      ls_scr-calc_score = 0 .

      READ TABLE gt_eket[] ASSIGNING <lfs_eket>
                                      WITH KEY ebeln = <lfs_po_items>-po_number
                                               ebelp = <lfs_po_items>-po_item
                                               BINARY SEARCH.
      IF <lfs_eket> IS ASSIGNED .
        ls_scr-eindt = <lfs_eket>-eindt.
        ls_scr-rdtt = ls_scr-rdtt + <lfs_eket>-eindt.
        UNASSIGN <lfs_eket>.
      ENDIF.

      LOOP AT gt_goodsmvt_items[] ASSIGNING <lfs_goodsmvt_items>
                                  WHERE po_number = <lfs_po_items>-po_number
                                    AND po_item = <lfs_po_items>-po_item.

        ls_scr-calca = ls_scr-calca + <lfs_goodsmvt_items>-entry_qnt.

        READ TABLE gt_goodsmvt_header ASSIGNING <lfs_goodsmvt_header>
                                       WITH KEY mat_doc = <lfs_goodsmvt_items>-mat_doc
                                       BINARY SEARCH.

        IF <lfs_goodsmvt_header> IS ASSIGNED
          AND <lfs_goodsmvt_header>-pstng_date < ls_scr-rdtt.

          ls_scr-calcb = ls_scr-calcb + <lfs_goodsmvt_items>-entry_qnt.
          UNASSIGN <lfs_goodsmvt_header>.
        ENDIF.

        UNASSIGN <lfs_goodsmvt_header>.
      ENDLOOP.

      lv_temp_any = ls_scr-calcb / ( <lfs_po_items>-disp_quan * 100 ).

      IF lv_temp_any < lv_mdq .
        ls_scr-calc_score = 1 .
      ENDIF.

      CLEAR lv_temp_any .

      READ TABLE lt_ekbe TRANSPORTING NO FIELDS
                 WITH KEY ebeln = <lfs_po_items>-po_number
                          ebelp = <lfs_po_items>-po_item
                          BINARY SEARCH.
      IF sy-subrc = 0 .
        ls_scr-t_color[] = lt_color[].
      ENDIF.

      APPEND ls_scr TO gt_screen_result[].
    ENDLOOP.

    CLEAR ls_scr.
  ENDLOOP.

ENDFORM.                    "gather_data_for_result
*&---------------------------------------------------------------------*
*&      Form  set_columns_technical
*&---------------------------------------------------------------------*
FORM set_columns_technical USING ir_columns TYPE REF TO cl_salv_columns_table.
*do not delete: data definition is just in case that you'll have to define f4 field.
*  DATA:  lr_column1 TYPE REF TO cl_salv_column_table,
*         lr_column TYPE REF TO cl_salv_column.

*  CHECK 1 = 2 .
  PERFORM set_column_technical USING ir_columns 'VENDOR' if_salv_c_bool_sap=>false.
  PERFORM set_column_technical USING ir_columns 'VEND_NAME' if_salv_c_bool_sap=>false.
  PERFORM set_column_technical USING ir_columns 'PO_NUMBER' if_salv_c_bool_sap=>false.
  PERFORM set_column_technical USING ir_columns 'PO_ITEM' if_salv_c_bool_sap=>false.
  PERFORM set_column_technical USING ir_columns 'DISP_QUAN' if_salv_c_bool_sap=>false.
  PERFORM set_column_technical USING ir_columns 'CALCA' if_salv_c_bool_sap=>false.
  PERFORM set_column_technical USING ir_columns 'CALCB' if_salv_c_bool_sap=>false.
  PERFORM set_column_technical USING ir_columns 'CALC_SCORE' if_salv_c_bool_sap=>false.
  PERFORM set_column_technical USING ir_columns 'EINDT' if_salv_c_bool_sap=>false.
  PERFORM set_column_technical USING ir_columns 'RDTT' if_salv_c_bool_sap=>false.

ENDFORM .                    "set_columns_technical
*&---------------------------------------------------------------------*
*&      Form  set_column_technical
*&---------------------------------------------------------------------*
FORM set_column_technical USING ir_columns TYPE REF TO cl_salv_columns_table
                                i_col_name TYPE lvc_fname
                                i_tru_or_fls TYPE sap_bool .

  DATA:  lr_column1 TYPE REF TO cl_salv_column_table,
        lr_column TYPE REF TO cl_salv_column.
  TRY.
      lr_column = ir_columns->get_column( i_col_name ).
      lr_column->set_technical( i_tru_or_fls ).
    CATCH cx_salv_not_found.
  ENDTRY.
ENDFORM.                    "set_column_technical
*&---------------------------------------------------------------------*
*&      Form  set_display_settings
*&---------------------------------------------------------------------*
FORM set_display_settings.

  DATA:
       ls_display TYPE REF TO cl_salv_display_settings,
       lv_title TYPE lvc_title .

  ls_display = gr_table->get_display_settings( ).
  lv_title = text-002 .
  TRY.
      ls_display->set_list_header( lv_title ).
      ls_display->set_vertical_lines( abap_true ).
      ls_display->set_horizontal_lines( abap_true ).
      ls_display->set_striped_pattern( abap_true ).
      ls_display->set_list_header_size( cl_salv_display_settings=>c_header_size_small ).
      ls_display->set_suppress_empty_data( abap_true ).
    CATCH cx_no_check.

  ENDTRY.

ENDFORM.                    "set_display_settings
*&--------------------------------------------------------------------*
*&      Form  set_columns
*&--------------------------------------------------------------------*
FORM set_columns.

  DATA:
    lr_columns TYPE REF TO cl_salv_columns,  "global columns settings
    lr_column  TYPE REF TO cl_salv_column_table. "individual column setting

  lr_columns = gr_table->get_columns( ).

*  lr_columns->set_optimize( abap_true ).

*  TRY.
*      lr_column ?= lr_columns->get_column( 'MANDT' ). "get a single column
*      lr_column->set_technical( abap_true ).         "Client column is a technical column
*    CATCH cx_salv_not_found.
*  ENDTRY.

  TRY.
*      lr_column ?= lr_columns->get_column( 'SEATSOCC' ).
*      lr_column->set_visible( abap_false ).

      gr_column ?= gr_columns->get_column( 'CALCA' ).
      gr_column->set_long_text( 'Calculated A' ).
      gr_column->set_medium_text( 'Calculated A' ).
      gr_column->set_short_text( 'Calc A' ).

      gr_column ?= gr_columns->get_column( 'CALCB' ).
      gr_column->set_long_text( 'Calculated B' ).
      gr_column->set_medium_text( 'Calculated B' ).
      gr_column->set_short_text( 'Calc B' ).

      gr_column ?= gr_columns->get_column( 'CALC_SCORE' ).
      gr_column->set_long_text( 'Calculated Score' ).
      gr_column->set_medium_text( 'Calculated Score' ).
      gr_column->set_short_text( 'Calc Sco' ).

      gr_column ?= gr_columns->get_column( 'EINDT' ).
      gr_column->set_long_text( 'Req. Date' ).
      gr_column->set_medium_text( 'Req. Date' ).
      gr_column->set_short_text( 'Req. Date' ).

      gr_column ?= gr_columns->get_column( 'RDTT' ).
      gr_column->set_long_text( 'Req. Date + Tolerance' ).
      gr_column->set_medium_text( 'Req.Date + Tolerance' ).
      gr_column->set_short_text( 'Req.Dt+Tol' ).

    CATCH cx_salv_not_found.
  ENDTRY.

*   change the PRICE color color
  DATA:
    ls_color TYPE lvc_s_colo.

*  TRY.
*      lr_column ?= lr_columns->get_column( '' ).
*
*      ls_color-col = col_group.
*      ls_color-int = 1.
*
*      lr_column->set_color( ls_color ).
*    CATCH cx_salv_not_found.
*  ENDTRY.

ENDFORM.                    "set_columns
*&--------------------------------------------------------------------*
*&      Form  set_sort
*&--------------------------------------------------------------------*
FORM set_sort USING col_name TYPE lvc_fname.

  DATA:
    lr_sorts TYPE REF TO cl_salv_sorts.   "sort information

  lr_sorts = gr_table->get_sorts( ).

  lr_sorts->clear( ).                         "remove all existing sort setings

  TRY.
      lr_sorts->add_sort(
        columnname = col_name
        position   = 1
        subtotal   = abap_true       "applies only if some aggregations are turned on
        sequence   = if_salv_c_sort=>sort_up ).
    CATCH cx_salv_not_found cx_salv_existing cx_salv_data_error.
  ENDTRY.

ENDFORM.                    "set_sort
*&--------------------------------------------------------------------*
*&      Form  set_aggregations
*&--------------------------------------------------------------------*
FORM set_aggregations USING col_name TYPE lvc_fname .

  DATA: lr_aggregations TYPE REF TO cl_salv_aggregations.

  lr_aggregations = gr_table->get_aggregations( ).
  lr_aggregations->clear( ).

  TRY.
      lr_aggregations->add_aggregation( columnname = col_name ).
    CATCH cx_salv_not_found cx_salv_data_error cx_salv_existing.
  ENDTRY.

ENDFORM.                    "set_aggregations
*&--------------------------------------------------------------------*
*&      Form  set_filter
*&--------------------------------------------------------------------*
FORM set_filter.

  DATA:
    lr_filters TYPE REF TO cl_salv_filters.

  lr_filters = gr_table->get_filters( ).

  lr_filters->clear( ).

  TRY.
      lr_filters->add_filter(
        columnname = 'CURRENCY'
        low        = 'USD' ).
    CATCH cx_salv_not_found cx_salv_data_error cx_salv_existing.
  ENDTRY.

ENDFORM.                    "set_filter
*&---------------------------------------------------------------------*
*&      Form  publish_to_screen
*&---------------------------------------------------------------------*
FORM publish_to_screen .

  IF lines( gt_screen_result[] ) = 0.
    MESSAGE s131(m7) DISPLAY LIKE 'S'.
    EXIT.
  ENDIF.

  TRY.
      cl_salv_table=>factory( IMPORTING r_salv_table = gr_table
                              CHANGING t_table = gt_screen_result[] ).
    CATCH cx_salv_msg.
  ENDTRY.

  gr_functions = gr_table->get_functions( ).
  gr_functions->set_all( abap_true ).

  PERFORM set_display_settings.

*  gr_display = gr_table->get_display_settings( ).
*  gr_display->set_striped_pattern( cl_salv_display_settings=>true ).
*  gr_display->set_list_header( text-002 ). "This is the heading

  gr_columns = gr_table->get_columns( ).

  PERFORM set_columns_technical USING gr_columns.
  PERFORM set_columns.

*  color-col = '6'.
*  color-int = '1'.
*  color-inv = '0'.
*  gr_column->set_color( color ).
*  gr_table->set_screen_status( pfstatus = 'SALV_TABLE_STANDARD'
*                               report = sy-repid
*                               set_functions = gr_table->c_functions_all ).

  TRY.
      gr_columns->set_color_column( 'T_COLOR' ).
    CATCH cx_salv_data_error.
  ENDTRY.

  gr_events = gr_table->get_event( ).

  TRY.
      CREATE OBJECT event_handler.

      SET HANDLER event_handler->on_user_command FOR gr_events.
      SET HANDLER event_handler->on_double_click FOR gr_events.

    CATCH cx_sy_create_object_error.
  ENDTRY.
* Set up selections.
  gr_selections = gr_table->get_selections( ).
  gr_selections->set_selection_mode( 1 ). "Single

*  gr_sorts = gr_table->get_sorts( ).
*  gr_sorts->add_sort( 'VENDOR' ).
*  gr_sorts->add_sort( 'PO_NUMBER' ).
  gr_table->display( ).
ENDFORM.                    "publish_to_screen
*&---------------------------------------------------------------------*
*&      Form  free
*&---------------------------------------------------------------------*
FORM free.
  FREE: gt_po_headers[],gt_po_items[],gt_return[],gt_eket[], gr_table,event_handler,
        gr_functions,gr_display,gr_columns,gr_column,gt_screen_result[].

  SYSTEM-CALL OBJMGR PERFORM GARBAGE COLLECTION.
ENDFORM. "free
*&---------------------------------------------------------------------*
*&      Form  EH_ON_PO_ITEM
*&---------------------------------------------------------------------*
FORM eh_on_po_item USING p_scr_result TYPE ty_scr_result .

  CHECK p_scr_result-po_number IS NOT INITIAL
    AND p_scr_result-po_item IS NOT INITIAL .

  CALL FUNCTION 'MM_HISTORY_POPUP_SHOW'
    EXPORTING
      pi_ebeln = p_scr_result-po_number
      pi_ebelp = p_scr_result-po_item
    EXCEPTIONS
      error    = 0
      OTHERS   = 0.

ENDFORM.                    " EH_ON_PO_ITEM
*&---------------------------------------------------------------------*
*&      Form  EH_ON_PO_NUMBER
*&---------------------------------------------------------------------*
FORM eh_on_po_number  USING  p_scr_result TYPE ty_scr_result .

  CHECK p_scr_result-po_number IS NOT INITIAL
    AND p_scr_result-po_item IS NOT INITIAL .

  CALL FUNCTION 'ME_DISPLAY_PURCHASE_DOCUMENT'
    EXPORTING
      i_ebeln              = p_scr_result-po_number
      i_ebelp              = p_scr_result-po_item
      i_enjoy              = 'X'
    EXCEPTIONS
      not_found            = 1
      no_authority         = 2
      invalid_call         = 3
      preview_not_possible = 4
      OTHERS               = 5.

ENDFORM.                    " EH_ON_PO_NUMBER
*&---------------------------------------------------------------------*
*&      Form  MAIN
*&---------------------------------------------------------------------*
FORM main.

  PERFORM bapi_po_getitems.
  PERFORM bapi_goodsmvt_getitems.

  WAIT UNTIL gv_task1 = 'X'.

  PERFORM gather_data_for_result.
  PERFORM publish_to_screen.
  PERFORM free.
ENDFORM.                    " MAIN

*&---------------------------------------------------------------------*
*&  Include           ZVENDOR1_3MAIN
*&---------------------------------------------------------------------*

INITIALIZATION.
  PERFORM initialization.

START-OF-SELECTION.
  PERFORM main.

Author: Girish Kumar Loganathan
Submitted: June 20, 2007

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*&---------------------------------------------------------------------*
*& Report  ZALVGRID_DRILLDOWN                                          *
*&---------------------------------------------------------------------*
REPORT  zalvgrid_drilldown                  .

TABLES:     ekko.

TYPE-POOLS: slis.                                 "ALV Declarations
*Data Declaration
*----------------
TYPES: BEGIN OF t_ekko,
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
  statu TYPE ekpo-statu,
  aedat TYPE ekpo-aedat,
  matnr TYPE ekpo-matnr,
  menge TYPE ekpo-menge,
  meins TYPE ekpo-meins,
  netpr TYPE ekpo-netpr,
  peinh TYPE ekpo-peinh,
END OF t_ekko.

DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
      wa_ekko TYPE t_ekko.

*ALV data declarations
DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
      gd_tab_group TYPE slis_t_sp_group_alv,
      gd_layout    TYPE slis_layout_alv,
      gd_repid     LIKE sy-repid,
      gt_events     TYPE slis_t_event,
      gd_prntparams TYPE slis_print_alv.


************************************************************************
*Start-of-selection.
START-OF-SELECTION.

  PERFORM data_retrieval.
  PERFORM build_fieldcatalog.
  PERFORM build_layout.
  PERFORM build_events.
  PERFORM build_print_params.
  PERFORM display_alv_report.
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*       Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
FORM build_fieldcatalog.

  fieldcatalog-fieldname   = 'EBELN'.
  fieldcatalog-seltext_m   = 'Purchase Order'.
  fieldcatalog-col_pos     = 0.
  fieldcatalog-outputlen   = 10.
  fieldcatalog-emphasize   = 'X'.
  fieldcatalog-key         = 'X'.
*  fieldcatalog-do_sum      = 'X'.
*  fieldcatalog-no_zero     = 'X'.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'EBELP'.
  fieldcatalog-seltext_m   = 'PO Item'.
  fieldcatalog-col_pos     = 1.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'STATU'.
  fieldcatalog-seltext_m   = 'Status'.
  fieldcatalog-col_pos     = 2.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'AEDAT'.
  fieldcatalog-seltext_m   = 'Item change date'.
  fieldcatalog-col_pos     = 3.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'MATNR'.
  fieldcatalog-seltext_m   = 'Material Number'.
  fieldcatalog-col_pos     = 4.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'MENGE'.
  fieldcatalog-seltext_m   = 'PO quantity'.
  fieldcatalog-col_pos     = 5.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'MEINS'.
  fieldcatalog-seltext_m   = 'Order Unit'.
  fieldcatalog-col_pos     = 6.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'NETPR'.
  fieldcatalog-seltext_m   = 'Net Price'.
  fieldcatalog-col_pos     = 7.
  fieldcatalog-outputlen   = 15.
  fieldcatalog-do_sum      = 'X'.
  fieldcatalog-datatype     = 'CURR'.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'PEINH'.
  fieldcatalog-seltext_m   = 'Price Unit'.
  fieldcatalog-col_pos     = 8.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
ENDFORM.                    " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*&      Form  BUILD_LAYOUT
*&---------------------------------------------------------------------*
*       Build layout for ALV grid report
*----------------------------------------------------------------------*
FORM build_layout.
  gd_layout-no_input          = 'X'.
  gd_layout-colwidth_optimize = 'X'.
  gd_layout-totals_text       = 'Totals'(201).
*  gd_layout-totals_only        = 'X'.
*  gd_layout-f2code            = 'DISP'.  "Sets fcode for when double
*                                         "click(press f2)
*  gd_layout-zebra             = 'X'.
*  gd_layout-group_change_edit = 'X'.
*  gd_layout-header_text       = 'helllllo'.
ENDFORM.                    " BUILD_LAYOUT
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*       Display report using ALV grid
*----------------------------------------------------------------------*
FORM display_alv_report.
  gd_repid = sy-repid.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program      = gd_repid
      i_callback_top_of_page  = 'TOP-OF-PAGE'  "see FORM
      i_callback_user_command = 'USER_COMMAND'
*     i_grid_title            = outtext
      is_layout               = gd_layout
      it_fieldcat             = fieldcatalog[]
*     it_special_groups       = gd_tabgroup
      it_events               = gt_events
      is_print                = gd_prntparams
      i_save                  = 'X'
*     is_variant              = z_template
    TABLES
      t_outtab                = it_ekko
    EXCEPTIONS
      program_error           = 1
      OTHERS                  = 2.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
ENDFORM.                    " DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*&      Form  DATA_RETRIEVAL
*&---------------------------------------------------------------------*
*       Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
FORM data_retrieval.

  SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh
  UP TO 10 ROWS
    FROM ekpo
    INTO TABLE it_ekko.
ENDFORM.                    " DATA_RETRIEVAL
*-------------------------------------------------------------------*
* Form  TOP-OF-PAGE                                                 *
*-------------------------------------------------------------------*
* ALV Report Header                                                 *
*-------------------------------------------------------------------*
FORM top-of-page.
*ALV Header declarations
  DATA: t_header TYPE slis_t_listheader,
        wa_header TYPE slis_listheader,
        t_line LIKE wa_header-info,
        ld_lines TYPE i,
        ld_linesc(10) TYPE c.

* Title
  wa_header-typ  = 'H'.
  wa_header-info = 'EKKO Table Report'.
  APPEND wa_header TO t_header.
  CLEAR wa_header.

* Date
  wa_header-typ  = 'S'.
  wa_header-key = 'Date: '.
  CONCATENATE  sy-datum+6(2) '.'
               sy-datum+4(2) '.'
               sy-datum(4) INTO wa_header-info.   "todays date
  APPEND wa_header TO t_header.
  CLEAR: wa_header.

* Total No. of Records Selected
  DESCRIBE TABLE it_ekko LINES ld_lines.
  ld_linesc = ld_lines.
  CONCATENATE 'Total No. of Records Selected: ' ld_linesc
                    INTO t_line SEPARATED BY space.
  wa_header-typ  = 'A'.
  wa_header-info = t_line.
  APPEND wa_header TO t_header.
  CLEAR: wa_header, t_line.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = t_header.
*            i_logo             = 'Z_LOGO'.
ENDFORM.                    "top-of-page
*------------------------------------------------------------------*
*       FORM USER_COMMAND                                          *
*------------------------------------------------------------------*
*       --> R_UCOMM                                                *
*       --> RS_SELFIELD                                            *
*------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm
                  rs_selfield TYPE slis_selfield.

* Check function code
  CASE r_ucomm.
    WHEN '&IC1'.
*   Check field clicked on within ALVgrid report
      IF rs_selfield-fieldname = 'EBELN'.
*     Read data table, using index of row user clicked on
        READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex.
*     Set parameter ID for transaction screen field
        SET PARAMETER ID 'BES' FIELD wa_ekko-ebeln.
*     Sxecute transaction ME23N, and skip initial data entry screen
        CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
      ENDIF.
  ENDCASE.
ENDFORM.                    "user_command
*&---------------------------------------------------------------------*
*&      Form  BUILD_EVENTS
*&---------------------------------------------------------------------*
*       Build events table
*----------------------------------------------------------------------*
FORM build_events.
  DATA: ls_event TYPE slis_alv_event.

  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
      i_list_type = 0
    IMPORTING
      et_events   = gt_events[].
  READ TABLE gt_events WITH KEY name =  slis_ev_end_of_page
                           INTO ls_event.
  IF sy-subrc = 0.
    MOVE 'END_OF_PAGE' TO ls_event-form.
    APPEND ls_event TO gt_events.
  ENDIF.

  READ TABLE gt_events WITH KEY name =  slis_ev_end_of_list
                         INTO ls_event.
  IF sy-subrc = 0.
    MOVE 'END_OF_LIST' TO ls_event-form.
    APPEND ls_event TO gt_events.
  ENDIF.
ENDFORM.                    " BUILD_EVENTS
*&---------------------------------------------------------------------*
*&      Form  BUILD_PRINT_PARAMS
*&---------------------------------------------------------------------*
*       Setup print parameters
*----------------------------------------------------------------------*
FORM build_print_params.
  gd_prntparams-reserve_lines = '3'.   "Lines reserved for footer
  gd_prntparams-no_coverpage = 'X'.
ENDFORM.                    " BUILD_PRINT_PARAMS
*&---------------------------------------------------------------------*
*&      Form  END_OF_PAGE
*&---------------------------------------------------------------------*
FORM end_of_page.
  DATA: listwidth TYPE i,
        ld_pagepos(10) TYPE c,
        ld_page(10)    TYPE c.

  WRITE: sy-uline(50).
  SKIP.
  WRITE:/40 'Page:', sy-pagno .
ENDFORM.                    "END_OF_PAGE
*&---------------------------------------------------------------------*
*&      Form  END_OF_LIST
*&---------------------------------------------------------------------*
FORM end_of_list.
  DATA: listwidth TYPE i,
        ld_pagepos(10) TYPE c,
        ld_page(10)    TYPE c.

  SKIP.
  WRITE:/40 'Page:', sy-pagno .
ENDFORM.                    "END_OF_LIST

REPORT zbapi_contract_create NO STANDARD PAGE HEADING

LINE-SIZE 120.
*&---------------------------------------------------------------------*

*& I N C L U D E S

*&---------------------------------------------------------------------*

*& TOP INCLUDE

INCLUDE zcontract_create_top.

*& FORMS INCLUDE

INCLUDE zcontract_create_forms.
*&---------------------------------------------------------------------*

*& A T - S E L E C T I O N - S C R E E N

*&---------------------------------------------------------------------*

*& Providing f4 help path to filmanager on presentation server

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

PERFORM get_file_name USING p_file.
*&---------------------------------------------------------------------*

*& S T A R T - O F - S E L E C T I O N

*&---------------------------------------------------------------------*

START-OF-SELECTION.

*& Getting xls file from presentation server and converting it into int tab

PERFORM convert_xls_to_itab USING it_type

CHANGING it_contract.
*&---------------------------------------------------------------------*

*& E N D - O F - S E L E C T I O N

*&---------------------------------------------------------------------*

END-OF-SELECTION.

*& Filling up data for bapi fm and processing it for contract creation

PERFORM build_and_processing_bapi USING it_contract.
*& return messages from bapi

PERFORM get_return_messages.
*&---------------------------------------------------------------------*

*& T O P - O F - P A G E

*&---------------------------------------------------------------------*

TOP-OF-PAGE.

PERFORM write_heading.

*&---------------------------------------------------------------------*

*& Include ZCONTRACT_CREATE_TOP

*&---------------------------------------------------------------------*

TYPE-POOLS: truxs.

*& structure same as xls file on presentation server

TYPES: BEGIN OF ty_contract,

vendor(10),

agree_type(2),

agree_date(10),

pur_org(4),

pur_grp(3),

item_cat(1),

plant(4),

sto_loc(4),

val_start(10),

val_end(10),

material(18),

qty(15),

uom(3),

net_price(15),

END OF ty_contract,

*& structure for reporting status for created contracted

BEGIN OF ty_message,

vendor(10),

status(12),

message TYPE bapi_msg,

END OF ty_message.

TYPES: ty_t_contract TYPE STANDARD TABLE OF ty_contract.

*& work area declarations

DATA: wa_contract TYPE ty_contract,

wa_contract_header TYPE bapioahead,

wa_contract_header_x TYPE bapioaheax,

wa_contract_detail TYPE bapioaitem,

wa_contract_detail_x TYPE bapioaitex,

wa_return TYPE bapiret2,

wa_message TYPE ty_message,

*& Internal table declarations

it_contract_detail TYPE STANDARD TABLE OF bapioaitem,

it_contract_detail_x TYPE STANDARD TABLE OF bapioaitex,

it_contract TYPE STANDARD TABLE OF ty_contract,

it_type TYPE truxs_t_text_data,

it_return TYPE STANDARD TABLE OF bapiret2,

it_message TYPE STANDARD TABLE OF ty_message,
*& misc data declarations for programming logic

l_count TYPE evrtp VALUE '00000'.

*& constants used in prog

CONSTANTS: cns_x TYPE char1 VALUE 'X'.

*&----------------- S E L E C T I O N - S C R E E N -----------------*

SELECTION-SCREEN BEGIN OF BLOCK bl1 WITH FRAME TITLE text-001.

PARAMETERS: p_file TYPE rlgrap-filename OBLIGATORY.

SELECTION-SCREEN END OF BLOCK bl1.
*&---------------------------------------------------------------------*

*& Include ZCONTRACT_CREATE_FORMS

*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*

*& Form convert_xls_to_itab

*&---------------------------------------------------------------------*

* Conversion of xls file

*----------------------------------------------------------------------*

* -->P_IT_TYPE used as import parameter for conversion

* <--P_IT_CONTRACT converted data from xls to int tab

*----------------------------------------------------------------------*

FORM convert_xls_to_itab USING p_it_type TYPE truxs_t_text_data

CHANGING p_it_contract TYPE ty_t_contract.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

EXPORTING

i_field_seperator = cns_x

i_line_header = cns_x

i_tab_raw_data = p_it_type

i_filename = p_file

TABLES

i_tab_converted_data = p_it_contract

EXCEPTIONS

conversion_failed = 1.

IF sy-subrc = 1.

MESSAGE e021(z12_psv1).

ENDIF.

ENDFORM. " convert_xls_to_itab

*&---------------------------------------------------------------------*

*& Form build_and_processing_bapi

*&---------------------------------------------------------------------*

* BAPI Usage

*----------------------------------------------------------------------*

* -->P_IT_CONTRACT converted int table from xls file

*----------------------------------------------------------------------*

FORM build_and_processing_bapi USING p_it_contract TYPE ty_t_contract.

** local variable for splitting entered dates

DATA: l_mm TYPE char2,

l_dd TYPE char2,

l_yyyy TYPE char4,

sep TYPE char1 VALUE '/', " separator for splitting date

l_date TYPE char8, " for setting document date

l_date1 TYPE char8, " for setting Validity start date

l_date2 TYPE char8. " for setting validity end date

LOOP AT p_it_contract INTO wa_contract.

** for agreement item no's

l_count = l_count + 10.

** setting document date for internal usage

CLEAR: l_mm, l_dd, l_yyyy, l_date.

SPLIT wa_contract-agree_date AT sep INTO l_mm l_dd l_yyyy

IN CHARACTER MODE.

CONCATENATE l_yyyy l_mm l_dd INTO l_date.

** setting validity start date for internal usage

CLEAR: l_mm, l_dd, l_yyyy, l_date1.

SPLIT wa_contract-agree_date AT sep INTO l_mm l_dd l_yyyy

IN CHARACTER MODE.

CONCATENATE l_yyyy l_mm l_dd INTO l_date1.

** setting validity end date for internal usage

CLEAR: l_mm, l_dd, l_yyyy, l_date2.

SPLIT wa_contract-agree_date AT sep INTO l_mm l_dd l_yyyy

IN CHARACTER MODE.

CONCATENATE l_yyyy l_mm l_dd INTO l_date2.

** assignment of header and details from it_contract for passing it to bapi fm

CLEAR: wa_contract_header, wa_contract_header_x,

wa_contract_detail, wa_contract_detail_x.

wa_contract_header-vendor = wa_contract-vendor.

wa_contract_header-doc_type = wa_contract-agree_type .

wa_contract_header-creat_date = l_date.

wa_contract_header-purch_org = wa_contract-pur_org.

wa_contract_header-pur_group = wa_contract-pur_grp.

wa_contract_header-vper_start = l_date1.

wa_contract_header-vper_end = l_date2.

wa_contract_header-doc_cat = 'K'.

wa_contract_header_x-vendor = cns_x.

wa_contract_header_x-doc_type = cns_x.

wa_contract_header_x-creat_date = cns_x.

wa_contract_header_x-purch_org = cns_x.

wa_contract_header_x-pur_group = cns_x.

wa_contract_header_x-vper_start = cns_x.

wa_contract_header_x-vper_end = cns_x.

wa_contract_header_x-doc_cat = cns_x.

wa_contract_detail-agrmt_item = l_count.

wa_contract_detail-material = wa_contract-material.

wa_contract_detail-plant = wa_contract-plant.

wa_contract_detail-stge_loc = wa_contract-sto_loc.

wa_contract_detail-po_unit = wa_contract-uom.

wa_contract_detail-net_price = wa_contract-net_price.

wa_contract_detail-item_cat = wa_contract-item_cat.

wa_contract_detail-target_qty = wa_contract-qty.

APPEND wa_contract_detail TO it_contract_detail.

wa_contract_detail_x-agrmt_item = cns_x.

wa_contract_detail_x-material = cns_x.

wa_contract_detail_x-plant = cns_x.

wa_contract_detail_x-stge_loc = cns_x.

wa_contract_detail_x-po_unit = cns_x.

wa_contract_detail_x-net_price = cns_x.

wa_contract_detail_x-item_cat = cns_x.

wa_contract_detail_x-target_qty = cns_x.

APPEND wa_contract_detail_x TO it_contract_detail_x.

AT END OF vendor.

PERFORM call_bapi.

ENDAT.

ENDLOOP.

ENDFORM. " build_and_processing_bapi

*&---------------------------------------------------------------------*

*& Form call_bapi

*&---------------------------------------------------------------------*

* calling bapi BAPI_AGREEMENT_CONTRACT

* for batch data transfer in transaction ME31K

*----------------------------------------------------------------------*

FORM call_bapi .

REFRESH it_return.

CALL FUNCTION 'BAPI_AGREEMENT_MAINTAIN'

EXPORTING

im_agreement_header = wa_contract_header

im_agreement_header_x = wa_contract_header_x

TABLES

ext_return = it_return

imt_agreement_items = it_contract_detail

imt_agreement_items_x = it_contract_detail_x.

REFRESH: it_contract_detail, it_contract_detail_x.

CLEAR l_count.

** generating status report for created contract

CLEAR wa_message.

wa_message-vendor = wa_contract_header-vendor.

LOOP AT it_return INTO wa_return.

IF wa_return-type = 'S' or

wa_return-type = 'I'.

wa_message-status = 'Created'.

wa_message-message = 'Contract Created Successfully'.

ELSE.

wa_message-status = 'Not Created'.

wa_message-message = wa_return-message..

ENDIF.

APPEND wa_message TO it_message.

ENDLOOP.

ENDFORM. " call_bapi

*&---------------------------------------------------------------------*

*& Form get_file_name

*&---------------------------------------------------------------------*

* Getting file path on pressing F4 for help

*----------------------------------------------------------------------*

* -->P_P_FILE file path from selection screen

*----------------------------------------------------------------------*

FORM get_file_name USING p_p_file TYPE rlgrap-filename.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

program_name = syst-repid

dynpro_number = syst-dynnr

field_name = p_p_file

* STATIC = ' '

* MASK = ' '

CHANGING

file_name = p_p_file.

ENDFORM. " get_file_name

*&---------------------------------------------------------------------*

*& Form get_return_messages

*&---------------------------------------------------------------------*

* Writting report containing status of contract

*----------------------------------------------------------------------*

FORM get_return_messages .

FORMAT INVERSE ON.

FORMAT COLOR 3 ON.

WRITE:/3(118) sy-uline.

WRITE:/3 sy-vline, 5 'VENDOR', 18 sy-vline, 20 'STATUS',

43 sy-vline, 45 'MESSAGE', 120 sy-vline,

/3(118) sy-uline.

FORMAT COLOR OFF.

FORMAT COLOR 5 ON.

LOOP AT it_message INTO wa_message.

WRITE:/3 sy-vline, 5 wa_message-vendor, 18 sy-vline,

20 wa_message-status, 43 sy-vline, 45 wa_message-message,

120 sy-vline,

/3(118) sy-uline.

ENDLOOP.

FORMAT COLOR OFF.

FORMAT INVERSE OFF.

ENDFORM. " get_return_messages

*&---------------------------------------------------------------------*

*& Form write_heading

*&---------------------------------------------------------------------*

* Writting heading of status report

*----------------------------------------------------------------------*

FORM write_heading .

WRITE:/40 'Status Report for Vendor Contract Creation'.

WRITE:/3(118) sy-uline.

SKIP 2.

ENDFORM. " write_heading

Author: Kaleemullah
Submitted: 19/03/2007

Description: Getting Reschedule exceptions with purchase order status LIKE MD04 (Stock Requirement List) transaction behaviour, Generally we need to work out on MDKP, MDTB and many other tables to extract the Exception message. Use the following code sample for the scenario of displaying Exception messages of a particular PO.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
FORM get_reschedules.
* Get Rescheduling Exceptions...
  DATA: v_ind LIKE sy-tabix.
*GET ALL Exceptions into i_excep.
  SELECT aussl auslt FROM t458b INTO TABLE i_excep
                                      WHERE spras = sy-langu.

  SORT i_tab3 BY matnr werks.
  DELETE ADJACENT DUPLICATES FROM i_tab3 COMPARING matnr werks.

  LOOP AT i_tab3 INTO w_itab3.
    REFRESH i_mdez.
    CHECK NOT w_itab3-matnr IS INITIAL.
    CHECK NOT w_itab3-werks IS INITIAL.

    CALL FUNCTION 'MD_STOCK_REQUIREMENTS_LIST_API'
      EXPORTING
        matnr = w_itab3-matnr
        werks = w_itab3-werks
      TABLES
        mdezx = i_mdez.

    SORT i_mdez BY extra aline.
    i_mdez-selkz = 'K'.
    MODIFY i_mdez TRANSPORTING selkz
                               WHERE selkz NE 'K'.

    LOOP AT i_tab1  WHERE matnr = w_itab3-matnr
                    AND   werks = w_itab3-werks.
      READ TABLE i_mdez WITH KEY extra+0(10)  = i_tab1-ebeln
                                 extra+11(05) = i_tab1-ebelp
                                 selkz = 'K'.
      IF sy-subrc = 0.
        v_ind = sy-tabix.
        i_mdez-aline = i_tab1-etenr.
        i_mdez-selkz = ' '.
        MODIFY i_mdez INDEX v_ind TRANSPORTING aline selkz.
      ENDIF.
      READ TABLE i_excep INTO w_excep WITH KEY aussl = i_mdez-aussl.
      i_tab1-auslt   = w_excep-auslt.
      i_tab1-mng01   = i_mdez-mng01.
      i_tab1-umdat   = i_mdez-umdat.
      i_tab1-v_flag  = i_mdez-aline.
      MODIFY i_tab1     TRANSPORTING auslt mng01 umdat v_flag
                        WHERE ebeln  EQ i_mdez-extra+0(10)
                        AND   ebelp  EQ i_mdez-extra+11(05)
                        AND   etenr  EQ i_mdez-aline
                        AND   menge  NE 0
                        AND   v_flag EQ ' '.
      CLEAR: i_mdez,
             i_tab1,
             v_ind,
             w_excep.
    ENDLOOP.
  ENDLOOP.
ENDFORM.                    " get_reschedules

The Function module 'MD_STOCK_REQUIREMENTS_LIST_API' will return the Output similar to MD04 (Stock Requirement List) transaction.

Author: Kaleemullah

Submitted: 17/04/2007

Report to Display All change History of Purchase requisitions With their release strategies.

Here is a hand made ready made report to display all the release strategies of purchase requisitions along with List of Approvers. This report may be useful for many with a minimal changes to be made in order to meet their individual requirement.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
TABLES :      cdhdr,
              t001w,
              eban,
              ekko.
*&---------------------------------------------------------------------*
*                         Type Declarations                            *
*&---------------------------------------------------------------------*
TYPE-POOLS : slis.

TYPES:  BEGIN OF t_cdhdr,
             objectid   LIKE cdhdr-objectid,
             changenr   LIKE cdhdr-changenr,
             objectclas LIKE cdhdr-objectclas,
             tcode      LIKE cdhdr-tcode,
             udate      LIKE cdhdr-udate,
             username   LIKE cdhdr-username,
             utime      LIKE cdhdr-utime,
             flag       TYPE c,
        END OF t_cdhdr,

        BEGIN OF t_eban,
             banfn   LIKE eban-banfn,    "Purchase requisition number
             bnfpo   LIKE eban-bnfpo,    "Item number of purch.req.
             bsart LIKE eban-bsart, "Purch.req document type
             frgkz LIKE eban-frgkz, "Release indicator
             frgzu LIKE eban-frgzu, "Release status
             frgst LIKE eban-frgst, "Release strategy in purc. req.
             ekgrp LIKE eban-ekgrp, "Purchasing group
             ernam   LIKE eban-ekgrp,    "Name of Person Crea'd Object
             afnam LIKE eban-afnam, "Name of requ'er/requester
             txz01 LIKE eban-txz01, "Short text
             matnr LIKE eban-matnr, "Material number
             werks LIKE eban-werks, "Plant
             menge LIKE eban-menge, "Purchase requisition quantity
             meins LIKE eban-meins, "Purch.req unit of measure
             badat LIKE eban-badat, "Requisition (request) date
             frgdt LIKE eban-frgdt, "Purch.req release date
             preis LIKE eban-preis, "Price in purchase requisition
             peinh   LIKE eban-peinh,    "Price Unit
             flief LIKE eban-flief, "Fixed vendor
             ebeln LIKE eban-ebeln, "Purchase order number
             ebelp LIKE eban-ebelp, "Purchase order item number
             frggr LIKE eban-frggr, "Release group
             waers LIKE eban-waers, "Currency Key
        END OF t_eban,

        BEGIN OF t_ebkn,
             banfn   LIKE eban-banfn,    "Purchase requisition number
             bnfpo   LIKE eban-bnfpo,    "Item number of purch.req.
             kostl   LIKE ebkn-kostl,    "Cost Center
        END OF t_ebkn,

        BEGIN OF t_output,
             werks   LIKE eban-werks,        "Plant               -1
             banfn   LIKE eban-banfn,        "Purchase Requisition-2
             bnfpo   LIKE eban-bnfpo,        "Item Pur.Requisition-3
             bsart   LIKE eban-bsart,        "Document Type       -4
             frggr   LIKE eban-frggr,     "Release Group       -5
             frgzu   LIKE eban-frgzu,     "Release Status      -6
             rcode(24),                      "Release Code        -7
             frgst   LIKE eban-frgst,        "Release Strategy
             frgkz   LIKE eban-frgkz,     "Release Indicator   -8
             ernam   LIKE eban-ernam,        "Person Responsible  -9
             kostl   LIKE ebkn-kostl,        "Cost Center         -10
             matnr   LIKE eban-matnr,        "Material            -11
             txz01   LIKE eban-txz01,        "Short Text          -12
             menge   LIKE eban-menge,        "Quantity Requested  -13
             meins   LIKE eban-meins,        "Unit of Measure     -14
             badat   LIKE eban-badat,        "Req Date            -15
             frgdt   LIKE eban-frgdt,        "Release Date        -16
             preis   LIKE eban-preis,        "Valuation Price     -17
             waers   LIKE eban-waers,        "Currency            -18
             peinh   LIKE eban-peinh,        "Per Unit            -19
             flief   LIKE eban-flief,        "Fixed Vendor        -20
             ebeln   LIKE ekpo-ebeln,        "Purchase Order      -21
             ebelp   LIKE ekpo-ebelp,        "Item PO             -22
             afnam   LIKE eban-afnam,        "Requisitioner       -23
       END OF t_output,

       BEGIN OF t_tcdrp,
           object LIKE tcdrp-object,
       END OF t_tcdrp,

       BEGIN OF t_t16fs,
           frggr LIKE t16fs-frggr,
           frgsx LIKE t16fs-frgsx,
           frgc1 LIKE t16fs-frgc1,
           frgc2 LIKE t16fs-frgc2,
           frgc3 LIKE t16fs-frgc3,
           frgc4 LIKE t16fs-frgc4,
           frgc5 LIKE t16fs-frgc5,
           frgc6 LIKE t16fs-frgc6,
           frgc7 LIKE t16fs-frgc7,
           frgc8 LIKE t16fs-frgc8,
       END OF t_t16fs,

       BEGIN OF t_cdpos,
            objectid   LIKE cdpos-objectid,
            changenr   LIKE cdpos-changenr,
            objectclas LIKE cdpos-objectclas,
            tabkey     LIKE cdpos-tabkey,
            fname      LIKE cdpos-fname,
            value_new  LIKE cdpos-value_new,
            value_old  LIKE cdpos-value_old,
       END OF t_cdpos,

       BEGIN OF t_cdpos1,
            objectid   LIKE eban-banfn,
            changenr   LIKE cdpos-changenr,
            objectclas LIKE cdpos-objectclas,
            value_new  LIKE cdpos-value_new,
       END OF t_cdpos1.

*&---------------------------------------------------------------------*
*                         Table Declarations                           *
*&---------------------------------------------------------------------*
DATA  : i_eban   TYPE STANDARD TABLE OF t_eban,
        i_ebkn   TYPE STANDARD TABLE OF t_ebkn,
        i_output TYPE STANDARD TABLE OF t_output,
        i_tcdrp  TYPE STANDARD TABLE OF t_tcdrp,
        i_cdhdr  TYPE STANDARD TABLE OF t_cdhdr,
        i_t16fs  TYPE STANDARD TABLE OF t_t16fs,
        i_cdpos  TYPE STANDARD TABLE OF t_cdpos,
        i_cdpos1 TYPE STANDARD TABLE OF t_cdpos1,
        i_cdpos3 TYPE STANDARD TABLE OF t_cdpos.

DATA  : t_fcat TYPE slis_t_fieldcat_alv.

*&---------------------------------------------------------------------*
*                         Work Area Declarations                       *
*&---------------------------------------------------------------------*
DATA  : wa_eban    LIKE LINE OF i_eban,
        wa_ebkn    LIKE LINE OF i_ebkn,
        wa_output  LIKE LINE OF i_output,
        wa_tcdrp   LIKE LINE OF i_tcdrp,
        wa_t16fs   LIKE LINE OF i_t16fs,
        wa_cdpos   LIKE LINE OF i_cdpos,
        wa_cdpos3  LIKE LINE OF i_cdpos.

DATA  : wa_fcat TYPE slis_fieldcat_alv.

*&---------------------------------------------------------------------*
*                         Constants Declarations                       *
*&---------------------------------------------------------------------*
CONSTANTS: c_me       LIKE tcdrp-devclass VALUE 'ME',
           c_inc(1)   TYPE c VALUE 'I',
           c_eq(2)    TYPE c VALUE 'EQ',
           c_frgzu(5) TYPE c VALUE 'FRGZU',
           c_frgkz(5) TYPE c VALUE 'FRGKZ',
           c_eban(4)  TYPE c VALUE 'EBAN',
           c_update   TYPE c VALUE 'U'.

*&---------------------------------------------------------------------*
*                         Input parameters                             *
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-033.
SELECT-OPTIONS :
           s_bukrs  FOR ekko-bukrs       OBLIGATORY,
           s_ekorg  FOR eban-ekorg       OBLIGATORY,
           s_ekgrp  FOR eban-ekgrp,
           s_bsart  FOR eban-bsart,
           s_value  FOR cdhdr-objectid,
           s_frggr  FOR ekko-frggr,
           s_user   FOR cdhdr-username,
           s_date   FOR cdhdr-udate,
           s_tcode  FOR cdhdr-tcode      OBLIGATORY,
           s_werks  FOR t001w-werks      OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.

SELECT-OPTIONS :
           s_object FOR cdhdr-objectclas NO-DISPLAY.
*&---------------------------------------------------------------------*
*                   INITIALIZATION
*&---------------------------------------------------------------------*
INITIALIZATION.

  PERFORM get_object_class.

*&---------------------------------------------------------------------*
*                   AT SELECTION-SCREEN
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN.
* Validate Input At Selection Screen
* PERFORM screen_validation.
*&---------------------------------------------------------------------*
*                   START-OF-SELECTION.
*&---------------------------------------------------------------------*
START-OF-SELECTION.
* Get all Transactions from CDHDR
  PERFORM get_cdhdr.
* Get Purchase Requisition Data
  PERFORM doc_details.
* Get Release codes
  PERFORM get_relcode.
*&---------------------------------------------------------------------*
*                   END-OF-SELECTION.
*&---------------------------------------------------------------------*
END-OF-SELECTION.
  IF i_eban IS INITIAL.
    MESSAGE s000(zm) WITH 'No Records Found for the Selection'(001).
  ELSE.
* Prepare O/P Table
    PERFORM fill_output.
* Submit to ALV O/P
    PERFORM alv_output.
  ENDIF.
*&---------------------------------------------------------------------*
*&                    Form  get_object_class
*&---------------------------------------------------------------------*
*                 Get Object Class for Purchase Req.
*----------------------------------------------------------------------*
FORM get_object_class.

  SELECT object
    INTO TABLE i_tcdrp
    FROM tcdrp
    WHERE devclass = c_me.

  LOOP AT i_tcdrp INTO wa_tcdrp.
    s_object-sign   = c_inc.
    s_object-option = c_eq.
    s_object-low    = wa_tcdrp-object.
    APPEND s_object.
  ENDLOOP.

ENDFORM.                    " get_object_class
*&---------------------------------------------------------------------*
*&                        Form  get_cdhdr
*&---------------------------------------------------------------------*
*                       Get Document Details
*----------------------------------------------------------------------*
FORM get_cdhdr.

  SELECT objectid
         changenr
         objectclas
         tcode
         udate
         username
         utime
                    INTO TABLE i_cdhdr
                    FROM cdhdr
                    WHERE objectclas IN s_object
                    AND   objectid   IN s_value
                    AND   tcode      IN s_tcode
                    AND   udate      IN s_date
                    AND   username   IN s_user
                    AND   change_ind =  'U'.
  IF sy-subrc = 0.
    SORT i_cdhdr BY objectclas objectid.

    SELECT objectid
           changenr
           objectclas
           tabkey
           fname
           value_new
           value_old
                      INTO TABLE i_cdpos  FROM cdpos
                      FOR ALL ENTRIES  IN i_cdhdr
                      WHERE objectclas EQ i_cdhdr-objectclas
                      AND   objectid   EQ i_cdhdr-objectid
                      AND   changenr   EQ i_cdhdr-changenr
                      AND   tabname    EQ c_eban
                      AND   fname      EQ c_frgzu
                      AND   chngind    EQ c_update.

    SELECT objectid
           changenr
           objectclas
           tabkey
           fname
           value_new
           value_old
                      INTO TABLE i_cdpos3 FROM cdpos
                      FOR ALL ENTRIES  IN i_cdhdr
                      WHERE objectclas EQ i_cdhdr-objectclas
                      AND   objectid   EQ i_cdhdr-objectid
                      AND   changenr   EQ i_cdhdr-changenr
                      AND   tabname    EQ c_eban
                      AND   fname      EQ c_frgkz
                      AND   chngind    EQ c_update.

    IF sy-subrc = 0.
      i_cdpos1[] = i_cdpos[].
      SORT i_cdpos1 BY objectid.
      DELETE ADJACENT DUPLICATES FROM i_cdpos1[] COMPARING objectid.
    ENDIF.
  ENDIF.

ENDFORM.                    " get_cdhdr
*&---------------------------------------------------------------------*
*&                    Form  doc_details
*&---------------------------------------------------------------------*
*                   Get Document Details
*----------------------------------------------------------------------*
FORM doc_details.

  IF NOT i_cdpos1[] IS INITIAL.
    SORT i_cdpos1 BY objectid.

    SELECT   banfn    "Purchase requisition number
             bnfpo    "Item number of purchase requisition
             bsart    "Purchase requisition document type
             frgkz    "Release indicator
             frgzu    "Release status
             frgst    "Release strategy in the purc. requisition
             ekgrp    "Purchasing group
             ernam    "Name of Person who Created the Object
             afnam    "Name of requisitioner/requester
             txz01    "Short text
             matnr    "Material number
             werks    "Plant
             menge    "Purchase requisition quantity
             meins    "Purchase requisition unit of measure
             badat    "Requisition (request) date
             frgdt    "Purchase requisition release date
             preis    "Price in purchase requisition
             peinh    "Price Unit
             flief    "Fixed vendor
             ebeln    "Purchase order number
             ebelp    "Purchase order item number
             frggr  "Release group
             waers    "Currency Key
                       INTO TABLE i_eban FROM eban
                       FOR ALL ENTRIES IN i_cdpos1
                       WHERE banfn EQ i_cdpos1-objectid
                       AND   bsart IN s_bsart
                       AND   ekgrp IN s_ekgrp
                       AND   ekorg IN s_ekorg
                       AND   frggr IN s_frggr
                       AND   werks IN s_werks.

    REFRESH i_cdpos1.

    IF sy-subrc = 0.
      SORT i_eban BY banfn bnfpo.
      SELECT   banfn    "Purchase requisition number
               bnfpo    "Item number of purchase requisition
               kostl    "Cost Center
                         INTO TABLE i_ebkn FROM ebkn
                         FOR ALL ENTRIES IN i_eban
                         WHERE banfn EQ i_eban-banfn
                         AND   bnfpo EQ i_eban-bnfpo.
      IF sy-subrc = 0.
        SORT i_ebkn BY banfn bnfpo.
      ENDIF.
    ENDIF.

  ENDIF.

ENDFORM.                    " doc_details
*&---------------------------------------------------------------------*
*&                  Form  fill_output
*&---------------------------------------------------------------------*
*               Prepare Final O/P Table
*----------------------------------------------------------------------*
FORM fill_output.

  DATA : v_count        TYPE i,
         v_chng_flg     TYPE c.

  v_count = 0.

  SORT i_cdpos  BY tabkey changenr.
  SORT i_cdpos3 BY objectid changenr objectclas tabkey fname.

  LOOP AT i_cdpos INTO wa_cdpos.

    ON CHANGE OF wa_cdpos-tabkey.
      v_chng_flg = 'X'.
      CLEAR : v_count.
    ENDON.

    v_count = v_count + 1.

    READ TABLE i_eban INTO wa_eban WITH KEY banfn = wa_cdpos-objectid
                                           bnfpo = wa_cdpos-tabkey+13(5)
                                           BINARY SEARCH.
    IF sy-subrc = 0.

      READ TABLE i_ebkn INTO wa_ebkn WITH KEY banfn = wa_eban-banfn
                                              bnfpo = wa_eban-bnfpo
                                              BINARY SEARCH.
      IF sy-subrc = 0.
        wa_output-kostl = wa_ebkn-kostl.
      ENDIF.
* Get all release codes for the current Rel. Strategy
      READ TABLE i_t16fs INTO wa_t16fs WITH KEY frggr = wa_eban-frggr
                                                frgsx = wa_eban-frgst
                                                BINARY SEARCH.
      IF sy-subrc = 0.
* Prepare Release Code
        PERFORM relcode USING v_count.
      ENDIF.
* Read Release Indicator
      PERFORM read_indicator.
      IF sy-subrc = 0.
        IF v_chng_flg = 'X'.
          wa_output-frgkz = wa_cdpos3-value_old.
        ELSE.
          wa_output-frgkz = wa_cdpos3-value_new.
        ENDIF.
      ENDIF.

      wa_output-werks = wa_eban-werks.
      wa_output-banfn = wa_eban-banfn.
      wa_output-bnfpo = wa_eban-bnfpo.
      wa_output-bsart = wa_eban-bsart.
      wa_output-frggr = wa_eban-frggr.
      wa_output-frgst = wa_eban-frgst.
      wa_output-ernam = wa_eban-ernam.
      wa_output-matnr = wa_eban-matnr.
      wa_output-txz01 = wa_eban-txz01.
      wa_output-menge = wa_eban-menge.
      wa_output-meins = wa_eban-meins.
      wa_output-badat = wa_eban-badat.
      wa_output-frgdt = wa_eban-frgdt.
      wa_output-preis = wa_eban-preis.
      wa_output-waers = wa_eban-waers.
      wa_output-peinh = wa_eban-peinh.
      wa_output-flief = wa_eban-flief.
      wa_output-ebeln = wa_eban-ebeln.
      wa_output-ebelp = wa_eban-ebelp.
      wa_output-afnam = wa_eban-afnam.
      wa_output-frgzu = wa_cdpos-value_new.

      APPEND  wa_output TO i_output.

      CLEAR:  wa_output,
              wa_eban,
              wa_ebkn,
              wa_t16fs,
              wa_cdpos3,
              v_chng_flg.
    ENDIF.

  ENDLOOP.

ENDFORM.                    " fill_output
*&---------------------------------------------------------------------*
*&                        Form  alv_output
*&---------------------------------------------------------------------*
*                         ALV O/P Display
*----------------------------------------------------------------------*
FORM alv_output.

  PERFORM fill_field_catalog.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
     i_grid_title                      =  text-034
     it_fieldcat                       =  t_fcat
    TABLES
      t_outtab                          = i_output
            .
  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.                    " alv_output
*&---------------------------------------------------------------------*
*&      Form  fill_field_catalog
*&---------------------------------------------------------------------*
*       Build Field Catalog
*----------------------------------------------------------------------*
FORM fill_field_catalog.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'WERKS' .
  wa_fcat-ref_tabname = 'T024' .
  wa_fcat-outputlen   =  5 . "colume width
  wa_fcat-seltext_m   = 'Plant'(010).
  wa_fcat-col_pos     =  1.
  wa_fcat-key         =  'X'.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'BANFN' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  15. "colume width
  wa_fcat-seltext_m   = 'Purch. Req.'(011).
  wa_fcat-col_pos     =  2.
  wa_fcat-key         =  'X'.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'BNFPO' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  5. "colume width
  wa_fcat-seltext_m   = 'Item'(012).
  wa_fcat-col_pos     =  3.
  wa_fcat-key         =  'X'.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'BSART' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  4. "colume width
  wa_fcat-seltext_m   = 'Document Type'(013).
  wa_fcat-col_pos     =  4.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'FRGGR' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  4. "colume width
  wa_fcat-seltext_m   = 'Grp.'(014).
  wa_fcat-col_pos     =  5.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'FRGZU' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  8. "colume width
  wa_fcat-seltext_m   = 'Rel Stat'(015).
  wa_fcat-col_pos     =  6.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'RCODE' .
  wa_fcat-outputlen   =  24. "colume width
  wa_fcat-seltext_m   = 'Rel. Code'(016).
  wa_fcat-col_pos     =  7.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'FRGKZ' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  4. "colume width
  wa_fcat-seltext_m   = 'Rel'(017).
  wa_fcat-col_pos     =  8.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'ERNAM' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  14. "colume width
  wa_fcat-seltext_m   = 'Person Resp.'(018).
  wa_fcat-col_pos     =  9.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'KOSTL' .
  wa_fcat-ref_tabname = 'EBKN' .
  wa_fcat-outputlen   =  10. "colume width
  wa_fcat-seltext_m   = 'Cost Center'(019).
  wa_fcat-col_pos     =  10.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'MATNR' .
  wa_fcat-ref_tabname = 'eban' .
  wa_fcat-outputlen   =  18. "colume width
  wa_fcat-seltext_m   = 'Material'(020).
  wa_fcat-col_pos     =  11.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'TXZ01' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  25. "colume width
  wa_fcat-seltext_m   = 'Short Text'(021).
  wa_fcat-col_pos     =  12.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'MENGE' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  13. "colume width
  wa_fcat-seltext_m   = 'Qty. Requested'(022).
  wa_fcat-col_pos     =  13.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'MEINS' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  3. "colume width
  wa_fcat-seltext_m   = 'Un.'(023).
  wa_fcat-col_pos     =  14.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'BADAT' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  5 . "colume width
  wa_fcat-seltext_m   = 'Req. Date'(024).
  wa_fcat-col_pos     =  15.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'FRGDT' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  5 . "colume width
  wa_fcat-seltext_m   = 'Rel. Date'(025).
  wa_fcat-col_pos     =  16.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'PREIS' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  11. "colume width
  wa_fcat-seltext_m   = 'Valn. Price'(026).
  wa_fcat-col_pos     =  17.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'WAERS' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  5 . "colume width
  wa_fcat-seltext_m   = 'Curr'(027).
  wa_fcat-col_pos     =  18.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'PEINH' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  5 . "colume width
  wa_fcat-seltext_m   = 'Per'(028).
  wa_fcat-col_pos     =  19.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'FLIEF' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  10. "colume width
  wa_fcat-seltext_m   = 'Fixed Vendor'(029).
  wa_fcat-col_pos     =  20.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'EBELN' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  10. "colume width
  wa_fcat-seltext_m   = 'Purchase Order'(030).
  wa_fcat-col_pos     =  21.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'EBELP' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  5. "colume width
  wa_fcat-seltext_m   = 'Item'(031).
  wa_fcat-col_pos     =  22.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'AFNAM' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  12. "colume width
  wa_fcat-seltext_m   = 'Requisitioner'(032).
  wa_fcat-col_pos     =  23.
  APPEND wa_fcat TO t_fcat.

ENDFORM.                    " fill_field_catalog
*&---------------------------------------------------------------------*
*&      Form  get_relcode
*&---------------------------------------------------------------------*
*       Get Release codes for all the documents
*----------------------------------------------------------------------*
FORM get_relcode.
  IF NOT i_eban IS INITIAL.

    SELECT  frggr
            frgsx
            frgc1
            frgc2
            frgc3
            frgc4
            frgc5
            frgc6
            frgc7
            frgc8
                  INTO TABLE i_t16fs FROM t16fs
                  FOR ALL ENTRIES IN i_eban
                  WHERE frggr = i_eban-frggr
                  AND   frgsx = i_eban-frgst.
    IF sy-subrc = 0.
      SORT i_t16fs BY frggr frgsx.
    ENDIF.

  ENDIF.
ENDFORM.                    " get_relcode
*&---------------------------------------------------------------------*
*&                          Form  relcode
*&---------------------------------------------------------------------*
*                 Concatenate Release Codes USING <FS>
*----------------------------------------------------------------------*
FORM relcode USING p_v_count TYPE i.

  DATA : v_ind TYPE sy-index.

  FIELD-SYMBOLS <fs> TYPE ANY.

  v_ind = 3.

  DO p_v_count TIMES.
    ASSIGN COMPONENT v_ind OF
           STRUCTURE wa_t16fs TO <fs>.
    IF sy-subrc = 0.
      CONCATENATE  wa_output-rcode  <fs> INTO wa_output-rcode
                                           SEPARATED BY space.
      v_ind = v_ind + 1.
    ENDIF.
  ENDDO.

ENDFORM.                    " relcode
*&---------------------------------------------------------------------*
*&                      Form  read_indicator
*&---------------------------------------------------------------------*
*                  To read the release indicator
*----------------------------------------------------------------------*
FORM read_indicator.

  READ TABLE i_cdpos3 INTO wa_cdpos3 WITH KEY
                               objectid     = wa_cdpos-objectid
                               changenr     = wa_cdpos-changenr
                               objectclas   = wa_cdpos-objectclas
                               tabkey       = wa_cdpos-tabkey
                               fname        = c_frgkz.
  IF sy-subrc <> 0.

    READ TABLE i_cdpos3 INTO wa_cdpos3 WITH KEY
                                 objectid     = wa_cdpos-objectid
                                 objectclas   = wa_cdpos-objectclas
                                 tabkey       = wa_cdpos-tabkey
                                 fname        = c_frgkz.
  ENDIF.
ENDFORM.                    " read_indicatorTABLES :      cdhdr,
              t001w,
              eban,
              ekko.
*&---------------------------------------------------------------------*
*                         Type Declarations                            *
*&---------------------------------------------------------------------*
TYPE-POOLS : slis.

TYPES:  BEGIN OF t_cdhdr,
             objectid   LIKE cdhdr-objectid,
             changenr   LIKE cdhdr-changenr,
             objectclas LIKE cdhdr-objectclas,
             tcode      LIKE cdhdr-tcode,
             udate      LIKE cdhdr-udate,
             username   LIKE cdhdr-username,
             utime      LIKE cdhdr-utime,
             flag       TYPE c,
        END OF t_cdhdr,

        BEGIN OF t_eban,
             banfn   LIKE eban-banfn,    "Purchase requisition number
             bnfpo   LIKE eban-bnfpo,    "Item number of purch.req.
             bsart LIKE eban-bsart, "Purch.req document type
             frgkz LIKE eban-frgkz, "Release indicator
             frgzu LIKE eban-frgzu, "Release status
             frgst LIKE eban-frgst, "Release strategy in purc. req.
             ekgrp LIKE eban-ekgrp, "Purchasing group
             ernam   LIKE eban-ekgrp,    "Name of Person Crea'd Object
             afnam LIKE eban-afnam, "Name of requ'er/requester
             txz01 LIKE eban-txz01, "Short text
             matnr LIKE eban-matnr, "Material number
             werks LIKE eban-werks, "Plant
             menge LIKE eban-menge, "Purchase requisition quantity
             meins LIKE eban-meins, "Purch.req unit of measure
             badat LIKE eban-badat, "Requisition (request) date
             frgdt LIKE eban-frgdt, "Purch.req release date
             preis LIKE eban-preis, "Price in purchase requisition
             peinh   LIKE eban-peinh,    "Price Unit
             flief LIKE eban-flief, "Fixed vendor
             ebeln LIKE eban-ebeln, "Purchase order number
             ebelp LIKE eban-ebelp, "Purchase order item number
             frggr LIKE eban-frggr, "Release group
             waers LIKE eban-waers, "Currency Key
        END OF t_eban,

        BEGIN OF t_ebkn,
             banfn   LIKE eban-banfn,    "Purchase requisition number
             bnfpo   LIKE eban-bnfpo,    "Item number of purch.req.
             kostl   LIKE ebkn-kostl,    "Cost Center
        END OF t_ebkn,

        BEGIN OF t_output,
             werks   LIKE eban-werks,        "Plant               -1
             banfn   LIKE eban-banfn,        "Purchase Requisition-2
             bnfpo   LIKE eban-bnfpo,        "Item Pur.Requisition-3
             bsart   LIKE eban-bsart,        "Document Type       -4
             frggr   LIKE eban-frggr,     "Release Group       -5
             frgzu   LIKE eban-frgzu,     "Release Status      -6
             rcode(24),                      "Release Code        -7
             frgst   LIKE eban-frgst,        "Release Strategy
             frgkz   LIKE eban-frgkz,     "Release Indicator   -8
             ernam   LIKE eban-ernam,        "Person Responsible  -9
             kostl   LIKE ebkn-kostl,        "Cost Center         -10
             matnr   LIKE eban-matnr,        "Material            -11
             txz01   LIKE eban-txz01,        "Short Text          -12
             menge   LIKE eban-menge,        "Quantity Requested  -13
             meins   LIKE eban-meins,        "Unit of Measure     -14
             badat   LIKE eban-badat,        "Req Date            -15
             frgdt   LIKE eban-frgdt,        "Release Date        -16
             preis   LIKE eban-preis,        "Valuation Price     -17
             waers   LIKE eban-waers,        "Currency            -18
             peinh   LIKE eban-peinh,        "Per Unit            -19
             flief   LIKE eban-flief,        "Fixed Vendor        -20
             ebeln   LIKE ekpo-ebeln,        "Purchase Order      -21
             ebelp   LIKE ekpo-ebelp,        "Item PO             -22
             afnam   LIKE eban-afnam,        "Requisitioner       -23
       END OF t_output,

       BEGIN OF t_tcdrp,
           object LIKE tcdrp-object,
       END OF t_tcdrp,

       BEGIN OF t_t16fs,
           frggr LIKE t16fs-frggr,
           frgsx LIKE t16fs-frgsx,
           frgc1 LIKE t16fs-frgc1,
           frgc2 LIKE t16fs-frgc2,
           frgc3 LIKE t16fs-frgc3,
           frgc4 LIKE t16fs-frgc4,
           frgc5 LIKE t16fs-frgc5,
           frgc6 LIKE t16fs-frgc6,
           frgc7 LIKE t16fs-frgc7,
           frgc8 LIKE t16fs-frgc8,
       END OF t_t16fs,

       BEGIN OF t_cdpos,
            objectid   LIKE cdpos-objectid,
            changenr   LIKE cdpos-changenr,
            objectclas LIKE cdpos-objectclas,
            tabkey     LIKE cdpos-tabkey,
            fname      LIKE cdpos-fname,
            value_new  LIKE cdpos-value_new,
            value_old  LIKE cdpos-value_old,
       END OF t_cdpos,

       BEGIN OF t_cdpos1,
            objectid   LIKE eban-banfn,
            changenr   LIKE cdpos-changenr,
            objectclas LIKE cdpos-objectclas,
            value_new  LIKE cdpos-value_new,
       END OF t_cdpos1.

*&---------------------------------------------------------------------*
*                         Table Declarations                           *
*&---------------------------------------------------------------------*
DATA  : i_eban   TYPE STANDARD TABLE OF t_eban,
        i_ebkn   TYPE STANDARD TABLE OF t_ebkn,
        i_output TYPE STANDARD TABLE OF t_output,
        i_tcdrp  TYPE STANDARD TABLE OF t_tcdrp,
        i_cdhdr  TYPE STANDARD TABLE OF t_cdhdr,
        i_t16fs  TYPE STANDARD TABLE OF t_t16fs,
        i_cdpos  TYPE STANDARD TABLE OF t_cdpos,
        i_cdpos1 TYPE STANDARD TABLE OF t_cdpos1,
        i_cdpos3 TYPE STANDARD TABLE OF t_cdpos.

DATA  : t_fcat TYPE slis_t_fieldcat_alv.

*&---------------------------------------------------------------------*
*                         Work Area Declarations                       *
*&---------------------------------------------------------------------*
DATA  : wa_eban    LIKE LINE OF i_eban,
        wa_ebkn    LIKE LINE OF i_ebkn,
        wa_output  LIKE LINE OF i_output,
        wa_tcdrp   LIKE LINE OF i_tcdrp,
        wa_t16fs   LIKE LINE OF i_t16fs,
        wa_cdpos   LIKE LINE OF i_cdpos,
        wa_cdpos3  LIKE LINE OF i_cdpos.

DATA  : wa_fcat TYPE slis_fieldcat_alv.

*&---------------------------------------------------------------------*
*                         Constants Declarations                       *
*&---------------------------------------------------------------------*
CONSTANTS: c_me       LIKE tcdrp-devclass VALUE 'ME',
           c_inc(1)   TYPE c VALUE 'I',
           c_eq(2)    TYPE c VALUE 'EQ',
           c_frgzu(5) TYPE c VALUE 'FRGZU',
           c_frgkz(5) TYPE c VALUE 'FRGKZ',
           c_eban(4)  TYPE c VALUE 'EBAN',
           c_update   TYPE c VALUE 'U'.

*&---------------------------------------------------------------------*
*                         Input parameters                             *
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-033.
SELECT-OPTIONS :
           s_bukrs  FOR ekko-bukrs       OBLIGATORY,
           s_ekorg  FOR eban-ekorg       OBLIGATORY,
           s_ekgrp  FOR eban-ekgrp,
           s_bsart  FOR eban-bsart,
           s_value  FOR cdhdr-objectid,
           s_frggr  FOR ekko-frggr,
           s_user   FOR cdhdr-username,
           s_date   FOR cdhdr-udate,
           s_tcode  FOR cdhdr-tcode      OBLIGATORY,
           s_werks  FOR t001w-werks      OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.

SELECT-OPTIONS :
           s_object FOR cdhdr-objectclas NO-DISPLAY.
*&---------------------------------------------------------------------*
*                   INITIALIZATION
*&---------------------------------------------------------------------*
INITIALIZATION.

  PERFORM get_object_class.

*&---------------------------------------------------------------------*
*                   AT SELECTION-SCREEN
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN.
* Validate Input At Selection Screen
* PERFORM screen_validation.
*&---------------------------------------------------------------------*
*                   START-OF-SELECTION.
*&---------------------------------------------------------------------*
START-OF-SELECTION.
* Get all Transactions from CDHDR
  PERFORM get_cdhdr.
* Get Purchase Requisition Data
  PERFORM doc_details.
* Get Release codes
  PERFORM get_relcode.
*&---------------------------------------------------------------------*
*                   END-OF-SELECTION.
*&---------------------------------------------------------------------*
END-OF-SELECTION.
  IF i_eban IS INITIAL.
    MESSAGE s000(zm) WITH 'No Records Found for the Selection'(001).
  ELSE.
* Prepare O/P Table
    PERFORM fill_output.
* Submit to ALV O/P
    PERFORM alv_output.
  ENDIF.
*&---------------------------------------------------------------------*
*&                    Form  get_object_class
*&---------------------------------------------------------------------*
*                 Get Object Class for Purchase Req.
*----------------------------------------------------------------------*
FORM get_object_class.

  SELECT object
    INTO TABLE i_tcdrp
    FROM tcdrp
    WHERE devclass = c_me.

  LOOP AT i_tcdrp INTO wa_tcdrp.
    s_object-sign   = c_inc.
    s_object-option = c_eq.
    s_object-low    = wa_tcdrp-object.
    APPEND s_object.
  ENDLOOP.

ENDFORM.                    " get_object_class
*&---------------------------------------------------------------------*
*&                        Form  get_cdhdr
*&---------------------------------------------------------------------*
*                       Get Document Details
*----------------------------------------------------------------------*
FORM get_cdhdr.

  SELECT objectid
         changenr
         objectclas
         tcode
         udate
         username
         utime
                    INTO TABLE i_cdhdr
                    FROM cdhdr
                    WHERE objectclas IN s_object
                    AND   objectid   IN s_value
                    AND   tcode      IN s_tcode
                    AND   udate      IN s_date
                    AND   username   IN s_user
                    AND   change_ind =  'U'.
  IF sy-subrc = 0.
    SORT i_cdhdr BY objectclas objectid.

    SELECT objectid
           changenr
           objectclas
           tabkey
           fname
           value_new
           value_old
                      INTO TABLE i_cdpos  FROM cdpos
                      FOR ALL ENTRIES  IN i_cdhdr
                      WHERE objectclas EQ i_cdhdr-objectclas
                      AND   objectid   EQ i_cdhdr-objectid
                      AND   changenr   EQ i_cdhdr-changenr
                      AND   tabname    EQ c_eban
                      AND   fname      EQ c_frgzu
                      AND   chngind    EQ c_update.

    SELECT objectid
           changenr
           objectclas
           tabkey
           fname
           value_new
           value_old
                      INTO TABLE i_cdpos3 FROM cdpos
                      FOR ALL ENTRIES  IN i_cdhdr
                      WHERE objectclas EQ i_cdhdr-objectclas
                      AND   objectid   EQ i_cdhdr-objectid
                      AND   changenr   EQ i_cdhdr-changenr
                      AND   tabname    EQ c_eban
                      AND   fname      EQ c_frgkz
                      AND   chngind    EQ c_update.

    IF sy-subrc = 0.
      i_cdpos1[] = i_cdpos[].
      SORT i_cdpos1 BY objectid.
      DELETE ADJACENT DUPLICATES FROM i_cdpos1[] COMPARING objectid.
    ENDIF.
  ENDIF.

ENDFORM.                    " get_cdhdr
*&---------------------------------------------------------------------*
*&                    Form  doc_details
*&---------------------------------------------------------------------*
*                   Get Document Details
*----------------------------------------------------------------------*
FORM doc_details.

  IF NOT i_cdpos1[] IS INITIAL.
    SORT i_cdpos1 BY objectid.

    SELECT   banfn    "Purchase requisition number
             bnfpo    "Item number of purchase requisition
             bsart    "Purchase requisition document type
             frgkz    "Release indicator
             frgzu    "Release status
             frgst    "Release strategy in the purc. requisition
             ekgrp    "Purchasing group
             ernam    "Name of Person who Created the Object
             afnam    "Name of requisitioner/requester
             txz01    "Short text
             matnr    "Material number
             werks    "Plant
             menge    "Purchase requisition quantity
             meins    "Purchase requisition unit of measure
             badat    "Requisition (request) date
             frgdt    "Purchase requisition release date
             preis    "Price in purchase requisition
             peinh    "Price Unit
             flief    "Fixed vendor
             ebeln    "Purchase order number
             ebelp    "Purchase order item number
             frggr  "Release group
             waers    "Currency Key
                       INTO TABLE i_eban FROM eban
                       FOR ALL ENTRIES IN i_cdpos1
                       WHERE banfn EQ i_cdpos1-objectid
                       AND   bsart IN s_bsart
                       AND   ekgrp IN s_ekgrp
                       AND   ekorg IN s_ekorg
                       AND   frggr IN s_frggr
                       AND   werks IN s_werks.

    REFRESH i_cdpos1.

    IF sy-subrc = 0.
      SORT i_eban BY banfn bnfpo.
      SELECT   banfn    "Purchase requisition number
               bnfpo    "Item number of purchase requisition
               kostl    "Cost Center
                         INTO TABLE i_ebkn FROM ebkn
                         FOR ALL ENTRIES IN i_eban
                         WHERE banfn EQ i_eban-banfn
                         AND   bnfpo EQ i_eban-bnfpo.
      IF sy-subrc = 0.
        SORT i_ebkn BY banfn bnfpo.
      ENDIF.
    ENDIF.

  ENDIF.

ENDFORM.                    " doc_details
*&---------------------------------------------------------------------*
*&                  Form  fill_output
*&---------------------------------------------------------------------*
*               Prepare Final O/P Table
*----------------------------------------------------------------------*
FORM fill_output.

  DATA : v_count        TYPE i,
         v_chng_flg     TYPE c.

  v_count = 0.

  SORT i_cdpos  BY tabkey changenr.
  SORT i_cdpos3 BY objectid changenr objectclas tabkey fname.

  LOOP AT i_cdpos INTO wa_cdpos.

    ON CHANGE OF wa_cdpos-tabkey.
      v_chng_flg = 'X'.
      CLEAR : v_count.
    ENDON.

    v_count = v_count + 1.

    READ TABLE i_eban INTO wa_eban WITH KEY banfn = wa_cdpos-objectid
                                           bnfpo = wa_cdpos-tabkey+13(5)
                                           BINARY SEARCH.
    IF sy-subrc = 0.

      READ TABLE i_ebkn INTO wa_ebkn WITH KEY banfn = wa_eban-banfn
                                              bnfpo = wa_eban-bnfpo
                                              BINARY SEARCH.
      IF sy-subrc = 0.
        wa_output-kostl = wa_ebkn-kostl.
      ENDIF.
* Get all release codes for the current Rel. Strategy
      READ TABLE i_t16fs INTO wa_t16fs WITH KEY frggr = wa_eban-frggr
                                                frgsx = wa_eban-frgst
                                                BINARY SEARCH.
      IF sy-subrc = 0.
* Prepare Release Code
        PERFORM relcode USING v_count.
      ENDIF.
* Read Release Indicator
      PERFORM read_indicator.
      IF sy-subrc = 0.
        IF v_chng_flg = 'X'.
          wa_output-frgkz = wa_cdpos3-value_old.
        ELSE.
          wa_output-frgkz = wa_cdpos3-value_new.
        ENDIF.
      ENDIF.

      wa_output-werks = wa_eban-werks.
      wa_output-banfn = wa_eban-banfn.
      wa_output-bnfpo = wa_eban-bnfpo.
      wa_output-bsart = wa_eban-bsart.
      wa_output-frggr = wa_eban-frggr.
      wa_output-frgst = wa_eban-frgst.
      wa_output-ernam = wa_eban-ernam.
      wa_output-matnr = wa_eban-matnr.
      wa_output-txz01 = wa_eban-txz01.
      wa_output-menge = wa_eban-menge.
      wa_output-meins = wa_eban-meins.
      wa_output-badat = wa_eban-badat.
      wa_output-frgdt = wa_eban-frgdt.
      wa_output-preis = wa_eban-preis.
      wa_output-waers = wa_eban-waers.
      wa_output-peinh = wa_eban-peinh.
      wa_output-flief = wa_eban-flief.
      wa_output-ebeln = wa_eban-ebeln.
      wa_output-ebelp = wa_eban-ebelp.
      wa_output-afnam = wa_eban-afnam.
      wa_output-frgzu = wa_cdpos-value_new.

      APPEND  wa_output TO i_output.

      CLEAR:  wa_output,
              wa_eban,
              wa_ebkn,
              wa_t16fs,
              wa_cdpos3,
              v_chng_flg.
    ENDIF.

  ENDLOOP.

ENDFORM.                    " fill_output
*&---------------------------------------------------------------------*
*&                        Form  alv_output
*&---------------------------------------------------------------------*
*                         ALV O/P Display
*----------------------------------------------------------------------*
FORM alv_output.

  PERFORM fill_field_catalog.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
     i_grid_title                      =  text-034
     it_fieldcat                       =  t_fcat
    TABLES
      t_outtab                          = i_output
            .
  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.                    " alv_output
*&---------------------------------------------------------------------*
*&      Form  fill_field_catalog
*&---------------------------------------------------------------------*
*       Build Field Catalog
*----------------------------------------------------------------------*
FORM fill_field_catalog.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'WERKS' .
  wa_fcat-ref_tabname = 'T024' .
  wa_fcat-outputlen   =  5 . "colume width
  wa_fcat-seltext_m   = 'Plant'(010).
  wa_fcat-col_pos     =  1.
  wa_fcat-key         =  'X'.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'BANFN' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  15. "colume width
  wa_fcat-seltext_m   = 'Purch. Req.'(011).
  wa_fcat-col_pos     =  2.
  wa_fcat-key         =  'X'.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'BNFPO' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  5. "colume width
  wa_fcat-seltext_m   = 'Item'(012).
  wa_fcat-col_pos     =  3.
  wa_fcat-key         =  'X'.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'BSART' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  4. "colume width
  wa_fcat-seltext_m   = 'Document Type'(013).
  wa_fcat-col_pos     =  4.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'FRGGR' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  4. "colume width
  wa_fcat-seltext_m   = 'Grp.'(014).
  wa_fcat-col_pos     =  5.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'FRGZU' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  8. "colume width
  wa_fcat-seltext_m   = 'Rel Stat'(015).
  wa_fcat-col_pos     =  6.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'RCODE' .
  wa_fcat-outputlen   =  24. "colume width
  wa_fcat-seltext_m   = 'Rel. Code'(016).
  wa_fcat-col_pos     =  7.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'FRGKZ' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  4. "colume width
  wa_fcat-seltext_m   = 'Rel'(017).
  wa_fcat-col_pos     =  8.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'ERNAM' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  14. "colume width
  wa_fcat-seltext_m   = 'Person Resp.'(018).
  wa_fcat-col_pos     =  9.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'KOSTL' .
  wa_fcat-ref_tabname = 'EBKN' .
  wa_fcat-outputlen   =  10. "colume width
  wa_fcat-seltext_m   = 'Cost Center'(019).
  wa_fcat-col_pos     =  10.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'MATNR' .
  wa_fcat-ref_tabname = 'eban' .
  wa_fcat-outputlen   =  18. "colume width
  wa_fcat-seltext_m   = 'Material'(020).
  wa_fcat-col_pos     =  11.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'TXZ01' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  25. "colume width
  wa_fcat-seltext_m   = 'Short Text'(021).
  wa_fcat-col_pos     =  12.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'MENGE' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  13. "colume width
  wa_fcat-seltext_m   = 'Qty. Requested'(022).
  wa_fcat-col_pos     =  13.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'MEINS' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  3. "colume width
  wa_fcat-seltext_m   = 'Un.'(023).
  wa_fcat-col_pos     =  14.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'BADAT' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  5 . "colume width
  wa_fcat-seltext_m   = 'Req. Date'(024).
  wa_fcat-col_pos     =  15.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'FRGDT' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  5 . "colume width
  wa_fcat-seltext_m   = 'Rel. Date'(025).
  wa_fcat-col_pos     =  16.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'PREIS' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  11. "colume width
  wa_fcat-seltext_m   = 'Valn. Price'(026).
  wa_fcat-col_pos     =  17.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'WAERS' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  5 . "colume width
  wa_fcat-seltext_m   = 'Curr'(027).
  wa_fcat-col_pos     =  18.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'PEINH' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  5 . "colume width
  wa_fcat-seltext_m   = 'Per'(028).
  wa_fcat-col_pos     =  19.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'FLIEF' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  10. "colume width
  wa_fcat-seltext_m   = 'Fixed Vendor'(029).
  wa_fcat-col_pos     =  20.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'EBELN' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  10. "colume width
  wa_fcat-seltext_m   = 'Purchase Order'(030).
  wa_fcat-col_pos     =  21.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'EBELP' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  5. "colume width
  wa_fcat-seltext_m   = 'Item'(031).
  wa_fcat-col_pos     =  22.
  APPEND wa_fcat TO t_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname   = 'AFNAM' .
  wa_fcat-ref_tabname = 'EBAN' .
  wa_fcat-outputlen   =  12. "colume width
  wa_fcat-seltext_m   = 'Requisitioner'(032).
  wa_fcat-col_pos     =  23.
  APPEND wa_fcat TO t_fcat.

ENDFORM.                    " fill_field_catalog
*&---------------------------------------------------------------------*
*&      Form  get_relcode
*&---------------------------------------------------------------------*
*       Get Release codes for all the documents
*----------------------------------------------------------------------*
FORM get_relcode.
  IF NOT i_eban IS INITIAL.

    SELECT  frggr
            frgsx
            frgc1
            frgc2
            frgc3
            frgc4
            frgc5
            frgc6
            frgc7
            frgc8
                  INTO TABLE i_t16fs FROM t16fs
                  FOR ALL ENTRIES IN i_eban
                  WHERE frggr = i_eban-frggr
                  AND   frgsx = i_eban-frgst.
    IF sy-subrc = 0.
      SORT i_t16fs BY frggr frgsx.
    ENDIF.

  ENDIF.
ENDFORM.                    " get_relcode
*&---------------------------------------------------------------------*
*&                          Form  relcode
*&---------------------------------------------------------------------*
*                 Concatenate Release Codes USING <FS>
*----------------------------------------------------------------------*
FORM relcode USING p_v_count TYPE i.

  DATA : v_ind TYPE sy-index.

  FIELD-SYMBOLS <fs> TYPE ANY.

  v_ind = 3.

  DO p_v_count TIMES.
    ASSIGN COMPONENT v_ind OF
           STRUCTURE wa_t16fs TO <fs>.
    IF sy-subrc = 0.
      CONCATENATE  wa_output-rcode  <fs> INTO wa_output-rcode
                                           SEPARATED BY space.
      v_ind = v_ind + 1.
    ENDIF.
  ENDDO.

ENDFORM.                    " relcode
*&---------------------------------------------------------------------*
*&                      Form  read_indicator
*&---------------------------------------------------------------------*
*                  To read the release indicator
*----------------------------------------------------------------------*
FORM read_indicator.

  READ TABLE i_cdpos3 INTO wa_cdpos3 WITH KEY
                               objectid     = wa_cdpos-objectid
                               changenr     = wa_cdpos-changenr
                               objectclas   = wa_cdpos-objectclas
                               tabkey       = wa_cdpos-tabkey
                               fname        = c_frgkz.
  IF sy-subrc <> 0.

    READ TABLE i_cdpos3 INTO wa_cdpos3 WITH KEY
                                 objectid     = wa_cdpos-objectid
                                 objectclas   = wa_cdpos-objectclas
                                 tabkey       = wa_cdpos-tabkey
                                 fname        = c_frgkz.
  ENDIF.
ENDFORM.                    " read_indicator
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*&---------------------------------------------------------------------*
*& Report  YMPUR_OPENPO
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  YMPUR_OPENPO.

TYPES : BEGIN OF TP_EKPO,
          EBELN TYPE EBELN,
          EBELP TYPE EBELP,
          MATNR TYPE MATNR,
          MENGE TYPE BSTMG,
          MEINS TYPE BSTME,
          KNTTP TYPE KNTTP,
          PSTYP TYPE PSTYP,
          LGORT TYPE LGORT_D,
          NETPR TYPE BPREI,
          ELIKZ TYPE ELIKZ,
          LOEKZ TYPE ELOEK,
          WERKS TYPE EWERK,
        END OF TP_EKPO.

DATA :  T_EKPO TYPE STANDARD TABLE OF TP_EKPO,
        WA_EKPO TYPE TP_EKPO.

TYPES : BEGIN OF TP_EKKO,
          EBELN TYPE EBELN,
          BSART TYPE ESART,
          LIFNR TYPE ELIFN,
          BUKRS TYPE BUKRS,
          EKORG TYPE EKORG,
          EKGRP TYPE BKGRP,
          INCO1 TYPE INCO1,
          INCO2 TYPE INCO2,
          ZTERM TYPE DZTERM,
          AEDAT TYPE ERDAT,
          KNUMV TYPE KNUMV,
          WAERS TYPE WAERS,
        END OF TP_EKKO.

DATA :  T_EKKO TYPE STANDARD TABLE OF TP_EKKO,
        WA_EKKO TYPE TP_EKKO.

DATA : W_EBELN TYPE EKKO-EBELN.

CONSTANTS: C_X TYPE C VALUE 'X'.

SELECTION-SCREEN : BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_EBELN FOR W_EBELN OBLIGATORY.
SELECTION-SCREEN : END OF BLOCK B1.


START-OF-SELECTION.

  PERFORM FETCH_DATA.
  PERFORM GRDONE_CHECK.

END-OF-SELECTION.

  PERFORM CREATE_PO.

*&---------------------------------------------------------------------*
*&      Form  FETCH_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FETCH_DATA .

  SELECT EBELN EBELP MATNR MENGE KNTTP PSTYP
         LGORT NETPR ELIKZ LOEKZ WERKS
    FROM EKPO
    INTO CORRESPONDING FIELDS OF TABLE T_EKPO
    WHERE EBELN IN S_EBELN AND ELIKZ NE 'X' AND LOEKZ EQ ' '.

  IF T_EKPO  IS INITIAL.
    " PERFORM error log
  ENDIF.

  SELECT EBELN BSART LIFNR BUKRS EKORG EKGRP INCO1
         INCO2 ZTERM AEDAT KNUMV WAERS
    FROM EKKO
    INTO TABLE T_EKKO
    FOR ALL ENTRIES IN T_EKPO
    WHERE EBELN EQ T_EKPO-EBELN.

  IF T_EKKO  IS INITIAL.
    " PERFORM error log
  ENDIF.


ENDFORM.                    " FETCH_DATA
*&---------------------------------------------------------------------*
*&      Form  GRDONE_CHECK
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GRDONE_CHECK .

  DATA : TL_XEKBES TYPE STANDARD TABLE OF EKBES WITH HEADER LINE.
  DATA : L_IDX TYPE SY-TABIX.

  LOOP AT T_EKPO INTO WA_EKPO.

    L_IDX = SY-TABIX.

    CALL FUNCTION 'ME_READ_HISTORY'
      EXPORTING
        EBELN                    = WA_EKPO-EBELN
        EBELP                    = WA_EKPO-EBELP
        WEBRE                    = ''
*   I_BYPASSING_BUFFER       =
*   I_REFRESH_BUFFER         =
*   I_EKBEH                  =
*   LFGJA                    =
*   LFBNR                    =
*   LFPOS                    =
 TABLES
*   XEKBE                    =
  XEKBES                   = TL_XEKBES
*   XEKBEZ                   =
*   XEKBNK                   =
*   XEKBZ                    =
*   XRSEG                    =
.
    WA_EKPO-MENGE = WA_EKPO-MENGE - TL_XEKBES-WEMNG.
    MODIFY T_EKPO INDEX L_IDX FROM WA_EKPO TRANSPORTING MENGE.

  ENDLOOP.

ENDFORM.                    " GRDONE_CHECK

*&---------------------------------------------------------------------*
*&      Form  CREATE_PO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM CREATE_PO .

  DATA: WL_HEADER TYPE BAPIMEPOHEADER,
        WL_HEADERX TYPE BAPIMEPOHEADERX,
        TL_ITEM TYPE STANDARD TABLE OF BAPIMEPOITEM,
        TL_ITEMX TYPE STANDARD TABLE OF BAPIMEPOITEMX,
        TL_RETURN TYPE STANDARD TABLE OF BAPIRET2,
        WL_RETURN TYPE BAPIRET2,
        WL_ITEM LIKE BAPIMEPOITEM,
        WL_ITEMX LIKE BAPIMEPOITEMX,
        L_BUKRS TYPE BUKRS,
        L_PONO TYPE EBELN,
        L_INT TYPE I.

  DATA: BEGIN OF TL_BAPIRETURN OCCURS 0.
          INCLUDE STRUCTURE BAPIRET2.
  DATA: END OF TL_BAPIRETURN.

  LOOP AT T_EKKO INTO WA_EKKO.

    WL_HEADER-COMP_CODE = 'CG01'.
    WL_HEADER-DOC_TYPE = WA_EKKO-BSART.
    WL_HEADER-CREAT_DATE = WA_EKKO-AEDAT.
    WL_HEADER-ITEM_INTVL = '10'.
    WL_HEADER-VENDOR = WA_EKKO-LIFNR.
    WL_HEADER-LANGU = SY-LANGU.
    WL_HEADER-PMNTTRMS = WA_EKKO-ZTERM.
    WL_HEADER-PURCH_ORG = WA_EKKO-EKORG.
    WL_HEADER-PUR_GROUP = WA_EKKO-EKGRP.
    WL_HEADER-CURRENCY = WA_EKKO-WAERS.
    WL_HEADER-REF_1 = WA_EKKO-EBELN.

    WL_HEADERX-COMP_CODE = C_X.
    WL_HEADERX-DOC_TYPE = C_X.
    WL_HEADERX-CREAT_DATE = C_X.
    WL_HEADERX-ITEM_INTVL = C_X .
    WL_HEADERX-VENDOR = C_X.
    WL_HEADERX-LANGU = C_X.
    WL_HEADERX-PMNTTRMS = C_X .
    WL_HEADERX-PURCH_ORG = C_X.
    WL_HEADERX-PUR_GROUP = C_X.
    WL_HEADERX-CURRENCY = C_X.
    WL_HEADERX-REF_1 = C_X.

    LOOP AT T_EKPO INTO WA_EKPO WHERE EBELN = WA_EKKO-EBELN.

      L_INT = L_INT + 10.
      WL_ITEM-PO_ITEM = L_INT.
      WL_ITEM-MATERIAL = WA_EKPO-MATNR.
      WL_ITEM-PLANT = 'CGP1'.
      WL_ITEM-QUANTITY = WA_EKPO-MENGE.
      WL_ITEM-PO_UNIT = WA_EKPO-MEINS.
      WL_ITEM-STGE_LOC = WA_EKPO-LGORT.
      WL_ITEM-ITEM_CAT = WA_EKPO-PSTYP.
      WL_ITEM-NET_PRICE = WA_EKPO-NETPR.
      WL_ITEM-ACCTASSCAT = WA_EKPO-KNTTP.
      APPEND WL_ITEM TO TL_ITEM.

      WL_ITEMX-PO_ITEM = L_INT.
      WL_ITEMX-PO_ITEMX = C_X.
      WL_ITEMX-MATERIAL = C_X.
      WL_ITEMX-PLANT = C_X .
      WL_ITEMX-QUANTITY = C_X .
      WL_ITEMX-STGE_LOC = C_X .
      WL_ITEMX-ITEM_CAT = C_X .
      WL_ITEMX-NET_PRICE = C_X .
      WL_ITEMX-ACCTASSCAT = C_X.
      APPEND WL_ITEMX TO TL_ITEMX.

    ENDLOOP.

    CALL FUNCTION 'BAPI_PO_CREATE1'
      EXPORTING
        POHEADER         = WL_HEADER
        POHEADERX        = WL_HEADERX
      IMPORTING
        EXPPURCHASEORDER = L_PONO
      TABLES
        RETURN           = TL_RETURN
        POITEM           = TL_ITEM
        POITEMX          = TL_ITEMX.

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        WAIT   = 'X'
      IMPORTING
        RETURN = TL_BAPIRETURN.

    WRITE: / 'Puchase Doc: ', WA_EKKO-EBELN.
    SKIP.
    CLEAR: WL_HEADER, WL_ITEMX, WL_HEADERX, TL_ITEM, TL_ITEMX,WL_ITEM.

    IF L_PONO IS INITIAL.
      LOOP AT TL_RETURN INTO WL_RETURN.
        WRITE / WL_RETURN-MESSAGE.
        CLEAR WL_RETURN.
      ENDLOOP.
      ULINE.
      SKIP.
    ELSE.
      WRITE : / 'New  PO Created Under the number :',
              L_PONO HOTSPOT ON.
      ULINE.
      SKIP.
    ENDIF.

  ENDLOOP.

ENDFORM.                    " CREATE_PO

--->  Introduction / Overview     Function Module to calculate TAX in Purchase Order- What is it?     

  This development is used for calculating tax amount based on Condition types. Generally when we create Purchase order, the tax amount is calculated based on tax code.

While creating Purchase order if we click on taxes, the tax detailed screen will appear (refer below screen shot), In which we can see Tax calculated based on condition type.  The tax field contains the sum of all the condition types .However in our development we need to calculate tax amount only for certain condition types which we could not find in any table, so for that we developed this Function module in which we would be getting all the condition types value separately.

--->  How this Function Module will work:

The Function Module requires Purchase order header details, item details and vendor details of Purchase Order .In purchase order, tax details are item specific. So if Purchase Order has multiple items, the function module should be in item loop.

The Table parameter has T_KONV parameter. These T_KONV parameters will populate with all condition type and amounts

The below screenshot is for TABLES parameters.

Write this code in source code

*Local Data declaration
DATA: my_taxcom TYPE j_1b_taxcom ,
      l_taxcom  TYPE taxcom ,
      l_wa_t001    TYPE t001,
      e_taxcom  TYPE taxcom ,
      l_wa_komv TYPE komv ,
      l_gv_amount TYPE netwr ,
      l_unitprice TYPE netwr,
      l_ipiamount TYPE netwr,
      l_total_ipi TYPE netwr,
      l_total  TYPE netwr  ,
      l_taxamount TYPE netwr.

SELECT SINGLE * FROM t001
                INTO l_wa_t001
                WHERE bukrs EQ i_ekko-bukrs.

* Fill tax fields relevant for PO
my_taxcom-txreg_sf = i_lfa1-txjcd.
my_taxcom-txreg_st = i_ekpo-txjcd.
my_taxcom-taxbs    = i_lfa1-taxbs.
my_taxcom-ipisp    = i_lfa1-ipisp.
my_taxcom-brsch    = i_lfa1-brsch.
my_taxcom-mtuse    = i_ekpo-j_1bmatuse.
my_taxcom-mtorg    = i_ekpo-j_1bmatorg.
my_taxcom-ownpr    = i_ekpo-j_1bownpro.
my_taxcom-steuc    = i_ekpo-j_1bnbm.
my_taxcom-matkl    = i_ekpo-matkl.
my_taxcom-vrkme    = i_ekpo-meins.
my_taxcom-mgame    = i_ekpo-menge.

* ISS Calculation with 2-level tax jurisdiction code
* To get the ISS Tax Condtions, need to pass the Following Parameters
 my_taxcom-loc_se = i_lfa1-txjcd.
 my_taxcom-loc_sr = i_lfa1-txjcd. 
* if you don't pass the above parameters and if your PO has ISS Tax conditions,
* you don't see them in the Result 
 
 
* Location of service provider = Tax Jur. Code of
* vendor:
my_taxcom-loc_pr   = i_lfa1-txjcd.
* Location of service = Tax Jur. Code of delivery address

*Populate fields based on country
CALL FUNCTION 'J_1B_SAVE_TAX_FIELDS'
  EXPORTING
    i_taxcom = my_taxcom.

CLEAR l_taxcom.
l_taxcom-bukrs = i_ekpo-bukrs.
l_taxcom-budat = i_ekko-bedat.
l_taxcom-waers = i_ekko-waers.
l_taxcom-kposn = i_ekpo-ebelp.
l_taxcom-mwskz = i_ekpo-mwskz.
l_taxcom-txjcd = i_ekpo-txjcd.
l_taxcom-shkzg = 'H'.
l_taxcom-xmwst = 'X'.
IF i_ekko-bstyp EQ 'F'.
  l_taxcom-wrbtr = i_ekpo-netwr.
ELSE.
  l_taxcom-wrbtr = i_ekpo-zwert.
ENDIF.
l_taxcom-lifnr = i_ekko-lifnr.
l_taxcom-land1 = i_ekko-lands. "WIA
l_taxcom-ekorg = i_ekko-ekorg.
l_taxcom-hwaer = l_wa_t001-waers.
l_taxcom-llief = i_ekko-llief.
l_taxcom-bldat = i_ekko-bedat.
l_taxcom-matnr = i_ekpo-matnr. "HTN-Abwicklung
l_taxcom-werks = i_ekpo-werks.
l_taxcom-bwtar = i_ekpo-bwtar.
l_taxcom-matkl = i_ekpo-matkl.
l_taxcom-meins = i_ekpo-meins.
IF i_ekko-bstyp EQ 'F'.
  l_taxcom-mglme = i_ekpo-menge.
ELSE.
  IF i_ekko-bstyp EQ 'K' AND i_ekpo-abmng GT 0.
    l_taxcom-mglme = i_ekpo-abmng.
  ELSE.
    l_taxcom-mglme = i_ekpo-ktmng.
  ENDIF.
ENDIF.
IF l_taxcom-mglme EQ 0.
  l_taxcom-mglme = 1000.
ENDIF.
l_taxcom-mtart = i_ekpo-mtart.

*Calculation of TAX

CALL FUNCTION 'CALCULATE_TAX_ITEM'
  EXPORTING
    dialog       = ' '
    display_only = ' '
    i_taxcom     = l_taxcom
  IMPORTING
    e_taxcom     = e_taxcom
  TABLES
    t_xkomv      = t_komv.
 

Now, we can Read form table T_KONV based on condition types.

--->  Scenario where the FM was used in the project 

1)      This Function  Module is used for printing partial tax amount in purchase order form .

2)      This Function module is used in SRM as well by remote call.

Author: Sujeet Mishra
Submitted: 16/08/2013
Description: Sample program to send email of Open Purchasing document.

REPORT &nbsp;zmm_openpo_email.
TABLES: &nbsp;ekko, lfa1.
\*DATA gv_address &nbsp; &nbsp; &nbsp; &nbsp; TYPE ad_smtpadr.
DATA: it_ekko TYPE TABLE OF ekko,
&nbsp; &nbsp; &nbsp; wa_ekko TYPE ekko,
it_lfa1 TYPE TABLE OF lfa1,
wa_lfa1 TYPE lfa1,
\*it_ekpo TYPE TABLE OF ekpo,
it_adr6 TYPE TABLE OF adr6,
wa_adr6 TYPE adr6.
SELECT-OPTIONS: s_ebeln FOR ekko-ebeln,
s_lifnr FOR lfa1-lifnr.
PARAMETERS: p_email &nbsp; TYPE somlreci1-receiver NO-DISPLAY.
TYPES: BEGIN OF t_ekpo,
&nbsp; ebeln TYPE ekpo-ebeln,
&nbsp; idnlf TYPE ekpo-idnlf,
&nbsp; &nbsp;END OF t_ekpo.
DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,
&nbsp; &nbsp; &nbsp; wa_ekpo TYPE t_ekpo.
TYPES: BEGIN OF t_charekpo,
&nbsp; ebeln(10) TYPE c,
&nbsp; idnlf(35) &nbsp;TYPE c,
&nbsp;END OF t_charekpo.
DATA: wa_charekpo TYPE t_charekpo.
DATA: &nbsp; it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WITH HEADER LINE.
DATA: &nbsp; it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WITH HEADER LINE.
DATA: &nbsp; t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
&nbsp; &nbsp; &nbsp; &nbsp; t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
&nbsp; &nbsp; &nbsp; &nbsp; t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
&nbsp; &nbsp; &nbsp; &nbsp; t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
&nbsp; &nbsp; &nbsp; &nbsp; t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
&nbsp; &nbsp; &nbsp; &nbsp; w_cnt TYPE i,
&nbsp; &nbsp; &nbsp; &nbsp; w_sent_all(1) TYPE c,
&nbsp; &nbsp; &nbsp; &nbsp; w_doc_data LIKE sodocchgi1,
&nbsp; &nbsp; &nbsp; &nbsp; gd_error &nbsp; &nbsp;TYPE sy-subrc,
&nbsp; &nbsp; &nbsp; &nbsp; gd_reciever TYPE sy-subrc.
START-OF-SELECTION.
\* &nbsp; Retrieve sample data from table ekpo
&nbsp; PERFORM data_retrieval.
\* &nbsp; Instructs mail send program for SAPCONNECT to send email(rsconn01)
&nbsp; PERFORM initiate_mail_execute_program.
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;DATA_RETRIEVAL
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; Retrieve data form EKPO table and populate itab it_ekko
\*----------------------------------------------------------------------\*
FORM data_retrieval.
&nbsp; SELECT * FROM ekko INTO TABLE it_ekko
&nbsp; &nbsp; WHERE ebeln IN s_ebeln AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lifnr IN s_lifnr.
&nbsp; IF it_ekko IS NOT INITIAL.
&nbsp; &nbsp; SELECT &nbsp;\* FROM lfa1
&nbsp; &nbsp; &nbsp; INTO TABLE it_lfa1
&nbsp; &nbsp; &nbsp; FOR ALL ENTRIES IN it_ekko
&nbsp; &nbsp; &nbsp; WHERE lifnr = it_ekko-lifnr.
&nbsp; &nbsp; SELECT * FROM ekpo
&nbsp; &nbsp; &nbsp; INTO &nbsp;CORRESPONDING FIELDS OF TABLE it_ekpo
&nbsp; &nbsp; &nbsp; FOR ALL ENTRIES IN it_ekko
&nbsp; &nbsp; &nbsp; WHERE ebeln = it_ekko-ebeln.
&nbsp; ENDIF.
&nbsp; IF it_lfa1 IS NOT INITIAL.
&nbsp; &nbsp; SELECT &nbsp;\* FROM adr6 INTO TABLE it_adr6
&nbsp; &nbsp; &nbsp; FOR ALL ENTRIES IN it_lfa1
&nbsp; &nbsp; &nbsp; WHERE addrnumber = it_lfa1-adrnr.
&nbsp; ENDIF.
&nbsp; DELETE ADJACENT DUPLICATES FROM it_ekpo
&nbsp; COMPARING ALL FIELDS.
&nbsp; LOOP AT it_lfa1 INTO wa_lfa1.
\* &nbsp; Populate table with detaisl to be entered into .xls file
&nbsp; &nbsp; PERFORM build_xls_data_table.
\* Populate message body text
&nbsp; &nbsp; PERFORM populate_email_message_body.
\* Send file by email as .xls speadsheet
&nbsp; &nbsp; PERFORM send_file_as_email_attachment
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TABLES it_message
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; it_attach
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; USING p_email
'From Great Offshore Ltd. New PO no against Old PO no'
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'XLS'
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'filename'
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' '
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' '
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' '
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CHANGING gd_error
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gd_reciever.
&nbsp; &nbsp; CLEAR wa_lfa1.
&nbsp; ENDLOOP.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" DATA_RETRIEVAL
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;BUILD_XLS_DATA_TABLE
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; Build data table for .xls document
\*----------------------------------------------------------------------\*
FORM build_xls_data_table.
\*If you have Unicode check active in program attributes thnen you will
\*need to declare constants as follows
&nbsp; CLASS cl_abap_char_utilities DEFINITION LOAD.
&nbsp; CONSTANTS:
&nbsp; &nbsp; &nbsp; con_tab &nbsp;TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,
&nbsp; &nbsp; &nbsp; con_cret TYPE c VALUE cl_abap_char_utilities=>cr_lf.
refresh it_attach\[\].
&nbsp; CONCATENATE 'SAP PO No' 'Old PO No'
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;INTO it_attach SEPARATED BY con_tab.
&nbsp; CONCATENATE con_cret it_attach &nbsp;INTO it_attach.
&nbsp; APPEND &nbsp;it_attach.
&nbsp; LOOP AT it_ekko INTO wa_ekko WHERE lifnr = wa_lfa1-lifnr.
&nbsp; &nbsp; LOOP AT it_ekpo INTO wa_charekpo
&nbsp; &nbsp; &nbsp; WHERE ebeln = wa_ekko-ebeln.
&nbsp; &nbsp; &nbsp; CONCATENATE wa_charekpo-ebeln wa_charekpo-idnlf
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;INTO it_attach SEPARATED BY con_tab.
&nbsp; &nbsp; &nbsp; CONCATENATE con_cret it_attach &nbsp;INTO it_attach.
&nbsp; &nbsp; &nbsp; APPEND &nbsp;it_attach.
&nbsp; &nbsp; ENDLOOP.
&nbsp; ENDLOOP.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" BUILD_XLS_DATA_TABLE
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;SEND_FILE_AS_EMAIL_ATTACHMENT
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; Send email
\*----------------------------------------------------------------------\*
FORM send_file_as_email_attachment TABLES pit_message
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pit_attach
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; USING p_email
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p_mtitle
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p_format
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p_filename
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p_attdescription
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p_sender_address
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p_sender_addres_type
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CHANGING p_error
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p_reciever.
&nbsp; DATA: ld_error &nbsp; &nbsp;TYPE sy-subrc,
&nbsp; &nbsp; &nbsp; &nbsp; ld_reciever TYPE sy-subrc,
&nbsp; &nbsp; &nbsp; &nbsp; ld_mtitle LIKE sodocchgi1-obj_descr,
&nbsp; &nbsp; &nbsp; &nbsp; ld_email LIKE &nbsp;somlreci1-receiver,
&nbsp; &nbsp; &nbsp; &nbsp; ld_format TYPE &nbsp;so_obj_tp ,
&nbsp; &nbsp; &nbsp; &nbsp; ld_attdescription TYPE &nbsp;so_obj_nam ,
&nbsp; &nbsp; &nbsp; &nbsp; ld_attfilename TYPE &nbsp;so_obj_des ,
&nbsp; &nbsp; &nbsp; &nbsp; ld_sender_address LIKE &nbsp;soextreci1-receiver,
&nbsp; &nbsp; &nbsp; &nbsp; ld_sender_address_type LIKE &nbsp;soextreci1-adr_typ,
&nbsp; &nbsp; &nbsp; &nbsp; ld_receiver LIKE &nbsp;sy-subrc.
&nbsp; ld_email &nbsp; = p_email.
&nbsp; ld_mtitle = p_mtitle.
&nbsp; ld_format &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= p_format.
&nbsp; ld_attdescription &nbsp; &nbsp; &nbsp;= p_attdescription.
&nbsp; ld_attfilename &nbsp; &nbsp; &nbsp; &nbsp; = p_filename.
&nbsp; ld_sender_address &nbsp; &nbsp; &nbsp;= p_sender_address.
&nbsp; ld_sender_address_type = p_sender_addres_type.
\* Fill the document data.
&nbsp; w_doc_data-doc_size = 1.
\* Populate the subject/generic message attributes
&nbsp; w_doc_data-obj_langu = sy-langu.
&nbsp; w_doc_data-obj_name &nbsp;= 'SAPRPT'.
&nbsp; w_doc_data-obj_descr = ld_mtitle .
&nbsp; w_doc_data-sensitivty = 'F'.
\* Fill the document data and get size of attachment
&nbsp; CLEAR w_doc_data.
&nbsp; READ TABLE it_attach INDEX w_cnt.
&nbsp; w_doc_data-doc_size =
&nbsp; &nbsp; &nbsp;( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
&nbsp; w_doc_data-obj_langu &nbsp;= sy-langu.
&nbsp; w_doc_data-obj_name &nbsp; = 'SAPRPT'.
&nbsp; w_doc_data-obj_descr &nbsp;= ld_mtitle.
&nbsp; w_doc_data-sensitivty = 'F'.
&nbsp; CLEAR t_attachment.
&nbsp; REFRESH t_attachment.
&nbsp; t_attachment\[\] = pit_attach\[\].
\* Describe the body of the message
&nbsp; CLEAR t_packing_list.
&nbsp; REFRESH t_packing_list.
&nbsp; t_packing_list-transf_bin = space.
&nbsp; t_packing_list-head_start = 1.
&nbsp; t_packing_list-head_num = 0.
&nbsp; t_packing_list-body_start = 1.
&nbsp; DESCRIBE TABLE it_message LINES t_packing_list-body_num.
&nbsp; t_packing_list-doc_type = 'RAW'.
&nbsp; APPEND t_packing_list.
\* Create attachment notification
&nbsp; t_packing_list-transf_bin = 'X'.
&nbsp; t_packing_list-head_start = 1.
&nbsp; t_packing_list-head_num &nbsp; = 1.
&nbsp; t_packing_list-body_start = 1.
&nbsp; DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
&nbsp; t_packing_list-doc_type &nbsp; = &nbsp;ld_format.
&nbsp; t_packing_list-obj_descr &nbsp;= &nbsp;ld_attdescription.
&nbsp; t_packing_list-obj_name &nbsp; = &nbsp;ld_attfilename.
&nbsp; t_packing_list-doc_size &nbsp; = &nbsp;t_packing_list-body_num * 255.
&nbsp; APPEND t_packing_list.
\* Add the recipients email address
&nbsp; CLEAR wa_adr6.
&nbsp; REFRESH t_receivers.
&nbsp; LOOP AT &nbsp;it_adr6 INTO wa_adr6
&nbsp; &nbsp; WHERE addrnumber = wa_lfa1-adrnr.
&nbsp; &nbsp; ld_email &nbsp;= wa_adr6-smtp_addr.
&nbsp; &nbsp; CLEAR t_receivers.
&nbsp; &nbsp; t_receivers-receiver = ld_email.
&nbsp; &nbsp; t_receivers-rec_type = 'U'.
&nbsp; &nbsp; t_receivers-com_type = 'INT'.
&nbsp; &nbsp; t_receivers-notif_del = 'X'.
&nbsp; &nbsp; t_receivers-notif_ndel = 'X'.
&nbsp; &nbsp; APPEND t_receivers.
&nbsp; ENDLOOP.
&nbsp; DATA: OBJHEAD LIKE SOLISTI1 &nbsp; OCCURS &nbsp;1 WITH HEADER LINE.
&nbsp; OBJHEAD = 'OLD_NEW_PO.XLS'. APPEND OBJHEAD.
if t_receivers\[\] is NOT INITIAL.
&nbsp; CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
&nbsp; &nbsp; EXPORTING
&nbsp; &nbsp; &nbsp; document_data &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= w_doc_data
&nbsp; &nbsp; &nbsp; put_in_outbox &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 'X'
&nbsp; &nbsp; &nbsp; sender_address &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = ld_sender_address
&nbsp; &nbsp; &nbsp; sender_address_type &nbsp; &nbsp; &nbsp; &nbsp;= ld_sender_address_type
&nbsp; &nbsp; &nbsp; commit_work &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 'X'
&nbsp; &nbsp; IMPORTING
&nbsp; &nbsp; &nbsp; sent_to_all &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= w_sent_all
&nbsp; &nbsp; TABLES
&nbsp; &nbsp; &nbsp; packing_list &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = t_packing_list
&nbsp; &nbsp; &nbsp; OBJECT_HEADER &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= OBJHEAD
&nbsp; &nbsp; &nbsp; contents_bin &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = t_attachment
&nbsp; &nbsp; &nbsp; contents_txt &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = it_message
&nbsp; &nbsp; &nbsp; receivers &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= t_receivers
&nbsp; &nbsp; EXCEPTIONS
&nbsp; &nbsp; &nbsp; too_many_receivers &nbsp; &nbsp; &nbsp; &nbsp; = 1
&nbsp; &nbsp; &nbsp; document_not_sent &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 2
&nbsp; &nbsp; &nbsp; document_type_not_exist &nbsp; &nbsp;= 3
&nbsp; &nbsp; &nbsp; operation_no_authorization = 4
&nbsp; &nbsp; &nbsp; parameter_error &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 5
&nbsp; &nbsp; &nbsp; x_error &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 6
&nbsp; &nbsp; &nbsp; enqueue_error &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 7
&nbsp; &nbsp; &nbsp; OTHERS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 8.
\* Populate zerror return code
&nbsp; ld_error = sy-subrc.
\* Populate zreceiver return code
&nbsp; LOOP AT t_receivers.
&nbsp; &nbsp; ld_receiver = t_receivers-retrn_code.
&nbsp; ENDLOOP.
&nbsp;endif.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"send_file_as_email_attachment
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;INITIATE_MAIL_EXECUTE_PROGRAM
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; Instructs mail send program for SAPCONNECT to send email.
\*----------------------------------------------------------------------\*
FORM initiate_mail_execute_program.
&nbsp; WAIT UP TO 2 SECONDS.
&nbsp; SUBMIT rsconn01 WITH mode = 'INT'
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WITH output = 'X'
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND RETURN.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" INITIATE_MAIL_EXECUTE_PROGRAM
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;POPULATE_EMAIL_MESSAGE_BODY
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; &nbsp;Populate message body text
\*----------------------------------------------------------------------\*
FORM populate_email_message_body.
&nbsp; REFRESH it_message.
&nbsp; it_message = text-001.
&nbsp; APPEND it_message.
&nbsp; it_message = text-002.
&nbsp; APPEND it_message.
&nbsp; it_message = ' '.
&nbsp; APPEND it_message.
&nbsp; it_message = text-003.
&nbsp; APPEND it_message.
&nbsp; it_message = text-004.
&nbsp; APPEND it_message.
&nbsp; it_message = ' '.
&nbsp; APPEND it_message.
&nbsp; it_message = text-005.
&nbsp; APPEND it_message.
&nbsp; it_message = text-006.
&nbsp; APPEND it_message.
&nbsp; it_message = ' '.
&nbsp; APPEND it_message.
&nbsp; it_message = text-007.
&nbsp; APPEND it_message.
&nbsp; it_message = ' '.
&nbsp; APPEND it_message.
&nbsp; it_message = text-008.
&nbsp; APPEND it_message.
&nbsp; it_message = ' '.
&nbsp; APPEND it_message.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" POPULATE_EMAIL_MESSAGE_BODY
Purpose:     
    To enable or disable a custom tab at either header level or item level in a purchase order or purchase requisition.

HOW TO DO THAT:

     System calls method PBO of class CL_TABSTRIP_VIEW_MM before displaying a tabstrip at header level and item level. As this class is not marked as final we will not be able to create enhancements pre-method or post-method.
                     To achieve our functionality we have to create implicit enhancement in the method –PBO. We can make use of standard code of method PBO.
**----------------------------------------------------------------------------------------------------------------------------------------------------
              LOOP AT SCREEN.
                              IF SCREEN-GROUP1 EQ 'TAB'.
                                    ADD 1 TO l_cnt_tabs.
                               IF l_cnt_tabs <= MAX_SUBVIEWS AND l_cnt_tabs <= l_cnt_views.
                                   READ TABLE SUBVIEWS INTO ls_subview INDEX l_cnt_tabs.
                                         IF SY-SUBRC EQ 0.
                                             if ls_subview-view->is_active( im_ask_parent = mmpur_no )    eq mmpur_yes.

                                           CALL METHOD ls_subview-VIEW->GET_LABEL
                                                             IMPORTING EX_LABEL = L_LABEL.
                                          CASE L_LABEL.
**-------------Disable the custom tab for header and item detail view levels of purchase order and purchase reqisition 
                                                     WHEN ‘CUSTOM_HEADER_PO’.
                                                          screen-invisible = 1.
                                                        MODIFY SCREEN.
                                                      WHEN ‘CUSTOM_HEADER_PR’.
                                                              screen-invisible = 1.
                                                               MODIFY SCREEN.
                                                      WHEN ‘CUSTOM_ITEM_PO’.
                                                               screen-invisible = 1.
                                                                 MODIFY SCREEN.
                                                      WHEN ‘CUSTOM_ITEM_PR’.
                                                                 screen-invisible = 1.
                                                                MODIFY SCREEN.
                                       ENDCASE.
                                                
                                          PERFORM SET_VALUE IN PROGRAM (PROG) USING
                                                                                     SCREEN-NAME L_LABEL.
                           ENDIF.                       "    if ls_subview-view->is_active( im_ask_parent = mmpur_no )    eq mmpur_yes.
                       ENDIF.                             "  IF SY-SUBRC EQ 0.
                  ENDIF.                                    " IF l_cnt_tabs <= MAX_SUBVIEWS AND l_cnt_tabs <= l_cnt_views.
           ENDIF.                                            "IF SCREEN-GROUP1 EQ 'TAB'.
  ENDLOOP.                                               "LOOP AT SCREEN.
**-------------------------------------------------------------------------------------------------------------------------------------------------
With the above code in place we will be able to disable the custom tabs at Header level and tem levels in Purchase Order and Purchase Requisition. 
NOTE- ‘CUSTOM_HEADER_PR’, ‘CUSTOM_HEADER_PO’, ‘CUSTOM_ITEM_PR’ and ‘CUSTOM_ITEM_PO’ are the labels provided for Custom tabs at header level and item level of purchase order and purchase requisition respectively.

 

 

Author: Sujeet Mishra
Submitted: 17/08/2013
Description : Purchase Requisition Report

REPORT ZMM_PR_RFQ_DETAILS.
TABLES : EBAN , EKPO.
TYPE-POOLS slis.
DATA : BEGIN OF INT_PR_DET OCCURS 0,
  BUKRS LIKE EKPO-BUKRS,
  EBELP LIKE EKPO-EBELP,
  BEDNR LIKE EKPO-BEDNR,
  ANFNR LIKE EKPO-ANFNR,
BANFN LIKE EBAN-BANFN,
 BADAT LIKE EBAN-BADAT,
 MATNR LIKE EBAN-MATNR,
 TXZ01 LIKE EBAN-TXZ01,
AFNAM LIKE EBAN-AFNAM,
 MENGE LIKE EBAN-MENGE,
 WERKs LIKE EBAN-WERKs,
 PREIS LIKE EBAN-PREIS,
PEINH LIKE EBAN-PEINH,
 EBELN LIKE EBAN-EBELN,
 BEDAT LIKE EBAN-BEDAT,
EKGRP LIKE EBAN-EKGRP,
BSMNG LIKE EBAN-BSMNG,
MEINS LIKE EBAN-MEINS,
&nbsp; &nbsp; &nbsp; &nbsp; MATKL LIKE &nbsp; &nbsp;EBAN-MATKL,
&nbsp; &nbsp; &nbsp; &nbsp; LFDAT LIKE &nbsp; &nbsp;EBAN-LFDAT,
&nbsp; &nbsp; &nbsp; &nbsp; FRGDT LIKE &nbsp; &nbsp;EBAN-FRGDT,
&nbsp; &nbsp; &nbsp; &nbsp;END OF INT_PR_DET.
data: wa_pr_det like LINE OF int_pr_det.
data: it_gr_ir type standard table of T8JVM01,
&nbsp; &nbsp; &nbsp; it_gr_ir1 type standard table of T8JVM01.
DATA TYPE_FOR_ALV TYPE slis_t_fieldcat_alv.
SELECTION-SCREEN SKIP 1 .
SELECT-OPTIONS : SO_PR_NO FOR EBAN-BANFN ,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SO_RFQ &nbsp; FOR EKPO-ANFNR,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SO_PR_DT FOR EBAN-BADAT ,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SO_M_CD &nbsp;FOR EBAN-MATNR ,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SO_BEDNR FOR EKPO-BEDNR NO INTERVALS.
\*------------------------------------------------------------\-
SELECTION-SCREEN SKIP 1 .
SELECT-OPTIONS SO_P_GRP FOR EBAN-EKGRP &nbsp;NO INTERVALS .
SELECTION-SCREEN SKIP 1 .
PARAMETERS PR_PLANT LIKE EBAN-WERKS .
DATA rec_found TYPE n.
DATA f_date LIKE sy-datum.
f_date = sy-datum - 10.
FREE INT_PR_DET .
SELECT
&nbsp; &nbsp; &nbsp; &nbsp;EKPO~BUKRS
&nbsp; &nbsp; &nbsp; &nbsp;EKPO~EBELP
&nbsp; &nbsp; &nbsp; &nbsp;EKPO~BEDNR
&nbsp; &nbsp; &nbsp; &nbsp;EKPO~ANFNR&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp;EBAN~BANFN
&nbsp; &nbsp; &nbsp; &nbsp;BADAT
&nbsp; &nbsp; &nbsp; &nbsp;EBAN~MATNR
&nbsp; &nbsp; &nbsp; &nbsp;EBAN~TXZ01
&nbsp; &nbsp; &nbsp; &nbsp;EBAN~AFNAM
&nbsp; &nbsp; &nbsp; &nbsp;EBAN~MENGE
&nbsp; &nbsp; &nbsp; &nbsp;EBAN~WERKs
&nbsp; &nbsp; &nbsp; &nbsp;PREIS
&nbsp; &nbsp; &nbsp; &nbsp;EBAN~PEINH
&nbsp; &nbsp; &nbsp; &nbsp;EBAN~EBELN
&nbsp; &nbsp; &nbsp; &nbsp;BEDAT
&nbsp; &nbsp; &nbsp; &nbsp;EKGRP
&nbsp; &nbsp; &nbsp; &nbsp;BSMNG
&nbsp; &nbsp; &nbsp; &nbsp;EBAN~MEINS
&nbsp; &nbsp; &nbsp; &nbsp;EBAN~MATKL
&nbsp; &nbsp; &nbsp; &nbsp;LFDAT
&nbsp; &nbsp; &nbsp; &nbsp;FRGDT
&nbsp; &nbsp; &nbsp; &nbsp;FROM EBAN
&nbsp; &nbsp; &nbsp; &nbsp;INNER join ekpo on ekpo~banfn &nbsp;= EBAN~banfn and
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ekpo~bnfpo &nbsp;= EBAN~bnfpo
&nbsp; &nbsp; &nbsp; &nbsp;INTO table INT_PR_DET
&nbsp; &nbsp; &nbsp; &nbsp;WHERE EBAN~BANFN IN SO_PR_NO
&nbsp; &nbsp; &nbsp; &nbsp;AND EKGRP IN SO_P_GRP
&nbsp; &nbsp; &nbsp; &nbsp;AND EBAN~MATNR IN SO_M_CD
&nbsp; &nbsp; &nbsp; &nbsp;AND EKPO~BEDNR IN SO_BEDNR
&nbsp; &nbsp; &nbsp; &nbsp;AND EKPO~ANFNR IN SO_RFQ
&nbsp; &nbsp; &nbsp; &nbsp;AND BADAT IN SO_PR_DT
&nbsp; &nbsp; &nbsp; &nbsp;and EBAN~WERKS EQ PR_PLANT
&nbsp; &nbsp; &nbsp; &nbsp;ORDER BY BADAT .
IF sy-subrc = 0.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
&nbsp;EXPORTING
&nbsp; &nbsp;i_program_name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = sy-cprog
&nbsp; &nbsp;i_internal_tabname &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 'INT_PR_DET'
&nbsp; &nbsp;i_inclname &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = sy-cprog
&nbsp; CHANGING
&nbsp; &nbsp; ct_fieldcat &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= TYPE_FOR_ALV
&nbsp;EXCEPTIONS
&nbsp; &nbsp;inconsistent_interface &nbsp; &nbsp; &nbsp; = 1
&nbsp; &nbsp;program_error &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 2
&nbsp; &nbsp;OTHERS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 3
&nbsp; &nbsp;.
IF sy-subrc <> 0.
&nbsp;MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
&nbsp;EXPORTING
&nbsp; &nbsp;i_grid_title &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 'PURCHASE REQUISITION DETAIL '
&nbsp; &nbsp;it_fieldcat &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = TYPE_FOR_ALV
&nbsp; TABLES
&nbsp; &nbsp; t_outtab &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= INT_PR_DET
&nbsp;EXCEPTIONS
&nbsp; &nbsp;program_error &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 1
&nbsp; &nbsp;OTHERS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 2
&nbsp; &nbsp;.
ELSE.
&nbsp; &nbsp; &nbsp; &nbsp;MESSAGE i001(zgk) .
endif.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .
IF sy-subrc <> 0.
&nbsp;MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

Author: Sujeet Mishra
Submitted: 17/08/2013
Description: Purchase Tracking Report

report &nbsp;zmm_po_track.
data : it_exclude type table of ui_func.
data: gs_variant1 type disvariant.
data: gs_variant2 type disvariant.
data gs_layout &nbsp; type lvc_s_layo.
tables : eban. &nbsp; &nbsp;
data : iekko like ekko occurs 0 with header line.
data : iekpo like ekpo occurs 0 with header line.
data : iekkn like ekkn occurs 0 with header line.
data : ibseg like bseg occurs 0 with header line.
type-pools : slis.
selection-screen begin of block b1 with frame title text-001.
parameters &nbsp;: p_bukrs like iekko-bukrs obligatory.
selection-screen end of block b1.
selection-screen begin of block b2 with frame title text-002.
select-options  : p_werks for iekpo-werks.
select-options  : p_ekgrp for iekko-ekgrp.
select-options : p_knttp for iekpo-knttp.
select-options   : p_kostl for iekkn-kostl.
select-options  : p_aufnr for iekkn-aufnr.
select-options    : p_wbs for iekkn-ps_psp_pnr.
select-options   : p_nplnr for iekkn-nplnr.
select-options   : p_prctr for iekkn-prctr.
select-options   : p_bedat for iekko-bedat.
selection-screen end of block b2.
data:
ok_code   type syst-ucomm,
copy_ok_code  like ok_code,
g_repid type sy-repid,
gv_flag  type c,
ref_container type ref to cl_gui_docking_container,
ref_alv    type ref to cl_gui_alv_grid,
ref_alv1  type ref to cl_gui_alv_grid,
  g_custom_container type ref to cl_gui_custom_container,
  lt_fieldcat type lvc_t_fcat,
  gs_layout_bsik &nbsp; type lvc_s_layo,
  gs_layout_bsad type lvc_s_layo,
 it_sort &nbsp; &nbsp;type lvc_t_sort.
data it_t8jvm01 type table of t8jvm01.
data wa_t8jvm01 like t8jvm01.
data wa_ekpo type ekpo.
data it_rbkp type table of rbkp.
data it_rseg type table of rseg.
data wa_rbkp type &nbsp;rbkp.
data wa_rseg type &nbsp;rseg.
data wa_ekko type ekko.
data it_ekkn type table of ekkn.
data wa_ekkn type ekkn.
data it_lfa1 type table of lfa1.
data wa_lfa1 type lfa1.
data: begin of it_mm_output occurs 0,
banfn like ekpo-banfn,
bnfpo like ekpo-bnfpo,
anfnr like ekpo-anfnr,
anfps like ekpo-anfps,
ebeln like ekpo-ebeln,
ebelp like ekpo-ebelp,
matkl like ekpo-matkl,
matnr like ekpo-matnr,
txz01 like ekpo-txz01,
lifnr like lfa1-lifnr,
name1 like lfa1-name1,
kostl like ekkn-kostl,
aufnr like ekkn-aufnr,
ps_psp_pnr like ekkn-ps_psp_pnr,
nplnr like ekkn-nplnr,
prctr like ekkn-prctr,
sakto like ekkn-sakto,
gr_year like t8jvm01-gr_year,
gr_doc like t8jvm01-gr_doc,
gr_line like t8jvm01-gr_line,
gr_quant like t8jvm01-gr_quant,
gr_remain_quant like t8jvm01-gr_remain_quant,
ir_year like t8jvm01-ir_year,
ir_doc like t8jvm01-ir_doc,
ir_line like t8jvm01-ir_line,
ir_quant like t8jvm01-ir_quant,
ir_remain_quant like t8jvm01-ir_remain_quant,
quantity_matched like t8jvm01-quantity_matched,
meins like t8jvm01-meins,
ref_gr like t8jvm01-ref_gr,
ref_gr_line like t8jvm01-ref_gr_line,
wrbtr like t8jvm01-wrbtr,
waers like t8jvm01-waers,
shkzg like t8jvm01-shkzg,
mwskz like rseg-mwskz,
wmwst1 like rbkp-wmwst1,
&nbsp; end of it_mm_output.
data wa_mm_output like line of it_mm_output.
data it_output2 like table of wa_mm_output.
data : g_custom_container1 type ref to cl_gui_custom_container.
data : g_alv_grid1 type ref to cl_gui_alv_grid.
data : g_custom_container2 type ref to cl_gui_custom_container.
data : g_alv_grid2 type ref to cl_gui_alv_grid.
data it_zvbakapup type table of zvbakapup.
data wa_zvbakapup type zvbakapup.
data it_vbfa type table of vbfa.
data wa_vbfa type vbfa.
data: begin of it_sd_output occurs 0,
vbeln like vbak-vbeln,
posnr like vbap-posnr,
fksaa like vbup-fksaa,
\*billno LIKE vbrk-vbeln,
kwmeng like vbap-kwmeng,
vrkme &nbsp;like vbap-vrkme,
end of it_sd_output.
data wa_sd_output like line of it_sd_output.
data it_output1 like table of wa_sd_output.
\*----------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; CLASS LCL_EVENT_RECEIVER DEFINITION
\*----------------------------------------------------------------------\*
\*
\*----------------------------------------------------------------------\*
class lcl_event_receiver definition .
 public section.
 methods :
 handle_toolbar
 for event toolbar of cl_gui_alv_grid
 importing e_object e_interactive,
 handle_menu_button
 for event menu_button of cl_gui_alv_grid
 importing e_object e_ucomm,
&nbsp; &nbsp; handle_ucomm
&nbsp; &nbsp; for event user_command of cl_gui_alv_grid
&nbsp; &nbsp; importing e_ucomm.
&nbsp; private section.
&nbsp; &nbsp; methods: check_menge
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;importing
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ps_good type lvc_s_modi
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pr_data_changed type ref to cl_alv_changed_data_protocol.
endclass. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"LCL_EVENT_RECEIVER DEFINITION
\*----------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; CLASS LCL_EVENT_RECEIVER IMPLEMENTATION
\*----------------------------------------------------------------------\*
\*
\*----------------------------------------------------------------------\*
class lcl_event_receiver implementation.
&nbsp; method handle_toolbar.
&nbsp; &nbsp; data : wa_toolbar type stb_button.
&nbsp; &nbsp; data : butn_type type i.
&nbsp; &nbsp; data : function type char20.
&nbsp; &nbsp; append wa_toolbar to e_object->mt_toolbar.
&nbsp; &nbsp; clear wa_toolbar.
&nbsp; &nbsp; append wa_toolbar to e_object->mt_toolbar.
&nbsp; endmethod. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; method handle_menu_button.
&nbsp; endmethod. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; method check_menge.
&nbsp; endmethod. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; method handle_ucomm.
&nbsp; &nbsp; data: lt_rows type lvc_t_row,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lt_rowid type lvc_t_roid,
&nbsp; wa_e_row type i,
&nbsp; wa_e_value type c,
&nbsp; wa_e_col type i,
&nbsp; wa_es_row_id type lvc_s_row,
&nbsp; wa_es_col_id type lvc_s_col,
&nbsp; wa_es_row_no type lvc_s_roid,
&nbsp; wa_et_cell type lvc_t_cell,
&nbsp; wa_et_cells type lvc_t_ceno.
&nbsp; &nbsp; call method g_alv_grid2->get_current_cell
&nbsp; &nbsp; &nbsp; importing
&nbsp; &nbsp; &nbsp; &nbsp; e_row &nbsp; &nbsp; = wa_e_row
&nbsp; &nbsp; &nbsp; &nbsp; e_value &nbsp; = wa_e_value
&nbsp; &nbsp; &nbsp; &nbsp; e_col &nbsp; &nbsp; = wa_e_col
&nbsp; &nbsp; &nbsp; &nbsp; es_row_id = wa_es_row_id
&nbsp; &nbsp; &nbsp; &nbsp; es_col_id = wa_es_col_id
&nbsp; &nbsp; &nbsp; &nbsp; es_row_no = wa_es_row_no.
&nbsp; &nbsp; if wa_e_value eq space.
&nbsp; &nbsp; &nbsp; case e_ucomm.
&nbsp; &nbsp; &nbsp; &nbsp; when 'TRF'.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; read table it_mm_output &nbsp;into wa_mm_output
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;index wa_es_row_no-row_id.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if sy-subrc = 0.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; refresh it_output1.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if wa_mm_output-matnr is &nbsp;initial.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exit.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; endif.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; select * from zvbakapup into table it_zvbakapup
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; where &nbsp;matnr = wa_mm_output-matnr and
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; auart = 'ZXYZ' .
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if sy-subrc = 0.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loop at it_zvbakapup into wa_zvbakapup.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; move-corresponding wa_zvbakapup to wa_sd_output.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; append wa_sd_output to it_output1.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; endloop.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; message s001(zmm)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; with 'No sales data exist for Material '.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; endif.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; endif.
&nbsp; &nbsp; &nbsp; endcase.
&nbsp; &nbsp; else.
&nbsp; &nbsp; endif.
&nbsp; endmethod. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"HANDLE_UCOMM
endclass. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"LCL_EVENT_RECEIVER IMPLEMENTATION
data : event_receiver type ref to lcl_event_receiver.
start-of-selection.
&nbsp; select * from ekko
&nbsp; &nbsp; into table iekko
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;where &nbsp; bukrs eq p_bukrs
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and ekgrp in p_ekgrp
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and bedat in p_bedat.
&nbsp; if not iekko\[\] is initial.
&nbsp; &nbsp; select * from lfa1 into table it_lfa1
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for all entries in iekko
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; where lifnr = iekko-lifnr.
&nbsp; &nbsp; select * from ekpo
&nbsp; &nbsp; &nbsp; into table iekpo
&nbsp; &nbsp; &nbsp; for all entries in iekko
&nbsp; &nbsp; &nbsp; where ebeln = iekko-ebeln and
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; werks in p_werks and
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; knttp in p_knttp and
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loekz ne 'L'.
&nbsp; &nbsp;select * from ekkn into table iekkn
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for all entries in iekko
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;where ebeln = iekko-ebeln
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and kostl in p_kostl
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and aufnr in p_aufnr
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and ps_psp_pnr in p_wbs
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and nplnr in p_nplnr
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and prctr in &nbsp;p_prctr.
&nbsp; endif.
&nbsp; loop at iekpo into wa_ekpo.
&nbsp; &nbsp; call function 'GJ_LINK_GR_IR'
&nbsp; &nbsp; &nbsp; exporting
&nbsp; &nbsp; &nbsp; &nbsp; bukrs &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= p_bukrs
&nbsp; &nbsp; &nbsp; &nbsp; po_nbr &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = wa_ekpo-ebeln
&nbsp; &nbsp; &nbsp; &nbsp; po_line &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= wa_ekpo-ebelp
&nbsp; &nbsp; &nbsp; tables
&nbsp; &nbsp; &nbsp; &nbsp; assignment &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = it_t8jvm01
&nbsp; &nbsp; &nbsp;exceptions
&nbsp; &nbsp; &nbsp; &nbsp;no_po &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 1
&nbsp; &nbsp; &nbsp; &nbsp;no_doc &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 2
&nbsp; &nbsp; &nbsp; &nbsp;missing_year &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 3
&nbsp; &nbsp; &nbsp; &nbsp;others &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 4
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .
&nbsp; &nbsp; if sy-subrc <> 0.
&nbsp; &nbsp; &nbsp; continue.
\* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
\* &nbsp; &nbsp; &nbsp; &nbsp; WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
&nbsp; &nbsp; endif.
&nbsp; &nbsp; if it_t8jvm01\[\] is not initial.
&nbsp; &nbsp; &nbsp; select * from rbkp into table it_rbkp
&nbsp; &nbsp; &nbsp; &nbsp; for all entries in it_t8jvm01
&nbsp; &nbsp; &nbsp; &nbsp; where
&nbsp; &nbsp; &nbsp; &nbsp; belnr = it_t8jvm01-ir_doc and
&nbsp; &nbsp; &nbsp; &nbsp; gjahr = it_t8jvm01-ir_year .
&nbsp; &nbsp; &nbsp; select * from rseg into table it_rseg
&nbsp; &nbsp; &nbsp; &nbsp; for all entries in it_t8jvm01
&nbsp; &nbsp; &nbsp; &nbsp; where
&nbsp; &nbsp; &nbsp; &nbsp; belnr = it_t8jvm01-ir_doc and
&nbsp; &nbsp; &nbsp; &nbsp; gjahr = it_t8jvm01-ir_year .
&nbsp; &nbsp; endif.
&nbsp; &nbsp; loop at it_t8jvm01 into wa_t8jvm01.
&nbsp; &nbsp; &nbsp; clear wa_rbkp.
&nbsp; &nbsp; &nbsp; read table it_rbkp into wa_rbkp
&nbsp; &nbsp; &nbsp; with key
&nbsp; &nbsp; &nbsp; &nbsp; belnr = wa_t8jvm01-ir_doc
&nbsp; &nbsp; &nbsp; &nbsp; gjahr = wa_t8jvm01-ir_year .
&nbsp; &nbsp; &nbsp; read table it_rseg into wa_rseg
&nbsp; &nbsp; &nbsp; with key
&nbsp; &nbsp; &nbsp; &nbsp; belnr = wa_t8jvm01-ir_doc
&nbsp; &nbsp; &nbsp; &nbsp; gjahr = wa_t8jvm01-ir_year
&nbsp; &nbsp; &nbsp; &nbsp; buzei = wa_t8jvm01-ir_line.
&nbsp; &nbsp; &nbsp; data :
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e_fwnav like &nbsp;bset-fwste,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e_fwnvv like &nbsp;bset-fwste,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e_fwste like &nbsp;bset-fwste,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e_fwast like &nbsp;bset-fwste .
&nbsp; &nbsp; &nbsp; data t_mwdat &nbsp;type table of rtax1u15.
&nbsp; &nbsp; &nbsp; call function 'CALCULATE_TAX_FROM_NET_AMOUNT'
&nbsp; &nbsp; &nbsp; &nbsp; exporting
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i_bukrs &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = wa_rbkp-bukrs
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i_mwskz &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = wa_rseg-mwskz
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i_waers &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = wa_t8jvm01-waers
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i_wrbtr &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = wa_t8jvm01-wrbtr importing
&nbsp; &nbsp; &nbsp;e_fwnav &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = e_fwnav
&nbsp; &nbsp;e_fwnvv &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = e_fwnvv
&nbsp; &nbsp;e_fwste &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = e_fwste
&nbsp; &nbsp; e_fwast &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = e_fwast
&nbsp; &nbsp; &nbsp; &nbsp; tables
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t_mwdat &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = t_mwdat
&nbsp; exceptions
&nbsp; &nbsp; bukrs_not_found &nbsp; &nbsp; &nbsp; &nbsp; = 1
&nbsp; &nbsp; country_not_found &nbsp; &nbsp; &nbsp; = 2
&nbsp; &nbsp; mwskz_not_defined &nbsp; &nbsp; &nbsp; = 3
&nbsp; &nbsp; mwskz_not_valid &nbsp; &nbsp; &nbsp; &nbsp; = 4
&nbsp; ktosl_not_found &nbsp; &nbsp; &nbsp; &nbsp; = 5
&nbsp; kalsm_not_found &nbsp; &nbsp; &nbsp; &nbsp; = 6
&nbsp; &nbsp; parameter_error &nbsp; &nbsp; &nbsp; &nbsp; = 7
&nbsp; &nbsp; knumh_not_found &nbsp; &nbsp; &nbsp; &nbsp; = 8
&nbsp; &nbsp; kschl_not_found &nbsp; &nbsp; &nbsp; &nbsp; = 9
&nbsp; &nbsp; unknown_error &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 10
&nbsp; &nbsp; account_not_found &nbsp; &nbsp; &nbsp; = 11
&nbsp; &nbsp; txjcd_not_valid &nbsp; &nbsp; &nbsp; &nbsp; = 12
&nbsp; &nbsp; others &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 13
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .
&nbsp; &nbsp; &nbsp; if sy-subrc <> 0.
\* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
\* &nbsp; &nbsp; &nbsp; &nbsp; WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
&nbsp; &nbsp; &nbsp; endif.
&nbsp; &nbsp; &nbsp; move-corresponding wa_t8jvm01 to wa_mm_output.
&nbsp; &nbsp; &nbsp; wa_mm_output-mwskz = &nbsp; &nbsp;wa_rseg-mwskz.
&nbsp; &nbsp; &nbsp; wa_mm_output-wmwst1 = e_fwste.
&nbsp; &nbsp; &nbsp; wa_mm_output-banfn = wa_ekpo-banfn.
&nbsp; &nbsp; &nbsp; wa_mm_output-bnfpo = wa_ekpo-bnfpo.
&nbsp; &nbsp; &nbsp; wa_mm_output-anfnr = wa_ekpo-anfnr.
&nbsp; &nbsp; &nbsp; wa_mm_output-anfps = wa_ekpo-anfps.
&nbsp; &nbsp; &nbsp; wa_mm_output-ebeln = wa_ekpo-ebeln.
&nbsp; &nbsp; &nbsp; wa_mm_output-ebelp = wa_ekpo-ebelp.
&nbsp; &nbsp; &nbsp; wa_mm_output-matkl = wa_ekpo-matkl.
&nbsp; &nbsp; &nbsp; wa_mm_output-matnr = wa_ekpo-matnr.
&nbsp; &nbsp; &nbsp; wa_mm_output-txz01 = wa_ekpo-txz01.
&nbsp;read table iekko into wa_ekko with key ebeln = wa_ekpo-ebeln.
&nbsp; if sy-subrc = 0.
&nbsp;read table it_lfa1 into wa_lfa1 with key lifnr = wa_ekko-lifnr.
&nbsp; &nbsp; &nbsp; &nbsp; if sy-subrc = 0.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wa_mm_output-lifnr = wa_lfa1-lifnr.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wa_mm_output-name1 = wa_lfa1-name1.
&nbsp; &nbsp; &nbsp; &nbsp; endif.
&nbsp; &nbsp; &nbsp; endif.
&nbsp; &nbsp; &nbsp; append wa_mm_output to it_output2.
&nbsp; &nbsp; &nbsp; append wa_mm_output to it_mm_output.
&nbsp; &nbsp; endloop.
&nbsp; endloop.
loop at it_mm_output into wa_mm_output.
read table iekkn into wa_ekkn with key ebeln = wa_mm_output-ebeln
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ebelp = wa_mm_output-ebelp.
&nbsp; &nbsp; if sy-subrc = 0.
&nbsp; &nbsp; &nbsp; wa_mm_output-kostl = wa_ekkn-kostl.
&nbsp; &nbsp; &nbsp; wa_mm_output-aufnr = wa_ekkn-aufnr.
&nbsp; &nbsp; &nbsp; wa_mm_output-ps_psp_pnr = wa_ekkn-ps_psp_pnr.
&nbsp; &nbsp; &nbsp; wa_mm_output-nplnr = wa_ekkn-nplnr.
&nbsp; &nbsp; &nbsp; wa_mm_output-prctr = wa_ekkn-prctr.
&nbsp; &nbsp; &nbsp; wa_mm_output-sakto = wa_ekkn-sakto.
&nbsp; &nbsp; endif.
modify it_mm_output from wa_mm_output
&nbsp; &nbsp;transporting kostl aufnr ps_psp_pnr nplnr prctr sakto.
&nbsp; endloop.
&nbsp;&nbsp;
&nbsp; delete it_mm_output where not ( kostl in p_kostl
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and aufnr in p_aufnr
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and ps_psp_pnr in p_wbs
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and nplnr in p_nplnr
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and prctr in p_prctr ).
&nbsp; perform create_alv_master2.&nbsp;
&nbsp; call screen 1005.
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;create_alv_master2
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
form create_alv_master2.
&nbsp; data: xfieldcat &nbsp; &nbsp;type slis_t_fieldcat_alv.
&nbsp; data : wa_fieldcat type slis_fieldcat_alv.
&nbsp; data : it_fieldcat2 &nbsp; &nbsp;type table of lvc_s_fcat.
&nbsp; if g_custom_container2 is initial.
&nbsp; &nbsp; create object g_custom_container2
&nbsp; &nbsp; &nbsp; exporting
&nbsp; &nbsp; &nbsp; &nbsp; container_name = 'CONT2'. "sorce of lead
&nbsp; &nbsp; if sy-subrc <> 0.
&nbsp; &nbsp; &nbsp; message id sy-msgid type sy-msgty number sy-msgno
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
&nbsp; &nbsp; endif.
&nbsp; &nbsp; create object g_alv_grid2
&nbsp; &nbsp; &nbsp; exporting
&nbsp; &nbsp; &nbsp; &nbsp; i_parent = g_custom_container2.
&nbsp; &nbsp; if sy-subrc <> 0.
&nbsp; &nbsp; &nbsp; message id sy-msgid type sy-msgty number sy-msgno
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
&nbsp; &nbsp; endif.
&nbsp; &nbsp; call function 'REUSE_ALV_FIELDCATALOG_MERGE'
&nbsp;exporting
&nbsp; &nbsp; &nbsp; &nbsp;i_program_name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = sy-repid
&nbsp; &nbsp; &nbsp; &nbsp;i_internal_tabname &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 'IT_MM_OUTPUT'
&nbsp; &nbsp;i_inclname &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = sy-repid
&nbsp; &nbsp; &nbsp; changing
&nbsp; &nbsp; &nbsp; &nbsp; ct_fieldcat &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= xfieldcat
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .
&nbsp; &nbsp; if sy-subrc <> 0.
\* &nbsp; &nbsp; &nbsp;MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
\* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
&nbsp; &nbsp; endif.
&nbsp; &nbsp; data: ls_fieldcat2 like line of it_fieldcat2.
&nbsp; &nbsp;&nbsp;
&nbsp; &nbsp; loop at xfieldcat into &nbsp;wa_fieldcat.
&nbsp; &nbsp; &nbsp; move-corresponding wa_fieldcat to ls_fieldcat2.
&nbsp; &nbsp; &nbsp; ls_fieldcat2-scrtext_l = wa_fieldcat-seltext_l.
&nbsp; &nbsp; &nbsp; ls_fieldcat2-scrtext_m = wa_fieldcat-seltext_m.
&nbsp; &nbsp; &nbsp; ls_fieldcat2-scrtext_s = wa_fieldcat-seltext_s.
&nbsp; &nbsp; &nbsp;append ls_fieldcat2 to it_fieldcat2.
&nbsp; &nbsp; &nbsp; clear ls_fieldcat2.
&nbsp; &nbsp; endloop.
&nbsp; &nbsp; perform exclude_toolbar changing it_exclude.
&nbsp; &nbsp; perform prepare_for_grid_layout.
&nbsp; &nbsp; call method g_alv_grid2->set_table_for_first_display
&nbsp; &nbsp; &nbsp; exporting
&nbsp; &nbsp; &nbsp; &nbsp; it_toolbar_excluding &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= it_exclude
&nbsp; &nbsp; &nbsp; &nbsp; is_variant &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= gs_variant2
&nbsp; &nbsp; &nbsp; &nbsp; i_save &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 'A'
&nbsp; &nbsp; &nbsp; &nbsp; is_layout &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = gs_layout
&nbsp; &nbsp; &nbsp; changing
&nbsp; &nbsp; &nbsp; &nbsp; it_outtab &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = it_mm_output\[\] &nbsp; &nbsp; &nbsp;"it_output2
&nbsp; &nbsp; &nbsp; &nbsp; it_fieldcatalog &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = it_fieldcat2
&nbsp; &nbsp; &nbsp; exceptions
&nbsp; &nbsp; &nbsp; &nbsp; invalid_parameter_combination = 1
&nbsp; &nbsp; &nbsp; &nbsp; program_error &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 2
&nbsp; &nbsp; &nbsp; &nbsp; too_many_lines &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 3
&nbsp; &nbsp; &nbsp; &nbsp; others &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 4.
&nbsp; &nbsp; if sy-subrc <> 0.
&nbsp; &nbsp; &nbsp; message id sy-msgid type sy-msgty number sy-msgno
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
&nbsp; &nbsp; endif.
&nbsp; &nbsp; call method g_alv_grid2->register_edit_event
&nbsp; &nbsp; &nbsp; exporting
&nbsp; &nbsp; &nbsp; &nbsp; i_event_id = cl_gui_alv_grid=>mc_evt_enter
&nbsp; &nbsp; &nbsp; exceptions
&nbsp; &nbsp; &nbsp; &nbsp; error &nbsp; &nbsp; &nbsp;= 1
&nbsp; &nbsp; &nbsp; &nbsp; others &nbsp; &nbsp; = 2.
&nbsp; &nbsp; if sy-subrc <> 0.
&nbsp; &nbsp; &nbsp; message id sy-msgid type sy-msgty number sy-msgno
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
&nbsp; &nbsp; endif.
&nbsp; &nbsp; create object event_receiver.
&nbsp; &nbsp; set handler event_receiver->handle_ucomm for g_alv_grid2.
&nbsp; &nbsp; set handler event_receiver->handle_toolbar for g_alv_grid2.
&nbsp; &nbsp; set handler event_receiver->handle_menu_button for g_alv_grid2.
&nbsp; &nbsp; call method g_alv_grid2->set_toolbar_interactive.
&nbsp; &nbsp; call method g_alv_grid2->set_ready_for_input
&nbsp; &nbsp; &nbsp; exporting
&nbsp; &nbsp; &nbsp; &nbsp; i_ready_for_input = 1.
&nbsp; &nbsp; call method g_alv_grid2->refresh_table_display.
&nbsp; endif.
endform. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"create_alv_master
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Module &nbsp;STATUS_0100 &nbsp;OUTPUT
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
module status_1005 output.
&nbsp; set pf-status 'SCREEN_0100_NEW'.
&nbsp; set titlebar 'SCREEN_0100_NEW'.
endmodule. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; " STATUS_0100 &nbsp;OUTPUT
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Module &nbsp;USER_COMMAND_0100 &nbsp;INPUT
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
module user_command_1005 input.
&nbsp; case sy-ucomm.
&nbsp; &nbsp; when 'BACK'.
&nbsp; &nbsp; &nbsp; leave to screen 0.
&nbsp; &nbsp; when 'EXIT'.
&nbsp; &nbsp; &nbsp; leave program.
&nbsp; &nbsp; when 'CANCEL'.
&nbsp; &nbsp; &nbsp; leave program.
&nbsp; endcase.
endmodule. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; " USER_COMMAND_0100 &nbsp;INPUT
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;exclude_toolbar
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp;-->P_IT_EXCLUDE &nbsp;text
\*----------------------------------------------------------------------\*
form exclude_toolbar changing p_it_exclude type ui_functions.
&nbsp; data : wa_exclude type ui_func.
&nbsp; wa_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
&nbsp; append wa_exclude to p_it_exclude.
&nbsp; wa_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.
&nbsp; append wa_exclude to p_it_exclude.
&nbsp; wa_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
&nbsp; append wa_exclude to p_it_exclude.
&nbsp; wa_exclude = cl_gui_alv_grid=>mc_fc_loc_cut.
&nbsp; append wa_exclude to p_it_exclude.
&nbsp; wa_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
&nbsp; append wa_exclude to p_it_exclude.
&nbsp; wa_exclude = cl_gui_alv_grid=>mc_fc_print.
&nbsp; append wa_exclude to p_it_exclude.
&nbsp; wa_exclude = cl_gui_alv_grid=>mc_fc_detail.
&nbsp; append wa_exclude to p_it_exclude.
&nbsp; wa_exclude = cl_gui_alv_grid=>mc_fc_refresh.
&nbsp; append wa_exclude to p_it_exclude.
&nbsp; wa_exclude = cl_gui_alv_grid=>mc_fc_check.
&nbsp; append wa_exclude to p_it_exclude.
&nbsp; wa_exclude = cl_gui_alv_grid=>mc_fc_loc_copy.
&nbsp; append wa_exclude to p_it_exclude.
&nbsp; wa_exclude = cl_gui_alv_grid=>mc_fc_loc_paste.
&nbsp; append wa_exclude to p_it_exclude.
&nbsp; wa_exclude = cl_gui_alv_grid=>mc_fc_loc_undo.
&nbsp; append wa_exclude to p_it_exclude.
&nbsp; wa_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
&nbsp; append wa_exclude to p_it_exclude.
endform. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"exclude_toolbar

Author: Sujeet Mishra
Submitted: 22/8/2013
Description: Sample program to display purchase requisition.

TABLES: EBAN, EKKO, EKPO, MAKT,T024, LFA1, T001W.
INITIALIZATION.
DATA: BEGIN OF ITAB OCCURS 0,
BANFN LIKE EBAN-BANFN,
MATNR LIKE EBAN-MATNR,
MAKTX LIKE MAKT-MAKTX,
MENGE LIKE EBAN-MENGE,
MEINS LIKE EBAN-MEINS,
LFDAT LIKE EBAN-LFDAT,
END OF ITAB.
DATA: BEGIN OF I_MAT OCCURS 0,
EBELN LIKE EKKO-EBELN,
EKGRP LIKE EKKO-EKGRP,
EKNAM LIKE T024-EKNAM,
LIFNR LIKE EKKO-LIFNR,
NAME1 LIKE LFA1-NAME1,
END OF I_MAT.
DATA: BEGIN OF I_VEN OCCURS 0,
&nbsp; &nbsp; &nbsp; &nbsp; ZTERM LIKE EKKO-ZTERM,
&nbsp; &nbsp; &nbsp; &nbsp; NETPR LIKE EKPO-NETPR,
&nbsp; &nbsp; &nbsp; END OF I_VEN.
&nbsp; DATA: FNAM(30), FVAL(18), MAT(18), VAN(10).
&nbsp; DATA: CLINES LIKE SY-INDEX.
&nbsp; DATA: MATNM LIKE MAKT-MAKTX, LIFNM LIKE LFA1-LIFNR.
&nbsp; SELECTION-SCREEN BEGIN OF BLOCK A WITH FRAME TITLE TEXT-003.
&nbsp; SELECT-OPTIONS: PLANT FOR EBAN-WERKS OBLIGATORY,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PUR_REQ FOR EBAN-BANFN .
&nbsp; SELECTION-SCREEN END OF BLOCK A.
TOP-OF-PAGE.
&nbsp; WRITE:/ 'PURCHASE REQUISITION REPORT' centered.
&nbsp; write:/ 'Report Date :', sy-datum.
&nbsp; ULINE /1(81).
START-OF-SELECTION.
&nbsp; select a~banfn a~matnr b~maktx a~menge a~meins a~lfdat into
&nbsp; corresponding fields of table itab from eban as a
&nbsp;inner join makt as b on a~matnr = b~matnr WHERE A~BANFN IN PUR_REQ AND
&nbsp; A~WERKS IN PLANT AND B~SPRAS = 'E' .
END-OF-SELECTION.
&nbsp; SORT ITAB BY BANFN MAKTX.
&nbsp; LOOP AT ITAB INTO ITAB.
&nbsp; &nbsp; AT NEW BANFN.
&nbsp; &nbsp; &nbsp; FORMAT COLOR COL_NEGATIVE INTENSIFIED OFF.
&nbsp; &nbsp; &nbsp; WRITE:/3 'PUR REQUISITION NO: ' , ITAB-BANFN .
&nbsp; &nbsp; &nbsp; FORMAT COLOR COL_HEADING INTENSIFIED ON.
&nbsp; &nbsp; &nbsp; ULINE AT /1(81).
&nbsp; WRITE:/1 SY-VLINE, 2 'MATERIAL ID & NAME', 35 SY-VLINE, 36 'QUANTITY',
&nbsp; 55 SY-VLINE, 56 'U O M', 66 SY-VLINE, 67 'DELIVERY DATE', 81 SY-VLINE.
&nbsp; &nbsp; &nbsp; ULINE AT /1(81).
&nbsp; &nbsp; ENDAT.
&nbsp; &nbsp; FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
&nbsp; &nbsp; HIDE: ITAB-BANFN.
&nbsp; WRITE:/1 SY-VLINE, 2 ITAB-MATNR, '-', ITAB-MAKTX UNDER 'MATERIAL', 35
&nbsp; SY-VLINE,
&nbsp; ITAB-MENGE UNDER 'QUANTITY', 55 SY-VLINE,
&nbsp; ITAB-MEINS UNDER 'U O M',66 SY-VLINE,
&nbsp; ITAB-LFDAT UNDER 'DELIVERY DATE', 81 SY-VLINE.
&nbsp; &nbsp; AT END OF BANFN.
&nbsp; &nbsp; &nbsp; SUM.
&nbsp; &nbsp; &nbsp; ULINE AT /1(81).
&nbsp; &nbsp; &nbsp; FORMAT COLOR COL_TOTAL INTENSIFIED OFF.
&nbsp; &nbsp; &nbsp; WRITE:/1 SY-VLINE, 2 'TOTAL :', 35 SY-VLINE, ITAB-MENGE UNDER
&nbsp; &nbsp; 'QUANTITY', 55 SY-VLINE, 66 SY-VLINE,81 SY-VLINE .
&nbsp; &nbsp; &nbsp; ULINE AT /1(81).
&nbsp; &nbsp; ENDAT.
&nbsp; ENDLOOP.
TOP-OF-PAGE DURING LINE-SELECTION.
&nbsp; IF FNAM = 'ITAB-MATNR'.
&nbsp; &nbsp; FORMAT COLOR COL_NEGATIVE INTENSIFIED OFF.
&nbsp; &nbsp; WRITE:/2 'MATERIAL DETAILS'.
&nbsp; &nbsp; PERFORM GETMATDESC USING FVAL.
&nbsp; &nbsp; WRITE:/2 'MAT NO:', FVAL, '-', MATNM .
&nbsp; &nbsp; ULINE AT /1(70).
&nbsp; &nbsp; FORMAT COLOR COL_HEADING INTENSIFIED OFF.
&nbsp; &nbsp; WRITE:/1 SY-VLINE,2 'P.O. NO', 13 SY-VLINE, 14 'PROD GROUP', 34
SY-VLINE, 35 'VENDOR ID & NAME', 70 SY-VLINE.
&nbsp; &nbsp; ULINE AT /1(70).
&nbsp; ENDIF.
&nbsp; IF FNAM = 'I_MAT-LIFNR'.
&nbsp; &nbsp; FORMAT COLOR COL_NEGATIVE INTENSIFIED OFF.
&nbsp; &nbsp; WRITE:/2 'VENDOR''''S DETAILS'.
&nbsp; &nbsp; PERFORM GETVENNM USING VAN.
&nbsp; &nbsp; WRITE:/2 'VENDOR ID:', FVAL, '-', LIFNM .
&nbsp; &nbsp; ULINE AT /1(45).
&nbsp; &nbsp; FORMAT COLOR COL_HEADING INTENSIFIED OFF.
&nbsp; &nbsp; WRITE:/1 SY-VLINE,2 'PAYMENT TERMS', 20 SY-VLINE,21 'NET PRICE', 45
&nbsp; SY-VLINE.
&nbsp; &nbsp; ULINE AT /1(45).
&nbsp; ENDIF.
AT LINE-SELECTION.
&nbsp; GET CURSOR FIELD FNAM VALUE FVAL.
&nbsp; IF FNAM = 'ITAB-MATNR'.
&nbsp; &nbsp; MAT = FVAL.
&nbsp; &nbsp; SELECT A~EBELN B~EKGRP D~EKNAM B~LIFNR C~NAME1 INTO TABLE I_MAT
&nbsp; &nbsp; &nbsp; FROM EKPO AS A
&nbsp; &nbsp; &nbsp; INNER JOIN EKKO AS B ON A~EBELN = B~EBELN
&nbsp; &nbsp; &nbsp; INNER JOIN LFA1 AS C ON B~LIFNR = C~LIFNR
&nbsp; &nbsp; &nbsp; INNER JOIN T024 AS D ON B~EKGRP = D~EKGRP
&nbsp; &nbsp; &nbsp; WHERE A~MATNR = MAT AND A~WERKS IN PLANT.
&nbsp; &nbsp; DESCRIBE TABLE I_MAT LINES CLINES.
&nbsp; &nbsp; IF CLINES GT 0.
&nbsp; &nbsp; &nbsp; FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
&nbsp; &nbsp; &nbsp; LOOP AT I_MAT.
&nbsp; &nbsp; &nbsp; &nbsp;WRITE:/1 SY-VLINE,2 I_MAT-EBELN, 13 SY-VLINE,14 I_MAT-EKGRP, '-'
, I_MAT-EKNAM, 34
&nbsp; &nbsp;SY-VLINE,35 I_MAT-LIFNR,'-', (20) I_MAT-NAME1, 70 SY-VLINE.
&nbsp; &nbsp; &nbsp; ENDLOOP.
&nbsp; &nbsp; &nbsp; ULINE AT /1(70).
&nbsp; &nbsp; ELSE.
&nbsp; &nbsp; &nbsp; MESSAGE I000.
&nbsp; &nbsp; ENDIF.
&nbsp; ENDIF.
&nbsp; IF FNAM = 'I_MAT-LIFNR'.
&nbsp; &nbsp; UNPACK FVAL TO VAN.
&nbsp; &nbsp; FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
&nbsp; &nbsp; REFRESH I_VEN.
&nbsp; &nbsp; SELECT A~ZTERM B~NETPR INTO CORRESPONDING FIELDS OF I_VEN
&nbsp; &nbsp; FROM EKKO AS A
&nbsp; &nbsp; INNER JOIN EKPO AS B ON A~EBELN = B~EBELN
&nbsp; &nbsp; WHERE A~LIFNR = VAN.
&nbsp; &nbsp; &nbsp; COLLECT I_VEN.
&nbsp; &nbsp; ENDSELECT.
&nbsp; &nbsp; SORT I_VEN BY ZTERM.
&nbsp; &nbsp; LOOP AT I_VEN.
&nbsp; &nbsp; &nbsp; WRITE:/1 SY-VLINE,2 I_VEN-ZTERM, 20 SY-VLINE,
&nbsp; &nbsp; &nbsp; 21 I_VEN-NETPR , 45 SY-VLINE.
&nbsp; &nbsp; &nbsp; IF SY-INDEX = 60.
&nbsp; &nbsp; &nbsp; &nbsp; ULINE AT /1(45).
&nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; ENDLOOP.
&nbsp; &nbsp; ULINE AT /1(45).
&nbsp; ENDIF.
END-OF-PAGE.
IF SY-LSIND = 0.
&nbsp; &nbsp; ULINE AT /1(81).
ELSEIF SY-LSIND = 1.
&nbsp; &nbsp; ULINE AT /1(70).
ELSEIF SY-LSIND = 2.
&nbsp; &nbsp; ULINE AT /1(45).
ENDIF.
\*&--------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;GETVENNM
\*&--------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp;-->VEN_NO &nbsp; &nbsp; text
\*---------------------------------------------------------------------\*
FORM GETVENNM USING VEN_NO.
&nbsp; SELECT SINGLE * FROM LFA1 WHERE LIFNR = VEN_NO.
&nbsp; LIFNM = LFA1-NAME1.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"GETVENNM
\*&--------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;GETMATDESC
\*&--------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp;-->MAT_NO &nbsp; &nbsp; text
\*---------------------------------------------------------------------\*
FORM GETMATDESC USING MAT_NO.
&nbsp; SELECT SINGLE * FROM MAKT WHERE MATNR = MAT_NO AND SPRAS = 'E'.
&nbsp; MATNM = MAKT-MAKTX.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"GETMATDESC

Sample  Declaration for data passing to BAPI for Item:


DATA:  it_poitem TYPE STANDARD TABLE OF bapimepoitem,
            it_poitemx TYPE STANDARD TABLE OF bapimepoitemx,
            it_poschedule TYPE STANDARD TABLE OF bapimeposchedule,
            it_poschedulex TYPE STANDARD TABLE OF bapimeposchedulx,
            it_poaccount TYPE STANDARD TABLE OF bapimepoaccount,
           it_poaccountx TYPE STANDARD TABLE OF bapimepoaccountx,
           it_pocond TYPE STANDARD TABLE OF bapimepocond,
it_pocondx TYPE STANDARD TABLE OF bapimepocondx,
it_pocondheader TYPE STANDARD TABLE OF bapimepocondheader,
it_pocondheaderx TYPE STANDARD TABLE OF bapimepocondheaderx,
it_return TYPE STANDARD TABLE OF bapiret2,
it_return1 TYPE STANDARD TABLE OF ty_return,
it_return2 TYPE STANDARD TABLE OF ty_return,
it_ret_collect TYPE STANDARD TABLE OF ty_return.

Sample declaration for Header Data:

DATA: wa_poheader TYPE bapimepoheader,
wa_poheaderx TYPE bapimepoheaderx,
wa_poitem TYPE bapimepoitem,
wa_poitemx TYPE bapimepoitemx,
wa_pocondheader TYPE bapimepocondheader,
wa_pocondheaderx TYPE bapimepocondheaderx,
wa_poschedule TYPE bapimeposchedule,
wa_poschedulex TYPE bapimeposchedulx,
wa_poaccount TYPE bapimepoaccount,
wa_poaccountx TYPE bapimepoaccountx,
wa_pocond TYPE bapimepocond,
wa_pocondx TYPE bapimepocondx,
wa_return TYPE bapiret2,
wa_ret_collect TYPE ty_return,
wa_modemessage TYPE ty_return.
* wa_poitemtext type bapimepotext.

Creating PO using BAPI:

CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = wa_poheader
poheaderx = wa_poheaderx
* POADDRVENDOR =
* TESTRUN =
* MEMORY_UNCOMPLETE =
* MEMORY_COMPLETE =
* POEXPIMPHEADER =
* POEXPIMPHEADERX =
* VERSIONS =
* NO_MESSAGING =
* NO_MESSAGE_REQ =
* NO_AUTHORITY =
no_price_from_po = 'X'
IMPORTING
exppurchaseorder = lv_po_number
* EXPHEADER =
* EXPPOEXPIMPHEADER =
TABLES
return = it_return
poitem = it_poitem
poitemx = it_poitemx
* POADDRDELIVERY =
poschedule = it_poschedule
poschedulex = it_poschedulex
poaccount = it_poaccount
* POACCOUNTPROFITSEGMENT =
poaccountx = it_poaccountx
pocondheader = it_pocondheader
pocondheaderx = it_pocondheaderx
pocond = it_pocond
pocondx = it_pocondx
* POLIMITS =
* POCONTRACTLIMITS =
* POSERVICES =
* POSRVACCESSVALUES =
* POSERVICESTEXT =
* EXTENSIONIN =
* EXTENSIONOUT =
* POEXPIMPITEM =
* POEXPIMPITEMX =
* POTEXTHEADER =
* potextitem = it_poitemtext
* ALLVERSIONS =
* POPARTNER =
* POCOMPONENTS =
* POCOMPONENTSX =
* POSHIPPING =
* POSHIPPINGX =
* POSHIPPINGEXP =
* NFMETALLITMS =
.
IF p_mode = ' '.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' " Function for BAPI Commit
EXPORTING
wait = 'X'
* IMPORTING
* RETURN = .
ENDIF.


Changing PO using BAPI:


CALL FUNCTION 'BAPI_PO_CHANGE'
EXPORTING
purchaseorder = lv_po_number
poheader = wa_poheader
poheaderx = wa_poheaderx
* POADDRVENDOR =
* TESTRUN =
* MEMORY_UNCOMPLETE =
* MEMORY_COMPLETE =
* POEXPIMPHEADER =
* POEXPIMPHEADERX =
* VERSIONS =
* NO_MESSAGING =
* NO_MESSAGE_REQ =
* NO_AUTHORITY =
* NO_PRICE_FROM_PO =
* IMPORTING
* EXPHEADER =
* EXPPOEXPIMPHEADER =
TABLES
return = it_return
poitem = it_poitem
poitemx = it_poitemx
* POADDRDELIVERY =
poschedule = it_poschedule
poschedulex = it_poschedulex
poaccount = it_poaccount
* POACCOUNTPROFITSEGMENT =
poaccountx = it_poaccountx
* POCONDHEADER =
* POCONDHEADERX =
pocond = it_pocond
pocondx = it_pocondx
* POLIMITS =
* POCONTRACTLIMITS =
* POSERVICES =
* POSRVACCESSVALUES =
* POSERVICESTEXT =
* EXTENSIONIN =
* EXTENSIONOUT =
* POEXPIMPITEM =
* POEXPIMPITEMX =
* POTEXTHEADER =
* POTEXTITEM =
* ALLVERSIONS =
* POPARTNER =
* POCOMPONENTS =
* POCOMPONENTSX =
* POSHIPPING =
* POSHIPPINGX =
* POSHIPPINGEXP =
* POHISTORY =
* POHISTORY_TOTALS =
* POCONFIRMATION =
* NFMETALLITMS =
.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
* IMPORTING
* RETURN = .

REPORT zashish  LINE-SIZE 170 LINE-COUNT 63 NO STANDARD PAGE HEADING.
**********************************************************************
* Program : ZAshish: Purchase Order Receipt Notification
* Author  : Ashish Patel
*
**********************************************************************
*-----------------------------------------------------------------------
* Progname / Pgmr: Zashish / Created: 26-SEP-00
*  Change Management request #: DBAR-4P6G-1228
*
*  Description:
*     Purchase Order Receipt Notification
*
*  CLONED_FROM_ALB_PROGRAM    ZFPPDSR
*-----------------------------------------------------------------------
TABLES : ekbe, ekpo, ekkn, zmail.
DATA: w_days LIKE t052-ztag1,
      w_aging(4) TYPE p,
      w_current LIKE bseg-wrbtr,
      w_1-30 LIKE bseg-wrbtr,
      w_31-xx LIKE bseg-wrbtr,
      w_total LIKE bseg-wrbtr,
      w_totcom LIKE bseg-wrbtr,
      w_tcocur  LIKE bseg-dmbtr,
      w_tcocur1 LIKE bseg-dmbtr,
      w_tcocur2 LIKE bseg-dmbtr,
      w_tcocur3 LIKE bseg-dmbtr,
      w_flag1(1) TYPE c,
      w_page(1)  TYPE c,
      duedate LIKE bsid-zfbdt,linetyp,
      w_transit(70) TYPE c.

DATA:
      w_outfil1(80) TYPE c             "jrt1/8/01
          VALUE '/sapmnt/export/mailsmtp/', "3/10/99 JRT
      w_time(8)      TYPE n,           "time for ds name"jrt4/23/98
      w_lin TYPE p,
      s_open(1)      TYPE c VALUE ' ', "open extract files"4/23/99 JR
      s_head(1)   TYPE c,              "write headers for extract
      w_output(80)   TYPE c,           "jrt1/8/01
      w_email(50)    TYPE c,           "jrt1/8/01
      w_data(200)    TYPE c,           "3/10/99 JRT
      w_outrec(200)  TYPE c,           "jrt 9/29/99
      w_catwrk(20)   TYPE c,           "jrt 9/29/99
      w_qtywrk(13)   TYPE c,           "jrt 9/29/99
      w_cpudt LIKE ekbe-cpudt,         "jrt 9/29/99
      w_cputm LIKE ekbe-cputm.         "jrt 9/29/99

DATA: BEGIN OF key_ekbe,
      cpudt LIKE ekbe-cpudt,
      cputm LIKE ekbe-cputm,
      END OF key_ekbe.

DATA: BEGIN OF start_zmail,
      cpudt LIKE ekbe-cpudt,
      cputm LIKE ekbe-cputm,
      END OF start_zmail.

DATA: BEGIN OF end_zmail,
      cpudt LIKE ekbe-cpudt,
      cputm LIKE ekbe-cputm,
      END OF end_zmail.

DATA: BEGIN OF t_zpmeml OCCURS 1.
        INCLUDE STRUCTURE zmail.
DATA: END OF t_zpmeml.

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

DATA: BEGIN OF whead.
        INCLUDE STRUCTURE thead.
DATA: END OF whead.

SELECT-OPTIONS: s_wempf FOR ekkn-wempf.
************************************************************************
************************************************************************
*                      F I E L D - G R O U P S                         *
************************************************************************
FIELD-GROUPS:
    header,
    detail.
INSERT:
    ekkn-wempf
    ekbe-ebeln
    ekbe-ebelp
                  INTO header,
    ekbe-bwart                                 "5/3/01 LHO
    ekpo-txz01
    ekbe-menge
    ekkn-aufnr
    ekkn-ablad
    zmail-langu
                  INTO detail.

INITIALIZATION.
  PERFORM set_select_opts.

START-OF-SELECTION.
*-----------------------------------------------------------------------
  SELECT * FROM ekbe
       WHERE vgabe = 1
         AND cpudt >= start_zmail-cpudt.

    MOVE ekbe-cpudt         TO key_ekbe-cpudt.
    MOVE ekbe-cputm         TO key_ekbe-cputm.

    IF key_ekbe < start_zmail.         "date/time less?
      CONTINUE.
    ENDIF.

    IF key_ekbe > end_zmail.           "date/time more?
      CONTINUE.
    ENDIF.

    SELECT  * FROM ekkn
        WHERE ebeln = ekbe-ebeln
          AND ebelp = ekbe-ebelp.
    ENDSELECT.

    IF sy-subrc = 0.
      CHECK ekkn-wempf NE ' '.
      CHECK ekkn-wempf IN s_wempf.
      SELECT SINGLE * FROM zmail
          WHERE wempf = ekkn-wempf.
      CHECK sy-subrc = 0.

      SELECT SINGLE * FROM ekpo
          WHERE ebeln = ekbe-ebeln
            AND ebelp = ekbe-ebelp.
      CHECK sy-subrc = 0.
      PERFORM update_t_zpmeml.
      EXTRACT detail.
    ENDIF.

  ENDSELECT.

END-OF-SELECTION.
*----------------------------------------------------------------------
* ---------- start of the list -----------------------------------
  SORT.
  LOOP.

    AT NEW ekkn-wempf.
      IF s_open = 'X'.
        CLOSE DATASET w_outfil1.
        s_open = ' '.
      ENDIF.
      MOVE 'X'  TO s_open.
      WRITE sy-uzeit TO w_time.
      w_outfil1+24(12) = ekkn-wempf.
      w_outfil1+36(01) = '.'.
      w_outfil1+37(08) = w_time.
      w_outfil1+45(04) = '.imp'.
      CONDENSE w_outfil1 NO-GAPS.
      OPEN DATASET w_outfil1 FOR OUTPUT IN TEXT MODE.
      PERFORM write_email_header.
    ENDAT.
    PERFORM write_po_data.

  ENDLOOP.

  IF s_open = 'X'.
    CLOSE DATASET w_outfil1.
    s_open = ' '.
  ENDIF.
* update ZPMEML with current values

  DESCRIBE TABLE t_zpmeml LINES w_lin.

  IF w_lin > 0.
    LOOP AT t_zpmeml.
      SELECT SINGLE * FROM zmail
           WHERE wempf = t_zpmeml-wempf.
      IF sy-subrc = 0.
        zmail-cpudt = t_zpmeml-cpudt.
        zmail-cputm = t_zpmeml-cputm.
        UPDATE zmail.
      ELSE.
        zmail-wempf = t_zpmeml-wempf.
        zmail-cpudt = t_zpmeml-cpudt.
        zmail-cputm = t_zpmeml-cputm.
        INSERT zmail.

      ENDIF.
    ENDLOOP.
  ENDIF.
*---------------------------------------------------------------------*
*       FORM WRITE_PO_DATA                                            *
*---------------------------------------------------------------------*
FORM write_po_data.

  CLEAR w_outrec.
  MOVE   'Purchase Order Number/item :'          TO w_outrec+1.
  IF zmail-langu = 'F'.
    MOVE   'N° de commande/Poste : '             TO w_outrec+1.
  ENDIF.
  MOVE  ekbe-ebeln                               TO w_outrec+31.
  MOVE  '/'                                      TO w_outrec+42.
  MOVE  ekbe-ebelp                               TO w_outrec+43.
  PERFORM write_extract.
*                      Movement type added 5/3/01 LHO
  CLEAR w_outrec.
  MOVE   'Movement Type:'                       TO w_outrec+1.
  IF zmail-langu = 'F'.
    MOVE   'Code Mouvement:'                    TO w_outrec+1.
  ENDIF.
  MOVE  ekbe-bwart                               TO w_outrec+17.
  PERFORM write_extract.

  CLEAR w_outrec.
  MOVE   'Description:'                          TO w_outrec+1.
  IF zmail-langu = 'F'.
    MOVE   'Designation :'                       TO w_outrec+1.
  ENDIF.
  MOVE  ekpo-txz01                               TO w_outrec+15.
  PERFORM write_extract.
  CLEAR w_outrec.
  MOVE  ekbe-menge                               TO w_qtywrk.
  MOVE  'Qty Received :'                         TO w_outrec+1.
  MOVE  w_qtywrk                                 TO w_outrec+16. "jrt125
  IF zmail-langu = 'F'.
    MOVE   'Quantite receptionnee :'             TO w_outrec+1.
    MOVE  w_qtywrk                               TO w_outrec+24.
  ENDIF.
  PERFORM write_extract.
  CLEAR w_outrec.
  MOVE   'Account Assign Order # :'              TO w_outrec+1.
  IF zmail-langu = 'F'.
    MOVE   'Imputation :'                        TO w_outrec+1.
  ENDIF.
  MOVE  ekkn-aufnr                               TO w_outrec+27.
  PERFORM write_extract.
  CLEAR w_outrec.
  MOVE   'Goods Recipient :'                     TO w_outrec+1.
  IF zmail-langu = 'F'.
    MOVE   'Receptionnaire :'                    TO w_outrec+1.
  ENDIF.
  MOVE  ekkn-wempf                               TO w_outrec+20.
  MOVE   'Unloading point:'                      TO w_outrec+35.
  MOVE  ekkn-ablad                               TO w_outrec+53.
  IF zmail-langu = 'F'.
    MOVE   'Pt de dechargement :'                TO w_outrec+35.
    MOVE  ekkn-ablad                             TO w_outrec+56.
  ENDIF.
  PERFORM write_extract.
  MOVE
 '********************************************************************'
                                                 TO w_outrec+1.
  PERFORM write_extract.
*
ENDFORM.                    "WRITE_PO_DATA

*----------------------------------------------------------------------*
*       Form  WRITE_EXTRACT
*----------------------------------------------------------------------*
FORM write_extract.

  TRANSFER w_outrec TO w_outfil1.
  CLEAR w_outrec.
ENDFORM.                    "WRITE_EXTRACT
***********************************************************************
*     FORM WRITE_EMAIL_HEADER
***********************************************************************
FORM write_email_header.

  CLEAR w_output.
  MOVE 'From: SAP@albemarle.com' TO w_output.      "jrt1/8/01
* MOVE 'From:' TO W_OUTPUT.
* W_OUTPUT+6(12) = EKKN-WEMPF.
  TRANSFER w_output TO w_outfil1.

  CLEAR w_output.
* W_OUTPUT = 'To:'.
* W_OUTPUT+6(50) = EKKN-WEMPF.
  CONCATENATE 'To: ' ekkn-wempf '@albemarle.com'  INTO w_output. "jrt1/8
  TRANSFER w_output TO w_outfil1.

  CLEAR w_output.
  MOVE 'Subject: Purchase Order Receipt(s)' TO w_output.
  TRANSFER w_output TO w_outfil1.

  CLEAR w_output.
  TRANSFER w_output TO w_outfil1.

ENDFORM.                    "WRITE_EMAIL_HEADER
***********************************************************************
*     FORM UPDATE_T_ZPMEML
***********************************************************************
FORM update_t_zpmeml.
  READ TABLE t_zpmeml  WITH KEY wempf = zmail-wempf.
  IF sy-subrc <> 0.
    t_zpmeml-wempf = zmail-wempf.
    t_zpmeml-cpudt = ekbe-cpudt.
    t_zpmeml-cputm = ekbe-cputm.
    APPEND t_zpmeml.
  ELSE.
    IF ekbe-cpudt = t_zpmeml-cpudt.
      IF ekbe-cputm > t_zpmeml-cputm.
        t_zpmeml-cpudt = ekbe-cpudt.
        t_zpmeml-cputm = ekbe-cputm.
        MODIFY t_zpmeml INDEX sy-tabix TRANSPORTING cpudt cputm.
      ENDIF.
    ELSE.
      IF ekbe-cpudt > t_zpmeml-cpudt.
        t_zpmeml-cpudt = ekbe-cpudt.
        t_zpmeml-cputm = ekbe-cputm.
        MODIFY t_zpmeml INDEX sy-tabix TRANSPORTING cpudt cputm.
      ENDIF.
    ENDIF.
  ENDIF.
ENDFORM.                    "UPDATE_T_ZPMEML
***********************************************************************
*     FORM SET_SELECT_OPTS
***********************************************************************
FORM set_select_opts.
  CLEAR: start_zmail, end_zmail.

  SELECT * FROM zmail.
    MOVE zmail-cpudt         TO start_zmail-cpudt.
    MOVE zmail-cputm         TO start_zmail-cputm.
    IF start_zmail > end_zmail.
      MOVE start_zmail TO end_zmail.
    ENDIF.
  ENDSELECT.

  MOVE end_zmail-cpudt TO w_cpudt.
  MOVE end_zmail-cputm TO w_cputm.
  CLEAR: start_zmail, end_zmail.
  w_cputm = w_cputm + 1.

*   set comparison keys
  MOVE w_cpudt         TO start_zmail-cpudt.
  MOVE w_cputm         TO start_zmail-cputm.
  MOVE sy-datum        TO end_zmail-cpudt.
  MOVE sy-uzeit        TO end_zmail-cputm.

ENDFORM.                    "SET_SELECT_OPTS
 

Author: Asis Mohanty

Submitted: 22/01/2008
Related Links:

  • <link>

Description

The purpose is to create a BTCI for loading
Purchase Orders. The data is taken from a       US DRP file.    REPORT ZMRGPORD
      LINE-SIZE 198.
*---------------------------------------------------------------------*
* Report: ZMRGPORD                                                          *
*                                                                                       *
* TECHNICAL DOCUMENTATION:                                            *
* - Jobnames........:                                                           *
*                                                                                      *
* - Variants........:                                                 *
*                                                                     *
* - Application Area: Material Management                             *
*                                                                     *
* - Author..........: Asis Mohanty / BCTS                             *
*                                                                     *
* - Conclusion Date.:                                                 *
*                                                                     *
* - Purpose.........:                                                               *
*---------------------------------------------------------------------*
************************************************************************
*
*
************************************************************************
* CHANGE HISTORY
*---------------------------------------------------------------------*
*  DATE    | NAME        |  DESCRIPTION          |     REFERENCE      *
*---------------------------------------------------------------------*
*          |             | Unicode conversion and|                    *
*          |             | upgrade to My SAP ERP |                    *
*---------------------------------------------------------------------*TABLES: LFM1,         "Vendor master record Purchasing organization data
        T001W,
        T024E,
        ZUSDRP1,
        MARA, MARC,
        EKKO, EKPO, EKET,
        EORD.
*----------------------------------*
* Layout del file US-DRP           *
*----------------------------------*
DATA: BEGIN OF USDRP OCCURS 0,
*                                       start amf082000
* brncod(5),                             "BRAND CODE                **
BRNCOD(8),                             "BRAND CODE                **
*                                       end amf082000
UKFLG1(2),                             "UNKNOWN FLAG 1
SHPDAT(6),                             "SHIP DATE                 **
SHPFRM(2),                             "SHIP FROM ID              **
FILL01(2),                             "FILLER 01
SHPTO(2),                              "SHIP TO ID                **
FILL02(2),                             "FILLER 02
INVNO(8),                              "INVOICE NUMBER            **
SHPQTY(8),                             "SHIPPED QUANTITY          **
CODCAR(4),                             "CARRIER
FILL03(1),                             "FILLER 03
USINVN(8),                             "US INVOICE NUMBER
SCCN(10),                              "SALES CUSTOMER NUMBER
FRNTYP(1),                             "FRINTYPE
FILL04(1),                             "FILLER 04
SECTOR(8),                             "SECTOR
DRPGRP(8),                             "DRP GROUP
FILL05(3),                             "FILLER 05
STATUS(1),                             "STATUS
END OF USDRP.
*
DATA: BEGIN OF TCONTROL OCCURS 0,
CONTRATO LIKE EKKO-KONNR,
ITEM     LIKE EKKO-LPONR,
MATERIAL(18),
END OF TCONTROL.DATA: BEGIN OF ITAB OCCURS 0,
CONTRATO LIKE EKKO-KONNR,
INVNRO(8),
ITEM     LIKE EKKO-LPONR,
PO(10),
PO_DATE(10),
VENDOR(10),
LEADTIME LIKE MARC-PLIFZ,
PURCH_ORG(4),
PURCH_GRP(3),
XXITEM(5),
MATERIAL(18),
QTY(17),
UNIT(3),
PRICE(14),
PRICE_UNIT(6),
CURRENCY(3),
DELIV_DATE(10),
PLANT(4),
NROLIN TYPE P,
LAST_ITEM LIKE EORD-EBELP,
END OF ITAB.DATA: BEGIN OF T_ITAB OCCURS 0.
        INCLUDE STRUCTURE ITAB.
DATA:  END OF T_ITAB.DATA: BEGIN OF XDAT OCCURS 0.
        INCLUDE STRUCTURE BDCDATA.
DATA: END OF XDAT.DATA: BEGIN OF KEY_CONTROL.
        INCLUDE STRUCTURE TCONTROL.
DATA: END OF KEY_CONTROL.DATA: BEGIN OF IWA.
        INCLUDE STRUCTURE ITAB.
DATA: END OF IWA.DATA: BEGIN OF BDCDAT OCCURS 0.
        INCLUDE STRUCTURE BDCDATA.
DATA: END OF BDCDAT.DATA: BEGIN OF CONTRATOS OCCURS 0,
      NROCON LIKE EORD-EBELN,
      NROINV LIKE ITAB-INVNRO,
      X_ITEM LIKE EORD-EBELP,
      Y_ITEM LIKE EORD-EBELP,
END OF CONTRATOS.DATA: BEGIN OF KEY_01,
      EBELN LIKE EORD-EBELN,
      INVNR LIKE ITAB-INVNRO,
      EBELP LIKE EORD-EBELP,
      END OF KEY_01.DATA: BEGIN OF KEY_02,
      EBELN LIKE EORD-EBELN,
      INVNR LIKE ITAB-INVNRO,
      END OF KEY_02.DATA: DATE   TYPE D,
      C_ITEM  TYPE P,                  "Counter of items
      X_FIRST TYPE P,
      C_LIN TYPE P,
      EVAL TYPE P,
      NROLIN TYPE P,
      NROREG TYPE P,
      CANTIDAD        LIKE EKPO-MENGE,
      POSCUR          LIKE SY-TABIX,
      POSREG          LIKE SY-TABIX,
      STSPGM(6)       TYPE C,
      EXISTE_INVNR    TYPE C,
      FLG_TODAY       TYPE C,
      LAST_ITEM       LIKE EORD-EBELP,
      FIRST_ITEM(1)   TYPE C,
      FIRST_DETAIL(1) TYPE C,
      DATE_1          TYPE D,
      DATE_2          TYPE D,
      REG_LOAD        TYPE P,
      REG_LEIDOS      TYPE P,
      REG_PROCES      TYPE P,
      REG_NOPROC      TYPE P,
      LENGTH TYPE I,
      ERROPMSG(100) VALUE ' ',
      FLAG,
      NUMLINMAX TYPE P VALUE '13',
      FLDANO TYPE P.DATA: BEGIN OF REG_ERRORES OCCURS 0,
*     brncod(5),                                  "amf082000
      BRNCOD(8),
      SHPDAT(6),
      SHPTO(2),
      INVNO(8),
      SHPQTY(8),
      MATERIAL(18),
      TIPERR(60),
      DELIV_DATE LIKE SY-DATUM,
      PO(10),
      END OF REG_ERRORES.
DATA: BEGIN OF TPLANTS OCCURS 0,
        COMPCODE LIKE T024E-BUKRS,
        PORGCODE LIKE T024E-EKORG,
        PLNTCODE LIKE T001W-WERKS,
      END OF TPLANTS.
*
DATA: BEGIN OF MAS_DETAIL OCCURS 0,
      INVNRO(8),
      END OF MAS_DETAIL.CONSTANTS:
     LEN_INFILE TYPE I VALUE 64.DATA: PLANT LIKE T001W-WERKS.
RANGES: RPLANT FOR T001W-WERKS.
DATA: STR TYPE I.
*---------------------------------------------------------------------*
*         SELECTION-SCREEN
*---------------------------------------------------------------------*
SELECTION-SCREEN: BEGIN OF BLOCK SEL1 WITH FRAME TITLE TEXT-SEL.
PARAMETERS:     PAR_CLNT   LIKE T001-MANDT  OBLIGATORY,
                PAR_COMP   LIKE T024E-BUKRS OBLIGATORY.
SELECT-OPTIONS: PAR_PLNT   FOR T001W-WERKS,
                S_MATNR FOR MARA-MATNR.                     "FDV300500
SELECTION-SCREEN: END OF BLOCK SEL1.
PARAMETERS:     P_FILE LIKE RLGRAP-FILENAME  DEFAULT
            '/opt/sapapp/tmp/sap_pe_int/pedrp/enroutes/drpfile.txt'.
*---------------------------------------------------------------------*
*         MAIN-PROGRAM                                                *
*---------------------------------------------------------------------*
start-of-selection.
* perform read_planta.
* perform read_file_pc.
PERFORM OPEN_UNIX_FILE.
PERFORM READ_UNIX_FILE.
PERFORM CLOSE_DATAFILES_UNIX.
*
IF STSPGM = 'ENDPGM'.
  WRITE: / TEXT-E02.
ELSE.
  PERFORM READ_DAT_MAT.
  PERFORM READ_RANGO_CONT.
  PERFORM READ_LIN_SCREEN.  PERFORM BDC_OPEN.
  PERFORM READ_CONTRATOS_VAL.
  PERFORM MOVE_DATA_TEM.  WHILE C_LIN <> 0.
    PERFORM READ_RANGO_CONT.
    PERFORM READ_LIN_SCREEN.
    PERFORM READ_CONTRATOS_VAL.
    PERFORM MOVE_DATA_TEM.
  ENDWHILE.ENDIF.PERFORM BDC_CLOSE.IF REG_PROCES <> 0.
  SUBMIT RSBDCSUB
     WITH MAPPE    EQ 'PORDE.USDRP'
     WITH VON      EQ SY-DATUM
     WITH BIS      EQ SY-DATUM
*     WITH Z-VERARB EQ 'X'                        "PCC26032007
*Z-VERARB is not a parameter or a select option in report RSBDCSUB
      WITH FEHLER   EQ 'X'
      WITH BATCHSYS EQ SY-HOST
      WITH LOGALL   EQ SPACE
      AND RETURN.
ENDIF.PERFORM PRINT_LOG.
*---------------------------------------------------------------------*
*       FORM READ_PLANTA                                              *
*---------------------------------------------------------------------*
FORM READ_PLANTA.
  SELECT * FROM T024E CLIENT SPECIFIED
                      WHERE MANDT EQ PAR_CLNT
                      AND   BUKRS EQ PAR_COMP.
    SELECT WERKS INTO PLANT FROM T001W CLIENT SPECIFIED
                      WHERE MANDT EQ PAR_CLNT
                      AND   EKORG EQ T024E-EKORG
                      AND   WERKS IN PAR_PLNT
                      ORDER BY WERKS.
      MOVE: PLANT       TO TPLANTS-PLNTCODE,
            T024E-EKORG TO TPLANTS-PORGCODE,
            T024E-BUKRS TO TPLANTS-COMPCODE.
      APPEND TPLANTS.
    ENDSELECT.
  ENDSELECT.*Rango de plantas
  SORT TPLANTS BY PLNTCODE.
  RPLANT-SIGN = 'I'.
  RPLANT-OPTION = 'BT'.
  LOOP AT TPLANTS.
    AT FIRST.
      X_FIRST = 1.
    ENDAT.
    IF X_FIRST = 1.
      RPLANT-LOW = TPLANTS-PLNTCODE.
      X_FIRST = 2.
    ENDIF.
  ENDLOOP.
  RPLANT-HIGH = TPLANTS-PLNTCODE.
  APPEND RPLANT.
ENDFORM.
*---------------------------------------------------------------------*
*       FORM READ_FILE_PC                                             *
*---------------------------------------------------------------------*
FORM READ_FILE_PC.
*{Begin of PCC22032007
*  CALL FUNCTION 'WS_UPLOAD'
*       EXPORTING
*            FILENAME = P_FILE
*       TABLES
*            DATA_TAB = USDRP
*       EXCEPTIONS
*            OTHERS   = 1.DATA: W_P_FILE TYPE STRING.MOVE: P_FILE TO W_P_FILE.   CALL FUNCTION 'GUI_UPLOAD'
     EXPORTING
       FILENAME                      = W_P_FILE
     TABLES
       DATA_TAB                      = USDRP
    EXCEPTIONS
      FILE_OPEN_ERROR               = 1
      FILE_READ_ERROR               = 2
      NO_BATCH                      = 3
      GUI_REFUSE_FILETRANSFER       = 4
      INVALID_TYPE                  = 5
      NO_AUTHORITY                  = 6
      UNKNOWN_ERROR                 = 7
      BAD_DATA_FORMAT               = 8
      HEADER_NOT_ALLOWED            = 9
      SEPARATOR_NOT_ALLOWED         = 10
      HEADER_TOO_LONG               = 11
      UNKNOWN_DP_ERROR              = 12
      ACCESS_DENIED                 = 13
      DP_OUT_OF_MEMORY              = 14
      DISK_FULL                     = 15
      DP_TIMEOUT                    = 16
      OTHERS                        = 17.   IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
   ENDIF.
*}End of PCC22032007
ENDFORM.
*&---------------------------------------------------------------------*
*& Routine OPEN_UNIX_FILE                                              *
*&---------------------------------------------------------------------*
FORM OPEN_UNIX_FILE.
  OPEN DATASET P_FILE FOR INPUT        " Open unix input data-file
                       IN TEXT MODE
                       MESSAGE ERROPMSG
                       ENCODING DEFAULT.          "PCC22032007
  IF SY-SUBRC NE 0.
    STSPGM = 'ENDPGM'.
    WRITE: / 'ZMRGPORD. OPEN ERROR IN UNIX INPUT FILE = ', P_FILE.
    WRITE: / 'SY-SUBRC = ', SY-SUBRC.
    WRITE: / 'SYSTEM MESSAGE = ', ERROPMSG.
    EXIT.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Routine READ_UNIX_FILE                                              *
*&         Read the Input data-file and spread procedures for          *
*&         build and transfer records ZESTI                            *
*&---------------------------------------------------------------------*
FORM READ_UNIX_FILE.
  DO.
    READ DATASET P_FILE INTO USDRP LENGTH LENGTH.
    IF SY-SUBRC <> 0.
      EXIT.                            " Leaves loop when end-data
    ENDIF.
*
    APPEND USDRP.
  ENDDO.ENDFORM.
*&---------------------------------------------------------------------*
*& Routine CLOSE_DATAFILES_UNIX                                        *
*&---------------------------------------------------------------------*
FORM CLOSE_DATAFILES_UNIX.  CLOSE DATASET P_FILE.                " Close unix input data-file
ENDFORM.
*---------------------------------------------------------------------*
*         READ_CONTRATOS_VAL
*---------------------------------------------------------------------*
FORM READ_CONTRATOS_VAL.
  DATA: XX_INVNRO LIKE ITAB-INVNRO.
  DATA: XX_CONTRATO LIKE ITAB-CONTRATO.
  SORT ITAB BY CONTRATO INVNRO ITEM.
  CLEAR XX_INVNRO.
  CLEAR XX_CONTRATO.  LOOP AT ITAB.
    IWA = ITAB.
    IF ( ITAB-INVNRO  <>  XX_INVNRO AND XX_INVNRO <> SPACE )
     OR (  ITAB-CONTRATO  <>  XX_CONTRATO AND XX_INVNRO <> SPACE ).
      PERFORM END_INVNRO.
    ENDIF.    IF ( ITAB-INVNRO  <>  XX_INVNRO ) OR
       ( ITAB-CONTRATO  <>  XX_CONTRATO ) .
      PERFORM NEW_PURCHASE_ORDER.
      XX_INVNRO = ITAB-INVNRO.
      XX_CONTRATO = ITAB-CONTRATO.
    ENDIF.    ADD 1 TO C_ITEM.
    PERFORM FILL_DYNPRO_124.           "Item overview screen    AT LAST.
      PERFORM END_INVNRO.
    ENDAT.
  ENDLOOP.
*
ENDFORM.
*---------------------------------------------------------------------*
*       NEW_PURCHASE_ORDER                                            *
*---------------------------------------------------------------------*
FORM NEW_PURCHASE_ORDER.
  FIRST_ITEM = SPACE.
  FLG_TODAY  = SPACE.
  KEY_02-EBELN = ITAB-CONTRATO.
  KEY_02-INVNR = ITAB-INVNRO.
  READ TABLE CONTRATOS WITH KEY KEY_02.
  PERFORM FLAG_TODAY.
  PERFORM FILL_DYNPRO_100.             "Initial screen
ENDFORM.
*---------------------------------------------------------------------*
*       FORM FILL_DYNPRO_100                                          *
*---------------------------------------------------------------------*
FORM FILL_DYNPRO_100.
  BDCDAT-PROGRAM   = 'SAPMM06E'.
  BDCDAT-DYNPRO    = '0100'.
  BDCDAT-DYNBEGIN  = 'X'.
  PERFORM LT TABLES BDCDAT USING 'RM06E-WERKS' ''.
  CLEAR BDCDAT-DYNBEGIN.
  PERFORM LT TABLES BDCDAT USING 'BDC_OKCODE' 'SL'.
*
  BDCDAT-PROGRAM   = 'SAPMM06E'.
  BDCDAT-DYNPRO    = '0502'.
  BDCDAT-DYNBEGIN  = 'X'.
  PERFORM: LT TABLES BDCDAT USING 'EKKO-KONNR'  IWA-CONTRATO.
  CLEAR BDCDAT-DYNBEGIN.
*
  PERFORM: LT TABLES BDCDAT USING 'RM06E-KTRPV' IWA-ITEM,
           LT TABLES BDCDAT USING 'RM06E-KTRPB' IWA-LAST_ITEM,
           LT TABLES BDCDAT USING 'BDC_OKCODE' ''.
*
  BDCDAT-PROGRAM   = 'SAPMM06E'.
  BDCDAT-DYNPRO    = '0514'.
  BDCDAT-DYNBEGIN  = 'X'.
  PERFORM: LT TABLES BDCDAT USING 'EKKO-BUKRS'  PAR_COMP.
  CLEAR BDCDAT-DYNBEGIN.
  PERFORM LT TABLES BDCDAT USING 'BDC_OKCODE ' ''.
ENDFORM.
*---------------------------------------------------------------------*
*       FORM FILL_DYNPRO_124                                          *
*---------------------------------------------------------------------*
FORM FILL_DYNPRO_124.  DATA: PRICE LIKE EKPO-NETPR,
        PRICE_UNIT LIKE EKPO-PEINH,
        QTY LIKE EKPO-MENGE,
        QTY2 LIKE EKPO-MENGE,
        N_ITEM(3),
        LEN TYPE P,
        NUM TYPE P,
        FMENGE(16) VALUE 'EKPO-MENGE(x)',
        FEEIND(16) VALUE 'RM06E-EEIND(x)',
        FLGORT(16) VALUE 'EKPO-LGORT(x)'.* Prepare the numeric and date fields for writting them with the user
* default formats.
  QTY = IWA-QTY.
  WRITE QTY TO IWA-QTY.* Prepare the fields
  N_ITEM = IWA-NROLIN.
  REPLACE 'x' WITH N_ITEM INTO FMENGE.
  CONDENSE FMENGE NO-GAPS.
  REPLACE 'x' WITH N_ITEM INTO FEEIND.
  CONDENSE FEEIND NO-GAPS.
  REPLACE 'x' WITH N_ITEM INTO FLGORT.
  CONDENSE FLGORT NO-GAPS.* Fill the values of the dynpro.
  IF C_ITEM EQ 1.
    BDCDAT-PROGRAM   = 'SAPMM06E'.
    BDCDAT-DYNPRO    = '0124'.
    BDCDAT-DYNBEGIN  = 'X'.
  ENDIF.  MOVE IWA-DELIV_DATE TO DATE.
  WRITE DATE TO IWA-DELIV_DATE.
  PERFORM: LT TABLES BDCDAT USING FMENGE  IWA-QTY.
  CLEAR BDCDAT-DYNBEGIN.
  PERFORM: LT TABLES BDCDAT USING FEEIND  IWA-DELIV_DATE.
*
  IF IWA-MATERIAL <> SPACE AND QTY <> 0.
    MOVE IWA-INVNRO TO MAS_DETAIL-INVNRO.
    APPEND MAS_DETAIL.
  ENDIF.
*
  NUM = C_ITEM MOD NUMLINMAX.                              "amf20001222
  IF NUM EQ 0 AND IWA-ITEM <> CONTRATOS-Y_ITEM.
*   perform lt tables bdcdat using 'BDC_OKCODE' 'VW'.
    PERFORM LT TABLES BDCDAT USING 'BDC_OKCODE' 'P+'.
    C_ITEM = 0.
  ENDIF.
ENDFORM.*---------------------------------------------------------------------*
*       FORM FILL_DYNPRO_111                                          *
*---------------------------------------------------------------------*
FORM FILL_DYNPRO_111.
  DATA: LIM TYPE P.
  DATA: LIN TYPE P.
  CLEAR LIM.
  DESCRIBE TABLE MAS_DETAIL LINES LIN.
  LOOP AT MAS_DETAIL.
    LIM = LIM + 1.
    BDCDAT-PROGRAM   = 'SAPMM06E'.
    BDCDAT-DYNPRO    = '0111'.
    BDCDAT-DYNBEGIN  = 'X'.
    PERFORM LT TABLES BDCDAT USING 'EKPO-BEDNR' MAS_DETAIL-INVNRO.
    BDCDAT-DYNBEGIN  = ' '.
    PERFORM LT TABLES BDCDAT USING 'EKPO-BSTAE' '9003'.
    IF LIM <> LIN.
      PERFORM LT TABLES BDCDAT USING 'BDC_OKCODE' 'NEXP'.
    ELSE.
      PERFORM LT TABLES BDCDAT USING 'BDC_OKCODE' '=BU'.
*      perform fill_dynpro_120.                       "amf20001221
    ENDIF.
  ENDLOOP.
ENDFORM.
*---------------------------------------------------------------------*
*       FORM FILL_DYNPRO_120                                          *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM FILL_DYNPRO_120.                                      "amf20001221
  BDCDAT-PROGRAM   = 'SAPMM06E'.
  BDCDAT-DYNPRO    = '0120'.
  BDCDAT-DYNBEGIN  = 'X'.
  PERFORM LT TABLES BDCDAT USING 'BDC_OKCODE ' '/11'.
* bdc-program = 'SAPMM06E'. bdc-dynpro = '0120'. bdc-dynbegin = 'X'.
* perform: lt tables bdc using 'BDC_OKCODE ' '/30'.
* bdc-program = 'SAPMM06E'. bdc-dynpro = '0120'. bdc-dynbegin = 'X'.
* perform: lt tables bdc using 'BDC_OKCODE ' '/2'.
* select * from ekpo where ebeln eq sto order by ebelp.
*   bdc-program = 'SAPMM06E'. bdc-dynpro = '0111'. bdc-dynbegin = 'X'.
*   perform: lt tables bdc using 'EKPO-BEDNR' sto,
*            lt tables bdc using 'BDC_OKCODE ' '/19'.
* endselect.
ENDFORM.
*---------------------------------------------------------------------*
*       FORM LT                                                       *
*---------------------------------------------------------------------*
*  -->  BDC                                                           *
*  -->  F_NAME                                                        *
*  -->  F_VAL                                                         *
*---------------------------------------------------------------------*
*{Begin of PCC22032007
*FORM LT TABLES BDC STRUCTURE BDCDATA USING F_NAME F_VAL.
FORM LT TABLES BDC STRUCTURE BDCDATA USING F_NAME TYPE C
                                           F_VAL  TYPE ANY.
*}End of PCC22032007
  BDC-FNAM      = F_NAME.
  BDC-FVAL      = F_VAL.
  APPEND BDC.
  MOVE-CORRESPONDING BDCDAT TO XDAT.
  APPEND XDAT.ENDFORM.*---------------------------------------------------------------------*
*       FORM BDC_INSERT                                               *
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
*  -->  BDCDAT                                                        *
*  -->  TCOD                                                          *
*---------------------------------------------------------------------*
FORM BDC_INSERT TABLES BDCDAT STRUCTURE BDCDATA
                USING TCOD.  CALL FUNCTION 'BDC_INSERT'
       EXPORTING
            TCODE         = TCOD
       TABLES
            DYNPROTAB     = BDCDAT
       EXCEPTIONS
*{Begin of PCC26032007
*            INTERNAL
*            ERROR         = 1
*            NOT_OPEN      = 2
*            QUEUE_ERROR   = 3
*            TCODE_INVALID = 4.
             INTERNAL_ERROR         = 1
             NOT_OPEN               = 2
             QUEUE_ERROR            = 3
             TCODE_INVALID          = 4
             PRINTING_INVALID       = 5
             POSTING_INVALID        = 6
             OTHERS                 = 7.
*}End of PCC26032007  REFRESH BDCDAT.ENDFORM.
*---------------------------------------------------------------------*
*       FORM BDC_CLOSE                                                *
*---------------------------------------------------------------------*
FORM BDC_CLOSE.  CALL FUNCTION 'BDC_CLOSE_GROUP'
       EXCEPTIONS
            OTHERS = 1.
  IF SY-SUBRC NE 0.
  ENDIF.ENDFORM.*---------------------------------------------------------------------*
*       FORM BDC_OPEN                                                 *
*---------------------------------------------------------------------*
FORM BDC_OPEN.
  DATA: GROUP LIKE APQI-GROUPID.
  GROUP = 'PORDE.USDRP'.
  CALL FUNCTION 'BDC_OPEN_GROUP'
       EXPORTING
            CLIENT = SY-MANDT
            GROUP  = GROUP
            USER   = SY-UNAME
            KEEP   = 'X'
       EXCEPTIONS
            OTHERS = 1.
  IF SY-SUBRC NE 0.
  ENDIF.ENDFORM.
*---------------------------------------------------------------------*
*       FORM READ_DAT_MAT                                             *
*---------------------------------------------------------------------*
FORM READ_DAT_MAT.
  DATA: FLG_CONTRATO TYPE C, DATE1(8).
  SORT USDRP BY INVNO.
  DESCRIBE TABLE USDRP LINES REG_LOAD.
  LOOP AT USDRP WHERE UKFLG1 = 'SE'.
    CLEAR ITAB.
    CLEAR REG_ERRORES.** Cambia formato de aammdd a aaaammdd
    MOVE USDRP-SHPDAT+0(2) TO FLDANO.* start amf082000
    STR = STRLEN( USDRP-BRNCOD ).
    CASE STR.
      WHEN 8.
        IF USDRP-BRNCOD+0(3) EQ '830'.
          USDRP-BRNCOD+0(3) = '000'.
        ENDIF.
      WHEN 5.
        USDRP-BRNCOD+3(5) = USDRP-BRNCOD(5).
        USDRP-BRNCOD+0(3) = '000'.
    ENDCASE.
* end amf082000* LA SAP yr 2k renovation 7/98  CCC15071998 Start
* if fldaño < 50.
*    concatenate '20' usdrp-shpdat into date.
* else.
*    concatenate '19' usdrp-shpdat into date.
* endif.
    IF FLDANO < 71.
      CONCATENATE '20' USDRP-SHPDAT INTO DATE1.
    ELSE.
      CONCATENATE '19' USDRP-SHPDAT INTO DATE1.
    ENDIF.
* LA SAP yr 2k renovation 7/98  CCC15071998 End    WRITE DATE1 TO ITAB-PO_DATE.
**
    REG_LEIDOS = REG_LEIDOS + 1.
*Quiebre de invoice number
    ON CHANGE OF USDRP-INVNO.
      CLEAR REG_ERRORES.
      CLEAR EXISTE_INVNR.
    ENDON.
*
    MOVE-CORRESPONDING USDRP TO REG_ERRORES.
*
    IF USDRP-SHPDAT+0(2) EQ SPACE.
      MOVE TEXT-E03 TO REG_ERRORES-TIPERR.
      APPEND REG_ERRORES.
      CONTINUE.
    ENDIF.
*
*
    SELECT SINGLE * FROM ZUSDRP1 WHERE SHTOID = USDRP-SHPTO  AND
*                                       werks in rplant.
                                          WERKS IN PAR_PLNT AND
                                          BUKRS EQ PAR_COMP AND
                                          BISMT EQ USDRP-BRNCOD+3.
    IF SY-SUBRC NE 0.
      SELECT SINGLE * FROM ZUSDRP1 WHERE WERKS IN PAR_PLNT AND
                                         BISMT EQ SPACE   AND
                                         SHTOID EQ USDRP-SHPTO AND
                                         BUKRS EQ PAR_COMP.
    ENDIF.
    IF SY-SUBRC EQ 0.
      IF ZUSDRP1-MATNR EQ SPACE.
        SELECT * FROM MARA WHERE BISMT = USDRP-BRNCOD AND   " LP
                                        LVORM = SPACE.
          SELECT SINGLE * FROM MARC WHERE MATNR EQ MARA-MATNR AND
                                              WERKS EQ ZUSDRP1-WERKS.
          IF SY-SUBRC EQ 0.
            EXIT.
          ENDIF.
        ENDSELECT.                     "LPADD
      ELSE.
        SELECT * FROM MARA WHERE MATNR = ZUSDRP1-MATNR AND
                                        LVORM = SPACE.
          SELECT SINGLE * FROM MARC WHERE MATNR EQ MARA-MATNR AND
                                              WERKS EQ ZUSDRP1-WERKS.
          IF SY-SUBRC EQ 0.
            EXIT.
          ENDIF.
        ENDSELECT.                     "LPADD
      ENDIF.
*--Si no encuentra por Old material number--*
      IF SY-SUBRC <> 0.
        SELECT SINGLE * FROM MARA WHERE
          MATNR = USDRP-BRNCOD AND LVORM = SPACE.
      ENDIF.      CHECK MARA-MATNR IN S_MATNR.                          "FDV300500      IF SY-SUBRC = 0.
*--Si existe POs con igual número de invoice y material number
        SELECT SINGLE * FROM EKPO WHERE BEDNR = USDRP-INVNO
                                    AND MATNR = MARA-MATNR.
        IF SY-SUBRC <> 0.
          SELECT SINGLE *  FROM MARC WHERE MATNR = MARA-MATNR AND
                                           WERKS = ZUSDRP1-WERKS.
          IF SY-SUBRC = 0.
            REG_ERRORES-MATERIAL = MARA-MATNR.
            ITAB-MATERIAL   = MARA-MATNR.
            ITAB-LEADTIME   = MARC-PLIFZ.
            ITAB-PURCH_GRP  = MARC-EKGRP.
            ITAB-PURCH_ORG  = TPLANTS-PORGCODE.
            ITAB-QTY        = USDRP-SHPQTY.
            ITAB-INVNRO     = USDRP-INVNO.
            ITAB-PLANT      = ZUSDRP1-WERKS.
            ITAB-LEADTIME   = MARC-PLIFZ.
            CLEAR FLG_CONTRATO.
            SELECT * FROM EORD WHERE MATNR  EQ ITAB-MATERIAL AND
                                     WERKS  EQ ITAB-PLANT    AND
                                     EBELN  NE SPACE.
              IF SY-DATUM GE EORD-VDATU AND
                 SY-DATUM LE EORD-BDATU.
                ITAB-VENDOR   =  EORD-LIFNR.
                ITAB-CONTRATO =  EORD-EBELN.
                ITAB-ITEM     =  EORD-EBELP.
                ITAB-UNIT     =  EORD-MEINS.
                DATE_1 =  ITAB-PO_DATE.
                DATE_2 =  DATE_1 + MARC-PLIFZ.
                MOVE: DATE_2 TO ITAB-DELIV_DATE.*               move: itab-contrato to key_control-contrato,
*                     itab-item     to key_control-item,
*                     itab-material to key_control-material.
*               read  table tcontrol with key key_control.
*               if sy-subrc <> 0.
                MOVE-CORRESPONDING ITAB TO TCONTROL.
                APPEND TCONTROL.
                APPEND ITAB.
                REG_PROCES = REG_PROCES + 1.
                CONTRATOS-NROCON = EORD-EBELN.
                CONTRATOS-NROINV = USDRP-INVNO.
                COLLECT CONTRATOS.
*               else.
*                      move-corresponding itab to t_itab.
*                      append t_itab.
*               endif.
                MOVE 'X' TO FLG_CONTRATO.
                REG_ERRORES-DELIV_DATE = ITAB-DELIV_DATE. "LP 06/
                MOVE TEXT-E00 TO REG_ERRORES-TIPERR.
                APPEND REG_ERRORES.
                EXIT.
              ENDIF.
            ENDSELECT.
            IF FLG_CONTRATO EQ SPACE.
              MOVE TEXT-E12 TO REG_ERRORES-TIPERR.
              APPEND REG_ERRORES.
            ENDIF.
          ELSE.
            MOVE TEXT-E11 TO REG_ERRORES-TIPERR.
            APPEND REG_ERRORES.
          ENDIF.
        ELSE.
*             move      to  reg_errores-ebelnr.
          CLEAR EKET.
          SELECT SINGLE * FROM EKET WHERE EBELN EQ EKPO-EBELN AND
                                          EBELP EQ EKPO-EBELP.
          REG_ERRORES-DELIV_DATE = EKET-EINDT.
          MOVE TEXT-E13 TO REG_ERRORES-TIPERR.
          REG_ERRORES-PO = EKPO-EBELN. " LP 06/02/99
          REG_ERRORES-MATERIAL = EKPO-MATNR.
          APPEND REG_ERRORES.
        ENDIF.
      ELSE.
        MOVE TEXT-E10 TO REG_ERRORES-TIPERR.
        APPEND REG_ERRORES.
      ENDIF.
    ENDIF.
  ENDLOOP.
ENDFORM.
*---------------------------------------------------------------------*
*       FORM READ_LIN_SCREEN
*---------------------------------------------------------------------*
FORM READ_LIN_SCREEN.
  SORT CONTRATOS BY NROCON NROINV.
  SORT ITAB BY CONTRATO INVNRO ITEM.  LOOP AT CONTRATOS.
    EVAL   = 0. NROREG = 0. NROLIN = 0.
*
    SELECT * FROM EORD WHERE EBELN  = CONTRATOS-NROCON AND
                             EBELP >= CONTRATOS-X_ITEM AND
                             EBELP <= CONTRATOS-Y_ITEM
                    ORDER BY EBELN EBELP.
      KEY_01-EBELN = EORD-EBELN.
      KEY_01-INVNR = CONTRATOS-NROINV.
      KEY_01-EBELP = EORD-EBELP.
      READ TABLE ITAB WITH KEY KEY_01 BINARY SEARCH.
      IF SY-SUBRC = 0.
        POSCUR = SY-TABIX.
        ADD 1 TO NROREG.
        ADD 1 TO NROLIN.
        ITAB-NROLIN = NROLIN.
        MODIFY ITAB INDEX POSCUR.
        EVAL = 1.
        LAST_ITEM = ITAB-ITEM.
      ELSE.
        IF EVAL <> 0.
          ADD 1 TO NROLIN.
          CLEAR ITAB.
          ITAB-CONTRATO = CONTRATOS-NROCON.
          ITAB-ITEM     = EORD-EBELP.
          ITAB-INVNRO   = CONTRATOS-NROINV.
          ITAB-NROLIN = NROLIN.
          APPEND ITAB.
          SORT ITAB BY CONTRATO INVNRO ITEM.
        ENDIF.
      ENDIF.
*
      IF NROREG = 1.
        POSREG = POSCUR.
      ENDIF.
*
      IF NROLIN = NUMLINMAX.                               "amf20001222
*     if nrolin = 12.
        NROLIN = 0.
      ENDIF.
    ENDSELECT.    READ TABLE ITAB INDEX POSREG.
    IF SY-SUBRC = 0.
      ITAB-LAST_ITEM = LAST_ITEM.
      MODIFY ITAB INDEX POSREG.
    ENDIF.
  ENDLOOP.
*
ENDFORM.
*---------------------------------------------------------------------*
*       FORM FLAG_TODAY                                               *
*---------------------------------------------------------------------*
FORM FLAG_TODAY.
  CLEAR FLG_TODAY.
  SELECT SINGLE * FROM EKKO WHERE KONNR EQ IWA-CONTRATO AND
                                  AEDAT EQ SY-DATUM.
  IF SY-SUBRC EQ 0.
    FLG_TODAY = 'X'.
  ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
*       FORM READ_RANGO_CONT
*---------------------------------------------------------------------*
FORM READ_RANGO_CONT.
  LOOP AT CONTRATOS.
    CLEAR CONTRATOS-X_ITEM.
    CLEAR CONTRATOS-Y_ITEM.
    SORT ITAB BY CONTRATO INVNRO ITEM.
    LOOP AT ITAB WHERE CONTRATO = CONTRATOS-NROCON AND
                         INVNRO   = CONTRATOS-NROINV.
      IF CONTRATOS-X_ITEM = 0.
        CONTRATOS-X_ITEM = ITAB-ITEM.
      ENDIF.
      CONTRATOS-Y_ITEM = ITAB-ITEM.
    ENDLOOP.
    MODIFY CONTRATOS.
  ENDLOOP.
ENDFORM.
*----------------------------------------------------------------------*
*         FORM MOVE_DATA_TEM
*----------------------------------------------------------------------*
FORM MOVE_DATA_TEM.
  CLEAR TCONTROL.
  REFRESH TCONTROL.
  CLEAR ITAB.
  REFRESH ITAB.
  CLEAR C_LIN.
  CLEAR CONTRATOS.
  REFRESH CONTRATOS.  LOOP AT T_ITAB.
    MOVE: T_ITAB-CONTRATO TO KEY_CONTROL-CONTRATO,
          T_ITAB-ITEM     TO KEY_CONTROL-ITEM,
          T_ITAB-MATERIAL TO KEY_CONTROL-MATERIAL.
    READ  TABLE TCONTROL WITH KEY KEY_CONTROL.
    IF SY-SUBRC <> 0.
      MOVE-CORRESPONDING T_ITAB TO TCONTROL.
      APPEND TCONTROL.
      MOVE-CORRESPONDING T_ITAB TO ITAB.
      APPEND ITAB.
      REG_PROCES = REG_PROCES + 1.
      CONTRATOS-NROCON = T_ITAB-CONTRATO.
      CONTRATOS-NROINV = T_ITAB-INVNRO.
      COLLECT CONTRATOS.
      DELETE T_ITAB.
    ENDIF.
*
  ENDLOOP.  DESCRIBE TABLE ITAB LINES C_LIN.ENDFORM.
*----------------------------------------------------------------------*
*    END_INVNRO
*----------------------------------------------------------------------*
FORM END_INVNRO.
  PERFORM LT TABLES BDCDAT USING 'BDC_OKCODE' 'VW'.
  BDCDAT-PROGRAM   = 'SAPMM06E'.
  BDCDAT-DYNPRO    = '0124'.
  BDCDAT-DYNBEGIN  = 'X'.
  PERFORM LT TABLES BDCDAT USING 'BDC_OKCODE' 'REFH'.
  CLEAR C_ITEM.
  PERFORM FILL_DYNPRO_111.             "USDRP Tracking Nro.  PERFORM BDC_INSERT TABLES BDCDAT USING 'ME21'.
  REFRESH MAS_DETAIL.
ENDFORM.
*----------------------------------------------------------------------*
*    PRINT_LOG
*----------------------------------------------------------------------*
FORM PRINT_LOG.
  WRITE:/ TEXT-T01.
  WRITE:/ 'Company', PAR_COMP.
  WRITE:/ TEXT-T03.
  WRITE:/ TEXT-T04.
  WRITE:/ TEXT-T05, TEXT-T06.
  ULINE.  LOOP AT REG_ERRORES.
    SELECT SINGLE * FROM EKPO WHERE BEDNR = REG_ERRORES-INVNO
                                AND MATNR = REG_ERRORES-MATERIAL.    WRITE:/ REG_ERRORES-INVNO, '    ',  REG_ERRORES-BRNCOD,
            REG_ERRORES-MATERIAL,REG_ERRORES-SHPDAT, REG_ERRORES-SHPQTY,
                                  REG_ERRORES-SHPTO, REG_ERRORES-TIPERR,
                                  REG_ERRORES-DELIV_DATE NO-ZERO,"LP 06
                                      REG_ERRORES-PO.   " LP 06/02/99  ENDLOOP.  WRITE:/ 'Registros cargados   >',  REG_LOAD.
  WRITE:/ 'Registros leidos     >',  REG_LEIDOS.
  WRITE:/ 'Registros procesados >',  REG_PROCES.  IF REG_PROCES <> 0.
    WRITE:/ 'Batch Input: Name session > PORDE.USDRP'.
  ELSE.
    WRITE:/ 'Batch Input: Session not created'.
  ENDIF.
ENDFORM.
*------------------------------------------------------------*
*       DOWN_LOAD
*------------------------------------------------------------*
FORM DOWN_LOAD.
  DATA:  FILEPC  LIKE RLGRAP-FILENAME VALUE 'd:\data\tabusdrp.txt',
         MODE(5) TYPE C.
*{Begin of PCC22032007
*  CALL FUNCTION 'WS_DOWNLOAD'
*       EXPORTING
*            FILENAME         = FILEPC
*            FILETYPE         = 'ASC'
*            MODE             = MODE
*       TABLES
*            DATA_TAB         = ITAB
*       EXCEPTIONS
*            FILE_OPEN_ERROR  = 01
*            FILE_WRITE_ERROR = 02
*            INVALID_TYPE     = 03
*            UNKNOWN_ERROR    = 04.DATA: W_FILEPC TYPE STRING.MOVE: FILEPC TO W_FILEPC. CALL FUNCTION 'GUI_DOWNLOAD'
   EXPORTING
     FILENAME                        = W_FILEPC
     FILETYPE                        = 'ASC'
   TABLES
     DATA_TAB                        = ITAB
  EXCEPTIONS
    FILE_WRITE_ERROR                = 1
    NO_BATCH                        = 2
    GUI_REFUSE_FILETRANSFER         = 3
    INVALID_TYPE                    = 4
    NO_AUTHORITY                    = 5
    UNKNOWN_ERROR                   = 6
    HEADER_NOT_ALLOWED              = 7
    SEPARATOR_NOT_ALLOWED           = 8
    FILESIZE_NOT_ALLOWED            = 9
    HEADER_TOO_LONG                 = 10
    DP_ERROR_CREATE                 = 11
    DP_ERROR_SEND                   = 12
    DP_ERROR_WRITE                  = 13
    UNKNOWN_DP_ERROR                = 14
    ACCESS_DENIED                   = 15
    DP_OUT_OF_MEMORY                = 16
    DISK_FULL                       = 17
    DP_TIMEOUT                      = 18
    FILE_NOT_FOUND                  = 19
    DATAPROVIDER_EXCEPTION          = 20
    CONTROL_FLUSH_ERROR             = 21
    OTHERS                          = 22. IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
 ENDIF.
*}End of PCC22032007
ENDFORM.
************************************************************************
* Program Name : ZFR01006
* Program Title : Sales Or Purchases Goods And Services Tax Report
* Program Description: Sales Or Purchases Goods And Services Tax Report
* SAP R/3 Module : FA - Finacial Accounting
* Program Type : E - Executable
* Development Type : R - Report
* Development Class : ZFA - Finacial Accounting
* Processing Type : Real time
* Frequency : Month End
* SAP R/3 Release : 4.6C
* Logical Database : BRF - Document Database
* Reference : ZFR0FA5R
* Input : Selection
* Output : ABAP List
* Trigger : Transaction code ZFR1006
* Special Logic : Not available
************************************************************************
* Notes:
* o Every changed ABAP must have a change header as shown below.
* o Every changed source line must be marked with the correction no.
* o Always leave the original & commented out.
*
* Amendment Log
* -------------
************************************************************************
* Umsatzsteuer-Voranmeldung RFUMSV00 *
************************************************************************
REPORT zfr01006
LINE-COUNT 58
LINE-SIZE 155
NO STANDARD PAGE HEADING
MESSAGE-ID f7.
*----------------------------------------------------------------------*
* Tabellen *
*----------------------------------------------------------------------*
TABLES:
bhdgd, "Batch-Heading
bkpf, "Belegkopf
bsec, "Belegsegment CPD-Daten
bseg, "Belegsegment Buchhaltung
bset, "Belegsteuerdaten
kna1, "Anschriftsdaten Kreditoren
konp, "Konditionen (Position)
lfa1, "Anschriftsdaten Debitoren
rfdt, "für 4.0-Umsetzung
ska1, "Sachkontenstamm
skat, "Sachkontenstamm
t001, "Buchungskreise
t001r, "Rundungsregeln pro Bukrs,Währung
t001z, "weitere Buchungskreisangaben
t005, "Land des Buchungskreises
t007a, "Steuerart des Umsatzsteuerkennz.
t007b, "Vorgangsschlüssel Umsatzsteuer
t007f, "Umsatzsteuerkreise
t007k, "Gruppierung für Druck
t007s, "Bezeichnung Steuerkennzeichen
t030, "Fixkontentabelle
t030b, "Fixbuchungsschlüssel
t685a, "Reisekosten?
ttxd, "nie Bukrs mit Jurisdictionscode
umsv, "Aufnahme von Bukrs-Steuersalden
" für Formulardruck
umsvz. "Zeitraum der Umsatzsteuer-
" Voranmeldung für Formulardruck
*----------------------------------------------------------------------*
* Selektionsparameter *
*----------------------------------------------------------------------*
*begin_of_block 1.
SELECT-OPTIONS:
sel_ukrs FOR t007f-umkrs NO-DISPLAY, "Tax on sales/purchase group
sel_mona FOR bkpf-monat NO-DISPLAY, "Fiscal period
sel_cpud FOR bkpf-cpudt NO-DISPLAY, "CPU Date
sel_bldt FOR bkpf-bldat, "Document Date
sel_mwkz FOR bset-mwskz NO-DISPLAY. "Tax on sales/purchase group
PARAMETERS:
par_xsau LIKE rfpdo1-umsvxart NO-DISPLAY, "Select output TAX
par_xsvo LIKE rfpdo1-umsvxart NO-DISPLAY. "Select input TAX
*SELECTION-SCREEN:
* SKIP,
* BEGIN OF LINE,
* COMMENT 01(50) TEXT-006 FOR FIELD PAR_TMDT,
* END OF LINE.
PARAMETERS:
par_tmdt LIKE bset-stmdt NO-DISPLAY, "date of TAX report
par_tmti LIKE bset-stmti NO-DISPLAY. "Time of TAX report
*end_of_block 1.
*BEGIN_OF_BLOCK 2.
PARAMETERS:
par_sort LIKE rfpdo-umsvsort NO-DISPLAY, "Sorting
par_xfwi LIKE rfpdo-umsvxfwi NO-DISPLAY, "Display foreign currency
par_xaus LIKE rfpdo-umsvxaus NO-DISPLAY, "Output tax line item
par_xvor LIKE rfpdo-umsvxvor NO-DISPLAY, "Input tax line item
par_xstk LIKE rfpdo2-umsvxstk NO-DISPLAY. "Tax control
SELECTION-SCREEN:
BEGIN OF LINE.
PARAMETERS:
par_xadr LIKE rfpdo-umsvxadr NO-DISPLAY. "Print address data
*ELECTION-SCREEN:
* COMMENT 03(28) TEXT-003 FOR FIELD PAR_XADR.
*ELECTION-SCREEN:
* COMMENT POS_LOW(17) TEXT-004 FOR FIELD PAR_STCD.
PARAMETERS:
par_stcd LIKE rfpdo1-umsvstcd NO-DISPLAY. "With tax code
SELECTION-SCREEN:
END OF LINE.
PARAMETERS:
par_xsht LIKE rfpdo-umsvxsht NO-DISPLAY, "Total by debit/credit
par_nava LIKE rfpdo2-umsvnava NO-DISPLAY, "Incr.bse amt by non-ded.inp.t
par_lsep LIKE rfpdo-allglsep NO-DISPLAY, "Separate list
par_mikf LIKE rfpdo-allgmikf NO-DISPLAY, "Print microfiche line
par_line LIKE rfpdo1-allgline NO-DISPLAY. "Additional title
*ELECTION-SCREEN:
* SKIP.
PARAMETERS:
par_umsv LIKE rfpdo1-umsvumsv NO-DISPLAY, "Prepare printing of forms
par_laud LIKE umsv-laufd NO-DISPLAY, "Program run date
par_laui LIKE umsv-laufi NO-DISPLAY. "Additional run ID
*END_OF_BLOCK 2. " des Reports
*BEGIN_OF_BLOCK 3.
PARAMETERS:
par_binp LIKE rfpdo-allgbinp NO-DISPLAY, "Create batch input session
par_blar LIKE rfpdo-allgblar NO-DISPLAY, "Postings document type
par_bdat LIKE rfpdo-allgbdat NO-DISPLAY, "Posting date
par_zkto LIKE rfpdo1-umsvzkto NO-DISPLAY,"Alternative tax payable acct
par_fdat LIKE rfpdo-allgfdat NO-DISPLAY , "Due date of the tax payable
"
par_bina LIKE rfpdo-allgbina NO-DISPLAY, "Batch input session name
par_sofa LIKE rfipi-bdcimmed NO-DISPLAY, "Process session immediately
par_adat LIKE tbtcjob-sdlstrtdt NO-DISPLAY, "Date for processing
par_zeit LIKE tbtcjob-sdlstrttm NO-DISPLAY. "Time for processing
*ELECTION-SCREEN:
* SKIP.
PARAMETERS:
par_bsud LIKE rfpdo2-umsvbsud NO-DISPLAY. "Update tax item date/time
*ND_OF_BLOCK 3.
* { Insert of SYDK948386 1
SELECTION-SCREEN BEGIN OF BLOCK tax WITH FRAME TITLE text-tax.
SELECTION-SCREEN PUSHBUTTON 25(30) text-mtx USER-COMMAND mtax.
SELECTION-SCREEN END OF BLOCK tax.
*} Insert
*----------------------------------------------------------------------*
* Interne Tabellen (TAB) *
*----------------------------------------------------------------------*
DATA:
* Auszug aus der Buchungskreistabelle
BEGIN OF tab_001 OCCURS 5,
bukrs LIKE t001-bukrs, "Buchungskreis
land1 LIKE t001-land1, "Land
waers LIKE t001-waers, "Hauswährung
kalsm LIKE t005-kalsm, "Kalkulationsschema (aus T005)
END OF tab_001,
* Umsatzsteuertabelle
BEGIN OF tab_007a OCCURS 15.
        INCLUDE STRUCTURE t007a.
DATA: text1 LIKE t007s-text1,
END OF tab_007a,
* Vorgangsschlüsseltabelle
BEGIN OF tab_007b OCCURS 5.
        INCLUDE STRUCTURE t007b.
DATA: END OF tab_007b,
********************************
* CTS SYDK9A0AKG.
*MOD-002
********************************
BEGIN OF tab_bseg OCCURS 0.
        INCLUDE STRUCTURE bseg.
DATA: END OF tab_bseg,
********************************
*MOD-002
********************************
********************************
* CTS SYDK9A0AKG.
*MOD-002
********************************
BEGIN OF tab_bset OCCURS 0.
        INCLUDE STRUCTURE bset.
DATA: END OF tab_bset,
********************************
*MOD-002
********************************
* Auszug aus der Konditionentabelle (Position)
BEGIN OF tab_konp OCCURS 15,
knumh LIKE konp-knumh, "Konditionssatznummer
kbetr LIKE konp-kbetr, "Prozentsatz
END OF tab_konp,
* Auszug aus der Debitoren-/Kreditorendatei für die Anschriftsdaten
BEGIN OF tab_adrs OCCURS 100,
koart LIKE bseg-koart, "Kontoart
ktnra LIKE bseg-lifnr, "Kontonummer Debitor/Kreditor
nummr(20) TYPE c, "Nummer gemäß PAR_STCD
name1 LIKE lfa1-name1, "Name
plort(46) TYPE c, "Postleitzahl
END OF tab_adrs,
* Tabelle mit Einzelposten-Informationen je Beleg
BEGIN OF tab_ep OCCURS 5,
txgrp LIKE bset-txgrp, "Gruppenkennzeichen
mwskz LIKE bset-mwskz, "Umsatzsteuerkennzeichen
ktosl LIKE bset-ktosl, "Vorgangsschlüssel
kschl LIKE bset-kschl, "Konditionsart
mwart LIKE t007a-mwart, "Umsatzsteuerart (A/V)
stgrp LIKE t007b-stgrp, "Art der Steuer (1/2/3)
stazf LIKE t007b-stazf, "nicht abzugsfähig
kbetr LIKE konp-kbetr, "Prozentsatz
shkzg LIKE bset-shkzg, "Soll-Haben-Kennzeichen
hkont LIKE bset-hkont, "Hauptbuchkonto
buzei LIKE bset-buzei, "Nummer der Buchungszeile
hwbas(8) TYPE p, "Steuerbasisbetrag in Hausw.
fwbas(8) TYPE p, "Steuerbasisbetrag in Belegw.
hwste(8) TYPE p, "Steuerbetrag in Hausw.
fwste(8) TYPE p, "Steuerbetrag in Fremdw.
hwnaf(8) TYPE p, "nicht abzugsf. Steuer Hausw.
fwnaf(8) TYPE p, "nicht abzugsf. Steuer Belegw.
sdiff(8) TYPE p, "Steuerkontrolle in Hausw.
END OF tab_ep,
* Tabelle für BSET-Update mit Zeilen, die aus TAB_EP gelöscht werden
BEGIN OF tab_bset_key OCCURS 50,
bukrs LIKE bset-bukrs,
belnr LIKE bset-belnr,
gjahr LIKE bset-gjahr,
buzei LIKE bset-buzei,
END OF tab_bset_key,
* Tabelle für das Summenblatt Vorsteuer/Ausgangssteuer
BEGIN OF tab_mwart OCCURS 5,
mwart LIKE t007a-mwart, "Umsatzsteuerart
mwskz LIKE bset-mwskz, "Umsatzsteuerkennzeichen
ktosl LIKE bset-ktosl, "Vorgangsschlüssel
waers LIKE bkpf-waers, "Währungsschlüssel
psatz(7) TYPE c, "Prozentsatz
shkzg LIKE bset-shkzg, "Soll-Haben-Kennzeichen
hwbas(8) TYPE p, "Steuerbasisbetrag in Hausw.
fwbas(8) TYPE p, "Steuerbasisbetrag in Belegw.
hwste(8) TYPE p, "Steuerbetrag in Hausw.
fwste(8) TYPE p, "Steuerbetrag in Fremdw.
hwnaf(8) TYPE p, "nicht abzugsf. Steuer Hausw.
fwnaf(8) TYPE p, "nicht abzugsf. Steuer Belegw.
END OF tab_mwart,
* Abschlußinformation für das Summenblatt Vorsteuer/Ausgangssteuer
BEGIN OF tab_mwart_sum OCCURS 5,
ktosl LIKE bset-ktosl, "Vorgangsschlüssel
hwbas(8) TYPE p, "Steuerbasisbetrag in Hausw.
fwbas(8) TYPE p, "Steuerbasisbetrag in Belegw.
hwste(8) TYPE p, "Steuerbetrag in Hausw.
fwste(8) TYPE p, "Steuerbetrag in Fremdw.
hwnaf(8) TYPE p, "nicht abzugsf. Steuer Hausw.
fwnaf(8) TYPE p, "nicht abzugsf. Steuer Belegw.
END OF tab_mwart_sum,
* Tabelle für das Summenblatt Steuersaldo je Buchungskreis
BEGIN OF tab_bukrs OCCURS 5,
mwskz LIKE bset-mwskz, "Umsatzsteuerkennzeichen
ktosl LIKE bset-ktosl, "Vorgangsschlüssel
waers LIKE bkpf-waers, "Währungsschlüssel
psatz(7) TYPE c, "Prozentsatz
shkzg LIKE bset-shkzg, "Soll-Haben-Kennzeichen
hwbas(8) TYPE p, "Steuerbasisbetrag in Hausw.
fwbas(8) TYPE p, "Steuerbasisbetrag in Belegw.
hwaus(8) TYPE p, "abzuführ. Ausg.st. in Hausw.
fwaus(8) TYPE p, "abzuführ. Ausg.st. in Fremdw.
hwvor(8) TYPE p, "abzugsf. Vorsteuer in Hausw.
fwvor(8) TYPE p, "abzugsf. Vorsteuer in Belegw.
sdiff(8) TYPE p, "Steuerkontrolle in Hausw.
END OF tab_bukrs,
* Abschlußinformation für das Summenblatt Steuersaldo je Buchungskreis
BEGIN OF tab_bukrs_sum OCCURS 5,
ktosl LIKE bset-ktosl, "Vorgangsschlüssel
hwbas(8) TYPE p, "Steuerbasisbetrag in Hausw.
fwbas(8) TYPE p, "Steuerbasisbetrag in Belegw.
hwaus(8) TYPE p, "abzuführ. Ausg.st. in Hausw.
fwaus(8) TYPE p, "abzuführ. Ausg.st. in Fremdw.
hwvor(8) TYPE p, "abzugsf. Vorsteuer in Hausw.
fwvor(8) TYPE p, "abzugsf. Vorsteuer in Belegw.
sdiff(8) TYPE p, "Steuerkontrolle in Hausw.
END OF tab_bukrs_sum,
* Tabelle für das Summenblatt Mandant,
* aufgeteilt nach Hauswährungen und Umsatzsteuerkennzeichen
BEGIN OF tab_hwaer_mwskz OCCURS 5,
hwaer LIKE t001-waers, "Hauswährung
mwskz LIKE bset-mwskz, "Umsatzsteuerkennzeichen
ktosl LIKE bset-ktosl, "Vorgangsschlüssel
psatz(7) TYPE c, "Prozentsatz
shkzg LIKE bset-shkzg, "Soll-Haben-Kennzeichen
hwbas(8) TYPE p, "Steuerbasisbetrag in Hausw.
hwaus(8) TYPE p, "abzuführ. Ausg.st. in Hausw.
hwvor(8) TYPE p, "abzugsf. Vorsteuer in Hausw.
END OF tab_hwaer_mwskz,
* Tabelle für das Summenblatt Mandant, aufgeteilt nach Hauswährungen
BEGIN OF tab_hwaer OCCURS 5,
hwaer LIKE t001-waers, "Hauswährung
bukrs LIKE t001-bukrs, "Buchungskreis
mwskz LIKE bset-mwskz, "Umsatzsteuerkennzeichen
ktosl LIKE bset-ktosl, "Vorgangsschlüssel
psatz(7) TYPE c, "Prozentsatz
shkzg LIKE bset-shkzg, "Soll-Haben-Kennzeichen
hwbas(8) TYPE p, "Steuerbasisbetrag in Hausw.
hwaus(8) TYPE p, "abzuführ. Ausg.st. in Hausw.
hwvor(8) TYPE p, "abzugsf. Vorsteuer in Hausw.
sdiff(8) TYPE p, "Steuerkontrolle in Hausw.
END OF tab_hwaer,
* Abschlußinfo für das Summenblatt Mandant, aufgeteilt nach Hauswährg
BEGIN OF tab_hwaer_sum OCCURS 5,
hwaer LIKE t001-waers, "Hauswährung
summe(1) TYPE n, "1 - Info über mehrer Buchungskr
bukrs LIKE t001-bukrs, "Buchungskreis
ktosl LIKE bset-ktosl, "Vorgangsschlüssel
hwbas(8) TYPE p, "Steuerbasisbetrag in Hausw.
hwaus(8) TYPE p, "abzuführ. Ausg.st. in Hausw.
hwvor(8) TYPE p, "abzugsf. Vorsteuer in Hausw.
sdiff(8) TYPE p, "Steuerkontrolle in Hausw.
END OF tab_hwaer_sum,
* Tabelle für die Batch-Input-Daten (<Z>ahl<L>ast <BU>chen)
BEGIN OF tab_zlbu OCCURS 85.
        INCLUDE STRUCTURE ftpost.
DATA: END OF tab_zlbu,
* Tabelle für die Zahllastbeleg-Nummern
BEGIN OF tab_bln OCCURS 1.
        INCLUDE STRUCTURE blntab.
DATA: END OF tab_bln,
* Tabelle für Steuern für interne Buchungsschnittstelle
BEGIN OF tab_fttax OCCURS 1.
        INCLUDE STRUCTURE fttax.
DATA: END OF tab_fttax,
* Tabelle für die Zahllastsalden für Batch-Input
BEGIN OF tab_bi OCCURS 5,
bukrs LIKE bkpf-bukrs,
hkont LIKE bset-hkont,
saldo LIKE tab_hwaer-hwvor,
END OF tab_bi,
* Tabelle für die Steuersalden pro Buchungskreis,
* Umsatzsteuerkennzeichen und Vorgangsschlüssel
BEGIN OF tab_umsv OCCURS 200.
        INCLUDE STRUCTURE umsv.
DATA: END OF tab_umsv,
* Tabelle von Umsatzsteuerkreisen mit zugehörigen Buchungskreisen
BEGIN OF tab_sel_bukrs OCCURS 30,
umkrs LIKE t001-umkrs, "Umsatzsteuerkreis
bukrs LIKE t001-bukrs, "Buchungskreis
END OF tab_sel_bukrs,
* Tabelle für die Steuerkontrolle:
* Zulässiger Rundungsfehler pro Steuerkennzeichen in einem Beleg
* (hängt auch von der Anzahl der Zeilen im Beleg mit diesem Stkz. ab)
BEGIN OF tab_diff OCCURS 10,
mwskz LIKE bset-mwskz, "Steuerkennzeichen
rndbl(8) TYPE p, "zul. Rundgsfehler (Belegzeilen)
rndst(8) TYPE p, "zul. Rundgsfehler (Steuerzeilen)
END OF tab_diff,
* Rundungsregeln pro Buchungskreis und Währung
BEGIN OF tab_001r OCCURS 50.
        INCLUDE STRUCTURE t001r.
DATA: END OF tab_001r,
* Steuersatz und Steuerbetrag für ein Steuerkennzeichen
BEGIN OF tab_rtax1u15 OCCURS 10.
        INCLUDE STRUCTURE rtax1u15.
DATA: END OF tab_rtax1u15,
* Memory für die aus TAB_RTAX1U15 ermittelten Prozentsätze
BEGIN OF tab_rtax OCCURS 50,
mwskz LIKE bset-mwskz,
ktosl LIKE bset-ktosl,
wmwst(8) TYPE p,
msatz(4) TYPE p,
END OF tab_rtax.
* Tabelle mit Buchungskreisen, aus denen Belege zu 4.0 umgesetzt wurden
*INCLUDE FIUUMS40.
DATA: BEGIN OF ums40 OCCURS 10,
bukrs LIKE bkpf-bukrs,
END OF ums40.
*----------------------------------------------------------------------*
* Feldleisten *
*----------------------------------------------------------------------*
DATA:
* Feldleiste mit Einzelposten-Informationen
BEGIN OF ep,
bukrs LIKE bkpf-bukrs, "Buchungskreis
mwart LIKE t007a-mwart, "Umsatzsteuerart
mwskz LIKE bset-mwskz, "Umsatzsteuerkennzeichen
ktosl LIKE bset-ktosl, "Vorgangsschlüssel
buper(6) TYPE n, "Buchungsperiode
waers LIKE bkpf-waers, "Währungsschlüssel
budat LIKE bkpf-budat, "Buchungsdatum
gjahr LIKE bsec-gjahr, "Geschäftsjahr
belnr LIKE bkpf-belnr, "Belegnummer
buzei LIKE bsec-buzei, "Buchungszeile
xblnr LIKE bkpf-xblnr, "Referenz-Belegnummer
qunum(13) TYPE c, "Quittungsnummer (Sortierung 4)
qutyp(4) TYPE c, "Quittungstyp (Sortierung 4)
qudat(10) TYPE c, "Quittungsdatum (Sortierung 4)
psatz(7) TYPE c, "Prozentsatz
koart LIKE bseg-koart, "Kontoart
ktnra LIKE bseg-kunnr, "Kontonummer Debitor/Kreditor
xcpdk LIKE kna1-xcpdk, "CPD-Konto
shkzg LIKE bset-shkzg, "Soll-Haben-Kennzeichen
hwbas(8) TYPE p, "Steuerbasisbetrag in Hausw.
fwbas(8) TYPE p, "Steuerbasisbetrag in Belegw.
hwste(8) TYPE p, "Steuerbetrag in Hausw.
fwste(8) TYPE p, "Steuerbetrag in Fremdw.
hwnaf(8) TYPE p, "nicht abzugsf. Steuer Hausw.
fwnaf(8) TYPE p, "nicht abzugsf. Steuer Belegw.
sdiff(8) TYPE p, "Steuerkontrolle in Hausw.
END OF ep,
* Feldleiste mit Saldo-Informationen
BEGIN OF saldo,
hwaus(8) TYPE p, "abzuführ. Ausg.st. in Hausw.
fwaus(8) TYPE p, "abzuführ. Ausg.st. in Fremdw.
hwvor(8) TYPE p, "abzugsf. Vorsteuer in Hausw.
fwvor(8) TYPE p, "abzugsf. Vorsteuer in Belegw.
END OF saldo,
* Feldleiste zur Aufnahme des variablen Teils der Mikrofiche-Zeile
BEGIN OF mikline,
bukrs LIKE bkpf-bukrs, "Buchungskreis
mwart LIKE t007a-mwart, "Umsatzsteuerart
mwskz LIKE bset-mwskz, "Umsatzsteuerkennzeichen
ktosl LIKE bset-ktosl, "Vorgangsschlüssel
belnr LIKE bset-belnr, "Belegnummer
END OF mikline,
* Feldleiste für Übergabe des selektierten Zeitraums an Druckreport
BEGIN OF fle_umsvz OCCURS 1.
        INCLUDE STRUCTURE umsvz.
DATA: END OF fle_umsvz.
DATA:
BEGIN OF intab OCCURS 0,
bukrs LIKE bkpf-bukrs, "Company code
mwart LIKE t007a-mwart, "Tax type
mwskz LIKE bset-mwskz, "Tax code
ktosl LIKE bset-ktosl, "Internal processing key
buper(6) TYPE n, "
waers LIKE bkpf-waers, "Currency
budat LIKE bkpf-budat, "Posting date in the document
gjahr LIKE bsec-gjahr, "Fiscal year
belnr LIKE bkpf-belnr, "Document number
buzei LIKE bsec-buzei, "Line item number
xblnr LIKE bkpf-xblnr, "Reference number
qunum(13) TYPE c, "
qutyp(4) TYPE c, "
qudat(10) TYPE c, "
psatz(7) TYPE c, "
koart LIKE bseg-koart, "Account type
ktnra LIKE bseg-kunnr, "Customer number
xcpdk LIKE kna1-xcpdk, "One time customer
shkzg LIKE bset-shkzg, "
hwbas LIKE bset-hwbas, "Tax base amount in local currency
fwbas LIKE bset-hwbas, "Tax base amount in document currency
hwste LIKE bset-hwste, "Tax amount in local currency
fwste LIKE bset-fwste, "Tax amount in document currency
hwnaf(8) TYPE p, "
fwnaf(8) TYPE p, "
sdiff(8) TYPE p, "
END OF intab.
DATA: BEGIN OF itab OCCURS 0,
bukrs LIKE bkpf-bukrs, "Company code
flag(1) TYPE c, "Indicator flag "SYDK919000
mwskz LIKE bset-mwskz, "Tax code
kunnr LIKE bseg-kunnr, "Customer/ Vendor
belnr LIKE bkpf-belnr, "Document number
budat LIKE bkpf-budat, "Posting date in the document
xblnr LIKE bkpf-xblnr, "Reference number
bldat LIKE bkpf-bldat, "Document date
gjahr LIKE bsec-gjahr, "Fiscal year
kalsm LIKE t005-kalsm, "Procedure
hwbas LIKE bset-hwbas, "Tax base amount in local currency
fwbas LIKE bset-hwbas, "Tax base amount in document currency
hwste LIKE bset-hwste, "Tax amount in local currency
fwste LIKE bset-fwste, "Tax amount in document currency
END OF itab.
*----------------------------------------------------------------------*
* Felder *
*----------------------------------------------------------------------*
DATA:
* Druckzeilen, Überschriften
txt_betrag(20) TYPE c, "aufbereiteter Betrag
txt_buper(7) TYPE c, "aufbereitete Periode
txt_datum(10) TYPE c, "aufbereitetes Datum
txt_uzeit(8) TYPE c, "aufbereitete Uhrzeit
txt_zeile1(132) TYPE c, "Überschriftszeile 1
txt_zeile2(132) TYPE c, "Überschriftszeile 2
txt_zeile3(132) TYPE c, "Überschriftszeile 3
txt_zeile4(132) TYPE c, "Druckzeile
* Zähler
cnt_updatecalls TYPE i VALUE 0, "Anzahl Update-Befehle
cnt_bukrs_pro_hwaer TYPE i VALUE 0, "Anzahl Bu.kreise pro Hauswährg.
cnt_lines TYPE i VALUE 0, "Anzahl Zeilen einer Tabelle
cnt_liste TYPE i, "Nummer der Ausgabeliste
* Schalter, Flags, Anzeiger
flg_asnaf(1) TYPE n VALUE 0, "n.abzugsf. bei Ausgangssteuer?
flg_persel(1) TYPE n VALUE 0, "Zeitraum abgegrenzt?
flg_einzlg(1) TYPE n, "Einzeilige Liste?
flg_uline(1) TYPE n, "Zuletzt ULINE ausgegeben?
flg_even(1) TYPE n, "Listeneintrag mit gerader Nr.?
flg_modify(1) TYPE n, "wurde n.abzugsf. zugeordnet?
flg_msg240(1) TYPE n VALUE 0, "Message 240 schon ausgegeben?
flg_neuuk(1) TYPE n VALUE 0, "Neuer Umsatzsteuerkreis?
flg_umkrs(1) TYPE n VALUE 0, "Abgrenzung von USt-Kreisen?
flg_vsnaf(1) TYPE n VALUE 0, "n.abzugsf. bei Vorsteuer?
* sonstige Hilfsfelder
hlp_colno LIKE sy-colno, "Hilfe für Aufruf POPUP_NO_LIST
hlp_fwbas(8) TYPE p, "Hilfe für Erwerbsteuerkorrektur
hlp_fwnaf LIKE bset-fwste, "Hilfe beim Zuordnen n.abzugf.
hlp_fwsld(8) TYPE p, "Steuersaldo in Belegw.
hlp_hwbas(8) TYPE p, "Hilfe für Erwerbsteuerkorrektur
hlp_hwnaf LIKE bset-hwste, "Hilfe beim Zuordnen n.abzugf.
hlp_hwnet LIKE bseg-wrbtr, "Hilfe HW-Netto bei FBS-Aufruf
hlp_hwsld(8) TYPE p, "Steuersaldo in Hausw.
hlp_hwste(8) TYPE p, "Hilfe für Erwerbsteuerkorrektur
hlp_hwste2 LIKE bset-fwste, "Hilfe HW-Steuer bei FBS-Aufruf
hlp_kbetr LIKE konp-kbetr, "Hilfe für Erwerbsteuerkorrektur
hlp_lfdnr(13) TYPE n, "lfd. Nummer, Konvertierungshilfe
hlp_lnlen TYPE i, "Länge der Druckzeile
hlp_lstbr TYPE i, "Breite der Liste
hlp_psatz(7) TYPE c, "Hilfe für Erwerbsteuerkorrektur
hlp_sdiff(8) TYPE p, "Hilfe für Steuerkontrolle
hlp_shkzg LIKE bset-shkzg, "Hilfe beim Zuordnen n.abzugf.
hlp_sort(20) TYPE c, "Hilfe beim Sortieren
hlp_stmdt LIKE bset-stmdt, "Laufdatum der Steuermeldung
hlp_stmti LIKE bset-stmti, "Uhrzeit der Steuermeldung
hlp_topbr TYPE i, "Breite des TOP-OF-PAGE-Textes
hlp_txgrp LIKE bset-txgrp, "Hilfe beim n.abzugsf./Erwerbst.
hlp_vline_space(2) TYPE c, "Hilfe bei Textprüfung
hlp_waers(6) TYPE c, "Währungsschlüssel rechtsbündig
* Variablen für Batch-Input
bi_belegpos LIKE ftpost-count, "Zähler für Pos. in Beleg
bi_summe(16) TYPE c, "Steuersaldo als Typ C
bi_datum(10) TYPE c, "Datum in Form DD/MM/YYYY
bi_sign(1) TYPE c, "Vorzeichen
xt007s-text1 LIKE t007s-text1,
w-name1 LIKE kna1-name1,
w-kalsm LIKE itab-kalsm,
v_mtcm(1) TYPE c,
w-kunnr LIKE bseg-kunnr,
w-flag(1) TYPE c,
w-mwskz LIKE bset-mwskz, "Total
ws-mwskz LIKE bset-mwskz, "Total
w-total LIKE bset-hwbas, "Total
w-vtotal LIKE bset-hwbas, "Vendor total
w-ttotal LIKE bset-hwbas, "Tax total
w-stotal LIKE bset-hwbas, "Sales total
w-gtotal LIKE bset-hwbas. "Grand total
* { Insert of SYDK948386 2
DATA df_ukurs LIKE zfr01006-ukurs. " SGD Exchange rate
DATA w_ukurs LIKE zfr01006-ukurs. " SGD Exchange rate DATA
*}Insert
*----------------------------------------------------------------------*
* Field-Groups *
*----------------------------------------------------------------------*
FIELD-GROUPS:
header,
daten.
INSERT
ep-bukrs "Buchungskreis
ep-mwart "Umsatzsteuerart
ep-mwskz "Umsatzsteuerkennzeichen
ep-ktosl "Vorgangsschlüssel
ep-buper "Buchungsperiode
ep-waers "Währungsschlüssel
ep-budat "Buchungsdatum
ep-belnr "Belegnummer
hlp_sort "Hilfsfeld für die Sortierung
INTO header.
INSERT ep INTO daten.
*----------------------------------------------------------------------*
* Vorbelegung im Selektionsdynpro *
*----------------------------------------------------------------------*
INITIALIZATION.
* GET_FRAME_TITLE: 1, 2, 3. "Rahmentexte füllen
* get_frame_title: 1. "Rahmentexte füllen
  par_xsau = 'X'.
  par_xsvo = 'X'.
  par_xaus = 'X'.
  par_xvor = 'X'.
  par_bina = sy-repid.
  par_sort = 1.
  CLEAR hlp_vline_space.
  hlp_vline_space+0(1) = sy-vline.
  auth_buk = 'X'. "<--- 3.1H
*----------------------------------------------------------------------*
* Prüfung der Eingaben im Selektionsdynpro *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON par_sort.
  IF NOT par_sort BETWEEN 1 AND 4.
    MESSAGE e115 WITH '4'.
  ENDIF.

AT SELECTION-SCREEN ON par_stcd.
  IF par_stcd NE 0 AND par_stcd NE 1 AND par_stcd NE 2.
    MESSAGE e115 WITH '2'.
  ENDIF.

AT SELECTION-SCREEN.
* { Insert of SYDK948386 3
  IF syst-ucomm EQ 'MTAX'.
    CALL TRANSACTION 'ZFR1006_SGD_EXC_RATE'.
  ENDIF.
*}Insert
  IF sel_mona-low <> 0 OR sel_mona-high <> 0.
    IF br_gjahr-low = 0 AND br_gjahr-high = 0.
      SET CURSOR FIELD 'BR_GJAHR-LOW'.
      MESSAGE e246.
    ENDIF.
  ENDIF.
  IF sel_mona-low EQ 0 AND sel_mona-high EQ 0
  AND sel_bldt-low = 0 AND sel_bldt-high = 0
  AND br_budat-low EQ 0 AND br_budat-high EQ 0
  AND par_tmdt = 0 AND par_tmti = 0.
    MESSAGE e241.
  ELSEIF par_bsud = space AND par_tmdt = 0 AND par_tmti = 0
  AND flg_msg240 = 0 AND ( sel_bldt-low <> 0 OR sel_bldt-high <> 0 ).
    flg_msg240 = 1.
    MESSAGE w240.
  ENDIF.
  IF par_bsud = 'X'.
    IF par_tmdt <> 0 OR par_tmti <> 0.
      MESSAGE e245.
    ENDIF.
  ELSEIF par_tmdt <> 0.
    IF par_tmti = 0.
      SET CURSOR FIELD 'PAR_TMTI'.
      MESSAGE e244.
    ENDIF.
  ELSEIF par_tmti <> 0.
    SET CURSOR FIELD 'PAR_TMDT'.
    MESSAGE e243.
  ENDIF.
  IF ( sel_ukrs-low <> space OR sel_ukrs-high <> space )
  AND ( br_bukrs-low <> space OR br_bukrs-high <> space ).
    MESSAGE e236.
  ENDIF.
  IF par_binp = 'X'.
    IF par_blar = space. "Belegart für Buchen der
      SET CURSOR FIELD 'PAR_BLAR'. " Zahllast über Batch-Input
      MESSAGE e205.
    ENDIF.
    IF par_bdat = 0. "Buchungsdatum für Buchen der
      SET CURSOR FIELD 'PAR_BDAT'. " Zahllast über Batch-Input
      MESSAGE e203.
    ENDIF.
    IF par_fdat = 0. "Fälligkeitsdatum für Abführen
      SET CURSOR FIELD 'PAR_FDAT'. " der Zahllast an das Finanzamt
      MESSAGE e204.
    ENDIF.
    IF par_bina = space. "Name der Batch-Input-Mappe
      SET CURSOR FIELD 'PAR_BINA'.
      MESSAGE e206.
    ENDIF.
    IF par_adat <> 0. "Datum für Abspielen der Mappe
      CLEAR par_sofa.
      IF par_zeit = 0. "Uhrzeit für Abspielen der Mappe
        SET CURSOR FIELD 'PAR_ZEIT'.
        MESSAGE e222.
      ENDIF.
    ELSEIF par_zeit <> 0. "Uhrzeit für Abspielen der Mappe
      CLEAR par_sofa.
      SET CURSOR FIELD 'PAR_ADAT'.
      MESSAGE e221.
    ENDIF.
  ENDIF.
* Wurden Umsatzsteuerkreise abgegrenzt?
  DESCRIBE TABLE sel_ukrs LINES cnt_lines.
  IF cnt_lines > 0.
    flg_umkrs = 1.
  ELSE.
    flg_umkrs = 0.
  ENDIF.
  IF flg_umkrs = 1.
* Es wurden Umsatzsteuerkreise abgegrenzt.
* Existenz zugehöriger Buchungskreise prüfen.
* Keine Buchungskreise mit Jurisdictionscode.
* Ggf. Existenz des angegebenen Zahllastkontos prüfen.
    SELECT * FROM t007f
    WHERE umkrs IN sel_ukrs.
      SELECT * FROM t001
      WHERE umkrs = t007f-umkrs.
        SELECT SINGLE * FROM t005 WHERE land1 EQ t001-land1.
        IF sy-subrc NE 0.
          MESSAGE e223 WITH t001-land1.
        ELSE.
          SELECT SINGLE * FROM ttxd WHERE kalsm EQ t005-kalsm.
          IF sy-subrc EQ 0.
            MESSAGE e229.
          ENDIF.
        ENDIF.
        IF par_binp = 'X' AND par_zkto <> space.
          SELECT SINGLE * FROM ska1
          WHERE ktopl = t001-ktopl
          AND saknr = par_zkto.
          IF sy-subrc <> 0.
            MESSAGE e238 WITH t001-ktopl t001-bukrs par_zkto.
          ENDIF.
        ENDIF.
      ENDSELECT.
      IF sy-subrc <> 0.
        SET CURSOR FIELD 'SEL_UKRS-LOW'.
        MESSAGE e405(fr) WITH t007f-umkrs.
        EXIT.
      ENDIF.
    ENDSELECT.
    IF sy-subrc <> 0.
      SET CURSOR FIELD 'SEL_UKRS-LOW'.
      MESSAGE e217.
    ENDIF.
  ELSE.
* Es wurden Buchungskreise abgegrenzt.
* Keine Buchungskreise mit Jurisdictionscode.
* Ggf. Existenz des angegebenen Zahllastkontos prüfen.
    CALL FUNCTION 'BUKRS_AUTHORITY_CHECK' "<--- 31H
    EXPORTING xdatabase = 'B' "<--- 31H
    TABLES xbukreis = br_bukrs. "<--- 31H
    SELECT * FROM t001
    WHERE bukrs IN br_bukrs.
      SELECT SINGLE * FROM t005 WHERE land1 EQ t001-land1.
      IF sy-subrc NE 0.
        MESSAGE e223 WITH t001-land1.
      ELSE.
        SELECT SINGLE * FROM ttxd WHERE kalsm EQ t005-kalsm.
        IF sy-subrc EQ 0.
          MESSAGE e229.
        ENDIF.
      ENDIF.
      IF par_binp = 'X' AND par_zkto <> space.
        SELECT SINGLE * FROM ska1
        WHERE ktopl = t001-ktopl
        AND saknr = par_zkto.
        IF sy-subrc <> 0.
          MESSAGE e238 WITH t001-ktopl t001-bukrs par_zkto.
        ENDIF.
      ENDIF.
    ENDSELECT.
  ENDIF.
  IF par_umsv = 'X'.
    IF sel_mona-low = 0 AND sel_mona-high = 0
    AND sel_bldt-low = 0 AND sel_bldt-high = 0
    AND br_budat-low = 0 AND br_budat-high = 0.
      MESSAGE e242.
    ENDIF.
    IF par_laud = 0. "Laufdatum des Reports
      SET CURSOR FIELD 'PAR_LAUD'.
      MESSAGE e208.
    ENDIF.
    IF par_laui = space. "Zusätzl. Laufidentifikation
      SET CURSOR FIELD 'PAR_LAUI'.
      MESSAGE e209.
    ENDIF.
* Prüfe, ob gewählte Werte bereits vergeben sind
    IF par_laud <> space AND par_laui <> space.
      SELECT SINGLE * FROM umsvz
      WHERE laufd = par_laud AND laufi = par_laui.
      IF sy-subrc = 0.
        SET CURSOR FIELD 'PAR_LAUI'.
        MESSAGE e210.
      ENDIF.
    ENDIF.
  ENDIF.
*----------------------------------------------------------------------*
* F4-Hilfe für den Lauf *
*----------------------------------------------------------------------*
*AT SELECTION-SCREEN ON VALUE-REQUEST FOR PAR_LAUD.
* PERFORM F4_LAUF(RFUVDE00) USING 'D' PAR_LAUD PAR_LAUI.
*AT SELECTION-SCREEN ON VALUE-REQUEST FOR PAR_LAUI.
* PERFORM F4_LAUF(RFUVDE00) USING 'I' PAR_LAUD PAR_LAUI.
*----------------------------------------------------------------------*
* Vorbereitungen *
*----------------------------------------------------------------------*
START-OF-SELECTION.
  COMMIT WORK.
  copy sel_cpud to br_cpudt.
  copy sel_bldt to br_bldat.
  READ TABLE br_bldat INDEX 1.
  hlp_stmdt = sy-datum.
  hlp_stmti = sy-uzeit.
  REFRESH tab_bset_key.
  REFRESH tab_sel_bukrs.
  IF flg_umkrs = 1.
* Es wurden Umsatzsteuerkreise abgegrenzt.
    REFRESH br_bukrs.
    CLEAR br_bukrs.
    br_bukrs-sign = 'I'.
    br_bukrs-option = 'EQ'.
* Zugehörige Buchungskreise holen.
    SELECT * FROM t007f
    WHERE umkrs IN sel_ukrs.
      SELECT * FROM t001
      WHERE umkrs = t007f-umkrs.
        MOVE-CORRESPONDING t001 TO tab_sel_bukrs.
        APPEND tab_sel_bukrs.
        br_bukrs-low = t001-bukrs.
        APPEND br_bukrs.
      ENDSELECT.
    ENDSELECT.
    CALL FUNCTION 'BUKRS_AUTHORITY_CHECK' "<--- 31H
    EXPORTING xdatabase = 'B' "<--- 31H
    TABLES xbukreis = br_bukrs. "<--- 31H
  ELSE.
* Es wurden Buchungskreise abgegrenzt.
    SELECT * FROM t001
    WHERE bukrs IN br_bukrs.
      MOVE-CORRESPONDING t001 TO tab_sel_bukrs.
      APPEND tab_sel_bukrs.
    ENDSELECT.
  ENDIF.
* Tabelle T007B einlesen
  SELECT * FROM t007b INTO TABLE tab_007b.
* Report-Titel aufbauen; FLG_PERSEL setzen
  IF br_bldat-low <> 0.
    flg_persel = 1.
    sy-title = text-005.
    WRITE br_bldat-low TO txt_datum DD/MM/YYYY.
    REPLACE '&DAT1' WITH txt_datum INTO sy-title.
    IF br_bldat-high <> 0.
      WRITE br_bldat-high TO txt_datum DD/MM/YYYY.
    ELSE.
      WRITE br_bldat-low TO txt_datum DD/MM/YYYY.
    ENDIF.
    REPLACE '&DAT2' WITH txt_datum INTO sy-title.
  ELSEIF br_budat-low NE 0.
    flg_persel = 1.
    sy-title = text-001.
    WRITE br_budat-low TO txt_datum DD/MM/YYYY.
    REPLACE '&DAT1' WITH txt_datum INTO sy-title.
    IF br_budat-high NE 0.
      WRITE br_budat-high TO txt_datum DD/MM/YYYY.
    ELSE.
      WRITE br_budat-low TO txt_datum DD/MM/YYYY.
    ENDIF.
    REPLACE '&DAT2' WITH txt_datum INTO sy-title.
  ELSEIF sel_mona-low <> 0.
    flg_persel = 1.
    sy-title = text-002.
    WRITE:
    sel_mona-low TO txt_buper(2),
    '/' TO txt_buper+2(1),
    br_gjahr-low TO txt_buper+3.
    REPLACE '&PER1' WITH txt_buper INTO sy-title.
    IF sel_mona-high NE 0.
      WRITE sel_mona-high TO txt_buper(2).
    ELSE.
      WRITE sel_mona-low TO txt_buper(2).
    ENDIF.
    REPLACE '&PER2' WITH txt_buper INTO sy-title.
  ELSE.
    flg_persel = 0.
    sy-title = text-007.
    WRITE:
    par_tmdt TO txt_datum DD/MM/YYYY,
    par_tmti TO txt_uzeit USING EDIT MASK '_::_'.
    REPLACE '&DATE' WITH txt_datum INTO sy-title.
    REPLACE '&TIME' WITH txt_uzeit INTO sy-title.
  ENDIF.
* Batch-Heading vorbereiten
  bhdgd-inifl = 0.
  bhdgd-lines = sy-linsz.
  bhdgd-uname = sy-uname.
  bhdgd-repid = sy-repid.
  bhdgd-line1 = sy-title.
  bhdgd-line2 = par_line.
  bhdgd-separ = par_lsep.
  bhdgd-domai = 'BUKRS'.
* Mikrofiche-Zeile vorbereiten
  bhdgd-miffl = par_mikf.
  IF par_xstk = 'X'.
* Erlaubte Rundungsdifferenzen pro Buchungskreis holen
    REFRESH tab_001r.
    SELECT * FROM t001
    WHERE bukrs IN br_bukrs.
* Rundungsdifferenzen nur für die Hauswährung merken
      SELECT SINGLE * FROM t001r
      WHERE bukrs = t001-bukrs
      AND waers = t001-waers.
      IF sy-subrc = 0.
        MOVE-CORRESPONDING t001r TO tab_001r.
        APPEND tab_001r.
      ELSE.
        MOVE-CORRESPONDING t001 TO tab_001r.
        tab_001r-reinh = 1.
        APPEND tab_001r.
      ENDIF.
    ENDSELECT.
  ENDIF.
* Tabelle mit Buchungskreisen, aus denen Belege zu 4.0 umgesetzt wurden
  IMPORT ums40 FROM DATABASE rfdt(fu) ID 'UMS40'.
*----------------------------------------------------------------------*
* Batch-Heading und eigene List-Überschriften *
*----------------------------------------------------------------------*
*OP-OF-PAGE.
* MOVE MIKLINE TO BHDGD-GRPIN.
* PERFORM BATCH-HEADING(RSBTCHH0).
* ULINE AT /0(HLP_TOPBR).
* IF TXT_ZEILE1 CN HLP_VLINE_SPACE.
* WRITE /0(HLP_TOPBR) TXT_ZEILE1 COLOR COL_HEADING INTENSIFIED.
* ENDIF.
* IF CNT_LISTE = 5.
* ULINE AT /0(HLP_TOPBR).
* ENDIF.
* IF TXT_ZEILE2 CN HLP_VLINE_SPACE.
* WRITE /0(HLP_TOPBR) TXT_ZEILE2 COLOR COL_HEADING INTENSIFIED.
* ENDIF.
* IF CNT_LISTE = 6.
* ULINE AT /0(HLP_TOPBR).
* ENDIF.
* IF TXT_ZEILE3 CN HLP_VLINE_SPACE.
* IF CNT_LISTE <> 6.
* WRITE /0(HLP_TOPBR) TXT_ZEILE3 COLOR COL_HEADING INTENSIFIED.
* ELSE.
* WRITE /0(HLP_LSTBR) TXT_ZEILE3 COLOR COL_HEADING INTENSIFIED.
* ENDIF.
* ENDIF.
* IF FLG_ULINE = 0.
* FLG_ULINE = 1.
* IF CNT_LISTE <> 6.
* ULINE AT /0(HLP_TOPBR).
* ELSE.
* ULINE AT /0(HLP_LSTBR).
* ENDIF.
* ENDIF.
*----------------------------------------------------------------------*
* Seitenende *
*----------------------------------------------------------------------*
*END-OF-PAGE.
  flg_even = 1.
*----------------------------------------------------------------------*
* Belegkopf *
*----------------------------------------------------------------------*
GET bkpf.
  CHECK:
  sel_mona.
  REFRESH:
  tab_diff,
  tab_ep.
  CLEAR:
  ep,
  tab_diff,
  tab_ep.
  PERFORM read_t001 USING bkpf-bukrs.
  IF par_bsud = 'X'.
* Bukrs, Belegnummer und Geschäftsjahr für BSET-Update mit den
* aus TAB_EP gelöschten Zeilen merken
    CLEAR tab_bset_key.
    MOVE-CORRESPONDING bkpf TO tab_bset_key.
  ENDIF.
* Erlaubte Rundungsdifferenz für Buchungskreis bzgl. Hauswährung
  IF par_xstk = 'X'.
    READ TABLE tab_001r WITH KEY bukrs = bkpf-bukrs.
  ENDIF.
*----------------------------------------------------------------------*
* Belegposition (Adressdaten, Skonto, Fortschreiben Anzahl der *
* Sachkontenzeilen pro Steuerkennzeichen) *
*----------------------------------------------------------------------*
GET bseg.
* Steuerkontrolle: Zulässige Rundungsdifferenz ermitteln
  IF par_xstk EQ 'X'. "Steuerkontrolle
* Merken der zulässigen Rundungsdifferenz pro Steuerkz. im Beleg,
* abhängig von der Anzahl der Beleg- und Steuerzeilen mit diesem Kz
* Kontokorrentzeilen und durch Steuerbeträge erzeugte automatische
* Zeilen werden nicht berücksichtigt
    IF bseg-koart <> 'D' AND bseg-koart <> 'K'
    AND ( bseg-mwart = space OR bseg-xauto = space ).
      tab_diff-mwskz = bseg-mwskz.
      tab_diff-rndbl = tab_001r-reinh.
      tab_diff-rndst = 0.
      COLLECT tab_diff.
    ENDIF.
  ENDIF.
  CHECK bseg-koart EQ 'D' OR bseg-koart EQ 'K'.
* Adressdaten des ersten Debitoren/Kreditoren je Beleg -----------------
  IF ( par_xadr EQ 'X' OR par_sort EQ 4 ) AND ep-ktnra EQ space.
    ep-koart = bseg-koart.
    ep-gjahr = bseg-gjahr.
    ep-buzei = bseg-buzei.
    IF bseg-koart EQ 'D'.
      SELECT SINGLE * FROM kna1
      WHERE kunnr = bseg-kunnr.
      ep-xcpdk = kna1-xcpdk.
      IF kna1-xcpdk <> space.
        ep-ktnra = bseg-kunnr.
      ELSEIF kna1-fiskn <> space.
        ep-ktnra = kna1-fiskn.
      ELSE.
        ep-ktnra = bseg-kunnr.
      ENDIF.
    ELSE.
      SELECT SINGLE * FROM lfa1
      WHERE lifnr = bseg-lifnr.
      ep-xcpdk = lfa1-xcpdk.
      IF lfa1-xcpdk <> space.
        ep-ktnra = bseg-lifnr.
      ELSEIF lfa1-fiskn <> space.
        ep-ktnra = lfa1-fiskn.
      ELSE.
        ep-ktnra = bseg-lifnr.
      ENDIF.
    ENDIF.
  ENDIF.
  MOVE-CORRESPONDING bseg TO tab_bseg.
  APPEND tab_bseg.
*----------------------------------------------------------------------*
* Umsatzsteuerposition *
*----------------------------------------------------------------------*
GET bset.
  CHECK:
  sel_mwkz,
  bset-hwbas NE 0.
* Überprüfen, ob Steuerzeile für aktuellen Lauf relevant ist
  IF par_bsud EQ 'X' OR par_tmdt NE 0 OR par_tmti NE 0.
    CHECK:
    bset-stmdt = par_tmdt,
    bset-stmti = par_tmti.
  ENDIF.
  PERFORM:
  read_t007a USING tab_001-kalsm bset-mwskz,
  read_t007b USING bset-ktosl,
  read_konp USING bset-knumh.
  CHECK tab_007b-stgrp NE 4.
  IF par_xstk EQ 'X'. "Steuerkontrolle
* Merken der zulässigen Rundungsdifferenz pro Steuerkz. im Beleg,
* abhängig von der Anzahl der Beleg- und Steuerzeilen mit diesem Kz
    tab_diff-mwskz = bset-mwskz.
    tab_diff-rndbl = 0.
    tab_diff-rndst = tab_001r-reinh.
    COLLECT tab_diff.
  ENDIF.
* Einzelpostentabelle füllen -------------------------------------------
  MOVE-CORRESPONDING bset TO tab_ep.
  IF bset-shkzg EQ 'H'.
    tab_ep-hwbas = tab_ep-hwbas * -1.
    tab_ep-fwbas = tab_ep-fwbas * -1.
    tab_ep-hwste = tab_ep-hwste * -1.
    tab_ep-fwste = tab_ep-fwste * -1.
  ENDIF.
  tab_ep-mwart = tab_007a-mwart.
  tab_ep-stgrp = tab_007b-stgrp.
  tab_ep-stazf = tab_007b-stazf.
  tab_ep-kbetr = tab_konp-kbetr.
  APPEND tab_ep.
*----------------------------------------------------------------------*
* Extrahieren der Daten je Beleg *
*----------------------------------------------------------------------*
GET bkpf LATE.
*{ Insert of SYDK948386 4
  CLEAR df_ukurs.
  SELECT SINGLE ukurs INTO df_ukurs
    FROM zfr01006
    WHERE bukrs EQ bkpf-bukrs
      AND belnr EQ bkpf-belnr
      AND gjahr EQ bkpf-gjahr.
  w_ukurs = df_ukurs.
*}Insert
* Belegkopf-Felder zum Extrahieren füllen ------------------------------
  ep-bukrs = bkpf-bukrs.
  ep-buper(4) = bkpf-gjahr.
  ep-buper+4 = bkpf-monat.
  IF par_xfwi EQ 'X'.
    ep-waers = bkpf-waers.
  ENDIF.
  ep-budat = bkpf-budat.
  ep-belnr = bkpf-belnr.
  ep-xblnr = bkpf-xblnr.
  IF par_sort EQ 4.
    CONDENSE bkpf-bktxt.
    SPLIT bkpf-bktxt AT space INTO ep-qunum ep-qutyp ep-qudat.
    CHECK ep-qunum NE space.
    IF ep-qudat IS INITIAL.
      WRITE bkpf-bldat TO ep-qudat DD/MM/YYYY.
    ENDIF.
    hlp_lfdnr = ep-qunum.
    hlp_sort = hlp_lfdnr.
  ENDIF.
* Steuerkontrolle ------------------------------------------------------
  IF par_xstk EQ 'X'. "Steuerkontrolle
    LOOP AT tab_ep.
      PERFORM read_tax_amount "Steuerbetrag berechnen
      USING tab_ep-mwskz tab_ep-ktosl tab_ep-kschl tab_ep-hwbas
      CHANGING hlp_hwste2.
      tab_ep-sdiff = hlp_hwste2 - tab_ep-hwste.
      MODIFY tab_ep. "Differenz merken
    ENDLOOP.
  ENDIF.
* Nicht abzugsfähige Steuer auf zugehörige Zeilen verteilen ------------
  LOOP AT tab_ep.
    tab_ep-hwnaf = 0.
    tab_ep-fwnaf = 0.
    IF tab_ep-stazf EQ 'X'.
      IF tab_ep-mwart EQ 'A'. "Flag für die Überschrift
        flg_asnaf = 1.
      ELSE.
        flg_vsnaf = 1.
      ENDIF.
      hlp_txgrp = tab_ep-txgrp.
      hlp_shkzg = tab_ep-shkzg.
      hlp_hwnaf = tab_ep-hwste.
      hlp_fwnaf = tab_ep-fwste.
      hlp_kbetr = tab_ep-kbetr.
      hlp_sdiff = tab_ep-sdiff.
      flg_modify = 0.
      LOOP AT tab_ep. "Zugehörige Zeile suchen
        IF tab_ep-txgrp EQ hlp_txgrp
        AND tab_ep-shkzg EQ hlp_shkzg
        AND tab_ep-stgrp NE 3
        AND tab_ep-stazf EQ space.
          tab_ep-hwste = tab_ep-hwste + hlp_hwnaf.
          tab_ep-fwste = tab_ep-fwste + hlp_fwnaf.
          tab_ep-hwnaf = hlp_hwnaf.
          tab_ep-fwnaf = hlp_fwnaf.
          tab_ep-kbetr = tab_ep-kbetr + hlp_kbetr.
          tab_ep-sdiff = tab_ep-sdiff + hlp_sdiff.
          MODIFY tab_ep.
          flg_modify = 1.
          EXIT.
        ENDIF.
      ENDLOOP.
      READ TABLE tab_ep INDEX sy-tabix.
      IF flg_modify EQ 1.
        IF par_bsud = 'X'.
          MOVE-CORRESPONDING tab_ep TO tab_bset_key.
          APPEND tab_bset_key. "Zeile merken für BSET-Update
        ENDIF.
        DELETE tab_ep. "Zeile mit n.abzugsf. löschen
      ELSE. "Zugehörige Zeile fehlte (dh 100%
        LOOP AT tab_007b. "n.abzugsf.) => Zeile generieren
          IF tab_007b-stgrp EQ tab_ep-stgrp
          AND tab_007b-stazf EQ space.
            tab_ep-ktosl = tab_007b-ktosl.
            tab_ep-stazf = space.
            tab_ep-hwnaf = tab_ep-hwste.
            tab_ep-fwnaf = tab_ep-fwste.
            MODIFY tab_ep.
            EXIT.
          ENDIF.
        ENDLOOP.
      ENDIF.
    ENDIF.
  ENDLOOP.
* Erwerbsteuer korrigieren ---------------------------------------------
  LOOP AT tab_ep.
    WRITE tab_ep-kbetr TO hlp_psatz NO-SIGN CURRENCY '3'.
    IF hlp_psatz(3) EQ '100'. "vermutlich Erwerbsteuer
      hlp_hwste = - tab_ep-hwste.
      hlp_txgrp = tab_ep-txgrp.
      flg_modify = 0.
      LOOP AT tab_ep.
        IF tab_ep-hwste EQ hlp_hwste "Erwerbsteuer!
        AND tab_ep-txgrp EQ hlp_txgrp.
          hlp_hwbas = tab_ep-hwbas. "Basisbetrag und Prozentsatz
          hlp_fwbas = tab_ep-fwbas. "merken
          hlp_kbetr = tab_ep-kbetr.
          flg_modify = 1.
          EXIT.
        ENDIF.
      ENDLOOP.
      IF flg_modify = 1.
        LOOP AT tab_ep
        WHERE txgrp EQ hlp_txgrp.
          WRITE tab_ep-kbetr TO hlp_psatz NO-SIGN CURRENCY '3'.
          IF hlp_psatz(3) EQ '100'. "100%-Zeile modifizieren:
            tab_ep-hwbas = - hlp_hwbas." Basisbetrag mit umgekehrtem
            tab_ep-fwbas = - hlp_fwbas." Vorzeichen und
            tab_ep-kbetr = hlp_kbetr." Partnerzeile übernehmen
            MODIFY tab_ep.
            EXIT.
          ENDIF.
        ENDLOOP.
      ENDIF.
    ENDIF.
  ENDLOOP.
* Selektierte Daten extrahieren ----------------------------------------
  LOOP AT tab_ep.
    AT NEW mwskz. "Erlaubte Rundungsdifferenz
      IF par_xstk EQ 'X'. "bei der Steuerkontrolle
        READ TABLE tab_diff WITH KEY mwskz = tab_ep-mwskz.
      ENDIF.
    ENDAT.
    MOVE-CORRESPONDING tab_ep TO ep.
    ep-gjahr = bkpf-gjahr.
    WRITE tab_ep-kbetr TO ep-psatz NO-SIGN CURRENCY '3'.
    IF par_xstk EQ 'X'. "Steuerkontrolle
      IF tab_diff-rndbl GE tab_diff-rndst.
        hlp_sdiff = tab_diff-rndbl.
      ELSE.
        hlp_sdiff = tab_diff-rndst.
      ENDIF.
      IF ep-sdiff GE 0.
        IF ep-sdiff LE hlp_sdiff.
          ep-sdiff = 0.
        ENDIF.
      ELSE.
        ep-sdiff = - ep-sdiff.
        IF ep-sdiff LE hlp_sdiff.
          ep-sdiff = 0.
        ENDIF.
        ep-sdiff = - ep-sdiff.
      ENDIF.
    ENDIF.
    CASE tab_ep-stgrp.
      WHEN 1.
        ep-mwart = 'A'.
      WHEN 2.
        ep-mwart = 'V'.
    ENDCASE.
    IF ( par_xsau NE space AND ep-mwart EQ 'A' ) OR
    ( par_xsvo NE space AND ep-mwart EQ 'V' ).
      IF ( ep-hwbas GT 0 AND ep-hwste LT 0 ) OR
      ( ep-hwbas LT 0 AND ep-hwste GT 0 ).
        ep-hwbas = - ep-hwbas.
        ep-fwbas = - ep-fwbas.
      ENDIF.
* { Insert of SYDK948386 5
      IF bkpf-waers NE 'SGD'.
*}Delete of SYDK949085 1
* IF EP-MWSKZ(1) EQ 'P'.
*} Delete
* { Insert of SYDK949111 1 MOVE}Insert
*} Insert of SYDK949085 1
        IF ep-mwskz(1) EQ 'P' AND ep-fwste GT 0.
*} Insert
          COMPUTE: ep-hwbas = ep-fwbas * df_ukurs / 100000,
          ep-hwste = ep-fwste * df_ukurs / 100000,
          ep-hwnaf = ep-fwnaf * df_ukurs / 100000.
        ELSE.
        ENDIF.
*{ Insert of SYDK949078 1
      ELSE.
*}Insert
        MOVE: ep-fwbas TO ep-hwbas,
        ep-fwste TO ep-hwste,
        ep-fwnaf TO ep-hwnaf.
***********************************
*MOD-003
***********************************
        LOOP AT tab_ep INTO wa_bset.
          IF NOT df_ukurs IS INITIAL.
            ep-hwste = wa_bset-hwste * df_ukurs / 100000.
            ep-hwbas = wa_bset-hwbas * df_ukurs / 100000.
          ENDIF.
        ENDLOOP.
**********************************
*MOD-003
**********************************
      ENDIF.
*} Insert
      EXTRACT daten.
    ENDIF.
    IF par_binp = 'X'. "Batch-Input gewünscht
      CLEAR tab_bi.
      tab_bi-bukrs = bkpf-bukrs. "Buchungskreis
      tab_bi-hkont = tab_ep-hkont. "Hauptbuchkonto
      tab_bi-saldo = tab_ep-hwste - tab_ep-hwnaf.
      "abzugsfähige bzw. abzuführende
      " Steuer in Hauswährung
      COLLECT tab_bi.
    ENDIF.
  ENDLOOP.
*----------------------------------------------------------------------*
* Verarbeitung der extrahierten Daten *
*----------------------------------------------------------------------*
END-OF-SELECTION.
  CASE par_sort.
    WHEN 1.
      SORT BY
      ep-bukrs "Buchungskreis
      ep-mwart "Umsatzsteuerart
      ep-mwskz "Umsatzsteuerkennzeichen
      ep-buper "Buchungsperiode
      ep-waers "Währungsschlüssel
      ep-budat "Buchungsdatum
      ep-belnr "Belegnummer
      ep-ktosl. "Vorgangsschlüssel
    WHEN 2.
      SORT.
    WHEN 3.
      SORT BY
      ep-bukrs "Buchungskreis
      ep-mwart "Umsatzsteuerart
      ep-belnr "Belegnummer
      ep-mwskz "Umsatzsteuerkennzeichen
      ep-ktosl. "Vorgangsschlüssel
    WHEN 4.
      SORT BY
      ep-bukrs "Buchungskreis
      ep-mwart "Umsatzsteuerart
      hlp_sort "Quittungsnr. (numerischer Teil)
      ep-belnr "Belegnummer
      ep-mwskz "Umsatzsteuerkennzeichen
      ep-ktosl. "Vorgangsschlüssel
  ENDCASE.
  IF par_umsv = 'X'.
    REFRESH tab_umsv.
    CLEAR fle_umsvz.
    fle_umsvz-mandt = sy-mandt.
    fle_umsvz-laufd = par_laud.
    fle_umsvz-laufi = par_laui.
    fle_umsvz-budt1 = br_budat-low.
    fle_umsvz-budt2 = br_budat-high.
    fle_umsvz-mona1 = sel_mona-low.
    fle_umsvz-mona2 = sel_mona-high.
    fle_umsvz-gjahr = br_gjahr-low.
    fle_umsvz-bldt1 = br_bldat-low.
    fle_umsvz-bldt2 = br_bldat-high.
  ENDIF.
  LOOP.
    MOVE ep-bukrs TO intab-bukrs.
    MOVE ep-mwart TO intab-mwart.
    MOVE ep-mwskz TO intab-mwskz.
    MOVE ep-ktosl TO intab-ktosl.
    MOVE ep-buper TO intab-buper.
    MOVE ep-waers TO intab-waers.
    MOVE ep-budat TO intab-budat.
    MOVE ep-gjahr TO intab-gjahr.
    MOVE ep-belnr TO intab-belnr.
    MOVE ep-buzei TO intab-buzei.
    MOVE ep-xblnr TO intab-xblnr.
    MOVE ep-qunum TO intab-qunum.
    MOVE ep-qutyp TO intab-qutyp.
    MOVE ep-qudat TO intab-qudat.
    MOVE ep-psatz TO intab-psatz.
    MOVE ep-koart TO intab-koart.
    MOVE ep-ktnra TO intab-ktnra.
    MOVE ep-xcpdk TO intab-xcpdk.
    MOVE ep-shkzg TO intab-shkzg.
    MOVE ep-hwbas TO intab-hwbas.
    MOVE ep-fwbas TO intab-fwbas.
    MOVE ep-hwste TO intab-hwste.
    MOVE ep-fwste TO intab-fwste.
    MOVE ep-hwnaf TO intab-hwnaf.
    MOVE ep-fwnaf TO intab-fwnaf.
    MOVE ep-sdiff TO intab-sdiff.
    APPEND intab. CLEAR intab.
  ENDLOOP.
  PERFORM move-data.
  PERFORM print-report.
  REFRESH itab.
  FREE itab.
*---------------------------------------------------------------------*
* FORM MOVE-DATA *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM move-data.
  DATA: v_line TYPE sy-tabix.
  DATA: v_tabix TYPE sy-tabix.
  DATA: l_tabix TYPE sy-tabix.
  DATA: l_hwste TYPE bset-hwste,
  l_hwbas TYPE bset-hwbas.
  CLEAR: l_hwste,
  l_hwbas.
  LOOP AT intab.
    SELECT * FROM bseg WHERE bukrs EQ intab-bukrs
    AND belnr EQ intab-belnr
    AND gjahr EQ intab-gjahr
    AND buzei EQ intab-buzei.
      IF bseg-kunnr EQ space AND bseg-lifnr NE space.
        itab-kunnr = bseg-lifnr.
      ELSEIF bseg-kunnr NE space AND bseg-lifnr EQ space.
        itab-kunnr = bseg-kunnr.
      ENDIF.
      MOVE-CORRESPONDING intab TO itab.
      APPEND itab. CLEAR itab.
    ENDSELECT.
  ENDLOOP.
************************************
**MOD-002
**CTS SYDK9A0AKG.
************************************
  SORT itab BY bukrs belnr gjahr.
  DELETE itab WHERE bukrs IS INITIAL OR belnr IS INITIAL.
  REFRESH: tab_bset.
  SELECT *
  INTO TABLE tab_bset
  FROM bset
  FOR ALL ENTRIES IN itab
  WHERE bukrs = itab-bukrs
  AND belnr = itab-belnr
  AND gjahr = itab-gjahr.
***********************************
**MOD-002
***********************************
  SORT tab_bset BY bukrs belnr gjahr.
  DELETE tab_bset WHERE bukrs IS INITIAL.
  LOOP AT itab.
    SELECT SINGLE * FROM t001 WHERE bukrs EQ itab-bukrs.
    SELECT SINGLE * FROM t005 WHERE land1 EQ t001-land1.
    IF sy-subrc EQ 0.
      itab-kalsm = t005-kalsm.
    ENDIF.
    SELECT * FROM bkpf WHERE bukrs EQ itab-bukrs
    AND belnr EQ itab-belnr
    AND gjahr EQ itab-gjahr.
      MOVE bkpf-bldat TO itab-bldat.
**********************************
*MOD-002
**********************************
      CLEAR: w_ukurs.
      SELECT SINGLE ukurs INTO w_ukurs FROM zfr01006
      WHERE bukrs EQ bkpf-bukrs
      AND belnr EQ bkpf-belnr
      AND gjahr EQ bkpf-gjahr.
      IF NOT tab_bset[] IS INITIAL.
        IF bkpf-waers NE 'SGD'.
          READ TABLE tab_bset WITH KEY bukrs = itab-bukrs
          belnr = itab-belnr
          gjahr = itab-gjahr
          shkzg = 'S'.
          IF sy-subrc = 0.
            IF tab_bset-fwste NE 0. "and tab_bset-fwbas ne 0.
* ep-hwste = tab_bset-fwste * w_ukurs / 100000.
* ep-hwbas = tab_bset-fwbas * w_ukurs / 100000.
              l_hwste = tab_bset-fwste * w_ukurs / 100000.
              l_hwbas = tab_bset-fwbas * w_ukurs / 100000.
            ENDIF.
          ELSE.
            READ TABLE tab_bset WITH KEY bukrs = itab-bukrs
            belnr = itab-belnr
            gjahr = itab-gjahr
            shkzg = 'H'.
            IF sy-subrc = 0.
              IF tab_bset-fwste NE 0. "and tab_bset-fwbas ne 0.
* ep-hwste = tab_bset-fwste * w_ukurs / 100000.
* ep-hwbas = tab_bset-fwbas * w_ukurs / 100000.
                l_hwste = tab_bset-fwste * w_ukurs / 100000.
                l_hwbas = tab_bset-fwbas * w_ukurs / 100000.
              ENDIF.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDIF.
      IF bkpf-waers NE 'SGD'.
        itab-hwste = l_hwste.
        itab-hwbas = l_hwbas.
        MODIFY itab TRANSPORTING hwste hwbas kalsm bldat.
      ELSE.
        MODIFY itab TRANSPORTING kalsm bldat.
      ENDIF.
**********************************
*MOD-003
**********************************
* MODIFY itab transporting hwste hwbas kalsm bldat.
      CLEAR itab.
      CLEAR: l_hwste,
      l_hwbas.
    ENDSELECT.
  ENDLOOP.
ENDFORM. "move-data
*---------------------------------------------------------------------*
* FORM PRINT-REPORT *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM print-report.
*Start add by SYDK919000
  LOOP AT itab.
    IF itab-mwskz(1) EQ 'S'.
      itab-flag = '1'.
    ELSEIF itab-mwskz(1) EQ 'P'.
      itab-flag = '2'.
    ENDIF.
    MODIFY itab.
  ENDLOOP.
*End add by SYDK919000
  SORT itab BY flag mwskz kunnr belnr budat.
  LOOP AT itab.
    w-flag = itab-flag.
    w-kalsm = itab-kalsm.
    w-mwskz = itab-mwskz.
    AT NEW bukrs.
      NEW-PAGE.
    ENDAT.
    AT NEW flag.
      NEW-PAGE.
    ENDAT.
    AT NEW mwskz.
      CLEAR: xt007s-text1.
      SKIP.
      SELECT SINGLE * FROM t007s WHERE spras EQ 'E'
      AND kalsm EQ w-kalsm
      AND mwskz EQ itab-mwskz.
      IF sy-subrc EQ 0.
        xt007s-text1 = t007s-text1.
      ENDIF.
      WRITE: /1 'Tax Code : ', itab-mwskz, xt007s-text1.
      SKIP.
    ENDAT.
    CLEAR: w-name1.
*If Purchase
    IF itab-mwskz(1) EQ 'P'.
      SELECT SINGLE * FROM lfa1 WHERE lifnr EQ itab-kunnr.
      IF sy-subrc EQ 0.
        w-name1 = lfa1-name1.
      ENDIF.
*Sales
    ELSEIF itab-mwskz(1) EQ 'S'.
      SELECT SINGLE * FROM kna1 WHERE kunnr EQ itab-kunnr.
      IF sy-subrc EQ 0.
        w-name1 = kna1-name1.
      ENDIF.
    ENDIF.
    CLEAR w-total.
    w-total = itab-hwbas + itab-hwste.
* IF WS-MWSKZ NE ITAB-MWSKZ. "SYDK919000
*{Insert of SYDK948386 6
*IF itab-hwbas NE 0.
*}Insert
    WRITE: /1 itab-kunnr, 10 w-name1, 50(12) itab-belnr, 62(10) itab-budat,
    75(20) itab-xblnr, 93(10) itab-bldat, 106(15) itab-hwbas,
    121(15) itab-hwste, 136(17) w-total.
*{ Insert of SYDK948386 7
*ELSE.
*  WRITE
*}Insert
* ELSE.
* IF W-KUNNR NE ITAB-KUNNR.
*WRITE: /1 ITAB-KUNNR, 10 W-NAME1, 50(12) ITAB-BELNR, 62(10) ITAB-BUDAT,
* 75(20) ITAB-XBLNR, 93(10) ITAB-BLDAT, 106(15) ITAB-HWBAS,
* 121(15) ITAB-HWSTE, 136(17) W-TOTAL.
* ELSE.
* WRITE: /50(12) ITAB-BELNR, 62(10) ITAB-BUDAT,
* 75(20) ITAB-XBLNR, 93(10) ITAB-BLDAT, 106(15) ITAB-HWBAS,
* 121(15) ITAB-HWSTE, 136(17) W-TOTAL.
* ENDIF.
* ENDIF.
* W-KUNNR = ITAB-KUNNR.
* WS-MWSKZ = ITAB-MWSKZ. "SYDK919000
    AT END OF kunnr.
      SKIP.
      SUM.
      w-vtotal = itab-hwbas + itab-hwste.
      IF w-mwskz(1) EQ 'S'.
        WRITE: /10 'Customer Total'.
      ELSE.
        WRITE: /10 'Vendor Total'.
      ENDIF.
      WRITE: 106(15) itab-hwbas, 121(15) itab-hwste, 136(17) w-vtotal.
      CLEAR: w-vtotal.
      SKIP.
    ENDAT.
    AT END OF mwskz.
      SKIP.
      SUM.
      w-ttotal = itab-hwbas + itab-hwste.
      WRITE: /10 'Tax Code Total: ', w-mwskz,
      106(15) itab-hwbas, 121(15) itab-hwste, 136(17) w-ttotal.
      CLEAR: w-ttotal.
      SKIP.
    ENDAT.
*Start add by SYDK919000
    AT END OF flag.
      SKIP.
      SUM.
      w-stotal = itab-hwbas + itab-hwste.
      IF w-flag EQ '1'.
        WRITE: /10 'SALES TOTAL '.
      ELSEIF w-flag EQ '2'.
        WRITE: /10 'PURCHASE TOTAL'.
      ENDIF.
      WRITE: 106(15) itab-hwbas, 121(15) itab-hwste, 136(17) w-stotal.
      CLEAR: w-stotal.
      SKIP.
    ENDAT.
*End add by SYDK919000
    AT LAST.
      SKIP.
      SUM.
      w-gtotal = itab-hwbas + itab-hwste.
      WRITE: /10 'GRAND TOTAL',
      106(15) itab-hwbas, 121(15) itab-hwste, 136(17) w-gtotal.
      CLEAR: w-gtotal.
    ENDAT.
  ENDLOOP.
  SKIP 3.
  WRITE: /70 '**** END OF REPORT ****'.
ENDFORM. "print-report

TOP-OF-PAGE.
  sy-title = 'Goods and Services Tax on Sales/Purchases'.
  WRITE: /1 sy-repid, 105 'USER-ID: ', sy-uname,
  130 'PAGE:', sy-pagno.
  WRITE: /45 sy-title, 130 'DATE: ', sy-datum.
  WRITE: /130 'TIME: ', sy-uzeit.
  WRITE: /1 'Posting Date from: ', br_budat-low, 'to', br_budat-high.
  ULINE.
  IF w-mwskz(1) EQ 'P'.
    WRITE: /1 'Vendor', 10 'Vendor Name', 50 'Doc. No',
    62 'Post.Date', 75 'Ref.No', 93 'Doc.Date',
    106 'Base Amount(SGD)', 128 'Tax(SGD)', 137 'Amount inc Tax(SGD)'.
  ELSE.
    WRITE: /1 'Customer', 10 'Customer Name', 50 'Doc. No',
    62 'Post.Date', 75 'Ref.No', 93 'Doc.Date',
    106 'Base Amount(SGD)', 128 'Tax(SGD)', 137 'Amount inc Tax(SGD)'.
  ENDIF.
  ULINE.
************************************************************************
* Unterprogramme *
*----------------------------------------------------------------------*
* READ_T001 Buchungskreisdaten lesen *
* READ_T007A Umsatzsteuerdaten lesen *
* READ_T007B Verrechnungsschlüsseldaten lesen *
* READ_KONP Prozentsatz lesen *
* READ_ADRS Anschriftsdaten Debitoren/Kreditoren lesen*
* READ_PRINT_SKAT Sachkonteninfo lesen und drucken *
* COLLECT_TAB_MWART Summenblatt Vor-/Ausgangssteuer aufbauen *
* COLLECT_TAB_MWART_SUM zugehörige Abschlußinformation *
* COLLECT_TAB_BUKRS Summenblatt Steuersaldo aufbauen *
* COL