Thursday, January 27, 2022

When do we go for call transaction method and when do we go for session method in SAP ABAP?


Call Transaction:

The Call transaction is used if you need the generated document number to be returned to the program. It is often used if you need to do some additional processing after your document is generated. It is usually a small data set because if you have large data, you might have a time out error.

Sessions Method:

Sessions are used when you are unsure when you will run the BDC... you could schedule it during the night.This is used when you are working with large numbers of transactions.

DMR mass creation BAPI Name.

 Which BAPI do they use for DMR mass creation?

 
BAPI Name: BAPI_BUSPROCESSND_CREATEMULTI
 
 

Which modules are used in BDC.

 

Which modules are used in BDC?

1.BDC_Open_group.

2.BDC_Insert.

3.BDC_Close_group

These three modules are primarily used in successfully transferring data in sequence using BDC.

Tuesday, October 13, 2020

Billing Date validation In SAP ABAP.

Billing Date validation In SAP ABAP.

INCLUDE  RV60AFZZ 

FORM USEREXIT_ACCOUNT_PREP_KOMKCV.
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""$"$\SE:(1) Form USEREXIT_ACCOUNT_PREP_KOMKCV, Start                                                                                                          A
*$*$-Start: (1)---------------------------------------------------------------------------------$*$*
ENHANCEMENT 1  ZAK_INVOICE_VALID.    "active version

**TYPES: BEGIN OF ty_final,
**        vbeln TYPE vbeln_vl,
**        lfdat TYPE lfdat_v,
**       END OF ty_final.
**DATA: it_final TYPE STANDARD TABLE OF ty_final,
**      wa_final TYPE ty_final.
**
**      SELECT SINGLE vbeln lfdat
**        FROM likp
**        INTO wa_final
**        WHERE vbeln = vbrp-vgbel.
**
**      IF VBRK-FKDAT < wa_final-lfdat.
**        MESSAGE 'billing Date should not be less than delivery date' TYPE 'E'.
**        fcode = 'ENT1'.
**        PERFORM FOLGE_GLEICHSETZEN(SAPMV60A).
**        SET SCREEN 6105.
**        LEAVE SCREEN.
**      ENDIF.

How to make field Address required in transaction KE51 in SAP

How to make field Address required in transaction KE51 in SAP ABAP.

Normally SAP doesn’t provide us configuration and user exit to make fields in Address tab required in transaction KE51 . but after little bit of debug ABAP Code, i found the clue that you need to create enhancement point in include program LRKPMF05  in subroutine md_user_command_handle.

Example:

FORM md_user_command_handle CHANGING p_fcode.

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""$"$\SE:(1) Form MD_USER_COMMAND_HANDLE, Start                                                                                                                A

*$*$-Start: (1)---------------------------------------------------------------------------------$*$*

ENHANCEMENT 1  ZIMP_CO_REQUIRED_ADDR_KE51.    "active version

"Added By Rachmad Kurniawan

"Tgl 06/10/2016

IF md_fcode = 'MD_SAVE'.

 IF PRCT_V-STRAS EQ ''.

  MESSAGE 'You must input Street' TYPE 'E'.

ENDIF.

IF PRCT_V-ORT01 EQ ''.

 MESSAGE 'You must input Kota' TYPE 'E'.

ENDIF.

 IF PRCT_V-LAND1 EQ ''.

 MESSAGE 'You must input Country' TYPE 'E'.

ENDIF.

 IF PRCT_V-REGIO EQ ''.

 MESSAGE 'You must input Region' TYPE 'E'.

ENDIF.

 ENDIF.

ENDENHANCEMENT.

Definition of Infotype within the Data Dictionary in ABAP HR

Definition of Infotype within the Data Dictionary.

Each infotype nnnn requires at least two structures and one table:

• Structure PSnnnn

Structure PSnnnn contains all of the infotype data fields.

• Structure Pnnnn

Structure Pnnnn contains infotype key fields and all of the data fields from structure PSnnnn .

• Transparent table PAnnnn and/or transparent table PBnnnn

Transparent table PAnnnn is required if you want to use an infotype within Personnel Administration.

If you want to use an infotype within Recruitment, transparent table PBnnnn is required.

In accordance with the distribution of infotype name ranges, objects P9nnn , PS9nnn , PA9nnn and PB9nnn are assigned to the customer name range.

Naming conventions for Infotypes in SAP ABAP HR

Naming conventions for Infotypes in SAP.

 • 0000 to 0999 – HR Master data / Applicant data

• 1000 to 1999 – Organizational Management

• 2000 to 2999 – Time data

• 4000 to 4999 – Applicant data

• 9000 to 9999 – Customer defined

Saturday, October 10, 2020

What is an IDOC Structure in SAP.

IDOC Structure.

  


Each IDOC has 3 records I.             Control Record:

Ø  It contains IDOC type & Message type information, Partner information such as partner system number, Port number of the sender & receiver system.

Ø  It is also contain technical & address information of sender & recipients.

 

     II.      Data Record:

Ø  These are collection of segments. The data record of an IDOC contains segment.

Ø  Segment is collection of fields which can be distributed the data between the systems.

 

III.         Status record:

Ø  It contains the status of the processed IDOC to know where an IDOC has been successful/failed.

Ø  The standard table EDIDC contains an IDOC information such as control records, different statuses etc.

  Note:

Ø  The Sender/Source system is also called as ‘Outbound system’.

Ø  The Receiver/Target system is also called as ‘Inbound system’.

Ø  The T-code ‘WE30’ is used to maintain different types of IDOC’s such as Basic IDOC, Extended IDOC.

Ø  The T-codes WE02/WE05 are used to list out the generated IDOC’s.

Ø  The T-code ‘WE19’ is used to test/check the IDOC.

Custom Segments:

Ø  The custom segments are starts with Z*/Y* & they are maintained by technical & functional consultants

Standard Segment:

Ø  These are system provided segments

