Application Development and Automation 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: 
Read only

Lsmw

Former Member
0 Likes
1,018

Hi,

any body can give me he steps and proper file format for uploading LONGTEXTS thru direct input program.

Regards

Murty

<LOCKED BY MODERATOR - USE APPROPRIATE TITLES>

Edited by: Alvaro Tejada Galindo on Jan 8, 2009 4:03 PM

Hi,

any body can give me he steps and proper file format for uploading LONGTEXTS thru direct input program.

Regards

Murty

<LOCKED BY MODERATOR - USE APPROPRIATE TITLES>

Edited by: Alvaro Tejada Galindo on Jan 8, 2009 4:03 PM

7 REPLIES 7
Read only

Former Member
0 Likes
971

using function mod

call funcation 'Save_test'

Read only

Former Member
Read only

Former Member
0 Likes
971

Registered: 4/4/07

Total Questions: 84 (75 unresolved)

Vague title

Wrong Forum

Reported!!

pk

Read only

Former Member
0 Likes
971

Hi,

hope this is enough coding to understand it.

xeing is an normal textfile, which was uploaded.


FORM verarbeitung.
  data: merker type i,
        zaehler type i.

  sort xeing by matnr spras LFDZL.

  loop at xeing where matnr ne space.
    add 1 to zaehler.
    dmatnr = xeing-matnr.
    replace '.' with '' into dmatnr.
    replace '-' with '' into dmatnr.
    condense dmatnr no-gaps.

    vmatnr = xeing-matnr.
    vmtart = xeing-mtart.
    vmstae = xeing-mstae.
    vdline = xeing-dline.

    select single * from mara where matnr eq dmatnr.
    if sy-subrc eq 0.
      at new spras.
        perform werte_setzen.
        refresh: xtxt, xtxt_read.
      endat.
      at new matnr.
        perform werte_setzen.
        refresh: xtxt, xtxt_read.
        Move: xeing-matnr to new_mara-matnr,
              'Grunddatentext' to new_mara-vpsta.
        append new_mara.

        Move: xeing-matnr to old_mara-matnr.
        append old_mara.

      endat.

      *xtxt-TDFORMAT  = '/'.*
      data: dtext1(74) type c,
            dtext2(74) type c.

*     laenge = strlen( xeing-dline ).
*     if laenge = 1.
      lh_return = '0D'.
      split xeing-dline at lh_return
        into dtext1
             dtext2.
      xtxt-tdline    = dtext1.
*     else.
*        split xeing-dline at lh_horizontal_tab
*           into dtext1
*                dtext2.
*        xtxt-tdline    = dtext1.
*      endif.
      append xtxt.
      ld_count = ld_count + 1.

      dmatnr = xeing-matnr.
      replace '.' with '' into dmatnr.
      replace '-' with '' into dmatnr.
      condense dmatnr no-gaps.

      clear merker.

      at end of spras.
        if pa_test is initial.
          merker = 1.
* Text ändern
          perform text_aendern.
        endif.
      endat.
      at end of matnr.
        if pa_test is initial and merker ne 1.
* Text ändern
          perform text_aendern.
        endif.
      endat.
      write: /.
      write: xeing-matnr, ' = ', dmatnr, ' = ', zaehler, ' = OK'.
    else.
      move: dmatnr              to imail-matnr,
            xeing-spras         to imail-spras.
      write: /.
      write: xeing-matnr, ' = ', dmatnr, ' = ', zaehler, ' = NO'.
      collect imail.
    endif.

  endloop.
ENDFORM.                    " verarbeitung

*************************************
FORM text_aendern.

  data: ltext LIKE bapi_mltx OCCURS 0 WITH HEADER LINE,
        lhead like BAPIMATHEAD,
        dreturn like BAPIRET2.

  clear ltext[].
  loop at xtxt.
  move: xtxt-tdformat to ltext-FORMAT_COL,     "xtxt-tdformat = /
          xtxt-tdline   to ltext-TEXT_LINE.      "xtxt-tdline = INITIAL
    ltext-APPLOBJECT  = pa_objec.                "Pa_objec = MATERIAL
    ltext-TEXT_NAME    = dmatnr.                 "dmatnr = 96312103
    ltext-TEXT_ID      = pa_id.                  "pa_id = GRUN
    ltext-LANGU   = xeing-spras.                 "ltext-langu = DE
