Sunday, September 27, 2020

BAPI MATERIAL CREATE Example in SAP ABAP.

BAPI MATERIAL CREATE  Example in SAP ABAP.



BAPI_MATERIAL_SAVEDATA BAPI For material Create in SAP ABAP.

REPORT zbij_bapi_material.

*&---------------------------------------------------------------------*
*& INCLUES FOR ALL EVENTS                                              *
*&---------------------------------------------------------------------*
INCLUDE zbapi_mat_data_declaration.
INCLUDE zbapi_mat_data_selec_screen.
INCLUDE zbapi_mat_data_logic.

*&---------------------------------------------------------------------*
*& Start of Selection Event                                            *
*&---------------------------------------------------------------------*
START-OF-SELECTION.
  
PERFORM gui_upload.
  
PERFORM bapi.

 

TOP

*&---------------------------------------------------------------------*
*&  Include           ZBAPI_MAT_DATA_DECLARATION
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*& External Table Declaration                                          *
*&---------------------------------------------------------------------*
TABLES bapimatheadbapi_marabapi_maraxbapi_makt.

*&---------------------------------------------------------------------*
*& Internal Table Declaration                                          *
*&---------------------------------------------------------------------*
DATA BEGIN OF it_bapi OCCURS 0,
          material   
TYPE bapimathead-material,
          ind_sector 
TYPE bapimathead-ind_sector,
          matl_type  
TYPE bapimathead-matl_type,
          matl_group 
TYPE bapi_mara-matl_group,
          base_uom   
TYPE bapi_mara-base_uom,
          matl_desc  
TYPE bapi_makt-matl_desc,
        
END OF it_bapi,

       it_return 
LIKE bapiret2,
       it_makt_bapi 
like bapi_makt OCCURS WITH HEADER LINE.

 

SELECTION SCREEN

*&---------------------------------------------------------------------*
*&  Include           ZBAPI_MAT_DATA_SELEC_SCREEN
*&---------------------------------------------------------------------*

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
"IBIPPARMS-PATH is a export structure of f4 help fm.
*PARAMETERS : p_file TYPE ibipparms-path OBLIGATORY.
PARAMETERS p_file TYPE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.

*&---------------------------------------------------------------------*
*&  At Selection Screen Event                                          *
*&---------------------------------------------------------------------*

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  
PERFORM f4_help.

SUB***************************************************

*&---------------------------------------------------------------------*
*&  Include           ZBAPI_MAT_DATA_LOGIC
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*&  Form F4_HELP                                                       *
*&---------------------------------------------------------------------*

FORM f4_help.
  
CALL FUNCTION 'F4_FILENAME'
    
EXPORTING
      program_name  
syst-cprog
      dynpro_number 
syst-dynnr
*     FIELD_NAME    = ' '
    
IMPORTING
      file_name     
p_file.
ENDFORM.                    "f4_help

*&---------------------------------------------------------------------*
*&  Form GUI_UPLOAD                                                    *
*&---------------------------------------------------------------------*
FORM gui_upload.
************************************************************************
***** For Notepad File

*  DATA:v_file TYPE string.
*  MOVE p_file TO v_file.

*  CALL FUNCTION 'GUI_UPLOAD'
*    EXPORTING
*     filename                      = v_file
*     filetype                      = 'DAT'
*     has_field_separator           = 'X'
**   HEADER_LENGTH                 = 0
**   READ_BY_LINE                  = 'X'
**   DAT_MODE                      = ' '
**   CODEPAGE                      = ' '
**   IGNORE_CERR                   = ABAP_TRUE
**   REPLACEMENT                   = '#'
**   CHECK_BOM                     = ' '
**   VIRUS_SCAN_PROFILE            =
**   NO_AUTH_CHECK                 = ' '
** IMPORTING
**   FILELENGTH                    =
**   HEADER                        =
*    TABLES
*      data_tab                      = it_bapi.

************************************************************************
***** For EXcel File
  
DATA lv_file TYPE rlgrap-filename,
         lv_raw  
