Thursday, 15 February 2024

Change Info record using BAPI_ALM_ORDER_MAINTAIN

 









 Data g_refnum(6TYPE N.

  REFRESH lt_methods,lt_component,lt_component_up..
  CLEAR ls_methods.
  CLEAR ls_component.
  CLEAR ls_component_up.

*Get Reservation N
  LOOP AT IT_DAT4 INTO WA_DAT4.
    Select single rsnum rspos
           into (wa_dat4-rsnum,wa_dat4-rspos)
           from RESB
           Where Aufnr EQ G_AUFNR
             And Matnr EQ wa_dat4-col_10

    Modify it_dat4 from wa_dat4.
  Endloop.

  g_refnum 1.
  LOOP AT IT_DAT4 INTO WA_DAT4 WHERE col_12 EQ SPACE.
*-- Component Mapping
    ls_methods-refnumber =  g_refnum .
    ls_methods-objecttype 'COMPONENT'.
    ls_methods-method     'CHANGE'.
    ls_methods-objectkey  =  G_AUFNR.
    Append ls_methods to lt_methods.

    ls_component-reserv_no =  wa_dat4-rsnum.
    ls_component-res_item  =  wa_dat4-rspos.
    ls_component-material  =  wa_dat4-col_10.
    ls_component-item_number =  wa_dat4-col_21.
    ls_component-activity '0010'.
    ls_component-info_rec ''.
    ls_component-pur_group wa_dat4-col_06.

    ls_component_up-material 'X'.
    ls_component_up-item_number 'X'.
    ls_component_up-info_rec 'X'.
    ls_component_up-pur_group 'X'.
    APPEND ls_component TO lt_component.
    APPEND ls_component_up TO lt_component_up.
    CLEAR ls_methods.

    ls_methods-method 'SAVE'.
    APPEND ls_methods TO lt_methods.
    g_refnum g_refnum + 1.
  ENDLOOP.

  call function 'BAPI_ALM_ORDER_MAINTAIN'
    TABLES
      it_methods      lt_methods
      it_component    lt_component
      it_component_up lt_component_up
      return          lt_return
      et_numbers      lt_numbers.

  Call function 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait 'X'.

Wednesday, 31 January 2024

Upload File From Server

 


Types : begin of itab1,
        rec(1000type c,
        end of itab1.

data  itab type table of itab1.
data  wa type itab1.

  refresh itab.
  clear itab.
  if p_fname is not initial.  "This Option not use

    message 'Can Not Select File, Only For Background' type 'E'.

    p_file  p_fname+7(53).

    replace all occurrences of '\' in p_file with '/'.
    concatenate '/sapinterface/N' p_file into p_file.

*   For Test Location only
    replace all occurrences of 'QAS' in p_file with ''.

    w_flname p_file+36(25).

    open dataset p_file
    for input in text mode encoding default ."WITH WINDOWS LINEFEED.

    if sy-subrc <> 0.
*    MESSAGE XXX WITH v_file.
    endif.

    do.
      read dataset p_file into wa.
      if sy-subrc <> 0.
        exit.
      endif.

      replace all occurrences of cl_abap_char_utilities=>cr_lf(1in wa with space.

      concatenate wa ';' w_flname into wa.
      append wa to itab.
    enddo.

    close dataset p_file.

Monday, 29 January 2024

IW32 - Change user and system Status - Using BAPI

 




datait_status type table of jstat,
        wa_status type jstat.

*Teco Complete
  refresh lt_methods.
  clear ls_methods.

  ls_methods-refnumber  1.                   "Reference number
  ls_methods-method     'TECHNICALCOMPLETE'"Method
  ls_methods-objecttype 'HEADER'.        "Object type
  ls_methods-objectkey  =  g_aufnr.
  append  ls_methods to lt_methods..

  clear ls_methods.
  ls_methods-refnumber  1.                  " <--- This has changed
  ls_methods-method     'SAVE'.               "Method
  ls_methods-objectkey  g_aufnr.
  append  ls_methods to lt_methods.

  refresh lt_header[].
  clear ls_header.

  ls_header-orderid    g_aufnr.
  ls_header-order_type g_ord_type.
  ls_header-planplant  '2000'.
  ls_header-bus_area   g_bus_area.
  ls_header-mn_wk_ctr  g_wrkctr.
  append ls_header to lt_header.


  refresh  lt_return[].
  call function 'BAPI_ALM_ORDER_MAINTAIN'
    tables
      it_methods lt_methods
      it_header  lt_header
      return     lt_return.

  call function 'BAPI_TRANSACTION_COMMIT'
    exporting
      wait 'X'.

  wait up to seconds.

********************************************************************
*  Bloc.
  clear objnr.
  concatenate 'OR' g_aufnr into objnr.

  clear wa_status.
  refresh it_status.
  wa_status-stat =  'E0018'.
  wa_status-inact 'X'.
  append wa_status to it_status.

  wa_status-stat =  'E0021'.
  wa_status-inact 'X'.
  append wa_status to it_status.

  wa_status-stat =  'E0020'.
  wa_status-inact ''.
  append wa_status to it_status.


  loop at it_status into wa_status.
    call function 'STATUS_CHANGE_EXTERN'
     exporting
      client                    sy-mandt
      objnr                     objnr
      user_status               wa_status-stat
      set_inact                 wa_status-inact
    importing
      stonr                     t_stone
* EXCEPTIONS
*   OBJECT_NOT_FOUND          = 1
*   STATUS_INCONSISTENT       = 2
*   STATUS_NOT_ALLOWED        = 3
*   OTHERS                    = 4
    .
  endloop.

  call function 'BAPI_TRANSACTION_COMMIT'
    exporting
      wait 'X'.

  wait up to seconds.








Visitor

Code Syntax Try...Endtry

  Code : Report Try. Parameters  NUMBER  type  I . data  RESULT  type  P  decimals  2 . data  OREF  type  ref  to  CX_ROOT . data  TEXT  typ...