Geschützt: Adding new line items to an Inbound delivery (with PO reference)

Dieser Inhalt ist passwortgeschützt. Um ihn anschauen zu können, bitte das Passwort eingeben:

Iterate field values and field names of unknown table

form fill_fcontent using it_tab type any table " iterate field values
                   changing it_fcont type rsanm_file_table. " für Z_LIEFZ
  data: lro_structdescr type ref to cl_abap_structdescr,
        lt_components   type cl_abap_structdescr=>component_table,
        lv_row type string.
  constants con_tab type c value cl_abap_char_utilities=>horizontal_tab.
  field-symbols: <ls_comp> like line of lt_components, <fs_field>, <wa> type any.
  loop at it_tab assigning <wa>.
    if lt_components is initial.
      lro_structdescr ?= cl_abap_typedescr=>describe_by_data( <wa> ).
      lt_components = lro_structdescr->get_components( ).
    endif.
    do. "iterate all columns in the row
      assign component sy-index of structure <wa> to <fs_field>.
      if sy-subrc <> 0.
        exit.
      endif.
      read table lt_components assigning <ls_comp> index sy-index.
      lv_row = lv_row && <fs_field> && con_tab.
    enddo.
    append lv_row to it_fcont. clear lv_row.
  endloop.
endform.
 
form fill_fheader using gs_line type any " iterate field names
                 changing it_filcont type rsanm_file_table. " für Z_LIEFZ
  data: lro_structdescr type ref to cl_abap_structdescr,
        lt_components   type cl_abap_structdescr=>component_table,
        lv_row type string.
  constants con_tab type c value cl_abap_char_utilities=>horizontal_tab.
  field-symbols: <ls_comp> like line of lt_components, <fs_field>, <wa> type any.
  clear it_filcont.
  assign gs_line to <wa>.
  if lt_components is initial.
    lro_structdescr ?= cl_abap_typedescr=>describe_by_data( <wa> ).
    lt_components = lro_structdescr->get_components( ).
  endif.
  do.
    assign component sy-index of structure <wa> to <fs_field>.
    if sy-subrc <> 0.
      exit.
    endif.
    read table lt_components assigning <ls_comp> index sy-index.
    lv_row = lv_row && <ls_comp>-name && con_tab.
  enddo.
  append lv_row to it_filcont. clear lv_row.
endform.

Einfacher REST-Service (ohne OData)

1. SE11: neue Tabelle ZREST_TAB:
MANDT:MANDT
ID:VBELN
CUSTOMER_NAME:NAME1
MOBILE:TELF1
EMAIL:AD_SMTPADR
DESCR:CHAR100
STATUS:CHAR10
ACTION_TAKEN:CHAR100
CLOSING_DATE:SYDATUM
CREATEDBY:SYUNAME
CREATEDON:SYDATUM
TIME:SYUZEIT

2. SNRO ZRESTC:NUMC10
3. Neue Klasse ZCL_WEBCO_RHANDLER und eine Überschreibung:

class ZCL_WEBCO_RHANDLER definition
  public
  inheriting from CL_REST_HTTP_HANDLER
  final
  create public .
public section.
  methods IF_REST_APPLICATION~GET_ROOT_HANDLER
    redefinition .
endclass.

if_rest_application~get_root_handler redefinition:

data lo_router type ref to cl_rest_router.
  create object lo_router.
 
  lo_router->attach(
    exporting
      iv_template      =  '/webco'    " Unified Name for Resources (-URI)
      iv_handler_class =  'ZCL_WEBCO_RESOURCEP'   " Object Type Name
  ).
  ro_root_handler = lo_router.

4. Neue Klasse ZCL_WEBCO_RESOURCEP und zwei Überschreibungen:

class ZCL_WEBCO_RESOURCEP definition
  public
  inheriting from CL_REST_RESOURCE
  final
  create public .
public section.
  methods IF_REST_RESOURCE~GET
    redefinition .
  methods IF_REST_RESOURCE~POST
    redefinition .
