ABAP program for SAPGUI automation

This is a part of Giovanni Davila's how-to guide: "Automating line-item data entry for purchase orders via SAPGUI scripting"

NOTE: This program is part of Giovanni Davila's how-to guide: " Automating line-item data entry for purchase orders via SAPGUI scripting".

* --------------------------------------------------- *
* Report: ZMM_PO_LINEITEM_SCRIPT
* Author: Giovanni Davila
* Copyright.
*
* Last modified: 08/02/2005
*
* http://www.SAPadministration.com
*
* It reads a flat file containing Purchase Order Line Items to generate
* a VBS script that automates the entry of line items.
* The output (VBS) script can be run with SAPGUI scripting, which needs
* to be activated on the SAP server.
* --------------------------------------------------- *

report  ZMM_PO_LINEITEM_SCRIPT.

* Internal table for line items that are read from input file.
data:
begin of ITAB occurs 0,
  S type STRING,
end of ITAB.

* Internal table for output script.
data:
begin of OTAB occurs 0,
  L1  type STRING,
  L2  type STRING,
  L3  type STRING,
  L4  type STRING,
  L5  type STRING,
  L6  type STRING,
  L7  type STRING,
  L8  type STRING,
  L9  type STRING,
  L10 type STRING,
  L11 type STRING,
  L12 type STRING,
  L13 type STRING,
  L14 type STRING,
  L15 type STRING,
  L16 type STRING,
  L17 type STRING,
  L18 type STRING,                                          "scroll 1
  L19 type STRING,                                          "scroll 2
  L20 type STRING,                                          "scroll 3
  L21 type STRING,                                          "scroll 4
  L22 type STRING,                                          "scroll 5
  L23 type STRING,                                          "scroll 6
  L24 type STRING,                                          "scroll 7
  L25 type STRING,                                          "scroll 8
  L26 type STRING,                                          "scroll 9
  L27 type STRING,                                          "scroll 10
  L28 type STRING,                                          "scroll 11
  L29 type STRING,                                          "scroll 12
end of OTAB.

* Internal table to hold each piece of data in each line item.
data:
begin of IPOITEM occurs 0,
  KNTTP type STRING,
  TXZ01 type STRING,
  MENGE type STRING,
  MEINS type STRING,
  EEIND type STRING,
  NETPR type STRING,
  WGBEZ type STRING,
  WERKS type STRING,
  LGOBE type STRING,
  SAKTO type STRING,
  KOSTL type STRING,
end of IPOITEM.

* Internal table to store header of VBS script.
data:
begin of VBSHEADER occurs 0,
  H1 type STRING value 'If Not IsObject(application) Then',
  H2 type STRING
     value '   Set SapGuiAuto  = GetObject("SAPGUI")',
  H3 type STRING
     value '   Set application = SapGuiAuto.GetScriptingEngine',
  H4 type STRING value 'End If',
  H5 type STRING value 'If Not IsObject(connection) Then',
  H6 type STRING
     value '   Set connection = application.Children(0)',
  H7 type STRING value 'End If',
  H8 type STRING value 'If Not IsObject(session) Then',
  H9 type STRING
     value '   Set session    = connection.Children(0)',
  H10 type STRING value 'End If',
  H11 type STRING value 'If IsObject(WScript) Then',
  H12 type STRING
      value '  WScript.ConnectObject session,     "on"',
  H13 type STRING
      value '  WScript.ConnectObject application, "on"',
  H14 type STRING value 'End If',
  H15 type STRING
      value 'session.findById("wnd[0]").maximize',
  H16 type STRING value 'session.findById("wnd[0]").sendVKey 0',
end of VBSHEADER.

* Internal table to create VBS script lines (commands).
* Need to concatenate row number (e.g. 0, 1, etc.).
* Need to concatenate line number (e.g. 13 or 19).
data:
begin of VBSSCRIPT occurs 0,
* account assignment
  L1   type STRING,
  L1_1 type STRING value 'session.findById("wnd[0]/usr/subSUB0:',
  L1_2 type STRING value 'SAPLMEGUI:00',
  L1_3 type STRING value '/subSUB2:SAPLMEVIEWS:1100/',
  L1_4 type STRING value 'subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:',
  L1_5 type STRING value '1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-KNTTP',
  L1_6 type STRING value '[2,',
  L1_7 type STRING value ']").text = "',

