Rename file on Application server

form datei_umbenennen using lv_altpfad lv_neupfad type string.
  data: lv_eof_reached   type c,
        lv_buffer(20480),
        lv_buflen        type i.
 
  open dataset lv_altpfad for input in binary mode.
  if sy-subrc ne 0.
    raise open_input_file_failed.
  endif.
 
  open dataset lv_neupfad for output in binary mode.
  if sy-subrc ne 0.
    raise open_output_file_failed.
  endif.
 
  clear lv_eof_reached.
 
  do.
    clear lv_buffer.
 
    read dataset lv_altpfad
            into lv_buffer length lv_buflen.
 
    if sy-subrc = 4.
      lv_eof_reached = 'X'.
    elseif sy-subrc > 4.
      raise read_block_failed.
    endif.
 
    transfer lv_buffer to lv_neupfad
      length lv_buflen.
 
    if sy-subrc ne 0.
      raise write_block_failed.
    endif.
 
    if lv_eof_reached eq 'X'.
      exit.
    endif.
  enddo.
 
  close dataset lv_altpfad.
  close dataset lv_neupfad.
  if sy-subrc <> 0.
    raise close_output_file_failed.
  endif.
 
  delete dataset lv_altpfad.
endform.

FMs and BAPIs to create customer/vendor master

_sap

Customers:
SD_CUSTOMER_MAINTAIN_ALL – quite powerful, but has no RFC (should be wrapped for it)
BAPI_CUSTOMER_CREATEFROMDATA1 – much simple, but has RFC (a BAPI).
As an additional way – using IDocs (DEBMAS).

Vendors:
Class VMD_EI_API – methods Initialize and Maintenance
Functional group LC01.
As an additional way – IDocs (CREMAS).

On distribution – is delivery packed?

STMSIcon03 FM WS_LM_CHANGE_DLV_DISTRIB_STATE STMSIcon01

ENHANCEMENT 1  YDISTRIBUTE.
if ( sy-tcode eq 'VL06I' or sy-tcode eq 'VL06ID' ) and  ( if_d_proctype eq proctype_inbdist ).
"VL06I - do not process the enhancement if it distributes via other ways"
"proctype_inbdist - checking only inbound deliveries"
 types: begin of t_params,
  paramval like yparamconst-paramval,
 end of t_params.
 data: lt_params type standard table of t_params,
       wa_params like line of lt_params, "work area (header line)"
       is_zles type boolean.  "default abap_false."
"which delivery types for checking/processing are defined in our Z-table?"
 select paramval from yparamconst into corresponding fields of table lt_params where paramid  = 'LIEFERUNGSNUMMER'.
 if sy-subrc eq 0.
  field-symbols: <ls_lfart> type lipov.
  loop at ct_worktab assigning <ls_lfart>.
    read table lt_params with key paramval = <ls_lfart>-lfart transporting no fields.
   if sy-subrc eq 0.
    is_zles = abap_true.
"all the selected delivery [types] are in yparamconst"
   endif.
  endloop.
 if is_zles eq abap_true.
  data: lt_wahl like gs_select occurs 0 with header line,
        begin of lt_wahl2 occurs 0,
          vbeln like likp-vbeln,
          verur like likp-verur,
        end of lt_wahl2,
        l_msg type c length 50,
        ans type char1.
  field-symbols: <ls_arbeit> type lipov,
                 <ls_wahl2> like line of lt_wahl2.
  loop at ct_worktab assigning <ls_arbeit>.
    lt_wahl-vbeln = <ls_arbeit>-vbeln.
    collect lt_wahl.
  endloop.
 
  check not lt_wahl[] is initial.
  select vbeln verur from likp
               into table lt_wahl2
               for all entries in lt_wahl
               where vbeln eq lt_wahl-vbeln.
