Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

upload data into ztable from text file

Former Member
0 Likes
2,790

I have a requirement where i have to create one table in se11.

and i have to upload data into tht table from the text file provided.

can u tell me how to do this?

Thanks in advance

points will be awarded.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,477

Hi Pavan,

Check this link it might be useful.

Regards,

Nisrin.

I have a requirement where i have to create one table in se11.

and i have to upload data into tht table from the text file provided.

can u tell me how to do this?

Thanks in advance

points will be awarded.

7 REPLIES 7
Read only

Former Member
0 Likes
1,477

write a small program to upload entries into an internal table

and insert into the table U've created ..

Read only

Former Member
0 Likes
1,477

Hi Pavan,

This code will help you.

DATA:
   BEGIN OF wa_input,
     kunnr TYPE kna1-kunnr,
   END OF wa_input.

DATA:
  i_input       LIKE STANDARD TABLE OF wa_input.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_input .
*"Subroutine Call to get file selection
  PERFORM f005_getfile_input CHANGING p_input.

*&---------------------------------------------------------------------*
*&      Form  f205_get_input
*&---------------------------------------------------------------------*
*       To get the input data from file
*----------------------------------------------------------------------*
*  There are no interface parameters to be passed to this subroutine.  *
*----------------------------------------------------------------------*
FORM f205_get_input .
  DATA: lw_filename TYPE string .

  lw_filename = p_input.
  w_filename = 'customers'.
  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                = lw_filename
      filetype                = 'ASC'
    TABLES
      data_tab                = i_input
    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.
  IF sy-subrc NE 0.
    MESSAGE i073(cms) WITH w_filename sy-subrc.
    MOVE c_x TO w_error.
    EXIT.
  ENDIF.                               " IF sy-subrc NE 0.

Regards,

Sandeep

Edited by: Sandeep patel on Jul 23, 2008 2:50 PM

Read only

GauthamV
Active Contributor
0 Likes
1,477

hi,

first create a table in se11.

now do table maintainance generator for that table.

using lsmw now upload 1 record using table maintaneance generator and record that.

now create a text file and upload the data.

Read only

Former Member
0 Likes
1,477

Pavan,

see this code:



REPORT yfbigl10 MESSAGE-ID yf.
INCLUDE yfbi0200_top.


TYPE-POOLS: slis.

PARAMETERS:
  client        LIKE sy-mandt      DEFAULT sy-mandt NO-DISPLAY .

SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME TITLE text-001.
PARAMETERS:
  infile        LIKE rlgrap-filename DEFAULT 'C:\',
  filetype(1)   TYPE c DEFAULT 'P',
  outfile(60)   TYPE c DEFAULT '/usr/sap/trans/wwi_temp' LOWER CASE,
  budat         LIKE bkpf-budat   OBLIGATORY.


SELECTION-SCREEN END OF BLOCK a.

SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-002.
PARAMETERS:
    test         AS CHECKBOX DEFAULT ' ' ,
    group        LIKE bgr00-group   DEFAULT 'WWI-UPLOAD',
    zkeep        AS CHECKBOX DEFAULT 'X' ,
    bdc_nr       TYPE p           DEFAULT '500'      ,
    acc1         LIKE bsis-hkont OBLIGATORY
       DEFAULT '69999900' ,
    tcode        LIKE sy-tcode DEFAULT 'FB01'.
PARAMETERS:
  val_cc        AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK b.

*----------------------------------------------------------------------*
*                   Global Table Definitions.                          *
*----------------------------------------------------------------------*
TABLES:
    sscrfields,                        " Selection screen fields
    bgr00,
    bbkpf,
    bbseg,
    knb1,
    lfb1,
    t001,
    cepc,
    csks,
    ska1,
    skb1,
    varid,
    tbsl,
    tcurc,
    t007a,
    t004f,
    t003.
TABLES:
    zwwi01
  , zwwi02
  , zwwi03
  , zwwi05
  , zwwi06
  , zwwi07
  , zwwi08,
    zfiinterface.
*----------------------------------------------------------------------*
*                   Global Data Definitions.                           *
*----------------------------------------------------------------------*
DATA:
   l_repid          LIKE syst-repid,                "LL 02/28/03 ADD
   msg_text(50)     TYPE c,
   file_ok(1)       TYPE c VALUE '1',
   first_time(1)    TYPE c VALUE '1',
   balance_entry(1) TYPE c VALUE '0',
   records_read     TYPE i,
   current_record   TYPE i,
   end_indicator(1) TYPE c VALUE '/',
   nodata(1)        TYPE c VALUE '/',
   sub_total(15)    TYPE p DECIMALS 2 VALUE 0,
   tot_hdr(15)      TYPE p DECIMALS 2 VALUE '0.00'," for calculating the total.
   lsub_total(15)    TYPE p DECIMALS 2 VALUE 0,
   ltot_hdr(15)      TYPE p DECIMALS 2 VALUE '0.00'," for calculating the total.
*   be_dummy         like bbseg-dummy,
   be_dummy         LIKE bbseg-dummyx,
*   be_prodper         LIKE bbseg-prodper,

   be_sgtxt         LIKE bbseg-sgtxt,
   be_wrbtr         LIKE bbseg-wrbtr,
   be_newbs         LIKE bbseg-newbs,
   previous_gsber   LIKE bbseg-gsber,
   balance_gsber    LIKE bbseg-gsber,
   temp_barea       LIKE bbseg-gsber,
   temp_ccode       LIKE bbkpf-bukrs,
   temp_traty(3),
   temp_txjcd       LIKE bbseg-txjcd,
   num_kostl(10)    TYPE n,
   num_prctr(10)    TYPE n,
   valid_flag(1)    TYPE c,
   error_flag(1)    TYPE c,
   error_flag_cc(1) TYPE c,                                 "JC 2/09/98
   temp_file_path   LIKE ibipparms-path,
   default_gsber    LIKE bbseg-gsber    VALUE '    ',       "RK051397
   newfile(45)      TYPE c,
   unix_cmd(80)     TYPE c.

DATA:
      x_buper          LIKE t009b-poper
    , x_gjahr          LIKE t009b-bdatj
    , hold_shkzg       LIKE tbsl-shkzg
    , hold_koart       LIKE tbsl-koart
    , hold_wwiktopl(4)
    .
*-------------------------------------------------------------------*
*                   Constants                                          *
*----------------------------------------------------------------------*
DATA:
   userid                LIKE sy-uname    VALUE 'BATCHUSER',
   true(1)               TYPE c           VALUE '1',
   false(1)              TYPE c           VALUE '0',
   batchuser             LIKE sy-uname    VALUE 'BATCHUSER',
*  bal_entry_act         like bbseg-dummy value '69999900'  ,
   on(1)                                  VALUE 'X'   ,
   off(1)                                 VALUE ' '   ,
   c_header(3)                            VALUE 'HDR' ,
   c_item(3)                              VALUE 'ITM' ,
   c_tax(3)                               VALUE 'ITV'  .

*----------------------------------------------------------------------*
*                   Internal Table Definition.                         *
*----------------------------------------------------------------------*
DATA: BEGIN OF x_file OCCURS 0,
       record(245),
      END   OF x_file .

DATA: BEGIN OF in_file OCCURS 0,
        traty(3),
        cisref(30),
        ifref(12),
        doctype(4),
*       docnum(10),
        extdocnr(16),
        docdat(8),
        postdat(8),
        comp(10),
        period(6),
        waers(5),
        headtxt(25),
        newbs(2),
        acctnum(8),
        amount(15),
        site(3),
        zuonr(18),
        sgtxt(50),
        centre(10),
        vatcode(2),
        bukrs   LIKE t001-bukrs,
        wwiktopl(4) ,
        blart   LIKE bkpf-blart,
        xblnr   LIKE bkpf-xblnr,
        newko   LIKE bbseg-newko,
        bldat   LIKE bkpf-bldat,
        budat   LIKE bkpf-budat,
        monat   LIKE bkpf-monat,
        wrbtr   LIKE bbseg-wrbtr,
        kostl   LIKE bseg-kostl,
        prctr   LIKE bseg-prctr,
        mwskz   LIKE bseg-mwskz,
        prodper(8),
      END   OF in_file .

*data: begin of in_file occurs 0,
*        traty(3),
*        bldat like bbkpf-bldat,        " Document date
*        blart like bbkpf-blart,        " Document type
*        bukrs like bbkpf-bukrs,        " Company code
*        budat like bbkpf-budat,        " Posting date
*        monat like bbkpf-monat,        " Fiscal month
*        waers like bbkpf-waers,        " Currency key
*        bktxt like bbkpf-bktxt,        " Document header text
*        newbs like bbseg-newbs,        " Posting key
*        dummy like bbseg-dummy,        " Account
*        wrbtr like bbseg-wrbtr,        " Amount in document currency
*        mwskz like bbseg-mwskz,        " Tax code
*        kostl like bbseg-kostl,        " Cost center
*        prctr like bbseg-prctr,        " Profit center
*        sgtxt like bbseg-sgtxt,        " Line item text
*        zuonr like bbseg-zuonr,        " Allocation code
*        xblnr like bbkpf-xblnr.        " Reference Document Number
*data: end of in_file.
*
DATA: BEGIN OF wa,
        char1(250)   TYPE c,
        char2(250)   TYPE c,
        char3(250)   TYPE c,
        char4(250)   TYPE c,
        char5(250)   TYPE c,
        char6(250)   TYPE c,
        char7(250)   TYPE c,
        char8(250)   TYPE c,
        char9(250)   TYPE c,
        char10(250)  TYPE c.   "LL 04/02/03 ADD - BBSEG = 2412 chars
DATA: END OF wa.

DATA: BEGIN OF error_tab OCCURS 0,
        recno       LIKE sy-tabix,
        msgtxt(60)  TYPE c,
      END OF error_tab.
DATA:    BEGIN OF i_bbkpf.
        INCLUDE STRUCTURE bbkpf.       " Belegkopf
DATA:    END OF i_bbkpf.

DATA:    BEGIN OF i_bbseg.
        INCLUDE STRUCTURE bbseg.    " Belegsegment
DATA:    END OF i_bbseg.

DATA:    BEGIN OF nametab OCCURS 120.
        INCLUDE STRUCTURE dntab.
DATA:    END OF nametab.

DATA: BEGIN OF i_zwwi01 OCCURS 0.
        INCLUDE STRUCTURE zwwi01.
DATA: END   OF i_zwwi01 .

DATA: BEGIN OF i_zwwi07 OCCURS 0.
        INCLUDE STRUCTURE zwwi07.
DATA: END   OF i_zwwi07 .


DATA: BEGIN OF i_zwwi05 OCCURS 0.
        INCLUDE STRUCTURE zwwi05.
DATA: END   OF i_zwwi05 .

DATA: BEGIN OF i_zwwi06 OCCURS 0.
        INCLUDE STRUCTURE zwwi06.
DATA: END   OF i_zwwi06 .

DATA: h_t001   TYPE t001   .

DATA:    char(61)  TYPE c.             " Hilfsfeld
FIELD-SYMBOLS: <f1> .
*----------------------------------------------------------------------*
*                        ALV Declarations.
*----------------------------------------------------------------------*

DATA  : events TYPE slis_t_event WITH HEADER LINE,
        ls_layout  TYPE slis_layout_alv,
        g_status TYPE slis_formname VALUE 'STANDARD_02',
        g_variant LIKE disvariant,
        g_repid LIKE sy-repid,
        gt_fieldcat TYPE slis_t_fieldcat_alv,
        ls_fieldcat LIKE gt_fieldcat,
        wa_fieldcat TYPE slis_fieldcat_alv,
        ls_event TYPE LINE OF slis_t_event.

DATA: refno TYPE char16.
DATA:  zfiinter TYPE zfiinterface OCCURS 0 WITH HEADER LINE.

"END LL 04/02/03 ADD
*----------------------------------------------------------------------*
*                        Include Definitions.                          *
*----------------------------------------------------------------------*
INCLUDE:
  ysbi0010.                           " calls to BI function modules
INCLUDE ysbi0030.                      " calls to job function modules

*----------------------------------------------------------------------*
*                  MAIN PROGRAM                                        *
*----------------------------------------------------------------------*

AT SELECTION-SCREEN ON VALUE-REQUEST FOR infile.

  CLEAR temp_file_path.
  l_repid = sy-repid.                             "LL 02/28/03 ADD
* Extracting Of The Selection Screen Input File Name.
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      program_name  = l_repid
      dynpro_number = sy-dynnr
      field_name    = 'PATH'
    IMPORTING
      file_name     = temp_file_path.

  MOVE temp_file_path TO infile.

AT SELECTION-SCREEN OUTPUT.
*----------------------------------------------------------------------*
START-OF-SELECTION.

  IF filetype = 'P'.
    PERFORM read_pc_file.
  ELSEIF filetype = 'U'.
    PERFORM read_un_file.
  ELSE.
    MESSAGE e017.
  ENDIF.

  SELECT * FROM zwwi01 INTO TABLE i_zwwi01 .
  SORT i_zwwi01 .
  SELECT * FROM zwwi05 INTO TABLE i_zwwi05 .
  SORT i_zwwi05 .
  SELECT * FROM zwwi06 INTO TABLE i_zwwi06 .
  SORT i_zwwi06 .

* perform check_subtotals.
  PERFORM setup_file.
*----------------------------------------------------------------------*
END-OF-SELECTION.

  CHECK file_ok = true.
  LOOP AT in_file.
    MOVE: in_file-amount  TO in_file-wrbtr .
*    move in_file-kostl to num_kostl.
*    move num_kostl to in_file-kostl.
    current_record = sy-tabix.

    IF temp_ccode NE in_file-comp
     AND  in_file-comp <> space .
      .   " if company code changes.
      first_time = true.               " to create header/detail item.
      CLEAR records_read.
      IF balance_entry EQ true.        "if code change already occurred
        PERFORM create_balance_entry.
        PERFORM fill_balfile.
        balance_entry = false.
      ELSEIF balance_entry EQ false.
        IF sub_total NE 0.
          MOVE current_record TO error_tab-recno.
          CONCATENATE 'Company code' temp_ccode 'does not balance.'
                           INTO error_tab-msgtxt SEPARATED BY space.
          APPEND error_tab.
          error_flag = 'Y'.                     "Joyce Chang 2/09/98
          CLEAR sub_total.
        ENDIF.
      ENDIF.
      temp_ccode = in_file-comp .
    ENDIF.

    IF in_file-traty = 'HDR'.          " if company code changes.
      first_time = true.               " to create header/detail item.
      CLEAR records_read.
      IF balance_entry EQ true.        "if code change already occurred
        PERFORM create_balance_entry.
        PERFORM fill_balfile.
        balance_entry = false.
      ELSEIF balance_entry EQ false.
        IF sub_total NE 0.
          MOVE current_record TO error_tab-recno.
          CONCATENATE 'Document' in_file-xblnr 'does not balance.'
                           INTO error_tab-msgtxt SEPARATED BY space.
          APPEND error_tab.
          error_flag = 'Y'.                     "Joyce Chang 2/09/98
          CLEAR sub_total.
        ENDIF.
      ENDIF.
      temp_traty = in_file-traty.
    ENDIF.

* balancing entry
    IF records_read = bdc_nr .
      CLEAR records_read.
      balance_entry = true.
      PERFORM create_balance_entry.
      PERFORM fill_balfile.
      first_time = true.
    ENDIF.

* validation and conversion routine
    PERFORM check_outfile.

* create bdc internal table
    PERFORM fill_outfile.

* running total for balancing entry
*    clear tbsl.
*    select single * from tbsl where bschl = in_file-newbs.
    IF tbsl-shkzg EQ 'S'.
      sub_total = sub_total + in_file-wrbtr.
    ELSEIF tbsl-shkzg EQ 'H'.
      sub_total = sub_total - in_file-wrbtr.
    ENDIF.

    records_read = records_read + 1.
    MODIFY in_file.
  ENDLOOP.

  IF balance_entry = true OR
    sub_total <> 0.
    PERFORM create_balance_entry.
    PERFORM fill_balfile.
  ENDIF.

*Commented by michelle...bhavina made today
* Changes done by Bhavina ....
  PERFORM next_step.
  PERFORM write_report.
*perform file_backup.




* add Validate Cost center option to allow to submit BDC session when  *
* errors detected.                                                     *
*----------------------------------------------------------------------*
*  IF error_flag_cc = 'Y'.
*    CASE val_cc.
*      WHEN 'X'.
*        PERFORM write_error_report.
*      WHEN ' '.
*        PERFORM write_error_report.
**        if error_flag = ' '.
** message i100 - invalid cost center found.
*        MESSAGE i100.
*        PERFORM next_step.
*        PERFORM file_backup.
**        endif.
*    ENDCASE.
*  ELSE.
**    if error_flag = ' '.
*    PERFORM next_step.
*    PERFORM file_backup.
**    else.
*    PERFORM write_error_report.
**    endif.
*  ENDIF.

*----added
* Commented by bhavina ....
  IF error_flag_cc = 'Y'.
    CASE val_cc.
      WHEN 'X'.
*        perform write_error_report.
      WHEN ' '.
*        perform write_error_report.
        IF error_flag = ' '.
* message i100 - invalid cost center found.
          MESSAGE i100.
          PERFORM next_step.
*          perform file_backup.
        ENDIF.
    ENDCASE.
  ELSE.
    IF error_flag = ' '.
      PERFORM next_step.
*perform file_backup.
    ELSE.
*      perform write_error_report.
    ENDIF.
  ENDIF.
* comment ended....


*&---------------------------------------------------------------------*
*&      Form  READ_UN_FILE
*&---------------------------------------------------------------------*
*   Read the input file from UNIX                                      *
*----------------------------------------------------------------------*

FORM read_un_file.

  OPEN DATASET infile FOR INPUT IN TEXT MODE MESSAGE msg_text.

  IF sy-subrc NE 0.
    MESSAGE i002 WITH sy-subrc 'open' infile.
    MESSAGE i003 WITH msg_text.
    file_ok = false.
    EXIT.
  ENDIF.

  DO.

    READ DATASET infile INTO in_file.

    IF sy-subrc = 4.                   " Last record read
      EXIT.
    ELSEIF sy-subrc NE 0.
      MESSAGE i002 WITH sy-subrc 'read' infile.
      file_ok = false.
      EXIT.
    ENDIF.
    MOVE in_file-kostl TO num_kostl.
    MOVE num_kostl TO in_file-kostl.
    MOVE budat TO in_file-postdat.
    APPEND in_file.

  ENDDO.

  CLOSE DATASET infile.

  IF sy-subrc NE 0.
    MESSAGE i002 WITH sy-subrc 'close' infile.
    file_ok = false.
    EXIT.
  ENDIF.

ENDFORM.                               " READ_UN_FILE
*&---------------------------------------------------------------------*
*&      Form  READ_PC_FILE
*&---------------------------------------------------------------------*
*  Read the input file from the current PC                            *
*----------------------------------------------------------------------*
FORM read_pc_file.

  DATA: file_len TYPE i,
        file_typ LIKE rlgrap-filetype VALUE 'DAT'.          "MD07/28/97

  CALL FUNCTION 'WS_UPLOAD'
    EXPORTING
      filename            = infile
      filetype            = file_typ
    IMPORTING
      filelength          = file_len
    TABLES
      data_tab            = x_file
    EXCEPTIONS
      conversion_error    = 1
      file_open_error     = 2
      file_read_error     = 3
      invalid_table_width = 4
      invalid_type        = 5
      no_batch            = 6
      unknown_error       = 7
      OTHERS              = 8.

  IF sy-subrc NE 0.
    MESSAGE i002 WITH sy-subrc 'upload' infile.
    MESSAGE i003 WITH msg_text.
    file_ok = false.
    EXIT.
  ENDIF.
  MOVE x_file[] TO in_file[] .
ENDFORM.                               " READ_PC_FILE
*&---------------------------------------------------------------------*
*&      Form  SETUP_FILE
*&---------------------------------------------------------------------*
*       text                                                           *
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM setup_file.

  OPEN DATASET outfile FOR OUTPUT IN TEXT MODE MESSAGE msg_text.

  IF sy-subrc NE 0.
    MESSAGE i002 WITH sy-subrc 'open' outfile.
    MESSAGE i003 WITH msg_text.
    file_ok = false.
    EXIT.
  ENDIF.

  CLEAR: bgr00.

* Populate The Batch Input Session Parameters.
  MOVE: '0'        TO bgr00-stype,
        group      TO bgr00-group,
        nodata     TO bgr00-nodata,
        sy-mandt   TO bgr00-mandt,
        batchuser  TO bgr00-usnam .
*        NODATA     TO BGR00-START,       "LL 03/26/03 DEL
  IF zkeep = 'X' .
    MOVE zkeep      TO bgr00-xkeep.
  ELSE.
    MOVE nodata     TO bgr00-xkeep.
  ENDIF.
  MOVE bgr00      TO wa.

  TRANSFER wa TO outfile.
  IF sy-subrc NE 0.
    MESSAGE e002 WITH sy-subrc 'write' outfile.
  ENDIF.

* Initialise the document input structures.
  PERFORM init_structures USING 'BBKPF' i_bbkpf nodata.
  PERFORM init_structures USING 'BBSEG' i_bbseg nodata.

ENDFORM.                               " SETUP_FILE
*&---------------------------------------------------------------------*
*&      Form  FILL_OUTFILE
*&---------------------------------------------------------------------*
*  Fills the batch input record structures                             *
*----------------------------------------------------------------------*
FORM fill_outfile.

  IF first_time = true.
    first_time = false.
