Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata
Error rendering macro 'code': Invalid value specified for parameter 'lang'
 *&---------------------------------------------------------------------*
*& Report  ZVARTABDYNFINAL
*&
*&---------------------------------------------------------------------*
*& DENMARK PROJECT
*&---------------------------------------------------------------------*
* PROGRAM DESCRIPTION: Dynamic Structures and Components.
*
*           DEVELOPER: Aveek Ghose
*       CREATION DATE: 2008-08-25
*          RDD NUMBER: DCDD027
* TRANSPORT NUMBER(S): RD2K902769
*
*- REVISION HISTORY -------------------------------------------------*
*
*           DEVELOPER:
*        DATE APPLIED: YYYY-MM-DD
*          SCR NUMBER: %LTScope Change Request ID%GT
*          RDD NUMBER: %LTToolset Object ID%GT
* TRANSPORT NUMBER(S):
*         DESCRIPTION:
*
*----------------------------------------------------------------------*

REPORT  ZVARTABDYNFINAL NO STANDARD PAGE HEADING
        LINE-SIZE   150
        LINE-COUNT  55
        MESSAGE-ID  zdev.

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

*&---------------------------------------------------------------------*
*&  Include           ZGTDMI_VARTAB_TOP
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
* PROGRAM DESCRIPTION: Variant Table and Content Upload Interface.
*
*           DEVELOPER: Aveek Ghose
*       CREATION DATE: 2008-08-25
*          RDD NUMBER: DCDD027
* TRANSPORT NUMBER(S): RD2K902769
*
*- REVISION HISTORY -------------------------------------------------*
*
*           DEVELOPER:
*        DATE APPLIED: YYYY-MM-DD
*          SCR NUMBER: %LTScope Change Request ID%GT
*          RDD NUMBER: %LTToolset Object ID%GT
* TRANSPORT NUMBER(S):
*         DESCRIPTION:
*
*----------------------------------------------------------------------*
************************************************************************
* TYPE POOLS
************************************************************************
************************************************************************
* TYPE POOLS
************************************************************************
************************************************************************
* TYPE POOLS
************************************************************************
*Type declaration for ALV display
TYPE-POOLS : slis.
Include %LTicon%GT.
type-pools: col,                                            "#EC *
            icon,                                           "#EC *
            sym,                                            "#EC *
            abap.                                           "#EC *

* Target structure definitions
tables:
  E1CUVTM,                                                  "#EC *
  E1DATEM,                                                  "#EC *
  E1CUV1M,                                                  "#EC *
  edp21,                                                    "#EC *
  edi_dc40,                                                 "#EC *
  edi_dd40,                                                 "#EC *
  edi_ds40.                                                 "#EC *
************************************************************************
* 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,                               "#EC *
          LINE(101) type c,
        END OF ty_dsninput.

*Structure for data retreived from Table dsn_input.
TYPES : BEGIN OF ty_newinput,                               "#EC *
          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,    "Material Number
          werks   TYPE werks_d,  "Plant
          lgort   TYPE lgort_d,  "Storage Location
          qunty   TYPE P DECIMALS 2, "Standard Order Quantity
          det_loc TYPE CHAR6, "Detail Location
          class   TYPE CHAR2,   "Class
          rate    TYPE P DECIMALS 2,    "Rate
        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,       "Material Number
          mtart TYPE mtart,       "Material Type
          sel_data TYPE char10,   "No of selectyed data
        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,
          Z_VARCOND type VARCOND.
TYPES: end of TY_CONTENT.

TYPES: begin of TY_CONTENTTAB,
          VTNAM(018) type C,
          COMP1(30) TYPE C,
          CHAR1(030) type C,
          COMP2(30) TYPE C,
          CHAR2(030) type C,
          COMP3(30) TYPE C,
          CHAR3(030) type C,
          COMP4(30) TYPE C,
          CHAR4(030) type C,
          COMP5(30) TYPE C,
          CHAR5(030) type C,
          COMP6(30) TYPE C,
          CHAR6(030) type C,
          COMP7(30) TYPE C,
          CHAR7(030) type C,
          COMP8(30) TYPE C,
          CHAR8(030) type C,
          COMP9(30) TYPE C,
          CHAR9(030) type C,
          COMP10(30) TYPE C,
          CHAR10(030) type C,
          COMP11(30) TYPE C,
          CHAR11(030) type C,
          COMP12(30) TYPE C,
          CHAR12(030) type C,
          COMP13(30) TYPE C,
          CHAR13(030) type C,
          COMP14(30) TYPE C,
          CHAR14(030) type C,
          COMP15(30) TYPE C,
          CHAR15(030) type C,
          FLAG(001) type C.
TYPES: end of TY_CONTENTTAB.

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,  " Internal number of variant table
         vtnam TYPE vtnam,  " Name of variant table
         dbtab_name type tabname16, "Custom table Name
         error  TYPE char1,  " Indicates error in data format
         reas   TYPE char50, " Reason for failure
       END OF ty_vtnam.
* Get data type for characteristic
TYPES: BEGIN OF ty_cabn,
        atinn  TYPE atinn,       "Internal characteristic
        atnam  TYPE atnam,       "Characteristic Name
        atfor  TYPE atfor,       "Data type of characteristic
        atson  TYPE atson,       "Indicator: Additional Values
        atprt  TYPE atprt,       "Check table
        atprr  TYPE atprr,       "Name of Check Report Program
        atprf  TYPE atprf,       "Function Module for Checking Values
        anzdz  TYPE anzdz,       "Number of Decimal Places
        check  TYPE char1,       "Indicates check required or not
       END OF ty_cabn.

* Get field names of variant table
TYPES: BEGIN OF ty_cuvtab_fld,
         vtint TYPE vtint,   " Internal number of variant table
         atinn TYPE atinn,   " Internal characteristic
         vtpos TYPE vtpos,   " Item number of characteristic in variant
***********************************************************************
*mod-012
***********************************************************************
         DBFLD type NAME_FELD,
***********************************************************************
*mod-012
***********************************************************************
         exist TYPE char1,   " X Indictaes characteristic is part of fil
       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,   " Internal number of variant table
        slnid  TYPE  slnid,   " Key for value combination in variant tab
        atinn  TYPE  atinn,   " Internal characteristic
        valc   TYPE  atwrt,   " Characteristic Value
      END OF ty_cuvtab_valc.

* Get previously loaded characteristic values for internal table (NUM)
TYPES: BEGIN OF ty_cuvtab_valn,
        vtint  TYPE  vtint,      " Internal number of variant table
        slnid  TYPE  slnid,
        " Key for value combination in variant tab
        atinn  TYPE  atinn,      " Internal characteristic
        val_from  TYPE  atflv,   " Internal floating point from
       END OF ty_cuvtab_valn.

* Store column positions of characteristics
TYPES: BEGIN OF ty_col_pos,
         vtint  TYPE vtint,   " Internal number of variant table
         vtnam  TYPE vtnam,   " Variant table name
         atinn  TYPE atinn,   "Internal characteristic
         atnam  TYPE atnam,   "Characteristic Name
         field  TYPE fieldname,   "Field name
         req    TYPE char1,       " Required or not
         vtpos  TYPE vtpos,       " Item number of characteristics
       END OF ty_col_pos.

* Store valid values for characteristics
TYPES: BEGIN OF ty_cawn,
          atinn TYPE atinn,   " Internal characteristic
          atzhl TYPE atzhl,   " Int counter
          atwrt TYPE atwrt,   " Characteristic Value
          atflv TYPE atflv,   " Internal floating point from
          lkenz TYPE lkenz,   " Deletion indicator
      END OF ty_cawn.

* Store error messages for individual lines
TYPES: BEGIN OF ty_error,
         vtnam  TYPE vtnam,       " Variant table name
         fname  TYPE fieldname,   " Fieldname
         atnam  TYPE atnam,       " Characteristic name
         atwrt  TYPE atwrt,       " Characteristic value
         row    TYPE char5,       " Row id
      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 VARIANT,
        no_chr(20) TYPE C,
      END OF ty_vnt_ma.

TYPES: BEGIN OF ty_dbtab,
        vtint     TYPE vtint,
        vtnam     TYPE vtnam,
        DBTAB_NAME TYPE TABNAME16,
      END OF ty_dbtab.

* 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: BEGIN OF TY_DATA,
       name TYPE string,
       value(15) type c,
      END OF TY_DATA.

DATA: I_DATATAB TYPE STANDARD TABLE OF TY_DATA.             "#EC NEEDED

TYPES:
  TUMLS_MESSTYPE type /SAPDMC/LS_MESSTYPE,
  TUMLS_MESSTYPETXT type EDI_TEXT60,
  TUMLS_MESSCODE type EDIPMESCOD.

TYPES:
  TUMLS_TABNAME TYPE TABNAME,                               "#EC *
  TUMLS_SEGMENT TYPE TABNAME.                               "#EC *

TYPES:
  TUMLS_PATHFILE TYPE /SAPDMC/LS_FILENAME,
  TUMLS_FILENAME TYPE /SAPDMC/LS_FILENAME,
  TUMLS_FILETEXT TYPE /SAPDMC/LS_FILETEXT.

TYPES:
  BEGIN OF type_errorline,
     msgty type SYMSGTY,
     id type SYMSGID,
     msgno type symsgno,
     par1 type symsgv,
     par2 type symsgv,
     par3 type symsgv,
     par4 type symsgv,
  END OF type_errorline.

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

DATA:
     LV_LINE2  TYPE REF TO DATA.

***********************************************************************
* GLOBAL INTERNAL TABLES
************************************************************************
DATA : i_newinput TYPE STANDARD TABLE OF ty_newinput INITIAL SIZE 0.
                                                            "#EC *
DATA : i_contentheader1 TYPE STANDARD TABLE OF ty_contenthd INITIAL SIZE
0.                                                          "#EC *
DATA : i_contenttab1 TYPE STANDARD TABLE OF ty_content INITIAL SIZE 0.
                                                            "#EC *
DATA : i_contenttab2 TYPE STANDARD TABLE OF ty_content INITIAL SIZE 0.
                                                            "#EC *
DATA : i_contenttab3 TYPE STANDARD TABLE OF ty_content INITIAL SIZE 0.
                                                            "#EC *
DATA : i_contenttab4 TYPE STANDARD TABLE OF ty_content INITIAL SIZE 0.
                                                            "#EC *
DATA : i_contenttab5 TYPE STANDARD TABLE OF ty_contenttab INITIAL SIZE 0
.                                                           "#EC *
DATA : i_E1CUV1M TYPE STANDARD TABLE OF E1CUV1M INITIAL SIZE 0."#EC *
DATA : i_errortab TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0."#EC *

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

**Internal Table for the structure TY_T001L
DATA : wa_vartab TYPE ty_vartab.                            "#EC *
DATA : wa_vartabdate TYPE ty_vartabdate.                    "#EC *
DATA : wa_vardetails TYPE ty_vardetails.                    "#EC *
DATA : wa_tabinput TYPE ty_tabinput.                        "#EC *
DATA : wa_dsninput TYPE ty_dsninput.                        "#EC *
DATA : wa_newinput TYPE ty_newinput.                        "#EC *
DATA : wa_gnewinput TYPE ty_newinput.                       "#EC *
DATA : wa_ginput_data TYPE ty_newinput.                     "#EC *
DATA : wa_final TYPE ty_final.                              "#EC *
DATA : wa_content TYPE ty_content.                          "#EC *
DATA : wa_contenthd TYPE ty_contenthd.                      "#EC *
DATA : wa_contentheader type ty_contenthd.                  "#EC *
DATA : wa_contenttab TYPE ty_content.                       "#EC *
DATA : wa_content1 TYPE ty_content.                         "#EC *
DATA : wa_contenthd1 TYPE ty_contenthd.                     "#EC *
DATA : wa_contentheader1 type ty_contenthd.                 "#EC *
DATA : wa_contenttab1 TYPE ty_content.                      "#EC *
DATA : wa_contenttab2 TYPE ty_content.                      "#EC *
DATA : wa_contenttab3 TYPE ty_content.                      "#EC *
DATA : wa_contenttab4 TYPE ty_content.                      "#EC *
DATA : wa_contenttab5 TYPE ty_contentTAB.                   "#EC *
DATA : wa_E1CUVTM TYPE E1CUVTM.                             "#EC *
DATA : wa_E1CUV1M TYPE E1CUV1M.                             "#EC *
DATA : wa_E1DATEM TYPE E1DATEM.                             "#EC *
DATA : wa_error_tab TYPE solisti1.                          "#EC *

************************************************************************
* 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 INITIAL SIZE 0."#EC *

*Internal Table to store the data to display the error message
DATA : i_error TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0."#EC *
DATA : itab_error TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0."#EC *

**Work area to store the data to display the error message
DATA : wa_errormsg TYPE solisti1.                           "#EC *

**Internal table which will store data for the error log
DATA:i_error_log TYPE STANDARD TABLE OF ty_error_log INITIAL SIZE 0.
                                                            "#EC *

************************************************************************
* GLOBAL VARIABLES
************************************************************************
DATA:  G_FILE TYPE string.                                  "#EC *
DATA : g_ctr_input_recs(5) type c.                          "#EC *
DATA:  g_ctr_output_recs(5) type p.                         "#EC *
data : g_msg(100) type c.                                   "#EC *
data:  g_struct_file TYPE string.                           "#EC *
data:  g_login type FILEINTERN.                             "#EC *
data:  g_phyin type string.                                 "#EC *
DATA:  g_lprnt type RSPOPSHORT.                             "#EC *
DATA:  g_FNAME1 TYPE STRING.                                "#EC *
DATA : g_repid TYPE repid,                                  "#EC *
       g_exit(1) TYPE C,                                    "#EC *
       gx_variant  type disvariant.                         "#EC *
DATA : g_lines    TYPE i .                                  "#EC *
data : g_save(1) type c.                                    "#EC *
DATA : g_splid     TYPE rspoid .                            "#EC *
data:  p_login type FILEINTERN.                             "#EC *
data:  p_phyin type string.                                 "#EC *

************************************************************************
* GLOBAL CONSTANTS
************************************************************************
CONSTANTS c_msgar   TYPE rslgarea   VALUE 'F8'.             "#EC *
CONSTANTS c_msgid   TYPE rslgsubid  VALUE 'E'.              "#EC *
CONSTANTS c_urgnc   TYPE char04     VALUE 'HIGH'.           "#EC *
CONSTANTS C_X(1)       TYPE C          VALUE 'X'.           "#EC *
CONSTANTS C_Y(1)       TYPE C          VALUE 'Y'.           "#EC *
CONSTANTS C_Z(1)       TYPE C          VALUE 'Z'.           "#EC *
CONSTANTS C_E(1)       TYPE C          VALUE 'E'.           "#EC *
CONSTANTS C_SAP(3)     TYPE C          VALUE 'SAP'.         "#EC *
CONSTANTS C_MOD(3)     TYPE C          VALUE 'MOD'.         "#EC *
CONSTANTS C_MD1(3)     TYPE C          VALUE 'MD1'.         "#EC *
CONSTANTS C_MD2(3)     TYPE C          VALUE 'MD2'.         "#EC *
CONSTANTS C_MD3(3)     TYPE C          VALUE 'MD3'.         "#EC *
CONSTANTS C_MD4(3)     TYPE C          VALUE 'MD4'.         "#EC *
CONSTANTS C_MD5(3)     TYPE C          VALUE 'MD5'.         "#EC *

constants:   c_000001(6)  type c value '000001',            "#EC *
             c_e1cuv1m(7) type c value 'E1CUV1M',           "#EC *
             c_02(2)  type c value '02',                    "#EC *
             c_009(3)   type c value '009',                 "#EC *
             c_0001(4) type c value '0001'.                 "#EC *

constants:  c_e1datem(7) type c value 'E1DATEM'.            "#EC *
constants:  c_e1cuvtm(7) type c value 'E1CUVTM'.            "#EC *

************************************************************************
* GLOBAL INTERNAL TABLES FOR ALV DISPLAY
************************************************************************
*Internal tables for ALV Field cat
DATA :
i_fieldcat_ov  TYPE STANDARD TABLE OF slis_fieldcat_alv INITIAL SIZE 0,
                                                            "#EC *
i_fieldcat_dtl TYPE STANDARD TABLE OF slis_fieldcat_alv INITIAL SIZE 0,
                                                            "#EC *
i_fieldcat_ov1 TYPE lvc_t_fcat,                             "#EC *
i_events       TYPE slis_t_event.                           "#EC *

************************************************************************
* GLOBAL WORK AREAS FOR ALV DISPLAY
************************************************************************
*Work area for ALV Field layout
DATA : wa_layout TYPE slis_layout_alv.                      "#EC *
*Work area for Field Cat. Table
DATA : wa_fieldcat TYPE slis_fieldcat_alv.                  "#EC *

