BDC Sample Program

Click here to download BDC CODE .

REPORT zmmat_mast

NO STANDARD PAGE HEADING LINE-SIZE 200.

*———————————————————————*

*Programmer : Niraj Visnoi *

*Website : http://sap.niraj.tripod.com *

*Email : niraj_visnoi@rediffmail.com *

*———————————————————————*

TABLES :mara, marc.

*———————————————————————*

* INTERNAL TABLES *

*———————————————————————*

DATA: BEGIN OF bdcdata OCCURS 0.

INCLUDE STRUCTURE bdcdata.

DATA: END OF bdcdata.

DATA:BEGIN OF itab_basic OCCURS 0,

matnr LIKE mara-matnr,

zzmatnr LIKE mara-matnr,

END OF itab_basic.

DATA:BEGIN OF itab_mrp OCCURS 0,

matnr LIKE mara-matnr,

werks LIKE marc-werks,

zzgpind LIKE marc-zzgpind,

zzdate(10) type C ,

END OF itab_mrp.

DATA: BEGIN OF tab_mara OCCURS 0.

INCLUDE STRUCTURE mara.

DATA: END OF tab_mara.

DATA: BEGIN OF tab_marc OCCURS 0.

INCLUDE STRUCTURE marc.

DATA: END OF tab_marc.

DATA: ertab_basic LIKE itab_basic OCCURS 0 WITH HEADER LINE.

DATA: ertab_mrp LIKE itab_mrp OCCURS 0 WITH HEADER LINE.

DATA : v_ctr TYPE i VALUE 1. “Ctr for no orecords

DATA : v_group(12) . “BDC Group Name

DATA : v_group_ctr(3) TYPE n . “BDC Group Counter

DATA : v_no_lines TYPE i.

DATA: v_grpname(10) TYPE c.

SELECTION-SCREEN BEGIN OF BLOCK dt-entry

WITH FRAME TITLE text-002.

selection-screen begin of line .

selection-screen comment 01(49) text-101.

parameters : p_basic radiobutton group r1.

selection-screen end of line.

selection-screen begin of line .

selection-screen comment 01(49) text-102.

parameters : p_mrp2 radiobutton group r1.

selection-screen end of line.

*

*PARAMETERS :

* p_basic RADIOBUTTON GROUP r1,

* p_mrp2 RADIOBUTTON GROUP r1.

SELECTION-SCREEN END OF BLOCK dt-entry.

SELECTION-SCREEN SKIP 1.

SELECTION-SCREEN BEGIN OF BLOCK fl-info

WITH FRAME TITLE text-003.

PARAMETER : p_dlhead AS CHECKBOX . “DEFAULT ‘X’.

SELECTION-SCREEN END OF BLOCK fl-info.

*

SELECTION-SCREEN SKIP 1.

PARAMETER : p_max TYPE i DEFAULT ‘5000’ . “No of rec / session

SET PF-STATUS ‘UPLOAD’.

AT USER-COMMAND .

IF sy-ucomm = ‘UPLOAD’ .

IF p_basic = ‘X’.

IF NOT itab_basic[] IS INITIAL .

PERFORM bdc_upload_basic.

ENDIF.

WRITE:/10 ‘Please execute the session in SM35 to Upload the data’.

FORMAT INTENSIFIED OFF COLOR OFF .

REFRESH itab_basic . CLEAR itab_basic .

SET PF-STATUS space.

ENDIF.

IF p_mrp2 = ‘X’.

IF NOT itab_mrp[] IS INITIAL .

PERFORM bdc_upload_mrp.

ENDIF..

WRITE:/10 ‘Please execute the session in SM35 to Upload the data’.

REFRESH itab_mrp . CLEAR itab_mrp .

SET PF-STATUS space.

ENDIF.

ENDIF.

START-OF-SELECTION.

IF p_basic = ‘X’.

CALL FUNCTION ‘UPLOAD’

EXPORTING

* CODEPAGE = ‘ ‘

filename = ‘C:\mm02_basic.txt ‘

filetype = ‘DAT’

TABLES

data_tab = itab_basic.

IF p_dlhead EQ ‘X’.

READ TABLE itab_basic INDEX 1.

DELETE itab_basic INDEX 1.

CLEAR itab_basic.

ENDIF.

PERFORM blank_data_validation.

ENDIF.

IF p_mrp2 = ‘X’.

* v_grpname = ‘MRP2’.

CALL FUNCTION ‘UPLOAD’

EXPORTING

* CODEPAGE = ‘ ‘

filename = ‘C:\mm02_mrp.txt ‘

filetype = ‘DAT’

TABLES

data_tab = itab_mrp.

IF p_dlhead EQ ‘X’.