endclass.

if_rest_resource~get redefinition:

data: lv_string1 type vbeln,
      lv_string2 type string,
      ls_co      type zrest_tab,
      ui2_cl_json type ref to cl_trex_json_serializer.
 
  lv_string1 = mo_request->get_uri_query_parameter( iv_name = 'ID' ).
 
  call function 'CONVERSION_EXIT_ALPHA_INPUT'
    exporting
      input  = lv_string1
    importing
      output = lv_string1.
 
  select single * from zrest_tab into corresponding fields of ls_co where id = lv_string1.
 
  create object ui2_cl_json
    exporting
      data = ls_co.    " Data to serialize
 
  ui2_cl_json->serialize( ).
  lv_string2 = ui2_cl_json->get_data( ).
 
  mo_response->create_entity( )->set_string_data( iv_data = lv_string2 ).
 
  mo_response->set_header_field(
    exporting
      iv_name  =  'Content-Type'   " Header Name
      iv_value =  'application/json'   " Header Value
  ).

if_rest_resource~post redefinition:

  data: lv_response type string,
        lv_data type string,
		ls_com type zrest_tab,
        lt_co type standard table of zrest_tab with default key,
        ui2d_cl_json type ref to cl_trex_json_deserializer,
        ui2s_cl_json type ref to cl_trex_json_serializer,
        lo_entity type ref to if_rest_entity,
        lo_response type ref to if_rest_entity.
 
  lo_entity = mo_request->get_entity( ).
  lo_response = mo_response->create_entity( ).
 
  "read string data i.e json
  lv_data = lo_entity->get_string_data( ).
 
  create object ui2d_cl_json.
  ui2d_cl_json->deserialize( exporting json = lv_data importing abap = lt_co ).
  read table lt_co into ls_com with key mandt = 800.
 
  call function 'NUMBER_GET_NEXT'
    exporting
      nr_range_nr             = '01'
      object                  = 'ZRESTC'
      quantity                = '1'
    importing
      number                  = ls_com-id
    exceptions
      ...    .
  ...
 
  ls_com-createdby    = sy-uname.
  ls_com-createdon    = sy-datum.
  ls_com-time         = sy-uzeit.
 
  insert into zrest_tab values ls_com.
 
  create object ui2s_cl_json
    exporting
      data = lt_co.    " Data to serialize
 
  ui2s_cl_json->serialize( ).
 
  lv_response = ui2s_cl_json->get_data( ).
 
  lo_response->set_string_data( iv_data = lv_response ).
endmethod.

5. SICF neuer Service /sap/bc/rest/webco – HandlerList:ZCL_WEBCO_RHANDLER
6. (Test) SoapUI https://sapgw.sys100.sap.sd:8000/sap/bc/rest/webco (x-csrf-Token?)

Die Tabelle ZREST_TAB enthält jetzt die neue Zeilen.

ABAP Query – clean some output entries

END-OF-SELECTION (nach Liste):

field-symbols: <g00> type table,
               <wa_g00> type any,
               <k1> type any,
               <ks> type any.
data: it_g00 type char100 value '%G00[]',
      lv_kna1land type string,
      lv_knasland type string.
assign (it_g00) to <g00>.
if <g00> is assigned.
 loop at <g00> assigning <wa_g00>.
    lv_kna1land = '<wa_g00>-kna1-land1'.
    lv_knasland = '<wa_g00>-knas-land1'.
    unassign: <k1>, <ks>.
    assign: (lv_kna1land) to <k1>,
            (lv_knasland) to <ks>.
  if <k1> is assigned.
    if <ks> is assigned.
      if <k1> eq <ks>.
        delete <g00>.
      endif.
    endif.
  endif.
 endloop.
endif.
" END-OF-SELECTION

EWM/ABAP – Adjust quantity

