Skip to end of metadata
Go to start of metadata


Applies to:

ABAP Report.

Summary

A sample ABAP Report for reading an SAP Offline Adobe form from SAP Inbox and update the content into SAP.

Created a Sample Customer Function Module to create Notification and Service Order. Below code is to read the Offline PDF from SAP Inbox and pass the date to the Custom FM to create the Notification and Servce Order.

    
Author:          Amarnath S
Company:     ZYLOG SYSTEMS LTD
Created on:    30.07.2010

//This is a code sample block


*Initialization.
DATA: user_data TYPE soudatai1.
DATA: folder_content TYPE STANDARD TABLE OF sofolenti1,wa_folder_content LIKE sofolenti1.
DATA: attachment_list TYPE STANDARD TABLE OF soattlsti1 WITH HEADER LINE,wa_attachment_list LIKE soattlsti1.
DATA: contents_hex TYPE STANDARD TABLE OF solix.
DATA: buffer TYPE xstring.
DATA: lo_pdfobj TYPE REF TO if_fp_pdf_object VALUE IS INITIAL, exc TYPE REF TO cx_root, xslt_message TYPE string.
DATA: input_length TYPE i.
DATA: RETURN_MSG TYPE STANDARD TABLE OF ZXNOTIF_SO_CREATE WITH HEADER LINE.
 
*This fm will read the folder details in the sap inbox for the particular user id.
CALL FUNCTION 'SO_USER_READ_API1'
 EXPORTING
   prepare_for_folder_access       = 'X'
 IMPORTING
   user_data                                  = user_data
 EXCEPTIONS
   user_not_exist                          = 1
   parameter_error                       = 2
   x_error                                      = 3
   OTHERS                                    = 4          .
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

*This fm will read the folder content present in the sap inbox folder.
CALL FUNCTION 'SO_FOLDER_READ_API1'
  EXPORTING
    folder_id                              = user_data-inboxfol
  TABLES
    folder_content                     = folder_content
 EXCEPTIONS
   folder_not_exist                    = 1
   operation_no_authorization  = 2
   x_error                                  = 3
   OTHERS                                = 4          .
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

CLEAR wa_folder_content.
SORT folder_content BY OBJ_NAME obj_descr creat_date creat_time.

READ TABLE folder_content INTO wa_folder_content WITH KEY obj_descr = 'Notification Service Order Creation Form'.

IF NOT wa_folder_content IS INITIAL.

*This fm will read the attachment present in the mail.
CALL FUNCTION 'SO_DOCUMENT_READ_API1'
  EXPORTING
    document_id                     = wa_folder_content-doc_id
 TABLES
    attachment_list                 = attachment_list
 EXCEPTIONS
   document_id_not_exist      = 1
   operation_no_authorization= 2
   x_error                                = 3
   OTHERS                               = 4          .
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
 
*Passing the length of the attachment to a variable
input_length = attachment_list-att_size.

*This fm will read the attachment and will give in the binary format.
CALL FUNCTION 'SO_ATTACHMENT_READ_API1'
  EXPORTING
    attachment_id                    = attachment_list-attach_id
 TABLES
   contents_hex                      = contents_hex
 EXCEPTIONS
   attachment_not_exist             = 1
   operation_no_authorization    = 2
   parameter_error                      = 3
   x_error                                     = 4
   enqueue_error                         = 5
   OTHERS                                    = 6          .
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

*This fm will convert the binary format to xstring format.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
  EXPORTING
    input_length       = input_length
 IMPORTING
   buffer                 = buffer
  TABLES
    binary_tab         = contents_hex
 EXCEPTIONS
   failed                  = 1
   OTHERS             = 2          .
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

*Subroutine to get the PDF Instance
PERFORM get_pdf_instantiate .
 
*Subroutine to Extract the PDF data and update the same into SAP
PERFORM extract_data.