TYPE truxs_t_text_data"truxs_xml_table.
  
MOVE   p_file TO lv_file.

  
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    
EXPORTING
      i_field_seperator    
'X'
*     I_LINE_HEADER        =
      i_tab_raw_data       
lv_raw
      i_filename           
lv_file
    
TABLES
      i_tab_converted_data 
it_bapi.
* EXCEPTIONS
*   CONVERSION_FAILED          = 1
*   OTHERS                     = 2

  
IF sy-subrc <> 0.
* Implement suitable error handling here
  
ENDIF.

ENDFORM.                    "gui_upload

*&---------------------------------------------------------------------*
*&      Form  bapi
*&---------------------------------------------------------------------*
FORM bapi.
  
LOOP AT it_bapi.
    bapimathead
-material   it_bapi-material.
    bapimathead
-ind_sector it_bapi-ind_sector.
    bapimathead
-matl_type  it_bapi-matl_type.
    bapimathead
-basic_view 'X'.

    bapi_mara
-matl_group   it_bapi-matl_group.
    bapi_mara
-base_uom     it_bapi-base_uom.
    bapi_marax
-matl_group  'X'.
    bapi_marax
-base_uom    'X'.

    it_makt_bapi
-matl_desc it_bapi-matl_desc.
    
APPEND it_makt_bapi.
    
CLEAR it_makt_bapi.

    
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
      
EXPORTING
        headdata            
bapimathead
        clientdata          
bapi_mara
        clientdatax         
bapi_marax
      
IMPORTING
        
return              it_return
      
TABLES
        materialdescription 
it_makt_bapi.

    
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      
EXPORTING
        
wait 'X'.
    
WRITE / it_return-type.

  
ENDLOOP.
ENDFORM.                    "bapi

Friday, September 25, 2020

BAPI PO CREATE Example in SAP ABAP.

BAPI PO CREATE Example in SAP ABAP. 




BAPI PO CREATE.

REPORT zbapi_po_creation.

include zbapi_po_creation_top. " top include for global data declration

include zbapi_po_creation_sel. " sel include for selecation

include zbapi_po_creation_sub. " f01 subrotine programs

*----------------------------------------------*
* I N I T I A L I Z A T I O N                  *
*----------------------------------------------*
INITIALIZATION.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

PERFORM f4_file_name.

*&---------------------------------------------------------------------*
*& Start of Selection Event                                            *
*&---------------------------------------------------------------------*
START-OF-SELECTION.

PERFORM data_process.      " CONVERTING DATA FROM EXCEL TO INTERNAL TABLE
*PERFORM uplode_data.
*----------------------------------------------*
* E N D - O F - S E  L E C T I O N             *
*----------------------------------------------*
END-OF-SELECTION.

CLEAR gcl_app_log.
*****Application Log
gcl_app_log =  zca_cl_application_log=>get_instance( ).

CALL METHOD gcl_app_log->create_app_log_handle(
EXPORTING
  i_object     = 'ZRKPANDEY'         " Object In SLGO
  i_subobject  = 'ZRKSUB'     " Sub Object In SLGO
  i_tcode      = sy-tcode
  i_repid      = sy-cprog
  RECEIVING
  r_log_handle = gs_log_handle ).
  PERFORM uplode_data.
************************* Save and Display Application Log *************************
CALL METHOD gcl_app_log->save_and_display_app_log
EXPORTING
  i_log_handle = gs_log_handle
  i_flg_save   = abap_false.

*Text elements
*----------------------------------------------------------
* T01 select flat file


*Selection texts
*----------------------------------------------------------
* P_FILE D       .
=============================================================================================
Code listing for: ZBAPI_PO_CREATION_TOP
Description: Include ZBAPI_PO_CREATION_TOP
*&---------------------------------------------------------------------*
*&  Include           ZBAPI_PO_CREATION_TOP
*&---------------------------------------------------------------------*
TYPES: BEGIN OF  ty_file,
  vendor      TYPE  elifn,   "   vendro
  purch_org   TYPE  ekorg,   "  puraches orgnization
  pur_group   TYPE  bkgrp,   "  purache groups
  co_code     TYPE  bukrs,   "  comapny code
  po_item     TYPE  ebelp,   " po item
  material    TYPE  matnr,   " material number
  short_text  TYPE  txz01,   " short text
  QUANTITY    type  BSTMG, " po quanity
  NET_PRICE	 TYPE	  BAPICUREXT,    " net price
  plant	     TYPE	  EWERK,        " net price