************************************************************************
* GLOBAL VARIABLES FOR ALV DISPLAY
************************************************************************
DATA : g_event  TYPE slis_t_event.                          "#EC *
DATA : g_top_of_page TYPE slis_t_listheader.                "#EC *
DATA : g_ok_code     TYPE char4.                            "#EC *
DATA : g_variant     type disvariant.                       "#EC *

************************************************************************
* GLOBAL CONSTANTS FOR ALV DISPLAY
************************************************************************
* BAL handling
data: iv_log_handle type BALLOGHNDL.                        "#EC *
data: is_log_header type bal_s_log.                         "#EC *
data: iv_object     type bal_s_log-object    value 'CAPI'.  "#EC *
data: iv_subobject  type bal_s_log-subobject value 'CAPI_LOG'."#EC *
data: iv_tcode      type bal_s_log-altcode   value 'SE38'.  "#EC *

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

RANGES:
    R_MESTYP FOR EDIDC-MESTYP,                              "#EC *
    R_CREDAT FOR EDIDC-CREDAT,                              "#EC *
    R_CRETIM FOR EDIDC-CRETIM,                              "#EC *
    R_SNDPRT FOR EDIDC-SNDPRT,                              "#EC *
    R_SNDPRN FOR EDIDC-SNDPRN.                              "#EC *
DATA:
    L_MESSTYPE TYPE TUMLS_MESSTYPE.                         "#EC *

********************************************************************
*MOD-005
********************************************************************
data:        p_sndprn TYPE EDI_SNDPRN,                      "#EC *
             p_sndprt TYPE EDI_SNDPRT,                      "#EC *
             p_sndpor TYPE EDI_SNDPOR.                      "#EC *

data:        p_rcvprn TYPE EDI_RCVPRN,                      "#EC *
             p_rcvprt TYPE EDI_RCVPRT,                      "#EC *
             p_rcvpor TYPE EDI_RCVPOR.                      "#EC *
data:
  init_E1CUVTM type E1CUVTM,                                "#EC *
  prev_E1CUVTM type E1CUVTM,                                "#EC *
  init_E1DATEM type E1DATEM,                                "#EC *
  prev_E1DATEM type E1DATEM,                                "#EC *
  init_E1CUV1M type E1CUV1M,                                "#EC *
  prev_E1CUV1M type E1CUV1M.                                "#EC *

* Source structure definitions
data:
  begin of LSMW_TAB_CONTENT,                                "#EC *
    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,                                    "#EC *
  g_cnt_TAB_CONTENT  type i.                                "#EC *

* Counter ct_xxxxxxxxxx: number of transferred records
data:
  ct_edi_dc40 type i,                                       "#EC *
  cs_edi_dc40 type i,                                       "#EC *
  ct_E1CUVTM  type i,                                       "#EC *
  cs_E1CUVTM  type i,                                       "#EC *
  ct_E1DATEM  type i,                                       "#EC *
  cs_E1DATEM  type i,                                       "#EC *
  ct_E1CUV1M  type i,                                       "#EC *
  cs_E1CUV1M  type i.                                       "#EC *

* 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.                           "#EC *

*----------Internal table
DATA: i_cabn        TYPE STANDARD TABLE OF ty_cabn,         "#EC *
      i_cabn_temp   TYPE STANDARD TABLE OF ty_cabn,         "#EC *
      i_cabn_atinn  TYPE STANDARD TABLE OF ty_cabn,         "#EC *
      i_file        TYPE STANDARD TABLE OF ty_file,         "#EC *
      i_file_tmp    TYPE STANDARD TABLE OF ty_file,         "#EC *
      i_vtnam       TYPE STANDARD TABLE OF ty_vtnam,        "#EC *
      i_cuvtab      TYPE STANDARD TABLE OF ty_vtnam,        "#EC *
      i_cuvtab_fld  TYPE STANDARD TABLE OF ty_cuvtab_fld,   "#EC *
      i_cuvtab_valn TYPE STANDARD TABLE OF ty_cuvtab_valn,  "#EC *
      i_cuvtab_valc TYPE STANDARD TABLE OF ty_cuvtab_valc,  "#EC *
      i_col_pos     TYPE STANDARD TABLE OF ty_col_pos,      "#EC *
      i_cawn        TYPE STANDARD TABLE OF ty_cawn,         "#EC *
      i_cawn_n      TYPE STANDARD TABLE OF ty_cawn,         "#EC *
      i_cawn_c      TYPE STANDARD TABLE OF ty_cawn,         "#EC *
      i_cawn_i      TYPE STANDARD TABLE OF ty_cawn,         "#EC *
      i_cuv_error   TYPE STANDARD TABLE OF ty_vtnam,        "#EC *
      i_dupl        TYPE STANDARD TABLE OF ty_dupl,         "#EC *
      i_dbtab       TYPE STANDARD TABLE OF ty_dbtab.        "#EC *

DATA: i_vnt_ma TYPE STANDARD TABLE OF ty_vnt_ma,            "#EC *
      i_split  TYPE STANDARD TABLE OF ty_split.             "#EC *

DATA: i_dupl_file TYPE STANDARD TABLE OF ty_dupl.           "#EC *

DATA: i_charval TYPE STANDARD TABLE OF ty_charval.          "#EC *

*---------- Constants
CONSTANTS: c_char TYPE atfor VALUE 'CHAR',                  "#EC *
           c_date TYPE atfor VALUE 'DATE',                  "#EC *
           c_time TYPE atfor VALUE 'TIME',                  "#EC *
           c_varcond TYPE atnam VALUE 'Z_VARCOND'.          "#EC *

*--------- Field Symbols
FIELD-SYMBOLS: %LTfs_vtnam%GT      TYPE ty_vtnam,               "#EC *
               %LTfs_cabn%GT       TYPE ty_cabn,                "#EC *
               %LTfs_cuvtab_fld%GT TYPE ty_cuvtab_fld,          "#EC *
               %LTfs_dupl%GT       TYPE ty_dupl.                "#EC *

FIELD-SYMBOLS: %LTFS_DYN_WA%GT TYPE ANY.

*-------- Variables
DATA: g_raw(500)  TYPE c,                                   "#EC *
      g_invalid   TYPE char1,                               "#EC *
      g_error     TYPE char1,                               "#EC *
      g_message   TYPE char50,                              "#EC *
      g_slnid_c    TYPE slnid,                              "#EC *
      g_slnid_n    TYPE slnid,                              "#EC *
      g_row        TYPE char5.                              "#EC *

DATA: g_varcond TYPE varcond, "Variant condition "#EC NEEDED
      g_split_var TYPE i,                                   "#EC *
      g_split_var1 type i.                                  "#EC *

Types: begin of ty_charname,
         name type atnam,
       end of ty_charname.

data: wa_charname type ty_charname,                         "#EC *
      i_charname type standard table of ty_charname.        "#EC *
data: cnt_i type i,                                         "#EC *
      g_tabix type char10.                                  "#EC *

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.          "#EC *

DATA: itab_zedidd40 type standard table of
                  ty_itab_zedidd40 initial size 0.          "#EC *

DATA: wa_itab_zedidc40 type ty_itab_zedidc40.               "#EC NEEDED

DATA: wa_itab_zedidd40 type ty_itab_zedidd40.
****************************************************************
*MOD-009
****************************************************************

data: itab_ze1cuvtm type e1cuvtm,                           "#EC *
      itab_ze1datem type e1datem,                           "#EC *
      itab_ze1cuv1m type e1cuv1m.                           "#EC *

data: wdocnum(16) type n value 0.                           "#EC *
data: wsegnum(6)  type n value 0.                           "#EC *
data: witemno(10) type n value 0.                           "#EC *
data: witemno_new(10)  type n value 0.                      "#EC *
data: witemno_gst(10)  type n value 0.                      "#EC *
data: witemno_qst(10)  type n value 0.                      "#EC *
TYPES: BEGIN OF ty_input_data1,                             "#EC *
          line(560) 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. "with header line.

DATA: i_input_data1 type standard table of
                  ty_input_data1 initial size 0. "with header line.

DATA: wa_input_data type ty_input_data1.                    "#EC *
DATA: g_cnt_input_recs type i.                              "#EC *
DATA: g_flg_error type c.                                   "#EC *
DATA: l_lines type i.                                       "#EC *
DATA: l_lines1 type i.                                      "#EC *
DATA: l_tabix type i.                                       "#EC *
DATA: wa_input_data1 type ty_input_data1.                   "#EC *

DATA: FILE TYPE STRING.
* Fields that are made available to the user:
DATA:
  g_cnt_records_read TYPE i,                                "#EC *
  g_cnt_records_transferred TYPE i,                         "#EC *
  g_cnt_transactions_read TYPE i,                           "#EC *
  g_cnt_transactions_transferred TYPE i,                    "#EC *
  g_cnt_idocs_package TYPE i.                               "#EC *

data: v_log_handle type balloghndl.                         "#EC *

DATA: gt_curr_edi_dc40 TYPE STANDARD TABLE OF edi_dc40 initial size 0.
                                                            "#EC *
DATA: gt_curr_edi_dd40 TYPE STANDARD TABLE OF edi_dd40 initial size 0.
                                                            "#EC *

DATA: wa_curr_edi_dc40 TYPE edi_dc40.                       "#EC *

DATA: wa_curr_edi_dd40 TYPE edi_dd40.                       "#EC *


* internal table for error messages during conversion
DATA: g_error_tab TYPE type_errortab,                       "#EC *
      wa_errortab TYPE type_errorline.                      "#EC *

DATA:  g_edidd_segnam type EDI4SEGNAM,                      "#EC *
       g_edidd_hlevel type EDI4HLEVEC.                      "#EC *

DATA: g_segnum(6) TYPE n.
DATA: g_objecttype(2) type C.

DATA: P_FNAME(128) TYPE C VALUE '/usr/sap/put/vartabheader'.
" MODIF ID MD1 OBLIGATORY.
DATA: P_FNAME1(128) TYPE C VALUE '/usr/sap/put/vartabcontent'.
" MODIF ID MD1 OBLIGATORY.

field-symbols: %LTdyn_table%GT type standard table,
               %LTdyn_table1%GT type standard table,
               %LTdyn_wa%GT,
               %LTdyn_wa1%GT TYPE ANY.

data: dy_table type ref to data,
      dy_line  type ref to data,
      xfc type lvc_s_fcat,
      ifc type lvc_t_fcat.

data: l_tabname TYPE tabname.

DATA: l_len_slnid TYPE i,                                   "#EC NEEDED
        l_len_varcond TYPE i,                               "#EC NEEDED
        l_temp_slnid TYPE i,                                "#EC NEEDED
        l_temp_slnc TYPE char5,                             "#EC NEEDED
        l_temp_varcond TYPE varcond,                        "#EC NEEDED
        l_sub_var      TYPE i,                              "#EC NEEDED
        l_val_split TYPE char10.                            "#EC NEEDED

DATA: l_invalid.                                            "#EC NEEDED

*Include for Global Data Declaration
*INCLUDE ZGTDMI_VARTAB_TOPDYN.
*INCLUDE /FACTGLB/GTDMI_VARTAB_TOP02.
*Include for Selection Screen
*INCLUDE ZGTDMI_VARTAB_SELDYN.
*INCLUDE /FACTGLB/GTDMI_VARTAB_SEL02.
*Include for Sub Routines
*INCLUDE ZGTDMI_VARTAB_FORMSDYN.
*INCLUDE /FACTGLB/GTDMI_VARTAB_FORMS02.

*&---------------------------------------------------------------------*
*&  Include           ZGTDMI_VARTAB_SEL
*&---------------------------------------------------------------------*

*----------------------------------------------------------------------*
* PROGRAM DESCRIPTION: Variant Table and Content Upload Interface.
*
*           DEVELOPER: Aveek Ghose
*       CREATION DATE: 2008-08-25
*          RDD NUMBER: DCDD027
* TRANSPORT NUMBER(S): RD2K902769
*
*- REVISION HISTORY -------------------------------------------------*
*
*           DEVELOPER:
*        DATE APPLIED: YYYY-MM-DD
*          SCR NUMBER: %LTScope Change Request ID%GT
*          RDD NUMBER: %LTToolset Object ID%GT
* TRANSPORT NUMBER(S):
*         DESCRIPTION:
*
*----------------------------------------------------------------------*

************************************************************************
* DECLARATION FOR SELECTION SCREEN
************************************************************************
*---------------------------------------------------------------------
*selection-screen skip 1.
*---------------------------------------------------------------------

*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 .
" Presentation server File Variant table
PARAMETERS:   p_inpt1  TYPE RLGRAP-FILENAME MODIF ID MOD .
" Presentation server File variant Content
SELECTION-SCREEN END OF BLOCK bl1.

** 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.

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_convt RADIOBUTTON GROUP RB1,
  rb_idoc RADIOBUTTON GROUP RB1.
* rb_proc RADIOBUTTON GROUP RB1.
SELECTION-SCREEN END OF BLOCK bl3.

************************************************************************
* INITIALIZATION
************************************************************************
INITIALIZATION.

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 %LT%GT 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 %LT%GT 0.
    MESSAGE e241.
  ENDIF.

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

AT SELECTION-SCREEN OUTPUT.

* IF rb_apsrv = '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.

  IF rb_apsrv = 'X'.
    PERFORM sub_upload_data_app.
    MESSAGE i257.
    LEAVE LIST-PROCESSING.
    EXIT.
  ELSE.
    PERFORM sub_upload_data.
  ENDIF.

* 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.

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           ZGTDMI_VARTAB_FORMS02                            *
*&---------------------------------------------------------------------*

*----------------------------------------------------------------------*
* PROGRAM DESCRIPTION: Variant Table and Content Upload Interface.
*
*           DEVELOPER: Aveek Ghose
*       CREATION DATE: 2008-08-25
*          RDD NUMBER: DCDD027
* TRANSPORT NUMBER(S): RD2K902769
*
*- REVISION HISTORY -------------------------------------------------*
*
*           DEVELOPER:
*        DATE APPLIED: YYYY-MM-DD
*          SCR NUMBER: %LTScope Change Request ID%GT
*          RDD NUMBER: %LTToolset Object ID%GT
* 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_UPLOAD_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  p2        text
*----------------------------------------------------------------------*
FORM SUB_UPLOAD_DATA .

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

* Upload from presentation server
*   perform sub_upload_from_preserver.
  perform sub_upload_from_appserver1.

ENDFORM.                    " SUB_UPLOAD_DATA
*&---------------------------------------------------------------------*
*&      Form  sub_get_physical_file
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      --%GTP_P_FPATH  text
*      --%GTP_P_LPATH  text
*----------------------------------------------------------------------*
FORM sub_get_physical_file USING    p_lfile type FILEINTERN "#EC *
                                    p_pfile type LOCALFILE. "#EC *

  IF 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.
  ENDIF.

ENDFORM.                    " sub_get_physical_file
**&---------------------------------------------------------------------
**
*&      Form  sub_end_selection
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  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
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  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 sy-subrc %LT%GT 0.
    MESSAGE i088.                  "Invalid Logical System
    LEAVE LIST-PROCESSING.
  ENDIF.

  IF rb_apsrv = 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
*----------------------------------------------------------------------*
*      --%GTP_P_FPATH  text
*      --%GTP_P_FNAME  text
*----------------------------------------------------------------------*
FORM sub_get_physical_file1 USING   p_lfile1 type FILEINTERN"#EC *
                                    p_pfile1 type LOCALFILE."#EC *

  IF 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.
  ENDIF.

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

*&---------------------------------------------------------------------*
*&      Form  get_internal_char
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      --%GTP_CHARAC   text
*      --%GTP_CABN     text
*      --%GTP_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 %LT%GT 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 = '/factglb/gta_custdev'.
    wa_errortab-msgno = 008.
    wa_errortab-par1 = wa_vtnam-reas.
    INSERT wa_errortab INTO TABLE g_error_tab.
*   APPEND WA_ERRORTAB TO G_ERROR_TAB.
  ENDIF.

ENDFORM.                    "get_internal_char

*&---------------------------------------------------------------------*
*&      Form  find_char_exist
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      --%GT%LTFS_VTNAM%GT text
*      --%GTWA_CABN    text
*----------------------------------------------------------------------*
FORM find_char_exist USING p_file  TYPE ty_file             "#EC *
                           p_vtnam TYPE ty_vtnam            "#EC *
                           p_cabn  TYPE ty_cabn.            "#EC *

  DATA: l_quot TYPE char2,                                  "#EC NEEDED
        l_pos  TYPE char3.                                  "#EC *

  IF p_vtnam-error IS INITIAL.
