Friday, March 15, 2019

RFC Function Module Create step by step in sap ABAP.


  • RFC Function Module Create step by step in sap ABAP.
  • Go to T-code-SE37
  • At first created function group.
  • If function group not created that time first create function group.
  • At first go to T-code-:-SE37=>Go to=>Function group=>Create Group



  1.  If function group already has created so you can selected your created function group.


  • After that give function module name next select create option.

  • After that select remote enable module option and also give the short text.   Program name and include option automatically created.


  •  Go to import tab


  •  Go to tables tab


BAPI MATERIAL CREATION........................

After that go to Source Code

FUNCTION zrth_pre_ord_chek_list.
*"-----------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(I_AUFNR) TYPE  AUFNR
*"  TABLES
*"      GT_FINAL STRUCTURE  ZPP_PRODORD_PRE_CHK
*"      GT_FINAL_AUIT STRUCTURE  ZPPRTHID_VALUE
*"      GT_FINAL_AREA STRUCTURE  ZPP_RTH_OP_AREA
*"------------------------------------------------------
*******************************************************
*              BAPI RELATED DATA                      *
*******************************************************
  
DATA:lv_werks TYPE werks_d.
  
DATAnumber           TYPE  bapi_order_key-order_number,
        collective_order 
TYPE  bapi_order_func_cntrl-collective_order,
        order_objects    
TYPE  bapi_pp_order_objects,
        
return           TYPE  bapireturn1,
        return2          
TYPE  bapiret2.

  
DATA:header           TYPE TABLE OF  bapi_order_header1,
       ls_header        
TYPE bapi_order_header1,
       
position         TYPE TABLE OF  bapi_order_item,
       ls_position      
TYPE bapi_order_item,
       sequence         
TYPE TABLE OF  bapi_order_sequence,
       ls_sequence      
TYPE  bapi_order_sequence,
       operation        
TYPE TABLE OF  bapi_order_operation1,
       ls_operation     
TYPE bapi_order_operation1,
       trigger_point    
TYPE TABLE OF  bapi_order_trigger_point,
       ls_trigger_point 
TYPE bapi_order_trigger_point,
       
component        TYPE TABLE OF  bapi_order_component,
       ls_component     
TYPE bapi_order_component,
       prod_rel_tool    
TYPE TABLE OF  bapi_order_prod_rel_tools,
       ls_prod_rel_tool 
TYPE  bapi_order_prod_rel_tools.

  
DATAi_insplot        TYPE  qibplosnr,
        i_inspoper       
TYPE  qibpvornr,
        lt_inspchar      
TYPE TABLE OF  bapi2045l3,
        ls_inspchar      
TYPE bapi2045l3,
        lt_insppointdata 
TYPE TABLE OF  bapi2045l4,
        ls_insppointdata 
TYPE bapi2045l4.

  
DATAlt_char_results   TYPE TABLE OF  bapi2045d2,
        lt_sample_results 
TYPE TABLE OF  bapi2045d3,
        lt_single_results 
TYPE TABLE OF  bapi2045d4,
        returntable       
TYPE TABLE OF  bapiret2.

*****************************************************
*                       Get Result                  *
*****************************************************
  
IF i_aufnr IS NOT INITIAL.
    
SELECT aufnr
           stlnr
           stlal
      
FROM afko
      
INTO TABLE gt_afko
      
WHERE aufnr EQ i_aufnr.

    
IF gt_afko[] IS NOT INITIAL.
      
SELECT  matnr
              werks
              stlal
              maktx
              stlnr
        
FROM zpp_bom
        
INTO TABLE gt_zpp_bom
*       INTO CORRESPONDING FIELDS OF TABLE gt_final
        
FOR ALL ENTRIES IN gt_afko
        
WHERE stlal  gt_afko-stlal
          
AND stlnr gt_afko-stlnr.

      
SELECT *
        
FROM zpprthid
        
INTO CORRESPONDING FIELDS OF TABLE gt_zppr.

      
IF gt_zppr[] IS NOT INITIAL.
        
SELECT z_op_type_id
               z_op_type_desc
               z_op_value
          
FROM zpprthid_value
          
INTO TABLE gt_zpprval
          
FOR ALL ENTRIES IN gt_zppr
          
WHERE z_op_type_id gt_zppr-z_op_type_id.
      
ENDIF.
    
ENDIF.

*******************************************************
*Call Bapi For Output Details of a Production Order   *
*******************************************************
    
