Call Transactions from LSMW by Clicking on Document Numbers in a Report

Jimbo's picture

While meaningful reporting can be invaluable for high-level downstream reporting and granular upstream reporting, it is also useful for the data conversion specialist loading the data. A user can copy-paste a document number or a Master Data number from a report into other transactions to view them, but a faster and more accurate way to do the same thing is by letting the user click on the number and having LSMW open the transaction directly to the desired object.

This example is from a report used to sunset duplicate thousands of Vendor Masters that were created when a Big 4 firm's specialist created new Vendor Masters as SAP was rolled out to each division in the company. The created a batch to extend survivor Vendor Masters to the Company Code and Purchase Org of the duplicate Vendor Masters and then block the victim Vendor Masters in a meaningful way based on what documents posted against the victim were still open.

The tool generated a report that, by complete accident, worked perfectly as a way to determine what parameters to pass to which transaction. It included the table from which the data was teased and the pertinent information to be passed into the appropriate transaction.

Here, the open financial documents associated with the victim are pulled from the BSIK table and displayed on the screen. Notice the hotspot keyword on the write line; that comes into play later.

select * from BSIK into lBSIK where LIFNR eq p_Victim.
  add 1 to OpenDocs.
  write: / 'BSIK' color col_negative, lBSIK-BELNR color 3 hotspot,
  lBSIK-BUKRS, lBSIK-GJAHR, lBSIK-BUDAT,
   'Open financial document.' color col_negative.
  select * from BSEG into lBSEG
   where BELNR eq lBSIK-BELNR
     and BUKRS eq lBSIK-BUKRS
     and GJAHR eq lBSIK-GJAHR
     and BUZEI eq 1.  "The first line item.
    select single * from TBSLT into lTBSLT
     where BSCHL eq lBSEG-BSCHL and spras eq sy-langu.
    write: 'PK:', lBSEG-BSCHL color 3, lTBSLT-LTEXT,
     lBSEG-PSWSL, lBSEG-PSWBT.
endselect.

The document number BELNR becomes a clickable object on the screen that calls some ABAP code from the GLOBAL_DATA section of the Field Mapping and Conversion Rules. The AT LINE-SELECTION code here looks at the SY-LISEL value which is the contents of the line on which the user clicked.

Because the table name is at the beginning of each line, it is easy to intuit what transaction should be opened and what values should be passed to that transaction. Here, the document number, Company Code and fiscal year are passed to the FB03 transaction while only the document number is passed to the ME23N transaction.

AT LINE-SELECTION.
  CASE sy-ucomm.
    WHEN 'PICK'.
      case sy-lisel+0(4).
        when 'BSIK' or 'BSAK'.
          set parameter id 'BLN' field sy-lisel+5(10).
          set parameter id 'BUK' field sy-lisel+16(4).
          set parameter id 'GJR' field sy-lisel+21(4).
          call transaction 'FB03' and skip first screen.
        when 'EKKO' or 'EKPA'.
          set parameter id 'BES' field sy-lisel+5(10).
          call transaction 'ME23N' and skip first screen.
        when others.
      endcase.
    when others.
  endcase.

KDY codes for XK03Launching the XK03 transaction from a report is a little more difficult, but not much more. It requires a little extra effort to tick the boxes appropriate for processing the screens based on whether the Company Code and/or Purchasing Org is being passed into it.

It works by passing the 3-digit codes for the desired processing options, each separated by a forward slash, as a string parameter to the XK03 transaction and the string must start with a forward slash. This snippet pulls up the desired screens for viewing or editing the Vendor Master.

This code is from another tool and each line begins with the number of the Vendor Master. It required the use of the SY-CUCOL to know where on the line the user clicked; a value less than 11 was assumed to be a click on the Vendor Master number at the beginning of the line.

data: lLIFNR like LFA1-LIFNR, 
      lLFM1 like LFM1, lLFB1 like LFB1,
      kdy_val(40) type c.