END OF ty_file.

DATA: po_number LIKE  bapimepoheader-po_number.

***** Internal Table
DATA : gt_final  TYPE STANDARD TABLE OF ty_file,
       gs_final  TYPE                   ty_file.
*       gt_return TYPE STANDARD TABLE OF bapireturn.

DATA : gt_return TYPE STANDARD TABLE OF bapiret2,
       gs_return TYPE bapiret2.


DATA : gt_type  TYPE truxs_t_text_data.


DATA: gt_po_items TYPE TABLE OF   bapimepoitem,
      gt_poitemx      TYPE TABLE OF bapimepoitemx,
      gs_poitemx      TYPE  bapimepoitemx,
      wa_po_items   LIKE bapimepoitem,
      return  TYPE  bapireturn,
      po_header TYPE TABLE OF  bapimepoheader,
      wa_poheaderx TYPE   bapimepoheaderx,
      wa_po_header TYPE  bapimepoheader.

* passing constan for values
DATA : gc_x TYPE c VALUE 'X'.

***** Declaration for application log
DATA: gt_return_log TYPE bapiret2_t.
****************** Class/Objects***************************
DATA: gcl_app_log   TYPE REF TO zca_cl_application_log,
****************** Internal Structure *********************
      gs_log_handle TYPE balloghndl.

"Local table
DATA: gt_return1 TYPE STANDARD TABLE OF bapiret2,
      gs_return1 TYPE bapiret2.

DATA: bapiret2 TYPE STANDARD TABLE OF bapiret2.

============================================================================================
Code listing for: ZBAPI_PO_CREATION_SEL
Description: Include ZBAPI_PO_CREATION_SEL
*&---------------------------------------------------------------------*
*&  Include           ZBAPI_PO_CREATION_SEL
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK a1 WITH FRAME TITLE TEXT-t01.

  PARAMETER p_file TYPE rlgrap-filename.

SELECTION-SCREEN END OF BLOCK a1.
============================================================================================
Code listing for: ZBAPI_PO_CREATION_SUB
Description: Include ZBAPI_PO_CREATION_SUB
*&---------------------------------------------------------------------*
*&  Include           ZBAPI_PO_CREATION_SUB
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  UPLODE_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM uplode_data .
  DATA : lv_log(100) TYPE c.
***** Uploading the data into the database table
  READ TABLE gt_final INTO gs_final INDEX 1.
* header data in po creation
    wa_po_header-vendor     = gs_final-vendor.
    wa_po_header-purch_org  = gs_final-purch_org.
    PERFORM f_converstion_exit.
    wa_po_header-pur_group  = gs_final-pur_group.
    wa_po_header-comp_code    = gs_final-co_code.
* passing x  values in po item
    wa_poheaderx-vendor    = gc_x.
    wa_poheaderx-purch_org = gc_x.
    wa_poheaderx-pur_group = gc_x.
    wa_poheaderx-comp_code   = gc_x.
* item data move
 LOOP AT gt_final INTO gs_final.
    wa_po_items-po_item    = gs_final-po_item.
    wa_po_items-material   = gs_final-material.
    wa_po_items-short_text = gs_final-short_text.
    wa_po_items-quantity  = gs_final-quantity.
    wa_po_items-net_price  = gs_final-net_price.
    wa_po_items-plant      = gs_final-plant.

* passing x value in po item
    gs_poitemx-po_item = gs_final-po_item.
    gs_poitemx-po_itemx   = gc_x.
    gs_poitemx-material   = gc_x.
    gs_poitemx-short_text = gc_x.
    gs_poitemx-quantity  = gc_x.
    gs_poitemx-po_price  = gc_x.
    gs_poitemx-plant      = gc_x.
    APPEND gs_poitemx TO gt_poitemx.
    APPEND wa_po_items TO gt_po_items.