*********************************************************
*MOD-012
*********************************************************
*   sort i_cuvtab_fld by vtint atinn.

    READ TABLE i_cuvtab_fld ASSIGNING %LTfs_cuvtab_fld%GT
    WITH KEY vtint = p_vtnam-vtint
             atinn = p_cabn-atinn
             binary search.

    IF sy-subrc = 0.
      %LTfs_cuvtab_fld%GT-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 = %LTfs_cuvtab_fld%GT-vtpos.
      APPEND wa_col_pos TO i_col_pos.
      CLEAR wa_col_pos.
    ENDIF.
  ENDIF.
ENDFORM.                    "find_char_exist

*&---------------------------------------------------------------------*
*&      Form  transfer_e1cuv1m
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      --%GTP_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

  IF p_trfcpt = c_x.
    wa_curr_edi_dd40 = wa_itab_zedidd40.
    APPEND wa_curr_edi_dd40 to gt_curr_edi_dd40.
  ENDIF.

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

*&---------------------------------------------------------------------*
*&      Form  transfer_e1cuvtm
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      --%GTP_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
*----------------------------------------------------------------------*
*      --%GTP_VTNAM  Variant table
*      --%GTP_FIELDNAME    Fieldname
*      --%GTP_ATNAM  Characteristic name
*      --%GTP_VAL       Value
*      --%GTP_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.
  APPEND wa_error TO itab_error.

ENDFORM.                    "errror_line

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

  SORT i_file.
  DELETE ADJACENT DUPLICATES FROM i_file.
ENDFORM.                    "sub_delete_duplicates "#EC CALLED

*&---------------------------------------------------------------------*
*&      Form  pop_dupl
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      --%GTP_VTNAM  text
*      --%GTP_SLNID       text
*      --%GTP_ATNAM   text
*      --%GTP_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:  %LTfs_val%GT 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 %LTfs_val%GT.
    CLEAR wa_col_pos.
*****************************************************
*MOD-012
*****************************************************
*    SORT i_col_pos BY  vtint
*                       vtnam
*                       atinn
*                       atnam.
******************************************************
*MOD-012
*****************************************************
    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 %LTfs_dupl%GT WITH KEY vtnam = p_vtnam
                                                   slnid = p_slnid.
    IF sy-subrc = 0.

      CONCATENATE '%LTFS_DUPL%GT-CHAR'  wa_col_pos-field INTO l_field.
      ASSIGN (l_field) TO %LTfs_val%GT.
      %LTfs_val%GT = 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 %LTfs_val%GT.
      %LTfs_val%GT = p_val.
      APPEND wa_dupl TO i_dupl.

    ENDIF.
  ENDIF.
ENDFORM.                    "pop_dupl

*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  TRANSFER_RECORD_IDOC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  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'.

*********************************************
      CLEAR: wa_curr_edi_dd40.
**********************************************
*MOD-012
**********************************************
      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 = 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
**********************************************

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

ENDFORM.                    " TRANSFER_RECORD_IDOC "#EC CALLED

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

*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  FILL_EDIDD_SEGMENTS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  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 %GT 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.
          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
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  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.

  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
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  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
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  p2        text
*----------------------------------------------------------------------*
FORM SUB_CONVERT_TRANSACTION .

  DATA: L_TABLE TYPE APITABL.                               "#EC *
  DATA: L_CHANGE_NUMBER TYPE AENNR.                         "#EC *
  DATA: L_DLOCK          TYPE DLOCK,                        "#EC *
        ITAB_VT_BASIC_DATA   TYPE  VTBASDAT,                "#EC *
        L_DATE            TYPE VONDATX,                     "#EC *
        L_LINE_NO         TYPE I.                           "#EC *

  DATA: wa_var_tab_entries type VTENTRIES.                  "#EC *
  DATA: ITAB_VAR_TAB_ENTRIES TYPE STANDARD TABLE OF VTENTRIES."#EC *

  PERFORM sub_clear_tables.

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

  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'                 "#EC *
      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.

* I_CONTENTTAB3[] = I_CONTENTTAB1[].

* SORT I_CONTENTTAB3 BY VTNAM.

  DELETE I_CONTENTTAB3 WHERE VTNAM IS INITIAL.
* DELETE ADJACENT DUPLICATES FROM I_CONTENTTAB1.
  CLEAR: L_LINES.
  DESCRIBE TABLE I_CONTENTTAB3 LINES L_LINES.
  IF L_LINES = 1.
    g_error = c_X.
    CLEAR wa_vtnam.
    MESSAGE I164.
    LEAVE LIST-PROCESSING.
  ENDIF.

**********************************************************************
*MOD-0112
**********************************************************************

* perform sub_clear_tables.

**********************************************************************
*MOD-012
**********************************************************************
* IF G_ERROR %LT%GT C_X.
**********************************************************************
*MOD-009
**********************************************************************
  clear: wa_contentheader1.

  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' ) .
*****************************************************
*MOD-012
***************************************************
        cnt_i = 18.
        g_raw = wa_file.
        DO 15 TIMES.
          wa_charname-name = g_raw+cnt_i(30).
          APPEND wa_charname TO i_charname.
          cnt_i = cnt_i + 30.
        ENDDO.

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

        APPEND wa_file TO i_file_tmp.
        CLEAR: WA_FILE.
* Check duplicate columns for characteristics
*         PERFORM sub_dupl_columns.
      ENDIF.
    ENDIF.
************************************************************************
**
***MOD-009
************************************************************************
**

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

* 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.

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

*    IF g_error %LT%GT '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 %LT%GT c_x.

    IF rb_idoc = c_x.
      PERFORM SUB_CREATE_IDOCS.
    ENDIF.

    MESSAGE I260.
*        LEAVE LIST-PROCESSING.
*      ENDIF.

    PERFORM SUB_CLEAR_VARIABLES.
    DELETE I_CONTENTTAB1 WHERE VTNAM = WA_CONTENTHEADER1-VTNAM.
*    ENDIF.

  ENDLOOP.

ENDFORM.                    " SUB_CONVERT_TRANSACTION
*&---------------------------------------------------------------------*
*&      Form  SUB_CREATE_IDOCS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  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'.                    "#EC *
** Local Data Declaration
*  DATA: l_logsys     TYPE logsys,                           "#EC *
*        l_i_model    TYPE TABLE OF bdi_mmodel,              "#EC *
*        l_rec_model  TYPE bdi_mmodel,                       "#EC *
*        l_rec_edidc  TYPE edidc,                            "#EC *
*        l_rec_edidd  TYPE edidd,                            "#EC *
*        l_v_cnt      TYPE i VALUE 0.                        "#EC *
*
*  DATA: wa_i_mmodel type bdi_mmodel.                        "#EC *
*
*  DATA:
*       l_text(132),                                         "#EC *
*       l_lines TYPE i,                                      "#EC *
*       l_idoc_nr_from TYPE i,                               "#EC *
*       l_idoc_nr_to TYPE i,                                 "#EC *
*       l_idoc_nr_from_char(10) type c,                      "#EC *
*       l_idoc_nr_to_char(10) type c,                        "#EC *
*       l_edkp1 type edkp1,                                  "#EC *
*       l_edk21 type edk21.                                  "#EC *
*  DATA:
*      l_flg_tranferred_something.                           "#EC *
*
*  FIELD-SYMBOLS:
*    %LTbuffer%GT.                                               "#EC *

  TYPES: BEGIN OF TY_DD03L,
          TABNAME TYPE TABNAME,
          FIELDNAME TYPE FIELDNAME,
         END OF TY_DD03L.

  DATA: ITAB_DD03L TYPE STANDARD TABLE OF TY_DD03L.         "#EC *
  DATA: WA_DD03L TYPE TY_DD03L.                             "#EC *

***************************************************************
*MOD-015
***************************************************************
  SELECT SINGLE DBTAB_NAME                                  "#EC *
  INTO L_TABNAME
  FROM CUVTAB
  WHERE VTNAM = wa_contentheader1-vtnam.

  CHECK SY-SUBRC = 0.

  IF NOT L_TABNAME IS INITIAL.
    perform get_structure.
    perform create_dynamic_itab.
    perform get_data.
  ENDIF.

ENDFORM.                    " SUB_CREATE_IDOCS
*&---------------------------------------------------------------------*
*&      Form  SUB_START_IDOC_PROCESS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  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 MESTYP EQ C_VTMMAS SIGN 'I'
*  AND RETURN.
*
*  REFRESH: R_CREDAT,
*           R_CRETIM,
*           R_MESTYP.
*
*
*ENDFORM.                    " SUB_START_IDOC_PROCESS
**&---------------------------------------------------------------------
**
*&      Form  SUB_UPLOAD_FROM_APPSERVER
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  p2        text
*----------------------------------------------------------------------*
FORM SUB_UPLOAD_FROM_APPSERVER .

  DATA: l_timestamp type timestamp.
  DATA: l_time(15) type C.
  DATA: WA_DVNT_TM TYPE ZDVNT_TM.
  DATA: l_counter type NUMC04.

  SELECT max( COUNTER )
       INTO L_COUNTER
       FROM ZDVNT_TM.

  L_COUNTER  = L_COUNTER + 1.

  get time stamp field l_timestamp.
  write l_timestamp to l_time.
  CONCATENATE P_FNAME SY-UNAME l_time '.txt'  INTO P_FNAME.

  WA_DVNT_TM-MANDT  = SY-MANDT.
  WA_DVNT_TM-BNAME  = SY-UNAME.
  WA_DVNT_TM-COUNTER = L_COUNTER.
  WA_dVNT_TM-FILETYPE = C_X.
  WA_DVNT_TM-FILEINTERN = P_FNAME.
  WA_DVNT_TM-DATE_TIME_STMP = l_time.
  insert into ZDVNT_TM values WA_DVNT_TM.

  get time stamp field l_timestamp.
  write l_timestamp to l_time.
  CONCATENATE P_FNAME1 SY-UNAME l_time '.txt'  INTO P_FNAME1.

  WA_DVNT_TM-MANDT  = SY-MANDT.
  WA_DVNT_TM-BNAME  = SY-UNAME.
  WA_DVNT_TM-COUNTER = L_COUNTER.
  WA_DVNT_TM-FILETYPE = C_Y.
  WA_DVNT_TM-FILEINTERN = P_FNAME1.
  WA_DVNT_TM-DATE_TIME_STMP = l_time.
  insert into ZDVNT_TM values WA_DVNT_TM.

  CLEAR: L_COUNTER.

  if rb_apsrv  = 'X'.
    OPEN DATASET p_fname FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    LOOP AT I_INPUT_DATA INTO WA_INPUT_DATA.
      IF SY-SUBRC = 0.
        TRANSFER WA_INPUT_DATA TO p_fname.
      ENDIF.
    ENDLOOP.

    OPEN DATASET p_fname1 FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    LOOP AT I_INPUT_DATA1 INTO WA_INPUT_DATA1.
      IF SY-SUBRC = 0.
        TRANSFER WA_INPUT_DATA1 TO p_fname1.
      ENDIF.
    ENDLOOP.
  ENDIF.

ENDFORM.                    " SUB_UPLOAD_FROM_APPSERVER
*&---------------------------------------------------------------------*
*&      Form  SUB_UPLOAD_FROM_PRESERVER
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  p2        text
*----------------------------------------------------------------------*
FORM SUB_UPLOAD_FROM_PRESERVER .

  CONSTANTS: C_ASC(10) TYPE C VALUE 'ASC'.                  "#EC *

* 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.

ENDFORM.                    " SUB_UPLOAD_FROM_PRESERVER
*&---------------------------------------------------------------------*
*&      Form  SUB_FINAL_MESSAGE_IDOC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  p2        text
*----------------------------------------------------------------------*
*FORM SUB_FINAL_MESSAGE_IDOC .
*
*  DATA:
*      l_tabix type sy-tabix,                                "#EC *
*      l_filename_read TYPE tumls_filename,                  "#EC *
*      l_filename_conv TYPE tumls_filename.                  "#EC *
*
*  DATA:
*    l_cnt_records_read(10) type c,                          "#EC *
*    l_cnt_transactions_read(10) type c,                     "#EC *
*    l_cnt_records_transferred(10) type c,                   "#EC *
*    l_cnt_transactions_transferred(10) type c.              "#EC *
*
*  DATA:
*    l_messagetext(130),                                     "#EC *
*    wa_errortab TYPE type_errorline.                        "#EC *
*
*
*  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: / '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.
*
*
*
*ENDFORM.                    " SUB_FINAL_MESSAGE_IDOC
**&---------------------------------------------------------------------
**
*&      Form  SUB_DISPLAY_VARIANT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  p2        text
*----------------------------------------------------------------------*
FORM SUB_DISPLAY_VARIANT .

  IF NOT i_cuv_error IS INITIAL.
    SKIP 2.
    WRITE:/ 'Following tables have incorrect characteristic names'(013).
* 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
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  p2        text
*----------------------------------------------------------------------*
FORM SUB_DISPLAY_ERRORLINES .

  SKIP 2.
  IF NOT itab_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 itab_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
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  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
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  p2        text
*----------------------------------------------------------------------*
FORM SUB_CLEAR_TABLES .

  CLEAR:  i_file,
          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
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  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
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  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'.
********************************************
**MOD-009
********************************************
**  itab_zedidd40-hlevel = '02'.
** itab_zedidd40-docnum          = wdocnum.                       "#EC
*NEEDED
**  itab_zedidd40-segnum          = wsegnum.
**  itab_zedidd40-segnam          = c_E1DATEM.
********************************************
**MOD-009
********************************************
*  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
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  p2        text
*----------------------------------------------------------------------*
FORM SUB_CONVERT_0003 .

  perform sub_store_file.

ENDFORM.                    " SUB_CONVERT_0003
*&---------------------------------------------------------------------*
*&      Form  SUB_GET_CUVTAB
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  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 %LT%GT 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 = '/factglb/gta_custdev'.
    wa_errortab-msgno = 075.
    wa_errortab-par1 = wa_vtnam-reas.
*   INSERT wa_errortab INTO TABLE g_error_tab.
    INSERT WA_ERRORTAB INTO TABLE G_ERROR_TAB.
    clear: wa_vtnam, wa_errortab.
  ENDIF.
***********************************************************
*MOD-012
***********************************************************
*   clear: WA_CONTENTHEADER1.
***********************************************************
*MOD-012
***********************************************************

ENDFORM.                    " SUB_GET_CUVTAB
*&---------------------------------------------------------------------*
*&      Form  SUB_GET_VNT_MA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  p2        text
*----------------------------------------------------------------------*
FORM SUB_GET_VNT_MA .

  constants: c_e(1)   TYPE c value 'E',                     "#EC *
             C_001(3) TYPE C VALUE '001'.                   "#EC *

  CLEAR wa_vnt_ma.

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

  IF sy-subrc %LT%GT 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 = '/factglb/gta_custdev'.
    wa_errortab-msgno = 076.
    wa_errortab-par1 = wa_vtnam-reas.
*   INSERT wa_errortab INTO TABLE g_error_tab.
    INSERT WA_ERRORTAB INTO TABLE G_ERROR_TAB.
    clear: wa_vtnam, wa_errortab.
  ENDIF.

ENDFORM.                    " SUB_GET_VNT_MA
*&---------------------------------------------------------------------*
*&      Form  SUB_GET_CUVTAB_VALN
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  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
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  p2        text
*----------------------------------------------------------------------*
FORM SUB_GET_CUVTAB_FLD .

  IF g_error %LT%GT c_x.

    IF NOT i_cuvtab[] IS INITIAL.
      SELECT vtint atinn vtpos DBFLD
      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 = '/factglb/gta_custdev'.
          wa_errortab-msgno = 077.
          wa_errortab-par2 = wa_vtnam-reas.
*         INSERT wa_errortab INTO TABLE g_error_tab.
          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
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  p2        text
*----------------------------------------------------------------------*
FORM SUB_CHECK_CABN .

  LOOP AT i_cabn ASSIGNING %LTfs_cabn%GT.
    READ TABLE i_cawn_i INTO wa_cawn WITH KEY atinn = %LTfs_cabn%GT-atinn.
    IF sy-subrc %LT%GT 0.
      %LTfs_cabn%GT-check = C_X.
    ENDIF.
  ENDLOOP.

ENDFORM.                    " SUB_CHECK_CABN
*&---------------------------------------------------------------------*
*&      Form  SUB_GET_CUVTAB_VALC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  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
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  p2        text
*----------------------------------------------------------------------*
FORM SUB_VALIDATE_TABLE_FIELDS .

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

    IF sy-subrc %LT%GT 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 %LT%GT 0.

        %LTfs_vtnam%GT-error = C_X.
        %LTfs_vtnam%GT-reas  = text-011.                        "#EC NOTEXT
        g_error = 'X'.
        CLEAR wa_vtnam.
        wa_vtnam = %LTfs_vtnam%GT.
        APPEND wa_vtnam TO i_cuv_error.
        wa_errortab-msgty = C_E.
        wa_errortab-id = '/factglb/gta_custdev'.
        wa_errortab-msgno = 078.
        wa_errortab-par2 = wa_vtnam-reas.
