In this blog, get some advanced tips for using the LSMW to initialize an IDoc structure with nodata signs and modify data records on the database table.
Many IDoc types use a nodata sign in LSMW recordings and batch input. This nodata sign (usually a forward slash “/”) is used to notify the data migration program that a field doesn’t contain a value (no data). This is to prevent the data migration program from writing a blank value into such fields.
The LSMW normally generates a structured variable init_<target structure> for each assigned target structure. This is done via FORM routine initialize_with_nodata. This variable can be used to initialize the fields of a target structure with nodata signs. You define the nodata sign value in the global variable g_nodata. This variable won’t be filled if you use the IDoc import method within the LSMW. You have to set this global variable once in the LSMW field mapping.
(Note: To migrate material master records, you’ll use the IDoc type MATMAS06. There are material master records in the target system that need to be updated. You only want to update some fields; the other field values must not be overwritten.)
All fields needs to be initialized with a nodata sign (/). In this example, we’re using the target structures E1MARAM and E1MAKTM..
The coding to initialize the structured variables init_e1maram and init_e1maktm must be inserted at processing time _BEGIN_OF_PROCESSING_ (see below). The first FORM routine’s USING parameter is filled with the name of the target structure E1MARAM and E1MAKTM, respectively. The second parameter is filled with the structured variable’s name init_e1maram and init_e1maktm.
* __BEGIN_OF_PROCESSING__ g_nodata = '/'. PERFORM initialize_with_nodata USING 'E1MARAM' init_e1maram. PERFORM initialize_with_nodata USING 'E1MAKTM' init_e1maktm.
The target structure fields will then be initialized in the target structure’s processing time _BEGIN_OF_RECORD_ (first code below). The following code samples show the processing time _BEGIN_OF_RECORD_ of the target structures E1MARAM and E1MAKTM. The initialization code to insert is written in bold.
g_edidd_segnam = 'E2MARAM006'. g_edidd_segnum = '0001'. g_edidd_psgnum = '000000'. g_edidd_hlevel = '02'. CLEAR E1MARAM. E1MARAM = INIT_E1MARAM.
g_edidd_segnam = 'E2MAKTM001'. g_edidd_segnum = '0004'. g_edidd_psgnum = '000001'. g_edidd_hlevel = '03'. CLEAR E1MAKTM. E1MAKTM = INIT_E1MAKTM.
Below shows how this will look in the field mapping:
Program coding in processing time _BEGIN_OF_PROCESSING_ is inserted between the LSMW conversion program sections reset_tables and execute_data_conversion.
These tips should help you better understand and be prepared for using the LSMW to initialize an IDoc structure with nodata signs as well as modify data records on the database table.