Application Development 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: 

file not getting uploaded

Former Member
0 Kudos
84

Hi all,

plz check my below code and suggest.

i am given one flat file from which a Ztable is getting updated .

the flat file contains one header that is record type 1and two line item records record type 2 and record type 3. some times there may not be record type 3.

the file looks like below.

header-1

line items

2

2

2

2

3

3

3

3

3

3

.there may be multiple 2 type records and multiple 3 type records.

the code is working fine but if there are multiple 2 type records all are not getting uploded.

plz help below is the code.

REPORT ZFRAMXUP NO STANDARD PAGE HEADING LINE-SIZE 200.

----


  • Tables updated: ZFAMXCCI

  • External files: Flat File

  • Input parameters: File Path

  • Output parameters: Number of records updated

----


TABLES: ZFAMXCCI. "American Express Payment Card Details

  • Work fields

DATA: W_DATE(8) TYPE C,

W_SEQNUM(10) TYPE C,

W_CNUM LIKE ZFAMXCCI-ZCNUM,

W_FLAG TYPE C VALUE 0.

  • Structures

  • Internal tables

DATA: BEGIN OF T_DATA OCCURS 0,

FLD(2350),

END OF T_DATA.

DATA: T_CDATA LIKE ZFAMXCCI OCCURS 0 WITH HEADER LINE,

W_DATA LIKE ZFAMXCCI,

W_REC LIKE ZFAMXCCI,

W_SREC LIKE SY-SUBRC,

W_EREC LIKE SY-SUBRC,

W_TREC LIKE SY-SUBRC.

  • To collect error messages

DATA : BEGIN OF IT_ERR OCCURS 0,

BUKRS LIKE ZFAMXCCI-BUKRS,

ZCNUM LIKE ZFAMXCCI-ZCNUM,

BUDAT LIKE ZFAMXCCI-BUDAT,

XBLNR LIKE ZFAMXCCI-XBLNR,

WRBTR LIKE ZFAMXCCI-WRBTR,

SAKNR LIKE ZFAMXCCI-SAKNR,

KOSTL LIKE ZFAMXCCI-KOSTL, MESSAGE(60),

END OF IT_ERR.

DATA : W_CON1(40),

W_CON2(250).

----


  • PARAMETERS *

----


SELECTION-SCREEN BEGIN OF BLOCK A_SELECTION WITH FRAME TITLE TEXT-000.

PARAMETERS: P_FILE LIKE RLGRAP-FILENAME. " File path

SELECTION-SCREEN END OF BLOCK A_SELECTION.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

  • Allow user to select the file

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

DEF_FILENAME = ' '

DEF_PATH = 'C:\'

MASK = ',.,..'

MODE = 'O'

TITLE = 'Choose A File'

IMPORTING

FILENAME = P_FILE

EXCEPTIONS

INV_WINSYS = 1

NO_BATCH = 2

SELECTION_CANCEL = 3

SELECTION_ERROR = 4

OTHERS = 5.

----


  • START-OF-SELECTION

----


START-OF-SELECTION.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

FILENAME = P_FILE

FILETYPE = 'ASC'

TABLES

DATA_TAB = T_DATA

EXCEPTIONS

CONVERSION_EROR = 1

FILE_OPEN_ERROR = 2

FILE_READ_ERROR = 3

INVALID_TYPE = 4

NO_BATCH = 5

UNKNOWN_ERROR = 6

INVALID_TABLE_WIDTH = 7

GUI_REFUSE_FILETRANSFER = 8

CUSTOMER_ERROR = 9

OTHERS = 10.

IF SY-SUBRC <> 0.

MESSAGE E701(BC) WITH 'Error while uploading file'.

ELSE.

SELECT * FROM ZFAMXCCI

INTO TABLE T_CDATA.

ENDIF.

  • Lock table

CALL FUNCTION 'ENQUEUE_EZFAMXCCI'

EXPORTING

MODE_ZFAMXCCI = 'E'

MANDT = SY-MANDT

