Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

LSMW User define routine translation

hi gurus,

I'm trying to load assets using LSMW. Everything is working fine except a minor issue. I'm trying to upload the vendors' for assets by using translation. There are some valid vendor codes which I've maintained in translation table. However there are some invalid vendor codes from legacy system (the asset is very old and the company doesn't deal with the vendor no more). For these invalid codes I want to assign a constant value but since I've not maintained the translation for these codes, LSMW issues an error during conversion. How can I create a user defined routine to assign the invalid vendor codes that I haven't maintained in the table to a constant value. thanks

Former Member
Former Member replied

In the step u201CMaintain Field Mapping and Conversion Rulesu201D declare global variables in the

u201CGlobal Data Definitions and Declarationsu201D section after you select all the checkboxes in the Popup window u201CDetermine Layoutu201D from the menu path u201CExtras / Layoutu201D.

Here is a example of the global data declaration :

  • __GLOBAL_DATA__

DATA: cTmp(250) TYPE C, iTmp TYPE I.

TYPES: BEGIN OF stBase.

TYPES : MESSAGE(250) TYPE C,MESSAGET

INCLUDE TYPE ZCAFSMMUPLDFMT.

TYPES : EWFIELDS(2000) TYPE C.

TYPES: END OF stBase.

Then, at the bottom of the u201CDisplay Field Mapping and Conversion Rulesu201D screen you can enter your User ABAP Routine within the u201CForm Routine (ABAP routines)u201D node. Below is a example of a routine :

FORM urOutputE1MARCM CHANGING pOut.

pOut = 0.

CLEAR waTmpE1MARCM. FREE itTmpE1MARCM.

MOVE-CORRESPONDING E1MARCM TO waTmpE1MARCM.

APPEND waTmpE1MARCM TO itTmpE1MARCM.

iTmp = 0.

iTmp = STRLEN( waTmpE1MARCM ).

IF iTmp > 0.

REPLACE ALL OCCURRENCES OF REGEX '/' IN TABLE itTmpE1MARCM WITH '

iTmp = 0. CLEAR waTmpE1MARCM.

MOVE-CORRESPONDING itTmpE1MARCM TO waTmpE1MARCM.

LOOP AT itTmpE1MARCM INTO waTmpE1MARCM. ENDLOOP.

iTmp = STRLEN( waTmpE1MARCM ).

IF iTmp > 0.

pOut = 1.

ELSE.

pOut = 0.

ENDIF.

ENDIF.

ENDFORM.

You can then call the routine within your mapping. I used the example a in the u201C__END_OF_RECORD__u201D node of a IDoc Segment to control whether or not the Segment is to be outputted or not.

PERFORM urOutputE1MARCM CHANGING iTmp.

IF iTmp > 0.

transfer_record.

ENDIF.

I hope this helps some.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question