*       INSERT wa_errortab INTO TABLE g_error_tab.
        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
                                        %LTfs_vtnam%GT.

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

      CHECK %LTfs_vtnam%GT-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
                                        %LTfs_vtnam%GT.
*      Find out if characteristic name exists in variant table definitio
        PERFORM find_char_exist USING wa_file
                                      %LTfs_vtnam%GT
                                      wa_cabn.
      ENDIF.
      CHECK %LTfs_vtnam%GT-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
                                        %LTfs_vtnam%GT.
*      Find out if characteristic name exists in variant table definitio
        PERFORM find_char_exist USING wa_file
                                      %LTfs_vtnam%GT
                                      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
                                        %LTfs_vtnam%GT.
*      Find out if characteristic name exists in variant table definitio
        PERFORM find_char_exist USING wa_file
                                      %LTfs_vtnam%GT
                                      wa_cabn.

      ENDIF.
      CHECK %LTfs_vtnam%GT-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
                                        %LTfs_vtnam%GT.
*      Find out if characteristic name exists in variant table definitio
        PERFORM find_char_exist USING wa_file
                                      %LTfs_vtnam%GT
                                      wa_cabn.

      ENDIF.
      CHECK %LTfs_vtnam%GT-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
                                        %LTfs_vtnam%GT.
*      Find out if characteristic name exists in variant table definitio
        PERFORM find_char_exist USING wa_file
                                      %LTfs_vtnam%GT
                                      wa_cabn.

      ENDIF.
      CHECK %LTfs_vtnam%GT-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
                                        %LTfs_vtnam%GT.

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

      ENDIF.
      CHECK %LTfs_vtnam%GT-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
                                        %LTfs_vtnam%GT.
*      Find out if characteristic name exists in variant table definitio
        PERFORM find_char_exist USING wa_file
                                      %LTfs_vtnam%GT
                                      wa_cabn.

      ENDIF.
      CHECK %LTfs_vtnam%GT-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
                                        %LTfs_vtnam%GT.
*      Find out if characteristic name exists in variant table definitio
        PERFORM find_char_exist USING wa_file
                                      %LTfs_vtnam%GT
                                      wa_cabn.

      ENDIF.
      CHECK %LTfs_vtnam%GT-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
                                        %LTfs_vtnam%GT.
*      Find out if characteristic name exists in variant table definitio
        PERFORM find_char_exist USING wa_file
                                      %LTfs_vtnam%GT
                                      wa_cabn.

      ENDIF.
      CHECK %LTfs_vtnam%GT-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
                                        %LTfs_vtnam%GT.
*      Find out if characteristic name exists in variant table definitio
        PERFORM find_char_exist USING wa_file
                                      %LTfs_vtnam%GT
                                      wa_cabn.

      ENDIF.
      CHECK %LTfs_vtnam%GT-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
                                        %LTfs_vtnam%GT.
*      Find out if characteristic name exists in variant table definitio
        PERFORM find_char_exist USING wa_file
                                      %LTfs_vtnam%GT
                                      wa_cabn.

      ENDIF.
      CHECK %LTfs_vtnam%GT-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
                                        %LTfs_vtnam%GT.
*      Find out if characteristic name exists in variant table definitio
        PERFORM find_char_exist USING wa_file
                                      %LTfs_vtnam%GT
                                      wa_cabn.

      ENDIF.
      CHECK %LTfs_vtnam%GT-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
                                        %LTfs_vtnam%GT.
*      Find out if characteristic name exists in variant table definitio
        PERFORM find_char_exist USING wa_file
                                      %LTfs_vtnam%GT
                                      wa_cabn.

      ENDIF.
      CHECK %LTfs_vtnam%GT-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
                                        %LTfs_vtnam%GT.
*      Find out if characteristic name exists in variant table definitio
        PERFORM find_char_exist USING wa_file
                                      %LTfs_vtnam%GT
                                      wa_cabn.

      ENDIF.
    ENDIF.
  ENDLOOP.

ENDFORM.                    " SUB_VALIDATE_TABLE_FIELDS
*&---------------------------------------------------------------------*
*&      Form  SUB_CHARAC_EXIST
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  p2        text
*----------------------------------------------------------------------*
FORM SUB_CHARAC_EXIST .

  IF g_error %LT%GT '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 = '/factglb/gta_custdev'.
      wa_errortab-msgno = 079.
      wa_errortab-par1 = wa_vtnam-reas.
*     INSERT wa_errortab INTO TABLE g_error_tab.
      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
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  p2        text
*----------------------------------------------------------------------*
FORM SUB_VALIDATE_CHARAC_VALUES .

  LOOP AT i_cuvtab INTO wa_vtnam WHERE error %LT%GT 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.
*************************************************
*MOD-012
*************************************************

      SORT i_dupl. " BY vtnam char1 char2 char3
      " char4 char5 char6 char7
      "  char8 char9 char10 char11
      "  char12 char13 char14 char15.
*************************************************
*MOD-012
*************************************************
    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 %LT g_slnid_n.
      g_slnid_c = g_slnid_n.
    ENDIF.

**************************************************************
*MOD-016
**************************************************************
*   g_split_var = 0.
**************************************************************
*MOD-016
**************************************************************

    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 = c_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
**************************************************************
*      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
******************************************************************

*****************************************************
**MOD-009
*****************************************************
    ENDLOOP.
  ENDLOOP.

ENDFORM.                    " SUB_VALIDATE_CHARAC_VALUES
*&---------------------------------------------------------------------*
*&      Form  SUB_TRANSFER_ST_CHAR
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  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 %GT 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
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  p2        text
*----------------------------------------------------------------------*
FORM SUB_TRANSFER_ST_NUM .

  DATA: l_val   TYPE p,                                     "#EC NEEDED
        l_val1  TYPE p DECIMALS 1,                          "#EC NEEDED
        l_val2  TYPE p DECIMALS 2,                          "#EC NEEDED
        l_val3  TYPE p DECIMALS 3,                          "#EC NEEDED
        l_char TYPE char16.                                 "#EC NEEDED

  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
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  p2        text
*----------------------------------------------------------------------*
FORM SUB_CHECK_CHAR_VALUES .

  DATA: l_fieldname TYPE fieldname,
         l_field_dup TYPE fieldname.
  FIELD-SYMBOLS: %LTfs_val%GT TYPE ANY,
                 %LTfs_val1%GT TYPE ANY.

*  DATA: l_len_slnid TYPE i,                                 "#EC NEEDED
*        l_len_varcond TYPE i,                               "#EC NEEDED
*        l_temp_slnid TYPE i,                                "#EC NEEDED
*        l_temp_slnc TYPE char5,                             "#EC NEEDED
*        l_temp_varcond TYPE varcond,                        "#EC NEEDED
*        l_sub_var      TYPE i,                              "#EC NEEDED
*        l_val_split TYPE char10.                            "#EC NEEDED
*
*  DATA: l_invalid.                                          "#EC NEEDED

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

************************************************************************
**
**MOD-012
************************************************************************
**
  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 %LTfs_val%GT.

* Put values in work area to check for duplicates
    IF wa_col_pos-atnam %LT%GT 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 %LTfs_val1%GT.
************************************************
*MOD-008
************************************************
*   %LTfs_val1%GT = %LTfs_val%GT.
      IF NOT %LTfs_val%GT is initial.
        %LTfs_val1%GT = %LTfs_val%GT.
*       ASSIGN %LTfs_val%GT TO %LTfs_val1%GT.
      ENDIF.
************************************************
*MOD-008
************************************************
      CONCATENATE g_varcond %LTfs_val%GT 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 %LTfs_val%GT 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      = %LTfs_val%GT
              EXCEPTIONS
                not_found  = 1.

            IF sy-subrc %LT%GT 0.
              l_invalid = c_x.
              g_invalid = c_x.
            ENDIF.
          ENDCATCH.
        ENDIF.
************************************************************************
*********
**MOD-012
************************************************************************
*********
        IF l_invalid %LT%GT 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 =
                                                         %LTfs_val%GT.
                IF sy-subrc = 0.
                  IF wa_cawn-lkenz = c_x.
                    PERFORM errror_line USING wa_file-vtnam
                                              l_fieldname
                                              wa_cabn-atnam
                                              %LTfs_val%GT
                                              g_row.
                    g_invalid = c_x.

                    wa_file-error = C_X.
                    modify i_file from wa_file transporting error.
                  ELSE.
                    CLEAR wa_e1cuv1m.
                    wa_e1cuv1m-msgfn = c_009.
                    wa_e1cuv1m-vtlineno5 = g_slnid_c.
                    wa_e1cuv1m-vtcharact = wa_cabn-atnam.
                    wa_e1cuv1m-atwrt  = %LTfs_val%GT.
                    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
                                            %LTfs_val%GT
                                            g_row.
                  g_invalid = C_X.
                  wa_file-error = C_X.
                  modify i_file from wa_file transporting error.

                ENDIF.
              WHEN OTHERS.
************************************************************
*MOD-008
***********************************************************
                READ TABLE i_cawn_n INTO wa_cawn WITH KEY atinn =
                wa_cabn-atinn
                                                          atflv =
                                                          %LTfs_val%GT.
                IF sy-subrc = 0.
                  IF wa_cawn-lkenz = C_X.
                    PERFORM errror_line USING wa_file-vtnam
                                              l_fieldname
                                              wa_cabn-atnam
                                              %LTfs_val%GT
                                              g_row.
                    g_invalid = C_X.
                    wa_file-error = C_X.
                    modify i_file from wa_file transporting error.

                  ELSE.
                    CLEAR wa_e1cuv1m.
                    wa_e1cuv1m-msgfn = C_009.
                    wa_e1cuv1m-vtlineno5 = g_slnid_c.
                    wa_e1cuv1m-vtcharact = wa_cabn-atnam.
                    wa_e1cuv1m-atflv  = %LTfs_val%GT.
                    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
                                            %LTfs_val%GT
                                            g_row.

                  g_invalid = C_X.
                  wa_file-error = C_X.
                  modify i_file from wa_file transporting error.

                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  = %LTfs_val%GT.
                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  = %LTfs_val%GT.
                APPEND wa_e1cuv1m TO i_e1cuv1m.
****************************************************
*MOD-008
****************************************************
*PERFORM transfer_e1cuv1m. " USING wa_e1cuv1m.       "#EC *
                clear: wa_e1cuv1m.
****************************************************
*MOD-008
****************************************************

            ENDCASE.
          ENDIF.
        ELSE.

          PERFORM errror_line USING wa_file-vtnam
                                    l_fieldname
                                    wa_col_pos-atnam
                                    %LTfs_val%GT
                                    g_row.
          g_invalid = 'X'.
          wa_file-error = C_X.
          modify i_file from wa_file transporting error.

        ENDIF.

      ELSE.
        PERFORM errror_line USING wa_file-vtnam
                                  l_fieldname
                                  wa_col_pos-atnam
                                  %LTfs_val%GT
                                  g_row.
        g_invalid = 'X'.
        wa_file-error = C_X.
        modify i_file from wa_file transporting error.

      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-015
************************************************************************
**

  if g_split_var = 1.
*   I_CONTENTTAB3[] = I_CONTENTTAB1[].
    DELETE I_CONTENTTAB1 INDEX 1.
  endif.

  READ TABLE I_CONTENTTAB1 INTO WA_CONTENTTAB1 INDEX g_split_var.

  READ TABLE I_CONTENTTAB1 INTO WA_CONTENTTAB1
    WITH KEY vtnam = wa_file-vtnam
           char1 = wa_file-char1
           char2 = wa_file-char2
           char3 = wa_file-char3
           char4 = wa_file-char4
           char5 = wa_file-char5
           char6 = wa_file-char6
           char7 = wa_file-char7
           char8 = wa_file-char8
           char9 = wa_file-char9
           char10 = wa_file-char10
           char11 = wa_file-char11
           char12 = wa_file-char12
           char13 = wa_file-char13
           char14 = wa_file-char14
           char15 = wa_file-char15.

  IF sy-subrc = 0.
    G_SPLIT_VAR = SY-TABIX.
    WA_CONTENTTAB1-Z_VARCOND = G_VARCOND.
    MODIFY I_CONTENTTAB1 INDEX g_split_var FROM WA_CONTENTTAB1
    TRANSPORTING Z_VARCOND.

  ENDIF.

*MODIFY I_CONTENTTAB1 FROM WA_CONTENTTAB1 TRANSPORTING Z_VARCOND
*where      vtnam = wa_file-vtnam and
*           char1 = wa_file-char1 and
*           char2 = wa_file-char2 and
*           char3 = wa_file-char3 and
*           char4 = wa_file-char4 and
*           char5 = wa_file-char5 and
*           char6 = wa_file-char6 and
*           char7 = wa_file-char7 and
*           char8 = wa_file-char8 and
*           char9 = wa_file-char9 and
*           char10 = wa_file-char10 and
*           char11 = wa_file-char11 and
*           char12 = wa_file-char12 and
*           char13 = wa_file-char13 and
*           char14 = wa_file-char14 and
*           char15 = wa_file-char15.
*
** g_split_var = g_split_var + 1.

************************************************************************
**
*MOD-015
************************************************************************
**


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

  if g_invalid %LT%GT c_x.
* 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.
  endif.
************************************************************************
**
*MOD-012
************************************************************************
**
*  PERFORM transfer_e1cuv1m. " USING wa_e1cuv1m.    "#EC *

ENDFORM.                    " SUB_CHECK_CHAR_VALUES
*&---------------------------------------------------------------------*
*&      Form  SUB_DUPL_COLUMNS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  p2        text
*----------------------------------------------------------------------*
FORM SUB_DUPL_COLUMNS .

  DATA: l_fieldname TYPE fieldname,                         "#EC NEEDED
          l_counter TYPE char2.                             "#EC NEEDED
  FIELD-SYMBOLS: %LTfs_char_val%GT TYPE ANY.                    "#EC *
  CONSTANTS: c_field TYPE char12 VALUE 'WA_FILE-CHAR'.      "#EC NEEDED

  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 %LTfs_char_val%GT.
      IF %LTfs_char_val%GT IS ASSIGNED.
        wa_charval-char = %LTfs_char_val%GT.
        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
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  p2        text
*----------------------------------------------------------------------*
FORM SUB_STORE_FILE .

  DATA: G_RAW(500) TYPE C,
        CNT_I TYPE I.

  MOVE-CORRESPONDING wa_contenttab1 TO wa_file.

  IF NOT ( wa_file-flag = 'X' OR wa_file-flag = 'x' ) .

***********************************************************
*MOD-012
***********************************************************
*    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.
***********************************************************
*MOD-012
**********************************************************

    APPEND wa_file TO i_file.
    cLEAR: WA_FILE.
  ELSE.
*****************************************************
*MOD-012
***************************************************
    cnt_i = 18.
    g_raw = wa_file.
    DO 15 TIMES.
      wa_charname-name = g_raw+cnt_i(30).
      APPEND wa_charname TO i_charname.
      cnt_i = cnt_i + 30.
    ENDDO.

**************************************************
*MOD-012
*****************************************************
    APPEND wa_file TO i_file_tmp.
* Check duplicate columns for characteristics
    PERFORM sub_dupl_columns.
    CLEAR: WA_FILE.
  ENDIF.
**************************************************
*MOD-012
*****************************************************

ENDFORM.                    " SUB_STORE_FILE
*&---------------------------------------------------------------------*
*&      Form  SUB_CLEAR_VARIABLES
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  p2        text
*----------------------------------------------------------------------*
FORM SUB_CLEAR_VARIABLES .

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

  CLEAR:  itab_zedidd40[],
          itab_zedidd40[].

  REFRESH: gt_curr_edi_dd40,
           i_error.
  CLEAR  : gt_curr_edi_dd40.

  CLEAR  : g_segnum,
           g_error.

*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 .


ENDFORM.                    " SUB_CLEAR_VARIABLES
*&---------------------------------------------------------------------*
*&      Form  sub_upload_data_app
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  p2        text
*----------------------------------------------------------------------*
FORM sub_upload_data_app.

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

  perform sub_upload_from_preserver.
  perform sub_upload_from_appserver.

ENDFORM.                    " sub_upload_data_app
*&---------------------------------------------------------------------*
*&      Form  sub_upload_from_appserver1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  p2        text
*----------------------------------------------------------------------*
FORM sub_upload_from_appserver1.

  DATA: l_timestamp type timestamp.                         "#EC *
  DATA: l_time(15) type C.                                  "#EC *
  DATA: L_COUNTER TYPE NUMC04.                              "#EC *
  DATA: WA_DVNT_TM TYPE ZDVNT_TM.                           "#EC *

  SELECT max( COUNTER )
  INTO l_counter
  FROM ZDVNT_TM.

  SELECT SINGLE FILEINTERN                                  "#EC *
  INTO P_FNAME
  FROM ZDVNT_TM
  WHERE BNAME = SY-UNAME AND
        FILETYPE = C_X AND
        COUNTER  = L_COUNTER.

  CHECK SY-SUBRC = 0.

  SELECT SINGLE FILEINTERN                                  "#EC *
  INTO P_FNAME1
  FROM ZDVNT_TM
  WHERE BNAME = SY-UNAME AND
        FILETYPE = C_Y AND
        COUNTER  = L_COUNTER.

  CHECK SY-SUBRC = 0.

  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.
