Friday 20 June 2014

3.BAPI- Difference Between Non Dialog & Dialog BAPI with example.

Dialog BAPIs usually calls the Screen where the user is required and it can not be executed in background where as with Non Dialog BAPIs can be called in Background mode without any User intervention. The below post shows the difference between the two types.

--------------------------------------------------------------------------------------------------------------
Step1.  Go to Tx- SWO1 & open the BO- BUS2032 Sales order. The two methods creates the Sales Order but one  without dialog mode and other is with dialog mode.













Step2. The associated FMs with the BAPI Methods.












Step3. Create the below report which created the Sales Order By Non Dialog BAPI FM call.
_________________________________________________________________________________

PARAMETERS : p_no_so TYPE int4.

DATA :  ls_ord_hdr     TYPE bapisdhd1,
               ls_ord_hdrx   TYPE bapisdhd1x,
               so_num           TYPE bapivbeln-vbeln,
               lt_so_num       LIKE TABLE OF so_num,
               lt_ret              TYPE TABLE OF bapiret2,
               lt_item           TYPE TABLE OF bapisditm,
               ls_item           TYPE bapisditm,
               lt_itemx         TYPE TABLE OF bapisditmx,
               ls_itemx        TYPE bapisditmx,
               lt_part            TYPE TABLE OF bapiparnr,
               ls_part            TYPE  bapiparnr,
               lt_schd           TYPE TABLE OF bapischdl ,
               ls_schd          TYPE bapischdl,
               lt_schdx         TYPE TABLE OF  bapischdlx,
               ls_schdx         TYPE bapischdlx.

START-OF-SELECTION.

******* Fill the Sales Order Header ****************
  ls_ord_hdr-doc_type  = 'TA'. " ORDER Type : OR->TA as per TVAK table
  ls_ord_hdr-sales_org  = 'AB99'.
  ls_ord_hdr-distr_chan  = 'WS'.
  ls_ord_hdr-division  = 'LT'.
  ls_ord_hdr-purch_no_c  = 'ORDER_100'.

  ls_ord_hdrx-updateflag = 'X'.
  ls_ord_hdrx-doc_type ='X'.
  ls_ord_hdrx-sales_org = 'X'.
  ls_ord_hdrx-distr_chan = 'X'.
  ls_ord_hdrx-division = 'X'.
  ls_ord_hdrx-purch_no_c = 'X'.
*********FILL PARTNERS TABLE  ******************
  ls_part-partn_role = 'AG'.  " SOLD TO PARTY
  ls_part-partn_numb = '0000099994'.
  APPEND ls_part TO lt_part.
  CLEAR ls_part.


  ls_part-partn_role = 'RE'.  " BILL TO PARTY
  ls_part-partn_numb = '0000099996'.
  APPEND ls_part TO lt_part.
  CLEAR ls_part.


  ls_part-partn_role = 'RG'.  " PAYER
  ls_part-partn_numb = '0000099997'.
  APPEND ls_part TO lt_part.
  CLEAR ls_part.

  ls_part-partn_role = 'WE'.  " SHIP TO PARTY
  ls_part-partn_numb = '0000099995'.
  APPEND ls_part TO lt_part.
  CLEAR ls_part.

*********FILL ITEMS ***********************
  ls_item-itm_number = '10'.
  ls_item-material = '000000000000001278'.
  ls_item-plant = 'PLBN'.
  ls_item-target_qty = '10'.
  ls_item-target_qu = 'EA'.
  APPEND ls_item TO lt_item.
  CLEAR : ls_item.

  ls_itemx-itm_number = '10'.
  ls_itemx-material = 'X'.
  ls_itemx-plant = 'X'.
  ls_itemx-target_qty = 'X'.
  ls_itemx-target_qu = 'X'.
  APPEND ls_itemx  TO lt_itemx.
  CLEAR : ls_itemx.
******* SCHEDULE LINE *********************

  ls_schd-itm_number = '10'.
  ls_schd-req_qty = '10'.
  APPEND ls_schd TO lt_schd.
  CLEAR ls_schd.


  ls_schdx-itm_number = '10'.
  ls_schdx-req_qty = 'X'.
  ls_schdx-updateflag = 'X'.
  APPEND ls_schdx TO lt_schdx.
  CLEAR ls_schdx.

  IF p_no_so > 0.
    DO p_no_so TIMES.
      CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
        EXPORTING
          order_header_in     = ls_ord_hdr
          order_header_inx    = ls_ord_hdrx
        IMPORTING
          salesdocument       = so_num
        TABLES
          return              = lt_ret
          order_items_in      = lt_item
          order_items_inx     = lt_itemx
          order_partners      = lt_part
          order_schedules_in  = lt_schd
          order_schedules_inx = lt_schdx.
      IF sy-subrc = 0.
        APPEND so_num TO lt_so_num.
        CLEAR so_num.
        COMMIT WORK.
      ENDIF.
    ENDDO.
  ENDIF.

END-OF-SELECTION.
  IF lt_so_num IS NOT INITIAL.
    LOOP AT lt_so_num INTO so_num.
      WRITE :/ 'Sales Order Generated By BAPI call-', sy-tabix , ':', so_num.
    ENDLOOP.
  ENDIF.

