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

Outbound interface

Former Member
0 Likes
662

Hi,

Iam doing outbound interface,from sap i have to download contents to CSV file,both application and presentation server,can anyone help me by providing sample code.

my email id: pj_swaminathan@hotmail.com

2 REPLIES 2
Read only

Former Member
Read only

Former Member
0 Likes
537

Hi,

Refer to the below specified code.For ur requirement refer to this perform

<b>perform f_download_error_file.</b>

In my case i have to download error file which is of CSV file format.

Refer to this internal table population it_error.

Only this is different from other files. Rest of the code is same .

----


  • TABLES

----


TABLES : BGR00, " Batch Input Structure for Session Data

BBKPF, " Doc Hdr for Accntng Doc (Batch Input Structure)

BBSEG. " Accounting Document Segment (Batch Input Structure)

************************************************************************

  • T y p e s D e c l a r a t i o n s *

************************************************************************

*-- Types for Input file

TYPES:BEGIN OF T_INFILE,

DATA(120) TYPE C, " Data Record

END OF T_INFILE.

*-- Types for Downloded Error file

TYPES:BEGIN OF T_ERROR,

DATA(120) TYPE C, " Data Record

END OF T_ERROR.

*-- Types to hold vendor data

TYPES:BEGIN OF T_LFA1,

LIFNR TYPE LIFNR, " Vendor no

BUKRS TYPE BUKRS, " Company code

END OF T_LFA1.

*-- Types to hold cost center data

TYPES : BEGIN OF t_csks,

kostl TYPE kostl, " Cost Center

bukrs TYPE bukrs, " Company Code

END OF t_csks.

*-- Types to hold internal order number

TYPES : BEGIN OF t_coas,

aufnr TYPE aufnr, " Internal Order no.

bukrs TYPE bukrs, " Company Code

END OF t_coas.

*-- Types to hold G/L account master (company code)

TYPES : BEGIN OF t_skb1,

bukrs TYPE bukrs, " Company Code

saknr TYPE saknr, " GL Account number

END OF t_skb1.

*-- Types to hold company code currency data

TYPES: BEGIN OF T_T001,

BUKRS TYPE T001-BUKRS, " Company code

WAERS TYPE T001-WAERS, " Currency

END OF T_T001.

*-- Types to hold Company Codes

TYPES: BEGIN OF T_COMCODE,

BUKRS TYPE LFB1-BUKRS, " Company Code

END OF T_COMCODE.

*-- Types to hold Vendor Numbers

TYPES: BEGIN OF T_VEND,

LIFNR TYPE LFA1-LIFNR, " GL Account number

END OF T_VEND.

*-- Types to hold GL Accounts

TYPES: BEGIN OF T_GL,

HKONT TYPE BSEG-SAKNR, " GL Account number

END OF T_GL.

*-- Types to hold Cost Centers Accounts

TYPES: BEGIN OF T_CC,

KOSTL TYPE CSKS-KOSTL, " Cost Center

END OF T_CC.

*-- Types to hold Internal Orders

TYPES: BEGIN OF T_IO,

AUFNR TYPE AUFK-AUFNR, " Internal Order

END OF T_IO.

*-- Structure declaration for Header record type data

DATA:BEGIN OF T_INVHEADER,

RECTYPE(1) TYPE C, " Record Type

BUKRS(4) TYPE C, " Company Code

BLDAT(8) TYPE C, " Document Date

XBLNR(16) TYPE C, " CT Reference Number

BKTXT(25) TYPE C, " SAP Invoice Header Text

END OF T_INVHEADER.

*-- Structure declaration for Vendor record type data

DATA:BEGIN OF T_VENDOR,

LIFNR(15) TYPE C, " Vendor Number

WRBTR(16) TYPE C, " Check Request Total Amount

WMWST(16) TYPE C, " Check Request Tax Amount

ZLSCH(1) TYPE C, " Payment Method

SGTXT(50) TYPE C, " Text Description

END OF T_VENDOR.

*-- Structure declaration for Line Item record type data

DATA:BEGIN OF T_LINEITEM,

HKONT(10) TYPE C, " SAP GL Account Number

KOSTL(10) TYPE C, " SAP Cost Center

AUFNR(10) TYPE C, " SAP Internal Order

END OF T_LINEITEM.

*-- Types to hold input data fields

TYPES: BEGIN OF T_INDATA.

types: counter(9) type n. " Counter Number for a Doc

INCLUDE STRUCTURE T_INVHEADER. " Structure for Header Record

INCLUDE STRUCTURE T_VENDOR. " Structure for VendorItem Record

INCLUDE STRUCTURE T_LINEITEM. " Structure for LineItem Record

TYPES: errmsg(100) type c, " Error Message

errflag(1) type c. " Error Flag

types: END OF T_INDATA.

*-- Types to store a Header and Trailer records

types: BEGIN OF T_HEAD_TRAI,

rectype(1) type c, " Record Type

intname(6) type c, " Interface Number

datetime(12) type c, " File Create Date & Time

END OF T_HEAD_TRAI.

----


  • Internal Table and structure Declarations *

----


*-- Internal table to input data

DATA:

it_INFILE TYPE STANDARD TABLE OF t_INFILE WITH HEADER LINE,

*-- Internal table to hold input file separated data

IT_INDATA TYPE STANDARD TABLE OF t_INDATA WITH HEADER LINE,

*-- Internal table to hold Error file data

it_ERROR TYPE STANDARD TABLE OF t_ERROR WITH HEADER LINE,

*-- Internal table to hold Error report data

IT_ERR_REP TYPE STANDARD TABLE OF t_INDATA WITH HEADER LINE,

*-- Internal table to hold only Header and Trailer records

IT_HEAD_TRAI TYPE STANDARD TABLE OF T_HEAD_TRAI WITH HEADER LINE,

*-- Internal table to hold company code with currency

it_T001 TYPE STANDARD TABLE OF t_T001 WITH HEADER LINE,

*-- Internal table to hold Company Code

it_COMCODE TYPE STANDARD TABLE OF t_COMCODE WITH HEADER LINE,

*-- Internal table to hold Vendor Numbers

it_GL TYPE STANDARD TABLE OF t_GL WITH HEADER LINE,

*-- Internal table to hold G/L account master (company code)

it_vend TYPE STANDARD TABLE OF t_vend WITH HEADER LINE,

*-- Internal table to hold CostCenter data

it_CC TYPE STANDARD TABLE OF t_CC WITH HEADER LINE,

*-- Internal table to hold Internal Orders

it_IO TYPE STANDARD TABLE OF t_IO WITH HEADER LINE,

*-- Internal table to hold vendor data