READ TABLE itab_mrp INDEX 1.

DELETE itab_mrp INDEX 1.

CLEAR itab_mrp.

ENDIF.

PERFORM valid_plant_check.

ENDIF.

IF sy-subrc 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

PERFORM display_data.

END-OF-SELECTION.

*———————————————————————-

*

* Start new screen

*

*———————————————————————-

*

FORM bdc_dynpro USING program dynpro.

CLEAR bdcdata.

bdcdata-program = program.

bdcdata-dynpro = dynpro.

bdcdata-dynbegin = ‘X’.

APPEND bdcdata.

ENDFORM.

*———————————————————————-

*

* Insert field

*

*———————————————————————-

*

FORM bdc_field USING fnam fval.

CLEAR bdcdata.

bdcdata-fnam = fnam.

bdcdata-fval = fval.

APPEND bdcdata.

ENDFORM.

*&———————————————————————*

*& Form blank_data_validation

*&———————————————————————*

* text

*———————————————————————-*

* –> p1 text

* <– p2 text

*———————————————————————-*

FORM blank_data_validation.

LOOP AT itab_basic.

IF itab_basic-matnr IS INITIAL OR itab_basic-zzmatnr IS INITIAL.

MOVE-CORRESPONDING itab_basic TO ertab_basic .

APPEND ertab_basic . CLEAR ertab_basic .

DELETE itab_basic.

CLEAR itab_basic.

CONTINUE.

ENDIF.

SELECT SINGLE * INTO tab_mara FROM mara WHERE matnr = itab_basic-matnr

.

IF sy-subrc 0.

MOVE-CORRESPONDING itab_basic TO ertab_basic .

APPEND ertab_basic . CLEAR ertab_basic .

DELETE itab_basic.

CLEAR itab_basic.

CONTINUE.

ENDIF.

*

ENDLOOP.

ENDFORM. ” dt_qty_validation

*&———————————————————————*

*& Form CALL_BDC_CLOSE_GROUP

*&———————————————————————*

* text

*———————————————————————-*

* –> p1 text

* P_0545 text

*———————————————————————-*

FORM call_bdc_insert USING v_tran_code.

DATA: xmode VALUE ‘E’.

CALL FUNCTION ‘BDC_INSERT’

EXPORTING

tcode = v_tran_code

TABLES

dynprotab = bdcdata

EXCEPTIONS

internal_error = 1

not_open = 2

queue_error = 3.

IF sy-subrc NE 0.

WRITE: /5 ‘BDC insert GROUP FAILED, return code = ‘, sy-subrc.

EXIT.

ENDIF.

ENDFORM. ” CALL_BDC_INSERT

*&———————————————————————*

*& Form display_data

*&———————————————————————*

* text

*———————————————————————-*

* –> p1 text

* p1 text

* p1 text

* p1 text

* p1 text

* p1 text

* <– p2 text

*———————————————————————–*

FORM valid_plant_check.

LOOP AT itab_mrp.

IF itab_mrp-matnr IS INITIAL OR itab_mrp-werks IS INITIAL OR

itab_mrp-zzgpind IS INITIAL.

MOVE-CORRESPONDING itab_mrp TO ertab_mrp .

APPEND ertab_mrp . CLEAR ertab_mrp .

DELETE itab_mrp.

CLEAR itab_mrp.

CONTINUE.

ENDIF.

SELECT SINGLE * INTO tab_marc FROM marc WHERE matnr = tab_marc-matnr

AND werks = itab_mrp-werks . .

IF sy-subrc = 0.

MOVE-CORRESPONDING itab_mrp TO ertab_mrp .

APPEND ertab_mrp . CLEAR ertab_mrp .

DELETE itab_mrp.

CLEAR itab_mrp.

CONTINUE.

ENDIF.

ENDLOOP.

ENDFORM. ” valid_plant_check

*———————————————————————*

* FORM open_group *

*———————————————————————*

* …….. *

*———————————————————————*

FORM open_group USING p_grp .

* open batchinput group

CALL FUNCTION ‘BDC_OPEN_GROUP’

EXPORTING

client = sy-mandt

group = p_grp

user = sy-uname

keep = ‘X’.

ENDFORM

Advertisements
Categories: ABAP, BDC | 1 Comment

Post navigation

One thought on “BDC Sample Program

  1. Regularly scheduled meals (every few hours) have also proven more wholesome than infrequent,
    haphazard ones. Opioids can offer short, intermediate and longer
    lasting analgesia, dependant on the particular properties of the medication (( An opioid
    is really a chemical that work well by binding to opioid receptors, which are found principally inside neurological
    system and also the gastrointestinal tract. * Involving inside
    the growth process and changes that is certainly never ending and self-initiated.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: