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: 

Append running ALPHA to duplicating entries from flat file

Former Member
0 Kudos

hi all,

i have a requirement to append a running alpha to the end of a value from flat file should the value is a duplicating one. example:

flat file output

12345 12345

12346 12346

12345 12345A

12347 12347

12348 12348

12345 12345B

12345 12345C

12347 12347A

can i know the best approach to do the above?

thanks

1 ACCEPTED SOLUTION

0 Kudos

REPORT ZEND_TEST16 .

types: begin of flat,

index type int4,

data type char6,

end of flat.

constants: c_abc(26) type c value 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.

data: lt_flatfile type table of flat.

data: lv_abc(26) value c_abc.

data: ls_flatfile type flat.

data: ls_flatfile_gw type flat.

field-symbols: <ls_flatfile> type flat.

*-- fill table

ls_flatfile-data = '12345'.

append ls_flatfile to lt_flatfile.

ls_flatfile-data = '12346'.

append ls_flatfile to lt_flatfile.

ls_flatfile-data = '12345'.

append ls_flatfile to lt_flatfile.

ls_flatfile-data = '12347'.

append ls_flatfile to lt_flatfile.

ls_flatfile-data = '12348'.

append ls_flatfile to lt_flatfile.

ls_flatfile-data = '12345'.

append ls_flatfile to lt_flatfile.

ls_flatfile-data = '12345'.

append ls_flatfile to lt_flatfile.

ls_flatfile-data = '12347'.

append ls_flatfile to lt_flatfile.

*--

loop at lt_flatfile assigning <ls_flatfile>.

<ls_flatfile>-index = sy-tabix.

endloop.

sort lt_flatfile by data.

loop at lt_flatfile assigning <ls_flatfile>.

if sy-tabix = 1.

ls_flatfile_gw = <ls_flatfile>.

continue.

endif.

if ls_flatfile_gw-data = <ls_flatfile>-data.

concatenate <ls_flatfile>-data lv_abc(1) into <ls_flatfile>-data.

shift lv_abc by 1 places left.

else.

lv_abc = c_abc.

ls_flatfile_gw = <ls_flatfile>.

endif.

endloop.

sort lt_flatfile by index.

loop at lt_flatfile assigning <ls_flatfile>.

write: / <ls_flatfile>-data.

endloop.

7 REPLIES 7

0 Kudos

REPORT ZEND_TEST16 .

types: begin of flat,

index type int4,

data type char6,

end of flat.

constants: c_abc(26) type c value 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.

data: lt_flatfile type table of flat.

data: lv_abc(26) value c_abc.

data: ls_flatfile type flat.

data: ls_flatfile_gw type flat.

field-symbols: <ls_flatfile> type flat.

*-- fill table

ls_flatfile-data = '12345'.

append ls_flatfile to lt_flatfile.

ls_flatfile-data = '12346'.

append ls_flatfile to lt_flatfile.

ls_flatfile-data = '12345'.

append ls_flatfile to lt_flatfile.

ls_flatfile-data = '12347'.

append ls_flatfile to lt_flatfile.

ls_flatfile-data = '12348'.

append ls_flatfile to lt_flatfile.

ls_flatfile-data = '12345'.

append ls_flatfile to lt_flatfile.

ls_flatfile-data = '12345'.

append ls_flatfile to lt_flatfile.

ls_flatfile-data = '12347'.

append ls_flatfile to lt_flatfile.

*--

loop at lt_flatfile assigning <ls_flatfile>.

<ls_flatfile>-index = sy-tabix.

endloop.

sort lt_flatfile by data.

loop at lt_flatfile assigning <ls_flatfile>.

if sy-tabix = 1.

ls_flatfile_gw = <ls_flatfile>.

continue.

endif.

if ls_flatfile_gw-data = <ls_flatfile>-data.

concatenate <ls_flatfile>-data lv_abc(1) into <ls_flatfile>-data.

shift lv_abc by 1 places left.

else.

lv_abc = c_abc.

ls_flatfile_gw = <ls_flatfile>.

endif.

endloop.

sort lt_flatfile by index.

loop at lt_flatfile assigning <ls_flatfile>.

write: / <ls_flatfile>-data.

endloop.

0 Kudos

Hi,

comment to the coding: It's not gonna work if you have more than 26 occurences of one flatfile-data item

regards

Steffen

Former Member
0 Kudos

first consider that field is VBELN

sort the internal table by VBELN

loop the internal table

IF GV_PRE_VBELN NE ITAB-VBELN.

PUT YOUR CONACTE LOGIC HERE

gv_pre_VBELN = ITAB-VBELN.

APPEND ITAB.

ELSE.

APPEND ITAB

ENDIF.

Former Member
0 Kudos

SORRY PUT EQ IN IF CONDITION

Former Member
0 Kudos

try this it may help you


data : begin of itab occurs 0,
       f1(10),
       end of itab.
data : count type i,
       flag,
       no type i value 1,
       pno type p decimals 2.
itab-f1 = '12345'.
append itab.


itab-f1 = '12345'.
append itab.

itab-f1 = '12346'.
append itab.

itab-f1 = '12345'.
append itab.

itab-f1 = '12347'.
append itab.

itab-f1 = '12348'.
append itab.

itab-f1 = '12345'.
append itab.

itab-f1 = '12345'.
append itab.

itab-f1 = '12347'.
append itab.

sort itab by f1.

loop at itab.
at new f1.
flag = 'X'.
endat.

pno = pno / 26.

no = ceil( pno ).
if flag is initial.
concatenate itab-f1 sy-abcde+count(no) into itab-f1.
count = count + 1.

else.
clear count.
endif.
write : / itab-f1.
pno = pno + 1.
clear : flag.
endloop.

it will work for more than 26 repeatation also..

regards

shiba dutta

0 Kudos

thanks all,

but i will have to code these in LSMW's IDoc structures.

meaning, i will not be able to read all the data from flat file at one time. i will have to process one line of record in flat file, then the next one (append alpha if duplicated exist), etc.

hope the above is clear

0 Kudos

Hi,

i don't know of a way to process the whole file within LSMW.

I would suggest preprocessing the file from a report at first and write the changed file back. After that start LSMW-processing.

regards

Steffen