Wednesday, August 29, 2018

Some ATP related tables in ECC

TABLES:
  afko,            " Order header data PP orders
  afpo,            " Order item data PP orders
  atpsb,           " ATP: Shared Buffer
  atp_eban,        " Purchase Requisition
  atp_ebub,        " Stock Transfer Purchase Requisition
  atp_ekes,        " Purchase Order Shipping Notification
  atp_eket,        " Purchase Order Schedule Lines
  atp_ekub,        " Stock Transfer Purchase Order
  atp_plpw,        " Stock Transfer Planned Order
  atp_resb,        " Reservation/dependent Requirements
  atp_vbbe,        " Sales Requirements: Individual Records
  ebkn,            " Purchase Requisition Account Assignment
  ekkn,            " Account Assignment in Purchasing Document
  mard,            " Material Master: Storage Location/Batch Segment
  mdqm,            " MRP View of the QM Inspection Lot
  mdur,            " Reading View of Stock Transfer Reservations
  mska,            " Sales Order Stocks
  msku,            " Special Stocks with Customer
  mspr,            " Project Stock
  mssa,            " Sales Order Stocks Totals
  mssl,            " Total Special Stocks with Vendor
  mssq,            " Project Stock Total
  resb,            " Reservations Table/Dependant Requirements
  vbbs.            " Sales Requirement Totals Record
* DI A&D Modification Subcontracting
TABLES:
  mcsd,            " Customer Stocks                          "RZ1045755
  mcss,            " Total Customer Stocks                    "RZ1045755
* DI A&D Modification Subcontracting
  msfd,            " Sales Order Stocks Subcontracting        "RZ1045755
  mscs,            " Customer Stocks Subcontracting           "RZ1045755
  msrd,            " Project Stock Subcontracting             "RZ1045755
  msfs,            " Sales Order Stocks Totals Subcontracting "RZ1045755
  mscd,            " Total Customer Stocks Subcontracting     "RZ1045755
  msrs.            " Project Stock Total Subcontracting       "RZ1045755

SAP ATP AVAILABILITY CHECK - USER EXITS


Function Module:  RV_AVAILABLITY_CHECK is where the ATP process kicks-in.

User Exits are available in include :  RV03VFZZ

Read Notes:
1644443 - Documentation on User-Exits in the area of the availability check