IT_LFA1 TYPE STANDARD TABLE OF t_LFA1 WITH HEADER LINE,

*-- Internal table to hold cost center data

it_csks TYPE STANDARD TABLE OF t_csks WITH HEADER LINE,

*-- Internal table to hold internal order number

it_coas TYPE STANDARD TABLE OF t_coas WITH HEADER LINE,

*-- Internal table to hold G/L account master (company code)

it_skb1 TYPE STANDARD TABLE OF t_skb1 WITH HEADER LINE,

*-- work area for input file data

wa_indata type t_indata.

*-- internal table to initialise structures

DATA: BEGIN OF it_nametab OCCURS 120.

INCLUDE STRUCTURE dntab. " DD interface: nametab definition

" for GET_NAMETAB

DATA: END OF it_nametab.

*-- Internal table to hold sessions data

DATA:BEGIN OF IT_LIST OCCURS 0.

INCLUDE STRUCTURE ABAPLIST. " Structure for Internal Table as

" List Container

DATA:END OF IT_LIST.

----


  • Global Variables *

----


DATA:

V_PGM_ID TYPE SY-REPID, " Program id

V_COUNT_INFILE TYPE I, " Counter

v_file TYPE rlgrap-filename, " File name

v_sess TYPE APQ_GRPN, " Session name

v_char(61) TYPE c, " Field name

v_bukrs TYPE t001-bukrs, " Company Code

V_MSG TYPE STRING, " Message Info

V_RC TYPE SYST-SUBRC. " SY-SUBRC Number

*-- Field symbols

FIELD-SYMBOLS: <f1> . " Field Symbol

----


  • Constants. *

----


CONSTANTS:

C_H(1) TYPE C VALUE 'H', " Header Rec Type

C_I(1) TYPE C VALUE 'I', " Inv Header Rec Type

C_V(1) TYPE C VALUE 'V', " Vendor Rec Type

C_L(1) TYPE C VALUE 'L', " Lineitem Rec Type

C_X(1) TYPE C VALUE 'X', " For Flag

C_T(1) TYPE C VALUE 'T', " Trailer Rec Type

C_TCODE(4) TYPE C VALUE 'FB01', " Transaction Code

C_COMMA(1) TYPE C VALUE ',', " Comma

C_DOCTYPE(2) TYPE C VALUE 'KU', " Doc type

C_NODATA(1) TYPE C VALUE '/', " NODATA

C_SESS LIKE APQI-GROUPID VALUE 'CT2SAP'. "Session

----


  • Selection Screen

----


SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

PARAMETERS :

p_file TYPE rlgrap-filename OBLIGATORY,

p_error TYPE rlgrap-filename OBLIGATORY,

  • p_path TYPE filepath-pathintern

  • DEFAULT 'Z0FI_AP_INT_SAPAP_TO_CT' MODIF ID z1,

  • p_path1 TYPE filepath-pathintern

  • DEFAULT 'Z0FI_AP_INT_CT_TO_SAPAP' MODIF ID z1,

r_pc RADIOBUTTON GROUP file DEFAULT 'X' USER-COMMAND rad, " PC

r_aix RADIOBUTTON GROUP file. " App server

SELECTION-SCREEN END OF BLOCK B1.

----


  • INITIALIZATION

----


INITIALIZATION.

V_PGM_ID = SY-REPID. " Program Name

----


  • A T S E L E C T I O N S C R E E N

----


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

*-- Provide input help for PC file

PERFORM f_validate_file USING p_file r_aix.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_error.

*-- Provide input help for PC error file download

PERFORM f_validate_error_file USING p_error r_aix.

----


  • A T S E L E C T I O N S C R E E N O U T P U T

----


*-- For modifying the selection screen layout

AT SELECTION-SCREEN OUTPUT.

PERFORM f_modify_screen.

----


  • START-OF-SELECTION *

----


START-OF-SELECTION.

*-- Get the file name for Application server

  • IF NOT r_aix IS INITIAL.

**-- Using default Logical Path if no logical path mentioned

  • IF p_path IS INITIAL.

  • p_path = 'Z0FI_AP_INT_CT_TO_SAPAP'.

  • ENDIF.

**-- Using default Logical Path if no logical path mentioned

  • IF p_path1 IS INITIAL.

  • p_path1 = 'Z0FI_AP_INT_SAPAP_TO_CT'.

  • ENDIF.

*-- Get Input file name using logical path

  • CLEAR: V_FILE.

  • PERFORM f_get_file_name_path USING p_path p_file

  • CHANGING v_file.

  • p_file = v_file.

**-- Get Error file name using logical path

  • CLEAR: V_FILE.

  • PERFORM f_get_file_name_path USING p_path1 p_error

  • CHANGING v_file.

  • p_error = v_file.

  • CLEAR: V_FILE.

  • ENDIF.

*-- If sequential file is selected

IF R_AIX = 'X'.

*-- Form to get data for apllication server

PERFORM F_GET_INPUT_DATA.

*-- if local file

ELSE.

*-- Form to get data for presentation server

PERFORM F_GET_LOCAL_DATA.

ENDIF.

*-- Perfrom to Split the record at Comma and arrange accordingly.

if not it_infile[] is initial.

PERFORM F_SPLIT_DATA.

endif.

if not it_indata[] is initial.

*-- Perform to fetch Company Code Currency, Cost Centers, GL Account's,

  • Internal Orders and Vendor Numbers

PERFORM F_SELECT_DATA.

*-- Perform to validate for Company Code Currency, Cost Centers,

  • GL Account's, Internal Orders, Vendor Numbers and amounts

perform f_validate_data.

*-- Perform to seperate error records to error internal table and delete

  • error records form the orginal internal table

perform f_separate_data.

endif.

if not it_indata[] is initial.

*-- Perform to pass the data to different RFBIBL00 structures

  • accordingly

perform f_populate_RFBIBL00.

endif.

----


  • END-OF-SELECTION

----


END-OF-SELECTION.

if not it_indata[] is initial.

*-- For submitting the program to rfbibloo

PERFORM F_SUBMIT_RFBIBLOO.

endif.

if not it_error[] is initial.

*-- Download error file to application server or presentation server

perform f_download_error_file.

endif.

*-- Form to display the error report

PERFORM F_DISPLAY_REPORT.

*--Standard footer

PERFORM STD_END_OF_REPORT.

----


  • TOP OF PAGE *

----


TOP-OF-PAGE.

*---Standard header

PERFORM STD_TOP_OF_PAGE CHANGING SY-TITLE.

&----


*& Form F_GET_INPUT_DATA

&----


  • text

----


FORM F_GET_INPUT_DATA .

*-- Opening Dataset

PERFORM F_FILE_IO

USING p_file 'I'.