* delete 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 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=%GTHORIZONTAL_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=%GTHORIZONTAL_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.

  I_CONTENTTAB3[] = I_CONTENTTAB1[].

ENDFORM.                    " sub_upload_from_appserver1
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  GET_STRUCTURE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  p2        text
*----------------------------------------------------------------------*
form get_structure.

  data : idetails type abap_compdescr_tab,
         xdetails type abap_compdescr.

  data : ref_table_des type ref to cl_abap_structdescr.
  refresh: ifc.

  ref_table_des ?=
      cl_abap_typedescr=%GTdescribe_by_name( l_tabname ).
  idetails[] = ref_table_des-%GTcomponents[].

  loop at idetails into xdetails.
    clear xfc.
    xfc-fieldname = xdetails-name .
    xfc-datatype = xdetails-type_kind.
    xfc-inttype = xdetails-type_kind.
    xfc-intlen = xdetails-length.
    xfc-decimals = xdetails-decimals.
    xfc-ref_table = l_tabname.
    xfc-ref_field = xdetails-name.
    append xfc to ifc.
  endloop.

endform.                    "get_structure
*&---------------------------------------------------------------------*
*&      Form  CREATE_DYNAMIC_ITAB
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  p2        text
*----------------------------------------------------------------------*
form create_dynamic_itab.

  clear: dy_table.
  unassign %LTdyn_table%GT.
  unassign %LTdyn_table1%GT.
  unassign %LTdyn_wa%GT.
  unassign %LTFS_DYN_WA%GT.

* Create dynamic internal table and assign to FS
  call method cl_alv_table_create=%GTcreate_dynamic_table
    EXPORTING
      it_fieldcatalog = ifc
    IMPORTING
      ep_table        = dy_table.

  assign dy_table-%GT* to %LTdyn_table%GT.
  assign dy_table-%GT* to %LTdyn_table1%GT.

* Create dynamic work area and assign to FS
  create data dy_line like line of %LTdyn_table%GT.
  assign dy_line-%GT* to %LTdyn_wa%GT.

* Create dynamic work area and assign to the dynamic table
  CREATE DATA LV_LINE2 LIKE LINE OF %LTdyn_table%GT.
  ASSIGN LV_LINE2-%GT* TO %LTFS_DYN_WA%GT.

endform.                    "create_dynamic_itab
*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  p2        text
*----------------------------------------------------------------------*
form get_data.

  DATA:   WA_CONTENT TYPE TY_CONTENT.
  DATA:   ITAB_CONTENT TYPE standard table of TY_CONTENT.

  DATA:   L_COMP1(30) TYPE C,
          L_COMP2(30) TYPE C,
          L_COMP3(30) TYPE C,
          L_COMP4(30) TYPE C,
          L_COMP5(30) TYPE C,
          L_COMP6(30) TYPE C,
          L_COMP7(30) TYPE C,
          L_COMP8(30) TYPE C,
          L_COMP9(30) TYPE C,
          L_COMP10(30) TYPE C,
          L_COMP11(30) TYPE C,
          L_COMP12(30) TYPE C,
          L_COMP13(30) TYPE C,
          L_COMP14(30) TYPE C,
          L_COMP15(30) TYPE C.


  DATA: l_value(15) type c.
  DATA: l_value1(30) type c.

  data: l_lines type i,
        l_lines_varcond type i,
        l_index1 type sy-index.

  field-symbols: %LTfs_field2%GT type any,
                 %LTfs_field3%GT type any.


  FIELD-SYMBOLS:   %LTfs_field%GT TYPE ANY,
                   %LTfs_field1%GT TYPE ANY.

*
* Local variable declaration
* DATA:  l_tabname TYPE tabname.    "Table name
  TYPES: BEGIN OF TY_CHARAC,
          CHAR(30) TYPE C,
         END OF TY_CHARAC.

  TYPES: BEGIN OF TY_DD03L,
          TABNAME TYPE TABNAME,
          FIELDNAME TYPE FIELDNAME,
         END OF TY_DD03L.

  DATA: ITAB_DD03L TYPE STANDARD TABLE OF TY_DD03L.
  DATA: WA_DD03L TYPE TY_DD03L.

  DATA: L_WA_CONTENT1(30) TYPE C.                           "#EC NEEDED
  DATA: L_TABIX(2) TYPE C.

  DATA : xfc1 TYPE lvc_s_fcat,
         xfc  TYPE lvc_s_fcat,
         ifc1 TYPE lvc_t_fcat,
         dy_table5 TYPE REF TO data,
         dy_line5  TYPE REF TO data,
         dy_line6  TYPE REF TO data.

  FIELD-SYMBOLS :   %LTdyn_table2%GT TYPE STANDARD TABLE,
                    %LTdyn_table3%GT TYPE STANDARD TABLE,
                    %LTdyn_wa5%GT TYPE ANY,
                    %LTdyn_wa6%GT TYPE ANY.

  TYPES: BEGIN OF TY_FIELD,
           FIELD(30) TYPE C.
  TYPES: END OF TY_FIELD.

  CONSTANTS C_FINAL(20) TYPE C   VALUE 'L_WA_FINAL'.        "#EC *

  TYPES: BEGIN OF TY_COMP,
          COMP(30) TYPE C,
         END OF TY_COMP.

  TYPES: BEGIN OF TY_CHAR,
          CHAR(30) TYPE C,
         END OF TY_CHAR.

***************************************************************
*MOD-015
***************************************************************
  SELECT SINGLE DBTAB_NAME                                  "#EC *
  INTO L_TABNAME
  FROM CUVTAB
  WHERE VTNAM = wa_contentheader1-vtnam.

  CHECK SY-SUBRC = 0.
  clear: xfc1.
  refresh: ifc1.

  READ TABLE i_contenttab1 INTO wa_contenttab1 INDEX 1.
  IF sy-subrc IS INITIAL.
    xfc1-datatype = 'C'.
    xfc1-inttype = 'C'.
    xfc1-intlen = 30.

    IF not wa_contenttab1-char1 IS INITIAL.
      xfc1-fieldname = 'VTNAM'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 18.
*      xfc1-ref_table = wa_contentheader1-vtnam.
*      xfc1-ref_field = wa_contenttab1-char1.
    ELSE.
      xfc1-fieldname = 'VTNAM'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 18.
*      xfc-ref_table = wa_contentheader1-vtnam.
*      xfc-ref_field = wa_contenttab1-char1.

    ENDIF.
    APPEND xfc1 TO ifc1.
    Clear: xfc1.

    IF not wa_contenttab1-char1 IS INITIAL.
      xfc1-fieldname = 'CHAR1'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc1-ref_table = wa_contentheader1-vtnam.
*      xfc1-ref_field = wa_contenttab1-char1.
    ELSE.
      xfc1-fieldname = 'CHAR1'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc-ref_table = wa_contentheader1-vtnam.
*      xfc-ref_field = wa_contenttab1-char1.

    ENDIF.
    APPEND xfc1 TO ifc1.
    Clear: xfc1.

    IF not wa_contenttab1-char2 IS INITIAL.
      xfc1-fieldname = 'CHAR2'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc1-ref_table = wa_contentheader1-vtnam.
*      xfc1-ref_field = wa_contenttab1-char2.
    ELSE.
      xfc1-fieldname = 'CHAR2'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc-ref_table = wa_contentheader1-vtnam.
*      xfc-ref_field = wa_contenttab1-char2.

    ENDIF.
    APPEND xfc1 TO ifc1.
    Clear: xfc1.

    IF not wa_contenttab1-char3 IS INITIAL.
      xfc1-fieldname = 'CHAR3'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc1-ref_table = wa_contentheader1-vtnam.
*      xfc1-ref_field = wa_contenttab1-char3.
    ELSE.
      xfc1-fieldname = 'CHAR3'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc-ref_table = wa_contentheader1-vtnam.
*      xfc-ref_field = wa_contenttab1-char3.

    ENDIF.
    APPEND xfc1 TO ifc1.
    Clear: xfc1.

    IF not wa_contenttab1-char4 IS INITIAL.
      xfc1-fieldname = wa_contenttab1-char4.
      xfc1-datatype = 'CHAR4'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc1-ref_table = wa_contentheader1-vtnam.
*      xfc1-ref_field = wa_contenttab1-char4.

    ELSE.
      xfc1-fieldname = 'CHAR4'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc-ref_table = wa_contentheader1-vtnam.
*      xfc-ref_field = wa_contenttab1-char4.
    ENDIF.
    APPEND xfc1 TO ifc1.
    Clear: xfc1.

    IF not wa_contenttab1-char5 IS INITIAL.
      xfc1-fieldname = wa_contenttab1-char5.
      xfc1-datatype = 'CHAR5'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc1-ref_table = wa_contentheader1-vtnam.
*      xfc1-ref_field = wa_contenttab1-char5.*
    ELSE.
      xfc1-fieldname = 'CHAR5'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*     xfc-ref_table = wa_contentheader1-vtnam.
*     xfc-ref_field = wa_contenttab1-char5.
    ENDIF.

    APPEND xfc1 TO ifc1.
    Clear: xfc1.

    IF not wa_contenttab1-char6 IS INITIAL.
      xfc1-fieldname = 'CHAR6'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc1-ref_table = wa_contentheader1-vtnam.
*      xfc1-ref_field = wa_contenttab1-char6.

    ELSE.
      xfc1-fieldname = 'CHAR6'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc-ref_table = wa_contentheader1-vtnam.
*      xfc-ref_field = wa_contenttab1-char6.

    ENDIF.

    APPEND xfc1 TO ifc1.
    Clear: xfc1.

    IF not wa_contenttab1-char7 IS INITIAL.
      xfc1-fieldname = 'CHAR7'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc1-ref_table = wa_contentheader1-vtnam.
*      xfc1-ref_field = wa_contenttab1-char7.

    ELSE.
      xfc1-fieldname = 'CHAR7'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc-ref_table = wa_contentheader1-vtnam.
*      xfc-ref_field = wa_contenttab1-char7.

    ENDIF.

    APPEND xfc1 TO ifc1.
    Clear: xfc1.

    IF not wa_contenttab1-char8 IS INITIAL.
      xfc1-fieldname = 'CHAR8'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc1-ref_table = wa_contentheader1-vtnam.
*      xfc1-ref_field = wa_contenttab1-char8.
*
    ELSE.
      xfc1-fieldname = 'CHAR8'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc-ref_table = wa_contentheader1-vtnam.
*      xfc-ref_field = wa_contenttab1-char8.

    ENDIF.

    APPEND xfc1 TO ifc1.
    Clear: xfc1.

    IF not wa_contenttab1-char9 IS INITIAL.
      xfc1-fieldname = 'CHAR9'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc1-ref_table = wa_contentheader1-vtnam.
*      xfc1-ref_field = wa_contenttab1-char9.

    ELSE.
      xfc1-fieldname = 'CHAR9'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc-ref_table = wa_contentheader1-vtnam.
*      xfc-ref_field = wa_contenttab1-char9.

    ENDIF.

    APPEND xfc1 TO ifc1.
    Clear: xfc1.

    IF not wa_contenttab1-char10 IS INITIAL.
      xfc1-fieldname = 'CHAR10'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc1-ref_table = wa_contentheader1-vtnam.
*      xfc1-ref_field = wa_contenttab1-char10.

    ELSE.
      xfc1-fieldname = 'CHAR10'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc-ref_table = wa_contentheader1-vtnam.
*      xfc-ref_field = wa_contenttab1-char10.

    ENDIF.

    APPEND xfc1 TO ifc1.
    Clear: xfc1.

    IF not wa_contenttab1-char11 IS INITIAL.
      xfc1-fieldname = 'CHAR11'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc1-ref_table = wa_contentheader1-vtnam.
*      xfc1-ref_field = wa_contenttab1-char11.

    ELSE.
      xfc1-fieldname = 'CHAR11'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc-ref_table = wa_contentheader1-vtnam.
*      xfc-ref_field = wa_contenttab1-char11.
*

    ENDIF.

    APPEND xfc1 TO ifc1.
    clear: xfc1.

    IF not wa_contenttab1-char12 IS INITIAL.
      xfc1-fieldname = 'CHAR12'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc1-ref_table = wa_contentheader1-vtnam.
*      xfc1-ref_field = wa_contenttab1-char12.

    ELSE.
      xfc1-fieldname = 'CHAR12'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc-ref_table = wa_contentheader1-vtnam.
*      xfc-ref_field = wa_contenttab1-char12.

    ENDIF.

    APPEND xfc1 TO ifc1.
    clear: xfc1.

    IF not wa_contenttab1-char13 IS INITIAL.
      xfc1-fieldname = 'CHAR13'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc1-ref_table = wa_contentheader1-vtnam.
*      xfc1-ref_field = wa_contenttab1-char13.

    ELSE.
      xfc1-fieldname = 'CHAR13'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc-ref_table = wa_contentheader1-vtnam.
*      xfc-ref_field = wa_contenttab1-char13.

    ENDIF.

    APPEND xfc1 TO ifc1.
    Clear: xfc1.

    IF not wa_contenttab1-char14 IS INITIAL.
      xfc1-fieldname = 'CHAR14'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc1-ref_table = wa_contentheader1-vtnam.
*      xfc1-ref_field = wa_contenttab1-char14.

    ELSE.
      xfc1-fieldname = 'CHAR14'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc-ref_table = wa_contentheader1-vtnam.
*      xfc-ref_field = wa_contenttab1-char14.
*
    ENDIF.

    APPEND xfc1 TO ifc1.
    Clear: xfc1.

    IF not wa_contenttab1-char15 IS INITIAL.
      xfc1-fieldname = 'CHAR15'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc1-ref_table = wa_contentheader1-vtnam.
*      xfc1-ref_field = wa_contenttab1-char15.

    ELSE.
      xfc1-fieldname = 'CHAR15'.
      xfc1-datatype = 'CHAR'.
      xfc1-inttype = 'C'.
      xfc1-intlen = 30.
*      xfc-ref_table = wa_contentheader1-vtnam.
*      xfc-ref_field = wa_contenttab1-char15.

    ENDIF.
    APPEND xfc1 TO ifc1.
    Clear: xfc1.

  ENDIF.

  clear: dy_table5.
  UNASSIGN %LTdyn_table2%GT.
  UNASSIGN %LTdyn_table3%GT.
  UNASSIGN %LTdyn_wa5%GT.
  UNASSIGN %LTdyn_wa6%GT.


  CALL METHOD cl_alv_table_create=%GTcreate_dynamic_table
    EXPORTING
      it_fieldcatalog = ifc1
    IMPORTING
      ep_table        = dy_table5.

  ASSIGN dy_table5-%GT* TO %LTdyn_table2%GT.
  ASSIGN dy_table5-%GT* TO %LTdyn_table3%GT.

* Create dynamic work area and assign to FS
  CREATE DATA dy_line5 LIKE LINE OF %LTdyn_table2%GT.
  ASSIGN dy_line5-%GT* TO %LTdyn_wa5%GT.
  CHECK ( %LTdyn_wa5%GT IS ASSIGNED ).

* Create dynamic work area and assign to FS
  CREATE DATA dy_line6 LIKE LINE OF %LTdyn_table3%GT.
  ASSIGN dy_line6-%GT* TO %LTdyn_wa6%GT.
  CHECK ( %LTdyn_wa6%GT IS ASSIGNED ).

* DELETE i_contenttab1 INDEX 1.

*try to condense the fields and move all data.
  LOOP AT i_contenttab1 INTO wa_contenttab1.
    MOVE wa_contenttab1 TO %LTdyn_wa5%GT.
    APPEND %LTdyn_wa5%GT TO %LTdyn_table2%GT.
  ENDLOOP.

********************************************************
*MOD-012
********************************************************
*  go_sdescr ?= cl_abap_structdescr=%GTdescribe_by_name( l_tabname ).
*  gd_tabnam     = go_sdescr-%GTget_relative_name( ).
*
*  DO 5 TIMES.
*READ TABLE go_sdescr-%GTcomponents INTO gs_component INDEX syst-index.
*
*    CONCATENATE gd_tabnam gs_component-name INTO gd_tabfield
*                                            SEPARATED BY '-'.
*
*    CLEAR: gs_comp.
*    gs_comp-type ?= cl_abap_datadescr=%GTdescribe_by_name( gd_tabfield ).
*    gs_comp-name  = gs_component-name.
*    APPEND gs_comp TO gt_components.
*  ENDDO.

