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: 

LSMW with header and item data in the same file without identifier

raveeshsaurabh3
Active Participant
0 Kudos
2,145

Hi Gurus,

This may sound as a repeated question. But my problem is that I am receving the data in the below format.

Header  Fields     Item Fields

---------------------     ---------------------------

F1     F2     F3     F4     F5     F6

1       2       3        10     B      C

1       2       3         20    X       Y

2       4       6         10    U       V

2       4       6          20   U       V

............

Header Fields are repeating in case of multiple items.

I can handle the aceario via two files, one for header and another for item. Also via a single file where we have header and items provided separately in the file with an identifier('H' for Header and 'I' for Item).But user is not agreeing on these file formats.

File Format provided to us is provided above. It is easy to handle it via BDC, but i have identified the standard object and its method in LSMW which can handle this. But I am finding it difficult to handle this file in LSMW.

My question is how to segregate the transactions in LSMW for such files.

Thanks In Advance for the replies.

Warm Regards,

Raveesh

1 ACCEPTED SOLUTION

gabrielenosatti
Explorer
0 Kudos
386

Hi Raveesh,

another option could be play with the __BEGIN_OF_TRANSACTION__ or __BEGIN_OF_RECORD__ sections of the LSMW.

The sections are called for every line of the input file. You can declare global variables that you can use to compare the previous header values with the current values, and then skip the section if they are the same.

Regards,

Gabriele

14 REPLIES 14

rahul_vishwakarma2
Contributor
0 Kudos
386

Hi Friend,

I am not sure what you want. If i am not wrong you need to upload 2 separate files i.e. one for Header and other one is for Item Level. If this is the requirement, then you need to upload separate file for each under LSMW transaction to perform.

Regards,

Kundan

0 Kudos
386

Hi Kundan,

Client is not agreeing on two separate files.

Neither he is is agreeing on Sequential file with the structure as given below.

H

I

I

What I want is to implement the LSMW with the file format given in the question(Header Repeating for the item). I am not able to implement the same. Hence asking for help.

Can you check and come back to me. Thanks for your help!!

Regards.

Raveesh

0 Kudos
386

Hi Raveesh

Can you take the file as is, run it through a conversion program to put it in a format which LSMW can handle, ideally 2 separate files.

I've used conversion programs previously to take a file in one format, and convert into an LSMW acceptable format.

This way Customer does not need to change anything, as far as they're concerned your processing the file in the format you receive it.

Hope this helps

Regards

Arden

gabrielenosatti
Explorer
0 Kudos
387

Hi Raveesh,

another option could be play with the __BEGIN_OF_TRANSACTION__ or __BEGIN_OF_RECORD__ sections of the LSMW.

The sections are called for every line of the input file. You can declare global variables that you can use to compare the previous header values with the current values, and then skip the section if they are the same.

Regards,

Gabriele

0 Kudos
386


Hi Gabriele,

Thanks for the reply!!

I was trying to implement the same. But was wondering when to skip the transaction. For my example file. The transaction(Using _END_OF_TRANSACTION_)  should be skipped for the first record. But it should not be skipped for the 2nd record as it is the last record for the header. How will I identify if this is the last record inside the LSMW?

0 Kudos
386

Sorry, I'm checking now, and maybe it's better if you use the __END_OF_RECORD__ process point. Every segment has its own __END_OF_RECORD__ and other process points. You should see the instruction TRANSFER_RECORD. This instruction transfer the fields from its segment to the converted data file. You can control this instruction with your own logic, and avoid an header segment if another line from the file, with the same header fields, has already been translated.

What standard object are you using?

Hope I've been clear enough.

Gabriele

0 Kudos
386

Hi Gabriele,

Thanks for your response!!

I am getting your point. But My only query now is that how to identify whether to skip the transaction or not? I can identify the records which need to be skipped like for my example:

for 2nd row, header record needs to be skipped, but transaction does not need to be skipped, as this is the end of the transaction. How will I identify that?

I hope I am clear in asking.

Thanks for your help!!

Warm Regards,

Raveesh

0 Kudos
386

Hi Raveesh,

you're right: you need to transfer the transaction only for the second row.

In LSMW coding you don't have access to other lines of the file except for the one that is currently in process, so you don't know if it's the last one of your logical header.

You can try to use TRANSFER_TRANSACTION at the __BEGIN_OF_TRANSACTION__ process; doing this, you should transfer the last transaction, before the new one is initialized. At this point, you should have the previous line of the file (that you have saved in your global variable) and the new line that is going to be processed. Then you have to add another TRANSFER_TRANSACTION at __END_OF_PROCESSING__ to make sure you transfer the very last line of the file as well.

Of course, you should get rid of the standard TRANSFER_TRANSACTION.

Hope this makes sense.

Gabriele

0 Kudos
386

Hi Gabriele,

It seems we are just there . Only problem left is the last trasaction. TRANSFER_TRANSACTION is not working in END_OF_PROCESSING, since the output file has already been closed. I checked this in the source code of LSMW.

IF p_trfcpt = no.
CLOSE DATASET g_dsn_out.
ENDIF.

Because of which I am getting a short dump. If I remove the TRANSFER_TRANSACTION from END_OFPROCESSING, then other transactions are passed succesfully, except the last one.

Is there a way to identify if this is the last record or last ransaction?

Also i forgot to mention the object/Method. It is 0460/0001(Create Maintenance Plan).

Thanks a lot for your help!! It seems that we will be able to close this today once we can get the last record transferred.

Raveesh


0 Kudos
386

Good, almost there!

I had a look at the generated code.

There's a global variable that says if it's the end of the file or not: G_FLG_END_OF_FILE; try to use this.

The code where I found the variable:

form execute_data_conversion.

  data: struc_length type i.

  do.

    perform read_next_record.

    if g_flg_end_of_file = yes. exit. endif.

The variable closes the DO loop, but then the generated report executes the translation one last time.

You can check the variable value at the END_OF_RECORD for the last structure and then execute the TRANSFER_TRANSACTION.

Gabriele

0 Kudos
386


Hi Gabriele,

Thanks a lot for your help!!

It seems to have worked.

Warm Regards,

Raveesh

0 Kudos
386

You're welcome!

Regards,

Gabriele

Former Member
0 Kudos
386

Hi,

Go to User Menu in LSMW, check on Generate Read Program and Generate Conversion Program.

This is where you can write all ABAP logic needed.

0 Kudos
386


Hi Akhtar,

I can go and change the code there. But is it advisable. Won't my written code wiped out every time someone changes the mapping rules.?

Please advise.

Thanks,

Raveesh