* Clear Input Structures.
    bbkpf = i_bbkpf.

    bbkpf-stype = '1'.
    bbkpf-tcode = tcode .
    WRITE in_file-bldat TO bbkpf-bldat. " Document date
    IF budat NE space.
      WRITE budat TO bbkpf-budat. " Posting  date
    ENDIF.
    bbkpf-blart = in_file-blart.       " Document type
    bbkpf-bukrs = in_file-bukrs.       " Company code
    bbkpf-monat = in_file-monat.       " Fiscal month
    bbkpf-waers = in_file-waers.       " Currency key
*    bbkpf-bktxt = in_file-zuonr.    " External Doc Number (JOBREF)

    bbkpf-bktxt = in_file-zuonr.       " External Doc Number (JOBREF)
    bbkpf-xblnr = in_file-xblnr.       " DOCTYPE/DOCNUM from input file
*   bbkpf-bldat = in_file-bldat.       " Date
*   bbkpf-budat = in_file-budat.       " Date

    PERFORM check_bbkpf.
    wa = bbkpf.

    TRANSFER wa TO outfile.
    IF sy-subrc NE 0.
      MESSAGE e002 WITH sy-subrc 'write' outfile.
    ENDIF.

    CLEAR : wa,in_file-bukrs.

  ENDIF.

  bbseg = i_bbseg.
  bbseg-stype = '2'.
  bbseg-tbnam = 'BBSEG'.
  bbseg-newbs = in_file-newbs.         " Posting key
  bbseg-newko = in_file-newko.         " Account
  bbseg-prodper = nodata.         " Production Period

  IF NOT in_file-bukrs IS INITIAL.
    bbseg-newbk = in_file-bukrs.
  ENDIF.

* CGunter - 2007/12/17  - Make sure NEWKO is not initial.
  IF bbseg-newko IS INITIAL.
    bbseg-newko = 'XXXXXXXXXX'.
  ENDIF.



  bbseg-wrbtr = in_file-wrbtr.         " Amount
  IF in_file-mwskz <> space.
    bbseg-mwskz = in_file-mwskz.         " Tax code
  ENDIF.
*  bbseg-txjcd = temp_txjcd.            " Tax jurisdiction code
*  clear temp_txjcd.
*
*  if ska1-xbilk = space and
*     in_file-kostl ne space and
*     in_file-kostl ne '0000000000'.
*    bbseg-kostl = in_file-kostl.       " Cost centre
*  endif.

*  bbseg-gsber = temp_barea.            " Business area
*  if temp_barea ne space.                                   " RK052897
*    default_gsber = temp_barea.                             " RK052897
*  endif.                                                    " RK052897
*  previous_gsber = temp_barea.         " Business area
*  move space to temp_barea.            " 12/18/96 MODIFICATION
  bbseg-kostl = in_file-kostl.         " Profit centre
  bbseg-prctr = in_file-prctr.         " Profit centre
  bbseg-zuonr = in_file-headtxt.
  bbseg-sgtxt = in_file-sgtxt.



  " Line item text
*  bbseg-zuonr = in_file-headtxt. "commented
  bbseg-zuonr = in_file-headtxt.
  PERFORM check_bbseg.

*  wa = bbseg.
*  TRANSFER wa TO outfile.
  TRANSFER bbseg TO outfile.


  IF sy-subrc NE 0.
    MESSAGE e002 WITH sy-subrc 'write' outfile.
  ENDIF.

ENDFORM.                               " FILL_OUTFILE
*&---------------------------------------------------------------------*
*&      Form  FILL_BALFILE
*&---------------------------------------------------------------------*
*  Fills the batch input record structure for balancing entry          *
*----------------------------------------------------------------------*
FORM fill_balfile.

  bbseg = i_bbseg.

  bbseg-stype = '2'.
  bbseg-tbnam = 'BBSEG'.
  bbseg-newbs = be_newbs.              " Posting key
  bbseg-newko = be_dummy.              " Account
  bbseg-wrbtr = be_wrbtr.              " Amount

*  if previous_gsber = space.         " Business area
*    bbseg-gsber = default_gsber.
*  else.
*    bbseg-gsber = previous_gsber.
*  endif.
  bbseg-sgtxt = be_sgtxt.              " Line item text
  bbseg-zuonr = in_file-headtxt.
  PERFORM check_bbseg.
  wa = bbseg.

  TRANSFER wa TO outfile.
  IF sy-subrc NE 0.
    MESSAGE e002 WITH sy-subrc 'write' outfile.
  ENDIF.

ENDFORM.                               " FILL_balFILE
*&---------------------------------------------------------------------*
*&      Form  CHECK_OUTFILE
*&---------------------------------------------------------------------*
*   Perform validation checks on all fields in incoming file           *
*----------------------------------------------------------------------*
FORM check_outfile.

  DATA: num_prctr(10) TYPE n,
        num_kostl(10) TYPE n.

* perform conversions on Header records
*---- Header Start ----------------------------------------------------*
  IF in_file-traty = c_header .
* Convert company code
    PERFORM convert_ccode    USING
             in_file-comp  .

* Check document date
*   if in_file-bldat is initial.
    IF in_file-docdat = space   .
      MOVE: current_record TO error_tab-recno,
            'Document date is blank.' TO error_tab-msgtxt.
      APPEND error_tab.
      error_flag = 'Y'.                          "Joyce Chang 2/09/98
    ELSE.
      PERFORM check_valid_date USING in_file-docdat.
      IF sy-subrc = 0.
        MOVE in_file-docdat TO in_file-bldat .
      ENDIF.
    ENDIF.

* Check posting date
*   if in_file-budat is initial.
    IF in_file-postdat = space   .
      MOVE: current_record TO error_tab-recno,
            'Posting date is blank.' TO error_tab-msgtxt.
      APPEND error_tab.
*   error_flag = true.
      error_flag = 'Y'.                            "Joyce Chang 2/09/98
    ELSE.
      MOVE budat TO in_file-postdat.
      PERFORM check_valid_date USING in_file-postdat.
      IF sy-subrc = 0.
        MOVE in_file-postdat TO in_file-budat .
      ENDIF.
    ENDIF.

* check fiscal period.
    PERFORM determine_period.
* Check fiscal month
    IF in_file-period+4(2) LT '01' OR
       in_file-period+4(2) GT '12'.
      MOVE current_record TO error_tab-recno.
      CONCATENATE 'Invalid fiscal month' in_file-period
                        INTO error_tab-msgtxt SEPARATED BY space.
      APPEND error_tab.
*   error_flag = true.
      error_flag = 'Y'.                            "Joyce Chang 2/09/98
    ENDIF.

    IF in_file-monat <> in_file-period+4(2) .
      MOVE current_record TO error_tab-recno.
      CONCATENATE 'Period in file <> Fiscal Month'
      in_file-period in_file-monat
                        INTO error_tab-msgtxt SEPARATED BY space.
      APPEND error_tab.
      error_flag = 'Y'.                            "Joyce Chang 2/09/98
    ENDIF.
* Check document type
    READ TABLE i_zwwi05 WITH KEY
     bukrs    = h_t001-bukrs
     doctype  = in_file-doctype.

*    select single * from zwwi05
*     where bukrs   = h_t001-bukrs
*     and   doctype = in_file-doctype.
*
    IF sy-subrc = 0 .
      MOVE i_zwwi05-blart  TO in_file-blart .
    ELSE.
      MOVE current_record TO error_tab-recno.
      CONCATENATE 'Invalid document type' in_file-doctype
                           INTO error_tab-msgtxt SEPARATED BY space.
      APPEND error_tab.
*   error_flag = true.
      error_flag = 'Y'.                            "Joyce Chang 2/09/98
    ENDIF.

* Check currency key
    TRANSLATE in_file-waers TO UPPER CASE. "CGunter 2008/01/16
    SELECT SINGLE * FROM tcurc WHERE waers = in_file-waers.
    IF sy-subrc NE 0.
      MOVE current_record TO error_tab-recno.
      CONCATENATE 'Invalid currency key' in_file-waers
                        INTO error_tab-msgtxt SEPARATED BY space.
      APPEND error_tab.
*   error_flag = true.
      error_flag = 'Y'.                           "Joyce Chang 2/09/98
    ENDIF.

* fill BKPF-XBLNR with the external document type & invoice doc nr.
    CONCATENATE in_file-doctype '/' in_file-extdocnr INTO in_file-xblnr.
* get the account type, so that later when the tax code is converted,
* we use the correct one for customer or vendor.
    SELECT SINGLE * FROM tbsl
    WHERE bschl = in_file-newbs.
    IF sy-subrc = 0 .
      MOVE tbsl-koart TO hold_koart.
    ELSE.
      MOVE current_record TO error_tab-recno.
      CONCATENATE 'Invalid posting key' in_file-newbs
                             INTO error_tab-msgtxt SEPARATED BY space.
      APPEND error_tab.
      error_flag = 'Y'.                           "Joyce Chang 2/09/98
    ENDIF.
  ENDIF .  "header

*---- Header End   ----------------------------------------------------*

* check these for every record.
* Check posting key
  CLEAR tbsl.
  IF in_file-newbs <> space  .
    SELECT SINGLE * FROM tbsl
    WHERE bschl = in_file-newbs.
    IF sy-subrc = 0 .
      IF tbsl-koart NE 'D' AND tbsl-koart NE 'S' AND tbsl-koart NE 'K' .
        MOVE current_record TO error_tab-recno.
        CONCATENATE 'Invalid posting key' in_file-newbs
                               INTO error_tab-msgtxt SEPARATED BY space.
        APPEND error_tab.
        error_flag = 'Y'.                           "Joyce Chang 2/09/98
      ELSE.
        MOVE tbsl-shkzg TO hold_shkzg .
      ENDIF.
    ELSE. "(subrc <> 0)
      MOVE current_record TO error_tab-recno.
      CONCATENATE 'Invalid posting key' in_file-newbs
                             INTO error_tab-msgtxt SEPARATED BY space.
      APPEND error_tab.
      error_flag = 'Y'.                           "Joyce Chang 2/09/98
    ENDIF.
  ELSE. "(in_file-newbs = initial)
    MOVE 'S' TO tbsl-koart .
    IF hold_shkzg = 'S' .
      MOVE '50' TO in_file-newbs.
    ELSEIF hold_shkzg = 'H' .
      MOVE '40' TO in_file-newbs.
    ENDIF.
  ENDIF.

* Check account number
  CASE tbsl-koart .
    WHEN 'D' .
      PERFORM check_sub-ledg_acct USING 'D' .
    WHEN 'K' .
      PERFORM check_sub-ledg_acct USING 'K' .
    WHEN OTHERS .
      PERFORM check_account_no.
  ENDCASE .
* Check amount
  IF in_file-wrbtr CN '0123456789. '.
    MOVE current_record TO error_tab-recno.
    CONCATENATE 'Invalid amount' in_file-wrbtr
                           INTO error_tab-msgtxt SEPARATED BY space.
    APPEND error_tab.
    error_flag = 'Y'.                            "Joyce Chang 2/09/98
  ENDIF.

* check whether cost or profit centre required in SAP.
  IF in_file-centre <> space.
    IF in_file-traty NE c_tax.

      PERFORM convert_centre.
    ELSE.
      MOVE: nodata  TO in_file-kostl,
            nodata  TO in_file-prctr.
    ENDIF.
  ENDIF.
* convert tax code. For ITV (tax) lines, this will also check
* the account number
  IF in_file-vatcode <> space.
    PERFORM tax_line .
  ENDIF.

** Cost Center/Profit Center (Input file will always have Cost center)
*    select single * from t004f
*                    where bukrs = 'SLBF'
*                    and   fstag = skb1-fstag.
*    if sy-subrc eq 0.
*      if t004f-faus1+9(1) = '+'.
** Cost center required
*        perform check_cost_center.
*        clear in_file-prctr.
*      elseif t004f-faus1+41(1) = '+'.
** Profit Center required
*        perform check_profit_center.
*      elseif t004f-faus1+9(1) = '.'.
** Cost center optional
*        perform check_cost_center.
*        clear in_file-prctr.
*      elseif t004f-faus1+41(1) = '.'.
** Profit Center optional
*        perform check_profit_center.
*      else.
****  Clear the field
**     clear: gldata-kostl, gldata-prctr.
*      endif.
*    endif.

** Check Balance Sheet item
*    if ska1-xbilk = 'X'.
*      perform check_bs_item.
*    endif.

** Tax jurisdiction code
*    if in_file-prctr ne space and
*       in_file-prctr ne '0000000000'.
*      select * from csks where
*          kokrs = '0100' and
**       kostl = in_file-prctr and
*          kostl = in_file-kostl and
*          datbi ge sy-datum and
*          datab le sy-datum.
*        exit.
*      endselect.
*      if sy-subrc eq 0.
** Profit center is not blank and tax code is not blank
*        if in_file-mwskz ne space.
*          temp_txjcd = csks-txjcd.
*        endif.
** B/S indicator is not on and profit center is not blank
*        if ska1-xbilk eq space.
*          temp_barea = csks-gsber.
*        endif.
*      endif.
*      clear in_file-kostl.          "since Profit center has a value
*    endif.


ENDFORM.                               " CHECK_OUTFILE

*&---------------------------------------------------------------------*
*&      Form  CHECK_ACCOUNT_NO
*&---------------------------------------------------------------------*
FORM check_account_no.
  DATA:subrc TYPE sy-subrc.
  UNPACK in_file-centre TO in_file-centre.
  IF in_file-acctnum <> space .
* first, try to find with the cost centre in the input file

    SELECT SINGLE * FROM zwwi07
           WHERE  wwiktopl  = hold_wwiktopl
           AND    oldsaknr  = in_file-acctnum
           AND    oldkostl  = in_file-centre .
    IF sy-subrc = 0.
      subrc = sy-subrc.
      SELECT SINGLE * FROM zwwi08
        WHERE kunnr = knb1-kunnr
        AND   hkont = zwwi07-newsaknr
        AND   bukrs = knb1-bukrs.
      IF sy-subrc = 0.
        MOVE zwwi08-zkont TO in_file-newko .
      ELSEIF subrc = 0.
        MOVE zwwi07-newsaknr TO in_file-newko.
      ENDIF.
    ELSE.


*    IF sy-subrc = 0 .
*      MOVE zwwi07-newsaknr TO in_file-newko .
*    ELSE.
** if that not found, then without the cost centre.
*      SELECT single * FROM  ZWWI07
*             WHERE  WWIKTOPL  = hold_wwiktopl
*             AND    OLDSAKNR  = in_file-acctnum
*             AND    OLDKOSTL  = ' '            .
*      if sy-subrc = 0 .
*        move zwwi02-newsaknr to in_file-newko .
*      else.

      MOVE current_record TO error_tab-recno.
      CONCATENATE 'Account' in_file-acctnum
                  'Company code: ' in_file-bukrs        "JChang 4/2/98
                  'not found in table ZWWI07'
                  INTO error_tab-msgtxt SEPARATED BY space.
      APPEND error_tab.
      error_flag = 'Y'.                            "Joyce Chang 2/09/98
    ENDIF.
*    endif.
  ENDIF.

ENDFORM.                               " CHECK_ACCOUNT_NO
*&---------------------------------------------------------------------*
*&      Form  CHECK_VALID_DATE
*&---------------------------------------------------------------------*
*   Checks an incoming date for validity                               *
*----------------------------------------------------------------------*
FORM check_valid_date USING date_in.
*
  DATA: x_date LIKE sy-datum.

  MOVE date_in TO x_date .
  CALL FUNCTION 'BUR_CHECK_VALID_DATES'
    EXPORTING
      i_date_from      = x_date
      i_date_to        = x_date
    EXCEPTIONS
      date_not_allowed = 1
      OTHERS           = 2.
  IF sy-subrc <> 0.
    MOVE current_record TO error_tab-recno.
    CONCATENATE 'Invalid date' x_date
                         INTO error_tab-msgtxt SEPARATED BY space.
    APPEND error_tab.
    error_flag = 'Y'.
  ENDIF.


ENDFORM.                               " CHECK_VALID_DATE
*&---------------------------------------------------------------------*
*&      Form  CREATE_BALANCE_ENTRY
*&---------------------------------------------------------------------*
*   Create a dummy entry in the amount of total processed so far       *
*----------------------------------------------------------------------*
FORM create_balance_entry.

  be_dummy = acc1 .            " Balancing entry account

  IF sub_total < 0.
    be_wrbtr = sub_total * ( -1 ).
  ELSE.
    be_wrbtr = sub_total.
  ENDIF.

  be_sgtxt = 'Balancing Entry'.

  IF sub_total < 0.
    be_newbs = '40'.                   " Debit
  ELSE.
    be_newbs = '50'.                   " Credit
  ENDIF.

  CLEAR sub_total.

ENDFORM.                               " CREATE_BALANCE_ENTRY
*&---------------------------------------------------------------------*
*&      Form  NEXT_STEP
*&---------------------------------------------------------------------*
*  Close the output dataset and call RFBIBL00 to process it.           *
*----------------------------------------------------------------------*
FORM next_step.

  DATA: i_list TYPE STANDARD TABLE OF abaplist.

  CLOSE DATASET outfile.
  CLEAR wa.
*  IF test = off .
*    SUBMIT rfbibl00 exporting list to memory
*    WITH  ds_name     = outfile
*    WITH  fl_check    = space
*    WITH  callmode    = 'B'
*    WITH  max_comm    = '1000'
*    WITH  anz_mode    = 'N'
*    WITH  pa_xprot    = space
**    with  xinf        = on       "no messages
*    WITH  xlog        = on
*    AND RETURN.
****start check whether selected file already uploaded or not Amit.
"  READ TABLE in_file INDEX 1.
  loop at in_file where site ne '' and zuonr ne ''.
  CONCATENATE in_file-site in_file-zuonr INTO refno.
  zfiinter-zz_refno = refno.
  zfiinter-chgdt = sy-datum.
*  APPEND   zfiinter.
  SELECT SINGLE * FROM zfiinterface
                  WHERE zz_refno = refno.
  IF sy-subrc = 0.
    MESSAGE i003(zfi) WITH zfiinterface-zz_refno zfiinterface-chgdt.
    LEAVE LIST-PROCESSING.
  ELSE.
    INSERT zfiinterface FROM zfiinter.
    IF sy-subrc = 0.
      COMMIT WORK.
    ENDIF.
  ENDIF.
  CLEAR zfiinter.
  endloop.
****end check whether selected file already uploaded or not Amit.
  IF test NE 'X'.
*      submit rfbibl01
    SUBMIT rfbibl01 EXPORTING LIST TO MEMORY
    WITH  ds_name     = outfile
    WITH  fl_check    = space
    WITH  callmode    = 'B'
    WITH  max_comm    = '1000'
    WITH  anz_mode    = 'N'
    WITH  pa_xprot    = space
*    with  xinf        = on       "no messages
    WITH  xlog        = on    "With log
    AND RETURN.


    CALL FUNCTION 'LIST_FROM_MEMORY'
      TABLES
        listobject       = i_list
* EXCEPTIONS
*   NOT_FOUND        = 1
*   OTHERS           = 2
              .

    CALL FUNCTION 'DISPLAY_LIST'
*     EXPORTING
*       FULLSCREEN                  =
*       CALLER_HANDLES_EVENTS       =
*       STARTING_X                  = 10
*       STARTING_Y                  = 10
*       ENDING_X                    = 60
*       ENDING_Y                    = 20
*     IMPORTING
*       USER_COMMAND                =
      TABLES
        listobject                  = i_list
*     EXCEPTIONS
*       EMPTY_LIST                  = 1
*       OTHERS                      = 2
              .


  ENDIF.
ENDFORM.                               " NEXT_STEP
*&---------------------------------------------------------------------*
*&      Form  CHECK_BS_ITEM
*&---------------------------------------------------------------------*
*  Checks records with accounts that have a balance sheet indicator    *
*----------------------------------------------------------------------*
FORM check_bs_item.

*  if in_file-kostl ne space and
*    in_file-kostl ne '0000000000'.
*    select * from csks where
*        kokrs = 'SLB1' and
*        kostl = in_file-kostl and
*        datbi ge sy-datum and
*        datab le sy-datum.
*      exit.
*    endselect.
*
*    if sy-subrc ne 0.
*      move current_record to error_tab-recno.
*      concatenate 'Cost center' in_file-kostl
*                  'Company code: ' in_file-bukrs
*                  'not found in CSKS'
*                  into error_tab-msgtxt separated by space.
*      append error_tab.
**     error_flag = true.
*      error_flag_cc = 'Y'.
*    else.
*      temp_barea = csks-gsber.
*      move space to in_file-kostl.
*      if in_file-mwskz ne space.
*        temp_txjcd = csks-txjcd.
*      endif.
*    endif.
*  endif.

ENDFORM.                    "check_bs_item

*&---------------------------------------------------------------------
*&      Form  CHECK_BBKPF
*&---------------------------------------------------------------------

FORM check_bbkpf.

*  perform fill_field using bbkpf-stype.
*  perform fill_field using bbkpf-tcode.
  PERFORM fill_field USING bbkpf-bldat.
  PERFORM fill_field USING bbkpf-blart.
  PERFORM fill_field USING bbkpf-bukrs.
  PERFORM fill_field USING bbkpf-budat.
  PERFORM fill_field USING bbkpf-monat.
  PERFORM fill_field USING bbkpf-waers.
  PERFORM fill_field USING bbkpf-xblnr.
*  perform fill_field using bbkpf-bvorg.
  PERFORM fill_field USING bbkpf-bktxt.