IF SY-SUBRC = 0 AND V_RC = 0.

*-- Read legacy input file into internal table for furthing processing

DO.

CLEAR IT_INFILE.

READ DATASET p_file INTO IT_INFILE.

IF SY-SUBRC NE 0.

EXIT.

ELSE.

APPEND IT_INFILE.

CLEAR IT_INFILE.

ENDIF.

ADD 1 TO V_COUNT_INFILE.

ENDDO.

*-- Determine if input file has data

IF V_COUNT_INFILE EQ 0.

MESSAGE A001(ZFI).

EXIT.

ENDIF.

*-- Closing dataset

PERFORM F_FILE_IO

USING p_file 'C'.

IF SY-SUBRC <> 0 OR V_RC <> 0.

MESSAGE I014 WITH V_MSG.

ENDIF.

ELSE.

MESSAGE I014 WITH V_MSG.

ENDIF.

ENDFORM. " F_GET_INPUT_DATA

&----


*& Form F_GET_LOCAL_DATA

&----


  • text

----


FORM F_GET_LOCAL_DATA .

DATA:LV_FILNAM TYPE STRING. "File name

LV_FILNAM = P_FILE.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = LV_FILNAM

FILETYPE = 'ASC'

TABLES

DATA_TAB = IT_INFILE

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CLEAR V_COUNT_INFILE.

DESCRIBE TABLE IT_INFILE LINES V_COUNT_INFILE.

  • Determine if input file has data

IF V_COUNT_INFILE EQ 0.

MESSAGE A001(ZFI).

EXIT.

ENDIF.

ENDFORM. " F_GET_LOCAL_DATA

&----


*& Form F_SPLIT_DATA

&----


  • text

----


FORM F_SPLIT_DATA .

data lv_counter(9) type n. " Counter Variable

LOOP AT IT_INFILE.

IF IT_INFILE+0(1) = C_H.

SPLIT IT_INFILE AT ',' INTO IT_HEAD_TRAI-rectype

IT_HEAD_TRAI-intname

IT_HEAD_TRAI-datetime.

APPEND it_head_trai.

CLEAR it_head_trai.

ENDIF.

IF IT_INFILE+0(1) = C_I.

SPLIT IT_INFILE AT ',' INTO IT_INDATA-RECTYPE

IT_INDATA-BUKRS

IT_INDATA-BLDAT

IT_INDATA-XBLNR

IT_INDATA-BKTXT.

lv_counter = ( lv_counter + 1 ).

move lv_counter to it_indata-counter.

*-- Move Company Codes into Company Code Internal table IT_COMCODE

IF NOT IT_INDATA-BUKRS IS INITIAL.

MOVE IT_INDATA-BUKRS TO IT_COMCODE-BUKRS.

APPEND IT_COMCODE.

CLEAR IT_COMCODE.

ENDIF.

APPEND IT_INDATA.

CLEAR IT_INDATA.

ENDIF.

IF IT_INFILE+0(1) = C_V.

SPLIT IT_INFILE AT ',' INTO IT_INDATA-RECTYPE

IT_INDATA-LIFNR

IT_INDATA-WRBTR

IT_INDATA-WMWST

IT_INDATA-ZLSCH

IT_INDATA-SGTXT.

*-- Move Vendor Numbers into Vendor number Internal table IT_VEND

IF NOT IT_INDATA-LIFNR IS INITIAL.

MOVE IT_INDATA-LIFNR+0(10) TO IT_VEND-LIFNR.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = IT_VEND-LIFNR

IMPORTING

OUTPUT = IT_VEND-LIFNR.

APPEND IT_VEND.

CLEAR IT_VEND.

ENDIF.

move lv_counter to it_indata-counter.

APPEND IT_INDATA.

CLEAR IT_INDATA.

ENDIF.

IF IT_INFILE+0(1) = C_L.

SPLIT IT_INFILE AT ',' INTO IT_INDATA-RECTYPE

IT_INDATA-HKONT

IT_INDATA-WRBTR

IT_INDATA-KOSTL

IT_INDATA-AUFNR

IT_INDATA-SGTXT.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = IT_INDATA-HKONT

IMPORTING

OUTPUT = IT_INDATA-HKONT.

move lv_counter to it_indata-counter.

*-- Move GL Accounts into GL Account Internal table IT_GL

IF NOT IT_INDATA-HKONT IS INITIAL.

MOVE IT_INDATA-HKONT TO IT_GL-HKONT.

APPEND IT_GL.

CLEAR IT_GL.

ENDIF.

*-- Move Cost Centers into Cost Center Internal table IT_CC

IF NOT IT_INDATA-KOSTL IS INITIAL.

MOVE IT_INDATA-KOSTL TO IT_CC-KOSTL.

APPEND IT_CC.

CLEAR IT_CC.

ENDIF.

*-- Move Internal Orders into Internal Order Internal table IT_IO

IF NOT IT_INDATA-AUFNR IS INITIAL.

MOVE IT_INDATA-AUFNR TO IT_IO-AUFNR.

APPEND IT_IO.

CLEAR IT_IO.

ENDIF.

APPEND IT_INDATA.

CLEAR IT_INDATA.

ENDIF.

IF IT_INFILE+0(1) = C_T.

SPLIT IT_INFILE AT ',' INTO IT_HEAD_TRAI-rectype

IT_HEAD_TRAI-intname

IT_HEAD_TRAI-datetime.

APPEND it_head_trai.

CLEAR it_head_trai.

ENDIF.

ENDLOOP.

ENDFORM. " F_SPLIT_DATA

&----


*& Form F_SELECT_DATA

&----


  • text

----


FORM F_SELECT_DATA .

*-- Fetch compnay codes based on the internal table IT_COMCODE

IF NOT IT_COMCODE[] IS INITIAL.

DELETE ADJACENT DUPLICATES FROM IT_COMCODE COMPARING BUKRS.

SELECT BUKRS

WAERS

INTO TABLE IT_T001

FROM T001

FOR ALL ENTRIES IN IT_COMCODE

WHERE BUKRS = IT_COMCODE-BUKRS.

IF SY-SUBRC <> 0.

MESSAGE I014 WITH 'Invalid Company code'(E01).

ELSE.

SORT IT_T001 BY BUKRS.

ENDIF.

ENDIF.

*-- Fetch Cost Centers based on the internal table IT_CC

if not it_cc[] is initial.

DELETE ADJACENT DUPLICATES FROM IT_CC COMPARING KOSTL.

SELECT kostl

bukrs

FROM csks

INTO TABLE it_csks

for all entries in it_cc

WHERE kostl = it_cc-kostl.

if sy-subrc = 0.

sort it_csks by kostl bukrs.