The following user-exits are available:
  • User-Exits in the include RV03VFZZ (called in Form MVERF_PRUEFEN)
  • User-Exits of the enhancement ATP00001 (called in Function Module AVAILABILITY_CHECK_CONTROLLER
See transaction CO09

Checking Rule: OVZ9


***INCLUDE LV03VFZZ .
************************************************************************
*                                                                      *
* This include is reserved for user modifications                      *
*                                                                      *
* Forms for availability check                                         *
*                                                                      *
* The name of modification modules should begin with 'ZZ'.             *
*                                                                      *
************************************************************************

*---------------------------------------------------------------------*
*       FORM ZZEXAMPLE                                                *
*---------------------------------------------------------------------*
*       text......................................                    *
*---------------------------------------------------------------------*
*FORM ZZEXAMPLE.

*  ...

*ENDFORM.
*eject

*---------------------------------------------------------------------*
*       FORM USEREXIT_AVAILABILITY_IN                                 *
*---------------------------------------------------------------------*
*       This userexit may be used to influence the availability       *
*       check which is carried out after this program                 *
*                                                                     *
*       This form is called from routine MVERF_PRUEFEN in LV03VF0M    *
*                                                                     *
*---------------------------------------------------------------------*
*       --> US_ATPPR: ATP or forecast check (if blank)                *
*---------------------------------------------------------------------*
FORM USEREXIT_AVAILABILITY_IN USING VALUE(US_ATPPR).

* Add your statements below


ENDFORM.
*eject

*---------------------------------------------------------------------*
*       FORM USEREXIT_AVAILABILITY_OUT                                *
*---------------------------------------------------------------------*
*       This userexit may be used to influence the results of the     *
*       availability which was carried out before this program was    *
*       called                                                        *
*                                                                     *
*       This form is called from routine MVERF_PRUEFEN in LV03VF0M    *
*                                                                     *
*---------------------------------------------------------------------*
*       --> US_ATPPR: ATP or forecast check (if blank)                *
*---------------------------------------------------------------------*
FORM USEREXIT_AVAILABILITY_OUT USING VALUE(US_ATPPR).

* Add your statements below


ENDFORM.
*eject

*---------------------------------------------------------------------*
*       FORM USEREXIT_DATA_REFRESH                                    *
*---------------------------------------------------------------------*
*       This userexit may be used to initialize global data which     *
*       are declared in LV03VTZZ.                                     *
*                                                                     *
*       This form is called from routine BEDARF_INITIALISIEREN in     *
*       LV03VF0B                                                      *
*---------------------------------------------------------------------*
FORM USEREXIT_DATA_REFRESH.

* Add your statements below


ENDFORM.
*eject
*---------------------------------------------------------------------*
*       FORM USEREXIT_PLANT_SELECTION                                 *
*---------------------------------------------------------------------*
*       This userexit may be used to provide a list of plants for     *
*       which availability is to be checked.                          *
*                                                                     *
*      This form is called from routine WERKE_ERMITTELN in LV03VF0W   *
*                                                                     *
*---------------------------------------------------------------------*
FORM USEREXIT_PLANT_SELECTION.

* Allowed plants in sales area
  LOOP AT PLANTS WHERE NOT EXISTS IS INITIAL.

* Place in here the logic to select from the allowed plants, if a
* selection is desired set field PLANTS-SELKZ to X

  ENDLOOP.

ENDFORM.
*eject

**************************************************
Global DATA

 MDVEX : Availability check result, structure 
 MDVPS:  Structure for simulated requirements
 MDVPK: Corrected Requirements
 XVBBD:  Indiv/Collective Requirements



Monday, August 20, 2018

SAP FI: DEBUG DME FILE GENERATION


Use program SAPFPAYM_SCHEDULE  and provide Run ID , Run Identifier and execute.

OR USE PROGRAM

SAPFPAYM if you would like to run the DMEE using changed parameters

Tuesday, August 14, 2018

ALV FCAT EXAMPLE

  CLEAR ls_fcat.
  ls_fcat-fieldname 'PRODH-PRODH1'.
  ls_fcat-seltext_s ls_fcat-seltext_m ls_fcat-seltext_l 'Business Segment Code'.
  APPEND ls_fcat TO gt_fcat.

  CLEAR ls_fcat.
  ls_fcat-fieldname 'PRODH-PRODH2'.
  ls_fcat-seltext_s ls_fcat-seltext_m ls_fcat-seltext_l 'Brand Code'.
  APPEND ls_fcat TO gt_fcat.

  CLEAR ls_fcat.
  ls_fcat-fieldname 'MATKL'.
  ls_fcat-ref_tabname 'VBRP'.
  ls_fcat-ref_fieldname 'MATKL'.
  APPEND ls_fcat TO gt_fcat.




  DATA ls_layout TYPE slis_layout_alv.
  ls_layout-colwidth_optimize 'X'.

  DATA ls_variant TYPE disvariant.
  ls_variant-report sy-repid.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      is_layout     ls_layout
      i_save        'A'
      is_variant    ls_variant
      it_fieldcat   gt_fcat
    TABLES
      t_outtab      gt_out
    EXCEPTIONS
      program_error 1
      OTHERS        2.
  IF sy-subrc <> 0.
* Implement
  ENDIF.

ABAP GUIDS



  DATA lv_guid TYPE sysuuid_c22.



  TRY.
      CALL METHOD cl_system_uuid=>if_system_uuid_static~create_uuid_c22
        RECEIVING
          uuid lv_guid.
      .
    CATCH cx_uuid_error .
      .
  ENDTRY.

ABAP EXCEL OLE


  CREATE OBJECT lv_application 'Excel.Application'
 CALL METHOD OF
      lv_application
      'Workbooks'    lv_workbook

CALL METHOD OF
      lv_workbook
      'Open'
   
    EXPORTING
      #1          lv_filename.


  GET PROPERTY OF lv_application 'ACTIVESHEET' lv_worksheet
                NO FLUSH.


  CALL METHOD OF
      lv_worksheet
      'Cells'      lv_cell
      NO
      FLUSH

    EXPORTING
      #1           lv_start_row
      #2           lv_start_col.

Monday, August 13, 2018

Launch Outlook from SAP / ABAP



If you want to launch Outlook for your users with a pre-drafted email, please see the links below


http://helponabap.blogspot.com/2017/06/how-to-open-outlook-mail-from-abap.html

https://abapblog.com/articles/tricks/19-save-message-with-attachment-in-outlook-s-drafts


Some useful OLE commands

call method of fo_appitem 'Save'. <----saves draft="" email="" folders="" in="" span="">
call method of fo_appitem 'Display'. <----launches email="" outlook="" span="" with="">



CDS View: Sales Volume By Year


@ClientHandling.algorithm: #SESSION_VARIABLE
@ObjectModel.usageType.dataClass: #MIXED
@ObjectModel.usageType.serviceQuality: #D
@ObjectModel.usageType.sizeCategory: #S
@AbapCatalog.sqlViewName: 'PSDSLSVOLBYYEAR'
@AccessControl.authorizationCheck: #NOT_REQUIRED
@VDM.private: true
@VDM.viewType: #COMPOSITE

define view P_SalesVolumebyYear
  as select from I_BillingDocItemAnalytics as Item
   
  left outer to one join I_CalendarDate as CalendarDateBillingDoc
    on Item.BillingDocumentDate = CalendarDateBillingDoc.CalendarDate
{
    @Semantics.calendar.year
    cast(CalendarDateBillingDoc.CalendarYear as billing_document_date_year) as BillingDocumentDateYear,
   
    @Semantics.systemDate.createdAt: true
    CreationDate,
   
    BillingDocumentType,
    SalesOrganization,
   
    BillingDocumentDate,
   
    @Semantics.currencyCode: true
    TransactionCurrency,
   
    @DefaultAggregation: #SUM
    @Semantics.amount.currencyCode: 'TransactionCurrency'
    sum(SalesVolumeNetAmount) as SalesVolumeNetAmount
}
where
      ReturnItemProcessingType   = ''
  and BillingDocumentIsCancelled = ''
group by
  CalendarYear,
  TransactionCurrency,
  CreationDate,
  BillingDocumentType,
  SalesOrganization,
  BillingDocumentDate                  
  


ODATA Attachment Get Contents

    CONSTANTS:
       lc_phio_class   TYPE sdok_class VALUE if_odata_cv_constants=>gc_soffphio .

    DATA:
      ls_message             TYPE bapiret2,
      ls_phio_object         TYPE sdokobject,
      lv_filesize            TYPE i,
      lt_file_access_info    TYPE STANDARD TABLE OF sdokfilaci,
      ls_file_access_info    TYPE sdokfilaci,
      lt_file_content_binary TYPE STANDARD TABLE OF sdokcntbin.
    DATA lo_objhead  TYPE REF TO cl_bcs_objhead.
    DATA ls_document TYPE soodk.
    CLEARls_phio_objectet_messagesev_filenamees_media_stream.

    ls_phio_object-class lc_phio_class.
    ls_phio_object-objid iv_file_id.

    IF iv_file_id IS NOT INITIAL.

      CALL FUNCTION 'SDOK_PHIO_LOAD_CONTENT'
        EXPORTING
          object_id           ls_phio_object
          text_as_stream      'X'
          as_is_mode          'X'
          raw_mode            'X'
        TABLES
          file_access_info    lt_file_access_info
          file_content_binary lt_file_content_binary
        EXCEPTIONS
          not_existing        1
          not_authorized      2
          no_content          3
          bad_storage_type    4
          OTHERS              5.

      IF sy-subrc NE 0.
        RAISE EXCEPTION TYPE cx_odata_cv_attach_exception
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.

      READ TABLE lt_file_access_info INTO ls_file_access_info INDEX 1.
      IF sy-subrc EQ 0.
        lv_filesize         ls_file_access_info-file_size.
        es_media_stream-mime_type ls_file_access_info-mimetype.
        IF ev_filename IS REQUESTED.
          ls_document iv_docnum.
          lo_objhead cl_bcs_objhead=>create_by_oidls_document ).
          ev_filename lo_objhead->get_filename).
        ENDIF.

        CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
          EXPORTING
            input_length lv_filesize
          IMPORTING
            buffer       es_media_stream-value
          TABLES
            binary_tab   lt_file_content_binary
          EXCEPTIONS
            failed       1
            OTHERS       2.

        IF sy-subrc NE 0.
          CLEAR ls_message.
          ls_message-id if_odata_cv_constants=>gc_message_class.
          ls_message-type 'E'.
          ls_message-number '007'.           " An internal error occurred while processing binary content
          APPEND ls_message TO et_messages.
          RETURN.
        ENDIF.

      ENDIF.
    ENDIF.