* NEU
    if ltext-TEXT_LINE = 'LZGRUND'.
      ltext-del_flag = 'X'.
      lhead-basic_view = 'X'.
    else.
      ltext-del_flag = ' '.
      lhead-basic_view = ' '.
    endif.
    append ltext.
  endloop.

  lhead-material = dmatnr.                      "dmatnr = 96312103
* NEU

  *CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'*
       *EXPORTING*
            *HEADDATA         = lhead*
       *IMPORTING*
            *RETURN           = dreturn*
       *TABLES*
            *MATERIALLONGTEXT = ltext.*
  clear xtxt_read.

  if dreturn ne space.
    if dreturn-type eq 'E' or dreturn-type eq 'W'.
      move: ltext-TEXT_NAME          to imail-matnr,
            ltext-LANGU              to imail-spras,
            dreturn-message          to imail-text.
      append imail.
    endif.
  endif.

eNDFORM.                    " text_aendern

Code Formatted by: Alvaro Tejada Galindo on Jan 8, 2009 4:02 PM

Read only

Former Member
0 Likes
971

Hi,

1. TCode : LSMW.

2. Enter Project name, sub project name and object name.

Execute.

3. Maintain object attributes.

Execute

select Batch Input recording

goto->Recording overview

create

recording name.

enter transaction code.

start recording

do recording as per ur choice.

save + back.

enter recording name in lsmw screen.

save + back

Now there will be 14 steps.

2. MAINTAIN SOURCE STRUCTURES.

Here you have to enter the name of internal table.

display change

create

save + back

3. MAINTAIN SOURCE FIELDS.

display change

select structure

source_fields->copy fields.

a dialogue window will come .

select -> from data file

apply source fields

enter No. of fields

length of fields

attach file

save + back

4. MAINTAIN STRUCTURE RELATIONS

display change

save + back

5. MAINTAN FIELD MAPPING & CONVERSION RULE

display change

click on source field, select exact field from structue and enter

repeat these steps for all fields.

save+back

6. MAINTAIN FIXED VALUES, TRANSACTION, USER DEFINED

execute

save + back

7. SPECIFY FILES.

display change

click on legacy data

attah flat file

give description

select tabulatore

enter

save + back

8. ASSIGN FILE

execute

display change

save + back

9. IMPORT DATA.

execute

display change

save + back

10. DISPLAY IMPORTED DATA

enter ok, it willl show records only.

back

11. CONVERT DATA

execute

display change

save + back

12. DISPLAY CONVERTED DATA

execute

display change

save + back

13. CREATE BATCH INPUT SESSION

tick keep batch input folder

F8

back

14. RUN BATCH INPUT SESSION.

sm35 will come

Object name will be shown here

select object & process

Regards

Md.MahaboobKhan

Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
971

Hi Satya,

Use this link:-

https://wiki.sdn.sap.com/wiki/display/ABAP/Stepstocreateasimple+LSMW

Hope this solves your problem.

Thanks & Regards,

Tarun Gambhir

Read only

Former Member
0 Likes
971

Step-by-Step Guide for using LSMW to Update Customer Master Records

Note! The screen prints in this article are from IDES Release 4.6. They may differ slightly in other versions.

Demo Example 2

LSMW to Update Customer Master Records with Standard Object

As an alternative to using u2018Transaction Recordingu2019, you could also use a standard SAP object to update Customer Master Records. Business Object u20180050u2019 is already pre-defined in the system with standard Batch Input Interface Program u2018RFBIDE00u2019.

Create an Object CUST_OBJ within Project as LSMW_DEMO and Subproject as CUSTOMERS as shown in Figure 20.

Figure 20 LSMW Object with Standard SAP Object

Note! For the Demo example 2, I will list only those steps that are different from the first demo example.

Step 1: Maintain Object attributes

You will be updating the customer master records with the help of Standard Batch Input; therefore, choose radio-button Standard Batch/Direct Input as shown in Figure 21. Enter Object u20180050u2019 for Customer Master Records and default method u20180000u2019 and click on Save.

Figure 21 Standard Batch/Direct Input Object Attributes

Step 2. Maintain Source Structures

Give a name and a description to the source structure (Figure 8).

Figure 8 Source Structure

Step 3. Maintain Source Fields

In this step, you need to list what fields are present in the source structure. The easiest way is to click on u2018Table Maintenanceu2019 icon to enter Fieldname, Type and Length for each field as shown in Figure 9.

