Skip to end of metadata
Go to start of metadata

*----------------------------------------------------------------------*
* PROGRAM DESCRIPTION: Inbound Idoc Interface.
*
*           DEVELOPER: Aveek Ghose
*       CREATION DATE: 2008-04-18
*          RDD NUMBER: DCDD027
* TRANSPORT NUMBER(S): RD2K902769
*
*- REVISION HISTORY -------------------------------------------------*
*
*           DEVELOPER:
*        DATE APPLIED: YYYY-MM-DD
*          SCR NUMBER:
*          RDD NUMBER:
* TRANSPORT NUMBER(S):
*         DESCRIPTION:
*
*----------------------------------------------------------------------*

 REPORT  ZGTDMI_VARTAB_IDOCS
         NO STANDARD PAGE HEADING
        LINE-SIZE   150
        LINE-COUNT  55
        MESSAGE-ID  ZFACTGLB.

* Include for Global Data Declaration
* INCLUDE ZFACTGLB_GTDMI_VARTAB_TOP.
* Include for Selection Screen
* INCLUDE ZFACTGLB_GTDMI_VARTAB_SEL.
* Include for Sub Routines
* INCLUDE ZFACTGLB_GTDMI_VARTAB_FORMS.

************************************************************************
* TYPE POOLS
************************************************************************
*Type declaration for ALV display

 TYPE-POOLS : slis.
 Include .
 type-pools: col,                                           "#EC *
             icon,                                          "#EC *
             sym.                                           "#EC *

* Target structure definitions

 TABLES:
        E1CUVTM , " Master table structure basic data
        E1DATEM , " Master Key Date and Change Number
        E1CUV1M , " Master characteristics of table line
        EDP21 , " Partner Profile: Inbound
       EDI_DC40 , " IDoc Control Record for Interface to External System
        EDI_DD40 , " IDoc Data Record for Interface to External System
        EDI_DS40 . " IDoc Status Record for Interface to External System

************************************************************************
* GLOBAL TYPES
************************************************************************

 TYPES:
        BEGIN OF TY_VARTAB.
         include structure E1CUVTM.
 TYPES:
        END OF TY_VARTAB.

 TYPES:
        BEGIN OF TY_VARTABDATE.
         INCLUDE STRUCTURE E1DATEM.
 TYPES:
        END OF TY_VARTABDATE.

*Structure for data retreived
 TYPES:
        BEGIN OF TY_VARDETAILS.
         INCLUDE STRUCTURE E1CUV1M.
 TYPES:
        END OF TY_VARDETAILS.

*Structure for data retreived from table tabinput.
 TYPES:
        BEGIN OF TY_TABINPUT,
          LINES TYPE STRING,
        END OF TY_TABINPUT.

*Structure for data retreived from Table dsn_input.
 TYPES:
        BEGIN OF TY_DSNINPUT,
          LINE(101) TYPE C,
        END OF TY_DSNINPUT.

*Structure for data retreived from Table dsn_input.
 TYPES:
        BEGIN OF TY_NEWINPUT,
          LINE(101) TYPE C,
          FLAG(1) TYPE C,
        END OF TY_NEWINPUT.

*Structure for keeping the values of all the custom tables
 TYPES:
        BEGIN OF TY_CUSTOM_TABS,
          MATNR TYPE MATNR,
          WERKS TYPE WERKS_D,
          LGORT TYPE LGORT_D,
          QUNTY TYPE P DECIMALS 2,
          DET_LOC TYPE CHAR6,
          CLASS TYPE CHAR2,
          RATE TYPE P DECIMALS 2,
        END OF TY_CUSTOM_TABS.

*Type declared for the internal table and work area which will store
*fields for error log
 TYPES:
        BEGIN OF TY_ERROR_LOG,
          MATNR TYPE MATNR,
          MTART TYPE MTART,
          SEL_DATA TYPE CHAR10,
        END OF TY_ERROR_LOG.

*Structure for keeping the output data
 TYPES:
        BEGIN OF TY_FINAL,
          VTNAM(018) TYPE C,
          CHAR1(030) TYPE C,
          CHAR2(030) TYPE C,
          CHAR3(030) TYPE C,
          CHAR4(030) TYPE C,
          CHAR5(030) TYPE C,
          CHAR6(030) TYPE C,
          CHAR7(030) TYPE C,
          CHAR8(030) TYPE C,
          CHAR9(030) TYPE C,
          CHAR10(030) TYPE C,
          CHAR11(030) TYPE C,
          CHAR12(030) TYPE C,
          CHAR13(030) TYPE C,
          CHAR14(030) TYPE C,
          CHAR15(030) TYPE C,
          FLAG(001) TYPE C,
        END OF TY_FINAL.

 TYPES:
        BEGIN OF TY_CONTENTHD,
          VTNAM(018) TYPE C,
          FLAG(001) TYPE C,
        END OF TY_CONTENTHD.

 TYPES:
        BEGIN OF TY_CONTENT,
          VTNAM(018) TYPE C,
          CHAR1(030) TYPE C,
          CHAR2(030) TYPE C,
          CHAR3(030) TYPE C,
          CHAR4(030) TYPE C,
          CHAR5(030) TYPE C,
          CHAR6(030) TYPE C,
          CHAR7(030) TYPE C,
          CHAR8(030) TYPE C,
          CHAR9(030) TYPE C,
          CHAR10(030) TYPE C,
          CHAR11(030) TYPE C,
          CHAR12(030) TYPE C,
          CHAR13(030) TYPE C,
          CHAR14(030) TYPE C,
          CHAR15(030) TYPE C,
          FLAG(001) TYPE C.
 TYPES:
          RECNR_000001 TYPE I.
 TYPES:
          RECNR_000002 TYPE I.

 TYPES:
        END OF TY_CONTENT.

 TYPES:
        BEGIN OF TY_E1CUVTM,
          MSGFN  TYPE MSGFN,
          VAR_TAB  TYPE APITABL,
          STATUS  TYPE RCUTBST,
          VTGROUP  TYPE RCUTBGR,
          AUTHSTRUC  TYPE RCUTBBE,
          AUTHENTRY  TYPE RCUFNBI,
          FLDELETE  TYPE FLLKENZ,
          DBTABNAME  TYPE TABNAME16,
          DBCONACTIVE TYPE DBCON_ACTI,
          PRESDEC  TYPE VTDCT,
        END OF TY_E1CUVTM.

 TYPES:
        BEGIN OF TY_E1CUV1M,
          MSGFN TYPE MSGFN,
          VTLINENO TYPE VTLINENO,
          VTCHARACT TYPE ATNAM,
          ATWRT TYPE ATWRT,
          ATFLV TYPE ATFLV,
          ATAWE TYPE MSEHI,
          ATFLB TYPE ATFLB,
          ATAW1 TYPE MSEHI,
          ATCOD TYPE ATCOD,
          ATTLV TYPE ATTLV,
          ATTLB TYPE ATTLB,
          ATPRZ TYPE ATPRZ,
          ATINC TYPE ATINC,
          VTLINENO5 TYPE VTLINENO5,
        END OF TY_E1CUV1M.

 TYPES:
        BEGIN OF TY_E1DATEM,
          MSGFN  TYPE MSGFN,
          KEY_DATE  TYPE SYDATUM,
          AENNR  TYPE AENNR,
          EFFECTIVITY TYPE  CC_MTEFF,
        END OF TY_E1DATEM.

 TYPES:
        BEGIN OF TY_VTNAM,
          VTINT TYPE VTINT,
          VTNAM TYPE VTNAM,
          ERROR TYPE CHAR1,
          REAS TYPE CHAR50,
        END OF TY_VTNAM.

* Get data type for characteristic
 TYPES:
        BEGIN OF TY_CABN,
          ATINN TYPE ATINN,
          ATNAM TYPE ATNAM,
          ATFOR TYPE ATFOR,
          ATSON TYPE ATSON,
          ATPRT TYPE ATPRT,
          ATPRR TYPE ATPRR,
          ATPRF TYPE ATPRF,
          ANZDZ TYPE ANZDZ,
          CHECK TYPE CHAR1,
        END OF TY_CABN.

* Get field names of variant table
 TYPES:
        BEGIN OF TY_CUVTAB_FLD,
          VTINT TYPE VTINT,
          ATINN TYPE ATINN,
          VTPOS TYPE VTPOS,
          EXIST TYPE CHAR1,
        END OF TY_CUVTAB_FLD.

* Store all data in internal table
 TYPES:
        BEGIN OF TY_FILE,
          VTNAM TYPE VTNAM,
          CHAR1 TYPE ATWRT,
          CHAR2 TYPE ATWRT,
          CHAR3 TYPE ATWRT,
          CHAR4 TYPE ATWRT,
          CHAR5 TYPE ATWRT,
          CHAR6 TYPE ATWRT,
          CHAR7 TYPE ATWRT,
          CHAR8 TYPE ATWRT,
          CHAR9 TYPE ATWRT,
          CHAR10 TYPE ATWRT,
          CHAR11 TYPE ATWRT,
          CHAR12 TYPE ATWRT,
          CHAR13 TYPE ATWRT,
          CHAR14 TYPE ATWRT,
          CHAR15 TYPE ATWRT,
          FLAG TYPE CHAR1,
          ERROR TYPE CHAR50,
        END OF TY_FILE.

* To check for duplicates
 TYPES:
        BEGIN OF TY_DUPL,
          VTNAM TYPE VTNAM,
          CHAR1 TYPE ATWRT,
          CHAR2 TYPE ATWRT,
          CHAR3 TYPE ATWRT,
          CHAR4 TYPE ATWRT,
          CHAR5 TYPE ATWRT,
          CHAR6 TYPE ATWRT,
          CHAR7 TYPE ATWRT,
          CHAR8 TYPE ATWRT,
          CHAR9 TYPE ATWRT,
          CHAR10 TYPE ATWRT,
          CHAR11 TYPE ATWRT,
          CHAR12 TYPE ATWRT,
          CHAR13 TYPE ATWRT,
          CHAR14 TYPE ATWRT,
          CHAR15 TYPE ATWRT,
          SLNID TYPE SLNID,
        END OF TY_DUPL.

* Get previously loaded characteristic values for internal table (CHAR)
 TYPES:
        BEGIN OF TY_CUVTAB_VALC,
          VTINT TYPE VTINT,
          SLNID TYPE SLNID,
          ATINN TYPE ATINN,
          VALC TYPE ATWRT,
        END OF TY_CUVTAB_VALC.

* Get previously loaded characteristic values for internal table (NUM)
 TYPES:
        BEGIN OF TY_CUVTAB_VALN,
          VTINT TYPE VTINT,
          SLNID TYPE SLNID,
          ATINN TYPE ATINN,
          VAL_FROM TYPE ATFLV,
        END OF TY_CUVTAB_VALN.

* Store column positions of characteristics
 TYPES:
        BEGIN OF TY_COL_POS,
          VTINT TYPE VTINT,
          VTNAM TYPE VTNAM,
          ATINN TYPE ATINN,
          ATNAM TYPE ATNAM,
          FIELD TYPE FIELDNAME,
          REQ TYPE CHAR1,
          VTPOS TYPE VTPOS,
        END OF TY_COL_POS.

* Store valid values for characteristics
 TYPES:
        BEGIN OF TY_CAWN,
          ATINN TYPE ATINN,
          ATZHL TYPE ATZHL,
          ATWRT TYPE ATWRT,
          ATFLV TYPE ATFLV,
          LKENZ TYPE LKENZ,
        END OF TY_CAWN.

* Store error messages for individual lines
 TYPES:
        BEGIN OF TY_ERROR,
          VTNAM TYPE VTNAM,
          FNAME TYPE FIELDNAME,
          ATNAM TYPE ATNAM,
          ATWRT TYPE ATWRT,
          ROW TYPE CHAR5,
        END OF TY_ERROR.

* Begin TPR# 4618
* To store unique number for variant
 TYPES:
        BEGIN OF TY_VNT_MA,
          VTNAM TYPE VTNAM,
* UNIQUE_NO TYPE /FACTGLB/GTDM_UNQN,
*         no_chr    TYPE /FACTGLB/GTDM_NO_CHR,
          UNIQUE_NO TYPE ZGTDM_UNQN,
          NO_CHR TYPE ZGTDM_NO_CHR,
        END OF TY_VNT_MA.

* To find out concatenated number for
 TYPES:
        BEGIN OF TY_SPLIT,
          F1 TYPE CHAR6,
        END OF TY_SPLIT.

 TYPES:
        BEGIN OF TY_CHARVAL,
          CHAR TYPE CHAR30,
        END OF TY_CHARVAL.

 TYPES:
          TUMLS_MESSTYPE LIKE /SAPDMC/LSSCREEN-MESSTYPE , " Message Type
         TUMLS_MESSTYPETXT LIKE /SAPDMC/LSSCREEN-MESSTYPETXT , " Short d
          TUMLS_MESSCODE LIKE EDK21-MESCOD. " Message code

 TYPES:
          TUMLS_TABNAME LIKE DFIES-TABNAME , " Table Name
          TUMLS_SEGMENT LIKE DFIES-TABNAME. " Table Name

 TYPES:
         TUMLS_PATHFILE LIKE /SAPDMC/LSOINP-FILENAME , " File Name (with
         TUMLS_FILENAME LIKE /SAPDMC/LSOINP-FILENAME , " File Name (with
         TUMLS_FILETEXT LIKE /SAPDMC/LSOINP-FILETEXT. " File description

 TYPES:
        BEGIN OF TYPE_ERRORLINE,
          MSGTY LIKE SY-MSGTY , " Message Type
          ID LIKE SY-MSGID , " Message Class
          MSGNO LIKE SY-MSGNO , " Message Number
          PAR1 LIKE SY-MSGV1 , " Message Variable
          PAR2 LIKE SY-MSGV2 , " Message Variable
          PAR3 LIKE SY-MSGV3 , " Message Variable
          PAR4 LIKE SY-MSGV4 , " Message Variable
        END OF TYPE_ERRORLINE.

TYPES:
   type_errortab TYPE SORTED TABLE
                 OF type_errorline
                 WITH NON-UNIQUE KEY id msgno par1 par2 par3 par4.

* TYPES:
* TYPE_ERRORTAB TYPE SORTED TABLE OF TYPE_ERRORLINE. " WITH NON-UNIQUE .
***********************************************************************
* GLOBAL INTERNAL TABLES
************************************************************************
 DATA:
          I_NEWINPUT TYPE STANDARD TABLE OF TY_NEWINPUT.
 DATA:
        I_CONTENTHEADER1 TYPE STANDARD TABLE OF TY_CONTENTHD.
 DATA:
        I_CONTENTTAB1 TYPE STANDARD TABLE OF TY_CONTENT.
                                                            "#EC NEEDED
 DATA:
        I_CONTENTTAB2 TYPE STANDARD TABLE OF TY_CONTENT.
 .                                                          "#EC NEEDED
 DATA:
        I_CONTENTTAB3 TYPE STANDARD TABLE OF TY_CONTENT.
 .                                                          "#EC NEEDED
 DATA:
        I_CONTENTTAB4 TYPE STANDARD TABLE OF TY_CONTENT.
 .                                                          "#EC NEEDED
 DATA:
        I_CONTENTTAB5 TYPE STANDARD TABLE OF TY_CONTENT.
 .                                                          "#EC NEEDED
 DATA:
        I_E1CUV1M TYPE STANDARD TABLE OF E1CUV1M.
 DATA:
        I_ERRORTAB TYPE STANDARD TABLE OF SOLISTI1.

************************************************************************
* GLOBAL WORK AREAS
************************************************************************

**Internal Table for the structure TY_T001L
 DATA:
        WA_VARTAB TYPE TY_VARTAB.
 DATA:
        WA_VARTABDATE TYPE TY_VARTABDATE.
 DATA:
        WA_VARDETAILS TYPE TY_VARDETAILS.
 DATA:
        WA_TABINPUT TYPE TY_TABINPUT.
 DATA:
        WA_DSNINPUT TYPE TY_DSNINPUT.
 DATA:
        WA_NEWINPUT TYPE TY_NEWINPUT.
 DATA:
        WA_GNEWINPUT TYPE TY_NEWINPUT.
 DATA:
        WA_GINPUT_DATA TYPE TY_NEWINPUT.
 DATA:
        WA_FINAL TYPE TY_FINAL.
 DATA:
        WA_CONTENT TYPE TY_CONTENT.
 DATA:
        WA_CONTENTHD TYPE TY_CONTENTHD.
 DATA:
        WA_CONTENTHEADER TYPE TY_CONTENTHD.
 DATA:
        WA_CONTENTTAB TYPE TY_CONTENT.
 DATA:
        WA_CONTENT1 TYPE TY_CONTENT.
 DATA:
        WA_CONTENTHD1 TYPE TY_CONTENTHD.
 DATA:
        WA_CONTENTHEADER1 TYPE TY_CONTENTHD.
 DATA:
        WA_CONTENTTAB1 TYPE TY_CONTENT.
 DATA:
        WA_CONTENTTAB2 TYPE TY_CONTENT.
 DATA:
        WA_CONTENTTAB3 TYPE TY_CONTENT.
 DATA:
        WA_CONTENTTAB4 TYPE TY_CONTENT.
 DATA:
        WA_CONTENTTAB5 TYPE TY_CONTENT.
 DATA:
        WA_E1CUVTM TYPE E1CUVTM.
 DATA:
        WA_E1CUV1M TYPE E1CUV1M.
 DATA:
        WA_E1DATEM TYPE E1DATEM.
 DATA:
        WA_ERROR_TAB TYPE SOLISTI1.

************************************************************************
* INTERNAL TABLES AND WORK AREAS FOR BDC
************************************************************************

*Internal Table to store the data to display the error message
 DATA:
        I_ERRORMSG TYPE STANDARD TABLE OF SOLISTI1.

*Internal Table to store the data to display the error message
 DATA:
        I_ERROR TYPE STANDARD TABLE OF SOLISTI1.

**Work area to store the data to display the error message
 DATA:
        WA_ERRORMSG TYPE SOLISTI1.

**Internal table which will store data for the error log
 DATA:
        I_ERROR_LOG TYPE STANDARD TABLE OF TY_ERROR_LOG.

************************************************************************
* GLOBAL VARIABLES
************************************************************************

 DATA:
        G_FILE TYPE STRING.
 DATA:
        G_CTR_INPUT_RECS(5) TYPE C.
 DATA:
        G_CTR_OUTPUT_RECS(5) TYPE P.
 DATA:
        G_MSG(100) TYPE C.
 DATA:
        G_LOGIN TYPE FILEINTERN.
 DATA:
        G_PHYIN TYPE STRING.
 DATA:
        G_LPRNT TYPE RSPOPSHORT.
 DATA:
        G_FNAME1 TYPE STRING.
 DATA:
        G_REPID LIKE SY-REPID,
        G_EXIT(1) TYPE C,
        GX_VARIANT LIKE DISVARIANT.
 DATA:
        G_LINES TYPE I.
 DATA:
        G_SAVE(1) TYPE C.
 DATA:
        G_SPLID TYPE RSPOID.
 DATA:
        P_LOGIN TYPE FILEINTERN.
 DATA:
        P_PHYIN TYPE STRING.

************************************************************************
* GLOBAL CONSTANTS
************************************************************************

 CONSTANTS:
        C_MSGAR TYPE RSLGAREA VALUE 'F8'.
 CONSTANTS:
        C_MSGID TYPE RSLGSUBID VALUE 'E'.
 CONSTANTS:
        C_URGNC TYPE CHAR04 VALUE 'HIGH'.
 CONSTANTS:
        C_X(1) TYPE C VALUE 'X'.
 CONSTANTS:
        C_Z(1) TYPE C VALUE 'Z'.
 CONSTANTS:
        C_Y(1) TYPE C VALUE 'Y'.
 CONSTANTS:
        C_E(1) TYPE C VALUE 'E'.
 CONSTANTS:
        C_SAP(3) TYPE C VALUE 'SAP'.
 CONSTANTS:
        C_MOD(3) TYPE C VALUE 'MOD'.
 CONSTANTS:
        C_MD1(3) TYPE C VALUE 'MD1'.
 CONSTANTS:
        C_MD2(3) TYPE C VALUE 'MD2'.
 CONSTANTS:
        C_MD3(3) TYPE C VALUE 'MD3'.
 CONSTANTS:
        C_000001(6) TYPE C VALUE '000001',
        C_E1CUV1M(7) TYPE C VALUE 'E1CUV1M',
        C_02(2) TYPE C VALUE '02',
        C_009(3) TYPE C VALUE '009',
        C_0001(4) TYPE C VALUE '0001'.

 CONSTANTS:
        C_E1DATEM(7) TYPE C VALUE 'E1DATEM'.
 CONSTANTS:
        C_E1CUVTM(7) TYPE C VALUE 'E1CUVTM'.

************************************************************************
* GLOBAL INTERNAL TABLES FOR ALV DISPLAY
************************************************************************

*Internal tables for ALV Field cat
 DATA:
        I_FIELDCAT_OV TYPE STANDARD TABLE OF SLIS_FIELDCAT_ALV,
        I_FIELDCAT_DTL TYPE STANDARD TABLE OF SLIS_FIELDCAT_ALV,
 i_fieldcat_ov1 TYPE lvc_t_fcat,                            "#EC NEEDED
 i_events       TYPE slis_t_event.                          "#EC NEEDED

************************************************************************
* GLOBAL WORK AREAS FOR ALV DISPLAY
************************************************************************

*Work area for ALV Field layout
 DATA:
        WA_LAYOUT TYPE SLIS_LAYOUT_ALV.
*Work area for Field Cat. Table
 DATA:
        WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

************************************************************************
* GLOBAL VARIABLES FOR ALV DISPLAY
************************************************************************
 DATA:
        G_EVENT TYPE SLIS_T_EVENT.
 DATA:
        G_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.
 DATA:
        G_OK_CODE TYPE CHAR4.
 DATA:
        G_VARIANT LIKE DISVARIANT.

************************************************************************
* GLOBAL CONSTANTS FOR ALV DISPLAY
************************************************************************
* BAL handling
 DATA:
        IV_LOG_HANDLE TYPE BALLOGHNDL.
 DATA:
        IS_LOG_HEADER TYPE BAL_S_LOG.
 DATA:
        IV_OBJECT TYPE BAL_S_LOG-OBJECT VALUE 'CAPI'.
 DATA:
        IV_SUBOBJECT TYPE BAL_S_LOG-SUBOBJECT VALUE 'CAPI_LOG'.
                                                            "#EC NEEDED
 DATA:
        IV_TCODE TYPE BAL_S_LOG-ALTCODE VALUE 'SE38'.

********************************************************************
*MOD-005
********************************************************************

 RANGES:
     R_MESTYP FOR EDIDC-MESTYP,
     R_CREDAT FOR EDIDC-CREDAT,
     R_CRETIM FOR EDIDC-CRETIM,
     R_SNDPRT FOR EDIDC-SNDPRT,         " Partnerart (Sender)
     R_SNDPRN FOR EDIDC-SNDPRN.         " Partnernummer (Sender)

 DATA:
        L_MESSTYPE TYPE TUMLS_MESSTYPE.
********************************************************************
*MOD-005
********************************************************************
 DATA:
        P_SNDPRN TYPE EDI_SNDPRN,
        P_SNDPRT TYPE EDI_SNDPRT,
        P_SNDPOR TYPE EDI_SNDPOR.

 DATA:
        P_RCVPRN TYPE EDI_RCVPRN,
        P_RCVPRT TYPE EDI_RCVPRT,
        P_RCVPOR TYPE EDI_RCVPOR.
 DATA:
        INIT_E1CUVTM LIKE E1CUVTM,
        PREV_E1CUVTM LIKE E1CUVTM,
        INIT_E1DATEM LIKE E1DATEM,
        PREV_E1DATEM LIKE E1DATEM,
        INIT_E1CUV1M LIKE E1CUV1M,
        PREV_E1CUV1M LIKE E1CUV1M.