"in addition we checking if the field External ID isn't empty"
  loop at lt_wahl2 transporting no fields
    where verur eq space.
  endloop.
 
  if sy-subrc eq 0.
   message s000(Y_YSD) into l_msg.
   call function 'POPUP_TO_CONFIRM'
    exporting
      titlebar       = 'Confirm'
      text_question  = l_msg
      text_button_1  = 'Yes'
      text_button_2  = 'No'
      display_cancel_button = ''
      default_button = '2'
    importing
      answer         = ans.
   if ans eq 2.
    return.
   endif.
  endif.
 
  clear l_msg.
 
  field-symbols: <ls_vepo> type lipov.
  data lt_vepo like VEPO occurs 0.
 
  loop at ct_worktab assigning <ls_vepo>.
    select vbeln from vepo into corresponding fields of table lt_vepo where vbeln eq <ls_vepo>-vbeln.
     if sy-subrc ne 0.
       message s001(Y_YSD) into l_msg.
       call function 'POPUP_TO_CONFIRM'
        exporting
          titlebar       = 'Confirm'
          text_question  = l_msg
          text_button_1  = 'Yes'
          text_button_2  = 'No'
          display_cancel_button = ''
          default_button = '2'
        importing
          answer         = ans.
       if ans eq 2.
        return.
   endif.
   endif.
  endloop.
 
 endif. "is_zles"
 
 endif.
endif.
ENDENHANCEMENT.

Важные слова не важны

В процессе написания кода по заданной спецификации неожижанно обнаружилось, что ключевые слова ABAP не являюся зарезервированными.
Поэтому нижеследующий код компилируется и даже выполняется:

TYPES TYPE.
 
DATA USING TYPE TYPE.
 
PERFORM FORM USING USING USING USING.
 
FORM FORM USING USING TYPE TYPE DATA LIKE USING TYPE TYPE TYPE.
 
  DATA = TYPE.
 
  DATA TO TYPE I.
  DATA ADD LIKE TO.
 
  ADD ADD TO TO.
 
  DATA IF.
  DATA EQ.
  DATA ENDIF.
  IF IF EQ EQ.
    MOVE TO TO ENDIF.
  ENDIF.
 
ENDFORM.

Даже если так писать и можно, то этого делать всё-таки не следует:

  • Усложняет восприятие, хотя есть и подсветка кода и uppercase/lowercase
  • Name-conventions
  • Ограничения при работе с БД
  • Это не смешно

Зато есть служебная таблица TRESE, в которой перечисляются разные наименования полей, которые нельзя создавать из-за ограниченний в разных БД.
© Иван Болховитинов

Geschützt: Propose next empty bin (WMS)

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

Saving Word documents from ABAP

program ytrans.
 
******************************************************************
* TABLE DECLARATIONS.
******************************************************************
tables: e070, e07t.
 
data:  display type c,
       exit type c,
       ok_code like sy-ucomm,
       lo_form type ref to ytform,
       lf_test type ref to ytform,
       l_template type string value 'block',
       l_num type i,
       isource type table of string,
       xsource type t_source.
 
selection-screen begin of block standard.
select-options: p_skorr    for e070-strkorr,
                p_user     for e070-as4user no intervals default sy-uname,
                p_date     for e070-as4date.
selection-screen skip.
 
selection-screen end of block standard.
 
start-of-selection.
  types: begin of t_reqs,
    sel,
    strkorr like e070-strkorr,
    as4text like e07t-as4text,
    as4user like e070-as4user,
    as4date like e070-as4date,
  end of t_reqs.
 
  data: lt_reqs type standard table of t_reqs,
        wa_reqs type t_reqs. "like line of lt_reqs. "work area (header line)"
  select * from e070 inner join e07t on e070~strkorr eq e07t~trkorr
    into corresponding fields of table lt_reqs where e070~trkorr in p_skorr[] and
    e070~as4user in p_user[] and e070~as4date in p_date[] and e070~trstatus eq 'R'.
 
  xsource = '1.'. append xsource to isource.
  xsource = '2.'. append xsource to isource.
  xsource = '3.'. append xsource to isource.
  xsource = '4.'. append xsource to isource.
end-of-selection.
 
  perform alv_grid_display.
 