Figure 9 Source fields of source Structure

Note that your input file will have four fields as key fields and you need to update three fields in the system.

Step 4: Maintain Structure Relations

Sales view of Customer Master is stored in table KNVV. Accordingly, you need to update structure BKNVV. However, in addition, the Standard Object u20180050u2019 also requires updates to BGR00, BKN00 and BKNA1 structures. (If you do not maintain Structure relations for mandatory entries, you might get a message such as u2018Target structure BKNA1 needs a relation to a source structureu2019.)

Even though you donu2019t want to update any fields in these structures, you need to create a relationship with source structures. In all, you need to create relationship for four target structures.

Create relationship between source structures XD02S with these target structures with icon u2018Create Relationshipu2019 .

Keep Cursor on these four target structures and click on icon u2018Create Relationu2019 and structure relations are maintained as shown in Figure 22.

Figure 22 Structure Relation

Step 5: Maintain field mapping and conversion rules

-- Keep your cursor on u2018TCODEu2019 field and click on u2018Insert Ruleu2019 icon

Figure 23 LSMW Conversion Rules

Choose radio button u2018Constantu2019 (Figure 23) to enter value u2018XD02u2019 transaction code.

-- Keep your cursor on field u2018KUNNRu2019 and click on u2018Assign source fieldu2019 icon

Choose source field u2018Customeru2019 from source structure u2018XD02Su2019. (See Figure 24.)

Figure 24 Assign Source fields

-- Similarly, choose source fields for Sales Organization, Distribution Channel, and Division. (See Figure 25.)

Figure 25 Field Mapping and Conversion Rules

-- Scroll down to structure BKNVV fields and assign source fields to three fields Sales Office, Sales Group, and Customer Group (Figure 26).

Figure 26 Field Mapping and Conversion Rules

Save and go back to main screen.

Step 6: Maintain fixed values, translations, user-defined routines

You can also maintain re-usable translations and user-defined routines, which can be used across conversion tasks. In this case, that step is not required.

Step 7: Specify files

In this step, we define how the layout of the input file is. The input file is a [Tab] delimited with the first row as field names. It is present on my PC (local drive) as C:\XD02.txt. (See Figure 13.)

Figure 13 File attributes

Create an Excel file (Figure 14) with your data and save it as a Tab-delimited text file on your local drive (C:\) and name it XD02.txt.

Figure 14 Source data in Excel file (saved as Tab delimited file)

Step 8: Assign files

Execute step u2018Assign Filesu2019 (Figure 15) and the system automatically defaults the filename to the source structure.

Figure 15 Assign file to Source Structure

Step 9: Read data

In this step, LSMW reads the data (Figure 16) from the source file (from your PCu2019s local drive). You have the option to read only selected rows and convert data values to Internal format.

Figure 16 Read Data

Step 10: Display read data

This step (Figure 17) is optional. If required, you can review the field contents for the rows of data read.

Figure 17 Display Read Data

Step 11: Convert data

This is the step that actually converts the source data (in source format) to a target format. Based on the conversion rules defined, source fields are mapped to target fields.

Step 12: Display Converted data

When you convert data, LSMW automatically converts into the appropriate structure layouts, as required by Standard program (RFBIDE00). (See Figure 27)

Figure 27 Converted data into multiple structures

Note that if you had only one record in source file, the converted file has four records.

Earlier, creating this input file, so that the standard interface program can read it, was a big nightmare, the primary reason being that it could have multiple record layouts. Even for a simple conversion with one input record, you would have to create this complex file with many record layouts. The advantage of LSMW is that it prepares these multi-layout files automatically.

Step 13: Create batch input session

Once source data is converted in internal format, you can create a BDC session to process the updates (Figures 28 and 29).

Figure 28 Create BDC Session

Figure 29 BDC Session u2018CUST_OBJu2019 created

Step 14: Run Batch Input Session

You can execute the BDC session by Run Batch input session. Executing a batch input session is a standard SM35 transaction for managing BDC sessions. Once you have successfully executed the batch input session, the customer master records are updated in the system. You can confirm this by viewing the customer master records (XD03).

Note! Browsing thru these 14 steps, you may get a feeling that this is a very lengthy and time-consuming activity. However, for the purposes of demonstration, I have made it detailed. Although it looks lengthy, actually it takes hardly few hours from start-to-finish! After playing around with few simple LSMW scripts, you will find it so easy to change and create more complex ones.