Thursday, February 20, 2020

C223 BDC Program in SAP ABAP.


C223 BDC Program in SAP ABAP.

C223 (Maintain Production Versions)
*&---------------------------------------------------------------------*
*& Report ZCPP_PROD_VER
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zcpp_prod_ver.

DATAlv_matnr    TYPE matnr,
      lv_werks
(4TYPE c.
DATA lv_count TYPE num2.
DATA lv_lines TYPE num2.
DATA lv_count_string TYPE string.
DATA lv_string TYPE string.
DATA date TYPE d.

TYPESBEGIN OF ty_line,
         matnr
(18TYPE c,
         werks
(4)  TYPE c,
         verid
(4)  TYPE c,
         text1
(40TYPE c,
         adatu
(10TYPE c,
         bdatu
(10TYPE c,
         bstmi
(17TYPE c,
         bstma
(17TYPE c,
         stlal
(2)  TYPE c,
         stlan
(1)  TYPE c,
         plnnr
(8)  TYPE c,
         alnal
(2)  TYPE c,
         plnty
(1)  TYPE c,
       
END OF ty_line.

TYPESBEGIN OF ty_header,
         matnr
(18TYPE c,
         werks
(4)  TYPE c,
       
END OF ty_header.
TYPESBEGIN OF ty_mkal,
         matnr 
TYPE matnr,
         werks 
TYPE werks_d,
         verid 
TYPE verid,
       
END OF ty_mkal.

DATA it_line    TYPE TABLE OF ty_line,
       wa_line    
TYPE ty_line,
       it_header  
TYPE TABLE OF ty_header,
       wa_header  
TYPE ty_header,
       it_mkal    
TYPE TABLE OF ty_mkal,
       wa_mkal    
TYPE ty_mkal,
       it_bdcdata 
TYPE TABLE OF bdcdata,
       wa_bdcdata 
TYPE bdcdata,
       v_lines    
TYPE i.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
PARAMETERSp_file TYPE rlgrap-filename,                   " File Path
            p_ses  
TYPE apqi-groupid.                      " Session Name

SELECTION-SCREEN END OF BLOCK b1.



AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  
PERFORM get_filename.

START-OF-SELECTION.
* Upload Excel data into internal table structure of Function module
  
PERFORM load_data.
  
PERFORM create_bdc_records.

  
DESCRIBE TABLE it_line LINES v_lines.

FORM get_filename .
  
CALL FUNCTION 'F4_FILENAME'
    
EXPORTING
      program_name  
syst-cprog
      dynpro_number 
syst-dynnr
      field_name    
' '
    
IMPORTING
      file_name     
p_file.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form LOAD_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM load_data .
  
CALL FUNCTION 'WS_UPLOAD'
    
EXPORTING
*     CODEPAGE                = ' '
      filename                
p_file
      filetype                
'DAT'
*     HEADLEN                 = ' '
*     LINE_EXIT               = ' '
*     TRUNCLEN                = ' '
*     USER_FORM               = ' '
*     USER_PROG               = ' '
*     DAT_D_FORMAT            = ' '
*   IMPORTING
*     FILELENGTH              =
    
TABLES
      data_tab                
it_line
    
EXCEPTIONS
      conversion_error        
1
      file_open_error         
2
      file_read_error         
3
      invalid_type            
4
      no_batch                
5
      unknown_error           
6
      invalid_table_width     
7
      gui_refuse_filetransfer 
8
      customer_error          
9
      no_authority            
10
      
OTHERS                  11.
  
IF sy-subrc <> 0.
* Implement suitable error handling here
  
ENDIF.

  
LOOP AT it_line INTO wa_line.
    
IF lv_matnr IS INITIAL.
      wa_header
-matnr wa_line-matnr.
      wa_header
-werks wa_line-werks.
      lv_matnr 
wa_line-matnr.
      lv_werks 
wa_line-werks.
      
APPEND wa_header TO it_header.
      
CLEAR wa_header.
    
ELSEIF LV_MATNR <> WA_LINE-MATNR OR LV_WERKS <> WA_LINE-WERKS..
*    ELSE.             "03.05.2018
      wa_header
-matnr wa_line-matnr.
      wa_header
-werks wa_line-werks.
      
APPEND wa_header TO it_header.
      
CLEAR wa_header.

      lv_matnr 
wa_line-matnr.
      lv_werks 
wa_line-werks.
    
ENDIF.

  
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form CREATE_BDC_RECORDS
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM create_bdc_records .
  
IF it_line IS NOT INITIAL.

    
PERFORM open_bdc_session.

    
LOOP AT it_header INTO wa_header.
      
REFRESH it_bdcdata[].
      
CLEAR wa_bdcdata.
*Map internal table data with screen field
      
PERFORM field_mapping.
* Inser the transaction
      
PERFORM insert_data.

    
ENDLOOP.
*Close session
    
PERFORM close_group.
  
ENDIF.

ENDFORM.

FORM open_bdc_session .
  
CALL FUNCTION 'BDC_OPEN_GROUP'
    
EXPORTING
*     CLIENT              = SY-MANDT
*     DEST                = FILLER8
      
group               p_ses
*     HOLDDATE            = FILLER8
      keep                
'X'
      user                
sy-uname
*     RECORD              = FILLER1
*     PROG                = SY-CPROG
*     DCPFM               = '%'
*     DATFM               = '%'
*   IMPORTING
*     QID                 =
    
EXCEPTIONS
      client_invalid      
1
      destination_invalid 
2
      group_invalid       
3
      group_is_locked     
4
      holddate_invalid    
5
      internal_error      
6
      queue_error         
7
      running             
8
      system_lock_error   
9
      user_invalid        
10
      
OTHERS              11.
  
IF sy-subrc <> 0.
    
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
           
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  
ELSE.
    
WRITE :'Group Open'(002)  .


  
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FIELD_MAPPING
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM field_mapping .
*  perform open_group.

  
PERFORM bdc_dynpro      USING 'SAPLCMFV' '1000'.
  
PERFORM bdc_field       USING 'BDC_OKCODE'
                                
'=REFR'.
  
PERFORM bdc_field       USING 'BDC_CURSOR'
                                
'MKAL-MATNR'.
  
PERFORM bdc_field       USING 'MKAL-WERKS'
                                wa_header
-werks.
  
PERFORM bdc_field       USING 'MKAL-MATNR'
                                wa_header
-matnr.




  
SELECT matnr werks verid
    
FROM mkal
    
INTO TABLE it_mkal
    
WHERE matnr wa_header-matnr AND werks wa_header-werks.





  lv_lines 
linesit_mkal ).

  
IF lv_lines => 10 AND lv_lines < 20.
    lv_lines 
lv_lines 10.
    
PERFORM bdc_dynpro      USING 'SAPLCMFV' '1000'.
    
PERFORM bdc_field       USING 'BDC_OKCODE'
                                
'=P+'.

  
ELSEIF lv_lines >= 20.
    lv_lines 
lv_lines 20.
    
PERFORM bdc_dynpro      USING 'SAPLCMFV' '1000'.
    
PERFORM bdc_field       USING 'BDC_OKCODE'
                                
'=P+'.

    
PERFORM bdc_dynpro      USING 'SAPLCMFV' '1000'.
    
PERFORM bdc_field       USING 'BDC_OKCODE'
                                
'=P+'.

  
ENDIF.
  lv_count 
lv_lines.
  
LOOP AT it_line INTO wa_line WHERE matnr wa_header-matnr AND werks wa_header-werks.



    
IF lv_count => '10'.
      lv_count 
'01'.
      
PERFORM bdc_dynpro      USING 'SAPLCMFV' '1000'.

      
PERFORM bdc_field       USING 'BDC_OKCODE'
                                  
'=P+'.

    
ENDIF.




    
PERFORM bdc_dynpro      USING 'SAPLCMFV' '1000'.
    
PERFORM bdc_field       USING 'BDC_OKCODE'
                                
'=PRFG'.

    lv_count_string 
lv_count.

    
IF lv_count_string <> 0.
      
CLEAR lv_string.
      
CONCATENATE 'MKAL_EXPAND-MARK(' lv_count_string ')' INTO lv_string.
      
PERFORM bdc_field       USING lv_string
                                  
''.
    
ENDIF.


    lv_count 
lv_count + 01.
    lv_count_string 
lv_count.





    
CLEAR lv_string.
    
CONCATENATE 'MKAL_EXPAND-WERKS(' lv_count_string ')' INTO lv_string.
    
PERFORM bdc_field       USING 'BDC_CURSOR'
                                  lv_string
.




    
CLEAR lv_string.
    
CONCATENATE 'MKAL_EXPAND-MARK(' lv_count_string ')' INTO lv_string.
    
PERFORM bdc_field       USING lv_string
                                  
'X'.

    
CLEAR lv_string.
    
CONCATENATE 'MKAL_EXPAND-MATNR(' lv_count_string ')' INTO lv_string.
    
PERFORM bdc_field       USING lv_string
                                  wa_line
-matnr.

    
CLEAR lv_string.
    
CONCATENATE 'MKAL_EXPAND-VERID(' lv_count_string ')' INTO lv_string.
    
PERFORM bdc_field       USING lv_string
                                  wa_line
-verid.

    
CLEAR lv_string.
    
CONCATENATE 'MKAL_EXPAND-TEXT1(' lv_count_string ')' INTO lv_string.
    
PERFORM bdc_field       USING lv_string
                                  wa_line
-text1.

    
CLEAR lv_string.
    
CONCATENATE 'MKAL_EXPAND-ADATU(' lv_count_string ')' INTO lv_string.
    
PERFORM bdc_field       USING lv_string
                                  wa_line
-adatu.

    
CLEAR lv_string.
    
CONCATENATE 'MKAL_EXPAND-BDATU(' lv_count_string ')' INTO lv_string.
    
PERFORM bdc_field       USING lv_string
                                  wa_line
-bdatu.

    
CLEAR lv_string.
    
CONCATENATE 'MKAL_EXPAND-BSTMI(' lv_count_string ')' INTO lv_string.
    
PERFORM bdc_field       USING lv_string
                                  wa_line
-bstmi.

    
CLEAR lv_string.
    
CONCATENATE 'MKAL_EXPAND-BSTMA(' lv_count_string ')' INTO lv_string.
    
PERFORM bdc_field       USING lv_string
                                  wa_line
-bstma.

    
CLEAR lv_string.
    
CONCATENATE 'MKAL_EXPAND-STLAL(' lv_count_string ')' INTO lv_string.
    
PERFORM bdc_field       USING lv_string
                                  wa_line
-stlal.

    
CLEAR lv_string.
    
CONCATENATE 'MKAL_EXPAND-STLAN(' lv_count_string ')' INTO lv_string.
    
PERFORM bdc_field       USING lv_string
                                  wa_line
-stlan.

*    CLEAR LV_STRING.
*    CONCATENATE 'MKAL_EXPAND-PLNNR(' LV_COUNT_STRING ')' INTO LV_STRING.
*
*    PERFORM BDC_FIELD       USING 'BDC_CURSOR'
*                                  LV_STRING.
    
CLEAR lv_string.
    
CONCATENATE 'MKAL_EXPAND-PLNNR(' lv_count_string ')' INTO lv_string.
    
PERFORM bdc_field       USING lv_string
                                  wa_line
-plnnr.

    
CLEAR lv_string.
    
CONCATENATE 'MKAL_EXPAND-ALNAL(' lv_count_string ')' INTO lv_string.
    
PERFORM bdc_field       USING lv_string
                                  wa_line
-alnal.


    
CLEAR lv_string.
    
CONCATENATE 'MKAL_EXPAND-PLNTY(' lv_count_string ')' INTO lv_string.
    
PERFORM bdc_field       USING lv_string
                                  wa_line
-plnty.



    
PERFORM bdc_dynpro      USING 'SAPMSSY0' '0120'.
    
PERFORM bdc_field       USING 'BDC_OKCODE'
                                  
'=BACK'.





  
ENDLOOP.




  
PERFORM bdc_dynpro      USING 'SAPLCMFV' '1000'.
  
PERFORM bdc_field       USING 'BDC_OKCODE'
                                
'=SAVE'.
  
PERFORM bdc_field       USING 'BDC_CURSOR'
                                
'MKAL-WERKS'.
  
PERFORM bdc_field       USING 'MKAL-WERKS'
                                wa_header
-werks.
  
PERFORM bdc_field       USING 'MKAL-MATNR'
                                wa_header
-matnr.
* perform close_group.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form INSERT_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM insert_data .
  
CALL FUNCTION 'BDC_INSERT'
    
EXPORTING
      tcode            
'C223'
*     POST_LOCAL       = NOVBLOCAL
*     PRINTING         = NOPRINT
*     SIMUBATCH        = ' '
*     CTUPARAMS        = ' '
    
TABLES
      dynprotab        
it_bdcdata
    
EXCEPTIONS
      internal_error   
1
      not_open         
2
      queue_error      
3
      tcode_invalid    
4
      printing_invalid 
5
      posting_invalid  
6
      
OTHERS           7.
  
IF sy-subrc <> 0.
    
WRITE :'DATA NOT INSERTED'.
  
ELSE .
    
WRITE :'DATA INSERTED'.
  
ENDIF.


ENDFORM.
*&---------------------------------------------------------------------*
*& Form CLOSE_GROUP
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM close_group .
  
CALL FUNCTION 'BDC_CLOSE_GROUP'
    
EXCEPTIONS
      not_open    
1
      queue_error 
2
      
OTHERS      3.
  
IF sy-subrc <> 0.
    
MESSAGE 'UNABLE TO CLOSE BDC SESSION !' TYPE 'S' DISPLAY LIKE 'E'.
  
ENDIF.                               " IF sy-subrc ..

  
WRITE 'CLOSED SESSION'(005).
ENDFORM.
*&---------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*      -->P_       text
*      -->P_       text
*&---------------------------------------------------------------------*
FORM bdc_dynpro  USING    VALUE(p_programTYPE bdcdata-program
                          
VALUE(p_screenTYPE bdcdata-dynpro.
  
CLEAR wa_bdcdata.
  wa_bdcdata
-program p_program.
  wa_bdcdata
-dynpro p_screen.
  wa_bdcdata
-dynbegin 'X'.
  
APPEND wa_bdcdata TO it_bdcdata.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form BDC_FIELD
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*      -->P_       text
*      -->P_       text
*&---------------------------------------------------------------------*
FORM bdc_field  USING   " VALUE(P_PROGRAM)
                        
" VALUE(P_DYNPRO)
                        
" VALUE(P_DYNBEGIN)
                         
VALUE(p_fnam)
                         
VALUE(p_fval).
  
CLEARwa_bdcdata.
*IF p_dynbegin = 'X' .
*    wa_bdcdata-program = p_program .
*    wa_bdcdata-dynpro  = p_dynpro .
*    wa_bdcdata-dynbegin = p_dynbegin .
*    APPEND wa_bdcdata TO it_bdcdata.
*  ELSE.
  wa_bdcdata
-fnam p_fnam.
  wa_bdcdata
-fval p_fval.
  
CONDENSE wa_bdcdata-fval.
  
APPEND wa_bdcdata TO it_bdcdata.
*  ENDIF.

ENDFORM.

Wednesday, February 19, 2020

Add postman plugin in chrome browser

How you add postman plugin in chrome browser.

Postman manly Use for POST and GET method. Postman use for API development purpose. There is also discuss how to open postman in chrome and Postman inspector for chrome.



This screen showing Lunch app but if you adding first time its showing add plugin ones you add plugin .

Check Browser    you find app click on this icon and you can find postman icon.




Click on postman icon you get this windows.




In this windows you can check in post method and give yours URL.

http://192.168.129.206:8000/sap/opu/odata/sap/ZREMPLOYEE_SRV/ZEmployeeSet.




Here you find authorization you select authorization type Basic authorization.
Here you give Username and password your sap login windows.
Click on Headers Enter X-CSRF-Token:Fetch here you Genrate new Tocken
Authorization:Basic cm9oaW5pazpkb2Npbmlob3Ix
Content-Type:application/x-www-form-urlencoded
X-CSRF-Token:Fetch.


In above windows After Enter URL and get methods and all authorization click send buttons ones you click send button you get status ok 200 now you services getting response successfully.

Now click on Header and copy Generated Token code.


x-csrf-token →vux6WrcunGe--EpUaMcmGw==
Now you done get method in postman next step i going to explain how to enter records for post lest carefully read and do
Select post methods and select body Enter this code
{
  "d" : {
    "__metadata" : {
      "id" : "http://hpsap.sqrlsep.com:8000/sap/opu/odata/sap/ZREMPLOYEE_SRV/ZEmployeeSet('1')",
      "uri" : "http://hpsap.sqrlsep.com:8000/sap/opu/odata/sap/ZREMPLOYEE_SRV/ZEmployeeSet('1')",
      "type" : "ZEMPLOYEE_SRV.ZEmployee"
    },
    "EmpId" : "157",
    "EmpName" : "rakesh",
    "EmpAddress" : "lucknow",
    "EmpDesignation" : "sap scrm",
    "EmpType" : "sap abap"
  }
}


Click on Header and paste Token key
X-CSRF-Token:vux6WrcunGe--EpUaMcmGw==
Content-Type:application/json

After updating all records click on the send buttons.

Now you can get response like create.


 So here you done get and post methods in in postman. So hope you enjoy this tutorial.