function y_adjo.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(IV_DLV_NUM) TYPE  STRING
*"----------------------------------------------------------------------
 
  data: lt_k_item       type /scdl/t_sp_k_item
       ,lv_lfr          type /scdl/dl_docid
       ,lv_qty          type /scdl/db_proci_o-qty
       ,wa_k_item       like line of lt_k_item
       ,ls_action       type /scdl/s_sp_act_action
       ,ls_prcode       type /scwm/dlv_prcode_add_str
       ,lo_prd_out      type ref to /scdl/cl_sp_prd_out
       ,lt_a_item       type /scdl/t_sp_a_item
       ,lv_rejected     type boole_d
       ,lo_message_box  type ref to /scdl/cl_sp_message_box
       ,lt_a_head       type /scdl/t_sp_a_head
       ,lt_k_head       type /scdl/t_sp_k_head
       ,wa_k_head       like line of lt_k_head
       ,lt_return_codes type /scdl/t_sp_return_code.
 
  field-symbols: <fs_action_control>.
  ls_action-action_code = /scwm/if_dl_c=>sc_ac_prcode_add.
  create data ls_action-action_control type /scwm/dlv_prcode_add_str.
 
* Lieferung
  select single docid into lv_lfr from /scdl/db_refdoc where refdocno eq iv_dlv_num and refdoccat eq 'ODR'.
  select docid into wa_k_item-docid from /scdl/db_proch_o where docno = '00000000000000000000000000000101423'. endselect.
  select itemid from /scdl/db_proci_o into wa_k_item-itemid where docno = '00000000000000000000000000000101423' and itemno = '0000000040'. endselect.
 
  if sy-subrc ne 0.
    message s038(/scdl/bo_action) display like 'E'.
    " Keine Lieferung gefunden
  endif.
  append wa_k_item to lt_k_item.
 
 
  if lo_prd_out is initial.
    create object lo_message_box.
    create object lo_prd_out
      exporting
        io_message_box = lo_message_box
        iv_mode        = /scdl/cl_sp=>sc_mode_classic
        iv_doccat      = /scdl/if_dl_doc_c=>sc_doccat_out_prd.
  endif.
 
*   Select Delivery
  wa_k_head-docid = wa_k_item-docid.
  append wa_k_head to lt_k_head.
 
  clear lv_rejected.
  refresh lt_return_codes.
  lo_prd_out->/scdl/if_sp1_aspect~select(
    exporting
      inkeys       = lt_k_head
      aspect       = /scdl/if_sp_c=>sc_asp_head
    importing
      outrecords   = lt_a_head
      rejected     = lv_rejected
      return_codes = lt_return_codes ).
 
* Lieferung sperren
  clear lv_rejected.
  refresh lt_return_codes.
  lo_prd_out->lock(
    exporting
      inkeys       = lt_k_head
      aspect       = /scdl/if_sp_c=>sc_asp_head
      lockmode     = /scdl/if_sp1_locking=>sc_exclusive_lock
    importing
      rejected     = lv_rejected
      return_codes = lt_return_codes ).
*   check if any error occurred
  "mcr_fill_error 'Lock delivery failed'.
 
*   adjust delivery
  clear lv_rejected.
  refresh lt_return_codes.
 
  ls_action-action_code = /scwm/if_dl_c=>sc_ac_prcode_add.
  create data ls_action-action_control type /scwm/dlv_prcode_add_str.
  assign ls_action-action_control->* to <fs_action_control>.
  ls_prcode-prcode = 'O001'.
  ls_prcode-qty    = -1.
  ls_prcode-uom    = 'ST'.
 
  <fs_action_control> = ls_prcode.
  lo_prd_out->/scdl/if_sp1_action~execute(
    exporting
      aspect             = /scdl/if_sp_c=>sc_asp_item
      inkeys             = lt_k_item
      inparam            = ls_action
      action             = /scdl/if_sp_c=>sc_act_execute_action
    importing
      outrecords         = lt_a_item
      rejected           = lv_rejected
      return_codes       = lt_return_codes ).