********************************************************
*MOD-012
********************************************************
  LOOP AT %LTdyn_table2%GT ASSIGNING %LTdyn_wa5%GT.
    MOVE-CORRESPONDING %LTdyn_wa5%GT TO wa_content.
    APPEND wa_content TO itab_content.
  ENDLOOP.
********************************************************
*MOD-012
********************************************************
  DATA: WA_DATATAB TYPE TY_DATA.
* DELETE GT_COMPONENTS INDEX 1.

  SELECT TABNAME FIELDNAME
  INTO TABLE ITAB_DD03L
  FROM DD03L
  WHERE TABNAME = L_TABNAME.

  CHECK SY-SUBRC = 0.

  DELETE ITAB_DD03L INDEX 1.

  LOOP AT I_CONTENTTAB3 INTO WA_CONTENTTAB3.
    MOVE-CORRESPONDING WA_CONTENTTAB3 TO WA_CONTENTTAB5.
    APPEND WA_CONTENTTAB5 TO I_CONTENTTAB5.
    CLEAR: WA_CONTENTTAB5.
  ENDLOOP.

  READ TABLE I_CONTENTTAB3 INTO WA_CONTENTTAB3 INDEX 1.
  IF SY-SUBRC = 0.
    APPEND WA_CONTENTTAB3 TO I_CONTENTTAB4.
    CLEAR WA_CONTENTTAB3.
  ENDIF.

  DELETE ITAB_CONTENT WHERE VTNAM IS INITIAL.

  LOOP AT I_CONTENTTAB5 INTO WA_CONTENTTAB5.

    READ TABLE I_CONTENTTAB4 INTO WA_CONTENTTAB4
    WITH KEY vtnam = WA_CONTENTTAB5-vtnam
             char1 = WA_CONTENTTAB5-char1.

    IF sy-subrc = 0.
      L_COMP1 = WA_CONTENTTAB4-CHAR1.
      WA_CONTENTTAB5-COMP1 = WA_CONTENTTAB4-CHAR1.
      MODIFY I_CONTENTTAB5 FROM WA_CONTENTTAB5 TRANSPORTING COMP1.
    ENDIF.

  ENDLOOP.

  LOOP AT I_CONTENTTAB5 INTO WA_CONTENTTAB5.

    READ TABLE I_CONTENTTAB4 INTO WA_CONTENTTAB4
    WITH KEY vtnam  = WA_CONTENTTAB5-vtnam
              char2 = WA_CONTENTTAB5-char2.
    IF sy-subrc = 0.
      L_COMP2 = WA_CONTENTTAB4-CHAR2.
      WA_CONTENTTAB5-COMP2 = WA_CONTENTTAB4-CHAR2.
      MODIFY I_CONTENTTAB5 FROM WA_CONTENTTAB5 TRANSPORTING COMP2.
    ENDIF.

  ENDLOOP.

  LOOP AT I_CONTENTTAB5 INTO WA_CONTENTTAB5.

    READ TABLE I_CONTENTTAB4 INTO WA_CONTENTTAB4
         WITH KEY vtnam  = WA_CONTENTTAB5-vtnam
             char3 = WA_CONTENTTAB5-char3.
    IF sy-subrc = 0.
      L_COMP3 = WA_CONTENTTAB4-CHAR3.
      WA_CONTENTTAB5-COMP3 = WA_CONTENTTAB4-CHAR3.
      MODIFY I_CONTENTTAB5 FROM WA_CONTENTTAB5 TRANSPORTING COMP3.
    ENDIF.
  ENDLOOP.


  LOOP AT I_CONTENTTAB5 INTO WA_CONTENTTAB5.

    READ TABLE I_CONTENTTAB4 INTO WA_CONTENTTAB4
    WITH KEY vtnam  = WA_CONTENTTAB5-vtnam
              char4 = WA_CONTENTTAB5-char4.
    IF sy-subrc = 0.
      L_COMP4 = WA_CONTENTTAB4-CHAR4.
      WA_CONTENTTAB5-COMP4 = WA_CONTENTTAB4-CHAR4.
      MODIFY I_CONTENTTAB5 FROM WA_CONTENTTAB5 TRANSPORTING COMP4.
    ENDIF.

  ENDLOOP.

  LOOP AT I_CONTENTTAB5 INTO WA_CONTENTTAB5.

    READ TABLE I_CONTENTTAB4 INTO WA_CONTENTTAB4
    WITH KEY vtnam  = WA_CONTENTTAB5-vtnam
              char5 = WA_CONTENTTAB5-char5.
    IF sy-subrc = 0.
      L_COMP5 = WA_CONTENTTAB4-CHAR5.
      WA_CONTENTTAB5-COMP5 = WA_CONTENTTAB4-CHAR5.
      MODIFY I_CONTENTTAB5 FROM WA_CONTENTTAB5 TRANSPORTING COMP5.
    ENDIF.

  ENDLOOP.

  LOOP AT I_CONTENTTAB5 INTO WA_CONTENTTAB5.

    READ TABLE I_CONTENTTAB4 INTO WA_CONTENTTAB4
    WITH KEY vtnam  = WA_CONTENTTAB5-vtnam
              char6 = WA_CONTENTTAB5-char6.
    IF sy-subrc = 0.
      L_COMP6 = WA_CONTENTTAB4-CHAR6.
      WA_CONTENTTAB5-COMP6 = WA_CONTENTTAB4-CHAR6.
      MODIFY I_CONTENTTAB5 FROM WA_CONTENTTAB5 TRANSPORTING COMP6.
    ENDIF.

  ENDLOOP.

  LOOP AT I_CONTENTTAB5 INTO WA_CONTENTTAB5.

    READ TABLE I_CONTENTTAB4 INTO WA_CONTENTTAB4
    WITH KEY vtnam  = WA_CONTENTTAB5-vtnam
              char7 = WA_CONTENTTAB5-char7.
    IF sy-subrc = 0.
      L_COMP7 = WA_CONTENTTAB4-CHAR7.
      WA_CONTENTTAB5-COMP7 = WA_CONTENTTAB4-CHAR7.
      MODIFY I_CONTENTTAB5 FROM WA_CONTENTTAB5 TRANSPORTING COMP7.
    ENDIF.

  ENDLOOP.

  LOOP AT I_CONTENTTAB5 INTO WA_CONTENTTAB5.

    READ TABLE I_CONTENTTAB4 INTO WA_CONTENTTAB4
    WITH KEY vtnam  = WA_CONTENTTAB5-vtnam
              char8 = WA_CONTENTTAB5-char8.
    IF sy-subrc = 0.
      L_COMP8 = WA_CONTENTTAB4-CHAR8.
      WA_CONTENTTAB5-COMP8 = WA_CONTENTTAB4-CHAR8.
      MODIFY I_CONTENTTAB5 FROM WA_CONTENTTAB5 TRANSPORTING COMP8.
    ENDIF.

  ENDLOOP.

  LOOP AT I_CONTENTTAB5 INTO WA_CONTENTTAB5.

    READ TABLE I_CONTENTTAB4 INTO WA_CONTENTTAB4
    WITH KEY vtnam  = WA_CONTENTTAB5-vtnam
              char9 = WA_CONTENTTAB5-char9.
    IF sy-subrc = 0.
      L_COMP9 = WA_CONTENTTAB4-CHAR9.
      WA_CONTENTTAB5-COMP9 = WA_CONTENTTAB4-CHAR9.
      MODIFY I_CONTENTTAB5 FROM WA_CONTENTTAB5 TRANSPORTING COMP9.
    ENDIF.

  ENDLOOP.

  LOOP AT I_CONTENTTAB5 INTO WA_CONTENTTAB5.

    READ TABLE I_CONTENTTAB4 INTO WA_CONTENTTAB4
     WITH KEY vtnam  = WA_CONTENTTAB5-vtnam
              char10 = WA_CONTENTTAB5-char10.
    IF sy-subrc = 0.
      L_COMP10 = WA_CONTENTTAB4-CHAR10.
      WA_CONTENTTAB5-COMP10 = WA_CONTENTTAB4-CHAR10.
      MODIFY I_CONTENTTAB5 FROM WA_CONTENTTAB5 TRANSPORTING COMP10.
    ENDIF.

  ENDLOOP.

  LOOP AT I_CONTENTTAB5 INTO WA_CONTENTTAB5.

    READ TABLE I_CONTENTTAB4 INTO WA_CONTENTTAB4
   WITH KEY vtnam  = WA_CONTENTTAB5-vtnam
             char11 = WA_CONTENTTAB5-char11.
    IF sy-subrc = 0.
      L_COMP11 = WA_CONTENTTAB4-CHAR11.
      WA_CONTENTTAB5-COMP11 = WA_CONTENTTAB4-CHAR11.
      MODIFY I_CONTENTTAB5 FROM WA_CONTENTTAB5 TRANSPORTING COMP11.
    ENDIF.

  ENDLOOP.

  LOOP AT I_CONTENTTAB5 INTO WA_CONTENTTAB5.

    READ TABLE I_CONTENTTAB4 INTO WA_CONTENTTAB4
   WITH KEY vtnam  = WA_CONTENTTAB5-vtnam
             char12 = WA_CONTENTTAB5-char12.
    IF sy-subrc = 0.
      L_COMP12 = WA_CONTENTTAB4-CHAR12.
      WA_CONTENTTAB5-COMP12 = WA_CONTENTTAB4-CHAR12.
      MODIFY I_CONTENTTAB5 FROM WA_CONTENTTAB5 TRANSPORTING COMP12.
    ENDIF.

  ENDLOOP.

  LOOP AT I_CONTENTTAB5 INTO WA_CONTENTTAB5.

    READ TABLE I_CONTENTTAB4 INTO WA_CONTENTTAB4
   WITH KEY vtnam  = WA_CONTENTTAB5-vtnam
             char13 = WA_CONTENTTAB5-char13.
    IF sy-subrc = 0.
      L_COMP13 = WA_CONTENTTAB4-CHAR13.
      WA_CONTENTTAB5-COMP13 = WA_CONTENTTAB4-CHAR13.
      MODIFY I_CONTENTTAB5 FROM WA_CONTENTTAB5 TRANSPORTING COMP13.
    ENDIF.

  ENDLOOP.


  LOOP AT I_CONTENTTAB5 INTO WA_CONTENTTAB5.

    READ TABLE I_CONTENTTAB4 INTO WA_CONTENTTAB4
   WITH KEY vtnam  = WA_CONTENTTAB5-vtnam
             char14 = WA_CONTENTTAB5-char14.
    IF sy-subrc = 0.
      L_COMP14 = WA_CONTENTTAB4-CHAR14.
      WA_CONTENTTAB5-COMP14 = WA_CONTENTTAB4-CHAR14.
      MODIFY I_CONTENTTAB5 FROM WA_CONTENTTAB5 TRANSPORTING COMP14.
    ENDIF.

  ENDLOOP.

  LOOP AT I_CONTENTTAB5 INTO WA_CONTENTTAB5.

    READ TABLE I_CONTENTTAB4 INTO WA_CONTENTTAB4
   WITH KEY vtnam  = WA_CONTENTTAB5-vtnam
             char15 = WA_CONTENTTAB5-char15.
    IF sy-subrc = 0.
      L_COMP15 = WA_CONTENTTAB4-CHAR15.
      WA_CONTENTTAB5-COMP15 = WA_CONTENTTAB4-CHAR15.
      MODIFY I_CONTENTTAB5 FROM WA_CONTENTTAB5 TRANSPORTING COMP15.
    ENDIF.

  ENDLOOP.

  LOOP AT I_CONTENTTAB5 INTO WA_CONTENTTAB5.
    WA_CONTENTTAB5-COMP1 = L_COMP1.
    WA_CONTENTTAB5-COMP2 = L_COMP2.
    WA_CONTENTTAB5-COMP3 = L_COMP3.
    WA_CONTENTTAB5-COMP4 = L_COMP4.
    WA_CONTENTTAB5-COMP5 = L_COMP5.
    WA_CONTENTTAB5-COMP6 = L_COMP6.
    WA_CONTENTTAB5-COMP7 = L_COMP7.
    WA_CONTENTTAB5-COMP8 = L_COMP8.
    WA_CONTENTTAB5-COMP9 = L_COMP9.
    WA_CONTENTTAB5-COMP10 = L_COMP10.
    WA_CONTENTTAB5-COMP11 = L_COMP11.
    WA_CONTENTTAB5-COMP12 = L_COMP12.
    WA_CONTENTTAB5-COMP13 = L_COMP13.
    WA_CONTENTTAB5-COMP14 = L_COMP14.
    WA_CONTENTTAB5-COMP15 = L_COMP15.

    MODIFY I_CONTENTTAB5 FROM WA_CONTENTTAB5 TRANSPORTING COMP1
                                                          COMP2
                                                          COMP3
                                                          COMP4
                                                          COMP5
                                                          COMP6
                                                          COMP7
                                                          COMP8
                                                          COMP9
                                                          COMP10
                                                          COMP11
                                                          COMP12
                                                          COMP13
                                                          COMP14
                                                          COMP15.

  ENDLOOP.

  DELETE I_CONTENTTAB5 INDEX 1.

  LOOP AT ITAB_DD03L INTO WA_DD03L.

    LOOP AT I_CONTENTTAB5 INTO WA_CONTENTTAB5
       WHERE VTNAM  = WA_DD03L-TABNAME AND
             COMP1  = WA_DD03L-FIELDNAME OR
             COMP2  = WA_DD03L-FIELDNAME OR
             COMP3  = WA_DD03L-FIELDNAME OR
             COMP4  = WA_DD03L-FIELDNAME OR
             COMP5  = WA_DD03L-FIELDNAME OR
             COMP6  = WA_DD03L-FIELDNAME OR
             COMP7  = WA_DD03L-FIELDNAME OR
             COMP8  = WA_DD03L-FIELDNAME OR
             COMP9  = WA_DD03L-FIELDNAME OR
             COMP10 = WA_DD03L-FIELDNAME OR
             COMP11 = WA_DD03L-FIELDNAME OR
             COMP12 = WA_DD03L-FIELDNAME OR
             COMP13 = WA_DD03L-FIELDNAME OR
             COMP14 = WA_DD03L-FIELDNAME OR
             COMP15 = WA_DD03L-FIELDNAME.

      CHECK SY-SUBRC = 0.
      L_TABIX = SY-TABIX.

      CONCATENATE 'CHAR' L_TABIX INTO L_WA_CONTENT1.

      l_value = WA_CONTENTTAB5-char1.
      l_value1 = WA_CONTENTTAB5-COMP1.
      ASSIGN WA_CONTENTTAB5-COMP1  to %LTfs_field%GT.
      ASSIGN l_value TO %LTfs_field1%GT.
      WA_DATATAB-NAME = l_value1.
      WA_DATATAB-VALUE = l_value.
      APPEND WA_DATATAB TO I_DATATAB.
      CLEAR:WA_DATATAB.

      l_value = WA_CONTENTTAB5-char2.
      l_value1 = WA_CONTENTTAB5-COMP2.
      ASSIGN WA_CONTENTTAB5-COMP2 to %LTfs_field%GT.
      ASSIGN l_value TO %LTfs_field1%GT.
      WA_DATATAB-NAME = l_value1.
      WA_DATATAB-VALUE = l_value.
      APPEND WA_DATATAB TO I_DATATAB.
      CLEAR:WA_DATATAB.

      l_value = WA_CONTENTTAB5-char3.
      l_value1 = WA_CONTENTTAB5-COMP3.
      ASSIGN WA_CONTENTTAB5-COMP3  to %LTfs_field%GT.
      ASSIGN l_value TO %LTfs_field1%GT.
      WA_DATATAB-NAME = l_value1.
      WA_DATATAB-VALUE = l_value.
      APPEND WA_DATATAB TO I_DATATAB.
      CLEAR:WA_DATATAB.

      l_value = WA_CONTENTTAB5-char4.
      l_value1 = WA_CONTENTTAB5-COMP4.
      ASSIGN WA_CONTENTTAB5-COMP3  to %LTfs_field%GT.
      ASSIGN l_value TO %LTfs_field1%GT.
      WA_DATATAB-NAME = l_value1.
      WA_DATATAB-VALUE = l_value.
      APPEND WA_DATATAB TO I_DATATAB.
      CLEAR:WA_DATATAB.

      l_value = WA_CONTENTTAB5-char5.
      l_value1 = WA_CONTENTTAB5-COMP5.
      ASSIGN WA_CONTENTTAB5-COMP3  to %LTfs_field%GT.
      ASSIGN l_value TO %LTfs_field1%GT.
      WA_DATATAB-NAME = l_value1.
      WA_DATATAB-VALUE = l_value.
      APPEND WA_DATATAB TO I_DATATAB.
      CLEAR:WA_DATATAB.

      l_value = WA_CONTENTTAB5-char6.
      l_value1 = WA_CONTENTTAB5-COMP6.
      ASSIGN WA_CONTENTTAB5-COMP3  to %LTfs_field%GT.
      ASSIGN l_value TO %LTfs_field1%GT.
      WA_DATATAB-NAME = l_value1.
      WA_DATATAB-VALUE = l_value.
      APPEND WA_DATATAB TO I_DATATAB.
      CLEAR:WA_DATATAB.

      l_value = WA_CONTENTTAB5-char7.
      l_value1 = WA_CONTENTTAB5-COMP7.
      ASSIGN WA_CONTENTTAB5-COMP3  to %LTfs_field%GT.
      ASSIGN l_value TO %LTfs_field1%GT.
      WA_DATATAB-NAME = l_value1.
      WA_DATATAB-VALUE = l_value.
      APPEND WA_DATATAB TO I_DATATAB.
      CLEAR:WA_DATATAB.

      l_value = WA_CONTENTTAB5-char8.
      l_value1 = WA_CONTENTTAB5-COMP8.
      ASSIGN WA_CONTENTTAB5-COMP3  to %LTfs_field%GT.
      ASSIGN l_value TO %LTfs_field1%GT.
      WA_DATATAB-NAME = l_value1.
      WA_DATATAB-VALUE = l_value.
      APPEND WA_DATATAB TO I_DATATAB.
      CLEAR:WA_DATATAB.

      l_value = WA_CONTENTTAB5-char9.
      l_value1 = WA_CONTENTTAB5-COMP9.
      ASSIGN WA_CONTENTTAB5-COMP3  to %LTfs_field%GT.
      ASSIGN l_value TO %LTfs_field1%GT.
      WA_DATATAB-NAME = l_value1.
      WA_DATATAB-VALUE = l_value.
      APPEND WA_DATATAB TO I_DATATAB.
      CLEAR:WA_DATATAB.

      l_value = WA_CONTENTTAB5-char10.
      l_value1 = WA_CONTENTTAB5-COMP10.
      ASSIGN WA_CONTENTTAB5-COMP3  to %LTfs_field%GT.
      ASSIGN l_value TO %LTfs_field1%GT.
      WA_DATATAB-NAME = l_value1.
      WA_DATATAB-VALUE = l_value.
      APPEND WA_DATATAB TO I_DATATAB.
      CLEAR:WA_DATATAB.

      l_value = WA_CONTENTTAB5-char11.
      l_value1 = WA_CONTENTTAB5-COMP11.
      ASSIGN WA_CONTENTTAB5-COMP3  to %LTfs_field%GT.
      ASSIGN l_value TO %LTfs_field1%GT.
      WA_DATATAB-NAME = l_value1.
      WA_DATATAB-VALUE = l_value.
      APPEND WA_DATATAB TO I_DATATAB.
      CLEAR:WA_DATATAB.

      l_value = WA_CONTENTTAB5-char12.
      l_value1 = WA_CONTENTTAB5-COMP12.
      ASSIGN WA_CONTENTTAB5-COMP3  to %LTfs_field%GT.
      ASSIGN l_value TO %LTfs_field1%GT.
      WA_DATATAB-NAME = l_value1.
      WA_DATATAB-VALUE = l_value.
      APPEND WA_DATATAB TO I_DATATAB.
      CLEAR:WA_DATATAB.

      l_value = WA_CONTENTTAB5-char13.
      l_value1 = WA_CONTENTTAB5-COMP13.
      ASSIGN WA_CONTENTTAB5-COMP3  to %LTfs_field%GT.
      ASSIGN l_value TO %LTfs_field1%GT.
      WA_DATATAB-NAME = l_value1.
      WA_DATATAB-VALUE = l_value.
      APPEND WA_DATATAB TO I_DATATAB.
      CLEAR:WA_DATATAB.

      l_value = WA_CONTENTTAB5-char14.
      l_value1 = WA_CONTENTTAB5-COMP14.
      ASSIGN WA_CONTENTTAB5-COMP3  to %LTfs_field%GT.
      ASSIGN l_value TO %LTfs_field1%GT.
      WA_DATATAB-NAME = l_value1.
      WA_DATATAB-VALUE = l_value.
      APPEND WA_DATATAB TO I_DATATAB.
      CLEAR:WA_DATATAB.

      l_value = WA_CONTENTTAB5-char15.
      l_value1 = WA_CONTENTTAB5-COMP15.
      ASSIGN WA_CONTENTTAB5-COMP3  to %LTfs_field%GT.
      ASSIGN l_value TO %LTfs_field1%GT.
      WA_DATATAB-NAME = l_value1.
      WA_DATATAB-VALUE = l_value.
      APPEND WA_DATATAB TO I_DATATAB.
      CLEAR:WA_DATATAB.