*  perform fill_field using bbkpf-pargb.
*  perform fill_field using bbkpf-auglv.
*  perform fill_field using bbkpf-vbund.
*  perform fill_field using bbkpf-xmwst.
*  perform fill_field using bbkpf-docid.
*  perform fill_field using bbkpf-barcd.
*  perform fill_field using bbkpf-stodt.
*  perform fill_field using bbkpf-brnch.
*  perform fill_field using bbkpf-numpg.
*  perform fill_field using bbkpf-stgrd.
*  perform fill_field using bbkpf-kursf_m.
*  perform fill_field using bbkpf-augtx.
*  perform fill_field using bbkpf-xprfg.
** jchang 3/26/03 end of change
*  perform fill_field using bbkpf-sende.
*
ENDFORM.                               " CHECK_BBKPF

*&---------------------------------------------------------------------*
*&      Form  FILL_FIELD
*&---------------------------------------------------------------------*
FORM fill_field USING in_field.

  IF in_field = space.
    in_field = nodata.
  ENDIF.

  IF in_field = '0000000000'.
    in_field = nodata.
  ENDIF.
ENDFORM.                               " FILL_FIELD

*&---------------------------------------------------------------------
*&      Form  CHECK_BBSEG
*&---------------------------------------------------------------------
*       text
*----------------------------------------------------------------------
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------

FORM check_bbseg.

*  perform fill_field using bbseg-stype.
*  perform fill_field using bbseg-tbnam.
  PERFORM fill_field USING bbseg-newbs.
  IF bbseg-newbs+0(1) = nodata OR bbseg-newbs = space.
    bbseg-newbs = 'XX'.
  ENDIF.
*  perform fill_field using bbseg-dummy.
  PERFORM fill_field USING bbseg-dummyx.
*  perform fill_field using bbseg-newum.
*  field not present in screen sapm50fa 0100
  IF NOT bbseg-newbk IS INITIAL.
    PERFORM fill_field USING bbseg-newbk.
*  bbseg-newbk = nodata .
*    clear bbseg-newbk.
  ENDIF.

  PERFORM fill_field USING bbseg-wrbtr.
*  field not present in screen sapm50fa 0100
  PERFORM fill_field USING bbseg-prodper.
*  perform fill_field using bbseg-dmbtr.
*  perform fill_field using bbseg-wmwst.
*  perform fill_field using bbseg-mwsts.
  PERFORM fill_field USING bbseg-mwskz.
*  perform fill_field using bbseg-xskrl.
*  perform fill_field using bbseg-fwzuz.
*  perform fill_field using bbseg-hwzuz.
*  perform fill_field using bbseg-gsber.
  PERFORM fill_field USING bbseg-kostl.
*  perform fill_field using bbseg-dummy4.
*  PERFORM fill_field USING bbseg-aufnr.
*  perform fill_field using bbseg-ebeln.
*  perform fill_field using bbseg-ebelp.
*  perform fill_field using bbseg-projn.
*  perform fill_field using bbseg-matnr.
*  perform fill_field using bbseg-werks.
*  perform fill_field using bbseg-menge.
*  perform fill_field using bbseg-meins.
*  perform fill_field using bbseg-vbel2.
*  perform fill_field using bbseg-posn2.
*  perform fill_field using bbseg-eten2.
*  perform fill_field using bbseg-pernr.
*  perform fill_field using bbseg-bewar.
*  perform fill_field using bbseg-valut.
*  perform fill_field using bbseg-zfbdt.
*  perform fill_field using bbseg-zinkz.
  PERFORM fill_field USING bbseg-zuonr.
*  perform fill_field using bbseg-fkont.
*  perform fill_field using bbseg-xaabg.
  PERFORM fill_field USING bbseg-sgtxt.
*  perform fill_field using bbseg-blnkz.
*  perform fill_field using bbseg-blnbt.
*  perform fill_field using bbseg-blnpz.
*  perform fill_field using bbseg-maber.
*  perform fill_field using bbseg-skfbt.
*  perform fill_field using bbseg-wskto.
*  perform fill_field using bbseg-zterm.
*  perform fill_field using bbseg-zbd1t.
*  perform fill_field using bbseg-zbd1p.
*  perform fill_field using bbseg-zbd2t.
*  perform fill_field using bbseg-zbd2p.
*  perform fill_field using bbseg-zbd3t.
*  perform fill_field using bbseg-zlspr.
*  perform fill_field using bbseg-rebzg.
*  perform fill_field using bbseg-rebzj.
*  perform fill_field using bbseg-rebzz.
*  perform fill_field using bbseg-zlsch.
*  perform fill_field using bbseg-samnr.
*  perform fill_field using bbseg-zbfix.
*  perform fill_field using bbseg-qsskz.
*  perform fill_field using bbseg-qsshb.
*  perform fill_field using bbseg-qsfbt.
*  perform fill_field using bbseg-esrnr.
*  perform fill_field using bbseg-esrpz.
*  perform fill_field using bbseg-esrre.
*  perform fill_field using bbseg-fdtag.
*  perform fill_field using bbseg-fdlev.
*  perform fill_field using bbseg-anln1.
*  perform fill_field using bbseg-anln2.
*  perform fill_field using bbseg-bzdat.
*  perform fill_field using bbseg-anbwa.
*  perform fill_field using bbseg-abper.
*  perform fill_field using bbseg-gbetr.
*  perform fill_field using bbseg-kursr.
*  perform fill_field using bbseg-mansp.
*  perform fill_field using bbseg-mschl.
*  perform fill_field using bbseg-hbkid.
*  perform fill_field using bbseg-bvtyp.
*  perform fill_field using bbseg-anfbn.
*  perform fill_field using bbseg-anfbu.
*  perform fill_field using bbseg-anfbj.
*  perform fill_field using bbseg-lzbkz.
*  perform fill_field using bbseg-landl.
*  perform fill_field using bbseg-diekz.
*  perform fill_field using bbseg-zolld.
*  perform fill_field using bbseg-zollt.
*  perform fill_field using bbseg-vrsdt.
*  perform fill_field using bbseg-vrskz.
*  perform fill_field using bbseg-hzuon.
*  perform fill_field using bbseg-regul.
*  perform fill_field using bbseg-name1.
*  perform fill_field using bbseg-name2.
*  perform fill_field using bbseg-name3.
*  perform fill_field using bbseg-name4.
*  perform fill_field using bbseg-stras.
*  perform fill_field using bbseg-ort01.
*  perform fill_field using bbseg-pstlz.
*  perform fill_field using bbseg-land1.
*  perform fill_field using bbseg-regio.
*  perform fill_field using bbseg-bankl.
*  perform fill_field using bbseg-banks.
*  perform fill_field using bbseg-bankn.
*  perform fill_field using bbseg-bkont.
*  perform fill_field using bbseg-stcd1.
*  perform fill_field using bbseg-stcd2.
*  perform fill_field using bbseg-madat.
*  perform fill_field using bbseg-manst.
*  perform fill_field using bbseg-egmld.
*  perform fill_field using bbseg-dummy2.
*  perform fill_field using bbseg-stceg.
*  perform fill_field using bbseg-stkza.
*  perform fill_field using bbseg-stkzu.
*  perform fill_field using bbseg-pfach.
*  perform fill_field using bbseg-pstl2.
*  perform fill_field using bbseg-spras.
*  perform fill_field using bbseg-xinve.
  PERFORM fill_field USING bbseg-newko.
  IF bbseg-newko+0(1) = nodata OR bbseg-newko = space.
    bbseg-newko = 'XXXXXXXXXX'.
  ENDIF.
*  perform fill_field using bbseg-newbw.
*  perform fill_field using bbseg-knrze.
*  perform fill_field using bbseg-hkont.
  PERFORM fill_field USING bbseg-prctr.
*  perform fill_field using bbseg-vertn.
*  perform fill_field using bbseg-vertt.
*  perform fill_field using bbseg-vbewa.
*  perform fill_field using bbseg-hwbas.
*  perform fill_field using bbseg-fwbas.
*  perform fill_field using bbseg-fipos.
*  perform fill_field using bbseg-vname.
*  perform fill_field using bbseg-egrup.
*  perform fill_field using bbseg-btype.
*  perform fill_field using bbseg-paobjnr.
*  perform fill_field using bbseg-kstrg.
*  perform fill_field using bbseg-imkey.
*  perform fill_field using bbseg-dummy3.
  PERFORM fill_field USING bbseg-zuonr.
*  perform fill_field using bbseg-nplnr.
*  perform fill_field using bbseg-vornr.
*  perform fill_field using bbseg-xegdr.
*  perform fill_field using bbseg-recid.
*  perform fill_field using bbseg-pprct.
*  PERFORM fill_field USING bbseg-projk.
*  perform fill_field using bbseg-uzawe.
  PERFORM fill_field USING bbseg-txjcd.
*  perform fill_field using bbseg-fistl.
*  perform fill_field using bbseg-geber.
*  perform fill_field using bbseg-dmbe2.
*  perform fill_field using bbseg-dmbe3.
*  perform fill_field using bbseg-pargb.
*  perform fill_field using bbseg-xref1.
*  perform fill_field using bbseg-xref2.
*  perform fill_field using bbseg-kblnr.
*  perform fill_field using bbseg-kblpos.
*  perform fill_field using bbseg-wdate.
*  perform fill_field using bbseg-wgbkz.
*  perform fill_field using bbseg-xaktz.
*  perform fill_field using bbseg-wname.
*  perform fill_field using bbseg-wort1.
*  perform fill_field using bbseg-wbzog.
*  perform fill_field using bbseg-wort2.
*  perform fill_field using bbseg-wbank.
*  perform fill_field using bbseg-wlzbp.
*  perform fill_field using bbseg-diskp.
*  perform fill_field using bbseg-diskt.
*  perform fill_field using bbseg-winfw.
*  perform fill_field using bbseg-winhw.
*  perform fill_field using bbseg-wevwv.
*  perform fill_field using bbseg-wstat.
*  perform fill_field using bbseg-wmwkz.
*  perform fill_field using bbseg-wstkz.
*  perform fill_field using bbseg-dummy.           "LL 04/02/03 ADD
*****perform fill_field using bbseg-pdummy_ke.              "TH 090299
*  perform fill_field using bbseg-vbund.
*  perform fill_field using bbseg-fkber.
*  perform fill_field using bbseg-dabrz.
*  perform fill_field using  bbseg-xstba.
*  perform fill_field using bbseg-sende.
***** New fields added to bseg for 3.1I upgrade.              TH 090799
*  perform fill_field using bbseg-rke_artnr.
*  perform fill_field using bbseg-rke_bonus.
*  perform fill_field using bbseg-rke_brsch.
*  perform fill_field using bbseg-rke_artnr.
*  perform fill_field using bbseg-rke_bukrs.
*  perform fill_field using bbseg-rke_bzirk.
*  perform fill_field using bbseg-rke_eform.
*  perform fill_field using bbseg-rke_fkart.
*  perform fill_field using bbseg-rke_gebie.
*  perform fill_field using bbseg-rke_gsber.
*  perform fill_field using bbseg-rke_kaufn.
*  perform fill_field using bbseg-rke_kdgrp.
*  perform fill_field using bbseg-rke_kdpos.
*  perform fill_field using bbseg-rke_kndnr.
*  perform fill_field using bbseg-rke_kokrs.
*  perform fill_field using bbseg-rke_kstrg.
*  perform fill_field using bbseg-rke_land1.
*  perform fill_field using bbseg-rke_maabc.
*  perform fill_field using bbseg-rke_matkl.
*  perform fill_field using bbseg-rke_prctr.
*  perform fill_field using bbseg-rke_pspnr.
*  perform fill_field using bbseg-rke_prodh.
** PERFORM FILL_FIELD USING BBSEG-RKE_RKAUFN.    "LL 02/28/03 CHG
*  perform fill_field using bbseg-rke_rkaufnr.
*  perform fill_field using bbseg-rke_spart.
*  perform fill_field using bbseg-rke_vkbur.
*  perform fill_field using bbseg-rke_vkgrp.
*  perform fill_field using bbseg-rke_vkorg.
*  perform fill_field using bbseg-rke_vtweg.
*  perform fill_field using bbseg-rke_werks.
*  perform fill_field using bbseg-rstgr.
*  perform fill_field using bbseg-fipex.
*****End of field added to bseg for 3.1I upgrade.              TH 090799

ENDFORM.                               " CHECK_BBSEG
*&---------------------------------------------------------------------*
*&      Form  CHECK_SUBTOTALS
*&---------------------------------------------------------------------*
*       text                                                           *
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM check_subtotals.

  LOOP AT in_file.
    CLEAR tbsl.
    SELECT SINGLE * FROM tbsl WHERE bschl = in_file-newbs.
    IF tbsl-shkzg EQ 'S' .
      sub_total = sub_total + in_file-amount.
    ELSEIF tbsl-shkzg EQ 'H' .
      sub_total = sub_total - in_file-amount.
    ELSE.
* error condition
      MESSAGE e009 WITH in_file-newbs sy-tabix.
    ENDIF.
  ENDLOOP.

  IF sub_total NE 0.
    MESSAGE e016 WITH sub_total.
  ENDIF.
  CLEAR sub_total.

ENDFORM.                               " CHECK_SUBTOTALS
*&---------------------------------------------------------------------*
*&      Form  CHECK_COST_CENTER
*&---------------------------------------------------------------------*
*       text                                                           *
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM check_cost_center.

  CLEAR csks.
  SELECT * FROM csks
           WHERE kostl = in_file-kostl
           AND   datbi GE sy-datum
           AND   datab LE sy-datum
           AND   bukrs = in_file-bukrs.
    EXIT.
  ENDSELECT.

  IF sy-subrc NE 0.
    MOVE current_record TO error_tab-recno.
    CONCATENATE 'Invalid Cost Center' in_file-kostl
                'Company code: ' in_file-bukrs         "JChang 4/2/98
                INTO error_tab-msgtxt SEPARATED BY space.
    APPEND error_tab.
*   error_flag = true.                            "Joyce Chang 2/09/98
    error_flag_cc = 'Y'.                          "Joyce Chang 2/09/98
  ENDIF.


ENDFORM.                               " CHECK_COST_CENTER

*&---------------------------------------------------------------------*
*&      Form  CHECK_PROFIT_CENTER
*&---------------------------------------------------------------------*
*       text                                                           *
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM check_profit_center.

** The following lines added per request from Laura Paddy and the
** subsequent lines commented. MD 07/03/97

  SELECT prctr FROM csks INTO in_file-prctr
               WHERE kostl = in_file-kostl
               AND   datbi GE sy-datum
               AND   datab LE sy-datum
               AND   bukrs = in_file-bukrs.
    EXIT.
  ENDSELECT.
  IF in_file-prctr IS INITIAL.
    MOVE current_record TO error_tab-recno.
    CONCATENATE 'Profit Center not found for cost center' in_file-kostl
                'Company code: ' in_file-bukrs
                INTO error_tab-msgtxt SEPARATED BY space.
    APPEND error_tab.
*   error_flag = true.
    error_flag = 'Y'.
  ENDIF.



ENDFORM.                               " CHECK_PROFIT_CENTER
*&---------------------------------------------------------------------*
*&      Form  WRITE_ERROR_REPORT
*&---------------------------------------------------------------------*
*       text                                                           *
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM write_error_report.
  WRITE : /'Error Log!'.
  SKIP 1.
  WRITE: /5 'Record No', 16 'Error Message'.
  ULINE: /5(10), 16(40).

  LOOP AT error_tab.
    WRITE: /5 error_tab-recno, 16 error_tab-msgtxt.
  ENDLOOP.

ENDFORM.                               " WRITE_ERROR_REPORT
*&---------------------------------------------------------------------*
*&      Form  FILE_BACKUP
*&---------------------------------------------------------------------*
*       text                                                           *
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM file_backup.
** If its a UNIX file then append _bkup to the filename.
  IF filetype = 'U'.
    CONCATENATE infile '_bkup' INTO newfile.
    CONCATENATE 'mv' infile newfile INTO unix_cmd SEPARATED BY space.
    CALL 'SYSTEM' ID 'COMMAND' FIELD unix_cmd.
  ENDIF.

ENDFORM.                    " FILE_BACKUP
*&---------------------------------------------------------------------*
*&      Form  init_structures
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->tabname  'BBSEG'
*      -->tab      'I_BBSEG'
*      -->i_nodata 'NODATA'
*----------------------------------------------------------------------*
FORM init_structures USING tabname tab i_nodata.
  REFRESH nametab.
  CALL FUNCTION 'NAMETAB_GET'
    EXPORTING
      langu          = sy-langu
      tabname        = tabname
    TABLES
      nametab        = nametab
    EXCEPTIONS
      no_texts_found = 1.
  IF sy-subrc NE 0.
    MESSAGE e000 WITH 'DDIC Structure ' tabname ' not found'.
  ENDIF.
  LOOP AT nametab.
    CLEAR char.
    CONCATENATE 'I_' nametab-tabname '-' nametab-fieldname INTO char.
    ASSIGN (char) TO <f1>.
    <f1> = i_nodata.
  ENDLOOP.
ENDFORM.                    " init_structures
*&---------------------------------------------------------------------*
*&      Form  check_sub-ledg_acct
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM check_sub-ledg_acct USING acctype .
  DATA: x_table(4),
        x_field(10) .

  CASE acctype.
    WHEN 'D' .
      SELECT        * FROM  knb1
             WHERE  bukrs  = in_file-bukrs
             AND    altkn  = in_file-acctnum .
        MOVE knb1-kunnr  TO  in_file-newko .
      ENDSELECT.

      IF sy-subrc NE 0.
        MOVE current_record TO error_tab-recno.
        CONCATENATE 'Account' in_file-acctnum
                    'Company code: ' in_file-bukrs        "JChang 4/2/98
                    'not found in table KNB1'
                    INTO error_tab-msgtxt SEPARATED BY space.
        APPEND error_tab.
*   error_flag = true.
        error_flag = 'Y'.                            "Joyce Chang 2/09/98
      ENDIF.

    WHEN 'K' .
      SELECT        * FROM  lfb1
             WHERE  bukrs  = in_file-bukrs
             AND    altkn  = in_file-acctnum .
        MOVE lfb1-lifnr  TO  in_file-newko .
      ENDSELECT.

      IF sy-subrc NE 0.
        MOVE current_record TO error_tab-recno.
        CONCATENATE 'Account' in_file-acctnum
                    'Company code: ' in_file-bukrs        "JChang 4/2/98
                    'not found in table LFB1'
                    INTO error_tab-msgtxt SEPARATED BY space.
        APPEND error_tab.
*   error_flag = true.
        error_flag = 'Y'.                            "Joyce Chang 2/09/98
      ENDIF.
  ENDCASE .

ENDFORM.                    " check_sub-ledg_acct
*&---------------------------------------------------------------------*
*&      Form  convert_ccode
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_IN_FILE_COMP  text
*----------------------------------------------------------------------*
FORM convert_ccode USING    ccode .

  READ TABLE i_zwwi01 WITH KEY
   oldbukrs = ccode.

  IF sy-subrc = 0.
    MOVE:  i_zwwi01-newbukrs  TO  in_file-bukrs ,
*           i_zwwi01-newbukrs  to  comp_tab-bukrs,
*           i_zwwi01-newbukrs  to  comp_tab-o_bukrs,
           i_zwwi01-wwiktopl  TO  hold_wwiktopl ,
           i_zwwi01-wwiktopl  TO  in_file-wwiktopl .
    SELECT SINGLE *     FROM t001
     INTO h_t001
      WHERE bukrs = in_file-bukrs .
*    move: h_t001-ktopl to in_tab-ktopl ,
*          h_t001-ktopl to comp_tab-ktopl ,
*          h_t001-waers to in_tab-waers ,
*          h_t001-waers to comp_tab-waers  .
*    SELECT        * FROM  TKA02
*           WHERE  BUKRS  = ncomp .
*      move: tka02-kokrs to in_tab-kokrs ,
*            tka02-kokrs to comp_tab-kokrs  .
*    ENDSELECT.
*    collect comp_tab .
  ELSE.
    CLEAR hold_wwiktopl.
    MOVE current_record TO error_tab-recno.
    CONCATENATE 'Invalid company code' in_file-comp
                      INTO error_tab-msgtxt SEPARATED BY space.
    APPEND error_tab.
*   error_flag = true.
    error_flag = 'Y'.                            "Joyce Chang 2/09/98

  ENDIF.

ENDFORM.                    " convert_ccode
*&---------------------------------------------------------------------*
*&      Form  convert_centre
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM convert_centre.

  MOVE in_file-centre TO num_kostl.
  MOVE num_kostl      TO in_file-centre.

  SELECT SINGLE * FROM  zwwi07
           WHERE  wwiktopl  = hold_wwiktopl
           AND    oldsaknr  = in_file-acctnum
           AND    oldkostl  = in_file-centre .

*  SELECT single * FROM  ZWWI03

*         WHERE  OLDBUKRS  = hold_wwiktopl
*         AND    OLDKOSTL  = in_file-centre .
*
  IF sy-subrc <> 0.
    MOVE current_record TO error_tab-recno.
    CONCATENATE 'Invalid cost centre' in_file-wwiktopl in_file-centre
                      INTO error_tab-msgtxt SEPARATED BY space.
    APPEND error_tab.
*   error_flag = true.
    error_flag = 'Y'.

  ELSE.
    IF ( in_file-newko > 40000000 AND
         in_file-newko < 49999999 ) .
      MOVE: nodata                  TO in_file-kostl   ,
            zwwi07-newprctr         TO in_file-prctr    ,
            zwwi07-newprctr+1(4)      TO in_file-bukrs.
    ELSE.
      MOVE: zwwi07-newkostl         TO in_file-kostl   ,
            nodata                  TO in_file-prctr   ,
            zwwi07-newkostl+1(4)    TO in_file-bukrs.
    ENDIF.

  ENDIF.