Ø  The T-code : WE31 is used to maintain the segments

 

Message Types:

Ø  These are identifiers of the application data to be distributed between the systems

Ø  The T-code WE81 is used to create & WE82 is to assign the message types to the IDOC (Data carrier)

Ø  The standard table EDIDC contains all available message type

System provided standard message types?

Message Type

Description

MATMAS

Material Master

DEBMAS

Customer Master

CREMAS

Vendor Master

 

Partner Profiles:

Ø  These are used to maintain the partner system details with which data to be distributed such as partner number, Partner type & Message type of outbound parameters. Ø The T-code WE20 is used to maintain partner profiles

Ports:

Ø  These are used to specify the way in which data to be distributed through an IDOC

Ø  The system generates one unique port number

Ø  The T-code WE21 is used to maintain ports for IDOC process

Customer Distribution Model:

Ø  It is used to define data distribution model to exchange the messages between two logical systems (SAP – SAP/SAP – non SAP)

Ø  The T-code BD64 is used to define/maintain customer distribution model

Process codes;

Ø  It is used to identify type of the data to be distributed through an IDOC interface.

Ø  The T-code WE41/WE42 is used to work with the process code 


Friday, October 9, 2020

How to check the IDOCs in SAP.

How to check the IDOCs?

Check the IDOCs in SAP.

Ans :- WE19 is the T-code to check the IDOC’s.

1.   Execute WE02/WE05

2.   Provide the Message type: CREMAS (Logical Sys), Partner no: LS810 & Click on Execute             3. After we get the status code 03, if we want to know the IDOC is reached to destination or                 not then we execute RBDMOIND standard program.

4.  The status of an IDOC (3) use in Green color (turn 10 to12) means it is delivered   

               Successfully. Yellow traffic light indicates/the status code remains same, IDOC is in                   Progress or in the Transaction RFC & Red traffic light/the status code turns 10 to 11                 indicates the Error/the IDOC is damaged.   

5.  Expand the Data Records folder & click on each segment to see the data to be distributed.    

Wednesday, October 7, 2020

What Are The Differences Between SAP Scripts & Smartforms in SAP ABAP.

What Are The Differences Between SAP Scripts & Smartforms? Differences between SAP Scripts and Smart Forms are:



 Smart Forms are client independent and SAP Scripts are client dependent.

 Multiple page formats are possible in Smart Forms which is not the case in SAP Scripts.

 It is possible to have a Smart Form without a main window where as you create a SAP Script without a main window.

 Smart Forms generates a function module when activated, which is not the case with SAP Scripts.

 SAP Scripts require a driver program to display the output whereas in Smart Forms the form routines can be written so that it is standalone.

 An integrated Form Builder helps to design Smart Forms more easily than SAP Scripts.

 A Table Painter and Smart Styles to assist in building up the Smart Forms which is not available in SAP Scripts.

 Smart Forms generates XML output which can be viewed through the web.


BAPI_MATERIAL_SAVEDATA Use For Material Extension Full Program Example in SAP ABAP

Material Extension  Full Program Example in SAP ABAP.


BAPI_MATERIAL_SAVEDATA Use For Material Extension in SAP ABAP.

REPORT zrmm_material_master_upld.
INCLUDE zrmm_material_master_upld_top.
INCLUDE zrmm_material_master_upld_ss.
INCLUDE zrmm_material_master_upld_sub.

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

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
  
PERFORM f4_help.

START-OF-SELECTION.
PERFORM get_data.

  
IF r_int abap_true.
    
PERFORM f_fill_matnr.
  
ELSEIF r_ext abap_true.
    gt_final[] 
gt_final_ext[].
  
ENDIF.

  
IF gt_final[] IS NOT INITIAL.
    
PERFORM f_create_material_master.

***** MSG Handling
    
PERFORM f_build_header,
              f_download_msg
.
  
ENDIF.
**&---------------------------------------------------------------------*
**& Form F4_HELP
**&---------------------------------------------------------------------*
**& text
**&---------------------------------------------------------------------*
**& -->  p1        text
**& <--  p2        text
**&---------------------------------------------------------------------*
FORM f4_help .
  
CALL FUNCTION 'F4_FILENAME'
    
EXPORTING
      program_name  
syst-cprog
      dynpro_number 
syst-dynnr
    
IMPORTING
      file_name     
p_path.
ENDFORM.

================================================================

TABLES:bapimathead,
       bapi_makt
,
       bapi_mara
,
       bapi_marax
,
       bapi_marc
,
       bapi_marcx
,
       bapi_mard
,
       bapi_mardx
,
       bapi_mpop
,
       bapi_mpopx
,
       bapi_mbew
,
       bapi_mbewx
,
       bapi_mvke
,
       bapi_mvkex
,
       bapi_mlgt
,
       bapi_mlgtx
,
       bapi_mpgd
,
       bapi_mpgdx 
.

TYPES BEGIN OF ty_ext_final,
          matnr
(40),
          mtart
(4),
          werks
(4),
          lgort
(4),
          vkorg
(4),
          vtweg
(2),
          maktx
(40),
          meins
(3),
          matkl
(9),
          bismt