* short text
  L2   type STRING,
  L2_1 type STRING value 'session.findById("wnd[0]/usr/subSUB0:',
  L2_2 type STRING value 'SAPLMEGUI:00',
  L2_3 type STRING value '/subSUB2:SAPLMEVIEWS:1100/',
  L2_4 type STRING value 'subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:',
  L2_5 type STRING value '1211/tblSAPLMEGUITC_1211/txtMEPO1211-TXZ01',
  L2_6 type STRING value '[5,',
  L2_7 type STRING value ']").text = "',

* quantity
  L3   type STRING,
  L3_1 type STRING value 'session.findById("wnd[0]/usr/subSUB0:',
  L3_2 type STRING value 'SAPLMEGUI:00',
  L3_3 type STRING value '/subSUB2:SAPLMEVIEWS:1100/',
  L3_4 type STRING value 'subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:',
  L3_5 type STRING value '1211/tblSAPLMEGUITC_1211/txtMEPO1211-MENGE',
  L3_6 type STRING value '[6,',
  L3_7 type STRING value ']").text = "',

* order unit
  L4   type STRING,
  L4_1 type STRING value 'session.findById("wnd[0]/usr/subSUB0:',
  L4_2 type STRING value 'SAPLMEGUI:00',
  L4_3 type STRING value '/subSUB2:SAPLMEVIEWS:1100/',
  L4_4 type STRING value 'subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:',
  L4_5 type STRING value '1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-MEINS',
  L4_6 type STRING value '[7,',
  L4_7 type STRING value ']").text = "',

* delivery date
  L5   type STRING,
  L5_1 type STRING value 'session.findById("wnd[0]/usr/subSUB0:',
  L5_2 type STRING value 'SAPLMEGUI:00',
  L5_3 type STRING value '/subSUB2:SAPLMEVIEWS:1100/',
  L5_4 type STRING value 'subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:',
  L5_5 type STRING value '1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-EEIND',
  L5_6 type STRING value '[9,',
  L5_7 type STRING value ']").text = "',

* net price
  L6   type STRING,
  L6_1 type STRING value 'session.findById("wnd[0]/usr/subSUB0:',
  L6_2 type STRING value 'SAPLMEGUI:00',
  L6_3 type STRING value '/subSUB2:SAPLMEVIEWS:1100/',
  L6_4 type STRING value 'subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:',
  L6_5 type STRING value '1211/tblSAPLMEGUITC_1211/txtMEPO1211-NETPR',
  L6_6 type STRING value '[10,',
  L6_7 type STRING value ']").text = "',

* material group
  L7   type STRING,
  L7_1 type STRING value 'session.findById("wnd[0]/usr/subSUB0:',
  L7_2 type STRING value 'SAPLMEGUI:00',
  L7_3 type STRING value '/subSUB2:SAPLMEVIEWS:1100/',
  L7_4 type STRING value 'subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:',
  L7_5 type STRING value '1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-WGBEZ',
  L7_6 type STRING value '[14,',
  L7_7 type STRING value ']").text = "',

* plant
  L8   type STRING,
  L8_1 type STRING value 'session.findById("wnd[0]/usr/subSUB0:',
  L8_2 type STRING value 'SAPLMEGUI:00',
  L8_3 type STRING value '/subSUB2:SAPLMEVIEWS:1100/',
  L8_4 type STRING value 'subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:',
  L8_5 type STRING value '1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-NAME1',
  L8_6 type STRING value '[15,',
  L8_7 type STRING value ']").text = "',

* storage location
  L9   type STRING,
  L9_1 type STRING value 'session.findById("wnd[0]/usr/subSUB0:',
  L9_2 type STRING value 'SAPLMEGUI:00',
  L9_3 type STRING value '/subSUB2:SAPLMEVIEWS:1100/',
  L9_4 type STRING value 'subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:',
  L9_5 type STRING value '1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-LGOBE',
  L9_6 type STRING value '[16,',
  L9_7 type STRING value ']").text = "',

