Convert spool list to internal table

function y_spool2_itable.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"  IMPORTING
*"     VALUE(RQIDENT) LIKE  TSP01-RQIDENT
*"     VALUE(FIRST_LINE) TYPE  I DEFAULT 1
*"     VALUE(LAST_LINE) TYPE  I OPTIONAL
*"     VALUE(PAGES) TYPE  C OPTIONAL
*"     VALUE(ZIEL) TYPE  C
*"  EXCEPTIONS
*"      NO_SUCH_JOB
*"      JOB_CONTAINS_NO_DATA
*"      SELECTION_EMPTY
*"      NO_PERMISSION
*"      CAN_NOT_ACCESS
*"      READ_ERROR
*"      NOT_ABAP_LIST
*"----------------------------------------------------------------------
* Ruslan@sap.sd
  types : begin of ty_me2m,
    matnr(18),
    matx(40),
    ekko(10),
    lief(43),
    menge(8),
    bme(3),
    lort(4),
  end of ty_me2m.
  data: mem_tab like abaplist occurs 10,
        buffer type list_string_table,
        data_is_otf type c,
        subrc type sy-subrc,
        wa_buffer like line of buffer,
        it_me2m type table of ty_me2m,
        wa_me2m like line of it_me2m,
        it_html type table of string,
        c_subrc(10),
        rqid type rqident,
        doctype type rspodoctyp,
        lv_fname type string,
        i_html type string,
        lv_errmsg type string,
        it_2save type rsanm_file_table,
        lr_exc type ref to cx_root.
 
  clear: subrc, c_subrc.
  rqid = rqident.
 
  call function 'RSPO_CHECK_JOB_ID_PERMISSION'
    exporting
      rqident       = rqident
      access        = 'DISP'
    exceptions
      no_such_job   = 1
      no_permission = 2.
  if sy-subrc <> 0.
    subrc = sy-subrc.
    c_subrc = subrc.
    condense c_subrc.
    case subrc.
      when 1. raise no_such_job.
      when 2. raise no_permission.
    endcase.
  endif.
 
  call function 'RSPO_GET_TYPE_SPOOLJOB'
    exporting
      rqident        = rqident
    importing
      is_otf         = data_is_otf
      doctype        = doctype
    exceptions
      can_not_access = 1.
  if sy-subrc <> 0.
    subrc = sy-subrc.
    c_subrc = subrc.
    condense c_subrc.
    case subrc.
      when 1. raise can_not_access.
    endcase.
  endif.
 
  if last_line ne 0 and last_line < first_line.
    raise selection_empty.
  endif.
 
  if data_is_otf = 'X' or doctype <> 'LIST'.
    raise not_abap_list.
  else.
    submit rspolist exporting list to memory and return
                    with rqident = rqident
                    with first = first_line
                    with last = last_line
                    with pages = pages.
 
    call function 'LIST_FROM_MEMORY'
      tables
        listobject = mem_tab
      exceptions
        not_found  = 1
        others     = 2.
    if sy-subrc <> 0.
      c_subrc = sy-subrc.
      condense c_subrc.
      raise read_error.
    endif.
 
    call function 'WRITE_LIST'
      tables
        listobject = mem_tab
      exceptions
        empty_list = 1
        others     = 2.
 
    call function 'LIST_TO_DAT'
      changing
        listdat            = buffer
        listobject         = mem_tab
      exceptions
        empty_list         = 1
        list_index_invalid = 2
        others             = 3.
    if sy-subrc <> 0.
      subrc = sy-subrc.
      if subrc = 1.
        if first_line <> 1 or not last_line is initial.
          raise selection_empty.
        else.
          raise job_contains_no_data.
        endif.
      else.
        raise read_error.
      endif.
    endif.
 
    loop at buffer into wa_buffer.
      split wa_buffer at cl_abap_char_utilities=>horizontal_tab into table it_html.
      read table it_html index 10 into wa_me2m-matnr.
      read table it_html index 11 into wa_me2m-matx.
      read table it_html index 2 into wa_me2m-ekko.  " Einkaufsbeleg
      read table it_html index 6 into wa_me2m-lief.
      read table it_html index 22 into wa_me2m-menge.
      read table it_html index 23 into wa_me2m-bme.
      read table it_html index 21 into wa_me2m-lort.
      append wa_me2m to it_me2m.
    endloop.
    delete it_me2m from 1 to 3. " Kopf Reinigung
 
    call function 'LIST_FREE_MEMORY'
      tables
        listobject = mem_tab
      exceptions
        others     = 1.
    if sy-subrc <> 0.
      raise read_error.
    endif.
  endif.
 
  perform itab_to_html in program y_routine using it_me2m changing i_html.
 
  lv_fname = ziel.
  perform sdatei_erstellen in program y_routine using lv_fname 1.
  append i_html to it_2save.
 
  try.
      cl_rsan_ut_appserv_file_writer=>appserver_file_write( exporting
                                                              i_filename  = lv_fname
                                                              i_data_tab  = it_2save ).
    catch cx_root into lr_exc.
      lv_errmsg = lr_exc->get_text( ).
      message lv_errmsg type 'E'.
  endtry.
endfunction.
 
 
form sdatei_erstellen using fv_fname type string is_html type i.
  open dataset fv_fname for output in legacy text mode code page '1160' with windows linefeed. " 1160 = CP1252   " encoding default.
  if sy-subrc ne 0.
    message e907(38). " Fehler bei der Datenübertragung
    exit.
  else.
    if is_html eq 1.
      transfer '<html dir="ltr"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>Reportausgabe</title></head>' to fv_fname.
      transfer '<body bgcolor="#E8EAD8"><span style="white-space:nowrap">LiefDat<br><table class="list" border=1 cellspacing=0 cellpadding=1 rules=groups><blockquote>' to fv_fname.
      transfer '<colgroup><colgroup><colgroup><colgroup><colgroup><colgroup><colgroup><colgroup>' to fv_fname.
      transfer '<tbody><tr style=background:#5dcbfd><td>Material</td><td>Kurztext</td><td>EinkBeleg</td><td>Lieferant/Lieferwerk</td><td>Menge</td><td>BME</font></td><td>LOrt</td></tr>' to fv_fname.
      transfer '<style>table.list { border-collapse: collapse; } table.list tr:nth-child(even) {background:#eef9ff} tr:nth-child(odd) {background:#d7ecf4}' to fv_fname.
      transfer 'html * { font-size: 13 !important; font-family: courier new !important; } </style>' to fv_fname.
    else.
      transfer '' to fv_fname length 0.
    endif.
    close dataset fv_fname.
  endif.
endform.
 
form itab_to_html using it_tab type any table
                  changing html type string.
  data: lt_field type table of string,
        lv_field type string,
        lv_extra type string,
        lv_num   type i.
  field-symbols: <lv_field> type any,
                 <lv_line> type any.
  loop at it_tab assigning <lv_line>.
    lv_num = 0.
    clear lt_field.
 
    do.
      add 1 to lv_num.
      assign component lv_num of structure <lv_line> to <lv_field>.
      if sy-subrc ne 0.
        exit.
      endif.
      lv_field = <lv_field>.
      append lv_field to lt_field.
    enddo.
    read table lt_field index 4 into lv_extra.
    if lv_extra ne 'Lieferant/Lieferwerk'.
      html = html && '<tr><td>' && concat_lines_of( table = lt_field sep = '</td><td>' ) && '</td></tr>'.
    endif.
  endloop.
 
  html = html && '</table>'.
endform.

Schreibe einen Kommentar



All fields are required. Your email address will not be published.