************************************************************************
********
**      ASSIGN COMPONENT GS_COMP-NAME OF STRUCTURE GS_COMP TO
*%LTfs_field%GT.
**      IF %LTfs_field%GT IS ASSIGNED.
**         ASSIGN COMPONENT L_WA_CONTENT1 OF STRUCTURE %LTdyn_wa5%GT TO
*%LTfs_field1%GT.
**         IF %LTfs_field1%GT IS ASSIGNED.
**            %LTfs_field%GT = %LTfs_field1%GT.
**         ENDIF.
**      ENDIF.
**      INSERT %LTdyn_wa%GT INTO TABLE %LTdyn_table%GT.
************************************************************************
********
    ENDLOOP.
  ENDLOOP.

************************************************************************
**
*MOD-012
************************************************************************
**
* Creating the Internal table with the structure of the
* current table.

  SELECT *
      FROM (l_tabname)
      INTO TABLE %LTdyn_table1%GT.

  sort %LTdyn_table1%GT.
  sort i_contenttab1.
* DELETE I_CONTENTTAB1 WHERE CHAR1 IS INITIAL.
  describe table %LTdyn_table1%GT lines l_lines1.

*  if l_lines1 %GT 0.
*    loop at i_contenttab1 into wa_contenttab1.
*      LOOP AT %LTdyn_table1%GT ASSIGNING %LTdyn_wa1%GT.
*        l_index1 = 2.
*
*assign component l_index1 of structure wa_contenttab1 to %LTfs_field2%GT.
*assign component l_index1 of structure %LTdyn_wa1%GT to %LTfs_field3%GT.
*        if  %LTfs_field3%GT = %LTfs_field2%GT.
*          clear: %LTdyn_wa1%GT.
*          wa_contenttab1-flag = c_x.
*          MODIFY i_contenttab1 FROM wa_contenttab1 TRANSPORTING flag.
*        endif.
*        UNASSIGN %LTfs_field2%GT.
*        UNASSIGN %LTfs_field3%GT.
*        l_index1 = l_index1 + 1.
*      endloop.
*    endloop.
*  endif.
*  clear:  l_index1.
*
************************************************************************
********************************
*MOD-015
************************************************************************
********************************

*  if l_lines1 %GT 0.
*    loop at i_contenttab1 into wa_contenttab1.
*      LOOP AT %LTdyn_table1%GT ASSIGNING %LTdyn_wa1%GT.
*
*read table i_contenttab3 into wa_contenttab3 with key vtnam =
*wa_contenttab1-vtnam binary search.
*        if sy-subrc = 0.
*READ TABLE i_col_pos INTO wa_col_pos with key vtnam =
*wa_contenttab1-vtnam
*atnam = wa_contenttab3-char1 binary search.
*
*          if sy-subrc = 0.
*READ TABLE I_CUVTAB_FLD INTO WA_CUVTAB_FLD WITH KEY VTINT =
*WA_COL_POS-VTINT
*ATINN = WA_COL_POS-ATINN
*VTPOS = WA_COL_POS-VTPOS BINARY SEARCH.
*
*            if sy-subrc = 0.
*              l_index1 = wa_col_pos-field + 1.
*              l_dbfld  = wa_cuvtab_fld-dbfld.
*assign component l_index1 of structure wa_contenttab1 to %LTfs_field2%GT.
*assign component l_dbfld of structure %LTdyn_wa%GT to %LTfs_field3%GT.
*              %LTfs_field3%GT = %LTfs_field2%GT.
*            endif.
*          endif.
*        endif.
*      endloop.
*    endif.
************************************************************************
********************************
*MOD-015
************************************************************************
********************************

  DELETE i_contenttab1 WHERE flag = c_x.

  SORT I_CONTENTTAB1.
  DELETE ADJACENT DUPLICATES FROM i_contenttab1.
* DELETE I_CONTENTTAB1 WHERE CHAR1 IS INITIAL.

************************************************************************
**
*MOD-012
************************************************************************
**
* UNASSIGN %LTdyn_table%GT.
************************************************************************
***
**MOD-012
************************************************************************
***
*  describe table itab_dd03l lines l_lines.
*  loop at i_contenttab1 into wa_contenttab1.
*    l_index1 = 2.
*    do l_lines times.
*assign component l_index1 of structure wa_contenttab1 to %LTfs_field2%GT.
*      assign component l_index1 of structure %LTdyn_wa%GT to %LTfs_field3%GT.
*      %LTfs_field3%GT = %LTfs_field2%GT.
*      l_index1 = l_index1 + 1.
*    enddo.
*    append %LTdyn_wa%GT to %LTdyn_table%GT.
*  endloop.

************************************************************************
****
***MOD-012
************************************************************************
******
*  describe table itab_dd03l lines l_lines.
*  l_lines_varcond = l_lines + 1.
*  loop at i_contenttab1 into wa_contenttab1.
*    l_index1 = 2.
*    do l_lines times.
*assign component l_index1 of structure wa_contenttab1 to %LTfs_field2%GT.
*      assign component l_index1 of structure %LTdyn_wa%GT to %LTfs_field3%GT.
*      %LTfs_field3%GT = %LTfs_field2%GT.
*      l_index1 = l_index1 + 1.
*    enddo.
*    UNASSIGN %LTfs_field2%GT.
*    UNASSIGN %LTfs_field3%GT.
*assign component 'Z_VARCOND' of structure wa_contenttab1 to
*%LTfs_field2%GT.
*assign component l_lines_varcond of structure %LTdyn_wa%GT to %LTfs_field3%GT.
*    %LTfs_field3%GT = %LTfs_field2%GT.
*    append %LTdyn_wa%GT to %LTdyn_table%GT.
*  endloop.
************************************************************************
**
***MOD-016
************************************************************************
***
*  loop at i_contenttab1 into wa_contenttab1
*       where vtnam = wa_contentheader1-vtnam.
*
*    read table i_file into wa_file
*    with key vtnam = wa_contentheader1-vtnam
*          char1 = wa_contenttab1-char1
*          char2 = wa_contenttab1-char2
*          char3 = wa_contenttab1-char3
*          char4 = wa_contenttab1-char4
*          char5 = wa_contenttab1-char5
*          char6 = wa_contenttab1-char6
*          char7 = wa_contenttab1-char7
*          char8 = wa_contenttab1-char8
*          char9 = wa_contenttab1-char9
*          char10 = wa_contenttab1-char10
*          char11 = wa_contenttab1-char11
*          char12 = wa_contenttab1-char12
*          char13 = wa_contenttab1-char13
*          char14 = wa_contenttab1-char14
*          char15 = wa_contenttab1-char15
*                                         .
*    if sy-subrc = 0.
*      wa_contenttab1-flag = c_x.
*      modify i_contenttab1 from wa_contenttab1 transporting flag.
*    endif.
*  endloop.
*
*  delete i_contenttab1 where flag = c_x.
************************************************************************
****
***MOD-016
************************************************************************
*****

  data: l_dbfld type NAME_FELD.

  describe table itab_dd03l lines l_lines.
  loop at i_contenttab1 into wa_contenttab1 where vtnam =
  wa_contentheader1-vtnam.
*read table i_contenttab3 into wa_contenttab3 with key vtnam =
*wa_contenttab1-vtnam binary search.
    read table i_contenttab3 into wa_contenttab3 index 1.
    if sy-subrc = 0.
      READ TABLE i_col_pos INTO wa_col_pos
        with key vtnam = wa_contenttab1-vtnam
                 atnam = wa_contenttab3-char1.
*                         . " binary search.

      if sy-subrc = 0.
        READ TABLE I_CUVTAB_FLD INTO WA_CUVTAB_FLD
            WITH KEY VTINT = WA_COL_POS-VTINT
                     ATINN = WA_COL_POS-ATINN
                     VTPOS = WA_COL_POS-VTPOS BINARY SEARCH.

        if sy-subrc = 0.
          l_index1 = wa_col_pos-field + 1.
*         l_index1 = wa_col_pos-field.
          l_dbfld  = wa_cuvtab_fld-dbfld.
          assign component l_index1 of structure wa_contenttab1 to
          %LTfs_field2%GT.
          assign component l_dbfld of structure %LTdyn_wa%GT to %LTfs_field3%GT.
          %LTfs_field3%GT = %LTfs_field2%GT.
        endif.
      endif.

************************************************************************
****
***MOD-015
************************************************************************
****

      READ TABLE i_col_pos INTO wa_col_pos with key vtnam =
      wa_contenttab1-vtnam
                                                    atnam =
                                                    wa_contenttab3-char2
                                                    . " binary search.

      if sy-subrc = 0.
        READ TABLE I_CUVTAB_FLD INTO WA_CUVTAB_FLD WITH KEY VTINT =
        WA_COL_POS-VTINT
                                                            ATINN =
WA_COL_POS-ATINN
                                                            VTPOS =
WA_COL_POS-VTPOS BINARY SEARCH.

        if sy-subrc = 0.
          l_index1 = wa_col_pos-field + 1.
*         l_index1 = wa_col_pos-field.

          l_dbfld  = wa_cuvtab_fld-dbfld.
          assign component l_index1 of structure wa_contenttab1 to
          %LTfs_field2%GT.
          assign component l_dbfld of structure %LTdyn_wa%GT to %LTfs_field3%GT.
          %LTfs_field3%GT = %LTfs_field2%GT.
        endif.
      endif.

      READ TABLE i_col_pos INTO wa_col_pos with key vtnam =
      wa_contenttab1-vtnam
                                                    atnam =
                                                    wa_contenttab3-char3
                                                    . " binary search.

      if sy-subrc = 0.
        READ TABLE I_CUVTAB_FLD INTO WA_CUVTAB_FLD WITH KEY VTINT =
        WA_COL_POS-VTINT
                                                            ATINN =
WA_COL_POS-ATINN
                                                            VTPOS =
WA_COL_POS-VTPOS BINARY SEARCH.

        if sy-subrc = 0.
          l_index1 = wa_col_pos-field + 1.
*        l_index1 = wa_col_pos-field.

          l_dbfld  = wa_cuvtab_fld-dbfld.
          assign component l_index1 of structure wa_contenttab1 to
          %LTfs_field2%GT.
          assign component l_dbfld of structure %LTdyn_wa%GT to %LTfs_field3%GT.
          %LTfs_field3%GT = %LTfs_field2%GT.
        endif.
      endif.

      .

      READ TABLE i_col_pos INTO wa_col_pos with key vtnam =
      wa_contenttab1-vtnam
                                                     atnam =
wa_contenttab3-char4. " binary search.

      if sy-subrc = 0.
        READ TABLE I_CUVTAB_FLD INTO WA_CUVTAB_FLD WITH KEY VTINT =
        WA_COL_POS-VTINT
                                                            ATINN =
WA_COL_POS-ATINN
                                                            VTPOS =
WA_COL_POS-VTPOS BINARY SEARCH.

        if sy-subrc = 0.
          l_index1 = wa_col_pos-field + 1.
*         l_index1 = wa_col_pos-field.

          l_dbfld  = wa_cuvtab_fld-dbfld.
          assign component l_index1 of structure wa_contenttab1 to
          %LTfs_field2%GT.
          assign component l_dbfld of structure %LTdyn_wa%GT to %LTfs_field3%GT.
          %LTfs_field3%GT = %LTfs_field2%GT.
        endif.
      endif.

      READ TABLE i_col_pos INTO wa_col_pos with key vtnam =
      wa_contenttab1-vtnam
                                                     atnam =
wa_contenttab3-char5. " binary search.

      if sy-subrc = 0.
        READ TABLE I_CUVTAB_FLD INTO WA_CUVTAB_FLD WITH KEY VTINT =
        WA_COL_POS-VTINT
                                                            ATINN =
WA_COL_POS-ATINN
                                                            VTPOS =
WA_COL_POS-VTPOS BINARY SEARCH.

        if sy-subrc = 0.
          l_index1 = wa_col_pos-field + 1.