EXCEPTIONS

FOREIGN_LOCK = 1

SYSTEM_FAILURE = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

MESSAGE E701(BC) WITH 'Custom Table Locked'.

ENDIF.

LOOP AT T_DATA.

IF T_DATA-FLD+1(1) = '1'.

IF W_FLAG = 1.

PERFORM UPLOAD.

endif.

CLEAR : W_REC,W_DATA.

  • Client

W_DATA-MANDT = SY-MANDT.

  • Credit Card Number

W_DATA-ZCNUM = T_DATA-FLD+40(19).

W_CNUM = W_DATA-ZCNUM. "DV1K931125

  • Document Date (Bill Date)

CONCATENATE T_DATA-FLD65(4) T_DATA-FLD59(2)

T_DATA-FLD+62(2)

INTO W_DATA-BLDAT.

W_DATA-ZCNAME = T_DATA-FLD+79(45).

  • Posting Date

CONCATENATE T_DATA-FLD175(4) T_DATA-FLD169(2)

T_DATA-FLD+172(2)

INTO W_DATA-BUDAT.

  • Currency

W_DATA-WAERS = 'USD'.

  • Ref. document number

W_DATA-XBLNR = T_DATA-FLD+179(16).

W_CON1 = T_DATA-FLD+219(40).

CONDENSE W_CON1.

W_DATA-ZSUPNAME = W_CON1.

W_CON2 = T_DATA-FLD+2051(250).

CONDENSE W_CON2.

W_DATA-ZCARDCOM = W_CON2.

W_REC = W_DATA.

ENDIF.

IF T_DATA-FLD+1(1) = '2'.

  • Company Code

  • w_data-bukrs = t_data-fld+577(4).

W_DATA-BUKRS = T_DATA-FLD+97(4). "Acct field1

W_SEQNUM = T_DATA-FLD+69(10).

  • Document type

IF T_DATA-FLD79(1) = ''.

W_DATA-BLART = 'KR'.

ELSE.

W_DATA-BLART = 'KG'.

ENDIF.

  • Amount

W_DATA-WRBTR = T_DATA-FLD+80(15).

  • G/L Account

  • w_data-saknr = t_data-fld+1065(6).

W_DATA-SAKNR = T_DATA-FLD+177(6). "Acct field3

  • Cost center

  • w_data-kostl = t_data-fld+826(6).

W_DATA-KOSTL = T_DATA-FLD+137(6). "Acct field2

W_DATA-ZIORDNUM = T_DATA-FLD+217(40). "internal order Num

  • Card Member Name

W_DATA-ZCNAME = W_REC-ZCNAME.

W_FLAG = 1.

ENDIF.

IF T_DATA-FLD+1(1) = '3'.

IF T_DATA-FLD+40(19) EQ W_CNUM AND

T_DATA-FLD+69(10) EQ W_SEQNUM.

W_DATA-ZMARDESC = T_DATA-FLD+359(80).

ENDIF.

W_FLAG = 1.

ENDIF.

ENDLOOP.

IF W_FLAG = 1.

PERFORM UPLOAD.

endif.

  • Unlock table

CALL FUNCTION 'DEQUEUE_EZFAMXCCI'

EXPORTING

MODE_ZFAMXCCI = 'E'

MANDT = SY-MANDT.

END-OF-SELECTION.

PERFORM WRITE_OUTPUT.

----


  • FORM upload *

----


  • ........ *

----


FORM UPLOAD.

W_FLAG = 0.

W_TREC = W_TREC + 1.

READ TABLE T_CDATA WITH KEY ZCNUM = W_DATA-ZCNUM

SAKNR = W_DATA-SAKNR

KOSTL = W_DATA-KOSTL

BUDAT = W_DATA-BUDAT

WRBTR = W_DATA-WRBTR

XBLNR = W_DATA-XBLNR

BLDAT = W_DATA-BLDAT.

IF SY-SUBRC NE 0.

ZFAMXCCI = W_DATA.