number i_aufnr.
    order_objects
-header         'X'.
    order_objects
-positions      'X'.
*   order_objects-sequences      = 'X'.
    order_objects
-operations     'X'.
*   order_objects-components     = 'X'.
*   order_objects-prod_rel_tools = 'X'.
*   order_objects-trigger_points = 'X'.
*   order_objects-suboperations  = 'X'.

    
CALL FUNCTION 'BAPI_PRODORD_GET_DETAIL'
      
EXPORTING
        
number           number
        collective_order 
collective_order
        order_objects    
order_objects
      
IMPORTING
        
return           return2
      
TABLES
        
header           header
        
position         position
        sequence         
sequence
        operation        
operation
        trigger_point    
trigger_point
        
component        component
        prod_rel_tool    
prod_rel_tool.


    
IF sy-subrc EQ 0.
      
READ TABLE header INTO ls_header INDEX 1.
      
IF sy-subrc EQ 0.
        lv_werks 
ls_header-production_plant.
      
ENDIF.

      
IF lv_werks IS NOT INITIAL.
        
SELECT *
          
FROM zrth_area_id
          
INTO CORRESPONDING FIELDS OF TABLE gt_zarea.

        
IF gt_zarea[] IS NOT INITIAL.
          
SELECT plant
                 matnr
                 zsection
                 z_section_desc
                 z_areaid
                 z_areaname
                 z_checklist_id
                 z_chk_list_ty_desc
                 z_remarks
                 zflag
            
FROM zpp_rth_op_area
            
INTO CORRESPONDING FIELDS OF TABLE gt_zarea_val
            
FOR ALL ENTRIES IN gt_zarea
            
WHERE z_areaid gt_zarea-z_areaid.
        
ENDIF.
      
ENDIF.
    
ENDIF.
  
ENDIF.
*****************************************************
****                   This is order                *
*****************************************************
  
LOOP AT gt_afko INTO gs_afko.
    gs_final
-aufnr  =  gs_afko-aufnr.
    
READ TABLE header INTO ls_header INDEX 1.
    
IF sy-subrc EQ 0.
      gs_final
-plant  ls_header-production_plant.
    
ENDIF.
    
READ TABLE gt_zpp_bom INTO gs_zpp_bom WITH KEY stlal gs_afko-stlal
                                                   stlnr 
gs_afko-stlnr.
    
IF sy-subrc EQ 0.
      gs_final
-material          gs_zpp_bom-matnr.
      gs_final
-material_text  gs_zpp_bom-maktx.
    
ENDIF.
    
APPEND gs_final TO gt_final.
    
CLEARgs_afkogs_final.
  
ENDLOOP.
*****************************************************
****                   This is adit                 *
*****************************************************
  
LOOP AT gt_zpprval INTO gs_zpprval.
    gs_final_auit
-z_op_type_id      gs_zpprval-z_op_type_id.
    gs_final_auit
-z_op_type_desc  gs_zpprval-z_op_type_desc.
    gs_final_auit
-z_op_value          gs_zpprval-z_op_value.
    
APPEND gs_final_auit TO gt_final_auit.
    
CLEAR:gs_final_auit,gs_zpprval.
  
ENDLOOP.
*****************************************************
****                   This is area                 *
*****************************************************
  
LOOP AT gt_zarea_val INTO gs_zarea_val.
    gs_final_area
-plant                     gs_zarea_val-plant.
    gs_final_area
-matnr                    gs_zarea_val-matnr.
    gs_final_area
-zsection                gs_zarea_val-zsection.
    gs_final_area
-z_section_desc     gs_zarea_val-z_section_desc.
    gs_final_area
-z_areaid               gs_zarea_val-z_areaid.
    gs_final_area
-z_areaname         gs_zarea_val-z_areaname.
    gs_final_area
-z_checklist_id     gs_zarea_val-z_checklist_id.
    gs_final_area
-z_chk_list_ty_desc gs_zarea_val-z_chk_list_ty_desc.
    gs_final_area
-z_remarks          gs_zarea_val-z_remarks.
    gs_final_area
-zflag                  gs_zarea_val-zflag.
    
APPEND gs_final_area TO gt_final_area.
    
CLEAR:gs_final_area,gs_zarea_val.
  
ENDLOOP.

ENDFUNCTION.

Thursday, February 28, 2019

BADI For Material check In SAP ABAP.

BADI FOR MATERIAL CHECK