*         l_index1 = wa_col_pos-field.

          l_dbfld  = wa_cuvtab_fld-dbfld.
          assign component l_index1 of structure wa_contenttab1 to
          %LTfs_field2%GT.
          assign component l_dbfld of structure %LTdyn_wa%GT to %LTfs_field3%GT.
          %LTfs_field3%GT = %LTfs_field2%GT.
        endif.
      endif.

      READ TABLE i_col_pos INTO wa_col_pos with key vtnam =
      wa_contenttab1-vtnam
                                                    atnam =
                                                    wa_contenttab3-char6
                                                    . " binary search.

      if sy-subrc = 0.
        READ TABLE I_CUVTAB_FLD INTO WA_CUVTAB_FLD WITH KEY VTINT =
        WA_COL_POS-VTINT
                                                            ATINN =
WA_COL_POS-ATINN
                                                            VTPOS =
WA_COL_POS-VTPOS BINARY SEARCH.

        if sy-subrc = 0.
          l_index1 = wa_col_pos-field + 1.
*         l_index1 = wa_col_pos-field.

          l_dbfld  = wa_cuvtab_fld-dbfld.
          assign component l_index1 of structure wa_contenttab1 to
          %LTfs_field2%GT.
          assign component l_dbfld of structure %LTdyn_wa%GT to %LTfs_field3%GT.
          %LTfs_field3%GT = %LTfs_field2%GT.
        endif.
      endif.

      READ TABLE i_col_pos INTO wa_col_pos with key vtnam =
      wa_contenttab1-vtnam
                                                    atnam =
                                                    wa_contenttab3-char7
                                                    . " binary search.

      if sy-subrc = 0.
        READ TABLE I_CUVTAB_FLD INTO WA_CUVTAB_FLD WITH KEY VTINT =
        WA_COL_POS-VTINT
                                                            ATINN =
WA_COL_POS-ATINN
                                                            VTPOS =
WA_COL_POS-VTPOS BINARY SEARCH.

        if sy-subrc = 0.
          l_index1 = wa_col_pos-field + 1.
*         l_index1 = wa_col_pos-field.

          l_dbfld  = wa_cuvtab_fld-dbfld.
          assign component l_index1 of structure wa_contenttab1 to
          %LTfs_field2%GT.
          assign component l_dbfld of structure %LTdyn_wa%GT to %LTfs_field3%GT.
          %LTfs_field3%GT = %LTfs_field2%GT.
        endif.
      endif.

      READ TABLE i_col_pos INTO wa_col_pos with key vtnam =
      wa_contenttab1-vtnam
                                                    atnam =
                                                    wa_contenttab3-char8
                                                    . "binary search.

      if sy-subrc = 0.
        READ TABLE I_CUVTAB_FLD INTO WA_CUVTAB_FLD WITH KEY VTINT =
        WA_COL_POS-VTINT
                                                            ATINN =
WA_COL_POS-ATINN
                                                            VTPOS =
WA_COL_POS-VTPOS BINARY SEARCH.

        if sy-subrc = 0.
          l_index1 = wa_col_pos-field + 1.
*         l_index1 = wa_col_pos-field.

          l_dbfld  = wa_cuvtab_fld-dbfld.
          assign component l_index1 of structure wa_contenttab1 to
          %LTfs_field2%GT.
          assign component l_dbfld of structure %LTdyn_wa%GT to %LTfs_field3%GT.
          %LTfs_field3%GT = %LTfs_field2%GT.
        endif.
      endif.

      READ TABLE i_col_pos INTO wa_col_pos with key vtnam =
      wa_contenttab1-vtnam
                                                    atnam =
                                                    wa_contenttab3-char9
                                                    . " binary search.

      if sy-subrc = 0.
        READ TABLE I_CUVTAB_FLD INTO WA_CUVTAB_FLD WITH KEY VTINT =
        WA_COL_POS-VTINT
                                                            ATINN =
WA_COL_POS-ATINN
                                                            VTPOS =
WA_COL_POS-VTPOS BINARY SEARCH.

        if sy-subrc = 0.
          l_index1 = wa_col_pos-field + 1.
*         l_index1 = wa_col_pos-field.
          l_dbfld  = wa_cuvtab_fld-dbfld.
          assign component l_index1 of structure wa_contenttab1 to
          %LTfs_field2%GT.
          assign component l_dbfld of structure %LTdyn_wa%GT to %LTfs_field3%GT.
          %LTfs_field3%GT = %LTfs_field2%GT.
        endif.
      endif.

      READ TABLE i_col_pos INTO wa_col_pos with key vtnam =
      wa_contenttab1-vtnam
                                                    atnam =
wa_contenttab3-char10. " binary search.

      if sy-subrc = 0.
        READ TABLE I_CUVTAB_FLD INTO WA_CUVTAB_FLD WITH KEY VTINT =
        WA_COL_POS-VTINT
                                                            ATINN =
WA_COL_POS-ATINN
                                                            VTPOS =
WA_COL_POS-VTPOS BINARY SEARCH.

        if sy-subrc = 0.
          l_index1 = wa_col_pos-field + 1.
*         l_index1 = wa_col_pos-field.

          l_dbfld  = wa_cuvtab_fld-dbfld.
          assign component l_index1 of structure wa_contenttab1 to
          %LTfs_field2%GT.
          assign component l_dbfld of structure %LTdyn_wa%GT to %LTfs_field3%GT.
          %LTfs_field3%GT = %LTfs_field2%GT.
        endif.
      endif.

      READ TABLE i_col_pos INTO wa_col_pos with key vtnam =
      wa_contenttab1-vtnam
                                                    atnam =
wa_contenttab3-char11. " binary search.

      if sy-subrc = 0.
        READ TABLE I_CUVTAB_FLD INTO WA_CUVTAB_FLD WITH KEY VTINT =
        WA_COL_POS-VTINT
                                                            ATINN =
WA_COL_POS-ATINN
                                                            VTPOS =
WA_COL_POS-VTPOS BINARY SEARCH.

        if sy-subrc = 0.
          l_index1 = wa_col_pos-field + 1.
*         l_index1 = wa_col_pos-field.

          l_dbfld  = wa_cuvtab_fld-dbfld.
          assign component l_index1 of structure wa_contenttab1 to
          %LTfs_field2%GT.
          assign component l_dbfld of structure %LTdyn_wa%GT to %LTfs_field3%GT.
          %LTfs_field3%GT = %LTfs_field2%GT.
        endif.
      endif.

      .

      READ TABLE i_col_pos INTO wa_col_pos with key vtnam =
      wa_contenttab1-vtnam
                                                    atnam =
wa_contenttab3-char12. " binary search.

      if sy-subrc = 0.
        READ TABLE I_CUVTAB_FLD INTO WA_CUVTAB_FLD WITH KEY VTINT =
        WA_COL_POS-VTINT
                                                            ATINN =
WA_COL_POS-ATINN
                                                            VTPOS =
WA_COL_POS-VTPOS BINARY SEARCH.

        if sy-subrc = 0.
          l_index1 = wa_col_pos-field + 1.
*         l_index1 = wa_col_pos-field.

          l_dbfld  = wa_cuvtab_fld-dbfld.
          assign component l_index1 of structure wa_contenttab1 to
          %LTfs_field2%GT.
          assign component l_dbfld of structure %LTdyn_wa%GT to %LTfs_field3%GT.
          %LTfs_field3%GT = %LTfs_field2%GT.
        endif.
      endif.

      READ TABLE i_col_pos INTO wa_col_pos with key vtnam =
      wa_contenttab1-vtnam
                                                    atnam =
wa_contenttab3-char13. " binary search.

      if sy-subrc = 0.
        READ TABLE I_CUVTAB_FLD INTO WA_CUVTAB_FLD WITH KEY VTINT =
        WA_COL_POS-VTINT
                                                            ATINN =
WA_COL_POS-ATINN
                                                            VTPOS =
WA_COL_POS-VTPOS BINARY SEARCH.

        if sy-subrc = 0.
          l_index1 = wa_col_pos-field + 1.
*         l_index1 = wa_col_pos-field.
          l_dbfld  = wa_cuvtab_fld-dbfld.
          assign component l_index1 of structure wa_contenttab1 to
          %LTfs_field2%GT.
          assign component l_dbfld of structure %LTdyn_wa%GT to %LTfs_field3%GT.
          %LTfs_field3%GT = %LTfs_field2%GT.
        endif.
      endif.


      READ TABLE i_col_pos INTO wa_col_pos with key vtnam =
      wa_contenttab1-vtnam
                                                    atnam =
wa_contenttab3-char14. " binary search.

      if sy-subrc = 0.
        READ TABLE I_CUVTAB_FLD INTO WA_CUVTAB_FLD WITH KEY VTINT =
        WA_COL_POS-VTINT
                                                            ATINN =
WA_COL_POS-ATINN
                                                            VTPOS =
WA_COL_POS-VTPOS BINARY SEARCH.

        if sy-subrc = 0.
          l_index1 = wa_col_pos-field + 1.
*         l_index1 = wa_col_pos-field.
          l_dbfld  = wa_cuvtab_fld-dbfld.
          assign component l_index1 of structure wa_contenttab1 to
          %LTfs_field2%GT.
          assign component l_dbfld of structure %LTdyn_wa%GT to %LTfs_field3%GT.
          %LTfs_field3%GT = %LTfs_field2%GT.
        endif.
      endif.

      READ TABLE i_col_pos INTO wa_col_pos with key vtnam =
      wa_contenttab1-vtnam
                                                    atnam =
wa_contenttab3-char15. " binary search.

      if sy-subrc = 0.
        READ TABLE I_CUVTAB_FLD INTO WA_CUVTAB_FLD WITH KEY VTINT =
        WA_COL_POS-VTINT
                                                            ATINN =
WA_COL_POS-ATINN
                                                            VTPOS =
WA_COL_POS-VTPOS BINARY SEARCH.

        if sy-subrc = 0.
          l_index1 = wa_col_pos-field + 1.
          l_dbfld  = wa_cuvtab_fld-dbfld.
          assign component l_index1 of structure wa_contenttab1 to
          %LTfs_field2%GT.
          assign component l_dbfld of structure %LTdyn_wa%GT to %LTfs_field3%GT.
          %LTfs_field3%GT = %LTfs_field2%GT.
        endif.
      endif.

      Data: l_lines1 type i.

      Describe table i_col_pos lines l_lines1.

      READ TABLE i_col_pos INTO wa_col_pos index l_lines1.

      if sy-subrc = 0.
        READ TABLE I_CUVTAB_FLD INTO WA_CUVTAB_FLD WITH KEY VTINT =
        WA_COL_POS-VTINT
                                                            ATINN =
WA_COL_POS-ATINN
                                                            VTPOS =
WA_COL_POS-VTPOS BINARY SEARCH.

        if sy-subrc = 0.
          l_index1 = wa_col_pos-field.
          l_dbfld  = wa_cuvtab_fld-dbfld.
          assign component 'Z_VARCOND' of structure wa_contenttab1 to
          %LTfs_field2%GT.
*assign component l_index1 of structure wa_contenttab1 to %LTfs_field2%GT.
          assign component l_dbfld of structure %LTdyn_wa%GT to %LTfs_field3%GT.
          %LTfs_field3%GT = %LTfs_field2%GT.
        endif.
        append %LTdyn_wa%GT to %LTdyn_table%GT.
      endif.

    endif.

  endloop.

*******************************************************************
*MOD-015
*********************************************************************
* SORT %LTdyn_table%GT.

********************************************************************
**MOD-015
*********************************************************************

*    IF I_CONTENTTAB1 IS INITIAL.
*      UNASSIGN %LTdyn_table%GT.
*    ENDIF.

  IF %LTdyn_table%GT IS ASSIGNED.
*     INSERT (l_tabname) FROM TABLE %LTdyn_table%GT.
    MODIFY (l_tabname) FROM TABLE %LTdyn_table%GT.
  ENDIF.
  UNASSIGN %LTdyn_table%GT.
************************************************************************
***
*MOD-015
************************************************************************
***
  Message i261 with l_tabname.
************************************************************************
******
*MOD-015
************************************************************************
******
  DELETE I_CONTENTTAB1 WHERE VTNAM = WA_CONTENTHEADER1-VTNAM.
************************************************************************
******
*MOD-015
************************************************************************
******

* leave list-processing.

************************************************************************
**********
*MOD-015
************************************************************************
**********
** Append last line for brand name subtotal
*  IF %LTFS_DYN_WA_BNAME%GT IS NOT INITIAL.
*    CONCATENATE LC_TOTAL %LTFS_DYN_WA_BNAME%GT+30(LC_BRANDNAME_LEN)
*       INTO %LTFS_DYN_WA_BNAME%GT+70(40) SEPARATED BY SPACE.
**  %LTDYN_WA1%GT+4(4) = %LTDYN_WA1%GT+LV_OFFSET1(4).
*    APPEND %LTFS_DYN_WA_BNAME%GT TO %LTFS_DYN_TABLE%GT.
*  ENDIF.
*
********************************************************
*MOD-012
********************************************************
*  LOOP AT %LTdyn_table2%GT ASSIGNING %LTdyn_wa5%GT.
*    MOVE-CORRESPONDING %LTdyn_wa5%GT TO wa_content.
*    APPEND wa_content TO itab_content.
*  ENDLOOP.
********************************************************
*MOD-012
********************************************************

*  LOOP AT ITAB_CONTENT INTO WA_CONTENT.
*    L_TABIX = SY-TABIX.
*    LOOP AT GT_COMPONENTS INTO GS_COMP.
*CONCATENATE 'L_WA_FINAL' GS_COMP-NAME INTO L_WA_FINAL SEPARATED BY '-'.
*      CONCATENATE 'L_WA_CONTENT-CHAR' L_TABIX INTO L_WA_CONTENT1.
*      ASSIGN L_WA_FINAL TO %LTWA_FINAL%GT.
*      %LTdyn_wa%GT = %LTWA_FINAL%GT.
*      INSERT %LTdyn_wa%GT INTO TABLE %LTdyn_table%GT.
*      UNASSIGN %LTWA_FINAL%GT.
*      UNASSIGN %LTdyn_wa%GT.
*      ASSIGN L_WA_CONTENT1 TO %LTWA_FINAL%GT.
*      %LTdyn_wa%GT = %LTWA_FINAL%GT.
*      INSERT %LTdyn_wa%GT INTO TABLE %LTdyn_table%GT.
*      UNASSIGN %LTWA_FINAL%GT.
*      UNASSIGN %LTdyn_wa%GT.
*    ENDLOOP.
*  ENDLOOP.

*  IF NOT %LTitab_final%GT IS INITIAL.
*    INSERT (l_tabname) FROM TABLE %LTitab_final%GT.
*  ENDIF.

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


endform.                    "get_data
**&---------------------------------------------------------------------
**
**&---------------------------------------------------------------------
**
*&---------------------------------------------------------------------*

*Text elements
*----------------------------------------------------------
* 013 Following tables have incorrect characteristic names
* 014 VTNAM
* 015 Characteristic name
* 017 Variant table
* 018 Fieldname
* 019 Characteristic name
* 020 Characteristic value
* 021 Row no


*Selection texts
*----------------------------------------------------------
* P_INPT         Presentation Server  File Hdr
* P_INPT1         Presentation Server  File Dtl
* P_PACKGE         Package
* P_TRFCPT         TRFC Port
* RB_APSRV         Application Server
* RB_CONVT          Convert Data
* RB_IDOC         Create Idocs


*Messages
*----------------------------------------------------------
*
* Message class: ZDEV
*088   Invalid Logical System
*164
*196   Please enter a File Name
*197   Please enter a Physical filename.
*237   Unabe to Access the Application Server File
*241   Unable to look up the File in the Folder.
*242
*243
*246
*257   File Loaded to Application Server.
*260   File has been processed and data has been converted.
*261   File has been processed and data uploaded to custom table &.



*&---------------------------------------------------------------------*
*&      Form  SUB_APP_LOG_INIT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      %LT--P_V_LOG_HANDLE  text
*----------------------------------------------------------------------*
 Form  SUB_APP_LOG_INIT CHANGING fp_log_handle TYPE balloghndl.

   DATA: l_s_log TYPE bal_s_log.                            "#EC NEEDED


   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 %LT%GT 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.                        "#EC NEEDED

* 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 %LT%GT 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
*----------------------------------------------------------------------*
* --%GT  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 %LT%GT 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
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  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 %LT%GT 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_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_APPLICATION_LOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --%GT  p1        text
*  %LT--  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 %LT%GT 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 %LT%GT 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 %LT%GT 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 %LT%GT 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 %LT%GT 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


*Selection texts
*----------------------------------------------------------
* P_INPT         File Header
* P_INPT1         File Detail
* P_PACKGE         Package
* P_TRFCPT         TRFC Port
* RB_APSRV         Application Server
* RB_CONVT         Convert Data
* RB_IDOC         Generate Idocs..


*Messages
*----------------------------------------------------------
*
* Message class: ZDEV
*088
*164
*196
*197
*237
*241
*242
*243
*246
*257
*260
*261
  • No labels