REPORT YUPLOAD LINE-SIZE 255 NO STANDARD PAGE HEADING.

* Performance test program
* This program uses the binary file recorded by the
*    sapgui appserv syst.number -rfile
* command during the creation of a raw material:
* login, /nmmr1, entering material name, industry sector, choosing
* basic data, entering unit of measure and material description, saving
* and logging out by /nex.
* The program multiplies the middle - business transaction - part of the
* binary file and multiplies it with different material names and
* descriptions. Also displays the input and output files in the
* following format: record number, offset, length, continuous binary
* or ascii string. This data will help to find out the different record
* numbers and offsets to split and change the binary file. ( 77, 100,
* 162, 6 ... in this case).
* The binary result can be replayed by
*      sapgui appserv syst.number -pfile -an

DATA: BEGIN OF ITAB OCCURS 20,
    LINE(1) TYPE X,
END OF ITAB,
BEGIN OF BTAB OCCURS 20,
    LENGTH TYPE I,
    LINE(400) TYPE X,
END OF BTAB,
BEGIN OF CTAB OCCURS 20,
    LENGTH TYPE I,
    LINE(400) TYPE X,
END OF CTAB,
BEGIN OF IREC OCCURS 10,
    LINE(400) TYPE X,
END OF IREC,
LAST, DSPSTR(400), MODE, A TYPE I, POINTER TYPE I, SUM TYPE I,
INDEX LIKE SY-INDEX, MATERIAL(18).

* upload the data file
CALL FUNCTION 'WS_UPLOAD'
     EXPORTING
          FILENAME = 'c:\sapgui\sapgui\recmat'
          FILETYPE = 'BIN'
     TABLES
          DATA_TAB = ITAB.

* split the source file to contignuous binary and text strings
LAST = 'B'.POINTER = 0.
LOOP AT ITAB.
  A = ITAB-LINE.
  IF A >= 32 AND A <= 124.
    IF LAST = 'B'.
      BTAB-LENGTH = POINTER.
      APPEND BTAB.CLEAR BTAB.
      BTAB-LINE = ITAB-LINE.
      LAST = 'A'.POINTER = 1.
    ELSE.
      BTAB-LINE+POINTER(1) = ITAB-LINE.
      POINTER = POINTER + 1.
    ENDIF.
  ELSE.
    IF LAST = 'B'.
      BTAB-LINE+POINTER(1) = ITAB-LINE.POINTER = POINTER + 1.
    ELSE.
      BTAB-LENGTH = POINTER.
      APPEND BTAB.CLEAR BTAB.
      BTAB-LINE = ITAB-LINE.
      LAST = 'B'.POINTER = 1.
    ENDIF.
  ENDIF.
ENDLOOP.
BTAB-LENGTH = POINTER.
APPEND BTAB.CLEAR BTAB.

* display the source file
LOOP AT BTAB.
  POINTER = BTAB-LENGTH.
  DSPSTR = BTAB+4(POINTER).
  WRITE: / SY-TABIX, SUM, POINTER, DSPSTR.
  SUM = SUM + POINTER.
ENDLOOP.

* change user name and password
*read table btab index 30.
*btab+4(12) = 'testuser    '.
*write btab to btab index 30.

*read table btab index 34.
*btab+4(8) = 'qwertyui'.
*write btab to btab index 34.

* login section
DO 77 TIMES.
  READ TABLE BTAB INDEX SY-INDEX.
  CTAB = BTAB.
  APPEND CTAB.
ENDDO.

* enter materials
DO 9 TIMES.                              " Create 9 new materials
  MATERIAL = 'testmat'.
  MATERIAL+7(2) = SY-INDEX.
  DO 98 TIMES.
    INDEX = SY-INDEX + 77.
    READ TABLE BTAB INDEX INDEX.
    CTAB = BTAB.
    IF INDEX = 100.
      CTAB+4(18) = MATERIAL.
    ENDIF.
    IF INDEX = 162.
      CTAB+6(12) = MATERIAL.
    ENDIF.
    APPEND CTAB.
  ENDDO.
ENDDO.

* log out
DO 6 TIMES.
  INDEX = SY-INDEX + 175.
  READ TABLE BTAB INDEX INDEX.
  CTAB = BTAB.
  APPEND CTAB.
ENDDO.

* display the result
WRITE: / '***********************************************************'.
LOOP AT CTAB.
  POINTER = CTAB-LENGTH.
  DSPSTR = CTAB+4(POINTER).
  WRITE: / SY-TABIX, SUM, POINTER, DSPSTR.
  SUM = SUM + POINTER.
ENDLOOP.

* download the result
MODE = ''.
LOOP AT CTAB.
  CLEAR IREC. REFRESH IREC.
  IREC = CTAB+4(400).
  APPEND IREC.
  POINTER = CTAB-LENGTH.
  CALL FUNCTION 'WS_DOWNLOAD'
       EXPORTING
            BIN_FILESIZE = POINTER
            FILENAME     = 'c:\sapgui\sapgui\recmat2'
            FILETYPE     = 'BIN'
            MODE         = MODE
       TABLES
            DATA_TAB     = IREC.
  MODE = 'A'.
ENDLOOP.