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

plz check the code

Former Member
0 Likes
1,793

Hi all.

plz check my program and could you plz correct where i am going wrong.

I have aflat file looks like below. but my program when i execute in the first loop it is taking the first record of type '1' and skipping all other records of type 2 and 3.

and it is doing perform upload.

and when it loops second time only it is taking the record ytpoe of 2 which has to be done in the forst loop itself. could some one correct my code.

1111111111111111111111

2222222222222222222222

2222222222222222222222

2222222222222222222222

3333333333333333333333

33333333333333333333333

-


11111111111111111111111

22222222222222222222222

222222222222222222222222

33333333333333333333333

-


TABLES: zfamxcci.

  • Work fields

DATA: w_date(8) TYPE c,

w_seqnum(10) TYPE c,

w_cnum LIKE zfamxcci-zcnum,

w_flag TYPE c VALUE 0,

flag(1).

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

----


AT SELECTION-SCREEN.

*

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

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

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

  • Start of change by madhava

w_seqnum = t_data-fld+69(10).

  • End of changes by Madhava

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

IF flag NE 'X'.

w_data-zmardesc = t_data-fld+359(80).

flag = 'X'.

ENDIF.

ENDIF.

w_flag = 1.

ENDIF.

IF w_flag = 1.

PERFORM upload.

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 = 1.

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.

regards,

siri.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,519

Hi

Clear the w_flag after Perform upload.

Regards

Raj

7 REPLIES 7
Read only

Former Member
0 Likes
1,520

Hi

Clear the w_flag after Perform upload.

Regards

Raj

Read only

0 Likes
1,519

hi thank you.

it is behaving the same.

regards,

siri.

Read only

Former Member
0 Likes
1,519

y u gave wws_upload in atselection screen also

Read only

0 Likes
1,519

hi,

that upload is for taking the flat file into an internal table and from that internal table actually i am inserting the data to Ztable Zfamxcci.

regards,

siri.

Read only

Former Member
0 Likes
1,519

Hey,

Now i got it...

If you want the successive records (starting with 2....) to be processed in the first iteration itself....then you need to this way

1. Make copy of your internal table (say itab2),

2. Loop on itab.

Loop on itab2 where <condition>.

<process records>

Endloop.

Endloop.

Regards

Raj

Message was edited by:

Rajasekhar Dinavahi

Read only

0 Likes
1,519

Raj,

could you plz explain it.

regards,

siri.

Read only

0 Likes
1,519

Hi Raj,

could u plz help me with the code .

i tried but not able to get it.

regards,

siri.