(40),   """"
          spart
(2),
          mtpos_mara
(4),
          brgew
(17),
*          gewei(3),
          ntgew
(13),
          taxkm
(1),
          taxkm1
(1),
          taxkm2
(1),
          taxkm3
(1),
          taxkm4
(1),
          ktgrm
(2),
          mtpos
(4),
***          New ADD
*          MVGR1(3),
*          MVGR2(3),
*          MVGR3(3),
*          MVGR4(3),
*          MVGR5(3),
****          New ADD
****      new add
          mtbfp
(2),
          xchpf
(1),
*          kautb(1),
****
          tragr
(4),
          ladgr
(4),
          prctr
(10),
          steuc
(16),
          ekgrp
(3),
          vabme
(1),
          taxim
(1),
          disgr
(4),
          dismm
(2),
          minbe
(10),             "New added
          dispo
(3),
          mabst
(17),
          disls
(2),
          beskz
(1),
          dzeit
(3),
          plifz
(3),
          webaz
(3),
*          perkz(1),
*          strgr(2),
*          mtvfp(2),
*          sbdkz(1),
*          prmod(1),
*          peran(3),
*          anzpr(3),
*          kzini(1),
*          siggr(9),
*          modav(1),
          fevor
(3),
          sfcpf
(6),
          mhdrz
(4),
          mhdhb
(4),
          iprkz
(1),
*
          sled_bbd
(1),
          sernp
(4),
          bwtty
(1),
          bklas
(4),
          mlast
(1),
*          stprs_1(14),
          peinh_1
(5),
          vprsv_1
(1),

          losgr
(17),
**          vprsv(1),
**          peinh(5),
**          stprs(14),
          umren2_1
(5),
          umren3_1
(5),
          umren4_1
(5),
          meinh2_1
(3),

          umren2_2
(5),
          umren3_2
(5),
          umren4_2
(5),
          meinh2_2
(3),

*          umren2_3(5),
*          umren3_3(5),
*          umren4_3(5),
*          meinh2_3(3),

          
"po_text(250),
          po_text1
(50),
          po_text2
(50),
          po_text3
(50),
          po_text4
(50),
          po_text5
(50),

        
END OF ty_ext_final,

        
BEGIN OF ty_int_final,
          mtart
(4),
          werks
(4),
          lgort
(4),
          vkorg
(4),
          vtweg
(2),
          maktx
(40),
          meins
(3),
          matkl
(9),
          bismt
(40),   """"
          spart
(2),
          mtpos_mara
(4),
          brgew
(17),
*          gewei(3),
          ntgew
(13),
          taxkm
(1),
          taxkm1
(1),
          taxkm2
(1),
          taxkm3
(1),
          taxkm4
(1),
          ktgrm
(2),
          mtpos
(4),
***          New ADD
*          MVGR1(3),
*          MVGR2(3),
*          MVGR3(3),
*          MVGR4(3),
*          MVGR5(3),
****          New ADD

****      new add
          mtbfp
(2),
          xchpf
(1),
*          kautb(1),
****
          tragr
(4),
          ladgr
(4),
          prctr
(10),
          steuc
(16),
          ekgrp
(3),
          vabme
(1),
          taxim
(1),
          disgr
(4),
          dismm
(2),
          minbe
(10),             "New added
          dispo
(3),
          mabst
(17),
          disls
(2),
          beskz
(1),
          dzeit
(3),
          plifz
(3),
          webaz
(3),
*          perkz(1),
*          strgr(2),
*          mtvfp(2),
*          sbdkz(1),
*          prmod(1),
*          peran(3),
*          anzpr(3),
*          kzini(1),
*          siggr(9),
*          modav(1),
          fevor
(3),
          sfcpf
(6),
          mhdrz
(4),
          mhdhb
(4),
          iprkz
(1),

          sled_bbd
(1),
          sernp
(4),
          bwtty
(1),
          bklas
(4),
          mlast
(1),
*          stprs_1(14),
          peinh_1
(5),
          vprsv_1
(1),

          losgr
(17),
**          vprsv(1),
**          peinh(5),
**          stprs(14),
          umren2_1
(5),
          umren3_1
(5),
          umren4_1
(5),
          meinh2_1
(3),

          umren2_2
(5),
          umren3_2
(5),
          umren4_2
(5),
          meinh2_2
(3),

*          umren2_3(5),
*          umren3_3(5),
*          umren4_3(5),
*          meinh2_3(3),
          po_text1 
TYPE TDLINE "(50),
          po_text2
(50),
          po_text3
(50),
          po_text4
(50),
          po_text5
(50),
        
END OF ty_int_final.


DATA gt_final     TYPE STANDARD TABLE OF ty_ext_final,
       gs_final     
TYPE ty_ext_final,

       gt_final_ext 
TYPE STANDARD TABLE OF ty_ext_final,
       gs_final_ext 
TYPE ty_ext_final,

       gt_final_int 
TYPE STANDARD TABLE OF ty_int_final,
       gs_final_int 
TYPE ty_int_final.

DATAgt_file_data  TYPE truxs_t_text_data.


DATA it_mlan  TYPE STANDARD TABLE OF bapi_mlan,
       wa_mlan  
TYPE bapi_mlan,

       it_marm  
TYPE STANDARD TABLE OF bapi_marm,
       it_marmx 
TYPE STANDARD TABLE OF bapi_marmx,

       it_makt  
TYPE STANDARD TABLE OF bapi_makt,
       wa_makt  
TYPE bapi_makt,

       wa_marm  
TYPE bapi_marm,
       wa_marmx 
TYPE bapi_marmx.

DATA it_return LIKE bapiret2,
       wa_return 
TYPE bapiret2.



DATA :it_excel TYPE STANDARD TABLE OF alsmex_tabline,
      wa_excel 
TYPE                   alsmex_tabline.
FIELD-SYMBOLS<fs>.

TYPES BEGIN OF ty_header,
          f_name 
TYPE char75,
        
END OF ty_header,

        
BEGIN OF msg,
          
line       TYPE i,
          
type       TYPE char10,
          message_v1 
TYPE symsgv,
          maktx      
TYPE makt-maktx,
          
message    TYPE bapi_msg,
        
END OF msg.


DATA lv_desktop TYPE string,
       lv_line    
TYPE i.

DATAlt_header TYPE STANDARD TABLE OF ty_header,
      ls_header 
TYPE ty_header,

      it_msg    
TYPE STANDARD TABLE OF msg,
      wa_msg    
TYPE msg.

=======================================================================================

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS P_PATH LIKE RLGRAP-FILENAME OBLIGATORY,
             P_STROW 
TYPE I OBLIGATORY,
             P_EDROW 
