cancel
Showing results for 
Search instead for 
Did you mean: 

Counting records in a flat file and Record number

Former Member
0 Kudos

Hi All,

I have been struggling to get a solution for this problem. Please help.

--> I have an IDOC to Flat file scenario. The flat file structure is mentioned below. The header and trailer come only once per file. The item segment repeats based on a few conditions. The catch is I am unable to generate a record number at every line. The record number has to be continous from the header to the last item. The first field of every line in the flat file is he record number.

--> Also the firlst field of the Trailer record is the Record Count, i.e. The total number of records in that flat file. Please help.

header - record number ,  ************* ,     ************

item1 -  record number ,  ************* ,     ************

item2 -   record number , ************* ,      ************

item n -   record number , ************* ,      ************

Trailer-    record Count   , ************* ,      ************

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Did you try using Global variable and increment it each time you create target node in a UDF.

-Amol

Shabarish_Nair
Active Contributor
0 Kudos

I had written a wiki on this some time back - http://wiki.sdn.sap.com/wiki/display/XI/Count+of+Records+-+%27Count+on+the+easiest+way+through%27

let me know if that helps

Former Member
0 Kudos

Hi Shabarish,

I have to count all the records in the target structure. There are some nodes which may or may not get generated depending on a few conditions.

So in a particular flat file if I have 1 header and 4 items and 1 trailer then the Flat file should look like this:

0001******************** (header)

0002******************** (item)

0003*******************  (item)

0004*******************  (item)

0005*******************  (item)

0005******************  (trailer)   -- here the trailer denotes total number of records in the file except the trailer.

Shabarish_Nair
Active Contributor
0 Kudos

solutions to such a requirement has been detailed in the wiki.

For simplicity, you can use two mappings to help you to achieve this. Do go through the wiki. Its all detailed there.

Former Member
0 Kudos

Hi Gopal

I have a scenario IDOC to File

requirement is :

in Idoc one line item repeats multiple times then thous many xml files has to be generate in receiver location.

Ex: line item 5 times repeated 5 xml files in one location.

the above one is my structure

if ZRDSPICK to repeats 5 times 5 xml files

but i am getting 5 messages in one file but required 5 different files

In mapping i kept occurrence 0-UB

signature occurrence 0-UB

ICO occurrence 0-UB still same prob

can please help

Former Member
0 Kudos

Rajesh, Did you follow below wiki -

maciej_jarecki
Contributor
0 Kudos

Hi

In mapping you change context to whole idoc, and use function

  • count to count all records.
  • Index to get current line

BR

Maciej

Former Member
0 Kudos

try this - the source msg should have line items to correspond to your target item structure. take the name of the line item segment and do a collapseContext followed by index function ,  then add 1 to it for header.

in case of header, map it to constant 1.

in case of trailer, above logic of item and instead of adding 1 add 2 to get the total record count.