ENDFORM.                    " convert_centre
*&---------------------------------------------------------------------*
*&      Form  tax_line
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM tax_line .
  DATA: hold_saknr LIKE bseg-saknr .

  READ TABLE i_zwwi06 WITH KEY
   bukrs    = h_t001-bukrs
   koart    = hold_koart
   taxcode  = in_file-vatcode.

  IF sy-subrc = 0 .
    MOVE: i_zwwi06-mwskz  TO in_file-mwskz ,
          i_zwwi06-saknr  TO hold_saknr .
  ELSE.
    MOVE current_record TO error_tab-recno.
    CONCATENATE 'Invalid Tax Code' in_file-vatcode
                         INTO error_tab-msgtxt SEPARATED BY space.
    APPEND error_tab.
    error_flag = 'Y'.                            "Joyce Chang 2/09/98
  ENDIF.

  IF in_file-traty = c_tax .
    IF in_file-acctnum <> space .
      PERFORM check_account_no.
    ELSE.
      in_file-newko = hold_saknr .
      CLEAR hold_saknr .
    ENDIF.
  ENDIF.
*    if skb1-mwskz is initial.
*      clear in_file-mwskz.
*    else.
*      if skb1-xmwno eq space and
*         in_file-mwskz eq space.
*        move: current_record to error_tab-recno,
*   'Tax code should not be blank for this record' to error_tab-msgtxt.
*        append error_tab.
**     error_flag = true.
*        error_flag = 'Y'.                          "Joyce Chang 2/09/98
*      endif.
*    endif.
*
*    if in_file-mwskz ne space.
*      if skb1-mwskz eq '+' or
*         skb1-mwskz eq '>' or
*         skb1-mwskz eq '-' or
*         skb1-mwskz eq '<' or
*         skb1-mwskz eq '*'.
*        if skb1-xmwno eq space.
*          valid_flag = false.
*          select * from t007a where mwskz = in_file-mwskz.
*            if skb1-mwskz eq '+' or
*               skb1-mwskz eq '>'.
*              if t007a-mwart eq 'A'.
*                valid_flag = true.
*                exit.
*              else.
*                valid_flag = false.
*              endif.
*            elseif skb1-mwskz eq '-' or
*                   skb1-mwskz eq '<'.
*              if t007a-mwart eq 'V'.
*                valid_flag = true.
*                exit.
*              else.
*                valid_flag = false.
*              endif.
*            else.
*              valid_flag = true.
*              exit.
*            endif.
*          endselect.
*          if valid_flag eq false.
*            move current_record to error_tab-recno.
*            concatenate 'Invalid tax code' in_file-mwskz
*                          into error_tab-msgtxt separated by space.
*            append error_tab.
**         error_flag = true.
*            error_flag = 'Y'.                      "Joyce Chang 2/09/98
*          endif.
*        endif.
*      endif.
*    endif.
*
ENDFORM.                    " tax_line
*&---------------------------------------------------------------------*
*&      Form  determine_period
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM determine_period.
  IF NOT in_file-budat IS INITIAL .
    CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'
      EXPORTING
        i_date               = in_file-budat
*   I_MONMIT             = 00
        i_periv              = h_t001-periv
      IMPORTING
        e_buper              = x_buper
        e_gjahr              = x_gjahr
   EXCEPTIONS
     input_false          = 1
     t009_notfound        = 2
     t009b_notfound       = 3
     OTHERS               = 4
              .
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ELSE .
      MOVE: x_buper TO in_file-monat .
    ENDIF.
  ENDIF.
ENDFORM.                    " determine_period

* Changes done by bhavina to display output data of infile....
*&---------------------------------------------------------------------*
*&      Form  write_report
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_IN_FILE  text
*----------------------------------------------------------------------*
FORM write_report.
  DATA: print_parameters TYPE pri_params,
        valid_flag       TYPE c LENGTH 1.

  DATA: ind LIKE sy-tabix.

*  sub_total(15)    TYPE p DECIMALS 2 VALUE 0,
  LOOP AT in_file.
    ind = sy-tabix.
    IF in_file-traty EQ 'HDR'.
      tot_hdr = tot_hdr + in_file-amount.
      IF in_file-traty EQ 'ITM' AND
      in_file-newbs  EQ '40'.
        tot_hdr = tot_hdr + in_file-amount.


      ELSEIF in_file-traty EQ 'ITM' AND
      in_file-newbs  EQ '50'.
        tot_hdr = tot_hdr - in_file-amount.

      ENDIF.
      IF in_file-traty EQ 'ITV' AND
      in_file-newbs  EQ '40'.
        tot_hdr = tot_hdr + in_file-amount.


      ELSEIF in_file-traty EQ 'ITV' AND
      in_file-newbs  EQ '50'.
        tot_hdr = tot_hdr - in_file-amount.


      ENDIF.

    ENDIF.
    MOVE-CORRESPONDING in_file TO int_display.
    int_display-acctnum1 = in_file-newko.
    READ TABLE i_zwwi06 WITH KEY bukrs = in_file-bukrs.
    "taxcode  = in_file-vatcode.
    IF sy-subrc = 0.
      int_display-acctnum2 = i_zwwi06-saknr.
    ENDIF.
    IF in_file-docdat IS NOT INITIAL.
      CONCATENATE in_file-docdat+6(2) '.'
                in_file-docdat+4(2) '.'
                in_file-docdat+0(4) INTO
                int_display-docdat.
    ENDIF.
    IF in_file-postdat IS NOT INITIAL.
      CONCATENATE in_file-postdat+6(2) '.'
                in_file-postdat+4(2) '.'
                in_file-postdat+0(4) INTO
                int_display-postdat.

    ENDIF.
    READ TABLE error_tab WITH KEY recno = ind.
    IF sy-subrc = 0.
      int_display-msgtxt = error_tab-msgtxt.
    ENDIF.
    APPEND int_display.
    CLEAR int_display.
  ENDLOOP.
***----add logic for local currency by amit
  LOOP AT int_display.
    IF int_display-postdat IS NOT INITIAL.
      CONCATENATE int_display-postdat+6(4)
              int_display-postdat+3(2)
              int_display-postdat+0(2) INTO
              int_display-pstdat.
      MODIFY int_display.
      CLEAR int_display.
    ENDIF.
  ENDLOOP.
  LOOP AT int_display WHERE  pstdat <> '00000000' AND waers <> ''.
    CALL FUNCTION 'READ_EXCHANGE_RATE'
      EXPORTING
       client                  = sy-mandt
        date                   = int_display-pstdat
        foreign_currency       = int_display-waers
        local_currency         = 'EUR'
        type_of_rate           = 'M'
*       EXACT_DATE             = ' '
     IMPORTING
       exchange_rate           =  int_display-ukurs
*       FOREIGN_FACTOR          =
*       LOCAL_FACTOR            =
*       VALID_FROM_DATE         =
*       DERIVED_RATE_TYPE       =
*       FIXED_RATE              =
*       OLDEST_RATE_FROM        =
     EXCEPTIONS
       no_rate_found           = 1
       no_factors_found        = 2
       no_spread_found         = 3
       derived_2_times         = 4
       overflow                = 5
       zero_rate               = 6
       OTHERS                  = 7.

    IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    int_display-lcamount = int_display-ukurs * int_display-amount.
    ltot_hdr = ltot_hdr + int_display-lcamount.

    MODIFY int_display.
    CLEAR int_display.
  ENDLOOP.
*  loop at int_display.
*          int_calc-extdocnr = int_display-extdocnr.
*          int_calc-postdat = int_display-postdat.
*          int_calc-bukrs  = int_display-bukrs.
*          int_calc-waers  = int_display-waers.
*          append int_calc.
*          clear int_calc.
*    endloop.
*    loop at int_calc.
*     int_temp-extdocnr = int_calc-extdocnr.
*     int_temp-bukrs =   int_calc-bukrs.
*     append int_temp.
*     if int_temp-bukrs = ''.
*       delete int_temp INDEX sy-tabix.
*       endif.
*     CLEAR int_temp.
*     endloop.
*     sort int_temp by extdocnr.
*      loop at int_display where waers <> ''.
*        READ TABLE int_temp WITH KEY extdocnr = int_display-extdocnr BINARY SEARCH.
*         if sy-subrc = 0.
*          int_display-bukrs = int_temp-bukrs.
*          modify int_display." index sy-tabix.
*          endif.
*          endloop.
***---- end changes by amit
*CALL FUNCTION 'GET_PRINT_PARAMETERS'
*    IMPORTING
*      out_parameters       = print_parameters
*      valid                = valid_flag
*    EXCEPTIONS
*      invalid_print_params = 2
*      OTHERS               = 4.

  print_parameters-pdest = 'LOCL'.
  print_parameters-plist = sy-repid.
  print_parameters-prnew = 'X'.
  print_parameters-pexpi = '8'.
  print_parameters-linct = '65'.
  print_parameters-linsz = '255'.
  print_parameters-paart = 'X_65_255'.
  print_parameters-prsap = 'D'.
  print_parameters-prrec = sy-uname.
  print_parameters-prdsn = 'LIST1S'.
  print_parameters-ptype = 'TEXT'.
  print_parameters-armod = '1'.
  print_parameters-priot = '5'.
  print_parameters-prunx = 'D'.
  print_parameters-prkeyext = '1'.
  print_parameters-prchk = '8164'.

  NEW-PAGE PRINT ON PARAMETERS print_parameters
                          NO DIALOG .  " <<<<
  WRITE :/ sy-uline.
  WRITE :/ 'External Doc No', 'Doc. Type',
           'Doc. Date', 'Posting Date', 'SIS/Company',
           'SAP Company', 'Currency', 'Posting Period',
           'Header Text', 'Cust/Vendor No', 'G/L Account',
           'Doc. Amount', 'Site Code', 'Assig. Number',
           'Text', 'Amount', 'Error Msg', 'Exch. Rate' , 'Amount LC' ."*---change by amit
  WRITE :/ sy-uline.
  LOOP AT int_display.
    WRITE:/ int_display-extdocnr UNDER 'External Doc No',
            int_display-xblnr UNDER 'Doc Number',
            int_display-doctype UNDER 'Doc. Type',
            int_display-docdat UNDER 'Doc. Date',
            int_display-postdat UNDER 'Posting Date',
            int_display-comp UNDER 'SIS/Company',
            int_display-bukrs UNDER 'SAP Company',
            int_display-waers UNDER 'Currency',
            int_display-period UNDER 'Posting Period',
            int_display-headtxt UNDER 'Header Text',
            int_display-acctnum1 UNDER 'Cust/Vendor No',
            int_display-acctnum2 UNDER 'G/L Account',
            int_display-amount UNDER 'Doc. Amount',
            int_display-site UNDER 'Site Code',
            int_display-zuonr UNDER 'Assig. Number',
            int_display-sgtxt UNDER 'Text',
            int_display-wrbtr UNDER 'Amount',
           int_display-msgtxt UNDER 'Error Msg',
*---change by amit
           int_display-ukurs UNDER 'Exch. Rate',
           int_display-lcamount UNDER 'Amount LC'.
  ENDLOOP.
  NEW-PAGE PRINT OFF.

  MESSAGE 'Spool Request has been created ! ' TYPE 'S'.

  DATA: layout TYPE slis_layout_alv.

  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      i_program_name         = sy-repid
      i_internal_tabname     = 'INT_DISPLAY'
      i_inclname             = 'YFBI0200_TOP'
*      i_bypassing_buffer     = 'X'
    CHANGING
      ct_fieldcat            = ls_fieldcat
    EXCEPTIONS
      inconsistent_interface = 1
      program_error          = 2
      OTHERS                 = 3.

  LOOP AT ls_fieldcat INTO wa_fieldcat.
    CASE wa_fieldcat-fieldname.

      WHEN 'EXTDOCNR'.
        wa_fieldcat-reptext_ddic = 'External Doc No'.
        wa_fieldcat-seltext_l    = 'External Doc No'.
        wa_fieldcat-seltext_m    = 'External Doc No'.
        wa_fieldcat-seltext_s    = 'External Doc No'.
        wa_fieldcat-outputlen    = '16'.
        wa_fieldcat-key          = 'X'.
        wa_fieldcat-col_pos      = 1.
      WHEN 'XBLNR'.
        wa_fieldcat-reptext_ddic = 'Doc Number'.
        wa_fieldcat-seltext_l    = 'Doc Number'.
        wa_fieldcat-seltext_m    = 'Doc Number'.
        wa_fieldcat-seltext_s    = 'Doc Number'.
        wa_fieldcat-outputlen    = '16'.
        wa_fieldcat-key          = 'X'.
        wa_fieldcat-col_pos      = 1.



      WHEN 'DOCTYPE'.
        wa_fieldcat-reptext_ddic = 'Doc. Type'.
        wa_fieldcat-seltext_l    = 'Doc. Type'.
        wa_fieldcat-seltext_m    = 'Doc. Type'.
        wa_fieldcat-seltext_s    = 'Doc. Type'.
      WHEN 'DOCDAT'.
        wa_fieldcat-reptext_ddic = 'Doc. Date'.
        wa_fieldcat-seltext_l    = 'Doc. Date'.
        wa_fieldcat-seltext_m    = 'Doc. Date'.
        wa_fieldcat-seltext_s    = 'Doc. Date'.
      WHEN 'POSTDAT'.
        wa_fieldcat-reptext_ddic = 'Posting Date'.
        wa_fieldcat-seltext_l    = 'Posting Date'.
        wa_fieldcat-seltext_m    = 'Posting Date'.
        wa_fieldcat-seltext_s    = 'Posting Date'.
        wa_fieldcat-outputlen    = '13'.
      WHEN 'COMP'.
        wa_fieldcat-reptext_ddic = 'SIS/Company'.
        wa_fieldcat-seltext_l    = 'SIS/Company'.
        wa_fieldcat-seltext_m    = 'SIS/Company'.
        wa_fieldcat-seltext_s    = 'SIS/Company'.
      WHEN 'BUKRS'.
        wa_fieldcat-reptext_ddic = 'SAP Company'.
        wa_fieldcat-seltext_l    = 'SAP Company'.
        wa_fieldcat-seltext_m    = 'SAP Company'.
        wa_fieldcat-seltext_s    = 'SAP Company'.
        wa_fieldcat-key          = ' '.
      WHEN 'WAERS'.
        wa_fieldcat-reptext_ddic = 'Currency'.
        wa_fieldcat-seltext_l    = 'Currency'.
        wa_fieldcat-seltext_m    = 'Currency'.
        wa_fieldcat-seltext_s    = 'Currency'.
      WHEN 'PERIOD'.
        wa_fieldcat-reptext_ddic = 'Posting Period'.
        wa_fieldcat-seltext_l    = 'Posting Period'.
        wa_fieldcat-seltext_m    = 'Posting Period'.
        wa_fieldcat-seltext_s    = 'Posting Period'.
        wa_fieldcat-outputlen    = '14'.
      WHEN 'HEADTXT'.
        wa_fieldcat-reptext_ddic = 'Header Text'.
        wa_fieldcat-seltext_l    = 'Header Text'.
        wa_fieldcat-seltext_m    = 'Header Text'.
        wa_fieldcat-seltext_s    = 'Header Text'.
      WHEN 'ACCTNUM1'.
        wa_fieldcat-reptext_ddic = 'Cust/Vendor No'.
        wa_fieldcat-seltext_l    = 'Cust/Vendor No'.
        wa_fieldcat-seltext_m    = 'Cust/Vendor No'.
        wa_fieldcat-seltext_s    = 'Cust/Vendor No'.
        wa_fieldcat-outputlen    = '15'.
      WHEN 'ACCTNUM2'.
        wa_fieldcat-reptext_ddic = 'G/L Account'.
        wa_fieldcat-seltext_l    = 'G/L Account'.
        wa_fieldcat-seltext_m    = 'G/L Account'.
        wa_fieldcat-seltext_s    = 'G/L Account'.
      WHEN 'AMOUNT'.
        wa_fieldcat-reptext_ddic = 'Doc. Amount'.
        wa_fieldcat-seltext_l    = 'Doc. Amount'.
        wa_fieldcat-seltext_m    = 'Doc. Amount'.
        wa_fieldcat-seltext_s    = 'Doc. Amount'.
      WHEN 'SITE'.
        wa_fieldcat-reptext_ddic = 'Site Code'.
        wa_fieldcat-seltext_l    = 'Site Code'.
        wa_fieldcat-seltext_m    = 'Site Code'.
        wa_fieldcat-seltext_s    = 'Site Code'.
      WHEN 'ZUONR'.
        wa_fieldcat-reptext_ddic = 'Assig. Number'.
        wa_fieldcat-seltext_l    = 'Assig. Number'.
        wa_fieldcat-seltext_m    = 'Assig. Number'.
        wa_fieldcat-seltext_s    = 'Assig. Number'.
      WHEN 'SGTXT'.
        wa_fieldcat-reptext_ddic = 'Text'.
        wa_fieldcat-seltext_l    = 'Text'.
        wa_fieldcat-seltext_m    = 'Text'.
        wa_fieldcat-seltext_s    = 'Text'.
        wa_fieldcat-outputlen    = '30'.
      WHEN 'WRBTR'.
        wa_fieldcat-reptext_ddic = 'Amount'.
        wa_fieldcat-seltext_l    = 'Amount'.
        wa_fieldcat-seltext_m    = 'Amount'.
        wa_fieldcat-seltext_s    = 'Amount'.
      WHEN 'MSGTXT'.
        wa_fieldcat-reptext_ddic = 'Error Msg'.
        wa_fieldcat-seltext_l    = 'Error Msg'.
        wa_fieldcat-seltext_m    = 'Error Msg'.
        wa_fieldcat-seltext_s    = 'Error Msg'.
        wa_fieldcat-outputlen    = '60'.
      WHEN 'UKURS'.
        wa_fieldcat-reptext_ddic = 'Exch. Rate'.
        wa_fieldcat-seltext_l    = 'Exch. Rate'.
        wa_fieldcat-seltext_m    = 'Exch. Rate'.
        wa_fieldcat-seltext_s    = 'Exch. Rate'.
        wa_fieldcat-outputlen    = '20'.
      WHEN 'LCAMOUNT'.
        wa_fieldcat-reptext_ddic = 'Amount LC'.
        wa_fieldcat-seltext_l    = 'Amount LC'.
        wa_fieldcat-seltext_m    = 'Amount LC'.
        wa_fieldcat-seltext_s    = 'Amount LC'.
        wa_fieldcat-outputlen    = '20'.

    ENDCASE.
    MODIFY ls_fieldcat FROM wa_fieldcat.
  ENDLOOP.

  ls_event-name = slis_ev_top_of_page.
  ls_event-form = 'TOP_OF_PAGE'.
  APPEND ls_event TO events.

  ls_event-name = 'END_OF_LIST'."slis_ev_end_of_page.
  ls_event-form = 'END_OF_PAGE'.
  APPEND ls_event TO events.


  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
*      i_bypassing_buffer      = 'X'
*      i_buffer_active         = ' '
      i_callback_program      = sy-repid
*      i_callback_user_command = 'USER_COMMAND'
      it_fieldcat             = ls_fieldcat[]
*      IT_SORT                 = ws_sort[]
*      i_save                  = 'A'
*      is_variant              = import_variant
      it_events               = events[]
      is_layout               = ls_layout
    TABLES
      t_outtab                = int_display
    EXCEPTIONS
      program_error           = 1
      OTHERS                  = 2.


ENDFORM.                    " write_report

*-------------------------------------------------------------------*
* Form  TOP_OF_PAGE                                                 *
*-------------------------------------------------------------------*
* ALV Report Header                                                 *
*-------------------------------------------------------------------*
FORM top_of_page.
  WRITE :/ 'Data uploaded for FI Interface'.
ENDFORM.              "top_of_page

*-------------------------------------------------------------------*
* Form  END_OF_PAGE                                                 *
*-------------------------------------------------------------------*
* ALV Report Total for HDR items                                    *
*-------------------------------------------------------------------*
FORM end_of_page.

* data: gt_list_commentary     type slis_t_listheader.
* data: wa_gt_list_commentary  type slis_listheader.

  DATA : loc_comm_info(250) TYPE c.
  DATA : lloc_comm_info(250) TYPE c.
  DATA : loc_temp(25) TYPE c.
  DATA : lloc_temp(25) TYPE c.
  loc_temp = tot_hdr.
  lloc_temp = ltot_hdr.

  CONCATENATE 'Total Value for the HDR = ' loc_temp  INTO loc_comm_info .
  CONCATENATE 'Total Value for the HDR in Local Currency = ' lloc_temp INTO lloc_comm_info.
* write :/ 'Total Value for the HDR = ',tot_hdr .
  WRITE :/ loc_comm_info UNDER 'Amount'.
  WRITE :/ lloc_comm_info UNDER 'Amount LC'.



* wa_gt_list_commentary-typ  = 'A'.
** wa_gt_list_commentary-key  = 'Testrun' .
* write loc_comm_info  to
*        wa_gt_list_commentary-info .
* append wa_gt_list_commentary to gt_list_commentary.
*
* CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
*   EXPORTING
*     IT_LIST_COMMENTARY       = gt_list_commentary.
**    I_LOGO                   =
**    I_END_OF_LIST_GRID       =
**    I_ALV_FORM               =         .


ENDFORM.              "end_of_page
* End of Changes by bhavina ......REPORT yfbigl10 MESSAGE-ID yf.
INCLUDE yfbi0200_top.