endif.

endif.

*-- Fetch Internal Orders based on the internal table IT_IO

IF NOT IT_IO[] IS INITIAL.

DELETE ADJACENT DUPLICATES FROM IT_IO COMPARING AUFNR.

SELECT aufnr

bukrs

FROM coas

INTO TABLE it_coas

FOR ALL ENTRIES IN IT_IO

WHERE AUFNR = IT_IO-AUFNR.

if sy-subrc = 0.

sort it_coas by aufnr bukrs.

endif.

ENDIF.

*-- Fetch G/L accounts based on the internal table IT_GL

IF NOT IT_GL[] IS INITIAL.

DELETE ADJACENT DUPLICATES FROM IT_GL COMPARING HKONT.

select bukrs

saknr

from skb1

into table it_skb1

for all entries in it_gl

where saknr = it_gl-HKONT.

if sy-subrc = 0.

sort it_skb1 by bukrs saknr.

endif.

endif.

*-- Selecting vendor numbers based on the internal table IT_VEND

IF NOT IT_VEND[] IS INITIAL.

SORT IT_VEND BY LIFNR.

DELETE ADJACENT DUPLICATES FROM IT_VEND COMPARING LIFNR.

SELECT A~LIFNR

B~BUKRS

FROM LFA1 AS A JOIN LFB1 AS B

ON ALIFNR = BLIFNR

INTO TABLE IT_LFA1

FOR ALL ENTRIES IN IT_VEND

WHERE a~LIFNR = IT_VEND-LIFNR.

if sy-subrc = 0.

sort it_lfa1 by LIFNR BUKRS.

endif.

ENDIF.

ENDFORM. " F_SELECT_DATA

&----


*& Form f_validate_data

&----


  • text

----


FORM f_validate_data .

data:

lv_vend_amt(17) type c, " For Vendor Amount

lv_lineitem_amt(17) type c, " For Line Item Amount

l_vend_amt type wrbtr,

l_lineitem_amt type wrbtr,

Lv_ERRFLAG TYPE C, " Error flag

lv_head_error type c, " Header Error Flag

lv_tabix type sy-tabix, " local sy-tabix

lv_header_tabix type sy-tabix, " sy-tabix for header rec

LV_BUKRS TYPE T001-BUKRS. " for Company code

loop at it_indata.

LV_TABIX = SY-TABIX.

at new counter.

READ TABLE it_indata INDEX LV_TABIX.

CLEAR IT_T001.

read table it_t001 with key bukrs = it_indata-bukrs binary search.

IF SY-SUBRC <> 0.

it_indata-errmsg = text-006.

Lv_ERRFLAG = C_X.

lv_head_error = C_X.

*-- Modify thge workarea record with the error message

MODIFY IT_INDATA index LV_TABIX TRANSPORTING errmsg.

ELSE.

MOVE it_indata-bukrs TO LV_BUKRS.

ENDIF.

endat.

*-- If the record type is vendor 'V'

if it_indata-rectype = c_v.

if lv_head_error <> c_x.

*-- Check for Record type "V" if the vendor line item amount is not

  • equal to zero or negative.

  • lv_vend_amt = ( it_indata-wrbtr + it_indata-wmwst ).

lv_vend_amt = it_indata-wrbtr.

if lv_vend_amt is initial or lv_vend_amt cs '-'.

Lv_ERRFLAG = c_x.

it_indata-errmsg = text-007.

MODIFY IT_INDATA index LV_TABIX TRANSPORTING errmsg.

endif.

clear it_lfa1.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = it_indata-LIFNR+0(10)

IMPORTING

OUTPUT = it_indata-LIFNR+0(10).

*-- Check for the vendor number

read table it_lfa1 with key LIFNR = it_indata-LIFNR+0(10)

bukrs = lv_bukrs

binary search.

if sy-subrc <> 0.

Lv_ERRFLAG = c_x.

it_indata-errmsg = text-008.

MODIFY IT_INDATA index LV_TABIX TRANSPORTING errmsg.

endif.

endif.

endif.

*-- If the record type is line item 'L'

if it_indata-rectype = c_l.

if lv_head_error <> c_x.

*-- Add the line item amounts

lv_lineitem_amt = ( lv_lineitem_amt + it_indata-wrbtr ).

*-- Check for the cost center

clear it_csks.

IF NOT it_indata-kostl IS INITIAL.

read table it_csks with key kostl = it_indata-kostl

bukrs = LV_BUKRS

binary search.

if sy-subrc <> 0.

Lv_ERRFLAG = c_x.

it_indata-errmsg = text-009.

MODIFY IT_INDATA index LV_TABIX TRANSPORTING errmsg.

endif.

ENDIF.

*-- Check for the Internal Order

clear it_coas.

IF NOT it_indata-aufnr IS INITIAL.

read table it_coas with key aufnr = it_indata-aufnr

bukrs = LV_BUKRS

binary search.

if sy-subrc <> 0.

Lv_ERRFLAG = c_x.

it_indata-errmsg = text-010.

MODIFY IT_INDATA index LV_TABIX TRANSPORTING errmsg.

endif.

ENDIF.

*-- Check for the GL Account

clear it_skb1.

read table it_skb1 with key bukrs = LV_BUKRS

saknr = it_indata-hkont

binary search.

if sy-subrc <> 0.

Lv_ERRFLAG = c_x.

it_indata-errmsg = text-011.

MODIFY IT_INDATA index LV_TABIX TRANSPORTING errmsg.

endif.

endif.

endif.

at end of counter.

READ TABLE it_indata INDEX LV_TABIX.

*-- Check for the Vendor amount and total Line Item Amounts, if not same

  • modify with error message

condense lv_vend_amt.

condense lv_lineitem_amt.

  • if lv_vend_amt <> lv_lineitem_amt.

l_vend_amt = lv_vend_amt.

l_lineitem_amt = lv_lineitem_amt.

if l_vend_amt <> l_lineitem_amt.

Lv_ERRFLAG = c_x.

it_indata-errmsg = text-012.

MODIFY IT_INDATA index LV_TABIX TRANSPORTING errmsg.

endif.

*-- At end of counter field modify the header record with the error flag

if lv_errflag = c_x.

READ TABLE IT_INDATA WITH KEY COUNTER = IT_INDATA-COUNTER.

it_indata-errflag = lv_errflag.

MODIFY IT_INDATA INDEX SY-TABIX.

endif.

CLEAR: Lv_ERRFLAG, lv_vend_amt, lv_lineitem_amt, lv_bukrs,

lv_head_error,

l_vend_amt, l_lineitem_amt.

endat.

clear: it_indata, LV_TABIX.

endloop.

ENDFORM. " f_validate_data

&----


