Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Reg BDC

Former Member
0 Likes
526

Hello friends,

Could any give me program for Sales order and purchase order for both call transaction and Session method with error handling.

3 REPLIES 3
Read only

Former Member
0 Likes
492

Hi Sunil,

Please check Naveen's code from the following thread :

https://forums.sdn.sap.com/click.jspa?searchID=7192985&messageID=1629601

Thanks,

Reward If Helpful.

Read only

Former Member
0 Likes
492

Hi,

Please find the code below,

************************************************************************

  • PROGRAM NAME: ZSDRBD55 AUTHOR: Sridhar Pulicherla(SP34316)

  • CREATE DATE : 03/26/07

  • TRANSACTION :

*

  • DESCRIPTION : Program to change the orders from the excel file,

  • adding another line to the exsisting order

  • (Copy of the old program from 4.7)

  • EXTERNAL

  • REFERENCES : None

*

  • MODIFICATIONS:

  • DATE PGMR MODIFICATION

  • mm/dd/yy xxxxxxxxxxxx (brief desc.; include Remedy Ticket #)

************************************************************************

REPORT zsdrbd55 NO STANDARD PAGE HEADING MESSAGE-ID zs .

DATA : l_vbeln LIKE vbak-vbeln,

l_matnr LIKE mara-matnr,

l_werks LIKE t001w-werks,

l_pstyv LIKE vbap-pstyv,

l_vbeln1 LIKE vbak-vbeln,

l_flag(1) TYPE c,

l_matnr1 LIKE mara-matnr.

DATA: group LIKE apqi-groupid VALUE 'ZSDRBD55'.

DATA: l_finame TYPE rlgrap-filename.

DATA: t_tab TYPE alsmex_tabline OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF t_vbak OCCURS 0,

vbeln TYPE vbak-vbeln,

matnr TYPE vbap-matnr,

werks TYPE vbap-werks,

menge TYPE vbap-zmeng,

pstyv type vbap-pstyv,

END OF t_vbak,

begin of t_vbap occurs 0,

vbeln type vbap-vbeln,

posnr type vbap-posnr,

end of t_vbap.

DATA: BEGIN OF t_error OCCURS 0,

value TYPE char50,

message TYPE char72,

END OF t_error.

data: l type c,

v_pstyv(20) type C,

v_matnr(20) type C,

v_menge(20) type C,

v_werks(20) type C.

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

PARAMETERS: p_finame TYPE rlgrap-filename OBLIGATORY.

SELECTION-SCREEN: END OF BLOCK b1.

DATA: BEGIN OF bdc_tab OCCURS 0.

INCLUDE STRUCTURE bdcdata.

DATA: END OF bdc_tab.

DATA : BEGIN OF t_error_log OCCURS 0,

data(200) TYPE c,

END OF t_error_log.

*CONSTANTS : c_tan(3) TYPE c VALUE 'TAN',

  • c_tann(4) TYPE c VALUE 'TANN',

  • c_10 LIKE vbap-posnr VALUE '10'.

INITIALIZATION.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_finame.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

  • EXPORTING

  • PROGRAM_NAME = SYST-REPID

  • DYNPRO_NUMBER = SYST-DYNNR

  • FIELD_NAME = ' '

  • STATIC = ' '

  • MASK = ' '

CHANGING

file_name = p_finame

EXCEPTIONS

mask_too_long = 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.

AT SELECTION-SCREEN.

*Declaration of local variables

DATA: l_path TYPE rlgrap-filename,

l_name TYPE string.

DATA: t_dir TYPE rlgrap-filename OCCURS 0.

*Split the filename and the file path

CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'

EXPORTING

full_name = p_finame

IMPORTING

stripped_name = l_name

file_path = l_path

EXCEPTIONS

x_error = 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.

CALL FUNCTION 'KCD_FRONT_END_DIRECTORY_READ'

EXPORTING

i_path = l_path

  • IMPORTING

  • E_PURE_PATH =

TABLES

e_directory = t_dir

EXCEPTIONS

download = 1

upload = 2

execute = 3

directory_not_exist = 4

directory = 5

OTHERS = 6

.

IF sy-subrc <> 0.

MESSAGE e999 WITH text-004.

ENDIF.

CALL FUNCTION 'STRING_REVERSE'

EXPORTING

string = p_finame

lang = 'E'

IMPORTING

rstring = l_finame

EXCEPTIONS

too_small = 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.

CONDENSE l_finame.

TRANSLATE l_finame TO UPPER CASE.

IF l_finame(3) NE 'SLX'.

MESSAGE e999 WITH text-003.

ENDIF.

START-OF-SELECTION.

PERFORM sub_download_data.

PERFORM open_bdc_group.

&----


*& Form sub_download_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM sub_download_data .

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = p_finame

i_begin_col = 1

i_begin_row = 1

i_end_col = 255

i_end_row = 65535

TABLES

intern = t_tab

EXCEPTIONS

inconsistent_parameters = 1

upload_ole = 2

OTHERS = 3.

IF sy-subrc <> 0.

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

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

ENDIF.

*Populate the internal tables into the order table to be

*populated with

CLEAR : t_vbak,

t_error_log,

l_flag.

REFRESH : t_vbak,

t_error_log.

LOOP AT t_tab.

*Populate the individual column numbers.

CASE t_tab-col.

WHEN '0001'.

*Check the order number doesnot exceed 10 characters

IF NOT STRLEN( t_tab-value ) GT 10.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = t_tab-value

IMPORTING

output = l_vbeln1.

IF sy-subrc <> 0.

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

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

ENDIF.

SELECT SINGLE vbeln

INTO l_vbeln

FROM vbak

WHERE vbeln EQ l_vbeln1.

IF sy-subrc EQ 0.

MOVE t_tab-value TO t_vbak-vbeln.

ELSE.

CONCATENATE text-015

space

t_tab-value

text-006

INTO t_error_log-data.

l_flag = 'X'.

CONTINUE.

ENDIF.

ELSE.

CONCATENATE text-015

space

t_tab-value

text-005

INTO t_error_log-data.

l_flag = 'X'.

CONTINUE.

ENDIF.

  • Check for Material No. - should not exceed 18 char's

WHEN '0002'.

IF NOT STRLEN( t_tab-value ) GT 18.

move t_tab-value to l_matnr1.

CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'

EXPORTING

input = t_tab-value

IMPORTING

output = t_tab-value.

IF sy-subrc <> 0.

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

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

ENDIF.

SELECT SINGLE matnr

INTO l_matnr

FROM mara

WHERE matnr EQ t_tab-value.

IF sy-subrc EQ 0.

MOVE t_tab-value TO t_vbak-matnr.

ELSE.

CONCATENATE text-015

space

t_vbak-vbeln

space

text-007

l_matnr1

INTO t_error_log-data.

l_flag = 'X'.

CONTINUE.

ENDIF.

ELSE.

CONCATENATE text-015

space

t_vbak-vbeln

space

text-008

t_tab-value

INTO t_error_log-data.

l_flag = 'X'.

CONTINUE.

ENDIF.

  • Check for Plant - Should not exceed 4 char's

WHEN '0003'.

IF NOT STRLEN( t_tab-value ) GT 4.

SELECT SINGLE werks

INTO l_werks

FROM t001w

WHERE werks EQ t_tab-value.

IF sy-subrc EQ 0.

MOVE t_tab-value TO t_vbak-werks.

ELSE.

CONCATENATE text-015

space

t_vbak-vbeln

space

text-009

t_tab-value

INTO t_error_log-data.

l_flag = 'X'.

CONTINUE.

ENDIF.

ELSE.

CONCATENATE text-015

space

t_vbak-vbeln

space

text-010

t_tab-value

INTO t_error_log-data.

l_flag = 'X'.

CONTINUE.

ENDIF.

WHEN '0004'.

IF NOT t_tab-value IS INITIAL.

MOVE t_tab-value TO t_vbak-menge.

ELSE.

CONCATENATE text-015

space

t_vbak-vbeln

space

t_tab-value

text-010

INTO t_error_log-data.

l_flag = 'X'.

CONTINUE.

ENDIF.

WHEN '0005'.

IF NOT t_tab-value IS INITIAL.

MOVE t_tab-value TO t_vbak-pstyv.

ELSE.

CONCATENATE text-015

space

t_vbak-vbeln

space

t_tab-value

text-010

INTO t_error_log-data.

l_flag = 'X'.

CONTINUE.

ENDIF.

WHEN OTHERS.

  • move sy-tabix to t_error_log-rec_no.

CONCATENATE text-015

space

t_vbak-vbeln

space

t_tab-value

text-014

INTO t_error_log-data.

ENDCASE.

AT END OF row.

IF NOT l_flag EQ 'X'.

APPEND: t_vbak.

CLEAR: t_vbak,

l_flag.

else.

APPEND: t_error_log.

CLEAR: t_vbak,

t_error_log.

ENDIF.

ENDAT.

ENDLOOP.

ENDFORM. " sub_download_data

&----


*& Form open_bdc_group

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM open_bdc_group .

IF t_vbak[] IS NOT INITIAL.

  • Open batch input Group

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

client = sy-mandt

group = group

keep = 'X'

user = sy-uname.

  • USER = 'BACKGROUND'.

LOOP AT t_vbak.

IF NOT t_vbak-vbeln IS INITIAL.

unpack t_vbak-vbeln to l_vbeln1.

select vbeln posnr from vbap

into table t_vbap

where vbeln EQ l_vbeln1.

describe table t_vbap lines l.

l = l + 1.

PERFORM generate_bdc_data.

CALL FUNCTION 'BDC_INSERT'

EXPORTING

tcode = 'VA02'

TABLES

dynprotab = bdc_tab.

ENDIF.

ENDLOOP.

CALL FUNCTION 'BDC_CLOSE_GROUP'.

SUBMIT rsbdcsub USING SELECTION-SET 'ZSDRBD55' AND RETURN.

DELETE ADJACENT DUPLICATES FROM t_error_log.

PERFORM disp_error_log.

ELSE.

WRITE : text-100.

ENDIF.

ENDFORM. " open_bdc_group

&----


*& Form generate_bdc_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM generate_bdc_data .

REFRESH bdc_tab.

PERFORM dynpro USING:

'X' 'SAPMV45A' '0102', "Initial screen

' ' 'BDC_CURSOR' 'VBAK-VBELN',

' ' 'BDC_OKCODE' '/00',

' ' 'VBAK-VBELN' t_vbak-vbeln.

PERFORM dynpro USING:

'X' 'SAPMV45A' '4001', "Sales Ord Change screen

'X' 'BDC_OKCODE' '=POAN',

' ' 'BDC_CURSOR' 'RV45A-MABNR(01)',

'X' 'SAPMV45A' '4001',

' ' 'BDC_OKCODE' '=SICH'.

concatenate 'RV45A-MABNR(0' l ')' into v_matnr.

condense v_matnr.

concatenate 'RV45A-KWMENG(0' l ')' into v_menge.

condense v_menge.

concatenate 'VBAP-PSTYV(0' l ')' into v_pstyv.

condense v_pstyv.

concatenate 'VBAP-WERKS(0' l ')' into v_werks.

condense v_werks.

PERFORM dynpro USING:

' ' 'BDC_CURSOR' v_werks, "2nd line itm material

  • ' ' 'RV45A-MABNR(03)' t_vbak-matnr,

' ' v_matnr t_vbak-matnr,

  • ' ' 'BDC_CURSOR' 'RV45A-KWMENG(02)', "2nd line itm qty

  • ' ' 'RV45A-KWMENG(03)' t_vbak-menge,

' ' v_MENGE t_vbak-menge,

  • ' ' 'BDC_CURSOR' 'VBAP-PSTYV(02)', "2nd line Itm catg "TANN"

  • ' ' 'VBAP-PSTYV(03)' t_vbak-pstyv,

' ' v_pstyv t_vbak-pstyv,

  • ' ' 'BDC_CURSOR' 'VBAP-WERKS(02)', "2nd line plant

  • ' ' 'VBAP-WERKS(03)' t_vbak-werks,

' ' v_werks t_vbak-werks.

  • ' ' 'BDC_OKCODE' '=SICH'.

    • ' ' 'BDC_OKCODE' '/00'.

ENDFORM. " generate_bdc_data

&----


*& Form dynpro

&----


  • text

----


  • -->P_ENDFORM text

----


FORM dynpro USING dynbegin name value.

CLEAR bdc_tab.

IF dynbegin = 'X'.

MOVE: name TO bdc_tab-program,

value TO bdc_tab-dynpro,

'X' TO bdc_tab-dynbegin.

APPEND bdc_tab.

ELSE.

MOVE: name TO bdc_tab-fnam,

value TO bdc_tab-fval.

  • IF bdc_tab-fnam EQ 'RV45A-KWMENG(02)'.

  • CONDENSE bdc_tab-fval.

  • ENDIF.

APPEND bdc_tab.

ENDIF.

ENDFORM. " DYNPRO

&----


*& Form disp_error_log

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM disp_error_log .

IF NOT t_error_log[] IS INITIAL.

LOOP AT t_error_log.

AT FIRST.

WRITE:/ text-012.

SKIP.

ENDAT.

WRITE:/ t_error_log-data.

ENDLOOP.

ELSE.

WRITE:/ text-013.

ENDIF.

ENDFORM. " disp_error_log

Thanks

Amjad.