* next lines
  L10   type STRING,
  L10_1 type STRING value 'session.findById("wnd[0]/usr/subSUB0:',
  L10_2 type STRING value 'SAPLMEGUI:00',
  L10_3 type STRING value '/subSUB2:SAPLMEVIEWS:1100/',
  L10_4 type STRING value 'subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:',
  L10_5 type STRING value '1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-LGOBE',
  L10_6 type STRING value '[16,',
  L10_7 type STRING value ']").setFocus',

* position line
  L11   type STRING,
  L11_1 type STRING value 'session.findById("wnd[0]/usr/subSUB0:',
  L11_2 type STRING value 'SAPLMEGUI:00',
  L11_3 type STRING value '/subSUB2:SAPLMEVIEWS:1100/',
  L11_4 type STRING value 'subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:',
  L11_5 type STRING value '1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-LGOBE',
  L11_6 type STRING value '[16,',
  L11_7 type STRING value ']").caretPosition = 3',

* new line
  L12 type STRING,

* G/L account
  L13   type STRING,
  L13_1 type STRING value 'session.findById("wnd[0]/usr/subSUB0:',
  L13_2 type STRING value 'SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/',
  L13_3 type STRING value 'subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:',
  L13_4 type STRING value '1301/subSUB2:SAPLMEGUI:1303/',
  L13_5 type STRING value 'tabsITEM_DETAIL/tabpTABIDT10/',
  L13_6 type STRING value 'ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/',
  L13_7 type STRING value 'subSUB2:SAPLMEACCTVI:0100/subSUB1:',
  L13_8 type STRING value 'SAPLMEACCTVI:1100/ctxtMEACCT1100-SAKTO"',
  L13_9 type STRING value ').text = "',

* cost center
  L14   type STRING,
  L14_1 type STRING value 'session.findById("wnd[0]/usr/subSUB0:',
  L14_2 type STRING value 'SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/',
  L14_3 type STRING value 'subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:',
  L14_4 type STRING value '1301/subSUB2:SAPLMEGUI:1303/',
  L14_5 type STRING value 'tabsITEM_DETAIL/tabpTABIDT10/',
  L14_6 type STRING value 'ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/',
  L14_7 type STRING value 'subSUB2:SAPLMEACCTVI:0100/subSUB1:',
  L14_8 type STRING value 'SAPLMEACCTVI:1100/subKONTBLOCK:SAPLKACB:',
  L14_9 type STRING value '1101/ctxtCOBL-KOSTL").text = "',

* next lines: focus and position
  L15   type STRING,
  L15_1 type STRING value 'session.findById("wnd[0]/usr/subSUB0:',
  L15_2 type STRING value 'SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:',
  L15_3 type STRING value '1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:',
  L15_4 type STRING value 'SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/',
  L15_5 type STRING value 'tabsITEM_DETAIL/tabpTABIDT10/',
  L15_6 type STRING value 'ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/',
  L15_7 type STRING value 'subSUB2:SAPLMEACCTVI:0100/subSUB1:',
  L15_8 type STRING value 'SAPLMEACCTVI:1100/subKONTBLOCK:SAPLKACB:',
  L15_9 type STRING value '1101/ctxtCOBL-KOSTL").setFocus',

  L16   type STRING,
  L16_1 type STRING value 'session.findById("wnd[0]/usr/subSUB0:',
  L16_2 type STRING value 'SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:',
  L16_3 type STRING value '1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:',
  L16_4 type STRING value 'SAPLMEGUI:1301/subSUB2:SAPLMEGUI:',
  L16_5 type STRING value '1303/tabsITEM_DETAIL/tabpTABIDT10/',
  L16_6 type STRING value 'ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/',
  L16_7 type STRING value 'subSUB2:SAPLMEACCTVI:0100/subSUB1:',
  L16_8 type STRING value 'SAPLMEACCTVI:1100/subKONTBLOCK:SAPLKACB:',
  L16_9 type STRING value '1101/ctxtCOBL-KOSTL").caretPosition = 6',

* new line
  L17 type STRING,
end of VBSSCRIPT.

* Internal table to create scroll lines (commands).
* Concatenate the value at the end of string.
data:
begin of VBSSCROLL occurs 0,
  S1   type STRING,
  S1_1 type STRING value 'session.findById("wnd[0]/usr/subSUB0:',
  S1_2 type STRING value 'SAPLMEGUI:0019/subSUB2:SAPLMEVIEWS:',
  S1_3 type STRING value '1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:',
  S1_4 type STRING value 'SAPLMEGUI:1211/tblSAPLMEGUITC_1211").',
  S1_5 type STRING value 'verticalScrollbar.position =',