* Source structure definitions
 DATA:
        BEGIN OF LSMW_TAB_CONTENT,
          VTNAM(018) TYPE C,
          CHAR1(030) TYPE C,
          CHAR2(030) TYPE C,
          CHAR3(030) TYPE C,
          CHAR4(030) TYPE C,
          CHAR5(030) TYPE C,
          CHAR6(030) TYPE C,
          CHAR7(030) TYPE C,
          CHAR8(030) TYPE C,
          CHAR9(030) TYPE C,
          CHAR10(030) TYPE C,
          CHAR11(030) TYPE C,
          CHAR12(030) TYPE C,
          CHAR13(030) TYPE C,
          CHAR14(030) TYPE C,
          CHAR15(030) TYPE C,
          FLAG(001) TYPE C,
        END OF LSMW_TAB_CONTENT.

* Counters
 DATA:
        G_CNT_VAR_TAB TYPE I,
        G_CNT_TAB_CONTENT TYPE I.

* Counter ct_xxxxxxxxxx: number of transferred records
 DATA:
        CT_EDI_DC40 TYPE I,
        CS_EDI_DC40 TYPE I,
        CT_E1CUVTM TYPE I,
        CS_E1CUVTM TYPE I,
        CT_E1DATEM TYPE I,
        CS_E1DATEM TYPE I,
        CT_E1CUV1M TYPE I,
        CS_E1CUV1M TYPE I.

* Global data definitions and data declarations

 DATA:
        WA_CABN TYPE TY_CABN,
        WA_CAWN TYPE TY_CAWN,
        WA_FILE TYPE TY_FILE,
        WA_VTNAM TYPE TY_VTNAM,
        WA_CUVTAB_FLD TYPE TY_CUVTAB_FLD,
        WA_CUVTAB_VALN TYPE TY_CUVTAB_VALN,
        WA_CUVTAB_VALC TYPE TY_CUVTAB_VALC,
        WA_COL_POS TYPE TY_COL_POS,
        WA_ERROR TYPE TY_ERROR,
        WA_DUPL TYPE TY_DUPL,
        WA_DUPL_FILE TYPE TY_DUPL.

 DATA:
        WA_VNT_MA TYPE TY_VNT_MA,
        WA_SPLIT TYPE TY_SPLIT.

 DATA:
        WA_CHARVAL TYPE TY_CHARVAL.

*----------Internal table
 DATA:
        I_CABN TYPE STANDARD TABLE OF TY_CABN,
        I_CABN_TEMP TYPE STANDARD TABLE OF TY_CABN,
        I_CABN_ATINN TYPE STANDARD TABLE OF TY_CABN,
        I_FILE TYPE STANDARD TABLE OF TY_FILE,
        I_FILE_TMP TYPE STANDARD TABLE OF TY_FILE,
        I_VTNAM TYPE STANDARD TABLE OF TY_VTNAM,
        I_CUVTAB TYPE STANDARD TABLE OF TY_VTNAM,
        I_CUVTAB_FLD TYPE STANDARD TABLE OF TY_CUVTAB_FLD,
        I_CUVTAB_VALN TYPE STANDARD TABLE OF TY_CUVTAB_VALN,
        I_CUVTAB_VALC TYPE STANDARD TABLE OF TY_CUVTAB_VALC,
        I_COL_POS TYPE STANDARD TABLE OF TY_COL_POS,
        I_CAWN TYPE STANDARD TABLE OF TY_CAWN,
        I_CAWN_N TYPE STANDARD TABLE OF TY_CAWN,
        I_CAWN_C TYPE STANDARD TABLE OF TY_CAWN,
        I_CAWN_I TYPE STANDARD TABLE OF TY_CAWN,
        I_CUV_ERROR TYPE STANDARD TABLE OF TY_VTNAM,
        I_DUPL TYPE STANDARD TABLE OF TY_DUPL.

 DATA:
        I_VNT_MA TYPE STANDARD TABLE OF TY_VNT_MA,
        I_SPLIT TYPE STANDARD TABLE OF TY_SPLIT.

 DATA:
        I_DUPL_FILE TYPE STANDARD TABLE OF TY_DUPL.

 DATA:
        I_CHARVAL TYPE STANDARD TABLE OF TY_CHARVAL.

*---------- Constants
 CONSTANTS:
        C_CHAR TYPE ATFOR VALUE 'CHAR',
        C_DATE TYPE ATFOR VALUE 'DATE',
        C_TIME TYPE ATFOR VALUE 'TIME',
        C_VARCOND TYPE ATNAM VALUE 'Z_VARCOND'.

*--------- Field Symbols
 FIELD-SYMBOLS:       TYPE ty_vtnam,              "#EC NEEDED
                       TYPE ty_cabn,               "#EC NEEDED
                 TYPE ty_cuvtab_fld,         "#EC NEEDED
                       TYPE ty_dupl.               "#EC NEEDED

*-------- Variables
 DATA:
        G_RAW(500) TYPE C,
        G_INVALID TYPE CHAR1,
        G_ERROR TYPE CHAR1,
        G_MESSAGE TYPE CHAR50,
        G_SLNID_C TYPE SLNID,
        G_SLNID_N TYPE SLNID,
        G_ROW TYPE CHAR5.

 DATA:
        G_VARCOND TYPE VARCOND,
        G_SPLIT_VAR TYPE I.

 TYPES:
        BEGIN OF TY_CHARNAME,
          NAME TYPE ATNAM,
        END OF TY_CHARNAME.

 DATA:
        WA_CHARNAME TYPE TY_CHARNAME,
        I_CHARNAME TYPE STANDARD TABLE OF TY_CHARNAME.
 DATA:
        CNT_I TYPE I,
        G_TABIX TYPE CHAR10.

 TYPES:
        BEGIN OF TY_ITAB_ZEDIDC40.
         include structure edi_dc40.
 TYPES:
        END OF TY_ITAB_ZEDIDC40.

 TYPES:
        BEGIN OF TY_ITAB_ZEDIDD40.
         include structure edi_dd40.
 TYPES:
        END OF TY_ITAB_ZEDIDD40.

 DATA:
        ITAB_ZEDIDC40 TYPE STANDARD TABLE OF TY_ITAB_ZEDIDC40 INITIAL
        SIZE 0.

 DATA:
        ITAB_ZEDIDD40 TYPE STANDARD TABLE OF TY_ITAB_ZEDIDD40 INITIAL
        SIZE 0.

 DATA:
        WA_ITAB_ZEDIDC40 TYPE TY_ITAB_ZEDIDC40.

 DATA:
        WA_ITAB_ZEDIDD40 TYPE TY_ITAB_ZEDIDD40.

 DATA:
        ITAB_ZE1CUVTM LIKE E1CUVTM,
        ITAB_ZE1DATEM LIKE E1DATEM,
        ITAB_ZE1CUV1M LIKE E1CUV1M.

 DATA:
        WDOCNUM(16) TYPE N VALUE 0.
 DATA:
        WSEGNUM(6) TYPE N VALUE 0.
 DATA:
        WITEMNO(10) TYPE N VALUE 0.
 DATA:
        WITEMNO_NEW(10) TYPE N VALUE 0.
 DATA:
        WITEMNO_GST(10) TYPE N VALUE 0.
 DATA:
        WITEMNO_QST(10) TYPE N VALUE 0.
 TYPES:
        BEGIN OF TY_INPUT_DATA1,
          LINE(255) TYPE C,
          FLAG(1) TYPE C,
        END OF TY_INPUT_DATA1.

 DATA:
        I_INPUT_DATA TYPE STANDARD TABLE OF TY_INPUT_DATA1 INITIAL
        SIZE 0.

 DATA:
        I_INPUT_DATA1 TYPE STANDARD TABLE OF TY_INPUT_DATA1 INITIAL
        SIZE 0.

 DATA:
        WA_INPUT_DATA TYPE TY_INPUT_DATA1.
 DATA:
        G_CNT_INPUT_RECS TYPE I.
 DATA:
        G_FLG_ERROR TYPE C.
 DATA:
        L_LINES TYPE I.
 DATA:
        L_TABIX TYPE I.
 DATA:
        WA_INPUT_DATA1 TYPE TY_INPUT_DATA1.

 DATA:
        FILE TYPE STRING.
* Fields that are made available to the user:
 DATA:
        G_CNT_RECORDS_READ TYPE I,
        G_CNT_RECORDS_TRANSFERRED TYPE I,
        G_CNT_TRANSACTIONS_READ TYPE I,
        G_CNT_TRANSACTIONS_TRANSFERRED TYPE I,
        G_CNT_IDOCS_PACKAGE TYPE I.

 DATA:
        V_LOG_HANDLE TYPE BALLOGHNDL.

 DATA:
        GT_CURR_EDI_DC40 TYPE STANDARD TABLE OF EDI_DC40 INITIAL SIZE 0.
 DATA:
        GT_CURR_EDI_DD40 TYPE STANDARD TABLE OF EDI_DD40 INITIAL SIZE 0.

 DATA:
        WA_CURR_EDI_DC40 TYPE EDI_DC40.
 DATA:
        WA_CURR_EDI_DD40 TYPE EDI_DD40.

* internal table for error messages during conversion
 DATA:
        G_ERROR_TAB TYPE TYPE_ERRORTAB,
        WA_ERRORTAB TYPE TYPE_ERRORLINE.

 DATA:
        G_EDIDD_SEGNAM LIKE EDI_DD40-SEGNAM, " Segment (external name)
       G_EDIDD_HLEVEL LIKE EDI_DD40-HLEVEL. " Hierarchy level of SAP seg

 DATA:
        G_SEGNUM(6) TYPE N.
 DATA:
        G_OBJECTTYPE(2) TYPE C.

************************************************************************
* INITIALIZATION
************************************************************************
************************************************************************
* DECLARATION FOR SELECTION SCREEN
************************************************************************
*---------------------------------------------------------------------
*selection-screen skip 1.
*---------------------------------------------------------------------
*SELECTION-SCREEN BEGIN OF BLOCK bl5 WITH FRAME TITLE text-035.
**
*parameters:
**  p_trfc   TYPE /SAPDMC/LS_TRFCPORT obligatory,
**  p_ptype  TYPE EDIPPARTYP obligatory,
**  p_sndpr  TYPE EDIPPARNUM obligatory,
*   p_rcvpr  TYPE EDIPPARNUM obligatory.
**  p_mestyp TYPE EDI4MESTYP obligatory,
**  p_idoc   TYPE EDI4IDOCTP obligatory.
*SELECTION-SCREEN END OF BLOCK bl5.
*

 SELECTION-SCREEN BEGIN OF BLOCK bl3 WITH FRAME TITLE text-032.
*  Radio Buttons :
 parameters:
   rb_apsrv RADIOBUTTON GROUP RB1  DEFAULT 'X' USER-COMMAND UCOM,
   rb_prsrv RADIOBUTTON GROUP RB1.

 SELECTION-SCREEN END OF BLOCK bl3.

*For all the input field entries
 SELECTION-SCREEN BEGIN OF BLOCK bl1 WITH FRAME TITLE text-001.
*Parameter for Input File Name:
 PARAMETERS:   p_inpt   TYPE RLGRAP-FILENAME MODIF ID MOD .
 PARAMETERS:   p_inpt1  TYPE RLGRAP-FILENAME MODIF ID MOD .
 SELECTION-SCREEN END OF BLOCK bl1.

 SELECTION-SCREEN BEGIN OF BLOCK bl2 WITH FRAME TITLE text-030.
 parameters :  p_fpath  type filename-FILEINTERN MODIF ID MD1 .
 "Logical Filepath
 PARAMETERS :  P_fname  TYPE LOCALFILE MODIF ID MD1 .
 " Physical File path
 parameters :  p_fpath1 type filename-FILEINTERN MODIF ID MD1 .
 "Logical Filepath
 PARAMETERS :  P_fname1 TYPE LOCALFILE MODIF ID MD1  .
 " Physical File path

 SELECTION-SCREEN END OF BLOCK bl2.

 SELECTION-SCREEN BEGIN OF BLOCK bl4 WITH FRAME TITLE text-033.
 parameters:
   p_upload as checkbox default C_X MODIF ID MD2,
* Input file from NT server
   p_inbd as checkbox default C_X MODIF ID MD2,
* Create idocs
   p_proc as checkbox default C_X MODIF ID MD2.
 SELECTION-SCREEN END OF BLOCK bl4.

** IDoc creation
 selection-screen begin of block idocpars
                  with frame title text-006.
 parameters:
    p_trfcpt as checkbox default C_X MODIF ID MD3,
    p_packge(5) type n default 1 MODIF ID MD3.
 selection-screen end of block idocpars.

************************************************************************
* INITIALIZATION
************************************************************************

 INITIALIZATION.

*Initialization of all the Global Variables
   PERFORM sub_refresh_variables.

   CONCATENATE C_SAP sy-sysid INTO p_rcvpor.
   CONCATENATE C_SAP sy-sysid INTO p_rcvprn.

   CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'                   "#EC *
        IMPORTING
             own_logical_system             = p_rcvprn
        EXCEPTIONS
             own_logical_system_not_defined = 1
             OTHERS                         = 2.

************************************************************************
* Check selection-screen entries *
************************************************************************

 AT SELECTION-SCREEN.

   PERFORM sub_get_physical_file USING p_fpath p_fname.

   PERFORM sub_get_physical_file1 USING p_fpath1 p_fname1.

************************************************************************
* AT SELECTION SCREEN
************************************************************************
 AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.
   PERFORM sub_get_file. " CHANGING p_fname.         "#EC *

 AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname1.
   PERFORM sub_get_file1. " CHANGING p_fname1.       "#EC *

 AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_INPT.

   CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
     EXPORTING
       STATIC        = C_X
     CHANGING
       FILE_NAME     = P_INPT
     EXCEPTIONS
       MASK_TOO_LONG = 1
       OTHERS        = 2.

   IF SY-SUBRC <> 0.
     MESSAGE e241.
   ENDIF.

 AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_INPT1.

   CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
     EXPORTING
       STATIC        = C_X
     CHANGING
       FILE_NAME     = P_INPT1
     EXCEPTIONS
       MASK_TOO_LONG = 1
       OTHERS        = 2.

   IF SY-SUBRC <> 0.
     MESSAGE e241.
   ENDIF.

*&---------------------------------------------------------------------*
* At Selection Screen Output
*&---------------------------------------------------------------------*

 AT SELECTION-SCREEN OUTPUT.

   IF rb_apsrv = 'X'.
     LOOP AT SCREEN.
       IF SCREEN-GROUP1 = c_mod.
         SCREEN-INPUT = 0.
       ENDIF.
       IF SCREEN-GROUP1 = c_md2.
         SCREEN-INPUT = 0.
       ENDIF.
       IF SCREEN-GROUP1 = c_md3.
         SCREEN-INPUT = 0.
       ENDIF.
       MODIFY SCREEN.
     ENDLOOP.
   endif.

   IF rb_prsrv = 'X'.
     LOOP AT SCREEN.
       IF SCREEN-GROUP1 = c_md1.
         SCREEN-INPUT = 0.
       ENDIF.
       IF SCREEN-GROUP1 = c_md2.
         SCREEN-INPUT = 0.
       ENDIF.
       IF SCREEN-GROUP1 = c_md3.
         SCREEN-INPUT = 0.
       ENDIF.
       MODIFY SCREEN.
     ENDLOOP.
   endif.

************************************************************************
* START-OF-SELECTION
************************************************************************

 START-OF-SELECTION.

*Subroutines for start of selection event
   PERFORM sub_start_selection.

   PERFORM sub_upload_data.

* Get characteristic details
   PERFORM sub_get_cabn.

* Get value for characteristics
   PERFORM sub_get_cawn.

**************************************************************
*MOD-008
**************************************************************
   perform sub_convert_transaction.

*  IF g_error <> c_x.
*    PERFORM SUB_CREATE_IDOCS.
*    PERFORM SUB_START_IDOC_PROCESS.
*  ENDIF.

 END-OF-SELECTION.
************************************************************************
* END OF SELECTION
************************************************************************

* Final message
   perform sub_final_message_idoc.

* Display errorneous variant tables.
   perform sub_display_variant.

* Display lines with incorrect data
   perform sub_display_errorlines.

*Subroutines for end of selection event
   PERFORM sub_end_selection.

   perform sub_clear_source_tables.

*&---------------------------------------------------------------------*
*&  Include           ZFACTGLB_GTDMI_VARTAB_FORMS
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*&  Include           /FACTGLB/GTDMI_VARTAB_FORMS
*&---------------------------------------------------------------------*

*----------------------------------------------------------------------*
* PROGRAM DESCRIPTION: Variant Table and Content Upload Interface.
*
*           DEVELOPER: Aveek Ghose
*       CREATION DATE: 2008-04-18
*          RDD NUMBER: DCDD027
* TRANSPORT NUMBER(S): RD2K902769
*
*- REVISION HISTORY -------------------------------------------------*
*
*           DEVELOPER:
*        DATE APPLIED: YYYY-MM-DD
*          SCR NUMBER:
*          RDD NUMBER:
* TRANSPORT NUMBER(S):
*         DESCRIPTION:
*
*----------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*&      Form  sub_refresh_variables
*&---------------------------------------------------------------------*
*   This Subroutien Rfreshes all the Global Variables, Internal Tables
*   and Work Areas usd in this program
*----------------------------------------------------------------------*

 FORM sub_refresh_variables .
**********************************
** REFRESH GLOBAL INTERNAL TABLES
**********************************

****************************
* REFRESH GLOBAL WORK AREAS
****************************

*Work Area for the structure I_MESSTAB
   CLEAR:  wa_vartab,
           wa_vartabdate,
           wa_vardetails,
           wa_tabinput,
           wa_dsninput,
           wa_dsninput,
           wa_newinput,
           wa_gnewinput,
           wa_ginput_data ,
           wa_final,
           wa_content,
           wa_contenthd ,
           wa_contentheader,
           wa_contenttab,
           wa_content1,
           wa_contenthd1,
           wa_contentheader1,
           wa_contenttab1,
           wa_E1CUVTM ,
           wa_E1CUV1M ,
           wa_E1DATEM .

*************************************************
* REFRESH INTERNAL TABLES AND WORK AREAS FOR BDC
*************************************************

*Internal Table to store the data to display the error message
   REFRESH i_errormsg[] .

*Internal Table to store the data to display the error message
   REFRESH i_error[].

**Work area to store the data to display the error message
   CLEAR wa_errormsg.

*Internal table which will store data for the error log
   REFRESH i_error_log[] .

***************************
* REFRESH GLOBAL VARIABLES
***************************
   CLEAR: g_ctr_input_recs,
          g_ctr_output_recs,
          g_msg,
*        g_struct_file,
          g_login,
          g_phyin ,
          g_FNAME1,
          g_repid,
          g_exit,
          gx_variant,
          g_lines ,
          g_save,
          g_splid ,
          p_login ,
          p_phyin.

*************************************************
* REFRESH GLOBAL INTERNAL TABLES FOR ALV DISPLAY
*************************************************
*Refresh Internal tables for ALV Field cat
   REFRESH i_fieldcat_ov[].
   REFRESH i_fieldcat_dtl[].
   REFRESH i_fieldcat_ov1[].
   REFRESH i_events[].

********************************************
* REFRESH GLOBAL WORK AREAS FOR ALV DISPLAY
********************************************
*Work area for ALV Field layout
   CLEAR  wa_layout.
*Work area for Field Cat. Table
   CLEAR  wa_fieldcat.

   CLEAR:
      g_cnt_records_read,
      g_cnt_records_transferred,
      g_cnt_transactions_read,
      g_cnt_transactions_transferred.

 ENDFORM.                    " sub_refresh_variables

*
*&---------------------------------------------------------------------
*&      Form  sub_populate_syslog
*&---------------------------------------------------------------------
*        Populate the error message
*----------------------------------------------------------------------*
 FORM sub_populate_syslog. " TABLES i_error STRUCTURE solisti1. "#EC *

   CONSTANTS:
          C_LP01(4) TYPE C VALUE 'LP01'.
   DATA:
          C_99 TYPE I VALUE 99.
   g_repid = sy-repid.
   g_lprnt = c_lp01.

   DESCRIBE TABLE i_errortab LINES g_lines.

   IF g_lines GT 0.

* To display the Text data in Spool
     CALL FUNCTION 'RSPO_SX_OUTPUT_TEXTDATA'
       EXPORTING
         dest           = g_lprnt
         rows           = g_lines
         startrow       = 1
         pages          = c_99
         rqtitle        = text-029
         immediately    = space
       IMPORTING
         rqid           = g_splid
       TABLES
         text_data      = i_errortab
       EXCEPTIONS
         name_missing   = 1
         name_twice     = 2
         not_found      = 3
         illegal_layout = 4
         internal_error = 5
         size_mismatch  = 6
         OTHERS         = 7.                                "#EC NOTEXT

     IF sy-subrc EQ 0.
       g_repid = sy-repid.

* To write the spool number of the error log to System log
       CALL FUNCTION 'RSLG_WRITE_SYSLOG_ENTRY'
         EXPORTING
           data_word1         = c_urgnc      " Urgency
           data_word2         = g_splid      " Spool Number
           data_word3         = g_repid      " Program Name
           sl_message_area    = c_msgar      " Message Area
           sl_message_subid   = c_msgid
         EXCEPTIONS
           data_missing       = 1     " Third character of msg area
           data_words_problem = 2
           other_problem      = 3
           pre_params_problem = 4
           OTHERS             = 5.
       IF sy-subrc NE 0.
         MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
       ENDIF.

     ENDIF.
   ENDIF.

 ENDFORM.                    " sub_populate_syslog

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

   CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'                "#EC *
     EXPORTING
       percentage = 0
       text       = text-005.

   if rb_apsrv  = 'X'.
* Upload from application server
     perform sub_upload_from_appserver.
   else.
* Upload from presentation server
     perform sub_upload_from_preserver.
   endif.

 ENDFORM.                    " SUB_UPLOAD_DATA
*&---------------------------------------------------------------------*
*&      Form  sub_get_physical_file
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_P_FPATH  text
*      -->P_P_LPATH  text
*----------------------------------------------------------------------*
 FORM sub_get_physical_file USING    p_lfile type FILEINTERN"#EC *
                                     p_pfile type LOCALFILE."#EC *

   CHECK NOT p_lfile IS INITIAL.

   CALL FUNCTION 'FILE_GET_NAME'
     EXPORTING
       client           = sy-mandt
       logical_filename = p_lfile
       operating_system = sy-opsys
     IMPORTING
       file_name        = p_pfile
     EXCEPTIONS
       file_not_found   = 1
       OTHERS           = 2.
   IF sy-subrc NE 0.
     p_pfile = '' .
     MESSAGE e237 WITH p_lfile.
   ENDIF.

 ENDFORM.                    " sub_get_physical_file
**&---------------------------------------------------------------------
*
*&      Form  sub_end_selection
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM sub_end_selection .
*Population of Error Log

*  IF g_error_tab[] IS NOT INITIAL.
*    PERFORM sub_create_erortab.                             "#EC *
*    PERFORM sub_populate_syslog. "tables i_errortab.          "#EC *
*  ENDIF.
*
   IF NOT G_ERROR_TAB[] IS INITIAL.
     perform sub_application_log.
   ENDIF.

** Population of Application Log*
*  IF NOT G_ERROR_TAB[] IS INITIAL.
*    PERFORM sub_app_log_init CHANGING v_log_handle.         "#EC *
*    PERFORM sub_app_log_add USING v_log_handle.             "#EC *
*    PERFORM sub_data_save USING v_log_handle.               "#EC *
*    PERFORM sub_log_show USING v_log_handle.                "#EC *
*  ENDIF.

 ENDFORM.                    " sub_end_selection
*&---------------------------------------------------------------------*
*&      Form  sub_start_selection
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM sub_start_selection .

   SET PF-STATUS '/FACTGLB/DMIVART'. "EXCLUDING rt_extab.