*   check if any error occurred
  if lv_rejected is not initial.
    "    or line_exists( lt_return_codes[ failed = 'x'] ).
    "  rollback work.
    "      mcr_fill_error 'delivery qty adjust failed'.
  else.
    lo_prd_out->save(  ).
    commit work and wait.
    "      ls_odo-msgtxt = 'delivery qty adjust successfully'.
  endif.
  /scwm/cl_tm=>cleanup( ).
 
endfunction.

OData POST

For java.sap.sd/odata

I have created OData service in SEGW and published it.

There are two case :

1.)With CSRF token —

By Default Gateway will generate the CSRF token, if any of CUD(Create, Update and Delete) operation we are doing it is mandatory to pass this token(CSRF ).

So before any CUD operation, Retrieve a CSRF token with a non-modifying request(get method).

Validity of this Token is 30 mins (which can further be altered by Tcode RZ11(Parameter : http/security_session_timeout) might be there is some diffrent mecanism as well

Fetching mechanism : In client side need to put one parameter X-CSRF-Token(‘X-CSRF-Token’) with the value ‘Fetch’ is sent along with the non-modifying request.

2.) Without CSRF token —

without CSRF first we need to override standard behavior of service, in SICF node for each service need to maintain parameter in GUI configuration as below :

Parameter Name: ~CHECK_CSRF_TOKEN

Parameter Value: 0/1 (disable/enable)

And At client level in Header need to pass X in Header

(‘X-Requested-With’: ‘X’)

Requested URI: /sap/opu/odata/sap/mein-dienst/infosatzSet

Web service ABAP method (for /inbound-idoc):

method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_DEEP_ENTITY.
data ir_deep_entity type zz_record_mpc_ext=>ts_deep_entity.
    io_data_provider->read_entry_data( IMPORTING es_data = ir_deep_entity ).
 
  copy_data_to_ref( exporting is_data = ir_deep_entity
                    changing cr_data = er_deep_entity ).
  endmethod.

redefinde MPC_EXT DEFINE Method:

data:
 lo_annotation     TYPE REF TO /iwbep/if_mgw_odata_annotation,
 lo_entity_type    TYPE REF TO /iwbep/if_mgw_odata_entity_typ,
 lo_complex_type   TYPE REF TO /iwbep/if_mgw_odata_cmplx_type,
 lo_property       TYPE REF TO /iwbep/if_mgw_odata_property,
 lo_entity_set     TYPE REF TO /iwbep/if_mgw_odata_entity_set.
 
 super->define( ).
 
 lo_entity_type = model->get_entity_type( iv_entity_name = 'E_Kopf' ). " Pos
 
 lo_entity_type->bind_structure( iv_structure_name  = 'zz_record_mpc_ext=>ts_deep_entity' ).

MPC_EXT Types:

* variable names should be same as of 'Navigation Property' name created
* in Entity 'Kopf' / 'Pos' else structure can not be referred in code.
 
*    types: " (create in MPC_EXT Class)
*      begin of ts_deep_entity,
*        kopf type standard table of ts_infosatz   with default key,
*        pos  type standard table of ts_staffelpos with default key,
*      end of ts_deep_entity.
 
 types: ty_t_soitem type standard table of zz_record_mpc=>ts_staffelpos with default key.
*" Represents full - header with one of more items
 types: begin of ty_s_so.
 include type zz_record_mpc=>ts_infosatz.
 types: SOItems type ty_t_soitem,
 end of ty_s_so.
 
 data: ls_so type ty_s_so,
 ls_item type zz_record_mpc=>ts_staffelpos.

Debug OData requests: blogs.sap.com/2016/10/29/method-not-allowed-error-trouble-shoot

Change spool request name (ewm)

To change spool request name for printing forms (they are was set up in SPPFCADM transaction) we can add next enhancement into FM /SCWM/EXECUTE_PPF_WO_PDF (warehouse order):