ENDIF.
&---------------------------------------------------------------------
*&      Form  GET_PDF_INSTANTIATE
&---------------------------------------------------------------------
*       text
----------------------------------------------------------------------
*  -->  p1        text
*  <--  p2        text
----------------------------------------------------------------------
FORM get_pdf_instantiate .
  DATA: lo_fp TYPE REF TO if_fp VALUE IS INITIAL.
  lo_fp = cl_fp=>get_reference( ).
* For handling exceptions
  DATA: lo_fpex TYPE REF TO cx_fp_runtime VALUE IS INITIAL.
  TRY.
      lo_pdfobj = lo_fp->create_pdf_object( connection = 'ADS' ).
*   Set document
      lo_pdfobj->set_document(
        EXPORTING
          pdfdata = buffer ).
*   Tell PDF object to extract data
      lo_pdfobj->set_extractdata( ).
*   Execute the call to ADS
      lo_pdfobj->execute( ).
    CATCH cx_fp_runtime_system INTO exc.
      xslt_message = exc->get_text( ).
  ENDTRY.

ENDFORM.                    " GET_PDF_INSTANTIATE
&---------------------------------------------------------------------
*&      Form  EXTRACT_DATA
&---------------------------------------------------------------------
*       text
----------------------------------------------------------------------
*  -->  p1        text
*  <--  p2        text
----------------------------------------------------------------------
FORM extract_data .

  DATA: xml_data TYPE xstring,
             t_return TYPE STANDARD TABLE OF bapiret2,
             t_per_info TYPE STANDARD TABLE OF smum_xmltb,
             lfs_per_info TYPE smum_xmltb.

  lo_pdfobj->get_data(
  IMPORTING
  formdata = xml_data ).

*this fm is for Parse XML docment into a table structure
  CALL FUNCTION 'SMUM_XML_PARSE'
    EXPORTING
      xml_input = xml_data
    TABLES
      xml_table = t_per_info
      return      = t_return.

  DATA: notif_data        TYPE STANDARD TABLE OF zxnotif_data_tmp,
        wa_notif_data     LIKE zxnotif_data_tmp,
        znotitem_text_tmp TYPE STANDARD TABLE OF znotitem_text_tmp,
        wa_item_text      TYPE znotitem_text_tmp,
        zxnotif_ltxt_tmp  TYPE STANDARD TABLE OF zxnotif_ltxt_tmp,
        wa_notif_ltxt     TYPE zxnotif_ltxt_tmp,
        zxorder_tmp       TYPE STANDARD TABLE OF zxorder_tmp,
        wa_order          TYPE zxorder_tmp,
        RETURN_MESSAGE    TYPE CHAR75.

LOOP AT t_per_info INTO lfs_per_info WHERE CNAME = 'PO_NUMBER'.
  IF lfs_per_info-cvalue IS NOT INITIAL.
    wa_notif_data-po_number = lfs_per_info-cvalue.
    wa_item_text-po_number = lfs_per_info-cvalue.
    wa_notif_ltxt-po_number = lfs_per_info-cvalue.
    wa_order-po_number = lfs_per_info-cvalue.
  ENDIF.