*Initialization of all the Global Variables
   PERFORM sub_refresh_variables.

   CONCATENATE C_SAP sy-sysid INTO p_rcvpor.
   CONCATENATE C_SAP sy-sysid INTO p_rcvprn.

   CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'                   "#EC *
        IMPORTING
             own_logical_system             = p_rcvprn
        EXCEPTIONS
             own_logical_system_not_defined = 1
             OTHERS                         = 2.

   IF rb_apsrv = C_X.
     IF p_fpath IS INITIAL.
       message i196.
       LEAVE LIST-PROCESSING.
     ENDIF.

     IF p_fname IS INITIAL.
       message i197.
       LEAVE LIST-PROCESSING.
     ENDIF.
     IF p_fpath1 IS INITIAL.
       message i196.
       LEAVE LIST-PROCESSING.
     ENDIF.

     IF p_fname1 IS INITIAL.
       message i197.
       LEAVE LIST-PROCESSING.
     ENDIF.

   ENDIF.

   IF rb_prsrv = C_X.
     IF p_inpt IS INITIAL.
       message i196.
       LEAVE LIST-PROCESSING.
     ENDIF.

     IF p_inpt1 IS INITIAL.
       message i197.
       LEAVE LIST-PROCESSING.
     ENDIF.
   ENDIF.

   g_objecttype = '04'.

 ENDFORM.                    " sub_start_selection
*&---------------------------------------------------------------------*
*&      Form  SUB_GET_PHYSICAL_FILE1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_P_FPATH  text
*      -->P_P_FNAME  text
*----------------------------------------------------------------------*
 FORM sub_get_physical_file1 USING   p_lfile1 type FILEINTERN"#EC *
                                     p_pfile1 type LOCALFILE."#EC *

   CHECK NOT p_lfile1 IS INITIAL.

   CALL FUNCTION 'FILE_GET_NAME'
     EXPORTING
       client           = sy-mandt
       logical_filename = p_lfile1
       operating_system = sy-opsys
     IMPORTING
       file_name        = p_pfile1
     EXCEPTIONS
       file_not_found   = 1
       OTHERS           = 2.
   IF sy-subrc NE 0.
     p_pfile1 = '' .
     MESSAGE e237 WITH p_lfile1.
   ENDIF.

 ENDFORM.                    " sub_get_physical_file1
*&---------------------------------------------------------------------*
*&      Form  SUB_GET_PHYSICAL_FILE1
*&---------------------------------------------------------------------*

* User-defined routines]

****************************************************************
**MOD-006
****************************************************************
** Eigene Routine
*form ur_CONVERSION_EXIT                                     "#EC CALLED
*     using p_in1                                            "#EC *
*           p_in2                                            "#EC *
*  changing p_out.                                           "#EC *
*
*  DATA: v_msgtext(120)    TYPE c.
*
*  CONSTANTS: c_msgtyp(001)  TYPE c   VALUE 'I',             "#EC NEEDED
*             c_msgid(020)   TYPE c   VALUE 'ZDEV'.          "#EC NEEDED
*
*  CALL FUNCTION p_in1                                       "#EC *
*    EXPORTING
*      input  = p_in2                                        "#EC *
*    IMPORTING
*      output = p_out.                                       "#EC *
*
*  IF sy-subrc NE 0.
*    CLEAR v_msgtext.
*************************************************
**MOD-008
*************************************************
**    MESSAGE ID c_msgid
**            TYPE c_msgtyp
**             NUMBER '096'
**             WITH sy-subrc
**                  p_in2
**            INTO v_msgtext.
**************************************************
***MOD-008
**************************************************
**    WRITE / v_msgtext.
**    CLEAR   v_msgtext.
*  ENDIF.
*endform.                    "ur_CONVERSION_EXIT "#EC CALLED

*&---------------------------------------------------------------------*
*&      Form  get_internal_char
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_CHARAC   text
*      -->P_CABN     text
*      -->P_VTNAM    text
*----------------------------------------------------------------------*
 FORM get_internal_char USING p_charac TYPE atnam
                     CHANGING p_cabn   TYPE ty_cabn
                              p_vtnam  TYPE ty_vtnam.

   sort i_cabn by atinn atnam.
   READ TABLE i_cabn INTO p_cabn
   WITH KEY atnam = p_charac. " BINARY SEARCH.

   IF sy-subrc <> 0.
     p_vtnam-error = C_X.
     CONCATENATE p_charac  text-012                         "#EC NOTEXT
     INTO p_vtnam-reas SEPARATED BY space.
*   p_vtnam-reas  = 'Characteristic name is not valid'.
     g_error = c_x.
     CLEAR wa_vtnam.
     wa_vtnam = p_vtnam.
     APPEND wa_vtnam TO i_cuv_error.

     wa_errortab-msgty = C_E.
     wa_errortab-id = 'ZFACTGLB'.
     wa_errortab-msgno = 249.
     wa_errortab-par1 = wa_vtnam-reas.
     INSERT wa_errortab INTO TABLE g_error_tab.
   ENDIF.

 ENDFORM.                    "get_internal_char

*&---------------------------------------------------------------------*
*&      Form  find_char_exist
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      --> text
*      -->WA_CABN    text
*----------------------------------------------------------------------*
 FORM find_char_exist USING p_file  TYPE ty_file            "#EC NEEDED
                            p_vtnam TYPE ty_vtnam           "#EC NEEDED
                            p_cabn  TYPE ty_cabn.           "#EC NEEDED

   DATA:
          L_QUOT TYPE CHAR2,
          L_POS TYPE CHAR3.

   IF p_vtnam-error IS INITIAL.
     sort i_cuvtab_fld by vtint atinn.
     READ TABLE i_cuvtab_fld ASSIGNING
     WITH KEY vtint = p_vtnam-vtint
              atinn = p_cabn-atinn
              BINARY SEARCH.
     IF sy-subrc = 0.
       -exist = c_x.
       READ TABLE i_charname INTO wa_charname
        WITH KEY name = p_cabn-atnam.
       IF sy-subrc = 0.
         g_tabix = sy-tabix.
         SHIFT g_tabix LEFT DELETING LEADING space.
         l_quot = g_tabix+0(2).
       ENDIF.
       wa_col_pos-vtint = p_vtnam-vtint.
       wa_col_pos-vtnam = p_vtnam-vtnam.
       wa_col_pos-atnam = p_cabn-atnam.
       wa_col_pos-atinn = p_cabn-atinn.
       wa_col_pos-field  = l_quot.
       wa_col_pos-vtpos = -vtpos.
       APPEND wa_col_pos TO i_col_pos.
       CLEAR wa_col_pos.
     ENDIF.
   ENDIF.
 ENDFORM.                    "find_char_exist

*&---------------------------------------------------------------------*
*&      Form  transfer_e1cuv1m
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_E1CUV1M  text
*----------------------------------------------------------------------*
 FORM transfer_e1cuv1m. " USING p_e1cuv1m TYPE e1cuv1m.         "#EC *

   CONSTANTS:
          C_000001(6) TYPE C VALUE '000001',
          C_E1CUV1M(7) TYPE C VALUE 'E1CUV1M',
          C_02(2) TYPE C VALUE '02',
          C_009(3) TYPE C VALUE '009',
          C_0001(4) TYPE C VALUE '0001'.

   CLEAR e1cuv1m.
   e1cuv1m = wa_e1cuv1m.                                    "#EC NEEDED
   wa_itab_zedidd40-docnum          = wdocnum.
   wa_itab_zedidd40-segnum          = c_000001.
   wa_itab_zedidd40-segnam          = c_E1CUV1M.
   wa_itab_zedidd40-hlevel          = c_02.
   E1CUV1M-MSGFN            = c_009.
   E1CUV1M-VTLINENO         = c_0001.
   wa_itab_zedidd40-sdata           = e1cuv1m.
* append itab_zedidd40.                                "  e1cuvtm
   witemno = 0.                                             "#EC NEEDED
   witemno_gst = 0.                                       "#EC NEEDED .
   witemno_qst = 0.                                         "#EC NEEDED
   witemno_new = 0.                                         "#EC NEEDED
   wsegnum = 1.                                             "#EC NEEDED
   clear: wa_e1cuv1m.                                       "#EC NEEDED
   clear: itab_ze1cuv1m.                                    "#EC NEEDED
****************************************************
*MOD-009
****************************************************
*  IF p_trfcpt = C_X.
*    gt_curr_edi_dd40 = itab_zedidd40.
*    APPEND gt_curr_edi_dd40.
*  ENDIF.
*
****************************************************
*MOD-009
****************************************************
   READ TABLE itab_zedidc40 into wa_itab_zedidc40 index 1.

   CASE g_objecttype.
     WHEN '03' OR '04'.
       IF wa_itab_zedidc40-tabnam = 'EDI_DC40'.
         IF p_trfcpt = 'X'.
           wa_curr_edi_dc40-TABNAM = 'EDI_DC40'.
           APPEND wa_curr_edi_dc40 to gt_curr_edi_dc40.
         ENDIF.
       ELSE.
*        CLEAR edi_dd40.
*        edi_dd40-segnam = itab_zedidd40-segnam.
**       edi_dd40-mandt = edi_dc40-mandt.
*        edi_dd40-docnum = itab_zedidd40-docnum.
*        ADD 1 TO g_segnum.
*        edi_dd40-segnum = g_segnum.
*        edi_dd40-hlevel = g_edidd_hlevel.
*        edi_dd40-sdata = itab_zedidd40.
         IF p_trfcpt = c_x.
           wa_curr_edi_dd40 = wa_itab_zedidd40.
           APPEND wa_curr_edi_dd40 to gt_curr_edi_dd40.
         ENDIF.
       ENDIF.
   ENDCASE.

****************************************************
*MOD-009
****************************************************
 ENDFORM.                    "transfer_e1cuv1m

*&---------------------------------------------------------------------*
*&      Form  transfer_e1cuvtm
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_E1CUVTM text
*----------------------------------------------------------------------*
 FORM transfer_e1cuvtm USING p_e1cuvtm TYPE e1cuvtm.        "#EC CALLED

   CLEAR e1cuvtm.
   e1cuvtm = p_e1cuvtm.
*MOD-009
* perform transfer_record_idoc.
*MOD-009
   CLEAR edi_dd40.
   edi_dd40-segnam = g_edidd_segnam.
   edi_dd40-mandt = edi_dc40-mandt.
   edi_dd40-docnum = edi_dc40-docnum.
   ADD 1 TO g_segnum.
   edi_dd40-segnum = g_segnum.
   edi_dd40-hlevel = g_edidd_hlevel.
   edi_dd40-sdata = e1cuvtm.
   IF p_trfcpt = C_X.
     wa_curr_edi_dd40 = edi_dd40.
     APPEND wa_curr_edi_dd40  to gt_curr_edi_dd40.
   ENDIF.

 ENDFORM.                    "transfer_e1cuvtm "#EC CALLED
*&---------------------------------------------------------------------*
*&      Form  transfer_e1datem
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
 FORM transfer_e1datem.                                     "#EC CALLED

   CLEAR e1datem.
   e1datem-msgfn = '009'.
   e1datem-key_date = sy-datum.
   perform transfer_record_idoc.
   CLEAR edi_dd40.
   edi_dd40-segnam = g_edidd_segnam.
   edi_dd40-mandt = edi_dc40-mandt.
   edi_dd40-docnum = edi_dc40-docnum.
   ADD 1 TO g_segnum.
   edi_dd40-segnum = g_segnum.
   edi_dd40-hlevel = g_edidd_hlevel.
   edi_dd40-sdata = e1datem.
   IF p_trfcpt = C_X.
     wa_curr_edi_dd40 = edi_dd40.
     APPEND wa_curr_edi_dd40 to gt_curr_edi_dd40.
   ENDIF.

 ENDFORM.                    "transfer_e1cuvtm "#EC CALLED

*&---------------------------------------------------------------------*
*&      Form  errror_line
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_VTNAM  Variant table
*      -->P_FIELDNAME    Fieldname
*      -->P_ATNAM  Characteristic name
*      -->P_VAL       Value
*      -->P_ROW       Rowid
*----------------------------------------------------------------------*
 FORM errror_line USING p_vtnam     TYPE vtnam
                        p_fieldname TYPE fieldname
                        p_atnam     TYPE atnam
                        p_val       TYPE atwrt
                        p_row       TYPE char5.
   CLEAR wa_error.
   wa_error-vtnam   = p_vtnam.
   wa_error-fname   = p_fieldname.
   wa_error-atnam   = p_atnam.
   wa_error-atwrt   = p_val.
   wa_error-row     = p_row.
   APPEND wa_error TO i_error.
 ENDFORM.                    "errror_line

*&---------------------------------------------------------------------*
*&      Form  delete_duplicates
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
 FORM sub_delete_duplicates.                                "#EC CALLED

   SORT i_file.

   DELETE ADJACENT DUPLICATES FROM i_file comparing vtnam
                                                    char1
                                                    char2
                                                    char3
                                                    char4
                                                    char5
                                                    char6
                                                    char7
                                                    char8
                                                    char9
                                                    char10
                                                    char11
                                                    char12
                                                    char13
                                                    char14
                                                    char15.

 ENDFORM.                    "sub_delete_duplicates "#EC CALLED

*&---------------------------------------------------------------------*
*&      Form  pop_dupl
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_VTNAM  text
*      -->P_SLNID       text
*      -->P_ATNAM   text
*      -->P_VAL   text
*----------------------------------------------------------------------*
 FORM pop_dupl USING p_vtnam  TYPE vtnam
                     p_slnid TYPE slnid
                     p_atnam TYPE atnam
                     p_val   TYPE any.

   DATA:
          L_FIELD TYPE FIELDNAME.
   FIELD-SYMBOLS:   TYPE ANY.

* Do not populate value for characteristic Z_VARCOND as it will not be
* part of duplicate check
   IF p_atnam NE c_varcond.
*  assign p_val to .
     CLEAR wa_col_pos.
*****************************************************
*MOD-008
*****************************************************
*    SORT i_col_pos BY  vtint
*                       vtnam
*                       atinn
*                       atnam.
*****************************************************
*MOD-008
*****************************************************
     READ TABLE i_col_pos INTO wa_col_pos WITH KEY vtnam = p_vtnam
                                                   atnam = p_atnam.
*  No need to check sy-subrc here
     CLEAR l_field.

     READ TABLE i_dupl ASSIGNING  WITH KEY vtnam = p_vtnam
                                                    slnid = p_slnid.
     IF sy-subrc = 0.

       CONCATENATE '-CHAR'  wa_col_pos-field INTO l_field.
       ASSIGN (l_field) TO .
        = p_val.
     ELSE.
       CLEAR wa_dupl.
       wa_dupl-vtnam = p_vtnam.
       wa_dupl-slnid = p_slnid.
       CONCATENATE 'WA_DUPL-CHAR'  wa_col_pos-field INTO l_field.
       ASSIGN (l_field) TO .
        = p_val.
       APPEND wa_dupl TO i_dupl.

     ENDIF.
   ENDIF.
 ENDFORM.                    "pop_dupl

*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  TRANSFER_RECORD_IDOC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM TRANSFER_RECORD_IDOC .                                "#EC CALLED

   READ TABLE itab_zedidc40 into wa_itab_zedidc40 index 1.

   CASE g_objecttype.
     WHEN '03' OR '04'.
**********************************************
*MOD-012
**********************************************
*      IF wa_itab_zedidc40-tabnam = 'EDI_DC40'.
*        IF p_trfcpt = 'X'.
*          wa_curr_edi_dc40 = wa_itab_zedidc40.
*          APPEND wa_curr_edi_dc40 to gt_curr_edi_dc40.
*        ENDIF.
*      ELSE.
**********************************************
*MOD-012
**********************************************

       CLEAR edi_dd40.
**********************************************
*MOD-012
**********************************************
       CLEAR: wa_curr_edi_dd40.
**********************************************
*MOD-012
**********************************************

       edi_dd40-segnam = g_edidd_segnam.
       edi_dd40-mandt = edi_dc40-mandt.
       edi_dd40-docnum = edi_dc40-docnum.
       ADD 1 TO g_segnum.
       edi_dd40-segnum = g_segnum.
       edi_dd40-hlevel = g_edidd_hlevel.
       edi_dd40-sdata = wa_itab_zedidd40.
       IF p_trfcpt = c_x.
         wa_curr_edi_dd40 = wa_itab_zedidd40.
         APPEND wa_curr_edi_dd40 to gt_curr_edi_dd40.
       ENDIF.
**********************************************
*MOD-012
**********************************************
*     ENDIF.
**********************************************
*MOD-012
**********************************************

   ENDCASE.

**********************************************
*MOD-012
**********************************************
   CLEAR: wa_itab_zedidc40.
**********************************************
*MOD-012
**********************************************

 ENDFORM.                    " TRANSFER_RECORD_IDOC "#EC CALLED

*********************************************************************
*MOD-008
*********************************************************************

*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  FILL_EDIDD_SEGMENTS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM FILL_EDIDD_SEGMENTS USING p_e1cuv1m TYPE e1cuv1m.     "#EC CALLED

   LOOP AT I_CONTENTTAB1 INTO WA_CONTENTTAB1.
     IF SY-TABIX = 1.
       wa_contenttab2 = wa_contenttab1.
       append wa_contenttab2 to i_contenttab2.
       clear: wa_contenttab2.
     ENDIF.
   ENDLOOP.

   LOOP AT I_CONTENTTAB1 INTO WA_CONTENTTAB1.
     L_TABIX = SY-TABIX.
     IF L_TABIX > 1.
       READ TABLE I_CONTENTTAB2 INTO WA_CONTENTTAB2
                    WITH KEY VTNAM = WA_CONTENTTAB1-VTNAM BINARY SEARCH.

       IF SY-SUBRC = 0.

*--- E1CUV1M-VTCHARACT
*if not WA_CONTENTTAB1-VTCHARACT is initial.
         if not WA_CONTENTTAB1-CHAR1 is initial.
*       E1CUV1M-VTCHARACT = TAB_CONTENT-ATNAM.
**---   E1CUV1M-VTLINENO
           E1CUV1M-MSGFN    = c_009.
           E1CUV1M-VTLINENO = c_0001.
** ---  E1CUV1M-MSGFN
           E1CUV1M-VTCHARACT = WA_CONTENTTAB2-CHAR1.
           E1CUV1M-ATWRT     = WA_CONTENTTAB1-CHAR1.
           wa_itab_zedidd40-docnum          = wdocnum.
           wa_itab_zedidd40-segnum          = c_000001.
           wa_itab_zedidd40-segnam          = p_E1CUV1M.
           wa_itab_zedidd40-hlevel          = c_02.
           wa_itab_zedidd40-sdata           = e1cuv1m.
           append wa_itab_zedidd40 to itab_zedidd40.        " e1cuvtm
           witemno = 0.                                     "#EC NEEDED
           witemno_gst = 0.                               "#EC NEEDED .
           witemno_qst = 0.                                 "#EC NEEDED
           witemno_new = 0.                                 "#EC NEEDED
           wsegnum = 1.                                     "#EC NEEDED
           clear: wa_e1cuv1m.                               "#EC NEEDED
           clear: itab_ze1cuv1m.                            "#EC NEEDED

         endif.

         if not WA_CONTENTTAB1-CHAR2 is initial.
*       E1CUV1M-VTCHARACT = TAB_CONTENT-ATNAM.
           E1CUV1M-MSGFN    = '009'.
           E1CUV1M-VTLINENO = '0001'.
** ---  E1CUV1M-MSGFN
           E1CUV1M-VTCHARACT = WA_CONTENTTAB2-CHAR2.
           E1CUV1M-ATWRT     = WA_CONTENTTAB1-CHAR2.
           wa_itab_zedidd40-docnum          = wdocnum.
           wa_itab_zedidd40-segnum          = c_000001.
           wa_itab_zedidd40-segnam          = p_E1CUV1M.
           wa_itab_zedidd40-hlevel          = c_02.
           wa_itab_zedidd40-sdata           = e1cuv1m.
           append wa_itab_zedidd40 to itab_zedidd40.        " e1cuvtm
           witemno = 0.                                     "#EC NEEDED
           witemno_gst = 0.                               "#EC NEEDED .
           witemno_qst = 0.                                 "#EC NEEDED
           witemno_new = 0.                                 "#EC NEEDED
           wsegnum = 1.                                     "#EC NEEDED
           clear: wa_e1cuv1m.                               "#EC NEEDED
           clear: itab_ze1cuv1m.                            "#EC NEEDED
         endif.

         if not WA_CONTENTTAB1-CHAR3 is initial.
*       E1CUV1M-VTCHARACT = TAB_CONTENT-ATNAM.
           E1CUV1M-MSGFN    = '009'.
           E1CUV1M-VTLINENO = '0001'.
** ---  E1CUV1M-MSGFN
           E1CUV1M-VTCHARACT = WA_CONTENTTAB2-CHAR3.
           E1CUV1M-ATWRT     = WA_CONTENTTAB1-CHAR3.
           wa_itab_zedidd40-docnum          = wdocnum.
           wa_itab_zedidd40-segnum          = c_000001.
           wa_itab_zedidd40-segnam          = p_E1CUV1M.
           wa_itab_zedidd40-hlevel          = c_02.
           wa_itab_zedidd40-sdata           = e1cuv1m.
           append wa_itab_zedidd40 to itab_zedidd40.        " e1cuvtm
           witemno = 0.                                     "#EC NEEDED
           witemno_gst = 0.                               "#EC NEEDED .
           witemno_qst = 0.                                 "#EC NEEDED
           witemno_new = 0.                                 "#EC NEEDED
           wsegnum = 1.                                     "#EC NEEDED
           clear: wa_e1cuv1m.                               "#EC NEEDED
           clear: itab_ze1cuv1m.                            "#EC NEEDED
         endif.

         if not WA_CONTENTTAB1-CHAR4 is initial.
*       E1CUV1M-VTCHARACT = TAB_CONTENT-ATNAM.
           E1CUV1M-MSGFN    = '009'.
           E1CUV1M-VTLINENO = '0001'.
** ---  E1CUV1M-MSGFN
           E1CUV1M-VTCHARACT = WA_CONTENTTAB2-CHAR4.
           E1CUV1M-ATWRT     = WA_CONTENTTAB1-CHAR4.
           wa_itab_zedidd40-docnum          = wdocnum.
           wa_itab_zedidd40-segnum          = c_000001.
           wa_itab_zedidd40-segnam          = p_E1CUV1M.
           wa_itab_zedidd40-hlevel          = c_02.
           wa_itab_zedidd40-sdata           = e1cuv1m.
           append wa_itab_zedidd40 to itab_zedidd40.        " e1cuvtm
           witemno = 0.                                     "#EC NEEDED
           witemno_gst = 0.                               "#EC NEEDED .
           witemno_qst = 0.                                 "#EC NEEDED
           witemno_new = 0.                                 "#EC NEEDED
           wsegnum = 1.                                     "#EC NEEDED
           clear: wa_e1cuv1m.                               "#EC NEEDED
           clear: itab_ze1cuv1m.                            "#EC NEEDED

         endif.

         if not WA_CONTENTTAB1-CHAR5 is initial.
*       E1CUV1M-VTCHARACT = TAB_CONTENT-ATNAM.
           E1CUV1M-MSGFN    = '009'.
           E1CUV1M-VTLINENO = '0001'.