end of VBSSCROLL.

data:
  GUILINE(2) type C value 'xx',    "SAPLMEGUI:00xx
  NEWLINE type STRING
          value 'session.findById("wnd[0]").sendVKey 0',
  CRLF(2) type C,                  "new line (carriage return)
  INFILEPATH type STRING,          "input file path
  OUTFILEPATH type STRING,         "output file path
  C type I,                        "total record counter
  C2(3) type C,                    "copy of total record counter
  EC type I,                       "entry record counter
  CC(3) type C,                    "copy of entry record counter
  SC type I,                       "scroll counter
  VLIM type I,                     "visible line items minus one
  VLI2 type I.                     "visible line items x 2

parameters:
  INFILE like RLGRAP-FILENAME    "user line-item input file
  default 'C:SAPlineitem.csv',

  OUTFILE like RLGRAP-FILENAME   "user VBS script file
  default 'C:SAPPO-script.vbs',

  FD(1) type C default ',',       "field separator (default comma)
  VLI type I default 5.           "visible line items in P.O. screen


* ----------------------------------------------
* Main Program
* ----------------------------------------------
start-of-selection.

  CRLF = CL_ABAP_CHAR_UTILITIES=>CR_LF.
  move -1 to C.
  move 0 to EC.
  move 0 to SC.
  move ' ' to CC.
  move ' ' to C2.
  move INFILE to INFILEPATH.
  move OUTFILE to OUTFILEPATH.
  VLIM = VLI - 1.        "visible line items - 1
  VLI2 = VLI * 2.        "visible line items x 2

* If number of visible line items entered is < 2 or > 5 exit.
  if VLI < 2 or VLI > 5.
    write:/ 'Wrong input!'.
    write:/ 'Visible line items must be between 2 and 5.'.
    exit.
  endif.

* Upload data file from user's desktop.
  call function 'GUI_UPLOAD'
    exporting
      FILENAME            = INFILEPATH
      FILETYPE            = 'ASC'
      HAS_FIELD_SEPARATOR = 'X'
    tables
      DATA_TAB            = ITAB
    exceptions
      FILE_OPEN_ERROR     = 1
      FILE_READ_ERROR     = 2.
  case SY-SUBRC.
    when 1.
      write '***ERROR opening input file!.'.
      exit.
    when 2.
      write '***ERROR reading input file!.'.
      exit.
  endcase.

* Process records found in input file.
  loop at ITAB where S is not initial.
    C = C + 1.
    C2 = C.

* Skip the first item because those are headers.
    if C > 0.
      EC = EC + 1.
* First line item entries have a special GUI position.
      if C <= VLI.
        CC = EC - 1.
      else.
        CC = EC.
      endif.
* Remove white spaces from CC.
      condense CC no-gaps.

* Write header for VBS script before any line items.
* Do this only once before the first line item.
* Also, assign SAPLMEGUI:0013 to first line item.
      if C = 1.
        move '13' to GUILINE.

        concatenate VBSHEADER-H1  CRLF into VBSHEADER-H1.
        concatenate VBSHEADER-H2  CRLF into VBSHEADER-H2.
        concatenate VBSHEADER-H3  CRLF into VBSHEADER-H3.
        concatenate VBSHEADER-H4  CRLF into VBSHEADER-H4.
        concatenate VBSHEADER-H5  CRLF into VBSHEADER-H5.
        concatenate VBSHEADER-H6  CRLF into VBSHEADER-H6.
        concatenate VBSHEADER-H7  CRLF into VBSHEADER-H7.
        concatenate VBSHEADER-H8  CRLF into VBSHEADER-H8.
        concatenate VBSHEADER-H9  CRLF into VBSHEADER-H9.
        concatenate VBSHEADER-H10 CRLF into VBSHEADER-H10.
        concatenate VBSHEADER-H11 CRLF into VBSHEADER-H11.
        concatenate VBSHEADER-H12 CRLF into VBSHEADER-H12.
        concatenate VBSHEADER-H13 CRLF into VBSHEADER-H13.
        concatenate VBSHEADER-H14 CRLF into VBSHEADER-H14.
        concatenate VBSHEADER-H15 CRLF into VBSHEADER-H15.

        append VBSHEADER.