*----------------------------------------------------------------------*
* Report            : YFBI0100.                                     *
* Author            : M. Sipprell         Date            10.30/2007   *
* MIS Req No        : WWI Interface       Version         4.6C   *
* Req Date Received : 06/24/1997          Correction No :  DEVK908364
* Requestor Ref No  :                                                  *
* Requestor Name    : Judy Hyde                                *
* Description       : Convert legacy system balances into documents    *
*                                                                      *
*----------------------------------------------------------------------*
*  Include ABAPS   :  YSBI0010                                         *
*                     YSBI0030                                         *
*   Called by       :                                                  *
*----------------------------------------------------------------------*
*                       CHANGE History.                                *
*----------------------------------------------------------------------*
* Change desc.      : provide validation cost center option that allow *
*                     to submit BDC session when invalid cost center   *
*                     detected.                                        *
*
* Change desc.      : add company code on error report when error      *
*                     detected for Cost center, Profit center and GL   *
*                     account.                                         *
*----------------------------------------------------------------------*
* Change desc.      : removed balance_gsber because this variable is   *
*                     not refreshed properly and create the balance    *
*                     entry from previouse business area.              *
*----------------------------------------------------------------------*
* Change desc.      : comment out field bbseg-pdummy_ke because it is no
*                     longer in use in 3.1I  Only used in 3.0E
*                     chg marked by TH 090299
*----------------------------------------------------------------------*
* Change desc.      : Replaced output file path with logical file name.*
*Change desc.       : 2 additional columns added to the report.
*                     1  Local Currency Amount (EUR).
*                     2  Currency Exchange rate posted.
*----------------------------------------------------------------------*
*change descGL account from ZWWI07  and customer determined from
*                  KNB1-ALTKN should be  used to read ZWWI08 for new revenue
*                   account if an entry is in ZWWI08.
*                  If not revenue account from ZWWI07 should be taken
*----------------------------------------------------------------------*
*  This program reads a sequential file from a PC or UNIX and formats  *
*  it to be processed by the SAP standard batch input program for      *
*  documents (RFBIBL00).                                               *
************************************************************************
*          - Chg field BBSEG-RKE_RKAUFN to BBSEG-RKE_RKAUFNR
*          - Delete line NODATA     TO BGR00-START
*          - Clean logic on init structure
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
*                        Input Parameters.                             *
*----------------------------------------------------------------------*

TYPE-POOLS: slis.

PARAMETERS:
  client        LIKE sy-mandt      DEFAULT sy-mandt NO-DISPLAY .

SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME TITLE text-001.
PARAMETERS:
  infile        LIKE rlgrap-filename DEFAULT 'C:\',
  filetype(1)   TYPE c DEFAULT 'P',
  outfile(60)   TYPE c DEFAULT '/usr/sap/trans/wwi_temp' LOWER CASE,
  budat         LIKE bkpf-budat   OBLIGATORY.


SELECTION-SCREEN END OF BLOCK a.

SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-002.
PARAMETERS:
    test         AS CHECKBOX DEFAULT ' ' ,
    group        LIKE bgr00-group   DEFAULT 'WWI-UPLOAD',
    zkeep        AS CHECKBOX DEFAULT 'X' ,
    bdc_nr       TYPE p           DEFAULT '500'      ,
    acc1         LIKE bsis-hkont OBLIGATORY
       DEFAULT '69999900' ,
    tcode        LIKE sy-tcode DEFAULT 'FB01'.
PARAMETERS:
  val_cc        AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK b.

*----------------------------------------------------------------------*
*                   Global Table Definitions.                          *
*----------------------------------------------------------------------*
TABLES:
    sscrfields,                        " Selection screen fields
    bgr00,
    bbkpf,
    bbseg,
    knb1,
    lfb1,
    t001,
    cepc,
    csks,
    ska1,
    skb1,
    varid,
    tbsl,
    tcurc,
    t007a,
    t004f,
    t003.
TABLES:
    zwwi01
  , zwwi02
  , zwwi03
  , zwwi05
  , zwwi06
  , zwwi07
  , zwwi08,
    zfiinterface.
*----------------------------------------------------------------------*
*                   Global Data Definitions.                           *
*----------------------------------------------------------------------*
DATA:
   l_repid          LIKE syst-repid,                "LL 02/28/03 ADD
   msg_text(50)     TYPE c,
   file_ok(1)       TYPE c VALUE '1',
   first_time(1)    TYPE c VALUE '1',
   balance_entry(1) TYPE c VALUE '0',
   records_read     TYPE i,
   current_record   TYPE i,
   end_indicator(1) TYPE c VALUE '/',
   nodata(1)        TYPE c VALUE '/',
   sub_total(15)    TYPE p DECIMALS 2 VALUE 0,
   tot_hdr(15)      TYPE p DECIMALS 2 VALUE '0.00'," for calculating the total.
   lsub_total(15)    TYPE p DECIMALS 2 VALUE 0,
   ltot_hdr(15)      TYPE p DECIMALS 2 VALUE '0.00'," for calculating the total.
*   be_dummy         like bbseg-dummy,
   be_dummy         LIKE bbseg-dummyx,
*   be_prodper         LIKE bbseg-prodper,

   be_sgtxt         LIKE bbseg-sgtxt,
   be_wrbtr         LIKE bbseg-wrbtr,
   be_newbs         LIKE bbseg-newbs,
   previous_gsber   LIKE bbseg-gsber,
   balance_gsber    LIKE bbseg-gsber,
   temp_barea       LIKE bbseg-gsber,
   temp_ccode       LIKE bbkpf-bukrs,
   temp_traty(3),
   temp_txjcd       LIKE bbseg-txjcd,
   num_kostl(10)    TYPE n,
   num_prctr(10)    TYPE n,
   valid_flag(1)    TYPE c,
   error_flag(1)    TYPE c,
   error_flag_cc(1) TYPE c,                                 "JC 2/09/98
   temp_file_path   LIKE ibipparms-path,
   default_gsber    LIKE bbseg-gsber    VALUE '    ',       "RK051397
   newfile(45)      TYPE c,
   unix_cmd(80)     TYPE c.

DATA:
      x_buper          LIKE t009b-poper
    , x_gjahr          LIKE t009b-bdatj
    , hold_shkzg       LIKE tbsl-shkzg
    , hold_koart       LIKE tbsl-koart
    , hold_wwiktopl(4)
    .
*-------------------------------------------------------------------*
*                   Constants                                          *
*----------------------------------------------------------------------*
DATA:
   userid                LIKE sy-uname    VALUE 'BATCHUSER',
   true(1)               TYPE c           VALUE '1',
   false(1)              TYPE c           VALUE '0',
   batchuser             LIKE sy-uname    VALUE 'BATCHUSER',
*  bal_entry_act         like bbseg-dummy value '69999900'  ,
   on(1)                                  VALUE 'X'   ,
   off(1)                                 VALUE ' '   ,
   c_header(3)                            VALUE 'HDR' ,
   c_item(3)                              VALUE 'ITM' ,
   c_tax(3)                               VALUE 'ITV'  .

*----------------------------------------------------------------------*
*                   Internal Table Definition.                         *
*----------------------------------------------------------------------*
DATA: BEGIN OF x_file OCCURS 0,
       record(245),
      END   OF x_file .

DATA: BEGIN OF in_file OCCURS 0,
        traty(3),
        cisref(30),
        ifref(12),
        doctype(4),
*       docnum(10),
        extdocnr(16),
        docdat(8),
        postdat(8),
        comp(10),
        period(6),
        waers(5),
        headtxt(25),
        newbs(2),
        acctnum(8),
        amount(15),
        site(3),
        zuonr(18),
        sgtxt(50),
        centre(10),
        vatcode(2),
        bukrs   LIKE t001-bukrs,
        wwiktopl(4) ,
        blart   LIKE bkpf-blart,
        xblnr   LIKE bkpf-xblnr,
        newko   LIKE bbseg-newko,
        bldat   LIKE bkpf-bldat,
        budat   LIKE bkpf-budat,
        monat   LIKE bkpf-monat,
        wrbtr   LIKE bbseg-wrbtr,
        kostl   LIKE bseg-kostl,
        prctr   LIKE bseg-prctr,
        mwskz   LIKE bseg-mwskz,
        prodper(8),
      END   OF in_file .

*data: begin of in_file occurs 0,
*        traty(3),
*        bldat like bbkpf-bldat,        " Document date
*        blart like bbkpf-blart,        " Document type
*        bukrs like bbkpf-bukrs,        " Company code
*        budat like bbkpf-budat,        " Posting date
*        monat like bbkpf-monat,        " Fiscal month
*        waers like bbkpf-waers,        " Currency key
*        bktxt like bbkpf-bktxt,        " Document header text
*        newbs like bbseg-newbs,        " Posting key
*        dummy like bbseg-dummy,        " Account
*        wrbtr like bbseg-wrbtr,        " Amount in document currency
*        mwskz like bbseg-mwskz,        " Tax code
*        kostl like bbseg-kostl,        " Cost center
*        prctr like bbseg-prctr,        " Profit center
*        sgtxt like bbseg-sgtxt,        " Line item text
*        zuonr like bbseg-zuonr,        " Allocation code
*        xblnr like bbkpf-xblnr.        " Reference Document Number
*data: end of in_file.
*
DATA: BEGIN OF wa,
        char1(250)   TYPE c,
        char2(250)   TYPE c,
        char3(250)   TYPE c,
        char4(250)   TYPE c,
        char5(250)   TYPE c,
        char6(250)   TYPE c,
        char7(250)   TYPE c,
        char8(250)   TYPE c,
        char9(250)   TYPE c,
        char10(250)  TYPE c.   "LL 04/02/03 ADD - BBSEG = 2412 chars
DATA: END OF wa.

DATA: BEGIN OF error_tab OCCURS 0,
        recno       LIKE sy-tabix,
        msgtxt(60)  TYPE c,
      END OF error_tab.
DATA:    BEGIN OF i_bbkpf.
        INCLUDE STRUCTURE bbkpf.       " Belegkopf
DATA:    END OF i_bbkpf.

DATA:    BEGIN OF i_bbseg.
        INCLUDE STRUCTURE bbseg.    " Belegsegment
DATA:    END OF i_bbseg.

DATA:    BEGIN OF nametab OCCURS 120.
        INCLUDE STRUCTURE dntab.
DATA:    END OF nametab.

DATA: BEGIN OF i_zwwi01 OCCURS 0.
        INCLUDE STRUCTURE zwwi01.
DATA: END   OF i_zwwi01 .

DATA: BEGIN OF i_zwwi07 OCCURS 0.
        INCLUDE STRUCTURE zwwi07.
DATA: END   OF i_zwwi07 .


DATA: BEGIN OF i_zwwi05 OCCURS 0.
        INCLUDE STRUCTURE zwwi05.
DATA: END   OF i_zwwi05 .

DATA: BEGIN OF i_zwwi06 OCCURS 0.
        INCLUDE STRUCTURE zwwi06.
DATA: END   OF i_zwwi06 .

DATA: h_t001   TYPE t001   .

DATA:    char(61)  TYPE c.             " Hilfsfeld
FIELD-SYMBOLS: <f1> .
*----------------------------------------------------------------------*
*                        ALV Declarations.
*----------------------------------------------------------------------*

DATA  : events TYPE slis_t_event WITH HEADER LINE,
        ls_layout  TYPE slis_layout_alv,
        g_status TYPE slis_formname VALUE 'STANDARD_02',
        g_variant LIKE disvariant,
        g_repid LIKE sy-repid,
        gt_fieldcat TYPE slis_t_fieldcat_alv,
        ls_fieldcat LIKE gt_fieldcat,
        wa_fieldcat TYPE slis_fieldcat_alv,
        ls_event TYPE LINE OF slis_t_event.

DATA: refno TYPE char16.
DATA:  zfiinter TYPE zfiinterface OCCURS 0 WITH HEADER LINE.

"END LL 04/02/03 ADD
*----------------------------------------------------------------------*
*                        Include Definitions.                          *
*----------------------------------------------------------------------*
INCLUDE:
  ysbi0010.                           " calls to BI function modules
INCLUDE ysbi0030.                      " calls to job function modules

*----------------------------------------------------------------------*
*                  MAIN PROGRAM                                        *
*----------------------------------------------------------------------*

AT SELECTION-SCREEN ON VALUE-REQUEST FOR infile.

  CLEAR temp_file_path.
  l_repid = sy-repid.                             "LL 02/28/03 ADD
* Extracting Of The Selection Screen Input File Name.
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      program_name  = l_repid
      dynpro_number = sy-dynnr
      field_name    = 'PATH'
    IMPORTING
      file_name     = temp_file_path.

  MOVE temp_file_path TO infile.

AT SELECTION-SCREEN OUTPUT.
*----------------------------------------------------------------------*
START-OF-SELECTION.

  IF filetype = 'P'.
    PERFORM read_pc_file.
  ELSEIF filetype = 'U'.
    PERFORM read_un_file.
  ELSE.
    MESSAGE e017.
  ENDIF.

  SELECT * FROM zwwi01 INTO TABLE i_zwwi01 .
  SORT i_zwwi01 .
  SELECT * FROM zwwi05 INTO TABLE i_zwwi05 .
  SORT i_zwwi05 .
  SELECT * FROM zwwi06 INTO TABLE i_zwwi06 .
  SORT i_zwwi06 .

* perform check_subtotals.
  PERFORM setup_file.
*----------------------------------------------------------------------*
END-OF-SELECTION.

  CHECK file_ok = true.
  LOOP AT in_file.
    MOVE: in_file-amount  TO in_file-wrbtr .
*    move in_file-kostl to num_kostl.
*    move num_kostl to in_file-kostl.
    current_record = sy-tabix.

    IF temp_ccode NE in_file-comp
     AND  in_file-comp <> space .
      .   " if company code changes.
      first_time = true.               " to create header/detail item.
      CLEAR records_read.
      IF balance_entry EQ true.        "if code change already occurred
        PERFORM create_balance_entry.
        PERFORM fill_balfile.
        balance_entry = false.
      ELSEIF balance_entry EQ false.
        IF sub_total NE 0.
          MOVE current_record TO error_tab-recno.
          CONCATENATE 'Company code' temp_ccode 'does not balance.'
                           INTO error_tab-msgtxt SEPARATED BY space.
          APPEND error_tab.
          error_flag = 'Y'.                     "Joyce Chang 2/09/98
          CLEAR sub_total.
        ENDIF.
      ENDIF.
      temp_ccode = in_file-comp .
    ENDIF.

    IF in_file-traty = 'HDR'.          " if company code changes.
      first_time = true.               " to create header/detail item.
      CLEAR records_read.
      IF balance_entry EQ true.        "if code change already occurred
        PERFORM create_balance_entry.
        PERFORM fill_balfile.
        balance_entry = false.
      ELSEIF balance_entry EQ false.
        IF sub_total NE 0.
          MOVE current_record TO error_tab-recno.
          CONCATENATE 'Document' in_file-xblnr 'does not balance.'
                           INTO error_tab-msgtxt SEPARATED BY space.
          APPEND error_tab.
          error_flag = 'Y'.                     "Joyce Chang 2/09/98
          CLEAR sub_total.
        ENDIF.
      ENDIF.
      temp_traty = in_file-traty.
    ENDIF.

* balancing entry
    IF records_read = bdc_nr .
      CLEAR records_read.
      balance_entry = true.
      PERFORM create_balance_entry.
      PERFORM fill_balfile.
      first_time = true.
    ENDIF.

* validation and conversion routine
    PERFORM check_outfile.

* create bdc internal table
    PERFORM fill_outfile.

* running total for balancing entry
*    clear tbsl.
*    select single * from tbsl where bschl = in_file-newbs.
    IF tbsl-shkzg EQ 'S'.
      sub_total = sub_total + in_file-wrbtr.
    ELSEIF tbsl-shkzg EQ 'H'.
      sub_total = sub_total - in_file-wrbtr.
    ENDIF.

    records_read = records_read + 1.
    MODIFY in_file.
  ENDLOOP.

  IF balance_entry = true OR
    sub_total <> 0.
    PERFORM create_balance_entry.
    PERFORM fill_balfile.
  ENDIF.

*Commented by michelle...bhavina made today
* Changes done by Bhavina ....
  PERFORM next_step.
  PERFORM write_report.
*perform file_backup.




* add Validate Cost center option to allow to submit BDC session when  *
* errors detected.                                                     *
*----------------------------------------------------------------------*
*  IF error_flag_cc = 'Y'.
*    CASE val_cc.
*      WHEN 'X'.
*        PERFORM write_error_report.
*      WHEN ' '.
*        PERFORM write_error_report.
**        if error_flag = ' '.
** message i100 - invalid cost center found.
*        MESSAGE i100.
*        PERFORM next_step.
*        PERFORM file_backup.
**        endif.
*    ENDCASE.
*  ELSE.
**    if error_flag = ' '.
*    PERFORM next_step.
*    PERFORM file_backup.
**    else.
*    PERFORM write_error_report.
**    endif.
*  ENDIF.

*----added
* Commented by bhavina ....
  IF error_flag_cc = 'Y'.
    CASE val_cc.
      WHEN 'X'.
*        perform write_error_report.
      WHEN ' '.
*        perform write_error_report.
        IF error_flag = ' '.
* message i100 - invalid cost center found.
          MESSAGE i100.
          PERFORM next_step.
*          perform file_backup.
        ENDIF.
    ENDCASE.
  ELSE.
    IF error_flag = ' '.
      PERFORM next_step.
*perform file_backup.
    ELSE.
*      perform write_error_report.
    ENDIF.
  ENDIF.
* comment ended....


*&---------------------------------------------------------------------*
*&      Form  READ_UN_FILE
*&---------------------------------------------------------------------*
*   Read the input file from UNIX                                      *
*----------------------------------------------------------------------*

FORM read_un_file.

  OPEN DATASET infile FOR INPUT IN TEXT MODE MESSAGE msg_text.

  IF sy-subrc NE 0.
    MESSAGE i002 WITH sy-subrc 'open' infile.
    MESSAGE i003 WITH msg_text.
    file_ok = false.
    EXIT.
  ENDIF.

  DO.

    READ DATASET infile INTO in_file.

    IF sy-subrc = 4.                   " Last record read
      EXIT.
    ELSEIF sy-subrc NE 0.
      MESSAGE i002 WITH sy-subrc 'read' infile.
      file_ok = false.
      EXIT.
    ENDIF.
    MOVE in_file-kostl TO num_kostl.
    MOVE num_kostl TO in_file-kostl.
    MOVE budat TO in_file-postdat.
    APPEND in_file.

  ENDDO.

  CLOSE DATASET infile.

  IF sy-subrc NE 0.
    MESSAGE i002 WITH sy-subrc 'close' infile.
    file_ok = false.
    EXIT.
  ENDIF.

ENDFORM.                               " READ_UN_FILE
*&---------------------------------------------------------------------*
*&      Form  READ_PC_FILE
*&---------------------------------------------------------------------*
*  Read the input file from the current PC                            *
*----------------------------------------------------------------------*
FORM read_pc_file.

  DATA: file_len TYPE i,
        file_typ LIKE rlgrap-filetype VALUE 'DAT'.          "MD07/28/97

  CALL FUNCTION 'WS_UPLOAD'
    EXPORTING
      filename            = infile
      filetype            = file_typ
    IMPORTING
      filelength          = file_len
    TABLES
      data_tab            = x_file
    EXCEPTIONS
      conversion_error    = 1
      file_open_error     = 2
      file_read_error     = 3
      invalid_table_width = 4
      invalid_type        = 5
      no_batch            = 6
      unknown_error       = 7
      OTHERS              = 8.

  IF sy-subrc NE 0.
    MESSAGE i002 WITH sy-subrc 'upload' infile.
    MESSAGE i003 WITH msg_text.
    file_ok = false.
    EXIT.
  ENDIF.
  MOVE x_file[] TO in_file[] .
ENDFORM.                               " READ_PC_FILE
*&---------------------------------------------------------------------*
*&      Form  SETUP_FILE
*&---------------------------------------------------------------------*
*       text                                                           *
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM setup_file.

  OPEN DATASET outfile FOR OUTPUT IN TEXT MODE MESSAGE msg_text.

  IF sy-subrc NE 0.
    MESSAGE i002 WITH sy-subrc 'open' outfile.
    MESSAGE i003 WITH msg_text.
    file_ok = false.
    EXIT.
  ENDIF.

  CLEAR: bgr00.

* Populate The Batch Input Session Parameters.
  MOVE: '0'        TO bgr00-stype,
        group      TO bgr00-group,
        nodata     TO bgr00-nodata,
        sy-mandt   TO bgr00-mandt,
        batchuser  TO bgr00-usnam .
*        NODATA     TO BGR00-START,       "LL 03/26/03 DEL
  IF zkeep = 'X' .
    MOVE zkeep      TO bgr00-xkeep.
  ELSE.
    MOVE nodata     TO bgr00-xkeep.
  ENDIF.
  MOVE bgr00      TO wa.

  TRANSFER wa TO outfile.
  IF sy-subrc NE 0.
    MESSAGE e002 WITH sy-subrc 'write' outfile.
  ENDIF.

* Initialise the document input structures.
  PERFORM init_structures USING 'BBKPF' i_bbkpf nodata.
  PERFORM init_structures USING 'BBSEG' i_bbseg nodata.

ENDFORM.                               " SETUP_FILE
*&---------------------------------------------------------------------*
*&      Form  FILL_OUTFILE
*&---------------------------------------------------------------------*
*  Fills the batch input record structures                             *
*----------------------------------------------------------------------*
FORM fill_outfile.

  IF first_time = true.
    first_time = false.
* Clear Input Structures.
    bbkpf = i_bbkpf.

    bbkpf-stype = '1'.
    bbkpf-tcode = tcode .
    WRITE in_file-bldat TO bbkpf-bldat. " Document date
    IF budat NE space.
      WRITE budat TO bbkpf-budat. " Posting  date
    ENDIF.
    bbkpf-blart = in_file-blart.       " Document type
    bbkpf-bukrs = in_file-bukrs.       " Company code
    bbkpf-monat = in_file-monat.       " Fiscal month
    bbkpf-waers = in_file-waers.       " Currency key