The Requirement for information message .When you creating a material if material group is A10 and division is: 05.
(This is only use for: As it needs two information for the material and user wants information message while saving the material. we can’t use field exit for this).
First step:
How to find appropriate BADI for this requirement??
Go to T-Code:--SE24
PUT:-- CL_EXITHANDLER.
NEXT:-Click display button.
Add the break- point into Class CL_EXITHANDLER’s GET_INSTANCE method.
Next:-Go to T-code MM01, After that you create a material and try to save it. it stops at many locations with different values of EXIT_NAME. (After checking into Se18 we got the BADI_MATERIAL_CHECK which can be used for our requirement.
    §  It has a method CHECK_DATA which is called before saving the material.
    §  It also has WMARA table as input data (Material Group and Division comes in MARA table).
Step 2:
Go to Transaction code SE18.
Open BADI: BADI_MATERIAL_CHECK.
Go to menu option Implementation  Create.
Step 3:
Put the name of implementation as ZMM_MAT_CHECK.
Step 4:
Double click on the method CHECK_DATA.If you notice the input parameters we have many data related to batch, material and storage location etc.
For our requirement we need material group and division which exist in WMARA. Put the below code inside the method then activate the class and method.

IF WMARA-MATKL EQ
‘A10’
AND WMARA-SPART EQ
’05’.
message
‘Material creation for this Group should be avoided for animal products!!’
TYPE
‘I’.

ENDIF.
This code is just checks the material group and division.
Step 5:
Go back and activate the implementation.
Step 6:
For this go to transaction MM01 and try to create a material.
(if you are confused use material name as CH004 ,
Industry sector as Animal Health and
Material Type as Beverages )
Click on the ENTER Button and from the view select BASIC DATA 1.


Wednesday, February 27, 2019

Delivery report In SAP ABAP.

SAP ABAP DELIVERY REPORT.

READ MORE BDC DETAILS

REPORT  ZSW_DEL_1 NO STANDARD PAGE HEADING LINE-COUNT 37(3).

TABLES VBAK,VBAP,VBFA,LIKP,LIPS.

TYPESBEGIN OF TY_VBAK,
        VBELN TYPE VBAK-VBELN,
        VKORG TYPE VBAK-VKORG,
        VTWEG TYPE VBAK-VTWEG,
        SPART TYPE VBAK-SPART,
      END OF TY_VBAK.
TYPESBEGIN OF TY_VBAP,
        VBELN TYPE VBAP-VBELN,
        POSNR TYPE VBAP-POSNR,
        MATNR TYPE VBAP-MATNR,
        ZMENG TYPE VBAP-ZMENG,
        NETPR TYPE VBAP-NETPR,
      END OF TY_VBAP.
TYPESBEGIN OF TY_LIKP,
        VBELN TYPE LIKP-VBELN,
      END OF TY_LIKP.
TYPESBEGIN OF TY_LIPS,
        VBELN TYPE LIPS-VBELN,
        POSNR TYPE LIPS-POSNR,
        LFIMG TYPE LIPS-LFIMG,
        NETPR TYPE LIPS-NETPR,
      END OF TY_LIPS.
TYPESBEGIN OF TY_VBFA,
        VBELV TYPE VBFA-VBELV,
        POSNV TYPE VBFA-POSNV,
        VBELN TYPE VBFA-VBELN,
        POSNN TYPE VBFA-POSNN,
        VBTYP_N TYPE VBFA-VBTYP_N,
      END OF TY_VBFA.
TYPESBEGIN OF TY_FINAL,
        VBELN TYPE VBAP-VBELN,
        POSNR TYPE VBAP-POSNR,
        MATNR TYPE VBAP-MATNR,
        ZMENG TYPE VBAP-ZMENG,
        NETPR TYPE VBAP-NETPR,
        VBELN1 TYPE LIPS-VBELN,
        POSNR1 TYPE LIPS-POSNR,
        LFIMG TYPE LIPS-LFIMG,
        NETPR1 TYPE LIPS-NETPR,
      END OF TY_FINAL.

DATA IT_VBAK TYPE TABLE OF TY_VBAK,
       WA_VBAK TYPE TY_VBAK.
DATA IT_VBAP TYPE TABLE OF TY_VBAP,
       WA_VBAP TYPE TY_VBAP.
DATA IT_LIKP TYPE TABLE OF TY_LIKP,
       WA_LIKP TYPE TY_LIKP.
DATA IT_LIPS TYPE TABLE OF TY_LIPS,
       WA_LIPS TYPE TY_LIPS.
DATA IT_VBFA TYPE TABLE OF TY_VBFA,
       WA_VBFA TYPE TY_VBFA.
DATA IT_FINAL TYPE TABLE OF TY_FINAL,
       WA_FINAL TYPE TY_FINAL.

DATA V_TITLE TYPE STRING.
DATA V_FNAME TYPE STRING.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS S_VBELN FOR VBAK-VBELN NO-EXTENSION.
SELECT-OPTIONS S_VKORG FOR VBAK-VKORG NO INTERVALS NO-EXTENSION.
SELECT-OPTIONS S_VTWEG FOR VBAK-VTWEG NO INTERVALS NO-EXTENSION.
SELECT-OPTIONS S_SPART FOR VBAK-SPART NO INTERVALS NO-EXTENSION.
SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN SKIP.

PARAMETERS P_FILE TYPE RLGRAP-FILENAME.
PARAMETERS DOWNLOAD AS CHECKBOX.

INITIALIZATION.
  V_TITLE 'THIS IS SALES DOCUMENT:ITEM DATA AND DELIVERY DETAILS'.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
  PERFORM GET_FILE_PATH.

AT SELECTION-SCREEN ON HELP-REQUEST FOR P_FILE.
  PERFORM GET_HELP_FOR_FILE_PATH.

AT SELECTION-SCREEN.
  PERFORM VALIDATE_SALESDOCUMENT.
  PERFORM VALIDATE_SALESORGANIZATION.
  PERFORM VALIDATE_DISTRIBUTIONCHANNEL.
  PERFORM VALIDATE_DIVISION.

START-OF-SELECTION.
  PERFORM GET_DATA.
  PERFORM DISPLAY_DATA.
  PERFORM DOWNLOAD_DATA.

END-OF-SELECTION.

TOP-OF-PAGE.
  PERFORM DISPLAY_HEADING.

END-OF-PAGE.
  PERFORM DISPLAY_FOOTER.


FORM GET_FILE_PATH .
  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    EXPORTING
      PROGRAM_NAME  SYST-REPID
      DYNPRO_NUMBER SYST-DYNNR
      FIELD_NAME    P_FILE
    CHANGING
      FILE_NAME     P_FILE.
ENDFORM.                    " GET_FILE_PATH

FORM GET_HELP_FOR_FILE_PATH .
  MESSAGE 'PLEASE SELECT THE FILE PATH' TYPE 'I'.
ENDFORM.                    " GET_HELP_FOR_FILE_PATH

FORM VALIDATE_SALESDOCUMENT .
  SELECT SINGLE VBELN
         FROM VBAK
         INTO WA_VBAK
         WHERE VBELN IN S_VBELN.
  IF SY-SUBRC <> 0.
    MESSAGE 'THIS IS INVALID SALES DOCUMENT NO' TYPE 'I'.
  ENDIF.
ENDFORM.                    " VALIDATE_SALESDOCUMENT

FORM VALIDATE_SALESORGANIZATION .
  SELECT VKORG
    FROM VBAK
    INTO WA_VBAK
    UP TO ROWS
    WHERE VKORG IN S_VKORG.
  ENDSELECT.
  IF SY-SUBRC <> 0.
    MESSAGE 'THIS IS INVALID SALES ORGANIZATION' TYPE 'I'.
  ENDIF.
ENDFORM.                    " VALIDATE_SALESORGANIZATION

FORM VALIDATE_DISTRIBUTIONCHANNEL.
  SELECT VTWEG
    FROM VBAK
    INTO WA_VBAK
    UP TO ROWS
    WHERE VTWEG IN S_VTWEG.
  ENDSELECT.
  IF SY-SUBRC <> 0.
    MESSAGE 'THIS IS INVALID DISTRIBUTION CHANNEL' TYPE 'I'.
  ENDIF.
ENDFORM.                    " VALIDATE_DISTRIBUTIONCHANNEL

FORM VALIDATE_DIVISION .
  SELECT SPART
    FROM VBAK
    INTO WA_VBAK
    UP TO ROWS
    WHERE SPART IN S_SPART.
  ENDSELECT.
  IF SY-SUBRC <> 0.
    MESSAGE 'THIS IS INVALID DIVISION' TYPE 'I'.
  ENDIF.
ENDFORM.                    " VALIDATE_DIVISION

***********************************
READ MORE BDC DETAILS  *
***********************************

FORM GET_DATA .
  SELECT VBELN
         VKORG
         VTWEG
         SPART
    FROM VBAK
    INTO TABLE IT_VBAK
    WHERE VBELN IN S_VBELN
    AND VKORG IN S_VKORG
    AND VTWEG IN S_VTWEG
    AND SPART IN S_SPART.
  IF IT_VBAK IS NOT INITIAL.

    SELECT VBELN
           POSNR
           MATNR
           ZMENG
           NETPR
      FROM VBAP
      INTO TABLE IT_VBAP
      FOR ALL ENTRIES IN IT_VBAK
      WHERE VBELN IT_VBAK-VBELN.

    SELECT VBELV
           POSNV
           VBELN
           POSNN
           VBTYP_N
      FROM VBFA
      INTO TABLE IT_VBFA
      FOR ALL ENTRIES IN IT_VBAP
      WHERE VBELV IT_VBAP-VBELN
        AND VBTYP_N 'J'.

    SELECT VBELN
      FROM LIKP
      INTO TABLE IT_LIKP
      FOR ALL ENTRIES IN IT_VBFA
      WHERE VBELN IT_VBFA-VBELN.

    SELECT VBELN
           POSNR
           LFIMG
           NETPR
      FROM LIPS
      INTO TABLE IT_LIPS
      FOR ALL ENTRIES IN IT_LIKP
      WHERE VBELN IT_LIKP-VBELN.

    SORT IT_VBAP.
    SORT IT_LIPS.

    LOOP AT IT_VBFA INTO WA_VBFA.
      READ TABLE IT_LIPS INTO WA_LIPS WITH KEY VBELN WA_VBFA-VBELN
                                               POSNR WA_VBFA-POSNN
                                               BINARY SEARCH.
      READ TABLE IT_VBAP INTO WA_VBAP WITH KEY VBELN WA_VBFA-VBELV
                                               POSNR WA_VBFA-POSNV
                                               BINARY SEARCH.
      WA_FINAL-VBELN  WA_VBAP-VBELN.
      WA_FINAL-POSNR  WA_VBAP-POSNR.
      WA_FINAL-MATNR  WA_VBAP-MATNR.
      WA_FINAL-ZMENG  WA_VBAP-ZMENG.
      WA_FINAL-NETPR  WA_VBAP-NETPR.
      WA_FINAL-VBELN1 WA_LIPS-VBELN.
      WA_FINAL-POSNR1 WA_LIPS-POSNR.
      WA_FINAL-LFIMG  WA_LIPS-LFIMG.
      WA_FINAL-NETPR1 WA_LIPS-NETPR.
      APPEND WA_FINAL TO IT_FINAL.
      CLEAR WA_FINAL.
    ENDLOOP.
  ENDIF.
ENDFORM.                    " GET_DATA

FORM DISPLAY_DATA .
  LOOP AT IT_FINAL INTO WA_FINAL.
    WRITE / WA_FINAL-VBELN,
              WA_FINAL-POSNR,
              WA_FINAL-MATNR,
              WA_FINAL-ZMENG,
              WA_FINAL-NETPR,
              WA_FINAL-VBELN1,
              WA_FINAL-POSNR1,
              WA_FINAL-LFIMG,
              WA_FINAL-NETPR.
  ENDLOOP.
ENDFORM.                    " DISPLAY_DATA

FORM DOWNLOAD_DATA .
  IF DOWNLOAD 'X'.
    V_FNAME P_FILE.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        FILENAME              V_FNAME
        FILETYPE              'ASC'
        WRITE_FIELD_SEPARATOR 'X'
      TABLES
        DATA_TAB              IT_FINAL.
    IF SY-SUBRC 0.
      MESSAGE 'SUCCESSFULLY DOWNLOADED' TYPE 'I'.
    ENDIF.
  ENDIF.
ENDFORM.                    " DOWNLOAD_DATA

FORM DISPLAY_HEADING .
  WRITESY-ULINE.
  WRITE :/45 V_TITLE.
  WRITESY-ULINE.
ENDFORM.                    " DISPLAY_HEADING

FORM DISPLAY_FOOTER .
  WRITESY-ULINE.
  WRITE :/45 'IBM'.
  WRITESY-ULINE.
ENDFORM.                    " DISPLAY_FOOTER


READ MORE BDC DETAILS.........