INSERT ZFAMXCCI.

IF SY-SUBRC = 0.

COMMIT WORK.

W_SREC = W_SREC + 1.

ELSE.

W_EREC = W_EREC + 1.

MOVE-CORRESPONDING W_DATA TO IT_ERR.

IT_ERR-MESSAGE = TEXT-003.

APPEND IT_ERR. CLEAR IT_ERR.

ENDIF.

ELSE.

W_EREC = W_EREC + 1.

  • Columns heading

MOVE-CORRESPONDING W_DATA TO IT_ERR.

IT_ERR-MESSAGE = TEXT-004.

APPEND IT_ERR. CLEAR IT_ERR.

ENDIF.

ENDFORM.

----


  • TOP-OF-PAGE

----


TOP-OF-PAGE.

PERFORM PAGE_HEADING.

----


  • FORMS *

----


----


  • FORM page_heading *

----


  • Heading for upload report. *

----


FORM PAGE_HEADING.

DATA: L_STR(50),

L_BUTXT(25) TYPE C.

  • Report header

CALL FUNCTION 'Z_REPORT_HEADING'

EXPORTING

APP_STRING = 'F'

DESC_STRING = 'American Express Payment Card Data Upload'.

  • SKIP.

  • ULINE.

ENDFORM.

&----


*& Form WRITE_OUTPUT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM WRITE_OUTPUT.

SKIP.

ULINE.

FORMAT COLOR COL_HEADING INVERSE ON.

WRITE: / SY-VLINE,

(035) 'Total number of records read: ',

(005) W_TREC,

AT SY-LINSZ SY-VLINE.

WRITE: / SY-VLINE,

(035) 'Total number of records uploaded: ',

(005) W_SREC,

AT SY-LINSZ SY-VLINE.

WRITE: / SY-VLINE,

(035) 'Total number of records failed: ',

(005) W_EREC,

AT SY-LINSZ SY-VLINE.

FORMAT COLOR OFF INVERSE OFF.

ULINE.

  • Check for error records

IF W_EREC GT 0.

SKIP.

ULINE.

WRITE: / SY-VLINE,

(035) 'Details of error records:',

AT SY-LINSZ SY-VLINE.

ULINE.

  • Columns heading

WRITE: / SY-VLINE,

(005) 'CCode',

(018) 'Credit Card Number',

(012) 'Posting date',

(018) 'Ref.Doc.Number',

(007) 'Amount' CENTERED,

(010) 'Acct#',

(010) 'CCTR',

(060) 'Error Message',

AT SY-LINSZ SY-VLINE.

ULINE.

LOOP AT IT_ERR.

WRITE: / SY-VLINE,

(005) IT_ERR-BUKRS,

(019) IT_ERR-ZCNUM,

(010) IT_ERR-BUDAT,

(018) IT_ERR-XBLNR,

(007) IT_ERR-WRBTR RIGHT-JUSTIFIED,

(010) IT_ERR-SAKNR,

(010) IT_ERR-KOSTL,

(060) IT_ERR-MESSAGE,

AT SY-LINSZ SY-VLINE.

ENDLOOP.

ULINE.

ENDIF.

ENDFORM. " WRITE_OUTPUT

regards,

siri.

1 ACCEPTED SOLUTION

kathryn_mcgallicher
Active Participant
0 Kudos
59

Hello,

It looks like w_flag is used to trigger a call to form upload after building record types 2 and 3. If this is true, then it seems you would want the "perform upload" within the loop structure, rather than outside.

My apologies if I have misunderstood your process.

Kathy

2 REPLIES 2

kathryn_mcgallicher
Active Participant
0 Kudos
60

Hello,

It looks like w_flag is used to trigger a call to form upload after building record types 2 and 3. If this is true, then it seems you would want the "perform upload" within the loop structure, rather than outside.

My apologies if I have misunderstood your process.

Kathy

0 Kudos
59

Thank you.

my problem is almost solved if any problem let u know .

regards,

siri.