** ---  E1CUV1M-MSGFN
           E1CUV1M-VTCHARACT = WA_CONTENTTAB2-CHAR5.
           E1CUV1M-ATWRT     = WA_CONTENTTAB1-CHAR5.
           wa_itab_zedidd40-docnum          = wdocnum.
           wa_itab_zedidd40-segnum          = c_000001.
           wa_itab_zedidd40-segnam          = p_E1CUV1M.
           wa_itab_zedidd40-hlevel          = c_02.
           wa_itab_zedidd40-sdata           = e1cuv1m.
           append wa_itab_zedidd40 to itab_zedidd40.        " e1cuvtm
           witemno = 0.                                     "#EC NEEDED
           witemno_gst = 0.                               "#EC NEEDED .
           witemno_qst = 0.                                 "#EC NEEDED
           witemno_new = 0.                                 "#EC NEEDED
           wsegnum = 1.                                     "#EC NEEDED
           clear: wa_e1cuv1m.                               "#EC NEEDED
           clear: itab_ze1cuv1m.                            "#EC NEEDED
         endif.

         if not WA_CONTENTTAB1-CHAR6 is initial.
*       E1CUV1M-VTCHARACT = TAB_CONTENT-ATNAM.
           E1CUV1M-MSGFN    = '009'.
           E1CUV1M-VTLINENO = '0001'.
** ---  E1CUV1M-MSGFN
           E1CUV1M-VTCHARACT = WA_CONTENTTAB2-CHAR6.
           E1CUV1M-ATWRT     = WA_CONTENTTAB1-CHAR6.
           wa_itab_zedidd40-docnum          = wdocnum.
           wa_itab_zedidd40-segnum          = c_000001.
           wa_itab_zedidd40-segnam          = p_E1CUV1M.
           wa_itab_zedidd40-hlevel          = c_02.
           wa_itab_zedidd40-sdata           = e1cuv1m.
           append wa_itab_zedidd40 to itab_zedidd40.        " e1cuvtm
           witemno = 0.                                     "#EC NEEDED
           witemno_gst = 0.                               "#EC NEEDED .
           witemno_qst = 0.                                 "#EC NEEDED
           witemno_new = 0.                                 "#EC NEEDED
           wsegnum = 1.                                     "#EC NEEDED
           clear: wa_e1cuv1m.                               "#EC NEEDED
           clear: itab_ze1cuv1m.                            "#EC NEEDED

         endif.

         If not WA_CONTENTTAB1-CHAR7 is initial.
*       E1CUV1M-VTCHARACT = TAB_CONTENT-ATNAM.
           E1CUV1M-MSGFN    = '009'.
           E1CUV1M-VTLINENO = '0001'.
** ---  E1CUV1M-MSGFN
           E1CUV1M-VTCHARACT = WA_CONTENTTAB2-CHAR7.
           E1CUV1M-ATWRT     = WA_CONTENTTAB1-CHAR7.
           wa_itab_zedidd40-docnum          = wdocnum.
           wa_itab_zedidd40-segnum          = c_000001.
           wa_itab_zedidd40-segnam          = p_E1CUV1M.
           wa_itab_zedidd40-hlevel          = c_02.
           wa_itab_zedidd40-sdata           = e1cuv1m.
           append wa_itab_zedidd40 to itab_zedidd40.        " e1cuvtm
           witemno = 0.                                     "#EC NEEDED
           witemno_gst = 0.                               "#EC NEEDED .
           witemno_qst = 0.                                 "#EC NEEDED
           witemno_new = 0.                                 "#EC NEEDED
           wsegnum = 1.                                     "#EC NEEDED
           clear: wa_e1cuv1m.                               "#EC NEEDED
           clear: itab_ze1cuv1m.                            "#EC NEEDED

         endif.

         if not WA_CONTENTTAB1-CHAR8 is initial.
*       E1CUV1M-VTCHARACT = TAB_CONTENT-ATNAM.
           E1CUV1M-MSGFN    = '009'.
           E1CUV1M-VTLINENO = '0001'.
** ---  E1CUV1M-MSGFN
           E1CUV1M-VTCHARACT = WA_CONTENTTAB2-CHAR8.
           E1CUV1M-ATWRT     = WA_CONTENTTAB1-CHAR8.
           wa_itab_zedidd40-docnum          = wdocnum.
           wa_itab_zedidd40-segnum          = c_000001.
           wa_itab_zedidd40-segnam          = p_E1CUV1M.
           wa_itab_zedidd40-hlevel          = c_02.
           wa_itab_zedidd40-sdata           = e1cuv1m.
           append wa_itab_zedidd40 to itab_zedidd40.        " e1cuvtm
           witemno = 0.                                     "#EC NEEDED
           witemno_gst = 0.                               "#EC NEEDED .
           witemno_qst = 0.                                 "#EC NEEDED
           witemno_new = 0.                                 "#EC NEEDED
           wsegnum = 1.                                     "#EC NEEDED
           clear: wa_e1cuv1m.                               "#EC NEEDED
           clear: itab_ze1cuv1m.                            "#EC NEEDED

         endif.

         if not WA_CONTENTTAB1-CHAR9 is initial.
*       E1CUV1M-VTCHARACT = TAB_CONTENT-ATNAM.
           E1CUV1M-MSGFN    = '009'.
           E1CUV1M-VTLINENO = '0001'.
** ---  E1CUV1M-MSGFN
           E1CUV1M-VTCHARACT = WA_CONTENTTAB2-CHAR9.
           E1CUV1M-ATWRT     = WA_CONTENTTAB1-CHAR9.
           wa_itab_zedidd40-docnum          = wdocnum.
           wa_itab_zedidd40-segnum          = c_000001.
           wa_itab_zedidd40-segnam          = p_E1CUV1M.
           wa_itab_zedidd40-hlevel          = c_02.
           wa_itab_zedidd40-sdata           = e1cuv1m.
           append wa_itab_zedidd40 to itab_zedidd40.        " e1cuvtm
           witemno = 0.                                     "#EC NEEDED
           witemno_gst = 0.                               "#EC NEEDED .
           witemno_qst = 0.                                 "#EC NEEDED
           witemno_new = 0.                                 "#EC NEEDED
           wsegnum = 1.                                     "#EC NEEDED
           clear: wa_e1cuv1m.                               "#EC NEEDED
           clear: itab_ze1cuv1m.                            "#EC NEEDED

         endif.

         if not WA_CONTENTTAB1-CHAR10 is initial.
*       E1CUV1M-VTCHARACT = TAB_CONTENT-ATNAM.

           E1CUV1M-MSGFN    = '009'.
           E1CUV1M-VTLINENO = '0001'.
** ---  E1CUV1M-MSGFN
           E1CUV1M-VTCHARACT = WA_CONTENTTAB2-CHAR10.
           E1CUV1M-ATWRT     = WA_CONTENTTAB1-CHAR10.
           wa_itab_zedidd40-docnum          = wdocnum.
           wa_itab_zedidd40-segnum          = c_000001.
           wa_itab_zedidd40-segnam          = p_E1CUV1M.
           wa_itab_zedidd40-hlevel          = c_02.
           wa_itab_zedidd40-sdata           = e1cuv1m.
           append wa_itab_zedidd40 to itab_zedidd40.        " e1cuvtm
           witemno = 0.                                     "#EC NEEDED
           witemno_gst = 0.                               "#EC NEEDED .
           witemno_qst = 0.                                 "#EC NEEDED
           witemno_new = 0.                                 "#EC NEEDED
           wsegnum = 1.                                     "#EC NEEDED
           clear: wa_e1cuv1m.                               "#EC NEEDED
           clear: itab_ze1cuv1m.                            "#EC NEEDED

         endif.

         if not WA_CONTENTTAB1-CHAR11 is initial.
*       E1CUV1M-VTCHARACT = TAB_CONTENT-ATNAM.
           E1CUV1M-MSGFN    = '009'.
           E1CUV1M-VTLINENO = '0001'.
** ---  E1CUV1M-MSGFN
           E1CUV1M-VTCHARACT = WA_CONTENTTAB2-CHAR11.
           E1CUV1M-ATWRT     = WA_CONTENTTAB1-CHAR11.
           wa_itab_zedidd40-docnum          = wdocnum.
           wa_itab_zedidd40-segnum          = c_000001.
           wa_itab_zedidd40-segnam          = p_E1CUV1M.
           wa_itab_zedidd40-hlevel          = c_02.
           wa_itab_zedidd40-sdata           = e1cuv1m.
           append wa_itab_zedidd40 to itab_zedidd40.        " e1cuvtm
           witemno = 0.                                     "#EC NEEDED
           witemno_gst = 0.                               "#EC NEEDED .
           witemno_qst = 0.                                 "#EC NEEDED
           witemno_new = 0.                                 "#EC NEEDED
           wsegnum = 1.                                     "#EC NEEDED
           clear: wa_e1cuv1m.                               "#EC NEEDED
           clear: itab_ze1cuv1m.                            "#EC NEEDED

         endif.

         if not WA_CONTENTTAB1-CHAR12 is initial.
*       E1CUV1M-VTCHARACT = TAB_CONTENT-ATNAM.
           E1CUV1M-MSGFN    = '009'.
           E1CUV1M-VTLINENO = '0001'.
** ---  E1CUV1M-MSGFN
           E1CUV1M-VTCHARACT = WA_CONTENTTAB2-CHAR12.
           E1CUV1M-ATWRT     = WA_CONTENTTAB1-CHAR12.
           wa_itab_zedidd40-docnum          = wdocnum.
           wa_itab_zedidd40-segnum          = c_000001.
           wa_itab_zedidd40-segnam          = p_E1CUV1M.
           wa_itab_zedidd40-hlevel          = c_02.
           wa_itab_zedidd40-sdata           = e1cuv1m.
           append wa_itab_zedidd40 to itab_zedidd40.        " e1cuvtm
           witemno = 0.                                     "#EC NEEDED
           witemno_gst = 0.                               "#EC NEEDED .
           witemno_qst = 0.                                 "#EC NEEDED
           witemno_new = 0.                                 "#EC NEEDED
           wsegnum = 1.                                     "#EC NEEDED
           clear: wa_e1cuv1m.                               "#EC NEEDED
           clear: itab_ze1cuv1m.                            "#EC NEEDED

         endif.

         if not WA_CONTENTTAB1-CHAR13 is initial.
*       E1CUV1M-VTCHARACT = TAB_CONTENT-ATNAM.
           E1CUV1M-MSGFN    = '009'.
           E1CUV1M-VTLINENO = '0001'.
** ---  E1CUV1M-MSGFN
           E1CUV1M-VTCHARACT = WA_CONTENTTAB2-CHAR13.
           E1CUV1M-ATWRT     = WA_CONTENTTAB1-CHAR13.
           wa_itab_zedidd40-docnum          = wdocnum.
           wa_itab_zedidd40-segnum          = c_000001.
           wa_itab_zedidd40-segnam          = p_E1CUV1M.
           wa_itab_zedidd40-hlevel          = c_02.
           wa_itab_zedidd40-sdata           = e1cuv1m.
           append wa_itab_zedidd40 to itab_zedidd40.        " e1cuvtm
           witemno = 0.                                     "#EC NEEDED
           witemno_gst = 0.                               "#EC NEEDED .
           witemno_qst = 0.                                 "#EC NEEDED
           witemno_new = 0.                                 "#EC NEEDED
           wsegnum = 1.                                     "#EC NEEDED
           clear: wa_e1cuv1m.                               "#EC NEEDED
           clear: itab_ze1cuv1m.                            "#EC NEEDED

         endif.

         if not WA_CONTENTTAB1-CHAR14 is initial.
*     E1CUV1M-VTCHARACT = TAB_CONTENT-ATNAM.
           E1CUV1M-MSGFN    = '009'.
           E1CUV1M-VTLINENO = '0001'.
** ---  E1CUV1M-MSGFN
           E1CUV1M-VTCHARACT = WA_CONTENTTAB2-CHAR14.
           E1CUV1M-ATWRT     = WA_CONTENTTAB1-CHAR14.
           wa_itab_zedidd40-docnum          = wdocnum.
           wa_itab_zedidd40-segnum          = c_000001.
           wa_itab_zedidd40-segnam          = p_E1CUV1M.
           wa_itab_zedidd40-hlevel          = c_02.
           wa_itab_zedidd40-sdata           = e1cuv1m.
           append wa_itab_zedidd40 to itab_zedidd40.        " e1cuvtm
           witemno = 0.                                     "#EC NEEDED
           witemno_gst = 0.                               "#EC NEEDED .
           witemno_qst = 0.                                 "#EC NEEDED
           witemno_new = 0.                                 "#EC NEEDED
           wsegnum = 1.                                     "#EC NEEDED
           clear: wa_e1cuv1m.                               "#EC NEEDED
           clear: itab_ze1cuv1m.                            "#EC NEEDED
         endif.

         if not WA_CONTENTTAB1-CHAR15 is initial.
*       E1CUV1M-VTCHARACT = TAB_CONTENT-ATNAM.
           E1CUV1M-MSGFN    = '009'.
           E1CUV1M-VTLINENO = '0001'.
** ---  E1CUV1M-MSGFN
           E1CUV1M-VTCHARACT = WA_CONTENTTAB2-CHAR15.
           E1CUV1M-ATWRT     = WA_CONTENTTAB1-CHAR15.
           wa_itab_zedidd40-docnum          = wdocnum.
           wa_itab_zedidd40-segnum          = c_000001.
           wa_itab_zedidd40-segnam          = p_E1CUV1M.
           wa_itab_zedidd40-hlevel          = c_02.
           wa_itab_zedidd40-sdata           = e1cuv1m.
           append wa_itab_zedidd40 to itab_zedidd40.        " e1cuvtm
           witemno = 0.                                     "#EC NEEDED
           witemno_gst = 0.                               "#EC NEEDED .
           witemno_qst = 0.                                 "#EC NEEDED
           witemno_new = 0.                                 "#EC NEEDED
           wsegnum = 1.                                     "#EC NEEDED
           clear: wa_e1cuv1m.                               "#EC NEEDED
           clear: itab_ze1cuv1m.                            "#EC NEEDED

         endif.

         CLEAR: wa_contenttab2.
       ENDIF.
       CLEAR: L_TABIX.
     ENDIF.
     CLEAR: wa_contenttab1.
   ENDLOOP.

   perform transfer_record_idoc.

 ENDFORM.                    " FILL_EDIDD_SEGMENTS
*&---------------------------------------------------------------------*
*&      Form  SUB_GET_CABN
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_GET_CABN .

   DATA:
          I_CABN_CHAR TYPE STANDARD TABLE OF TY_CONTENT INITIAL SIZE 0.
                                                            "#EC NEEDED
   DATA:
          WA_CABN_CHAR TYPE TY_CONTENT.

   READ TABLE I_CONTENTTAB1 INTO WA_CONTENTTAB1 INDEX 1.
   MOVE-CORRESPONDING WA_CONTENTTAB1 TO WA_CABN_CHAR.
   APPEND WA_CABN_CHAR TO I_CABN_CHAR.
   CLEAR: WA_CABN_CHAR.

*****************************************************
****MOD-008
*****************************************************
*  SELECT atinn atnam atfor
*         atson atprt atprr
*         atprf anzdz FROM cabn
*         INTO TABLE i_cabn.
******************************************************
*****MOD-008
******************************************************

   SELECT atinn
          atnam
          atfor
          atson
          atprt
          atprr
          atprf
          anzdz
          FROM cabn
          INTO TABLE i_cabn
          FOR ALL ENTRIES IN I_CABN_CHAR
          WHERE ( ATNAM = i_cabn_char-char1 or
                ATNAM = i_cabn_char-char2 or
                ATNAM = i_cabn_char-char3 or
                ATNAM = i_cabn_char-char4 or
                ATNAM = i_cabn_char-char5 or
                ATNAM = i_cabn_char-char6 or
                ATNAM = i_cabn_char-char7 or
                ATNAM = i_cabn_char-char8 or
                ATNAM = i_cabn_char-char9 or
                ATNAM = i_cabn_char-char10 or
                ATNAM = i_cabn_char-char11 or
                ATNAM = i_cabn_char-char12 or
                ATNAM = i_cabn_char-char13 or
                ATNAM = i_cabn_char-char14 or
                ATNAM = i_cabn_char-char15 ).

   IF sy-subrc = 0.
     SORT i_cabn BY atinn atnam.
     delete i_cabn where atnam is initial.
     i_cabn_temp[] = i_cabn[].
     i_cabn_atinn[] = i_cabn[].
*   Sort IT by internal characteristic number
     SORT i_cabn_atinn BY atinn atnam.
     DELETE ADJACENT DUPLICATES FROM i_cabn_atinn COMPARING atinn atnam.

     DELETE   i_cabn_temp
     WHERE atson IS NOT INITIAL
     AND   atprt IS NOT INITIAL
     AND   atprr IS NOT INITIAL
     AND   atprf IS NOT INITIAL.

   ENDIF.

 ENDFORM.                    " SUB_GET_CABN
*&---------------------------------------------------------------------*
*&      Form  SUB_GET_CAWN
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_GET_CAWN .

   IF NOT i_cabn_temp[] is initial.

     SELECT atinn
            atzhl
            atwrt
            atflv
            lkenz
            FROM cawn
            INTO TABLE i_cawn
            FOR ALL ENTRIES IN i_cabn_temp
            WHERE atinn = i_cabn_temp-atinn.

     IF sy-subrc = 0.
       i_cawn_c[] = i_cawn[].
       DELETE i_cawn_c WHERE atwrt IS INITIAL.
       SORT i_cawn_c BY atinn atwrt.

       i_cawn_n = i_cawn.
       DELETE i_cawn_n WHERE atflv IS INITIAL.
       SORT i_cawn_n BY atinn atflv.

       i_cawn_i = i_cawn.
       SORT i_cawn_i BY atinn.
       DELETE ADJACENT DUPLICATES FROM i_cawn_i COMPARING atinn.
     ENDIF.
   ENDIF.

 ENDFORM.                    " SUB_GET_CAWN
*&---------------------------------------------------------------------*
*&      Form  SUB_CONVERT_TRANSACTION
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_CONVERT_TRANSACTION .

   DATA:
          L_TABLE TYPE APITABL.
   DATA:
          L_CHANGE_NUMBER TYPE AENNR.
   DATA:
       L_DLOCK LIKE CUVTAB_ST-DLOCK_CONT, " Indicator: distribution lock
          ITAB_VT_BASIC_DATA LIKE VTBASDAT,
          L_DATE LIKE CLBASD-VAL_FROM, " Valid-from date
          L_LINE_NO TYPE I.

   TYPES:
          BEGIN OF TY_VAR_TAB_VTENTRIES.
           INCLUDE STRUCTURE VTENTRIES.
   TYPES:
            FLAG(1) TYPE C.
   TYPES:
          END OF TY_VAR_TAB_VTENTRIES.

   DATA:
          WA_VAR_TAB_ENTRIES TYPE VTENTRIES.
   DATA:
          WA_VAR_TAB_ENTRIES1 TYPE TY_VAR_TAB_VTENTRIES.

   DATA:
          ITAB_VAR_TAB_ENTRIES TYPE STANDARD TABLE OF VTENTRIES INITIAL
          SIZE 0.
   DATA:
          ITAB_VAR_TAB_ENTRIES1 TYPE STANDARD TABLE OF
          TY_VAR_TAB_VTENTRIES INITIAL SIZE 0.
   DATA:
          C_MARK(1) TYPE C VALUE 'X'.

********************************************************
*MOD-009
********************************************************

   PERFORM sub_clear_tables.

   loop at i_contentheader1 into wa_contentheader1.

     CALL FUNCTION 'CARD_TABLE_READ_STRUCTURE'
       EXPORTING
         VAR_TAB    = WA_CONTENTHEADER1-VTNAM
         CHANGE_NO  = L_CHANGE_NUMBER
         DATE       = L_DATE
       IMPORTING
         BASIC_DATA = ITAB_VT_BASIC_DATA
       EXCEPTIONS
         ERROR      = 1
         OTHERS     = 2.

     CHECK SY-SUBRC IS INITIAL.

     CALL FUNCTION 'CARD_TABLE_READ_ENTRIES'
       EXPORTING
         VAR_TABLE       = WA_CONTENTHEADER1-VTNAM
         CHANGE_NO       = L_CHANGE_NUMBER
         DATE            = L_DATE
       TABLES
         VAR_TAB_ENTRIES = ITAB_VAR_TAB_ENTRIES
       EXCEPTIONS
         ERROR           = 1
         OTHERS          = 2.

   ENDLOOP.