ENHANCEMENT 1  Y_PPF_WO_PDF.    "active version
  field-symbols: <ft> type /scwm/tt_whohu_pdf.
  assign ('LT_WHOHU_PDF') to <ft>.
  if <ft> is assigned.
    zscwm_ex_prnt_pdf_wo=>set_whohu_ref( changing ct_whohu = <ft> ).
  endif.
  data: v_text1(10)
       ,v_text2(10)
       ,v_text3(10)
       ,v_text4(20).
    xs_output_params-reqnew   = 'X'.
    xs_output_params-reqfinal = 'X'.
    split xs_output_params-covtitle at ' ' into v_text1 v_text2 v_text3 v_text4.
    clear: xs_output_params-covtitle.
 
    case iv_form.
      when 'Y_ZAKAZ_WO_MULTIPLE'.
        xs_output_params-covtitle = v_text3 && ' - Заказ на комплектование - ' &&  v_text2.
      when 'Y_ZAKAZ__WO_HUIDENT'.
        xs_output_params-covtitle = v_text3 && ' - ЕО (Handling unit) - ' &&  v_text2.
      when 'Y_BIRKA_DETALI_UZLA'.
        xs_output_params-covtitle = v_text3 && ' - Бирка №1 - ' &&  v_text2.
      when 'Y_BIRKA_DETALI_UZLA_N0'.
        xs_output_params-covtitle = v_text3 && ' - Бирка №0 - ' &&  v_text2.
    endcase.
ENDENHANCEMENT.

For HU forms (FM /SCWM/EXECUTE_PPF_HU_PDF):

ENHANCEMENT 1  YEI_PPF_HU_PDF.    "active version
  FIELD-SYMBOLS: <ft> TYPE /scwm/tt_huhdr_int.
  ASSIGN ('IT_HUHDR') TO <ft>.
  IF <ft> IS ASSIGNED.
    yscwm_ex_prnt_pdf_hu=>set_huhdr_ref( CHANGING ct_huhdr = <ft> ).
  ENDIF.
ENDENHANCEMENT.

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.

Singleton

O_SINGLETON  Static Attribute Private  Type Ref To Z_CL_MYCLASSNAME
 
method factory. " static public
    if o_singleton is initial.
      o_singleton = new #( ).
    endif.
    ro_ret = o_singleton.
 
endmethod.
 
RO_RET  Returning Parameter  Type Ref To  Z_CL_MYCLASSNAME
 