TYPE I OBLIGATORY.

SELECTION-SCREEN SKIP 1.

SELECTION-SCREEN END OF BLOCK B1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME title text-002.
  
PARAMETERS r_int RADIOBUTTON GROUP rd1 DEFAULT 'X',
               r_ext 
RADIOBUTTON GROUP rd1.
  
SELECTION-SCREEN end of BLOCK b2.

======================================================================================


*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM get_data .
  
DATA index    TYPE i.
  
IF r_ext abap_true.

    
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
      
EXPORTING
        filename                
p_path
        i_begin_col             
1
        i_begin_row             
p_strow
        i_end_col               
100
        i_end_row               
p_edrow
      
TABLES
        intern                  
it_excel
      
EXCEPTIONS
        inconsistent_parameters 
1
        upload_ole              
2
        
OTHERS                  3.
    
IF sy-subrc <> 0.
      
MESSAGE 'ERROR OCCUR IN READING THE EXCEL FILE' TYPE 'I'.
      
STOP.
    
ENDIF.

    
LOOP AT it_excel INTO wa_excel.
      
index wa_excel-col.
      
ASSIGN COMPONENT index OF STRUCTURE gs_final_ext TO <fs>.
      <fs> 
wa_excel-value.
      
AT END OF row.
*      APPEND wa_final TO it_final.
        
APPEND gs_final_ext TO gt_final_ext.
        
CLEAR gs_final_ext.
      
ENDAT.
    
ENDLOOP.

*    CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
*      EXPORTING
*        i_line_header        = abap_true
*        i_tab_raw_data       = gt_file_data
*        i_filename           = p_file
*      TABLES
*        i_tab_converted_data = gt_final_ext[]
*      EXCEPTIONS
*        conversion_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.
*    SORT gt_final_ext BY matnr.
  
ELSEIF r_int abap_true.


    
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
      
EXPORTING
        filename                
p_path
        i_begin_col             
1
        i_begin_row             
p_strow
        i_end_col               
100
        i_end_row               
p_edrow
      
TABLES
        intern                  
it_excel
      
EXCEPTIONS
        inconsistent_parameters 
1
        upload_ole              
2
        
OTHERS                  3.
    
IF sy-subrc <> 0.
      
MESSAGE 'ERROR OCCUR IN READING THE EXCEL FILE' TYPE 'I'.
      
STOP.
    
ENDIF.

    
LOOP AT it_excel INTO wa_excel.
      
index wa_excel-col.
      
ASSIGN COMPONENT index OF STRUCTURE gs_final_int TO <fs>.
      <fs> 
wa_excel-value.
      
AT END OF row.
*      APPEND wa_final TO it_final.
        
APPEND gs_final_int TO gt_final_int.
        
CLEAR gs_final_int.
      
ENDAT.
    
ENDLOOP.

*   BREAK-POINT.

*    CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
*      EXPORTING
*        i_line_header        = abap_true
*        i_tab_raw_data       = gt_file_data
*        i_filename           = p_file
*      TABLES
*        i_tab_converted_data = gt_final_int[]
*      EXCEPTIONS
*        conversion_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.
  
ENDIF.

*  BREAK-POINT.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form UPLOAD_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM f_fill_matnr .

  
DATA lv_lines TYPE i.
  
DATA :lv_new_mat_total TYPE bapimatall-req_numbers,
        required_numbers 
LIKE  bapimatall-req_numbers,
        lt_material      
TYPE STANDARD TABLE OF  bapimatinr,
        lt_material1     
TYPE STANDARD TABLE OF  bapimatinr,
        ls_material      
TYPE bapimatinr,
        material_type    
LIKE  bapimatdoa-matl_type.


  
DESCRIBE TABLE gt_final_int LINES lv_lines.

  
IF lv_lines > 255 .
    
MESSAGE 'For Internal material Number range only 255 line is allowed.' TYPE 'E'.
  
ENDIF.
  