*********************************************************************
**MOD-012
*********************************************************************

   SORT itab_var_tab_entries by VTCHARACT VTVALUE.

   loop at i_contenttab1 into wa_contenttab1.
     if sy-tabix = 1.
       continue.
     endif.

     IF wa_contenttab1-char1 ne ' '.

       READ TABLE itab_var_tab_entries into wa_var_tab_entries
          WITH KEY VTVALUE = wa_contenttab1-char1 binary search.

       IF SY-SUBRC = 0.
         wa_contenttab1-flag = C_Y.
         modify i_contenttab1 from wa_contenttab1 transporting flag.
       ELSE.
         IF wa_var_tab_entries-VTCHARACT = C_VARCOND.
           wa_contenttab1-flag = C_Y.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
         ELSE.
           wa_contenttab1-flag = C_Z.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
           CONTINUE.
         ENDIF.
       ENDIF.
     ENDIF.

     IF wa_contenttab1-char2 ne ' '.

       READ TABLE itab_var_tab_entries into wa_var_tab_entries
          WITH KEY VTVALUE = wa_contenttab1-char2.

       IF SY-SUBRC = 0.
         wa_contenttab1-flag = C_Y.
         modify i_contenttab1 from wa_contenttab1 transporting flag.
       ELSE.
         IF wa_var_tab_entries-VTCHARACT = C_VARCOND.
           wa_contenttab1-flag = C_Y.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
         ELSE.
           wa_contenttab1-flag = C_Z.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
           CONTINUE.
         ENDIF.
       ENDIF.
     ENDIF.

     IF wa_contenttab1-char3 ne ' '.

       READ TABLE itab_var_tab_entries into wa_var_tab_entries
          WITH KEY VTVALUE = wa_contenttab1-char3.

       IF SY-SUBRC = 0.
         wa_contenttab1-flag = C_Y.
         modify i_contenttab1 from wa_contenttab1 transporting flag.
       ELSE.
         IF wa_var_tab_entries-VTCHARACT = C_VARCOND.
           wa_contenttab1-flag = C_Y.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
         ELSE.
           wa_contenttab1-flag = C_Z.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
           CONTINUE.
         ENDIF.
       ENDIF.
     ENDIF.

     IF wa_contenttab1-char4 ne ' '.

       READ TABLE itab_var_tab_entries into wa_var_tab_entries
          WITH KEY VTVALUE = wa_contenttab1-char4.

       IF SY-SUBRC = 0.
         wa_contenttab1-flag = C_Y.
         modify i_contenttab1 from wa_contenttab1 transporting flag.
       ELSE.
         IF wa_var_tab_entries-VTCHARACT = C_VARCOND.
           wa_contenttab1-flag = C_Y.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
         ELSE.
           wa_contenttab1-flag = C_Z.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
           CONTINUE.
         ENDIF.
       ENDIF.
     ENDIF.

     IF wa_contenttab1-char5 ne ' '.

       READ TABLE itab_var_tab_entries into wa_var_tab_entries
          WITH KEY VTVALUE = wa_contenttab1-char5.

       IF SY-SUBRC = 0.
         wa_contenttab1-flag = C_Y.
         modify i_contenttab1 from wa_contenttab1 transporting flag.

       ELSE.
         IF wa_var_tab_entries-VTCHARACT = C_VARCOND.
           wa_contenttab1-flag = C_Y.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
         ELSE.
           wa_contenttab1-flag = C_Z.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
           CONTINUE.
         ENDIF.
       ENDIF.
     ENDIF.

     IF wa_contenttab1-char6 ne ' '.

       READ TABLE itab_var_tab_entries into wa_var_tab_entries
          WITH KEY VTVALUE = wa_contenttab1-char6.

       IF SY-SUBRC = 0.
         wa_contenttab1-flag = C_Y.
         modify i_contenttab1 from wa_contenttab1 transporting flag.

       ELSE.
         IF wa_var_tab_entries-VTCHARACT = C_VARCOND.
           wa_contenttab1-flag = C_Y.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
         ELSE.
           wa_contenttab1-flag = C_Z.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
           CONTINUE.
         ENDIF.
       ENDIF.
     ENDIF.

     IF wa_contenttab1-char7 ne ' '.

       READ TABLE itab_var_tab_entries into wa_var_tab_entries
          WITH KEY VTVALUE = wa_contenttab1-char7.

       IF SY-SUBRC = 0.
         wa_contenttab1-flag = C_Y.
         modify i_contenttab1 from wa_contenttab1 transporting flag.

       ELSE.
         IF wa_var_tab_entries-VTCHARACT = C_VARCOND.
           wa_contenttab1-flag = C_Y.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
         ELSE.
           wa_contenttab1-flag = C_Z.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
           CONTINUE.
         ENDIF.
       ENDIF.
     ENDIF.

     IF wa_contenttab1-char8 ne ' '.

       READ TABLE itab_var_tab_entries into wa_var_tab_entries
          WITH KEY VTVALUE = wa_contenttab1-char8.

       IF SY-SUBRC = 0.
         wa_contenttab1-flag = C_Y.
         modify i_contenttab1 from wa_contenttab1 transporting flag.

       ELSE.
         IF wa_var_tab_entries-VTCHARACT = C_VARCOND.
           wa_contenttab1-flag = C_Y.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
         ELSE.
           wa_contenttab1-flag = C_Z.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
           CONTINUE.
         ENDIF.
       ENDIF.
     ENDIF.

     IF wa_contenttab1-char9 ne ' '.

       READ TABLE itab_var_tab_entries into wa_var_tab_entries
          WITH KEY VTVALUE = wa_contenttab1-char9.

       IF SY-SUBRC = 0.
         wa_contenttab1-flag = C_Y.
         modify i_contenttab1 from wa_contenttab1 transporting flag.

       ELSE.

         IF wa_var_tab_entries-VTCHARACT = C_VARCOND.
           wa_contenttab1-flag = C_Y.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
         ELSE.
           wa_contenttab1-flag = C_Z.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
           CONTINUE.
         ENDIF.
       ENDIF.
     ENDIF.

     IF wa_contenttab1-char10 ne ' '.

       READ TABLE itab_var_tab_entries into wa_var_tab_entries
          WITH KEY VTVALUE = wa_contenttab1-char10.

       IF SY-SUBRC = 0.
         wa_contenttab1-flag = C_Y.
         modify i_contenttab1 from wa_contenttab1 transporting flag.

       ELSE.
         IF wa_var_tab_entries-VTCHARACT = C_VARCOND.
           wa_contenttab1-flag = C_Y.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
         ELSE.
           wa_contenttab1-flag = C_Z.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
           CONTINUE.
         ENDIF.
       ENDIF.
     ENDIF.

     IF wa_contenttab1-char11 ne ' '.

       READ TABLE itab_var_tab_entries into wa_var_tab_entries
          WITH KEY VTVALUE = wa_contenttab1-char11.

       IF SY-SUBRC = 0.
         wa_contenttab1-flag = C_Y.
         modify i_contenttab1 from wa_contenttab1 transporting flag.

       ELSE.
         IF wa_var_tab_entries-VTCHARACT = C_VARCOND.
           wa_contenttab1-flag = C_Y.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
         ELSE.
           wa_contenttab1-flag = C_Z.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
           CONTINUE.
         ENDIF.
       ENDIF.
     ENDIF.

     IF wa_contenttab1-char12 ne ' '.

       READ TABLE itab_var_tab_entries into wa_var_tab_entries
          WITH KEY VTVALUE = wa_contenttab1-char12.

       IF SY-SUBRC = 0.
         wa_contenttab1-flag = C_Y.
         modify i_contenttab1 from wa_contenttab1 transporting flag.

       ELSE.
         IF wa_var_tab_entries-VTCHARACT = C_VARCOND.
           wa_contenttab1-flag = C_Y.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
         ELSE.
           wa_contenttab1-flag = C_Z.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
           CONTINUE.
         ENDIF.
       ENDIF.
     ENDIF.

     IF wa_contenttab1-char13 ne ' '.

       READ TABLE itab_var_tab_entries into wa_var_tab_entries
          WITH KEY VTVALUE = wa_contenttab1-char13.

       IF SY-SUBRC = 0.
         wa_contenttab1-flag = C_Y.
         modify i_contenttab1 from wa_contenttab1 transporting flag.

       ELSE.
         IF wa_var_tab_entries-VTCHARACT = C_VARCOND.
           wa_contenttab1-flag = C_Y.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
         ELSE.
           wa_contenttab1-flag = C_Z.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
           CONTINUE.
         ENDIF.
       ENDIF.
     ENDIF.

     IF wa_contenttab1-char14 ne ' '.

       READ TABLE itab_var_tab_entries into wa_var_tab_entries
          WITH KEY VTVALUE = wa_contenttab1-char14.

       IF SY-SUBRC = 0.
         wa_contenttab1-flag = C_Y.
         modify i_contenttab1 from wa_contenttab1 transporting flag.

       ELSE.
         IF wa_var_tab_entries-VTCHARACT = C_VARCOND.
           wa_contenttab1-flag = C_Y.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
         ELSE.
           wa_contenttab1-flag = C_Z.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
           CONTINUE.
         ENDIF.
       ENDIF.
     ENDIF.

     IF wa_contenttab1-char15 ne ' '.

       READ TABLE itab_var_tab_entries into wa_var_tab_entries
          WITH KEY VTVALUE = wa_contenttab1-char15.

       IF SY-SUBRC = 0.
         wa_contenttab1-flag = C_Y.
         modify i_contenttab1 from wa_contenttab1 transporting flag.

       ELSE.
         IF wa_var_tab_entries-VTCHARACT = C_VARCOND.
           wa_contenttab1-flag = C_Y.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
         ELSE.
           wa_contenttab1-flag = C_Z.
           modify i_contenttab1 from wa_contenttab1 transporting flag.
           CONTINUE.
         ENDIF.
       ENDIF.
     ENDIF.
   endloop.

   Delete i_contenttab1 where flag = C_Y.

*********************************************************************
**MOD-010
*********************************************************************
   I_CONTENTTAB3[] = I_CONTENTTAB1[].

   SORT I_CONTENTTAB3 BY VTNAM.

   DELETE I_CONTENTTAB3 WHERE VTNAM IS INITIAL.
   CLEAR: L_LINES.
   DESCRIBE TABLE I_CONTENTTAB3 LINES L_LINES.

   IF L_LINES = 1.
     g_error = 'X'.
     CLEAR wa_vtnam.
     MESSAGE I144.
     LEAVE LIST-PROCESSING.
   ENDIF.

**********************************************************************
*MOD-009
**********************************************************************
   IF G_ERROR <> C_X.
**********************************************************************
*MOD-009
**********************************************************************

     loop at i_contentheader1 into wa_contentheader1.

       perform sub_convert_0001.                            " E1CUVTM

       perform sub_convert_0002.                            " E1DATEM'
************************************************************************
*
***MOD-009
************************************************************************
*

       READ TABLE I_CONTENTTAB1 INTO WA_CONTENTTAB1 INDEX 1.
       IF WA_CONTENTTAB1-VTNAM NE WA_CONTENTHEADER1-VTNAM.
         MOVE-CORRESPONDING wa_contenttab1 TO wa_file.
         IF ( wa_file-flag = 'X' OR wa_file-flag = 'x' ) .
           APPEND wa_file TO i_file_tmp.
           CLEAR: WA_FILE.
         ENDIF.
       ENDIF.

************************************************************************
*
***MOD-009
************************************************************************
*

       loop at i_contenttab1 into wa_contenttab1
           where VTNAM = wa_contentheader1-VTNAM.
         perform sub_convert_0003.
         clear: wa_contenttab1.
       ENDLOOP.

**********************************************************
**MOD-012
**********************************************************
* Delete Duplicates:

       PERFORM sub_delete_duplicates.

* Get internal variant table number, store in internal table I_CUVTAB
       PERFORM sub_get_cuvtab.

* Get unique number for variant table from table /FACTGLB/DVNT_MA
       PERFORM sub_get_vnt_ma.

* Get internal table fields and their order
       PERFORM sub_get_cuvtab_fld.

*     clear: wa_contentheader1.

* Find out if check is required for characteristic, if no value
* exists in CAWN, no check is required

*  IF g_error <> 'X'.

       PERFORM sub_check_cabn.

* Get already uploaded characteristic values (Character, date, time)
       PERFORM sub_get_cuvtab_valc.

* Get already uploaded characteristic values (Numeric)
       PERFORM sub_get_cuvtab_valn.

* Find table name and characteristic names
       PERFORM sub_validate_table_fields.

* Check if all characteristics of table are defined in file
       PERFORM sub_charac_exist.

* Validate characteristic values
       PERFORM sub_validate_charac_values.

       IF g_error <> c_x.
         PERFORM SUB_CREATE_IDOCS.
         PERFORM SUB_START_IDOC_PROCESS.
       ENDIF.

*********************************************************
*MOD-012
*********************************************************
       clear:  wa_contentheader1.
       CLEAR:  g_cnt_idocs_package,
               itab_zedidc40[],
               itab_zedidd40[].

       CLEAR:  itab_zedidd40[],
               itab_zedidd40[].

       REFRESH: gt_curr_edi_dd40.
       CLEAR  : gt_curr_edi_dd40.

       CLEAR  : g_segnum.

*Work Area for the structure I_MESSTAB
       CLEAR:  wa_vartab,
               wa_vartabdate,
               wa_vardetails,
               wa_tabinput,
               wa_dsninput,
               wa_dsninput,
               wa_newinput,
               wa_gnewinput,
               wa_ginput_data ,
               wa_final,
               wa_content,
               wa_contenthd ,
               wa_contentheader,
               wa_contenttab,
               wa_content1,
               wa_contenthd1,
               wa_contentheader1,
               wa_contenttab1,
               wa_E1CUVTM ,
               wa_E1CUV1M ,
               wa_E1DATEM .

     ENDLOOP.
   ENDIF.
********************************************************
*MOD-012
********************************************************
** Delete Duplicates:
*
*    PERFORM sub_delete_duplicates.
*
** Get internal variant table number, store in internal table I_CUVTAB
*    PERFORM sub_get_cuvtab. " using wa_contentheader1.
*
** Get unique number for variant table from table /FACTGLB/DVNT_MA
*    PERFORM sub_get_vnt_ma. " using wa_contentheader1.
*
** Get internal table fields and their order
*    PERFORM sub_get_cuvtab_fld. " using wa_contentheader1.
*
*    clear: wa_contentheader1.
*
** Find out if check is required for characteristic, if no value
** exists in CAWN, no check is required
*
**  IF g_error <> 'X'.
*
*    PERFORM sub_check_cabn.
*
** Get already uploaded characteristic values (Character, date, time)
*    PERFORM sub_get_cuvtab_valc.
*
** Get already uploaded characteristic values (Numeric)
*    PERFORM sub_get_cuvtab_valn.
*
** Find table name and characteristic names
*    PERFORM sub_validate_table_fields.
*
** Check if all characteristics of table are defined in file
*    PERFORM sub_charac_exist.
*
** Validate characteristic values
*    PERFORM sub_validate_charac_values.
*
** ENDIF.
* ENDIF.
***********************************************************************
**MOD-012
***********************************************************************

 ENDFORM.                    " SUB_CONVERT_TRANSACTION
*&---------------------------------------------------------------------*
*&      Form  SUB_CREATE_IDOCS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_CREATE_IDOCS .

   CONSTANTS:
          C_VTMMAS TYPE EDI_MESTYP VALUE 'VTMMAS'.
   CONSTANTS:
          C_EDI_DC40(8) TYPE C VALUE 'EDI_DC40'.
   CONSTANTS:
          C_2(1) TYPE C VALUE '2'.
   CONSTANTS:
          C_LS(2) TYPE C VALUE 'LS'.
   CONSTANTS:
          C_VTMMAS02(8) TYPE C VALUE 'VTMMAS02'.
   CONSTANTS:
          L_C_X TYPE CHAR1 VALUE 'X'.
* Local Data Declaration
   DATA:
          L_LOGSYS TYPE LOGSYS,
          L_I_MODEL TYPE TABLE OF BDI_MMODEL,
          L_REC_MODEL TYPE BDI_MMODEL,
          L_REC_EDIDC TYPE EDIDC,
          L_REC_EDIDD TYPE EDIDD,
          L_V_CNT TYPE I VALUE 0.

   DATA:
          WA_I_MMODEL TYPE BDI_MMODEL.

   DATA:
          L_TEXT(132),
          L_LINES TYPE I,
          L_IDOC_NR_FROM TYPE I,
          L_IDOC_NR_TO TYPE I,
          L_IDOC_NR_FROM_CHAR(10) TYPE C,
          L_IDOC_NR_TO_CHAR(10) TYPE C,
          L_EDKP1 LIKE EDKP1,
          L_EDK21 LIKE EDK21.

   DATA:
          L_FLG_TRANFERRED_SOMETHING.

   FIELD-SYMBOLS:
     .                                              "#EC *

*******************************************************************
*MOD-009
*******************************************************************
* Getting own logical system
   CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'
     IMPORTING
       own_logical_system             = l_logsys
     EXCEPTIONS
       own_logical_system_not_defined = 1
       OTHERS                         = 2.
   IF sy-subrc <> 0.
     MESSAGE i088.                  "Invalid Logical System
     LEAVE LIST-PROCESSING.
   ENDIF.

* Getting the systems to which the Idocs are to be sent
   CALL FUNCTION 'MMODEL_INT_VALID_GET'
     EXPORTING
       mestyp = C_VTMMAS
     TABLES
       model  = l_i_model.
*     SUBRC check is not required because no exceptions are defined in
*     this FM.
*******************************************************************
*MOD-009
*******************************************************************
*  IF NOT P_SNDPR is initial.
*    SELECT SINGLE * FROM edp21                              "#EC *
*               WHERE sndprn = p_sndpr
*               AND   mestyp = C_VTMMAS.
*    if sy-subrc = 0.
*      p_mestyp  = edp21-mestyp.
*      p_sndprt  = edp21-sndprt.
*    endif.
*  ENDIF.

   SORT l_i_model by sndsystem mestyp rcvsystem.

   READ TABLE l_i_model into wa_i_mmodel with key sndsystem = l_logsys
 binary search.
**************************************************
*MOD-008
**************************************************
   DELETE I_CONTENTTAB1 INDEX 1.
   SORT I_CONTENTTAB1 BY VTNAM.
   DELETE I_CONTENTTAB1 where vtnam is initial.
**************************************************
*MOD-008
**************************************************

**************************************************
*MOD-012
**************************************************

* loop at i_contentheader1 into wa_contentheader1.
**************************************************
*MOD-008
**************************************************
   READ TABLE I_CONTENTTAB1 INTO WA_CONTENTTAB1 WITH KEY VTNAM =
 WA_CONTENTHEADER1-VTNAM BINARY SEARCH.
   IF SY-SUBRC = 0.
**************************************************
*MOD-008
**************************************************
     clear itab_zedidc40.
     wa_itab_zedidc40-tabnam    = C_EDI_DC40.
     wa_itab_zedidc40-docnum    = wdocnum.                  "#EC NEEDED
     wa_itab_zedidc40-direct    = C_2.
     concatenate 'SAP' sy-sysid into wa_itab_zedidc40-rcvpor.
     wa_itab_zedidc40-rcvprt    =  C_LS.
*     itab_zedidc40-rcvprn    = 'ID3CLNT800'.
*     itab_zedidc40-rcvprn    =  p_rcvpr.
     wa_itab_zedidc40-rcvprn    =  wa_i_mmodel-RCVSYSTEM.
     wa_itab_zedidc40-sndpor    = 'SAPT90'.
     wa_itab_zedidc40-sndprt    = C_LS.
*     itab_zedidc40-sndprn    = 'T90CLNT090'.
     wa_itab_zedidc40-sndprn    = l_logsys.
     wa_itab_zedidc40-credat    = sy-datum.
     wa_itab_zedidc40-cretim    = sy-uzeit.
     wa_itab_zedidc40-mestyp    = C_VTMMAS.
     wa_itab_zedidc40-idoctyp   = C_VTMMAS02.
     append wa_itab_zedidc40 to itab_zedidc40.  " Control Record
     clear: wa_contentheader1.
     clear: wa_contenttab1.
   ENDIF.
*  endloop.
**************************************************
*MOD-008
**************************************************

   READ TABLE itab_zedidc40 into wa_itab_zedidc40 INDEX 1.

   IF SY-SUBRC = 0.
     l_edkp1-mandt = sy-mandt.
     l_edkp1-parnum = wa_itab_zedidc40-sndprn.
     l_edkp1-partyp = wa_itab_zedidc40-sndprt.
     CALL FUNCTION 'EDI_AGREE_PARTNER_READ'                 "#EC *
       EXPORTING
         rec_edkp1 = l_edkp1.
     IF sy-subrc <> 0.                                      "#EC *
       MESSAGE i810(/sapdmc/lsmw) WITH wa_itab_zedidc40-sndprn
                                       wa_itab_zedidc40-sndprt.
       EXIT.
     ENDIF.

     l_edk21-mandt = sy-mandt.
     l_edk21-sndprn = wa_itab_zedidc40-sndprn.
     l_edk21-sndprt = wa_itab_zedidc40-sndprt.
     l_edk21-mestyp = wa_itab_zedidc40-mestyp.
     l_edk21-mescod = wa_itab_zedidc40-mescod.
     CALL FUNCTION 'EDI_AGREE_IN_MESSTYPE_READ'             "#EC *
       EXPORTING
         rec_edk21 = l_edk21.
     IF sy-subrc <> 0.                                      "#EC *
       MESSAGE i811(/sapdmc/lsmw) WITH wa_itab_zedidc40-mestyp.
       EXIT.
     ENDIF.
   ENDIF.

   CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'                "#EC *
     EXPORTING
       text = text-010.

   if p_proc = c_x.
     wdocnum = 0.
     if g_error <> c_x.
*************************************************************
*MOD-012
*************************************************************
*     LOOP AT itab_zedidc40 into wa_itab_zedidc40.
*************************************************************
*MOD-012
*************************************************************
       call function 'IDOC_INBOUND_ASYNCHRONOUS'
         TABLES
           idoc_control_rec_40 = itab_zedidc40
*           idoc_control_rec_40 = gt_curr_edi_dc40
           idoc_data_rec_40    = gt_curr_edi_dd40.
       add 1 to g_cnt_transactions_transferred.
       add 1 to g_cnt_transactions_read.
       add 1 to wdocnum.
       IF sy-subrc ne 0.
         perform sub_application_log.
       ENDIF.
*************************************************************
*MOD-012
*************************************************************
*     endloop.
*************************************************************
*MOD-012
*************************************************************

     endif.
     skip 2.
   endif.

   DESCRIBE TABLE itab_zedidc40 LINES l_lines.
   ADD l_lines TO g_cnt_records_transferred.
   DESCRIBE TABLE gt_curr_edi_dd40 LINES l_lines.
   ADD l_lines TO g_cnt_records_transferred.

   CLEAR:
     g_cnt_idocs_package,
     itab_zedidc40[],
     itab_zedidd40[].

   CLEAR:
     itab_zedidd40[],
     itab_zedidd40[].

   REFRESH: gt_curr_edi_dd40.
   CLEAR  : gt_curr_edi_dd40.

   CLEAR g_segnum.

 ENDFORM.                    " SUB_CREATE_IDOCS
*&---------------------------------------------------------------------*
*&      Form  SUB_START_IDOC_PROCESS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_START_IDOC_PROCESS .

   CONSTANTS:
          C_I(1) TYPE C VALUE 'I'.
   CONSTANTS:
          C_EQ(2) TYPE C VALUE 'EQ'.
   CONSTANTS:
          C_VTMMAS(6) TYPE C VALUE 'VTMMAS'.

* RBDAPP01 aufrufen
   R_CREDAT-SIGN = C_I.
   R_CREDAT-OPTION = C_EQ.
   R_CREDAT-LOW = SY-DATUM.
   APPEND R_CREDAT.

   R_CRETIM-SIGN = C_I.
   R_CRETIM-OPTION = C_EQ.
   R_CRETIM-LOW = SY-UZEIT.
   APPEND R_CRETIM.

   R_MESTYP-SIGN = C_I.
   R_MESTYP-OPTION = C_EQ.
   R_MESTYP-LOW = C_VTMMAS.
   APPEND R_MESTYP.

   LOOP AT itab_zedidc40 into wa_itab_zedidc40.
     R_SNDPRT-SIGN = C_I.
     R_SNDPRT-OPTION = C_EQ.
     R_SNDPRT-LOW = wa_itab_zedidc40-sndprt.
     APPEND R_SNDPRT.

     R_SNDPRN-SIGN = C_I.
     R_SNDPRN-OPTION = C_EQ.
     R_SNDPRN-LOW = wa_itab_zedidc40-sndprn.
     APPEND R_SNDPRN.
   ENDLOOP.

   SUBMIT RBDAPP01                                       "#EC CI_SUBMIT
           WITH CREDAT IN R_CREDAT
           WITH CRETIM IN R_CRETIM
           WITH MESTYP IN R_MESTYP
           WITH SNDPRN IN R_SNDPRN
           WITH SNDPRT IN R_SNDPRT
           VIA SELECTION-SCREEN
           AND RETURN.

* Rufe RBDINPUT
   R_MESTYP-SIGN = C_I.
   R_MESTYP-OPTION = C_EQ.
   R_MESTYP-LOW = L_MESSTYPE.
   APPEND R_MESTYP.

   SUBMIT RBDINPUT                                       "#EC CI_SUBMIT
      VIA SELECTION-SCREEN
      AND RETURN.

**CALL TRANSACTION 'WE02'
   SUBMIT RSEIDOC2                                       "#EC CI_SUBMIT
   WITH CREDAT EQ R_CREDAT-LOW SIGN C_I
* WITH DOCNUM EQ GT_ITAB_WA-DOCNUM SIGN 'I'
   AND RETURN.

 ENDFORM.                    " SUB_START_IDOC_PROCESS
*&---------------------------------------------------------------------*
*&      Form  SUB_UPLOAD_FROM_APPSERVER
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_UPLOAD_FROM_APPSERVER .

   open dataset p_fname for input in text mode encoding default.
   if sy-subrc = 0.
     DO.
       READ DATASET p_fname INTO wa_input_data.
       IF sy-subrc NE 0.
         IF g_cnt_input_recs = 0.
           MESSAGE i242.
           g_flg_error = C_Y.
           STOP.
         ENDIF.
         EXIT.
       ELSE.
         APPEND wa_input_data to i_input_data.
         ADD 1 TO g_cnt_input_recs.
         CLEAR: wa_input_data.
       ENDIF.
     ENDDO.
   else.
     message e246 with text-003.
   endif.
   close dataset p_fname.

   open dataset p_fname1 for input in text mode encoding default.
   if sy-subrc = 0.
     DO.
       READ DATASET p_fname1 INTO wa_input_data1.
       IF sy-subrc NE 0.
         IF g_cnt_input_recs = 0.