ENDLOOP.
    CALL FUNCTION 'BAPI_PO_CREATE1'
      EXPORTING
        poheader         = wa_po_header
        poheaderx        = wa_poheaderx
      IMPORTING
        exppurchaseorder = po_number
      TABLES
        return           = gt_return1
        poitem           = gt_po_items
        poitemx          = gt_poitemx.
    IF gt_return1[] IS NOT INITIAL.
      LOOP AT gt_return1 INTO gs_return1. "data(gs_return1).
        gs_return-type       = gs_return1-type.
        gs_return-id         = gs_return1-id.
        CONCATENATE po_number gs_return1-message
        INTO lv_log SEPARATED BY ' - '.
        gs_return-message_v1 = lv_log.
        APPEND gs_return TO gt_return.
        CLEAR : gs_return1.
      ENDLOOP.
    ENDIF.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.
  CHECK sy-subrc EQ 0.
  CALL METHOD gcl_app_log->add_message_to_app_log
    EXPORTING
      i_log_handle = gs_log_handle
      i_tab_return = gt_return.
ENDFORM.                    " UPLODE_DATA
*&---------------------------------------------------------------------*
*&      Form  F4_FILE_NAME
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f4_file_name .
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      field_name = 'P_FILE'
    IMPORTING
      file_name  = p_file.

ENDFORM.                    " F4_FILE_NAME
*&---------------------------------------------------------------------*
*&      Form  DATA_PROCESS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM data_process .
****** Uploading the data in the file into internal table

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
      i_field_seperator    = 'X'
      i_line_header        = 'X'
      i_tab_raw_data       = gt_type
      i_filename           = p_file
    TABLES
      i_tab_converted_data = gt_final[]
    EXCEPTIONS
      conversion_failed    = 1
      OTHERS               = 2.
  IF sy-subrc NE 0.
    MESSAGE ID sy-msgid
    TYPE sy-msgty
    NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
ENDFORM.                    " DATA_PROCESS
*&---------------------------------------------------------------------*
*&      Form  F_CONVERSTION_EXIT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_converstion_exit .
  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
      input  = gs_final-pur_group
    IMPORTING
      output = gs_final-pur_group.

ENDFORM.                    " F_CONVERSTION_EXIT
===============================================

Wednesday, September 23, 2020

BAPI Sales Order Cerate Program in SAP ABAP

BAPI Sales Order Cerate  Program.



BAPI Sales Order Process.

REPORT zbapi_sales_order NO STANDARD PAGE HEADING.

include zbapi_sales_order_top.
include zbapi_sales_order_sel.
include zbapi_sales_order_f01.

*----------------------------------------------*
* I N I T I A L I Z A T I O N                  *
*----------------------------------------------*
INITIALIZATION.


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  PERFORM f4_file_name.

*&---------------------------------------------------------------------*
*& Start of Selection Event                                            *
*&---------------------------------------------------------------------*
START-OF-SELECTION.

  PERFORM data_process.      " CONVERTING DATA FROM EXCEL TO INTERNAL TABLE


  CLEAR gcl_app_log.
*****Application Log
  gcl_app_log =  zca_cl_application_log=>get_instance( ).

  CALL METHOD gcl_app_log->create_app_log_handle(
    EXPORTING
      i_object     = 'ZRKPAN'         " Object In SLGO
      i_subobject  = 'ZRKSUB'     " Sub Object In SLGO
      i_tcode      = sy-tcode
      i_repid      = sy-cprog
    RECEIVING
      r_log_handle = gs_log_handle ).
  PERFORM uplode_data.

END-OF-SELECTION.
************************* Save and Display Application Log *************************
  CALL METHOD gcl_app_log->save_and_display_app_log
    EXPORTING
      i_log_handle = gs_log_handle
      i_flg_save   = abap_false.