* Write header to output file.
        call function 'GUI_DOWNLOAD'
          exporting
            FILENAME         = OUTFILEPATH
            FILETYPE         = 'ASC'
          tables
            DATA_TAB         = VBSHEADER
          exceptions
            FILE_WRITE_ERROR = 1.

* If line item >= 2 assign SAPLMEGUI:0013.
      else.
        move '19' to GUILINE.
      endif.

* Extract each piece of data in line item.
* Use field delimeter (separator) entered by user.
      clear IPOITEM.
      split ITAB-S at FD into  IPOITEM-KNTTP
                               IPOITEM-TXZ01
                               IPOITEM-MENGE
                               IPOITEM-MEINS
                               IPOITEM-EEIND
                               IPOITEM-NETPR
                               IPOITEM-WGBEZ
                               IPOITEM-WERKS
                               IPOITEM-LGOBE
                               IPOITEM-SAKTO
                               IPOITEM-KOSTL.

* Put together entire script lines (commands).
* GUILINE contains the special GUI position.
      concatenate VBSSCRIPT-L1_1 VBSSCRIPT-L1_2 GUILINE
                  VBSSCRIPT-L1_3 VBSSCRIPT-L1_4 VBSSCRIPT-L1_5
                  VBSSCRIPT-L1_6 CC
                  VBSSCRIPT-L1_7 IPOITEM-KNTTP '"' CRLF
                  into VBSSCRIPT-L1.

      concatenate VBSSCRIPT-L2_1 VBSSCRIPT-L2_2 GUILINE
                  VBSSCRIPT-L2_3 VBSSCRIPT-L2_4 VBSSCRIPT-L2_5
                  VBSSCRIPT-L2_6 CC
                  VBSSCRIPT-L2_7 IPOITEM-TXZ01 '"' CRLF
                  into VBSSCRIPT-L2.

      concatenate VBSSCRIPT-L3_1 VBSSCRIPT-L3_2 GUILINE
                  VBSSCRIPT-L3_3 VBSSCRIPT-L3_4 VBSSCRIPT-L3_5
                  VBSSCRIPT-L3_6 CC
                  VBSSCRIPT-L3_7 IPOITEM-MENGE '"' CRLF
                  into VBSSCRIPT-L3.

      concatenate VBSSCRIPT-L4_1 VBSSCRIPT-L4_2 GUILINE
                  VBSSCRIPT-L4_3 VBSSCRIPT-L4_4 VBSSCRIPT-L4_5
                  VBSSCRIPT-L4_6 CC
                  VBSSCRIPT-L4_7 IPOITEM-MEINS '"' CRLF
                  into VBSSCRIPT-L4.

      concatenate VBSSCRIPT-L5_1 VBSSCRIPT-L5_2 GUILINE
                  VBSSCRIPT-L5_3 VBSSCRIPT-L5_4 VBSSCRIPT-L5_5
                  VBSSCRIPT-L5_6 CC
                  VBSSCRIPT-L5_7 IPOITEM-EEIND '"' CRLF
                  into VBSSCRIPT-L5.

      concatenate VBSSCRIPT-L6_1 VBSSCRIPT-L6_2 GUILINE
                  VBSSCRIPT-L6_3 VBSSCRIPT-L6_4 VBSSCRIPT-L6_5
                  VBSSCRIPT-L6_6 CC
                  VBSSCRIPT-L6_7 IPOITEM-NETPR '"' CRLF
                  into VBSSCRIPT-L6.

      concatenate VBSSCRIPT-L7_1 VBSSCRIPT-L7_2 GUILINE
                  VBSSCRIPT-L7_3 VBSSCRIPT-L7_4 VBSSCRIPT-L7_5
                  VBSSCRIPT-L7_6 CC
                  VBSSCRIPT-L7_7 IPOITEM-WGBEZ '"' CRLF
                  into VBSSCRIPT-L7.

      concatenate VBSSCRIPT-L8_1 VBSSCRIPT-L8_2 GUILINE
                  VBSSCRIPT-L8_3 VBSSCRIPT-L8_4 VBSSCRIPT-L8_5
                  VBSSCRIPT-L8_6 CC
                  VBSSCRIPT-L8_7 IPOITEM-WERKS '"' CRLF
                  into VBSSCRIPT-L8.

      concatenate VBSSCRIPT-L9_1 VBSSCRIPT-L9_2 GUILINE
                  VBSSCRIPT-L9_3 VBSSCRIPT-L9_4 VBSSCRIPT-L9_5
                  VBSSCRIPT-L9_6 CC
                  VBSSCRIPT-L9_7 IPOITEM-LGOBE '"' CRLF
                  into VBSSCRIPT-L9.

      concatenate VBSSCRIPT-L10_1 VBSSCRIPT-L10_2 GUILINE
                  VBSSCRIPT-L10_3 VBSSCRIPT-L10_4 VBSSCRIPT-L10_5
                  VBSSCRIPT-L10_6 CC
                  VBSSCRIPT-L10_7 CRLF
                  into VBSSCRIPT-L10.

      concatenate VBSSCRIPT-L11_1 VBSSCRIPT-L11_2 GUILINE
                  VBSSCRIPT-L11_3 VBSSCRIPT-L11_4 VBSSCRIPT-L11_5
                  VBSSCRIPT-L11_6 CC VBSSCRIPT-L11_7 CRLF
                  into VBSSCRIPT-L11.

      concatenate NEWLINE CRLF into VBSSCRIPT-L12.

      concatenate VBSSCRIPT-L13_1 VBSSCRIPT-L13_2 VBSSCRIPT-L13_3
                  VBSSCRIPT-L13_4 VBSSCRIPT-L13_5 VBSSCRIPT-L13_6
                  VBSSCRIPT-L13_7 VBSSCRIPT-L13_8 VBSSCRIPT-L13_9
                  IPOITEM-SAKTO '"' CRLF
                  into VBSSCRIPT-L13.

      concatenate VBSSCRIPT-L14_1 VBSSCRIPT-L14_2 VBSSCRIPT-L14_3
                  VBSSCRIPT-L14_4 VBSSCRIPT-L14_5 VBSSCRIPT-L14_6
                  VBSSCRIPT-L14_7 VBSSCRIPT-L14_8 VBSSCRIPT-L14_9
                  IPOITEM-KOSTL '"' CRLF
                  into VBSSCRIPT-L14.

      concatenate VBSSCRIPT-L15_1 VBSSCRIPT-L15_2 VBSSCRIPT-L15_3
                  VBSSCRIPT-L15_4 VBSSCRIPT-L15_5 VBSSCRIPT-L15_6
                  VBSSCRIPT-L15_7 VBSSCRIPT-L15_8 VBSSCRIPT-L15_9
                  CRLF into VBSSCRIPT-L15.

      concatenate VBSSCRIPT-L16_1 VBSSCRIPT-L16_2 VBSSCRIPT-L16_3
                  VBSSCRIPT-L16_4 VBSSCRIPT-L16_5 VBSSCRIPT-L16_6
                  VBSSCRIPT-L16_7 VBSSCRIPT-L16_8 VBSSCRIPT-L16_9
                  CRLF into VBSSCRIPT-L16.

      move NEWLINE to VBSSCRIPT-L17.