DESCRIBE TABLE gt_final_int LINES lv_new_mat_total ."lv_lines.


  
READ TABLE gt_final_int INTO DATA(ls_f_intINDEX 1.

  
CALL FUNCTION 'BAPI_MATERIAL_GETINTNUMBER'
    
EXPORTING
      material_type    
ls_f_int-mtart "'ZROH'
*     INDUSTRY_SECTOR  = ' '
      required_numbers 
lv_new_mat_total
* IMPORTING
*     RETURN           =
    
TABLES
      material_number  
lt_material.



  
LOOP AT gt_final_int INTO gs_final_int.
    
MOVE-CORRESPONDING gs_final_int TO gs_final_ext.
    
READ TABLE lt_material INTO ls_material INDEX 1.
    
IF sy-subrc 0.
      gs_final_ext
-matnr ls_material-material.
    
ENDIF.
    
APPEND gs_final_ext TO gt_final.
    
DELETE lt_material WHERE material ls_material-material.
    
CLEAR gs_final_int ,gs_final_ext ls_material.
  
ENDLOOP.

*  BREAK-POINT.
ENDFORM.
**&---------------------------------------------------------------------*
**& Form F_CREATE_MATERIAL_MASTER
**&---------------------------------------------------------------------*
**& text
**&---------------------------------------------------------------------*
**& -->  p1        text
**& <--  p2        text
**&---------------------------------------------------------------------*
FORM f_create_material_master .
  
DATAls_header LIKE thead,
        lt_lines  
TYPE STANDARD TABLE OF tline WITH HEADER LINE.

  lv_line 
p_strow.
  
LOOP AT gt_final INTO gs_final.
    
CLEAR bapimathead bapi_mara bapi_marax bapi_maktbapi_marcbapi_marcx,
            bapi_mard
bapi_mardxbapi_mpopbapi_mpopxbapi_mbewbapi_mbewx,
            bapi_mvke
bapi_mvkexbapi_mlgtbapi_mlgtxbapi_mpgdbapi_mpgdx.
****************  Feeling Header data
    
IF r_ext abap_true .
      
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
        
EXPORTING
          
input  gs_final-matnr
        
IMPORTING
          
output gs_final-matnr
*     EXCEPTIONS
*         LENGTH_ERROR       = 1
*         OTHERS = 2
        
.
      
IF sy-subrc <> 0.
* Implement suitable error handling here
      
ENDIF.
    
ENDIF .
    bapimathead
-material gs_final-matnr.
    bapimathead
-material_long gs_final-matnr.
    bapimathead
-matl_type gs_final-mtart.
    bapimathead
-ind_sector 'S'.
    bapimathead
-basic_view 'X'.
    bapimathead
-sales_view 'X'.
    bapimathead
-purchase_view 'X'.
    bapimathead
-forecast_view 'X'.
    bapimathead
-storage_view 'X'.
    bapimathead
-account_view 'X'.
    bapimathead
-cost_view 'X'.
    bapimathead
-mrp_view 'X'.
    bapimathead
-work_sched_view 'X'.
    bapimathead
-quality_view 'X'.
**************  End of header data

**************  Feeling Material description : MAKT
    
REFRESH it_makt.
    wa_makt
-langu 'E'.
    wa_makt
-langu_iso 'EN'.
    wa_makt
-matl_desc gs_final-maktx.
    
APPEND wa_makt TO it_makt.
************** ENd of material description

**************  Feelinf material data : MARA
    bapi_mara
-matl_group gs_final-matkl.
    
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
      
EXPORTING
        
input          gs_final-meins
        
language       sy-langu
      
IMPORTING
        
output         gs_final-meins
      
EXCEPTIONS
        unit_not_found 
1
        
OTHERS         2.
    
IF sy-subrc <> 0.
* Implement suitable error handling here
    
ENDIF.

    bapi_mara
-base_uom gs_final-meins.
    bapi_mara
-old_mat_no gs_final-bismt.
*BAPI_MARA- = gs_final-brgew.
    
IF gs_final-ntgew IS NOT INITIAL.
      bapi_mara
-net_weight gs_final-ntgew.

      bapi_mara
-unit_of_wt 'KG'             ." Joy gs_final-gewei.
    
ENDIF.

    bapi_mara
-division gs_final-spart.
    bapi_mara
-item_cat gs_final-mtpos_mara.
    bapi_mara
-trans_grp gs_final-tragr.
*    bapi_mara-minremlife = gs_final-mhdrz.
*    bapi_mara-shelf_life = gs_final-mhdhb.
*    bapi_mara-sled_bbd = gs_final-sled_bbd.
    bapi_mara
-var_ord_un gs_final-vabme.

*    CALL FUNCTION 'CONVERSION_EXIT_PERKZ_INPUT'
*      EXPORTING
*        input  = gs_final-iprkz
*      IMPORTING
*        output = bapi_mara-period_ind_expiration_date.

*    bapi_mara-period_ind_expiration_date = gs_final-iprkz.
    bapi_mara
-batch_mgmt gs_final-xchpf.


    bapi_marax
-matl_group =  'X'.
    bapi_marax
-base_uom =    'X'.
*    bapi_marax-old_mat_no =  'X'.
*BAPI_MARA- = gs_final-brgew.'X'.
    
IF gs_final-ntgew IS NOT INITIAL.
      bapi_marax
-net_weight =  'X'.
      bapi_marax
-unit_of_wt =  'X'.
    
ENDIF.
    bapi_marax
-division =    'X'.
    bapi_marax
-item_cat =    'X'.
    bapi_marax
-trans_grp =   'X'.
    bapi_marax
-minremlife =  'X'.
    bapi_marax
-shelf_life =  'X'.
    bapi_marax
-sled_bbd =    'X'.
    bapi_marax
-var_ord_un 'X'.
    bapi_marax
-period_ind_expiration_date 'X'.
    bapi_marax
-batch_mgmt 'X'.
    bapi_marax
-old_mat_no gs_final-bismt.



*********** Material Data at plant level  : MARC
    bapi_marc
-plant   gs_final-werks.
    bapi_marc
-ctrl_code   gs_final-steuc.
    bapi_marc
-pur_group   gs_final-ekgrp.
*    bapi_marc-profit_ctr   = gs_final-prctr.
    
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      
EXPORTING
        
input  gs_final-prctr
      
IMPORTING
        
output bapi_marc-profit_ctr.

    
IF gs_final-dismm 'PD' OR gs_final-dismm 'VB'.
      bapi_marc
-mrp_group   gs_final-disgr.
      bapi_marc
-mrp_type   gs_final-dismm.
      bapi_marc
-mrp_ctrler   gs_final-dispo.
      bapi_marc
-max_stock   gs_final-mabst.
      bapi_marc
-lotsizekey   gs_final-disls.
      bapi_marc
-proc_type   gs_final-beskz.
      bapi_marc
-inhseprodt   gs_final-dzeit.
    
ELSE.
      bapi_marc
-mrp_type   gs_final-dismm.
    
ENDIF.
    bapi_marc
-loadinggrp   gs_final-ladgr.

    bapi_marc
-serno_prof   gs_final-sernp.
    bapi_marc
-plnd_delry   gs_final-plifz.
    bapi_marc
-gr_pr_time   gs_final-webaz.
*    bapi_marc-period_ind   = gs_final-perkz.
*    bapi_marc-plan_strgp   = gs_final-strgr.
    bapi_marc
-availcheck   '02'."gs_final-mtvfp.
*    bapi_marc-dep_req_id   = gs_final-sbdkz.
    bapi_marc
-production_scheduler   gs_final-fevor.
    bapi_marc
-lot_size   gs_final-losgr.
*    bapi_marc-auto_p_ord   = gs_final-kautb.
    bapi_marc
-prodprof   gs_final-sfcpf.
*BAPI_MARC-   = gs_final-
*BAPI_MARC-   = gs_final-



*BAPI_MARCx-  = ='X'.
*BAPI_MARCx-  = ='X'.
*BAPI_MARCx-  = ='X'.



    bapi_marcx
-plant  gs_final-werks."'X'.
    bapi_marcx
-ctrl_code  'X'.
    bapi_marcx
-pur_group  'X'.
    bapi_marcx
-profit_ctr  'X'.
    bapi_marcx
-loadinggrp  'X'.

    
IF gs_final-dismm 'PD' OR gs_final-dismm 'VB'.
      bapi_marcx
-mrp_group  'X'.
      bapi_marcx
-mrp_type  'X'.
      bapi_marcx
-mrp_ctrler  'X'.
      bapi_marcx
-max_stock   'X'.
      bapi_marcx
-lotsizekey  'X'.
      bapi_marcx
-proc_type  'X'.
      bapi_marcx
-inhseprodt  'X'.
      bapi_marcx
-serno_prof 'X' .
    
ELSE.
      bapi_marcx
-mrp_type  'X'.
    
ENDIF.

    bapi_marcx
-plnd_delry  'X'.
    bapi_marcx
-gr_pr_time  'X'.
    bapi_marcx
-period_ind  'X'.
    bapi_marcx
-plan_strgp  'X'.
    bapi_marcx
-availcheck  'X'.
    bapi_marcx
-dep_req_id  'X'.
    bapi_marcx
-lot_size   'X'.
    bapi_marcx
-production_scheduler  'X'.
    bapi_marcx
-prodprof   'X'.
    bapi_marcx
-auto_p_ord   'X'.


    
IF gs_final-dismm 'VB'.
      bapi_marc
-reorder_pt   gs_final-minbe.
      bapi_marcx
-reorder_pt  'X'.
    
ENDIF.

************* End of Material Data at plant level  : MARC



************* Material Data at Storage Location Level : MARD
    
IF gs_final-mtart NE 'ZSRV'.
      bapi_mard
-plant  gs_final-werks.
      bapi_mard
-stge_loc  gs_final-lgort.
      bapi_mardx
-plant gs_final-werks ."'X'.
      bapi_mardx
-stge_loc gs_final-lgort ."'X'.
    
ENDIF.

************* End of Material Data at Storage Location Level : MARD

************* Forecast Parameters : MPOP
    bapi_mpop
-plant gs_final-werks.
*    bapi_mpop-fore_model = gs_final-prmod.
*    bapi_mpop-hist_vals = gs_final-peran.
*    bapi_mpop-fore_pds = gs_final-anzpr.
*    bapi_mpop-initialize = gs_final-kzini.
*    bapi_mpop-tracklimit = gs_final-siggr.
*    bapi_mpop-model_sp = gs_final-modav.

    bapi_mpopx
-plant gs_final-werks.
    bapi_mpopx
-fore_model 'X'.
    bapi_mpopx
-hist_vals 'X'.
    bapi_mpopx
-fore_pds 'X'.
    bapi_mpopx
-initialize 'X'.
    bapi_mpopx
-tracklimit 'X'.
    bapi_mpopx
-model_sp 'X'.
************* End of  Forecast Parameters : MPOP


************* TAX Data
    
REFRESH it_mlan.
    
CLEAR wa_mlan.
    wa_mlan
-depcountry 'IN'.
    wa_mlan
-depcountry_iso 'IN'.
    wa_mlan
-tax_type_1 'JOSG'.
    wa_mlan
-taxclass_1 gs_final-taxkm.
    wa_mlan
-tax_ind gs_final-taxim.
    
APPEND wa_mlan TO it_mlan.

    wa_mlan
-depcountry 'IN'.
    wa_mlan
-depcountry_iso 'IN'.
    wa_mlan
-tax_type_1 'JOCG'.
    wa_mlan
-taxclass_1 gs_final-taxkm1.
    wa_mlan
-tax_ind gs_final-taxim.
    
APPEND wa_mlan TO it_mlan.

    wa_mlan
-depcountry 'IN'.
    wa_mlan
-depcountry_iso 'IN'.
    wa_mlan
-tax_type_1 'JOIG'.
    wa_mlan
-taxclass_1 gs_final-taxkm2.
    wa_mlan
-tax_ind gs_final-taxim.
    
APPEND wa_mlan TO it_mlan.

    wa_mlan
-depcountry 'IN'.
    wa_mlan
-depcountry_iso 'IN'.
    wa_mlan
-tax_type_1 'JOUG'.
    wa_mlan
-taxclass_1 gs_final-taxkm3.
    wa_mlan
-tax_ind gs_final-taxim.
    
APPEND wa_mlan TO it_mlan.


    wa_mlan
-depcountry 'IN'.
    wa_mlan
-depcountry_iso 'IN'.
    wa_mlan
-tax_type_1 'JTC1'.
    wa_mlan
-taxclass_1 gs_final-taxkm4.
    wa_mlan
-tax_ind gs_final-taxim.
    
APPEND wa_mlan TO it_mlan.
*    wa_mlan-taxclass_2 = gs_final-taxkm1.
*    wa_mlan-taxclass_3 = gs_final-taxkm2.
*    wa_mlan-taxclass_4 = gs_final-taxkm3.


************* End of TAX Data

************* Sales Data : MVKE
    bapi_mvke
-sales_org gs_final-vkorg.
    bapi_mvke
-distr_chan gs_final-vtweg.
    bapi_mvke
-acct_assgt gs_final-ktgrm.
    bapi_mvke
-item_cat gs_final-mtpos.

    
IF r_ext abap_true.
*      bapi_mvke-matl_grp_1 = gs_final-mvgr1.
*      bapi_mvke-matl_grp_2 = gs_final-mvgr2.
*      bapi_mvke-matl_grp_3 = gs_final-mvgr3.
*      bapi_mvke-matl_grp_4 = gs_final-mvgr4.
*      bapi_mvke-matl_grp_5 = gs_final-mvgr5.
    
ENDIF.
    bapi_mvkex
-sales_org gs_final-vkorg.
    bapi_mvkex
-distr_chan gs_final-vtweg.
    bapi_mvkex
-acct_assgt  'X'.
    bapi_mvkex
-item_cat 'X'.

    
IF r_ext abap_true.

      bapi_mvkex
-matl_grp_1 'X'.
      bapi_mvkex
-matl_grp_2 'X'.
      bapi_mvkex
-matl_grp_3 'X'.
      bapi_mvkex
-matl_grp_4 'X'.
      bapi_mvkex
-matl_grp_5 'X'.
    
ENDIF.
************* End of Sales Data : MVKE


************* Valuation Area : MBEW
    bapi_mbew
-val_area gs_final-werks.
    bapi_mbew
-val_class gs_final-bklas.
    bapi_mbew
-price_ctrl gs_final-vprsv_1.
    bapi_mbew
-price_unit gs_final-peinh_1.
    bapi_mbew
-val_cat gs_final-bwtty.
*    bapi_mbew-std_price = gs_final-stprs.
    bapi_mbew
-ml_settle gs_final-mlast.
*BAPI_MBEW- = gs_final-
    bapi_mbewx
-val_area gs_final-werks.
    bapi_mbewx
-val_class 'X'.
    bapi_mbewx
-price_ctrl 'X'.
    bapi_mbewx
-price_unit 'X'.
    bapi_mbewx
-std_price 'X'.
    bapi_mbewx
-val_cat   'X'.
    bapi_mbewx
-ml_settle 'X'.

    
IF gs_final-mtart 'ZSRV'.
      bapi_mbew
-pr_ctrl_pp    'V'.
      bapi_mbewx
-pr_ctrl_pp   'X'.

      bapi_mbew
-price_ctrl    'V'.
      bapi_mbewx
-price_ctrl   'X'.

      bapi_mbew
-pr_ctrl_py    'V'.
      bapi_mbewx
-pr_ctrl_py   'X'.
    
ENDIF.

*BAPI_MBEWX- = 'X'.
************* END of Valuation Area : MBEW

************* Unit of measure
    
REFRESH it_marm it_marmx.
    
CLEAR wa_marm.

*     bapi_mara-base_uom

****     Gross weight
    wa_marm
-unit_of_wt 'KG'.  "bapi_mara-base_uom.
    wa_marm
-alt_unit bapi_mara-base_uom."'KG'.   "bapi_mara-base_uom.
    wa_marm
-gross_wt gs_final-brgew.
    
APPEND wa_marm TO it_marm.

    wa_marmx
-unit_of_wt 'KG'"bapi_mara-base_uom.
    wa_marmx
-alt_unit bapi_mara-base_uom.
    wa_marmx
-gross_wt 'X'."gs_final-brgew.
    
APPEND wa_marmx TO it_marmx.
***
*    CLEAR : wa_marm , wa_marmx.
    
IF gs_final-umren2_1 IS NOT INITIAL AND gs_final-umren3_1 IS NOT INITIAL
      
AND gs_final-umren4_1 IS NOT INITIAL AND gs_final-meinh2_1 IS NOT INITIAL.
      wa_marm
-denominatr gs_final-umren2_1.
      wa_marm
-alt_unit gs_final-umren3_1.
      wa_marm
-numerator gs_final-umren4_1.
      wa_marm
-alt_unit_iso gs_final-meinh2_1.
      
APPEND wa_marm TO it_marm.

      wa_marmx
-denominatr  'X'.
      wa_marmx
-numerator  'X'.
      wa_marmx
-alt_unit gs_final-umren3_1 .
      wa_marmx
-alt_unit_iso gs_final-meinh2_1.
      
APPEND wa_marmx TO it_marmx.
    
ELSE.
*      REFRESH: it_marm , it_marmx.
    
ENDIF.

*    wa_marm-denominatr = gs_final-umren3.
*    wa_marm-numerator = gs_final-umrez3.
*    APPEND wa_marm TO it_marm.
*
*    wa_marm-denominatr = gs_final-umren4.
*    wa_marm-numerator = gs_final-umrez4.
*    APPEND wa_marm TO it_marm.
*    wa_marm-denominatr = gs_final-.
*    APPEND wa_marm TO it_marm.


*************
    
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
      
EXPORTING
        headdata             
bapimathead
        clientdata           
bapi_mara
        clientdatax          
bapi_marax
        plantdata            
bapi_marc
        plantdatax           
bapi_marcx
        forecastparameters   
bapi_mpop
        forecastparametersx  
bapi_mpopx
*       PLANNINGDATA         =
*       PLANNINGDATAX        =
        storagelocationdata  
bapi_mard
        storagelocationdatax 
bapi_mardx
        valuationdata        
bapi_mbew
        valuationdatax       
bapi_mbewx
*       WAREHOUSENUMBERDATA  =
*       WAREHOUSENUMBERDATAX =
        salesdata            
bapi_mvke
        salesdatax           
bapi_mvkex
        storagetypedata      
bapi_mlgt
        storagetypedatax     
bapi_mlgtx
*       FLAG_ONLINE          = ' '
*       FLAG_CAD_CALL        = ' '
*       NO_DEQUEUE           = ' '
*       NO_ROLLBACK_WORK     = ' '
*       CLIENTDATACWM        =
*       CLIENTDATACWMX       =
*       VALUATIONDATACWM     =
*       VALUATIONDATACWMX    =
      
IMPORTING
        
return               it_return
      
TABLES
        materialdescription  
it_makt
        unitsofmeasure       
it_marm
        unitsofmeasurex      
it_marmx
*       INTERNATIONALARTNOS  =
*       MATERIALLONGTEXT     =
        taxclassifications   
it_mlan
*       RETURNMESSAGES       =
*       PRTDATA              =
*       PRTDATAX             =
*       EXTENSIONIN          =
*       EXTENSIONINX         =
*       UNITSOFMEASURECWM    =
*       UNITSOFMEASURECWMX   =
      
.

    
IF it_return-type NE 'E' .
      
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
*   WAIT          =
* IMPORTING
*   RETURN        =
        
.
      wa_msg
-line lv_line.
      wa_msg
-message it_return-message.
      wa_msg
-message_v1 it_return-message_v1.
      wa_msg
-maktx     gs_final-maktx.
      wa_msg
-type it_return-type.

      
APPEND wa_msg TO it_msg.

      
IF gs_final-po_text1 IS NOT INITIAL.
        
CLEARls_header  .
        
REFRESH lt_lines.

        ls_header
-tdobject  'MATERIAL'.
        ls_header
-tdname    gs_final-matnr.
        ls_header
-tdid      'BEST'.
        ls_header
-tdspras   sy-langu.


        
CONCATENATE gs_final-po_text1 ' '
                   
INTO DATA(lv_textSEPARATED BY space .
        lt_lines
-tdline lv_text ."gs_final-po_text.
        
APPEND lt_lines.

        
CLEAR lv_text.
        
CONCATENATE  gs_final-po_text2 ' '
                    
INTO lv_text SEPARATED BY space .
        lt_lines
-tdline lv_text ."gs_final-po_text.
        
APPEND lt_lines.

        
CLEAR lv_text.
        
CONCATENATE  gs_final-po_text3 ' '
                  
INTO lv_text SEPARATED BY space .
        lt_lines
-tdline lv_text ."gs_final-po_text.
        
APPEND lt_lines.

        
CLEAR lv_text.
        
CONCATENATE  gs_final-po_text4 ' '
                  
INTO lv_text SEPARATED BY space .
        lt_lines
-tdline lv_text ."gs_final-po_text.
        
APPEND lt_lines.

        
CLEAR lv_text.
        
CONCATENATE  gs_final-po_text5 ' '
                  
INTO lv_text SEPARATED BY space .
        lt_lines
-tdline lv_text ."gs_final-po_text.
        
APPEND lt_lines.


        
CALL FUNCTION 'SAVE_TEXT'
          
EXPORTING
            
client          sy-mandt
            
header          ls_header
            savemode_direct 
'X'
          
TABLES
            
lines           lt_lines
          
EXCEPTIONS
            
OTHERS          1.
*    REFRESH :lt_lines.
*   CONCATENATE  gs_final-po_text3 gs_final-po_text4
*               INTO DATA(lv_text1) SEPARATED BY space .
*        lt_lines-tdline = lv_text1 ."gs_final-po_text.
*        APPEND lt_lines.
*
*        CALL FUNCTION 'SAVE_TEXT'
*          EXPORTING
*            client          = sy-mandt
*            header          = ls_header
*            savemode_direct = 'X'
*          TABLES
*            lines           = lt_lines
*          EXCEPTIONS
*            OTHERS          = 1.
      
ENDIF.
    
ELSE.
      
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
*   IMPORTING
*     RETURN        =
        
.

      wa_msg
-line lv_line.
      wa_msg
-message it_return-message.
      wa_msg
-message_v1 it_return-message_v1.
      wa_msg
-type it_return-type.
      
APPEND wa_msg TO it_msg.
    
ENDIF.
*    BREAK-POINT.

    lv_line 
lv_line + 1.
  
ENDLOOP.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form F_BUILD_HEADER
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM f_build_header .
  ls_header
-f_name 'Line Number'.
  
APPEND ls_header TO lt_header.
  
CLEAR ls_header.

  ls_header
-f_name 'Type'.
  
APPEND ls_header TO lt_header.
  
CLEAR ls_header.

  ls_header
-f_name 'Material Number'.
  
APPEND ls_header TO lt_header.
  
CLEAR ls_header.

  ls_header
-f_name 'Material Desc'.
  
APPEND ls_header TO lt_header.
  
CLEAR ls_header.

  ls_header
-f_name 'Message'.
  
APPEND ls_header TO lt_header.
  
CLEAR ls_header.

  ls_header
-f_name ''.
  
APPEND ls_header TO lt_header.
  
CLEAR ls_header.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form F_DOWNLOAD_MSG
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM f_download_msg .

  
CALL METHOD cl_gui_frontend_services=>get_desktop_directory
    
CHANGING
      desktop_directory 
lv_desktop
    
EXCEPTIONS
      cntl_error        
1.
  
IF sy-subrc <> 0.
    
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
               
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  
ENDIF.
  
CALL METHOD cl_gui_cfw=>update_view.


  
CONCATENATE lv_desktop '\Shakambari' '\Material Master' '\Material Upload' '_' sy-datum '_' sy-uzeit '.xls' INTO lv_desktop.
*BREAK-POINT.
  
CALL FUNCTION 'GUI_DOWNLOAD'
    
EXPORTING
*     BIN_FILESIZE            =
      filename                
lv_desktop
      filetype                
'DAT'
*     APPEND                  = 'X'
      write_field_separator   
'X'
    
TABLES
      data_tab                
it_msg
      fieldnames              
lt_header
    
EXCEPTIONS
      file_write_error        
1
      no_batch                
2
      gui_refuse_filetransfer 
3
      invalid_type            
4
      no_authority            
5
      unknown_error           
6
      header_not_allowed      
7
      separator_not_allowed   
8
      filesize_not_allowed    
9
      header_too_long         
10
      dp_error_create         
11
      dp_error_send           
12
      dp_error_write          
13
      unknown_dp_error        
14
      access_denied           
15
      dp_out_of_memory        
16
      disk_full               
17
      dp_timeout              
18
      file_not_found          
19
      dataprovider_exception  
20
      control_flush_error     
21
      
OTHERS                  22.
  
IF sy-subrc <> 0.
* Implement suitable error handling here
  
ENDIF.


ENDFORM.