Skip to end of metadata
Go to start of metadata

List of all pages

Pages at first level

This is the  program to accept a range of Sales documents (VBAK-VBELN), and display the following contents of the sales document header data (from VBAK):
o Sales document number,
o Sales document creation date,
o Name of the person who created the document,
o Document category,
o Document type,
o Delivery block,
o Billing block,
o Net value of the document,
o Sales organization,
o Sold to party.

When the user double clicks on any of the sales document header data, the list should display the Sales Document: Item Data (from VBAP) for that particular sales document selected. Display the following data of the sales document item data in the secondary list:
o Sales document,
o Sales document item,
o Material number,
o Base unit of measure.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*Table declarations...................................................
TABLES vbak.
*Selection screen elements............................................
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS s_vbeln FOR vbak-vbeln.
SELECTION-SCREEN END OF BLOCK b1.
*--------------------------------------------------------------------*
*         TYPE DECLARATION TO HOLD SALES DOCUMENT HEADER DATA
*--------------------------------------------------------------------*
TYPES:
 BEGIN OF type_s_itab,
  vbeln TYPE vbak-vbeln,               " Sales Document Number
  erdat TYPE vbak-erdat,               " Creation Date
  ernam TYPE vbak-ernam,               " Creater's Name
  vbtyp TYPE vbak-vbtyp,               " Document Category
  auart TYPE vbak-auart,               " Document Type
  lifsk TYPE vbak-lifsk,               " delivary Block
  faksk TYPE vbak-faksk,               " Billing Block
  netwr TYPE vbak-netwr,               " Net Value
  waerk TYPE vbak-waerk,               " Currency Key
  vkorg TYPE vbak-vkorg,               " Sales Organization
  kunnr TYPE vbak-kunnr,               " Sold To Party
 END OF type_s_itab,
*--------------------------------------------------------------------*
*         TYPE DECLARATION TO HOLD SALES DOCUMENT ITEM DATA
*--------------------------------------------------------------------*
 BEGIN OF type_s_itab1,
  vbeln TYPE vbap-vbeln,               " Sales Document Number
  posnr TYPE vbap-posnr,               " Sales Document Item
  matnr TYPE vbap-matnr,               " Material Number
  meins TYPE vbap-meins,               " Base Unit Of Measure
 END OF type_s_itab1.
DATA:
*--------------------------------------------------------------------*
*           FIELD STRING TO HOLD SALES DOCUMENT HEADER DATA
*--------------------------------------------------------------------*
fs_itab TYPE type_s_itab,
*--------------------------------------------------------------------*
*   FIELD STRING TO HOLD SALES DOCUMENT ITEM DATA
*--------------------------------------------------------------------*
fs_itab1 TYPE type_s_itab1,
*--------------------------------------------------------------------
*  INTERNAL TABLE TO HOLD SALES DOCUMENT HEADER
DATA
*--------------------------------------------------------------------
 t_itab LIKE TABLE OF fs_itab,
*--------------------------------------------------------------------*
* INTERNAL TABLE TO HOLD SALES DOCUMENT ITEM DATA
*--------------------------------------------------------------------*
 t_itab1 LIKE TABLE OF fs_itab1.
*--------------------------------------------------------------------*
*                        START-OF-SELECTION
*--------------------------------------------------------------------*
START-OF-SELECTION.
  PERFORM selection.
  PERFORM selection2.
*--------------------------------------------------------------------*
*                         END-OF-SELECTION
*--------------------------------------------------------------------*
END-OF-SELECTION.
  PERFORM display.
*--------------------------------------------------------------------*
*                             TOP-OF-PAGE
*--------------------------------------------------------------------*
TOP-OF-PAGE.
  PERFORM heading.
*--------------------------------------------------------------------*
*                         AT LINE-SELECTION
*--------------------------------------------------------------------*
AT LINE-SELECTION.
  PERFORM detail_list.
TOP-OF-PAGE DURING LINE-SELECTION.
  PERFORM heading2.
*&---------------------------------------------------------------------*
*&      Form  selection
*&---------------------------------------------------------------------*
*  This subroutine retrieves Sales Document Header Data with in the
*  range of Sales Document Number given by the user
*----------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine
*----------------------------------------------------------------------*
FORM selection .
  SELECT  vbeln                        " Sales Document Number
          erdat                              " Creation Date
          ernam                             " Creater's Name
          vbtyp                             " Document Category
          auart                              " Document Type
          lifsk                                 " delivary Block
          faksk                              " Billing Block
          netwr                             " Net Value
          waerk                            " Currency Key
          vkorg                             " Sales Organization
          kunnr                             " Sold To Party
          FROM vbak INTO CORRESPONDING FIELDS OF TABLE t_itab
          WHERE vbeln IN s_vbeln.
  IF sy-subrc <> 0.
    MESSAGE text-003 TYPE 'I'.
    LEAVE LIST-PROCESSING.
  ELSEIF s_vbeln-low IS INITIAL.
    MESSAGE text-004 TYPE 'I'.
    LEAVE LIST-PROCESSING.
  ELSEIF s_vbeln-low EQ 0.
    MESSAGE text-019 TYPE 'I'.
    LEAVE LIST-PROCESSING.
  ENDIF.                               " IF SY_SUBRC
ENDFORM.                               " selection
*&---------------------------------------------------------------------*
*&      Form  selection2
*&---------------------------------------------------------------------*
* This subroutine retrieves Sales Document Item Data form the table
* vbap corresponds to the Sales Document Number range given by the user
*----------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine
*----------------------------------------------------------------------*
FORM selection2 .
  SELECT  vbeln                        " Sales Document Number
          posnr                        " Sales Document Item
          matnr                        " Material Number
          meins                        " Base Unit Of Measure
          FROM vbap INTO CORRESPONDING FIELDS OF TABLE t_itab1
          WHERE vbeln IN s_vbeln.
ENDFORM.                               " Selection2
*&---------------------------------------------------------------------*
*&      Form  display
*&---------------------------------------------------------------------*
* This subroutine displays the Sales Document Header Data from the
* table VBAK corresponds to the range of Sales Document Number given by
* the user
*----------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine
*----------------------------------------------------------------------*
FORM display .
  SKIP.
  LOOP AT t_itab INTO fs_itab.
    WRITE:/
             fs_itab-vbeln COLOR 3,
          11 fs_itab-erdat COLOR 3,
          22 fs_itab-ernam COLOR 3,
          32 fs_itab-vbtyp COLOR 3,
          44 fs_itab-auart COLOR 3,
          54 fs_itab-lifsk COLOR 3,
          66 fs_itab-faksk COLOR 3,
          69 fs_itab-netwr CURRENCY fs_itab-waerk COLOR 3,
          90 fs_itab-vkorg COLOR 3,
         100 fs_itab-vkorg COLOR 3.
    HIDE fs_itab-vbeln.
  ENDLOOP.                             " LOOP AT T_ITAB
ENDFORM.                               " Display
*&---------------------------------------------------------------------*
*&      Form  detail_list
*&---------------------------------------------------------------------*
* This subroutine retrieves  the Sales Document Item Data from table
*  VBAP for that particular Sales Document selected from the basic list
*----------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine
*----------------------------------------------------------------------*
FORM detail_list .
  IF sy-lilli LE 2.
    MESSAGE text-020 TYPE 'E'.
  ENDIF.                               " IF SY-LILLI LE 2
  IF sy-lsind EQ 2.
    MESSAGE text-002 TYPE 'E' DISPLAY LIKE 'I'.
  ENDIF.                               " IF SY-LSIND EQ 2
  LOOP AT t_itab1 INTO fs_itab1 WHERE vbeln EQ fs_itab-vbeln.
    WRITE:/
             fs_itab1-vbeln COLOR 3,
          20 fs_itab1-posnr COLOR 3,
          40 fs_itab1-matnr COLOR 3,
          60 fs_itab1-meins COLOR 3.
  ENDLOOP.                             " LOOP AT T_ITAB1
ENDFORM.                               " Detail_list
*&---------------------------------------------------------------------*
*&      Form  heading
*&---------------------------------------------------------------------*
* This subroutine is to display the heading for basic list of
* Sales Document Header data
*----------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine
*----------------------------------------------------------------------*
FORM heading .
  WRITE:/
     text-005 COLOR 4,
  11 text-014 COLOR 4,
  22 text-006 COLOR 4,
  32 text-007 COLOR 4,
  44 text-008 COLOR 4,
  54 text-009 COLOR 4,
  68 text-010 COLOR 4,
  80 text-011 COLOR 4,
  90 text-012 COLOR 4,
 100 text-013 COLOR 4.
ENDFORM.                               " Heading
*&---------------------------------------------------------------------*
*&      Form  heading2
*&---------------------------------------------------------------------*
* This subroutine is to display heading for detailed list of Sales
* Document Line data
*----------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine
*----------------------------------------------------------------------*
FORM heading2 .
  WRITE:/
     text-015 COLOR 4,
     text-016 COLOR 4,
     text-017 COLOR 4,
     text-018 COLOR 4.
ENDFORM.                                                    " Heading2

Author: Rajesh Manchal
Submitted: 07/02/07

Description : You can use the follwing program to Close all the Open Sales Orders which are closed actually but not in the SAP System becuase there was a difference in the initial quantity and the qnantity deliverd. Please be aware that the program takes the a series of sales orders and closes them by chaning the ordered quantity to the deliverd quantity by adjusting the scheduling line agreement data with the sales order data.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
TABLES: vbak, vbap, vbep.

SELECT-OPTIONS sales FOR vbak-vbeln OBLIGATORY.

DATA itab LIKE vbap OCCURS 0 WITH HEADER LINE.
DATA itab1 LIKE vbap OCCURS 0 WITH HEADER LINE.

SELECT * FROM vbap INTO TABLE itab WHERE vbeln IN sales.
LOOP AT itab.
  SELECT SINGLE * FROM vbap  WHERE vbeln = itab-vbeln.
  IF vbap-kwmeng NE itab-kbmeng.
    WRITE:/ itab-vbeln COLOR 1.

    UPDATE vbap
    SET kwmeng = itab-kbmeng
    WHERE vbeln = itab-vbeln.

    UPDATE vbap
    SET lsmeng = itab-kbmeng
    WHERE vbeln = itab-vbeln.

    SELECT SINGLE * FROM vbep
      WHERE vbeln =  itab-vbeln
        AND etenr = '0001'.
    IF sy-subrc = 0.
      UPDATE vbep
        SET wmeng = itab-kbmeng
        WHERE vbeln = itab-vbeln
          AND etenr = '0001'.
      UPDATE vbep
        SET cmeng = itab-kbmeng
        WHERE vbeln = itab-vbeln
          AND etenr = '0001'.
    ENDIF.
    CALL FUNCTION 'SD_SALES_DOCUMENT_UPDATE'
      EXPORTING
        i_vbeln = itab-vbeln.
  ENDIF.
ENDLOOP.

TOP-OF-PAGE.
  WRITE:/ 'The following orders are closed' COLOR 2.

Author: Narendran Muthukumaran
Submitted: 04/18/2007

Description Sample program to create sales order using BAPI.

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

* Parameters
* Sales document type
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text FOR FIELD p_auart.
PARAMETERS: p_auart TYPE auart OBLIGATORY.
SELECTION-SCREEN END OF LINE.

* Sales organization
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text1 FOR FIELD p_vkorg.
PARAMETERS: p_vkorg TYPE vkorg OBLIGATORY.
SELECTION-SCREEN END OF LINE.

* Distribution channel
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text2 FOR FIELD p_vtweg.
PARAMETERS: p_vtweg TYPE vtweg OBLIGATORY.
SELECTION-SCREEN END OF LINE.

* Division.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text3 FOR FIELD p_spart.
PARAMETERS: p_spart TYPE spart OBLIGATORY.
SELECTION-SCREEN END OF LINE.

SKIP 1.

* Sold-to
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text4 FOR FIELD p_sold.
PARAMETERS: p_sold  TYPE kunnr OBLIGATORY.
SELECTION-SCREEN END OF LINE.

* Ship-to
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text5 FOR FIELD p_ship.
PARAMETERS: p_ship  TYPE kunnr OBLIGATORY.
SELECTION-SCREEN END OF LINE.

SKIP 1.

* Material
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text6 FOR FIELD p_matnr.
PARAMETERS: p_matnr TYPE matnr   OBLIGATORY.
SELECTION-SCREEN END OF LINE.

* Quantity.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text7 FOR FIELD p_menge.
PARAMETERS: p_menge TYPE kwmeng  OBLIGATORY.
SELECTION-SCREEN END OF LINE.

* Plant
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text9 FOR FIELD p_plant.
PARAMETERS: p_plant TYPE werks_d OBLIGATORY.
SELECTION-SCREEN END OF LINE.

* Data declarations.
DATA: v_vbeln            LIKE vbak-vbeln.
DATA: header             LIKE bapisdhead1.
DATA: headerx            LIKE bapisdhead1x.
DATA: item               LIKE bapisditem  OCCURS 0 WITH HEADER LINE.
DATA: itemx              LIKE bapisditemx OCCURS 0 WITH HEADER LINE.
DATA: partner            LIKE bapipartnr  OCCURS 0 WITH HEADER LINE.
DATA: return             LIKE bapiret2    OCCURS 0 WITH HEADER LINE.
DATA: lt_schedules_inx   TYPE STANDARD TABLE OF bapischdlx
                         WITH HEADER LINE.
DATA: lt_schedules_in    TYPE STANDARD TABLE OF bapischdl
                         WITH HEADER LINE.

* Initialization.
INITIALIZATION.
v_text   = 'Order type'.
v_text1  = 'Sales Org'.
v_text2  = 'Distribution channel'.
v_text3  = 'Division'.
v_text4  = 'Sold-to'.
v_text5  = 'Ship-to'.
v_text6  = 'Material'.
v_text7  = 'Quantity'.
v_text9  = 'Plant'.

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

* Header data

* Sales document type
  header-doc_type = p_auart.
  headerx-doc_type = 'X'.

* Sales organization
  header-sales_org = p_vkorg.
  headerx-sales_org = 'X'.

* Distribution channel
  header-distr_chan  = p_vtweg.
  headerx-distr_chan = 'X'.

* Division
  header-division = p_spart.
  headerx-division = 'X'.

  headerx-updateflag = 'I'.

* Partner data
* Sold to
  partner-partn_role = 'AG'.
  partner-partn_numb = p_sold.
  APPEND partner.

* Ship to
  partner-partn_role = 'WE'.
  partner-partn_numb = p_ship.
  APPEND partner.

* ITEM DATA
  itemx-updateflag = 'I'.

* Line item number.
  item-itm_number = '000010'.
  itemx-itm_number = 'X'.

* Material
  item-material = p_matnr.
  itemx-material = 'X'.

* Plant
  item-plant    = p_plant.
  itemx-plant   = 'X'.

* Quantity
  item-target_qty = p_menge.
  itemx-target_qty = 'X'.

  APPEND item.
  APPEND itemx.

*   Fill schedule lines
  lt_schedules_in-itm_number = '000010'.
  lt_schedules_in-sched_line = '0001'.
  lt_schedules_in-req_qty    = p_menge.
  APPEND lt_schedules_in.

*   Fill schedule line flags
  lt_schedules_inx-itm_number  = '000010'.
  lt_schedules_inx-sched_line  = '0001'.
  lt_schedules_inx-updateflag  = 'X'.
  lt_schedules_inx-req_qty     = 'X'.
  APPEND lt_schedules_inx.

* Call the BAPI to create the sales order.
* Since 4.6C this BAPI is outdated. Use BAPI_SALESORDER_CREATEFROMDAT2 instead.
  CALL FUNCTION 'BAPI_SALESDOCU_CREATEFROMDATA1'
       EXPORTING
            sales_header_in     = header
            sales_header_inx    = headerx
       IMPORTING
            salesdocument_ex    = v_vbeln
       TABLES
            return              = return
            sales_items_in      = item
            sales_items_inx     = itemx
            sales_schedules_in  = lt_schedules_in
            sales_schedules_inx = lt_schedules_inx
            sales_partners      = partner.

* Check the return table.
  LOOP AT return WHERE type = 'E' OR type = 'A'.
    EXIT.
  ENDLOOP.

  IF sy-subrc = 0.

    WRITE: / 'Error in creating document'.

  ELSE.

* Commit the work.
    COMMIT WORK AND WAIT.

    WRITE: / 'Document ', v_vbeln, ' created'.

  ENDIF.

REPORT  zalv_oops.

* declaration of variables.

TYPE-POOLS: slis.
TABLES: vbak,vbap.


*Global variables to be used for ALV Grid.

*--- ALV Grid instance reference
DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid .
*--- Name of the custom control added on the screen
DATA gc_custom_control_name TYPE scrfname VALUE 'CUSTOM_CONTROL' .
*--- Custom container instance reference
DATA gr_ccontainer TYPE REF TO cl_gui_custom_container .
*--- Field catalog table
DATA gt_fieldcat TYPE lvc_t_fcat .
*--- Layout structure
DATA gs_layout TYPE lvc_s_layo .
*--- Flag to check validation - Initially set to S (Success)
DATA gv_valid_flag TYPE c VALUE 'S'.
*--- Flag to set the color of field VOREF - Initially set to F (False)
DATA gv_flag TYPE c VALUE 'F'.


*Internal Table declaration.

DATA: BEGIN OF t_vbak OCCURS 0,

    vbeln TYPE vbak-vbeln,
    vbtyp TYPE vbak-vbtyp,
    vkorg TYPE vbak-vkorg,
    vtweg TYPE vbak-vtweg,
    spart TYPE vbak-spart,
    erdat TYPE vbak-erdat,
    ernam TYPE vbak-ernam,

END OF t_vbak.

DATA: BEGIN OF t_vbap OCCURS 0,
      vbeln TYPE vbap-vbeln,
      posnr TYPE vbap-posnr,
      matnr TYPE vbap-matnr,
      lgort TYPE vbap-lgort,
      vstel TYPE vbap-vstel,
      prctr TYPE vbap-prctr,
      aufnr TYPE vbap-aufnr,
      voref TYPE vbap-voref,
      zmeng TYPE vbap-zmeng,
      netpr TYPE vbap-netpr,

END OF t_vbap.

DATA: BEGIN OF t_output OCCURS 0 ,
      vbeln LIKE vbak-vbeln,  "Sales Document number
      posnr LIKE vbap-posnr,  "Sales Document Item
      matnr LIKE vbap-matnr,  "Material njumber
      vbtyp LIKE vbak-vbtyp,  "SD document category
      vkorg LIKE vbak-vkorg,  "SAles Organisation
      vtweg LIKE vbak-vtweg,  "Distribution Channel
      spart LIKE vbak-spart,  "Division
      erdat LIKE vbak-erdat,  "Record Creation date
      ernam LIKE vbak-ernam,  "Person who created record
      lgort LIKE vbap-lgort,  "Storage Location
      vstel LIKE vbap-vstel,  "Shipping /Recieving point
      prctr LIKE vbap-prctr,  "Profit center
      aufnr LIKE vbap-aufnr,  "Order number
      voref LIKE vbap-voref,  "Reference indicator
                              "(Color: Red if X else Green)
      zmeng LIKE vbap-zmeng,  "Target quantity
      netpr LIKE vbap-netpr,  "Net price
      comments(100) TYPE c,   "Comments(Editable)

  END OF t_output.


* Work Area
DATA wa_output LIKE t_output.




*Selection Screen Display.
SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-h01.

SELECT-OPTIONS: s_vbeln FOR vbak-vbeln,
                s_erdat FOR vbak-erdat,
                s_ernam FOR vbak-ernam,
                s_vbtyp FOR vbak-vbtyp,
                s_vkorg FOR vbak-vkorg,
                s_vtweg FOR vbak-vtweg,
                s_spart FOR vbak-spart.

SELECTION-SCREEN : END OF BLOCK b1.


*----------------------------------------------------------------------*
*       CLASS lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION .
  PUBLIC SECTION .
    CLASS-METHODS:

*Double-click control
    handle_double_click
    FOR EVENT double_click OF cl_gui_alv_grid
    IMPORTING e_row e_column.
ENDCLASS.                    "lcl_event_handler DEFINITION


*----------------------------------------------------------------------*
*       CLASS lcl_event_handler IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION .

*Handle Double Click
  METHOD handle_double_click .
    READ TABLE t_output INTO wa_output INDEX e_row-index.
* Display Sales Order on double click.
    IF sy-subrc EQ 0 AND e_column-fieldname EQ 'VBELN'.
      CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
    ENDIF.
  ENDMETHOD .                    "handle_double_click

ENDCLASS.                    "lcl_event_handler IMPLEMENTATION


* validation at Selection Screen.
AT SELECTION-SCREEN.
  PERFORM data_validation.

* Selecting data.
START-OF-SELECTION.

  IF gv_valid_flag NE 'E'.

    SELECT vbeln vbtyp vkorg vtweg spart erdat ernam
     FROM vbak
     INTO CORRESPONDING FIELDS OF TABLE t_vbak
     WHERE vbeln IN s_vbeln AND vkorg IN s_vkorg
            AND vtweg IN s_vtweg
            AND spart IN s_spart AND erdat IN s_erdat
            AND ernam IN s_ernam AND vbtyp IN s_vbtyp.

    IF NOT t_vbak[] IS INITIAL.

      SELECT vbeln posnr matnr lgort vstel prctr aufnr voref zmeng netpr
         INTO CORRESPONDING FIELDS OF TABLE t_vbap
         FROM vbap
         FOR ALL ENTRIES IN t_vbak
         WHERE vbeln = t_vbak-vbeln.
    ENDIF.
  ENDIF.

  t_output[] = t_vbak[].

  IF NOT t_output[] IS INITIAL.
    LOOP AT t_output.
      READ TABLE t_vbap WITH KEY vbeln = t_output-vbeln.
      MOVE t_vbap-posnr TO t_output-posnr.
      MOVE t_vbap-matnr TO t_output-matnr.
      MOVE t_vbap-lgort TO t_output-lgort.
      MOVE t_vbap-vstel TO t_output-vstel.
      MOVE t_vbap-prctr TO t_output-prctr.
      MOVE t_vbap-aufnr TO t_output-aufnr.
      MOVE t_vbap-voref TO t_output-voref.
      MOVE t_vbap-zmeng TO t_output-zmeng.
      MOVE t_vbap-netpr TO t_output-netpr.
      INSERT t_output INDEX sy-tabix.
    ENDLOOP.

  ENDIF.

  IF NOT t_output[] IS INITIAL.
    CALL SCREEN '2000'.
  ELSE.
    MESSAGE 'No data fetched' TYPE 'I'.
  ENDIF.

*  perform display_alv.

*&---------------------------------------------------------------------*
*       FORM display_alv                                              *
*---------------------------------------------------------------------*
FORM display_alv.

  IF gr_alvgrid IS INITIAL .
*----Creating custom container instance
    CREATE OBJECT gr_ccontainer
      EXPORTING
        container_name              = 'CUSTOM_CONTROL'
      EXCEPTIONS
        cntl_error                  = 1
        cntl_system_error           = 2
        create_error                = 3
        lifetime_error              = 4
        lifetime_dynpro_dynpro_link = 5
        OTHERS                      = 6.
    IF sy-subrc <> 0.
*--Exception handling
    ENDIF.

*----Creating ALV Grid instance
    CREATE OBJECT gr_alvgrid
      EXPORTING
        i_parent          = gr_ccontainer
      EXCEPTIONS
        error_cntl_create = 1
        error_cntl_init   = 2
        error_cntl_link   = 3
        error_dp_create   = 4
        OTHERS            = 5.
    IF sy-subrc <> 0.
*--Exception handling
    ENDIF.


*----Preparing layout structure
    PERFORM prepare_layout CHANGING gs_layout .

*----Preparing field catalog.
    PERFORM prepare_field_catalog CHANGING gt_fieldcat .

*----Here will be additional preparations
*--e.g. initial sorting criteria, initial filtering criteria, excluding
*--functions

    CALL METHOD gr_alvgrid->set_table_for_first_display
      EXPORTING
        is_layout                     = gs_layout
      CHANGING
        it_outtab                     = t_output[]
        it_fieldcatalog               = gt_fieldcat
      EXCEPTIONS
        invalid_parameter_combination = 1
        program_error                 = 2
        too_many_lines                = 3
        OTHERS                        = 4.
    IF sy-subrc <> 0.
*--Exception handling
    ENDIF.

  ELSE .

    CALL METHOD gr_alvgrid->refresh_table_display
      EXCEPTIONS
        finished = 1
        OTHERS   = 2.
    IF sy-subrc <> 0.
*--Exception handling
    ENDIF.
  ENDIF .

*--Registering handler methods to handle ALV Grid events

  SET HANDLER lcl_event_handler=>handle_double_click FOR gr_alvgrid.

ENDFORM .                    "display_alv
*&---------------------------------------------------------------------*
*       FORM prepare_fieldcatalo
*
*---------------------------------------------------------------------*
FORM prepare_field_catalog  CHANGING p_fcat TYPE lvc_t_fcat .

  DATA m_fieldcat TYPE lvc_s_fcat .
*creating the field catalog manually

  CLEAR m_fieldcat .
  m_fieldcat-col_pos = '1'.
  m_fieldcat-fieldname = 'VBELN'.
  m_fieldcat-tabname = 'T_SALES'.
  m_fieldcat-seltext = 'Document No.'.
  m_fieldcat-reptext = 'Document No.'.
  APPEND m_fieldcat TO p_fcat.

  CLEAR m_fieldcat .
  m_fieldcat-col_pos = '2'.
  m_fieldcat-fieldname = 'POSNR'.
  m_fieldcat-tabname = 'T_SALES'.
  m_fieldcat-seltext = 'Sales Doc Item'.
  m_fieldcat-reptext = 'Sales Doc Item'.
  APPEND m_fieldcat TO p_fcat.

  CLEAR m_fieldcat .
  m_fieldcat-col_pos = '3'.
  m_fieldcat-fieldname = 'MATNR'.
  m_fieldcat-tabname = 'T_SALES'.
  m_fieldcat-seltext = 'Material Number'.
  m_fieldcat-reptext = 'Material Number'.
  APPEND m_fieldcat TO p_fcat.

  CLEAR m_fieldcat .
  m_fieldcat-col_pos = '4'.
  m_fieldcat-fieldname = 'VBTYP'.
  m_fieldcat-tabname = 'T_SALES'.
  m_fieldcat-seltext = 'SD Doc Category'.
  m_fieldcat-reptext = 'SD Doc Category'.
  APPEND m_fieldcat TO p_fcat.

  CLEAR m_fieldcat .
  m_fieldcat-col_pos = '5'.
  m_fieldcat-fieldname = 'VKORG'.
  m_fieldcat-tabname = 'T_SALES'.
  m_fieldcat-seltext = 'Sales Organisation'.
  m_fieldcat-reptext = 'Sales Organisation'.
  APPEND m_fieldcat TO p_fcat.

  CLEAR m_fieldcat .
  m_fieldcat-col_pos = '6'.
  m_fieldcat-fieldname = 'VTWEG'.
  m_fieldcat-tabname = 'T_SALES'.
  m_fieldcat-seltext = 'Distribution Channel'.
  m_fieldcat-reptext = 'Distribution Channel'.
  APPEND m_fieldcat TO p_fcat.

  CLEAR m_fieldcat .
  m_fieldcat-col_pos = '7'.
  m_fieldcat-fieldname = 'SPART'.
  m_fieldcat-tabname = 'T_SALES'.
  m_fieldcat-seltext = 'Division'.
  m_fieldcat-reptext = 'Division'.
  APPEND m_fieldcat TO p_fcat.

  CLEAR m_fieldcat .
  m_fieldcat-col_pos = '8'.
  m_fieldcat-fieldname = 'ERDAT'.
  m_fieldcat-tabname = 'T_SALES'.
  m_fieldcat-seltext = 'Record creation Date'.
  m_fieldcat-reptext = 'Record creation Date'.
  APPEND m_fieldcat TO p_fcat.

  CLEAR m_fieldcat .
  m_fieldcat-col_pos = '9'.
  m_fieldcat-fieldname = 'ERNAM'.
  m_fieldcat-tabname = 'T_SALES'.
  m_fieldcat-seltext = 'Record Created By'.
  m_fieldcat-reptext = 'Record Created By'.
  APPEND m_fieldcat TO p_fcat.

  CLEAR m_fieldcat .
  m_fieldcat-col_pos = '10'.
  m_fieldcat-fieldname = 'LGORT'.
  m_fieldcat-tabname = 'T_SALES'.
  m_fieldcat-seltext = 'Storage location'.
  m_fieldcat-reptext = 'Storage location'.
  APPEND m_fieldcat TO p_fcat.

  CLEAR m_fieldcat .
  m_fieldcat-col_pos = '11'.
  m_fieldcat-fieldname = 'VSTEL'.
  m_fieldcat-tabname = 'T_SALES'.
  m_fieldcat-seltext = 'Shipping/Recieving Point'.
  m_fieldcat-reptext = 'Shipping/Recieving Point'.
  APPEND m_fieldcat TO p_fcat.

  CLEAR m_fieldcat .
  m_fieldcat-col_pos = '12'.
  m_fieldcat-fieldname = 'PRCTR'.
  m_fieldcat-tabname = 'T_SALES'.
  m_fieldcat-seltext = 'Profit Center'.
  m_fieldcat-reptext = 'Profit Center'.
  APPEND m_fieldcat TO p_fcat.

  CLEAR m_fieldcat .
  m_fieldcat-col_pos = '13'.
  m_fieldcat-fieldname = 'AUFNR'.
  m_fieldcat-tabname = 'T_SALES'.
  m_fieldcat-seltext = 'Order Number'.
  m_fieldcat-reptext = 'Order Number'.
  APPEND m_fieldcat TO p_fcat.

  CLEAR m_fieldcat .
  m_fieldcat-col_pos = '14'.
  m_fieldcat-fieldname = 'VOREF'.
  m_fieldcat-tabname = 'T_SALES'.
  m_fieldcat-seltext = 'Reference Indicator'.
  m_fieldcat-reptext = 'Reference Indicator'.
  IF gv_flag EQ 'F'.
    m_fieldcat-emphasize = 'C500'.
  ELSE.
    m_fieldcat-emphasize = 'C600'.
  ENDIF.
  APPEND m_fieldcat TO p_fcat.

  CLEAR m_fieldcat .
  m_fieldcat-col_pos = '15'.
  m_fieldcat-fieldname = 'ZMENG'.
  m_fieldcat-tabname = 'T_SALES'.
  m_fieldcat-seltext = 'Target Quantity'.
  m_fieldcat-reptext = 'Target Quantity'.
  APPEND m_fieldcat TO p_fcat.

  CLEAR m_fieldcat .
  m_fieldcat-col_pos = '16'.
  m_fieldcat-fieldname = 'NETPR'.
  m_fieldcat-tabname = 'T_SALES'.
  m_fieldcat-seltext = 'Net Price'.
  m_fieldcat-reptext = 'Net Price'.
  APPEND m_fieldcat TO p_fcat.

  CLEAR m_fieldcat .
  m_fieldcat-col_pos = '17'.
  m_fieldcat-fieldname = 'COMMENTS'.
  m_fieldcat-tabname = 'T_SALES'.
  m_fieldcat-seltext = 'COMMENTS'.
  m_fieldcat-reptext = 'COMMENTS'.
  m_fieldcat-edit = 'X'.
  m_fieldcat-tooltip = text-011.
  m_fieldcat-outputlen = 50.
  APPEND m_fieldcat TO p_fcat.

ENDFORM.                    " prepare_field_catalog
*&---------------------------------------------------------------------*
*&      Form  prepare_layout
*&---------------------------------------------------------------------*
FORM prepare_layout  CHANGING p_gs_layout TYPE lvc_s_layo.
  p_gs_layout-zebra = 'X' .
  p_gs_layout-grid_title = 'Sales Document Details' .
  p_gs_layout-smalltitle = 'X' .
  p_gs_layout-cwidth_opt = 'X' .

* If the field value of Reference Indicator(VOREF) is 'X' then the color
* in the output should be set as red, else green.
  LOOP AT t_output INTO wa_output.
    IF wa_output-voref EQ 'X'.
      gv_flag = 'T'.
    ENDIF.
  ENDLOOP.

ENDFORM.                    " prepare_layout
*&---------------------------------------------------------------------*
*&      Form  data_validation
*&---------------------------------------------------------------------*
*       validate the data on the selection screen
*----------------------------------------------------------------------*
FORM data_validation .
  DATA: v_vbeln LIKE vbak-vbeln,
        v_erdat LIKE vbak-erdat,
        v_ernam LIKE vbak-ernam,
        v_vbtyp LIKE vbak-vbtyp,
        v_vkorg LIKE vbak-vkorg,
        v_vtweg LIKE vbak-vtweg,
        v_spart LIKE vbak-spart.

* validating the Doc number.
  IF NOT s_vbeln IS INITIAL.
    SELECT SINGLE vbeln FROM vbak INTO v_vbeln
      WHERE vbeln EQ s_vbeln-low.

    IF sy-subrc NE 0.
      gv_valid_flag = 'E'.        " validation flag set to Error
      MESSAGE text-012 TYPE 'E'.  " Invalid Sales Doc Number
    ENDIF.
  ENDIF.

* validating the Record creation date.
  IF NOT s_erdat IS INITIAL.
    SELECT SINGLE erdat FROM vbak INTO v_erdat
      WHERE erdat EQ s_erdat-low.
    IF sy-subrc NE 0.
      gv_valid_flag = 'E'.        " validation flag set to Error
      MESSAGE text-013 TYPE 'E'.  " Invalid Record creation date
    ENDIF.
  ENDIF.

* validating the Person who created the record.
  IF NOT s_ernam IS INITIAL.
    SELECT SINGLE ernam FROM vbak INTO v_ernam
      WHERE ernam EQ s_ernam-low.
    IF sy-subrc NE 0.
      gv_valid_flag = 'E'.        " validation flag set to Error
      MESSAGE text-014 TYPE 'E'.  " Invalid Person creating record
    ENDIF.
  ENDIF.

* validating the Document category type.
  IF NOT s_vbtyp IS INITIAL.
    SELECT SINGLE vbtyp FROM vbak INTO v_vbtyp
      WHERE vbtyp EQ s_vbtyp-low.
    IF sy-subrc NE 0.
      gv_valid_flag = 'E'.        " validation flag set to Error
      MESSAGE text-015 TYPE 'E'.  " Invalid doc category
    ENDIF.
  ENDIF.

* validating the Sales Organization.
  IF NOT s_vkorg IS INITIAL.
    SELECT SINGLE vkorg FROM vbak INTO v_vkorg
      WHERE vkorg EQ s_vkorg-low.
    IF sy-subrc NE 0.
      gv_valid_flag = 'E'.        " validation flag set to Error
      MESSAGE text-016 TYPE 'E'.  " Invalid Sales Organisation
    ENDIF.
  ENDIF.

* validating the distribution channel.
  IF NOT s_vtweg IS INITIAL.
    SELECT SINGLE vtweg FROM vbak INTO v_vtweg
      WHERE vtweg EQ s_vtweg-low.
    IF sy-subrc NE 0.
      gv_valid_flag = 'E'.        " validation flag set to Error
      MESSAGE text-017 TYPE 'E'.  " Invalid Distribution channel
    ENDIF.
  ENDIF.

* validating the Division.
  IF NOT s_spart IS INITIAL.
    SELECT SINGLE spart FROM vbak INTO v_spart
      WHERE spart EQ s_spart-low.
    IF sy-subrc NE 0.
      gv_valid_flag = 'E'.        " validation flag set to Error
      MESSAGE text-018 TYPE 'E'.  " Invalid Division
    ENDIF.
  ENDIF.
ENDFORM.                    " data_validation
*&---------------------------------------------------------------------*
*&      Module  STATUS_2000  OUTPUT
*&---------------------------------------------------------------------*
MODULE status_2000 OUTPUT.
  SET PF-STATUS 'Z101756_ALV_OOPS'.
  SET TITLEBAR 'Sales Records'.

  PERFORM display_alv.

*if the data fetched successfully for the selection criteria entered by
*the user,the subroutine to display the ALV grid output is called

ENDMODULE.                 " STATUS_2000  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_2000  INPUT
*&---------------------------------------------------------------------*
MODULE user_command_2000 INPUT.
  IF sy-ucomm EQ 'BACK'.
    LEAVE TO SCREEN 0.
  ENDIF.
ENDMODULE.                 " USER_COMMAND_2000  INPUT
*&---------------------------------------------------------------------*
*&      Form  handle_double_click
*&---------------------------------------------------------------------*
FORM handle_double_click  USING     i_row TYPE lvc_s_row
                                    i_column TYPE lvc_s_col
                                    is_row_no TYPE lvc_s_roid.


ENDFORM.                    " handle_double_click
 

Author: name as link to Business Card
Submitted: <date>
Related Links:

  • <link>

Description

In the following VB code, SAP BAPI_SALESORDER_CHANGE is called from an external VB application to change the 'Requested Delivery Date'. The BAPI documentation states to enter 'U' in the UPDATEFLAG field in ORDER_HEADER_INX structure but at the same time, we need to specify the field to change by inserting 'X' in corresponding field of ORDER_HEADER_INX structure. Following code will show how to input the modify parameters of the fields required.

'--------
'--------
'SOME VARIABLE DECLARATION AND ASSIGNMENTS
'--------
Dim obSAPFnCntrl As Object
Dim obSAPConn As Object
'Creating SAP Function object
obSAPFnCntrl = CreateObject("SAP.Functions")
'Creating Connection Object to connect to SAP
obSAPConn = obSAPFnCntrl.
Connection
'SET CONNECTION PARAMETERS WITH PRE ASSIGNED VARIABLES
obSAPConn.ApplicationServer = CNT_STR_APPLN_SRVR
obSAPConn.SystemNumber = CNT_STR_SYS_NUM
obSAPConn.User = CNT_STR_USR
obSAPConn.Password = CNT_STR_PWD
obSAPConn.Language = CNT_STR_LOGON_LANG
obSAPConn.Client = CNT_STR_CLIENT
'NOW CONNECT TO R/3
If obSAPConn.
Logon(0, True) = False Then
MsgBox("SAP Logon Failed")
obSAPConn = Nothing
obSAPFnCntrl = Nothing
Else
MsgBox("SAP Logon Succeeded")
End If
'create a BAPI function object
Dim obSAP_CalledBAPI As Object
obSAP_CalledBAPI = obSAPFnCntrl.Add("BAPI_SALESORDER_CHANGE")
'export parameter with assignment - CHAR 10
obSAP_CalledBAPI.Exports("SALESDOCUMENT").Value = "5000539446"
'EXPORT PARAMETER - ONLY FIELD NEEDS CHANGE IN ORDER_HEADER_IN.
obSAP_CalledBAPI.Exports("ORDER_HEADER_INX").Value("REQ_DATE_H") = 20080808
'EXPORT PARAMETER - FIELDS NEED TO CHANGE IN ORDER_HEADER_INX.
obSAP_CalledBAPI.Exports("ORDER_HEADER_INX").Value("UPDATEFLAG") = "U"
obSAP_CalledBAPI.Exports("ORDER_HEADER_INX").Value("REQ_DATE_H") = "X"
'TABLES PARAMETER
Dim obSAP_Tbl_Return As Object
obSAP_Tbl_Return = obSAP_CalledBAPI.Tables("RETURN")
'NOW CALL THE BAPI & COMMIT - BANG!
If obSAP_CalledBAPI.
Call = False Then
MsgBox("BAPI Call failed")
Else
MsgBox("BAPI Call successful")
Dim obCommit As Object
   'WE NEED TO CALL THIS BAPI EXPLICITLY TO COMMIT
   obCommit = obSAPFnCntrl.Add("BAPI_TRANSACTION_COMMIT")
   If obCommit.Call = False Then
      MsgBox("Commit Failed")
   Else
      MsgBox("Commit successful")
   End If
End If
'CHECK THE RETURN CODES & MESSAGE
MsgBox(obSAP_Tbl_Return.
Value(1, 4))
'LOGOFF & OBJECTS CLEANUP CODES
'------------
'------------

The following program attempts to delete the sales document flow in an SD document. This program was copied from the standard program - WS_CORR_VBFA_LIEF_LPI - which was used to delete the document flow of an inconsistent sales document. The reason for creating this was because we had originally automated the delivery process, however the material document which was created on PGI was archived ( due to wrong selection of the function module :(  ) . To offset this the following had to be done to the sales orders :

(1) Run the delivery deletion program

(2) Reset the status of the items in the sales orders (manually)

(3) Create the delivery and PGI

I had checked a lot of forums, but none gave a conclusive answer. Note - the original Delivery number is not deleted, but rather converted into a delivery with no items.

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

TABLES: vbfa, vbuk, vbup.

INCLUDE vblpdata.
INCLUDE vblkdata.
INCLUDE v50rmacro.

DATA: BEGIN OF lt_likp OCCURS 10,
           vbeln LIKE likp-vbeln,
           likp_subrc LIKE sy-subrc,
           vbuk_subrc LIKE sy-subrc,
      END   OF lt_likp.

SELECT-OPTIONS: s_vbeln  FOR vbfa-vbelv MEMORY ID auf.
PARAMETER :     p_del TYPE likp-vbeln.
PARAMETERS:     p_test        DEFAULT 'X'.

DATA:   vbtyp_li_j(1)  VALUE 'J',                 " Lieferscheine
        vbtyp_li_t(1)  VALUE 'T',                 " Lieferscheine
        lips_subrc     LIKE sy-subrc,
        likp_subrc     LIKE sy-subrc,
        vbuk_subrc     LIKE sy-subrc,
        vbup_subrc     LIKE sy-subrc,
        kz_erster_durchlauf.

* Für alle spezifizierten Belegflüsse...
SELECT * FROM vbfa
         WHERE vbelv IN s_vbeln           AND
               ( vbtyp_n = vbtyp_li_j  OR
                 vbtyp_n = vbtyp_li_t    ).
  IF kz_erster_durchlauf IS INITIAL.
    kz_erster_durchlauf = 'X'.
    SET PARAMETER ID 'AUF' FIELD vbfa-vbelv.
  ENDIF.

*   Status Kopf
  SELECT SINGLE * FROM vbuk
         WHERE  vbeln = vbfa-vbeln.
  vbuk_subrc = sy-subrc.
*   Status Position
  SELECT SINGLE * FROM vbup
         WHERE  vbeln = vbfa-vbeln  AND
                posnr = vbfa-posnn.
  vbup_subrc = sy-subrc.

*Set for deletion of delivery document.
*   Kopf
  SELECT SINGLE * FROM likp
         WHERE  vbeln = vbfa-vbeln.
  IF likp-vbeln EQ p_del.
    likp_subrc = '4'.
  ENDIF.

*   Position
  SELECT SINGLE * FROM lips
         WHERE vbeln = vbfa-vbeln  AND
               posnr = vbfa-posnn.
  lips_subrc = sy-subrc.

  &mr_set_off.
  IF vbuk_subrc <> 0 OR vbup_subrc <> 0 OR
     likp_subrc <> 0 OR lips_subrc <> 0.
*     Zum Belegfluß-Satz fehlt mindestens ein Lieferungs-Segment.
*     Belegfluß-Satz, Positionsstatus und Position werden gelöscht
    WRITE: / 'Preceding doc.: ',  vbfa-vbelv, vbfa-posnv,
             'Subsequent doc.: ', vbfa-vbeln, vbfa-posnn,
                                  vbfa-vbtyp_n.
    IF p_test = ' '.
      DELETE vbfa FROM vbfa.                      " Belegfluß löschen
      WRITE / 'VBFA deleted'.
    ELSE.
      WRITE / 'VBFA to be deleted'.
    ENDIF.

    IF vbuk_subrc <> 0.
      WRITE / 'VBUK missing'.
    ENDIF.

    IF likp_subrc <> 0.
      WRITE / 'LIKP missing'.
    ENDIF.

    IF vbup_subrc = 0.
      IF p_test = ' '.
        DELETE vbup FROM vbup.              " Positionsstatus löschen
        WRITE / 'VBUP deleted'.
      ELSE.
        WRITE / 'VBUP to be deleted'.
      ENDIF.
    ELSE.
      WRITE / 'VBUP missing'.
    ENDIF.

    IF lips_subrc = 0.
      IF p_test = ' '.
        DELETE lips FROM lips.                     " Position löschen
        WRITE / 'Lips deleted'.
      ELSE.
        WRITE / 'Lips to be deleted'.
      ENDIF.
    ELSE.
      WRITE / 'LIPS missing'.
    ENDIF.

*     Sammeln Lieferung zum späteren Status-update
    CLEAR lt_likp.
    lt_likp-vbeln      = vbfa-vbeln.
    lt_likp-likp_subrc = likp_subrc.
    lt_likp-vbuk_subrc = vbuk_subrc.
    COLLECT lt_likp.     "Sammeln Lieferung zum späteren Status-update
  ENDIF.
ENDSELECT.

IF sy-subrc <> 0.
  WRITE:/ 'No documentflow for these orders.'.
  EXIT.
ELSE.
  READ TABLE lt_likp INDEX 1 TRANSPORTING NO FIELDS.
  IF sy-subrc <> 0.
    WRITE:/ 'No inconsistencies found.'.
    EXIT.
  ENDIF.
ENDIF.
&mr_set_on.

* Status-update für Lieferungen, deren Belegfluß geändert wurde.
CHECK p_test = ' '.
LOOP AT lt_likp.
  IF lt_likp-likp_subrc <> 0 OR
     lt_likp-vbuk_subrc <> 0.
    WRITE: / text-001,
             lt_likp-vbeln.
    CONTINUE.
  ENDIF.

*   Initialisierung für Status neu bestimmen.
  PERFORM no_dequeue(sapmv50a) IF FOUND.
  PERFORM lieferungsupdate_extern_init(sapmv50a) IF FOUND.
  PERFORM transaktion_init(sapmv50a) USING 'VL02' IF FOUND.
  PERFORM lieferungsupdate_extern_init(sapmv50a) IF FOUND.
  PERFORM synchron(sapmv50a) IF FOUND.
  PERFORM nicht_sperren(sapmv50a) IF FOUND.
  PERFORM no_messages_update(sapmv50a) IF FOUND.
  PERFORM aufrufer_transport(sapmv50a) IF FOUND.
  likp-vbeln = lt_likp-vbeln.

  PERFORM beleg_lesen(sapmv50a).
  SORT xlips BY mandt vbeln posnr.
  REFRESH ilips.
  LOOP AT xlips.
    lips = xlips.
    PERFORM ilips_anlegen(sapfv50p) USING sy-tabix.
  ENDLOOP.
  SORT ilips BY posnr.
  REFRESH ilips.
  LOOP AT xlips.
    ilips-posnr = xlips-posnr.
    ilips-tabix = sy-tabix.
    APPEND ilips.
  ENDLOOP.

  LOOP AT xlips.
    slips-tabix = sy-tabix.
    lips = xlips.
     *lips = lips.
    PERFORM lips_referenz_lesen(sapfv50p).
    PERFORM lips_bearbeiten_vorbereiten(sapfv50p).
    PERFORM lips_bearbeiten(sapfv50p).
  ENDLOOP.
  PERFORM position_gewichtsupdate_chsp(sapfv50p) USING space.
  PERFORM beleg_sichern(sapmv50a) USING 'X'.
  COMMIT WORK.
ENDLOOP.

IF p_test NE 'X'.

*Delete the material document entries from the flow document
  DELETE FROM vbfa WHERE vbelv IN s_vbeln AND vbtyp_n = 'R'.

ENDIF.
REPORT  zjenni_bapi_salesorder_create.

*-------------------------Data Declaration-----------------------------*
DATA: st_bapisdhead LIKE bapisdhead, " Sales Order Header Data
      ta_bapiitemin LIKE bapiitemin OCCURS 0 WITH HEADER LINE, " Ln item
      ta_bapipartnr LIKE bapipartnr OCCURS 0 WITH HEADER LINE, " Partner
      d_bapireturn1 LIKE bapireturn1, " Bapi return msg
      d_vbeln LIKE bapivbeln-vbeln. " Sales Order Number

* Move the data to create sales order in the repective parameters------*
MOVE: 'TA' TO st_bapisdhead-doc_type, " Sales document type
      '15493' TO st_bapisdhead-purch_no_c,
      '00010' TO ta_bapiitemin-itm_number,
      'Y-351' TO ta_bapiitemin-material,
      '1100' TO ta_bapiitemin-plant,
      '1' TO ta_bapiitemin-req_qty,
      'AG' TO ta_bapipartnr-partn_role, " Sold to Party
      '0000007777' TO ta_bapipartnr-partn_numb.

* Append the internal tables-------------------------------------------*
APPEND ta_bapipartnr.
CLEAR ta_bapipartnr.
APPEND ta_bapiitemin.
CLEAR ta_bapiitemin.

* Move ship to party---------------------------------------------------*
MOVE: 'RG' TO ta_bapipartnr-partn_role, " Ship to party
      '0000007777' TO ta_bapipartnr-partn_numb.

* Append the internal tables-------------------------------------------*
APPEND ta_bapipartnr.
CLEAR ta_bapipartnr.


* Call the Bapi to create the sales order
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT1'
  EXPORTING
    order_header_in = st_bapisdhead
  IMPORTING
    salesdocument   = d_vbeln
    return          = d_bapireturn1
  TABLES
    order_items_in  = ta_bapiitemin
    order_partners  = ta_bapipartnr.

IF d_vbeln <> space.
  WRITE: 'Sales order No. ', d_vbeln.
ELSE.
  WRITE: 'No data'.
  WRITE: / d_bapireturn1.
ENDIF.
 

The code below was developed to take the material details as input and create the documents using the bapi's. This function module was called separately from a another function module in a separate task. This function module was used in responding to a mobile device.

Description

/* your snippet */

 
FUNCTION z_gsesdfm_cb_createord .

*"----------------------------------------------------------------------

*"*"Local Interface:

*"  IMPORTING

*"     VALUE(HEADER_DATA) TYPE  ZGSESDSS_HEADER_DATA

*"     VALUE(ITEM_DATA) TYPE  ZGSESDTT_ITEM_DATA

*"  EXPORTING

*"     VALUE(DGV_PO_NUMBER) TYPE  EBELN

*"     VALUE(DGV_VBELN) TYPE  VBELN

*"     VALUE(DGV_DELIVERY) TYPE  VBELN

*"     VALUE(DGV_INVOICE) TYPE  VBELN

*"     VALUE(STATUS) TYPE  BAPIRET2_T

*"----------------------------------------------------------------------





***REFRESH INTERNAL TABLES *****************************************************************************************************************************

  REFRESH : dgmst_bapiitemin,

            dgmst_bapipartnr,

            dgmst_bapiitemex,

            dgmst_rett,

            dgmst_salesdocument,

            dgmst_xkomfk,

            dgmst_xvbfs,

            dgmst_xvbss,

            dgmst_xkomv,

            dgmst_xthead,

            dgmst_xvbpa,

            dgmst_xvbrk,

            dgmst_xvbrp,

            dgmst_return_deli,

            dgmst_salesdocument_deli,

            dgmst_status_t,

            dgmst_vbpok_tab.

***CLEAR VARIABLES AND WORK-AREA*****************************************************************************************************************************

  CLEAR :   dgmss_bapisdhead,

            dgmss_bapiitemin,

            dgmss_bapipartnr,

            dgmss_bapiitemex,

            dgmss_return,

            dgmss_commit_return,

            dgmss_vbpok_tab,

            dgmss_rett,

            dgmss_item,

            dgmss_commit_ret_del,

            dgmss_vbkok_wa,

            dgmss_vbsk_i,

            dgmss_salesdocument_deli,

            dgw_bapiitemin,

            dgw_bapipartnr,

            dgw_bapiitemex,

            dgw_xkomfk,

            dgw_xvbfs,

            dgw_xvbss,

            dgw_xkomv,

            dgw_xthead,

            dgw_xvbpa,

            dgw_xvbrk,

            dgw_xvbrp,

            dgw_itemdata,

            dgw_return_deli,

            dgw_status,

            dgw_salesdocument,

            dgw_rett,

            dgw_vbpok_tab,

            dgv_delivery,

            dgw_status_t,

            dgv_ship_point.



***PURCHASE ORDER NUMBER*******************************************************************************************************************************

  dgv_po_number = header_data-purch_no.



****vendor change**************************************************************************************************************************

  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

    EXPORTING

      input  = header_data-partn_numb

    IMPORTING

      output = header_data-partn_numb.





***SALES DOCUMENT CREATION*****************************************************************************************************************************



*********BAPI HEADER STRUCTURE.

*********DOCUMENT-TYPE SALES-ORG DISTRIBUTION-CHANNEL DIVISION PO-METHOD PO-NUMBER

  CLEAR dgmss_bapisdhead.

  dgmss_bapisdhead-doc_type     = 'TA'.

  dgmss_bapisdhead-sales_org    = 'BP01'.

  dgmss_bapisdhead-distr_chan   = '10'.

  dgmss_bapisdhead-division     = '13'.

  dgmss_bapisdhead-po_method    = 'TELE'.

  dgmss_bapisdhead-purch_no     = header_data-purch_no.



*********BAPI PARTNER STRUCTURE.

*********PARTNER-ROLE PARTNER-NUMBER.

  CLEAR dgmss_bapipartnr.

  dgmss_bapipartnr-partn_role = 'AG'.

  dgmss_bapipartnr-partn_numb = header_data-partn_numb.

  APPEND dgmss_bapipartnr TO dgmst_bapipartnr.



*********BAPI ITEM DETAILS STRUCTURE.

*********ITEM NUMBER MATERIAL REQUIRED QUANTITY UNIT NET_VALUE CURRENCY.

  CLEAR dgw_itemdata.



  LOOP AT item_data INTO dgw_itemdata.



    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

      EXPORTING

        input  = dgw_itemdata-material

      IMPORTING

        output = dgw_itemdata-material.



    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

      EXPORTING

        input  = dgw_itemdata-itm_number

      IMPORTING

        output = dgw_itemdata-itm_number.



    dgmss_bapiitemin-itm_number = dgw_itemdata-itm_number.

    dgmss_bapiitemin-material   = dgw_itemdata-material.

    dgmss_bapiitemin-req_qty    = dgw_itemdata-quantity.

    dgmss_bapiitemin-sales_unit = dgw_itemdata-unit.



    dgmss_bapiitemex-itm_number = dgw_itemdata-itm_number.

    dgmss_bapiitemex-material   = dgw_itemdata-material.

    dgmss_bapiitemex-net_value  = dgw_itemdata-amount.

    dgmss_bapiitemex-currency   = dgw_itemdata-currency.



    APPEND dgmss_bapiitemin TO dgmst_bapiitemin.

    APPEND dgmss_bapiitemex TO dgmst_bapiitemex.



    CLEAR : dgmss_bapiitemex,

            dgmss_bapiitemin.



  ENDLOOP.



*********BAPI SALES ORDER CREATION



  CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDATA'

    EXPORTING

      order_header_in          = dgmss_bapisdhead

   IMPORTING

      salesdocument            = dgv_vbeln

*     SOLD_TO_PARTY            =

*     SHIP_TO_PARTY            =

*     BILLING_PARTY            =

      return                   = dgw_status

    TABLES

      order_items_in           = dgmst_bapiitemin

      order_partners           = dgmst_bapipartnr

      order_items_out          = dgmst_bapiitemex

*     ORDER_CFGS_REF           =

*     ORDER_CFGS_INST          =



            .

*********BAPI SALES ORDER CREATION STATUS RETURN.



*  dgv_str_vbeln = dgv_vbeln.

*

*  IF dgw_status IS NOT INITIAL.

*    APPEND dgw_status TO status.

*  elseif dgv_vbeln is not initial.

*    dgw_status-type = 'S'.

*    concatenate dgv_str_vbeln 'Sales order created' into dgw_status-message.

*    APPEND dgw_status TO status.

*      ENDIF.

*  CLEAR dgw_status.



*********BAPI SALES ORDER COMMIT.

  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

    EXPORTING

      wait   = 'X'

    IMPORTING

      return = dgmss_commit_return.



*********************14-04-2014 - start of change - Updating the values to the custom DB Table*********************************



  IF dgv_vbeln IS NOT INITIAL.

    dgw_status_t-vendor = header_data-partn_numb.

    dgw_status_t-purchase_order = dgv_po_number.

    dgw_status_t-sales_order = dgv_vbeln.

    dgw_status_t-status = 'SALES ORDER CREATED'.



    dgw_status_e-message = 'SALES ORDER CREATED'.

    dgw_status_e-number  = dgv_vbeln.

*************15-04-2014 - Start of Change**********************

    dgw_status_E-id = dgv_vbeln.

    dgw_status_e-type = 'S'. " dgw_status-type.

*************15-04-2014 - End of Change************************

    APPEND dgw_status_t TO dgmst_status_t.

    MODIFY zgsesddt_cbres FROM TABLE dgmst_status_t.

    append dgw_status_e to status.

    CLEAR dgw_status_t.

    CLEAR dgw_status_e.



  ELSE.





    dgw_status_t-status = 'SALES ORDER NOT CREATED'.

    dgw_status_t-purchase_order = dgv_po_number.

    dgw_status_t-sales_order = dgv_vbeln.

    dgw_status_E-id = dgv_vbeln.

    dgw_status_e-type = dgw_status-type.

    dgw_status_e-message = dgw_status-message.

    dgw_status_e-log_no = dgw_status-log_no.

    dgw_status_e-MESSAGE_V1 = dgw_status-MESSAGE_V1.

    dgw_status_e-MESSAGE_V2 = dgw_status-MESSAGE_V2.

    dgw_status_e-MESSAGE_V3 = dgw_status-MESSAGE_V3.

    dgw_status_e-MESSAGE_V4 = dgw_status-MESSAGE_V4.



    APPEND dgw_status_t TO dgmst_status_t.

    append dgw_Status_e to status.

    MODIFY zgsesddt_cbres FROM TABLE dgmst_status_t.

    CLEAR dgw_status_t.

    CLEAR dgw_status_e.

    EXIT.



  ENDIF.

*********************14-04-2014 - End of change - Updating the values to the custom DB Table*********************************



***END OF SALES DOCUMENT CREATION*********************************************************************************************************************

  WAIT UP TO 02 SECONDS.



***DELIVERY DOCUMENT CREATION*****************************************************************************************************************************



*********BAPI PARTNER STRUCTURE.

*********SALES ORDER NUMBER .



  dgmss_salesdocument_deli-ref_doc = dgv_vbeln.

  APPEND dgmss_salesdocument_deli TO dgmst_salesdocument_deli .



*********BAPI DELIVERY ORDER CREATION



  CALL FUNCTION 'BAPI_OUTB_DELIVERY_CREATE_SLS'

   EXPORTING

   ship_point              = 'BP01'

*   DUE_DATE                =

*   DEBUG_FLG               =

*   NO_DEQUEUE              = ' '

   IMPORTING

     delivery                =    dgv_delivery

*   NUM_DELIVERIES          =

    TABLES

      sales_order_items       = dgmst_salesdocument_deli

      return                  = dgmst_return_deli.



*********BAPI DELIVERY ORDER CREATION STATUS CAPTURE

*  LOOP AT dgmst_return_deli INTO dgw_return_deli.

*    APPEND dgw_return_deli TO status.

*  ENDLOOP.

*********BAPI DELIVERY ORDER CREATION COMMIT.

  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

    EXPORTING

      wait = 'X'.

*   IMPORTING

*     return        = dgmss_commit_retURN.



***END OF DELIVERY DOCUMENT CREATION************************************************************************************************************************



*********************14-04-2014 - start of change - Updating the values to the custom DB Table*********************************



  IF dgv_delivery IS NOT INITIAL.

    read table dgmst_status_t into dgw_status_t with key sales_order = dgv_vbeln.

    if sy-subrc = 0 .

    dgw_status_t-delivery = dgv_delivery.

    dgw_status_t-status = 'DELIVERY CREATED'.

    MODIFY dgmst_status_t FROM DGW_STATUS_T INDEX SY-INDEX .

    UPDATE zgsesddt_cbres FROM table dgmst_status_t.

***    PR

    dgw_status_e-message = 'DELIVERY CREATED'.

*    dgw_status_e-number  = dgv_delivery .

    dgw_status_E-id = dgv_delivery.

    dgw_status_e-type = 'S'.

***PR

    append dgw_status_e to status.

    CLEAR dgw_status_e.

    endif.



  ELSE.



    dgw_status_e-message = 'DELIVERY NOT CREATED'.

*    dgw_status_E-id = dgv_i.

    dgw_status_e-type = 'E'.

    append dgw_status_e to status.



    IF DGMST_RETURN_DELI IS NOT INITIAL.

      LOOP AT dgmst_return_deli INTO dgw_return_deli.

        APPEND dgw_return_deli TO status.

      ENDLOOP.

      ENDIF.

      IF SY-SUBRC = 0.

        READ TABLE dgmst_status_t INTO dgw_status_t index sy-index.

    dgw_status_t-status = 'DELIVERY NOT CREATED'.

   APPEND DGW_STATUS_T to dgmst_status_t.

    UPDATE zgsesddt_cbres FROM table dgmst_status_t.

        ENDIF.



    EXIT.



  ENDIF.



*********************14-04-2014 - End of change - Updating the values to the custom DB Table*************************************



***POST GOODS ISSUE*************************************************************************************************************************************



  dgmss_vbkok_wa-vbeln_vl = dgv_delivery.

  dgmss_vbkok_wa-wabuc = 'X'.



  CLEAR: dgw_itemdata,

         dgmss_vbpok_tab,

         dgw_xkomfk,

         dgw_xvbfs.



  LOOP AT item_data INTO dgw_itemdata.



    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

      EXPORTING

        input  = dgw_itemdata-material

      IMPORTING

        output = dgw_itemdata-material.



    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

      EXPORTING

        input  = dgw_itemdata-itm_number

      IMPORTING

        output = dgw_itemdata-itm_number.



    dgmss_vbpok_tab-vbeln_vl = dgv_delivery.

    dgmss_vbpok_tab-posnr_vl = dgw_itemdata-itm_number.

    dgmss_vbpok_tab-matnr = dgw_itemdata-material.

    dgmss_vbpok_tab-werks = 'BP01'.

    dgmss_vbpok_tab-taqui = 'X'.



    APPEND dgmss_vbpok_tab TO dgmst_vbpok_tab.



    dgw_xkomfk-vbeln = dgv_delivery.

    dgw_xkomfk-posnr = dgw_itemdata-itm_number.

    APPEND dgw_xkomfk TO dgmst_xkomfk.



    dgw_xvbfs-vbeln = dgv_delivery.

    dgw_xvbfs-posnr = dgw_itemdata-itm_number.

    APPEND dgw_xvbfs TO dgmst_xvbfs.





    CLEAR : dgmss_vbpok_tab,

            dgw_xkomfk,

            dgw_xvbfs.



  ENDLOOP.



***Post Goods Issue Function Module************



  CALL FUNCTION 'WS_DELIVERY_UPDATE_2'

    EXPORTING

      vbkok_wa                           = dgmss_vbkok_wa

     synchron                           = 'X'

*   NO_MESSAGES_UPDATE_1               = ' '

     commit                             = 'X'

      delivery                           = dgv_delivery

*   UPDATE_PICKING                     = ' '

     nicht_sperren_1                    = 'X'

*   IF_CONFIRM_CENTRAL                 = ' '

*   IF_WMPP                            = ' '

*   IF_GET_DELIVERY_BUFFERED           = ' '

*   IF_NO_GENERIC_SYSTEM_SERVICE       = ' '

     if_database_update_1               = '1'

*   IF_NO_INIT_1                       = ' '

*   IF_NO_READ_1                       = ' '

     if_error_messages_send             = 'X'

*   IF_NO_BUFFER_REFRESH               = ' '

*   IT_PARTNER_UPDATE                  =

*   IT_SERNR_UPDATE                    =

*   IF_NO_REMOTE_CHG_1                 = ' '

*   IF_NO_MES_UPD_PACK                 = ' '

*   IF_LATE_DELIVERY_UPD               = ' '

*   IF_TXT_REINITIALIZE                =

*   IF_BOR_INIT                        = ' '

*   SPE_MES_NO_SEND_NODIAL             =

* IMPORTING

*   EF_ERROR_ANY                       =

*   EF_ERROR_IN_ITEM_DELETION          =

*   EF_ERROR_IN_POD_UPDATE             =

*   EF_ERROR_IN_INTERFACE              =

*   EF_ERROR_IN_GOODS_ISSUE            =

*   EF_ERROR_IN_FINAL_CHECK            =

*   EF_ERROR_PARTNER_UPDATE            =

*   EF_ERROR_SERNR_UPDATE              =

   TABLES

     vbpok_tab                          = dgmst_vbpok_tab

           .

***END OF POST GOODS ISSUE*********************************************************************************************************************

**

**IF DGMST_VBPOK_TAB IS NOT INITIAL.

**

**    dgw_status_e-message = 'PGI DONE'.

**    dgw_status_E-id = 'BAPI'.

**    dgw_status_e-type = 'S'.

**    append dgw_status_e to status.

**

**    else.

**    dgw_status_e-message = 'PGI NOT DONE'.

**    dgw_status_E-id = 'BAPI'.

**    dgw_status_e-type = 'E'.

**    append dgw_status_e to status.

**

**ENDIF.



***INVOICE DOCUMENT CREATION*****************************************************************************************************************************



  dgmss_vbsk_i-smart = 'F'.   "Hardcoded the Mandatory Field.



***Invoice Creation Function Module****************



  CALL FUNCTION 'RV_INVOICE_CREATE'

    EXPORTING

*   DELIVERY_DATE             = 0

*   INVOICE_DATE              = 0

*   INVOICE_TYPE              = '    '

*   PRICING_DATE              = 0

      vbsk_i                    = dgmss_vbsk_i

     with_posting              = 'B'

*   SELECT_DATE               = 0

*   I_NO_VBLOG                = ' '

*   I_ANALYZE_MODE            = ' '

*   ID_UTASY                  = ' '

*   ID_UTSWL                  = ' '

*   ID_UTSNL                  = ' '

*   ID_NO_ENQUEUE             = ' '

*   ID_NEW_CANCELLATION       = ' '

*   I_BLART                   = ' '

* IMPORTING

*   VBSK_E                    =

*   OD_BAD_DATA               =

*   DET_REBATE                =

    TABLES

      xkomfk                    = dgmst_xkomfk

      xkomv                     = dgmst_xkomv

      xthead                    = dgmst_xthead

      xvbfs                     = dgmst_xvbfs

      xvbpa                     = dgmst_xvbpa

      xvbrk                     = dgmst_xvbrk

      xvbrp                     = dgmst_xvbrp

      xvbss                     = dgmst_xvbss .

*   XKOMFKGN                  = XKOMFKGN

*   XKOMFKKO                  = XKOMFKKO.



***********BAPI INVOICE CREATION COMMIT******************************************



  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

    EXPORTING

      wait = 'X'.

*   IMPORTING

*     return        = dgmss_commit_retURN.



**********CAPTURE INVOICE NUMBER.***********************************************



  READ TABLE dgmst_xvbss INTO dgw_xvbss INDEX 1 .

  IF sy-subrc = 0 .

    dgv_invoice = dgw_xvbss-vbeln.

  ENDIF.



*********************14-04-2014 - start of change - Updating the values to the custom DB Table*********************************



  IF dgv_invoice IS NOT INITIAL.

    dgw_status_t-invoice = dgv_invoice.

    dgw_status_t-status = 'SUCCESS'.

    APPEND dgw_status_t TO dgmst_status_t.

    MODIFY zgsesddt_cbres FROM TABLE dgmst_status_t.

    dgw_status_e-message = 'INVOICE CREATED'.

*    dgw_status_e-number  =  dgv_invoice .

    dgw_status_E-id = dgv_invoice.

    dgw_status_e-type = 'S'.

    append dgw_status_e to status.

  ELSE.

    dgw_status_t-status = 'FAILURE'.

    APPEND dgw_status_t TO dgmst_status_t.

    MODIFY zgsesddt_cbres FROM TABLE dgmst_status_t.



    dgw_status_e-message = 'INVOICE NOT CREATED'.

*    dgw_status_E-id = dgv_invoice.

    dgw_status_e-type = 'E'.

    append dgw_status_e to status.



    EXIT.

  ENDIF.



*********************14-04-2014 - End of change - Updating the values to the custom DB Table*************************************



ENDFUNCTION.


 


 


 


 


FUNCTION-POOL zerpsdfg_test.                "MESSAGE-ID ..



*Structure Declaration----------------



DATA :    dgmss_bapisdhead          TYPE bapisdhead,

          dgmss_bapiitemin          TYPE bapiitemin,

          dgmss_bapipartnr          TYPE bapipartnr,

          dgmss_bapiitemex          TYPE bapiitemex,

          dgmss_return              TYPE bapireturn,

          dgmss_commit_return       TYPE bapiret2,

          dgmss_vbpok_tab           TYPE vbpok,

          dgmss_rett                TYPE bapiret2,

          dgmss_item                TYPE bapidlvreftosalesorder,

          dgmss_commit_ret_del      TYPE bapiret2,

          dgmss_vbkok_wa            TYPE vbkok,

          dgmss_vbsk_i              TYPE vbsk,

          dgmss_salesdocument_deli  TYPE bapidlvreftosalesorder,



* Internal table declaration---------------



          dgmst_bapiitemin            LIKE TABLE OF dgmss_bapiitemin,

          dgmst_bapipartnr            LIKE TABLE OF dgmss_bapipartnr,

          dgmst_bapiitemex            LIKE TABLE OF dgmss_bapiitemex,

          dgmst_rett                  LIKE TABLE OF dgmss_rett,

          dgmst_salesdocument         TYPE TABLE OF bapidlvreftosalesorder,

          dgmst_xkomfk                TYPE TABLE OF komfk,

          dgmst_xvbfs                 TYPE TABLE OF vbfs,

          dgmst_xvbss                 TYPE TABLE OF vbss,

          dgmst_xkomv                 TYPE TABLE OF komv,

          dgmst_xthead                TYPE TABLE OF theadvb,

          dgmst_xvbpa                 TYPE TABLE OF vbpavb,

          dgmst_xvbrk                 TYPE TABLE OF vbrkvb,

          dgmst_xvbrp                 TYPE TABLE OF vbrpvb,

          dgmst_return_deli           TYPE TABLE OF  bapiret2,

          dgmst_salesdocument_deli    TYPE TABLE OF bapidlvreftosalesorder,

          dgmst_vbpok_tab             TYPE TABLE OF vbpok,

          dgmst_status_t type table of ZGSESDDT_CBRES,

* Work Area declaration----------

          dgw_bapiitemin              LIKE LINE OF dgmst_bapiitemin,

          dgw_bapipartnr              LIKE LINE OF dgmst_bapipartnr,

          dgw_bapiitemex              LIKE LINE OF dgmst_bapiitemex,

          dgw_xkomfk                  LIKE LINE OF dgmst_xkomfk,

          dgw_xvbfs                   LIKE LINE OF dgmst_xvbfs,

          dgw_xvbss                   LIKE LINE OF dgmst_xvbss,

          dgw_xkomv                   LIKE LINE OF dgmst_xkomv,

          dgw_xthead                  LIKE LINE OF dgmst_xthead,

          dgw_xvbpa                   LIKE LINE OF dgmst_xvbpa,

          dgw_xvbrk                   LIKE LINE OF dgmst_xvbrk,

          dgw_xvbrp                   LIKE LINE OF dgmst_xvbrp,

          dgw_itemdata                TYPE zgsesdss_item_data,

          dgw_return_deli             TYPE bapiret2,

          dgw_status                  TYPE bapireturn,

          dgw_salesdocument           LIKE LINE OF dgmst_salesdocument,

          dgw_rett                    LIKE LINE OF dgmst_rett,

          dgw_vbpok_tab               LIKE LINE OF dgmst_vbpok_tab,

          dgw_status_t                type ZGSESDDT_CBRES,

          DGW_status_e                type BAPIRET2,





* Variable Declaration------



          dgv_delivery                TYPE bapishpdelivnumb-deliv_numb,

          dgv_str_vbeln               type string,

          dgv_str_invo                type string,

          dgv_str_pgi                 type string,

          dgv_ship_point              TYPE bapidlvcreateheader-ship_point.


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

TABLES:  vbak , vbap , vbpa , kna1.

DATA: it_bapi_header LIKE bapisdhead.
DATA: it_bapi_sold_to_party LIKE bapipartnr OCCURS 0 WITH HEADER LINE.
DATA: so_no LIKE bapivbeln-vbeln.
DATA: it_bapi_items_in LIKE bapiitemin OCCURS 0 WITH HEADER LINE.
DATA: it_bapi_return LIKE bapireturn1.

CONTROLS: tab_ctl TYPE TABLEVIEW USING SCREEN 1000.

DATA: BEGIN OF it_so_header OCCURS 0,
        vbeln LIKE vbak-vbeln,
        auart LIKE vbak-auart,
        vkorg LIKE vbak-vkorg,
        vtweg LIKE vbak-vtweg,
        spart LIKE vbak-spart,
      END OF it_so_header.
DATA: BEGIN OF it_so_partner_fn OCCURS 0,
        parvw LIKE vbpa-parvw,
        kunnr LIKE vbpa-kunnr,
      END OF it_so_partner_fn.
DATA: BEGIN OF it_details OCCURS 0,
        matnr LIKE vbap-matnr,
        kwmeng LIKE vbap-kwmeng,
      END OF it_details.
*&---------------------------------------------------------------------*
*&      Module  STATUS_1000  OUTPUT
*&---------------------------------------------------------------------*
MODULE status_1000 OUTPUT.
  SET PF-STATUS 'SOMENU'.
  SET TITLEBAR 'Sales Order'.
ENDMODULE.                 " STATUS_1000  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_1000  INPUT
*&---------------------------------------------------------------------*
MODULE user_command_1000 INPUT.
  CASE sy-ucomm.
    WHEN 'EXIT'.
      SET SCREEN 0.
      LEAVE TO SCREEN 0.
    WHEN 'CAN'.
      SET SCREEN 0.
      LEAVE TO SCREEN 0.
    WHEN 'SAVE'.
      PERFORM pop_it_header.
      PERFORM pop_it_partner_fn.
      PERFORM pop_it_details.
      PERFORM call_bapi.
      PERFORM msg.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_1000  INPUT
*&---------------------------------------------------------------------*
*&      Form  POP_IT_HEADER
*&---------------------------------------------------------------------*
FORM pop_it_header .
  it_bapi_header-doc_type = vbak-auart.
  it_bapi_header-sales_org = vbak-vkorg.
  it_bapi_header-distr_chan = vbak-vtweg.
  it_bapi_header-division = vbak-spart.
*APPEND IT_BAPI_HEADER.
*CLEAR IT_BAPI_HEADER.
ENDFORM.                    " POP_IT_HEADER
*&---------------------------------------------------------------------*
*&      Form  POP_IT_PARTNER_FN
*&---------------------------------------------------------------------*
FORM pop_it_partner_fn .
  it_bapi_sold_to_party-partn_role = vbpa-parvw.
  it_bapi_sold_to_party-partn_numb = vbpa-kunnr.
  APPEND it_bapi_sold_to_party.
  CLEAR it_bapi_sold_to_party.
ENDFORM.                    " POP_IT_PARTNER_FN
*&---------------------------------------------------------------------*
*&      Form  POP_IT_DETAILS
*&---------------------------------------------------------------------*
FORM pop_it_details .
  LOOP AT it_details.
    it_bapi_items_in-material = it_details-matnr .
    it_bapi_items_in-req_qty = it_details-kwmeng.
    APPEND it_bapi_items_in.
    CLEAR it_bapi_items_in.
  ENDLOOP .
ENDFORM.                    " POP_IT_DETAILS
*&---------------------------------------------------------------------*
*&      Module  CREATE_ENTRY  INPUT
*&---------------------------------------------------------------------*
MODULE create_entry INPUT.
  APPEND it_details.
  CLEAR it_details.
ENDMODULE.                 " CREATE_ENTRY  INPUT
*&---------------------------------------------------------------------*
*&      Form  CALL_BAPI
*&---------------------------------------------------------------------*
FORM call_bapi .
  CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT1'
    EXPORTING
      order_header_in = it_bapi_header
    IMPORTING
      salesdocument   = so_no
      return          = it_bapi_return
    TABLES
      order_items_in  = it_bapi_items_in
      order_partners  = it_bapi_sold_to_party.
ENDFORM.                    " CALL_BAPI
*&---------------------------------------------------------------------*
*&      Form  MSG
*&---------------------------------------------------------------------*
FORM msg .
  IF it_bapi_return-type = 'S'.
    MESSAGE i000(znm) WITH it_bapi_return-message.
  ELSEIF it_bapi_return-type = 'E'.
    MESSAGE e000(znm) WITH it_bapi_return-message.
  ELSE.
    MESSAGE i000(znm) WITH so_no.
  ENDIF.
ENDFORM.                    "msg
*---------------------------------------------------------------------*
*Report        : ZContract
*created      : 20.04.2010 14:30:52
*Created By   : kk.adhvaryu
*----------------------------------------------------------------------*
REPORT  : zcontract.

DATA: header LIKE bapisdhd1,
      v_order LIKE bapivbeln-vbeln,
      w_return LIKE bapiret2,
      t_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
      t_items LIKE bapisditm OCCURS 0 WITH HEADER LINE,
      t_itemsx LIKE bapisditmx OCCURS 0 WITH HEADER LINE,
      t_partners LIKE bapiparnr OCCURS 0 WITH HEADER LINE,
      t_conds LIKE bapicond OCCURS 0 WITH HEADER LINE,
      t_condsx LIKE bapicondx OCCURS 0 WITH HEADER LINE,
      t_texts LIKE bapisdtext OCCURS 0 WITH HEADER LINE,
      t_contract LIKE bapictr OCCURS 0 WITH HEADER LINE,
      v_exit.
DATA: gs_wait TYPE bapita-wait.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS:
  p_sp TYPE kunnr,
  p_sh TYPE kunnr,
  p_auart TYPE auart,
  p_vkorg TYPE vkorg,
  p_vtweg TYPE vtweg,
  p_spart TYPE spart,
  p_valid TYPE vlauf_veda,    "Validity period for contract
  p_unitv TYPE kdzeh,         "Unit of val.period
  p_cancel TYPE vkues_veda,   "Cancellation proced.
  p_stat TYPE vbdat_veda,     "Cont.start.dt
  p_end TYPE vndat_veda.      "Cont.end.dt

SELECTION-SCREEN END OF BLOCK b1.

START-OF-SELECTION.
  header-doc_type = p_auart.
  header-sales_org = p_vkorg.
  header-distr_chan = p_vtweg.
  header-division = p_spart.

  t_contract-con_st_dat = p_stat.
  t_contract-con_en_dat = p_end.
  t_contract-val_per = p_valid.
  t_contract-val_per_un = p_unitv.
  t_contract-canc_proc = p_cancel.
  APPEND t_contract.

  SELECT SINGLE msehi FROM t006b
    INTO (t_items-sales_unit)
    WHERE mseh3 = 'PC'
      AND spras = 'E'.

  t_items-itm_number = '000010'.
  t_items-material = 'Q1512'.
  t_items-plant = '2601'.
  t_items-ship_point = '2601'.
  t_items-target_qty = '10.000'.
  t_items-target_qu = 'PC'.
  APPEND t_items.
  t_itemsx-sales_unit = 'X'.
  APPEND  t_itemsx.

*****PARTNERS

  t_partners-partn_role = 'AG'.
  t_partners-partn_numb = p_sp.
  APPEND t_partners.
  t_partners-partn_role = 'RE'.
  t_partners-partn_numb = p_sh .
  APPEND  t_partners.

*** TEXTS ***

  t_texts-text_id = '0002'.
  t_texts-itm_number = '000010'.
  t_texts-langu = 'E'.
*  'EN' TO w_texts-langu_iso,
  t_texts-format_col = '*'.
  t_texts-text_line = ''.
  APPEND t_texts.
  CALL FUNCTION 'BAPI_CONTRACT_CREATEFROMDATA'
    EXPORTING
      contract_header_in      = header
      convert                 = 'X'
    IMPORTING
      salesdocument           = v_order
    TABLES
      return                  = t_return
      contract_items_in       = t_items
      contract_items_inx      = t_itemsx
      contract_partners       = t_partners
      contract_conditions_in  = t_conds
      contract_conditions_inx = t_condsx
      contract_data_in        = t_contract
      contract_text           = t_texts.

  IF t_return[] IS INITIAL.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
    WRITE: 'Sales document', v_order, 'has been created'.
  ELSE.
    LOOP AT t_return INTO w_return.
      CASE w_return-type.
        WHEN 'E'.
          MESSAGE ID w_return-id TYPE 'I' NUMBER w_return-number
            WITH  w_return-message_v1
                  w_return-message_v2
                  w_return-message_v3
                  w_return-message_v4.
          v_exit = 'X'.
        WHEN 'A'.
          MESSAGE ID w_return-id TYPE 'I' NUMBER w_return-number
            WITH  w_return-message_v1
                  w_return-message_v2
                  w_return-message_v3
                  w_return-message_v4.
          v_exit = 'X'.

        WHEN 'I'.

          MESSAGE ID w_return-id TYPE 'I' NUMBER w_return-number
            WITH  w_return-message_v1
                  w_return-message_v2
                  w_return-message_v3
                  w_return-message_v4.

        WHEN 'W'.

          MESSAGE ID w_return-id TYPE 'W' NUMBER w_return-number
            WITH  w_return-message_v1
                  w_return-message_v2
                  w_return-message_v3
                  w_return-message_v4.

        WHEN 'S'.

          MESSAGE ID w_return-id TYPE 'S' NUMBER w_return-number
            WITH  w_return-message_v1
                  w_return-message_v2
                  w_return-message_v3
                  w_return-message_v4.

      ENDCASE.
    ENDLOOP.

  ENDIF.
  IF v_exit = 'X'.
    EXIT.
  ELSE.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.
  ENDIF.
 
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*---------------------------------------------------------------------*
* Report  : ZOPEN_ORD_AGE
* Purpose : Aging analysis of Open Sale orders
* Display balance amount of open sale order with pending days
*Days can not be greater than 998 days
*---------------------------------------------------------------------*

REPORT zopen_ord_age MESSAGE-ID fr NO STANDARD PAGE HEADING
LINE-SIZE 300.

TABLES : vbrp, vbak, vbap, kna1, vbuk, vbpa, vbfa,vbup, bhdgd.

DATA : tot_amt TYPE vbrk-netwr.

DATA  posnr LIKE vbap-posnr.

DATA: BEGIN OF itab_vbak2 OCCURS 0,
      vbeln TYPE vbak-vbeln,           "sales order no
      posnr TYPE vbap-posnr,
      audat TYPE vbak-audat,
      spart TYPE vbak-spart,           " Division
      vkbur TYPE vbak-vkbur,           " Sales office
      kunnr TYPE vbak-kunnr,
      fkrel TYPE vbap-fkrel,
      matkl TYPE vbap-matkl,
      matnr TYPE vbap-matnr,
      werks TYPE vbap-werks,
      days      TYPE i,              " Diff with Key date
      kzwi5 TYPE vbap-kzwi5,
      bal_amt TYPE vbap-kzwi5,
END OF itab_vbak2.

DATA: BEGIN OF itab_vbak3 OCCURS 0,
      vbeln LIKE vbak-vbeln,           "sales order no
      posnr LIKE vbap-posnr,
      audat LIKE vbak-audat,
      spart LIKE vbak-spart,           " Division
      vkbur LIKE vbak-vkbur,           " Sales office
      kunnr LIKE vbak-kunnr,
      name  LIKE kna1-name1,
      matkl LIKE vbap-matkl,
      matnr LIKE vbap-matnr,
      werks LIKE vbap-werks,
      kzwi5 LIKE vbap-kzwi5,
      amt1  TYPE p DECIMALS 2,   " Bal at start of period
      amt2  TYPE p DECIMALS 2,   " Bal at start of period
      amt3  TYPE p DECIMALS 2,   " Bal at start of period
      amt4      TYPE p DECIMALS 2,   " Bal at start of period
      amt5      TYPE p DECIMALS 2,   " Bal at start of period
      amt6      TYPE p DECIMALS 2,   " Bal at start of period
END OF itab_vbak3.

*data declaration for printing day range
DATA: BEGIN OF varueb1,
        feld1(80)   TYPE c,
        feld2(14)   TYPE c,
        feld3(14)   TYPE c,
        feld4(14)   TYPE c,
        feld5(14)   TYPE c,
        feld6(14)   TYPE c,
        feld7(14)   TYPE c,
      END   OF varueb1.

DATA: BEGIN OF varueb2,
        feld1(80)   TYPE c,
        feld2(14)   TYPE c,
        feld3(14)   TYPE c,
        feld4(14)   TYPE c,
        feld5(14)   TYPE c,
        feld6(14)   TYPE c,
        feld7(14)   TYPE c,
      END   OF varueb2.

DATA: varueb3(255),
      varueb4(255),
      vartxt1(40),
      vartxt(40)  TYPE c.
*--------------------------------------------------------------------*
DATA: rp01(2)   TYPE p,                                     "   0
      rp02(2)   TYPE p,                                     "  20
      rp03(2)   TYPE p,                                     "  40
      rp04(2)   TYPE p,                                     "  80
      rp05(2)   TYPE p,                                     " 100
      rp06(2)   TYPE p,                                     "   1
      rp07(2)   TYPE p,                                     "  21
      rp08(2)   TYPE p,                                     "  41
      rp09(2)   TYPE p,                                     "  81
      rp10(2)   TYPE p.                                     " 101

DATA: rc01(4)   TYPE c,                "  0
      rc02(4)   TYPE c,                                     "  20
      rc03(4)   TYPE c,                                     "  40
      rc04(4)   TYPE c,                                     "  80
      rc05(4)   TYPE c,                                     " 100
      rc06(4)   TYPE c,                                     "   1
      rc07(4)   TYPE c,                                     "  21
      rc08(4)   TYPE c,                                     "  41
      rc09(4)   TYPE c,                                     "  81
      rc10(4)   TYPE c.                                     " 101

DATA: col01(15)  TYPE c,
      col02(15)  TYPE c,
      col03(15)  TYPE c,
      col04(15)  TYPE c,
      col05(15)  TYPE c,
      col06(15)  TYPE c.

DATA: waers LIKE t001-waers VALUE 'INR',
      v_name(40),
      v_vkbur(5),
      v_temp(132),
      text_val(172).

*FOR ALV DISPLAY
TYPE-POOLS: slis.
CONSTANTS: formname_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE'.

*Data Decelararion for alv display
DATA: i_fieldtab TYPE slis_t_fieldcat_alv,
      i_heading  TYPE slis_t_listheader,
      i_layout   TYPE slis_layout_alv,
      i_sort     TYPE slis_t_sortinfo_alv,
      i_print    TYPE slis_print_alv,
      i_events   TYPE slis_t_event,
      i_repname  LIKE sy-repid,
      f2code   LIKE sy-ucomm VALUE  '&ETA',
      i_save(1) TYPE c,
      i_exit(1) TYPE c,
      i_variant LIKE disvariant,
      h_text(50).

DATA: w_variant          LIKE disvariant,
      wx_variant         LIKE disvariant,
      w_variant_save(1)  TYPE c,
      w_exit(1) TYPE c,
      w_repid LIKE sy-repid.

*Selection screen declarations
START-OF-SELECTION.
  SELECTION-SCREEN SKIP 1.
  SELECTION-SCREEN BEGIN OF BLOCK v1 WITH FRAME TITLE text-001.
  SELECT-OPTIONS:
                 psal_org FOR vbak-vkorg OBLIGATORY,
                 psal_off FOR vbak-vkbur,
                 pspart FOR vbap-spart OBLIGATORY,
                 werks FOR vbap-werks,
                 pmatkl FOR vbap-matkl,
                 pmatnr FOR vbap-matnr,
                 paudat FOR vbak-audat OBLIGATORY,
                 pord_no FOR vbak-vbeln.

  PARAMETERS : key_date LIKE sy-datum DEFAULT sy-datum.
  SELECTION-SCREEN END OF BLOCK v1.
  SELECTION-SCREEN SKIP 1.

  SELECTION-SCREEN BEGIN OF BLOCK v2 WITH FRAME TITLE text-002.
  SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT 01(30) text-003.
  SELECTION-SCREEN POSITION POS_LOW.
  PARAMETERS:
              day1 LIKE rfpdo1-allgrogr DEFAULT '030'.
  PARAMETERS:
              day2 LIKE rfpdo1-allgrogr DEFAULT '060'.
  PARAMETERS:
              day3 LIKE rfpdo1-allgrogr DEFAULT '090'.
  PARAMETERS:
              day4 LIKE rfpdo1-allgrogr DEFAULT '120'.
  PARAMETERS:
              day5 LIKE rfpdo1-allgrogr DEFAULT '150'.
  SELECTION-SCREEN END OF LINE.

  PARAMETERS: p_vari LIKE disvariant-variant.
  SELECTION-SCREEN END OF BLOCK v2.

  REFRESH: itab_vbak2, itab_vbak3.

INITIALIZATION.
  i_repname = sy-repid.
  REFRESH: i_fieldtab,i_events, i_heading.
  CLEAR: i_fieldtab, i_events, i_heading.
* For variant
  PERFORM init_variant.
  PERFORM variant_default USING p_vari.

*-----------------------------------
* At Selection Screen Value Request
*-----------------------------------
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_vari.
  PERFORM variant_f4 USING p_vari.

AT SELECTION-SCREEN.
  PERFORM variant_fill.

START-OF-SELECTION.

  PERFORM check_days_range.

* For printing day range
* initialization for printing report info
  MOVE '0'      TO bhdgd-inifl.
  MOVE sy-linsz TO bhdgd-lines.
  MOVE sy-uname TO bhdgd-uname.
  MOVE sy-repid TO bhdgd-repid.
  MOVE sy-title TO bhdgd-line1.
  MOVE '    '   TO bhdgd-line2.
  MOVE '1000'   TO bhdgd-bukrs.
  MOVE '    '   TO bhdgd-miffl.
  MOVE '    '   TO bhdgd-separ.
  MOVE 'BUKRS'  TO bhdgd-domai.

  PERFORM print_dayrange.

  SELECT vbeln audat vkorg vtweg vkbur kunnr
         FROM vbak
         INTO
         (vbak-vbeln, vbak-audat, vbak-vkorg,
          vbak-vtweg, vbak-vkbur, vbak-kunnr)
         WHERE vbeln IN pord_no
         AND audat IN paudat
         AND vbtyp = 'C'
         AND vkorg IN psal_org
         AND spart IN pspart
         AND vkbur IN psal_off.

*   authorization object
    AUTHORITY-CHECK OBJECT 'V_VBAK_VKO'
           ID 'VKORG' FIELD vbak-vkorg
           ID 'VTWEG' FIELD vbak-vtweg
           ID 'SPART' FIELD vbak-spart
           ID 'ACTVT' FIELD '03'.
    IF sy-subrc <> 0.
      MESSAGE e208(00) WITH 'No relevant authorizations found'.
    ENDIF.

    IF sy-subrc = 0.
      SELECT posnr matkl matnr fkrel spart werks kzwi5
               FROM vbap INTO
               (itab_vbak2-posnr, itab_vbak2-matkl,
               itab_vbak2-matnr,itab_vbak2-fkrel,itab_vbak2-spart,
               itab_vbak2-werks, itab_vbak2-kzwi5)
               WHERE vbeln = vbak-vbeln .

        CHECK ( itab_vbak2-fkrel = 'A'     "Delivery-related billing doc
             OR itab_vbak2-fkrel = 'D' )   "Relevant for pro forma
          AND itab_vbak2-matkl IN pmatkl
          AND itab_vbak2-matnr IN pmatnr
          AND itab_vbak2-spart IN pspart.

        itab_vbak2-vbeln = vbak-vbeln.
        itab_vbak2-audat = vbak-audat.
        itab_vbak2-vkbur = vbak-vkbur.
        itab_vbak2-kunnr = vbak-kunnr.

        SELECT SINGLE * FROM vbup WHERE vbeln = itab_vbak2-vbeln
                                    AND posnr = itab_vbak2-posnr
                                    AND gbsta NE 'C'.

*       difference in posting date and key date
        itab_vbak2-days = key_date - itab_vbak2-audat.

        IF sy-subrc EQ 0 AND itab_vbak2-days GE 0.

*         For pending amount - sum biling amounts
          SELECT SINGLE vbfa~vbeln vbfa~posnn
                 INTO (vbfa-vbeln, vbfa-posnn)
             FROM vbfa
             WHERE vbelv = itab_vbak2-vbeln
               AND posnv = itab_vbak2-posnr
               AND vbtyp_n = 'M'.

          IF sy-subrc = 0.
            SELECT SINGLE * FROM vbrp WHERE vbeln = vbfa-vbeln
                   AND posnr = vbfa-posnn.
*           get gross bill amount
            itab_vbak2-bal_amt = vbrp-kzwi5.
            APPEND itab_vbak2.
          ENDIF.
          CLEAR itab_vbak2.
        ENDIF.
      ENDSELECT.
    ENDIF.
  ENDSELECT.

* Sorting amount according to posting date in range defined
  PERFORM amount_range TABLES itab_vbak2 itab_vbak3.

END-OF-SELECTION.

  PERFORM fieldcat USING i_fieldtab[].
  PERFORM eventtab USING i_events[].
  PERFORM comment USING i_heading[].
  PERFORM get_final_data.

  FREE: itab_vbak2, itab_vbak3.

*&---------------------------------------------------------------------*
*&      Form  fieldcat
*&---------------------------------------------------------------------*
FORM fieldcat USING p_fieldtab TYPE slis_t_fieldcat_alv.

  DATA: l_fieldcat TYPE slis_fieldcat_alv.
  CLEAR l_fieldcat.

* DATA FIELD CATALOG for DETAIL LIST - Field Description to ALV

  DATA: day11 LIKE rfpdo1-allgrogr,
        day22 LIKE rfpdo1-allgrogr,
        day33 LIKE rfpdo1-allgrogr,
        day44 LIKE rfpdo1-allgrogr,
        day55 LIKE rfpdo1-allgrogr.

  day11 = day1 + 1.
  day22 = day2 + 1.
  day33 = day3 + 1.
  day44 = day4 + 1.
  day55 = day5 + 1.

  CONCATENATE 'To' day1+1(2) INTO col01 SEPARATED BY space.
  CONCATENATE 'Fr' day11+1(2) 'To' day2+1(2) INTO col02
  SEPARATED BY space.
  CONCATENATE 'Fr' day22+1(2) 'To' day3 INTO col03 SEPARATED BY space.
  CONCATENATE 'Fr' day33 'To' day4 INTO col04 SEPARATED BY space.
  CONCATENATE 'Fr' day44 'To' day5 INTO col05 SEPARATED BY space.
  CONCATENATE 'Fr' day55 INTO col06 SEPARATED BY space.

  CLEAR l_fieldcat.
  l_fieldcat-tabname    = 'ITAB_VBAK3'.

  l_fieldcat-fieldname  = 'VKBUR'.
  l_fieldcat-outputlen  = 8.
  l_fieldcat-seltext_l  = 'Sales Off'.
  APPEND l_fieldcat TO p_fieldtab.
  CLEAR l_fieldcat.

  l_fieldcat-fieldname  = 'SPART'.
  l_fieldcat-outputlen  = 2.
  l_fieldcat-seltext_l  = 'Dv'.
  APPEND l_fieldcat TO p_fieldtab.
  CLEAR l_fieldcat.

  l_fieldcat-fieldname  = 'VBELN'.
  l_fieldcat-outputlen  = 8.
  l_fieldcat-no_zero = 'X'.
  l_fieldcat-seltext_l  = 'Doc No'.
  APPEND l_fieldcat TO p_fieldtab.
  CLEAR l_fieldcat.

  l_fieldcat-fieldname  = 'POSNR'.
  l_fieldcat-outputlen  = 3.
  l_fieldcat-no_zero = 'X'.
  l_fieldcat-seltext_l  = 'Item'.
  APPEND l_fieldcat TO p_fieldtab.
  CLEAR l_fieldcat.

  l_fieldcat-fieldname  = 'KUNNR'.
  l_fieldcat-outputlen  = 6.
  l_fieldcat-no_zero = 'X'.
  l_fieldcat-seltext_l  = 'Sold to Party'.
  APPEND l_fieldcat TO p_fieldtab.
  CLEAR l_fieldcat.

  l_fieldcat-fieldname  = 'NAME'.
  l_fieldcat-outputlen  = 12.
  l_fieldcat-seltext_l  = 'Name'.
  APPEND l_fieldcat TO p_fieldtab.
  CLEAR l_fieldcat.

  l_fieldcat-fieldname  = 'MATKL'.
  l_fieldcat-outputlen  = 4.
  l_fieldcat-seltext_l  = 'Mat Group'.
  APPEND l_fieldcat TO p_fieldtab.
  CLEAR l_fieldcat.

  l_fieldcat-fieldname  = 'MATNR'.
  l_fieldcat-outputlen  = 8.
  l_fieldcat-seltext_l  = 'Mat No'.
  l_fieldcat-no_zero = 'X'.
  APPEND l_fieldcat TO p_fieldtab.
  CLEAR l_fieldcat.

  l_fieldcat-fieldname  = 'WERKS'.
  l_fieldcat-outputlen  = 6.
  l_fieldcat-seltext_l  = 'Plant'.
  l_fieldcat-no_zero = ' '.
  APPEND l_fieldcat TO p_fieldtab.
  CLEAR l_fieldcat.

  l_fieldcat-fieldname  = 'KZWI5'.
  l_fieldcat-outputlen  = 13.
  l_fieldcat-seltext_l  = 'Net amount'.
  APPEND l_fieldcat TO p_fieldtab.
  CLEAR l_fieldcat.

  l_fieldcat-fieldname  = 'AMT1'.
  l_fieldcat-outputlen  = 13.
  l_fieldcat-seltext_l  = col01.
  APPEND l_fieldcat TO p_fieldtab.
  CLEAR l_fieldcat.

  IF day1 <> ' '.
    l_fieldcat-fieldname  = 'AMT2'.
    l_fieldcat-outputlen  = 13.
    l_fieldcat-seltext_l  = col02.    "'From 16 To 60'.
    APPEND l_fieldcat TO p_fieldtab.
    CLEAR l_fieldcat.
  ENDIF.
  IF day2 <> ' '.
    l_fieldcat-fieldname  = 'AMT3'.
    l_fieldcat-outputlen  = 13.
    l_fieldcat-seltext_l  = col03.    "'From 61 To 90'.
    APPEND l_fieldcat TO p_fieldtab.
    CLEAR l_fieldcat.
  ENDIF.
  IF day3 <> ' '.
    l_fieldcat-fieldname  = 'AMT4'.
    l_fieldcat-outputlen  = 13.
    l_fieldcat-seltext_l  = col04.     "'From 91 To 180'.
    APPEND l_fieldcat TO p_fieldtab.
    CLEAR l_fieldcat.
  ENDIF.
  IF day4 <> ' '.
    l_fieldcat-fieldname  = 'AMT5'.
    l_fieldcat-outputlen  = 13.
    l_fieldcat-seltext_l  = col05.      "'From 181 To 360'.
    APPEND l_fieldcat TO p_fieldtab.
    CLEAR l_fieldcat.
  ENDIF.
  IF day5 <> ' '.
    l_fieldcat-fieldname  = 'AMT6'.
    l_fieldcat-outputlen  = 13.
    l_fieldcat-seltext_l  = col06.      "'From 360'.
    APPEND l_fieldcat TO p_fieldtab.
    CLEAR l_fieldcat.
  ENDIF.

  CLEAR l_fieldcat.
ENDFORM.                    " FIELDCAT
*&---------------------------------------------------------------------*
*&      Form  EVENTTAB
*&---------------------------------------------------------------------*
FORM eventtab USING p_events TYPE slis_t_event.

  DATA: ls_event TYPE slis_alv_event.
  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
      i_list_type = 0
    IMPORTING
      et_events   = p_events.

  READ TABLE p_events WITH KEY name = slis_ev_top_of_page
                           INTO ls_event.
  IF sy-subrc = 0.
    MOVE formname_top_of_page TO ls_event-form.
    APPEND ls_event TO p_events.
  ENDIF.

ENDFORM.                    " EVENTTAB
*&--------------------------------------------------------------------*
*&      Form  BUILD_LAYOUT
*&--------------------------------------------------------------------*
FORM build_layout USING p_layout TYPE slis_layout_alv.

  p_layout-f2code       = f2code.
  p_layout-zebra        = 'X'.
  p_layout-detail_popup = 'X'.

ENDFORM.                    " BUILD_LAYOUT
*&---------------------------------------------------------------------*
*&      Form  COMMENT
*&---------------------------------------------------------------------*
FORM comment  USING    p_i_heading TYPE slis_t_listheader.

  DATA: hline TYPE slis_listheader,
        hline1 TYPE slis_listheader,
        text(60) TYPE c,
        sep(20) TYPE c,
        yrs(4) TYPE c,
        mnths(2) TYPE c,
        days(2) TYPE c,
        date(10) TYPE c.
  CLEAR: hline, hline1, text.

  hline-typ  = 'H'.

  WRITE : 'Open Sale Order Aging Details' TO hline-info.
  APPEND hline TO i_heading.
  hline1-typ  = 'H'.
*   to convert date format from yyyymmdd to ddmmyyyy
  days  = key_date+6(2).
  mnths = key_date+4(2).
  yrs   = key_date(4).
  CONCATENATE days mnths yrs INTO text SEPARATED BY '.'.
  CONCATENATE 'as on Key Date : ' text INTO text.
  WRITE: text TO hline1-info.
  APPEND hline1 TO i_heading.

ENDFORM.                    " COMMENT

*&--------------------------------------------------------------------*
*&      Form  TOP_OF_PAGE
*&--------------------------------------------------------------------*
FORM top_of_page.
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = i_heading
      i_logo             = 'ALV_REPORT'.

ENDFORM.                    " TOP_OF_PAGE

*&---------------------------------------------------------------------*
*&      Form  CHECK_DAYS_RANGE
*&---------------------------------------------------------------------*
FORM check_days_range .

  IF day1 GT '998'
   OR day2 GT '998'
   OR day3 GT '998'
   OR day4 GT '998'
   OR day5 GT '998'.

*   SET CURSOR FIELD day5.
    MESSAGE e381.
  ENDIF.

  IF NOT day5 IS INITIAL.
    IF  day5 GT day4
    AND day4 GT day3
    AND day3 GT day2
    AND day2 GT day1.
    ELSE.
      MESSAGE e379.
    ENDIF.
  ELSE.
    IF NOT day4 IS INITIAL.
      IF  day4 GT day3
      AND day3 GT day2
      AND day2 GT day1.
      ELSE.
        MESSAGE e379.
      ENDIF.
    ELSE.
      IF NOT day3 IS INITIAL.
        IF  day3 GT day2
        AND day2 GT day1.
        ELSE.
          MESSAGE e379.
        ENDIF.
      ELSE.
        IF NOT day2 IS INITIAL.
          IF  day2 GT day1.
          ELSE.
            MESSAGE e379.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.

ENDFORM.                    " CHECK_DAYS_RANGE
*&---------------------------------------------------------------------*
*&      Form  PRINT_DAYRANGE
*&---------------------------------------------------------------------*
FORM print_dayrange .

  DATA: text(10).

  rp01 = day1.
  rp02 = day2.
  rp03 = day3.
  rp04 = day4.
  rp05 = day5.

  rp06 = rp01 + 1.
  IF NOT rp02 IS INITIAL.
    rp07 = rp02 + 1.
  ENDIF.
  IF NOT rp03 IS INITIAL.
    rp08 = rp03 + 1.
  ENDIF.
  IF NOT rp04 IS INITIAL.
    rp09 = rp04 + 1.
  ENDIF.
  IF NOT rp05 IS INITIAL.
    rp10 = rp05 + 1.
  ENDIF.

  WRITE: rp01 TO rc01.
  IF NOT rp02 IS INITIAL.
    WRITE: rp02 TO rc02.
    MOVE text-202 TO varueb2-feld3.
  ENDIF.
  IF NOT rp03 IS INITIAL.
    WRITE: rp03 TO rc03.
    MOVE text-203 TO varueb2-feld4.
  ENDIF.
  IF NOT rp04 IS INITIAL.
    WRITE: rp04 TO rc04.
    MOVE text-204 TO varueb2-feld5.
  ENDIF.
  IF NOT rp05 IS INITIAL.
    WRITE: rp05 TO rc05.
    MOVE text-205 TO varueb2-feld6.
  ENDIF.
  IF NOT rp06 IS INITIAL.
    WRITE: rp06 TO rc06.
    MOVE text-206 TO varueb1-feld3.
  ENDIF.
  IF NOT rp07 IS INITIAL.
    WRITE: rp07 TO rc07.
    MOVE text-207 TO varueb1-feld4.
  ENDIF.
  IF NOT rp08 IS INITIAL.
    WRITE: rp08 TO rc08.
    MOVE text-208 TO varueb1-feld5.
  ENDIF.
  IF NOT rp09 IS INITIAL.
    WRITE: rp09 TO rc09.
    MOVE text-209 TO varueb1-feld6.
  ENDIF.
  IF NOT rp10 IS INITIAL.
    WRITE: rp10 TO rc10.
    MOVE text-210 TO varueb1-feld7.
  ENDIF.

* Variable
  v_name = ' Order            SOff'.
  v_temp = text-005.
  CONCATENATE v_temp+0(10) v_name  v_temp+10(5) '  SGrp '
              v_temp+20(112)
              INTO text_val.
  MOVE text_val TO varueb1-feld1.

  MOVE text-201 TO varueb2-feld2.

  REPLACE 'RP01' WITH rc01 INTO varueb2.                    "bis   0
  REPLACE 'RP02' WITH rc02 INTO varueb2.                    "bis  20
  REPLACE 'RP03' WITH rc03 INTO varueb2.                    "bis  40
  REPLACE 'RP04' WITH rc04 INTO varueb2.                    "bis  80
  REPLACE 'RP05' WITH rc05 INTO varueb2.                    "bis 100
  REPLACE 'RP06' WITH rc06 INTO varueb1.                    "von   1
  REPLACE 'RP07' WITH rc07 INTO varueb1.                    "von  21
  REPLACE 'RP08' WITH rc08 INTO varueb1.                    "von  41
  REPLACE 'RP09' WITH rc09 INTO varueb1.                    "von  81
  REPLACE 'RP10' WITH rc10 INTO varueb1.                    "von 101

  MOVE text-010 TO varueb3.

  WRITE key_date TO text DD/MM/YY.
  CONDENSE text.
  REPLACE '$STIDA' WITH text INTO varueb3.

  WRITE waers TO text.
  CONDENSE text.
  REPLACE '$SKAL' WITH waers INTO varueb3.

ENDFORM.                    " PRINT_DAYRANGE
*&---------------------------------------------------------------------*
*&      Form  GET_FINAL_DATA
*&---------------------------------------------------------------------*
FORM get_final_data .

  PERFORM build_layout USING i_layout.
  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      i_program_name     = i_repname
      i_internal_tabname = 'INV'
      i_inclname         = i_repname
    CHANGING
      ct_fieldcat        = i_fieldtab.
  IF sy-subrc <> 0.
    WRITE: 'SY-SUBRC: ', sy-subrc, 'REUSE_ALV_FIELDCATALOG_MERGE'.
  ENDIF.

*LIST display
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_interface_check        = ' '
      i_buffer_active          = ' '
      i_callback_program       = i_repname
      i_callback_pf_status_set = ' '
      i_callback_user_command  = 'USER_COMMAND'
      i_structure_name         = 'ITAB_VBAK3'
      is_layout                = i_layout
      it_fieldcat              = i_fieldtab
      it_sort                  = i_sort[]
      i_default                = 'X'
      i_save                   = 'A'
      is_variant               = i_variant
      it_events                = i_events[]
      is_print                 = i_print
    TABLES
      t_outtab                 = itab_vbak3.
  IF sy-subrc <> 0.
    WRITE: 'SY-SUBRC: ', sy-subrc, 'REUSE_ALV_GRID_DISPLAY'.
  ENDIF.

ENDFORM.                    " GET_FINAL_DATA
*&---------------------------------------------------------------------*
*&      Form  AMOUNT_RANGE
*&---------------------------------------------------------------------*
FORM amount_range TABLES i1 LIKE itab_vbak2[]
                         i2 LIKE itab_vbak3[].
  DATA: r_tage TYPE p,
        adj_amt LIKE bsid-wrbtr,
        amt1 LIKE bsid-wrbtr,
        amt2 LIKE bsid-wrbtr,
        amt3 LIKE bsid-wrbtr,
        amt4 LIKE bsid-wrbtr,
        amt5 LIKE bsid-wrbtr,
        amt6 LIKE bsid-wrbtr.

  LOOP AT i1.

    IF i1-bal_amt  > 0.
      r_tage = i1-days.

      IF r_tage <= rp01.
        amt1 = amt1 + i1-bal_amt .
      ELSE.
        IF r_tage <= rp02
        OR rp07 IS INITIAL.
          amt2 = amt2 + i1-bal_amt .
        ELSE.
          IF r_tage <= rp03
          OR rp08 IS INITIAL.
            amt3 = amt3 + i1-bal_amt .
          ELSE.
            IF r_tage <= rp04
            OR rp09 IS INITIAL.
              amt4 = amt4 + i1-bal_amt .
            ELSE.
              IF r_tage <= rp05
              OR rp10 IS INITIAL.
                amt5 = amt5 + i1-bal_amt .
              ELSE.
                amt6 = amt6 + i1-bal_amt .
              ENDIF.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.

    MOVE-CORRESPONDING i1 TO i2.
    i2-amt1 = amt1.
    i2-amt2 = amt2.
    i2-amt3 = amt3.
    i2-amt4 = amt4.
    i2-amt5 = amt5.
    i2-amt6 = amt6.
    SELECT SINGLE kunnr name1 FROM kna1 INTO
       (i2-kunnr, i2-name)
        WHERE kunnr = i1-kunnr.
    APPEND i2.
    CLEAR: amt1, amt2, amt3, amt4, amt5, amt6, i2.
  ENDLOOP.

  FREE i1.

ENDFORM.                    " AMOUNT_RANGE
*&---------------------------------------------------------------------*
*&      Form  init_variant
*&---------------------------------------------------------------------*
FORM init_variant .

  CLEAR: w_variant.
  w_repid = sy-repid.
  w_variant-report = w_repid.
  w_variant-username = sy-uname.
  w_variant_save = 'A'.  " All type

ENDFORM.                    " init_variant
*&---------------------------------------------------------------------*
*&      Form  variant_default
*&---------------------------------------------------------------------*
FORM variant_default  USING p_variant.

  wx_variant = w_variant.

  IF NOT p_variant IS INITIAL.
    wx_variant-variant = p_variant.
  ENDIF.

  CALL FUNCTION 'LVC_VARIANT_DEFAULT_GET'
    EXPORTING
      i_save        = w_variant_save
    CHANGING
      cs_variant    = wx_variant
    EXCEPTIONS
      wrong_input   = 1
      not_found     = 2
      program_error = 3
      OTHERS        = 4.

  CASE sy-subrc.
    WHEN 0.
      p_variant = wx_variant-variant.
    WHEN 2.
      CLEAR p_variant.
  ENDCASE.

ENDFORM.                    " variant_default
*&---------------------------------------------------------------------*
*&      Form  variant_f4
*&---------------------------------------------------------------------*
FORM variant_f4  USING  p_variant.

  CALL FUNCTION 'LVC_VARIANT_F4'
    EXPORTING
      is_variant    = w_variant
      i_save        = w_variant_save
    IMPORTING
      e_exit        = w_exit
      es_variant    = wx_variant
    EXCEPTIONS
      not_found     = 1
      program_error = 2
      OTHERS        = 3.

  IF w_exit IS INITIAL.
    w_variant-variant = wx_variant-variant.
    p_variant  = wx_variant-variant.
  ENDIF.
ENDFORM.                    " variant_f4
*&---------------------------------------------------------------------*
*&      Form  variant_fill
*&---------------------------------------------------------------------*
FORM variant_fill .
  CLEAR w_variant.
  IF p_vari IS INITIAL.
    w_variant-variant = 'STANDARD'.
    w_variant-report = w_repid.
  ELSE.
    w_variant-variant = p_vari.
    w_variant-report = w_repid.

    CALL FUNCTION 'LVC_VARIANT_EXISTENCE_CHECK'
      EXPORTING
        i_save     = w_variant_save
      CHANGING
        cs_variant = w_variant
      EXCEPTIONS
        OTHERS     = 01.

  ENDIF.
ENDFORM.                    " variant_fill

Author: Sujeet Mishra
Submitted: 21/8/2013
Description: Sample OOPS Tree report to display Sales Flow

include z_sales_tree_rpt_top.
include z_sales_tree_class_def.
selection-screen begin of block a0 with frame title text-001.
select-options:
&nbsp; s_erdat for vbak-erdat,
&nbsp; s_ernam for vbak-ernam.
parameters: s_vbtyp like vbfa-vbtyp_n default 'C'.
selection-screen end of block a0.
start-of-selection.
 refresh: itab_data, itab_selection.
 perform update_selection_table tables itab_selection.
perform create_input_table tables itab_data
itab_selection.
if not itab_data is initial.
create object g_application.
 call screen 2000.
 else.
 message i043(z1).
 endif.
end-of-selection.
 include z_sales_tree_forms.
 include z_sales_tree_pbo.
 include z_sale_tree_pai.
\*----------------------------------------------------------------------\*
\* &nbsp; INCLUDE Z_SALES_TREE_CLASS_DEF &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *
\*----------------------------------------------------------------------\*
class lcl_application definition.
 public section.
methods:
 handle_node_double_click
 for event node_double_click
of cl_gui_list_tree
 importing node_key,
 handle_expand_no_children
 for event expand_no_children
of cl_gui_list_tree
 importing node_key,
 handle_item_double_click
 for event item_double_click
 of cl_gui_list_tree
 importing node_key item_name,
 handle_button_click
 for event button_click
 of cl_gui_list_tree
 importing node_key item_name,
 handle_link_click
 for event link_click
 of cl_gui_list_tree
 importing node_key item_name,
 handle_checkbox_change
for event checkbox_change
of cl_gui_list_tree
importing node_key item_name checked.
endclass.
\*---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; CLASS lcl_application IMPLEMENTATION
\*---------------------------------------------------------------------\*
class lcl_application implementation.
&nbsp; method &nbsp;handle_node_double_click.
&nbsp; &nbsp; read table itab_data with key node_key = node_key into wa_data.
&nbsp; &nbsp; if sy-subrc = 0.
&nbsp; &nbsp; &nbsp; select single rfmng rfwrt matnr
&nbsp; &nbsp; &nbsp; &nbsp; into (vbfa-rfmng, vbfa-rfwrt, vbfa-matnr)
&nbsp; &nbsp; &nbsp; &nbsp; from vbfa
&nbsp; &nbsp; &nbsp; &nbsp; where vbelv = wa_data-vbeln
&nbsp; &nbsp; &nbsp; &nbsp; and &nbsp; posnv = wa_data-posnn.
&nbsp; &nbsp; endif.
&nbsp; endmethod.
&nbsp; method &nbsp;handle_item_double_click.
&nbsp; &nbsp; &nbsp; &nbsp;read table itab_data with key node_key = node_key into wa_data.
&nbsp; &nbsp; if sy-subrc = 0.
&nbsp; &nbsp; &nbsp; select single rfmng rfwrt matnr
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;into (vbfa-rfmng, vbfa-rfwrt, vbfa-matnr)
&nbsp; &nbsp; &nbsp; &nbsp; from vbfa
&nbsp; &nbsp; &nbsp; &nbsp; where vbelv = wa_data-vbeln
&nbsp; &nbsp; &nbsp; &nbsp; and &nbsp; posnv = wa_data-posnn.
&nbsp; &nbsp; endif.
&nbsp; endmethod.
&nbsp;method &nbsp;handle_link_click.
&nbsp;endmethod.
&nbsp; method &nbsp;handle_button_click.
&nbsp; endmethod.
&nbsp; &nbsp;method &nbsp;handle_checkbox_change.
&nbsp; &nbsp;endmethod.
&nbsp; method handle_expand_no_children.
&nbsp; &nbsp; data: node_table type treev_ntab,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; node type treev_node,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; item_table type item_table_type,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; item type mtreeitm.
&nbsp; &nbsp; if node_key = 'Child2'. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
&nbsp; &nbsp; &nbsp;clear node.
&nbsp; &nbsp; &nbsp; node-node_key = 'New3'. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; node-relatkey = 'Child2'.
&nbsp; &nbsp; &nbsp; node-relatship = cl_gui_list_tree=>relat_last_child.
&nbsp; &nbsp; &nbsp; append node to node_table.
\* Node with key 'New4'
&nbsp; &nbsp; &nbsp; clear node.
&nbsp; &nbsp; &nbsp; node-node_key = 'New4'. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; node-relatkey = 'Child2'.
&nbsp; &nbsp; &nbsp; node-relatship = cl_gui_list_tree=>relat_last_child.
&nbsp; &nbsp; &nbsp; append node to node_table.
&nbsp;
\* Items of node with key 'New3'
&nbsp; &nbsp; &nbsp; clear item.
&nbsp; &nbsp; &nbsp; item-node_key = 'New3'.
&nbsp; &nbsp; &nbsp; item-item_name = '1'.
&nbsp; &nbsp; &nbsp; item-class = cl_gui_list_tree=>item_class_text.
&nbsp; &nbsp; &nbsp; item-length = 11.
&nbsp; &nbsp; &nbsp; item-usebgcolor = 'X'. "
&nbsp; &nbsp; &nbsp; item-text = 'SAPTROX1'.
&nbsp; &nbsp; &nbsp; append item to item_table.
&nbsp;
&nbsp; &nbsp; &nbsp; clear item.
&nbsp; &nbsp; &nbsp; item-node_key = 'New3'.
&nbsp; &nbsp; &nbsp; item-item_name = '2'.
&nbsp; &nbsp; &nbsp; item-class = cl_gui_list_tree=>item_class_text.
&nbsp; &nbsp; &nbsp; item-alignment = cl_gui_list_tree=>align_auto.
&nbsp; &nbsp; &nbsp; item-font = cl_gui_list_tree=>item_font_prop.
&nbsp; &nbsp; &nbsp; item-text = 'Comment to SAPTROX1'. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
&nbsp; &nbsp; &nbsp; append item to item_table.
\* Items of node with key 'New4'
&nbsp; &nbsp; &nbsp; clear item.
&nbsp; &nbsp; &nbsp; item-node_key = 'New4'.
&nbsp; &nbsp; &nbsp; item-item_name = '1'.
&nbsp; &nbsp; &nbsp; item-class = cl_gui_list_tree=>item_class_text.
&nbsp; &nbsp; &nbsp; item-length = 11.
&nbsp; &nbsp; &nbsp; item-usebgcolor = 'X'. "
&nbsp; &nbsp; &nbsp; item-text = 'SAPTRIXTROX'.
&nbsp; &nbsp; &nbsp; append item to item_table.
&nbsp; &nbsp; &nbsp; clear item.
&nbsp; &nbsp; &nbsp; item-node_key = 'New4'.
&nbsp; &nbsp; &nbsp; item-item_name = '2'.
&nbsp; &nbsp; &nbsp; item-class = cl_gui_list_tree=>item_class_text.
&nbsp; &nbsp; &nbsp; item-alignment = cl_gui_list_tree=>align_auto.
&nbsp; &nbsp; &nbsp; item-font = cl_gui_list_tree=>item_font_prop.
&nbsp; &nbsp; &nbsp; item-text = 'Comment to SAPTRIXTROX'. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "#EC NOTEXT
&nbsp; &nbsp; &nbsp; append item to item_table.
&nbsp; &nbsp; endif.
&nbsp;
&nbsp; &nbsp; call method g_tree->add_nodes_and_items
&nbsp; &nbsp; &nbsp; exporting
&nbsp; &nbsp; &nbsp; &nbsp; node_table = node_table
&nbsp; &nbsp; &nbsp; &nbsp; item_table = item_table
&nbsp; &nbsp; &nbsp; &nbsp; item_table_structure_name = 'MTREEITM'
&nbsp; &nbsp; &nbsp; exceptions
&nbsp; &nbsp; &nbsp; &nbsp;failed = 1
&nbsp; &nbsp; &nbsp; &nbsp; cntl_system_error = 3
&nbsp; &nbsp; &nbsp; &nbsp; error_in_tables = 4
&nbsp; &nbsp; &nbsp; &nbsp; dp_error = 5
&nbsp; &nbsp; &nbsp; &nbsp; table_structure_name_not_found = 6.
&nbsp; &nbsp; if sy-subrc <> 0.
&nbsp; &nbsp; &nbsp; message a000(tree_control_msg).
&nbsp; &nbsp; endif.
&nbsp; endmethod.
endclass.
\*----------------------------------------------------------------------\*
\* &nbsp; INCLUDE Z_SALES_TREE_FORMS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *
\*----------------------------------------------------------------------\*
\*----------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;update_sel_screen_attributes
\*&---------------------------------------------------------------------\*
form update_sel_screen_attributes.
&nbsp; loop at screen.
&nbsp; &nbsp; if screen-group1 = 'SC1'.
&nbsp; &nbsp; &nbsp; screen-intensified = '1'.
&nbsp; &nbsp; &nbsp; modify screen.
&nbsp; &nbsp; endif.
&nbsp; &nbsp; if screen-group1 = 'XXX' and sy-tcode <> 'ZXXX'.
&nbsp; &nbsp; &nbsp; if not sy-tcode = 'ZXX'.
&nbsp; &nbsp; &nbsp; &nbsp; screen-invisible = '1'.
&nbsp; &nbsp; &nbsp; &nbsp; screen-active = '0'.
&nbsp; &nbsp; &nbsp; &nbsp; modify screen.
&nbsp; &nbsp; &nbsp; endif.
&nbsp; &nbsp; endif.
&nbsp; &nbsp; if screen-group1 = 'ECN' and sy-tcode <> 'ZXXX'.
&nbsp; &nbsp; &nbsp; if not sy-tcode = 'ZXX'.
&nbsp; &nbsp; &nbsp; &nbsp; screen-invisible = '1'.
&nbsp; &nbsp; &nbsp; &nbsp; screen-active = '0'.
&nbsp; &nbsp; &nbsp; &nbsp; modify screen.
&nbsp; &nbsp; &nbsp; endif.
&nbsp; &nbsp; endif.
&nbsp; &nbsp; if screen-group1 = 'ECO' and sy-tcode <> 'ZXXX'.
&nbsp; &nbsp; &nbsp; if not sy-tcode = 'ZXX'.
&nbsp; &nbsp; &nbsp; &nbsp; screen-invisible = '1'.
&nbsp; &nbsp; &nbsp; &nbsp; screen-active = '0'.
&nbsp; &nbsp; &nbsp; &nbsp; modify screen.
&nbsp; &nbsp; &nbsp; endif.
&nbsp; &nbsp; endif.
&nbsp;endloop.
endform. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" update_sel_screen_attributes
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;create_and_init_tree
\*&---------------------------------------------------------------------\*
form create_and_init_tree.
&nbsp; data: node_table type treev_ntab,
&nbsp; &nbsp; &nbsp; &nbsp; item_table type item_table_type,
&nbsp; &nbsp; &nbsp; &nbsp; events type cntl_simple_events,
&nbsp; &nbsp; &nbsp; &nbsp; event type cntl_simple_event.
&nbsp; create object g_custom_container
&nbsp; &nbsp; exporting
&nbsp; &nbsp; &nbsp; container_name = 'TREE_CONTROL'
&nbsp; &nbsp; exceptions
&nbsp; &nbsp; &nbsp; cntl_error = 1
&nbsp; &nbsp; &nbsp; cntl_system_error = 2
&nbsp; &nbsp; &nbsp; create_error = 3
&nbsp; &nbsp; &nbsp; lifetime_error = 4
&nbsp; &nbsp; &nbsp; lifetime_dynpro_dynpro_link = 5.
&nbsp; if sy-subrc <> 0.
&nbsp; &nbsp; message a000(tree_control_msg).
&nbsp; endif.
&nbsp; create object g_tree
&nbsp; &nbsp; exporting
&nbsp; &nbsp; &nbsp; parent &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= g_custom_container
&nbsp; &nbsp; &nbsp; node_selection_mode = cl_gui_list_tree=>node_sel_mode_single
&nbsp; &nbsp; &nbsp; item_selection &nbsp; &nbsp; = 'X'
&nbsp; &nbsp; &nbsp; with_headers &nbsp; &nbsp; &nbsp; = ' '
&nbsp; &nbsp; exceptions
&nbsp; &nbsp; &nbsp; cntl_system_error &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 1
&nbsp; &nbsp; &nbsp; create_error &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 2
&nbsp; &nbsp; &nbsp; failed &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 3
&nbsp; &nbsp; &nbsp; illegal_node_selection_mode = 4
&nbsp; &nbsp; &nbsp; lifetime_error &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 5.
&nbsp; if sy-subrc <> 0.
&nbsp; &nbsp; message a000(tree_control_msg).
&nbsp; endif.
&nbsp; event-eventid = cl_gui_list_tree=>eventid_node_double_click.
&nbsp; event-appl_event = 'X'. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "
&nbsp; append event to events.
&nbsp; event-eventid = cl_gui_list_tree=>eventid_item_double_click.
&nbsp; event-appl_event = 'X'.
&nbsp; append event to events.
&nbsp; &nbsp;" expand no children
&nbsp; event-eventid = cl_gui_list_tree=>eventid_expand_no_children.
&nbsp; event-appl_event = 'X'.
&nbsp; append event to events.
&nbsp;
&nbsp; " link click
&nbsp; event-eventid = cl_gui_list_tree=>eventid_link_click.
&nbsp; event-appl_event = 'X'.
&nbsp; append event to events.
&nbsp; &nbsp;" button click
&nbsp; event-eventid = cl_gui_list_tree=>eventid_button_click.
&nbsp; event-appl_event = 'X'.
&nbsp; append event to events.
&nbsp; " checkbox change
&nbsp; event-eventid = cl_gui_list_tree=>eventid_checkbox_change.
&nbsp; event-appl_event = 'X'.
&nbsp; append event to events.
&nbsp;
&nbsp; call method g_tree->set_registered_events
&nbsp; &nbsp; exporting
&nbsp; &nbsp; &nbsp; events = events
&nbsp; &nbsp; exceptions
&nbsp; &nbsp; &nbsp; cntl_error &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 1
&nbsp; &nbsp; &nbsp; cntl_system_error &nbsp; &nbsp; &nbsp; &nbsp; = 2
&nbsp; &nbsp; &nbsp; illegal_event_combination = 3.
&nbsp; if sy-subrc <> 0.
&nbsp; &nbsp;message a000(tree_control_msg).
&nbsp; endif.
\* assign event handlers in the application class to each desired event
&nbsp; set handler g_application->handle_node_double_click for g_tree.
&nbsp; set handler g_application->handle_item_double_click for g_tree.
&nbsp; set handler g_application->handle_expand_no_children for g_tree.
&nbsp; set handler g_application->handle_link_click for g_tree.
&nbsp; set handler g_application->handle_button_click for g_tree.
&nbsp; set handler g_application->handle_checkbox_change for g_tree.
&nbsp; perform build_node_and_item_table using node_table item_table.
&nbsp; call method g_tree->add_nodes_and_items
&nbsp; &nbsp; exporting
&nbsp; &nbsp; &nbsp; node_table = node_table
&nbsp; &nbsp; &nbsp; item_table = item_table
&nbsp; &nbsp; &nbsp; item_table_structure_name = 'MTREEITM'
&nbsp; &nbsp; exceptions
&nbsp; &nbsp; &nbsp;failed &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 1
&nbsp; &nbsp; &nbsp; cntl_system_error &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 3
&nbsp; &nbsp; &nbsp; error_in_tables &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 4
&nbsp; &nbsp; &nbsp; dp_error &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 5
&nbsp; &nbsp; &nbsp; table_structure_name_not_found = 6.
&nbsp; if sy-subrc <> 0.
&nbsp; &nbsp; message a000(tree_control_msg).
&nbsp; endif.
endform. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" create_and_init_tree
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;build_node_and_item_table
\*&---------------------------------------------------------------------\*
form build_node_and_item_table &nbsp;using
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;node_table type treev_ntab
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;item_table type item_table_type.
&nbsp; data: node type treev_node,
&nbsp; &nbsp; &nbsp; &nbsp; item type mtreeitm.
\* Build the node and item table.
&nbsp; loop at itab_data into wa_data.
&nbsp; &nbsp; clear node.
&nbsp; &nbsp; node-node_key = wa_data-node_key.
&nbsp; &nbsp; node-relatkey = wa_data-relatkey.
&nbsp; &nbsp; node-isfolder = wa_data-folder.
&nbsp; &nbsp; if wa_data-relatkey is initial.
&nbsp; &nbsp; &nbsp; clear: node-relatship,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;node-exp_image,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;node-expander.
&nbsp; &nbsp; &nbsp; node-hidden = ' '.
&nbsp; &nbsp; &nbsp; node-disabled = ' '.
&nbsp; &nbsp; else.
&nbsp; &nbsp; &nbsp; node-relatship = cl_gui_list_tree=>relat_last_child.
&nbsp; &nbsp;endif.
&nbsp; &nbsp; append node to node_table.
\* Update Items
&nbsp; &nbsp; clear item.
&nbsp; &nbsp; item-node_key = wa_data-node_key.
&nbsp; &nbsp; item-item_name = '1'.
&nbsp; &nbsp; item-length = 10.
&nbsp; &nbsp; item-class = cl_gui_list_tree=>item_class_text. " Text Item
&nbsp; &nbsp; item-alignment = cl_gui_list_tree=>align_auto.
&nbsp; &nbsp; item-font = cl_gui_list_tree=>item_font_prop.
&nbsp; &nbsp; item-usebgcolor = 'X'.
&nbsp; &nbsp; case wa_data-type.
&nbsp; &nbsp; &nbsp; when 'C'.
&nbsp; &nbsp; &nbsp; &nbsp; item-text = 'ORDER'.
&nbsp; &nbsp; &nbsp; when 'J'.
&nbsp; &nbsp; &nbsp; &nbsp; item-text = 'DELIVERY'.
&nbsp; &nbsp; &nbsp; when 'M'.
&nbsp; &nbsp; &nbsp; &nbsp;item-text = 'INVOICE'.
&nbsp; &nbsp; &nbsp; when '+'.
&nbsp; &nbsp; &nbsp; &nbsp; item-text = 'Payment'.
&nbsp; &nbsp; &nbsp; when 'Q'.
&nbsp; &nbsp; &nbsp; &nbsp; item-text = 'Whse Xfer'.
&nbsp; &nbsp; &nbsp; when 'R'.
&nbsp; &nbsp; &nbsp; &nbsp; item-text = 'Goods Mvmt'.
&nbsp; &nbsp; &nbsp; when 'H'.
&nbsp; &nbsp; &nbsp; &nbsp; item-text = 'Return Gds'.
&nbsp; &nbsp; endcase.
&nbsp; &nbsp; append item to item_table.
&nbsp; &nbsp; &nbsp;clear item.
&nbsp; &nbsp; item-node_key = wa_data-node_key.
&nbsp; &nbsp; item-item_name = '2'.
&nbsp; &nbsp; item-length = 10.
&nbsp; &nbsp; item-class = cl_gui_list_tree=>item_class_text.&nbsp;
&nbsp; &nbsp; item-alignment = cl_gui_list_tree=>align_auto.
&nbsp; &nbsp; item-font = cl_gui_list_tree=>item_font_prop.
&nbsp; &nbsp; item-text = wa_data-vbeln.
&nbsp; &nbsp; append item to item_table.
&nbsp; &nbsp; clear item.
&nbsp; &nbsp;item-node_key = wa_data-node_key.
&nbsp; &nbsp; item-item_name = '3'.
&nbsp; &nbsp; item-length = 6.
&nbsp; &nbsp; item-class = cl_gui_list_tree=>item_class_text.&nbsp;
&nbsp; &nbsp; item-alignment = cl_gui_list_tree=>align_auto.
&nbsp; &nbsp; item-font = cl_gui_list_tree=>item_font_prop.
&nbsp; &nbsp; item-text = wa_data-posnn.
&nbsp; &nbsp; append item to item_table.
&nbsp; &nbsp; clear item.
&nbsp; &nbsp; item-node_key = wa_data-node_key.
&nbsp; &nbsp; item-item_name = '4'.
&nbsp; &nbsp; item-length = 10.
&nbsp; &nbsp; item-class = cl_gui_list_tree=>item_class_text.&nbsp;
&nbsp; &nbsp; item-alignment = cl_gui_list_tree=>align_auto.
&nbsp; &nbsp; item-font = cl_gui_list_tree=>item_font_prop.
&nbsp; &nbsp; item-text = wa_data-rfmng.
&nbsp; &nbsp; append item to item_table.
&nbsp; &nbsp; &nbsp;clear item.
&nbsp; &nbsp; item-node_key = wa_data-node_key.
&nbsp; &nbsp; item-item_name = '5'.
&nbsp; &nbsp; item-length = 10.
&nbsp; &nbsp; item-class = cl_gui_list_tree=>item_class_text. " Text Item
&nbsp; &nbsp; item-alignment = cl_gui_list_tree=>align_auto.
&nbsp; &nbsp; item-font = cl_gui_list_tree=>item_font_prop.
&nbsp; &nbsp; item-text = wa_data-rfwrt.
&nbsp; &nbsp; append item to item_table.
&nbsp; endloop.
endform. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" build_node_and_item_table
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;create_input_table
\*&---------------------------------------------------------------------\*
form create_input_table tables &nbsp; p_itab_data like itab_data
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;p_itab_selection like itab_selection.
&nbsp; data: l_tabix like sy-tabix,
&nbsp; &nbsp; &nbsp; &nbsp;lm_tabix like sy-tabix,
&nbsp; &nbsp; &nbsp; &nbsp; begin of wl_data,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vbeln &nbsp; like vbfa-vbeln,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; posnn &nbsp; like vbfa-posnn,
&nbsp; &nbsp; &nbsp; &nbsp; end of &nbsp;wl_data,
&nbsp; &nbsp; &nbsp; &nbsp; t_counter(4) type n,
&nbsp; &nbsp; &nbsp; &nbsp; t_parent(4) type c,
&nbsp; &nbsp; &nbsp; &nbsp; t_parent1(4) type c,
&nbsp; &nbsp; &nbsp; &nbsp; t_exit type flag,
&nbsp; &nbsp; &nbsp; &nbsp; is_del_data like line of itab_data,
&nbsp; &nbsp; &nbsp; &nbsp; it_inv_data type itab_type occurs 0.
&nbsp;t_counter = 1.
&nbsp; loop at p_itab_selection.
&nbsp; &nbsp; clear: t_parent, t_parent1, t_exit.
&nbsp; &nbsp; refresh it_vbfa.
&nbsp; &nbsp; is_vbc06-vbeln = p_itab_selection-vbeln.
&nbsp; &nbsp; call function 'RV_ORDER_FLOW_INFORMATION'
&nbsp; &nbsp; &nbsp; exporting
&nbsp; &nbsp; &nbsp; &nbsp; aufbereitung &nbsp; &nbsp; &nbsp; &nbsp;= '2'
\* &nbsp; &nbsp; &nbsp; BELEGTYP &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= ' '
&nbsp; &nbsp; &nbsp; &nbsp; comwa &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = is_vbc06
&nbsp; &nbsp; &nbsp; &nbsp; nachfolger &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 'X'
&nbsp; &nbsp; &nbsp; &nbsp; n_stufen &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= '50'
&nbsp; &nbsp; &nbsp; &nbsp; vorgaenger &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 'X'
&nbsp; &nbsp; &nbsp; &nbsp; v_stufen &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= '50'
\* &nbsp; &nbsp; IMPORTING
\* &nbsp; &nbsp; &nbsp; BELEGTYP_BACK &nbsp; &nbsp; &nbsp; =
&nbsp; &nbsp; &nbsp; tables
&nbsp; &nbsp; &nbsp; &nbsp; vbfa_tab &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= &nbsp;it_vbfa
&nbsp; &nbsp; &nbsp; exceptions
&nbsp; &nbsp; &nbsp; &nbsp; no_vbfa &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 1
&nbsp; &nbsp; &nbsp; &nbsp; no_vbuk_found &nbsp; &nbsp; &nbsp; = 2
&nbsp; &nbsp; &nbsp; &nbsp; others &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 3
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .
&nbsp; &nbsp; clear: wa_data.
&nbsp; &nbsp; wa_data-folder = 'X'.
&nbsp; &nbsp; wa_data-node_key = t_counter.
&nbsp; &nbsp; wa_data-relatkey = t_parent.
&nbsp; &nbsp; wa_data-type &nbsp; &nbsp; = p_itab_selection-vbtyp.
&nbsp; &nbsp; wa_data-vbeln &nbsp; &nbsp;= p_itab_selection-vbeln.
&nbsp; &nbsp; wa_data-posnn &nbsp; &nbsp;= '0'.
&nbsp; &nbsp; append wa_data to p_itab_data.
&nbsp; &nbsp; t_parent = t_counter.
&nbsp; &nbsp; add 1 to t_counter.
\*Find any deliveries for this order
&nbsp; &nbsp; loop at it_vbfa where vbtyp_n = 'J'. &nbsp; &nbsp; &nbsp;" Delivery
&nbsp; &nbsp; &nbsp; clear: wa_data.
&nbsp; &nbsp; &nbsp; wa_data-folder = 'X'.
&nbsp; &nbsp; &nbsp; wa_data-node_key = t_counter.
&nbsp; &nbsp; &nbsp; wa_data-relatkey = t_parent.
&nbsp; &nbsp; &nbsp; wa_data-type &nbsp; &nbsp; = it_vbfa-vbtyp_n.
&nbsp; &nbsp; &nbsp; wa_data-vbeln &nbsp; &nbsp;= it_vbfa-vbeln.
&nbsp; &nbsp; &nbsp; wa_data-posnn &nbsp; &nbsp;= it_vbfa-posnn.
&nbsp; &nbsp; &nbsp; wa_data-rfmng &nbsp; &nbsp;= it_vbfa-rfmng.
&nbsp; &nbsp; &nbsp; is_del_data &nbsp; &nbsp; &nbsp;= wa_data.
&nbsp; &nbsp; &nbsp; t_parent1 = t_counter.
&nbsp; &nbsp; &nbsp;add 1 to t_counter.
&nbsp; &nbsp; &nbsp; wa_vbelv &nbsp;= it_vbfa-vbeln.
&nbsp; &nbsp; &nbsp; wa_posnv &nbsp;= it_vbfa-posnn.
&nbsp; &nbsp; &nbsp; l_tabix &nbsp; = sy-tabix.
\* Find any invoices Warehouse xfers or Goods Movements for this delivery
&nbsp; &nbsp; &nbsp; refresh: it_inv_data.
&nbsp; &nbsp; &nbsp; loop at it_vbfa where vbelv = wa_vbelv
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and &nbsp; posnv = wa_posnv.
&nbsp; &nbsp; &nbsp; &nbsp; case it_vbfa-vbtyp_n.
&nbsp; &nbsp; &nbsp; &nbsp; when 'M'. &nbsp; &nbsp;"Invoice
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clear: wa_data.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wa_data-folder = ' '.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wa_data-node_key = t_counter.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wa_data-relatkey = t_parent1.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wa_data-type &nbsp; &nbsp; = it_vbfa-vbtyp_n.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wa_data-vbeln &nbsp; &nbsp;= it_vbfa-vbeln.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wa_data-posnn &nbsp; &nbsp;= it_vbfa-posnn.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wa_data-rfmng &nbsp; &nbsp;= it_vbfa-rfmng.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wa_data-rfwrt &nbsp; &nbsp;= it_vbfa-rfwrt.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; append wa_data to it_inv_data.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wj_vbelv &nbsp; &nbsp; &nbsp; &nbsp; = it_vbfa-vbeln.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wj_posnv &nbsp; &nbsp; &nbsp; &nbsp; = it_vbfa-posnn.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wa_nodekey &nbsp; &nbsp; &nbsp; = wa_data-node_key.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; describe table it_inv_data lines lm_tabix.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; add 1 to t_counter.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; perform get_payment &nbsp;tables it_inv_data using t_counter.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; perform get_returns &nbsp;tables it_inv_data using t_counter.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; describe table it_inv_data lines l_tabix.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if l_tabix > lm_tabix.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; read table it_inv_data index lm_tabix into wa_data.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wa_data-folder = 'X'.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; modify it_inv_data index lm_tabix from wa_data.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; endif.
&nbsp; &nbsp; &nbsp; &nbsp; when 'Q' or 'R'. &nbsp; &nbsp;" WMS transfer, or Goods Mvmt
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clear: wa_data.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wa_data-folder = ' '.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wa_data-node_key = t_counter.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wa_data-relatkey = t_parent1.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wa_data-type &nbsp; &nbsp; = it_vbfa-vbtyp_n.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wa_data-vbeln &nbsp; &nbsp;= it_vbfa-vbeln.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wa_data-posnn &nbsp; &nbsp;= it_vbfa-posnn.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wa_data-rfmng &nbsp; &nbsp;= it_vbfa-rfmng.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; append wa_data to it_inv_data.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; add 1 to t_counter.
&nbsp; &nbsp; &nbsp; &nbsp; when others.
&nbsp; &nbsp; &nbsp; &nbsp; endcase.
&nbsp; &nbsp; &nbsp; endloop. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" finding any matching invoices
&nbsp; &nbsp; &nbsp; if it_inv_data is initial.
&nbsp; &nbsp; &nbsp; &nbsp; is_del_data-folder = ' '.
&nbsp; &nbsp; &nbsp; endif.
&nbsp; &nbsp; &nbsp; append is_del_data to p_itab_data.
&nbsp; &nbsp; &nbsp; append lines of it_inv_data to p_itab_data.
&nbsp; &nbsp; &nbsp; refresh: it_inv_data.
&nbsp; &nbsp; endloop. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" finding any deliveries
&nbsp; endloop.
&nbsp; clear: t_parent, t_parent1, t_exit.
endform. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" create_input_table
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;update_selection_table
\*&---------------------------------------------------------------------\*
form update_selection_table tables &nbsp;itab_selection.
&nbsp; if not s_ernam is initial or
&nbsp; &nbsp; &nbsp;not s_erdat is initial or
&nbsp; &nbsp; &nbsp;not s_vbtyp is initial.
&nbsp; &nbsp; select: vbeln vbtyp into corresponding fields of
&nbsp; &nbsp; table &nbsp;itab_selection
&nbsp; &nbsp; from &nbsp; vbak
&nbsp; &nbsp; where erdat in s_erdat and
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ernam in s_ernam and
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vbtyp = &nbsp;s_vbtyp.
&nbsp; endif.
endform. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" update_selection_table
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;get_payment
\*&---------------------------------------------------------------------\*
form get_payment &nbsp;tables it_inv_data using pt_counter .
&nbsp; loop at it_vbfa where vbelv = wj_vbelv
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and &nbsp; posnv = wj_posnv
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and &nbsp; vbtyp_n = '+'.
&nbsp; &nbsp; wa_data-folder = ' '.
&nbsp; &nbsp; wa_data-relatkey = wa_nodekey.
&nbsp; &nbsp; wa_data-node_key = pt_counter.
&nbsp; &nbsp; wa_data-type &nbsp; &nbsp; = it_vbfa-vbtyp_n.
&nbsp; &nbsp; wa_data-vbeln &nbsp; &nbsp;= it_vbfa-vbeln.
&nbsp; &nbsp;wa_data-posnn &nbsp; &nbsp;= it_vbfa-posnn.
&nbsp; &nbsp; wa_data-rfmng &nbsp; &nbsp;= it_vbfa-rfmng.
&nbsp; &nbsp; wa_data-rfwrt &nbsp; &nbsp;= it_vbfa-rfwrt.
&nbsp; &nbsp;append wa_data to it_inv_data.
&nbsp; &nbsp; add 1 to pt_counter.
&nbsp; endloop.
endform. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" get_payment
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;get_returns
\*&---------------------------------------------------------------------\*
form get_returns &nbsp; tables it_inv_data using pt_counter .
&nbsp; data: ld_rfwrt(11) type c,
&nbsp; &nbsp; &nbsp; &nbsp; ld_tabix like sy-tabix.
&nbsp; loop at it_vbfa where vbelv = wj_vbelv
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and &nbsp; posnv = wj_posnv
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and &nbsp; vbtyp_n = 'H'.
&nbsp; &nbsp; ld_tabix &nbsp; &nbsp; &nbsp; &nbsp; = sy-tabix.
&nbsp; &nbsp; wa_data-folder &nbsp; = ' '.
&nbsp; &nbsp; wa_data-relatkey = wa_nodekey.
&nbsp; &nbsp; wa_data-node_key = pt_counter.
&nbsp; &nbsp; wa_data-type &nbsp; &nbsp; = it_vbfa-vbtyp_n.
&nbsp; &nbsp; wa_data-vbeln &nbsp; &nbsp;= it_vbfa-vbeln.
&nbsp; &nbsp; wa_data-posnn &nbsp; &nbsp;= it_vbfa-posnn.
&nbsp; &nbsp; wa_data-rfmng &nbsp; &nbsp;= it_vbfa-rfmng.
&nbsp; &nbsp; ld_rfwrt &nbsp; &nbsp; &nbsp; &nbsp; = it_vbfa-rfwrt.
&nbsp; &nbsp; concatenate ld_rfwrt '-' into &nbsp;ld_rfwrt.
&nbsp; &nbsp; wa_data-rfwrt &nbsp; &nbsp;= ld_rfwrt.
&nbsp; &nbsp; append wa_data to it_inv_data.
&nbsp; &nbsp; add 1 to pt_counter.
&nbsp; endloop.
endform.
\*----------------------------------------------------------------------\*
\* &nbsp; INCLUDE Z_XXXX_TREE_PBO &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *
\*----------------------------------------------------------------------\*
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Module &nbsp;STATUS_2000 &nbsp;OUTPUT
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
module status_2000 output.
&nbsp; set pf-status 'Z_XXXX_TREE_2000'.
&nbsp; set titlebar 'Z_XXXX_TREE_2000'.
endmodule. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; " STATUS_2000 &nbsp;OUTPUT
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Module &nbsp;init_data_2000 &nbsp;OUTPUT
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp;text
\*----------------------------------------------------------------------\*
module init_data_2000 output.
&nbsp; &nbsp;if g_tree is initial.
&nbsp; &nbsp; &nbsp;perform create_and_init_tree.
&nbsp; endif.
endmodule.
\*----------------------------------------------------------------------\*
\* &nbsp; INCLUDE Z_SALES_TREE_RPT_TOP &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *
\*----------------------------------------------------------------------\*
\* Table Definitions
tables: vbak, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"Sales Document: Header Data
&nbsp; &nbsp; &nbsp; &nbsp; vbfa. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"Sales Document Flow
\* Type definitions
types: begin of itab_type,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;folder &nbsp; type flag,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;node_key type mtreeitm,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;relatkey type tv_nodekey,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;type &nbsp; &nbsp; like vbak-vbtyp,
&nbsp; &nbsp; &nbsp; &nbsp; vbeln &nbsp; &nbsp;like vbak-vbeln,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;posnn &nbsp; &nbsp;like vbfa-posnn,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rfmng(10) type c,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rfwrt(12) type c,
&nbsp; &nbsp; &nbsp; &nbsp;end of itab_type.
&nbsp;types: begin of sel_type,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;vbeln &nbsp; &nbsp;like vbak-vbeln,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;vbtyp &nbsp; &nbsp;like vbak-vbtyp,
&nbsp; &nbsp; &nbsp; &nbsp;end of sel_type.
\* data Definitions
data: okcode &nbsp; &nbsp;like sy-ucomm,
&nbsp; &nbsp; &nbsp; itab_data type itab_type occurs 0,
&nbsp; &nbsp; &nbsp; itab_selection type sel_type occurs 0.
data: begin of it_vbfa occurs 0.
&nbsp; &nbsp; &nbsp; &nbsp; include structure vbfa.
data: end of it_vbfa,
&nbsp; &nbsp; &nbsp; is_vbfa &nbsp; like line of it_vbfa,
&nbsp; &nbsp; &nbsp; is_vbc06 &nbsp;like vbco6,
&nbsp; &nbsp; &nbsp; wa_vbelv &nbsp;like vbfa-vbelv,
&nbsp; &nbsp; &nbsp; wj_vbelv &nbsp;like vbfa-vbelv,
&nbsp; &nbsp; &nbsp; wa_posnv &nbsp;like vbfa-posnv,
&nbsp; &nbsp; &nbsp; wj_posnv &nbsp;like vbfa-posnv,
&nbsp; &nbsp; &nbsp; wa_nodekey type tv_nodekey,
&nbsp; &nbsp; &nbsp; t_screen(3) type c,
&nbsp; &nbsp; &nbsp; t_dynnr like sy-dynnr,
&nbsp; &nbsp; &nbsp; l_transcode &nbsp;like sy-tcode,
&nbsp; &nbsp; &nbsp; l_ok_zpcr(4) type c &nbsp;value 'MM01',
&nbsp; &nbsp; &nbsp; wa_data &nbsp; type itab_type.
\* Tree list definitions
class lcl_application definition deferred.
class cl_gui_cfw &nbsp; &nbsp; &nbsp;definition load.
types: item_table_type like standard table of mtreeitm
&nbsp; &nbsp; &nbsp; &nbsp;with default key.
data: g_application &nbsp; &nbsp; &nbsp;type ref to lcl_application,
&nbsp; &nbsp; &nbsp; g_custom_container type ref to cl_gui_custom_container,
&nbsp; &nbsp; &nbsp; g_tree &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type ref to cl_gui_list_tree,
&nbsp; &nbsp; &nbsp; g_ok_code &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;type sy-ucomm.
\*----------------------------------------------------------------------\*
\* &nbsp; INCLUDE Z_SALE_TREE_PAI &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;Module &nbsp;USER_COMMAND_2000 &nbsp;INPUT
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
module user_command_2000 input.
&nbsp; data: return_code type i.
&nbsp; call method cl_gui_cfw=>dispatch
&nbsp; &nbsp; importing return_code = return_code.
&nbsp; if return_code <> cl_gui_cfw=>rc_noevent.
&nbsp; &nbsp; clear okcode.
&nbsp; &nbsp; exit.
&nbsp; endif.
&nbsp; &nbsp;case okcode.
&nbsp; &nbsp; when 'EXIT' or 'RETURN'. " Finish program
&nbsp; &nbsp; &nbsp; if not g_custom_container is initial.
&nbsp; &nbsp; &nbsp; &nbsp; call method g_custom_container->free
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;exceptions
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cntl_system_error = 1
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cntl_error &nbsp; &nbsp; &nbsp; &nbsp;= 2.
&nbsp; &nbsp; &nbsp; &nbsp; if sy-subrc <> 0.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; message a000(tree_control_msg).
&nbsp; &nbsp; &nbsp; &nbsp; endif.
&nbsp; &nbsp; &nbsp; &nbsp;clear g_custom_container.
&nbsp; &nbsp; &nbsp; &nbsp; clear g_tree.
&nbsp; &nbsp; &nbsp; endif.
&nbsp; &nbsp; &nbsp; leave to screen 0.
&nbsp; endcase.
&nbsp; clear okcode.
endmodule. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; " USER_COMMAND_2000 &nbsp;INPUT
&nbsp;Screen 2000
process before output.
&nbsp;module status_2000.
&nbsp;module init_data_2000.
process after input.
&nbsp;module user_command_2000.

Author: Andrea Olivieri
Supported Releases: SAP ECC 6.0
Submitted: 10 February 2009

The following report can be used as example for displaying at "Schedule-line level" the quantities to be delivered and delivered of a given Sales Order.

*&---------------------------------------------------------------------*
*& Report  ZSDN_SIMPLE_CHECK_VBEP
*&
*&---------------------------------------------------------------------*
*& Simple Abap : Sales Order Schedule Lines Details
*& This is an example for displaying at "Schedule-line level" the
*& quantities to be delivered and delivered of a given Sales Order
*&---------------------------------------------------------------------*
REPORT  zsdn_simple_check_vbep.
TYPE-POOLS: slis.
TABLES: vbak, vbap, vbep, vbfa.

TYPES: BEGIN OF vbep_ty,
        vbeln TYPE vbepvb-vbeln,
        posnr TYPE vbepvb-posnr,
        etenr TYPE vbepvb-etenr,
        ettyp TYPE vbepvb-ettyp,
        edatu TYPE vbepvb-edatu,
        mbdat TYPE vbepvb-mbdat,
        wmeng TYPE vbepvb-wmeng,
        olfmng TYPE vbepvb-olfmng,
        vsmng TYPE vbepvb-vsmng,
        vrkme TYPE vbepvb-vrkme,
       END OF vbep_ty.

DATA: vbep_out TYPE STANDARD TABLE OF vbep_ty,
      lvbep_out TYPE vbep_ty.

DATA: t_heading TYPE slis_t_listheader.
DATA: xvbap TYPE STANDARD TABLE OF vbapvb.
DATA: xvbep TYPE STANDARD TABLE OF vbepvb.
DATA: xvbup TYPE STANDARD TABLE OF vbup.
DATA: xvbfa TYPE STANDARD TABLE OF vbfa.
DATA: lvbap TYPE vbapvb.
DATA: lvbep TYPE vbepvb.
DATA: lvbup TYPE vbup.
DATA: lvbfa TYPE vbfa.

PARAMETERS: pvbeln TYPE vbak-vbeln OBLIGATORY MATCHCODE OBJECT vmva.

SELECT SINGLE * FROM vbak WHERE vbeln = pvbeln.

CHECK sy-subrc = 0.

SELECT * FROM  vbap INTO CORRESPONDING FIELDS OF TABLE xvbap
        WHERE  vbeln  = pvbeln
        AND    abgru  = space.

CHECK sy-subrc = 0.

LOOP AT xvbap INTO lvbap.
  PERFORM read_vbup.
  PERFORM read_vbfa.
  PERFORM read_vbep.
  IF sy-subrc <> 0. CONTINUE. ENDIF.
  PERFORM check_deliveries.
ENDLOOP.

PERFORM alv USING t_heading.

*&---------------------------------------------------------------------*
*&      Form  read_vbup
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM read_vbup.

  SELECT * FROM  vbup INTO TABLE xvbup
          WHERE  vbeln  = lvbap-vbeln
          AND    posnr  = lvbap-posnr.

ENDFORM.                    " read_vbup
*&---------------------------------------------------------------------*
*&      Form  read_vbfa
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM read_vbfa.

  SELECT * FROM  vbfa INTO TABLE xvbfa
         WHERE  vbelv    = lvbap-vbeln
         AND    posnv    = lvbap-posnr
         AND    vbtyp_n  = 'J'.

ENDFORM.                    " read_vbfa
*&---------------------------------------------------------------------*
*&      Form  read_vbep
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM read_vbep.

  SELECT * FROM  vbep
         INTO TABLE xvbep
         WHERE  vbeln  =  lvbap-vbeln
         AND    posnr  =  lvbap-posnr
         AND    bmeng  > 0.

ENDFORM.                    " read_vbep

*&---------------------------------------------------------------------*
*&      Form  check_deliveries
*&---------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM check_deliveries.

  DATA: zvbap TYPE TABLE OF vbapvb ,
        lzvbap TYPE vbapvb.

  APPEND lvbap TO zvbap.

  CALL FUNCTION 'RV_SCHEDULE_CHECK_DELIVERIES'
    EXPORTING
      fbeleg                  = lvbap-vbeln
      fposnr                  = lvbap-posnr
    TABLES
      fvbfa                   = xvbfa
      fvbup                   = xvbup
      fxvbep                  = xvbep
      fvbap                   = zvbap
    EXCEPTIONS
      fehler_bei_lesen_fvbup  = 1
      fehler_bei_lesen_fxvbep = 2
      OTHERS                  = 3.

  IF sy-subrc <> 0.
    RETURN.
  ENDIF.

  LOOP AT xvbep INTO lvbep.
    MOVE-CORRESPONDING lvbep TO lvbep_out.
    APPEND lvbep_out TO vbep_out.
  ENDLOOP.

ENDFORM.                    " check_deliveries
*&---------------------------------------------------------------------*
*&      Form  ALV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM alv USING  t_heading  TYPE slis_t_listheader.

  DATA: gr_table TYPE REF TO cl_salv_table.
  DATA: gr_display TYPE REF TO cl_salv_display_settings.
  DATA: gr_functions TYPE REF TO cl_salv_functions.
  DATA: gr_layout TYPE REF TO cl_salv_layout.

  cl_salv_table=>factory( IMPORTING r_salv_table = gr_table CHANGING t_table = vbep_out ).
  gr_display = gr_table->get_display_settings( ).
  gr_display->set_striped_pattern( cl_salv_display_settings=>true ).
  gr_functions = gr_table->get_functions( ).
  gr_functions->set_all( abap_true ).
  gr_layout = gr_table->get_layout( ).
  gr_layout->set_save_restriction( cl_salv_layout=>restrict_none ).
  gr_table->display( ).
ENDFORM.                    " ALV

Purpose

This document provides some best practices which can be used for sales order enhancement implementation

Overview

In an SAP implementation for the client, there could be multiple implementation of the same user exit for different purpose; multiple implementations could refer to same master data. The typical problems faced in such scenarios are

1)      Same master data is  fetched from  data base tables multiple times in different implementation

2)      Unnecessary data fetches for master data like material, sales organization, company code details which are available as structure in standard program SAPMV45A.

3)       Multiple loops on sales order item, schedule item in each implementation.

4)      Fetching of master data at incorrect place  which leads to execution of  the select query multiple times to fetch the same data

5)      Incorrectly updating of Update indicator for sales item and schedule item might cause inconsistency in sales order transaction.

6)      Triggering of subsequent document creation on save of sales order is performed at same LUW which takes additional time to save the sales order.

 

This document is intended to solve these problems by providing few tips which will help us improving performance as well make the code look neat and maintainable

User Exits in Sales order Management

The user should have background of user exits which can be implemented to achieve custom functionality in sales order management

 

The standard Include MV45AFZZ contains the FORM routines which can be used to have write custom code to implement custom logic in sales order management.

The user exits which you can use for modifications in sales document processing are listed below.

 

Listing few user exit routines which is mostly used by developer during sap implementation

 

USEREXIT_DELETE_DOCUMENT

This user exit can be used for deleting data which was stored in a separate table during sales document creation, for example, if the sales document is deleted.

For example, if an additional table is filled with the name of the person in charge (ERNAM) during order entry, this data can also be deleted after the sales order has been deleted.

The user exit is called up at the end of the FORM routine BELEG_LOESCHEN shortly before the routine BELEG_SICHERN.

 

USEREXIT_MOVE_FIELD_TO_VBAK

Use this user exit to assign values to new fields at sales document header level. It is described in the section "Transfer of the customer master fields into the sales document".

The user exit is called up at the end of the FORM routine VBAK_FUELLEN.

 

USEREXIT_MOVE_FIELD_TO_VBAP

Use this user exit to assign values to new fields at sales document item level. It is described in the section "Copy customer master fields into the sales document".

The user exit is called up at the end of the FORM routine VBAP_FUELLEN.

 

USEREXIT_MOVE_FIELD_TO_VBEP

Use this user exit to assign values to new fields at the level of the sales document schedule lines.

The user exit is called up at the end of the FORM routine VBEP_FUELLEN.

 

USEREXIT_MOVE_FIELD_TO_VBKD

Use this user exit to assign values to new fields for business data of the sales document. It is described in the section "Copy customer master fields into sales document" .The user exit is called up at the end of the FORM routine VBKD_FUELLEN.

 

USEREXIT_NUMBER_RANGE

Use this user exit to define the number ranges for internal document number assignment depending on the required fields. For example, if you want to define the number range depending on the sales organization (VKORG) or on the selling company (VKBUR), use this user exit. The user exit is called up in the FORM routine BELEG_SICHERN.

 

USEREXIT_PRICING_PREPARE_TKOMK

Use this user exit if you want to include and assign a value to an additional header field in the communication structure KOMK taken as a basis for pricing.

 

USEREXIT_PRICING_PREPARE_TKOMP

Use this user exit if you want to include or assign a value to an additional item field in the communication structure KOMP taken as a basis for pricing.

 

USEREXIT_READ_DOCUMENT

You use this user exit if further additional tables are to be read when importing TA01 or TA02. The user exit is called up at the end of the FORM routine BELEG_LESEN.

 

USEREXIT_SAVE_DOCUMENT

Use this user exit to fill user-specific statistics update tables.

The user exit is called up by the FORM routine BELEG-SICHERN before the COMMIT command.

 

USEREXIT_SAVE_DOCUMENT_PREPARE

Use this user exit to make certain changes or checks immediately before saving a document. It is the last possibility for changing or checking a document before posting.

The user exit is carried out at the beginning of the FORM routine BELEG_SICHERN.

 

Modularization

When we have multiple Implementations for each user exit, it becomes very important to maintain the modularization for each implementation to keep the functionality separate and loosely coupled.

 Create a Master Z Include in MV45ATZZ which will have Custom Includes for each implementation. Each enhancement implementation will be encapsulated in subroutine in each of these custom include. Each logical unit of processing should be written in subroutine which can be reused by other implementations if required. For example Currency conversion, quantity conversion.

MV45ATZZ

       Z_MAIN_INCLUDE - Define global data declaration and common subroutines.

                 Contains implementation specific subroutines 

                  Z_INCLUDE_IMP1

                   Z_INCLUDE_IMP2

                  Z_INCLUDE_IMP3

Data Fetch

Master data like sales organization, company code, material, reference order details are available in the standard program SAPMV45A. We don’t need to fetch this data from the database table again.

 

For example:

1)      TVKO-BUKRS contains the company code details

2)       CVBAK, CVBAP, CVBEP contains the reference order , item and schedule line details respectively

3)      VBAK, VBAP. VBEP structure contains the current order header, item schedule details respectively.

4)      The Internal tables XVBAK, XVBAP, XVBEP contains the header, item , schedule line details of the order

5)      The Internal tables YVBAK, YVBAP, YVBEP contains the old values of the header, item, schedule line details of the order. Note these tables have values only when corresponding original data is changed.

6)      The Internal table XVBPA, YVBPA contains the partner function details of sales order (Current and Old value).

 

To get list of all the available global data in the program SAPMV45A, go in debugging mode and select ‘Global’ Tab

Check whether the required data is available in SAPMV45A program. Only when the data is not available, do a database select to fetch the required data.

 Check whether the selection condition values for database select are present at header Exit USEREXIT_MOVE_FIELD_TO_VBAK and try to fetch required data in this user exit. Try avoiding data select in user exits USEREXIT_MOVE_FIELD_TO_VBAP and USEREXIT_MOVE_FIELD_TO_VBEP because these perform are called for each line item and schedule item respectively. Performing database select is these routines are equivalent to select in a loop.

 Always make a practice to check whether the data required for your enhancement is already fetched in other enhancement by checking main Include to avoid selecting same data again.

 If the same processing /checks are required in sales order processing and during save of sales order, fetch the required data and store it in global variables and use it in user exit called during save of sales order. If the global variables are initial, then fetch the data from database.

 Identify all the TVARVC entry to be fetched and have only one select from TVARVC in the user exit USEREXIT_MOVE_FIELD_TO_VBAK. Each enhancement implementation will read its corresponding entry from the internal table instead of own select on TVARVC.

  

Sales item and schedule line processing 

Generally we have requirements around processing some logic for each sales order item and schedule line items using the user exit USEREXIT_MOVE_FIELD_TO_VBAP,

USEREXIT_MOVE_FIELD_TO_VBEP and USEREXIT_SAVE_DOCUMENT_PREPARE.

 

1)      Avoid the nested loops on sales item and schedule line .If not possible use parallel cursor method to improve the performance .Copy the XVBAP and XVBEP internal table to local copy and sort the data by sales order number and sales item number.    

If ITAB1 has n1 entries and ITAB2 has n2 entries, the time needed for. The nested loop with the straightforward algorithm is O (n1 * n2), whereas the parallel cursor approach takes only O (n1 + n2) time.

2)      Do not loop at item and schedule line table for each implementation, instead loop at these tables once and have subroutines for each implementation.

 

General   Practice

 

LOOP AT   XVBAP INTO LS_VBAP WHERE UPDKZ NE ‘D’

PERFORM   IMPLEMENTATION 1

ENDLOOP


 
 

LOOP AT   XVBAP INTO LS_VBAP WHERE UPDKZ NE ‘D’

PERFORM   IMPLEMENTATION 2

ENDLOOP

 

 

Good   practice

 

LOOP AT   XVBAP INTO LS_VBAP WHERE UPDKZ NE ‘D’

PERFORM   IMPLEMENTATION 1

PERFORM   IMPLEMENTATION 2

PERFORM   IMPLEMENTATION 3

ENDLOOP


 
 

 

3)      When processing the internal table entries make sure you don’t process the entry which is marked for deletion. Generally in standard transaction, the data which is deleted from screen is not deleted from internal table. The record is marked with update indicator as ‘D’. Processing deleted records might cause inconsistency in the sap transaction.

 

4)      Setting the update indicator: Generally when any data in these tables are changed due to custom logic for example XVBAP, we need to set the indicator as ‘U’, so that standard update knows that there has been some change in data and data has to be updated. Make sure to check whether the data exist in its corresponding Y structure (In this example YVBAP) before setting the indicator as ‘Update’. Incorrectly setting the value might cause inconsistency in sales order

Checking Transaction code

 

To perform certain logic for create /change mode of sales order, don’t check the sy-tcode with values ‘VA01’ or ‘VA02’. 

Use the following standard screen control structure T180. 

T180-TRTYP = ‘H’ means create mode

T180-TRTYP = ‘V’ means change mode.

 

Capturing Custom message in BAPI

Whenever we are adding the custom message in standard sales order processing, if the same message has to be captured in the BAPI return table we need to add the following code.

 

  IF call_bapi = abap_true.

        PERFORM   message_vbfs_aufbauen(sapfv45l) USING sy-msgid

                                                        sy-msgno

                                                        sy-msgty

                                                        sy-msgv1

                                                        sy-msgv2

                                                        sy-msgv3

                                                        Space.

   ENDIF.

 

 

 Parallel Processing

 

Generally to automate the certain process with Sales order process we generally implement the user exit USEREXIT_SAVE_DOCUMENT_PREPARE to create subsequent documents during save of sales order. Calling the subsequent document creation in same LUW as sales order save will cause additional time in saving the sales order. To make the process independent of save of sales order, we can call the subsequent document creation in FM with BACKGROUND TASK or NEW TASK. The document creation will be called in different session independent of save of sales order. The application log can be updated to notify whether there was any error in creation of subsequent document creation.

Deleting a sales line item

To delete a line item in the sales order, generally we update the indicator as ‘Delete’ in the table XVBAP. This could cause inconsistency because corresponding all other tables will not be updated accordingly. The standard routine XVBAP_LOESCHEN in program SAPFV45P can be called to delete the line item; this will take care of updating all the relevant structures and tables in sales order.

Adding Partner Function

To add a partner function to the sales order, generally we update the table XVBPA table in user exit USEREXIT_MOVE_FIELD_TO_VBAP. This could cause issue sometimes if the update indicator is not updated correctly. Instead of manually inserting the entry in XVBPA [], we can use the FM used by standard to create/update partner function in sales order management. Standard FM SD_PARTNER_SINGLE_MODIFY and SD_PARTNER_DATA_GET can be called to update/insert partner function details. FM SD_PARTNER_SINGLE_MODIFY adds /updates the partner details to global memory GVT_LOCAL_MEMORY-XVBPA.FM SD_PARTNER_DATA_GET updates XVBPA from GVT_LOCAL_MEMORY-XVBPA

 

 

 

 

 

 

                 

 

 

 

 

 

  

  

 

 

Related Content

Related Documents

Insert SAP Help links or other WIKI content link.
Please hyperlink the title of the related document

Example: Explanation about how to create a WIKI page

Related SAP Notes/KBAs

Insert links to any related SAP Notes/KBAs that support your topic or are related. Please hyperlink ONLY SAP Note or KBA number.
Example:

SAP Note 83020: What is consulting, what is support

SAP KBA 12345: This is an example KBA link

(Use the following Hyperlink with SAP Note/KBA number at end: https://service.sap.com/sap/support/notes/123456)
__________________________________________________________________________________________________________

Use this structure to help you compose your contributions for WIKI and at the same time will ensure spelling and grammar.

 

 

 

This code snippet will create the sales order using BAPI.

REPORT z_sales_create.
DATA:
  fs_patnr TYPE bapipartnr,
  t_patnr LIKE STANDARD TABLE OF fs_patnr.
*------------------------Data Declaration----------------------------*
DATA:
  st_bapisdhead LIKE bapisdhead, " Sales Order Header Data
  ta_bapiitemin LIKE bapiitemin OCCURS 0 WITH HEADER LINE," Ln item
  d_bapireturn1 LIKE bapireturn1, " Bapi return msg
  d_vbeln LIKE bapivbeln-vbeln. " Sales Order Number
* Move the data to create sales order in the repective parameters------*
MOVE:
  'TA' TO st_bapisdhead-doc_type, " Sales document type
  '1' TO st_bapisdhead-purch_no_c,
  '0001' TO st_bapisdhead-sales_org,
  '01' TO st_bapisdhead-distr_chan,
  '01' TO st_bapisdhead-division.
MOVE:
  'AG' TO fs_patnr-partn_role," Sold to Party
  '0000000001' TO fs_patnr-partn_numb.
APPEND fs_patnr TO t_patnr.
CLEAR fs_patnr.
MOVE:
  'WE' TO fs_patnr-partn_role," Shipto Party
  '0000000001' TO fs_patnr-partn_numb.
APPEND fs_patnr TO t_patnr.
CLEAR fs_patnr.
MOVE:
  'PC' TO ta_bapiitemin-material,
  '0001' TO ta_bapiitemin-plant,
  '1' TO ta_bapiitemin-req_qty.
APPEND ta_bapiitemin.
* Call the Bapi to create the sales order
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT1'
  EXPORTING
    order_header_in = st_bapisdhead
  IMPORTING
    salesdocument   = d_vbeln
    return          = d_bapireturn1
  TABLES
    order_items_in  = ta_bapiitemin
    order_partners  = t_patnr.
IF sy-subrc EQ 0.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDIF.
IF d_vbeln <> space.
  WRITE: 'Sales order No. ', d_vbeln.
ENDIF.
 

The output will be as:

Sample Program to create sales order using BAPI
Sales order No.  837
REPORT zsd_pending_order NO STANDARD PAGE HEADING LINE-SIZE 255.

*Pending sale order details :  Details of open sale orders
* output list: Open delivery details with open quantities
TABLES : vbak, vbap, likp, lips, kna1, vbuk, vbpa, vepvg, vbfa, vbup.
DATA : pend_qty LIKE  vbap-kwmeng,
       dlv_qty LIKE  vbap-kwmeng,
       ord_qty LIKE vbap-kwmeng.
DATA: BEGIN OF itab_vbak OCCURS 0,
      vbeln LIKE vbak-vbeln,           "sales order no
      audat LIKE vbak-audat,           " created date
      auart LIKE vbak-auart,           " Sales Document Type
      vkorg LIKE vbak-vkorg,           "Sales Organization
      vtweg LIKE vbak-vtweg,           " distribution channel
      spart LIKE vbak-spart,           " Division
      vkgrp LIKE vbak-vkgrp,           " Sales group
      vkbur LIKE vbak-vkbur,           " Sales office
      kunnr LIKE vbak-kunnr,           " sold to party
      kunag LIKE vbak-kunnr,           " ship to party
      cust LIKE vbak-kunnr,            " sold to party
      ship LIKE kna1-name1,            " ship to party
      city LIKE kna1-ort01,            " ship to party location
      deliv LIKE likp-vbeln,           " delivery
      matnr LIKE vbap-matnr,
      arktx LIKE vbap-arktx,           " mat description
      kwmeng LIKE vbap-kwmeng,
      kbmeng LIKE vbap-kbmeng,
      fkrel LIKE vbap-matnr,
      vstel LIKE vbap-vstel,
      route LIKE vbap-route,
      chln_no LIKE likp-xabln,
      grn_no LIKE likp-bolnr,
      truck_no LIKE likp-traid,
      dlv_dt LIKE vbfa-erdat,           "dlvy date
      ord_qty LIKE vbap-kwmeng,
      dlvd_qty LIKE vbap-kwmeng,
      pend_qty LIKE vbap-kwmeng,
      kzwi5 LIKE vbap-kzwi5,
      posnr LIKE vbap-posnr,
      vsart LIKE likp-vsart,
      sdabw LIKE likp-sdabw,
END OF itab_vbak.
DATA  posnr LIKE vbap-posnr.
*FOR ALV DISPLAY
TYPE-POOLS: slis.
CONSTANTS: formname_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE'.
*Data Decelararion for alv display
DATA: i_fieldtab TYPE slis_t_fieldcat_alv,
      i_heading  TYPE slis_t_listheader,
      i_layout   TYPE slis_layout_alv,
      i_sort     TYPE slis_t_sortinfo_alv,
      i_print    TYPE slis_print_alv,
      i_events   TYPE slis_t_event,
      i_repname  LIKE sy-repid,
      f2code   LIKE sy-ucomm VALUE  '&ETA',
      i_save(1) TYPE c,
      i_exit(1) TYPE c,
      i_variant LIKE disvariant,
      h_text(50).

START-OF-SELECTION.
  SELECTION-SCREEN SKIP 1.
  SELECTION-SCREEN BEGIN OF BLOCK v1 WITH FRAME TITLE text-001.
  SELECTION-SCREEN SKIP 1.
  SELECT-OPTIONS:
                 ord_no FOR vepvg-vbeln,
                 audat FOR vbak-audat OBLIGATORY,
                 matnr FOR vbap-matnr,
                 spart FOR vbap-spart OBLIGATORY,
                 vstel FOR vepvg-vstel OBLIGATORY,
                 sale_org FOR vbak-vkorg OBLIGATORY,
                 sale_off FOR vbak-vkbur.
  SELECTION-SCREEN SKIP 1.
* check box for ALV display
  PARAMETERS p_alv AS CHECKBOX.
  SELECTION-SCREEN END OF BLOCK v1.
  SELECTION-SCREEN SKIP 1.
  DATA:   ftab(72) OCCURS 5 WITH HEADER LINE.
  REFRESH ftab.
  ftab = 'VBELN'. 
  APPEND ftab.
  REFRESH itab_vbak.

INITIALIZATION.
  i_repname = sy-repid.

START-OF-SELECTION.
  SELECT vbeln audat vkorg vtweg spart vkbur kunnr FROM vbak
       INTO
       (itab_vbak-vbeln, itab_vbak-audat,
        vbak-vkorg, vbak-vtweg, vbak-spart,
        itab_vbak-vkbur, itab_vbak-kunnr)
       WHERE vbeln IN ord_no
       AND audat IN audat
       AND vbtyp = 'C'
       AND vkorg IN sale_org
       AND spart IN spart
       AND vkbur IN sale_off.
*   authorization object
    AUTHORITY-CHECK OBJECT 'V_VBAK_VKO'
           ID 'VKORG' FIELD vbak-vkorg
           ID 'VTWEG' FIELD vbak-vtweg
           ID 'SPART' FIELD vbak-spart
           ID 'ACTVT' FIELD '03'.
    IF sy-subrc <> 0.
      MESSAGE e208(00) WITH 'No relevant authorizations found'.
    ENDIF.
    IF sy-subrc = 0.
      SELECT posnr kwmeng kbmeng matnr arktx  "added for mat description
               fkrel vstel route kzwi5 spart
               FROM vbap INTO CORRESPONDING FIELDS OF itab_vbak
               WHERE vbeln = itab_vbak-vbeln .
        CHECK ( itab_vbak-fkrel = 'A' OR
        "Delivery-related billing document
                itab_vbak-fkrel = 'D' )   "Relevant for pro forma
          AND itab_vbak-vstel IN vstel
          AND itab_vbak-matnr IN matnr
          AND itab_vbak-spart IN spart.
        SELECT SINGLE * FROM vbup WHERE vbeln = itab_vbak-vbeln
                                    AND posnr = itab_vbak-posnr.
        CHECK vbup-gbsta NE 'C'.
        dlv_qty = 0.
        SELECT SINGLE kunnr FROM vbpa INTO itab_vbak-kunnr
               WHERE vbeln = itab_vbak-vbeln
               AND parvw = 'WE'.
        SELECT SINGLE name1 ort01 FROM kna1 INTO
               (itab_vbak-cust, itab_vbak-city)
                WHERE kunnr = itab_vbak-kunnr.
*       in case of partially processed sale order get delivery details
        CLEAR : dlv_qty, itab_vbak-dlv_dt, itab_vbak-dlvd_qty,
        itab_vbak-chln_no,
                itab_vbak-grn_no, itab_vbak-truck_no.
        IF vbup-gbsta EQ 'B'. "partially processed
          dlv_qty = 0.
*         get details from delivery
          SELECT vbfa~vbeln vbfa~rfmng vbfa~vbtyp_n vbfa~erdat
             INTO (vbfa-vbeln, vbfa-rfmng, vbfa-vbtyp_n, vbfa-erdat)
             FROM vbfa
             WHERE vbelv = itab_vbak-vbeln
               AND posnv = itab_vbak-posnr.
            CHECK vbfa-vbtyp_n = 'J'.
            CLEAR : dlv_qty, itab_vbak-dlv_dt, itab_vbak-dlvd_qty,
            itab_vbak-chln_no,
                    itab_vbak-grn_no, itab_vbak-truck_no.
            SELECT SINGLE erdat xabln bolnr traid vsart sdabw
                  INTO (itab_vbak-dlv_dt, itab_vbak-chln_no,
                  itab_vbak-grn_no,
                  itab_vbak-truck_no, itab_vbak-vsart, itab_vbak-sdabw)
                  FROM likp
                  WHERE vbeln = vbfa-vbeln.
            IF sy-subrc = 0.
              dlv_qty = dlv_qty + vbfa-rfmng.
              itab_vbak-dlv_dt = vbfa-erdat.
              itab_vbak-dlvd_qty = dlv_qty.
              itab_vbak-deliv = vbfa-vbeln.
            ENDIF.
            APPEND itab_vbak.
          ENDSELECT.
        ELSEIF vbup-gbsta EQ 'A'.
*         for unprocessed sale order
*         ship to party details
          itab_vbak-kunag = itab_vbak-kunnr.
          itab_vbak-ship = itab_vbak-cust.
          APPEND itab_vbak.
        ENDIF.
      ENDSELECT.
    ENDIF.
    CLEAR itab_vbak.
  ENDSELECT.
  LOOP AT itab_vbak.
*   clear with change in document / item no
    ON CHANGE OF itab_vbak-vbeln OR itab_vbak-posnr.
      CLEAR: dlv_qty,ord_qty,pend_qty.
    ENDON.
    AT NEW posnr.
*     In case full qty not delivered
      IF itab_vbak-kwmeng > itab_vbak-dlvd_qty.
        SELECT SINGLE vbpa~kunnr INTO vbpa-kunnr
           FROM vbpa
           WHERE vbeln = itab_vbak-vbeln
            AND  posnr = itab_vbak-posnr
            AND  parvw = 'WE'.
        IF sy-subrc EQ 0.
          itab_vbak-kunag = vbpa-kunnr.
          SELECT SINGLE name1 ort01 FROM kna1 INTO
                (itab_vbak-ship, itab_vbak-city)
                 WHERE kunnr = itab_vbak-kunag.
          IF sy-subrc NE 0.
            SELECT SINGLE vbpa~kunnr INTO vbpa-kunnr
               FROM vbpa
               WHERE vbeln = itab_vbak-vbeln
               AND parvw = 'WE'.
            itab_vbak-kunag = vbpa-kunnr.
            IF sy-subrc NE 0 AND p_alv NE 'X'.
              WRITE :/ 'vbpadetls' , itab_vbak-vbeln, itab_vbak-posnr,
              itab_vbak-vbeln.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDIF.
      itab_vbak-ord_qty = itab_vbak-kwmeng.
*     Delivered Qty & Pending qty
      dlv_qty = dlv_qty + itab_vbak-dlvd_qty.
      itab_vbak-pend_qty = itab_vbak-kwmeng - dlv_qty.
      MODIFY itab_vbak TRANSPORTING kunag ship city dlvd_qty ord_qty
      pend_qty .
    ENDAT.
  ENDLOOP.

END-OF-SELECTION.
  SORT itab_vbak BY vbeln posnr audat kunnr matnr.
  IF p_alv NE 'X'.
    LOOP AT itab_vbak.
      SELECT SINGLE kna1~name1 kna1~ort01
             INTO
             (kna1-name1, kna1-ort01)
             FROM kna1
             WHERE kunnr = itab_vbak-kunnr.
      pend_qty = itab_vbak-ord_qty - itab_vbak-dlvd_qty.
      FORMAT COLOR COL_NORMAL.
      WRITE : /01(10) itab_vbak-vbeln,
              12(10)  itab_vbak-audat,
              24(8)  itab_vbak-kunag NO-ZERO,
              34(6)  itab_vbak-posnr NO-ZERO,
              42(10) itab_vbak-matnr NO-ZERO,
              54(15) itab_vbak-arktx,
              72(25) itab_vbak-ship,
              100(15) itab_vbak-city,
              118(8)  itab_vbak-ord_qty,
              128(10) itab_vbak-route,
              140(10) itab_vbak-dlv_dt,
              152(10) itab_vbak-dlvd_qty,
              164(10)  itab_vbak-chln_no,
              176(10)  itab_vbak-grn_no,
              188(10)  itab_vbak-truck_no,
              200(10) itab_vbak-pend_qty,
              218(15) itab_vbak-kzwi5 LEFT-JUSTIFIED.
      FORMAT RESET.
      AT END OF audat.
        SUM.
        pend_qty = itab_vbak-ord_qty - itab_vbak-dlvd_qty.
        FORMAT COLOR COL_BACKGROUND.
        WRITE: /118(8) itab_vbak-ord_qty,
               152(10) itab_vbak-dlvd_qty,
               200(10) pend_qty,
               218 itab_vbak-kzwi5 LEFT-JUSTIFIED.
        FORMAT RESET.
      ENDAT.
      AT LAST.
        SUM.
        pend_qty = itab_vbak-ord_qty - itab_vbak-dlvd_qty.
        FORMAT COLOR COL_TOTAL.
        WRITE : /5 'Grand Total : '.
        WRITE: /118(8) itab_vbak-ord_qty,
              152(10) itab_vbak-dlvd_qty,
              200(10) pend_qty,
              218 itab_vbak-kzwi5 LEFT-JUSTIFIED.
        FORMAT RESET.
      ENDAT.
    ENDLOOP.
  ELSE.
*   for ALV Display
    i_repname = sy-repid.
    PERFORM fieldcat USING i_fieldtab[].
    PERFORM eventtab USING i_events[].
    PERFORM comment USING i_heading[].
    PERFORM call_alv.
    PERFORM build_layout USING i_layout.
  ENDIF.

TOP-OF-PAGE.
  IF p_alv NE 'X'.
    FORMAT COLOR COL_HEADING.
    WRITE: /01 'Ord No',
            12 'Ord Date',
            24 'Sold to Party',
            34 'Item No',
            42 'Mat No',
            54 'Mat Descp',
            72 'Ship to Party',
            100 'City',
            118 'Qty',
            128 'Route',
            140 'Dlv Date',
            152 'Dlv Qty',
            164 'Challan No',
            176 'GRN No',
            188 'Truck No',
            200 'Pend Qty',
            218 'Total Value'.
    FORMAT RESET.
  ENDIF.
*&---------------------------------------------------------------------*
*&      Form  fieldcat
*&---------------------------------------------------------------------*
FORM fieldcat USING p_fieldtab TYPE slis_t_fieldcat_alv.
  DATA: l_fieldcat TYPE slis_fieldcat_alv.
  CLEAR l_fieldcat.
  l_fieldcat-tabname    = 'ITAB_VBAK'.
  l_fieldcat-fix_column = 'X'.
  l_fieldcat-no_out     = ' '.
  l_fieldcat-fieldname  = 'VKBUR'.
  l_fieldcat-outputlen  = 6.
  l_fieldcat-seltext_l  = 'Sales Office'.
  l_fieldcat-no_zero = 'X'.
  APPEND l_fieldcat TO p_fieldtab.
  l_fieldcat-fieldname  = 'VSTEL'.
  l_fieldcat-outputlen  = 5.
  l_fieldcat-seltext_l  = 'Shipping Point'.
  l_fieldcat-no_zero = ' '.
  APPEND l_fieldcat TO p_fieldtab.
  l_fieldcat-fieldname  = 'VBELN'.
  l_fieldcat-outputlen  = 10.
  l_fieldcat-seltext_l  = 'Order No.'.
  l_fieldcat-no_zero = 'X'.
  l_fieldcat-hotspot = 'X'.
  APPEND l_fieldcat TO p_fieldtab.
  l_fieldcat-fieldname  = 'AUDAT'.
  l_fieldcat-outputlen  = 10.
  l_fieldcat-seltext_l  = 'Doc Date'.
  l_fieldcat-hotspot = ''.
  l_fieldcat-no_zero = ' '.
  APPEND l_fieldcat TO p_fieldtab.
  l_fieldcat-fieldname  = 'POSNR'.
  l_fieldcat-outputlen  = 5.
  l_fieldcat-seltext_l  = 'Item'.
  l_fieldcat-no_zero = 'X'.
  APPEND l_fieldcat TO p_fieldtab.
  l_fieldcat-fieldname  = 'MATNR'.
  l_fieldcat-outputlen  = 10.
  l_fieldcat-seltext_l  = 'Material No'.
  l_fieldcat-no_zero = 'X'.
  APPEND l_fieldcat TO p_fieldtab.
  l_fieldcat-fieldname  = 'ARKTX'.
  l_fieldcat-outputlen  = 15.
  l_fieldcat-seltext_l  = 'Mat. Description'.
  l_fieldcat-no_zero = 'X'.
  APPEND l_fieldcat TO p_fieldtab.
  l_fieldcat-fieldname  = 'KUNNR'.
  l_fieldcat-outputlen  = 8.
  l_fieldcat-seltext_l  = 'Sold to Party'.
  l_fieldcat-no_zero = 'X'.
  APPEND l_fieldcat TO p_fieldtab.
  l_fieldcat-fieldname  = 'CUST'.
  l_fieldcat-outputlen  = 15.
  l_fieldcat-seltext_l  = 'Sold to Party Descp.'.
  l_fieldcat-no_zero = 'X'.
  APPEND l_fieldcat TO p_fieldtab.
  l_fieldcat-fieldname  = 'KUNAG'.
  l_fieldcat-outputlen  = 8.
  l_fieldcat-seltext_l  = 'Ship to Party'.
  l_fieldcat-no_zero = 'X'.
  APPEND l_fieldcat TO p_fieldtab.
  l_fieldcat-fieldname  = 'SHIP'.
  l_fieldcat-outputlen  = 15.
  l_fieldcat-seltext_l  = 'Ship to Party Descp'.
  l_fieldcat-no_zero = 'X'.
  APPEND l_fieldcat TO p_fieldtab.
  l_fieldcat-fieldname  = 'CITY'.
  l_fieldcat-outputlen  = 13.
  l_fieldcat-seltext_l  = 'City'.
  l_fieldcat-no_zero = ' '.
  APPEND l_fieldcat TO p_fieldtab.
  l_fieldcat-fieldname  = 'DELIV'.
  l_fieldcat-outputlen  = 10.
  l_fieldcat-seltext_l  = 'Delivery No.'.
  l_fieldcat-no_zero = 'X'.
  l_fieldcat-hotspot = 'X'.
  APPEND l_fieldcat TO p_fieldtab.
  l_fieldcat-fieldname  = 'ORD_QTY'.
  l_fieldcat-outputlen  = 10.
  l_fieldcat-seltext_l  = 'Qty'.
  l_fieldcat-no_zero = ' '.
  l_fieldcat-hotspot = ' '.
  APPEND l_fieldcat TO p_fieldtab.
  l_fieldcat-fieldname  = 'ROUTE'.
  l_fieldcat-outputlen  = 10.
  l_fieldcat-seltext_l  = 'Route'.
  l_fieldcat-no_zero = 'X'.
  APPEND l_fieldcat TO p_fieldtab.
  l_fieldcat-fieldname  = 'DLV_DT'.
  l_fieldcat-outputlen  = 10.
  l_fieldcat-seltext_l  = 'Delivered date'.
  APPEND l_fieldcat TO p_fieldtab.
  l_fieldcat-fieldname  = 'DLVD_QTY'.
  l_fieldcat-outputlen  = 10.
  l_fieldcat-seltext_l  = 'Delivered Qty'.
  l_fieldcat-no_zero = ' '.
  APPEND l_fieldcat TO p_fieldtab.
  l_fieldcat-fieldname  = 'CHLN_NO'.
  l_fieldcat-outputlen  = 15.
  l_fieldcat-seltext_l  = 'Challan No'.
  APPEND l_fieldcat TO p_fieldtab.
  l_fieldcat-fieldname  = 'GRN_NO'.
  l_fieldcat-outputlen  = 15.
  l_fieldcat-seltext_l  = 'GR Number'.
  APPEND l_fieldcat TO p_fieldtab.
  l_fieldcat-fieldname  = 'TRUCK_NO'.
  l_fieldcat-outputlen  = 10.
  l_fieldcat-seltext_l  = 'Truck No'.
  APPEND l_fieldcat TO p_fieldtab.
  l_fieldcat-fieldname  = 'VSART'.
  l_fieldcat-outputlen  = 10.
  l_fieldcat-seltext_l  = 'Ship.Typ '.
  l_fieldcat-no_zero = ' '.
  APPEND l_fieldcat TO p_fieldtab.
  l_fieldcat-fieldname  = 'SDABW'.
  l_fieldcat-outputlen  = 10.
  l_fieldcat-seltext_l  = 'Sp.Proc Ind '.
  l_fieldcat-no_zero = ' '.
  APPEND l_fieldcat TO p_fieldtab.
  l_fieldcat-fieldname  = 'PEND_QTY'.
  l_fieldcat-outputlen  = 10.
  l_fieldcat-seltext_l  = 'Pending Qty'.
  l_fieldcat-no_zero = ' '.
  APPEND l_fieldcat TO p_fieldtab.
  l_fieldcat-fieldname  = 'KZWI5'.
  l_fieldcat-outputlen  = 13.
  l_fieldcat-seltext_l  = 'Value'.
  APPEND l_fieldcat TO p_fieldtab.
  CLEAR l_fieldcat.
ENDFORM.                    " FIELDCAT
*&---------------------------------------------------------------------*
*&      Form  EVENTTAB
*&---------------------------------------------------------------------*
FORM eventtab USING p_events TYPE slis_t_event.
  DATA: ls_event TYPE slis_alv_event.
  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
      i_list_type = 0
    IMPORTING
      et_events   = p_events.
  READ TABLE p_events WITH KEY name = slis_ev_top_of_page
                           INTO ls_event.
  IF sy-subrc = 0.
    MOVE formname_top_of_page TO ls_event-form.
    APPEND ls_event TO p_events.
  ENDIF.
ENDFORM.                    " EVENTTAB
*&--------------------------------------------------------------------*
*&      Form  BUILD_LAYOUT
*&--------------------------------------------------------------------*
FORM build_layout USING p_layout TYPE slis_layout_alv.
  p_layout-f2code       = f2code.
  p_layout-zebra        = 'X'.
  p_layout-detail_popup = 'X'.
ENDFORM.                    " BUILD_LAYOUT
*&---------------------------------------------------------------------*
*&      Form  COMMENT
*&---------------------------------------------------------------------*
FORM comment  USING    p_i_heading TYPE slis_t_listheader.
  DATA: hline TYPE slis_listheader,
        text(60) TYPE c,
        sep(20) TYPE c.
  CLEAR: hline, text.
  hline-typ  = 'H'.
  WRITE : 'Pending Sale Order Details' TO hline-info.
  APPEND hline TO i_heading.
ENDFORM.                    " COMMENT
*&--------------------------------------------------------------------*
*&      Form  TOP_OF_PAGE
*&--------------------------------------------------------------------*
FORM top_of_page.
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = i_heading
      i_logo             = 'ALV_REPORT'.
ENDFORM.                    " TOP_OF_PAGE
*&---------------------------------------------------------------------*
*&      Form  call_alv
*&---------------------------------------------------------------------*
FORM call_alv .
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_interface_check        = ' '
      i_buffer_active          = ' '
      i_callback_program       = i_repname
      i_callback_pf_status_set = ' '
      i_callback_user_command  = 'FRM_ALV_USER_COMMAND'
      i_structure_name         = 'ITAB_VBAK'
      i_background_id          = ' '
      is_layout                = i_layout
      it_fieldcat              = i_fieldtab
      it_sort                  = i_sort[]
      i_default                = 'X'
      i_save                   = 'A'
      is_variant               = i_variant
      it_events                = i_events[]
      is_print                 = i_print
    TABLES
      t_outtab                 = itab_vbak.
  IF sy-subrc <> 0.
    WRITE: 'SY-SUBRC: ', sy-subrc, 'REUSE_ALV_LIST_DISPLAY'.
  ENDIF.
ENDFORM.                    " call_alv
*&--------------------------------------------------------------------*
*&      Form  frm_alv_user_command
*&--------------------------------------------------------------------*
FORM frm_alv_user_command USING ucomm LIKE sy-ucomm
              selfield TYPE slis_selfield.
  CASE ucomm.
    WHEN '&IC1'.
      IF selfield-tabname = 'ITAB_VBAK'.
        IF selfield-fieldname = 'VBELN'.
          READ TABLE itab_vbak INDEX selfield-tabindex.
          IF sy-subrc = 0.
            SET PARAMETER ID 'AUN' FIELD itab_vbak-vbeln.
            CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
          ENDIF.
        ELSEIF selfield-fieldname = 'DELIV'.
          READ TABLE itab_vbak INDEX selfield-tabindex.
          IF sy-subrc = 0.
            SET PARAMETER ID 'VL' FIELD itab_vbak-deliv.
            CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN.
          ENDIF.
        ENDIF.
      ENDIF.
  ENDCASE.
ENDFORM.                    "frm_alv_user_command
 
*---------------------------------------------------------------------*
* Report  : ZOPEN_ORD_AGE                                              
* Purpose : Aging analysis of Open Sale orders                     
* Display balance amount of open sale order with pending days
*Days can not be greater than 998 days
*---------------------------------------------------------------------*

REPORT zopen_ord_age MESSAGE-ID fr NO STANDARD PAGE HEADING
LINE-SIZE 300.

TABLES : vbrp, vbak, vbap, kna1, vbuk, vbpa, vbfa,vbup, bhdgd.

DATA : tot_amt TYPE vbrk-netwr.

DATA  posnr LIKE vbap-posnr.

DATA: BEGIN OF itab_vbak2 OCCURS 0,
      vbeln TYPE vbak-vbeln,           "sales order no
      posnr TYPE vbap-posnr,
      audat TYPE vbak-audat,
      spart TYPE vbak-spart,           " Division
      vkbur TYPE vbak-vkbur,           " Sales office
      kunnr TYPE vbak-kunnr,
      fkrel TYPE vbap-fkrel,
      matkl TYPE vbap-matkl,
      matnr TYPE vbap-matnr,
      werks TYPE vbap-werks,
      days      TYPE i,              " Diff with Key date
      kzwi5 TYPE vbap-kzwi5,
      bal_amt TYPE vbap-kzwi5,
END OF itab_vbak2.

DATA: BEGIN OF itab_vbak3 OCCURS 0,
      vbeln LIKE vbak-vbeln,           "sales order no
      posnr LIKE vbap-posnr,
      audat LIKE vbak-audat,
      spart LIKE vbak-spart,           " Division
      vkbur LIKE vbak-vkbur,           " Sales office
      kunnr LIKE vbak-kunnr,
      name  LIKE kna1-name1,
      matkl LIKE vbap-matkl,
      matnr LIKE vbap-matnr,
      werks LIKE vbap-werks,
      kzwi5 LIKE vbap-kzwi5,
      amt1  TYPE p DECIMALS 2,   " Bal at start of period
      amt2  TYPE p DECIMALS 2,   " Bal at start of period
      amt3  TYPE p DECIMALS 2,   " Bal at start of period
      amt4      TYPE p DECIMALS 2,   " Bal at start of period
      amt5      TYPE p DECIMALS 2,   " Bal at start of period
      amt6      TYPE p DECIMALS 2,   " Bal at start of period
END OF itab_vbak3.

*data declaration for printing day range
DATA: BEGIN OF varueb1,
        feld1(80)   TYPE c,
        feld2(14)   TYPE c,
        feld3(14)   TYPE c,
        feld4(14)   TYPE c,
        feld5(14)   TYPE c,
        feld6(14)   TYPE c,
        feld7(14)   TYPE c,
      END   OF varueb1.

DATA: BEGIN OF varueb2,
        feld1(80)   TYPE c,
        feld2(14)   TYPE c,
        feld3(14)   TYPE c,
        feld4(14)   TYPE c,
        feld5(14)   TYPE c,
        feld6(14)   TYPE c,
        feld7(14)   TYPE c,
      END   OF varueb2.

DATA: varueb3(255),
      varueb4(255),
      vartxt1(40),
      vartxt(40)  TYPE c.
*--------------------------------------------------------------------*
DATA: rp01(2)   TYPE p,                                     "   0
      rp02(2)   TYPE p,                                     "  20
      rp03(2)   TYPE p,                                     "  40
      rp04(2)   TYPE p,                                     "  80
      rp05(2)   TYPE p,                                     " 100
      rp06(2)   TYPE p,                                     "   1
      rp07(2)   TYPE p,                                     "  21
      rp08(2)   TYPE p,                                     "  41
      rp09(2)   TYPE p,                                     "  81
      rp10(2)   TYPE p.                                     " 101

DATA: rc01(4)   TYPE c,                "  0
      rc02(4)   TYPE c,                                     "  20
      rc03(4)   TYPE c,                                     "  40
      rc04(4)   TYPE c,                                     "  80
      rc05(4)   TYPE c,                                     " 100
      rc06(4)   TYPE c,                                     "   1
      rc07(4)   TYPE c,                                     "  21
      rc08(4)   TYPE c,                                     "  41
      rc09(4)   TYPE c,                                     "  81
      rc10(4)   TYPE c.                                     " 101

DATA: col01(15)  TYPE c,
      col02(15)  TYPE c,
      col03(15)  TYPE c,
      col04(15)  TYPE c,
      col05(15)  TYPE c,
      col06(15)  TYPE c.

DATA: waers LIKE t001-waers VALUE 'INR',
      v_name(40),
      v_vkbur(5),
      v_temp(132),
      text_val(172).

*FOR ALV DISPLAY
TYPE-POOLS: slis.
CONSTANTS: formname_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE'.

*Data Decelararion for alv display
DATA: i_fieldtab TYPE slis_t_fieldcat_alv,
      i_heading  TYPE slis_t_listheader,
      i_layout   TYPE slis_layout_alv,
      i_sort     TYPE slis_t_sortinfo_alv,
      i_print    TYPE slis_print_alv,
      i_events   TYPE slis_t_event,
      i_repname  LIKE sy-repid,
      f2code   LIKE sy-ucomm VALUE  '&ETA',
      i_save(1) TYPE c,
      i_exit(1) TYPE c,
      i_variant LIKE disvariant,
      h_text(50).

DATA: w_variant          LIKE disvariant,
      wx_variant         LIKE disvariant,
      w_variant_save(1)  TYPE c,
      w_exit(1) TYPE c,
      w_repid LIKE sy-repid.

*Selection screen declarations
START-OF-SELECTION.
  SELECTION-SCREEN SKIP 1.
  SELECTION-SCREEN BEGIN OF BLOCK v1 WITH FRAME TITLE text-001.
  SELECT-OPTIONS:
                 psal_org FOR vbak-vkorg OBLIGATORY,
                 psal_off FOR vbak-vkbur,
                 pspart FOR vbap-spart OBLIGATORY,
                 werks FOR vbap-werks,
                 pmatkl FOR vbap-matkl,
                 pmatnr FOR vbap-matnr,
                 paudat FOR vbak-audat OBLIGATORY,
                 pord_no FOR vbak-vbeln.

  PARAMETERS : key_date LIKE sy-datum DEFAULT sy-datum.
  SELECTION-SCREEN END OF BLOCK v1.
  SELECTION-SCREEN SKIP 1.

  SELECTION-SCREEN BEGIN OF BLOCK v2 WITH FRAME TITLE text-002.
  SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT 01(30) text-003.
  SELECTION-SCREEN POSITION POS_LOW.
  PARAMETERS:
              day1 LIKE rfpdo1-allgrogr DEFAULT '030'.
  PARAMETERS:
              day2 LIKE rfpdo1-allgrogr DEFAULT '060'.
  PARAMETERS:
              day3 LIKE rfpdo1-allgrogr DEFAULT '090'.
  PARAMETERS:
              day4 LIKE rfpdo1-allgrogr DEFAULT '120'.
  PARAMETERS:
              day5 LIKE rfpdo1-allgrogr DEFAULT '150'.
  SELECTION-SCREEN END OF LINE.

  PARAMETERS: p_vari LIKE disvariant-variant.
  SELECTION-SCREEN END OF BLOCK v2.

  REFRESH: itab_vbak2, itab_vbak3.

INITIALIZATION.
  i_repname = sy-repid.
  REFRESH: i_fieldtab,i_events, i_heading.
  CLEAR: i_fieldtab, i_events, i_heading.
* For variant
  PERFORM init_variant.
  PERFORM variant_default USING p_vari.

*-----------------------------------
* At Selection Screen Value Request
*-----------------------------------
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_vari.
  PERFORM variant_f4 USING p_vari.

AT SELECTION-SCREEN.
  PERFORM variant_fill.

START-OF-SELECTION.

  PERFORM check_days_range.

* For printing day range
* initialization for printing report info
  MOVE '0'      TO bhdgd-inifl.
  MOVE sy-linsz TO bhdgd-lines.
  MOVE sy-uname TO bhdgd-uname.
  MOVE sy-repid TO bhdgd-repid.
  MOVE sy-title TO bhdgd-line1.
  MOVE '    '   TO bhdgd-line2.
  MOVE '1000'   TO bhdgd-bukrs.
  MOVE '    '   TO bhdgd-miffl.
  MOVE '    '   TO bhdgd-separ.
  MOVE 'BUKRS'  TO bhdgd-domai.

  PERFORM print_dayrange.

  SELECT vbeln audat vkorg vtweg vkbur kunnr
         FROM vbak
         INTO
         (vbak-vbeln, vbak-audat, vbak-vkorg,
          vbak-vtweg, vbak-vkbur, vbak-kunnr)
         WHERE vbeln IN pord_no
         AND audat IN paudat
         AND vbtyp = 'C'
         AND vkorg IN psal_org
         AND spart IN pspart
         AND vkbur IN psal_off.

*   authorization object
    AUTHORITY-CHECK OBJECT 'V_VBAK_VKO'
           ID 'VKORG' FIELD vbak-vkorg
           ID 'VTWEG' FIELD vbak-vtweg
           ID 'SPART' FIELD vbak-spart
           ID 'ACTVT' FIELD '03'.
    IF sy-subrc <> 0.
      MESSAGE e208(00) WITH 'No relevant authorizations found'.
    ENDIF.

    IF sy-subrc = 0.
      SELECT posnr matkl matnr fkrel spart werks kzwi5
               FROM vbap INTO
               (itab_vbak2-posnr, itab_vbak2-matkl,
               itab_vbak2-matnr,itab_vbak2-fkrel,itab_vbak2-spart,
               itab_vbak2-werks, itab_vbak2-kzwi5)
               WHERE vbeln = vbak-vbeln .

        CHECK ( itab_vbak2-fkrel = 'A'     "Delivery-related billing doc
             OR itab_vbak2-fkrel = 'D' )   "Relevant for pro forma
          AND itab_vbak2-matkl IN pmatkl
          AND itab_vbak2-matnr IN pmatnr
          AND itab_vbak2-spart IN pspart.

        itab_vbak2-vbeln = vbak-vbeln.
        itab_vbak2-audat = vbak-audat.
        itab_vbak2-vkbur = vbak-vkbur.
        itab_vbak2-kunnr = vbak-kunnr.

        SELECT SINGLE * FROM vbup WHERE vbeln = itab_vbak2-vbeln
                                    AND posnr = itab_vbak2-posnr
                                    AND gbsta NE 'C'.

*       difference in posting date and key date
        itab_vbak2-days = key_date - itab_vbak2-audat.

        IF sy-subrc EQ 0 AND itab_vbak2-days GE 0.

*         For pending amount - sum biling amounts
          SELECT SINGLE vbfa~vbeln vbfa~posnn
                 INTO (vbfa-vbeln, vbfa-posnn)
             FROM vbfa
             WHERE vbelv = itab_vbak2-vbeln
               AND posnv = itab_vbak2-posnr
               AND vbtyp_n = 'M'.

          IF sy-subrc = 0.
            SELECT SINGLE * FROM vbrp WHERE vbeln = vbfa-vbeln
                   AND posnr = vbfa-posnn.
*           get gross bill amount
            itab_vbak2-bal_amt = vbrp-kzwi5.
            APPEND itab_vbak2.
          ENDIF.
          CLEAR itab_vbak2.
        ENDIF.
      ENDSELECT.
    ENDIF.
  ENDSELECT.

* Sorting amount according to posting date in range defined
  PERFORM amount_range TABLES itab_vbak2 itab_vbak3.

END-OF-SELECTION.

  PERFORM fieldcat USING i_fieldtab[].
  PERFORM eventtab USING i_events[].
  PERFORM comment USING i_heading[].
  PERFORM get_final_data.

  FREE: itab_vbak2, itab_vbak3.

*&---------------------------------------------------------------------*
*&      Form  fieldcat
*&---------------------------------------------------------------------*
FORM fieldcat USING p_fieldtab TYPE slis_t_fieldcat_alv.

  DATA: l_fieldcat TYPE slis_fieldcat_alv.
  CLEAR l_fieldcat.

* DATA FIELD CATALOG for DETAIL LIST - Field Description to ALV

  DATA: day11 LIKE rfpdo1-allgrogr,
        day22 LIKE rfpdo1-allgrogr,
        day33 LIKE rfpdo1-allgrogr,
        day44 LIKE rfpdo1-allgrogr,
        day55 LIKE rfpdo1-allgrogr.

  day11 = day1 + 1.
  day22 = day2 + 1.
  day33 = day3 + 1.
  day44 = day4 + 1.
  day55 = day5 + 1.

  CONCATENATE 'To' day1+1(2) INTO col01 SEPARATED BY space.
  CONCATENATE 'Fr' day11+1(2) 'To' day2+1(2) INTO col02
  SEPARATED BY space.
  CONCATENATE 'Fr' day22+1(2) 'To' day3 INTO col03 SEPARATED BY space.
  CONCATENATE 'Fr' day33 'To' day4 INTO col04 SEPARATED BY space.
  CONCATENATE 'Fr' day44 'To' day5 INTO col05 SEPARATED BY space.
  CONCATENATE 'Fr' day55 INTO col06 SEPARATED BY space.

  CLEAR l_fieldcat.
  l_fieldcat-tabname    = 'ITAB_VBAK3'.

  l_fieldcat-fieldname  = 'VKBUR'.
  l_fieldcat-outputlen  = 8.
  l_fieldcat-seltext_l  = 'Sales Off'.
  APPEND l_fieldcat TO p_fieldtab.
  CLEAR l_fieldcat.

  l_fieldcat-fieldname  = 'SPART'.
  l_fieldcat-outputlen  = 2.
  l_fieldcat-seltext_l  = 'Dv'.
  APPEND l_fieldcat TO p_fieldtab.
  CLEAR l_fieldcat.

  l_fieldcat-fieldname  = 'VBELN'.
  l_fieldcat-outputlen  = 8.
  l_fieldcat-no_zero = 'X'.
  l_fieldcat-seltext_l  = 'Doc No'.
  APPEND l_fieldcat TO p_fieldtab.
  CLEAR l_fieldcat.

  l_fieldcat-fieldname  = 'POSNR'.
  l_fieldcat-outputlen  = 3.
  l_fieldcat-no_zero = 'X'.
  l_fieldcat-seltext_l  = 'Item'.
  APPEND l_fieldcat TO p_fieldtab.
  CLEAR l_fieldcat.

  l_fieldcat-fieldname  = 'KUNNR'.
  l_fieldcat-outputlen  = 6.
  l_fieldcat-no_zero = 'X'.
  l_fieldcat-seltext_l  = 'Sold to Party'.
  APPEND l_fieldcat TO p_fieldtab.
  CLEAR l_fieldcat.

  l_fieldcat-fieldname  = 'NAME'.
  l_fieldcat-outputlen  = 12.
  l_fieldcat-seltext_l  = 'Name'.
  APPEND l_fieldcat TO p_fieldtab.
  CLEAR l_fieldcat.

  l_fieldcat-fieldname  = 'MATKL'.
  l_fieldcat-outputlen  = 4.
  l_fieldcat-seltext_l  = 'Mat Group'.
  APPEND l_fieldcat TO p_fieldtab.
  CLEAR l_fieldcat.

  l_fieldcat-fieldname  = 'MATNR'.
  l_fieldcat-outputlen  = 8.
  l_fieldcat-seltext_l  = 'Mat No'.
  l_fieldcat-no_zero = 'X'.
  APPEND l_fieldcat TO p_fieldtab.
  CLEAR l_fieldcat.

  l_fieldcat-fieldname  = 'WERKS'.
  l_fieldcat-outputlen  = 6.
  l_fieldcat-seltext_l  = 'Plant'.
  l_fieldcat-no_zero = ' '.
  APPEND l_fieldcat TO p_fieldtab.
  CLEAR l_fieldcat.

  l_fieldcat-fieldname  = 'KZWI5'.
  l_fieldcat-outputlen  = 13.
  l_fieldcat-seltext_l  = 'Net amount'.
  APPEND l_fieldcat TO p_fieldtab.
  CLEAR l_fieldcat.

  l_fieldcat-fieldname  = 'AMT1'.
  l_fieldcat-outputlen  = 13.
  l_fieldcat-seltext_l  = col01.
  APPEND l_fieldcat TO p_fieldtab.
  CLEAR l_fieldcat.

  IF day1 <> ' '.
    l_fieldcat-fieldname  = 'AMT2'.
    l_fieldcat-outputlen  = 13.
    l_fieldcat-seltext_l  = col02.    "'From 16 To 60'.
    APPEND l_fieldcat TO p_fieldtab.
    CLEAR l_fieldcat.
  ENDIF.
  IF day2 <> ' '.
    l_fieldcat-fieldname  = 'AMT3'.
    l_fieldcat-outputlen  = 13.
    l_fieldcat-seltext_l  = col03.    "'From 61 To 90'.
    APPEND l_fieldcat TO p_fieldtab.
    CLEAR l_fieldcat.
  ENDIF.
  IF day3 <> ' '.
    l_fieldcat-fieldname  = 'AMT4'.
    l_fieldcat-outputlen  = 13.
    l_fieldcat-seltext_l  = col04.     "'From 91 To 180'.
    APPEND l_fieldcat TO p_fieldtab.
    CLEAR l_fieldcat.
  ENDIF.
  IF day4 <> ' '.
    l_fieldcat-fieldname  = 'AMT5'.
    l_fieldcat-outputlen  = 13.
    l_fieldcat-seltext_l  = col05.      "'From 181 To 360'.
    APPEND l_fieldcat TO p_fieldtab.
    CLEAR l_fieldcat.
  ENDIF.
  IF day5 <> ' '.
    l_fieldcat-fieldname  = 'AMT6'.
    l_fieldcat-outputlen  = 13.
    l_fieldcat-seltext_l  = col06.      "'From 360'.
    APPEND l_fieldcat TO p_fieldtab.
    CLEAR l_fieldcat.
  ENDIF.

  CLEAR l_fieldcat.
ENDFORM.                    " FIELDCAT
*&---------------------------------------------------------------------*
*&      Form  EVENTTAB
*&---------------------------------------------------------------------*
FORM eventtab USING p_events TYPE slis_t_event.

  DATA: ls_event TYPE slis_alv_event.
  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
      i_list_type = 0
    IMPORTING
      et_events   = p_events.

  READ TABLE p_events WITH KEY name = slis_ev_top_of_page
                           INTO ls_event.
  IF sy-subrc = 0.
    MOVE formname_top_of_page TO ls_event-form.
    APPEND ls_event TO p_events.
  ENDIF.

ENDFORM.                    " EVENTTAB
*&--------------------------------------------------------------------*
*&      Form  BUILD_LAYOUT
*&--------------------------------------------------------------------*
FORM build_layout USING p_layout TYPE slis_layout_alv.

  p_layout-f2code       = f2code.
  p_layout-zebra        = 'X'.
  p_layout-detail_popup = 'X'.

ENDFORM.                    " BUILD_LAYOUT
*&---------------------------------------------------------------------*
*&      Form  COMMENT
*&---------------------------------------------------------------------*
FORM comment  USING    p_i_heading TYPE slis_t_listheader.

  DATA: hline TYPE slis_listheader,
        hline1 TYPE slis_listheader,
        text(60) TYPE c,
        sep(20) TYPE c,
        yrs(4) TYPE c,
        mnths(2) TYPE c,
        days(2) TYPE c,
        date(10) TYPE c.
  CLEAR: hline, hline1, text.

  hline-typ  = 'H'.

  WRITE : 'Open Sale Order Aging Details' TO hline-info.
  APPEND hline TO i_heading.
  hline1-typ  = 'H'.
*   to convert date format from yyyymmdd to ddmmyyyy
  days  = key_date+6(2).
  mnths = key_date+4(2).
  yrs   = key_date(4).
  CONCATENATE days mnths yrs INTO text SEPARATED BY '.'.
  CONCATENATE 'as on Key Date : ' text INTO text.
  WRITE: text TO hline1-info.
  APPEND hline1 TO i_heading.

ENDFORM.                    " COMMENT
*&--------------------------------------------------------------------*
*&      Form  TOP_OF_PAGE
*&--------------------------------------------------------------------*
FORM top_of_page.
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = i_heading
      i_logo             = 'ALV_REPORT'.

ENDFORM.                    " TOP_OF_PAGE
*&---------------------------------------------------------------------*
*&      Form  CHECK_DAYS_RANGE
*&---------------------------------------------------------------------*
FORM check_days_range .

  IF day1 GT '998'
   OR day2 GT '998'
   OR day3 GT '998'
   OR day4 GT '998'
   OR day5 GT '998'.

*   SET CURSOR FIELD day5.
    MESSAGE e381.
  ENDIF.

  IF NOT day5 IS INITIAL.
    IF  day5 GT day4
    AND day4 GT day3
    AND day3 GT day2
    AND day2 GT day1.
    ELSE.
      MESSAGE e379.
    ENDIF.
  ELSE.
    IF NOT day4 IS INITIAL.
      IF  day4 GT day3
      AND day3 GT day2
      AND day2 GT day1.
      ELSE.
        MESSAGE e379.
      ENDIF.
    ELSE.
      IF NOT day3 IS INITIAL.
        IF  day3 GT day2
        AND day2 GT day1.
        ELSE.
          MESSAGE e379.
        ENDIF.
      ELSE.
        IF NOT day2 IS INITIAL.
          IF  day2 GT day1.
          ELSE.
            MESSAGE e379.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.

ENDFORM.                    " CHECK_DAYS_RANGE
*&---------------------------------------------------------------------*
*&      Form  PRINT_DAYRANGE
*&---------------------------------------------------------------------*
FORM print_dayrange .

  DATA: text(10).

  rp01 = day1.
  rp02 = day2.
  rp03 = day3.
  rp04 = day4.
  rp05 = day5.

  rp06 = rp01 + 1.
  IF NOT rp02 IS INITIAL.
    rp07 = rp02 + 1.
  ENDIF.
  IF NOT rp03 IS INITIAL.
    rp08 = rp03 + 1.
  ENDIF.
  IF NOT rp04 IS INITIAL.
    rp09 = rp04 + 1.
  ENDIF.
  IF NOT rp05 IS INITIAL.
    rp10 = rp05 + 1.
  ENDIF.

  WRITE: rp01 TO rc01.
  IF NOT rp02 IS INITIAL.
    WRITE: rp02 TO rc02.
    MOVE text-202 TO varueb2-feld3.
  ENDIF.
  IF NOT rp03 IS INITIAL.
    WRITE: rp03 TO rc03.
    MOVE text-203 TO varueb2-feld4.
  ENDIF.
  IF NOT rp04 IS INITIAL.
    WRITE: rp04 TO rc04.
    MOVE text-204 TO varueb2-feld5.
  ENDIF.
  IF NOT rp05 IS INITIAL.
    WRITE: rp05 TO rc05.
    MOVE text-205 TO varueb2-feld6.
  ENDIF.
  IF NOT rp06 IS INITIAL.
    WRITE: rp06 TO rc06.
    MOVE text-206 TO varueb1-feld3.
  ENDIF.
  IF NOT rp07 IS INITIAL.
    WRITE: rp07 TO rc07.
    MOVE text-207 TO varueb1-feld4.
  ENDIF.
  IF NOT rp08 IS INITIAL.
    WRITE: rp08 TO rc08.
    MOVE text-208 TO varueb1-feld5.
  ENDIF.
  IF NOT rp09 IS INITIAL.
    WRITE: rp09 TO rc09.
    MOVE text-209 TO varueb1-feld6.
  ENDIF.
  IF NOT rp10 IS INITIAL.
    WRITE: rp10 TO rc10.
    MOVE text-210 TO varueb1-feld7.
  ENDIF.

* Variable
  v_name = ' Order            SOff'.
  v_temp = text-005.
  CONCATENATE v_temp+0(10) v_name  v_temp+10(5) '  SGrp '
              v_temp+20(112)
              INTO text_val.
  MOVE text_val TO varueb1-feld1.

  MOVE text-201 TO varueb2-feld2.

  REPLACE 'RP01' WITH rc01 INTO varueb2.                    "bis   0
  REPLACE 'RP02' WITH rc02 INTO varueb2.                    "bis  20
  REPLACE 'RP03' WITH rc03 INTO varueb2.                    "bis  40
  REPLACE 'RP04' WITH rc04 INTO varueb2.                    "bis  80
  REPLACE 'RP05' WITH rc05 INTO varueb2.                    "bis 100
  REPLACE 'RP06' WITH rc06 INTO varueb1.                    "von   1
  REPLACE 'RP07' WITH rc07 INTO varueb1.                    "von  21
  REPLACE 'RP08' WITH rc08 INTO varueb1.                    "von  41
  REPLACE 'RP09' WITH rc09 INTO varueb1.                    "von  81
  REPLACE 'RP10' WITH rc10 INTO varueb1.                    "von 101

  MOVE text-010 TO varueb3.

  WRITE key_date TO text DD/MM/YY.
  CONDENSE text.
  REPLACE '$STIDA' WITH text INTO varueb3.

  WRITE waers TO text.
  CONDENSE text.
  REPLACE '$SKAL' WITH waers INTO varueb3.

ENDFORM.                    " PRINT_DAYRANGE
*&---------------------------------------------------------------------*
*&      Form  GET_FINAL_DATA
*&---------------------------------------------------------------------*
FORM get_final_data .

  PERFORM build_layout USING i_layout.
  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      i_program_name     = i_repname
      i_internal_tabname = 'INV'
      i_inclname         = i_repname
    CHANGING
      ct_fieldcat        = i_fieldtab.
  IF sy-subrc <> 0.
    WRITE: 'SY-SUBRC: ', sy-subrc, 'REUSE_ALV_FIELDCATALOG_MERGE'.
  ENDIF.

*LIST display
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_interface_check        = ' '
      i_buffer_active          = ' '
      i_callback_program       = i_repname
      i_callback_pf_status_set = ' '
      i_callback_user_command  = 'USER_COMMAND'
      i_structure_name         = 'ITAB_VBAK3'
      is_layout                = i_layout
      it_fieldcat              = i_fieldtab
      it_sort                  = i_sort[]
      i_default                = 'X'
      i_save                   = 'A'
      is_variant               = i_variant
      it_events                = i_events[]
      is_print                 = i_print
    TABLES
      t_outtab                 = itab_vbak3.
  IF sy-subrc <> 0.
    WRITE: 'SY-SUBRC: ', sy-subrc, 'REUSE_ALV_GRID_DISPLAY'.
  ENDIF.

ENDFORM.                    " GET_FINAL_DATA
*&---------------------------------------------------------------------*
*&      Form  AMOUNT_RANGE
*&---------------------------------------------------------------------*
FORM amount_range TABLES i1 LIKE itab_vbak2[]
                         i2 LIKE itab_vbak3[].
  DATA: r_tage TYPE p,
        adj_amt LIKE bsid-wrbtr,
        amt1 LIKE bsid-wrbtr,
        amt2 LIKE bsid-wrbtr,
        amt3 LIKE bsid-wrbtr,
        amt4 LIKE bsid-wrbtr,
        amt5 LIKE bsid-wrbtr,
        amt6 LIKE bsid-wrbtr.

  LOOP AT i1.

    IF i1-bal_amt  > 0.
      r_tage = i1-days.

      IF r_tage <= rp01.
        amt1 = amt1 + i1-bal_amt .
      ELSE.
        IF r_tage <= rp02
        OR rp07 IS INITIAL.
          amt2 = amt2 + i1-bal_amt .
        ELSE.
          IF r_tage <= rp03
          OR rp08 IS INITIAL.
            amt3 = amt3 + i1-bal_amt .
          ELSE.
            IF r_tage <= rp04
            OR rp09 IS INITIAL.
              amt4 = amt4 + i1-bal_amt .
            ELSE.
              IF r_tage <= rp05
              OR rp10 IS INITIAL.
                amt5 = amt5 + i1-bal_amt .
              ELSE.
                amt6 = amt6 + i1-bal_amt .
              ENDIF.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.

    MOVE-CORRESPONDING i1 TO i2.
    i2-amt1 = amt1.
    i2-amt2 = amt2.
    i2-amt3 = amt3.
    i2-amt4 = amt4.
    i2-amt5 = amt5.
    i2-amt6 = amt6.
    SELECT SINGLE kunnr name1 FROM kna1 INTO
       (i2-kunnr, i2-name)
        WHERE kunnr = i1-kunnr.
    APPEND i2.
    CLEAR: amt1, amt2, amt3, amt4, amt5, amt6, i2.
  ENDLOOP.

  FREE i1.

ENDFORM.                    " AMOUNT_RANGE
*&---------------------------------------------------------------------*
*&      Form  init_variant
*&---------------------------------------------------------------------*
FORM init_variant .

  CLEAR: w_variant.
  w_repid = sy-repid.
  w_variant-report = w_repid.
  w_variant-username = sy-uname.
  w_variant_save = 'A'.  " All type

ENDFORM.                    " init_variant
*&---------------------------------------------------------------------*
*&      Form  variant_default
*&---------------------------------------------------------------------*
FORM variant_default  USING p_variant.

  wx_variant = w_variant.

  IF NOT p_variant IS INITIAL.
    wx_variant-variant = p_variant.
  ENDIF.

  CALL FUNCTION 'LVC_VARIANT_DEFAULT_GET'
    EXPORTING
      i_save        = w_variant_save
    CHANGING
      cs_variant    = wx_variant
    EXCEPTIONS
      wrong_input   = 1
      not_found     = 2
      program_error = 3
      OTHERS        = 4.

  CASE sy-subrc.
    WHEN 0.
      p_variant = wx_variant-variant.
    WHEN 2.
      CLEAR p_variant.
  ENDCASE.

ENDFORM.                    " variant_default
*&---------------------------------------------------------------------*
*&      Form  variant_f4
*&---------------------------------------------------------------------*
FORM variant_f4  USING  p_variant.

  CALL FUNCTION 'LVC_VARIANT_F4'
    EXPORTING
      is_variant    = w_variant
      i_save        = w_variant_save
    IMPORTING
      e_exit        = w_exit
      es_variant    = wx_variant
    EXCEPTIONS
      not_found     = 1
      program_error = 2
      OTHERS        = 3.

  IF w_exit IS INITIAL.
    w_variant-variant = wx_variant-variant.
    p_variant  = wx_variant-variant.
  ENDIF.
ENDFORM.                    " variant_f4
*&---------------------------------------------------------------------*
*&      Form  variant_fill
*&---------------------------------------------------------------------*
FORM variant_fill .
  CLEAR w_variant.
  IF p_vari IS INITIAL.
    w_variant-variant = 'STANDARD'.
    w_variant-report = w_repid.
  ELSE.
    w_variant-variant = p_vari.
    w_variant-report = w_repid.

    CALL FUNCTION 'LVC_VARIANT_EXISTENCE_CHECK'
      EXPORTING
        i_save     = w_variant_save
      CHANGING
        cs_variant = w_variant
      EXCEPTIONS
        OTHERS     = 01.

  ENDIF.
ENDFORM.                    " variant_fill
 
TYPES:BEGIN OF s_all,
  vkorg TYPE vkorg,              "sales organization
  fkart TYPE fkart,              "billing type
  fkdat TYPE fkdat,              "billing date
  b_vbeln TYPE vbeln_vf,           "billing document
  kunag TYPE kunag,              "sold-to party
  spart TYPE spart,              "division
  gsber TYPE gsber,              "business area
  bstnk TYPE bstnk,              "po munber
  aubel TYPE vbeln_va,           "sales document
  matnr TYPE matnr,              "material number
  kwert TYPE kwert,              "gross value
  kbetr TYPE kbetr,              "rate(condition amount or percentage)
  knumv TYPE knumv,              "number of document condition
  kposn TYPE kposn,              "condition item number
  kschl TYPE kscha,              "condition type
  b_posnr TYPE posnr_vf,           "billing item
  waerk TYPE waerk,              "sd document currency
  kurrf TYPE kurrf,              "exchange rate_accntg
  name1 TYPE name1_gp,                                      "name 1
  kunnr TYPE name1,              "customer name 1
  arktx TYPE arktx,              "short text for sales order item
  fkimg TYPE fkimg,              "actual billed quantity
  vrkme TYPE vrkme,              "sales unit
  netwr TYPE netwr_fp,           "net value of the billing item in document currency
  s_vbeln TYPE vbeln_va,           "sales document
  ra01_discount TYPE kbetr,      "ra01%discount
  ra01_dis_amt  TYPE kwert,      "ra01 discount amount
  ra00_discount TYPE kbetr,      "ra00%discount
  ra00_dis_amt  TYPE kwert,      "ra00 discount amount
  s_kwmeng TYPE kwmeng,            "sales order total quantity
  s_kwert  TYPE kwert,             "sales order total gross value
  END OF s_all.

TYPES: BEGIN OF s_konv,
  kwert TYPE kwert,              "gross value
  kbetr TYPE kbetr,              "rate(condition amount or percentage)
  knumv TYPE knumv,              "number of document condition
  kposn TYPE kposn,              "condition item number
  kschl TYPE kscha,              "condition type

  END OF s_konv.

TYPES: BEGIN OF s_kna1,
  name1 TYPE name1_gp,                                      "name 1
  kunnr TYPE name1,              "customer name 1
  kunag TYPE kunag,              "sold-to party
  END OF s_kna1.

TYPES: BEGIN OF s_vbap,
  kwmeng TYPE kwmeng,            "cumulative order quantity in sales units
  abgru  TYPE abgru_va,          "reason for rejection of quotations and sales orders
s_vbeln  TYPE vbeln_va,          "sales document
  END OF s_vbap.

TYPE-POOLS: slis.                      "ALV Declarations

TYPES: t_all TYPE STANDARD TABLE OF s_all,
       t_konv TYPE STANDARD TABLE OF s_konv,
       t_kna1 TYPE STANDARD TABLE OF s_kna1,
       t_vbap TYPE STANDARD TABLE OF s_vbap.

DATA: it_all TYPE t_all,
      it_konv TYPE t_konv,
      it_kna1 TYPE t_kna1,
      it_vbap TYPE t_vbap,
      it_total TYPE t_all,
      it_total_out TYPE t_all.

DATA: wa_all TYPE LINE OF t_all,
      wa_konv TYPE LINE OF t_konv,
      wa_kna1 TYPE LINE OF t_kna1,
      wa_vbap TYPE LINE OF t_vbap,
      wa_total TYPE LINE OF t_all,
      wa_total_out TYPE LINE OF t_all.

DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
      gd_repid     LIKE sy-repid.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-000.

SELECT-OPTIONS: x_vkorg FOR wa_all-vkorg,                                "sales organization
                x_fkart FOR wa_all-fkart MATCHCODE OBJECT h_tvfk,        "billing type
                x_fkdat FOR wa_all-fkdat,                                "billing date
                x_vbeln FOR wa_all-b_vbeln MATCHCODE OBJECT f4_vbrk,     "billing document
                x_kunag FOR wa_all-kunag MATCHCODE OBJECT debi.          "sold-to party
SELECTION-SCREEN SKIP.

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

PARAMETERS x_check AS CHECKBOX.

SELECT-OPTIONS: x_spart FOR wa_all-spart,                                "division
                x_gsber FOR wa_all-gsber MATCHCODE OBJECT h_tgsb,        "business area
                x_matnr FOR wa_all-matnr,                                "material
                x_bstnk FOR wa_all-bstnk,                                "po munber
                x_aubel FOR wa_all-aubel.                                "sales document

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

START-OF-SELECTION.
  PERFORM data_select.
  PERFORM data_processing.

END-OF-SELECTION.
  PERFORM data_display.

*&---------------------------------------------------------------------*
*&      Form  data_select
*&---------------------------------------------------------------------*
*       perform data selecting
*----------------------------------------------------------------------*
FORM data_select.
  PERFORM select_from_vbrk_vbrp_vbak.
  PERFORM select_from_konv.
  PERFORM select_from_kna1.
  PERFORM select_from_vbap.
ENDFORM.                    "data_select
*&---------------------------------------------------------------------*
*&      Form  data_processing
*&---------------------------------------------------------------------*
*       perform data processing
*----------------------------------------------------------------------*
FORM data_processing.
  PERFORM get_gross_dis_amt.
  PERFORM get_total_gross.
  PERFORM get_total.
ENDFORM.                    "data_processing
*&---------------------------------------------------------------------*
*&      Form  data_display
*&---------------------------------------------------------------------*
*       perform data displaying
*----------------------------------------------------------------------*
FORM data_display.
  IF x_check = 'X'.
    PERFORM build_fieldcatalog.
    PERFORM display_alv_report USING it_all.
  ELSE.
    PERFORM build_fieldcatalog.
    PERFORM display_alv_report USING it_total_out.
  ENDIF.
ENDFORM.                    "data_display
*&---------------------------------------------------------------------*
*&      Form  select_from_vbrk_vbrp_vbak
*&---------------------------------------------------------------------*
*       1~select data from table vbrk/vbrp/vbak into it_all.
*       2~when billing type is 's1',add negative to net value
*----------------------------------------------------------------------*
FORM select_from_vbrk_vbrp_vbak.
  SELECT vbrk~vkorg
         vbrk~fkart
         vbrk~fkdat
         vbrk~vbeln AS b_vbeln
         vbrk~kunag
         vbrp~spart
         vbrp~matnr
         vbrp~gsber
         vbrp~aubel
         vbak~bstnk
         vbrk~knumv
         vbrp~posnr AS b_posnr
         vbrk~waerk
         vbrk~kurrf
         vbrp~matnr
         vbrp~arktx
         vbrp~fkimg
         vbrp~vrkme
         vbrp~netwr
    INTO CORRESPONDING FIELDS OF TABLE it_all
    FROM vbrp
    JOIN vbak ON vbak~vbeln = vbrp~aubel
    JOIN vbrk ON vbrk~vbeln = vbrp~vbeln
    WHERE vbrk~vkorg IN x_vkorg
    AND   vbrk~vkorg NOT IN ('4802','4803')
    AND   vbrk~fkart IN x_fkart
    AND   vbrk~fkart NOT IN ('ZMF8','ZPF8')
    AND   vbrk~fkdat IN x_fkdat
    AND   vbrk~vbeln IN x_vbeln
    AND   vbrk~kunag IN x_kunag
    AND   vbrp~spart IN x_spart
    AND   vbrp~matnr IN x_matnr
    AND   vbrp~gsber IN x_gsber
    AND   vbrp~aubel IN x_aubel.

  SORT it_all BY b_vbeln kunag.

  IF sy-subrc <> 0.
    MESSAGE i001(zjenni_msg).
  ENDIF.

  LOOP AT it_all INTO wa_all.
    IF wa_all-fkart = 'S1'.
      wa_all-netwr = -1 * wa_all-netwr.
      MODIFY it_all FROM wa_all TRANSPORTING netwr.
    ENDIF.
  ENDLOOP.
  CLEAR wa_all.

ENDFORM.                    "select_from_vbrk_vbrp_vbak
*&---------------------------------------------------------------------*
*&      Form  select_from_konv
*&---------------------------------------------------------------------*
*       select data from table konv into it_konv
*----------------------------------------------------------------------*
FORM select_from_konv.

  IF it_all[] IS NOT INITIAL.

    SELECT kwert
           kbetr
           knumv
           kposn
           kschl
      FROM konv
      INTO CORRESPONDING FIELDS OF TABLE it_konv
      FOR ALL ENTRIES IN it_all
      WHERE knumv = it_all-knumv
      AND   kposn = it_all-b_posnr
      AND   kschl IN ('PR00','RA00','RA01').
  ENDIF.
  SORT it_konv BY knumv kposn.

  IF sy-subrc <> 0.
    MESSAGE i001(zjenni_msg).
  ENDIF.

ENDFORM.                    "select_from_konv
*&---------------------------------------------------------------------*
*&      Form  select_from_kna1
*&---------------------------------------------------------------------*
*       select data from table kna1 into it_all
*----------------------------------------------------------------------*
FORM select_from_kna1.
  IF it_all[] IS NOT INITIAL.

    SELECT name1
           kunnr
      FROM kna1
      INTO CORRESPONDING FIELDS OF TABLE it_kna1
      FOR ALL ENTRIES IN it_all
      WHERE kunnr = it_all-kunag.
  ENDIF.
  SORT it_kna1 BY kunnr.

  IF sy-subrc <> 0.
    MESSAGE i001(zjenni_msg).
  ENDIF.

  LOOP AT it_all INTO wa_all.
    READ TABLE it_kna1 INTO wa_kna1
    WITH KEY kunnr = wa_all-kunag BINARY SEARCH.
    wa_all-name1 = wa_kna1-name1.
    MODIFY it_all  FROM wa_all TRANSPORTING name1.
  ENDLOOP.
  CLEAR wa_all.

ENDFORM.                    "select_from_kna1
*&---------------------------------------------------------------------*
*&      Form  select_from_vbap
*&---------------------------------------------------------------------*
*       1~select data from table vbap
*       2~get sales order total quantity
*----------------------------------------------------------------------*
FORM select_from_vbap.
  DATA: it_temp TYPE t_vbap,
        wa_temp TYPE LINE OF t_vbap.

  IF it_all[] IS NOT INITIAL.
    SELECT kwmeng
           abgru
           posnr
           vbeln AS s_vbeln
      FROM vbap
      INTO CORRESPONDING FIELDS OF TABLE it_vbap
      FOR ALL ENTRIES IN it_all
      WHERE vbeln = it_all-aubel
      AND   posnr = it_all-b_posnr
      AND   abgru = ''.
  ENDIF.
  SORT it_vbap BY kwmeng.

  IF sy-subrc <> 0.
    MESSAGE i001(zjenni_msg).
  ENDIF.

  LOOP AT it_vbap INTO wa_vbap.
    COLLECT wa_vbap INTO it_temp.
  ENDLOOP.
  CLEAR wa_vbap.

  LOOP AT it_all INTO wa_all.
    READ TABLE it_temp INTO wa_temp
    WITH KEY s_vbeln = wa_all-aubel BINARY SEARCH.
    wa_all-s_kwmeng = wa_temp-kwmeng.
    MODIFY it_all  FROM wa_all TRANSPORTING s_kwmeng.
  ENDLOOP.
  CLEAR wa_all.

ENDFORM.                    "select_from_vbap
*&---------------------------------------------------------------------*
*&      Form  get_gross_dis_amt
*&---------------------------------------------------------------------*
*       get particular gross value, discount,discount amount
*----------------------------------------------------------------------*
FORM get_gross_dis_amt.
  DATA: it_temp TYPE t_konv,
        wa_temp TYPE LINE OF t_konv.

  LOOP AT it_all INTO wa_all.
    READ TABLE it_konv INTO wa_konv
    WITH KEY knumv = wa_all-knumv
             kposn = wa_all-b_posnr
             BINARY SEARCH.

    IF wa_konv-kschl = 'PR00'.
      wa_all-kwert = wa_konv-kwert.
      MODIFY it_all FROM wa_all TRANSPORTING kwert.
    ENDIF.

    IF wa_konv-kschl = 'RA01'.
      wa_all-ra01_discount = wa_konv-kbetr / 10.
      wa_all-ra01_dis_amt = wa_konv-kwert.
      MODIFY it_all FROM wa_all TRANSPORTING ra01_discount.
      MODIFY it_all FROM wa_all TRANSPORTING ra01_dis_amt.
    ENDIF.

    IF wa_konv-kschl = 'RA00'.
      wa_all-ra01_discount = wa_konv-kbetr / 10.
      wa_all-ra01_dis_amt = wa_konv-kwert.
      MODIFY it_all FROM wa_all TRANSPORTING ra00_discount.
      MODIFY it_all FROM wa_all TRANSPORTING ra00_dis_amt.
    ENDIF.
    CLEAR wa_konv.

  ENDLOOP.
  CLEAR wa_all.

ENDFORM.                    "get_gross_dis_amt
*&---------------------------------------------------------------------*
*&      Form  get_total_gross
*&---------------------------------------------------------------------*
*       1~get total gross value
*       2~when billing type is 's1',add negative to gross value and total gross
*----------------------------------------------------------------------*
FORM get_total_gross.
  DATA: it_temp TYPE t_konv,
        wa_temp TYPE LINE OF t_konv,
        it_konv_temp TYPE t_konv,
        wa_konv_temp TYPE LINE OF t_konv.

  IF it_all[] IS NOT INITIAL.
    SELECT kwert
           knumv
           kschl
      FROM konv
      INTO CORRESPONDING FIELDS OF TABLE it_konv_temp
      FOR ALL ENTRIES IN it_all
      WHERE knumv = it_all-knumv
      AND   kschl = 'PR00'.
  ENDIF.

  LOOP AT it_konv_temp INTO wa_konv_temp.
    COLLECT wa_konv_temp INTO it_temp.
  ENDLOOP.
  CLEAR wa_konv_temp.

  LOOP AT it_temp INTO wa_temp.
*    write: at / wa_temp-kwert,
*                '@'.
  ENDLOOP.

  LOOP AT it_all INTO wa_all.
    READ TABLE it_temp INTO wa_temp
    WITH KEY knumv = wa_all-knumv
    BINARY SEARCH.
    wa_all-s_kwert = wa_temp-kwert.
    MODIFY it_all  FROM wa_all TRANSPORTING s_kwert.
  ENDLOOP.
  CLEAR wa_all.

  LOOP AT it_all INTO wa_all.
    IF wa_all-fkart = 'S1'.
      wa_all-kwert = -1 * wa_all-kwert.
      wa_all-s_kwert = -1 * wa_all-s_kwert.
      MODIFY it_all FROM wa_all TRANSPORTING kwert s_kwert.
    ENDIF.
  ENDLOOP.
  CLEAR wa_all.

ENDFORM.                    "get_total_gross
*&---------------------------------------------------------------------*
*&      Form  get_total
*&---------------------------------------------------------------------*
*       get all the total value into it_total_out
*----------------------------------------------------------------------*
FORM get_total.
  DATA: it_total_temp TYPE t_all,
        wa_total_temp TYPE LINE OF t_all.

  LOOP AT it_all INTO wa_all.
    wa_total_temp-b_vbeln = wa_all-b_vbeln.
    wa_total_temp-fkart = wa_all-fkart.
    wa_total_temp-vkorg = wa_all-vkorg.
    wa_total_temp-kunag = wa_all-kunag.
    wa_total_temp-name1 = wa_all-name1.
    wa_total_temp-fkdat = wa_all-fkdat.
    wa_total_temp-fkimg = wa_all-fkimg.
    wa_total_temp-ra01_discount = wa_all-ra01_discount.
    wa_total_temp-ra00_discount = wa_all-ra00_discount.
    wa_total_temp-netwr = wa_all-netwr.
    wa_total_temp-vrkme = wa_all-vrkme.
    wa_total_temp-waerk = wa_all-waerk.
    APPEND wa_total_temp TO it_total.
  ENDLOOP.
  CLEAR wa_all.

  LOOP AT it_total INTO wa_total.
    COLLECT wa_total INTO it_total_out.
  ENDLOOP.
  CLEAR wa_total.

  LOOP AT it_total_out INTO wa_total_out.
    READ TABLE it_all INTO wa_all
    WITH KEY b_vbeln = wa_total_out-b_vbeln BINARY SEARCH.
    wa_total_out-kurrf = wa_all-kurrf.
    wa_total_out-kwert = wa_all-s_kwert.
    MODIFY it_total_out FROM wa_total_out TRANSPORTING kurrf kwert netwr.
  ENDLOOP.
  CLEAR wa_total_out.

ENDFORM.                    "get_total
*&---------------------------------------------------------------------*
*&      Form  build_fieldcatalog
*&---------------------------------------------------------------------*
*       form fieldcatalog for both items and totals
*----------------------------------------------------------------------*
FORM build_fieldcatalog.

  DATA count TYPE i VALUE 1.

  fieldcatalog-fieldname   = 'B_VBELN'.
  fieldcatalog-seltext_l   = text-001.                    " 'Billing Document'.
  fieldcatalog-col_pos     = count.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
  count = count + 1.

  fieldcatalog-fieldname   = 'FKART'.
  fieldcatalog-seltext_l   = text-003.                    " 'Billing Type'.
  fieldcatalog-col_pos     = count.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
  count = count + 1.

  fieldcatalog-fieldname   = 'VKORG'.
  fieldcatalog-seltext_l   = text-002.                    " 'Sales Org'.
  fieldcatalog-col_pos     = count.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
  count = count + 1.

  fieldcatalog-fieldname   = 'KUNAG'.
  fieldcatalog-seltext_l   = text-005.                    " 'Sold-to Party'.
  fieldcatalog-col_pos     = count.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
  count = count + 1.

  fieldcatalog-fieldname   = 'NAME1'.
  fieldcatalog-seltext_l   = text-011.                    " 'Name'.
  fieldcatalog-col_pos     = count.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
  count = count + 1.

  fieldcatalog-fieldname   = 'FKDAT'.
  fieldcatalog-seltext_l   = text-004.                    " 'Billing date'.
  fieldcatalog-col_pos     = count.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
  count = count + 1.

  fieldcatalog-fieldname   = 'SPART'.
  fieldcatalog-seltext_l   = text-006.                    " 'Division'.
  fieldcatalog-col_pos     = count.
  IF x_check <> 'X'.
    fieldcatalog-no_out      =  'X'.
    count = count + 1.
  ENDIF.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'MATNR'.
  fieldcatalog-seltext_l   = text-008.                    " 'Material No'.
  fieldcatalog-col_pos     = count.
  IF x_check <> 'X'.
    fieldcatalog-no_out      =  'X'.
    count = count + 1.
  ENDIF.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'ARKTX'.
  fieldcatalog-seltext_l   = text-012.                    " 'Material Description'.
  fieldcatalog-col_pos     = count.
  IF x_check <> 'X'.
    fieldcatalog-no_out      =  'X'.
    count = count + 1.
  ENDIF.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'FKIMG'.
  fieldcatalog-seltext_l   = text-013.                    " 'Billing Qty'.
  fieldcatalog-col_pos     = count.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
  count = count + 1.

  fieldcatalog-fieldname   = 'VRKME'.
  fieldcatalog-seltext_l   = text-014.                    " 'Sales Unit'.
  fieldcatalog-col_pos     = count.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
  count = count + 1.

  fieldcatalog-fieldname   = 'KURRF'.
  fieldcatalog-seltext_l   = text-015.                    " 'Exchange rate-accntg'.
  fieldcatalog-col_pos     = count.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
  count = count + 1.

  fieldcatalog-fieldname   = 'KWERT'.
  fieldcatalog-seltext_l   = text-016.                    " 'Gross Value'.
  fieldcatalog-col_pos     = count.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
  count = count + 1.

  fieldcatalog-fieldname   = 'WAERK'.
  fieldcatalog-seltext_l   = text-017.                    " 'Currency'.
  fieldcatalog-col_pos     = count.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
  count = count + 1.

  fieldcatalog-fieldname   = 'RA01_DISCOUNT'.
  fieldcatalog-seltext_l   = text-018.                    " 'RA01%Discount'.
  fieldcatalog-col_pos     = count.
  IF x_check <> 'X'.
    fieldcatalog-no_out      =  'X'.
    count = count + 1.
  ENDIF.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = ''.
  fieldcatalog-seltext_l   = ''.
  fieldcatalog-edit_mask   = '%'.
  fieldcatalog-col_pos     = count.
  IF x_check <> 'X'.
    fieldcatalog-no_out      =  'X'.
    count = count + 1.
  ENDIF.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'RA01_DIS_AMT'.
  fieldcatalog-seltext_l   = text-019.                    " 'RA01 Discount Amount'.
  fieldcatalog-col_pos     = count.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
  count = count + 1.

  fieldcatalog-fieldname   = 'WAERK'.
  fieldcatalog-seltext_l   = text-017.
  fieldcatalog-col_pos     = count.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
  count = count + 1.

  fieldcatalog-fieldname   =  'RA00_DISCOUNT'.
  fieldcatalog-seltext_l   =  text-020.                    " 'RA00%Discount'.
  fieldcatalog-col_pos     = count.
  IF x_check <> 'X'.
    fieldcatalog-no_out      =  'X'.
    count = count + 1.
  ENDIF.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = ''.
  fieldcatalog-seltext_l   = ''.
  fieldcatalog-edit_mask   = '%'.
  fieldcatalog-col_pos     = count.
  IF x_check <> 'X'.
    fieldcatalog-no_out      =  'X'.
    count = count + 1.
  ENDIF.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'RA00_DIS_AMT'.
  fieldcatalog-seltext_l   = text-021.                    " 'RA00 Discount Amount'.
  fieldcatalog-col_pos     = count.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
  count = count + 1.

  fieldcatalog-fieldname   =  'WAERK'.
  fieldcatalog-seltext_l   =  text-017.
  fieldcatalog-col_pos     = count.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
  count = count + 1.

  fieldcatalog-fieldname   = 'NETWR'.
  fieldcatalog-seltext_l   = text-022.                    " 'Net Value'.
  fieldcatalog-col_pos     = count.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
  count = count + 1.

  fieldcatalog-fieldname   =  'WAERK'.
  fieldcatalog-seltext_l   =  text-017.
  fieldcatalog-col_pos     = count.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
  count = count + 1.

  fieldcatalog-fieldname   = 'GSBER'.
  fieldcatalog-seltext_l   = text-007.                    " 'Business Area'.
  fieldcatalog-col_pos     = count.
  IF x_check <> 'X'.
    fieldcatalog-no_out      =  'X'.
    count = count + 1.
  ENDIF.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'BSTNK'.
  fieldcatalog-seltext_l   = text-009.                    " 'PO Number'.
  fieldcatalog-col_pos     = count.
  IF x_check <> 'X'.
    fieldcatalog-no_out      =  'X'.
    count = count + 1.
  ENDIF.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'AUBEL'.
  fieldcatalog-seltext_l   = text-010.                    " 'Sales Document'.
  fieldcatalog-col_pos     = count.
  IF x_check <> 'X'.
    fieldcatalog-no_out      =  'X'.
    count = count + 1.
  ENDIF.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   =  'S_KWMENG'.
  fieldcatalog-seltext_l   =  text-023.                   " 'Sales Order Total Quantity'.
  fieldcatalog-col_pos     = count.
  IF x_check <> 'X'.
    fieldcatalog-no_out      =  'X'.
    count = count + 1.
  ENDIF.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'S_KWERT'.
  fieldcatalog-seltext_l   = text-024.                     " 'Sales Order Total Gross Value'.
  fieldcatalog-col_pos     = count.
  IF x_check <> 'X'.
    fieldcatalog-no_out      =  'X'.
    count = count + 1.
  ENDIF.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   =  'WAERK'.
  fieldcatalog-seltext_l   =  text-017.
  fieldcatalog-col_pos     = count.
  IF x_check <> 'X'.
    fieldcatalog-no_out      =  'X'.
    count = count + 1.
  ENDIF.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

ENDFORM.                    " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*&      Form  display_alv_report
*&---------------------------------------------------------------------*
*       form alv display
*----------------------------------------------------------------------*
*      -->FT_OUTPUT  text
*----------------------------------------------------------------------*
FORM display_alv_report USING ft_output TYPE STANDARD TABLE.
  gd_repid = sy-repid.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = gd_repid
      it_fieldcat        = fieldcatalog[]
      i_save             = 'X'
    TABLES
      t_outtab           = ft_output
    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
 

 Function group IPW1 has function modules, which SAP uses internally to update/Upload serial numbers

 

Example:

 

Function SERNR_ADD_TO_AU is used for adding serial numbers to SO/Contract.

 Function SERNR_ADD_TO_PO is used for adding serial numbers to PO

 

Use functions from function group IPW1 in following sequence for uploading serial numbers

 

1. Read serial number profile for a fiven line item from SO/Contract
CALL FUNCTION 'SERIAL_PROFILE_READ'
EXPORTING
profile_r = lwavbap-serail
operation_r = 'SDAU'
EXCEPTIONS
no_t377p_entry = 1
no_t377_entry = 2
OTHERS = 3.

 

2. Make sure serial number not locked when uploading it
CALL FUNCTION 'DEQUEUE_EIEQSE'
EXPORTING
mode_risenq = 'E'
mandt = sy-mandt
sernr = lwafinal_tab-sernr. “ Serial number to be uploaded

 


3. Upload Serial number in SO/Contract etc. using standard function
*Upating the Serial Number
CALL FUNCTION 'SERNR_ADD_TO_AU'
EXPORTING
sernr = lwafinal_tab-sernr
profile = lwavbap-serail
material = lwavbap-matnr
quantity = lv_quant
cuobj = lwavbap-cuobj
document = lwavbap-vbeln
item = lwavbap-posnr
debitor = lwavbak-kunnr
vbtyp = lwavbak-vbtyp
sd_auart = lwavbak-auart
sd_postyp = lwavbap-pstyv
i_no_enqueue = c_x
i_more_allowed = c_x
i_bapi = c_x
IMPORTING
anzsn = lv_anzsn
zeilen_id = lv_zeilen_id
serial_commit = lv_commit
EXCEPTIONS
konfigurations_error = 1
serialnumber_errors = 2
serialnumber_warnings = 3
no_profile_operation = 4
error_message = 5
OTHERS = 6.

 

4.Call function to refresh serial numbers internally in ABAP memory . The below function should be used immediately after 'SERNR_ADD_TO_AU' in case of errors . In case of successful postings function 'SERIAL_INTTAB_REFRESH' should ne used immediately after 'BAPI_TRANSACTION_COMMIT'

CALL FUNCTION 'SERIAL_INTTAB_REFRESH'.

 

5.Use following functions to Post Serial number on to a document Item incase call to function 'SERNR_ADD_TO_AU' is successful

CALL FUNCTION 'SERIAL_LISTE_POST_AU'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.

 

 

 

 

Scenario:

Many times there is a business requirement of linking documents, entering notes, sending notes or linking an internet address to various SAP objects. These external  attachments can be reference documents, pictures, Email attachments, design , diagrams or related spreadsheets. To meet this requirement SAP has provided a tool bar called 'Generic Service Toolbar'(GOS).

Recently, I came across a requirement where i had to create a attachment for existing sales order (va02) through report. in this requirement i have created a Custom report.

By using this report, You can attach a wide range of documents like Word Document, Excel Sheets, PDF and Text files and many more, including pictures.

Go to transaction SE38 and create report .

Here is the Source Code.

*Declarations

*Structure Declarations

TYPES : BEGIN OF ty_table,    "Structure for FileName

         fname(128) TYPE c,

  END OF ty_table.

*Data Declarations

DATA: w_prog                TYPE sy-repid,         "Current Program Name

             w_dynnr              TYPE sy-dynnr,        "Current Dynpro Number

             w_attachement   TYPE borident,         "Work Area for BOR object identifier

             ws_borident        TYPE borident,         "Work Area for BOR object identifier

             w_document       TYPE sood4,            "Interface for send screen and MOM

             folder_id             TYPE soodk,             "Definition of Object Key

             w_h_data           TYPE sood2,             "Object Definition Workarea

             w_fol_data         TYPE sofm2,             "Folder Contents Work area

             w_rec_data        TYPE soos6,             "Transfer Information of folder Work area

             ws_files              TYPE ty_table,

             wt_files               TYPE TABLE OF ty_table.

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

*Parameter Declarations

PARAMETER: p_mandt TYPE sy-mandt,                                                      " Client Number

            p_vbeln TYPE vbeln,                                                                            " Sales Order Number

            p_path  TYPE ibipparms-path  MEMORY ID ad_local_path,               " File Path

            p_name(30).                                                                                          " Name of attachement.

SELECTION-SCREEN END OF BLOCK b1.

*Initialization Event

INITIALIZATION .

w_prog = sy-repid .

w_dynnr = sy-dynnr .

*/ Selection Screen  For File Path Selection

  AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path .

*/ F4 Help for file selection

  CALL FUNCTION 'F4_FILENAME'

  EXPORTING

    program_name        = w_prog

    dynpro_number       = w_dynnr

    field_name               = 'P_PATH'

IMPORTING

    file_name                 = p_path .

*Start of selection Evvent

START-OF-SELECTION .

*/Client Validations

IF sy-mandt NE p_mandt .

WRITE 'Mandt Error' .

EXIT .

ENDIF .

*/ Assign Object Keys to the Structure BOR

ws_borident-objkey      = p_vbeln.             "SalesOrder Number

ws_borident-objtype     = 'EQUI'.               "Object Type

ws_borident-objtype     = 'BUS2032'.        "BUS Number

 

*/ Filename Assign to the Structure

ws_files-fname = p_path .               "Path

APPEND ws_files TO wt_files . 

*/ Folder Root

CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'

EXPORTING

      region    = 'B'

IMPORTING

      folder_id = folder_id

EXCEPTIONS

     OTHERS    = 1.

*/ Append data to the MOM Structure

  w_document-foltp   = folder_id-objtp.

  w_document-folyr   = folder_id-objyr .

  w_document-folno   = folder_id-objno .

  w_document-objdes  = p_name .           "Name of file

  w_document-objnam  = p_name .          "Name of file

*/ Attachment FileName Assignment

  w_h_data-objdes = p_name .                 "Name of file

*/ Using this function module to read FILE from Presentation server

CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER'

EXPORTING

   method                  = 'IMPORTFROMPC'

   ref_document        = w_document

TABLES

    files                       = wt_files

CHANGING

    document              = w_document

    header_data          = w_h_data

    folmem_data         = w_fol_data

    receive_data         = w_rec_data .

*/ File Creation OkCodes

       IF w_document-okcode = 'CREA' OR w_document-okcode = 'CHNG'.

          w_attachement-objtype = 'MESSAGE'.

          w_attachement-objkey  = w_document(34).

 

          CALL FUNCTION 'BINARY_RELATION_CREATE_COMMIT'

             EXPORTING

                obj_rolea            = ws_borident

                obj_roleb            = w_attachement

                relationtype         = 'ATTA'

             EXCEPTIONS

                no_model             = 1

                internal_error       = 2

                unknown              = 3

                OTHERS             = 4.

*/Error Handling

           IF sy-subrc <> 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

           WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

           ENDIF.

           ENDIF .

Before Execution:

Go to the transaction VA03 (Sales Order Display ) in system as shown in the below screen shot.

There is no attachment existed for this sales order. Now go to report and execute it following selection screen will be display.

Give the inputs Client Number, Sales  order number , File path and file name as shown in below.

In this i have given a text document for attachment.

When click on execute button it will create a sales order attachment.

Now go to transaction VA03 and check whether the attachment is added or not.

Attachment is added.

Table Storage:

The Content of file converted to binary and it stores in tables like SOOD and SRGBTBREL.

 SOOD Table stores the information of attached Object info.

SRGBTBREL table stores the information of Relationships in GOS Environment.


I hope this WIKI would help many ABAP'ers in attaching files.

Thanks&Regards,

Harikrishna M.

This Code here is to show the the sales details for current 10 days......for a given customer and if the customer is not there for that current 10 days it gives the message. This Program is based on object oriented programming using classes where the event double-click is handled with appropriate validations.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
REPORT yh_sdreq.
*==========================================*
* Program Name: Display the Sales header and item Information of 10
*                           days from today
*----------------------------------------------------------------------*
* Author: Richa Tripathi *
*----------------------------------------------------------------------*
* Description: Display the Sales header information of 10 days from
*               today on the customer number entered by the user and
*               then if the user clicks on a sales order number the
*               item description of that order number is shown.
* *********************************************************
*DATA declaration
*Data declaration for Sales Table
DATA: BEGIN OF fs_sd1,
        autlf TYPE vbak-autlf,               " Complete delivery defined ?
        vbeln TYPE vbak-vbeln,               " Sales Document Number
        aufnr TYPE vbak-aufnr,               "Sales Order Number
        bstnk TYPE vbak-bstnk,               " Customer purchase order number
        vdatu TYPE vbak-vdatu,               " Requested delivery date
        lifsk TYPE vbak-lifsk,               " delivery block
        kunnr TYPE vbak-kunnr,               " Sold-to-party
      END OF fs_sd1.
*Field String Declarations for Sales item Table........................
DATA: BEGIN OF fs_sd2,
        posnr TYPE vbap-posnr,               " Sales item Number
        matnr TYPE vbap-matnr,               " Material Number
        zmeng TYPE vbap-zmeng,               " Quantity
        zieme TYPE vbap-zieme,               " Unit
        werks TYPE vbap-werks,               " Plant
        lgort TYPE vbap-lgort,               " Storage Location
      END OF fs_sd2.
*Internal Table Declaration Sales Header Table.......................
DATA: t_sd1 LIKE STANDARD TABLE OF fs_sd1.
*Internal Table Declaration Sales item Table.......................
DATA: t_sd2 LIKE STANDARD TABLE OF fs_sd2.
*Work Variable Declarations..............................
DATA: w_date TYPE vbak-vdatu, " Stores Date
      r_container TYPE REF TO cl_gui_custom_container,
      r_grid TYPE REF TO cl_gui_alv_grid,
      r_container1 TYPE REF TO cl_gui_custom_container,
      r_grid1 TYPE REF TO cl_gui_alv_grid.
*Data declarations for ALV Interactive list
DATA: t_cat TYPE lvc_t_fcat,
      w_cat TYPE lvc_s_fcat,
      w_lay TYPE lvc_s_layo,
      w_sort TYPE lvc_s_sort,
      t_sort TYPE lvc_t_sort.
* Parameters Declaration
************************************************************************
* SELECTION-SCREEN BEGIN OF BLOCK b1
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETER : p_kunnr TYPE kna1-kunnr.
SELECTION-SCREEN END OF BLOCK b1.
***********************************************************************
* AT SELECTION-SCREEN ON CUSTOMER NUMBER
***********************************************************************
AT SELECTION-SCREEN ON p_kunnr.
  PERFORM validations.
*----------------------------------------------------------------------*
* CLASS lcl_event DEFINITION
*----------------------------------------------------------------------*
*Defination of the Methods Used
*----------------------------------------------------------------------*
CLASS lcl_class DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS lcl_method
      FOR EVENT double_click
      OF cl_gui_alv_grid
      IMPORTING e_column
                es_row_no.
ENDCLASS.                             "lcl_class DEFINITION
*-----------------------------------------------------------------------------------------------*
* CLASS lcl_class IMPLEMENTATION
*------------------------------------------------------------------------------------------------*
* This Implementaion Is For The Double Click On Sales Order Number
*------------------------------------------------------------------------------------------------*
CLASS lcl_class IMPLEMENTATION.
  METHOD lcl_method .
    IF e_column EQ 'VBELN'.
      READ TABLE t_sd1 INTO fs_sd1 INDEX es_row_no-row_id.
      IF sy-subrc EQ 0.
        SELECT  posnr                " Sales item Number
                matnr                " Material Number
                zmeng                " Quantity
                zieme                " Unit
                werks                " Plant
                lgort                " Storage Location
          FROM vbap
          INTO TABLE t_sd2
          WHERE vbeln EQ fs_sd1-vbeln .
        IF sy-subrc NE 0.
          MESSAGE 'Order Number is initail'(008) TYPE 'S'.
        ENDIF.
* Call Screen For item table Display
        CALL SCREEN 101.
      ENDIF.                            " IF SY-SUBRC EQ 0
    ELSE.
      MESSAGE 'Click on Delivery Number Only'(002) TYPE 'S'.
    ENDIF. " IF E_COLUMN EQ 'VBELN'
  ENDMETHOD.                         " lcl_method
ENDCLASS.                            " lcl_class IMPLEMENTATION
************************************************************************
* START OF SELECTION
************************************************************************
START-OF-SELECTION.
* Call Screen For header table Display
  CALL SCREEN 100.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* Module to define the Status For the First header table display screen
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'STATUS'.
  SET TITLEBAR 'SALES HEADER'.
ENDMODULE.                           " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* Defining the User-actions on the List
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
  CASE sy-ucomm.
    WHEN 'BACK'.
      LEAVE TO SCREEN 0.
  ENDCASE.                           " CASE SY-UCOMM
ENDMODULE.                           " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Module OBJECTS OUTPUT
*&---------------------------------------------------------------------*
* This Module Fills the Field catalog and displays the ALV
*----------------------------------------------------------------------*
MODULE objects OUTPUT.
* Clearing the fields
  CLEAR t_cat.
  CLEAR w_cat.
  CLEAR w_sort.
  CLEAR t_sort.
  CLEAR w_lay.
*Filling the Field Catalog
  w_cat-fieldname = 'VBELN'.
  w_cat-coltext = 'SALES ORDER NUMBER'.
  w_cat-col_pos = 1.
  w_cat-emphasize = 'C700'.
  APPEND w_cat TO t_cat.
  CLEAR w_cat.
  w_cat-fieldname = 'AUFNR'.
  w_cat-coltext = 'SALES ORDER'.
  w_cat-col_pos = 2.
  w_cat-emphasize = 'C700'.
  APPEND w_cat TO t_cat.
  CLEAR w_cat.
  w_cat-fieldname = 'BSTNK'.
  w_cat-coltext = 'PURCHASE ORDER'.
  w_cat-col_pos = 3.
  w_cat-just = 'C'.
  APPEND w_cat TO t_cat.
  CLEAR w_cat.
  w_cat-fieldname = 'KUNNR'.
  w_cat-coltext = 'SOLD-TO-PARTY'.
  w_cat-col_pos = 4.
  APPEND w_cat TO t_cat.
  CLEAR w_cat.
  w_cat-fieldname = 'VDATU'.
  w_cat-coltext = 'DELIVERY DATE'.
  w_cat-col_pos = 5.
  APPEND w_cat TO t_cat.
  CLEAR w_cat.
  w_cat-fieldname = 'LIFSK'.
  w_cat-coltext = 'DELIVERY BLOCK'.
  w_cat-col_pos = 6.
  APPEND w_cat TO t_cat.
  CLEAR w_cat.
*Defining the Grid Title
  w_lay-grid_title = 'SALES INFORMATION'.
  w_lay-zebra = 'X'.
*Defining the Sort Order
  w_sort-spos = '1'.
  w_sort-fieldname = 'VDATU'.
  w_sort-up = 'X'.
  APPEND w_sort TO t_sort.
  CLEAR w_sort.
*Creating container object
  CREATE OBJECT r_container
    EXPORTING
      container_name              = 'CONTAINER1'
    EXCEPTIONS
      cntl_error                  = 1
      cntl_system_error           = 2
      create_error                = 3
      lifetime_error              = 4
      lifetime_dynpro_dynpro_link = 5
      OTHERS                      = 6.
  IF sy-subrc <> 0.
    MESSAGE 'Container for the ALV Not Defined'(006) TYPE 'E'.
  ENDIF.                             " IF SY-SUBRC NE 0
*Creating ALV grid for list...........................
  CREATE OBJECT r_grid
    EXPORTING
      i_parent          = r_container
    EXCEPTIONS
      error_cntl_create = 1
      error_cntl_init   = 2
      error_cntl_link   = 3
      error_dp_create   = 4
      OTHERS            = 5.
  IF sy-subrc <> 0.
    MESSAGE 'Grid for the ALV Not Defined'(005) TYPE 'E'.
  ENDIF.                             " IF SY-SUBRC NE 0
*ALV for display item field details
  CALL METHOD r_grid->set_table_for_first_display
    EXPORTING
      i_structure_name              = 'FS_SD1'
      is_layout                     = w_lay
    CHANGING
      it_outtab                     = t_sd1
      it_fieldcatalog               = t_cat
      it_sort                       = t_sort
    EXCEPTIONS
      invalid_parameter_combination = 1
      program_error                 = 2
      too_many_lines                = 3
      OTHERS                        = 4.
  IF sy-subrc <> 0.
    MESSAGE 'Parameters for the ALV Not Defined Properly'(004) TYPE 'E'.
  ENDIF. " IF SY-SUBRC NE 0
  CLEAR fs_sd1.
  SET HANDLER lcl_class=>lcl_method FOR r_grid.
ENDMODULE.                             " OBJECTS OUTPUT
*&---------------------------------------------------------------------*
*& Module STATUS_0101 OUTPUT
*&---------------------------------------------------------------------*
*This Module Sets the Status For The Header Data Display
*----------------------------------------------------------------------*
MODULE status_0101 OUTPUT.
  SET PF-STATUS 'STATUS'.
  SET TITLEBAR 'STATUS HEADER'.
ENDMODULE.                           " STATUS_0101 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0101 INPUT
*&---------------------------------------------------------------------*
* This Module Sets the User-Command On Screen
*----------------------------------------------------------------------*
MODULE user_command_0101 INPUT.
  CASE sy-ucomm.
    WHEN 'BACK'.
      LEAVE TO SCREEN 0.
  ENDCASE.                           " CASE SY-UCOMM
ENDMODULE .                          " USER_COMMAND_0101 INPUT
*&---------------------------------------------------------------------*
*& Module OBJECT2 OUTPUT
*&---------------------------------------------------------------------*
* This Module Fills the Field Catalog For Item Data
*----------------------------------------------------------------------*
MODULE object2 OUTPUT.
*Clearing the fields
  CLEAR t_cat.
  CLEAR w_cat.
  CLEAR w_sort.
  CLEAR t_sort.
  CLEAR w_lay.
*Filling the Field Catalog
  w_cat-fieldname = 'POSNR'.
  w_cat-coltext = 'SALES ITEM'.
  w_cat-col_pos = 1.
  w_cat-emphasize = 'C700'.
  APPEND w_cat TO t_cat.
  CLEAR w_cat.
  w_cat-fieldname = 'MATNR'.
  w_cat-coltext = 'MATERIAL NUMBER'.
  w_cat-col_pos = 2.
  w_cat-just = 'C'.
  APPEND w_cat TO t_cat.
  CLEAR w_cat.
  w_cat-fieldname = 'ZMENG'.
  w_cat-coltext = 'QUANTITY'.
  w_cat-col_pos = 3.
  APPEND w_cat TO t_cat.
  CLEAR w_cat.
  w_cat-fieldname = 'ZIEME'.
  w_cat-coltext = 'UNIT'.
  w_cat-col_pos = 4.
  APPEND w_cat TO t_cat.
  CLEAR w_cat.
  w_cat-fieldname = 'WERKS'.
  w_cat-coltext = 'PLANT'.
  w_cat-col_pos = 5.
  APPEND w_cat TO t_cat.
  CLEAR w_cat.
*Defining the Grid Title
  w_lay-grid_title = 'SALES ITEM INFORMATION'.
  w_lay-zebra = 'X'.
*Defining the Sort Order
  w_sort-spos = '1'.
  w_sort-fieldname = 'POSNR'.
  w_sort-up = 'X'.
  APPEND w_sort TO t_sort.
  CLEAR w_sort.
*Creating container object
  CREATE OBJECT r_container1
    EXPORTING
      container_name              = 'CONTAINER2'
    EXCEPTIONS
      cntl_error                  = 1
      cntl_system_error           = 2
      create_error                = 3
      lifetime_error              = 4
      lifetime_dynpro_dynpro_link = 5
      OTHERS                      = 6.
  IF sy-subrc <> 0.
    MESSAGE 'Container for the ALV Not Defined'(006) TYPE 'E'.
  ENDIF.                             " IF SY-SUBRC NE 0
*Creating ALV grid for list
  CREATE OBJECT r_grid1
    EXPORTING
      i_parent          = r_container1
    EXCEPTIONS
      error_cntl_create = 1
      error_cntl_init   = 2
      error_cntl_link   = 3
      error_dp_create   = 4
      OTHERS            = 5.
  IF sy-subrc <> 0.
    MESSAGE 'Grid for the ALV Not Defined'(005) TYPE 'E'.
  ENDIF.                             " IF SY-SUBRC NE 0
*ALV for display field details....................
  CALL METHOD r_grid1->set_table_for_first_display
    EXPORTING
      i_structure_name              = 'FS_SD2'
      is_layout                     = w_lay
    CHANGING
      it_outtab                     = t_sd2
      it_fieldcatalog               = t_cat
      it_sort                       = t_sort
    EXCEPTIONS
      invalid_parameter_combination = 1
      program_error                 = 2
      too_many_lines                = 3
      OTHERS                        = 4.
  IF sy-subrc <> 0.
    MESSAGE 'Parameters for the ALV Not Defined Properly'(004) TYPE 'E'.
  ENDIF.                               " IF SY-SUBRC NE 0
ENDMODULE.                             " OBJECT2 OUTPUT
*&---------------------------------------------------------------------*
*& Form VALIDATIONS
*&---------------------------------------------------------------------*
* This Subroutine Validates the Customer number
*----------------------------------------------------------------------*
* This Subroutine Has no Interface Parameters To be Passed
*----------------------------------------------------------------------*
FORM validations .
  DATA : w_kunnr TYPE kna1-kunnr.
*Get the date of 10 days after the sy-datum
  w_date = sy-datum.
  w_date = w_date + 10.

  SELECT SINGLE kunnr " Customer Number
    FROM kna1
    INTO w_kunnr
    WHERE kunnr EQ p_kunnr.
  IF sy-subrc NE 0.
    MESSAGE 'Customer Number Not Found'(003) TYPE 'E'.
  ENDIF.                             " IF SY-SUBRC NE 0

  SELECT  autlf                                       " Delivery Complete or not
          vbeln                                       " Sales Document Number
          aufnr                                       " Sales Order Number
          bstnk                                       " Customer purchase order number
          vdatu                                       " Requested delivery date
          lifsk                                       " delivery block
          kunnr                                       " Sold-to-party
    FROM vbak
    INTO TABLE t_sd1
    WHERE kunnr EQ p_kunnr
      AND vdatu BETWEEN sy-datum AND w_date
      AND autlf EQ ' '.
  IF sy-subrc NE 0.
    MESSAGE 'This Customer Number doesnot exist for coming ten days'(007)
    TYPE 'E'.
  ENDIF.                             " IF SY-SUBRC NE 0
ENDFORM.                             " VALIDATIONS
*&---------------------------------------------------------------------*
*& Module CLEAR_UCOMM OUTPUT
*&---------------------------------------------------------------------*
MODULE clear_ucomm OUTPUT.
  CLEAR sy-ucomm.
ENDMODULE.                           " CLEAR_UCOMM OUTPUT

Sometimes you need to fire up a call transaction in a new window...

STEP 1: Define a remote enabled function module

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
 function z_call_transaction_sess .
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(TCODE) TYPE  TCODE
*"     VALUE(SKIP) TYPE  FLAG OPTIONAL
*"  TABLES
*"      ITAB_DATA STRUCTURE ZSE_ITAB
*"  EXCEPTIONS
*"      NO_TRANSACTION
*"----------------------------------------------------------------------

  tables: tstc.

  data: itab_message type table of bdcmsgcoll.

  data: t_vkorg like vbak-vkorg,
        t_vbeln like vbak-vbeln,
        t_ebeln like ekko-ebeln,
        t_bukrs like ekko-bukrs,
        t_belnr like vbrk-vbeln,
        t_vtweg like vbak-vtweg,
        t_spart like vbak-spart,
        t_kunnr like kna1-kunnr,
        t_lifnr like lfa1-lifnr,
        t_kschl like rv13a-kschl,
        t_accnt like bkpf-belnr.

  select single tcode into tstc-tcode from tstc
    where tcode = tcode.
  if sy-subrc <> 0.
    raise no_transaction.
  endif.

  loop at itab_data.
    case itab_data-field.
      when 'EBELN'.
        t_ebeln = itab_data-value.
        set parameter id 'BES' field t_ebeln.
      when 'BELNR'.
        t_belnr = itab_data-value.
        set parameter id 'VF' field t_belnr.
      when 'VBELN'.
        t_vbeln = itab_data-value.
        set parameter id 'AUN' field t_vbeln.
      when 'VKORG'.
        t_vkorg = itab_data-value.
        set parameter id 'VKO' field t_vkorg.
      when 'VTWEG'.
        t_vtweg = itab_data-value.
        set parameter id 'VTW' field t_vtweg.
      when 'SPART'.
        t_spart = itab_data-value.
        set parameter id 'SPA' field t_spart.
      when 'KUNNR'.
        t_kunnr = itab_data-value.
        set parameter id 'KUN' field t_kunnr.
      when 'KSCHL'.
        t_kschl = itab_data-value.
        set parameter id 'VKS' field t_kschl.
      when 'BUKRS'.
        t_bukrs = itab_data-value.
        set parameter id 'BUK' field t_bukrs.
      when 'ACCNT'.
        t_accnt = itab_data-value.
        set parameter id 'BLN' field t_accnt.
      when 'LIFNR'.
        t_lifnr = itab_data-value.
        set parameter id 'LIF' field t_lifnr.
    endcase.
  endloop.

  case skip.
    when 'X'.
      call transaction tcode and skip first screen.
    when others.
      call transaction tcode.
  endcase.

  case tcode.
    when 'VA01'.
      get parameter id 'AUN' field t_vbeln.
      loop at itab_data where field = 'VBELN'.
        if not t_vbeln is initial.
          itab_data-value = t_vbeln.
        else.
          clear itab_data-value.
        endif.
        modify itab_data.
      endloop.
  endcase.

endfunction.

STEP 2: Calling the function module

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
      t_itab_fields-field = 'VBELN'.
      t_itab_fields-value = t_vbeln.
      Append t_itab_fields.

      call function 'Z_CALL_TRANSACTION_SESS'
        starting new task 'TA'
           exporting
                tcode          = 'VA02'
                skip           = 'X'
           tables
                itab_data      = t_itab_fields
           exceptions
                no_transaction = 1
                others         = 2.

Author: Lakshmi Sailaja Nalam
Submitted: 13 June 2007
Company: Intelligroup Asia Pvt. Ltd

Applies to : ECC 5.0

Summary :
This Tech article talks about copying requirements of sales orders. It explains how to create and deploy customized routines that meet business requirements.

Introduction:

          R/3 systemprovides flexibility to support different logistic processes like price determination, invoices, purchase orders, contracts etc. VOFM transaction is used to maintain standard routines and create and deploy customized routines that meet the business requirements. Each routine is assigned a number and is maintained in an ABAP include. These include files are included in a parent include. The parent include is included in the main program. Activation and deactivation of routine modifies the parent include by adding or removing the include containing the routine.

VOFM routines are divided into four categories.

i)                    Copying requirements

ii)                  Data Transfer

iii)                 Requirements

iv)                 Formulae

Copying Requirements are the form routines that are used to check few conditions before copying process. There are various scenarios where we make use of these copying requirements. Checks can be done before we create sales orders by giving contracts as reference, sales orders by giving reference of sales orders and so on.

Scenario:                
                Let us consider, a new contract has to be created with order type ZZSC by giving reference of ZSC order type contract. VBAK-FAKSK is the field that holds the information about blocking of contract.

Instead of creating a completely new code to the routine, few lines of code can be added to the existing routine. In order to determine which routines get executed in the standard process, go to VTAA - Order to order copying control transaction.

Search for the combination of contract order types, ZSC as source and ZZSC as target. Select the entry and selectHeader node on the left panel and click on Details button.
 
Upon clicking the details button, a screen is displayed which gives the routines that are executed while creating ZZSC order type contract from ZSC order type.
 
The existing routines for copying requirements are listed in VOFM transaction.
 
Copying requirements -> Orders moves to the screen. Routines 600-999 can be created. This range is determined by the group indicator.
An additional check about the contracts has to be done to the existing routine. Get the code from the routine 002.
 
Create a new routine 601 and give description to it. Select the routine and click on Source text button on application tool bar.
 
Access key is required to create it. It can be obtained from www.service.sap.com by passing the required parameters.
 
After giving the access key, it asks for a request. Then, click on Source text button.
From the menu Edit -> Modification Operations -> Switch off assistant , it switches off the assistant to make further changes in the include *RV45B601.*
 
Copy the code of existing routine 002 to 601.
Documentation to the structures used in the routine is mentioned in the top of the subroutine.
 
Insert the following piece of code in the subroutine.
 
Activate the program and go back.
Now, the routine has to be activated. Once, activated, the checkbox Active gets checked.
 
Activation can be verified in the program RV45BNNN. A new include statement of the routine RV45B601 gets added.
 
Note : If the new routine is not activated properly, execute program RV80HGEN to regenerate all the VOFM routines. The output of this program denotes that all routines were activated.
Go to VTAA transaction in change mode and change the copying requirements routine 002 to 601 (Routine 601 gets displayed in the F4 help only if it is activated) and Save.
 
Test Case:
Create a contract in VA41transaction by giving reference of a blocked contract.
Ex : 0040000100 is a blocked contract (FAKSK is not initial).

 
An error message is thrown which says that contract is blocked.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
REPORT  ztl_sdc001p_customermaster NO STANDARD PAGE HEADING LINE-SIZE 500
        MESSAGE-ID zrtl.

*------------------------------------------------------------------------
*     Include Programs
*------------------------------------------------------------------------

*Data Declarations and Selection screen Details
INCLUDE ztl_sdc001p_customermaster_top.

*Include for Selection Screen
INCLUDE ztl_sdc001p_customermaster_sel.

*Program logic and Subroutines
INCLUDE ztl_sdc001p_customermaster_sub.

INITIALIZATION.

AT SELECTION-SCREEN OUTPUT.
  IF rd_csv = 'X'.
    v_ffilter =  '.|*.CSV'.

  ELSEIF rd_xls = 'X'.
    v_ffilter =  '.|*.XLS'.
  ENDIF.

  CLEAR  p_fname.
  IF p_fname IS NOT INITIAL.
    MESSAGE i036.
  ENDIF.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.
* get f4 help for filename
* Get the input file
  PERFORM get_input_file.

*------------------------------------------------------------------------
* Start-of-selection
*------------------------------------------------------------------------

START-OF-SELECTION.

* check for existence in Presentation Server
  PERFORM check_fname USING p_fname.

  IF p_creat = c_yes.
    v_flag1 = 1.
* check for the tcode xd01
    v_tcode = c_xd01.
* upload data from presentation server into internal table
    PERFORM create_upload_presentation USING p_fname.
* BDC Operations
    PERFORM create_bdcoperations.
    CLEAR v_flag1.

  ELSEIF p_exten = c_yes.
* check for the tcode xd01
    v_tcode = c_xd01.
* upload data from presentation server into internal table
    PERFORM extend_upload_presentation USING p_fname.
* BDC Operations
    PERFORM extend_bdcoperations.

  ELSEIF p_chang = c_yes.
* check for the tcode xd02
    v_tcode = c_xd02.
* upload data from presentation server into internal table
    PERFORM create_upload_presentation USING p_fname.
* Data Selection.
    PERFORM get_data.
* BDC Operations
    PERFORM change_bdcoperations.

  ENDIF.

END-OF-SELECTION.

* Display the Report.
  PERFORM print_custom.

* Clear the Data after use
  PERFORM free_data.

*Text elements
*----------------------------------------------------------
* 008 No error records
* 009 Cust No
* 010 No success records
* 015 Customer Master Conversion
* 017 Customer Successful Records Table
* 018 Error Records Table
* H03 File Type

*Selection texts
*----------------------------------------------------------
* P_CHANG         Change Customer
* P_CREAT         Create Customer
* P_EXTEN         Extend Customer
* P_FNAME D       .
* RD_CSV         CSV File
* RD_XLS         Excel File

*Messages
*----------------------------------------------------------
*
* Message class: ZDEV
*002   Error in Application
*004   File does not exist
*012   Error in uploading data from excel file
*036   Select File to Load
*--------------------------------------------------------------------*

Author: Asis Mohanty
Submitted: 22/01/2008

Description
Open Sales Order

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
REPORT zdr162
       NO STANDARD PAGE HEADING LINE-SIZE 255.
*************************Internal Table*****************************
DATA: BEGIN OF i_tab OCCURS 0,
        auart(4) TYPE c,   "Sales document type
        vkorg(4)  TYPE c,   "Sales Organization
        vtweg(2) TYPE c,    "Distribution Channel
        spart(2) TYPE c,   "Division
        kunnr(10) TYPE c,  "Customer
        bstkd(35) TYPE c,  "PO number
        bstdk(10) TYPE c,  "PO Date
        matnr(18) TYPE c,  "Material
        kwmeng(18) TYPE c, "Order quantity
        text(100) TYPE c,  "LONG TEXT
        END OF i_tab.
DATA: BEGIN OF i_tab_dtl OCCURS 0,
        bstkd(35) TYPE c,  "PO number
        auart(4) TYPE c,
        matnr(18) TYPE c,  "Material
        kwmeng(18) TYPE c, "Order quantity
        END OF i_tab_dtl.
DATA: BEGIN OF i_tab_hdr OCCURS 0,
        bstkd(35) TYPE c,  "PO number
        auart(4) TYPE c,   "Sales document type
        bstdk(10) TYPE c,  "PO Date
        vkorg(4)  TYPE c,   "Sales Organization
        vtweg(2) TYPE c,    "Distribution Channel
        spart(2) TYPE c,   "Division
        kunnr(10) TYPE c,  "Customer
        matnr(18) TYPE c,  "Material
        kwmeng(18) TYPE c, "Order quantity
        text(100) TYPE c,  "LONG TEXT
      END OF i_tab_hdr.
DATA: BEGIN OF i_header.
        INCLUDE STRUCTURE thead.
DATA: END OF i_header.
DATA: BEGIN OF i_lines OCCURS 0.
        INCLUDE STRUCTURE tline.
DATA: END OF i_lines.
*       Batchinputdata of single transaction
DATA:   bdcdata LIKE bdcdata    OCCURS 0 WITH HEADER LINE.
*       messages of call transaction
DATA:   messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
*       error session opened (' ' or 'X')
DATA:   e_group_opened.
*       message texts
TABLES: t100.
DATA: BEGIN OF i_messages OCCURS 0,
       bstkd LIKE vbkd-bstkd,
       auart LIKE vbak-auart,
*       MATNR LIKE VBAP-MATNR,
       longtext(225).
        INCLUDE STRUCTURE bdcmsgcoll.
DATA: END OF i_messages.
DATA: nodata(1)  VALUE '/' .          "nodata
**************************Session Creation***************************
*INCLUDE bdcrecx1.
*************************Selection Screen****************************
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS p_mode LIKE ctu_params-dismode DEFAULT 'N'.
*A: show all dynpros
*E: show dynpro on error only
*N: do not display dynpro
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-t01.
PARAMETERS: pfile LIKE rlgrap-filename DEFAULT space.
SELECTION-SCREEN END OF BLOCK b2.
**********************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR pfile.
  CALL FUNCTION 'WS_FILENAME_GET'
    EXPORTING
      def_filename     = space
      def_path         = pfile
      mask             = ',*.*,*.*.'
      mode             = 'E'
      title            = 'Choose File Name'
    IMPORTING
      filename         = pfile
    EXCEPTIONS
      inv_winsys       = 04
      no_batch         = 08
      selection_cancel = 12
      selection_error  = 16.
  IF sy-subrc EQ '04'.
    MESSAGE e999(zpa) WITH 'FILE NOT FOUND'(e01).
  ENDIF.
**************************Main Logic*******************************
START-OF-SELECTION.
  PERFORM f_upload_file.
  PERFORM f_delete_blank.
  PERFORM f_create_header.
  PERFORM f_create_detail.
  PERFORM f_create_output_heading.
  PERFORM f_call_va01.
  PERFORM f_save_messages.
  PERFORM f_write_mesg.
*&---------------------------------------------------------------------*
*&      Form  f_upload_file
*&---------------------------------------------------------------------*
*       Upload File
*----------------------------------------------------------------------*
FORM f_upload_file .
  CALL FUNCTION 'WS_UPLOAD'
    EXPORTING
      filename = pfile
      filetype = 'DAT'
    TABLES
      data_tab = i_tab.
ENDFORM.                    " f_upload_file
*&---------------------------------------------------------------------*
*&      Form  f_call_va01
*&---------------------------------------------------------------------*
*       Call VA01
*----------------------------------------------------------------------*
FORM f_call_va01 .
  DATA: v_bdcfd1(100), v_bdcfd2(100).
  DATA: cnt(2) TYPE n.
  LOOP AT i_tab_hdr.
    PERFORM header.
    cnt = 1.
    LOOP AT i_tab_dtl WHERE bstkd  = i_tab_hdr-bstkd
                        AND   auart = i_tab_hdr-auart.
      PERFORM bdc_dynpro      USING 'SAPMV45A' '4001'.
*        PERFORM bdc_field       USING 'BDC_CURSOR'
*                                'VBAP-POSNR(01)'.
*
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=POAN'.
      CONCATENATE 'RV45A-KWMENG(' cnt ')' INTO v_bdcfd1.
      PERFORM bdc_field       USING 'BDC_CURSOR'
                                      v_bdcfd1.
      CONCATENATE 'RV45A-MABNR(' cnt ')' INTO v_bdcfd2.
      PERFORM bdc_field       USING v_bdcfd2
                                     i_tab_dtl-matnr.
      PERFORM bdc_field       USING v_bdcfd1
                                     i_tab_dtl-kwmeng.
      cnt = 2.
    ENDLOOP.
**Save Code
    PERFORM bdc_dynpro      USING 'SAPMV45A' '4001'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=SICH'.
*    PERFORM bdc_transaction USING 'VA01'.
    CALL TRANSACTION 'VA01' USING bdcdata
                     MODE p_mode
                     MESSAGES INTO messtab.
    PERFORM f_fill_messages .
*Fetch the message record having Sales Order
    READ TABLE messtab WITH KEY tcode = 'VA01'
                                dyname = 'SAPMV45A'
                                dynumb = '4001'
                                msgtyp = 'S'
                                msgspra = 'E'
                                msgid = 'V1'
                                msgnr = '311'.
    IF sy-subrc EQ 0.
      PERFORM f_header_text.
    ENDIF.
    REFRESH: messtab, bdcdata.
  ENDLOOP.
ENDFORM.                    "f_call_va01
*&---------------------------------------------------------------------*
*&      Form  f_create_detail
*&---------------------------------------------------------------------*
*       Store Detail Prgs.
*----------------------------------------------------------------------*
FORM f_create_detail .
  LOOP AT i_tab.
    TRANSLATE: i_tab-auart TO UPPER CASE,
               i_tab-bstkd TO UPPER CASE.
    i_tab_dtl-bstkd = i_tab-bstkd.
    i_tab_dtl-auart = i_tab-auart.
    i_tab_dtl-matnr = i_tab-matnr.
    i_tab_dtl-kwmeng = i_tab-kwmeng.
    APPEND i_tab_dtl.
    CLEAR i_tab_dtl.
  ENDLOOP.
ENDFORM.                    " f_create_detail
*&---------------------------------------------------------------------*
*&      Form  F_CREATE_HEADER
*&---------------------------------------------------------------------*
*       Create Header
*----------------------------------------------------------------------*
FORM f_create_header .
  DATA: v_po LIKE vbkd-bstkd, v_so LIKE vbak-auart.
  SORT i_tab BY bstkd auart.
  LOOP AT i_tab.
    TRANSLATE: i_tab-auart TO UPPER CASE,
               i_tab-bstkd TO UPPER CASE,
                    i_tab-vkorg TO UPPER CASE,
                    i_tab-vtweg TO UPPER CASE,
                    i_tab-spart TO UPPER CASE,
                    i_tab-kunnr TO UPPER CASE.
    IF v_po NE i_tab-bstkd OR v_so NE i_tab-auart.
      i_tab_hdr-bstkd  =  i_tab-bstkd.
      i_tab_hdr-bstdk  =  i_tab-bstdk.
      i_tab_hdr-auart  =  i_tab-auart.
      i_tab_hdr-vkorg  =  i_tab-vkorg.
      i_tab_hdr-vtweg  =  i_tab-vtweg.
      i_tab_hdr-spart  =  i_tab-spart.
      i_tab_hdr-kunnr  =  i_tab-kunnr.
      i_tab_hdr-text   = i_tab-text.
      APPEND i_tab_hdr.
      CLEAR i_tab_hdr.
      v_po = i_tab-bstkd.
      v_so = i_tab-auart.
    ENDIF.
  ENDLOOP.
ENDFORM.                    " F_CREATE_HEADER
*&---------------------------------------------------------------------*
*&      Form  header
*&---------------------------------------------------------------------*
*       Populate Header fields in sales order
*----------------------------------------------------------------------*
FORM header .
  PERFORM bdc_dynpro      USING 'SAPMV45A' '0101'.
  PERFORM bdc_field       USING 'BDC_CURSOR'
                                'VBAK-SPART'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '/00'.
  PERFORM bdc_field       USING 'VBAK-AUART'
*                                  'ZVOR'.
                                 i_tab_hdr-auart.
  PERFORM bdc_field       USING 'VBAK-VKORG'
*                                  'PSPR'.
                                 i_tab_hdr-vkorg.
  PERFORM bdc_field       USING 'VBAK-VTWEG'
*                                  'DL'.
                                 i_tab_hdr-vtweg.
  PERFORM bdc_field       USING 'VBAK-SPART'
*                                  '01'.
                                 i_tab_hdr-spart.
  PERFORM bdc_dynpro      USING 'SAPMV45A' '4001'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '/00'.
  PERFORM bdc_field       USING 'BDC_CURSOR'
                                'VBKD-BSTDK'.
  PERFORM bdc_field       USING 'VBKD-BSTKD'
*                                  'PO'.
                                 i_tab_hdr-bstkd.
  PERFORM bdc_field       USING 'VBKD-BSTDK'
*                                  '09.09.2003'.
                                 i_tab_hdr-bstdk.
  PERFORM bdc_field       USING 'KUAGV-KUNNR'
*                                '1'.
                                 i_tab_hdr-kunnr.
ENDFORM.                    " header
*&---------------------------------------------------------------------*
*&      Form  F_HEADER_TEXT
*&---------------------------------------------------------------------*
*       Save Sales Order Header Text
*----------------------------------------------------------------------*
FORM f_header_text .
  DATA: v_salord(10).
  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
      input  = messtab-msgv2
    IMPORTING
      output = v_salord.
  i_header-tdobject = 'VBBK'.
  i_header-tdname = v_salord.
  i_header-tdid = 'Z002'.
  i_header-tdspras = 'EN'.
  i_header-tdtitle = 'Sales Order Header Text'.
  i_lines-tdformat = '*'.
  i_lines-tdline = i_tab_hdr-text.
  APPEND i_lines.
  CLEAR i_lines.
  CALL FUNCTION 'SAVE_TEXT'
    EXPORTING
      header          = i_header
*     insert          = 'X'
      savemode_direct = 'X'
    TABLES
      lines           = i_lines.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    EXIT.
  ENDIF.
  REFRESH i_lines.
  CLEAR i_header.
ENDFORM.                    " F_HEADER_TEXT
*&---------------------------------------------------------------------*
*&      Form  f_fill_messages
*&---------------------------------------------------------------------*
FORM f_fill_messages .
  DATA: l_mstring(250).
  LOOP AT messtab.
    i_messages-bstkd = i_tab_hdr-bstkd.
    i_messages-auart = i_tab_hdr-auart.
    SELECT SINGLE * FROM t100 WHERE sprsl = messtab-msgspra
                              AND   arbgb = messtab-msgid
                              AND   msgnr = messtab-msgnr.
    IF sy-subrc = 0.
      l_mstring = t100-text.
      IF l_mstring CS '&1'.
        REPLACE '&1' WITH messtab-msgv1 INTO l_mstring.
        REPLACE '&2' WITH messtab-msgv2 INTO l_mstring.
        REPLACE '&3' WITH messtab-msgv3 INTO l_mstring.
        REPLACE '&4' WITH messtab-msgv4 INTO l_mstring.
      ELSE.
        REPLACE '&' WITH messtab-msgv1 INTO l_mstring.
        REPLACE '&' WITH messtab-msgv2 INTO l_mstring.
        REPLACE '&' WITH messtab-msgv3 INTO l_mstring.
        REPLACE '&' WITH messtab-msgv4 INTO l_mstring.
      ENDIF.
      CONDENSE l_mstring.
      IF messtab-msgtyp = 'E'.
        WRITE: /2 i_tab_hdr-bstkd,
                14 i_tab_hdr-auart,
                24 messtab-msgtyp,
                36 l_mstring COLOR 6.
      ELSE.
        WRITE: /2 i_tab_hdr-bstkd,
                14 i_tab_hdr-auart,
                24 messtab-msgtyp,
                36 l_mstring.
      ENDIF.
      i_messages-msgtyp = messtab-msgtyp.
      i_messages-longtext = l_mstring.
      i_messages-dyname = messtab-dyname.
      i_messages-dynumb = messtab-dynumb.
      i_messages-msgspra = messtab-msgspra.
      i_messages-msgid = messtab-msgid.
      i_messages-msgnr = messtab-msgnr.
      i_messages-env = messtab-env.
      i_messages-fldname = messtab-fldname.
      APPEND i_messages.
      CLEAR i_messages.
    ELSE.
      WRITE: /2 messtab.
      i_messages-dyname = messtab-dyname.
      i_messages-dynumb = messtab-dynumb.
      i_messages-msgtyp = messtab-msgtyp.
      i_messages-msgspra = messtab-msgspra.
      i_messages-msgid = messtab-msgid.
      i_messages-msgnr = messtab-msgnr.
      i_messages-env = messtab-env.
      i_messages-fldname = messtab-fldname.
      APPEND i_messages.
      CLEAR i_messages.
    ENDIF.
  ENDLOOP.
ENDFORM.                    " f_fill_messages
*&---------------------------------------------------------------------*
*&      Form  f_save_messages
*&---------------------------------------------------------------------*
*       Save message on local disk
*----------------------------------------------------------------------*
FORM f_save_messages .
  CALL FUNCTION 'WS_DOWNLOAD'
    EXPORTING
      filename = 'C:\SOORDER.TXT'
      filetype = 'DAT'
    TABLES
      data_tab = i_messages.
ENDFORM.                    " f_save_messages
*----------------------------------------------------------------------*
*        Start new screen                                              *
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
  CLEAR bdcdata.
  bdcdata-program  = program.
  bdcdata-dynpro   = dynpro.
  bdcdata-dynbegin = 'X'.
  APPEND bdcdata.
ENDFORM.                    "BDC_DYNPRO
*----------------------------------------------------------------------*
*        Insert field                                                  *
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
  IF fval <> nodata.
    CLEAR bdcdata.
    bdcdata-fnam = fnam.
    bdcdata-fval = fval.
    APPEND bdcdata.
  ENDIF.
ENDFORM.                    "BDC_FIELD
*&---------------------------------------------------------------------*
*&      Form  f_write_mesg
*&---------------------------------------------------------------------*
*       Print message on screen
*----------------------------------------------------------------------*
FORM f_write_mesg .
  SKIP.
  ULINE.
  WRITE: /2  'Log file downloded at C:\SOORDER.TXT'.
ENDFORM.                    " f_write_mesg
*&---------------------------------------------------------------------*
*&      Form  f_create_output_heading
*&---------------------------------------------------------------------*
FORM f_create_output_heading .
  WRITE: /2 'PO No.' COLOR 1,
         14 'SO Type' COLOR 1,
         24 'Msg. Type' COLOR 1,
         36 'Message' COLOR 1.
  ULINE.
ENDFORM.                    " f_create_output_heading
*&---------------------------------------------------------------------*
*&      Form  f_delete_blank
*&---------------------------------------------------------------------*
*       Delete blank lines
*----------------------------------------------------------------------*
FORM f_delete_blank .
  DELETE i_tab WHERE bstkd = space  AND auart = space.
ENDFORM.                    " f_delete_blank

Author: Sujeet Mishra
Submitted: 14/08/2013
Related Links:

Description: Customer Ageing Report.

 Refer SAP Standard Report before creating any custom report:

S_ALR_87012085  Vendor Payment History with OI sorted Items.

S_ALR_87012178  Customer (AR) Aging report by Customer

S_ALR_87012168  Customer (AR) Aging report by Invoice

REPORT &nbsp;zfi_customer_ageing.
TYPE-POOLS: slis.
TABLES: knb1,kna1,knvv,fagl_splinfo,bapi3007_2, tgsb.
DATA: i_data TYPE STANDARD TABLE OF bapi3007_2 WITH HEADER LINE.
DATA: lv_bukrs TYPE bapi3007_1-comp_code,
      lv_kunnr TYPE bapi3007_1-customer,
      lv_date  TYPE bapi3007-key_date.
DATA: lv_line  TYPE i.
DATA: lv_sum TYPE fagl_splinfo-pswbt.
DATA: lv_amtlc TYPE bsid-dmbtr.
DATA: lv_amtdc TYPE bsid-dmbtr.
DATA : lv_amtlcfix TYPE bsid-dmbtr.
DATA : lv_amtdcfix TYPE bsid-dmbtr.
DATA: lv_brtxt(20),
      lv_ktext(20),
      lv_gtext(30),
      lv_ltext(20).
DATA: lv_dudat TYPE d.
DATA: lv_ovdat TYPE d.
DATA: lv_day TYPE i.
DATA: lv_days(10).
DATA: gv_days(15).
DATA: lv_top(60).
DATA: lv_txt(10).
DATA: lv_pernr TYPE vbpa-pernr.
DATA: lv_invref_docdate TYPE bkpf-bldat.
DATA: ibkpf TYPE bkpf.
DATA: i_date TYPE STANDARD TABLE OF faede WITH HEADER LINE.
DATA: i_kna1 TYPE STANDARD TABLE OF kna1 WITH HEADER LINE.
DATA: i_knb1 TYPE STANDARD TABLE OF knb1 WITH HEADER LINE.
DATA: i_knvv TYPE STANDARD TABLE OF knvv WITH HEADER LINE.
DATA: it_t001 TYPE TABLE OF t001 WITH HEADER LINE.
DATA: i_splinfo TYPE STANDARD TABLE OF fagl_splinfo WITH HEADER LINE.
TYPES: BEGIN OF t_ageing,
bukrs TYPE knb1-bukrs,
kunnr TYPE kna1-kunnr,
name1 TYPE kna1-name1,
ort01 TYPE kna1-ort01,
zregio TYPE kna1-regio,
konzs TYPE kna1-konzs,
currency(5),
prctr TYPE cepc-prctr,
ltext TYPE cepct-ltext,
gsber TYPE fagl_splinfo-gsber,
zzbdiv TYPE bseg-zzbdiv,
zztdiv TYPE bseg-zztdiv,
inv_year TYPE bseg-rebzj,
inv_ref TYPE bseg-rebzg,
inv_item TYPE bseg-rebzz,
sp_gl_ind(1),
brsch TYPE kna1-brsch,
brtxt TYPE t016t-brtxt,
vkorg TYPE knvv-vkorg,
vtweg TYPE knvv-vtweg,
spart TYPE knvv-spart,
kdgrp TYPE knvv-kdgrp,
ktext TYPE t151t-ktext,
bzirk TYPE knvv-bzirk,
vkbur TYPE knvv-vkbur,
vkgrp TYPE knvv-vkgrp,
busab TYPE knb1-busab,
niels TYPE kna1-niels,
kukla TYPE kna1-kukla,
bran1 TYPE kna1-bran1,
pernr TYPE vbpa-pernr,
pstng_date TYPE sy-datum,
usnam TYPE bkpf-usnam,
ppnam &nbsp; TYPE bkpf-ppnam,
&nbsp; &nbsp; &nbsp; cpudt TYPE bkpf-cpudt,
&nbsp; &nbsp; &nbsp; cputm TYPE bkpf-cputm,
&nbsp; &nbsp; &nbsp; doc_date TYPE sy-datum,
&nbsp; &nbsp; &nbsp; doc_type TYPE bkpf-blart,
&nbsp; &nbsp; &nbsp; bline_date TYPE sy-datum,
&nbsp; &nbsp; &nbsp; adate TYPE sy-datum,
&nbsp; &nbsp; &nbsp; lv_dudat TYPE sy-datum,
&nbsp; &nbsp; &nbsp; pmnttrms(4),
&nbsp; &nbsp; &nbsp; zlspr TYPE bsid-zlspr,
&nbsp; &nbsp; &nbsp; bill_doc(10),
&nbsp; &nbsp; &nbsp; ref_doc_no(16),
&nbsp; &nbsp; &nbsp; alloc_nmbr(18),
&nbsp; &nbsp; &nbsp; days(10),
&nbsp; &nbsp; &nbsp; intrate TYPE zzroi,
&nbsp; &nbsp; &nbsp; int TYPE bsid-dmbtr,
&nbsp; &nbsp; &nbsp; doc_no(10),
&nbsp; &nbsp; &nbsp; fisc_year(4),
&nbsp; &nbsp; &nbsp; item_num(3),
&nbsp; &nbsp; &nbsp; gtext TYPE tgsbt-gtext,
&nbsp; &nbsp; &nbsp; spl_no TYPE fagl_splinfo-spl_no,
&nbsp; &nbsp; &nbsp; lc_fixamt TYPE bsid-dmbtr,
&nbsp; &nbsp; &nbsp; lc_amount TYPE bsid-dmbtr,
&nbsp; &nbsp; &nbsp; lv_amt &nbsp; &nbsp;TYPE bsid-dmbtr,
&nbsp; &nbsp; &nbsp; lv_amt1 &nbsp; TYPE bsid-dmbtr,
&nbsp; &nbsp; &nbsp; lv_amt2 &nbsp; TYPE bsid-dmbtr,
&nbsp; &nbsp; &nbsp; lv_amt3 &nbsp; TYPE bsid-dmbtr,
&nbsp; &nbsp; &nbsp; lv_amt4 &nbsp; TYPE bsid-dmbtr,
&nbsp; &nbsp; &nbsp; lv_amt5 &nbsp; TYPE bsid-dmbtr,
&nbsp; &nbsp; &nbsp; lv_amt6 &nbsp; TYPE bsid-dmbtr,
&nbsp; &nbsp; &nbsp; lv_amt7 &nbsp; TYPE bsid-dmbtr,
&nbsp; &nbsp; &nbsp; lv_amt8 &nbsp; TYPE bsid-dmbtr,
&nbsp; &nbsp; &nbsp; lv_reval &nbsp;TYPE bsid-dmbtr,&nbsp;
&nbsp; &nbsp; &nbsp; lv_exdif &nbsp;TYPE bsid-dmbtr,&nbsp;
&nbsp; &nbsp; &nbsp; lv_exrate TYPE ukursp, &nbsp; &nbsp;&nbsp;
&nbsp; &nbsp; &nbsp; lv_sgtxt &nbsp; TYPE bseg-sgtxt,
END OF t_ageing.
DATA: i_ageing &nbsp;TYPE STANDARD TABLE OF t_ageing WITH HEADER LINE.
DATA: i_age &nbsp; &nbsp; TYPE STANDARD TABLE OF t_ageing WITH HEADER LINE.
DATA: wa_ageing LIKE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LINE OF i_ageing.
\*&---------------------------------------------------------------------\*
\*& Internal Table Declaration For Field Catalog
\*&---------------------------------------------------------------------\*
DATA: fcat &nbsp; &nbsp; &nbsp;TYPE slis_t_fieldcat_alv,
&nbsp; &nbsp; &nbsp; ls_fact &nbsp; TYPE slis_fieldcat_alv,
&nbsp; &nbsp; &nbsp; ls_adjust TYPE slis_layout_alv.
DATA : gt_events &nbsp; TYPE slis_t_event.
DATA: &nbsp;gt_list_top_of_page TYPE slis_t_listheader.
DATA: i_sort TYPE slis_t_sortinfo_alv.
DATA: wa_sort TYPE slis_sortinfo_alv,
&nbsp; &nbsp; &nbsp; color &nbsp; &nbsp; TYPE slis_t_specialcol_alv,
&nbsp; &nbsp; &nbsp; ls_color &nbsp;TYPE slis_specialcol_alv.
CONSTANTS:
gc_formname_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE'.
\*&---------------------------------------------------------------------\*
\*& Selection Screen
\*&---------------------------------------------------------------------\*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_bukrs FOR knb1-bukrs OBLIGATORY,
s_busab FOR knb1-busab NO-DISPLAY,
s_vkorg FOR knvv-vkorg NO-DISPLAY,
 s_vtweg FOR knvv-vtweg NO-DISPLAY,
 s_spart FOR knvv-spart,
 s_kunnr FOR kna1-kunnr,
 s_vbund FOR kna1-vbund NO-DISPLAY,
 s_konzs FOR kna1-konzs.
PARAMETERS : &nbsp; &nbsp;p_spart AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-007.
SELECT-OPTIONS: s_gsber FOR tgsb-gsber NO-DISPLAY,
 s_prctr FOR fagl_splinfo-prctr,
 s_zzbdiv FOR fagl_splinfo-zzbdiv,
 s_zztdiv FOR fagl_splinfo-zztdiv.
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-006.
PARAMETERS: p_date LIKE rfpdo-allgstid OBLIGATORY.
PARAMETERS: p_ddate RADIOBUTTON GROUP &nbsp;g1,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p_pdate RADIOBUTTON GROUP &nbsp;g1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(10) text-002 FOR FIELD p_0 .
PARAMETERS: p_0(3) TYPE n DEFAULT '0',
 p_a(3) TYPE n DEFAULT '045' OBLIGATORY,
 p_b(3) TYPE n DEFAULT '060' OBLIGATORY,
 p_c(3) TYPE n DEFAULT '090' OBLIGATORY,
 p_d(3) TYPE n DEFAULT '120' OBLIGATORY,
 p_e(3) TYPE n DEFAULT '180' OBLIGATORY,
 p_f(3) TYPE n DEFAULT '365' OBLIGATORY.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b3.
SELECTION-SCREEN BEGIN OF BLOCK b8 WITH FRAME TITLE text-012.
SELECT-OPTIONS: s_kdgrp FOR knvv-kdgrp &nbsp;NO-DISPLAY,
 s_bzirk FOR knvv-bzirk &nbsp;NO-DISPLAY,
s_vkbur FOR knvv-vkbur &nbsp;NO-DISPLAY,
 s_vkgrp FOR knvv-vkgrp &nbsp;NO-DISPLAY,
 s_niels FOR kna1-niels &nbsp;NO-DISPLAY,
s_kukla FOR kna1-kukla &nbsp;NO-DISPLAY,
 s_brsch FOR kna1-brsch &nbsp;NO-DISPLAY,
 s_bran1 FOR kna1-bran1 &nbsp;NO-DISPLAY.
SELECTION-SCREEN END OF BLOCK b8.
SELECTION-SCREEN BEGIN OF BLOCK b7 WITH FRAME TITLE text-011.
PARAMETERS: p_lc &nbsp;RADIOBUTTON GROUP g5,
 p_dc RADIOBUTTON GROUP g5 DEFAULT 'X',
 p_reval AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK b7.
SELECTION-SCREEN BEGIN OF BLOCK b5 WITH FRAME TITLE text-009.
PARAMETERS: p_detail &nbsp;RADIOBUTTON GROUP g3,
 p_accsum RADIOBUTTON GROUP g3 DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK b5.
SELECTION-SCREEN BEGIN OF BLOCK b6 WITH FRAME TITLE text-010.
PARAMETERS: p_bdci RADIOBUTTON GROUP g4,
 p_di &nbsp; RADIOBUTTON GROUP g4,
 p_ci &nbsp; RADIOBUTTON GROUP g4,
 p_ch &nbsp; AS CHECKBOX DEFAULT ' '.
SELECT-OPTIONS: s_sgli FOR bapi3007_2-sp_gl_ind.
SELECTION-SCREEN END OF BLOCK b6.
INITIALIZATION.
&nbsp; PERFORM e03_eventtab_build USING gt_events\[\].
&nbsp; CLEAR: p_a,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;p_b,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;p_c,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;p_d,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;p_e,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;p_f.
AT SELECTION-SCREEN.
&nbsp; PERFORM checking.
&nbsp; IF s_sgli\[\] IS INITIAL.
&nbsp; &nbsp; s_sgli-sign = 'I'.
&nbsp; &nbsp; s_sgli-option = 'EQ'.
&nbsp; &nbsp; s_sgli-low = ' '.
&nbsp; &nbsp; APPEND s_sgli.
&nbsp; ENDIF.
&nbsp; IF p_spart = ' ' AND s_spart\[\] IS INITIAL.
&nbsp; &nbsp; MESSAGE e001(38) WITH 'Please select a Division'.
&nbsp; ENDIF.
&nbsp; IF p_spart = 'X' AND s_spart\[\] IS NOT INITIAL.
&nbsp; &nbsp; MESSAGE e001(38) WITH 'Please do not select a Division'.
&nbsp; ENDIF.
AT SELECTION-SCREEN OUTPUT.
&nbsp; LOOP AT SCREEN.
&nbsp; &nbsp; IF screen-name = 'P_0'.
&nbsp; &nbsp; &nbsp; screen-input = '0'.
&nbsp; &nbsp; &nbsp; MODIFY SCREEN.
&nbsp; &nbsp; ENDIF.
&nbsp; ENDLOOP.
START-OF-SELECTION.
&nbsp; PERFORM selection.
&nbsp; SORT i_knvv BY kunnr.
&nbsp; LOOP AT i_knvv.
&nbsp; &nbsp; DELETE ADJACENT DUPLICATES FROM i_knvv COMPARING kunnr.
&nbsp; ENDLOOP.
&nbsp; LOOP AT i_knb1.
&nbsp; &nbsp; READ TABLE i_knvv WITH KEY kunnr = i_knb1-kunnr.
&nbsp; &nbsp; READ TABLE i_kna1 WITH KEY kunnr = i_knb1-kunnr.
&nbsp; &nbsp; SELECT SINGLE brtxt
&nbsp; &nbsp; &nbsp; FROM t016t
&nbsp; &nbsp; &nbsp; INTO lv_brtxt
&nbsp; &nbsp; &nbsp;WHERE brsch = i_kna1-brsch
&nbsp; &nbsp; &nbsp; &nbsp;AND spras = sy-langu.
&nbsp; &nbsp; SELECT SINGLE ktext
&nbsp; &nbsp; &nbsp;FROM t151t
&nbsp; &nbsp; &nbsp;INTO lv_ktext
&nbsp; &nbsp; WHERE kdgrp = i_knvv-kdgrp
&nbsp; &nbsp; &nbsp; AND spras = sy-langu.
&nbsp; &nbsp; lv_bukrs = i_knb1-bukrs.
&nbsp; &nbsp; lv_kunnr = i_knb1-kunnr.
&nbsp; &nbsp; lv_date &nbsp;= p_date.
&nbsp; &nbsp; CALL FUNCTION 'BAPI_AR_ACC_GETOPENITEMS'
&nbsp; &nbsp; &nbsp; EXPORTING
&nbsp; &nbsp; &nbsp; &nbsp; companycode = lv_bukrs
&nbsp; &nbsp; &nbsp; &nbsp; customer &nbsp; &nbsp;= lv_kunnr
&nbsp; &nbsp; &nbsp; &nbsp; keydate &nbsp; &nbsp; = lv_date
&nbsp; &nbsp; &nbsp; TABLES
&nbsp; &nbsp; &nbsp; &nbsp; lineitems &nbsp; = i_data.
&nbsp; &nbsp; IF p_di EQ 'X'.
&nbsp; &nbsp; &nbsp; p_ch = ' '.
&nbsp; &nbsp; &nbsp; LOOP AT i_data WHERE db_cr_ind EQ 'S' AND sp_gl_ind IN s_sgli.
&nbsp; &nbsp; &nbsp; &nbsp; PERFORM split_operation.
&nbsp; &nbsp; &nbsp; ENDLOOP.
&nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; IF p_ci EQ 'X'.
&nbsp; &nbsp; &nbsp; p_ch = ' '.
&nbsp; &nbsp; &nbsp; LOOP AT i_data WHERE db_cr_ind EQ 'H' AND sp_gl_ind IN s_sgli.
&nbsp; &nbsp; &nbsp; &nbsp; i_data-lc_amount = \-1 * i_data-lc_amount.
&nbsp; &nbsp; &nbsp; &nbsp; i_data-amt_doccur = \-1 * i_data-amt_doccur.
&nbsp; &nbsp; &nbsp; &nbsp; PERFORM split_operation.
&nbsp; &nbsp; &nbsp; ENDLOOP.
&nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; IF p_bdci EQ 'X'.
&nbsp; &nbsp; &nbsp; LOOP AT i_data WHERE sp_gl_ind IN s_sgli.
&nbsp; &nbsp; &nbsp; &nbsp; IF i_data-db_cr_ind EQ 'H'.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i_data-lc_amount = \-1 * i_data-lc_amount.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i_data-amt_doccur = \-1 * i_data-amt_doccur.
&nbsp; &nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp; &nbsp; PERFORM split_operation.
&nbsp; &nbsp; &nbsp; ENDLOOP.
&nbsp; &nbsp; ENDIF.
&nbsp; ENDLOOP.
&nbsp; PERFORM fieldcatalog.
&nbsp; PERFORM e04_comment_build &nbsp;USING gt_list_top_of_page\[\].
&nbsp; PERFORM alv_display.
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;SELECTION
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
\* &nbsp;--> &nbsp;p1 &nbsp; &nbsp; &nbsp; &nbsp;text
\* &nbsp;<-\- &nbsp;p2 &nbsp; &nbsp; &nbsp; &nbsp;text
\*----------------------------------------------------------------------\*
FORM selection .
&nbsp; SELECT *
&nbsp; &nbsp;FROM knvv
&nbsp; &nbsp;INTO TABLE i_knvv
&nbsp; WHERE kunnr IN s_kunnr
&nbsp; &nbsp; AND vkorg IN s_vkorg
&nbsp; &nbsp; AND vtweg IN s_vtweg
&nbsp; &nbsp; AND spart IN s_spart
&nbsp; &nbsp; AND kdgrp IN s_kdgrp
&nbsp; &nbsp; AND bzirk IN s_bzirk
&nbsp; &nbsp; AND vkbur IN s_vkbur
&nbsp; &nbsp; AND vkgrp IN s_vkgrp.
&nbsp; IF p_spart = ' '.
&nbsp; &nbsp; SELECT *
&nbsp; &nbsp; &nbsp; &nbsp; FROM kna1
&nbsp; &nbsp; &nbsp; &nbsp; INTO TABLE i_kna1
&nbsp; &nbsp; &nbsp; &nbsp; FOR ALL ENTRIES IN i_knvv
&nbsp; &nbsp; &nbsp; &nbsp; WHERE kunnr EQ i_knvv-kunnr
&nbsp; &nbsp; &nbsp; &nbsp; AND &nbsp; niels IN s_niels
&nbsp; &nbsp; &nbsp; &nbsp; AND &nbsp; kukla IN s_kukla
&nbsp; &nbsp; &nbsp; &nbsp; AND &nbsp; brsch IN s_brsch
&nbsp; &nbsp; &nbsp; &nbsp; AND &nbsp; bran1 IN s_bran1
&nbsp; &nbsp; &nbsp; &nbsp; AND &nbsp; vbund IN s_vbund
&nbsp; &nbsp; &nbsp; &nbsp; AND &nbsp; konzs IN s_konzs.
&nbsp; &nbsp; SELECT *
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FROM knb1
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;INTO TABLE i_knb1 FOR ALL ENTRIES IN i_kna1
&nbsp; &nbsp; &nbsp; &nbsp; WHERE kunnr = i_kna1-kunnr
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND bukrs IN s_bukrs
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND busab IN s_busab.
&nbsp; ELSE.
&nbsp; &nbsp; SELECT *
&nbsp; &nbsp; &nbsp; FROM kna1
&nbsp; &nbsp; &nbsp; INTO TABLE i_kna1
&nbsp; &nbsp; &nbsp; WHERE kunnr IN s_kunnr
&nbsp; &nbsp; &nbsp; AND &nbsp; niels IN s_niels
&nbsp; &nbsp; &nbsp; AND &nbsp; kukla IN s_kukla
&nbsp; &nbsp; &nbsp; AND &nbsp; brsch IN s_brsch
&nbsp; &nbsp; &nbsp; AND &nbsp; bran1 IN s_bran1
&nbsp; &nbsp; &nbsp; AND &nbsp; vbund IN s_vbund
&nbsp; &nbsp; &nbsp; AND &nbsp; konzs IN s_konzs.
&nbsp; &nbsp; SELECT *
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FROM knb1
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;INTO TABLE i_knb1 FOR ALL ENTRIES IN i_kna1
&nbsp; &nbsp; &nbsp; &nbsp; WHERE kunnr = i_kna1-kunnr
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND bukrs IN s_bukrs
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND busab IN s_busab.
&nbsp; ENDIF.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" SELECTION
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;DATA_ENTRY
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
\* &nbsp;--> &nbsp;p1 &nbsp; &nbsp; &nbsp; &nbsp;text
\* &nbsp;<-\- &nbsp;p2 &nbsp; &nbsp; &nbsp; &nbsp;text
\*----------------------------------------------------------------------\*
FORM data_entry .
\*&---------------------------------------------------------------------\*
\*& Selecting Text For Businees Area
\*&---------------------------------------------------------------------\*
&nbsp; IF i_data-inv_ref EQ ' '.
&nbsp; &nbsp; i_data-inv_ref &nbsp; &nbsp;= i_data-doc_no.
&nbsp; &nbsp; i_data-inv_year &nbsp; = i_data-fisc_year.
&nbsp; &nbsp; i_data-inv_item &nbsp; = i_data-item_num.
&nbsp; ENDIF.
\* Document for Invoice reference stored in Variable.
&nbsp; CLEAR: lv_invref_docdate.
&nbsp; SELECT SINGLE bldat
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM bkpf
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; INTO lv_invref_docdate
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE bukrs = i_data-comp_code AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; belnr = i_data-inv_ref &nbsp; AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gjahr = i_data-inv_year.
&nbsp; SELECT SINGLE gtext
&nbsp; &nbsp; &nbsp;FROM tgsbt
&nbsp; &nbsp; &nbsp;INTO lv_gtext
&nbsp; &nbsp; WHERE gsber = i_splinfo-gsber
&nbsp; &nbsp; &nbsp; AND spras = sy-langu.
&nbsp; SELECT SINGLE ktext
&nbsp; &nbsp;FROM cepct
&nbsp; &nbsp;INTO lv_ltext
&nbsp; WHERE prctr = i_splinfo-prctr
&nbsp; &nbsp; AND spras = sy-langu.
&nbsp; CLEAR : lv_pernr.
&nbsp; IF i_data-bill_doc NE ' '.
&nbsp; &nbsp; SELECT SINGLE pernr FROM vbpa INTO lv_pernr
&nbsp; &nbsp; WHERE vbeln = i_data-bill_doc
&nbsp; &nbsp; AND parvw = 'ZA'.
&nbsp; ENDIF.
&nbsp; DATA: lv_vbelv TYPE vbfa-vbelv,
&nbsp; &nbsp; &nbsp; &nbsp; lv_intrate TYPE vbak-zzroi.
&nbsp; CLEAR: lv_vbelv, lv_intrate.
&nbsp; SELECT SINGLE vbelv FROM vbfa INTO lv_vbelv
&nbsp; &nbsp; WHERE vbeln = i_data-ref_doc_no
&nbsp; &nbsp; &nbsp; AND vbtyp_v = 'C'.
&nbsp; IF sy-subrc = 0.
&nbsp; &nbsp; SELECT SINGLE zzroi FROM vbak INTO lv_intrate
&nbsp; &nbsp; &nbsp; WHERE vbeln = lv_vbelv.
&nbsp; ENDIF.
&nbsp; PERFORM date_calculation.
&nbsp; CLEAR : i_ageing, it_t001.
&nbsp; READ TABLE it_t001 WITH KEY bukrs = i_knb1-bukrs.
&nbsp; i_ageing-bukrs &nbsp; &nbsp; &nbsp;= i_knb1-bukrs.
&nbsp; i_ageing-kunnr &nbsp; &nbsp; &nbsp;= i_knb1-kunnr.
&nbsp; i_ageing-name1 &nbsp; &nbsp; &nbsp;= i_kna1-name1.
&nbsp; i_ageing-ort01 &nbsp; &nbsp; &nbsp;= i_kna1-ort01.
&nbsp; i_ageing-regio &nbsp; &nbsp; &nbsp;= i_kna1-regio.
&nbsp; i_ageing-brsch &nbsp; &nbsp; &nbsp;= i_kna1-brsch.
&nbsp; i_ageing-brtxt &nbsp; &nbsp; &nbsp;= lv_brtxt.
&nbsp; i_ageing-konzs &nbsp; &nbsp; &nbsp;= i_kna1-konzs.
&nbsp; i_ageing-vkorg &nbsp; &nbsp; &nbsp;= i_knvv-vkorg.
&nbsp; i_ageing-vtweg &nbsp; &nbsp; &nbsp;= i_knvv-vtweg.
&nbsp; i_ageing-spart &nbsp; &nbsp; &nbsp;= i_knvv-spart.
&nbsp; i_ageing-kdgrp &nbsp; &nbsp; &nbsp;= i_knvv-kdgrp.
&nbsp; i_ageing-ktext &nbsp; &nbsp; &nbsp;= lv_ktext.
&nbsp; i_ageing-bzirk &nbsp; &nbsp; &nbsp;= i_knvv-bzirk.
&nbsp; i_ageing-vkbur &nbsp; &nbsp; &nbsp;= i_knvv-vkbur.
&nbsp; i_ageing-vkgrp &nbsp; &nbsp; &nbsp;= i_knvv-vkgrp.
&nbsp; i_ageing-pernr &nbsp; &nbsp; &nbsp;= lv_pernr.
&nbsp; i_ageing-busab &nbsp; &nbsp; &nbsp;= i_knb1-busab.
&nbsp; i_ageing-gsber &nbsp; &nbsp; &nbsp;= i_splinfo-gsber.
&nbsp; i_ageing-spl_no &nbsp; &nbsp; = i_splinfo-spl_no.
&nbsp; i_ageing-gtext &nbsp; &nbsp; &nbsp;= lv_gtext.
&nbsp; i_ageing-prctr &nbsp; &nbsp; &nbsp;= i_splinfo-prctr.
&nbsp; &nbsp;i_ageing-ltext &nbsp; &nbsp; &nbsp;= lv_ltext.
&nbsp; i_ageing-doc_no &nbsp; &nbsp; = i_data-doc_no.
&nbsp; i_ageing-fisc_year &nbsp;= i_data-fisc_year.
&nbsp; i_ageing-item_num &nbsp; = i_data-item_num.
&nbsp; i_ageing-pstng_date = i_data-pstng_date.
&nbsp; i_ageing-doc_date &nbsp; = i_data-doc_date.
&nbsp; i_ageing-usnam &nbsp; &nbsp; &nbsp;= ibkpf-usnam.
&nbsp; i_ageing-ppnam &nbsp; &nbsp; &nbsp;= ibkpf-ppnam.
&nbsp; i_ageing-cpudt &nbsp; &nbsp; &nbsp;= ibkpf-cpudt.
&nbsp; i_ageing-cputm &nbsp; &nbsp; &nbsp;= ibkpf-cputm.
&nbsp; i_ageing-doc_type &nbsp; = i_data-doc_type.
&nbsp; i_ageing-currency &nbsp; = i_data-currency.
&nbsp; i_ageing-bline_date = i_data-bline_date.
&nbsp; i_ageing-adate &nbsp; &nbsp; &nbsp;= p_date.
&nbsp; i_ageing-lv_dudat &nbsp; = lv_dudat.
&nbsp; i_ageing-pmnttrms &nbsp; = i_data-pmnttrms.
&nbsp; i_ageing-zlspr &nbsp; &nbsp; &nbsp;= i_data-pmnt_block.
&nbsp; i_ageing-bill_doc &nbsp; = i_data-bill_doc.
&nbsp; i_ageing-ref_doc_no = i_data-ref_doc_no.
&nbsp; i_ageing-alloc_nmbr = i_data-alloc_nmbr.
&nbsp; i_ageing-lv_sgtxt &nbsp; = i_data-item_text.
&nbsp; i_ageing-inv_ref &nbsp; &nbsp;= i_data-inv_ref.
&nbsp; i_ageing-inv_year &nbsp; = i_data-inv_year.
&nbsp; i_ageing-inv_item &nbsp; = i_data-inv_item.
&nbsp; i_ageing-sp_gl_ind &nbsp;= i_data-sp_gl_ind.
&nbsp; i_ageing-lc_amount &nbsp;= lv_amtlc.
&nbsp; IF p_dc = 'X'.
&nbsp; &nbsp; i_ageing-lc_fixamt &nbsp;= lv_amtlcfix.
&nbsp; ELSE.
&nbsp; &nbsp; i_ageing-lc_fixamt &nbsp;= lv_amtdcfix.
&nbsp; ENDIF.
&nbsp; i_ageing-days &nbsp; &nbsp; &nbsp; = lv_days.
&nbsp; i_ageing-intrate &nbsp; &nbsp;= lv_intrate.
&nbsp; i_ageing-int &nbsp; &nbsp; &nbsp; &nbsp;= i_ageing-lc_amount * lv_intrate / 365.
&nbsp; IF p_ch = ' '.
&nbsp; &nbsp; IF lv_days LT p_0. "AND lv_amtlc GE 0.
&nbsp; &nbsp; &nbsp; i_ageing-lv_amt = lv_amtlc.
&nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; IF lv_days GT p_0 AND lv_days LE p_a AND p_a IS NOT INITIAL.
&nbsp; &nbsp; &nbsp; i_ageing-lv_amt1 = lv_amtlc.
&nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; IF lv_days GT p_a AND lv_days LE p_b AND p_b IS NOT INITIAL.
&nbsp; &nbsp; &nbsp; i_ageing-lv_amt2 = lv_amtlc.
&nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; IF lv_days GT p_b AND lv_days LE p_c AND p_c IS NOT INITIAL.
&nbsp; &nbsp; &nbsp; i_ageing-lv_amt3 = lv_amtlc.
&nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; IF lv_days GT p_c AND lv_days LE p_d AND p_d IS NOT INITIAL.
&nbsp; &nbsp; &nbsp; i_ageing-lv_amt4 = lv_amtlc.
&nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; IF lv_days GT p_d AND lv_days LE p_e AND p_e IS NOT INITIAL .
&nbsp; &nbsp; &nbsp; i_ageing-lv_amt5 = lv_amtlc.
&nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; IF lv_days GT p_e AND lv_days LE p_f AND p_f IS NOT INITIAL.
&nbsp; &nbsp; &nbsp; i_ageing-lv_amt6 = lv_amtlc.
&nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; IF lv_days GT p_f AND p_f IS NOT INITIAL.
&nbsp; &nbsp; &nbsp; i_ageing-lv_amt7 = lv_amtlc.
&nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; IF lv_days GT p_f AND p_f IS INITIAL.
&nbsp; &nbsp; &nbsp; i_ageing-lv_amt7 = lv_amtlc.
&nbsp; &nbsp; ENDIF.
&nbsp; ENDIF.
&nbsp; IF p_ch = 'X'.
&nbsp; &nbsp; IF lv_days LT p_0 AND &nbsp;i_data-sp_gl_ind EQ ' '.
&nbsp; &nbsp; &nbsp; i_ageing-lv_amt = lv_amtlc.
&nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; IF lv_days GT p_0 AND lv_days LE p_a AND p_a IS NOT INITIAL
&nbsp; &nbsp; &nbsp; AND i_data-sp_gl_ind EQ ' '.
&nbsp; &nbsp; &nbsp; i_ageing-lv_amt1 = lv_amtlc.
&nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; IF lv_days GT p_a AND lv_days LE p_b AND p_b IS NOT INITIAL
&nbsp; &nbsp; &nbsp; AND i_data-sp_gl_ind EQ ' '.
&nbsp; &nbsp; &nbsp; i_ageing-lv_amt2 = lv_amtlc.
&nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; IF lv_days GT p_b AND lv_days LE p_c AND p_c IS NOT INITIAL
&nbsp; &nbsp; &nbsp; AND i_data-sp_gl_ind EQ ' '.
&nbsp; &nbsp; &nbsp; i_ageing-lv_amt3 = lv_amtlc.
&nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; IF lv_days GT p_c AND lv_days LE p_d AND p_d IS NOT INITIAL
&nbsp; &nbsp; &nbsp; AND i_data-sp_gl_ind EQ ' '.
&nbsp; &nbsp; &nbsp; i_ageing-lv_amt4 = lv_amtlc.
&nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; IF lv_days GT p_d AND lv_days LE p_e AND p_e IS NOT INITIAL
&nbsp; &nbsp; &nbsp; AND i_data-sp_gl_ind EQ ' '.
&nbsp; &nbsp; &nbsp; i_ageing-lv_amt5 = lv_amtlc.
&nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; IF lv_days GT p_e AND lv_days LE p_f AND p_f IS NOT INITIAL
&nbsp; &nbsp; &nbsp; AND i_data-sp_gl_ind EQ ' '.
&nbsp; &nbsp; &nbsp; i_ageing-lv_amt6 = lv_amtlc.
&nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; IF lv_days GT p_f AND p_f IS NOT INITIAL
&nbsp; &nbsp; &nbsp; AND i_data-sp_gl_ind EQ ' '.
&nbsp; &nbsp; &nbsp; i_ageing-lv_amt7 = lv_amtlc.
&nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; IF lv_days GT p_f AND p_f IS INITIAL
&nbsp; &nbsp; &nbsp; AND i_data-sp_gl_ind EQ ' '.
&nbsp; &nbsp; &nbsp; i_ageing-lv_amt7 = lv_amtlc.
&nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; IF i_data-sp_gl_ind NE ' '.
&nbsp; &nbsp; &nbsp; i_ageing-lv_amt8 = lv_amtlc.
&nbsp; &nbsp; ENDIF.
&nbsp; ENDIF.
&nbsp; IF p_reval = 'X'.
&nbsp; &nbsp; PERFORM forex_reval.
&nbsp; ENDIF.
&nbsp; IF &nbsp; &nbsp;i_ageing-prctr IN s_prctr
&nbsp; &nbsp; &nbsp; APPEND i_ageing.
&nbsp; ENDIF.
&nbsp; CLEAR i_ageing.
&nbsp; CLEAR: lv_amtlc, lv_amtlcfix, lv_amtdcfix.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" DATA_ENTRY
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;FIELDCATALOG
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
\* &nbsp;--> &nbsp;p1 &nbsp; &nbsp; &nbsp; &nbsp;text
\* &nbsp;<-\- &nbsp;p2 &nbsp; &nbsp; &nbsp; &nbsp;text
\*----------------------------------------------------------------------\*
FORM fieldcatalog .
&nbsp; ls_fact-fieldname = 'BUKRS'.
&nbsp; ls_fact-seltext_m = 'Company Code'.
&nbsp; ls_fact-no_out = 'X'.
&nbsp; APPEND ls_fact TO fcat.
&nbsp; CLEAR ls_fact.
&nbsp; ls_fact-fieldname = 'KUNNR'.
&nbsp; ls_fact-seltext_m = 'Customer Code'.
&nbsp; APPEND ls_fact TO fcat.
&nbsp; CLEAR ls_fact.
&nbsp; ls_fact-fieldname = 'NAME1'.
&nbsp; ls_fact-seltext_m = 'Customer Name'.
&nbsp; APPEND ls_fact TO fcat.
&nbsp; CLEAR ls_fact.
&nbsp; ls_fact-fieldname = 'ORT01'.
&nbsp; ls_fact-seltext_m = 'Customer City'.
&nbsp; APPEND ls_fact TO fcat.
&nbsp; CLEAR ls_fact.
&nbsp; ls_fact-fieldname = 'KONZS'.
&nbsp; ls_fact-seltext_m = 'Group Key'.
&nbsp; APPEND ls_fact TO fcat.
&nbsp; CLEAR ls_fact.
&nbsp; ls_fact-fieldname = 'PRCTR'.
&nbsp; ls_fact-seltext_m = 'Profit Center'.
&nbsp; APPEND ls_fact TO fcat.
&nbsp; CLEAR ls_fact.
&nbsp; ls_fact-fieldname = 'LTEXT'.
&nbsp; ls_fact-seltext_m = 'PC Description'.
&nbsp; APPEND ls_fact TO fcat.
&nbsp; CLEAR ls_fact.
&nbsp; IF p_accsum <> 'X'.
&nbsp; &nbsp; ls_fact-fieldname = 'INV_REF'.
&nbsp; &nbsp; ls_fact-seltext_m = 'Invoice Reference'.
&nbsp; &nbsp; ls_fact-no_out = 'X'.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; &nbsp; ls_fact-fieldname = 'INV_YEAR'.
&nbsp; &nbsp; ls_fact-seltext_m = 'Invoice Ref Year'.
&nbsp; &nbsp; ls_fact-no_out = 'X'.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; &nbsp; ls_fact-fieldname = 'INV_ITEM'.
&nbsp; &nbsp; ls_fact-seltext_m = 'Invoice Ref Item'.
&nbsp; &nbsp; ls_fact-no_out = 'X'.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; &nbsp; ls_fact-fieldname = 'BILL_DOC'.
&nbsp; &nbsp; ls_fact-seltext_m = 'Billing Doc-Internal'.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; &nbsp; ls_fact-fieldname = 'ALLOC_NMBR'.
&nbsp; &nbsp; ls_fact-seltext_m = 'Billing Doc-External'.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; ENDIF.
&nbsp; IF p_dc = 'X'.
&nbsp; &nbsp; ls_fact-fieldname = 'LC_FIXAMT'.
&nbsp; &nbsp; ls_fact-seltext_m = 'Amt in Local Curr'.
&nbsp; &nbsp; ls_fact-emphasize = 'C400'.
&nbsp; &nbsp; ls_fact-do_sum = 'X'.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; ELSE.
&nbsp; &nbsp; ls_fact-fieldname = 'LC_FIXAMT'.
&nbsp; &nbsp; ls_fact-seltext_m = 'Amt in Doc Curr'.
&nbsp; &nbsp; ls_fact-emphasize = 'C400'.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; ENDIF.
&nbsp; ls_fact-fieldname = 'CURRENCY'.
&nbsp; ls_fact-seltext_m = 'Currency'.
&nbsp; ls_fact-emphasize = 'C400'.
&nbsp; APPEND ls_fact TO fcat.
&nbsp; CLEAR ls_fact.
&nbsp; ls_fact-fieldname = 'LC_AMOUNT'.
&nbsp; ls_fact-seltext_m = 'Amount'.
&nbsp; ls_fact-emphasize = 'C400'.
&nbsp; IF p_lc = 'X'.
&nbsp; &nbsp; ls_fact-do_sum = 'X'.
&nbsp; ENDIF.
&nbsp; APPEND ls_fact TO fcat.
&nbsp; CLEAR ls_fact.
&nbsp; ls_fact-fieldname = 'LV_AMT'.
&nbsp; CONCATENATE 'Less Than' p_0 INTO gv_days.
&nbsp; ls_fact-seltext_m = gv_days.
&nbsp; ls_fact-emphasize = 'C500'.
&nbsp; IF p_lc = 'X'.
&nbsp; &nbsp; ls_fact-do_sum = 'X'.
&nbsp; ENDIF.
&nbsp; APPEND ls_fact TO fcat.
&nbsp; CLEAR ls_fact.
&nbsp; ls_fact-fieldname = 'LV_AMT1'.
&nbsp; PERFORM days_concatenation USING p_0 p_a.
&nbsp; ls_fact-seltext_m = gv_days.
&nbsp; ls_fact-emphasize = 'C500'.
&nbsp; IF p_lc = 'X'.
&nbsp; &nbsp; ls_fact-do_sum = 'X'.
&nbsp; ENDIF.
&nbsp; APPEND ls_fact TO fcat.
&nbsp; CLEAR ls_fact.
&nbsp; ls_fact-fieldname = 'LV_AMT2'.
&nbsp; PERFORM days_concatenation USING p_a p_b.
&nbsp; ls_fact-seltext_m = gv_days.
&nbsp; ls_fact-emphasize = 'C500'.
&nbsp; IF p_lc = 'X'.
&nbsp; &nbsp; ls_fact-do_sum = 'X'.
&nbsp; ENDIF.
&nbsp; APPEND ls_fact TO fcat.
&nbsp; CLEAR ls_fact.
&nbsp; ls_fact-fieldname = 'LV_AMT3'.
&nbsp; PERFORM days_concatenation USING p_b p_c.
&nbsp; ls_fact-seltext_m = gv_days.
&nbsp; ls_fact-emphasize = 'C500'.
&nbsp; IF p_lc = 'X'.
&nbsp; &nbsp; ls_fact-do_sum = 'X'.
&nbsp; ENDIF.
&nbsp; APPEND ls_fact TO fcat.
&nbsp; CLEAR ls_fact.
&nbsp; ls_fact-fieldname = 'LV_AMT4'.
&nbsp; PERFORM days_concatenation USING p_c p_d.
&nbsp; ls_fact-seltext_m = gv_days.
&nbsp; ls_fact-emphasize = 'C500'.
&nbsp; IF p_lc = 'X'.
&nbsp; &nbsp; ls_fact-do_sum = 'X'.
&nbsp; ENDIF.
&nbsp; APPEND ls_fact TO fcat.
&nbsp; CLEAR ls_fact.
&nbsp; ls_fact-fieldname = 'LV_AMT5'.
&nbsp; PERFORM days_concatenation USING p_d p_e.
&nbsp; ls_fact-seltext_m = gv_days.
&nbsp; ls_fact-emphasize = 'C500'.
&nbsp; IF p_lc = 'X'.
&nbsp; &nbsp; ls_fact-do_sum = 'X'.
&nbsp; ENDIF.
&nbsp; APPEND ls_fact TO fcat.
&nbsp; CLEAR ls_fact.
&nbsp; ls_fact-fieldname = 'LV_AMT6'.
&nbsp; PERFORM days_concatenation USING p_e p_f.
&nbsp; ls_fact-seltext_m = gv_days.
&nbsp; ls_fact-emphasize = 'C500'.
&nbsp; IF p_lc = 'X'.
&nbsp; &nbsp; ls_fact-do_sum = 'X'.
&nbsp; ENDIF.
&nbsp; APPEND ls_fact TO fcat.
&nbsp; CLEAR ls_fact.
&nbsp; ls_fact-fieldname = 'LV_AMT7'.
&nbsp; CONCATENATE 'Greater Than' p_f INTO gv_days.
&nbsp; ls_fact-seltext_m = gv_days.
&nbsp; ls_fact-emphasize = 'C500'.
&nbsp; IF p_lc = 'X'.
&nbsp; &nbsp; ls_fact-do_sum = 'X'.
&nbsp; ENDIF.
&nbsp; APPEND ls_fact TO fcat.
&nbsp; CLEAR ls_fact.
&nbsp; IF p_ch = 'X'.
&nbsp; &nbsp; ls_fact-fieldname = 'LV_AMT8'.
&nbsp; &nbsp; ls_fact-seltext_m = 'Special GL Amount'.
&nbsp; &nbsp; ls_fact-emphasize = 'C600'.
&nbsp; &nbsp; IF p_lc = 'X'.
&nbsp; &nbsp; &nbsp; ls_fact-do_sum = 'X'.
&nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; ENDIF.
&nbsp; IF p_accsum <> 'X'.
&nbsp; &nbsp; ls_fact-fieldname = 'PSTNG_DATE'.
&nbsp; &nbsp; ls_fact-seltext_m = 'Posting Date'.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; &nbsp; ls_fact-fieldname = 'DOC_DATE'.
&nbsp; &nbsp; ls_fact-seltext_m = 'Document Date'.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; &nbsp; ls_fact-fieldname = 'DOC_TYPE'.
&nbsp; &nbsp; ls_fact-seltext_m = 'Document Type'.
&nbsp; &nbsp; ls_fact-no_out = 'X'.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; &nbsp; ls_fact-fieldname = 'ADATE'.
&nbsp; &nbsp; ls_fact-seltext_m = 'Analysis Date'.
&nbsp; &nbsp; ls_fact-no_out = 'X'.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; &nbsp; ls_fact-fieldname = 'BLINE_DATE'.
&nbsp; &nbsp; ls_fact-seltext_m = 'Baseline Date'.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; &nbsp; ls_fact-fieldname = 'PMNTTRMS'.
&nbsp; &nbsp; ls_fact-seltext_m = 'Payment Terms'.
&nbsp; &nbsp; ls_fact-no_out = 'X'.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; &nbsp; ls_fact-fieldname = 'LV_DUDAT'.
&nbsp; &nbsp; ls_fact-seltext_m = 'Due Date'.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; &nbsp; ls_fact-fieldname = 'DAYS'.
&nbsp; &nbsp; ls_fact-seltext_m = 'Overdue Days'.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; ENDIF.
&nbsp; IF p_reval = 'X'.
&nbsp; &nbsp; IF p_accsum <> 'X'.
&nbsp; &nbsp; &nbsp; ls_fact-fieldname = 'LV_EXRATE'.
&nbsp; &nbsp; &nbsp; ls_fact-seltext_m = 'Revaluation Ex. Rate'.
&nbsp; &nbsp; &nbsp; ls_fact-emphasize = 'C700'.
&nbsp; &nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; &nbsp; CLEAR ls_fact.
&nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; ls_fact-fieldname = 'LV_REVAL'.
&nbsp; &nbsp; ls_fact-seltext_m = 'Revaluated LC Amount'.
&nbsp; &nbsp; ls_fact-emphasize = 'C700'.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; &nbsp; ls_fact-fieldname = 'LV_EXDIF'.
&nbsp; &nbsp; ls_fact-seltext_m = 'Revaluation Difference'.
&nbsp; &nbsp; ls_fact-emphasize = 'C700'.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; ENDIF.
&nbsp; ls_fact-fieldname = 'INT'.
&nbsp; ls_fact-seltext_m = 'Overdue Interest'.
&nbsp; ls_fact-emphasize = 'C100'.
&nbsp; APPEND ls_fact TO fcat.
&nbsp; CLEAR ls_fact.
&nbsp; IF p_accsum <> 'X'.
&nbsp; &nbsp; ls_fact-fieldname = 'INTRATE'.
&nbsp; &nbsp; ls_fact-seltext_m = 'Int Rate p.a'.
&nbsp; &nbsp; ls_fact-emphasize = 'C100'.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; &nbsp; ls_fact-fieldname = 'SP_GL_IND'.
&nbsp; &nbsp; ls_fact-seltext_m = 'Special GL Indicator'.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; &nbsp; ls_fact-fieldname = 'LV_SGTXT'.
&nbsp; &nbsp; ls_fact-seltext_m = 'Line Item Text'.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; &nbsp; ls_fact-fieldname = 'DOC_NO'.
&nbsp; &nbsp; ls_fact-seltext_m = 'Accounting Doccument Number'.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; &nbsp; ls_fact-fieldname = 'FISC_YEAR'.
&nbsp; &nbsp; ls_fact-seltext_m = 'Document Year'.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; &nbsp; ls_fact-fieldname = 'ITEM_NUM'.
&nbsp; &nbsp; ls_fact-seltext_m = 'Line Item'.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; &nbsp; ls_fact-fieldname = 'ZLSPR'.
&nbsp; &nbsp; ls_fact-seltext_m = 'Payment Block'.
&nbsp; &nbsp; ls_fact-no_out = 'X'.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; &nbsp; ls_fact-fieldname = 'USNAM'.
&nbsp; &nbsp; ls_fact-seltext_m = 'User ID'.
&nbsp; &nbsp; ls_fact-no_out = 'X'.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; &nbsp; ls_fact-fieldname = 'PPNAM'.
&nbsp; &nbsp; ls_fact-seltext_m = 'Parking User ID'.
&nbsp; &nbsp; ls_fact-no_out = 'X'.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; &nbsp; ls_fact-fieldname = 'CPUDT'.
&nbsp; &nbsp; ls_fact-seltext_m = 'Entry Date'.
&nbsp; &nbsp; ls_fact-no_out = 'X'.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; &nbsp; ls_fact-fieldname = 'CPUTM'.
&nbsp; &nbsp; ls_fact-seltext_m = 'Entry Time'.
&nbsp; &nbsp; ls_fact-no_out = 'X'.
&nbsp; &nbsp; APPEND ls_fact TO fcat.
&nbsp; &nbsp; CLEAR ls_fact.
&nbsp; ENDIF.
&nbsp; ls_fact-fieldname = 'REGIO'.
&nbsp; ls_fact-seltext_m = 'Customer State'.
&nbsp; ls_fact-no_out = 'X'.
&nbsp; APPEND ls_fact TO fcat.
&nbsp; wa_sort-spos = '02'.
&nbsp; wa_sort-fieldname = 'KUNNR'.
&nbsp; wa_sort-up = 'X'.
&nbsp; wa_sort-group = '*'.
&nbsp; wa_sort-subtot = 'X'.
&nbsp; APPEND wa_sort TO i_sort.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" FIELDCATALOG
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;ALV_DISPLAY
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
\* &nbsp;--> &nbsp;p1 &nbsp; &nbsp; &nbsp; &nbsp;text
\* &nbsp;<-\- &nbsp;p2 &nbsp; &nbsp; &nbsp; &nbsp;text
\*----------------------------------------------------------------------\*
FORM alv_display .
&nbsp; SORT i_ageing BY bukrs kunnr currency prctr gsber zzbdiv zztdiv inv_year inv_ref inv_item &nbsp;sp_gl_ind.
&nbsp; IF p_detail = 'X'.
&nbsp; &nbsp; LOOP AT i_ageing INTO wa_ageing.
&nbsp; &nbsp; &nbsp; PERFORM data_condense USING wa_ageing-kunnr.
&nbsp; &nbsp; &nbsp; PERFORM data_condense USING wa_ageing-prctr.
&nbsp; &nbsp; &nbsp; PERFORM data_condense USING wa_ageing-doc_no.
&nbsp; &nbsp; &nbsp; PERFORM data_condense USING wa_ageing-bill_doc.
&nbsp; &nbsp; &nbsp; APPEND wa_ageing TO i_age.
&nbsp; &nbsp; &nbsp; CLEAR i_age.
&nbsp; &nbsp; ENDLOOP.
&nbsp; ENDIF.
&nbsp; IF p_accsum = 'X'.
&nbsp; &nbsp; LOOP AT i_ageing INTO wa_ageing.
&nbsp; &nbsp; &nbsp; AT END OF ltext.
&nbsp; &nbsp; &nbsp; &nbsp; SUM.
&nbsp; &nbsp; &nbsp; &nbsp; PERFORM data_condense USING wa_ageing-kunnr.
&nbsp; &nbsp; &nbsp; &nbsp; PERFORM data_condense USING wa_ageing-prctr.
&nbsp; &nbsp; &nbsp; &nbsp; PERFORM data_condense USING wa_ageing-doc_no.
&nbsp; &nbsp; &nbsp; &nbsp; PERFORM data_condense USING wa_ageing-bill_doc.
&nbsp; &nbsp; &nbsp; &nbsp; APPEND wa_ageing TO i_age.
&nbsp; &nbsp; &nbsp; &nbsp; CLEAR i_age.
&nbsp; &nbsp; &nbsp; ENDAT.
&nbsp; &nbsp; ENDLOOP.
&nbsp; ENDIF.
&nbsp; ls_adjust-colwidth_optimize = 'X'.
&nbsp; CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
&nbsp; &nbsp; EXPORTING
&nbsp; &nbsp; &nbsp; i_buffer_active &nbsp; &nbsp;= space
&nbsp; &nbsp; &nbsp; i_default &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 'X'
&nbsp; &nbsp; &nbsp; i_save &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 'A'
&nbsp; &nbsp; &nbsp; i_callback_program = sy-repid
&nbsp; &nbsp; &nbsp; it_fieldcat &nbsp; &nbsp; &nbsp; &nbsp;= fcat
&nbsp; &nbsp; &nbsp; it_sort &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= i_sort
&nbsp; &nbsp; &nbsp; is_layout &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= ls_adjust
&nbsp; &nbsp; &nbsp; it_events &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= gt_events\[\]
&nbsp; &nbsp; TABLES
&nbsp; &nbsp; &nbsp; t_outtab &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = i_age.
&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; ENDIF.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" ALV_DISPLAY
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;SPLIT_OPERATION
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
\* &nbsp;--> &nbsp;p1 &nbsp; &nbsp; &nbsp; &nbsp;text
\* &nbsp;<-\- &nbsp;p2 &nbsp; &nbsp; &nbsp; &nbsp;text
\*----------------------------------------------------------------------\*
FORM split_operation .
&nbsp; SELECT *
&nbsp; &nbsp; FROM fagl_splinfo
&nbsp; &nbsp; INTO TABLE i_splinfo
&nbsp; &nbsp;WHERE belnr = i_data-doc_no
&nbsp; &nbsp; &nbsp;AND gjahr = i_data-fisc_year
&nbsp; &nbsp; &nbsp;AND bukrs = i_data-comp_code
&nbsp; &nbsp; &nbsp;AND buzei = i_data-item_num.
&nbsp; CLEAR ibkpf.
&nbsp; SELECT SINGLE * FROM bkpf INTO ibkpf
&nbsp; &nbsp; &nbsp; WHERE bukrs = i_data-comp_code AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; belnr = i_data-doc_no &nbsp; &nbsp;AND
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gjahr = i_data-fisc_year.
&nbsp; DESCRIBE TABLE i_splinfo LINES lv_line.
&nbsp; IF lv_line = 1.
&nbsp; &nbsp; READ TABLE i_splinfo WITH KEY belnr = i_data-doc_no.
&nbsp; &nbsp; IF p_lc = 'X'.
&nbsp; &nbsp; &nbsp; lv_amtlc = i_data-lc_amount.
&nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; IF p_dc = 'X'.
&nbsp; &nbsp; &nbsp; lv_amtlc = i_data-amt_doccur .
&nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; lv_amtlcfix = i_data-lc_amount.
&nbsp; &nbsp; lv_amtdcfix = i_data-amt_doccur.
&nbsp; &nbsp; PERFORM data_entry.
&nbsp; ENDIF.
&nbsp; IF lv_line GT 1.
&nbsp; &nbsp; LOOP AT i_splinfo
&nbsp; &nbsp; &nbsp; WHERE belnr = i_data-doc_no
&nbsp; &nbsp; &nbsp; &nbsp; AND gjahr = i_data-fisc_year
&nbsp; &nbsp; &nbsp; &nbsp; AND bukrs = i_data-comp_code
&nbsp; &nbsp; &nbsp; &nbsp; AND buzei = i_data-item_num.
&nbsp; &nbsp; &nbsp; lv_sum = lv_sum + i_splinfo-pswbt.
&nbsp; &nbsp; ENDLOOP.
&nbsp; &nbsp; LOOP AT i_splinfo
&nbsp; &nbsp; &nbsp; WHERE belnr = i_data-doc_no
&nbsp; &nbsp; &nbsp; &nbsp; AND gjahr = i_data-fisc_year
&nbsp; &nbsp; &nbsp; &nbsp; AND bukrs = i_data-comp_code
&nbsp; &nbsp; &nbsp; &nbsp; AND buzei = i_data-item_num.
&nbsp; &nbsp; &nbsp; CLEAR: lv_amtlc, lv_amtdc.
&nbsp; &nbsp; &nbsp; IF p_lc = 'X'.
&nbsp; &nbsp; &nbsp; &nbsp; lv_amtlc = ( i_data-lc_amount * i_splinfo-pswbt ) / lv_sum.
&nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp; IF p_dc = 'X'.
&nbsp; &nbsp; &nbsp; &nbsp; lv_amtlc = ( i_data-amt_doccur * i_splinfo-pswbt ) / lv_sum.
&nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp; lv_amtlcfix = ( i_data-lc_amount * i_splinfo-pswbt ) / lv_sum.
&nbsp; &nbsp; &nbsp; lv_amtdcfix = ( i_data-amt_doccur * i_splinfo-pswbt ) / lv_sum.
&nbsp; &nbsp; &nbsp; PERFORM data_entry.
&nbsp; &nbsp; ENDLOOP.
&nbsp; &nbsp; CLEAR lv_sum.
&nbsp; ENDIF.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" SPLIT_OPERATION
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;DATE_CALCULATION
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
\* &nbsp;--> &nbsp;p1 &nbsp; &nbsp; &nbsp; &nbsp;text
\* &nbsp;<-\- &nbsp;p2 &nbsp; &nbsp; &nbsp; &nbsp;text
\*----------------------------------------------------------------------\*
FORM date_calculation .
&nbsp; IF p_pdate = 'X'.
&nbsp; &nbsp; lv_dudat = lv_invref_docdate.
&nbsp; ENDIF.
&nbsp; IF p_ddate = 'X'.
&nbsp; &nbsp; IF i_data-bline_date IS NOT INITIAL.
&nbsp; &nbsp; &nbsp; i_date-shkzg = i_data-db_cr_ind.
&nbsp; &nbsp; &nbsp; i_date-koart = 'D'.
&nbsp; &nbsp; &nbsp; i_date-zfbdt = i_data-bline_date.
&nbsp; &nbsp; &nbsp; i_date-zbd1t = i_data-dsct_days1.
&nbsp; &nbsp; &nbsp; i_date-zbd2t = i_data-dsct_days2.
&nbsp; &nbsp; &nbsp; i_date-zbd3t = i_data-netterms.
&nbsp; &nbsp; &nbsp; i_date-rebzg = i_data-inv_ref.
&nbsp; &nbsp; &nbsp; APPEND i_date.
&nbsp; &nbsp; ELSE.
&nbsp; &nbsp; &nbsp; i_date-shkzg = i_data-db_cr_ind.
&nbsp; &nbsp; &nbsp; i_date-koart = 'D'.
&nbsp; &nbsp; &nbsp; i_date-zfbdt = i_data-pstng_date.
&nbsp; &nbsp; &nbsp; i_date-zbd1t = i_data-dsct_days1.
&nbsp; &nbsp; &nbsp; i_date-zbd2t = i_data-dsct_days2.
&nbsp; &nbsp; &nbsp; i_date-zbd3t = i_data-netterms.
&nbsp; &nbsp; &nbsp; i_date-rebzg = i_data-inv_ref.
&nbsp; &nbsp; &nbsp; APPEND i_date.
&nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; CALL FUNCTION 'DETERMINE_DUE_DATE'
&nbsp; &nbsp; &nbsp; EXPORTING
&nbsp; &nbsp; &nbsp; &nbsp; i_faede = i_date
&nbsp; &nbsp; &nbsp; IMPORTING
&nbsp; &nbsp; &nbsp; &nbsp; e_faede = i_date.
&nbsp; &nbsp; lv_dudat = i_date-netdt.
&nbsp; ENDIF.
&nbsp; lv_ovdat = p_date.
&nbsp; CALL FUNCTION 'HR_SGPBS_YRS_MTHS_DAYS'
&nbsp; &nbsp; EXPORTING
&nbsp; &nbsp; &nbsp; beg_da &nbsp; &nbsp; = lv_dudat
&nbsp; &nbsp; &nbsp; end_da &nbsp; &nbsp; = lv_ovdat
&nbsp; &nbsp; IMPORTING
&nbsp; &nbsp; &nbsp; no_cal_day = lv_day.
&nbsp; lv_days = lv_day.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" DATE_CALCULATION
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;DAYS_CONCATENATION
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp;-->P_P_0 &nbsp;text
\* &nbsp; &nbsp; &nbsp;-->P_P_A &nbsp;text
\*----------------------------------------------------------------------\*
FORM days_concatenation &nbsp;USING &nbsp; &nbsp;p_p_0
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p_p_a.
&nbsp; IF p_p_0 <> 0.
&nbsp; &nbsp; p_p_0 = p_p_0 + 1.
&nbsp; ENDIF.
&nbsp; CONCATENATE p_p_0 '-' p_p_a INTO gv_days.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" DAYS_CONCATENATION
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;CHECKING
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
\* &nbsp;--> &nbsp;p1 &nbsp; &nbsp; &nbsp; &nbsp;text
\* &nbsp;<-\- &nbsp;p2 &nbsp; &nbsp; &nbsp; &nbsp;text
\*----------------------------------------------------------------------\*
FORM checking .
&nbsp; SELECT * FROM t001 INTO TABLE it_t001
&nbsp; &nbsp; WHERE bukrs IN s_bukrs.
&nbsp; LOOP AT it_t001.
&nbsp; &nbsp; AUTHORITY-CHECK OBJECT 'F_BKPF_BUK'
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ID 'BUKRS' FIELD it_t001-bukrs
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ID 'ACTVT' FIELD '03'.
&nbsp; &nbsp; IF sy-subrc <> 0.
&nbsp; &nbsp; &nbsp; MESSAGE
&nbsp; &nbsp; &nbsp; 'You do not have display authorisation for this company code'
&nbsp; &nbsp; &nbsp; TYPE 'E' .
&nbsp; &nbsp; ENDIF.
&nbsp; ENDLOOP.
&nbsp; IF p_a LE p_0 AND p_a IS NOT INITIAL.
&nbsp; &nbsp; MESSAGE e001(38) WITH 'Please Check The Entry - Age Block 1-2'.
&nbsp; ENDIF.
&nbsp; IF p_b LE p_a AND p_b IS NOT INITIAL.
&nbsp; &nbsp; MESSAGE e001(38) WITH 'Please Check The Entry - Age Block 2-3'.
&nbsp; ENDIF.
&nbsp; IF p_c LE p_b AND p_c IS NOT INITIAL.
&nbsp; &nbsp; MESSAGE e001(38) WITH 'Please Check The Entry - Age Block 3-4'.
&nbsp; ENDIF.
&nbsp; IF p_d LE p_c AND p_d IS NOT INITIAL.
&nbsp; &nbsp; MESSAGE e001(38) WITH 'Please Check The Entry - Age Block 4-5'.
&nbsp; ENDIF.
&nbsp; IF p_e LE p_d AND p_e IS NOT INITIAL.
&nbsp; &nbsp; MESSAGE e001(38) WITH 'Please Check The Entry - Age Block 5-6'.
&nbsp; ENDIF.
&nbsp; IF p_f LE p_e AND p_f IS NOT INITIAL.
&nbsp; &nbsp; MESSAGE e001(38) WITH 'Please Check The Entry - Age Block 6-7'.
&nbsp; ENDIF.
&nbsp; IF p_bdci = ' '.
&nbsp; &nbsp; p_ch = ' '.
&nbsp; ENDIF.
&nbsp; IF p_dc = ' ' AND p_reval <> ' '.
&nbsp; &nbsp; MESSAGE e001(38) WITH 'Revaluation only possible when' 'display is in Document Currency'.
&nbsp; ENDIF.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" CHECKING
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;E03_EVENTTAB_BUILD
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp;-->P_GT_EVENTS\[\] &nbsp;text
\*----------------------------------------------------------------------\*
FORM e03_eventtab_build USING e03_lt_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; = e03_lt_events.
&nbsp; READ TABLE e03_lt_events WITH KEY name = &nbsp;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 gc_formname_top_of_page TO ls_event-form.
&nbsp; &nbsp; APPEND ls_event TO e03_lt_events.
&nbsp; ENDIF.
&nbsp; ls_event-name = 'USER_COMMAND'.
&nbsp; ls_event-form = 'VAL'.
&nbsp; APPEND ls_event TO gt_events.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" E03_EVENTTAB_BUILD
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;E04_COMMENT_BUILD
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp;-->P_GT_LIST_TOP_OF_PAGE\[\] &nbsp;text
\*----------------------------------------------------------------------\*
FORM e04_comment_build &nbsp;USING e04_lt_top_of_page TYPE slis_t_listheader.
&nbsp; DATA: ls_line TYPE slis_listheader.
&nbsp; CLEAR ls_line.
&nbsp; ls_line-typ &nbsp;= 'H'.
&nbsp; ls_line-info = 'Customer Ageing Analysis'.
&nbsp; APPEND ls_line TO e04_lt_top_of_page.
&nbsp; CLEAR ls_line.
&nbsp; IF s_bukrs\[\] IS NOT INITIAL.
&nbsp; &nbsp; ls_line-typ &nbsp;= 'S'.
&nbsp; &nbsp; ls_line-key &nbsp;= ' '.
&nbsp; &nbsp; LOOP AT s_bukrs.
&nbsp; &nbsp; &nbsp; CONCATENATE 'Company Code: ' s_bukrs-low
&nbsp; &nbsp; &nbsp; &nbsp; INTO lv_top SEPARATED BY space.
&nbsp; &nbsp; &nbsp; IF s_bukrs-high IS NOT INITIAL.
&nbsp; &nbsp; &nbsp; &nbsp; CONCATENATE lv_top ' to ' s_bukrs-high INTO lv_top
&nbsp; &nbsp; &nbsp; &nbsp; SEPARATED BY space.
&nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp; IF s_bukrs-sign = 'E'.
&nbsp; &nbsp; &nbsp; &nbsp; CONCATENATE lv_top ' (Excluded) ' INTO lv_top
&nbsp; &nbsp; &nbsp; &nbsp; SEPARATED BY space.
&nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp; ls_line-info = lv_top.
&nbsp; &nbsp; &nbsp; APPEND ls_line TO e04_lt_top_of_page.
&nbsp; &nbsp; ENDLOOP.
&nbsp; &nbsp; CLEAR lv_top.
&nbsp; ENDIF.
&nbsp; IF s_busab IS NOT INITIAL.
&nbsp; &nbsp; ls_line-key &nbsp;= ' '.
&nbsp; &nbsp; CONCATENATE 'Accounting Clerk: ' s_busab-low ' to '
&nbsp; &nbsp; s_busab-high INTO lv_top SEPARATED BY space.
&nbsp; &nbsp; ls_line-info = lv_top.
&nbsp; &nbsp; APPEND ls_line TO e04_lt_top_of_page.
&nbsp; &nbsp; CLEAR lv_top.
&nbsp; ENDIF.
&nbsp; IF s_vbund IS NOT INITIAL.
&nbsp; &nbsp; ls_line-key &nbsp;= ' '.
&nbsp; &nbsp; CONCATENATE 'Trading Partner: ' s_vbund-low ' to ' s_vbund-high
&nbsp; &nbsp; &nbsp; INTO lv_top SEPARATED BY space.
&nbsp; &nbsp; ls_line-info = lv_top.
&nbsp; &nbsp; APPEND ls_line TO e04_lt_top_of_page.
&nbsp; &nbsp; CLEAR lv_top.
&nbsp; ENDIF.
&nbsp; IF s_kdgrp IS NOT INITIAL.
&nbsp; &nbsp; ls_line-key &nbsp;= ' '.
&nbsp; &nbsp; CONCATENATE 'Customer Group: ' s_kdgrp-low ' to '
&nbsp; &nbsp; s_kdgrp-high INTO lv_top SEPARATED BY space.
&nbsp; &nbsp; ls_line-info = lv_top.
&nbsp; &nbsp; APPEND ls_line TO e04_lt_top_of_page.
&nbsp; &nbsp; CLEAR lv_top.
&nbsp; ENDIF.
&nbsp; IF s_vkorg IS NOT INITIAL.
&nbsp; &nbsp; ls_line-key &nbsp;= ' '.
&nbsp; &nbsp; CONCATENATE 'Sales Organisation: ' s_vkorg-low ' to '
&nbsp; &nbsp; s_vkorg-high INTO lv_top SEPARATED BY space.
&nbsp; &nbsp; ls_line-info = lv_top.
&nbsp; &nbsp; APPEND ls_line TO e04_lt_top_of_page.
&nbsp; &nbsp; CLEAR lv_top.
&nbsp; ENDIF.
&nbsp; IF s_vtweg IS NOT INITIAL.
&nbsp; &nbsp; ls_line-key &nbsp;= ' '.
&nbsp; &nbsp; CONCATENATE 'Distribution Channel: ' s_vtweg-low ' to '
&nbsp; &nbsp; s_vtweg-high INTO lv_top SEPARATED BY space.
&nbsp; &nbsp; ls_line-info = lv_top.
&nbsp; &nbsp; APPEND ls_line TO e04_lt_top_of_page.
&nbsp; &nbsp; CLEAR lv_top.
&nbsp; ENDIF.
&nbsp; IF s_spart IS NOT INITIAL.
&nbsp; &nbsp; ls_line-key &nbsp;= ' '.
&nbsp; &nbsp; CONCATENATE 'Division: ' s_spart-low ' to '
&nbsp; &nbsp; s_spart-high INTO lv_top SEPARATED BY space.
&nbsp; &nbsp; ls_line-info = lv_top.
&nbsp; &nbsp; APPEND ls_line TO e04_lt_top_of_page.
&nbsp; &nbsp; CLEAR lv_top.
&nbsp; ENDIF.
&nbsp; IF s_bzirk IS NOT INITIAL.
&nbsp; &nbsp; ls_line-key &nbsp;= ' '.
&nbsp; &nbsp; CONCATENATE 'Sales District: ' s_bzirk-low ' to '
&nbsp; &nbsp; s_bzirk-high INTO lv_top SEPARATED BY space.
&nbsp; &nbsp; ls_line-info = lv_top.
&nbsp; &nbsp; APPEND ls_line TO e04_lt_top_of_page.
&nbsp; &nbsp; CLEAR lv_top.
&nbsp; ENDIF.
&nbsp; IF s_kunnr IS NOT INITIAL.
&nbsp; &nbsp; ls_line-key &nbsp;= ' '.
&nbsp; &nbsp; CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
&nbsp; &nbsp; &nbsp; EXPORTING
&nbsp; &nbsp; &nbsp; &nbsp; input &nbsp;= s_kunnr-low
&nbsp; &nbsp; &nbsp; IMPORTING
&nbsp; &nbsp; &nbsp; &nbsp; output = s_kunnr-low.
&nbsp; &nbsp; CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
&nbsp; &nbsp; &nbsp; EXPORTING
&nbsp; &nbsp; &nbsp; &nbsp; input &nbsp;= s_kunnr-high
&nbsp; &nbsp; &nbsp; IMPORTING
&nbsp; &nbsp; &nbsp; &nbsp; output = s_kunnr-high.
&nbsp; &nbsp; CONCATENATE 'Customer: &nbsp; ' s_kunnr-low ' &nbsp;to '
&nbsp; &nbsp; s_kunnr-high INTO lv_top SEPARATED BY space.
&nbsp; &nbsp; ls_line-info = lv_top.
&nbsp; &nbsp; APPEND ls_line TO e04_lt_top_of_page.
&nbsp; &nbsp; CLEAR lv_top.
&nbsp; ENDIF.
&nbsp; IF p_lc = 'X'.
&nbsp; &nbsp; ls_line-key &nbsp;= ' '.
&nbsp; &nbsp; lv_top = 'Display in Local Currency'.
&nbsp; &nbsp; ls_line-info = lv_top.
&nbsp; &nbsp; APPEND ls_line TO e04_lt_top_of_page.
&nbsp; &nbsp; CLEAR lv_top.
&nbsp; ENDIF.
&nbsp; IF p_dc = 'X'.
&nbsp; &nbsp; ls_line-key &nbsp;= ' '.
&nbsp; &nbsp; lv_top = 'Display in Document Currency'.
&nbsp; &nbsp; ls_line-info = lv_top.
&nbsp; &nbsp; APPEND ls_line TO e04_lt_top_of_page.
&nbsp; &nbsp; CLEAR lv_top.
&nbsp; ENDIF.
&nbsp; IF s_gsber IS NOT INITIAL.
&nbsp; &nbsp; ls_line-key &nbsp;= ' '.
&nbsp; &nbsp; CONCATENATE 'Business Area: ' s_gsber-low ' to '
&nbsp; &nbsp; s_gsber-high INTO lv_top SEPARATED BY space.
&nbsp; &nbsp; ls_line-info = lv_top.
&nbsp; &nbsp; APPEND ls_line TO e04_lt_top_of_page.
&nbsp; &nbsp; CLEAR lv_top.
&nbsp; ENDIF.
&nbsp; IF s_prctr IS NOT INITIAL.
&nbsp; &nbsp; ls_line-key &nbsp;= ' '.
&nbsp; &nbsp; LOOP AT s_prctr.
&nbsp; &nbsp; &nbsp; CONCATENATE 'Profit center: ' s_prctr-low INTO lv_top
&nbsp; &nbsp; &nbsp; SEPARATED BY space.
&nbsp; &nbsp; &nbsp; IF s_prctr-high IS NOT INITIAL.
&nbsp; &nbsp; &nbsp; &nbsp; CONCATENATE lv_top ' to ' s_prctr-high INTO lv_top
&nbsp; &nbsp; &nbsp; &nbsp; SEPARATED BY space.
&nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp; IF s_prctr-sign = 'E'.
&nbsp; &nbsp; &nbsp; &nbsp; CONCATENATE lv_top ' (Excluded)' INTO lv_top
&nbsp; &nbsp; &nbsp; &nbsp; SEPARATED BY space.
&nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp; ls_line-info = lv_top.
&nbsp; &nbsp; &nbsp; APPEND ls_line TO e04_lt_top_of_page.
&nbsp; &nbsp; ENDLOOP.
&nbsp; &nbsp; CLEAR lv_top.
&nbsp; ENDIF.
&nbsp; IF s_zzbdiv IS NOT INITIAL.
&nbsp; &nbsp; ls_line-key &nbsp;= ' '.
&nbsp; &nbsp; LOOP AT s_zzbdiv.
&nbsp; &nbsp; &nbsp; CONCATENATE 'Business Division: ' s_zzbdiv-low INTO lv_top
&nbsp; &nbsp; &nbsp; SEPARATED BY space.
&nbsp; &nbsp; &nbsp; IF s_zzbdiv-high IS NOT INITIAL.
&nbsp; &nbsp; &nbsp; &nbsp; CONCATENATE lv_top ' to ' s_zzbdiv-high INTO lv_top
&nbsp; &nbsp; &nbsp; &nbsp; SEPARATED BY space.
&nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp; IF s_zzbdiv-sign = 'E'.
&nbsp; &nbsp; &nbsp; &nbsp; CONCATENATE lv_top ' (Excluded)' INTO lv_top
&nbsp; &nbsp; &nbsp; &nbsp; SEPARATED BY space.
&nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp; ls_line-info = lv_top.
&nbsp; &nbsp; &nbsp; APPEND ls_line TO e04_lt_top_of_page.
&nbsp; &nbsp; ENDLOOP.
&nbsp; &nbsp; CLEAR lv_top.
&nbsp; ENDIF.
&nbsp; IF s_zztdiv IS NOT INITIAL.
&nbsp; &nbsp; ls_line-key &nbsp;= ' '.
&nbsp; &nbsp; LOOP AT s_zztdiv.
&nbsp; &nbsp; &nbsp; CONCATENATE 'Tax Division: ' s_zztdiv-low INTO lv_top
&nbsp; &nbsp; &nbsp; SEPARATED BY space.
&nbsp; &nbsp; &nbsp; IF s_zztdiv-high IS NOT INITIAL.
&nbsp; &nbsp; &nbsp; &nbsp; CONCATENATE lv_top ' to ' s_zztdiv-high INTO lv_top
&nbsp; &nbsp; &nbsp; &nbsp; SEPARATED BY space.
&nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp; IF s_zztdiv-sign = 'E'.
&nbsp; &nbsp; &nbsp; &nbsp; CONCATENATE lv_top ' (Excluded)' INTO lv_top
&nbsp; &nbsp; &nbsp; &nbsp; SEPARATED BY space.
&nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; &nbsp; &nbsp; ls_line-info = lv_top.
&nbsp; &nbsp; &nbsp; APPEND ls_line TO e04_lt_top_of_page.
&nbsp; &nbsp; ENDLOOP.
&nbsp; &nbsp; CLEAR lv_top.
&nbsp; ENDIF.
&nbsp; IF p_date IS NOT INITIAL.
&nbsp; &nbsp; ls_line-typ &nbsp;= 'A'.
&nbsp; &nbsp; ls_line-key &nbsp;= ' '.
&nbsp; &nbsp; CALL FUNCTION 'CONVERSION_EXIT_IDATE_OUTPUT'
&nbsp; &nbsp; &nbsp; EXPORTING
&nbsp; &nbsp; &nbsp; &nbsp; input &nbsp;= p_date
&nbsp; &nbsp; &nbsp; IMPORTING
&nbsp; &nbsp; &nbsp; &nbsp; output = lv_txt.
&nbsp; &nbsp; CONCATENATE 'Analysis Date: ' lv_txt INTO lv_top.
&nbsp; &nbsp; ls_line-info = lv_top.
&nbsp; &nbsp; APPEND ls_line TO e04_lt_top_of_page.
&nbsp; ENDIF.
&nbsp; CLEAR ls_line.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" E04_COMMENT_BUILD
\*&---------------------------------------------------------------------\*
\*& &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; &nbsp; &nbsp;EXPORTING
\* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i_logo &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 'HTMLCNTL_TESTHTM2_SAPLOGO'
\* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;i_logo &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 'ENJOYSAP_LOGO'
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; it_list_commentary = gt_list_top_of_page.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"TOP_OF_PAGE
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;VAL
\*&---------------------------------------------------------------------\*
FORM val USING user_command LIKE sy-ucomm sel TYPE slis_selfield.
&nbsp; DATA: lv_docno(10).
&nbsp; IF p_detail = 'X'.
&nbsp; &nbsp; READ TABLE i_age INDEX sel-tabindex.
&nbsp; &nbsp; SET PARAMETER ID 'BLN' FIELD i_age-doc_no.
&nbsp; &nbsp; SET PARAMETER ID 'BUK' FIELD i_age-bukrs.
&nbsp; &nbsp; SET PARAMETER ID 'GJR' FIELD i_age-fisc_year.
&nbsp; &nbsp; CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.
&nbsp; ENDIF.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "val
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;DATA_CONDENSE
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp;-->P_WA_AGEING_KUNNR &nbsp;text
\*----------------------------------------------------------------------\*
FORM data_condense &nbsp;USING &nbsp; &nbsp;p_data.
&nbsp; CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
&nbsp; &nbsp; EXPORTING
&nbsp; &nbsp; &nbsp; input &nbsp;= p_data
&nbsp; &nbsp; IMPORTING
&nbsp; &nbsp; &nbsp; output = p_data.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" DATA_CONDENSE
\*&---------------------------------------------------------------------\*
\*& &nbsp; &nbsp; &nbsp;Form &nbsp;FOREX_REVAL
\*&---------------------------------------------------------------------\*
\* &nbsp; &nbsp; &nbsp; text
\*----------------------------------------------------------------------\*
\* &nbsp;--> &nbsp;p1 &nbsp; &nbsp; &nbsp; &nbsp;text
\* &nbsp;<-\- &nbsp;p2 &nbsp; &nbsp; &nbsp; &nbsp;text
\*----------------------------------------------------------------------\*
FORM forex_reval .
&nbsp; DATA: wa_rate TYPE bapi1093_0,
&nbsp; &nbsp; &nbsp; &nbsp; wa_ret TYPE bapiret1.
&nbsp; IF i_ageing-currency <> it_t001-waers.
&nbsp; &nbsp; CALL FUNCTION 'BAPI_EXCHANGERATE_GETDETAIL'
&nbsp; &nbsp; &nbsp; EXPORTING
&nbsp; &nbsp; &nbsp; &nbsp; rate_type &nbsp;= 'C'
&nbsp; &nbsp; &nbsp; &nbsp; from_curr &nbsp;= i_ageing-currency
&nbsp; &nbsp; &nbsp; &nbsp; to_currncy = it_t001-waers
&nbsp; &nbsp; &nbsp; &nbsp; date &nbsp; &nbsp; &nbsp; = p_date
&nbsp; &nbsp; &nbsp; IMPORTING
&nbsp; &nbsp; &nbsp; &nbsp; exch_rate &nbsp;= wa_rate
&nbsp; &nbsp; &nbsp; &nbsp; return &nbsp; &nbsp; = wa_ret.
&nbsp; &nbsp; IF wa_ret IS NOT INITIAL.
&nbsp; &nbsp; &nbsp; MESSAGE e000(38) WITH wa_ret-message.
&nbsp; &nbsp; ELSE.
&nbsp; &nbsp; &nbsp; i_ageing-lv_reval = ( i_ageing-lc_amount / wa_rate-from_factor * wa_rate-to_factor ) * wa_rate-exch_rate.
&nbsp; &nbsp; &nbsp; i_ageing-lv_exrate = wa_rate-exch_rate.
&nbsp; &nbsp; ENDIF.
&nbsp; ELSE.
&nbsp; &nbsp; i_ageing-lv_reval = i_ageing-lc_amount.
&nbsp; &nbsp; i_ageing-lv_exrate = '1'.
&nbsp; ENDIF.
&nbsp; i_ageing-lv_exdif = i_ageing-lv_reval - i_ageing-lc_fixamt.
ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" FOREX_REVAL
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
TABLES sscrfields.
TYPES : BEGIN OF struct1 ,
        cust_no TYPE kna1-kunnr ,
        cust_name TYPE kna1-name1,
        cust_addr TYPE kna1-adrnr ,
        order_no TYPE vbak-bstnk ,
        order_date TYPE vbak-erdat ,
        vbeln  TYPE vbak-vbeln,
        END OF struct1.
TYPES : BEGIN OF struct2 ,
        order_no LIKE vbak-bstnk ,
        mat_no LIKE vbap-matnr ,
        mat_dscr LIKE vbap-arktx ,
        order_qn LIKE vbap-kwmeng,
        END OF struct2.
DATA : itab1 TYPE TABLE OF struct1 WITH HEADER LINE,
*       wa TYPE struct1,
       itab2 TYPE TABLE OF struct2 WITH HEADER LINE,
       i TYPE i.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001 NO INTERVALS.
PARAMETERS : p_custno TYPE kna1-kunnr DEFAULT '1175' OBLIGATORY,
             p_c_code TYPE vbak-bukrs_vf DEFAULT '1000' OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN PUSHBUTTON /10(20) charly USER-COMMAND abcd.

INITIALIZATION.
  MOVE 'Get List' TO charly.

AT SELECTION-SCREEN.
*at user-command.
  IF sscrfields-ucomm = 'ABCD'.
    LEAVE TO LIST-PROCESSING.
*write 'hi'.
  ENDIF.
  SELECT a~kunnr a~name1 a~adrnr b~bstnk b~erdat b~vbeln
               INTO TABLE
               itab1
               FROM
               kna1 AS a INNER JOIN vbak AS b
               ON
               a~kunnr = b~kunnr
               WHERE
               a~kunnr = p_custno
               AND
               b~bukrs_vf = p_c_code.
  LOOP AT itab1.
    WRITE :/5 itab1-cust_no ,   24
              itab1-cust_name , 45
              itab1-cust_addr , 62
              itab1-order_no ,  85
              itab1-order_date.
  ENDLOOP.

TOP-OF-PAGE DURING LINE-SELECTION.
  WRITE : 4 'Order No' , 18 'Material No' , 34 'Material Description' , 60 'Order Quantity '.
  ULINE.
*end-of-page.
*write 'sy-pagno'.
AT LINE-SELECTION.
  WINDOW : STARTING AT 10 10
          ENDING AT 100 20.
  i = sy-lilli.
  READ TABLE itab1 INDEX i.
  SELECT c~bstnk d~matnr d~arktx d~kwmeng
               INTO TABLE itab2
               FROM
               vbak AS c INNER JOIN vbap AS d
               ON
               c~vbeln = d~vbeln
    WHERE d~vbeln = itab1-vbeln.
  LOOP AT itab2.
    WRITE :/2
       itab2-order_no ,   20
       itab2-mat_no ,     35
       itab2-mat_dscr ,   52
       itab2-order_qn .
  ENDLOOP.
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
REPORT  ztl_customer_material NO STANDARD PAGE HEADING LINE-SIZE 500
                                      MESSAGE-ID zrtl.

*------------------------------------------------------------------------
*     Include Programs
*------------------------------------------------------------------------

*Data Declarations and Selection screen Details
INCLUDE ztl_sdc005p_cust_material_top.

*Include for Selection Screen
INCLUDE ztl_sdc005p_cust_material_sel.

*Program logic and Subroutines
INCLUDE ztl_sdc005p_cust_material_sub.

INITIALIZATION.

AT SELECTION-SCREEN OUTPUT.
  IF rd_csv = 'X'.
    v_ffilter =  '.|*.CSV'.

  ELSEIF rd_xls = 'X'.
    v_ffilter =  '.|*.XLS'.
  ENDIF.

  CLEAR  p_fname.
  IF p_fname IS NOT INITIAL.
    MESSAGE i036.
  ENDIF.

AT SELECTION-SCREEN.
  IF p_fname IS NOT INITIAL.
    PERFORM validate_file USING p_fname.
  ENDIF.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.
* get f4 help for filename & Get the input file
  PERFORM get_input_file.

*------------------------------------------------------------------------
* Start-of-selection
*------------------------------------------------------------------------

START-OF-SELECTION.

* check for existence in Presentation Server
  PERFORM check_fname USING p_fname.

*NEW*
* upload data from presentation server into internal table
  PERFORM create_upload_presentation USING p_fname.

  IF p_creat = c_yes.
    v_flag1 = 1.
* check for the tcode VD51
    v_tcode = c_vd51.
** Get data.
    PERFORM get_data.
    MOVE 1 TO v_recno.
    LOOP AT t_custom INTO wa_custom .

      READ TABLE t_knmt INTO wa_knmt WITH TABLE KEY kunnr = wa_custom-kunnr
                                                     vkorg = wa_custom-vkorg
                                                     vtweg = wa_custom-vtweg
                                                     matnr = wa_custom-matnr.
      IF sy-subrc NE 0.
* BDC Operations
        PERFORM create_bdcoperations.

      ELSE.
        v_msg = text-066.

        MOVE : v_recno TO wa_errortab-slno,
               wa_custom-kunnr TO wa_errortab-kunnr,
               wa_custom-vkorg TO wa_errortab-vkorg,
               wa_custom-matnr TO wa_errortab-matnr,
               v_msg TO wa_errortab-message.
        APPEND wa_errortab TO t_gerror.
        CLEAR: wa_errortab.

      ENDIF.
      v_recno = v_recno + 1.
    ENDLOOP.
    CLEAR v_recno.

  ELSEIF p_chang = c_yes.
* check for the tcode VD52
    v_tcode = c_vd52.
** Get data.
    PERFORM get_data.
    MOVE 1 TO v_recno.
    LOOP AT t_custom INTO wa_custom .
      READ TABLE t_knmt INTO wa_knmt WITH TABLE KEY kunnr = wa_custom-kunnr
                                                    vkorg = wa_custom-vkorg
                                                    vtweg = wa_custom-vtweg
                                                    matnr = wa_custom-matnr.
      IF sy-subrc EQ 0.
* BDC Operations
        PERFORM change_bdcoperations.
      ELSE.
        v_msg = text-070.

        MOVE : v_recno TO wa_errortab-slno,
               wa_custom-kunnr TO wa_errortab-kunnr,
               wa_custom-vkorg TO wa_errortab-vkorg,
               wa_custom-matnr TO wa_errortab-matnr,
               v_msg TO wa_errortab-message.
        APPEND wa_errortab TO t_gerror.
        CLEAR: wa_errortab.

      ENDIF.
      v_recno = v_recno + 1.
    ENDLOOP.
    CLEAR v_recno.

  ENDIF.

END-OF-SELECTION.

* Error Log
  IF t_gerror IS NOT INITIAL.

    TRY.
        CALL METHOD cl_salv_table=>factory
          IMPORTING
            r_salv_table = v_o_gr_alv
          CHANGING
            t_table      = t_gerror.
      CATCH cx_salv_msg.                                "#EC NO_HANDLER
    ENDTRY.
*  Bulid fieldcat
    PERFORM alv_fieldcat.

    v_gr_display->set_list_header( text-067 ).
    v_o_gr_alv->display( ).
  ENDIF.

*Free internal tables.
  PERFORM free_internal.

*Text elements
*----------------------------------------------------------
* 002 Customer-Material Data
* 015 Customer Material Info Record conversion
* 041 Serial no
* 042 Customer number
* 043 Sales Organization
* 045 Material Number
* 061 Message
* 064 Customer-Material Information was saved
* 066 Customer-Material Information Already Exists
* 067 Customer-Material Information Record upload
* 070 Customer  with sales org. distribution chan. 01 is not defined
* H03 File Type

*Selection texts
*----------------------------------------------------------
* P_BACK         Background
* P_CHANG         Change Customer
* P_CREAT         Create Customer
* P_FNAME D       .
* P_FORE         Foreground
* RD_CSV         CSV File
* RD_XLS         Excel File

*Messages
*----------------------------------------------------------
*
* Message class: ZRTL
*002   Error in Application
*004   File does not exist
*012   Error in uploading data from excel file
*036   Select File to Load
*038   Select the XLS file for &
*039   Select the CSV file for &
*059   Error in the function module
*--------------------------------------------------------------------*

Author: Pablo Casamayor
Submitted: 28.06.2008

The aim of this tutorial is to help in providing a solution when we want to display customer fields in logistics invoice verification transactions.


Figure 1 (customer fields in MIR7 transaction)

The requirement was to display additional fields in logistics invoice verification transactions.

The original idea was to use exit LMR1M001 but reading the documentation of EXIT_SAPLMR1M_003 I found out that:

As of Release 4.6A, transaction MR1M is no longer supported. Therefore this customer exit and its functions are obsolete.

Besides this I had to do the development in two different systems (SAP ERP Central Component 5.0 and SAP ECC 6.0).

So I gave up the exit and concentrated my efforts in finding an alternative.

For this I found badi BADI_FDCB_SUBBAS01

The documentation of this badi is:

Subscreen enhancement in function group FDCB, basic data screen 010 for vendors, 510 for customers.

These screens are accessed in the Enjoy transactions for FI document entry or MM invoice receipt. In FI, for example, these are the transactions FB60, FB65, FB70, FB75 or for parking, FV60, FV65, FV70, FV75.

In MM, screen 010 is accessed for example in transaction MIRO.

Screen fields: The fields must be in structure INVFO.

If the values in the FI document are to be saved, the fields must also be in table BKPF or BSEG. If the values in the MM document are to be saved, the fields must be in the structure ACMM_VENDOR_COMP, the view RBKP, and table RBKP.

My case was the one referring to MM.

First I tried to implement BADI_FDCB_SUBBAS01 but there was an implementation already running (FI_FDCB_SUBBAS01_EX).

Then I tried with the following one BADI_FDCB_SUBBAS02 but there was an implementation already running (FI_FDCB_SUBBAS02_EX).

Next I tried with BADI_FDCB_SUBBAS03 but there was an implementation already running (WRF_BADI_FDCB_BAS).

The only badi left then was BADI_FDCB_SUBBAS04.

Just having a look at the example implementation class CL_EXM_IM_BADI_FDCB_SUBBAS01 of badi BADI_FDCB_SUBBAS01 i found out that there were two methods available:

PUT_DATA_TO_SCREEN_OBJECT

GET_DATA_FROM_SCREEN_OBJECT

And within them I needed to add the following:

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
method IF_EX_BADI_FDCB_SUBBAS01~PUT_DATA_TO_SCREEN_OBJECT .
* fill interface attributes from importing paramters
  me->if_ex_badi_fdcb_subbas01~invfo  = im_invfo.
endmethod.

method IF_EX_BADI_FDCB_SUBBAS01~GET_DATA_FROM_SCREEN_OBJECT .
* fill export parameters from interface attributes
  ex_invfo  = me->if_ex_badi_fdcb_subbas01~invfo.
endmethod.

I just substituted subbas01 by subbas04.

Then based on tab subscreen of implementation FI_FDCB_SUBBAS01_EX i had to create dynpro 100 as well.

For this dynpro the flow logic was:

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
PROCESS BEFORE OUTPUT.
* MODULE STATUS_0100.
  MODULE receive_data.
*

PROCESS AFTER INPUT.
* get again actual data from main screen
  MODULE receive_actual_data.
*
* implement from here on customer coding
* enumerate ALL fields on the screen because of field transportation
* with or within a module
  FIELD:
   invfo-lotkz.
* send data back to main screen
  MODULE USER_COMMAND_0100.

*----------------------------------------------------------------------*
***INCLUDE LBADI_EXAMPLE_FDCB_BASO01 .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  receive_data OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE receive_data OUTPUT.
  IF o_badi_fdcb_subbas01 IS INITIAL.
    CALL METHOD cl_exithandler=>get_instance_for_subscreens
      CHANGING
        instance                      = o_badi_fdcb_subbas01
      EXCEPTIONS
        no_reference                  = 1
        no_interface_reference        = 2
        no_exit_interface             = 3
        data_incons_in_exit_managem   = 4
        class_not_implement_interface = 5
        OTHERS                        = 6.
    IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
  ENDIF.
* object created  ?
  CHECK NOT o_badi_fdcb_subbas01 IS INITIAL.
* get data from main screen

  CALL METHOD o_badi_fdcb_subbas01->get_data_from_screen_object
    IMPORTING
      ex_invfo = invfo.
ENDMODULE.                 " receive_data  OUTPUT


*----------------------------------------------------------------------*
***INCLUDE LBADI_EXAMPLE_FDCB_BASI01 .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  receive_actual_data  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module receive_actual_data input.
*  object created  ?
  CHECK NOT o_badi_fdcb_subbas01 IS INITIAL.
* get data from main screen

  CALL METHOD o_badi_fdcb_subbas01->get_data_from_screen_object
    IMPORTING
      ex_invfo  = invfo.
endmodule.                 " receive_actual_data  INPUT


*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module USER_COMMAND_0100 input.
 CHECK NOT o_badi_fdcb_subbas01 IS INITIAL.
* put data to main screen

  CALL METHOD o_badi_fdcb_subbas01->put_data_to_screen_object
    EXPORTING
      im_invfo  = invfo.
endmodule.                 " USER_COMMAND_0100  INPUT


and so I did for my implementation (instead of subbas01 I used subbas04).

In my case only MM invoice receipt was going to be affected.

So I created my customer fields in append structures of:

INVFO, RBKP, RBKP_V, ACMM_VENDOR_COMP.



Figure 2 (append structure to structure INVFO)



Figure 3 (append structure to table RBKP)



Figure 4 (append structure to view RBKP_V)



Figure 5 (append structure to structure ACMM_VENDOR_COMP)

From here on you can display additional fields in logistics invoice verification transactions. Just add the new fields in the screen and code the corresponding logic.

Tips: the following transactions will be affected  

'FB60'

'FB65'

'FB70'

'FB75'

'FV60'

'FV65'

'FV70'

'FV75'

'FV63'

'MIRO'

'MR8M'

'MIRA'

'MIR7'

'MIR4'

You´ll need to add what´s necessary to prevent the new custom fields from appearing in unwanted transactions.

This is an simple interactive report program for retrieving some customer details. It would be definitely helpful for the Starters.

*************************************************************************
**** Program to display Customer Details, Bill Header, Bill item ********
****             Details using Interactive Report                ********
*************************************************************************

REPORT  zsan_intrep_pr3.

TABLES: kna1, vbak, vbap, makt.

DATA: BEGIN OF x_kna1,
      kunnr TYPE kna1-kunnr,
      name1 TYPE kna1-name1,
      ort01 TYPE kna1-ort01,
      land1 TYPE kna1-land1,
      END OF x_kna1.

DATA: BEGIN OF x_vbak,
      kunnr TYPE vbak-kunnr,
      vbeln TYPE vbak-vbeln,
      erdat TYPE vbak-erdat,
      netwr TYPE vbak-netwr,
      waerk TYPE vbak-waerk,
      END OF x_vbak.

DATA: BEGIN OF x_vbap,
      vbeln TYPE vbap-vbeln,
      matnr TYPE vbap-matnr,
      netwr TYPE vbap-netwr,
      waerk TYPE vbap-waerk,
      END OF x_vbap.

DATA: BEGIN OF x_makt,
      matnr TYPE makt-matnr,
      maktx TYPE makt-maktx,
      END OF x_makt.

DATA: t_kna1 LIKE x_kna1 OCCURS 0 WITH HEADER LINE,
      t_vbak LIKE x_vbak OCCURS 0,
      t_vbap LIKE x_vbap OCCURS 0,
      t_makt LIKE x_makt OCCURS 0.

DATA: w_kna1 LIKE x_kna1,
      w_vbak LIKE x_vbak,
      w_vbap LIKE x_vbap,
      w_makt LIKE x_makt.

START-OF-SELECTION.


  SELECT kunnr name1 ort01 land1 FROM kna1 INTO TABLE t_kna1.

  SORT t_kna1 ASCENDING BY kunnr.

  LOOP AT t_kna1 INTO w_kna1.
    WRITE: / w_kna1-kunnr HOTSPOT, w_kna1-name1, w_kna1-ort01, w_kna1-land1.
    HIDE w_kna1-kunnr.
  ENDLOOP.


AT LINE-SELECTION.

  CASE sy-lsind.

    WHEN 1.

*WINDOW STARTING AT 10 10.

      SELECT kunnr vbeln erdat netwr waerk FROM vbak INTO TABLE t_vbak WHERE kunnr = w_kna1-kunnr.
      LOOP AT t_vbak INTO w_vbak.
        WRITE: /  w_vbak-vbeln HOTSPOT, w_vbak-erdat, w_vbak-netwr, w_vbak-waerk.
        HIDE w_vbak-vbeln.
      ENDLOOP.

    WHEN 2.

      SELECT vbeln matnr netwr waerk FROM vbap INTO TABLE t_vbap WHERE vbeln = w_vbak-vbeln.

*WINDOW STARTING AT 10 10.

      LOOP AT t_vbap INTO w_vbap.
        WRITE:/ w_vbap-matnr HOTSPOT, w_vbap-netwr, w_vbap-waerk.
        HIDE w_vbap-matnr.
      ENDLOOP.


    WHEN 3.

      SELECT matnr maktx FROM makt INTO TABLE t_makt WHERE matnr = w_vbap-matnr.

      WINDOW STARTING AT 10 10.

      LOOP AT t_makt INTO w_makt.
        WRITE:/ w_makt-maktx.
      ENDLOOP.

  ENDCASE.
 

Related Links:

Description

With this tutorial it is possible to create contact persons with the BAPI BAPI_ADDRCONTPART_SAVEREPLICA for customers.
The example is for customers only.

One of the main problems is that the created contactperson with the BAPI BAPI_ADDRCONTPART_SAVEREPLICA didn't become available in Tcode XD02
this was due to the problem that the table KNVK was not updated trough this BAPI

other problem was that with function  SD_CUSTOMER_MAINTAIN_ALL not all necessary contact information could be managed like email adress.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
DATA: st_sender TYPE bapi_sender.
DATA: gs_kna1 TYPE kna1.
DATA: h_kunnr TYPE kunnr.
DATA: gt_knvk TYPE STANDARD TABLE OF fknvk.
DATA: gs_knvk TYPE fknvk.
DATA: new_contactid TYPE bapicontact_01-contact.
DATA: new_contactid_create TYPE bapi4003_1-objkey_p.
DATA: gt_bapiad3vl TYPE STANDARD TABLE OF bapiad3vl.
DATA: gs_bapiad3vl TYPE bapiad3vl.
DATA: gt_bapiadsmtp TYPE STANDARD TABLE OF bapiadsmtp.
DATA: gs_bapiadsmtp TYPE bapiadsmtp.
DATA: gt_bapiadtel TYPE STANDARD TABLE OF bapiadtel.
DATA: gs_bapiadtel TYPE bapiadtel.

DATA: objid_cust LIKE bapi4002_1-objkey.
DATA: gs_return TYPE bapiret2.
DATA: gt_return TYPE STANDARD TABLE OF bapiret2.
DATA: gs_commit_return TYPE bapiret2.
DATA: gs_addr_no TYPE bapi4003_1-addr_no.
DATA: gs_pers_no TYPE bapi4003_1-pers_no.

h_kunnr = '1100'.             "example customer code
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  EXPORTING
    input  = h_kunnr
  IMPORTING
    output = h_kunnr.

SELECT SINGLE * FROM kna1
INTO gs_kna1
WHERE kunnr EQ h_kunnr.
gs_knvk-kunnr = h_kunnr.
gs_knvk-name1 = 'lastname'.         "lastname
gs_knvk-namev = 'firstname'.        "firstname
gs_knvk-ernam = sy-uname.
gs_knvk-erdat = sy-datum.
APPEND gs_knvk TO gt_knvk.

lastname en firstname must be the same as passed to the BAPI!
 otherwise the data of KNVK will overwrite the data entered by the BAPI
 this can be tested by entering different fpor knvk and the bapi
 if xd03 is started and double click on the contact you see the bapi details
 if xd02 is started and double click on the contact the lastname and firstname of the knvk overwrite the addres  data of the bapi
 other data entered with the bapi like email telephone and roomnumber maintain the values written with the BAPI

get the key for the next contact person

Instead of using BAPI_PARTNEREMPLOYEE_GETINTNUM to retrieve the next number for the parnr
 I use the function  'SD_CUSTOMER_MAINTAIN_ALL' to retrieve the next number
 so the connection with KNVK is already established

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
CALL FUNCTION 'SD_CUSTOMER_MAINTAIN_ALL'
  EXPORTING
    i_kna1                     = gs_kna1
    i_maintain_address_by_kna1 = ' '
    pi_postflag                = 'X'
  TABLES
    t_xknvk                    = gt_knvk
  EXCEPTIONS
    client_error               = 1
    kna1_incomplete            = 2
    knb1_incomplete            = 3
    knb5_incomplete            = 4
    knvv_incomplete            = 5
    kunnr_not_unique           = 6
    sales_area_not_unique      = 7
    sales_area_not_valid       = 8
    insert_update_conflict     = 9
    number_assignment_error    = 10
    number_not_in_range        = 11
    number_range_not_extern    = 12
    number_range_not_intern    = 13
    account_group_not_valid    = 14
    parnr_invalid              = 15
    bank_address_invalid       = 16
    tax_data_not_valid         = 17
    no_authority               = 18
    company_code_not_unique    = 19
    dunning_data_not_valid     = 20
    knb1_reference_invalid     = 21
    cam_error                  = 22
    OTHERS                     = 23.


READ TABLE gt_knvk INDEX 1 INTO gs_knvk.
new_contactid_create = gs_knvk-parnr.
objid_cust = h_kunnr.

*common data
*lastname en firstname must be the same as passed to KNVK!
gs_bapiad3vl-lastname = 'lastname'.       "lastname
gs_bapiad3vl-firstname = 'firstname'.     "firstname
gs_bapiad3vl-pers_group = 'BP'.
gs_bapiad3vl-room_no_p = 'roomnumber'.
APPEND gs_bapiad3vl TO gt_bapiad3vl.

* email
gs_bapiadsmtp-e_mail = 'youre@email.adres'.       "email
APPEND gs_bapiadsmtp TO gt_bapiadsmtp.

* telephone nr
gs_bapiadtel-telephone = '020-11'.        "telephone
gs_bapiadtel-extension = '55111'.       "telephone
APPEND gs_bapiadtel TO gt_bapiadtel.

CALL FUNCTION 'BAPI_ADDRCONTPART_SAVEREPLICA'
  EXPORTING
    obj_type_p       = 'BUS1006001'
    obj_id_p         = new_contactid_create
    obj_type_c       = 'KNA1'
    obj_id_c         = objid_cust
    context          = '0005'
    iv_check_address = 'X'
    importingreturn  = gs_return
    address_number   = gs_addr_no
    person_number    = gs_pers_no
  TABLES
    bapiad3vl        = gt_bapiad3vl
    bapiadtel        = gt_bapiadtel
    bapiadsmtp       = gt_bapiadsmtp.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
  EXPORTING
    wait   = 'X'
  IMPORTING
    return = gs_commit_return.

instead of the bapi 'BAPI_ADDRCONTPART_SAVEREPLICA' also the bapi BAPI_ADDRESSCONTPART_CHANGE can be used.

DATA fm_name TYPE rs38l_fnam.
TABLES: vbak,
        vbrk,
        vbfa.
*---------------------------------------------------------------------*
*SELECTION SCREEN*
*---------------------------------------------------------------------
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
*select-options: S_vbeln for vbrk-vbeln.
PARAMETERS: p_vbeln TYPE vbrk-vbeln OBLIGATORY.
*select-options: p_audat for VBAK-audat.
PARAMETERS: p_audat TYPE vbak-audat OBLIGATORY.
*obligatory.
SELECTION-SCREEN END OF BLOCK b1.
***---------------------------------------------------------------------
DATA: BEGIN OF it_data1 OCCURS 0,
  vbeln TYPE vbak-vbeln,
  posnr TYPE vbap-posnr,
  audat TYPE vbak-audat,
  auart TYPE vbak-auart,
  kunnr TYPE vbak-kunnr,
  matnr TYPE vbap-matnr,
  arktx TYPE vbap-arktx,
  kwmeng TYPE vbap-kwmeng,
  netwr TYPE vbak-netwr,
END OF it_data1.
******
******
*data:it_struct type standard table of struct.
*data:wa_It like line of it_struct .
*DATA:it_struct TYPE standard TABLE OF struct ,wa like line of it_struct
*.
***start-of-selection.
***select a~vbeln b~posnr a~audat a~auart a~kunnr b~matnr b~kwmeng
**b~netwr
***from vbak as a inner join vbap as b on a~vbeln = b~vbeln into
***corresponding fields of table itab
*** where
***a~vbeln eq vbeln.
*
DATA: itab TYPE  STANDARD TABLE OF vbak WITH HEADER LINE.
DATA: itab1 TYPE STANDARD TABLE OF vbap.
DATA: itab2 TYPE STANDARD TABLE OF vbpa.
DATA: wa_itab1 LIKE LINE OF itab1.
DATA: wa_itab2 LIKE LINE OF itab2.
DATA: itab3 TYPE  STANDARD TABLE OF adrc WITH HEADER LINE.
DATA: itab4 TYPE  STANDARD TABLE OF adrc WITH HEADER LINE.
*start-of-selection.
DATA: sum TYPE i.
sum = 0.
DATA: customer TYPE char10,
      consignee TYPE char10.

SELECT vbeln audat kunnr netwr
  FROM vbak INTO CORRESPONDING FIELDS OF TABLE itab
  WHERE vbeln EQ p_vbeln AND audat EQ p_audat.
SELECT vbeln arktx kwmeng posnr netwr
  FROM vbap INTO CORRESPONDING FIELDS OF TABLE itab1
  FOR ALL ENTRIES IN itab
  WHERE vbeln = itab-vbeln .
******************************************************
*SELECT KUNAG KUNRG VBELN
*FROM VBRK INTO CORRESPONDING FIELDS OF TABLE ITAB2
*WHERE VBELN eq p_VBELN .
SELECT vbeln posnr kunnr adrnr parvw FROM vbpa
  INTO CORRESPONDING FIELDS OF TABLE itab2
  FOR ALL ENTRIES IN itab
  WHERE vbeln = itab-vbeln AND kunnr = itab-kunnr.
LOOP AT itab2 INTO wa_itab2.
  IF wa_itab2-parvw = 'AG'.
    MOVE: wa_itab2-adrnr TO customer.
  ELSEIF
  wa_itab2-parvw = 'RG'.
    MOVE:wa_itab2-adrnr TO consignee.
  ENDIF.
ENDLOOP.
SELECT addrnumber name1 city1 city2 street country tel_number fax_number
  FROM adrc
  INTO CORRESPONDING FIELDS OF TABLE itab3 WHERE addrnumber EQ customer.
SELECT addrnumber name1 city1 city2 street country tel_number fax_number
  FROM adrc
  INTO CORRESPONDING FIELDS OF TABLE itab4 WHERE addrnumber EQ consignee.
******************************************************
LOOP AT itab1 INTO wa_itab1 .
  sum = sum + wa_itab1-netwr.
  MOVE : wa_itab1-vbeln TO it_data1-vbeln,
  wa_itab1-arktx TO it_data1-arktx,
*****           itab1-arktx TO it_data1-arktx,
             wa_itab1-kwmeng TO it_data1-kwmeng,
             wa_itab1-netwr TO it_data1-netwr,
             wa_itab1-posnr TO it_data1-posnr.
  APPEND it_data1.
*condense it_data1-kwmeng .
ENDLOOP.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
  EXPORTING
    formname           = 'Z_INV_SMARTFORM1'
  IMPORTING
    fm_name            = fm_name
  EXCEPTIONS
    no_form            = 1
    no_function_module = 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.
CALL FUNCTION fm_name
  EXPORTING
    sum      = sum
  TABLES
    itab     = itab
    itab3    = itab3
    itab4    = itab4
    it_data1 = it_data1.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
 

ALE Audit

ALE AUDIT is the technique of using IDocs communication. The purpose of ALE Audit is to check the cross-system IDoc flow and posting in the partner system.

Features:

1. ALE Audit provides an automatic and seamless tracing facility for individual documents in distributed applications.
2. Documents that have been sent from one application to another can also be traced from start to finish.    
3. Another feature of ALE Audit is that the processing status of a document can be queried from a central point.          

ALE Audit is a statistics database for IDocs that is maintained on the sending system.

ALE Audit enables the sender system to monitor the processing status of dispatched IDocs in the receiver system. The receiver system periodically sends confirmations back to the sender system, which are logged in IDoc status records and in individual audit tables.

Status records generated from the confirmations contain the following values:
 •       39 - IDocs in receiver system (ALE Service) and still being processed.
 •       40 - Application document processing not completed successfully in receiver system.
 •       41 - Application document processed in the receiver system. Processing completed independently of the processing status in the receiver system. The message in the status record is the same as the corresponding message in the IDoc status record in the receiver system.

Dispatch of Audit confirmations

For performance reasons confirmations are dispatched periodically for a packet of IDocs rather than for each one. Confirmations have a special IDoc ALEAUD01 with message type ALEAUD.
Confirmations can only be dispatched if a message flow for the message type ALEAUD has been maintained in the distribution model (BD64).

ALE Audit IDocs

The Audit IDoc ALEAUD01 contains three segments: E1ADHDR, ESTATE and E1PRTOB.

One IDoc contains a maximum of 500 IDocs confirmations. The segments comprise the following:
•       Segment E1ADHDR
 E1ADHDR contains message type, variants and function for the ensuing confirmations. Each confirmation comprises exactly one segment E1STATE and one segment E1PRTOB.
•       Segment E1STATE
 E1STATE contains the IDoc number of the sender system (Field DOCNUM), the current status in the receiver system and the message fields from the current status record.
•       Segment E1PRTOB
 E1PRTOB contains the receiver's IDoc number and, if existing, the application object generated in inbound processing.

Scenario:

Here we are taking the scenario for message type DEBMAS (Customer Master).

Here we need to transfer the customer master data from the outbound system to inbound system and audit confirmations for the DEBMAS.

ALE Audit requirement for DEBMAS

Procedure

These below steps are for the ALE Audit confirmations for the message type DEBMAS.

Sender logical system is ECICLNT800 and

Receiver logical system is ECICLNT080.

Note: for the ALEAUD configuration, we must have the regular ALE configurations...i.e.

1.     Define logical systems - BD54,
2.     Assigning logical systems to clients - SCC4
3.     Create RFC destination - SM59
4.     Port definition - WE21
5.     Create Partner profiles - WE20

All the above configuration has to be done both sides, i.e. the sender system and the receiver system.
After the above steps, we need to follow the below steps.

6.     Creation of Distribution Model - Transaction BD64
a.     Create Distribution model (in the outbound system) for message type DEBMAS
                      I.        Generate Partner profiles: Environment ->Generate Partner Profiles
                    II.        Distribute the Distribution model: EDIT->Model view Distribute

b.    Create Distribution model (in the inbound system) for message type ALEAUD

                      I.        Generate Partner profiles: Environment ->Generate Partner Profiles
                    II.        Distribute the Distribution model: EDIT->Model view Distribute

For Audit confirmations, we need to maintain the message type ALEAUD in the distribution model view of inbound system. So for that we need to create the model view in the inbound system.
Example: Here the Screen shot from T.Code: BD64, Distribution model ALEAUD1 created in the inbound system. For audit confirmation we need to add a message type 'ALEAUD'.

ALEAUD working Process:
Once all the above configurations are complete, we need to send an IDoc of DEBMAS type.

We can use Standalone application from SAP for this...

Go to T.Code: BD12 transaction and enter a valid customer number and enter the message type (DEBMAS) and logical system (ECICLNT080).
 

Dispatch of Audit confirmations:

The RBDSTATE report we need to execute at the receiver system (ECICLNT 080) that means in the inbound system.
The RBDSTATE report dispatches the audit confirmations. This Report can also use from the BALE transaction by selecting Periodic processing -> Schedule audit

This report generates IDocs from the message type ALEAUD containing information about the processing state of inbound IDocs in your own system.
Go to SE38 and enter the report name and pass the parameters                      
The selection screen parameters of this report allows you to regulate the in which system and which application message type that confirmation should be generated in the current report run.

1. Confirmations to system: The system which we need to send the information (here outbound system ECICLNT800)
2. Message type - message type audit confirmations should be made - DEBMAS
3. Date IDoc changed - IDoc creation date

Above three parameters are mandatory.

Message code - optional and Message function - optional

And execute. We see the generated ALEAUD IDoc:

Using this IDoc number, we can analyze the details about the application data and as well as the outbound system details that is control record data, status record  and data record for which message type IDoc is generated. Using the application data field (in table EDID4) we can know that for which message type IDoc is generated.


 

                                                                      or

Using this document number go to WE02, give this document number (here 000000000020054) and execute and we can find the IDoc number for the DEBMAS (here is the DEBMAS) for the inbound system (080).

 


Go to BD87 and give the IDoc number and execute the transaction

 

Using this document number go to outbound system and go to WE02 and enter DEBMAS as message type  and execute and we can find the IDoc number for the DEBMAS (here is the DEBMAS) for the outbound system (client 800).  

And go to BD87 and give the IDoc number (0000000000870818 or 0000000000870819) and execute  

and click on trace IDocs, there we can find the ALE message status.

So like this ALEAUD sends the confirmation to the outbound system (Sender system).

This is the process for the Audit confirmation for DEBMAS (Customer Master).

Conclusions: With the above example explains on how the ALE Audit requirements can be used in projects. This can be a reference document for all such requirements of Audit acknowledgements in ALE environment.

REPORT zbdctest
       NO STANDARD PAGE HEADING LINE-SIZE 255.

INCLUDE bdcrecx1.

PARAMETERS: dataset(132) LOWER CASE.
***    DO NOT CHANGE - the generated data section - DO NOT CHANGE    ***
*
*   If it is nessesary to change the data section use the rules:
*   1.) Each definition of a field exists of two lines
*   2.) The first line shows exactly the comment
*       '* data element: ' followed with the data element
*       which describes the field.
*       If you don't have a data element use the
*       comment without a data element name
*   3.) The second line shows the fieldname of the
*       structure, the fieldname must consist of
*       a fieldname and optional the character '_' and
*       three numbers and the field length in brackets
*   4.) Each field must be type C.
*
*** Generated data section with specific formatting - DO NOT CHANGE  ***
DATA: BEGIN OF record,
* data element: VBELN_VA
        vbeln_001(030),
* data element: BSTDK
        bstdk_002(010),
* data element: RB_AAUART
        rb_auart_003(001),
* data element: KETDAT
        ketdat_004(010),
* data element: KPRGBZ
        kprgbz_005(001),
* data element: PRSDT
        prsdt_006(010),
* data element: DZTERM
        zterm_007(004),
* data element: INCO1
        inco1_008(003),
* data element: INCO2
        inco2_009(028),
* data element: KWMENG
        kwmeng_010(019),
* data element: BSTDK
        bstdk_011(010),
* data element: RB_AAUART
        rb_auart_012(001),
* data element: KETDAT
        ketdat_013(010),
* data element: KPRGBZ
        kprgbz_014(001),
* data element: PRSDT
        prsdt_015(010),
* data element: DZTERM
        zterm_016(004),
* data element: INCO1
        inco1_017(003),
* data element: INCO2
        inco2_018(028),
* data element: AUDAT
        audat_019(010),
* data element: WAERK
        waerk_020(005),
* data element: PRSDT
        prsdt_021(010),
* data element: KONDA
        konda_022(002),
* data element: BSTDK
        bstdk_023(010),
* data element: RB_AAUART
        rb_auart_024(001),
* data element: KETDAT
        ketdat_025(010),
* data element: KPRGBZ
        kprgbz_026(001),
* data element: PRSDT
        prsdt_027(010),
* data element: DZTERM
        zterm_028(004),
* data element: INCO1
        inco1_029(003),
* data element: INCO2
        inco2_030(028),
      END OF record.

*** End generated data section ***

START-OF-SELECTION.

  PERFORM open_dataset USING dataset.
  PERFORM open_group.

  DO.

    READ DATASET dataset INTO record.
    IF sy-subrc <> 0. EXIT. ENDIF.

    PERFORM bdc_dynpro      USING 'SAPMV45A' '0102'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'VBAK-VBELN'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '/00'.
    PERFORM bdc_field       USING 'VBAK-VBELN'
                                  record-vbeln_001.
    PERFORM bdc_dynpro      USING 'SAPMV45A' '4001'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=ITEM'.
    PERFORM bdc_field       USING 'VBKD-BSTDK'
                                  record-bstdk_002.
    PERFORM bdc_field       USING 'RV45A-RB_AUART'
                                  record-rb_auart_003.
    PERFORM bdc_field       USING 'RV45A-KETDAT'
                                  record-ketdat_004.
    PERFORM bdc_field       USING 'RV45A-KPRGBZ'
                                  record-kprgbz_005.
    PERFORM bdc_field       USING 'VBKD-PRSDT'
                                  record-prsdt_006.
    PERFORM bdc_field       USING 'VBKD-ZTERM'
                                  record-zterm_007.
    PERFORM bdc_field       USING 'VBKD-INCO1'
                                  record-inco1_008.
    PERFORM bdc_field       USING 'VBKD-INCO2'
                                  record-inco2_009.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'VBAP-POSNR(01)'.
    PERFORM bdc_dynpro      USING 'SAPMV45A' '4003'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '/EBACK'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'RV45A-KWMENG'.
    PERFORM bdc_field       USING 'RV45A-KWMENG'
                                  record-kwmeng_010.
    PERFORM bdc_dynpro      USING 'SAPMV45A' '4001'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=ITEM'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'VBAK-VBELN'.
    PERFORM bdc_field       USING 'VBKD-BSTDK'
                                  record-bstdk_011.
    PERFORM bdc_field       USING 'RV45A-RB_AUART'
                                  record-rb_auart_012.
    PERFORM bdc_field       USING 'RV45A-KETDAT'
                                  record-ketdat_013.
    PERFORM bdc_field       USING 'RV45A-KPRGBZ'
                                  record-kprgbz_014.
    PERFORM bdc_field       USING 'VBKD-PRSDT'
                                  record-prsdt_015.
    PERFORM bdc_field       USING 'VBKD-ZTERM'
                                  record-zterm_016.
    PERFORM bdc_field       USING 'VBKD-INCO1'
                                  record-inco1_017.
    PERFORM bdc_field       USING 'VBKD-INCO2'
                                  record-inco2_018.
    PERFORM bdc_dynpro      USING 'SAPMV45A' '4002'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '/EBACK'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'VBAK-AUDAT'.
    PERFORM bdc_field       USING 'VBAK-AUDAT'
                                  record-audat_019.
    PERFORM bdc_field       USING 'VBAK-WAERK'
                                  record-waerk_020.
    PERFORM bdc_field       USING 'VBKD-PRSDT'
                                  record-prsdt_021.
    PERFORM bdc_field       USING 'VBKD-KONDA'
                                  record-konda_022.
    PERFORM bdc_dynpro      USING 'SAPMV45A' '4001'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=SICH'.
    PERFORM bdc_field       USING 'VBKD-BSTDK'
                                  record-bstdk_023.
    PERFORM bdc_field       USING 'RV45A-RB_AUART'
                                  record-rb_auart_024.
    PERFORM bdc_field       USING 'RV45A-KETDAT'
                                  record-ketdat_025.
    PERFORM bdc_field       USING 'RV45A-KPRGBZ'
                                  record-kprgbz_026.
    PERFORM bdc_field       USING 'VBKD-PRSDT'
                                  record-prsdt_027.
    PERFORM bdc_field       USING 'VBKD-ZTERM'
                                  record-zterm_028.
    PERFORM bdc_field       USING 'VBKD-INCO1'
                                  record-inco1_029.
    PERFORM bdc_field       USING 'VBKD-INCO2'
                                  record-inco2_030.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'RV45A-MABNR(02)'.
    PERFORM bdc_transaction USING 'VA02'.

  ENDDO.

  PERFORM close_group.
  PERFORM close_dataset USING dataset.
**********************

***INCLUDE BDCRECX1.
*  for programs doing a data transfer by creating a batch-input session
*  and
*  for programs doing a data transfer by CALL TRANSACTION USING

  SELECTION-SCREEN BEGIN OF LINE.
  PARAMETERS session RADIOBUTTON GROUP ctu.  "create session
  SELECTION-SCREEN COMMENT 3(20) text-s07 FOR FIELD session.
  SELECTION-SCREEN POSITION 45.
  PARAMETERS ctu RADIOBUTTON GROUP  ctu.     "call transaction
  SELECTION-SCREEN COMMENT 48(20) text-s08 FOR FIELD ctu.
  SELECTION-SCREEN END OF LINE.

  SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT 3(20) text-s01 FOR FIELD group.
  SELECTION-SCREEN POSITION 25.
  PARAMETERS group(12).                      "group name of session
  SELECTION-SCREEN COMMENT 48(20) text-s05 FOR FIELD ctumode.
  SELECTION-SCREEN POSITION 70.
  PARAMETERS ctumode LIKE ctu_params-dismode DEFAULT 'N'.
  "A: show all dynpros
  "E: show dynpro on error only
  "N: do not display dynpro
  SELECTION-SCREEN END OF LINE.

  SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT 3(20) text-s02 FOR FIELD user.
  SELECTION-SCREEN POSITION 25.
  PARAMETERS: user(12) DEFAULT sy-uname.     "user for session in batch
  SELECTION-SCREEN COMMENT 48(20) text-s06 FOR FIELD cupdate.
  SELECTION-SCREEN POSITION 70.
  PARAMETERS cupdate LIKE ctu_params-updmode DEFAULT 'L'.
  "S: synchronously
  "A: asynchronously
  "L: local
  SELECTION-SCREEN END OF LINE.

  SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT 3(20) text-s03 FOR FIELD keep.
  SELECTION-SCREEN POSITION 25.
  PARAMETERS: keep AS CHECKBOX.       "' ' = delete session if finished
  "'X' = keep   session if finished
  SELECTION-SCREEN COMMENT 48(20) text-s09 FOR FIELD e_group.
  SELECTION-SCREEN POSITION 70.
  PARAMETERS e_group(12).             "group name of error-session
  SELECTION-SCREEN END OF LINE.

  SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT 3(20) text-s04 FOR FIELD holddate.
  SELECTION-SCREEN POSITION 25.
  PARAMETERS: holddate LIKE sy-datum.
  SELECTION-SCREEN COMMENT 51(17) text-s02 FOR FIELD e_user.
  SELECTION-SCREEN POSITION 70.
  PARAMETERS: e_user(12) DEFAULT sy-uname.    "user for error-session
  SELECTION-SCREEN END OF LINE.

  SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT 51(17) text-s03 FOR FIELD e_keep.
  SELECTION-SCREEN POSITION 70.
  PARAMETERS: e_keep AS CHECKBOX.     "' ' = delete session if finished
  "'X' = keep   session if finished
  SELECTION-SCREEN END OF LINE.

  SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT 51(17) text-s04 FOR FIELD e_hdate.
  SELECTION-SCREEN POSITION 70.
  PARAMETERS: e_hdate LIKE sy-datum.
  SELECTION-SCREEN END OF LINE.

  SELECTION-SCREEN SKIP.

  SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT 1(33) text-s10 FOR FIELD nodata.
  PARAMETERS: nodata DEFAULT '/' LOWER CASE.          "nodata
  SELECTION-SCREEN END OF LINE.

  SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT 1(33) FOR FIELD smalllog.
  PARAMETERS: smalllog AS CHECKBOX.  "' ' = log all transactions
  "'X' = no transaction logging
  SELECTION-SCREEN END OF LINE.

*----------------------------------------------------------------------*
*   data definition
*----------------------------------------------------------------------*
*       Batchinputdata of single transaction
  DATA:   bdcdata LIKE bdcdata    OCCURS 0 WITH HEADER LINE.
*       messages of call transaction
  DATA:   messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
*       error session opened (' ' or 'X')
  DATA:   e_group_opened.
*       message texts
  TABLES: t100.


*----------------------------------------------------------------------*
*   at selection screen                                                *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
* group and user must be filled for create session
  IF session = 'X' AND
     group = space OR user = space.
    MESSAGE e613(ms).
  ENDIF.

*----------------------------------------------------------------------*
*   open dataset                                                       *
*----------------------------------------------------------------------*
FORM open_dataset USING p_dataset.
  OPEN DATASET p_dataset
               FOR INPUT IN TEXT MODE
               ENCODING DEFAULT.
  IF sy-subrc <> 0.
    WRITE: / text-e00, sy-subrc.
    STOP.
  ENDIF.
ENDFORM.                    "open_dataset
*----------------------------------------------------------------------*
*   close dataset                                                      *
*----------------------------------------------------------------------*
FORM close_dataset USING p_dataset.
  CLOSE DATASET p_dataset.
ENDFORM.                    "close_dataset
*----------------------------------------------------------------------*
*   create batchinput session                                          *
*   (not for call transaction using...)                                *
*----------------------------------------------------------------------*
FORM open_group.
  IF session = 'X'.
    SKIP.
    WRITE: /(20) 'Create group'(i01), group.
    SKIP.
*   open batchinput group
    CALL FUNCTION 'BDC_OPEN_GROUP'
      EXPORTING
        client   = sy-mandt
        group    = group
        user     = user
        keep     = keep
        holddate = holddate.
    WRITE: /(30) 'BDC_OPEN_GROUP'(i02),
            (12) 'returncode:'(i05),
                 sy-subrc.
  ENDIF.
ENDFORM.                    "open_group
*----------------------------------------------------------------------*
*   end batchinput session                                             *
*   (call transaction using...: error session)                         *
*----------------------------------------------------------------------*
FORM close_group.
  IF session = 'X'.
*   close batchinput group
    CALL FUNCTION 'BDC_CLOSE_GROUP'.
    WRITE: /(30) 'BDC_CLOSE_GROUP'(i04),
            (12) 'returncode:'(i05),
                 sy-subrc.
  ELSE.
    IF e_group_opened = 'X'.
      CALL FUNCTION 'BDC_CLOSE_GROUP'.
      WRITE: /.
      WRITE: /(30) 'Fehlermappe wurde erzeugt'(i06).
      e_group_opened = ' '.
    ENDIF.
  ENDIF.
ENDFORM.                    "close_group
*----------------------------------------------------------------------*
*        Start new transaction according to parameters                 *
*----------------------------------------------------------------------*
FORM bdc_transaction USING tcode.
  DATA: l_mstring(480).
  DATA: l_subrc LIKE sy-subrc.
* batch input session
  IF session = 'X'.
    CALL FUNCTION 'BDC_INSERT'
      EXPORTING
        tcode     = tcode
      TABLES
        dynprotab = bdcdata.
    IF smalllog <> 'X'.
      WRITE: / 'BDC_INSERT'(i03),
               tcode,
               'returncode:'(i05),
               sy-subrc,
               'RECORD:',
               sy-index.
    ENDIF.
* call transaction using
  ELSE.
    REFRESH messtab.
    CALL TRANSACTION tcode USING bdcdata
                     MODE   ctumode
                     UPDATE cupdate
                     MESSAGES INTO messtab.
    l_subrc = sy-subrc.
    IF smalllog <> 'X'.
      WRITE: / 'CALL_TRANSACTION',
               tcode,
               'returncode:'(i05),
               l_subrc,
               'RECORD:',
               sy-index.
      LOOP AT messtab.
        SELECT SINGLE * FROM t100 WHERE sprsl = messtab-msgspra
                                  AND   arbgb = messtab-msgid
                                  AND   msgnr = messtab-msgnr.
        IF sy-subrc = 0.
          l_mstring = t100-text.
          IF l_mstring CS '&1'.
            REPLACE '&1' WITH messtab-msgv1 INTO l_mstring.
            REPLACE '&2' WITH messtab-msgv2 INTO l_mstring.
            REPLACE '&3' WITH messtab-msgv3 INTO l_mstring.
            REPLACE '&4' WITH messtab-msgv4 INTO l_mstring.
          ELSE.
            REPLACE '&' WITH messtab-msgv1 INTO l_mstring.
            REPLACE '&' WITH messtab-msgv2 INTO l_mstring.
            REPLACE '&' WITH messtab-msgv3 INTO l_mstring.
            REPLACE '&' WITH messtab-msgv4 INTO l_mstring.
          ENDIF.
          CONDENSE l_mstring.
          WRITE: / messtab-msgtyp, l_mstring(250).
        ELSE.
          WRITE: / messtab.
        ENDIF.
      ENDLOOP.
      SKIP.
    ENDIF.
** Erzeugen fehlermappe ************************************************
    IF l_subrc <> 0 AND e_group <> space.
      IF e_group_opened = ' '.
        CALL FUNCTION 'BDC_OPEN_GROUP'
          EXPORTING
            client   = sy-mandt
            group    = e_group
            user     = e_user
            keep     = e_keep
            holddate = e_hdate.
        e_group_opened = 'X'.
      ENDIF.
      CALL FUNCTION 'BDC_INSERT'
        EXPORTING
          tcode     = tcode
        TABLES
          dynprotab = bdcdata.
    ENDIF.
  ENDIF.
  REFRESH bdcdata.
ENDFORM.                    "bdc_transaction
*----------------------------------------------------------------------*
*        Start new screen                                              *
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
  CLEAR bdcdata.
  bdcdata-program  = program.
  bdcdata-dynpro   = dynpro.
  bdcdata-dynbegin = 'X'.
  APPEND bdcdata.
ENDFORM.                    "bdc_dynpro
*----------------------------------------------------------------------*
*        Insert field                                                  *
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
  IF fval <> nodata.
    CLEAR bdcdata.
    bdcdata-fnam = fnam.
    bdcdata-fval = fval.
    APPEND bdcdata.
  ENDIF.
ENDFORM.                    "bdc_field
 


  • No labels