*         MESSAGE s000 WITH 'Input file is empty'.
           MESSAGE i242.
           g_flg_error = C_Y.
           STOP.
         ENDIF.
         EXIT.
       ELSE.
         APPEND wa_input_data1 to i_input_data1.
         ADD 1 TO g_cnt_input_recs.
         CLEAR: wa_input_data1.
       ENDIF.
     ENDDO.
   else.
     message e246 with text-003.
   endif.
   close dataset p_fname1.

   delete i_input_data index 1.

   delete i_input_data1 INDEX 1.

   loop at i_input_data INTO WA_INPUT_DATA.

     SPLIT wa_input_data AT CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB
                                         INTO wa_contenthd-vtnam
                                              wa_contenthd-flag.

     append wa_contenthd to i_contentheader1.
     clear: wa_contenthd.
   endloop.

   loop at i_input_data1 INTO WA_INPUT_DATA1.

     SPLIT wa_input_data1 AT CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB
                                        INTO       wa_content1-VTNAM
                                                   wa_content1-CHAR1
                                                   wa_content1-CHAR2
                                                   wa_content1-CHAR3
                                                   wa_content1-CHAR4
                                                   wa_content1-CHAR5
                                                   wa_content1-CHAR6
                                                   wa_content1-CHAR7
                                                   wa_content1-CHAR8
                                                   wa_content1-CHAR9
                                                   wa_content1-CHAR10
                                                   wa_content1-CHAR11
                                                   wa_content1-CHAR12
                                                   wa_content1-CHAR13
                                                   wa_content1-CHAR14
                                                   wa_content1-CHAR15
                                                   wa_content1-FLAG.
     append wa_content1 to i_contenttab1.
     clear: wa_content1.
   endloop.

 ENDFORM.                    " SUB_UPLOAD_FROM_APPSERVER
*&---------------------------------------------------------------------*
*&      Form  SUB_UPLOAD_FROM_PRESERVER
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_UPLOAD_FROM_PRESERVER .

   CONSTANTS:
          C_ASC(10) TYPE C VALUE 'ASC'.

* Read file from NT server into a table
   file = p_inpt.

   call function 'GUI_UPLOAD'
     EXPORTING
       filename                = file
       filetype                = 'ASC'
     TABLES
       data_tab                = i_input_data
     EXCEPTIONS
       file_open_error         = 1
       file_read_error         = 2
       no_batch                = 3
       gui_refuse_filetransfer = 4
       invalid_type            = 5
       no_authority            = 6
       unknown_error           = 7
       bad_data_format         = 8
       header_not_allowed      = 9
       separator_not_allowed   = 10
       header_too_long         = 11
       unknown_dp_error        = 12
       access_denied           = 13
       dp_out_of_memory        = 14
       disk_full               = 15
       dp_timeout              = 16
       others                  = 17.

   if sy-subrc ne 0.
     write: / text-036:, p_inpt.
     skip 2.
     stop.
   endif.

* Read file from NT server into a table
   CLEAR: file.
   file = p_inpt1.

   call function 'GUI_UPLOAD'
     EXPORTING
       filename                = file
       filetype                = 'ASC'
     TABLES
       data_tab                = i_input_data1
     EXCEPTIONS
       file_open_error         = 1
       file_read_error         = 2
       no_batch                = 3
       gui_refuse_filetransfer = 4
       invalid_type            = 5
       no_authority            = 6
       unknown_error           = 7
       bad_data_format         = 8
       header_not_allowed      = 9
       separator_not_allowed   = 10
       header_too_long         = 11
       unknown_dp_error        = 12
       access_denied           = 13
       dp_out_of_memory        = 14
       disk_full               = 15
       dp_timeout              = 16
       others                  = 17.

   if sy-subrc ne 0.
     write: / text-036:, p_inpt.
     skip 2.
     stop.
   endif.

   delete i_input_data INDEX 1.
   delete i_input_data1 index 1.

   loop at i_input_data into wa_input_data.

     SPLIT wa_input_data AT CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB
                                         INTO wa_contenthd-vtnam
                                              wa_contenthd-flag.
     append wa_contenthd to i_contentheader1.
     clear: wa_contenthd.
   endloop.

   loop at i_input_data1 into wa_input_data1.

     SPLIT wa_input_data1 AT CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB
                                        INTO       wa_content1-VTNAM
                                                   wa_content1-CHAR1
                                                   wa_content1-CHAR2
                                                   wa_content1-CHAR3
                                                   wa_content1-CHAR4
                                                   wa_content1-CHAR5
                                                   wa_content1-CHAR6
                                                   wa_content1-CHAR7
                                                   wa_content1-CHAR8
                                                   wa_content1-CHAR9
                                                   wa_content1-CHAR10
                                                   wa_content1-CHAR11
                                                   wa_content1-CHAR12
                                                   wa_content1-CHAR13
                                                   wa_content1-CHAR14
                                                   wa_content1-CHAR15
                                                   wa_content1-FLAG.
     append wa_content1 to i_contenttab1.
     clear: wa_content1.
   endloop.

 ENDFORM.                    " SUB_UPLOAD_FROM_PRESERVER
*&---------------------------------------------------------------------*
*&      Form  SUB_FINAL_MESSAGE_IDOC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_FINAL_MESSAGE_IDOC .

   DATA:
          L_TABIX LIKE SY-TABIX, " Index of Internal Tables
          L_FILENAME_READ TYPE TUMLS_FILENAME,
          L_FILENAME_CONV TYPE TUMLS_FILENAME.

   DATA:
          L_CNT_RECORDS_READ(10) TYPE C,
          L_CNT_TRANSACTIONS_READ(10) TYPE C,
          L_CNT_RECORDS_TRANSFERRED(10) TYPE C,
          L_CNT_TRANSACTIONS_TRANSFERRED(10) TYPE C.

   DATA:
          L_MESSAGETEXT(130),
          WA_ERRORTAB TYPE TYPE_ERRORLINE.

   l_cnt_records_read = g_cnt_records_read.
   l_cnt_transactions_read = g_cnt_transactions_read.
   l_cnt_records_transferred = g_cnt_records_transferred.
   l_cnt_transactions_transferred = g_cnt_transactions_transferred.

   WRITE: / 'DATE:', sy-datum DD/MM/YYYY,
            '-',
            'TIME:', sy-uzeit USING EDIT MASK '_::_ h'.

   ULINE.

   ULINE.

   WRITE: / 'Inbound Idoc Creation Variant Table'(002).     "#EC *

****************************************************************
*MOD-009
****************************************************************
   ULINE.

   WRITE: / 'Transactions Read.'(024),                      "#EC *
          30 g_cnt_transactions_read.
   WRITE: / 'Transactions Transferred:'(026),               "#EC *
          30 g_cnt_transactions_transferred.
   WRITE: / 'Records Transferred:'(027),                    "#EC *
          30 g_cnt_records_transferred.

   ULINE.
****************************************************************
*MOD-009
****************************************************************

*****************************************************
*MOD-008
*****************************************************
*  IF NOT g_error_tab IS INITIAL.
*    LOOP AT g_error_tab INTO wa_errortab.
*      AT NEW msgty.
*        CASE wa_errortab-msgty.
*          WHEN 'E'.
*            SKIP.
*            WRITE / icon_message_critical AS ICON .
*          WHEN 'I'.
*            SKIP.
*            WRITE / icon_green_light AS ICON .
*          WHEN 'S'.
*            SKIP.
*            WRITE / icon_red_light AS ICON .
*          WHEN 'W'.
*            SKIP.
*            WRITE / icon_yellow_light AS ICON .
*          WHEN 'A'.
*            SKIP.
*            WRITE / icon_alert AS ICON .
*          WHEN 'X'.
*            SKIP.
*            WRITE / icon_action_fault AS ICON .
*          WHEN OTHERS.
*           usually can't happen
*            SKIP.
*            WRITE / icon_message_critical AS ICON .
*            wa_errortab-msgty = 'E'.
*            MODIFY g_error_tab FROM wa_errortab.
*        ENDCASE.
*      ENDAT.
*      AT NEW par1.
*        WRITE: /
*     '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ',
*        '- - - - - - - - - - - - - - - - -  '.
*      ENDAT.
*      AT NEW par2.
*        SKIP.
*      ENDAT.
*      MESSAGE ID wa_errortab-id
*              TYPE wa_errortab-msgty
*              NUMBER wa_errortab-msgno
*              WITH wa_errortab-par1 wa_errortab-par2
*                   wa_errortab-par3 wa_errortab-par4
*      INTO l_messagetext.
*      WRITE l_messagetext.
*    ENDLOOP.
*    SKIP.
*    ULINE.
*  ENDIF.
*****************************************************
*MOD-008
*****************************************************

 ENDFORM.                    " SUB_FINAL_MESSAGE_IDOC
*&---------------------------------------------------------------------*
*&      Form  SUB_DISPLAY_VARIANT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_DISPLAY_VARIANT .

   IF NOT i_cuv_error IS INITIAL.
     SKIP 2.
*   WRITE:/ 'Following tables have incorrect characteristic names'(013).
                                                            "#EC NOTEXT
     WRITE:/ text-013.                                      "#EC NOTEXT

     WRITE:/ sy-uline(72).
     FORMAT COLOR 1 ON.
     WRITE:/1   sy-vline,
                2  text-014,                                "#EC NOTEXT
                20 sy-vline,
                21 text-015,                                "#EC NOTEXT
                72 sy-vline.
     FORMAT COLOR 1 OFF.
     WRITE:/ sy-uline(72).
     LOOP AT i_cuv_error INTO wa_vtnam.
       WRITE:/1   sy-vline,
              2 wa_vtnam-vtnam,
             20 sy-vline,
             21 wa_vtnam-reas,
             72 sy-vline.
       WRITE:/ sy-uline(72).
     ENDLOOP.
   ENDIF.

 ENDFORM.                    " SUB_DISPLAY_VARIANT
*&---------------------------------------------------------------------*
*&      Form  SUB_DISPLAY_ERRORLINES
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_DISPLAY_ERRORLINES .

   SKIP 2.
   IF NOT i_error IS INITIAL.
     FORMAT COLOR 1 ON.
*    WRITE:/ 'Following lines have invalid/blank values'.    "#EC NOTEXT
     WRITE:/ text-016.                                      "#EC NOTEXT

     SKIP.
     WRITE:/ sy-uline(120).
     WRITE:/1  sy-vline,
            2  'Variant table'(017),                        "#EC NOTEXT
            20 sy-vline,
            21 'Fieldname'(018),                            "#EC NOTEXT
            51 sy-vline,
            52 'Characteristic name'(019),                  "#EC NOTEXT
            82 sy-vline,
            83 'Characteristic value'(020),                 "#EC NOTEXT
            113 sy-vline,
            114 'Row no'(021),                              "#EC NOTEXT
            120 sy-vline.
     FORMAT COLOR 1 OFF.
     WRITE:/ sy-uline(120).
     LOOP AT i_error INTO wa_error.
       WRITE:/1  sy-vline,
              2  wa_error-vtnam,
              20 sy-vline,
              21 wa_error-fname+8(6),
              51 sy-vline,
              52 wa_error-atnam,
              82 sy-vline,
              83 wa_error-atwrt,
              113 sy-vline,
              114 wa_error-row,
              120 sy-vline.
       WRITE:/ sy-uline(120).
     ENDLOOP.
   ENDIF.

 ENDFORM.                    " SUB_DISPLAY_ERRORLINES

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

   Refresh: I_CONTENTHEADER1,
            I_CONTENTTAB1.

****************************
* REFRESH GLOBAL WORK AREAS
****************************

*Work Area for the structure I_MESSTAB
   CLEAR:  wa_vartab,
           wa_vartabdate,
           wa_vardetails,
           wa_tabinput,
           wa_dsninput,
           wa_dsninput,
           wa_newinput,
           wa_gnewinput,
           wa_ginput_data ,
           wa_final,
           wa_content,
           wa_contenthd ,
           wa_contentheader,
           wa_contenttab,
           wa_content1,
           wa_contenthd1,
           wa_contentheader1,
           wa_contenttab1,
           wa_E1CUVTM ,
           wa_E1CUV1M ,
           wa_E1DATEM .

*************************************************
* REFRESH INTERNAL TABLES AND WORK AREAS FOR BDC
*************************************************

*Internal Table to store the data to display the error message
   REFRESH i_errormsg[] .

*Internal Table to store the data to display the error message
   REFRESH i_error[].

**Work area to store the data to display the error message
   CLEAR wa_errormsg.

*Internal table which will store data for the error log
   REFRESH i_error_log[] .

***************************
* REFRESH GLOBAL VARIABLES
***************************
   CLEAR: g_ctr_input_recs,
          g_ctr_output_recs,
          g_msg,
*        g_struct_file,
          g_login,
          g_phyin ,
          g_FNAME1,
          g_repid,
          g_exit,
          gx_variant,
          g_lines ,
          g_save,
          g_splid ,
          p_login ,
          p_phyin.

*************************************************
* REFRESH GLOBAL INTERNAL TABLES FOR ALV DISPLAY
*************************************************
*Refresh Internal tables for ALV Field cat
   REFRESH i_fieldcat_ov[].
   REFRESH i_fieldcat_dtl[].
   REFRESH i_fieldcat_ov1[].
   REFRESH i_events[].

   Refresh:  itab_zedidc40,
             itab_zedidd40,
             gt_curr_edi_dc40,
             gt_curr_edi_dd40.

   CLEAR:   i_file,
            i_file_tmp,
            i_cuvtab_fld,
            i_cuvtab_valn,
            i_cuvtab,
            i_cuvtab_valc,
            i_col_pos,
            g_slnid_c,
            g_slnid_n,
            g_split_var.

 ENDFORM.                    " SUB_CLEAR_SOURCE_TABLES
*&---------------------------------------------------------------------*
*&      Form  SUB_CLEAR_TABLES
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_CLEAR_TABLES .

   Refresh:  itab_zedidc40,
             itab_zedidd40,
             gt_curr_edi_dc40,
             gt_curr_edi_dd40.

   CLEAR:  i_file,
           i_file_tmp,
           i_cuvtab_fld,
           i_cuvtab_valn,
           i_cuvtab,
           i_cuvtab_valc,
           i_col_pos,
           g_slnid_c,
           g_slnid_n,
           g_split_var.

 ENDFORM.                    " SUB_CLEAR_TABLES
*&---------------------------------------------------------------------*
*&      Form  SUB_CONVERT_0001
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_CONVERT_0001 .

   CONSTANTS:
          C_01(2) TYPE C VALUE '01'.

   clear itab_ze1cuvtm.
   clear itab_zedidd40.
   wdocnum = wdocnum + 1.
   itab_ze1cuvtm-msgfn           = c_009.
   if not wa_contentheader1-vtnam is initial.
     itab_ZE1CUVTM-VAR_TAB       = wa_contentheader1-vtnam.
   endif.

   wa_itab_zedidd40-docnum   = wdocnum.                     "#EC NEEDED
   wa_itab_zedidd40-segnum   = c_000001.
   wa_itab_zedidd40-segnam   = 'E2CUVTM001'.
   wa_itab_zedidd40-psgnum    = '000000'.
* itab_zedidd40-segnam          = c_E1CUVTM.
   wa_itab_zedidd40-hlevel          = c_01.
   wa_itab_zedidd40-sdata           = itab_ze1cuvtm.
   append wa_itab_zedidd40 to itab_zedidd40.

   perform transfer_record_idoc.

 ENDFORM.                    " SUB_CONVERT_0001
*&---------------------------------------------------------------------*
*&      Form  SUB_CONVERT_0002
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_CONVERT_0002 .

* ze1datem
   witemno = witemno + 1.                                   "#EC NEEDED
   wsegnum = wsegnum + 1.                                   "#EC NEEDED
   clear itab_ze1datem.
   itab_ze1datem-msgfn           = c_009.
   itab_ze1datem-key_date        = sy-datum.

   wa_itab_zedidd40-segnam = 'E2DATEM001'.
   wa_itab_zedidd40-segnum = '0002'.
   wa_itab_zedidd40-psgnum = '000001'.
   wa_itab_zedidd40-hlevel          = c_02.
   wa_itab_zedidd40-sdata           = itab_ze1datem.
   append wa_itab_zedidd40 to itab_zedidd40.                " E1DATEM
   witemno = 0.                                             "#EC NEEDED
   witemno_gst = 0.                                         "#EC NEEDED
   witemno_qst = 0.                                         "#EC NEEDED
   witemno_new = 0.                                         "#EC NEEDED
   wsegnum = 1.                                             "#EC NEEDED

   perform transfer_record_idoc.

 ENDFORM.                    " SUB_CONVERT_0002
*&---------------------------------------------------------------------*
*&      Form  SUB_CONVERT_0003
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_CONVERT_0003 .

   perform sub_store_file.

 ENDFORM.                    " SUB_CONVERT_0003
*&---------------------------------------------------------------------*
*&      Form  SUB_GET_CUVTAB
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_GET_CUVTAB .

   CLEAR g_error.

***********************************************************
*MOD-012
***********************************************************
* LOOP AT I_CONTENTHEADER1 INTO WA_CONTENTHEADER1.
***********************************************************
*MOD-012
***********************************************************

   SELECT vtint vtnam FROM cuvtab
   INTO CORRESPONDING FIELDS OF TABLE i_cuvtab
   WHERE vtnam = wa_contentheader1-vtnam.
   IF sy-subrc <> 0.
     g_error = c_x.
     CLEAR wa_vtnam.
     wa_vtnam-vtnam = wa_contentheader1-vtnam.
     wa_vtnam-reas = text-008.
     APPEND wa_vtnam TO i_cuv_error.
     wa_errortab-msgty = 'E'.
     wa_errortab-id = 'ZFACTGLB'.
     wa_errortab-msgno = 145.
     wa_errortab-par1 = wa_vtnam-reas.
     INSERT wa_errortab INTO TABLE g_error_tab.
     clear: wa_vtnam, wa_errortab.
   ENDIF.
***********************************************************
*MOD-012
***********************************************************
*   clear: WA_CONTENTHEADER1.
***********************************************************
*MOD-012
***********************************************************
* ENDLOOP.
***********************************************************
*MOD-012
***********************************************************

 ENDFORM.                    " SUB_GET_CUVTAB
*&---------------------------------------------------------------------*
*&      Form  SUB_GET_VNT_MA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_GET_VNT_MA .

   CONSTANTS:
          C_E(1) TYPE C VALUE 'E',
          C_001(3) TYPE C VALUE '001'.

   CLEAR wa_vnt_ma.

**************************************************
*MOD-012
**************************************************
* LOOP AT I_CONTENTHEADER1 INTO WA_CONTENTHEADER1.
**************************************************
*MOD-012
**************************************************

   SELECT SINGLE vtnam unique_no no_chr
   FROM ZDVNT_MA
   INTO wa_vnt_ma
   WHERE vtnam = wa_contentheader1-vtnam.

   IF sy-subrc <> 0.
     g_error = 'X'.
     CLEAR wa_vtnam.
     wa_vtnam-vtnam = wa_contentheader1-vtnam.
     wa_vtnam-error = c_x.
     wa_vtnam-reas = text-023                        .      "#EC NOTEXT
     APPEND wa_vtnam TO i_cuv_error.
     wa_errortab-msgty = c_e.
     wa_errortab-id = 'ZFACTGLB'.
     wa_errortab-msgno = 250.
     wa_errortab-par1 = wa_vtnam-reas.
     INSERT wa_errortab INTO TABLE g_error_tab.
     clear: wa_vtnam, wa_errortab.
   ENDIF.
**************************************************
*MOD-012
**************************************************
*    clear: wa_contentheader1.
*  ENDLOOP.
**************************************************
*MOD-012
**************************************************

 ENDFORM.                    " SUB_GET_VNT_MA
*&---------------------------------------------------------------------*
*&      Form  SUB_GET_CUVTAB_VALN
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_GET_CUVTAB_VALN .

   IF NOT i_cuvtab[] IS INITIAL.
     SELECT vtint slnid atinn val_from
     FROM cuvtab_valn INTO TABLE i_cuvtab_valn
     FOR ALL ENTRIES IN i_cuvtab
     WHERE vtint = i_cuvtab-vtint.

     IF sy-subrc = 0.
       SORT i_cuvtab_valn BY vtint slnid.
     ENDIF.
   ENDIF.

 ENDFORM.                    " SUB_GET_CUVTAB_VALN
*&---------------------------------------------------------------------*
*&      Form  SUB_GET_CUVTAB_FLD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_GET_CUVTAB_FLD .

   IF g_error <> c_x.

     IF NOT i_cuvtab[] IS INITIAL.
       SELECT vtint atinn vtpos FROM cuvtab_fld
       INTO TABLE i_cuvtab_fld
       FOR ALL ENTRIES IN i_cuvtab
       WHERE vtint = i_cuvtab-vtint.

       IF sy-subrc = 0.
         SORT i_cuvtab_fld BY vtint atinn.
       ELSE.
         LOOP AT I_CONTENTHEADER1 INTO WA_CONTENTHEADER1.

           Sort i_cuvtab by vtint vtnam.
           READ TABLE i_cuvtab INTO wa_vtnam WITH KEY VTNAM =
 WA_CONTENTHEADER1-VTNAM BINARY SEARCH.
           IF SY-SUBRC = 0.
             g_error = c_x.
             CLEAR wa_vtnam.
             wa_vtnam-vtnam = wa_contentheader1-vtnam.
             wa_vtnam-reas = text-009.
             APPEND wa_vtnam TO i_cuv_error.
             wa_errortab-msgty = c_e.
             wa_errortab-id = 'ZFACTGLB'.
             wa_errortab-msgno = 251.
             wa_errortab-par2 = wa_vtnam-reas.
             INSERT wa_errortab INTO TABLE g_error_tab.
             clear: wa_vtnam, wa_errortab.
           ENDIF.
         ENDLOOP.
       ENDIF.
     ENDIF.
   ENDIF.

 ENDFORM.                    " SUB_GET_CUVTAB_FLD
*&---------------------------------------------------------------------*
*&      Form  SUB_CHECK_CABN
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_CHECK_CABN .

   LOOP AT i_cabn ASSIGNING .
     READ TABLE i_cawn_i INTO wa_cawn WITH KEY atinn = -atinn.
     IF sy-subrc <> 0.
       -check = C_X.
     ENDIF.
   ENDLOOP.

 ENDFORM.                    " SUB_CHECK_CABN
*&---------------------------------------------------------------------*
*&      Form  SUB_GET_CUVTAB_VALC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_GET_CUVTAB_VALC .

   IF NOT i_cuvtab[] is initial.
     SELECT vtint slnid atinn valc
     FROM cuvtab_valc INTO TABLE i_cuvtab_valc
     FOR ALL ENTRIES IN i_cuvtab
     WHERE vtint = i_cuvtab-vtint.
     IF sy-subrc = 0.
       SORT i_cuvtab_valc BY vtint slnid.
     ENDIF.
   ENDIF.

 ENDFORM.                    " SUB_GET_CUVTAB_VALC
*&---------------------------------------------------------------------*
*&      Form  SUB_VALIDATE_TABLE_FIELDS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_VALIDATE_TABLE_FIELDS .

   SORT I_FILE_TMP BY VTNAM.
   LOOP AT i_cuvtab ASSIGNING .
     READ TABLE i_file_tmp INTO wa_file WITH KEY flag  = 'X'.

     IF sy-subrc <> 0.
* Row containing characteristic names might have 'x' instead of 'X'
       READ TABLE i_file_tmp INTO wa_file WITH KEY flag  = 'x'.
       IF sy-subrc <> 0.
         -error = C_X.
         -reas  = text-011.                       "#EC NOTEXT
         g_error = 'X'.
         CLEAR wa_vtnam.
         wa_vtnam = .
         APPEND wa_vtnam TO i_cuv_error.
         wa_errortab-msgty = C_E.
         wa_errortab-id = 'ZFACTGLB'.
         wa_errortab-msgno = 252.
         wa_errortab-par2 = wa_vtnam-reas.
         INSERT wa_errortab INTO TABLE g_error_tab.
         clear: wa_vtnam, wa_errortab.
         EXIT.
       ENDIF.
     ELSE.
*   Check for characteristic name 1
       IF wa_file-char1 IS NOT INITIAL.
         CLEAR wa_cabn.

         PERFORM get_internal_char USING wa_file-char1
                                CHANGING wa_cabn
                                         .

*      Find out if characteristic name exists in variant table definitio
         PERFORM find_char_exist USING wa_file
                                      
                                       wa_cabn.
       ENDIF.

       CHECK -error IS INITIAL.
*   Check for characteristic name 2
       IF wa_file-char2 IS NOT INITIAL.
         CLEAR wa_cabn.
         PERFORM get_internal_char USING wa_file-char2
                                CHANGING wa_cabn
                                         .