Upload Attachment

    TYPESBEGIN OF t_binary,
             line(2550TYPE x,
           END OF t_binary.

    DATA:
      lv_size        TYPE i,
      lv_filename    TYPE filep,
      lt_binary      TYPE TABLE OF t_binary,
      ls_drao        TYPE drao,
      lt_drao        TYPE STANDARD TABLE OF drao,
      ls_loio_object TYPE sdokobject,
      ls_phio_object TYPE sdokobject,
      lt_bad_obj     TYPE TABLE OF sdokerrkey,
      lt_prop        TYPE STANDARD TABLE OF sdokpropty,
      ls_prop        TYPE sdokpropty,
      lt_components  TYPE sdokcomprps,
      ls_component   TYPE sdokcomprp,
      lt_messages    TYPE /plmb/t_spi_msg,
      lv_mimetype    TYPE w3conttype,
      lv_createdat   TYPE sdok_chtst,
      lx_cv_base     TYPE REF TO cx_odata_cv_base_exception.

    FIELD-SYMBOLS:
       TYPE t_binary.

    CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
      EXPORTING
        buffer        is_media_resource-value
      IMPORTING
        output_length lv_size
      TABLES
        binary_tab    lt_binary.

    LOOP AT lt_binary ASSIGNING .
      CLEAR ls_drao.
      ls_drao-orblk -line.
      ls_drao-orln  lv_size.
      APPEND ls_drao TO lt_drao.
    ENDLOOP.
    TRY.
        lv_filename iv_slug.
        lv_mimetype is_media_resource-mime_type.
        CALL METHOD cl_odata_cv_bo=>get_instance)->checkin_contents_from_table(
          EXPORTING
            iv_docfile     lv_filename
            it_drao        lt_drao
            iv_storage_cat iv_storage_cat
            iv_mimetype    lv_mimetype
          IMPORTING
            es_loio_object ls_loio_object
            es_phio_object ls_phio_object ).