________________________________________________________________________________

Step4. Create the below report which created the Sales Order By Dialog BAPI FM call.
_________________________________________________________________________________

PARAMETERS : p_no_so TYPE int4.

DATA :  ls_ord_hdr      TYPE bapisdhead1,
               ls_ord_hdrx    TYPE bapisdhead1x,
               so_num           TYPE bapivbeln-vbeln,
               lt_so_num       LIKE TABLE OF so_num,
               lt_ret               TYPE TABLE OF bapiret2,
               lt_item            TYPE TABLE OF bapisditem,
               ls_item           TYPE bapisditem,
               lt_itemx          TYPE TABLE OF bapisditmx,
               ls_itemx         TYPE bapisditmx,
                lt_part           TYPE TABLE OF bapipartnr,
               ls_part           TYPE  bapipartnr,
                lt_schd          TYPE TABLE OF bapischedule,
               ls_schd          TYPE bapischedule,
               lt_schdx        TYPE TABLE OF  bapischedulex,
                ls_schdx       TYPE bapischedulex.

START-OF-SELECTION.

******* Fill the Sales Order Header ****************
  ls_ord_hdr-doc_type  = 'TA'. " ORDER Type : OR->TA as per TVAK table
  ls_ord_hdr-sales_org  = 'AB99'.
  ls_ord_hdr-distr_chan  = 'WS'.
  ls_ord_hdr-division  = 'LT'.
  ls_ord_hdr-purch_no_c  = 'ORDER_100'.

  ls_ord_hdrx-doc_type ='X'.
  ls_ord_hdrx-sales_org = 'X'.
  ls_ord_hdrx-distr_chan = 'X'.
  ls_ord_hdrx-division = 'X'.
  ls_ord_hdrx-purch_no_c = 'X'.
*********FILL PARTNERS TABLE  ******************
  ls_part-partn_role = 'AG'.  " SOLD TO PARTY
  ls_part-partn_numb = '0000099994'.
  APPEND ls_part TO lt_part.
  CLEAR ls_part.


  ls_part-partn_role = 'RE'.  " BILL TO PARTY
  ls_part-partn_numb = '0000099996'.
  APPEND ls_part TO lt_part.
  CLEAR ls_part.


  ls_part-partn_role = 'RG'.  " PAYER
  ls_part-partn_numb = '0000099997'.
  APPEND ls_part TO lt_part.
  CLEAR ls_part.

  ls_part-partn_role = 'WE'.  " SHIP TO PARTY
  ls_part-partn_numb = '0000099995'.
  APPEND ls_part TO lt_part.
  CLEAR ls_part.

*********FILL ITEMS ***********************
  ls_item-itm_number = '10'.
  ls_item-material = '000000000000001248'.
  ls_item-plant = 'PLBN'.
  ls_item-target_qty = '10'.
  ls_item-target_qu = 'EA'.
  APPEND ls_item TO lt_item.
  CLEAR : ls_item.

  ls_itemx-itm_number = '10'.
  ls_itemx-material = 'X'.
  ls_itemx-plant = 'X'.
  ls_itemx-target_qty = 'X'.
  ls_itemx-target_qu = 'X'.
  APPEND ls_itemx  TO lt_itemx.
  CLEAR : ls_itemx.
******* SCHEDULE LINE *********************

  ls_schd-itm_number = '10'.
  ls_schd-req_qty = '10'.
  APPEND ls_schd TO lt_schd.
  CLEAR ls_schd.


  ls_schdx-itm_number = '10'.
  ls_schdx-req_qty = 'X'.
  ls_schdx-updateflag = 'X'.
  APPEND ls_schdx TO lt_schdx.
  CLEAR ls_schdx.

  IF p_no_so > 0.
    DO p_no_so TIMES.

      CALL FUNCTION 'BAPI_SALESDOCU_CREATEWITHDIA' " Calls VA01 Transaction
        EXPORTING
          sales_header_in               = ls_ord_hdr
          sales_header_inx              = ls_ord_hdrx
     IMPORTING
      SALESDOCUMENT_EX              = so_num
       TABLES
         return                        = lt_ret
         sales_items_in                = lt_item
         sales_items_inx               = lt_itemx
         sales_partners                = lt_part
         sales_schedules_in            = lt_schd
         sales_schedules_inx           = lt_schdx.

      IF sy-subrc = 0.
        APPEND so_num TO lt_so_num.
        CLEAR so_num.
        COMMIT WORK.
      ENDIF.
    ENDDO.
  ENDIF.

END-OF-SELECTION.
  IF lt_so_num IS NOT INITIAL.
    LOOP AT lt_so_num INTO so_num.
      WRITE :/ 'Sales Order Generated By BAPI call-', sy-tabix , ':', so_num.
    ENDLOOP.
  ENDIF.


_________________________________________________________________________________

Step5. Execute both the report and see the output.










Step6. The first one directly creates the Sales Order  & the other Dialog BAPI calls the transaction VA01 and waits for the user action like Save or modifying something in the Screen.







Step7.














Step8. When it is saved the Sales order number is generated.














------------------------------------xxxx--------------------xxxx--------------------xxxx------------------


No comments:

Comments system

Disqus Shortname