AT LINE-SELECTION.
  CASE sy-ucomm.
    WHEN 'PICK'.
      if sy-cucol lt 11. "Clicked on vendor number...
        lLIFNR = sy-lisel+0(10).
        if lLIFNR co '1234567890 '.
          shift lLIFNR right deleting trailing space.
          overlay lLIFNR with '0000000000'.
        endif.
        set parameter id 'LIF' field lLIFNR.
        kdy_val = '/110/120/130'. "LFA1 data.
        case sy-lisel+11(4).
          when 'BSIK' or 'BSAK'.
            set parameter id 'BUK' field sy-lisel+27(4).
            kdy_val = '/110/120/130/210/215/220'. "LFA1 and LFB1
          when 'EKKO' or 'EKPA'.
            set parameter id 'BUK' field sy-lisel+27(4).
            kdy_val = '/110/120/130/210/215/220'. "LFA1 and LFB1
          when 'LFA1'.
            select * from LFB1 into lLFB1 where LIFNR eq lLIFNR.
              set parameter id 'BUK' field lLFB1-BUKRS.
              kdy_val = '/110/120/130/210/215/220'. "LFA1 and LFB1
            endselect.
          when others.
        endcase.
        select * from LFM1 into lLFM1 up to 1 rows
         where LIFNR eq lLIFNR.
          set parameter id 'EKO' field lLFM1-EKORG.
          concatenate kdy_val '/310/320' into kdy_val.
        endselect.
        set parameter id 'KDY' field KDY_VAL.
        call transaction 'XK03' and skip first screen.
      else.
        case sy-lisel+11(4).
          when 'BSIK' or 'BSAK'.
            set parameter id 'BLN' field sy-lisel+16(10).
            set parameter id 'BUK' field sy-lisel+27(4).
            set parameter id 'GJR' field sy-lisel+32(4).
            call transaction 'FB03' and skip first screen.
          when 'EKKO' or 'EKPA'.
            set parameter id 'BES' field sy-lisel+16(10).
            call transaction 'ME23N' and skip first screen.
          when others.
        endcase.
      endif.
    when others.
  endcase.

Customer Masters are really easy and require the simple basics, but there appears to be no way to select which screen is presented. The parameters are just the first thee characters of KUNNR, BUKRS, VKORG, VTWEG and SPART.

AT LINE-SELECTION.
  CASE sy-ucomm.
    WHEN 'PICK'.
      case sy-lisel+0(4).
        when 'KNVV'.
          "Line looks like KNVV 1009023958 4421 99 99...
          sKNA1-KUNNR = sy-lisel+5(10).
          if sKNA1-KUNNR co '1234567890 '.
            shift sKNA1-KUNNR right deleting trailing space.
            overlay sKNA1-KUNNR with '0000000000'.
          endif.
          select * from KNVV into lKNVV
           where KUNNR eq lKNVV-KUNNR
             and VKORG eq sy-lisel+16(4)
             and VTWEG eq sy-lisel+21(2)
             and SPART eq sy-lisel+24(2).
            set parameter id 'KUN' field lKNVV-KUNNR.
            "set parameter id 'BUK' field lKNB1-BUKRS.
            set parameter id 'VKO' field lKNVV-VKORG.
            set parameter id 'VTW' field lKNVV-VTWEG.
            set parameter id 'SPA' field lKNVV-SPART.
            call transaction 'XD03' and skip first screen.
          endselect.
        when others.
      endcase.
    when others.
  endcase.

Most other transactions are easy enough to call with the first screen skipped once the parameters are found and finding them is incredibly easy. For example, in transaction IW33, the parameter for the Order Number on the first screen can be found by clicking F1 and then clicking the "Technical Information" button just like in the image below.

https://i.pinimg.com/originals/bb/b3/5d/bbb35db94923a4f10feb320e5584b7e2.gif|https://www.cs.vu.nl/~frankh/dilbert/illusion_of_understanding.gif|https://blog.capterra.com/wp-content/uploads/2015/12/dt051228-720x228.gif|https://ahmeds.files.wordpress.com/2007/06/status-report.gif?w=670|https://www.cs.vu.nl/~frankh/dilbert/summaries.gif

Programming Language: 
ABAP