*& Form f_populate_RFBIBL00

&----


  • text

----


FORM f_populate_RFBIBL00 .

data: LV_TABIX TYPE SY-TABIX. " Variable dor SY-TABIX

CONCATENATE '/int/' sy-sysid '/' sy-mandt '/in/REQ1231_CT_SAPAP.dat'

INTO v_file.

CONDENSE v_file NO-GAPS.

*-- OPEN DATASET v_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

PERFORM F_FILE_IO

USING v_file 'O'.

IF V_RC IS INITIAL AND SYST-SUBRC IS INITIAL.

LOOP AT IT_INDATA.

lv_tabix = sy-tabix.

at first.

*-- To populate BGR00 structure

PERFORM f_populate_bgr00.

TRANSFER bgr00 TO v_file.

endat.

at new counter.

read table it_indata index lv_tabix.

clear v_bukrs.

wa_indata = it_indata.

move wa_indata-bukrs to v_bukrs.

*-- To populate BBKPF structure

PERFORM f_populate_bbkpf.

TRANSFER bbkpf TO v_file.

endat.

wa_indata = it_indata.

*-- To populate BBSEG structure for vendor line item

if it_indata-rectype = c_v.

PERFORM f_populate_vend_bbseg.

TRANSFER bbseg TO v_file.

endif.

*-- To populate BBSEG structure for GL line item

if it_indata-rectype = c_l.

PERFORM f_populate_lineitem_bbseg.

TRANSFER bbseg TO v_file.

endif.

ENDLOOP.

*-- Closing the dataset

PERFORM F_FILE_IO

USING v_file 'C'.

IF NOT V_RC IS INITIAL OR NOT SYST-SUBRC IS INITIAL.

MESSAGE I014 WITH V_MSG.

ENDIF.

ELSE.

MESSAGE I014 WITH V_MSG.

endif.

ENDFORM. " f_populate_RFBIBL00

&----


*& Form f_populate_bgr00

&----


  • Populate BGR00

----


FORM f_populate_bgr00 .

PERFORM f_init_structures USING 'BGR00' c_nodata.

CLEAR v_sess.

CONCATENATE c_sess sy-datum+4(4) INTO v_sess SEPARATED BY '-'.

bgr00-stype = '0'.

bgr00-group = v_sess.

bgr00-mandt = sy-mandt.

bgr00-usnam = sy-uname.

bgr00-start = space.

bgr00-xkeep = 'X'.

ENDFORM. " f_populate_bgr00

&----


*& Form f_init_structures

&----


  • Init Structures

----


FORM f_init_structures USING tabname LIKE dntab-tabname

i_nodata LIKE c_nodata.

REFRESH it_nametab.

CLEAR it_nametab.

CALL FUNCTION 'NAMETAB_GET'

EXPORTING

langu = sy-langu

tabname = tabname

TABLES

nametab = it_nametab

EXCEPTIONS

no_texts_found = 1.

IF sy-subrc = 0.

LOOP AT it_nametab.

CLEAR v_char.

CONCATENATE it_nametab-tabname '-' it_nametab-fieldname INTO

v_char.

ASSIGN (v_char) TO <f1>.

<f1> = i_nodata.

ENDLOOP.

ENDIF.

ENDFORM. " f_init_structures

&----


*& Form f_populate_bbkpf

&----


  • Populate BBKPF

----


FORM f_populate_bbkpf .

data: lv_bldat(8) type c. " For Document Date

PERFORM f_init_structures USING 'BBKPF' c_nodata.

read table it_t001 with key bukrs = wa_indata-bukrs binary search.

if sy-subrc = 0.

bbkpf-waers = it_t001-waers.

endif.

*-- To post Header record.

bbkpf-stype = '1'.

bbkpf-tcode = C_TCODE.

WRITE sy-datum TO BBKPF-BUDAT.

concatenate

wa_indata-bldat+0(2)

wa_indata-bldat+2(2)

  • wa_indata-bldat+0(2)

wa_indata-bldat+4(4) into lv_bldat.

WRITE lv_bldat TO BBKPF-BLDAT.

bbkpf-blart = C_DOCTYPE.

bbkpf-bukrs = wa_indata-bukrs.

bbkpf-xblnr = wa_indata-xblnr+0(12).

bbkpf-bktxt = wa_indata-bktxt.

ENDFORM. " f_populate_bbkpf

&----


*& Form f_populate_vend_bbseg

&----


  • Populate BBSEG for Vendor Line Item

----


FORM f_populate_vend_bbseg .

PERFORM f_init_structures USING 'BBSEG' c_nodata.

bbseg-stype = '2'.

bbseg-tbnam = 'BBSEG'.

bbseg-newbs = '31'. " Credit Entry

bbseg-newko = wa_indata-lifnr.

BBSEG-WRBTR = wa_indata-WRBTR.

*-- Remove the below comment line if mapping is needed

  • BBSEG-WMWST = wa_indata-WMWST.

BBSEG-WMWST = ' '.

BBSEG-ZLSCH = 'C'.

BBSEG-SGTXT = ''.

ENDFORM. " f_populate_vend_bbseg

&----


*& Form f_populate_lineitem_bbseg

&----


  • Populate BBSEG for GL Line Item

----


FORM f_populate_lineitem_bbseg .

PERFORM F_INIT_STRUCTURES USING 'BBSEG' C_NODATA.

BBSEG-STYPE = '2'.

BBSEG-TBNAM = 'BBSEG'.

BBSEG-NEWBS = '40'.

BBSEG-NEWKO = wa_indata-HKONT.

BBSEG-WRBTR = wa_indata-WRBTR.

if not wa_indata-KOSTL is initial.

BBSEG-KOSTL = wa_indata-KOSTL.

endif.

if not wa_indata-aufnr is initial.

BBSEG-AUFNR = wa_indata-aufnr.

endif.

*-- Remove the below comment line if mapping is needed

  • BBSEG-SGTXT = wa_indata-SGTXT.

ENDFORM. " f_populate_lineitem_bbseg

&----


*& Form F_SUBMIT_RFBIBL00

&----


  • Submit RFBIBL00 program

----


FORM F_SUBMIT_RFBIBLOO .

*-- Submitting the file for RFBIBL00

SUBMIT RFBIBL00 WITH DS_NAME = V_FILE

WITH CALLMODE = 'B'

WITH MAX_COMM = '9999'

WITH XINF = 'X'

AND RETURN.

*-- Process the session if created successfully

IF SY-SUBRC = 0.

SUBMIT RSBDCSUB WITH MAPPE = V_SESS

WITH Z_VERARB = 'X'

WITH FEHLER = ''

EXPORTING LIST TO MEMORY

AND RETURN.