*    bbkpf-bktxt = in_file-zuonr.    " External Doc Number (JOBREF)

    bbkpf-bktxt = in_file-zuonr.       " External Doc Number (JOBREF)
    bbkpf-xblnr = in_file-xblnr.       " DOCTYPE/DOCNUM from input file
*   bbkpf-bldat = in_file-bldat.       " Date
*   bbkpf-budat = in_file-budat.       " Date

    PERFORM check_bbkpf.
    wa = bbkpf.

    TRANSFER wa TO outfile.
    IF sy-subrc NE 0.
      MESSAGE e002 WITH sy-subrc 'write' outfile.
    ENDIF.

    CLEAR : wa,in_file-bukrs.

  ENDIF.

  bbseg = i_bbseg.
  bbseg-stype = '2'.
  bbseg-tbnam = 'BBSEG'.
  bbseg-newbs = in_file-newbs.         " Posting key
  bbseg-newko = in_file-newko.         " Account
  bbseg-prodper = nodata.         " Production Period

  IF NOT in_file-bukrs IS INITIAL.
    bbseg-newbk = in_file-bukrs.
  ENDIF.

* CGunter - 2007/12/17  - Make sure NEWKO is not initial.
  IF bbseg-newko IS INITIAL.
    bbseg-newko = 'XXXXXXXXXX'.
  ENDIF.



  bbseg-wrbtr = in_file-wrbtr.         " Amount
  IF in_file-mwskz <> space.
    bbseg-mwskz = in_file-mwskz.         " Tax code
  ENDIF.
*  bbseg-txjcd = temp_txjcd.            " Tax jurisdiction code
*  clear temp_txjcd.
*
*  if ska1-xbilk = space and
*     in_file-kostl ne space and
*     in_file-kostl ne '0000000000'.
*    bbseg-kostl = in_file-kostl.       " Cost centre
*  endif.

*  bbseg-gsber = temp_barea.            " Business area
*  if temp_barea ne space.                                   " RK052897
*    default_gsber = temp_barea.                             " RK052897
*  endif.                                                    " RK052897
*  previous_gsber = temp_barea.         " Business area
*  move space to temp_barea.            " 12/18/96 MODIFICATION
  bbseg-kostl = in_file-kostl.         " Profit centre
  bbseg-prctr = in_file-prctr.         " Profit centre
  bbseg-zuonr = in_file-headtxt.
  bbseg-sgtxt = in_file-sgtxt.



  " Line item text
*  bbseg-zuonr = in_file-headtxt. "commented
  bbseg-zuonr = in_file-headtxt.
  PERFORM check_bbseg.

*  wa = bbseg.
*  TRANSFER wa TO outfile.
  TRANSFER bbseg TO outfile.


  IF sy-subrc NE 0.
    MESSAGE e002 WITH sy-subrc 'write' outfile.
  ENDIF.

ENDFORM.                               " FILL_OUTFILE
*&---------------------------------------------------------------------*
*&      Form  FILL_BALFILE
*&---------------------------------------------------------------------*
*  Fills the batch input record structure for balancing entry          *
*----------------------------------------------------------------------*
FORM fill_balfile.

  bbseg = i_bbseg.

  bbseg-stype = '2'.
  bbseg-tbnam = 'BBSEG'.
  bbseg-newbs = be_newbs.              " Posting key
  bbseg-newko = be_dummy.              " Account
  bbseg-wrbtr = be_wrbtr.              " Amount

*  if previous_gsber = space.         " Business area
*    bbseg-gsber = default_gsber.
*  else.
*    bbseg-gsber = previous_gsber.
*  endif.
  bbseg-sgtxt = be_sgtxt.              " Line item text
  bbseg-zuonr = in_file-headtxt.
  PERFORM check_bbseg.
  wa = bbseg.

  TRANSFER wa TO outfile.
  IF sy-subrc NE 0.
    MESSAGE e002 WITH sy-subrc 'write' outfile.
  ENDIF.

ENDFORM.                               " FILL_balFILE
*&---------------------------------------------------------------------*
*&      Form  CHECK_OUTFILE
*&---------------------------------------------------------------------*
*   Perform validation checks on all fields in incoming file           *
*----------------------------------------------------------------------*
FORM check_outfile.

  DATA: num_prctr(10) TYPE n,
        num_kostl(10) TYPE n.

* perform conversions on Header records
*---- Header Start ----------------------------------------------------*
  IF in_file-traty = c_header .
* Convert company code
    PERFORM convert_ccode    USING
             in_file-comp  .

* Check document date
*   if in_file-bldat is initial.
    IF in_file-docdat = space   .
      MOVE: current_record TO error_tab-recno,
            'Document date is blank.' TO error_tab-msgtxt.
      APPEND error_tab.
      error_flag = 'Y'.                          "Joyce Chang 2/09/98
    ELSE.
      PERFORM check_valid_date USING in_file-docdat.
      IF sy-subrc = 0.
        MOVE in_file-docdat TO in_file-bldat .
      ENDIF.
    ENDIF.

* Check posting date
*   if in_file-budat is initial.
    IF in_file-postdat = space   .
      MOVE: current_record TO error_tab-recno,
            'Posting date is blank.' TO error_tab-msgtxt.
      APPEND error_tab.
*   error_flag = true.
      error_flag = 'Y'.                            "Joyce Chang 2/09/98
    ELSE.
      MOVE budat TO in_file-postdat.
      PERFORM check_valid_date USING in_file-postdat.
      IF sy-subrc = 0.
        MOVE in_file-postdat TO in_file-budat .
      ENDIF.
    ENDIF.

* check fiscal period.
    PERFORM determine_period.
* Check fiscal month
    IF in_file-period+4(2) LT '01' OR
       in_file-period+4(2) GT '12'.
      MOVE current_record TO error_tab-recno.
      CONCATENATE 'Invalid fiscal month' in_file-period
                        INTO error_tab-msgtxt SEPARATED BY space.
      APPEND error_tab.
*   error_flag = true.
      error_flag = 'Y'.                            "Joyce Chang 2/09/98
    ENDIF.

    IF in_file-monat <> in_file-period+4(2) .
      MOVE current_record TO error_tab-recno.
      CONCATENATE 'Period in file <> Fiscal Month'
      in_file-period in_file-monat
                        INTO error_tab-msgtxt SEPARATED BY space.
      APPEND error_tab.
      error_flag = 'Y'.                            "Joyce Chang 2/09/98
    ENDIF.
* Check document type
    READ TABLE i_zwwi05 WITH KEY
     bukrs    = h_t001-bukrs
     doctype  = in_file-doctype.

*    select single * from zwwi05
*     where bukrs   = h_t001-bukrs
*     and   doctype = in_file-doctype.
*
    IF sy-subrc = 0 .
      MOVE i_zwwi05-blart  TO in_file-blart .
    ELSE.
      MOVE current_record TO error_tab-recno.
      CONCATENATE 'Invalid document type' in_file-doctype
                           INTO error_tab-msgtxt SEPARATED BY space.
      APPEND error_tab.
*   error_flag = true.
      error_flag = 'Y'.                            "Joyce Chang 2/09/98
    ENDIF.

* Check currency key
    TRANSLATE in_file-waers TO UPPER CASE. "CGunter 2008/01/16
    SELECT SINGLE * FROM tcurc WHERE waers = in_file-waers.
    IF sy-subrc NE 0.
      MOVE current_record TO error_tab-recno.
      CONCATENATE 'Invalid currency key' in_file-waers
                        INTO error_tab-msgtxt SEPARATED BY space.
      APPEND error_tab.
*   error_flag = true.
      error_flag = 'Y'.                           "Joyce Chang 2/09/98
    ENDIF.

* fill BKPF-XBLNR with the external document type & invoice doc nr.
    CONCATENATE in_file-doctype '/' in_file-extdocnr INTO in_file-xblnr.
* get the account type, so that later when the tax code is converted,
* we use the correct one for customer or vendor.
    SELECT SINGLE * FROM tbsl
    WHERE bschl = in_file-newbs.
    IF sy-subrc = 0 .
      MOVE tbsl-koart TO hold_koart.
    ELSE.
      MOVE current_record TO error_tab-recno.
      CONCATENATE 'Invalid posting key' in_file-newbs
                             INTO error_tab-msgtxt SEPARATED BY space.
      APPEND error_tab.
      error_flag = 'Y'.                           "Joyce Chang 2/09/98
    ENDIF.
  ENDIF .  "header

*---- Header End   ----------------------------------------------------*

* check these for every record.
* Check posting key
  CLEAR tbsl.
  IF in_file-newbs <> space  .
    SELECT SINGLE * FROM tbsl
    WHERE bschl = in_file-newbs.
    IF sy-subrc = 0 .
      IF tbsl-koart NE 'D' AND tbsl-koart NE 'S' AND tbsl-koart NE 'K' .
        MOVE current_record TO error_tab-recno.
        CONCATENATE 'Invalid posting key' in_file-newbs
                               INTO error_tab-msgtxt SEPARATED BY space.
        APPEND error_tab.
        error_flag = 'Y'.                           "Joyce Chang 2/09/98
      ELSE.
        MOVE tbsl-shkzg TO hold_shkzg .
      ENDIF.
    ELSE. "(subrc <> 0)
      MOVE current_record TO error_tab-recno.
      CONCATENATE 'Invalid posting key' in_file-newbs
                             INTO error_tab-msgtxt SEPARATED BY space.
      APPEND error_tab.
      error_flag = 'Y'.                           "Joyce Chang 2/09/98
    ENDIF.
  ELSE. "(in_file-newbs = initial)
    MOVE 'S' TO tbsl-koart .
    IF hold_shkzg = 'S' .
      MOVE '50' TO in_file-newbs.
    ELSEIF hold_shkzg = 'H' .
      MOVE '40' TO in_file-newbs.
    ENDIF.
  ENDIF.

* Check account number
  CASE tbsl-koart .
    WHEN 'D' .
      PERFORM check_sub-ledg_acct USING 'D' .
    WHEN 'K' .
      PERFORM check_sub-ledg_acct USING 'K' .
    WHEN OTHERS .
      PERFORM check_account_no.
  ENDCASE .
* Check amount
  IF in_file-wrbtr CN '0123456789. '.
    MOVE current_record TO error_tab-recno.
    CONCATENATE 'Invalid amount' in_file-wrbtr
                           INTO error_tab-msgtxt SEPARATED BY space.
    APPEND error_tab.
    error_flag = 'Y'.                            "Joyce Chang 2/09/98
  ENDIF.

* check whether cost or profit centre required in SAP.
  IF in_file-centre <> space.
    IF in_file-traty NE c_tax.

      PERFORM convert_centre.
    ELSE.
      MOVE: nodata  TO in_file-kostl,
            nodata  TO in_file-prctr.
    ENDIF.
  ENDIF.
* convert tax code. For ITV (tax) lines, this will also check
* the account number
  IF in_file-vatcode <> space.
    PERFORM tax_line .
  ENDIF.

** Cost Center/Profit Center (Input file will always have Cost center)
*    select single * from t004f
*                    where bukrs = 'SLBF'
*                    and   fstag = skb1-fstag.
*    if sy-subrc eq 0.
*      if t004f-faus1+9(1) = '+'.
** Cost center required
*        perform check_cost_center.
*        clear in_file-prctr.
*      elseif t004f-faus1+41(1) = '+'.
** Profit Center required
*        perform check_profit_center.
*      elseif t004f-faus1+9(1) = '.'.
** Cost center optional
*        perform check_cost_center.
*        clear in_file-prctr.
*      elseif t004f-faus1+41(1) = '.'.
** Profit Center optional
*        perform check_profit_center.
*      else.
****  Clear the field
**     clear: gldata-kostl, gldata-prctr.
*      endif.
*    endif.

** Check Balance Sheet item
*    if ska1-xbilk = 'X'.
*      perform check_bs_item.
*    endif.

** Tax jurisdiction code
*    if in_file-prctr ne space and
*       in_file-prctr ne '0000000000'.
*      select * from csks where
*          kokrs = '0100' and
**       kostl = in_file-prctr and
*          kostl = in_file-kostl and
*          datbi ge sy-datum and
*          datab le sy-datum.
*        exit.
*      endselect.
*      if sy-subrc eq 0.
** Profit center is not blank and tax code is not blank
*        if in_file-mwskz ne space.
*          temp_txjcd = csks-txjcd.
*        endif.
** B/S indicator is not on and profit center is not blank
*        if ska1-xbilk eq space.
*          temp_barea = csks-gsber.
*        endif.
*      endif.
*      clear in_file-kostl.          "since Profit center has a value
*    endif.


ENDFORM.                               " CHECK_OUTFILE

*&---------------------------------------------------------------------*
*&      Form  CHECK_ACCOUNT_NO
*&---------------------------------------------------------------------*
FORM check_account_no.
  DATA:subrc TYPE sy-subrc.
  UNPACK in_file-centre TO in_file-centre.
  IF in_file-acctnum <> space .
* first, try to find with the cost centre in the input file

    SELECT SINGLE * FROM zwwi07
           WHERE  wwiktopl  = hold_wwiktopl
           AND    oldsaknr  = in_file-acctnum
           AND    oldkostl  = in_file-centre .
    IF sy-subrc = 0.
      subrc = sy-subrc.
      SELECT SINGLE * FROM zwwi08
        WHERE kunnr = knb1-kunnr
        AND   hkont = zwwi07-newsaknr
        AND   bukrs = knb1-bukrs.
      IF sy-subrc = 0.
        MOVE zwwi08-zkont TO in_file-newko .
      ELSEIF subrc = 0.
        MOVE zwwi07-newsaknr TO in_file-newko.
      ENDIF.
    ELSE.


*    IF sy-subrc = 0 .
*      MOVE zwwi07-newsaknr TO in_file-newko .
*    ELSE.
** if that not found, then without the cost centre.
*      SELECT single * FROM  ZWWI07
*             WHERE  WWIKTOPL  = hold_wwiktopl
*             AND    OLDSAKNR  = in_file-acctnum
*             AND    OLDKOSTL  = ' '            .
*      if sy-subrc = 0 .
*        move zwwi02-newsaknr to in_file-newko .
*      else.

      MOVE current_record TO error_tab-recno.
      CONCATENATE 'Account' in_file-acctnum
                  'Company code: ' in_file-bukrs        "JChang 4/2/98
                  'not found in table ZWWI07'
                  INTO error_tab-msgtxt SEPARATED BY space.
      APPEND error_tab.
      error_flag = 'Y'.                            "Joyce Chang 2/09/98
    ENDIF.
*    endif.
  ENDIF.

ENDFORM.                               " CHECK_ACCOUNT_NO
*&---------------------------------------------------------------------*
*&      Form  CHECK_VALID_DATE
*&---------------------------------------------------------------------*
*   Checks an incoming date for validity                               *
*----------------------------------------------------------------------*
FORM check_valid_date USING date_in.
*
  DATA: x_date LIKE sy-datum.

  MOVE date_in TO x_date .
  CALL FUNCTION 'BUR_CHECK_VALID_DATES'
    EXPORTING
      i_date_from      = x_date
      i_date_to        = x_date
    EXCEPTIONS
      date_not_allowed = 1
      OTHERS           = 2.
  IF sy-subrc <> 0.
    MOVE current_record TO error_tab-recno.
    CONCATENATE 'Invalid date' x_date
                         INTO error_tab-msgtxt SEPARATED BY space.
    APPEND error_tab.
    error_flag = 'Y'.
  ENDIF.


ENDFORM.                               " CHECK_VALID_DATE
*&---------------------------------------------------------------------*
*&      Form  CREATE_BALANCE_ENTRY
*&---------------------------------------------------------------------*
*   Create a dummy entry in the amount of total processed so far       *
*----------------------------------------------------------------------*
FORM create_balance_entry.

  be_dummy = acc1 .            " Balancing entry account

  IF sub_total < 0.
    be_wrbtr = sub_total * ( -1 ).
  ELSE.
    be_wrbtr = sub_total.
  ENDIF.

  be_sgtxt = 'Balancing Entry'.

  IF sub_total < 0.
    be_newbs = '40'.                   " Debit
  ELSE.
    be_newbs = '50'.                   " Credit
  ENDIF.

  CLEAR sub_total.

ENDFORM.                               " CREATE_BALANCE_ENTRY
*&---------------------------------------------------------------------*
*&      Form  NEXT_STEP
*&---------------------------------------------------------------------*
*  Close the output dataset and call RFBIBL00 to process it.           *
*----------------------------------------------------------------------*
FORM next_step.

  DATA: i_list TYPE STANDARD TABLE OF abaplist.

  CLOSE DATASET outfile.
  CLEAR wa.
*  IF test = off .
*    SUBMIT rfbibl00 exporting list to memory
*    WITH  ds_name     = outfile
*    WITH  fl_check    = space
*    WITH  callmode    = 'B'
*    WITH  max_comm    = '1000'
*    WITH  anz_mode    = 'N'
*    WITH  pa_xprot    = space
**    with  xinf        = on       "no messages
*    WITH  xlog        = on
*    AND RETURN.
****start check whether selected file already uploaded or not Amit.
"  READ TABLE in_file INDEX 1.
  loop at in_file where site ne '' and zuonr ne ''.
  CONCATENATE in_file-site in_file-zuonr INTO refno.
  zfiinter-zz_refno = refno.
  zfiinter-chgdt = sy-datum.
*  APPEND   zfiinter.
  SELECT SINGLE * FROM zfiinterface
                  WHERE zz_refno = refno.
  IF sy-subrc = 0.
    MESSAGE i003(zfi) WITH zfiinterface-zz_refno zfiinterface-chgdt.
    LEAVE LIST-PROCESSING.
  ELSE.
    INSERT zfiinterface FROM zfiinter.
    IF sy-subrc = 0.
      COMMIT WORK.
    ENDIF.
  ENDIF.
  CLEAR zfiinter.
  endloop.
****end check whether selected file already uploaded or not Amit.
  IF test NE 'X'.
*      submit rfbibl01
    SUBMIT rfbibl01 EXPORTING LIST TO MEMORY
    WITH  ds_name     = outfile
    WITH  fl_check    = space
    WITH  callmode    = 'B'
    WITH  max_comm    = '1000'
    WITH  anz_mode    = 'N'
    WITH  pa_xprot    = space
*    with  xinf        = on       "no messages
    WITH  xlog        = on    "With log
    AND RETURN.


    CALL FUNCTION 'LIST_FROM_MEMORY'
      TABLES
        listobject       = i_list
* EXCEPTIONS
*   NOT_FOUND        = 1
*   OTHERS           = 2
              .

    CALL FUNCTION 'DISPLAY_LIST'
*     EXPORTING
*       FULLSCREEN                  =
*       CALLER_HANDLES_EVENTS       =
*       STARTING_X                  = 10
*       STARTING_Y                  = 10
*       ENDING_X                    = 60
*       ENDING_Y                    = 20
*     IMPORTING
*       USER_COMMAND                =
      TABLES
        listobject                  = i_list
*     EXCEPTIONS
*       EMPTY_LIST                  = 1
*       OTHERS                      = 2
              .


  ENDIF.
ENDFORM.                               " NEXT_STEP
*&---------------------------------------------------------------------*
*&      Form  CHECK_BS_ITEM
*&---------------------------------------------------------------------*
*  Checks records with accounts that have a balance sheet indicator    *
*----------------------------------------------------------------------*
FORM check_bs_item.

*  if in_file-kostl ne space and
*    in_file-kostl ne '0000000000'.
*    select * from csks where
*        kokrs = 'SLB1' and
*        kostl = in_file-kostl and
*        datbi ge sy-datum and
*        datab le sy-datum.
*      exit.
*    endselect.
*
*    if sy-subrc ne 0.
*      move current_record to error_tab-recno.
*      concatenate 'Cost center' in_file-kostl
*                  'Company code: ' in_file-bukrs
*                  'not found in CSKS'
*                  into error_tab-msgtxt separated by space.
*      append error_tab.
**     error_flag = true.
*      error_flag_cc = 'Y'.
*    else.
*      temp_barea = csks-gsber.
*      move space to in_file-kostl.
*      if in_file-mwskz ne space.
*        temp_txjcd = csks-txjcd.
*      endif.
*    endif.
*  endif.

ENDFORM.                    "check_bs_item

*&---------------------------------------------------------------------
*&      Form  CHECK_BBKPF
*&---------------------------------------------------------------------

FORM check_bbkpf.

*  perform fill_field using bbkpf-stype.
*  perform fill_field using bbkpf-tcode.
  PERFORM fill_field USING bbkpf-bldat.
  PERFORM fill_field USING bbkpf-blart.
  PERFORM fill_field USING bbkpf-bukrs.
  PERFORM fill_field USING bbkpf-budat.
  PERFORM fill_field USING bbkpf-monat.
  PERFORM fill_field USING bbkpf-waers.
  PERFORM fill_field USING bbkpf-xblnr.
*  perform fill_field using bbkpf-bvorg.
  PERFORM fill_field USING bbkpf-bktxt.
*  perform fill_field using bbkpf-pargb.
*  perform fill_field using bbkpf-auglv.
*  perform fill_field using bbkpf-vbund.
*  perform fill_field using bbkpf-xmwst.
*  perform fill_field using bbkpf-docid.
*  perform fill_field using bbkpf-barcd.
*  perform fill_field using bbkpf-stodt.
*  perform fill_field using bbkpf-brnch.
*  perform fill_field using bbkpf-numpg.
*  perform fill_field using bbkpf-stgrd.
*  perform fill_field using bbkpf-kursf_m.
*  perform fill_field using bbkpf-augtx.
*  perform fill_field using bbkpf-xprfg.
** jchang 3/26/03 end of change
*  perform fill_field using bbkpf-sende.
*
ENDFORM.                               " CHECK_BBKPF