*&---------------------------------------------------------------------*
*&      Form  alv_grid_display
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form alv_grid_display.
  type-pools: slis.
  data: it_fieldcat  type slis_t_fieldcat_alv,
        wa_fieldcat  type slis_fieldcat_alv,
        fs_layout type slis_layout_alv.
  fs_layout-box_fieldname = 'SEL'.
  fs_layout-zebra = 'X'.
 
  wa_fieldcat-fieldname  = 'STRKORR'.
  wa_fieldcat-seltext_m  = 'Номер запроса'.
  append wa_fieldcat to it_fieldcat.
  wa_fieldcat-fieldname  = 'AS4TEXT'.
  wa_fieldcat-seltext_m  = 'Описание'.
  append wa_fieldcat to it_fieldcat.
  wa_fieldcat-fieldname  = 'AS4USER'.
  wa_fieldcat-seltext_m  = 'Имя пользователя'.
  append wa_fieldcat to it_fieldcat.
  wa_fieldcat-fieldname  = 'AS4DATE'.
  wa_fieldcat-seltext_m  = 'Дата'.
  append wa_fieldcat to it_fieldcat.
 
  call function 'REUSE_ALV_GRID_DISPLAY'
    exporting
      it_fieldcat              = it_fieldcat
      is_layout                = fs_layout
      i_callback_program       = sy-repid
      i_callback_pf_status_set = 'SET_GUI_STATUS'
      i_callback_user_command  = 'COMMANDS_HANDLER'
    tables
      t_outtab                 = lt_reqs
    exceptions
      program_error            = 1
      others                   = 2.
endform.                    "alv_grid_display
*&---------------------------------------------------------------------*
*&      Form  set_gui_stat
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->RT_EXTAB   text
*----------------------------------------------------------------------*
form set_gui_status using rt_extab type slis_t_extab.
  set pf-status 'YSTATUS' excluding rt_extab.
  set titlebar text-005.
endform.                    "set_gui_status
 
*&---------------------------------------------------------------------*
*&      Form  STAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->R_UCOMM      text
*      -->RS_SELFIELD  text
*----------------------------------------------------------------------*
form commands_handler using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
  data selfield type slis_selfield.
  data lt_sel type standard table of t_reqs.
  case r_ucomm.
    when 'QUIT'.
      leave program.
    when 'SELE'.
      delete lt_reqs where sel ne 'X'.
      set pf-status ''.
      call screen 0100.
  endcase.
endform.                    "STAT
 
*----------------------------------------------------------------------*
*  MODULE status_0100 OUTPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
module status_0100 output.
  "class CL_ABAP_CHAR_UTILITIES definition load.
  data: io_text type string,
        lv_username type string,
        header_date type string,
        lv_commalist type string,
        lv_reqlist type string,
        lv_reqtext type string,
        lv_teststeps type string.
 
  field-symbols: <fs> like line of lt_reqs,
                 <fsi> like line of isource.
 
  case sy-ucomm.
    when 'TESTS'.
      editor-call for isource.
    when 'EXIT'.
      leave program.
    when 'GENERATE'.
      loop at lt_reqs assigning <fs> .
        concatenate <fs>-strkorr lv_reqlist into lv_reqlist separated by ';'.
        lv_reqtext = <fs>-strkorr && cl_abap_char_utilities=>horizontal_tab &&
                      <fs>-as4text && cl_abap_char_utilities=>cr_lf && lv_reqtext.
        lv_commalist = |{ <fs>-strkorr }, { lv_commalist }|.
      endloop.
 
      shift lv_reqlist right deleting trailing ';'. shift lv_reqlist left deleting leading space.
      shift lv_commalist right deleting trailing ', '.
 
      select single name_text from user_addrp into lv_username where bname = sy-uname.
      concatenate sy-datum+6(2) sy-datum+4(2) sy-datum(4) into header_date separated by '.'.
 
      sort isource descending.
      loop at isource assigning <fsi> .
        lv_teststeps = <fsi> && cl_abap_char_utilities=>horizontal_tab &&
                      lv_teststeps && cl_abap_char_utilities=>cr_lf.
      endloop.
 
      create object
        lo_form
        exporting
          i_template = 'Y_TRMAIN'.
 
      lo_form->replicate(
       i_template_id = l_template
       i_copy_num = 2
      ).
 
      lo_form->prep_seq_access( ).
      if lo_form->find_variable('header_date') eq abap_true.
        lo_form->set_value( header_date ).
      endif.
      if lo_form->find_variable('header_num') eq abap_true.
        lo_form->set_value( lv_commalist ).
      endif.
      if lo_form->find_variable('source_client') eq abap_true.
        lo_form->set_value( sy-mandt && space && sy-sysid ).
      endif.
      if lo_form->find_variable('dest_client') eq abap_true.
        lo_form->set_value('300 [PEW]').
      endif.
      if lo_form->find_variable('sec_nums') eq abap_true.
        lo_form->set_value( lv_commalist ).
      endif.
      if lo_form->find_variable('trans_list') eq abap_true.
        lo_form->set_value( lv_reqtext ).
      endif.
      if lo_form->find_variable('special') eq abap_true.
        lo_form->set_value( io_text ).
      endif.
      if lo_form->find_variable('owna') eq abap_true.
        lo_form->set_value( lv_username ).
      endif.
      lo_form->finish_seq_access( ).
      lo_form->clean( ).
 
      lo_form->display( sy-datum && '_' && lv_reqlist ).
 
      create object
        lf_test
        exporting
          i_template = 'Y_TESTS'.
 
      lf_test->replicate(
       i_template_id = l_template
       i_copy_num = 2
      ).
 
      lf_test->prep_seq_access( ).
      if lf_test->find_variable('header_date') eq abap_true.
        lf_test->set_value( header_date ).
      endif.
      if lf_test->find_variable('trans_list') eq abap_true.
        lf_test->set_value( lv_reqtext ).
      endif.
      if lf_test->find_variable('sec_nums') eq abap_true.
        lf_test->set_value( lv_commalist ).
      endif.
      if lf_test->find_variable('test_sys') eq abap_true.
        lf_test->set_value( 'TES310' ).
      endif.
      if lf_test->find_variable('test_steps') eq abap_true.
        lf_test->set_value( lv_teststeps ).
      endif.
      if lf_test->find_variable('special') eq abap_true.
        lf_test->set_value( io_text ).
      endif.
      if lf_test->find_variable('owna') eq abap_true.
        lf_test->set_value( lv_username ).
      endif.
      lf_test->finish_seq_access( ).
      lf_test->clean( ).
 
      lf_test->display( sy-datum && '_' && lv_reqlist && '_ПТ').
      leave program.
  endcase.