* Copy lines into output internal table.
      move VBSSCRIPT-L1 to OTAB-L1.
      move VBSSCRIPT-L2 to OTAB-L2.
      move VBSSCRIPT-L3 to OTAB-L3.
      move VBSSCRIPT-L4 to OTAB-L4.
      move VBSSCRIPT-L5 to OTAB-L5.
      move VBSSCRIPT-L6 to OTAB-L6.
      move VBSSCRIPT-L7 to OTAB-L7.
      move VBSSCRIPT-L8 to OTAB-L8.
      move VBSSCRIPT-L9 to OTAB-L9.
      move VBSSCRIPT-L10 to OTAB-L10.
      move VBSSCRIPT-L11 to OTAB-L11.
      move VBSSCRIPT-L12 to OTAB-L12.
      move VBSSCRIPT-L13 to OTAB-L13.
      move VBSSCRIPT-L14 to OTAB-L14.
      move VBSSCRIPT-L15 to OTAB-L15.
      move VBSSCRIPT-L16 to OTAB-L16.
      move VBSSCRIPT-L17 to OTAB-L17.

* Clear scroll lines.
      clear OTAB-L18.
      clear OTAB-L19.
      clear OTAB-L20.
      clear OTAB-L21.
      clear OTAB-L22.
      clear OTAB-L23.
      clear OTAB-L24.
      clear OTAB-L25.
      clear OTAB-L26.
      clear OTAB-L27.
      clear OTAB-L28.
      clear OTAB-L29.