IF SY-SUBRC = 0.

*-- Displaying the sessions data

PERFORM F_SESSION_LIST.

ENDIF.

ENDIF.

ENDFORM. " F_SUBMIT_RFBIBLOO

&----


*& Form F_SESSION_LIST

&----


  • To process Session List

----


FORM F_SESSION_LIST .

DATA:LV_UCOMM LIKE SY-UCOMM. "usercommand

CALL FUNCTION 'LIST_FROM_MEMORY'

TABLES

LISTOBJECT = IT_LIST

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2.

IF NOT IT_LIST[] IS INITIAL.

CALL FUNCTION 'DISPLAY_LIST'

  • EXPORTING

  • FULLSCREEN = 'X'

  • CALLER_HANDLES_EVENTS =

IMPORTING

USER_COMMAND = LV_UCOMM

TABLES

LISTOBJECT = IT_LIST

EXCEPTIONS

EMPTY_LIST = 1

OTHERS = 2

.

ENDIF.

ENDFORM. " F_SESSION_LIST

&----


*& Form f_download_error_file

&----


  • Download Error File

----


FORM f_download_error_file .

*-- If sequential file is selected

IF R_AIX = 'X'.

*-- Form to get data for apllication server

PERFORM F_DOWNLOAD_TO_APP.

ELSE.

*-- Form to get data for presentation server

PERFORM F_DOWNLOAD_TO_PRE.

ENDIF.

ENDFORM. " f_download_error_file

&----


*& Form F_DOWNLOAD_TO_PRE

&----


  • Download to Presentation Server

----


FORM F_DOWNLOAD_TO_PRE .

DATA:LV_FILNAM TYPE STRING. "File name

LV_FILNAM = P_ERROR.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

FILENAME = LV_FILNAM

  • FILETYPE = 'ASC'

TABLES

DATA_TAB = IT_ERROR

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6

HEADER_NOT_ALLOWED = 7

SEPARATOR_NOT_ALLOWED = 8

FILESIZE_NOT_ALLOWED = 9

HEADER_TOO_LONG = 10

DP_ERROR_CREATE = 11

DP_ERROR_SEND = 12

DP_ERROR_WRITE = 13

UNKNOWN_DP_ERROR = 14

ACCESS_DENIED = 15

DP_OUT_OF_MEMORY = 16

DISK_FULL = 17

DP_TIMEOUT = 18

FILE_NOT_FOUND = 19

DATAPROVIDER_EXCEPTION = 20

CONTROL_FLUSH_ERROR = 21

OTHERS = 22

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " F_DOWNLOAD_TO_PRE

&----


*& Form f_modify_screen

&----


  • Modify Screen

----


FORM f_modify_screen .

*-- Use default values

IF sy-slset IS INITIAL.

IF r_aix = 'X'.

p_file = '/int/D01/030/in/LPAD1231SAP'.

p_error = '/int/D01/030/out/REQ1231_ERRORS'.

ELSE.

p_file = 'C:\LPAD1231SAP.TXT'.

p_error = 'C:\REQ1231_ERRORS.TXT'.

ENDIF.

ENDIF.

*-- modify the screen

  • IF r_pc = 'X'.

  • LOOP AT SCREEN.

  • IF screen-group1 = 'Z1' .

  • p_file = 'C:\LPAD1231SAP.TXT'.

  • p_error = 'C:\REQ1231_ERRORS.TXT'.

  • ELSE.

  • p_file = 'LPAD1231SAP.TXT'.

  • p_error = 'REQ1231_ERRORS.TXT'.

  • ENDIF.

  • MODIFY SCREEN.

  • ENDLOOP.

  • ENDIF.

ENDFORM. " f_modify_screen

&----


*& Form f_validate_file

&----


  • Validate File

----


  • f_file

  • f_aix

----


FORM f_validate_file USING f_file TYPE rlgrap-filename

f_aix TYPE any.

*-- Get the current value for the parameter

PERFORM f_get_current_value USING f_aix.

IF f_aix IS INITIAL.

PERFORM f_get_local_file_name USING f_file .

ELSE.

MESSAGE i000 WITH

'File Browsing not supported for Application server'(m09).

ENDIF.

ENDFORM. " f_validate_file

&----


*& Form f_get_current_value

&----


  • Get Current values

----


  • -->P_F_AIX text

----


FORM f_get_current_value USING f_unix TYPE any.

DATA: BEGIN OF i_dynpfields OCCURS 0.

INCLUDE STRUCTURE dynpread.

DATA: END OF i_dynpfields.

CLEAR i_dynpfields.

REFRESH i_dynpfields.

i_dynpfields-fieldname = 'R_AIX'.

APPEND i_dynpfields.

CALL FUNCTION 'DYNP_VALUES_READ'

EXPORTING

dyname = sy-cprog

dynumb = sy-dynnr

TABLES

dynpfields = i_dynpfields

EXCEPTIONS

invalid_abapworkarea = 1

invalid_dynprofield = 2

invalid_dynproname = 3

invalid_dynpronummer = 4

invalid_request = 5

no_fielddescription = 6

invalid_parameter = 7

undefind_error = 8

double_conversion = 9

stepl_not_found = 10

OTHERS = 11.

IF sy-subrc <> 0.

MESSAGE i000 WITH 'Unable to read the selection screen values'(m08).

ELSE.

READ TABLE i_dynpfields INDEX 1.

IF sy-subrc = 0.

MOVE i_dynpfields-fieldvalue TO r_aix.

ENDIF.

ENDIF.

ENDFORM. " f_get_current_value

&----


*& Form f_get_local_file_name

&----


  • get local file name

----


FORM f_get_local_file_name USING f_file TYPE rlgrap-filename.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

CHANGING

file_name = f_file

EXCEPTIONS

mask_too_long = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE i000 WITH 'Error in getting filename'(m07).

ENDIF.

ENDFORM. " f_get_local_file_name

&----


*& Form f_validate_error_file

&----


  • Validate error file

----


FORM f_validate_error_file USING f_error TYPE rlgrap-filename

f_aix TYPE any.

*get the current value for the parameter

PERFORM f_get_current_value USING f_aix.

IF f_aix IS INITIAL.

PERFORM f_get_local_error_file_name USING f_error .

ELSE.

MESSAGE i000 WITH

'File Browsing not supported for Application server'(m09).

ENDIF.

ENDFORM. " f_validate_error_file

&----


*& Form f_get_local_error_file_name

&----


  • Get Error file name

----


  • -->P_F_ERROR text

----


FORM f_get_local_error_file_name USING f_error TYPE rlgrap-filename.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

CHANGING

file_name = f_error

EXCEPTIONS