*      Find out if characteristic name exists in variant table definitio
         PERFORM find_char_exist USING wa_file
                                      
                                       wa_cabn.
       ENDIF.
       CHECK -error IS INITIAL.
*   Check for characteristic name 3
       IF wa_file-char3 IS NOT INITIAL.
         CLEAR wa_cabn.
         PERFORM get_internal_char USING wa_file-char3
                                CHANGING wa_cabn
                                         .
*      Find out if characteristic name exists in variant table definitio
         PERFORM find_char_exist USING wa_file
                                      
                                       wa_cabn.

       ENDIF.
*   Check for characteristic name 4
       IF wa_file-char4 IS NOT INITIAL.
         CLEAR wa_cabn.
         PERFORM get_internal_char USING wa_file-char4
                                   CHANGING wa_cabn
                                         .
*      Find out if characteristic name exists in variant table definitio
         PERFORM find_char_exist USING wa_file
                                      
                                       wa_cabn.

       ENDIF.
       CHECK -error IS INITIAL.
*   Check for characteristic name 5
       IF wa_file-char5 IS NOT INITIAL.
         CLEAR wa_cabn.
         PERFORM get_internal_char USING wa_file-char5
                                CHANGING wa_cabn
                                         .
*      Find out if characteristic name exists in variant table definitio
         PERFORM find_char_exist USING wa_file
                                      
                                       wa_cabn.

       ENDIF.
       CHECK -error IS INITIAL.
*   Check for characteristic name 6
       IF wa_file-char6 IS NOT INITIAL.
         CLEAR wa_cabn.
         PERFORM get_internal_char USING wa_file-char6
                                CHANGING wa_cabn
                                         .
*      Find out if characteristic name exists in variant table definitio
         PERFORM find_char_exist USING wa_file
                                      
                                       wa_cabn.

       ENDIF.
       CHECK -error IS INITIAL.
*   Check for characteristic name 7
       IF wa_file-char7 IS NOT INITIAL.
         CLEAR wa_cabn.
         PERFORM get_internal_char USING wa_file-char7
                                CHANGING wa_cabn
                                         .

*      Find out if characteristic name exists in variant table definitio
         PERFORM find_char_exist USING wa_file
                                      
                                       wa_cabn.

       ENDIF.
       CHECK -error IS INITIAL.
*   Check for characteristic name 8
       IF wa_file-char8 IS NOT INITIAL.
         CLEAR wa_cabn.
         PERFORM get_internal_char USING wa_file-char8
                                CHANGING wa_cabn
                                         .
*      Find out if characteristic name exists in variant table definitio
         PERFORM find_char_exist USING wa_file
                                      
                                       wa_cabn.

       ENDIF.
       CHECK -error IS INITIAL.
*   Check for characteristic name 9
       IF wa_file-char9 IS NOT INITIAL.
         CLEAR wa_cabn.
         PERFORM get_internal_char USING wa_file-char9
                                CHANGING wa_cabn
                                         .
*      Find out if characteristic name exists in variant table definitio
         PERFORM find_char_exist USING wa_file
                                      
                                       wa_cabn.

       ENDIF.
       CHECK -error IS INITIAL.
*   Check for characteristic name 10
       IF wa_file-char10 IS NOT INITIAL.
         CLEAR wa_cabn.
         PERFORM get_internal_char USING wa_file-char10
                                CHANGING wa_cabn
                                         .
*      Find out if characteristic name exists in variant table definitio
         PERFORM find_char_exist USING wa_file
                                      
                                       wa_cabn.

       ENDIF.
       CHECK -error IS INITIAL.
*   Check for characteristic name 11
       IF wa_file-char11 IS NOT INITIAL.
         CLEAR wa_cabn.
         PERFORM get_internal_char USING wa_file-char11
                                CHANGING wa_cabn
                                         .
*      Find out if characteristic name exists in variant table definitio
         PERFORM find_char_exist USING wa_file
                                      
                                       wa_cabn.

       ENDIF.
       CHECK -error IS INITIAL.
*   Check for characteristic name 12
       IF wa_file-char12 IS NOT INITIAL.
         CLEAR wa_cabn.
         PERFORM get_internal_char USING wa_file-char12
                                CHANGING wa_cabn
                                         .
*      Find out if characteristic name exists in variant table definitio
         PERFORM find_char_exist USING wa_file
                                      
                                       wa_cabn.

       ENDIF.
       CHECK -error IS INITIAL.
*   Check for characteristic name 13
       IF wa_file-char13 IS NOT INITIAL.
         CLEAR wa_cabn.
         PERFORM get_internal_char USING wa_file-char13
                                CHANGING wa_cabn
                                         .
*      Find out if characteristic name exists in variant table definitio
         PERFORM find_char_exist USING wa_file
                                      
                                       wa_cabn.

       ENDIF.
       CHECK -error IS INITIAL.
*   Check for characteristic name 14
       IF wa_file-char14 IS NOT INITIAL.
         CLEAR wa_cabn.
         PERFORM get_internal_char USING wa_file-char14
                                CHANGING wa_cabn
                                         .
*      Find out if characteristic name exists in variant table definitio
         PERFORM find_char_exist USING wa_file
                                      
                                       wa_cabn.

       ENDIF.
       CHECK -error IS INITIAL.
*   Check for characteristic name 15
       IF wa_file-char15 IS NOT INITIAL.
         CLEAR wa_cabn.
         PERFORM get_internal_char USING wa_file-char15
                                CHANGING wa_cabn
                                         .
*      Find out if characteristic name exists in variant table definitio
         PERFORM find_char_exist USING wa_file
                                      
                                       wa_cabn.

       ENDIF.
     ENDIF.
   ENDLOOP.

 ENDFORM.                    " SUB_VALIDATE_TABLE_FIELDS
*&---------------------------------------------------------------------*
*&      Form  SUB_CHARAC_EXIST
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_CHARAC_EXIST .

   IF g_error <> 'X'.

     LOOP AT i_cuvtab_fld INTO wa_cuvtab_fld WHERE exist = space.
       g_error = 'X'.
       CLEAR wa_vtnam.
       READ TABLE i_cuvtab INTO wa_vtnam WITH KEY
       vtint = wa_cuvtab_fld-vtint.
* No need to check sy-subrc here
       READ TABLE i_cabn INTO wa_cabn WITH KEY atinn =
 wa_cuvtab_fld-atinn.
* No need to check sy-subrc here

       CONCATENATE wa_cabn-atnam text-022                   "#EC NOTEXT
       INTO wa_vtnam-reas SEPARATED BY space.
       APPEND wa_vtnam TO i_cuv_error.
       wa_errortab-msgty = C_E.
       wa_errortab-id = 'ZFACTGLB'.
       wa_errortab-msgno = 252.
       wa_errortab-par1 = wa_vtnam-reas.
       INSERT wa_errortab INTO TABLE g_error_tab.
       clear: wa_vtnam, wa_errortab.
     ENDLOOP.
   ENDIF.

 ENDFORM.                    " SUB_CHARAC_EXIST
*&---------------------------------------------------------------------*
*&      Form  SUB_VALIDATE_CHARAC_VALUES
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_VALIDATE_CHARAC_VALUES .

   LOOP AT i_cuvtab INTO wa_vtnam WHERE error <> c_x.
     CLEAR i_dupl_file. "A
*   Clear internal table for duplicate entries
     CLEAR i_dupl.
* Transfer already stored characteristic values (CHAR, DATE and TIME)
     PERFORM sub_transfer_st_char.

* Transfer already stored characteristic values (Numeric)
     PERFORM sub_transfer_st_num.

* Check if Internal table for duplicate records is populated or not
     IF NOT i_dupl IS INITIAL.
       SORT i_dupl. " BY vtnam char1 char2 char3
       " char4 char5 char6 char7
       "  char8 char9 char10 char11
       "  char12 char13 char14 char15.
     ENDIF.

*************************************************
*MOD-012
*************************************************
*    SORT i_col_pos BY  vtint
*                       vtnam
*                       atinn
*                       atnam.
*************************************************
*MOD-012
*************************************************

*  Check current sequence number for SLNID
*  We would only use G_SLNID_C from here onwards for sequnce purpose
     IF g_slnid_c < g_slnid_n.
       g_slnid_c = g_slnid_n.
     ENDIF.

     LOOP AT i_file INTO wa_file WHERE vtnam = wa_vtnam-vtnam.
       CLEAR wa_dupl_file.

       CLEAR i_e1cuv1m.
*   Increment Sequence counter for each record
       g_slnid_c = g_slnid_c + 1.

*   Increment Sequnce counter for concatenation
       g_split_var = g_split_var + 1.

*    Counter for each row
       g_row = g_row + 1.
       CLEAR g_invalid.
*******************************************
*MOD-008
*******************************************
       PERFORM sub_check_char_values.
*******************************************
*MOD-008
*******************************************
*     Check for duplicate values
       READ TABLE i_dupl INTO wa_dupl
       WITH KEY vtnam = wa_dupl_file-vtnam
                char1 = wa_dupl_file-char1
                char2 = wa_dupl_file-char2
                char3 = wa_dupl_file-char3
                char4 = wa_dupl_file-char4
                char5 = wa_dupl_file-char5
                char6 = wa_dupl_file-char6
                char7 = wa_dupl_file-char7
                char8 = wa_dupl_file-char8
                char9 = wa_dupl_file-char9
                char10 = wa_dupl_file-char10
                char11 = wa_dupl_file-char11
                char12 = wa_dupl_file-char12
                char13 = wa_dupl_file-char13
                char14 = wa_dupl_file-char14
                char15 = wa_dupl_file-char15.

       IF sy-subrc = 0.
         g_invalid = 'X'.
*     Reduce counter by 1 to maintain sequence
         g_split_var = g_split_var - 1.
       ELSE.
         CLEAR wa_dupl.
         wa_dupl = wa_dupl_file.
         APPEND wa_dupl TO i_dupl.
         CLEAR wa_dupl.
       ENDIF.

*****************************************************
**mod-012
****************************************************
       wa_e1cuv1m-msgfn = C_009.
       wa_e1cuv1m-vtlineno5 = g_slnid_c.
       wa_e1cuv1m-vtcharact = c_varcond.
       wa_e1cuv1m-atwrt  = g_varcond.
       APPEND wa_e1cuv1m TO i_e1cuv1m.

*************************************************************
*MOD-012
*************************************************************

*******************************************************************
**MOD-012
*******************************************************************
       IF g_invalid IS INITIAL.
         LOOP AT i_e1cuv1m INTO wa_e1cuv1m.
*         perform fill_edidd_segments USING wa_e1cuv1m.
           PERFORM transfer_e1cuv1m. " USING wa_e1cuv1m.    "#EC *
         ENDLOOP.
       ENDIF.
*******************************************************************
**MOD-012
*******************************************************************
       clear: g_invalid.
*******************************************************************
**MOD-012
******************************************************************
     ENDLOOP.
   ENDLOOP.

 ENDFORM.                    " SUB_VALIDATE_CHARAC_VALUES
*&---------------------------------------------------------------------*
*&      Form  SUB_TRANSFER_ST_CHAR
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_TRANSFER_ST_CHAR .

   DATA:
          L_LINES TYPE I.

   LOOP AT i_cuvtab_valc INTO wa_cuvtab_valc
                          WHERE vtint = wa_vtnam-vtint.
     CLEAR wa_cabn.
     READ TABLE i_cabn_atinn INTO wa_cabn
     WITH KEY atinn = wa_cuvtab_valc-atinn BINARY SEARCH.
* No need to check sy-subrc here
     CLEAR wa_e1cuv1m.
     wa_e1cuv1m-msgfn = c_009.
     wa_e1cuv1m-vtlineno5 = wa_cuvtab_valc-slnid.
     wa_e1cuv1m-vtcharact = wa_cabn-atnam.
     wa_e1cuv1m-atwrt = wa_cuvtab_valc-valc.
****************************************************
*MOD-008
****************************************************
     PERFORM transfer_e1cuv1m. " USING wa_e1cuv1m.      "#EC *
****************************************************
*MOD-008
****************************************************
* store last value
     g_slnid_c = wa_cuvtab_valc-slnid.

* Find concatenated number at the end of variant
     IF wa_cabn-atnam = c_varcond.
       CLEAR i_split.
       SPLIT wa_cuvtab_valc-valc AT '_' INTO TABLE i_split.
       CLEAR l_lines.

       DESCRIBE TABLE i_split LINES l_lines.
* Read last line of table as it contains concatenated number
       READ TABLE i_split INTO wa_split INDEX l_lines.
       SHIFT wa_split-f1 LEFT DELETING LEADING space.
       IF wa_split-f1 CO '0123456789 '.
         CLEAR l_lines.
         l_lines = wa_split-f1.
         IF l_lines > g_split_var.
           g_split_var = l_lines.
         ENDIF.
       ENDIF.
     ENDIF.

*  Check for duplicate records
     PERFORM pop_dupl USING wa_vtnam-vtnam
                            g_slnid_c
                            wa_cabn-atnam
                            wa_cuvtab_valc-valc.

   ENDLOOP.

 ENDFORM.                    " SUB_TRANSFER_ST_CHAR
*&---------------------------------------------------------------------*
*&      Form  SUB_TRANSFER_ST_NUM
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_TRANSFER_ST_NUM .

   DATA:
          L_VAL TYPE P,
          L_VAL1 TYPE P DECIMALS 1,
          L_VAL2 TYPE P DECIMALS 2,
          L_VAL3 TYPE P DECIMALS 3,
          L_CHAR TYPE CHAR16.

   LOOP AT i_cuvtab_valn INTO wa_cuvtab_valn
                 WHERE vtint = wa_vtnam-vtint.
     CLEAR wa_cabn.
     READ TABLE i_cabn_atinn INTO wa_cabn
     WITH KEY atinn = wa_cuvtab_valn-atinn BINARY SEARCH.

     CLEAR wa_e1cuv1m.
     wa_e1cuv1m-msgfn = c_009.
     wa_e1cuv1m-vtlineno5 = wa_cuvtab_valn-slnid.
     wa_e1cuv1m-vtcharact = wa_cabn-atnam.
     wa_e1cuv1m-atflv     = wa_cuvtab_valn-val_from.

****************************************************
*MOD-008
****************************************************
     PERFORM transfer_e1cuv1m. " USING wa_e1cuv1m.    "#EC *
****************************************************
*MOD-008
****************************************************
* store last value
     g_slnid_n = wa_cuvtab_valn-slnid.
* Convert characteristic value from Exp format to normal format
     CLEAR: l_val, l_char, l_val1, l_val2, l_val3.
     CASE wa_cabn-anzdz.
       WHEN 0.
         l_val =  wa_cuvtab_valn-val_from.
         l_char = l_val.
       WHEN 1.
         l_val1 = wa_cuvtab_valn-val_from.
         l_char = l_val1.
       WHEN 2.
         l_val2 = wa_cuvtab_valn-val_from.
         l_char = l_val2.
       WHEN 3.
         l_val = wa_cuvtab_valn-val_from.
         l_char = l_val.

     ENDCASE.

     SHIFT l_char LEFT DELETING LEADING space.
*  Check for duplicate records
     PERFORM pop_dupl USING wa_vtnam-vtnam
                            g_slnid_n
                            wa_cabn-atnam
                            l_char.

   ENDLOOP.

 ENDFORM.                    " SUB_TRANSFER_ST_NUM
*&---------------------------------------------------------------------*
*&      Form  SUB_CHECK_CHAR_VALUES
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_CHECK_CHAR_VALUES .

************************************************************************
*MOD-012
************************************************************************
   DATA:
          L_FIELDNAME TYPE FIELDNAME,
          L_FIELD_DUP TYPE FIELDNAME.
   FIELD-SYMBOLS:  TYPE ANY,
                   TYPE ANY.

   DATA:
          L_LEN_SLNID TYPE I,
          L_LEN_VARCOND TYPE I,
          L_TEMP_SLNID TYPE I,
          L_TEMP_SLNC TYPE CHAR5,
          L_TEMP_VARCOND TYPE VARCOND,
          L_SUB_VAR TYPE I,
          L_VAL_SPLIT TYPE CHAR10.
************************************************************************
**
*MOD-012
************************************************************************
**

   DATA:
          L_INVALID.

* We are sorting it to concatenate characteristics value into Variant
   CLEAR g_varcond.
   CONCATENATE 'V' wa_vnt_ma-unique_no INTO g_varcond.

   LOOP AT i_col_pos INTO wa_col_pos WHERE vtnam = wa_file-vtnam.
     CLEAR l_fieldname.
*  Dynamically assign value to field l_value for validation
     CONCATENATE 'WA_FILE-CHAR' wa_col_pos-field INTO l_fieldname.
     ASSIGN (l_fieldname) TO .

* Put values in work area to check for duplicates
     IF wa_col_pos-atnam <> c_varcond.   " Variant condition
       CLEAR l_field_dup.
       wa_dupl_file-vtnam = wa_file-vtnam.
      CONCATENATE 'WA_DUPL_FILE-CHAR' wa_col_pos-field INTO l_field_dup.
       ASSIGN (l_field_dup) TO .
************************************************
*MOD-008
************************************************
        = .
*      IF NOT  is initial.
*        ASSIGN  TO .
*      ENDIF.
************************************************
*MOD-008
************************************************
       CONCATENATE g_varcond  INTO g_varcond SEPARATED BY '_'.
* ENDIF commented out, It will be taken to the end just before endloop
* Value for Z_VARCOND will be generated by program as per new logic
*    ENDIF.
       IF  IS NOT INITIAL.
         SORT I_CABN BY ATINN ATNAM.
         CLEAR wa_cabn.
         READ TABLE i_cabn INTO wa_cabn
         WITH KEY atnam = wa_col_pos-atnam. " BINARY SEARCH.

* Validate values against function module stored in field ATPRF
         CLEAR l_invalid.
         IF wa_cabn-atprf IS NOT INITIAL.
           CATCH SYSTEM-EXCEPTIONS OTHERS = 1.
             CALL FUNCTION wa_cabn-atprf
               EXPORTING
                 charact_no = wa_cabn-atinn
                 charact    = wa_cabn-atnam
                 value      =
               EXCEPTIONS
                 not_found  = 1.

             IF sy-subrc <> 0.
               l_invalid = c_x.
               g_invalid = c_x.
             ENDIF.
           ENDCATCH.
         ENDIF.

         IF l_invalid <> c_x.

*     SY-SUBRC should not fail here because check has already been done
*     We need to validate value only if following fields are blank
           IF wa_cabn-atson IS INITIAL    " Indicator: Additional Values
           AND wa_cabn-atprt IS INITIAL   " Check table
           AND wa_cabn-atprr IS INITIAL   " Name of Check Report Program
           AND wa_cabn-atprf IS INITIAL   " Function Module for Checking
           AND wa_cabn-check IS INITIAL.  " No value found in CAWN table
*       Check value
             CLEAR wa_cawn.

             CASE wa_cabn-atfor.
               WHEN c_char OR c_date OR c_time.
                 READ TABLE i_cawn_c INTO wa_cawn WITH KEY atinn =
 wa_cabn-atinn
                                                          atwrt =
 .
                 IF sy-subrc = 0.
                   IF wa_cawn-lkenz = c_x.
                     PERFORM errror_line USING wa_file-vtnam
                                               l_fieldname
                                               wa_cabn-atnam
                                              
                                               g_row.
                     g_invalid = c_x.

                   ELSE.
                     CLEAR wa_e1cuv1m.
                     wa_e1cuv1m-msgfn = c_009.
                     wa_e1cuv1m-vtlineno5 = g_slnid_c.
                     wa_e1cuv1m-vtcharact = wa_cabn-atnam.
                     wa_e1cuv1m-atwrt  = .
                     APPEND wa_e1cuv1m TO i_e1cuv1m.
****************************************************
*MOD-008
****************************************************
*                   perform fill_edidd_segments USING wa_e1cuv1m.
*                   PERFORM transfer_e1cuv1m. " USING wa_e1cuv1m.
                                                            "#EC *
                     clear: wa_e1cuv1m.
****************************************************
*MOD-008
****************************************************
                   ENDIF.
                 ELSE.
                   PERFORM errror_line USING wa_file-vtnam
                                             l_fieldname
                                             wa_cabn-atnam
                                            
                                             g_row.
                   g_invalid = C_X.
                 ENDIF.
               WHEN OTHERS.
************************************************************
*MOD-008
***********************************************************
                 READ TABLE i_cawn_n INTO wa_cawn WITH KEY atinn =
 wa_cabn-atinn
                                                           atflv =
 .
                 IF sy-subrc = 0.
                   IF wa_cawn-lkenz = C_X.
                     PERFORM errror_line USING wa_file-vtnam
                                               l_fieldname
                                               wa_cabn-atnam
                                              
                                               g_row.
                     g_invalid = C_X.
                   ELSE.
                     CLEAR wa_e1cuv1m.
                     wa_e1cuv1m-msgfn = C_009.
                     wa_e1cuv1m-vtlineno5 = g_slnid_c.
                     wa_e1cuv1m-vtcharact = wa_cabn-atnam.
                     wa_e1cuv1m-atflv  = .
                     APPEND wa_e1cuv1m TO i_e1cuv1m.

*****************************************************
**MOD-008
*****************************************************
*                   perform fill_edidd_segments USING wa_e1cuv1m.
*                   PERFORM transfer_e1cuv1m. " USING wa_e1cuv1m.
                                                            "#EC *
                     clear: wa_e1cuv1m.
*****************************************************
**MOD-008
*****************************************************
                   ENDIF.
                 ELSE.
                   PERFORM errror_line USING wa_file-vtnam
                                             l_fieldname
                                             wa_cabn-atnam
                                            
                                             g_row.

                   g_invalid = C_X.
                 ENDIF.
*************************************************************
*MOD-008
************************************************************
             ENDCASE.
           ELSE.
             CASE wa_cabn-atfor.
               WHEN c_char OR c_date OR c_time.
                 CLEAR wa_e1cuv1m.
                 wa_e1cuv1m-msgfn = C_009.
                 wa_e1cuv1m-vtlineno5 = g_slnid_c.
                 wa_e1cuv1m-vtcharact = wa_cabn-atnam.
                 wa_e1cuv1m-atwrt  = .
                 APPEND wa_e1cuv1m TO i_e1cuv1m.

****************************************************
*MOD-008
****************************************************
*               perform fill_edidd_segments USING wa_e1cuv1m.
*               PERFORM transfer_e1cuv1m. " USING wa_e1cuv1m.
                                                            "#EC *
                 clear: wa_e1cuv1m.
****************************************************
*MOD-008
****************************************************
               WHEN OTHERS.
                 CLEAR wa_e1cuv1m.
                 wa_e1cuv1m-msgfn = C_009.
                 wa_e1cuv1m-vtlineno5 = g_slnid_c.
                 wa_e1cuv1m-vtcharact = wa_cabn-atnam.
                 wa_e1cuv1m-atflv  = .
                 APPEND wa_e1cuv1m TO i_e1cuv1m.

             ENDCASE.
           ENDIF.
         ELSE.

           PERFORM errror_line USING wa_file-vtnam
                                     l_fieldname
                                     wa_col_pos-atnam
                                    
                                     g_row.
           g_invalid = C_X.

         ENDIF.

       ELSE.
         PERFORM errror_line USING wa_file-vtnam
                                   l_fieldname
                                   wa_col_pos-atnam
                                  
                                   g_row.
         g_invalid = C_X.

       ENDIF.

     ENDIF.

     clear: wa_col_pos.
   ENDLOOP.

* Assign value to type i variable to find length
   CLEAR: l_len_slnid,
          l_len_varcond,
          l_temp_slnid,
          l_temp_slnc,
          l_temp_varcond,
          l_sub_var .