*Selection texts
*----------------------------------------------------------
* P_FILE D       .
=============================================================================================
*&---------------------------------------------------------------------*
*&  Include           ZBAPI_SALES_ORDER_TOP
*&---------------------------------------------------------------------*

TYPES: BEGIN OF  ty_file,
        doc_type  TYPE auart,    "  DOCUMENT TYPE
        sales_org  TYPE vkorg,   "  SALES ORGNIZATIN
        distr_chan TYPE vtweg,   "  DISTRIBUATION CHANNEL
        division   TYPE spart,   "  DIVISION
        partn_role TYPE parvw,   " SOLD TO PARTY
        partn_numb TYPE kunnr,   " SHIP TO PARTY
        po_itm_no  TYPE posex,   " ITEM
        material   TYPE matnr,   " MATERIAL
        target_qty TYPE dzmeng,  " QUANTITY
        plant      TYPE plant,   " PALNT
END OF ty_file.

DATA: gs_order_header_in      TYPE              bapisdhd1,             " Header data
      gs_order_header_inx     TYPE              bapisdhd1x,            " header datax
      gs_salesdocument        TYPE              bapivbeln-vbeln,       " document number
      gt_order_items_in	      TYPE TABLE OF    	bapisditm,             " item data internal table
      gs_order_items_in       TYPE              bapisditm,             " item data work area
      gt_order_items_inx      TYPE TABLE OF     bapisditmx,            " item datax internla tabel
      gs_order_items_inx      TYPE              bapisditmx,            " item data work area
      gt_order_partners	      TYPE TABLE OF     bapiparnr,             " sold to party
      gs_order_partners	      TYPE              bapiparnr.             " ship to party
***** Internal Table
DATA : gt_final  TYPE STANDARD TABLE OF ty_file,
       gs_final  TYPE                   ty_file.
*       gt_return TYPE STANDARD TABLE OF bapireturn.

DATA : gt_return TYPE STANDARD TABLE OF bapiret2,
      gs_return TYPE bapiret2.


DATA : gt_type  TYPE truxs_t_text_data.


* passing constan for values
DATA : gc_x TYPE c VALUE 'X'.

***** Declaration for application log
DATA: gt_return_log TYPE bapiret2_t.
****************** Class/Objects***************************
DATA: gcl_app_log   TYPE REF TO zca_cl_application_log,
****************** Internal Structure *********************
      gs_log_handle TYPE balloghndl.

"Local table
DATA: gt_return1 TYPE STANDARD TABLE OF bapiret2,
      gs_return1 TYPE bapiret2.

DATA: bapiret2 TYPE STANDARD TABLE OF bapiret2.
=======================================================================
*&---------------------------------------------------------------------*
*&  Include           ZBAPI_SALES_ORDER_SEL
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK a1 WITH FRAME TITLE TEXT-t01.

  PARAMETER p_file TYPE rlgrap-filename.

SELECTION-SCREEN END OF BLOCK a1.
==========================================================================================
*&---------------------------------------------------------------------*
*&  Include           ZBAPI_SALES_ORDER_F01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  F4_FILE_NAME
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f4_file_name .
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      field_name = 'P_FILE'
    IMPORTING
      file_name  = p_file.

ENDFORM.                    " F4_FILE_NAME
*&---------------------------------------------------------------------*
*&      Form  DATA_PROCESS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM data_process .
****** Uploading the data in the file into internal table

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
      i_field_seperator    = 'X'
      i_line_header        = 'X'
      i_tab_raw_data       = gt_type
      i_filename           = p_file
    TABLES
      i_tab_converted_data = gt_final[]
    EXCEPTIONS
      conversion_failed    = 1
      OTHERS               = 2.
  IF sy-subrc NE 0.
    MESSAGE ID sy-msgid
    TYPE sy-msgty
    NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
