Enterprise Resource Planning Blogs by Members
Gain new perspectives and knowledge about enterprise resource planning in blog posts from community members. Share your own comments and ERP insights today!
cancel
Showing results for 
Search instead for 
Did you mean: 
JL23
Active Contributor

This blog shall explain how to load long text with LSMW direct input method.

It does not really matter if the long text belongs to material master or vendor master, customer master or even to transactional data like contracts or bill of materials.

Long text to any object is stored in the SAP's long text tables STXH (header) and STXL.(lines)

Most objects do not have any indicator that tells about existing long text, It is just a piece of code that is executed when you go to the text screens and retrieves the text from STXH and STXL table if present.  Hence inserting text with the correct key into these tables will automatically make this text available when you e.g. go MM02 Material master change transaction into the purchase order text view.

Our business case here is to add purchase order long text to material masters that got migrated earlier.

The source file is prepared in Excel and has just 3 columns: old material number, purchase order long text and line number

I do not explain any single LSMW step in this blog in deep detail as I described it in in my other blogs:

LSMW Material master by BAPI method - Part 1

LSMW Material master by BAPI method - Part 2

So i am just focusing here on the difference to these other blogs and the specifics with the direct input method and how do deal with long text.

I am continuing in my existing project SCN, with subproject MATERIAL and create a new object called MM_PO_TEXT

LSMW Step 1 Maintain object attributes

Set the radio button to Standard/Direct Input Import Method

Then move the cursor into the Object field and use F4 to find the object for Long texts

Do the same for the Method.

The Program name and the program type will then be defaulted by SAP itself.

The icon with the glasses allows you to display the source code of this program (I have used twice in lifetime, but only to answer a question in the forum, I never needed it for myself, especially not to execute this LSMW method)

LSMW Step 2 Maintain Source Structures

My source file is just a flat file without deeper structure, so only one entry in this step needed. I name my structure LONGTEXT

LSMW Step 3 Source Fields

Now I am adding the fields to this structure. As I have only a few fields I am doing it using the table icon.

Defining the fields in the same sequence as they appear in my source file

Define them as character fields, with a field length like it was in the legacy system,

The length of the old material number does not matter in this case as the  material number itself was never that long in the legacy system.

The attentive reader will see that I just entered 2 fields in the source field definitions while my source file has 3 fields.

Reason: I am lazy. To be honest I do not make use of the content of the line number field in this upload program.

I only require this line number in the Excel file as an objective evidence for the sequence of lines in case there are multiple lines.

LSMW Step 4 Maintain Structure Relations

The target structure is automatically proposed based on the chosen import method in LSMW step 1.

I assign my source structure to both structures, header and row.

LSMW Step 5 Maintain Field Mapping and Conversion Rules

To keep my program flexible for any language that need to be loaded (per source file one language)

I am adding a selection parameter in the __GLOBAL_DATA__ section.

Just double click the light blue field with the name  __GLOBAL_DATA__ to get into the code editor

Enter here a statement   PARAMETER: PSPRAS like MAKT-SPRAS

PSPRAS is my field name and with the LIKE MAKT-SPRAS I tell the program that it shall be like the language field from MAKT table.

Further I add a data declaration for 2 other fields:

W_SKIP TYPE i. this is an integer number field that I want to use to count the records I cannot convert

and

W_SKIP_FLAG type C VALUE ' '  which describes a character field with no initial content. I will use this to trigger the event to skip the transaction.

In the header structure I assign a constant "MATERIAL" to the object field, and a constant "BEST" to the ID field

(You can obtain these values if you go into the text view of existing data and click there the text editor icon. After you are taken to the text editor chose from menu Goto > header and you will see the key fields and its content)

The NAME field shall get the new material number. But my source file has only the old material number.

Hence I need to add coding to determine the material number based on the old number.

As you know, the old material number is stored in the basic data view of material master. Go into the material master Press F1 in that field and then the icon for technical field help and you can see the field name and the table.

With this information we can create the coding to get the material number.

First I add a data declaration to define a workarea. which will receive the found data.I could have done this already in the __GLOBAL_DATA__ section, but it can be done everywhere in the source.

Then a select statement to find a record in table MARA that matches with my old material number.

If a record is found, then the material number is moved to the target field /SAPDMC/LTXTH-NAME

If not found, then I write a message into the conversion log to know which old material number could not be converted. And I move a Y (for YES) into my help field w_skip_flag: This is as well for safety reasons. The direct input will not check if your material exists. It will just post what you deliver, regardless if correct or nonsense. So you can create a lot of ghost texts if you do not care enough. Hence you need to control it yourself.


SELECT  single  * FROM  MARA into WA_MARA

       WHERE  BISMT  = longtext-old_number.

if sy-subrc = 0. "record found

  /SAPDMC/LTXTH-NAME = WA_MARA-MATNR.

else.

  WRITE:/ longtext-old_number , 'not in MARA-BISMT'.

  w_skip_flag = 'Y'.

endif.

Next is the language field which needs some attention. You remember, I had defined a selection parameter for the language to be flexible and to use the same LSMW object for whatever language that will be loaded.

I start again with a data declaration for a workarea for the language, because I need to check that I do not enter nonsense into the language parameter field.

So I verify the entered language if it is available in the language table T002.

If the entered language cannot be found, then I skip the record from being loaded. Which is then the case for all records as the language parameter is only entered once. And in that case I write as well a small message into the conversion log.

Now look what I have done at the __END_OF_RECORD__   processing time.

I changed the default "transfer_record" into "on_change_transfer_record"

This little change controls that the header record is only written when the material number changes (material number is the only variable in the header structure)

This means I write just one header record while I write several rows.

In the structure for the row I only assign my long text line. SAP is processing the source file from the first record in sequence to the last record, thus I do not need the line number from my source file.

Now to the final manipulations. in the processing time __END_OF_TRANSACTION__ I check my help field. This help field has the value 'Y' in case the material number could not be found for the given old material number, hence I have to skip this transaction from posting.

And at the __END_OF_PROCESSING__ I write the numbers of skipped records to the conversion log.

which will then look like in this screenshot:

LSMW Step 6 Maintain fixed values, Translations , user defined routines

Not necessary for this business case

LSMW Step 7 - Specify files

Save the Excel source file as Unicode Text. Then specify this text file in step 7.

LSMW Step 8 - Assign Files

As there is only one source structure and one source file, SAP does the proposal and you only need to click save

LSMW Step 9 - Read Data

SAP generates the read program, you can execute it for the entire file or just for a selection of records.

SAP will give you a summary of read records and read transactions.

Compare it with your source file to be certain that everything was read.

LSMW Step 10 - Display read data

Important step to check that you data was correct read and that it was transferred to the fields defined in step 3.

From the overview click a line to get to its detail view..

LSMW Step 11 - Convert Data

In the conversion step you can execute the conversion for all records that where read from your source file, or just for a selection for a test case.

Here you can see the parameter PSPRAS for the language, that I defined in step 5 Mapping rules.

LSMW Step 12 - Display converted data

In this screenshot of the converted data you can see that the new material number is assigned.

The yellow lines represent the header, and the blue lines the text lines.

So you see that we have 2 materials with just one long text line followed by a material with 6 lines

LSMW Step 13 - Execute Direct Input

In this step you execute, post the data to your SAP system.

SAP defaults all data. you only need to click execute

The long text upload is really done in a few seconds for many hundred records, don't be surprised, nothing wrong.

When finished SAP gives you this summary:

Loading long text means that SAP does REPLACE existing text with the same key.

Even the old text has many hundred lines and the new text just one, all lines of old text are deleted and then the new text written.

73 Comments
Labels in this area