ENDLOOP.
  CLEAR lfs_per_info.

  READ TABLE t_per_info INTO lfs_per_info WITH KEY cname = 'NOTIF_TYPE'.
  wa_notif_data-notif_type = lfs_per_info-cvalue.
  CLEAR lfs_per_info.

  READ TABLE t_per_info INTO lfs_per_info WITH KEY cname = 'CONTACT_NUMBER'.
  wa_notif_data-contact_number = lfs_per_info-cvalue.
  IF lfs_per_info-cvalue IS INITIAL.
    wa_notif_data-contact_number = '0000000000'.
  ENDIF.
  CLEAR lfs_per_info.

  READ TABLE t_per_info INTO lfs_per_info WITH KEY cname = 'EQUNR'."'EQUIPMENT'.
  wa_notif_data-equipment = lfs_per_info-cvalue.
  IF lfs_per_info-cvalue IS INITIAL.
    wa_notif_data-equipment = '0000000000'.
  ENDIF.
  CLEAR lfs_per_info.

  READ TABLE t_per_info INTO lfs_per_info WITH KEY cname = 'SHORT_TEXT'.
  wa_notif_data-short_text = lfs_per_info-cvalue.
  IF lfs_per_info-cvalue IS INITIAL.
    wa_notif_data-short_text = ''.
  ENDIF.
  CLEAR lfs_per_info.

  READ TABLE t_per_info INTO lfs_per_info WITH KEY cname = 'PRIORITY'.
  wa_notif_data-priority = lfs_per_info-cvalue.
  IF lfs_per_info-cvalue IS INITIAL.
    wa_notif_data-priority = ''.
  ENDIF.
  CLEAR lfs_per_info.

  READ TABLE t_per_info INTO lfs_per_info WITH KEY cname = 'REQ_ST_DT'.
  IF lfs_per_info-cvalue IS NOT INITIAL.
    CONCATENATE lfs_per_info-cvalue+0(4) lfs_per_info-cvalue+5(2) lfs_per_info-cvalue+8(2)   
                     INTO wa_notif_data-req_st_dt.
  ELSE.
    wa_notif_data-req_st_dt = ''.
  ENDIF.
  CLEAR lfs_per_info.

  READ TABLE t_per_info INTO lfs_per_info WITH KEY cname = 'REQ_ST_TM'.
  IF lfs_per_info-cvalue IS NOT INITIAL.
  CONCATENATE lfs_per_info-cvalue+0(2) lfs_per_info-cvalue+3(2) lfs_per_info-cvalue+6(2) 
                  INTO wa_notif_data-req_st_tm.
  ENDIF.
  CLEAR lfs_per_info.

  READ TABLE t_per_info INTO lfs_per_info WITH KEY cname = 'REQ_END_DT'.
  IF lfs_per_info-cvalue IS NOT INITIAL.
    CONCATENATE lfs_per_info-cvalue+0(4) lfs_per_info-cvalue+5(2) lfs_per_info-cvalue+8(2)
                    INTO   wa_notif_data-req_end_dt.
  ELSE.
    wa_notif_data-req_end_dt = ''.
  ENDIF.
  CLEAR lfs_per_info.

  READ TABLE t_per_info INTO lfs_per_info WITH KEY cname = 'REQ_END_TM'.
  IF lfs_per_info-cvalue IS NOT INITIAL.
      CONCATENATE lfs_per_info-cvalue+0(2) lfs_per_info-cvalue+3(2) lfs_per_info-cvalue+6(2)
                      INTO wa_notif_data-req_end_tm.
  ENDIF.
  CLEAR lfs_per_info.

  READ TABLE t_per_info INTO lfs_per_info WITH KEY cname = 'STRMLFNDATE'.
  IF lfs_per_info-cvalue IS NOT INITIAL.
    CONCATENATE lfs_per_info-cvalue+0(4) lfs_per_info-cvalue+5(2) lfs_per_info-cvalue+8(2) 
                     INTO wa_notif_data-strmlfndate.
  ELSE.
    wa_notif_data-strmlfndate = ''.
  ENDIF.
  CLEAR lfs_per_info.

  READ TABLE t_per_info INTO lfs_per_info WITH KEY cname = 'STRMLFNTIME'.
  IF lfs_per_info-cvalue IS NOT INITIAL.
    CONCATENATE lfs_per_info-cvalue+0(2) lfs_per_info-cvalue+3(2) lfs_per_info-cvalue+6(2)
                     INTO wa_notif_data-strmlfntime.
  ENDIF.
  CLEAR lfs_per_info.

  READ TABLE t_per_info INTO lfs_per_info WITH KEY cname = 'REPORTED_BY'.

  wa_notif_data-reported_by = lfs_per_info-cvalue.
  IF lfs_per_info-cvalue IS INITIAL.
    wa_notif_data-reported_by = ''.
  ENDIF.
  CLEAR lfs_per_info.

  READ TABLE t_per_info INTO lfs_per_info WITH KEY cname = 'NOTIF_DATE'.
  IF lfs_per_info-cvalue IS NOT INITIAL.
    CONCATENATE lfs_per_info-cvalue+0(4) lfs_per_info-cvalue+5(2) lfs_per_info-cvalue+8(2)
                     INTO wa_notif_data-notif_date.
  ELSE.
    wa_notif_data-notif_date = ''.
  ENDIF.
  CLEAR lfs_per_info.

  READ TABLE t_per_info INTO lfs_per_info WITH KEY cname = 'NOTIFTIME'.
  IF lfs_per_info-cvalue IS NOT INITIAL.
    CONCATENATE lfs_per_info-cvalue+0(2) lfs_per_info-cvalue+3(2) lfs_per_info-cvalue+6(2)
                    INTO wa_notif_data-notiftime  .
  ENDIF.
  CLEAR lfs_per_info.

  wa_notif_data-user_status     = 'X'.

  READ TABLE t_per_info INTO lfs_per_info WITH KEY cname = 'ITEM_TEXT'.
  wa_item_text-item_text = lfs_per_info-cvalue.
  IF lfs_per_info-cvalue IS INITIAL.
    wa_item_text-item_text = ''.
  ENDIF.
  CLEAR lfs_per_info.

  READ TABLE t_per_info INTO lfs_per_info WITH KEY cname = 'TEXT_LINE'.
  wa_notif_ltxt-text_line = lfs_per_info-cvalue.
  IF lfs_per_info-cvalue IS INITIAL.
    wa_notif_ltxt-text_line = ''.
  ENDIF.
  CLEAR lfs_per_info.

  READ TABLE t_per_info INTO lfs_per_info WITH KEY cname = 'AUFART'."'ORDER_TYPE'.
  wa_order-order_type = lfs_per_info-cvalue.
  IF lfs_per_info-cvalue IS INITIAL.
    wa_order-order_type = ''.
  ENDIF.
  CLEAR lfs_per_info.

  READ TABLE t_per_info INTO lfs_per_info WITH KEY cname = 'MATKL'."'MATERIAL GROUP'.
  wa_order-MATERIAL_GROUP = lfs_per_info-cvalue.
  IF lfs_per_info-cvalue IS INITIAL.
    wa_order-MATERIAL_GROUP = '01'.
  ENDIF.
  CLEAR lfs_per_info.

  READ TABLE t_per_info INTO lfs_per_info WITH KEY cname = 'MAIN_WORK_CENTER'.
  wa_order-main_work_center = lfs_per_info-cvalue.
  IF lfs_per_info-cvalue IS INITIAL.
    wa_order-main_work_center = ''.
  ENDIF.
  CLEAR lfs_per_info.

  wa_order-status_with_num = 'RDCO'.

  APPEND wa_notif_data TO notif_data.
  APPEND wa_item_text  TO znotitem_text_tmp.
  APPEND wa_notif_ltxt   TO zxnotif_ltxt_tmp.
  APPEND wa_order         TO zxorder_tmp.

*Custom FM to create Notification and Service Order
CALL FUNCTION 'Z_X_NOTIFICATION_SORDER_CREATE'
 IMPORTING
   RETURN_MESSAGE       = RETURN_MESSAGE
  TABLES
    notif_data1                 = notif_data
    notitem_text               = znotitem_text_tmp
    NOTIF_LTXT                = zxnotif_ltxt_tmp
    it_order                       = zxorder_tmp
   RETURN_MSG              = RETURN_MSG          .

  READ TABLE return_msg WITH KEY mtyp_notif = 'E'.
  IF sy-subrc EQ 0.
    doc_chng-obj_descr = '*Error in Notification Creation*'.
  ENDIF.

  READ TABLE return_msg WITH KEY mtyp_notif = 'S'.
  IF sy-subrc EQ 0.
    doc_chng-obj_descr = 'Successfully Notification No. has been Created'.
  ENDIF.

Related Content