mask_too_long = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE i000 WITH 'Error in getting filename'(m07).

ENDIF.

ENDFORM. " f_get_local_error_file_name

&----


*& Form f_get_file_name_path

&----


  • Get Physical Path name

----


  • -->P_P_PATH text

  • -->P_P_FILE text

  • <--P_V_FILE text

----


FORM f_get_file_name_path USING p_logicalpath TYPE filepath-pathintern

p_file TYPE any

CHANGING v_file TYPE any.

CALL FUNCTION 'FILE_GET_NAME_USING_PATH'

EXPORTING

  • CLIENT = SY-MANDT

logical_path = p_logicalpath

operating_system = sy-opsys

  • PARAMETER_1 = ' '

  • PARAMETER_2 = ' '

  • PARAMETER_3 = ' '

  • USE_BUFFER = ' '

file_name = p_file

  • USE_PRESENTATION_SERVER = ' '

  • ELEMINATE_BLANKS = 'X'

IMPORTING

file_name_with_path = v_file

EXCEPTIONS

path_not_found = 1

missing_parameter = 2

operating_system_not_found = 3

file_system_not_found = 4

OTHERS = 5.

IF sy-subrc <> 0.

MESSAGE i000

WITH 'Logical Path Not Found for the given File name'(m10).

STOP.

ENDIF.

ENDFORM. " f_get_file_name_path

&----


*& Form F_DOWNLOAD_TO_APP

&----


  • Download to Application Server

----


FORM F_DOWNLOAD_TO_APP .

*-- Open the dataset

PERFORM F_FILE_IO

USING p_error 'O'.

IF V_RC IS INITIAL AND SYST-SUBRC IS INITIAL.

LOOP AT it_error.

TRANSFER it_error TO p_error.

ENDLOOP.

*-- Close the data set

PERFORM F_FILE_IO

USING p_error 'C'.

IF NOT V_RC IS INITIAL OR NOT SYST-SUBRC IS INITIAL.

MESSAGE I014 WITH V_MSG.

ENDIF.

ELSE.

MESSAGE I014 WITH V_MSG.

ENDIF.

ENDFORM. " F_DOWNLOAD_TO_APP

&----


*& Form F_DISPLAY_REPORT

&----


  • Display Report

----


FORM F_DISPLAY_REPORT .

DATA: LV_DETAIL TYPE I, " Counter for Detail records

LV_ERROR TYPE I, " Counter for Error records

LV_SUCC TYPE I. " Counter for Success records

DESCRIBE TABLE IT_INFILE LINES LV_DETAIL.

LV_DETAIL = LV_DETAIL - 2.

DESCRIBE TABLE IT_ERR_REP LINES LV_ERROR.

LV_SUCC = LV_DETAIL - LV_ERROR.

WRITE:/ 'Number of Detail records:', LV_DETAIL.

WRITE:/ 'Number of success records passed to Session:', LV_SUCC.

WRITE:/ 'Number of error records before processing Session:',

LV_ERROR.

SKIP 1.

if not it_err_rep[] is initial.

FORMAT COLOR 1 INTENSIFIED OFF.

SKIP 2.

WRITE:/1(174) 'ERROR REPORT'(H01) CENTERED.

ULINE /1(174).

WRITE:/1 SY-VLINE,

(8) TEXT-013,

SY-VLINE,

(16) TEXT-014,

SY-VLINE,

(17) TEXT-015,

SY-VLINE,

(15) TEXT-016,

SY-VLINE,

(16) ' ',

SY-VLINE,

(50) TEXT-017,

SY-VLINE,

(30) TEXT-018,

SY-VLINE.

WRITE:/1 SY-VLINE,

(8) ' ',

SY-VLINE,

(16) TEXT-019,

SY-VLINE,

(17) TEXT-020,

SY-VLINE,

(15) TEXT-021,

SY-VLINE,

(16) TEXT-022,

SY-VLINE,

(50) TEXT-023,

SY-VLINE,

(30) ' ',

SY-VLINE.

WRITE:/1 SY-VLINE,

(8) ' ',

SY-VLINE,

(16) TEXT-024,

SY-VLINE,

(17) TEXT-025,

SY-VLINE,

(15) TEXT-026,

SY-VLINE,

(16) TEXT-027,

SY-VLINE,

(50) TEXT-028,

SY-VLINE,

(30) ' ',

SY-VLINE.

ULINE /1(174).

LOOP AT IT_ERR_REP.

IF IT_ERR_REP-RECTYPE = 'I'.

WRITE:/1 SY-VLINE,

(8) IT_ERR_REP-RECTYPE,

SY-VLINE,

(16) IT_ERR_REP-BUKRS,

SY-VLINE,

(17) IT_ERR_REP-BLDAT,

SY-VLINE,

(15) IT_ERR_REP-XBLNR,

SY-VLINE,

(16) ' ',

SY-VLINE,

(50) IT_ERR_REP-BKTXT,

SY-VLINE,

(30) IT_ERR_REP-ERRMSG,

SY-VLINE.

ENDIF.

IF IT_ERR_REP-RECTYPE = 'V'.

WRITE:/1 SY-VLINE,

(8) IT_ERR_REP-RECTYPE,

SY-VLINE,

(16) IT_ERR_REP-LIFNR,

SY-VLINE,

(17) IT_ERR_REP-WRBTR,

SY-VLINE,

(15) IT_ERR_REP-WMWST,

SY-VLINE,

(16) IT_ERR_REP-ZLSCH,

SY-VLINE,

(50) IT_ERR_REP-SGTXT,

SY-VLINE,

(30) IT_ERR_REP-ERRMSG,

SY-VLINE.

ENDIF.

IF IT_ERR_REP-RECTYPE = 'L'.

WRITE:/1 SY-VLINE,

(8) IT_ERR_REP-RECTYPE,

SY-VLINE,

(16) IT_ERR_REP-HKONT,

SY-VLINE,

(17) IT_ERR_REP-WRBTR,

SY-VLINE,

(15) IT_ERR_REP-KOSTL,

SY-VLINE,

(16) IT_ERR_REP-AUFNR,

SY-VLINE,

(50) IT_ERR_REP-SGTXT,

SY-VLINE,

(30) IT_ERR_REP-ERRMSG,

SY-VLINE.

ENDIF.

ENDLOOP.

ULINE /1(174).

endif.

ENDFORM. " F_DISPLAY_REPORT

&----


*& Form f_separate_data

&----


  • Separate Data

----


FORM f_separate_data .

data: lv_errflag type c, " For Error Flag

LV_ERRNUM TYPE I, " For Error Counter

LV_ERRNUM_TEMP TYPE STRING, " For Error Temp Counter