endmodule.                 " STATUS_0100  OUTPUT

Processing and modifying outbound JIT calls

Broadcast from jit.sap.sd/processing-outbound:

As I’ve said before – user-defined actions for JIT outbound can be implemented into BAdI interface IF_EX_JITO_ACTION (BAdI JITO_ACTION).

Below you can find JIT-action ZSDJ, which added into call control flow and doing next things with component groups, selected in JITOM transaction and accumulated in system structure JITODIACO_CT:
– a popup window with two input fields DATE and TIME
– converting these DATE and TIME into TIMESTAMP
– updates required planned date and time of selected component groups (JITODIACO_CT).

method IF_EX_JITO_ACTION~CUSTOMER_ACTION.
 
if action_iv = 'ZSDJ'.
 
 data: l_returnCode(1) type C,
       ivals type table of sval,
       lt_fields type sval,
       lv_foop type sval,
       lv_xdate type datum,
       lv_xtime type uzeit,
       ls_jitodiaco type jitodiaco,
       lv_timestamp type tzntstmps.
 
 clear: lt_fields.
 lt_fields-TABNAME   = 'RKAUF'.
 lt_fields-FIELDNAME = 'TODATE'.
 lt_fields-VALUE     = sy-datum.
 lt_fields-FIELD_OBL = 'X'.
 lt_fields-FIELDTEXT = 'Укажите дату:'.
 append lt_fields to ivals.
 
 clear: lt_fields.
 lt_fields-tabname   = 'SFSRFW_TIMES'.
 lt_fields-fieldname = 'CREATETIME'.
 lt_fields-field_obl = 'X'.
 lt_fields-value     = sy-uzeit.
 lt_fields-fieldtext = 'Укажите время:'.
 append lt_fields to ivals.
 
 call function 'POPUP_GET_VALUES'
  exporting
   popup_title = 'Запланированная дата потребности'
  importing
   returncode = l_returnCode
  tables
   fields = ivals
  exceptions
   error_in_fields = 1
  others = 2.
 
 if l_returnCode eq 'A' or sy-subrc <> 0.
   " lv_error = 'X'.
   exit.
 else. " √ -ОК-!
  loop at ivals[] into lv_foop.
    if lv_foop-fieldname eq 'TODATE'.
     lv_xdate = lv_foop-value.
    else.
     lv_xtime = lv_foop-value.
    endif.
  endloop.
 
 call function 'CONVERT_INTO_TIMESTAMP'
  exporting
    i_datlo     = lv_xdate
    i_timlo     = lv_xtime
    i_tzone     = sy-zonlo
  IMPORTING
    e_timestamp = lv_timestamp.
 
  if jitodiaco_ct[] is not initial.
   loop AT jitodiaco_ct into ls_jitodiaco.
    update jitoit set rdate = lv_timestamp where outpo eq ls_jitodiaco-outpo and intst eq 'XX10'.
   endloop.
  endif.
 
 endif.
 