ENDFORM.                    " DATA_PROCESS
*&---------------------------------------------------------------------*
*&      Form  UPLODE_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM uplode_data .
  DATA : lv_log(100) TYPE c.
  READ TABLE gt_final INTO gs_final INDEX 1.

  DATA: lt_order_schedules_in TYPE STANDARD TABLE OF  bapischdl,
        lt_order_schedules_inx  TYPE STANDARD TABLE OF  bapischdlx,
        ls_order_schedules_in TYPE   bapischdl,
        ls_order_schedules_inx  TYPE   bapischdlx.
*
*  gs_order_header_in- = gs_final-
* header data for sales order creation
  PERFORM f_converstion_exit.
  gs_order_header_in-doc_type   = gs_final-doc_type.
  gs_order_header_in-sales_org  = gs_final-sales_org.
  gs_order_header_in-distr_chan = gs_final-distr_chan.
  gs_order_header_in-division   = gs_final-division.

  gs_order_header_inx-doc_type   = gc_x.
  gs_order_header_inx-sales_org  = gc_x.
  gs_order_header_inx-distr_chan = gc_x.
  gs_order_header_inx-division   = gc_x.

* sales item data
  gs_order_items_in-po_itm_no  = gs_final-po_itm_no.
  gs_order_items_in-material   = gs_final-material.
  gs_order_items_in-target_qty = gs_final-target_qty.
  gs_order_items_in-plant      = gs_final-plant.

  gs_order_items_inx-po_itm_no = gc_x.
  gs_order_items_inx-material = gc_x.
  gs_order_items_inx-target_qty = gc_x.
  gs_order_items_inx-plant = gc_x.
  gs_order_items_inx-updateflag = gc_x.
  gs_order_items_inx-reqmts_typ = gc_x.

  APPEND gs_order_items_in TO gt_order_items_in.
  APPEND gs_order_items_inx TO gt_order_items_inx.
* SHEDULE QUANITITY
  ls_order_schedules_in-req_qty = gs_final-target_qty.
  ls_order_schedules_in-itm_number = gs_final-po_itm_no.
  ls_order_schedules_inx-req_qty = gc_x.
  ls_order_schedules_inx-itm_number = gc_x.
  APPEND ls_order_schedules_in TO lt_order_schedules_in.
  APPEND ls_order_schedules_inx TO lt_order_schedules_inx.
* partner of
  PERFORM f_partn_role.
  gs_order_partners-partn_role =  gs_final-partn_role.
  gs_order_partners-partn_numb =  gs_final-partn_numb.
  APPEND gs_order_partners TO gt_order_partners.
  CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
    EXPORTING
      order_header_in  = gs_order_header_in
      order_header_inx = gs_order_header_inx
    IMPORTING
      salesdocument    = gs_salesdocument
    TABLES
      return           = gt_return1
      order_items_in   = gt_order_items_in
      order_items_inx  = gt_order_items_inx
      order_partners   = gt_order_partners
  order_schedules_in            = lt_order_schedules_in
  order_schedules_inx           = lt_order_schedules_inx.
if gt_return1[] IS NOT INITIAL.
  LOOP AT gt_return1 INTO gs_return1. "data(gs_return1).
    gs_return-type       = gs_return1-type.
    gs_return-id         = gs_return1-id.
    CONCATENATE gs_salesdocument gs_return1-message
    INTO lv_log SEPARATED BY ' - '.
    gs_return-message_v1 = lv_log.
    APPEND gs_return TO gt_return.
    CLEAR : gs_return1.
  ENDLOOP.
ENDIF.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
  EXPORTING
    wait = 'X'.
CHECK sy-subrc EQ 0.
CALL METHOD gcl_app_log->add_message_to_app_log
  EXPORTING
    i_log_handle = gs_log_handle
    i_tab_return = gt_return.

ENDFORM.                    " UPLODE_DATA
*&---------------------------------------------------------------------*
*&      Form  F_CONVERSTION_EXIT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_converstion_exit .
  CALL FUNCTION 'CONVERSION_EXIT_AUART_INPUT'
    EXPORTING
      input  = gs_final-doc_type
    IMPORTING
      output = gs_final-doc_type.