* EC -begin-
* if maximum line item entries reset counter and scroll.
      if EC = VLI.
        EC = 0.

* If line items >= visible line items and
* line items < visible line items x 2, scroll.
        if C >= VLI and C < VLI2.
          SC = 0.
          if SC <= VLIM.
            concatenate CRLF VBSSCROLL-S1_1 VBSSCROLL-S1_2
                        VBSSCROLL-S1_3 VBSSCROLL-S1_4
                        VBSSCROLL-S1_5 ' 1' into VBSSCROLL-S1.
            move VBSSCROLL-S1 to OTAB-L18.
            SC = SC + 1.
          endif.

          if SC < VLIM.
            concatenate CRLF VBSSCROLL-S1_1 VBSSCROLL-S1_2
                      VBSSCROLL-S1_3 VBSSCROLL-S1_4
                      VBSSCROLL-S1_5 ' 2' into VBSSCROLL-S1.
            move VBSSCROLL-S1 to OTAB-L19.
            SC = SC + 1.
          endif.

          if SC < VLIM.
            concatenate CRLF VBSSCROLL-S1_1 VBSSCROLL-S1_2
                        VBSSCROLL-S1_3 VBSSCROLL-S1_4
                        VBSSCROLL-S1_5 ' 3' into VBSSCROLL-S1.
            move VBSSCROLL-S1 to OTAB-L20.
            SC = SC + 1.
          endif.

          if SC < VLIM.
            concatenate CRLF VBSSCROLL-S1_1 VBSSCROLL-S1_2
                      VBSSCROLL-S1_3 VBSSCROLL-S1_4
                      VBSSCROLL-S1_5 ' 4' into VBSSCROLL-S1.
            move VBSSCROLL-S1 to OTAB-L21.
            SC = SC + 1.
          endif.
        endif.