* Put i type value in variable with 10 characters
   CLEAR l_val_split.
   l_val_split = g_split_var.
   SHIFT l_val_split LEFT DELETING LEADING space.
   l_temp_slnid = g_split_var.
   l_temp_slnc = l_val_split+0(5).
*  SHIFT l_temp_slnc LEFT DELETING LEADING space.
   l_len_slnid = STRLEN( l_temp_slnc ).
   l_len_varcond = STRLEN( g_varcond ).
   l_sub_var = 26 - l_len_slnid.
   l_sub_var = l_sub_var - 1.
   l_temp_varcond = g_varcond+0(l_sub_var).
   CLEAR g_varcond.
   CONCATENATE l_temp_varcond l_temp_slnc INTO g_varcond
                                          SEPARATED BY '_'.
**************************************************************
**MOD-009
**************************************************************
*  REFRESH: i_e1cuv1m.
*  CLEAR wa_e1cuv1m.
*  wa_e1cuv1m-msgfn = C_009.
*  wa_e1cuv1m-vtlineno5 = g_slnid_c.
*  wa_e1cuv1m-vtcharact = c_varcond.
*  wa_e1cuv1m-atwrt  = g_varcond.
*  APPEND wa_e1cuv1m TO i_e1cuv1m.
*
*  PERFORM transfer_e1cuv1m. " USING wa_e1cuv1m.    "#EC *
*
**************************************************************
**MOD-009
**************************************************************

 ENDFORM.                    " SUB_CHECK_CHAR_VALUES
*&---------------------------------------------------------------------*
*&      Form  SUB_DUPL_COLUMNS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_DUPL_COLUMNS .

   DATA:
          L_FIELDNAME TYPE FIELDNAME,
          L_COUNTER TYPE CHAR2.
   FIELD-SYMBOLS:  TYPE ANY.                   "#EC *
   CONSTANTS:
          C_FIELD TYPE CHAR12 VALUE 'WA_FILE-CHAR'.

   DO 15 TIMES.
     l_counter = l_counter + 1.
     CONCATENATE c_field l_counter INTO l_fieldname.
     IF l_fieldname IS NOT INITIAL.
       ASSIGN (l_fieldname) TO .
       IF  IS ASSIGNED.
         wa_charval-char = .
         APPEND wa_charval TO i_charval.
       ENDIF.
     ENDIF.
   ENDDO.

   IF i_charval IS NOT INITIAL.
     DELETE i_charval WHERE char IS INITIAL.
     SORT i_charval.
     DELETE ADJACENT DUPLICATES FROM i_charval.
     IF sy-subrc = 0.
       MESSAGE i243.
       LEAVE LIST-PROCESSING.
     ENDIF.
   ENDIF.

 ENDFORM.                    " SUB_DUPL_COLUMNS
*&---------------------------------------------------------------------*
*&      Form  SUB_STORE_FILE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_STORE_FILE .

   MOVE-CORRESPONDING wa_contenttab1 TO wa_file.

   IF NOT ( wa_file-flag = 'X' OR wa_file-flag = 'x' ) .
******************************************************
**MDO-008
******************************************************
*    LOOP AT I_CONTENTTAB1 INTO WA_CONTENTTAB1.
*      IF SY-TABIX = 1.
*        wa_contenttab2 = wa_contenttab1.
*        append wa_contenttab2 to i_contenttab2.
*        clear: wa_contenttab2.
*      ENDIF.
*    ENDLOOP.
******************************************************
**MOD-008
******************************************************

     LOOP AT I_CONTENTTAB1 INTO WA_CONTENTTAB1.
       L_TABIX = SY-TABIX.
       IF L_TABIX = 1.
         wa_contenttab2 = wa_contenttab1.
         append wa_contenttab2 to i_contenttab2.
         clear: wa_contenttab2.
         clear: l_tabix.
         continue.
       ENDIF.
     ENDLOOP.

*     IF L_TABIX > 1.
     READ TABLE I_CONTENTTAB2 INTO WA_CONTENTTAB2 INDEX 1.
*               WITH KEY VTNAM = WA_CONTENTTAB1-VTNAM BINARY SEARCH.
*****************************************************
*MOD-008
*****************************************************
     IF SY-SUBRC = 0.
       if not WA_CONTENTTAB2-CHAR1 is initial.
         wa_charname-name = WA_CONTENTTAB2-CHAR1.
         APPEND wa_charname TO i_charname.
       endif.
       if not WA_CONTENTTAB2-CHAR2 is initial.
         wa_charname-name = WA_CONTENTTAB2-CHAR2.
         APPEND wa_charname TO i_charname.
       endif.
       if not WA_CONTENTTAB2-CHAR3 is initial.
         wa_charname-name = WA_CONTENTTAB2-CHAR3.
         APPEND wa_charname TO i_charname.
       endif.
       if not WA_CONTENTTAB2-CHAR4 is initial.
         wa_charname-name = WA_CONTENTTAB2-CHAR4.
         APPEND wa_charname TO i_charname.
       endif.
       if not WA_CONTENTTAB2-CHAR5 is initial.
         wa_charname-name = WA_CONTENTTAB2-CHAR5.
         APPEND wa_charname TO i_charname.
       endif.
       if not WA_CONTENTTAB2-CHAR6 is initial.
         wa_charname-name = WA_CONTENTTAB2-CHAR6.
         APPEND wa_charname TO i_charname.
       endif.
       if not WA_CONTENTTAB2-CHAR7 is initial.
         wa_charname-name = WA_CONTENTTAB2-CHAR7.
         APPEND wa_charname TO i_charname.
       endif.
       if not WA_CONTENTTAB2-CHAR8 is initial.
         wa_charname-name = WA_CONTENTTAB2-CHAR8.
         APPEND wa_charname TO i_charname.
       endif.
       if not WA_CONTENTTAB2-CHAR9 is initial.
         wa_charname-name = WA_CONTENTTAB2-CHAR9.
         APPEND wa_charname TO i_charname.
       endif.
       if not WA_CONTENTTAB2-CHAR10 is initial.
         wa_charname-name = WA_CONTENTTAB2-CHAR10.
         APPEND wa_charname TO i_charname.
       endif.
       if not WA_CONTENTTAB2-CHAR11 is initial.
         wa_charname-name = WA_CONTENTTAB2-CHAR11.
         APPEND wa_charname TO i_charname.
       endif.
       if not WA_CONTENTTAB2-CHAR12 is initial.
         wa_charname-name = WA_CONTENTTAB2-CHAR12.
         APPEND wa_charname TO i_charname.
       endif.
       if not WA_CONTENTTAB2-CHAR13 is initial.
         wa_charname-name = WA_CONTENTTAB2-CHAR13.
         APPEND wa_charname TO i_charname.
       endif.
       if not WA_CONTENTTAB2-CHAR14 is initial.
         wa_charname-name = WA_CONTENTTAB2-CHAR14.
         APPEND wa_charname TO i_charname.
       endif.
       if not WA_CONTENTTAB2-CHAR15 is initial.
         wa_charname-name = WA_CONTENTTAB2-CHAR15.
         APPEND wa_charname TO i_charname.
       endif.
     ENDIF.
*****************************************************
*MOD-008
*****************************************************
*     ENDIF.
* ENDLOOP.
*****************************************************
*MOD-012
*****************************************************
*   SORT I_CHARNAME BY NAME.
*****************************************************
*MOD-012
*****************************************************
     DELETE ADJACENT DUPLICATES FROM I_CHARNAME COMPARING NAME.
     DELETE I_CHARNAME WHERE NAME IS INITIAL.
     APPEND wa_file TO i_file.
     cLEAR: WA_FILE.
   ELSE.
     APPEND wa_file TO i_file_tmp.

* Check duplicate columns for characteristics
     PERFORM sub_dupl_columns.
     CLEAR: WA_FILE.
   ENDIF.

 ENDFORM.                    " SUB_STORE_FILE
*&---------------------------------------------------------------------*
*&      Form  SUB_GET_FILE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_P_FNAME  text
*----------------------------------------------------------------------*
 FORM SUB_GET_FILE. " CHANGING P_P_FNAME.        "#EC NEEDED

   DATA:
          C_FNH_MASK TYPE DXFIELDS-FILEMASK VALUE '* *',
          SEARCH_DIR TYPE DXFIELDS-LONGPATH VALUE '/USR/SAP/TRANS/',
          FILE_PATH LIKE DXFIELDS-LONGPATH. " Long path name

   CALL FUNCTION 'F4_DXFILENAME_TOPRECURSION'
     EXPORTING
       I_LOCATION_FLAG = 'A'
       I_SERVER        = ' '
       I_PATH          = SEARCH_DIR
       FILEMASK        = C_FNH_MASK
       FILEOPERATION   = 'R'
     IMPORTING
       O_PATH          = FILE_PATH
     EXCEPTIONS
       RFC_ERROR       = 1
       OTHERS          = 2.

   IF SY-SUBRC EQ 0.
     P_fname = FILE_PATH.                                   "#EC
   ENDIF.

 ENDFORM.                    " SUB_GET_FILE
*&---------------------------------------------------------------------*
*&      Form  SUB_GET_FILE1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_P_FNAME1  text
*----------------------------------------------------------------------*
 FORM SUB_GET_FILE1. "  CHANGING P_P_FNAME1.            "#EC NEEDED

   DATA:
          C_FNH_MASK TYPE DXFIELDS-FILEMASK VALUE '* *',
          SEARCH_DIR TYPE DXFIELDS-LONGPATH VALUE '/USR/SAP/TRANS/',
          FILE_PATH LIKE DXFIELDS-LONGPATH. " Long path name

   CALL FUNCTION 'F4_DXFILENAME_TOPRECURSION'
     EXPORTING
       I_LOCATION_FLAG = 'A'
       I_SERVER        = ' '
       I_PATH          = SEARCH_DIR
       FILEMASK        = C_FNH_MASK
       FILEOPERATION   = 'R'
     IMPORTING
       O_PATH          = FILE_PATH
     EXCEPTIONS
       RFC_ERROR       = 1
       OTHERS          = 2.

   IF SY-SUBRC EQ 0.
     P_fname1 = FILE_PATH.                                  "#EC
   ENDIF.

 ENDFORM.                    " SUB_GET_FILE1
*&---------------------------------------------------------------------*
*&      Form  SUB_APP_LOG_INIT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_V_LOG_HANDLE  text
*----------------------------------------------------------------------*
 Form  SUB_APP_LOG_INIT CHANGING fp_log_handle TYPE balloghndl.

   DATA:
          L_S_LOG TYPE BAL_S_LOG.

   CLEAR l_s_log.

*  IS_LOG_HEADER-EXTNUMBER  = TEXT-L01.
   IS_LOG_HEADER-ALUSER     = SY-UNAME.
   IS_LOG_HEADER-ALDATE     = SY-DATUM.
   IS_LOG_HEADER-ALTIME     = SY-UZEIT.
   IS_LOG_HEADER-ALTCODE    = IV_TCODE.
   IS_LOG_HEADER-ALPROG     = SY-REPID.
   IS_LOG_HEADER-OBJECT     = 'CAPI'.
   IS_LOG_HEADER-SUBOBJECT  = 'CAPI_LOG'.
   is_log_header-del_before = 'X'.

   CALL FUNCTION 'BAL_LOG_CREATE'
     EXPORTING
       i_s_log                 = is_log_header
     IMPORTING
       e_log_handle            = fp_log_handle
     EXCEPTIONS
       log_header_inconsistent = 1
       OTHERS                  = 2.
   IF sy-subrc <> 0.
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
   ENDIF.

 ENDFORM.                    " f_app_log_init

*&---------------------------------------------------------------------*
*&      Form  SUB_APP_LOG_INIT
*&---------------------------------------------------------------------*

 FORM sub_app_log_add  USING fp_log_handle TYPE balloghndl.

   DATA:
          L_V_PROBCLASS TYPE BAL_S_MSG-PROBCLASS,
          L_S_MSG TYPE BAL_S_MSG,
          L_V_MSG TYPE BOOLEAN.

* priority clas
   CONSTANTS:
          L_C_PROBCLASS_VERY_HIGH TYPE BAL_S_MSG-PROBCLASS VALUE '1',
          L_C_PROBCLASS_HIGH TYPE BAL_S_MSG-PROBCLASS VALUE '2',
          L_C_PROBCLASS_MEDIUM TYPE BAL_S_MSG-PROBCLASS VALUE '3',
          L_C_PROBCLASS_LOW TYPE BAL_S_MSG-PROBCLASS VALUE '4',
          L_C_PROBCLASS_NONE TYPE BAL_S_MSG-PROBCLASS VALUE ' '.

* message types
   CONSTANTS:
          L_C_MSGTY_X TYPE SY-MSGTY VALUE 'X',
          L_C_MSGTY_A TYPE SY-MSGTY VALUE 'A',
          L_C_MSGTY_E TYPE SY-MSGTY VALUE 'E',
          L_C_MSGTY_W TYPE SY-MSGTY VALUE 'W',
          L_C_MSGTY_I TYPE SY-MSGTY VALUE 'I',
          L_C_MSGTY_S TYPE SY-MSGTY VALUE 'S',
          L_C_MSGTY_NONE TYPE SY-MSGTY VALUE ' '.

** entry check
*  CHECK sy-msgno NE 0.
*  CHECK sy-msgid NE space.

** define data of message for Application Log
*  l_s_msg-msgty     = sy-msgty.
*  l_s_msg-msgid     = sy-msgid.
*  l_s_msg-msgno     = sy-msgno.
*  l_s_msg-msgv1     = sy-msgv1.
*  l_s_msg-msgv2     = sy-msgv2.
*  l_s_msg-msgv3     = sy-msgv3.
*  l_s_msg-msgv4     = sy-msgv4.

******************************************
*MOD-009
******************************************
   CLEAR: WA_ERROR_TAB.
   CLEAR: L_S_MSG.

   LOOP AT G_ERROR_TAB INTO WA_ERRORTAB.
     l_s_msg-msgty     = WA_ERRORTAB-msgty.
     l_s_msg-msgid     = WA_ERRORTAB-id.
     l_s_msg-msgno     = WA_ERRORTAB-msgno.
     l_s_msg-msgv1     = WA_ERRORTAB-par1.
     l_s_msg-msgv2     = WA_ERRORTAB-par2.
     l_s_msg-msgv3     = WA_ERRORTAB-par3.
     l_s_msg-msgv4     = WA_ERRORTAB-par4.
   ENDLOOP.

*   CASE sy-msgty.
   CASE l_s_msg-msgty.
     WHEN l_c_msgty_x.
       l_v_probclass = l_c_probclass_very_high.  l_v_msg = 'X'.
     WHEN l_c_msgty_a.
       l_v_probclass = l_c_probclass_very_high.  l_v_msg = 'X'.
     WHEN l_c_msgty_e.
       l_v_probclass = l_c_probclass_high.       l_v_msg = 'X'.
     WHEN l_c_msgty_w.
       l_v_probclass = l_c_probclass_medium.
     WHEN l_c_msgty_i.
       l_v_probclass = l_c_probclass_low.
     WHEN l_c_msgty_s.
       l_v_probclass = l_c_probclass_low.
     WHEN l_c_msgty_none.
       l_v_probclass = l_c_probclass_none.
   ENDCASE.
* bis hier temporär
   l_s_msg-probclass = l_v_probclass.
* add this message to log file

   CALL FUNCTION 'BAL_LOG_MSG_ADD'
     EXPORTING
       i_log_handle     = fp_log_handle
       i_s_msg          = l_s_msg
     EXCEPTIONS
       log_not_found    = 1
       msg_inconsistent = 2
       log_is_full      = 3
       OTHERS           = 4.

   IF sy-subrc <> 0.
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
   ENDIF.

 ENDFORM.                    " f_app_log_add
*&---------------------------------------------------------------------*
*&      Form  f_data_save
*&---------------------------------------------------------------------*
* Saving the app log
*----------------------------------------------------------------------*
* -->  FP_LOG_HANDLE   Variable
*----------------------------------------------------------------------*
 FORM sub_data_save USING fp_log_handle TYPE balloghndl.

   DATA:
          LT_LOG_HANDLE TYPE BAL_T_LOGH.

   APPEND fp_log_handle TO lt_log_handle.

   CALL FUNCTION 'BAL_DB_SAVE'
     EXPORTING
       i_client         = sy-mandt
       i_save_all       = ' '
       i_t_log_handle   = lt_log_handle
     EXCEPTIONS
       log_not_found    = 1
       save_not_allowed = 2
       numbering_error  = 3
       OTHERS           = 4.

   IF sy-subrc <> 0.
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
   ENDIF.

 ENDFORM.                    " f_data_save

*&---------------------------------------------------------------------*
*&      Form  f_data_save
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  SUB_CREATE_ERORTAB
*&---------------------------------------------------------------------*
*      text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_CREATE_ERORTAB .

   LOOP AT G_ERROR_TAB INTO WA_ERRORTAB.
     concatenate   WA_ERRORTAB-msgty
                   WA_ERRORTAB-id
                   WA_ERRORTAB-msgno
                   WA_ERRORTAB-par1
                   WA_ERRORTAB-par2
                   WA_ERRORTAB-par3
                   WA_ERRORTAB-par4
                   into wa_error_tab-line separated by space.
     APPEND WA_ERROR_TAB TO I_ERRORTAB.
     CLEAR: WA_ERROR_TAB, wa_errortab.
   ENDLOOP.

 ENDFORM.                    " SUB_CREATE_ERORTAB
*&---------------------------------------------------------------------*
*&      Form  BAL_DB_SAVE
*&---------------------------------------------------------------------*
 FORM sub_log_show USING fp_log_handle TYPE balloghndl.     "#EC NEEDED

   DATA:
          LS_PROFILE TYPE BAL_S_PROF.

   CALL FUNCTION 'BAL_DSP_PROFILE_SINGLE_LOG_GET'
     IMPORTING
       E_S_DISPLAY_PROFILE = LS_PROFILE.

* we therefore show all messages immediately
   LS_PROFILE-EXP_LEVEL   = 0.
   LS_PROFILE-USE_GRID   = C_X.

   CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
     EXPORTING
       I_S_DISPLAY_PROFILE = LS_PROFILE
     EXCEPTIONS
       OTHERS              = 1.
   IF SY-SUBRC <> 0.
     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
   ENDIF.

 ENDFORM.                    " LOG_DISPLAY
*&---------------------------------------------------------------------*
*&      Form  BAL_DB_SAVE
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  SUB_APPLICATION_LOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 FORM SUB_APPLICATION_LOG .

   TYPES:
          BEGIN OF TYPE_ERRORLINE,
            MSGTY LIKE SY-MSGTY , " Message Type
            ID LIKE SY-MSGID , " Message Class
            MSGNO LIKE SY-MSGNO , " Message Number
            PAR1 LIKE SY-MSGV1 , " Message Variable
            PAR2 LIKE SY-MSGV2 , " Message Variable
            PAR3 LIKE SY-MSGV3 , " Message Variable
            PAR4 LIKE SY-MSGV4 , " Message Variable
          END OF TYPE_ERRORLINE.

   TYPES:
          BEGIN OF TY_BALMI.
           INCLUDE STRUCTURE BALMI.
   TYPES:
          END OF TY_BALMI.

   TYPES:
          BEGIN OF TY_BALNRI.
           INCLUDE STRUCTURE BALNRI.
   TYPES:
          END OF TY_BALNRI.

   DATA:
          L_S_BALHDRI TYPE BALHDRI,
          L_LOGHANDLE TYPE BALLOGHNDL.

   DATA:
          L_S_MSG TYPE STANDARD TABLE OF TY_BALMI INITIAL SIZE 0,
          L_I_MSG TYPE STANDARD TABLE OF TY_BALMI INITIAL SIZE 0,
          L_ST_MSG TYPE STANDARD TABLE OF TY_BALMI INITIAL SIZE 0.

   DATA:
          L_S_BALNRI TYPE STANDARD TABLE OF TY_BALNRI.

   DATA:
          WA_S_MSG TYPE TY_BALMI,
          WA_ST_MSG TYPE TY_BALMI.
   DATA:
          WA_S_BALNRI TYPE TY_BALNRI.
   DATA:
          LS_PROFILE TYPE BAL_S_PROF.

   CALL FUNCTION 'APPL_LOG_INIT'
    EXPORTING
      object                    = 'CAPI'
      subobject                 = 'CAPI_LOG'
*   LOG_HANDLE                = ' '
    EXCEPTIONS
      object_not_found          = 1
      subobject_not_found       = 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.

   l_s_balhdri-object = 'CAPI'.
   l_s_balhdri-subobject = 'CAPI_LOG'.

   CALL FUNCTION 'APPL_LOG_WRITE_HEADER'
     EXPORTING
       header                    = l_s_balhdri
*   LOG_HANDLE                =
    IMPORTING
*   UPDATE_OR_INSERT          =
      e_log_handle              = l_loghandle
    EXCEPTIONS
      object_not_found          = 1
      subobject_not_found       = 2
      error                     = 3
      OTHERS                    = 4
             .
   IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
   ENDIF.

   LOOP AT G_ERROR_TAB INTO WA_ERRORTAB.
     wa_s_msg-msgty     = 'I'.
     wa_s_msg-msgid     = 'ZFACTGLB'.
     wa_s_msg-msgno     = WA_ERRORTAB-msgno.
     wa_s_msg-msgv1     = WA_ERRORTAB-par1.
     wa_s_msg-msgv2     = WA_ERRORTAB-par2.
     wa_s_msg-msgv3     = WA_ERRORTAB-par3.
     wa_s_msg-msgv4     = WA_ERRORTAB-par4.
     APPEND wa_s_msg to l_s_msg.
     clear: wa_s_msg.
   ENDLOOP.

   CALL FUNCTION 'APPL_LOG_WRITE_MESSAGES'
     EXPORTING
       object              = 'CAPI'
       subobject           = 'CAPI_LOG'
       log_handle          = l_loghandle
     TABLES
       messages            = l_s_msg
     EXCEPTIONS
       object_not_found    = 1
       subobject_not_found = 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 'APPL_LOG_WRITE_DB'
     EXPORTING
       object                = 'CAPI'
       subobject             = 'CAPI_LOG'
       log_handle            = l_loghandle
     TABLES
       OBJECT_WITH_LOGNUMBER = L_S_BALNRI
     EXCEPTIONS
       OBJECT_NOT_FOUND      = 1
       SUBOBJECT_NOT_FOUND   = 2
       INTERNAL_ERROR        = 3
       OTHERS                = 4.

   IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
   ENDIF.

   CALL FUNCTION 'BAL_DSP_PROFILE_SINGLE_LOG_GET'
     IMPORTING
       E_S_DISPLAY_PROFILE = LS_PROFILE.

* we therefore show all messages immediately
   LS_PROFILE-EXP_LEVEL   = 0.
   LS_PROFILE-USE_GRID   = C_X.

   CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
     EXPORTING
       I_S_DISPLAY_PROFILE = LS_PROFILE
     EXCEPTIONS
       OTHERS              = 1.
   IF SY-SUBRC <> 0.
     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
   ENDIF.

 ENDFORM.                    " SUB_APPLICATION_LOG

*Selection texts
*----------------------------------------------------------
* P_FNAME         Physical File Name
* P_FNAME1         Physical File Name
* P_FPATH         Logical File Name
* P_FPATH1         Logical File Name
* P_INBD         Inbound
* P_INPT         Presentation Server  File Hdr
* P_INPT1         Presentation Server  File Dtl
* P_PACKGE         Package
* P_PROC         Process Idocs
* P_TRFCPT         TRFC Port
* P_UPLOAD          Convert Data
* RB_APSRV         Application Server
* RB_PRSRV         Presentation Server

*Messages
*----------------------------------------------------------
*
* Message class: /SAPDMC/LSMW
*810   No partner exists with the name '&', type '&'
*811   Create a partner profile for message type '&'
*
* Message class: ZFACTGLB
*088
*144
*196
*197
*237
*241
*242
*243
*246

--------------------------------------------------------------------------------

  • No labels