*&---------------------------------------------------------------------*
*&      Form  FILL_FIELD
*&---------------------------------------------------------------------*
FORM fill_field USING in_field.

  IF in_field = space.
    in_field = nodata.
  ENDIF.

  IF in_field = '0000000000'.
    in_field = nodata.
  ENDIF.
ENDFORM.                               " FILL_FIELD

*&---------------------------------------------------------------------
*&      Form  CHECK_BBSEG
*&---------------------------------------------------------------------
*       text
*----------------------------------------------------------------------
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------

FORM check_bbseg.

*  perform fill_field using bbseg-stype.
*  perform fill_field using bbseg-tbnam.
  PERFORM fill_field USING bbseg-newbs.
  IF bbseg-newbs+0(1) = nodata OR bbseg-newbs = space.
    bbseg-newbs = 'XX'.
  ENDIF.
*  perform fill_field using bbseg-dummy.
  PERFORM fill_field USING bbseg-dummyx.
*  perform fill_field using bbseg-newum.
*  field not present in screen sapm50fa 0100
  IF NOT bbseg-newbk IS INITIAL.
    PERFORM fill_field USING bbseg-newbk.
*  bbseg-newbk = nodata .
*    clear bbseg-newbk.
  ENDIF.

  PERFORM fill_field USING bbseg-wrbtr.
*  field not present in screen sapm50fa 0100
  PERFORM fill_field USING bbseg-prodper.
*  perform fill_field using bbseg-dmbtr.
*  perform fill_field using bbseg-wmwst.
*  perform fill_field using bbseg-mwsts.
  PERFORM fill_field USING bbseg-mwskz.
*  perform fill_field using bbseg-xskrl.
*  perform fill_field using bbseg-fwzuz.
*  perform fill_field using bbseg-hwzuz.
*  perform fill_field using bbseg-gsber.
  PERFORM fill_field USING bbseg-kostl.
*  perform fill_field using bbseg-dummy4.
*  PERFORM fill_field USING bbseg-aufnr.
*  perform fill_field using bbseg-ebeln.
*  perform fill_field using bbseg-ebelp.
*  perform fill_field using bbseg-projn.
*  perform fill_field using bbseg-matnr.
*  perform fill_field using bbseg-werks.
*  perform fill_field using bbseg-menge.
*  perform fill_field using bbseg-meins.
*  perform fill_field using bbseg-vbel2.
*  perform fill_field using bbseg-posn2.
*  perform fill_field using bbseg-eten2.
*  perform fill_field using bbseg-pernr.
*  perform fill_field using bbseg-bewar.
*  perform fill_field using bbseg-valut.
*  perform fill_field using bbseg-zfbdt.
*  perform fill_field using bbseg-zinkz.
  PERFORM fill_field USING bbseg-zuonr.
*  perform fill_field using bbseg-fkont.
*  perform fill_field using bbseg-xaabg.
  PERFORM fill_field USING bbseg-sgtxt.
*  perform fill_field using bbseg-blnkz.
*  perform fill_field using bbseg-blnbt.
*  perform fill_field using bbseg-blnpz.
*  perform fill_field using bbseg-maber.
*  perform fill_field using bbseg-skfbt.
*  perform fill_field using bbseg-wskto.
*  perform fill_field using bbseg-zterm.
*  perform fill_field using bbseg-zbd1t.
*  perform fill_field using bbseg-zbd1p.
*  perform fill_field using bbseg-zbd2t.
*  perform fill_field using bbseg-zbd2p.
*  perform fill_field using bbseg-zbd3t.
*  perform fill_field using bbseg-zlspr.
*  perform fill_field using bbseg-rebzg.
*  perform fill_field using bbseg-rebzj.
*  perform fill_field using bbseg-rebzz.
*  perform fill_field using bbseg-zlsch.
*  perform fill_field using bbseg-samnr.
*  perform fill_field using bbseg-zbfix.
*  perform fill_field using bbseg-qsskz.
*  perform fill_field using bbseg-qsshb.
*  perform fill_field using bbseg-qsfbt.
*  perform fill_field using bbseg-esrnr.
*  perform fill_field using bbseg-esrpz.
*  perform fill_field using bbseg-esrre.
*  perform fill_field using bbseg-fdtag.
*  perform fill_field using bbseg-fdlev.
*  perform fill_field using bbseg-anln1.
*  perform fill_field using bbseg-anln2.
*  perform fill_field using bbseg-bzdat.
*  perform fill_field using bbseg-anbwa.
*  perform fill_field using bbseg-abper.
*  perform fill_field using bbseg-gbetr.
*  perform fill_field using bbseg-kursr.
*  perform fill_field using bbseg-mansp.
*  perform fill_field using bbseg-mschl.
*  perform fill_field using bbseg-hbkid.
*  perform fill_field using bbseg-bvtyp.
*  perform fill_field using bbseg-anfbn.
*  perform fill_field using bbseg-anfbu.
*  perform fill_field using bbseg-anfbj.
*  perform fill_field using bbseg-lzbkz.
*  perform fill_field using bbseg-landl.
*  perform fill_field using bbseg-diekz.
*  perform fill_field using bbseg-zolld.
*  perform fill_field using bbseg-zollt.
*  perform fill_field using bbseg-vrsdt.
*  perform fill_field using bbseg-vrskz.
*  perform fill_field using bbseg-hzuon.
*  perform fill_field using bbseg-regul.
*  perform fill_field using bbseg-name1.
*  perform fill_field using bbseg-name2.
*  perform fill_field using bbseg-name3.
*  perform fill_field using bbseg-name4.
*  perform fill_field using bbseg-stras.
*  perform fill_field using bbseg-ort01.
*  perform fill_field using bbseg-pstlz.
*  perform fill_field using bbseg-land1.
*  perform fill_field using bbseg-regio.
*  perform fill_field using bbseg-bankl.
*  perform fill_field using bbseg-banks.
*  perform fill_field using bbseg-bankn.
*  perform fill_field using bbseg-bkont.
*  perform fill_field using bbseg-stcd1.
*  perform fill_field using bbseg-stcd2.
*  perform fill_field using bbseg-madat.
*  perform fill_field using bbseg-manst.
*  perform fill_field using bbseg-egmld.
*  perform fill_field using bbseg-dummy2.
*  perform fill_field using bbseg-stceg.
*  perform fill_field using bbseg-stkza.
*  perform fill_field using bbseg-stkzu.
*  perform fill_field using bbseg-pfach.
*  perform fill_field using bbseg-pstl2.
*  perform fill_field using bbseg-spras.
*  perform fill_field using bbseg-xinve.
  PERFORM fill_field USING bbseg-newko.
  IF bbseg-newko+0(1) = nodata OR bbseg-newko = space.
    bbseg-newko = 'XXXXXXXXXX'.
  ENDIF.
*  perform fill_field using bbseg-newbw.
*  perform fill_field using bbseg-knrze.
*  perform fill_field using bbseg-hkont.
  PERFORM fill_field USING bbseg-prctr.
*  perform fill_field using bbseg-vertn.
*  perform fill_field using bbseg-vertt.
*  perform fill_field using bbseg-vbewa.
*  perform fill_field using bbseg-hwbas.
*  perform fill_field using bbseg-fwbas.
*  perform fill_field using bbseg-fipos.
*  perform fill_field using bbseg-vname.
*  perform fill_field using bbseg-egrup.
*  perform fill_field using bbseg-btype.
*  perform fill_field using bbseg-paobjnr.
*  perform fill_field using bbseg-kstrg.
*  perform fill_field using bbseg-imkey.
*  perform fill_field using bbseg-dummy3.
  PERFORM fill_field USING bbseg-zuonr.
*  perform fill_field using bbseg-nplnr.
*  perform fill_field using bbseg-vornr.
*  perform fill_field using bbseg-xegdr.
*  perform fill_field using bbseg-recid.
*  perform fill_field using bbseg-pprct.
*  PERFORM fill_field USING bbseg-projk.
*  perform fill_field using bbseg-uzawe.
  PERFORM fill_field USING bbseg-txjcd.
*  perform fill_field using bbseg-fistl.
*  perform fill_field using bbseg-geber.
*  perform fill_field using bbseg-dmbe2.
*  perform fill_field using bbseg-dmbe3.
*  perform fill_field using bbseg-pargb.
*  perform fill_field using bbseg-xref1.
*  perform fill_field using bbseg-xref2.
*  perform fill_field using bbseg-kblnr.
*  perform fill_field using bbseg-kblpos.
*  perform fill_field using bbseg-wdate.
*  perform fill_field using bbseg-wgbkz.
*  perform fill_field using bbseg-xaktz.
*  perform fill_field using bbseg-wname.
*  perform fill_field using bbseg-wort1.
*  perform fill_field using bbseg-wbzog.
*  perform fill_field using bbseg-wort2.
*  perform fill_field using bbseg-wbank.
*  perform fill_field using bbseg-wlzbp.
*  perform fill_field using bbseg-diskp.
*  perform fill_field using bbseg-diskt.
*  perform fill_field using bbseg-winfw.
*  perform fill_field using bbseg-winhw.
*  perform fill_field using bbseg-wevwv.
*  perform fill_field using bbseg-wstat.
*  perform fill_field using bbseg-wmwkz.
*  perform fill_field using bbseg-wstkz.
*  perform fill_field using bbseg-dummy.           "LL 04/02/03 ADD
*****perform fill_field using bbseg-pdummy_ke.              "TH 090299
*  perform fill_field using bbseg-vbund.
*  perform fill_field using bbseg-fkber.
*  perform fill_field using bbseg-dabrz.
*  perform fill_field using  bbseg-xstba.
*  perform fill_field using bbseg-sende.
***** New fields added to bseg for 3.1I upgrade.              TH 090799
*  perform fill_field using bbseg-rke_artnr.
*  perform fill_field using bbseg-rke_bonus.
*  perform fill_field using bbseg-rke_brsch.
*  perform fill_field using bbseg-rke_artnr.
*  perform fill_field using bbseg-rke_bukrs.
*  perform fill_field using bbseg-rke_bzirk.
*  perform fill_field using bbseg-rke_eform.
*  perform fill_field using bbseg-rke_fkart.
*  perform fill_field using bbseg-rke_gebie.
*  perform fill_field using bbseg-rke_gsber.
*  perform fill_field using bbseg-rke_kaufn.
*  perform fill_field using bbseg-rke_kdgrp.
*  perform fill_field using bbseg-rke_kdpos.
*  perform fill_field using bbseg-rke_kndnr.
*  perform fill_field using bbseg-rke_kokrs.
*  perform fill_field using bbseg-rke_kstrg.
*  perform fill_field using bbseg-rke_land1.
*  perform fill_field using bbseg-rke_maabc.
*  perform fill_field using bbseg-rke_matkl.
*  perform fill_field using bbseg-rke_prctr.
*  perform fill_field using bbseg-rke_pspnr.
*  perform fill_field using bbseg-rke_prodh.
** PERFORM FILL_FIELD USING BBSEG-RKE_RKAUFN.    "LL 02/28/03 CHG
*  perform fill_field using bbseg-rke_rkaufnr.
*  perform fill_field using bbseg-rke_spart.
*  perform fill_field using bbseg-rke_vkbur.
*  perform fill_field using bbseg-rke_vkgrp.
*  perform fill_field using bbseg-rke_vkorg.
*  perform fill_field using bbseg-rke_vtweg.
*  perform fill_field using bbseg-rke_werks.
*  perform fill_field using bbseg-rstgr.
*  perform fill_field using bbseg-fipex.
*****End of field added to bseg for 3.1I upgrade.              TH 090799

ENDFORM.                               " CHECK_BBSEG
*&---------------------------------------------------------------------*
*&      Form  CHECK_SUBTOTALS
*&---------------------------------------------------------------------*
*       text                                                           *
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM check_subtotals.

  LOOP AT in_file.
    CLEAR tbsl.
    SELECT SINGLE * FROM tbsl WHERE bschl = in_file-newbs.
    IF tbsl-shkzg EQ 'S' .
      sub_total = sub_total + in_file-amount.
    ELSEIF tbsl-shkzg EQ 'H' .
      sub_total = sub_total - in_file-amount.
    ELSE.
* error condition
      MESSAGE e009 WITH in_file-newbs sy-tabix.
    ENDIF.
  ENDLOOP.

  IF sub_total NE 0.
    MESSAGE e016 WITH sub_total.
  ENDIF.
  CLEAR sub_total.

ENDFORM.                               " CHECK_SUBTOTALS
*&---------------------------------------------------------------------*
*&      Form  CHECK_COST_CENTER
*&---------------------------------------------------------------------*
*       text                                                           *
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM check_cost_center.

  CLEAR csks.
  SELECT * FROM csks
           WHERE kostl = in_file-kostl
           AND   datbi GE sy-datum
           AND   datab LE sy-datum
           AND   bukrs = in_file-bukrs.
    EXIT.
  ENDSELECT.

  IF sy-subrc NE 0.
    MOVE current_record TO error_tab-recno.
    CONCATENATE 'Invalid Cost Center' in_file-kostl
                'Company code: ' in_file-bukrs         "JChang 4/2/98
                INTO error_tab-msgtxt SEPARATED BY space.
    APPEND error_tab.
*   error_flag = true.                            "Joyce Chang 2/09/98
    error_flag_cc = 'Y'.                          "Joyce Chang 2/09/98
  ENDIF.


ENDFORM.                               " CHECK_COST_CENTER

*&---------------------------------------------------------------------*
*&      Form  CHECK_PROFIT_CENTER
*&---------------------------------------------------------------------*
*       text                                                           *
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM check_profit_center.

** The following lines added per request from Laura Paddy and the
** subsequent lines commented. MD 07/03/97

  SELECT prctr FROM csks INTO in_file-prctr
               WHERE kostl = in_file-kostl
               AND   datbi GE sy-datum
               AND   datab LE sy-datum
               AND   bukrs = in_file-bukrs.
    EXIT.
  ENDSELECT.
  IF in_file-prctr IS INITIAL.
    MOVE current_record TO error_tab-recno.
    CONCATENATE 'Profit Center not found for cost center' in_file-kostl
                'Company code: ' in_file-bukrs
                INTO error_tab-msgtxt SEPARATED BY space.
    APPEND error_tab.
*   error_flag = true.
    error_flag = 'Y'.
  ENDIF.



ENDFORM.                               " CHECK_PROFIT_CENTER
*&---------------------------------------------------------------------*
*&      Form  WRITE_ERROR_REPORT
*&---------------------------------------------------------------------*
*       text                                                           *
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM write_error_report.
  WRITE : /'Error Log!'.
  SKIP 1.
  WRITE: /5 'Record No', 16 'Error Message'.
  ULINE: /5(10), 16(40).

  LOOP AT error_tab.
    WRITE: /5 error_tab-recno, 16 error_tab-msgtxt.
  ENDLOOP.

ENDFORM.                               " WRITE_ERROR_REPORT
*&---------------------------------------------------------------------*
*&      Form  FILE_BACKUP
*&---------------------------------------------------------------------*
*       text                                                           *
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM file_backup.
** If its a UNIX file then append _bkup to the filename.
  IF filetype = 'U'.
    CONCATENATE infile '_bkup' INTO newfile.
    CONCATENATE 'mv' infile newfile INTO unix_cmd SEPARATED BY space.
    CALL 'SYSTEM' ID 'COMMAND' FIELD unix_cmd.
  ENDIF.

ENDFORM.                    " FILE_BACKUP
*&---------------------------------------------------------------------*
*&      Form  init_structures
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->tabname  'BBSEG'
*      -->tab      'I_BBSEG'
*      -->i_nodata 'NODATA'
*----------------------------------------------------------------------*
FORM init_structures USING tabname tab i_nodata.
  REFRESH nametab.
  CALL FUNCTION 'NAMETAB_GET'
    EXPORTING
      langu          = sy-langu
      tabname        = tabname
    TABLES
      nametab        = nametab
    EXCEPTIONS
      no_texts_found = 1.
  IF sy-subrc NE 0.
    MESSAGE e000 WITH 'DDIC Structure ' tabname ' not found'.
  ENDIF.
  LOOP AT nametab.
    CLEAR char.
    CONCATENATE 'I_' nametab-tabname '-' nametab-fieldname INTO char.
    ASSIGN (char) TO <f1>.
    <f1> = i_nodata.
  ENDLOOP.
ENDFORM.                    " init_structures
*&---------------------------------------------------------------------*
*&      Form  check_sub-ledg_acct
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM check_sub-ledg_acct USING acctype .
  DATA: x_table(4),
        x_field(10) .

  CASE acctype.
    WHEN 'D' .
      SELECT        * FROM  knb1
             WHERE  bukrs  = in_file-bukrs
             AND    altkn  = in_file-acctnum .
        MOVE knb1-kunnr  TO  in_file-newko .
      ENDSELECT.

      IF sy-subrc NE 0.
        MOVE current_record TO error_tab-recno.
        CONCATENATE 'Account' in_file-acctnum
                    'Company code: ' in_file-bukrs        "JChang 4/2/98
                    'not found in table KNB1'
                    INTO error_tab-msgtxt SEPARATED BY space.
        APPEND error_tab.
*   error_flag = true.
        error_flag = 'Y'.                            "Joyce Chang 2/09/98
      ENDIF.

    WHEN 'K' .
      SELECT        * FROM  lfb1
             WHERE  bukrs  = in_file-bukrs
             AND    altkn  = in_file-acctnum .
        MOVE lfb1-lifnr  TO  in_file-newko .
      ENDSELECT.

      IF sy-subrc NE 0.
        MOVE current_record TO error_tab-recno.
        CONCATENATE 'Account' in_file-acctnum
                    'Company code: ' in_file-bukrs        "JChang 4/2/98
                    'not found in table LFB1'
                    INTO error_tab-msgtxt SEPARATED BY space.
        APPEND error_tab.
*   error_flag = true.
        error_flag = 'Y'.                            "Joyce Chang 2/09/98
      ENDIF.
  ENDCASE .

ENDFORM.                    " check_sub-ledg_acct
*&---------------------------------------------------------------------*
*&      Form  convert_ccode
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_IN_FILE_COMP  text
*----------------------------------------------------------------------*
FORM convert_ccode USING    ccode .

  READ TABLE i_zwwi01 WITH KEY
   oldbukrs = ccode.

  IF sy-subrc = 0.
    MOVE:  i_zwwi01-newbukrs  TO  in_file-bukrs ,
*           i_zwwi01-newbukrs  to  comp_tab-bukrs,
*           i_zwwi01-newbukrs  to  comp_tab-o_bukrs,
           i_zwwi01-wwiktopl  TO  hold_wwiktopl ,
           i_zwwi01-wwiktopl  TO  in_file-wwiktopl .
    SELECT SINGLE *     FROM t001
     INTO h_t001
      WHERE bukrs = in_file-bukrs .
*    move: h_t001-ktopl to in_tab-ktopl ,
*          h_t001-ktopl to comp_tab-ktopl ,
*          h_t001-waers to in_tab-waers ,
*          h_t001-waers to comp_tab-waers  .
*    SELECT        * FROM  TKA02
*           WHERE  BUKRS  = ncomp .
*      move: tka02-kokrs to in_tab-kokrs ,
*            tka02-kokrs to comp_tab-kokrs  .
*    ENDSELECT.
*    collect comp_tab .
  ELSE.
    CLEAR hold_wwiktopl.
    MOVE current_record TO error_tab-recno.
    CONCATENATE 'Invalid company code' in_file-comp
                      INTO error_tab-msgtxt SEPARATED BY space.
    APPEND error_tab.
*   error_flag = true.
    error_flag = 'Y'.                            "Joyce Chang 2/09/98

  ENDIF.

ENDFORM.                    " convert_ccode
*&---------------------------------------------------------------------*
*&      Form  convert_centre
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM convert_centre.

  MOVE in_file-centre TO num_kostl.
  MOVE num_kostl      TO in_file-centre.

  SELECT SINGLE * FROM  zwwi07
           WHERE  wwiktopl  = hold_wwiktopl
           AND    oldsaknr  = in_file-acctnum
           AND    oldkostl  = in_file-centre .

*  SELECT single * FROM  ZWWI03

*         WHERE  OLDBUKRS  = hold_wwiktopl
*         AND    OLDKOSTL  = in_file-centre .
*
  IF sy-subrc <> 0.
    MOVE current_record TO error_tab-recno.
    CONCATENATE 'Invalid cost centre' in_file-wwiktopl in_file-centre
                      INTO error_tab-msgtxt SEPARATED BY space.
    APPEND error_tab.
*   error_flag = true.
    error_flag = 'Y'.

  ELSE.
    IF ( in_file-newko > 40000000 AND
         in_file-newko < 49999999 ) .
      MOVE: nodata                  TO in_file-kostl   ,
            zwwi07-newprctr         TO in_file-prctr    ,
            zwwi07-newprctr+1(4)      TO in_file-bukrs.
    ELSE.
      MOVE: zwwi07-newkostl         TO in_file-kostl   ,
            nodata                  TO in_file-prctr   ,
            zwwi07-newkostl+1(4)    TO in_file-bukrs.
    ENDIF.

  ENDIF.
