SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Open Contracts Creation using ME31K



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ММ
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Thu Nov 08, 2007 5:28 pm    Post subject: Open Contracts Creation using ME31K Reply with quote

Author: Kiran Kumar Somaroutu

Description
This code is useful in Creating Open Contracts based on the information provided in the flat file. This code is special in a way that it uses complex logic instead of using AT NEW functionality. It deals with three levels of table controls, i.e. A table control within a table control and within it one more table control are to be dealt with. This was dealt with pure logic and not using AT <commands>.

Code:
/* REPORT ZMCG047CONTR NO STANDARD PAGE HEADING
                               LINE-SIZE 255
                               MESSAGE-ID ZM.
*
*&---------------------------------------------------------------------
*&       Table declarations
*&---------------------------------------------------------------------
*
TABLES : T001W,     "Plants/Branches
         T024E,     "Purchasing Organizations
         T001.      "Company Codes
*
*----------------------------------------------------------------------*
*              TYPE-POOLS  DECLARATION
*----------------------------------------------------------------------*
*
TYPE-POOLS : SLIS.
*
*----------------------------------------------------------------------
*                       Types  Declaration                            *
*----------------------------------------------------------------------
*
TYPES: BEGIN OF T_RECORD,    "record storing contract info
        LIFNR(010),      "Vendor Number
        EVART(004),      "Agreement Type
        EKORG(004),      "Purchasing Organization
        EKGRP(003),      "Purchasing Group
        WERKS(004),      "Plant
        LGORT(004),      "Storage Location
        KDATB(010),      "Valid start Date
        KDATE(010),      "Valid End Date
        ZTERM(004),      "Payment Terms
        KTWRT(020),      "Target Value
        EPSTP(001),      "Item Category
        EMATN(018),      "Material Number
        KTMNG(017),      "Target Quantity
        NETPR(014),      "Net Price
        PEINH(006),      "Net Price Unit
        BPRME(003),      "Net Price Order Price Unit
        IDNLF(035),      "Vendor Material number
        WEBRE(001),      "GR Based-IV
        MEPRF(001),      "Pricing Date Category
        LTEX1(040),      "Info Text
        DATAB(010),      "Valid From
        DATBI(010),      "Valid To
        KSCHL(004),      "Condition Type
        KBETR(016),      "Condition Rate if scale is not given
        KONWA(005),      "Currency
        KPEIN(005),      "Condition Pricing Unit
        KMEIN(003),      "Condition Unit of Measure
        KSTBM(019),      "Scale
        KBETR_01(016),   "Scale Rate
        DEL_FLAG,        "Delete Flag Indicator
        ERR_MSG(100),    "Error Message
      END OF T_RECORD,
*
      BEGIN OF T_ERR_RECORD,   "to have error records stored
         LIFNR(010),      "Vendor Number
         EVART(004),      "Agreement Type
         EKORG(004),      "Purchasing Organization
         EKGRP(003),      "Purchasing Group
         WERKS(004),      "Plant
         LGORT(004),      "Storage Location
         KDATB(010),      "Valid start Date
         KDATE(010),      "Valid End Date
         ZTERM(004),      "Payment Terms
         KTWRT(020),      "Target Value
         EPSTP(001),      "Item Category
         EMATN(018),      "Material Number
         KTMNG(017),      "Target Quantity
         NETPR(014),      "Net Price
         PEINH(006),      "Net Price Unit
         BPRME(003),      "Net Price Order Price Unit
         IDNLF(035),      "Vendor Material number
         WEBRE(001),      "GR Based-IV
         MEPRF(001),      "Pricing Date Category
         LTEX1(040),      "Info Text
         DATAB(010),      "Valid From
         DATBI(010),      "Valid To
         KSCHL(004),      "Condition Type
         KBETR(016),      "Condition Rate if scale is not given
         KONWA(005),      "Currency
         KPEIN(005),      "Condition Pricing Unit
         KMEIN(003),      "Condition Unit of Measure
         KSTBM(019),      "Scale
         KBETR_01(016),   "Scale Rate
         DEL_FLAG,        "Delete Flag Indicator
         ERR_MSG(100),    "Error Message
      END OF T_ERR_RECORD,
*
      BEGIN OF T_LOEKZ,    "To have deletion indicators for materials
          LOEKZ(001),    "Deletion indicator in purchasing document
          EMATN(018),    "Material Number
          WERKS(004),    "Plant
          LGORT(004),    "Storage Location
          BSTYP(001),    "Purchasing document category
      END OF T_LOEKZ,
*
      BEGIN OF T_MATNR,  " Type definition to store details of materials
           MATNR(018),    "Material Number
      END OF T_MATNR,
*
      BEGIN OF T_T001,   " Type definition for company codes
          BUKRS(004),    " Company Code
      END OF T_T001,
*
      BEGIN OF T_ZMVXREF,   "Cross-Reference table type
          D_ALTKN(10),      "Legacy Vendor Number
          D_BUKRS(4),       "Legacy Company Code
          M_ALTKN(10),      "SAP Company Code
      END OF T_ZMVXREF,
*
      BEGIN OF T_LFA1,    "Master data of vendors
          LIFNR(10),      "Vendor Number
      END OF T_LFA1,
*
*  Type Declaration for T024E (Company Codes)
       BEGIN OF T_T024E,
         EKORG   LIKE   T024E-EKORG, "Purchasing organization
         BUKRS   LIKE   T024E-BUKRS, "Company Code
       END OF T_T024E,
*
*  Type Declaration for t001w (Plant)
       BEGIN OF T_T001W,
         WERKS  LIKE  T001W-WERKS,        "Plant
       END OF T_T001W,
*
*  Type Declatation for String Line
       BEGIN OF T_STR1,                                     "#EC NEEDED
         SLINE(6000) TYPE C,
       END OF T_STR1.
*
TYPES:  BEGIN OF T_BDCDATA.  "BDC Data
        INCLUDE STRUCTURE BDCDATA.
TYPES:  END OF T_BDCDATA.
*
*----------------------------------------------------------------------
*       Internal Tables  Declaration                                  *
*----------------------------------------------------------------------
*
DATA:
*      Internal table to store input file data
       I_RECORD TYPE STANDARD TABLE OF T_RECORD INITIAL SIZE 0,
*      Internal table to capture errors
       I_ERR_REC TYPE STANDARD TABLE OF T_ERR_RECORD INITIAL SIZE 0,
*      Internal table to check for deletion indicators
       I_LOEKZ TYPE STANDARD TABLE OF T_LOEKZ INITIAL SIZE 0,
*      Internal table to check for material numbers
       I_MATNR TYPE STANDARD TABLE OF T_MATNR INITIAL SIZE 0,
*      Internal table used for storing Cross-Reference data of Vendor
       I_ZMVXREF TYPE STANDARD TABLE OF T_ZMVXREF INITIAL SIZE 0,
*      Internal table for holding Vendor Numbers from Master table
       I_LFA1 TYPE STANDARD TABLE OF T_LFA1 INITIAL SIZE 0,
*      Internal table for holding Purchase Org and Company Codes
       I_T024E TYPE STANDARD TABLE OF T_T024E INITIAL SIZE 0,
*      Internal table for holding Plants
       I_T001W TYPE STANDARD TABLE OF T_T001W INITIAL SIZE 0,
*      Internal table for storing a list of Company Codes
       I_T001 TYPE STANDARD TABLE OF T_T001 INITIAL SIZE 0,
*      Internal table used for ALV Reporting
       I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
*      Internal table used for holding List Header
       I_LISTHEADER TYPE SLIS_T_LISTHEADER,    "EC NEEDED
*      Internal table to hold ALV Event
       I_ALV_EVENT TYPE SLIS_T_EVENT,
*      Internal table to hold Sort Info for ALV Report
       I_SORT TYPE SLIS_T_SORTINFO_ALV,
*      Internal table for BDC Data
       I_BDCDATA TYPE STANDARD TABLE OF T_BDCDATA INITIAL SIZE 0,
*      Internal table for messages
       I_MESSTAB TYPE TABLE OF BDCMSGCOLL,
*      Internal table for String line
       I_STR1 TYPE STANDARD TABLE OF T_STR1 INITIAL SIZE 0.
*
*----------------------------------------------------------------------
*       Work Area Declaration                                         *
*----------------------------------------------------------------------
*
DATA:
*  Work Area to hold data for the Open Contract
      WA_RECORD TYPE T_RECORD,
*  Work Area to hold previous record data
      WA_RECORDPREV TYPE T_RECORD,
*  Work Area to hold errors
      WA_ERR_REC TYPE T_ERR_RECORD,
*  Work Area to hold the Deletion Indicator of materials
      WA_LOEKZ TYPE T_LOEKZ,
*  Work Area to hold Material numbers of required materials
      WA_MATNR TYPE T_MATNR,      "EC NEEDED
*  Work Area to hold errors occured while performing BDC
      WA_MESSTAB TYPE BDCMSGCOLL,
*  Work Area to hold field catalog for ALV Reports
      WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
*  Work Area to hold list header data for ALV reports
      WA_LISTHEADER TYPE SLIS_LISTHEADER,
*  Work Area to hold ALV Event
      WA_ALV_EVENT LIKE LINE OF I_ALV_EVENT,  "EC NEEDED
*  Work Area to hold Layout of ALV Report
      WA_LAYOUT TYPE SLIS_LAYOUT_ALV,
*  Work Area to hold Cross-Reference data of Vendor
      WA_ZMVXREF TYPE T_ZMVXREF,
*  Work Area to hold Vendor Numbers from Master table
      WA_LFA1 TYPE T_LFA1,    "EC NEEDED
*  Work Area to hold Purchase Org and Company Codes
      WA_T024E TYPE T_T024E,
*  Work Area to hold Company Codes
      WA_T001 TYPE T_T001,
*  Work Area to hold Plants
      WA_T001W TYPE T_T001W,
*  Work Area to hold Sort Info for ALV Report
      WA_SORT TYPE SLIS_SORTINFO_ALV,
*  Work Area to hold BDC Data
      WA_BDCDATA TYPE T_BDCDATA,
*  Work Area for String line
      WA_STR1 TYPE T_STR1.
*
*----------------------------------------------------------------------
*       Variables  Declaration                                        *
*----------------------------------------------------------------------
*
DATA: V_ERRMSG(500),           "To temporarily store the error message
      V_CONV_DATE(10) TYPE C,  "To capture the converted date format
      V_DATE LIKE SY-DATUM,
      V_REPID LIKE SY-REPID,   "holds report id
      V_CROSS_REFERENCE_ERROR TYPE I,  " cross-reference error
      V_INPUTERROR_FLAG VALUE '',      " input error status
      V_FILENAME TYPE STRING,          " File Name
      VEN_FLAG(1),                       " at new status
      MAT_FLAG(1),                      " at new status
      V_IND(2) TYPE N,                 " index of table control
      V_IND2(2) TYPE N,                " index of table control
      V_IND3(2) TYPE N,                " index of table control
      V_EVRTP1(20),
      V_EPSTP1(20),
      V_EMATN1(20),
      V_KTMNG1(20),
      V_NETPR1(20),
      V_PEINH1(20),
      V_BPRME1(20),
      V_TCSELFLAG1(20),
      V_KSCHL2(20),
      V_KBETR2(20),
      V_KONWA2(20),
      V_KPEIN2(20),
      V_KMEIN2(20),
      V_SELKZ2(20),
      V_KBETR3(20),
      V_KSTBM3(20),
      V_LINE TYPE I,
      V_STR TYPE X VALUE '09',
      V_EXIST TYPE C,
      V_EXIST1 TYPE C,
      V_ISDIR TYPE C,
      V_ISDIR1 TYPE C.
*
*----------------------------------------------------------------------
*       Constants  Declaration                                        *
*----------------------------------------------------------------------
*
CONSTANTS: C_TCODE(5) VALUE 'ME31K', "Trx code - Open Contract Creation
           C_TRUE     VALUE 'X',       " Del_Flag indicator
           C_LOEKZ_MARKED VALUE 'X',   "Deletion indicator for material
           C_INPUTERROR_FLAG_YES VALUE 'X',  "Input File Indicator
           C_VEN_ERR1 VALUE 1,    "Error Indicator
           C_16(2)    VALUE '16',
           C_VEN_ERR2 VALUE 2,    "Error Indicator
           C_VEN_ERR3 VALUE 3,    "Error Indicator
           C_VEN_SUCS VALUE 0,    "Success Indicator
           C_SUCCESS  LIKE SY-SUBRC VALUE '0',
           C_STRUE    VALUE 'S',  "Del_flag for SAP Errors
           C_YTRUE    VALUE 'Y',  "Del_flag for Success Records
           C_MSGTYP_E VALUE 'E',  "holds error message type
           C_MSGTYP_S VALUE 'S',  "holds success message type
           C_BSTYP    VALUE 'K',  "Purchasing Document type is Contract
           C_BACKGROUND VALUE 'N', "Background mode
           C_FOREGROUND VALUE 'A', "All Screen mode
           C_ERRORS   VALUE 'E',   "Error screen mode
           C_WK(2)    VALUE 'WK'. "Value Contract
*
*----------------------------------------------------------------------
*        Selection Screen                                             *
*----------------------------------------------------------------------
*
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-033.
*
SELECTION-SCREEN SKIP.
*
SELECT-OPTIONS:
*              Plant
               S_WERKS FOR T001W-WERKS OBLIGATORY,
*              Purchase Organization
               S_EKORG FOR T024E-EKORG OBLIGATORY.
*              Company Code
PARAMETER      P_BUKRS LIKE T001-BUKRS OBLIGATORY.
*
SELECTION-SCREEN SKIP.
SELECTION-SCREEN ULINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN POSITION 3.
PARAMETER RB_SERVE RADIOBUTTON GROUP RBX DEFAULT 'X' USER-COMMAND U1.
SELECTION-SCREEN COMMENT 6(19)  TEXT-036.
SELECTION-SCREEN POSITION 37.
PARAMETER RB_LOCAL RADIOBUTTON GROUP RBX.
SELECTION-SCREEN COMMENT 40(13) TEXT-035.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN SKIP.
*
PARAMETERS:
*    Parameter holding Input File name
          P_FILE LIKE RLGRAP-FILENAME
                 OBLIGATORY
                 LOWER CASE
                 DEFAULT 'C:\'
                 MODIF ID G1,
          P_FILE1 LIKE RLGRAP-FILENAME
                  OBLIGATORY
                  LOWER CASE
                  DEFAULT '/celestica/interface/corp/in/work/'
                  MODIF ID G2,
*    Parameter specifying Mode of calling the Transaction.
          P_MODE DEFAULT 'N' OBLIGATORY,
*    Check box used to test the input file.
          P_TEST AS CHECKBOX DEFAULT 'X',
*    Parameter holding Filename for holding Input File Errors
          P_IPERR LIKE RLGRAP-FILENAME
                  OBLIGATORY
                  LOWER CASE
                  DEFAULT 'C:\'
                  MODIF ID G1,
          P_IPERR1 LIKE RLGRAP-FILENAME
                 OBLIGATORY
                 LOWER CASE
                 DEFAULT '/celestica/interface/corp/in/work/047_Err.txt'
                 MODIF ID G2.
*
SELECTION-SCREEN END OF BLOCK B2.
*
*----------------------------------------------------------------------
*        AT Selection Screen  Events                                  *
*----------------------------------------------------------------------
*  Loop the screen to activate relative paths
AT SELECTION-SCREEN OUTPUT.
  LOOP AT SCREEN.
    IF RB_SERVE = C_TRUE AND SCREEN-GROUP1 = 'G1'.
      SCREEN-OUTPUT = 0.
      SCREEN-ACTIVE = 0.
      SCREEN-INPUT = 0.
    ELSEIF RB_LOCAL = C_TRUE AND SCREEN-GROUP1 = 'G2'.
      SCREEN-OUTPUT = 0.
      SCREEN-ACTIVE = 0.
      SCREEN-INPUT = 0.
    ENDIF.
    MODIFY SCREEN.
  ENDLOOP.
*
AT SELECTION-SCREEN ON BLOCK B2.
*  Checking Access Authorization for the user
  CALL FUNCTION 'ZU_DATA_ACCESS_AUTH_CHECK'
       EXPORTING
            ACTVT        = C_16
            P_BUKRS      = P_BUKRS
       TABLES
            S_WERKS      = S_WERKS
            S_EKORG      = S_EKORG
       EXCEPTIONS
            BUKRS_FAILED = 1
            VKORG_FAILED = 2
            VTWEG_FAILED = 3
            EKORG_FAILED = 4
            WERKS_FAILED = 5
            LGNUM_FAILED = 6
            OTHERS       = 7.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
*
AT SELECTION-SCREEN ON P_BUKRS.
  IF NOT P_BUKRS IS INITIAL.
    SELECT SINGLE BUKRS INTO T001
                        FROM T001
                        WHERE BUKRS EQ P_BUKRS.
    IF SY-SUBRC NE 0.
      MESSAGE I000 WITH TEXT-089.
      STOP.
    ENDIF.
  ENDIF.*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
* Search Help to select Input File path.
  PERFORM GET_FILE_NAME USING P_FILE.
*
* Check for the existence of the file.
  IF RB_LOCAL EQ C_TRUE.
    CALL FUNCTION 'TMP_GUI_GET_FILE_EXIST'
         EXPORTING
              FNAME          = P_FILE
         IMPORTING
              EXIST          = V_EXIST
              ISDIR          = V_ISDIR
         EXCEPTIONS
              FILEINFO_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.
    IF V_ISDIR IS INITIAL.
      IF V_EXIST IS INITIAL.
        MESSAGE I000 WITH TEXT-018.
        STOP.
      ENDIF.
    ELSEIF V_ISDIR EQ C_TRUE.
      MESSAGE I000 WITH TEXT-068.
      STOP.
    ENDIF.
  ENDIF.
*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_IPERR.
* Search Help to select Input Error File path.
  PERFORM GET_FILE_NAME USING P_IPERR.
*
AT SELECTION-SCREEN.
* Validate Transaction Mode
  IF  P_MODE <> C_BACKGROUND AND
      P_MODE <> C_FOREGROUND AND
      P_MODE <C_ERRORS>  p1        Path along with the file name
*----------------------------------------------------------------------
*
FORM GET_FILE_NAME USING L_FILE LIKE RLGRAP-FILENAME.  CALL FUNCTION 'WS_FILENAME_GET'
       EXPORTING
            MASK             = ',*.TXT,*.txt.'
            MODE             = 'O'
            TITLE            = TEXT-011
       IMPORTING
            FILENAME         = L_FILE
       EXCEPTIONS
            INV_WINSYS       = 1
            NO_BATCH         = 2
            SELECTION_CANCEL = 3
            SELECTION_ERROR  = 4
            OTHERS           = 5.
  CASE SY-SUBRC.
    WHEN 1.
      MESSAGE I000 WITH TEXT-084.
      STOP.
    WHEN 2.
      MESSAGE I000 WITH TEXT-085.
      STOP.
    WHEN 3.
      MESSAGE I000 WITH TEXT-086.
      STOP.
    WHEN 4.
      MESSAGE I000 WITH TEXT-087.
      STOP.
  ENDCASE.
*
ENDFORM.                    " GET_file_name*&---------------------------------------------------------------------*
*&      Form  upload_flatfile_data
*&---------------------------------------------------------------------*
*       Uploading data from Flat File
*----------------------------------------------------------------------*
*
FORM UPLOAD_FLATFILE_DATA
                      TABLES I_L_RECORD STRUCTURE WA_RECORD
                      USING L_FILENAME TYPE STRING.  DATA WA_L_RECORD TYPE T_RECORD.
* Upload the Flat file data
  IF RB_LOCAL EQ C_TRUE. "File is on the Local System
    CALL FUNCTION 'GUI_UPLOAD'
         EXPORTING
              FILENAME                = L_FILENAME
              FILETYPE                = 'ASC'
              HAS_FIELD_SEPARATOR     = 'X'
         TABLES
              DATA_TAB                = I_L_RECORD
         EXCEPTIONS
              FILE_OPEN_ERROR         = 1
              FILE_READ_ERROR         = 2
              NO_BATCH                = 3
              GUI_REFUSE_FILETRANSFER = 4
              INVALID_TYPE            = 5
              NO_AUTHORITY            = 6
              UNKNOWN_ERROR           = 7
              BAD_DATA_FORMAT         = 8
              HEADER_NOT_ALLOWED      = 9
              SEPARATOR_NOT_ALLOWED   = 10
              HEADER_TOO_LONG         = 11
              UNKNOWN_DP_ERROR        = 12
              ACCESS_DENIED           = 13
              DP_OUT_OF_MEMORY        = 14
              DISK_FULL               = 15
              DP_TIMEOUT              = 16
              OTHERS                  = 17.    CASE SY-SUBRC.
      WHEN 0.
        DESCRIBE TABLE I_L_RECORD LINES V_LINE.
        IF V_LINE EQ 0.
          MESSAGE I000 WITH TEXT-065.
          STOP.
        ENDIF.
      WHEN 1.
        MESSAGE I000 WITH TEXT-068.
        STOP.
      WHEN 2.
        MESSAGE I000 WITH TEXT-069.
        STOP.
      WHEN 3.
        MESSAGE I000 WITH TEXT-070.
        STOP.
      WHEN 4.
        MESSAGE I000 WITH TEXT-071.
        STOP.
      WHEN 5.
        MESSAGE I000 WITH TEXT-072.
        STOP.
      WHEN 6.
        MESSAGE I000 WITH TEXT-073.
        STOP.
      WHEN 7.
        MESSAGE I000 WITH TEXT-074.
        STOP.
      WHEN 8.
        MESSAGE I000 WITH TEXT-075.
        STOP.
      WHEN 9.
        MESSAGE I000 WITH TEXT-076.
        STOP.
      WHEN 10.
        MESSAGE I000 WITH TEXT-077.
        STOP.
      WHEN 11.
        MESSAGE I000 WITH TEXT-078.
        STOP.
      WHEN 12.
        MESSAGE I000 WITH TEXT-079.
        STOP.
      WHEN 13.
        MESSAGE I000 WITH TEXT-080.
        STOP.
      WHEN 14.
        MESSAGE I000 WITH TEXT-081.
        STOP.
      WHEN 15.
        MESSAGE I000 WITH TEXT-082.
        STOP.
      WHEN 16.
        MESSAGE I000 WITH TEXT-083.
        STOP.
    ENDCASE.
    CLEAR V_LINE.
  ELSEIF RB_SERVE EQ C_TRUE. "File is on the Application Server
    P_MODE = C_BACKGROUND.
    OPEN DATASET P_FILE1 FOR INPUT IN TEXT MODE.
    CHECK SY-SUBRC EQ C_SUCCESS.
    CLEAR WA_STR1.
    DO.
      READ DATASET P_FILE1 INTO WA_STR1.
      IF SY-SUBRC <> 0.      " NE SUCCESS.
        EXIT.
      ELSEIF SY-SUBRC EQ C_SUCCESS.
        APPEND WA_STR1 TO I_STR1.
        CLEAR WA_STR1.
      ENDIF.                  " ENDIF on SY-SUBRC 0 Check.
    ENDDO.                    " ENDDO    DELETE I_STR1 WHERE SLINE EQ ' '.
    DESCRIBE TABLE I_STR1 LINES V_LINE.
    IF V_LINE EQ 0.
      MESSAGE S000 WITH TEXT-065.
      STOP.
    ENDIF.
    LOOP AT I_STR1 INTO WA_STR1.
      CLEAR: WA_L_RECORD.
      SPLIT WA_STR1-SLINE AT V_STR
      INTO WA_L_RECORD-LIFNR
           WA_L_RECORD-EVART
           WA_L_RECORD-EKORG
           WA_L_RECORD-EKGRP
           WA_L_RECORD-WERKS
           WA_L_RECORD-LGORT
           WA_L_RECORD-KDATB
           WA_L_RECORD-KDATE
           WA_L_RECORD-ZTERM
           WA_L_RECORD-KTWRT
           WA_L_RECORD-EPSTP
           WA_L_RECORD-EMATN
           WA_L_RECORD-KTMNG
           WA_L_RECORD-NETPR
           WA_L_RECORD-PEINH
           WA_L_RECORD-BPRME
           WA_L_RECORD-IDNLF
           WA_L_RECORD-WEBRE
           WA_L_RECORD-MEPRF
           WA_L_RECORD-LTEX1
           WA_L_RECORD-DATAB
           WA_L_RECORD-DATBI
           WA_L_RECORD-KSCHL
           WA_L_RECORD-KBETR
           WA_L_RECORD-KONWA
           WA_L_RECORD-KPEIN
           WA_L_RECORD-KMEIN
           WA_L_RECORD-KSTBM
           WA_L_RECORD-KBETR_01
           WA_L_RECORD-DEL_FLAG
           WA_L_RECORD-ERR_MSG.
      APPEND WA_L_RECORD TO I_L_RECORD.
      CLEAR: WA_L_RECORD,
              WA_STR1.
    ENDLOOP.
    REFRESH I_STR1.
    CLOSE DATASET P_FILE1.
  ENDIF.
ENDFORM.
*
*&---------------------------------------------------------------------*
*&      Form  BDC_DYNPRO
*&---------------------------------------------------------------------*
*       Data populated into i_bdcdata table for program
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
  CLEAR WA_BDCDATA.
  WA_BDCDATA-PROGRAM  = PROGRAM.
  WA_BDCDATA-DYNPRO   = DYNPRO.
  WA_BDCDATA-DYNBEGIN = C_TRUE.
  APPEND WA_BDCDATA TO I_BDCDATA.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  BDC_FIELD
*&---------------------------------------------------------------------*
*       Data populated into i_bdcdata table for fields
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
  CLEAR WA_BDCDATA.
  WA_BDCDATA-FNAM = FNAM.
  WA_BDCDATA-FVAL = FVAL.
  APPEND WA_BDCDATA TO I_BDCDATA.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  convert_date
*&---------------------------------------------------------------------*
*       Converting the data from the file format to mm/dd/yyyy format
*----------------------------------------------------------------------*
*      <--P_wa_record_kdatb  Source Date
*      <--p_l_conv_date      Target Date
*----------------------------------------------------------------------*
FORM CONVERT_DATE USING L_DATE
                        L_TAR_DATE.
  CONCATENATE L_DATE+0(2)
              '/'
              L_DATE+3(2)
              '/'
              L_DATE+6(4)
              INTO L_TAR_DATE.
ENDFORM.                    " convert_date
*&---------------------------------------------------------------------*
*&      Form  validate_flatfile_data
*&---------------------------------------------------------------------*
*       Validating the input file
*----------------------------------------------------------------------*
FORM VALIDATE_FLATFILE_DATA.  DATA: L_TODAY LIKE SY-DATUM,
        L_STARTDATE_C LIKE SY-DATUM,
        L_ENDDATE_C LIKE SY-DATUM,
        L_ENDDATE_C1 LIKE SY-DATUM,
        L_STARTDATE_C1 LIKE SY-DATUM,
        L_STARTDATE(8),
        L_ENDDATE(8).* Fetch indicator for all records on the material, plant & storage
* location combination.
  IF NOT I_RECORD[] IS INITIAL.
    REFRESH I_LOEKZ.
    SELECT EMATN            " Material Number
           WERKS            " Plant
           LGORT            " Storage Location
           BSTYP            " Purchasing Document Category
           LOEKZ            " Deletion indicator
      INTO TABLE I_LOEKZ
      FROM EKPO
      FOR ALL ENTRIES IN I_RECORD
      WHERE EMATN = I_RECORD-EMATN
        AND WERKS = I_RECORD-WERKS
        AND LGORT = I_RECORD-LGORT
        AND BSTYP = C_BSTYP
        AND LOEKZ = C_LOEKZ_MARKED.
    IF SY-SUBRC EQ 0.
      SORT I_LOEKZ BY EMATN WERKS LGORT BSTYP LOEKZ.
    ENDIF.* Fetching Plants for all entries in the selection screen
    REFRESH I_T001W.
    SELECT WERKS  "Plant
        INTO TABLE I_T001W
        FROM T001W
        WHERE WERKS IN S_WERKS.
    IF SY-SUBRC EQ 0.
      SORT I_T001W BY WERKS.
    ENDIF.* Fetching materials for the plants listed in flat file
    REFRESH I_MATNR.
    SELECT MATNR          " Material Number
      INTO TABLE I_MATNR
      FROM MARC
      FOR ALL ENTRIES IN I_RECORD
      WHERE WERKS = I_RECORD-WERKS.
    IF SY-SUBRC EQ 0.
      SORT I_MATNR BY MATNR.
    ENDIF.* Fetching Company Codes for repective Purchase Organizations
    REFRESH I_T024E.
    SELECT EKORG       "  Purchase Organization
           BUKRS       "  Company Code
        INTO TABLE I_T024E
        FROM T024E
        WHERE EKORG IN S_EKORG.
    IF SY-SUBRC EQ 0.
      SORT I_T024E BY EKORG.
    ENDIF.* Fetching SAP Data using Legacy Data.
    REFRESH I_ZMVXREF.
    SELECT D_ALTKN
           D_BUKRS
           M_ALTKN
        INTO TABLE I_ZMVXREF
        FROM ZMVXREF
        FOR ALL ENTRIES IN I_RECORD
        WHERE D_ALTKN = I_RECORD-LIFNR.
    IF SY-SUBRC EQ 0.
      SORT I_ZMVXREF BY D_ALTKN D_BUKRS.
    ENDIF.* Fetching Vendors from LFA1
    IF NOT I_ZMVXREF[] IS INITIAL.
      REFRESH I_LFA1.
      SELECT LIFNR
         INTO TABLE I_LFA1
         FROM LFA1
         FOR ALL ENTRIES IN I_ZMVXREF
         WHERE LIFNR = I_ZMVXREF-M_ALTKN.
      IF SY-SUBRC EQ 0.
        SORT I_LFA1 BY LIFNR.
      ENDIF.
    ENDIF.* Start Validating the flat file
    CLEAR: WA_RECORD,
           WA_T024E,
           WA_ZMVXREF,
           WA_LFA1,
           WA_LOEKZ,
           WA_MATNR.    LOOP AT I_RECORD INTO WA_RECORD.
      L_TODAY = SY-DATUM.
      L_STARTDATE = WA_RECORD-KDATB.
      L_ENDDATE = WA_RECORD-KDATE.      IF WA_RECORD-DEL_FLAG IS INITIAL.
        READ TABLE I_T001W INTO WA_T001W
                           WITH KEY WERKS = WA_RECORD-WERKS
                           BINARY SEARCH.
        IF SY-SUBRC EQ 0.
*   Cross-Reference check performed for the given Vendors
          READ TABLE I_T024E INTO WA_T024E
                             WITH KEY EKORG = WA_RECORD-EKORG
                             BINARY SEARCH.
          IF SY-SUBRC NE 0.
            V_CROSS_REFERENCE_ERROR = C_VEN_ERR3.
          ELSE.
            READ TABLE I_ZMVXREF INTO WA_ZMVXREF
                        WITH KEY D_ALTKN = WA_RECORD-LIFNR
                                 D_BUKRS = P_BUKRS
                        BINARY SEARCH.
            IF SY-SUBRC EQ 0.
              READ TABLE I_LFA1 INTO WA_LFA1
                         WITH KEY LIFNR = WA_ZMVXREF-M_ALTKN
                         BINARY SEARCH.
              IF SY-SUBRC EQ 0.
                V_CROSS_REFERENCE_ERROR = C_VEN_SUCS.
              ELSE.
                V_CROSS_REFERENCE_ERROR = C_VEN_ERR2.
              ENDIF.
            ELSE.
              V_CROSS_REFERENCE_ERROR = C_VEN_ERR1.
            ENDIF.
          ENDIF.
* Legacy Vendor could not be mapped
          IF V_CROSS_REFERENCE_ERROR EQ C_VEN_ERR1.
        V_INPUTERROR_FLAG = C_INPUTERROR_FLAG_YES. "Inp.file err. occurd
            WA_RECORD-DEL_FLAG = C_TRUE.
            WA_RECORD-ERR_MSG = TEXT-007.
            MODIFY I_RECORD FROM WA_RECORD
                            TRANSPORTING DEL_FLAG
                                         ERR_MSG
                            WHERE LIFNR = WA_RECORD-LIFNR.
* Legacy Vendor is mapped but the obtained SAP vendor doesn't exist.
          ELSEIF V_CROSS_REFERENCE_ERROR EQ C_VEN_ERR2.
*           Inp.file err. occurd
            V_INPUTERROR_FLAG = C_INPUTERROR_FLAG_YES.
            WA_RECORD-DEL_FLAG = C_TRUE.
            WA_RECORD-ERR_MSG = TEXT-008.
            MODIFY I_RECORD FROM WA_RECORD
                            TRANSPORTING DEL_FLAG
                                         ERR_MSG
                            WHERE LIFNR = WA_RECORD-LIFNR.
* Purchase Organization doesn't exist in T024E.
          ELSEIF V_CROSS_REFERENCE_ERROR EQ C_VEN_ERR3.
*             Inp.file err. occurd
            V_INPUTERROR_FLAG = C_INPUTERROR_FLAG_YES.
            WA_RECORD-DEL_FLAG = C_TRUE.
            WA_RECORD-ERR_MSG = TEXT-014.
            MODIFY I_RECORD FROM WA_RECORD
                            TRANSPORTING DEL_FLAG
                                         ERR_MSG
                            WHERE EKORG = WA_RECORD-EKORG.
* Vendor is mapped and validated successfully
          ELSEIF V_CROSS_REFERENCE_ERROR EQ C_VEN_SUCS.* Checking for the deletion indicator for that record
            CONCATENATE WA_RECORD-KDATB+6(4)
                        WA_RECORD-KDATB+3(2)
                        WA_RECORD-KDATB+0(2)
                        INTO
                        L_STARTDATE.
            MOVE L_STARTDATE TO L_STARTDATE_C.            CONCATENATE WA_RECORD-KDATB+6(4)
                        WA_RECORD-KDATB+0(2)
                        WA_RECORD-KDATB+3(2)
                        INTO
                        L_STARTDATE_C1.            CONCATENATE WA_RECORD-KDATE+6(4)
                        WA_RECORD-KDATE+3(2)
                        WA_RECORD-KDATE+0(2)
                        INTO
                        L_ENDDATE.
            MOVE L_ENDDATE TO L_ENDDATE_C.            CONCATENATE WA_RECORD-KDATE+6(4)
                        WA_RECORD-KDATE+0(2)
                        WA_RECORD-KDATE+3(2)
                        INTO
                        L_ENDDATE_C1.            READ TABLE I_LOEKZ INTO WA_LOEKZ WITH KEY
                                             EMATN = WA_RECORD-EMATN
                                             WERKS = WA_RECORD-WERKS
                                             LGORT = WA_RECORD-LGORT
                                             BINARY SEARCH.
            IF SY-SUBRC EQ 0.
*             Inpfle err.occured
              V_INPUTERROR_FLAG = C_INPUTERROR_FLAG_YES.
              WA_RECORD-ERR_MSG = TEXT-003.
              WA_RECORD-DEL_FLAG = C_TRUE.    "marking the record
              MODIFY I_RECORD FROM WA_RECORD
                              TRANSPORTING DEL_FLAG
                                            ERR_MSG
                              WHERE LIFNR = WA_RECORD-LIFNR
                                AND EVART = WA_RECORD-EVART
                                AND EKORG = WA_RECORD-EKORG
                                AND EKGRP = WA_RECORD-EKGRP
                                AND WERKS = WA_RECORD-WERKS
                                AND LGORT = WA_RECORD-LGORT
                                AND KDATB = WA_RECORD-KDATB
                                AND KDATE = WA_RECORD-KDATE
                                AND ZTERM = WA_RECORD-ZTERM
                                AND KTWRT = WA_RECORD-KTWRT
                                AND EPSTP = WA_RECORD-EPSTP
                                AND EMATN = WA_RECORD-EMATN.* Validating the Purchasing Organization for Blank/Null
            ELSEIF WA_RECORD-EKORG IS INITIAL.
*             Inpfle err.occured
              V_INPUTERROR_FLAG = C_INPUTERROR_FLAG_YES.
              WA_RECORD-ERR_MSG = TEXT-010.
              WA_RECORD-DEL_FLAG = C_TRUE.
              MODIFY I_RECORD FROM WA_RECORD
                              TRANSPORTING DEL_FLAG
                                           ERR_MSG
                              WHERE LIFNR = WA_RECORD-LIFNR
                                AND EVART = WA_RECORD-EVART
                                AND EKORG = WA_RECORD-EKORG
                                AND EKGRP = WA_RECORD-EKGRP
                                AND WERKS = WA_RECORD-WERKS
                                AND LGORT = WA_RECORD-LGORT
                                AND KDATB = WA_RECORD-KDATB
                                AND KDATE = WA_RECORD-KDATE
                                AND ZTERM = WA_RECORD-ZTERM
                                AND KTWRT = WA_RECORD-KTWRT
                                AND EPSTP = WA_RECORD-EPSTP
                                AND EMATN = WA_RECORD-EMATN.* Validating the Plant for Blank/Null
            ELSEIF WA_RECORD-WERKS IS INITIAL.
*             Inpfle err.occured
              V_INPUTERROR_FLAG = C_INPUTERROR_FLAG_YES.
              WA_RECORD-ERR_MSG = TEXT-039.
              WA_RECORD-DEL_FLAG = C_TRUE.
              MODIFY I_RECORD FROM WA_RECORD
                              TRANSPORTING DEL_FLAG
                                           ERR_MSG
                              WHERE LIFNR = WA_RECORD-LIFNR
                                AND EVART = WA_RECORD-EVART
                                AND EKORG = WA_RECORD-EKORG
                                AND EKGRP = WA_RECORD-EKGRP
                                AND WERKS = WA_RECORD-WERKS
                                AND LGORT = WA_RECORD-LGORT
                                AND KDATB = WA_RECORD-KDATB
                                AND KDATE = WA_RECORD-KDATE
                                AND ZTERM = WA_RECORD-ZTERM
                                AND KTWRT = WA_RECORD-KTWRT
                                AND EPSTP = WA_RECORD-EPSTP
                                AND EMATN = WA_RECORD-EMATN.* Validating the Contract Validity Start Date
            ELSEIF L_STARTDATE_C1 GT L_TODAY.             "#EC PORTABLE
*             Inpfle err.occured
              V_INPUTERROR_FLAG = C_INPUTERROR_FLAG_YES.
              WA_RECORD-ERR_MSG = TEXT-004.
              WA_RECORD-DEL_FLAG = C_TRUE.      "marking the record
              MODIFY I_RECORD FROM WA_RECORD
                              TRANSPORTING DEL_FLAG
                                           ERR_MSG
                              WHERE LIFNR = WA_RECORD-LIFNR
                                AND EVART = WA_RECORD-EVART
                                AND EKORG = WA_RECORD-EKORG
                                AND EKGRP = WA_RECORD-EKGRP
                                AND WERKS = WA_RECORD-WERKS
                                AND LGORT = WA_RECORD-LGORT
                                AND KDATB = WA_RECORD-KDATB.
* Validating the Contract Validity End Date
            ELSEIF L_ENDDATE_C1 LE L_TODAY.               "#EC PORTABLE
*             Inpfle err.ocrd
              V_INPUTERROR_FLAG = C_INPUTERROR_FLAG_YES.
              WA_RECORD-ERR_MSG = TEXT-005.
              WA_RECORD-DEL_FLAG = C_TRUE.    "marking the record
              MODIFY I_RECORD FROM WA_RECORD
                              TRANSPORTING DEL_FLAG
                                           ERR_MSG
                              WHERE LIFNR = WA_RECORD-LIFNR
                                AND EVART = WA_RECORD-EVART
                                AND EKORG = WA_RECORD-EKORG
                                AND EKGRP = WA_RECORD-EKGRP
                                AND WERKS = WA_RECORD-WERKS
                                AND LGORT = WA_RECORD-LGORT
                                AND KDATB = WA_RECORD-KDATB
                                AND KDATE = WA_RECORD-KDATE.
* Checking for Material under the Plant for Agreement Type 'WK'
            ELSEIF WA_RECORD-EVART = C_WK.
              READ TABLE I_MATNR INTO WA_MATNR
                                 WITH KEY MATNR = WA_RECORD-EMATN
                                 BINARY SEARCH.
              IF SY-SUBRC NE 0.
             V_INPUTERROR_FLAG = C_INPUTERROR_FLAG_YES. "Inpfle err.ocrd
                WA_RECORD-ERR_MSG = TEXT-006.
                WA_RECORD-DEL_FLAG = C_TRUE.   "marking the record
                MODIFY I_RECORD FROM WA_RECORD
                                TRANSPORTING DEL_FLAG
                                             ERR_MSG
                                WHERE LIFNR = WA_RECORD-LIFNR
                                  AND EVART = WA_RECORD-EVART
                                  AND EKORG = WA_RECORD-EKORG
                                  AND EKGRP = WA_RECORD-EKGRP
                                  AND WERKS = WA_RECORD-WERKS
                                  AND LGORT = WA_RECORD-LGORT
                                  AND KDATB = WA_RECORD-KDATB
                                  AND KDATE = WA_RECORD-KDATE
                                  AND ZTERM = WA_RECORD-ZTERM
                                  AND KTWRT = WA_RECORD-KTWRT
                                  AND EPSTP = WA_RECORD-EPSTP
                                  AND EMATN = WA_RECORD-EMATN.
              ENDIF.
            ENDIF.  " checking of deletion indicator
          ENDIF.   " checking for success of vendor cross reference
        ELSE.
          V_INPUTERROR_FLAG = C_INPUTERROR_FLAG_YES. "Inpfle err.ocrd
          WA_RECORD-ERR_MSG = TEXT-041.
          WA_RECORD-DEL_FLAG = C_TRUE.   "marking the record
          MODIFY I_RECORD FROM WA_RECORD
                          TRANSPORTING DEL_FLAG
                                       ERR_MSG
                          WHERE WERKS = WA_RECORD-WERKS.
        ENDIF. " Plant checked to selection screen
      ENDIF.  " the records for which del_flag is initial
      CLEAR: WA_RECORD,
             WA_T024E,
             WA_ZMVXREF,
             WA_LFA1,
             WA_LOEKZ,
             WA_MATNR,
             L_TODAY,
             L_STARTDATE_C,
             L_ENDDATE_C,
             L_STARTDATE,
             L_ENDDATE.
    ENDLOOP.    LOOP AT I_RECORD INTO WA_RECORD.
      IF WA_RECORD-DEL_FLAG = C_TRUE.
        APPEND WA_RECORD TO I_ERR_REC.
        CLEAR WA_RECORD.
      ENDIF.
    ENDLOOP.  ELSE.
    MESSAGE E000 WITH TEXT-013.  " no records in the flat file
    STOP.
  ENDIF.
ENDFORM.                    " validate_flatfile_data
*&---------------------------------------------------------------------*
*&      Form  DOWNLOAD_ERROR_FILE
*&---------------------------------------------------------------------*
*       Downloads all records along with the records encountering the
*       input file validation error
*----------------------------------------------------------------------*
FORM DOWNLOAD_ERROR_FILE.  DATA L_ISDIR TYPE C.  IF V_INPUTERROR_FLAG = C_INPUTERROR_FLAG_YES.
    V_FILENAME = P_IPERR.* Check for the existence of the file.
    IF RB_LOCAL EQ C_TRUE.
      CALL FUNCTION 'TMP_GUI_GET_FILE_EXIST'
           EXPORTING
                FNAME          = P_IPERR
           IMPORTING
                ISDIR          = L_ISDIR
           EXCEPTIONS
                FILEINFO_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.
      IF L_ISDIR EQ C_TRUE.
        MESSAGE I000 WITH TEXT-088.
        STOP.
      ENDIF.
    ENDIF.    IF RB_LOCAL EQ C_TRUE.
* Download the Input Error File.
      CALL FUNCTION 'GUI_DOWNLOAD'
           EXPORTING
                FILENAME                = V_FILENAME
                FILETYPE                = 'ASC'
                WRITE_FIELD_SEPARATOR   = '#'
           TABLES
                DATA_TAB                = I_ERR_REC
           EXCEPTIONS
                FILE_WRITE_ERROR        = 1
                NO_BATCH                = 2
                GUI_REFUSE_FILETRANSFER = 3
                INVALID_TYPE            = 4
                NO_AUTHORITY            = 5
                UNKNOWN_ERROR           = 6
                HEADER_NOT_ALLOWED      = 7
                SEPARATOR_NOT_ALLOWED   = 8
                FILESIZE_NOT_ALLOWED    = 9
                HEADER_TOO_LONG         = 10
                DP_ERROR_CREATE         = 11
                DP_ERROR_SEND           = 12
                DP_ERROR_WRITE          = 13
                UNKNOWN_DP_ERROR        = 14
                ACCESS_DENIED           = 15
                DP_OUT_OF_MEMORY        = 16
                DISK_FULL               = 17
                DP_TIMEOUT              = 18
                FILE_NOT_FOUND          = 19
                DATAPROVIDER_EXCEPTION  = 20
                CONTROL_FLUSH_ERROR     = 21
                OTHERS                  = 22.
      IF SY-SUBRC <0> 1.    "added on 9th sep
          PERFORM BDC_FIELD       USING V_KSCHL2
                                        WA_RECORD-KSCHL.
        ENDIF.                  "added on 9th sep
        PERFORM BDC_FIELD       USING V_KBETR2
                                      WA_RECORD-KBETR.
        PERFORM BDC_FIELD       USING V_KONWA2
                                      WA_RECORD-KONWA.
        PERFORM BDC_FIELD       USING V_KPEIN2
                                      WA_RECORD-KPEIN.
        PERFORM BDC_FIELD       USING V_KMEIN2
                                      WA_RECORD-KMEIN.
        PERFORM BDC_FIELD       USING V_SELKZ2
                                      'X'.
        CLEAR MAT_FLAG.
        L_SCA_INDEX = 1.
        L_CON_INDEX = L_CON_INDEX + 1.
      ENDIF.      V_IND3 = L_SCA_INDEX.
      IF V_IND3 GT 1.
        V_IND3 = 2.
      ENDIF.      CONCATENATE 'KONM-KSTBM(' V_IND3 ')' INTO V_KSTBM3.
      CONCATENATE 'KONM-KBETR(' V_IND3 ')' INTO V_KBETR3.      PERFORM BDC_DYNPRO      USING 'SAPMV13A' '0303'.
      PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                    '=NEWP'.
      PERFORM BDC_DYNPRO      USING 'SAPMV13A' '0303'.
      PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                    '/00'.
      IF WA_RECORD-KBETR IS INITIAL.
        PERFORM BDC_FIELD       USING V_KSTBM3
                                     WA_RECORD-KSTBM.
        PERFORM BDC_FIELD       USING V_KBETR3
                                  WA_RECORD-KBETR_01.
      ENDIF.      L_SCA_INDEX = L_SCA_INDEX + 1.
    ENDIF.  " check the c_true, c_strue.    AT END OF KMEIN.
      PERFORM BDC_DYNPRO      USING 'SAPMV13A' '0303'.
      PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                    V_KSTBM3.
      PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                    '=BACK'.
    ENDAT.    AT END OF LTEX1.
      PERFORM BDC_DYNPRO      USING 'SAPMV13A' '0201'.
      PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                    'RV13A-DATAB'.
      PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                    '=BACK'.
    ENDAT.    AT END OF KTWRT.
      PERFORM BDC_DYNPRO      USING 'SAPMM06E' '0220'.
      PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                    V_EVRTP1.
      PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                    '=BU'.
      PERFORM BDC_DYNPRO      USING 'SAPLSPO1' '0300'.
      PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                     '=YES'.      CALL TRANSACTION C_TCODE USING I_BDCDATA MODE P_MODE
                                   MESSAGES INTO I_MESSTAB.      IF SY-SUBRC <> 0.
        PERFORM GET_MESSAGE USING C_MSGTYP_E
                            CHANGING V_ERRMSG.
        WA_RECORD-ERR_MSG = V_ERRMSG.
        WA_RECORD-DEL_FLAG = C_STRUE.
* Since all the related line items are to be dealt such modify is used
        MODIFY I_RECORD FROM WA_RECORD
                        TRANSPORTING DEL_FLAG
                                     ERR_MSG
                        WHERE LIFNR = WA_RECORD-LIFNR
                          AND EVART = WA_RECORD-EVART
                          AND EKORG = WA_RECORD-EKORG
                          AND EKGRP = WA_RECORD-EKGRP
                          AND WERKS = WA_RECORD-WERKS
                          AND LGORT = WA_RECORD-LGORT
                          AND KDATB = WA_RECORD-KDATB
                          AND KDATE = WA_RECORD-KDATE
                          AND ZTERM = WA_RECORD-ZTERM
                          AND KTWRT = WA_RECORD-KTWRT.
        CLEAR V_ERRMSG.
      ELSEIF SY-SUBRC EQ 0.
        PERFORM GET_MESSAGE USING C_MSGTYP_S
                            CHANGING V_ERRMSG.
        WA_RECORD-ERR_MSG = V_ERRMSG.
        WA_RECORD-DEL_FLAG = C_YTRUE.
* Since all the related line items are to be dealt such modify is used
        MODIFY I_RECORD FROM WA_RECORD
                        TRANSPORTING DEL_FLAG
                                     ERR_MSG
                        WHERE LIFNR = WA_RECORD-LIFNR
                          AND EVART = WA_RECORD-EVART
                          AND EKORG = WA_RECORD-EKORG
                          AND EKGRP = WA_RECORD-EKGRP
                          AND WERKS = WA_RECORD-WERKS
                          AND LGORT = WA_RECORD-LGORT
                          AND KDATB = WA_RECORD-KDATB
                          AND KDATE = WA_RECORD-KDATE
                          AND ZTERM = WA_RECORD-ZTERM
                          AND KTWRT = WA_RECORD-KTWRT.
        CLEAR V_ERRMSG.
      ENDIF.      CLEAR WA_BDCDATA.
      REFRESH: I_BDCDATA,
               I_MESSTAB.
    ENDAT.
    MOVE WA_RECORD TO WA_RECORDPREV.
    CLEAR WA_RECORD.
  ENDLOOP.  LOOP AT I_RECORD INTO WA_RECORD.
    IF WA_RECORD-DEL_FLAG = C_STRUE.
      APPEND WA_RECORD TO I_ERR_REC.
    ENDIF.
    CLEAR WA_RECORD.
  ENDLOOP.
ENDFORM.                    " BUILD_BDC_DATA*&---------------------------------------------------------------------*
*&      Form  get_message
*&---------------------------------------------------------------------*
*       Obtains message from the message table
*----------------------------------------------------------------------*
*      <--GV_ERRMSG  Error Message generated by SAP
*----------------------------------------------------------------------*
FORM GET_MESSAGE USING L_MSGTYP TYPE C
                 CHANGING L_MSGTX LIKE V_ERRMSG.
  DATA: L_MSTRING(500) TYPE C,
        L_MESSAGES TYPE T100.
  CLEAR: WA_MESSTAB,
         L_MSTRING,
         L_MSGTX.
  LOOP AT I_MESSTAB INTO WA_MESSTAB WHERE MSGTYP = L_MSGTYP.    SELECT SINGLE * FROM T100
           INTO L_MESSAGES  WHERE SPRSL = WA_MESSTAB-MSGSPRA
                               AND ARBGB = WA_MESSTAB-MSGID
                               AND MSGNR = WA_MESSTAB-MSGNR.
    IF SY-SUBRC = 0.
      L_MSTRING = L_MESSAGES-TEXT.
      IF L_MSTRING CS '&1'.
        CONDENSE WA_MESSTAB-MSGV1.
        CONDENSE WA_MESSTAB-MSGV2.
        CONDENSE WA_MESSTAB-MSGV3.
        CONDENSE WA_MESSTAB-MSGV4.
        REPLACE '&1' WITH WA_MESSTAB-MSGV1 INTO L_MSTRING.
        REPLACE '&2' WITH WA_MESSTAB-MSGV2 INTO L_MSTRING.
        REPLACE '&3' WITH WA_MESSTAB-MSGV3 INTO L_MSTRING.
        REPLACE '&4' WITH WA_MESSTAB-MSGV4 INTO L_MSTRING.
      ELSE.
        CONDENSE WA_MESSTAB-MSGV1.
        CONDENSE WA_MESSTAB-MSGV2.
        CONDENSE WA_MESSTAB-MSGV3.
        CONDENSE WA_MESSTAB-MSGV4.
        REPLACE '&' WITH WA_MESSTAB-MSGV1 INTO L_MSTRING.
        REPLACE '&' WITH WA_MESSTAB-MSGV2 INTO L_MSTRING.
        REPLACE '&' WITH WA_MESSTAB-MSGV3 INTO L_MSTRING.
        REPLACE '&' WITH WA_MESSTAB-MSGV4 INTO L_MSTRING.
      ENDIF.
      CONDENSE L_MSTRING.
    ENDIF.
    CONCATENATE L_MSGTX L_MSTRING INTO L_MSGTX SEPARATED BY SPACE.
    CLEAR WA_MESSTAB.
  ENDLOOP.
*
ENDFORM.                 " get_message
*&---------------------------------------------------------------------*
*&      Form  display_inperr_records
*&---------------------------------------------------------------------*
*   Diplays the records with the input file validation errors in ALV
*----------------------------------------------------------------------*
FORM DISPLAY_INPERR_RECORDS.  WRITE SY-DATUM TO V_DATE  DD/MM/YYYY.
  REFRESH I_ALV_EVENT.
  CLEAR WA_ALV_EVENT.  WA_LISTHEADER-TYP = 'H'.
  WA_LISTHEADER-KEY = ''.
  WA_LISTHEADER-INFO = TEXT-029.
  APPEND WA_LISTHEADER TO I_LISTHEADER.  WA_LISTHEADER-TYP = 'S'.
  WA_LISTHEADER-KEY = TEXT-030.
  WA_LISTHEADER-INFO = V_DATE.
  APPEND WA_LISTHEADER TO I_LISTHEADER.  WA_LISTHEADER-TYP = 'S'.
  WA_LISTHEADER-KEY = TEXT-031.
  WA_LISTHEADER-INFO = SY-UZEIT.
  APPEND WA_LISTHEADER TO I_LISTHEADER.  PERFORM BUILD_FC USING '1' 'LIFNR' 'I_ERR_REC' TEXT-020 '10'.
  PERFORM BUILD_FC USING '2' 'EVART' 'I_ERR_REC' TEXT-021 '4'.
  PERFORM BUILD_FC USING '3' 'EKORG' 'I_ERR_REC' TEXT-022 '4'.
  PERFORM BUILD_FC USING '4' 'EKGRP' 'I_ERR_REC' TEXT-023 '3'.
  PERFORM BUILD_FC USING '5' 'WERKS' 'I_ERR_REC' TEXT-024 '4'.
  PERFORM BUILD_FC USING '6' 'LGORT' 'I_ERR_REC' TEXT-025 '4'.
  PERFORM BUILD_FC USING '7' 'KDATB' 'I_ERR_REC' TEXT-042 '10'.
  PERFORM BUILD_FC USING '8' 'KDATE' 'I_ERR_REC' TEXT-043 '10'.
  PERFORM BUILD_FC USING '9' 'ZTERM' 'I_ERR_REC' TEXT-044 '4'.
  PERFORM BUILD_FC USING '10' 'KTWRT' 'I_ERR_REC' TEXT-045 '20'.
  PERFORM BUILD_FC USING '11' 'EPSTP' 'I_ERR_REC' TEXT-046 '1'.
  PERFORM BUILD_FC USING '12' 'EMATN' 'I_ERR_REC' TEXT-026 '18'.
  PERFORM BUILD_FC USING '13' 'KTMNG' 'I_ERR_REC' TEXT-047 '17'.
  PERFORM BUILD_FC USING '14' 'NETPR' 'I_ERR_REC' TEXT-048 '14'.
  PERFORM BUILD_FC USING '15' 'PEINH' 'I_ERR_REC' TEXT-049 '6'.
  PERFORM BUILD_FC USING '16' 'BPRME' 'I_ERR_REC' TEXT-050 '3'.
  PERFORM BUILD_FC USING '17' 'IDNLF' 'I_ERR_REC' TEXT-051 '35'.
  PERFORM BUILD_FC USING '18' 'WEBRE' 'I_ERR_REC' TEXT-052 '1'.
  PERFORM BUILD_FC USING '19' 'MEPRF' 'I_ERR_REC' TEXT-053 '1'.
  PERFORM BUILD_FC USING '20' 'LTEX1' 'I_ERR_REC' TEXT-054 '40'.
  PERFORM BUILD_FC USING '21' 'DATAB' 'I_ERR_REC' TEXT-055 '10'.
  PERFORM BUILD_FC USING '22' 'DATBI' 'I_ERR_REC' TEXT-056 '10'.
  PERFORM BUILD_FC USING '23' 'KSCHL' 'I_ERR_REC' TEXT-057 '4'.
  PERFORM BUILD_FC USING '24' 'KBETR' 'I_ERR_REC' TEXT-058 '16'.
  PERFORM BUILD_FC USING '25' 'KONWA' 'I_ERR_REC' TEXT-059 '5'.
  PERFORM BUILD_FC USING '26' 'KPEIN' 'I_ERR_REC' TEXT-060 '5'.
  PERFORM BUILD_FC USING '27' 'KMEIN' 'I_ERR_REC' TEXT-061 '3'.
  PERFORM BUILD_FC USING '28' 'KSTBM' 'I_ERR_REC' TEXT-062 '19'.
  PERFORM BUILD_FC USING '29' 'KBETR_01' 'I_ERR_REC' TEXT-063 '16'.
  PERFORM BUILD_FC USING '30' 'DEL_FLAG' 'I_ERR_REC' TEXT-064 '1'.
  PERFORM BUILD_FC USING '31' 'ERR_MSG' 'I_ERR_REC' TEXT-027 '100'.  WA_LAYOUT-ZEBRA = 'X'.
  WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.  PERFORM SORTBUILD USING I_SORT[].  V_REPID = SY-REPID.  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
            I_CALLBACK_PROGRAM = V_REPID
            I_GRID_TITLE       = TEXT-009
            IT_FIELDCAT        = I_FIELDCAT
            IS_LAYOUT          = WA_LAYOUT
            I_DEFAULT          = 'X'
            I_SAVE             = 'X'
            IT_SORT            = I_SORT
            IT_EVENTS          = I_ALV_EVENT
       TABLES
            T_OUTTAB           = I_ERR_REC
       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_inperr_records
*&---------------------------------------------------------------------*
*&      Form  display_processed_records
*&---------------------------------------------------------------------*
*   Diplays the processed records with their status in ALV Grid
*----------------------------------------------------------------------*
FORM DISPLAY_PROCESSED_RECORDS.  WRITE SY-DATUM TO V_DATE  DD/MM/YYYY.
  REFRESH I_ALV_EVENT.
  CLEAR WA_ALV_EVENT.  WA_LISTHEADER-TYP = 'H'.
  WA_LISTHEADER-KEY = ''.
  WA_LISTHEADER-INFO = TEXT-029.
  APPEND WA_LISTHEADER TO I_LISTHEADER.  WA_LISTHEADER-TYP = 'S'.
  WA_LISTHEADER-KEY = TEXT-030.
  WA_LISTHEADER-INFO = V_DATE.
  APPEND WA_LISTHEADER TO I_LISTHEADER.  WA_LISTHEADER-TYP = 'S'.
  WA_LISTHEADER-KEY = TEXT-031.
  WA_LISTHEADER-INFO = SY-UZEIT.
  APPEND WA_LISTHEADER TO I_LISTHEADER.  PERFORM BUILD_FC USING '1' 'LIFNR' 'I_RECORD' TEXT-020 '10'.
  PERFORM BUILD_FC USING '2' 'EVART' 'I_RECORD' TEXT-021 '4'.
  PERFORM BUILD_FC USING '3' 'EKORG' 'I_RECORD' TEXT-022 '4'.
  PERFORM BUILD_FC USING '4' 'EKGRP' 'I_RECORD' TEXT-023 '3'.
  PERFORM BUILD_FC USING '5' 'WERKS' 'I_RECORD' TEXT-024 '4'.
  PERFORM BUILD_FC USING '6' 'LGORT' 'I_RECORD' TEXT-025 '4'.
  PERFORM BUILD_FC USING '7' 'KDATB' 'I_RECORD' TEXT-042 '10'.
  PERFORM BUILD_FC USING '8' 'KDATE' 'I_RECORD' TEXT-043 '10'.
  PERFORM BUILD_FC USING '9' 'ZTERM' 'I_RECORD' TEXT-044 '4'.
  PERFORM BUILD_FC USING '10' 'KTWRT' 'I_RECORD' TEXT-045 '20'.
  PERFORM BUILD_FC USING '11' 'EPSTP' 'I_RECORD' TEXT-046 '1'.
  PERFORM BUILD_FC USING '12' 'EMATN' 'I_RECORD' TEXT-026 '18'.
  PERFORM BUILD_FC USING '13' 'KTMNG' 'I_RECORD' TEXT-047 '17'.
  PERFORM BUILD_FC USING '14' 'NETPR' 'I_RECORD' TEXT-048 '14'.
  PERFORM BUILD_FC USING '15' 'PEINH' 'I_RECORD' TEXT-049 '6'.
  PERFORM BUILD_FC USING '16' 'BPRME' 'I_RECORD' TEXT-050 '3'.
  PERFORM BUILD_FC USING '17' 'IDNLF' 'I_RECORD' TEXT-051 '35'.
  PERFORM BUILD_FC USING '18' 'WEBRE' 'I_RECORD' TEXT-052 '1'.
  PERFORM BUILD_FC USING '19' 'MEPRF' 'I_RECORD' TEXT-053 '1'.
  PERFORM BUILD_FC USING '20' 'LTEX1' 'I_RECORD' TEXT-054 '40'.
  PERFORM BUILD_FC USING '21' 'DATAB' 'I_RECORD' TEXT-055 '10'.
  PERFORM BUILD_FC USING '22' 'DATBI' 'I_RECORD' TEXT-056 '10'.
  PERFORM BUILD_FC USING '23' 'KSCHL' 'I_RECORD' TEXT-057 '4'.
  PERFORM BUILD_FC USING '24' 'KBETR' 'I_RECORD' TEXT-058 '16'.
  PERFORM BUILD_FC USING '25' 'KONWA' 'I_RECORD' TEXT-059 '5'.
  PERFORM BUILD_FC USING '26' 'KPEIN' 'I_RECORD' TEXT-060 '5'.
  PERFORM BUILD_FC USING '27' 'KMEIN' 'I_RECORD' TEXT-061 '3'.
  PERFORM BUILD_FC USING '28' 'KSTBM' 'I_RECORD' TEXT-062 '19'.
  PERFORM BUILD_FC USING '29' 'KBETR_01' 'I_RECORD' TEXT-063 '16'.
  PERFORM BUILD_FC USING '30' 'DEL_FLAG' 'I_RECORD' TEXT-064 '1'.
  PERFORM BUILD_FC USING '31' 'ERR_MSG' 'I_RECORD' TEXT-027 '100'.  WA_LAYOUT-ZEBRA = 'X'.
  WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.  PERFORM SORTBUILD USING I_SORT[].  V_REPID = SY-REPID.  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
            I_CALLBACK_PROGRAM = V_REPID
            I_GRID_TITLE       = TEXT-066
            IT_FIELDCAT        = I_FIELDCAT
            IS_LAYOUT          = WA_LAYOUT
            I_DEFAULT          = 'X'
            I_SAVE             = 'X'
            IT_SORT            = I_SORT
            IT_EVENTS          = I_ALV_EVENT
       TABLES
            T_OUTTAB           = I_RECORD
       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_processed_records
*&---------------------------------------------------------------------*
*&      Form  BUILD_FC
*&---------------------------------------------------------------------*
*  Populating the Field Catalog for the ALV
*----------------------------------------------------------------------*
FORM BUILD_FC USING    VALUE(L_COPOS)
                       VALUE(L_FNAME)
                       VALUE(L_TABNAME)
                       VALUE(L_TITLE)
                       VALUE(L_WIDTH).  WA_FIELDCAT-COL_POS      = L_COPOS.
  WA_FIELDCAT-FIELDNAME    = L_FNAME.
  WA_FIELDCAT-TABNAME      = L_TABNAME.
  WA_FIELDCAT-REPTEXT_DDIC = L_TITLE.
  WA_FIELDCAT-OUTPUTLEN    = L_WIDTH.  APPEND WA_FIELDCAT TO I_FIELDCAT.
ENDFORM.                    " BUILD_FC
*&---------------------------------------------------------------------*
*&      Form  SORTBUILD
*&---------------------------------------------------------------------*
*      Sorting the fields in the ALV report
*----------------------------------------------------------------------*
FORM SORTBUILD USING I_SORT TYPE SLIS_T_SORTINFO_ALV.  CLEAR WA_SORT.
  WA_SORT-FIELDNAME = 'LIFNR'.
  WA_SORT-SPOS      = 1.
  WA_SORT-UP        = 'X'.
  APPEND WA_SORT TO I_SORT.  CLEAR WA_SORT.
  WA_SORT-FIELDNAME = 'EVART'.
  WA_SORT-SPOS      = 2.
  WA_SORT-UP        = 'X'.
  APPEND WA_SORT TO I_SORT.  CLEAR WA_SORT.
  WA_SORT-FIELDNAME = 'EKORG'.
  WA_SORT-SPOS      = 3.
  WA_SORT-UP        = 'X'.
  APPEND WA_SORT TO I_SORT.  CLEAR WA_SORT.
  WA_SORT-FIELDNAME = 'EKGRP'.
  WA_SORT-SPOS      = 4.
  WA_SORT-UP        = 'X'.
  APPEND WA_SORT TO I_SORT.  CLEAR WA_SORT.
  WA_SORT-FIELDNAME = 'WERKS'.
  WA_SORT-SPOS      = 5.
  WA_SORT-UP        = 'X'.
  APPEND WA_SORT TO I_SORT.  CLEAR WA_SORT.
  WA_SORT-FIELDNAME = 'LGORT'.
  WA_SORT-SPOS      = 6.
  WA_SORT-UP        = 'X'.
  APPEND WA_SORT TO I_SORT.  CLEAR WA_SORT.
  WA_SORT-FIELDNAME = 'EMATN'.
  WA_SORT-SPOS      = 7.
  WA_SORT-UP        = 'X'.
  APPEND WA_SORT TO I_SORT.ENDFORM.                    " SORTBUILD */
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ММ All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.