cancel
Showing results for 
Search instead for 
Did you mean: 

Adding Header to a file in append mode

Former Member
0 Kudos

Hi All,

I have a requirement where in i need to add one file header to a file in append mode .

The requirement is as follows :

In a day , SAP sends certain number of IDOCs to XI . For the first IDOC that comes in ,XI has to create a file and later for the rest of the IDOCs ,XI just has to append the file content .

- At the End of the Day , the target system picks this file for processing.

My file structure is as follows:

File Header

seg1

seg2

seg3

seg1

seg2

seg2

seg3

seg3

While creating a file in append mode at receiver , the header record gets appended multiple times which is not desirable.

Please suggest me ways to make sure that the file gets written in the above format with the file header only once .

Thanks for your help,

Pooja

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Thank you,

I achieved the desired output with the help of a UDF that checks the presence of target file (at the mentioned path) and the absence serves as an indicator to create the header.

Thanks,

Pooja

ambrish_mishra
Active Contributor
0 Kudos

Nice one...

ambrish_mishra
Active Contributor
0 Kudos

Pooja,

What if multiple IDocs hit PI at the same time and the while your UDF is executing the file is being written ?

Please test the solution by triggering multiple IDocs at the same time just to avoid surprises at Go live

Hope it helps!

Ambrish

Answers (6)

Answers (6)

Former Member
0 Kudos

Hi Pooja,

I too have the same requirement and tried a lot with FCC parameters.

can you please share the sample UDF or any links which can help.

Thanks in Advance.

Gouse

Former Member
0 Kudos

Hello Pooja,

Can you please share your solution in detail. We are using content conversion and have column names for each column in the file. In the append mode the column names repeat every time a file is appended. please advise.

Thanks

Arvind

arkesh_sharma
Active Participant
0 Kudos

Hi Pooja,

This is just a suggestion. Please let me know if this doesn't suit you.

Suggestion:

Create a Global container variable. Set the value as false by default. When the value comes in PI for the first time, pass the header data and set the value of global variable as true and start a timer in the UDF itself which will keep track of time. For every consecutive record, check the value of the global variable if it is true/false. If it is true then do not map the header data. Reset the value of the global variable to false when the timer reaches a value of 24 hours (say for example).

Thanks,

Arkesh

ambrish_mishra
Active Contributor
0 Kudos

Hi Arkesh,

AFAIK, the value of a global container is persisted till the execution of a mapping nor will a UDF work beyond a message execution.

Here the requirement is to see through multiple message executions and append Header only once while trying to avoid a BPM solution.

Ambrish

PS: I don't comment on alternate solutions but don't want Pooja to get confused here.

arkesh_sharma
Active Participant
0 Kudos

Hi Ambrish,

Thank You for responding to my comment.

My comment was based on a blog (http://scn.sap.com/people/gabrielsagayaselvam.panneerselvam/blog/2011/05/05/jdbc-lookup-optimization) but missed on the persistence point.

Thank You for pointing that out. I will keep that in mind.

Thanks,

Arkesh

Former Member
0 Kudos

Hi Pooja ,

Why dont you use a BPM to collect all the messages and write the file in one shot .

You can either add a waiting time inside the BPM or you can ask ABAP to trigger an proxy message in the end once all the IDOCS have been sent out of R3 . In the BPM , you can use this proxy message as a trigger to stop collecting and then proceed further.

Regards

Vinay

Former Member
0 Kudos

Pooja,

Is there a flag/identifer that would tell PI that the IDOC being sent is the first IDOC in the day?

If not what you are asking for cannot be achieved with simple design. Until the source system sends any kind of identifier this is not possible.

The other round about way of doing this, is to read the file you have create thorugh out the day, read it back into PI and  remove the header whereever not required.

Ambrish, not sure what property file you are refering to here? Do you have any link that we can go through. Even if the property file solution works, I think it would be a very rigid design as it will be dependent on 24hr clock.

-Vicky.

ambrish_mishra
Active Contributor
0 Kudos

Hi Pooja,

You can try like below:

You need an indicator to make sure you don't populate the header the second time. You can ask ABAP team to populate this indicator. So the second time, don't populate the header data based on this indicator. Is the target file fixed length or delimited ?

Ambrish

Former Member
0 Kudos

Hi Ambrish,

Thanks for the approach

The ABAP team is collecting IDOCs and then processing it in batch. In Batch processing, the IDocs need not be passed to XI in sequence; therefore the indicator for the first record may not work in this case (the sequence is not maintained).

The target file is fixed length.

Pooja

ambrish_mishra
Active Contributor
0 Kudos

Hi Pooja,

In that case, work with a property file. so for a particular day maintain the values in property file like current date       dateValue

Header              Y/N

In the first run, check the property file if cuuent date is null && header date is N, then update date as today's date and header as Y... in subsequent runs, since it is Y for a particular day, then don't update the header in the target.

hope it helps!

Ambrish

ambrish_mishra
Active Contributor
0 Kudos

Pooja,

If you need any further inputs on the above, do revert back.

Ambrish