ENDFORM.                    " convert_centre
*&---------------------------------------------------------------------*
*&      Form  tax_line
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM tax_line .
  DATA: hold_saknr LIKE bseg-saknr .

  READ TABLE i_zwwi06 WITH KEY
   bukrs    = h_t001-bukrs
   koart    = hold_koart
   taxcode  = in_file-vatcode.

  IF sy-subrc = 0 .
    MOVE: i_zwwi06-mwskz  TO in_file-mwskz ,
          i_zwwi06-saknr  TO hold_saknr .
  ELSE.
    MOVE current_record TO error_tab-recno.
    CONCATENATE 'Invalid Tax Code' in_file-vatcode
                         INTO error_tab-msgtxt SEPARATED BY space.
    APPEND error_tab.
    error_flag = 'Y'.                            "Joyce Chang 2/09/98
  ENDIF.

  IF in_file-traty = c_tax .
    IF in_file-acctnum <> space .
      PERFORM check_account_no.
    ELSE.
      in_file-newko = hold_saknr .
      CLEAR hold_saknr .
    ENDIF.
  ENDIF.
*    if skb1-mwskz is initial.
*      clear in_file-mwskz.
*    else.
*      if skb1-xmwno eq space and
*         in_file-mwskz eq space.
*        move: current_record to error_tab-recno,
*   'Tax code should not be blank for this record' to error_tab-msgtxt.
*        append error_tab.
**     error_flag = true.
*        error_flag = 'Y'.                          "Joyce Chang 2/09/98
*      endif.
*    endif.
*
*    if in_file-mwskz ne space.
*      if skb1-mwskz eq '+' or
*         skb1-mwskz eq '>' or
*         skb1-mwskz eq '-' or
*         skb1-mwskz eq '<' or
*         skb1-mwskz eq '*'.
*        if skb1-xmwno eq space.
*          valid_flag = false.
*          select * from t007a where mwskz = in_file-mwskz.
*            if skb1-mwskz eq '+' or
*               skb1-mwskz eq '>'.
*              if t007a-mwart eq 'A'.
*                valid_flag = true.
*                exit.
*              else.
*                valid_flag = false.
*              endif.
*            elseif skb1-mwskz eq '-' or
*                   skb1-mwskz eq '<'.
*              if t007a-mwart eq 'V'.
*                valid_flag = true.
*                exit.
*              else.
*                valid_flag = false.
*              endif.
*            else.
*              valid_flag = true.
*              exit.
*            endif.
*          endselect.
*          if valid_flag eq false.
*            move current_record to error_tab-recno.
*            concatenate 'Invalid tax code' in_file-mwskz
*                          into error_tab-msgtxt separated by space.
*            append error_tab.
**         error_flag = true.
*            error_flag = 'Y'.                      "Joyce Chang 2/09/98
*          endif.
*        endif.
*      endif.
*    endif.
*
ENDFORM.                    " tax_line
*&---------------------------------------------------------------------*
*&      Form  determine_period
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM determine_period.
  IF NOT in_file-budat IS INITIAL .
    CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'
      EXPORTING
        i_date               = in_file-budat
*   I_MONMIT             = 00
        i_periv              = h_t001-periv
      IMPORTING
        e_buper              = x_buper
        e_gjahr              = x_gjahr
   EXCEPTIONS
     input_false          = 1
     t009_notfound        = 2
     t009b_notfound       = 3
     OTHERS               = 4
              .
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ELSE .
      MOVE: x_buper TO in_file-monat .
    ENDIF.
  ENDIF.
ENDFORM.                    " determine_period

* Changes done by bhavina to display output data of infile....
*&---------------------------------------------------------------------*
*&      Form  write_report
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_IN_FILE  text
*----------------------------------------------------------------------*
FORM write_report.
  DATA: print_parameters TYPE pri_params,
        valid_flag       TYPE c LENGTH 1.

  DATA: ind LIKE sy-tabix.

*  sub_total(15)    TYPE p DECIMALS 2 VALUE 0,
  LOOP AT in_file.
    ind = sy-tabix.
    IF in_file-traty EQ 'HDR'.
      tot_hdr = tot_hdr + in_file-amount.
      IF in_file-traty EQ 'ITM' AND
      in_file-newbs  EQ '40'.
        tot_hdr = tot_hdr + in_file-amount.


      ELSEIF in_file-traty EQ 'ITM' AND
      in_file-newbs  EQ '50'.
        tot_hdr = tot_hdr - in_file-amount.

      ENDIF.
      IF in_file-traty EQ 'ITV' AND
      in_file-newbs  EQ '40'.
        tot_hdr = tot_hdr + in_file-amount.


      ELSEIF in_file-traty EQ 'ITV' AND
      in_file-newbs  EQ '50'.
        tot_hdr = tot_hdr - in_file-amount.


      ENDIF.

    ENDIF.
    MOVE-CORRESPONDING in_file TO int_display.
    int_display-acctnum1 = in_file-newko.
    READ TABLE i_zwwi06 WITH KEY bukrs = in_file-bukrs.
    "taxcode  = in_file-vatcode.
    IF sy-subrc = 0.
      int_display-acctnum2 = i_zwwi06-saknr.
    ENDIF.
    IF in_file-docdat IS NOT INITIAL.
      CONCATENATE in_file-docdat+6(2) '.'
                in_file-docdat+4(2) '.'
                in_file-docdat+0(4) INTO
                int_display-docdat.
    ENDIF.
    IF in_file-postdat IS NOT INITIAL.
      CONCATENATE in_file-postdat+6(2) '.'
                in_file-postdat+4(2) '.'
                in_file-postdat+0(4) INTO
                int_display-postdat.

    ENDIF.
    READ TABLE error_tab WITH KEY recno = ind.
    IF sy-subrc = 0.
      int_display-msgtxt = error_tab-msgtxt.
    ENDIF.
    APPEND int_display.
    CLEAR int_display.
  ENDLOOP.
***----add logic for local currency by amit
  LOOP AT int_display.
    IF int_display-postdat IS NOT INITIAL.
      CONCATENATE int_display-postdat+6(4)
              int_display-postdat+3(2)
              int_display-postdat+0(2) INTO
              int_display-pstdat.
      MODIFY int_display.
      CLEAR int_display.
    ENDIF.
  ENDLOOP.
  LOOP AT int_display WHERE  pstdat <> '00000000' AND waers <> ''.
    CALL FUNCTION 'READ_EXCHANGE_RATE'
      EXPORTING
       client                  = sy-mandt
        date                   = int_display-pstdat
        foreign_currency       = int_display-waers
        local_currency         = 'EUR'
        type_of_rate           = 'M'
*       EXACT_DATE             = ' '
     IMPORTING
       exchange_rate           =  int_display-ukurs
*       FOREIGN_FACTOR          =
*       LOCAL_FACTOR            =
*       VALID_FROM_DATE         =
*       DERIVED_RATE_TYPE       =
*       FIXED_RATE              =
*       OLDEST_RATE_FROM        =
     EXCEPTIONS
       no_rate_found           = 1
       no_factors_found        = 2
       no_spread_found         = 3
       derived_2_times         = 4
       overflow                = 5
       zero_rate               = 6
       OTHERS                  = 7.

    IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    int_display-lcamount = int_display-ukurs * int_display-amount.
    ltot_hdr = ltot_hdr + int_display-lcamount.

    MODIFY int_display.
    CLEAR int_display.
  ENDLOOP.
*  loop at int_display.
*          int_calc-extdocnr = int_display-extdocnr.
*          int_calc-postdat = int_display-postdat.
*          int_calc-bukrs  = int_display-bukrs.
*          int_calc-waers  = int_display-waers.
*          append int_calc.
*          clear int_calc.
*    endloop.
*    loop at int_calc.
*     int_temp-extdocnr = int_calc-extdocnr.
*     int_temp-bukrs =   int_calc-bukrs.
*     append int_temp.
*     if int_temp-bukrs = ''.
*       delete int_temp INDEX sy-tabix.
*       endif.
*     CLEAR int_temp.
*     endloop.
*     sort int_temp by extdocnr.
*      loop at int_display where waers <> ''.
*        READ TABLE int_temp WITH KEY extdocnr = int_display-extdocnr BINARY SEARCH.
*         if sy-subrc = 0.
*          int_display-bukrs = int_temp-bukrs.
*          modify int_display." index sy-tabix.
*          endif.
*          endloop.
***---- end changes by amit
*CALL FUNCTION 'GET_PRINT_PARAMETERS'
*    IMPORTING
*      out_parameters       = print_parameters
*      valid                = valid_flag
*    EXCEPTIONS
*      invalid_print_params = 2
*      OTHERS               = 4.

  print_parameters-pdest = 'LOCL'.
  print_parameters-plist = sy-repid.
  print_parameters-prnew = 'X'.
  print_parameters-pexpi = '8'.
  print_parameters-linct = '65'.
  print_parameters-linsz = '255'.
  print_parameters-paart = 'X_65_255'.
  print_parameters-prsap = 'D'.
  print_parameters-prrec = sy-uname.
  print_parameters-prdsn = 'LIST1S'.
  print_parameters-ptype = 'TEXT'.
  print_parameters-armod = '1'.
  print_parameters-priot = '5'.
  print_parameters-prunx = 'D'.
  print_parameters-prkeyext = '1'.
  print_parameters-prchk = '8164'.

  NEW-PAGE PRINT ON PARAMETERS print_parameters
                          NO DIALOG .  " <<<<
  WRITE :/ sy-uline.
  WRITE :/ 'External Doc No', 'Doc. Type',
           'Doc. Date', 'Posting Date', 'SIS/Company',
           'SAP Company', 'Currency', 'Posting Period',
           'Header Text', 'Cust/Vendor No', 'G/L Account',
           'Doc. Amount', 'Site Code', 'Assig. Number',
           'Text', 'Amount', 'Error Msg', 'Exch. Rate' , 'Amount LC' ."*---change by amit
  WRITE :/ sy-uline.
  LOOP AT int_display.
    WRITE:/ int_display-extdocnr UNDER 'External Doc No',
            int_display-xblnr UNDER 'Doc Number',
            int_display-doctype UNDER 'Doc. Type',
            int_display-docdat UNDER 'Doc. Date',
            int_display-postdat UNDER 'Posting Date',
            int_display-comp UNDER 'SIS/Company',
            int_display-bukrs UNDER 'SAP Company',
            int_display-waers UNDER 'Currency',
            int_display-period UNDER 'Posting Period',
            int_display-headtxt UNDER 'Header Text',
            int_display-acctnum1 UNDER 'Cust/Vendor No',
            int_display-acctnum2 UNDER 'G/L Account',
            int_display-amount UNDER 'Doc. Amount',
            int_display-site UNDER 'Site Code',
            int_display-zuonr UNDER 'Assig. Number',
            int_display-sgtxt UNDER 'Text',
            int_display-wrbtr UNDER 'Amount',
           int_display-msgtxt UNDER 'Error Msg',
*---change by amit
           int_display-ukurs UNDER 'Exch. Rate',
           int_display-lcamount UNDER 'Amount LC'.
  ENDLOOP.
  NEW-PAGE PRINT OFF.

  MESSAGE 'Spool Request has been created ! ' TYPE 'S'.

  DATA: layout TYPE slis_layout_alv.

  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      i_program_name         = sy-repid
      i_internal_tabname     = 'INT_DISPLAY'
      i_inclname             = 'YFBI0200_TOP'
*      i_bypassing_buffer     = 'X'
    CHANGING
      ct_fieldcat            = ls_fieldcat
    EXCEPTIONS
      inconsistent_interface = 1
      program_error          = 2
      OTHERS                 = 3.

  LOOP AT ls_fieldcat INTO wa_fieldcat.
    CASE wa_fieldcat-fieldname.

      WHEN 'EXTDOCNR'.
        wa_fieldcat-reptext_ddic = 'External Doc No'.
        wa_fieldcat-seltext_l    = 'External Doc No'.
        wa_fieldcat-seltext_m    = 'External Doc No'.
        wa_fieldcat-seltext_s    = 'External Doc No'.
        wa_fieldcat-outputlen    = '16'.
        wa_fieldcat-key          = 'X'.
        wa_fieldcat-col_pos      = 1.
      WHEN 'XBLNR'.
        wa_fieldcat-reptext_ddic = 'Doc Number'.
        wa_fieldcat-seltext_l    = 'Doc Number'.
        wa_fieldcat-seltext_m    = 'Doc Number'.
        wa_fieldcat-seltext_s    = 'Doc Number'.
        wa_fieldcat-outputlen    = '16'.
        wa_fieldcat-key          = 'X'.
        wa_fieldcat-col_pos      = 1.



      WHEN 'DOCTYPE'.
        wa_fieldcat-reptext_ddic = 'Doc. Type'.
        wa_fieldcat-seltext_l    = 'Doc. Type'.
        wa_fieldcat-seltext_m    = 'Doc. Type'.
        wa_fieldcat-seltext_s    = 'Doc. Type'.
      WHEN 'DOCDAT'.
        wa_fieldcat-reptext_ddic = 'Doc. Date'.
        wa_fieldcat-seltext_l    = 'Doc. Date'.
        wa_fieldcat-seltext_m    = 'Doc. Date'.
        wa_fieldcat-seltext_s    = 'Doc. Date'.
      WHEN 'POSTDAT'.
        wa_fieldcat-reptext_ddic = 'Posting Date'.
        wa_fieldcat-seltext_l    = 'Posting Date'.
        wa_fieldcat-seltext_m    = 'Posting Date'.
        wa_fieldcat-seltext_s    = 'Posting Date'.
        wa_fieldcat-outputlen    = '13'.
      WHEN 'COMP'.
        wa_fieldcat-reptext_ddic = 'SIS/Company'.
        wa_fieldcat-seltext_l    = 'SIS/Company'.
        wa_fieldcat-seltext_m    = 'SIS/Company'.
        wa_fieldcat-seltext_s    = 'SIS/Company'.
      WHEN 'BUKRS'.
        wa_fieldcat-reptext_ddic = 'SAP Company'.
        wa_fieldcat-seltext_l    = 'SAP Company'.
        wa_fieldcat-seltext_m    = 'SAP Company'.
        wa_fieldcat-seltext_s    = 'SAP Company'.
        wa_fieldcat-key          = ' '.
      WHEN 'WAERS'.
        wa_fieldcat-reptext_ddic = 'Currency'.
        wa_fieldcat-seltext_l    = 'Currency'.
        wa_fieldcat-seltext_m    = 'Currency'.
        wa_fieldcat-seltext_s    = 'Currency'.
      WHEN 'PERIOD'.
        wa_fieldcat-reptext_ddic = 'Posting Period'.
        wa_fieldcat-seltext_l    = 'Posting Period'.
        wa_fieldcat-seltext_m    = 'Posting Period'.
        wa_fieldcat-seltext_s    = 'Posting Period'.
        wa_fieldcat-outputlen    = '14'.
      WHEN 'HEADTXT'.
        wa_fieldcat-reptext_ddic = 'Header Text'.
        wa_fieldcat-seltext_l    = 'Header Text'.
        wa_fieldcat-seltext_m    = 'Header Text'.
        wa_fieldcat-seltext_s    = 'Header Text'.
      WHEN 'ACCTNUM1'.
        wa_fieldcat-reptext_ddic = 'Cust/Vendor No'.
        wa_fieldcat-seltext_l    = 'Cust/Vendor No'.
        wa_fieldcat-seltext_m    = 'Cust/Vendor No'.
        wa_fieldcat-seltext_s    = 'Cust/Vendor No'.
        wa_fieldcat-outputlen    = '15'.
      WHEN 'ACCTNUM2'.
        wa_fieldcat-reptext_ddic = 'G/L Account'.
        wa_fieldcat-seltext_l    = 'G/L Account'.
        wa_fieldcat-seltext_m    = 'G/L Account'.
        wa_fieldcat-seltext_s    = 'G/L Account'.
      WHEN 'AMOUNT'.
        wa_fieldcat-reptext_ddic = 'Doc. Amount'.
        wa_fieldcat-seltext_l    = 'Doc. Amount'.
        wa_fieldcat-seltext_m    = 'Doc. Amount'.
        wa_fieldcat-seltext_s    = 'Doc. Amount'.
      WHEN 'SITE'.
        wa_fieldcat-reptext_ddic = 'Site Code'.
        wa_fieldcat-seltext_l    = 'Site Code'.
        wa_fieldcat-seltext_m    = 'Site Code'.
        wa_fieldcat-seltext_s    = 'Site Code'.
      WHEN 'ZUONR'.
        wa_fieldcat-reptext_ddic = 'Assig. Number'.
        wa_fieldcat-seltext_l    = 'Assig. Number'.
        wa_fieldcat-seltext_m    = 'Assig. Number'.
        wa_fieldcat-seltext_s    = 'Assig. Number'.
      WHEN 'SGTXT'.
        wa_fieldcat-reptext_ddic = 'Text'.
        wa_fieldcat-seltext_l    = 'Text'.
        wa_fieldcat-seltext_m    = 'Text'.
        wa_fieldcat-seltext_s    = 'Text'.
        wa_fieldcat-outputlen    = '30'.
      WHEN 'WRBTR'.
        wa_fieldcat-reptext_ddic = 'Amount'.
        wa_fieldcat-seltext_l    = 'Amount'.
        wa_fieldcat-seltext_m    = 'Amount'.
        wa_fieldcat-seltext_s    = 'Amount'.
      WHEN 'MSGTXT'.
        wa_fieldcat-reptext_ddic = 'Error Msg'.
        wa_fieldcat-seltext_l    = 'Error Msg'.
        wa_fieldcat-seltext_m    = 'Error Msg'.
        wa_fieldcat-seltext_s    = 'Error Msg'.
        wa_fieldcat-outputlen    = '60'.
      WHEN 'UKURS'.
        wa_fieldcat-reptext_ddic = 'Exch. Rate'.
        wa_fieldcat-seltext_l    = 'Exch. Rate'.
        wa_fieldcat-seltext_m    = 'Exch. Rate'.
        wa_fieldcat-seltext_s    = 'Exch. Rate'.
        wa_fieldcat-outputlen    = '20'.
      WHEN 'LCAMOUNT'.
        wa_fieldcat-reptext_ddic = 'Amount LC'.
        wa_fieldcat-seltext_l    = 'Amount LC'.
        wa_fieldcat-seltext_m    = 'Amount LC'.
        wa_fieldcat-seltext_s    = 'Amount LC'.
        wa_fieldcat-outputlen    = '20'.

    ENDCASE.
    MODIFY ls_fieldcat FROM wa_fieldcat.
  ENDLOOP.

  ls_event-name = slis_ev_top_of_page.
  ls_event-form = 'TOP_OF_PAGE'.
  APPEND ls_event TO events.

  ls_event-name = 'END_OF_LIST'."slis_ev_end_of_page.
  ls_event-form = 'END_OF_PAGE'.
  APPEND ls_event TO events.


  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
*      i_bypassing_buffer      = 'X'
*      i_buffer_active         = ' '
      i_callback_program      = sy-repid
*      i_callback_user_command = 'USER_COMMAND'
      it_fieldcat             = ls_fieldcat[]
*      IT_SORT                 = ws_sort[]
*      i_save                  = 'A'
*      is_variant              = import_variant
      it_events               = events[]
      is_layout               = ls_layout
    TABLES
      t_outtab                = int_display
    EXCEPTIONS
      program_error           = 1
      OTHERS                  = 2.


ENDFORM.                    " write_report

*-------------------------------------------------------------------*
* Form  TOP_OF_PAGE                                                 *
*-------------------------------------------------------------------*
* ALV Report Header                                                 *
*-------------------------------------------------------------------*
FORM top_of_page.
  WRITE :/ 'Data uploaded for FI Interface'.
ENDFORM.              "top_of_page

*-------------------------------------------------------------------*
* Form  END_OF_PAGE                                                 *
*-------------------------------------------------------------------*
* ALV Report Total for HDR items                                    *
*-------------------------------------------------------------------*
FORM end_of_page.

* data: gt_list_commentary     type slis_t_listheader.
* data: wa_gt_list_commentary  type slis_listheader.

  DATA : loc_comm_info(250) TYPE c.
  DATA : lloc_comm_info(250) TYPE c.
  DATA : loc_temp(25) TYPE c.
  DATA : lloc_temp(25) TYPE c.
  loc_temp = tot_hdr.
  lloc_temp = ltot_hdr.

  CONCATENATE 'Total Value for the HDR = ' loc_temp  INTO loc_comm_info .
  CONCATENATE 'Total Value for the HDR in Local Currency = ' lloc_temp INTO lloc_comm_info.
* write :/ 'Total Value for the HDR = ',tot_hdr .
  WRITE :/ loc_comm_info UNDER 'Amount'.
  WRITE :/ lloc_comm_info UNDER 'Amount LC'.



* wa_gt_list_commentary-typ  = 'A'.
.
* write loc_comm_info  to
*        wa_gt_list_commentary-info .
* append wa_gt_list_commentary to gt_list_commentary.
*
* CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
*   EXPORTING
*     IT_LIST_COMMENTARY       = gt_list_commentary.
**    I_LOGO                   =
**    I_END_OF_LIST_GRID       =
**    I_ALV_FORM               =         .


ENDFORM.              "end_of_page
* End of Changes by bhavina ......

Cheers

Read only

Former Member
0 Likes
1,478

Hi Pavan,

Check this link it might be useful.

Regards,

Nisrin.

Read only

Former Member
0 Likes
1,477

Hi

Go through the link given below :

http://diocio.wordpress.com/2007/02/12/sap-upload-tab-delimited-file-from-pc-into-internal-table/

(Sample code for how to upload data from text file )

With Regards

Nikunj Shah

Read only

Former Member
0 Likes
1,477

TO Amit Gujargoud

Hi

i am doing something similar like your. I am taking a CSV file ; seperator form directory AL11 and then convert it and then submit it to the standard program RFBIBL00

my flat file is a bit like this

1 line of BKPF

2 line of BSEG

can you please advise a technical flow on how i can proceed so as not to move / in 200 fields manually. Please advise