endif.
 
endmethod.

Mapping columns on distributing into EWM

Firmenzentrale SAP

During distribuiton a delivery from ERP to EWM we can add some ERP-related data into EWM delivery tables:

/SCWM/IF_EX_MAPIN_OD_SAVEREPL~MAPIN
 
METHOD /scwm/if_ex_mapin_od_saverepl~mapin.
 
  DATA: lv_break TYPE char1,
        lt_vbeln TYPE TABLE OF zerp_get_pkkey_vbeln,
        lv_dest         TYPE char10.
 
  FIELD-SYMBOLS: <ls_item_data> LIKE LINE OF it_bapi_item_data,
                 <ls_vbeln> LIKE LINE OF lt_vbeln,
                 <ls_dlv_request> LIKE LINE OF ct_dlv_request,
                 <ls_keymap> TYPE /scdl/dl_keymap_item_str,
                 <ls_item> TYPE /scdl/af_dr_item_str.
 
  IF is_bapi_header_data-dlv_type = 'ZKBN'.
 
    LOOP AT it_bapi_item_data ASSIGNING <ls_item_data>.
      APPEND INITIAL LINE TO lt_vbeln ASSIGNING <ls_vbeln>.
      <ls_vbeln>-vbeln = <ls_item_data>-deliv_numb.
      <ls_vbeln>-posnr = <ls_item_data>-itm_number.
    ENDLOOP.
 
    lv_dest = zcl_ewm_main=>get_destination( ).
    CALL FUNCTION 'ZERP_GET_PKKEY' DESTINATION lv_dest
      TABLES
        it_vbeln = lt_vbeln
      EXCEPTIONS
        not_data = 1
        OTHERS   = 2.
    IF sy-subrc = 0.
      LOOP AT ct_dlv_request ASSIGNING <ls_dlv_request>.
        LOOP AT <ls_dlv_request>-t_item ASSIGNING <ls_item>.
          LOOP AT <ls_item>-t_keymap_item ASSIGNING <ls_keymap>.
            READ TABLE lt_vbeln ASSIGNING <ls_vbeln> WITH KEY vbeln = <ls_keymap>-docno
                                                              posnr = <ls_keymap>-itemno.
            IF sy-subrc = 0.
              <ls_item>-s_eew-zzpkkey = <ls_vbeln>-pkkey.
            ENDIF.
          ENDLOOP.
        ENDLOOP.
      ENDLOOP.
    ENDIF.
  ENDIF.
 
 
ENDMETHOD.

For SMW0

Auth Obj check

method is_auth_for_plant.
    authority-check object 'S_TRVL_BKS'
             id 'ACTVT' field '01'
             id 'WERKS' field iv_plant.
    if sy-subrc eq 0.
      rv_authorized = abap_true.
    else.
      rv_authorized = abap_false.
    endif.
endmethod.
*                                         ///*
*                                   ///////////////////
*                             ,///////////////////////
*                            (/////////////////////
*                            (////////////////////////
*                         (///////////////////////////*
*                       /////////////////////////////
*                              (//////////////////////
*                                ///////////////////(
*                                ///////////////(              ////*/
*                               //////////////////       //////////////
*                              ////////////////////////////////////////
*                            */////////////////////////////////////////
*                           //////////////////////////////////////(*
*                          /////////////////////////////////////.
*                        ,/////////////////////////////////(/
*                      *//////////////////////////////(#
*                    (//////////////////////////////
*                  (//////////////////////////////////
*                ///////////////////////////////////////
*              ////////////////////(   #//////////////////
*            ////////////////////        ((/////////////////*,,.
*          *//////////////////(            /(//////////////////////*
*            ///////////////.                 (///////////////////
*              ,/////////////                   (///////////////
*                  (//////////                    //////////
*                       .(////                      (///
*
*