ENDFORM.                    " F_CONVERSTION_EXIT
*&---------------------------------------------------------------------*
*&      Form  F_PARTN_ROLE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_partn_role .
  CALL FUNCTION 'CONVERSION_EXIT_PARVW_INPUT'
    EXPORTING
      input  = gs_final-partn_role
    IMPORTING
      output = gs_final-partn_role.


ENDFORM.                    " F_PARTN_ROLE

Total and Subtotal Reports in SAP ABAP.

 

Total and Subtotal Reports in SAP ABAP.


Total and Subtotal Example in SAP ABAP.

REPORT  ZREPORTS_TOTAL.

TABLES: ekko.

TYPE-POOLS: slis.

DATA: wa_fcat   TYPE lvc_s_fcat,

      it_fcat   TYPE lvc_t_fcat,

      wa_layout TYPE lvc_s_layo,

      wa_top    TYPE slis_listheader,

      it_top    TYPE slis_t_listheader.

 

TYPES: BEGIN OF ty_ekko,

ebeln TYPE ekko-ebeln,

aedat TYPE ekko-aedat,

END OF ty_ekko.

DATA: wa_ekko TYPE ty_ekko,

      it_ekko TYPE TABLE OF ty_ekko.

 

TYPES: BEGIN OF ty_ekpo,

ebeln TYPE ekpo-ebeln,

ebelp TYPE ekpo-ebelp,

matnr TYPE ekpo-matnr,

werks TYPE ekpo-werks,

menge TYPE ekpo-menge,

meins TYPE ekpo-meins,

END OF ty_ekpo.

DATA: wa_ekpo TYPE ty_ekpo,

      it_ekpo TYPE TABLE OF ty_ekpo.

 

TYPES: BEGIN OF ty_out,

ebeln TYPE char15,

ebelp TYPE char5,

matnr TYPE ekpo-matnr,

werks TYPE ekpo-werks,

menge TYPE ekpo-menge,

meins TYPE ekpo-meins,

color TYPE char4,

bold  TYPE lvc_t_styl,

END OF ty_out.

DATA: wa_out TYPE ty_out,

      it_out TYPE TABLE OF ty_out.

 

INITIALIZATION.

SELECT-OPTIONS s_aedat FOR ekko-aedat.

 

START-OF-SELECTION.

PERFORM get_ekko.

PERFORM get_ekpo.

 

END-OF-SELECTION.

PERFORM prepare_output.

PERFORM field_catalog.

PERFORM alv_grid_display.

 

TOP-OF-PAGE.

PERFORM top_of_page.

*&---------------------------------------------------------------------*

*&      Form  GET_EKKO

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

FORM get_ekko .

 

SELECT ebeln aedat FROM ekko

INTO TABLE it_ekko

WHERE aedat IN s_aedat.

 

ENDFORM.

*&---------------------------------------------------------------------*

*&      Form  GET_EKPO

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

FORM get_ekpo .

 

IF it_ekko IS NOT INITIAL.

SELECT ebeln ebelp matnr werks menge meins

FROM ekpo INTO TABLE it_ekpo

FOR ALL ENTRIES IN it_ekko

WHERE ebeln = it_ekko-ebeln

AND matnr NE ' '.

 

IF sy-subrc = 0.

SORT it_ekpo BY ebeln ebelp.

ENDIF.

ENDIF.

 

ENDFORM.

*&---------------------------------------------------------------------*

*&      Form  PREPARE_OUTPUT

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

FORM prepare_output .

 

DATA: lw_bold TYPE lvc_s_styl,

      lt_bold TYPE lvc_t_styl.

 

IF it_ekpo IS NOT INITIAL.

LOOP AT it_ekpo INTO wa_ekpo.

wa_out-ebeln = wa_ekpo-ebeln.

wa_out-ebelp = wa_ekpo-ebelp.

wa_out-matnr = wa_ekpo-matnr.

SHIFT wa_out-matnr LEFT DELETING LEADING '0'.

wa_out-werks = wa_ekpo-werks.

wa_out-menge = wa_ekpo-menge.

wa_out-meins = wa_ekpo-meins.

APPEND wa_out TO it_out.