*    IF lt_bapi_messages IS NOT INITIAL.
*      CALL METHOD cl_cv_attachment_dpc_ext=>raise_busi_exception
*        EXPORTING
*          it_messages          = lt_bapi_messages
*          io_message_container = io_message_container
*          iv_msg_type          = 'E'
*          iv_msg_id            = if_odata_cv_constants=>gc_message_class
*          iv_entity_type       = iv_entity_name
*          iv_message_target    = iv_slug.
*    ENDIF.

        CLEARes_original_content.
        es_original_content-application_id     ls_loio_object-objid.
        es_original_content-file_id            ls_phio_object-objid.
        es_original_content-filename           lv_filename.
        es_original_content-contenttype        is_media_resource-mime_type.
        es_original_content-attachmentstatus   if_odata_cv_constants=>gc_attachmentstatus.
        es_original_content-checkedinstatus    abap_true.
        es_original_content-source             if_odata_cv_constants=>gc_dms_object.

        CALL METHOD cl_odata_cv_bo=>get_instance)->get_sdok_loio_properties(
          EXPORTING
            is_object     ls_loio_object
          CHANGING
            ct_properties lt_prop ).

        LOOP AT lt_prop INTO ls_prop.
          CASE ls_prop-name.
            WHEN 'DMS_APPLICATION'.
              es_original_content-wsapplication ls_prop-value.
          ENDCASE.
        ENDLOOP.

        CLEAR lt_prop.

        CALL METHOD cl_odata_cv_bo=>get_instance)->get_sdok_phio_properties(
          EXPORTING
            is_object     ls_phio_object
          CHANGING
            ct_properties lt_prop ).

        LOOP AT lt_prop INTO ls_prop.
          CASE ls_prop-name.
            WHEN 'CREATED_AT'.
              CLEARlv_createdat.
              lv_createdat ls_prop-value.
              es_original_content-createdat lv_createdat.
            WHEN 'CREATED_BY'.
              es_original_content-createdby ls_prop-value.
          ENDCASE.
        ENDLOOP.

        CLEAR ls_component.

        ls_component-class ls_phio_object-class.
        ls_component-objid ls_phio_object-objid.
        APPEND ls_component TO lt_components.

        CALL METHOD cl_odata_cv_bo=>get_instance)->get_sdok_phios_file_properties(
          IMPORTING
            et_bad_objects lt_bad_obj
          CHANGING
            ct_components  lt_components ).

        CHECK lt_bad_obj IS INITIAL.
        READ TABLE lt_components INTO ls_component INDEX 1.
        IF sy-subrc 0.
          MOVE ls_component-file_size TO es_original_content-filesize.
        ENDIF.

* --- Get the user details via CDS view

        SELECT SINGLE name_text INTO es_original_content-fullname FROM v_usr_name       "#EHSM_SQL
        WHERE bname es_original_content-createdby.

      CATCH cx_odata_cv_attach_exception cx_odata_cv_db_exception INTO lx_cv_base.
        RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
          EXPORTING
            previous lx_cv_base.