*  lv_myvariabe = z_cl_myclassname=>factory( )->some_method(

wiki.scn.sap.com/Singleton

Eingehende IDoc erzeugen (Staffeln/Konditionssätze)

function y_staffladen.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(IV_KSCHL) TYPE  KSCHL OPTIONAL
*"     REFERENCE(IV_KAPPL) TYPE  KAPPL
*"     REFERENCE(IV_STFKZ) TYPE  STFKZ
*"     REFERENCE(EKORG) TYPE  EKORG
*"     REFERENCE(MATNR) TYPE  MATNR
*"     REFERENCE(LIFNR) TYPE  LIFNR
*"     REFERENCE(WERK) TYPE  WERKS-WERKS
*"     REFERENCE(DATAB) TYPE  DATAB
*"     REFERENCE(DATBI) TYPE  DATBI
*"----------------------------------------------------------------------
 
  constants: lcon_table_no_017   type kotabnr value '017',
             lcon_applicatio_m   type kappl value 'M',
             lcon_cond_type_zpb0 type kschl value 'ZPB0',
             lcon_scale_type_a   type stfkz value 'A',
             lcon_calc_type_c    type krech value 'C',
             lcon_valid_from     type kodatab value '19960330',
             lcon_valid_to       type kodatbi value '66660606',
             lcon_cond_usage_a   type kvewe value 'A',
             lcon_cond_count_i   type kopos value '01'.
 
  types: begin of t_varkey_a017_header,
           vkorg type vkorg,
           vtweg type vtweg,
           spart type spart,
           kunnr type kunnr_v,
           pltyp type pltyp,
           waerk type waerk,
           matnr type matnr,
         end of t_varkey_a017_header.
 
  data: ls_edidc    type edi_dc40,
        lt_edidd    type table of edi_dd40,
        ls_edidd    like line of lt_edidd,
        ls_e1komg   type e1komg,
        ls_e1konh   type e1konh,
        ls_e1konp   type e1konp,
        ls_e1konm   type e1konm,
        lv_varkey   type t_varkey_a017_header.
 
  ls_edidd-segnam = 'E1KOMG'.
  ls_edidd-psgnum = '0000'.
  ls_edidd-hlevel = '01'.
  ls_e1komg-kvewe = lcon_cond_usage_a.
  ls_e1komg-kotabnr = lcon_table_no_017.
  ls_e1komg-kappl = lcon_applicatio_m.
  ls_e1komg-kschl = lcon_cond_type_zpb0.
* varkey aus KONH:
  ls_e1komg-vakey = '0280011017A400              2155300 0'.
* ls_varkey = sy-mandt &&'M'&&'KSCHL'&&'LIFNR'&&'MATNR'&&'EKORG'&&'WERKS'&&'ESOKZ'&&'DATBI'&&'DATAB'.
  ls_edidd-sdata  = ls_e1komg.
  append ls_edidd to lt_edidd.
  clear ls_edidd.
 
  ls_edidd-segnam = 'E1KONH'.
  ls_edidd-psgnum = '0001'.
  ls_edidd-hlevel = '01'.
  ls_e1konh-datab = lcon_valid_from.
  ls_e1konh-datbi = lcon_valid_to.
  ls_edidd-sdata  = ls_e1konh.
  append ls_edidd to lt_edidd.
  clear ls_edidd.
 
  ls_edidd-segnam = 'E1KONP'.
  ls_edidd-psgnum = '0001'.
  ls_edidd-hlevel = '01'.
  ls_e1konp-kschl = lcon_cond_type_zpb0.
  ls_e1konp-stfkz = lcon_scale_type_a.
  ls_e1konp-kzbzg = 'C'.
  ls_e1konp-konms = 'PCE'.
  ls_e1konp-krech = lcon_calc_type_c.
  ls_e1konp-konwa = 'EUR'.
  ls_e1konp-kmein = 'PCE'.
  ls_e1konp-kwaeh = 'EUR'.
  ls_e1konp-zaehk_ind = lcon_cond_count_i.
  ls_edidd-sdata  = ls_e1konp.
  append ls_edidd to lt_edidd.
  clear ls_edidd.
 
  ls_edidd-segnam = 'E1KONM'.
  ls_edidd-psgnum = '0002'.
  ls_edidd-hlevel = '01'.
  ls_e1konm-kstbm = '1000'.
  ls_e1konm-kbetr = '16.30'.
  ls_edidd-sdata  = ls_e1konm.
  append ls_edidd to lt_edidd.
  clear ls_edidd.
 
  ls_edidd-segnam = 'E1KONM'.
  ls_edidd-psgnum = '0002'.
  ls_edidd-hlevel = '01'.
  ls_e1konm-kstbm = '10000'.
  ls_e1konm-kbetr = '15.50'.
  ls_edidd-sdata  = ls_e1konm.
  append ls_edidd to lt_edidd.
  clear ls_edidd.
 
  ls_edidc-mestyp = 'COND_A'.
  ls_edidc-idoctyp = 'COND_A04'.
  ls_edidc-rcvpor = ls_edidc-sndpor = 'SAPDEV'.
  ls_edidc-rcvprt = ls_edidc-sndprt = 'LS'.
  ls_edidc-sndprn = ls_edidc-rcvprn ='DEVCLNT100'.
  ls_edidc-status = '64'.
  ls_edidc-direct = '2'.
 
  call function 'IDOC_INBOUND_SINGLE'
    exporting
      pi_idoc_control_rec_40  = ls_edidc
      pi_do_commit            = 'X'
*  importing
*    pe_idoc_number
    tables
      pt_idoc_data_records_40 = lt_edidd
    exceptions
      idoc_not_saved          = 1
      others                  = 2.
 
endfunction.