CLEAR: wa_out.

 

AT END OF ebeln.

SUM.

wa_out-ebeln = 'SUB TOTAL'.

wa_out-menge = wa_ekpo-menge.

wa_out-color = 'C200'.

lw_bold-style = '00000121'.

INSERT lw_bold INTO lt_bold INDEX 1.

wa_out-bold = lt_bold.

FREE lt_bold.

 

APPEND wa_out TO it_out.

CLEAR: wa_out, lw_bold, wa_ekpo.

ENDAT.

 

AT LAST.

SUM.

wa_out-ebeln = 'GRAND TOTAL'.

wa_out-menge = wa_ekpo-menge.

wa_out-color = 'C210'.

lw_bold-style = '00000121'.

INSERT lw_bold INTO lt_bold INDEX 1.

wa_out-bold = lt_bold.

FREE lt_bold.

 

APPEND wa_out TO it_out.

CLEAR: wa_out, lw_bold, wa_ekpo.

ENDAT.

ENDLOOP.

ENDIF.

 

FREE it_ekpo.

 

ENDFORM.

*&---------------------------------------------------------------------*

*&      Form  FIELD_CATALOG

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

FORM field_catalog .

 

DATA: lv_col TYPE i VALUE 0.

 

lv_col            = 1 + lv_col.

wa_fcat-col_pos   = lv_col.

wa_fcat-fieldname = 'EBELN'.

wa_fcat-reptext   = 'Purchase Order'.

APPEND wa_fcat TO it_fcat.

CLEAR wa_fcat.

 

lv_col            = 1 + lv_col.

wa_fcat-col_pos   = lv_col.

wa_fcat-fieldname = 'EBELP'.

wa_fcat-reptext   = 'Item'.

APPEND wa_fcat TO it_fcat.

CLEAR wa_fcat.

 

lv_col            = 1 + lv_col.

wa_fcat-col_pos   = lv_col.

wa_fcat-fieldname = 'MATNR'.

wa_fcat-reptext   = 'Material'.

APPEND wa_fcat TO it_fcat.

CLEAR wa_fcat.

 

lv_col            = 1 + lv_col.

wa_fcat-col_pos   = lv_col.

wa_fcat-fieldname = 'WERKS'.

wa_fcat-reptext   = 'Plant'.

APPEND wa_fcat TO it_fcat.

CLEAR wa_fcat.

 

lv_col            = 1 + lv_col.

wa_fcat-col_pos   = lv_col.

wa_fcat-fieldname = 'MENGE'.

wa_fcat-reptext   = 'Quantity'.

APPEND wa_fcat TO it_fcat.

CLEAR wa_fcat.

 

lv_col            = 1 + lv_col.

wa_fcat-col_pos   = lv_col.

wa_fcat-fieldname = 'MEINS'.

wa_fcat-reptext   = 'Unit'.

APPEND wa_fcat TO it_fcat.

CLEAR wa_fcat.

 

wa_layout-zebra      = 'X'.

wa_layout-cwidth_opt = 'X'.

wa_layout-info_fname = 'COLOR'.

wa_layout-stylefname = 'BOLD'.

 

ENDFORM.

*&---------------------------------------------------------------------*

*&      Form  ALV_GRID_DISPLAY

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

FORM alv_grid_display .

 

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'

EXPORTING

  i_callback_program     = sy-repid

  i_callback_top_of_page = 'TOP_OF_PAGE'

  is_layout_lvc          = wa_layout

  it_fieldcat_lvc        = it_fcat

TABLES

  t_outtab               = it_out

EXCEPTIONS

  program_error          = 1

  OTHERS                 = 2.

 

 

ENDFORM.

*&---------------------------------------------------------------------*

*&      Form  TOP_OF_PAGE

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

FORM top_of_page .

 

REFRESH it_top.

 

wa_top-typ  = 'H'.

wa_top-info = 'Purchasing List'.

APPEND wa_top TO it_top.

CLEAR wa_top.

 

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

  it_list_commentary = it_top.

 

ENDFORM.