LV_TABIX TYPE SY-TABIX. " For SY-TABIX

LOOP AT IT_INDATA.

LV_TABIX = SY-TABIX.

*-- At new of counter field check for error flag is set and move all the

  • counter fields to error internal table IT_ERROR

AT NEW COUNTER.

READ TABLE IT_INDATA INDEX LV_TABIX.

IF IT_INDATA-ERRFLAG = 'X'.

if not it_indata-errmsg is initial.

concatenate IT_INDATA-rectype

IT_INDATA-bukrs

IT_INDATA-bldat

IT_INDATA-xblnr

IT_INDATA-bktxt

IT_INDATA-errmsg into it_error

separated by c_comma.

else.

concatenate IT_INDATA-rectype

IT_INDATA-bukrs

IT_INDATA-bldat

IT_INDATA-xblnr

IT_INDATA-bktxt into it_error

separated by c_comma.

endif.

*-- Move the error record to IT_ERR_REP internal field for output list

MOVE: IT_INDATA-rectype TO IT_ERR_REP-rectype,

IT_INDATA-bukrs TO IT_ERR_REP-bukrs,

IT_INDATA-bldat TO IT_ERR_REP-bldat,

IT_INDATA-xblnr TO IT_ERR_REP-xblnr,

IT_INDATA-bktxt TO IT_ERR_REP-bktxt,

IT_INDATA-errmsg TO IT_ERR_REP-errmsg.

append it_err_rep.

clear it_err_rep.

append it_error.

clear it_error.

LV_ERRNUM = LV_ERRNUM + 1.

lv_errflag = 'X'.

ENDIF.

ENDAT.

*-- Check for the vendor record type and error flag is set and move all

  • the records to error internal table IT_ERROR

if it_indata-rectype = c_v.

if lv_errflag = 'X'.

LV_ERRNUM = LV_ERRNUM + 1.

if not it_indata-errmsg is initial.

concatenate IT_INDATA-rectype

IT_INDATA-lifnr

IT_INDATA-wrbtr

IT_INDATA-wmwst

IT_INDATA-zlsch

IT_INDATA-sgtxt

IT_INDATA-errmsg into it_error

separated by c_comma.

else.

concatenate IT_INDATA-rectype

IT_INDATA-lifnr

IT_INDATA-wrbtr

IT_INDATA-wmwst

IT_INDATA-zlsch

IT_INDATA-sgtxt into it_error

separated by c_comma.

endif.

*-- Move the error record to IT_ERR_REP internal field for output list

MOVE: IT_INDATA-rectype TO IT_ERR_REP-rectype,

IT_INDATA-lifnr TO IT_ERR_REP-lifnr,

IT_INDATA-wrbtr TO IT_ERR_REP-wrbtr,

IT_INDATA-wmwst TO IT_ERR_REP-wmwst,

IT_INDATA-zlsch TO IT_ERR_REP-zlsch,

IT_INDATA-sgtxt TO IT_ERR_REP-sgtxt,

IT_INDATA-errmsg TO IT_ERR_REP-errmsg.

append it_err_rep.

clear it_err_rep.

append it_error.

clear it_error.

it_indata-errflag = 'X'.

modify it_indata transporting ERRFLAG.

endif.

endif.

*-- Check for the line item record type and error flag is set and move

  • all the records to error internal table IT_ERROR

if it_indata-rectype = c_l.

if lv_errflag = 'X'.

LV_ERRNUM = LV_ERRNUM + 1.

if not it_indata-errmsg is initial.

concatenate IT_INDATA-rectype

IT_INDATA-hkont

IT_INDATA-wrbtr

IT_INDATA-kostl

IT_INDATA-aufnr

IT_INDATA-sgtxt

IT_INDATA-errmsg into it_error

separated by c_comma.

else.

concatenate IT_INDATA-rectype

IT_INDATA-hkont

IT_INDATA-wrbtr

IT_INDATA-kostl

IT_INDATA-aufnr

IT_INDATA-sgtxt into it_error

separated by c_comma.

endif.

*-- Move the error record to IT_ERR_REP internal field for output list

MOVE: IT_INDATA-rectype TO IT_ERR_REP-rectype,

IT_INDATA-hkont TO IT_ERR_REP-hkont,

IT_INDATA-wrbtr TO IT_ERR_REP-wrbtr,

IT_INDATA-kostl TO IT_ERR_REP-kostl,

IT_INDATA-aufnr TO IT_ERR_REP-aufnr,

IT_INDATA-sgtxt TO IT_ERR_REP-sgtxt,

IT_INDATA-errmsg TO IT_ERR_REP-errmsg.

append it_err_rep.

clear it_err_rep.

append it_error.

clear it_error.

it_indata-errflag = 'X'.

modify it_indata transporting ERRFLAG.

endif.

endif.

AT END OF COUNTER.

READ TABLE IT_INDATA INDEX LV_TABIX.

CLEAR LV_ERRFLAG.

ENDAT.

ENDLOOP.

*-- Delete all the error records from the internal table IT_INDATA

delete it_indata where ERRFLAG = 'X'.

*-- For the error internal table IT_ERROR add the Header and Trailer

  • records to download the same

IF NOT IT_ERROR[] IS INITIAL.

*-- Insert Header record at Index 1

read table it_head_trai index 1.

if sy-subrc = 0.

concatenate it_head_trai-rectype

it_head_trai-intname

it_head_trai-datetime into it_error

separated by c_comma.

INSERT it_error index 1.

clear it_error.

endif.

*-- Append Trailer record

read table it_head_trai index 2.

if sy-subrc = 0.

MOVE LV_ERRNUM TO LV_ERRNUM_TEMP.

concatenate it_head_trai-rectype

it_head_trai-intname

it_head_trai-datetime

LV_ERRNUM_TEMP into it_error

separated by c_comma.

append it_error.

clear it_error.

ENDIF.

ENDIF.

ENDFORM. " f_separate_data

&----


*& Form F_FILE_IO

&----


  • text

----


  • -->U_FILE file on appln. server

  • -->V_OPRN file operation (i.e. Close,Open,Input..)

----


FORM F_FILE_IO

USING U_FILE TYPE rlgrap-filename

VALUE(V_OPRN) TYPE CHAR1.

CALL FUNCTION 'Z01_UT_UNICODE_FILE_IO'

EXPORTING

I_FILE = U_FILE

I_IO_OPRN = V_OPRN

IMPORTING

E_RC = V_RC

E_MSG = V_MSG

EXCEPTIONS

FILENAME_NOT_SUPPLIED = 1

INVALID_FILE_IO_OPRN = 2

OTHERS = 3.

ENDFORM. " F_FILE_IO

Reward with points if this is useful.

Regards,

savitha.