* If line item >= visible line items x 2, scroll.
* First, scroll down VLI times.
* Second, scroll down VLI+2 times and VLI+1 times.
* Third, scroll down VLI items again.
        if C >= VLI2.
          SC = 0.

          if SC < VLI.
            C2 = C - VLI + SC.
            concatenate CRLF VBSSCROLL-S1_1 VBSSCROLL-S1_2
                        VBSSCROLL-S1_3 VBSSCROLL-S1_4
                        VBSSCROLL-S1_5 C2 into VBSSCROLL-S1.
            move VBSSCROLL-S1 to OTAB-L18.
            SC = SC + 1.
          endif.

          if SC < VLI.
            C2 = C - VLI + SC.
            concatenate CRLF VBSSCROLL-S1_1 VBSSCROLL-S1_2
                        VBSSCROLL-S1_3 VBSSCROLL-S1_4
                        VBSSCROLL-S1_5 C2 into VBSSCROLL-S1.
            move VBSSCROLL-S1 to OTAB-L19.
            SC = SC + 1.
          endif.

          if SC < VLI.
            C2 = C - VLI + SC.
            concatenate CRLF VBSSCROLL-S1_1 VBSSCROLL-S1_2
                        VBSSCROLL-S1_3 VBSSCROLL-S1_4
                        VBSSCROLL-S1_5 C2 into VBSSCROLL-S1.
            move VBSSCROLL-S1 to OTAB-L20.
            SC = SC + 1.
          endif.

          if SC < VLI.
            C2 = C - VLI + SC.
            concatenate CRLF VBSSCROLL-S1_1 VBSSCROLL-S1_2
                        VBSSCROLL-S1_3 VBSSCROLL-S1_4
                        VBSSCROLL-S1_5 C2 into VBSSCROLL-S1.
            move VBSSCROLL-S1 to OTAB-L21.
            SC = SC + 1.
          endif.

          if SC < VLI.
            C2 = C - VLI + SC.
            concatenate CRLF VBSSCROLL-S1_1 VBSSCROLL-S1_2
                        VBSSCROLL-S1_3 VBSSCROLL-S1_4
                        VBSSCROLL-S1_5 C2 into VBSSCROLL-S1.
            move VBSSCROLL-S1 to OTAB-L22.
            SC = SC + 1.
          endif.

          C2 = C - VLI - 2.
          concatenate CRLF VBSSCROLL-S1_1 VBSSCROLL-S1_2
                      VBSSCROLL-S1_3 VBSSCROLL-S1_4
                      VBSSCROLL-S1_5 C2 into VBSSCROLL-S1.
          move VBSSCROLL-S1 to OTAB-L23.

          C2 = C - VLI - 1.
          concatenate CRLF VBSSCROLL-S1_1 VBSSCROLL-S1_2
                      VBSSCROLL-S1_3 VBSSCROLL-S1_4
                      VBSSCROLL-S1_5 C2 into VBSSCROLL-S1.
          move VBSSCROLL-S1 to OTAB-L24.

          SC = 0.

          if SC < VLI.
            C2 = C - VLI + SC.
            concatenate CRLF VBSSCROLL-S1_1 VBSSCROLL-S1_2
                        VBSSCROLL-S1_3 VBSSCROLL-S1_4
                        VBSSCROLL-S1_5 C2 into VBSSCROLL-S1.
            move VBSSCROLL-S1 to OTAB-L25.
            SC = SC + 1.
          endif.

          if SC < VLI.
            C2 = C - VLI + SC.
            concatenate CRLF VBSSCROLL-S1_1 VBSSCROLL-S1_2
                        VBSSCROLL-S1_3 VBSSCROLL-S1_4
                        VBSSCROLL-S1_5 C2 into VBSSCROLL-S1.
            move VBSSCROLL-S1 to OTAB-L26.
            SC = SC + 1.
          endif.

          if SC < VLI.
            C2 = C - VLI + SC.
            concatenate CRLF VBSSCROLL-S1_1 VBSSCROLL-S1_2
                        VBSSCROLL-S1_3 VBSSCROLL-S1_4
                        VBSSCROLL-S1_5 C2 into VBSSCROLL-S1.
            move VBSSCROLL-S1 to OTAB-L27.
            SC = SC + 1.
          endif.

          if SC < VLI.
            C2 = C - VLI + SC.
            concatenate CRLF VBSSCROLL-S1_1 VBSSCROLL-S1_2
                        VBSSCROLL-S1_3 VBSSCROLL-S1_4
                        VBSSCROLL-S1_5 C2 into VBSSCROLL-S1.
            move VBSSCROLL-S1 to OTAB-L28.
            SC = SC + 1.
          endif.

          if SC < VLI.
            C2 = C - VLI + SC.
            concatenate CRLF VBSSCROLL-S1_1 VBSSCROLL-S1_2
                        VBSSCROLL-S1_3 VBSSCROLL-S1_4
                        VBSSCROLL-S1_5 C2 into VBSSCROLL-S1.
            move VBSSCROLL-S1 to OTAB-L29.
            SC = SC + 1.
          endif.

        endif.

* EC -end-
      endif.

      append OTAB.

    endif.
  endloop.

* write line items to VBS script.
  call function 'GUI_DOWNLOAD'
    exporting
      FILENAME         = OUTFILEPATH
      FILETYPE         = 'ASC'
      APPEND           = 'X'
    tables
      DATA_TAB         = OTAB
    exceptions
      FILE_WRITE_ERROR = 1.
  case SY-SUBRC.
    when 1.
      write: '***ERROR writing to output file!'.
      exit.
  endcase.

  write:/ 'Today is: ', SY-DATUM.
  write:/ SY-UNAME, SY-SYSID, SY-SAPRL, SY-DBSYS, SY-OPSYS, SY-TCODE.
  uline.
  write:/ 'Your input file was processed.'.
  write:/ 'Total # of records (line items): ', C.
  write:/ 'VBS script: ', OUTFILEPATH.
  uline.
  skip.
  write:/ 'Instructions:'.
  write:/ '  1. Run transaction ME21N (Purchase Order Creation).'.
  write:/ '  2. Enter Vendor #.'.
  write:/ '  3. Enter Purchasing Group.'.
  write:/ '  4. Run (play) script.'.
  write:/ '  5. Enjoy!!!'.

end-of-selection.
This was first published in August 2005

Dig deeper on SAP ABAP

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchManufacturingERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchCRM

SearchContentManagement

SearchFinancialApplications

Close