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

bdc query?

Former Member
0 Likes
500

Hi All,

here is the scenario which im facing ...

there are 2 transactions which is to handled ..lets say MM01 AND MM02,,,the material document number which is created/generated in MM01 has to passed as an input to the second transaction MM02......

how to handle the above mentioned scenario in session and call transaction methods????????

Regards,

2 REPLIES 2
Read only

Former Member
0 Likes
426

See the below example code and which wiill create sales order and Delivery and billing

PROCESS BEFORE OUTPUT.

MODULE status_9000.

LOOP AT t_tcdata WITH CONTROL t_tc CURSOR t_tc-current_line.

ENDLOOP.

PROCESS AFTER INPUT.

CHAIN.

FIELD VBAK-vdatu MODULE validate_date.

FIELD g_kunnr1 MODULE validate_cuts1.

FIELD g_kunnr2 MODULE validate_cuts2.

field g_zzjp_remarks module validate_remarks.

" ON INPUT

ENDCHAIN.

LOOP AT t_tcdata. " Looping the internal table

CHAIN.

FIELD t_tcdata-matnr MODULE validate_matnr.

FIELD t_tcdata-kdmat MODULE validate_kdmat.

FIELD t_tcdata-kwmeng MODULE validate_quan.

FIELD t_tcdata-charg MODULE validate_charg .

ENDCHAIN.

MODULE table_modify.

ENDLOOP.

MODULE user_command_9000. " Processes User Command in Screen 9000

MODULE clear_okcode. " Initializing the ok_code

MODULE exit AT EXIT-COMMAND. " Exit Command for Screen 9000

----


  • INCLUDE MZJPV327F01 *

----


&----


*& Form F_BDC_PRG

&----


  • This is for Processing of Sales ordewr ,Delivery and Billing Through

  • BDC *

----


FORM f_bdc_prg.

  • --VA01 transaction.--(1)

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

  • Populating the BDCDATA structure(screen related) *

  • for the screen '0101'. *

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

REFRESH t_bdcdata.

PERFORM f_bdc_dynpro USING 'SAPMV45A' '0101'.

PERFORM f_bdc_field USING 'BDC_CURSOR' 'VBAK-AUART'.

PERFORM f_bdc_field USING 'BDC_OKCODE' '/00'.

PERFORM f_bdc_field USING 'VBAK-AUART' c_auart.

PERFORM f_bdc_field USING 'VBAK-VKORG' c_vkorg.

PERFORM f_bdc_field USING 'VBAK-VTWEG' c_vtweg.

PERFORM f_bdc_field USING 'VBAK-SPART' c_spart.

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

  • Populating the BDCDATA structure(screen related) *

  • for the screen '4001'. *

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

PERFORM f_bdc_dynpro USING 'SAPMV45A' '4001'.

PERFORM f_bdc_field USING 'BDC_OKCODE' '=KBES'.

PERFORM f_bdc_field USING 'BDC_CURSOR' 'KUWEV-KUNNR'.

PERFORM f_bdc_field USING 'KUWEV-KUNNR' g_kunnr1.

WRITE: VBAK-vdatu TO VBAK-vdatu.

PERFORM f_bdc_field USING 'RV45A-KETDAT' VBAK-vdatu.

PERFORM f_bdc_field USING 'VBAK-AUGRU' c_augru.

IF t_tcdata-matnr IS INITIAL AND NOT t_tcdata-kdmat IS INITIAL.

SELECT matnr zjd_touitsumatnr FROM mara INTO TABLE t_kdmat.

sort t_kdmat by matnr.

LOOP AT t_kdmat.

READ TABLE t_kdmat WITH KEY zjd_touitsumatnr+3(5) = t_tcdata-kdmat.

IF SY-SUBRC = 0.

g_matnr = t_kdmat-MATNR.

exit.

ENDIF.

ENDLOOP.

g_ctr = 0.

LOOP AT t_tcdata.

g_ctr = g_ctr + 01.

CONCATENATE c_matnr '( ' g_ctr ' ) ' INTO g_mabnr.

PERFORM f_bdc_field USING g_mabnr g_matnr. "t_tcdata-matnr..

CONCATENATE c_kdmat '( ' g_ctr ' ) ' INTO g_kdmat.

PERFORM f_bdc_field USING g_kdmat t_tcdata-kdmat.

CONCATENATE c_kwmeng '( ' g_ctr ' ) ' INTO g_kwmeng.

PERFORM f_bdc_field USING g_kwmeng t_tcdata-kwmeng.

CONCATENATE c_charg '( ' g_ctr ' ) ' INTO g_charg.

PERFORM f_bdc_field USING g_charg t_tcdata-charg.

ENDLOOP.

ELSE.

g_ctr = 0.

LOOP AT t_tcdata.

g_ctr = g_ctr + 01.

CONCATENATE c_matnr '( ' g_ctr ' ) ' INTO g_mabnr.

PERFORM f_bdc_field USING g_mabnr t_tcdata-matnr.

CONCATENATE c_kdmat '( ' g_ctr ' ) ' INTO g_kdmat.

PERFORM f_bdc_field USING g_kdmat t_tcdata-kdmat.

CONCATENATE c_kwmeng '( ' g_ctr ' ) ' INTO g_kwmeng.

PERFORM f_bdc_field USING g_kwmeng t_tcdata-kwmeng.

CONCATENATE c_charg '( ' g_ctr ' ) ' INTO g_charg.

PERFORM f_bdc_field USING g_charg t_tcdata-charg.

ENDLOOP.

ENDIF.

PERFORM f_bdc_dynpro USING 'SAPMV45A' '4002'.

PERFORM f_bdc_field USING 'BDC_OKCODE' '/EBACK'.

IF vbkd-bsark = space .

PERFORM f_bdc_field USING 'BDC_CURSOR' 'VBKD-BSARK'.

PERFORM f_bdc_field USING 'VBKD-BSARK' c_bsark.

ENDIF.

PERFORM f_bdc_dynpro USING 'SAPMV45A' '4001'.

PERFORM f_bdc_field USING 'BDC_OKCODE' '=KZKU'.

PERFORM f_bdc_dynpro USING 'SAPMV45A' '4002'.

PERFORM f_bdc_field USING 'BDC_OKCODE' '=SICH'.

PERFORM f_bdc_field USING 'BDC_CURSOR' 'VBAK-ZZJP_REMARKS'.

PERFORM f_bdc_field USING 'VBAK-ZZJP_REMARKS' g_zzjp_remarks.

*Calling Va01 Transaction code

CALL TRANSACTION c_va01 USING t_bdcdata MODE C_N MESSAGES INTO

t_bdcmsg.

IF sy-subrc NE 0.

SET SCREEN 9000.

CLEAR : VBAK-vdatu,

g_kunnr1,

g_kunnr2,

g_zzjp_remarks.

clear g_matnr.

clear t_kdmat.

REFRESH t_tcdata.

MESSAGE e000 WITH 'Could not register order document'(t16).

ENDIF.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

v2 = sy-msgv2

IMPORTING

msg = g_vbeln

EXCEPTIONS

not_found = 1

OTHERS = 2.

IF sy-subrc = 0.

g_vbeln = sy-msgv2.

ENDIF.

----


  • VL10 Transaction *

----


IF NOT g_vbeln IS INITIAL.

PERFORM f_create_delivery.

ELSE.

SET SCREEN 9000.

REFRESH t_tcdata.

CLEAR: VBAK-vdatu,

g_kunnr1,

g_kunnr2,

g_zzjp_remarks.

ENDIF.

ENDFORM. " F_BDC_PRG

&----


*& Form F_CREATE_DELIVERY

&----


  • Creation of Delivery

----


FORM f_create_delivery.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = g_vbeln

IMPORTING

output = g_vbeln.

  • Getting plant

WAIT UP TO 2 SECONDS.

SELECT SINGLE WERKS FROM VBAP INTO G_WERKS WHERE VBELN = G_VBELN.

REFRESH: t_bdcmsg,t_bdcdata.

----


  • Getting shipping point

----


PERFORM f_bdc_dynpro USING 'RVV50R10C'

'1000'.

PERFORM f_bdc_field USING 'BDC_CURSOR'

'ST_LEDAT-HIGH'.

PERFORM f_bdc_field USING 'BDC_OKCODE'

'=S0S_TAB2'.

PERFORM f_bdc_field USING 'ST_LEDAT-LOW'

''.

PERFORM f_bdc_field USING 'ST_LEDAT-HIGH'

''.

PERFORM f_bdc_dynpro USING 'RVV50R10C'

'1000'.

PERFORM f_bdc_field USING 'BDC_OKCODE'

'=ONLI'.

PERFORM f_bdc_field USING 'BDC_CURSOR'

'ST_VBELN-LOW'.

PERFORM f_bdc_field USING 'ST_VBELN-LOW'

g_vbeln.

PERFORM f_bdc_dynpro USING 'SAPLSLVC_FULLSCREEN'

'0500'.

PERFORM f_bdc_field USING 'BDC_OKCODE'

'=&ALL'.

PERFORM f_bdc_dynpro USING 'SAPLSLVC_FULLSCREEN'

'0500'.

PERFORM f_bdc_field USING 'BDC_OKCODE'

'=SAMD'.

PERFORM f_bdc_dynpro USING 'SAPLSLVC_FULLSCREEN'

'0500'.

PERFORM f_bdc_field USING 'BDC_OKCODE'

'=&F03'.

PERFORM f_bdc_dynpro USING 'RVV50R10C'

'1000'.

PERFORM f_bdc_field USING 'BDC_OKCODE'

'/EE'.

PERFORM f_bdc_field USING 'BDC_CURSOR'

'ST_VSTEL-LOW'.

WAIT UP TO 5 SECONDS.

CALL TRANSACTION c_vl10 USING t_bdcdata MODE C_N

MESSAGES INTO t_bdcmsg.

IF sy-subrc NE 0.

MESSAGE e000 WITH 'Could not register the order document'(t16).

ENDIF.

SELECT SINGLE vbeln FROM lips INTO g_vbeln1

WHERE vgbel = g_vbeln.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = g_vbeln1

IMPORTING

OUTPUT = g_vbeln1

.

IF NOT g_vbeln1 IS INITIAL.

PERFORM f_post_create.

ELSE.

SET SCREEN 9000.

CLEAR : g_kunnr1,

g_kunnr2,

VBAK-vdatu,

t_tcdata,

g_zzjp_remarks.

ENDIF.

ENDFORM. " F_CREATE_DELIVERY

&----


*& Form F_POST_CREATE

&----


  • Creation of vl02n tcode

----


FORM f_post_create.

refresh t_bdcdata.

refresh t_bdcmsg.

PERFORM f_bdc_dynpro USING 'SAPMV50A' '4004'.

PERFORM f_bdc_field USING 'BDC_CURSOR' 'LIKP-VBELN'.

PERFORM f_bdc_field USING 'BDC_OKCODE' '=WABU_T'.

PERFORM f_bdc_field USING 'LIKP-VBELN' g_vbeln1.

CALL TRANSACTION c_vl02n USING t_bdcdata MODE C_N

messages into t_bdcmsg.

IF NOT g_vbeln1 IS INITIAL.

PERFORM f_billing_docu.

ELSE.

SET SCREEN 9000.

CLEAR : g_kunnr1,

g_kunnr2,

VBAK-vdatu,

g_zzjp_remarks,

t_tcdata.

ENDIF.

ENDFORM. " F_POST_CREATE

**&----


*

**& Form F_BILLING_DOCU

**&----


*

    • Creation of Billing Document (VF01)

**----


FORM f_billing_docu.

REFRESH t_bdcdata.

refresh t_bdcmsg.

PERFORM f_bdc_dynpro USING 'SAPMV60A' '0102'.

PERFORM f_bdc_field USING 'BDC_CURSOR' 'KOMFK-VBELN(01)'.

PERFORM f_bdc_field USING 'KOMFK-VBELN(01)' g_vbeln1.

PERFORM f_bdc_field USING 'BDC_OKCODE' '=FAKT'.

PERFORM f_bdc_dynpro USING 'SAPMV60A' '0104'.

PERFORM f_bdc_field USING 'BDC_OKCODE' '=SICH'.

CALL TRANSACTION c_vf01 USING t_bdcdata MODE C_N

MESSAGES INTO t_bdcmsg .

IF sy-subrc NE 0.

MESSAGE e000 WITH 'could not register Dispatch document'(t17).

ENDIF.

CLEAR g_vbeln.

CLEAR g_vbeln1.

REFRESH t_bdcmsg.

PERFORM f_create_sales.

ENDFORM. " F_BILLING_DOCU

**&----


*

**& Form F_CREATE_SALES

**&----


*

    • Creation of Sales order with ZJPB Order type

**----


FORM f_create_sales.

    • --VA01 transaction.--(1)

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

*

    • Populating the BDCDATA structure(screen related)

*

    • for the screen '0101'.

*

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

*

*

REFRESH t_bdcdata.

PERFORM f_bdc_dynpro USING 'SAPMV45A' '0101'.

PERFORM f_bdc_field USING 'BDC_OKCODE' '=ENT2'.

PERFORM f_bdc_field USING 'BDC_CURSOR' 'VBAK-AUART'.

PERFORM f_bdc_field USING 'VBAK-AUART' c_auart1.

PERFORM f_bdc_field USING 'VBAK-VKORG' c_vkorg.

PERFORM f_bdc_field USING 'VBAK-VTWEG' c_vtweg.

PERFORM f_bdc_field USING 'VBAK-SPART' c_spart.

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

  • Populating the BDCDATA structure(screen related)

  • for the screen '4001'.

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

PERFORM f_bdc_dynpro USING 'SAPMV45A' '4001'.

PERFORM f_bdc_field USING 'BDC_OKCODE' '=SICH'.

PERFORM f_bdc_field USING 'BDC_CURSOR' 'KUWEV-KUNNR'.

PERFORM f_bdc_field USING 'KUWEV-KUNNR' g_kunnr2.

PERFORM f_bdc_field USING 'VBKD-BSTKD' c_bstkd.

PERFORM f_bdc_field USING 'RV45A-KETDAT' VBAK-vdatu.

PERFORM f_bdc_field USING 'VBAK-AUGRU' c_augru.

IF t_tcdata-matnr IS INITIAL AND NOT t_tcdata-kdmat IS INITIAL.

SELECT matnr zjd_touitsumatnr FROM mara INTO TABLE t_kdmat.

sort t_kdmat by matnr.

LOOP AT t_kdmat.

READ TABLE t_kdmat WITH KEY zjd_touitsumatnr+3(5) = t_tcdata-kdmat.

IF SY-SUBRC = 0.

g_matnr = t_kdmat-MATNR.

exit.

ENDIF.

ENDLOOP.

LOOP AT t_tcdata.

g_ctr = g_ctr + 01.

CONCATENATE c_matnr '( ' g_ctr ' ) ' INTO g_mabnr.

PERFORM f_bdc_field USING g_mabnr g_matnr.

CONCATENATE c_kdmat '( ' g_ctr ' ) ' INTO g_kdmat.

PERFORM f_bdc_field USING g_kdmat t_tcdata-kdmat.

CONCATENATE c_kwmeng '( ' g_ctr ' ) ' INTO g_kwmeng.

PERFORM f_bdc_field USING g_kwmeng t_tcdata-kwmeng.

CONCATENATE c_charg '( ' g_ctr ' ) ' INTO g_charg.

PERFORM f_bdc_field USING g_charg t_tcdata-charg.

CONCATENATE C_WERKS '(' G_CTR')' INTO G_WERKS1.

PERFORM F_BDC_FIELD USING G_WERKS1 G_WERKS.

ENDLOOP.

ELSE.

g_ctr = 0.

LOOP AT t_tcdata.

g_ctr = g_ctr + 01.

CONCATENATE c_matnr '( ' g_ctr ' ) ' INTO g_mabnr.

PERFORM f_bdc_field USING g_mabnr t_tcdata-matnr.

CONCATENATE c_kdmat '( ' g_ctr ' ) ' INTO g_kdmat.

PERFORM f_bdc_field USING g_kdmat t_tcdata-kdmat.

CONCATENATE c_kwmeng '( ' g_ctr ' ) ' INTO g_kwmeng.

PERFORM f_bdc_field USING g_kwmeng t_tcdata-kwmeng.

CONCATENATE c_charg '( ' g_ctr ' ) ' INTO g_charg.

PERFORM f_bdc_field USING g_charg t_tcdata-charg.

CONCATENATE C_WERKS '(' G_CTR')' INTO G_WERKS1.

PERFORM F_BDC_FIELD USING G_WERKS1 G_WERKS.

ENDLOOP.

ENDIF.

wait up to 5 seconds.

CALL TRANSACTION c_va01 USING t_bdcdata MODE C_N MESSAGES INTO

t_bdcmsg.

IF sy-subrc NE 0.

MESSAGE e000 WITH 'Could not register order document'(t16).

ENDIF.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

v2 = sy-msgv2

IMPORTING

msg = g_vbeln

EXCEPTIONS

not_found = 1

OTHERS = 2.

IF sy-subrc = 0.

g_vbeln = sy-msgv2.

ENDIF.

REFRESH t_bdcmsg.

clear g_matnr.

clear t_kdmat.

IF NOT g_vbeln IS INITIAL.

PERFORM f_create_delivery1.

ELSE.

SET SCREEN 9000.

REFRESH t_tcdata.

CLEAR: VBAK-vdatu,

g_kunnr1,

g_kunnr2,

g_zzjp_remarks.

ENDIF.

ENDFORM. " F_CREATE_SALES

**&----


*

**& Form F_BILLING_DOCU1

**&----


*

    • Creation of Billing Document (VF01)

**----


FORM f_billing_docu1.

REFRESH t_bdcdata.

PERFORM f_bdc_dynpro USING 'SAPMV60A' '0102'.

PERFORM f_bdc_field USING 'BDC_CURSOR' 'KOMFK-VBELN(01)'.

PERFORM f_bdc_field USING 'KOMFK-VBELN(01)' g_vbeln1.

PERFORM f_bdc_field USING 'BDC_OKCODE' '=FAKT'.

PERFORM f_bdc_dynpro USING 'SAPMV60A' '0104'.

PERFORM f_bdc_field USING 'BDC_OKCODE' '=SICH'.

wait up to 5 seconds.

CALL TRANSACTION c_vf01 USING t_bdcdata MODE c_n

MESSAGES INTO t_bdcmsg .

IF sy-subrc NE 0.

MESSAGE e000 WITH 'could not register Dispatch document'(t17).

ENDIF.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

v2 = sy-msgv2

IMPORTING

msg = g_text.

MOVE g_text TO g_zzjp_remarks.

CLEAR: g_vbeln,

g_werks.

REFRESH t_bdcmsg.

SET SCREEN 9000.

REFRESH t_tcdata.

CLEAR: VBAK-vdatu,

g_kunnr1,

g_zzjp_remarks,

g_kunnr2.

ENDFORM. " F_BILLING_DOCU1

**&----


*

**& Form F_BDC_DYNPRO

**&----


*

    • Routine for populating the BDCDATA structure with the

    • Screen related information

**----


*

    • p_prog is the program name to which data is passed

    • p_scrn is the screen number to which the data is passed

**----


FORM f_bdc_dynpro USING p_prog

p_scrn.

CLEAR t_bdcdata.

t_bdcdata-program = p_prog.

t_bdcdata-dynpro = p_scrn.

t_bdcdata-dynbegin = 'X'.

APPEND t_bdcdata.

ENDFORM. " F_BDC_DYNPRO

**&----


*

**& Form f_bdc_field

**&----


*

    • Routine for populating the BDCDATA structure with data

    • Fields related information.

**----


*

    • p_fnam is the field name to which value is passed

    • p_fval is the field value which is passed

**----


FORM f_bdc_field USING p_fnam

p_fval.

CLEAR t_bdcdata.

t_bdcdata-fnam = p_fnam.

t_bdcdata-fval = p_fval.

APPEND t_bdcdata.

ENDFORM. " F_BDC_FIELD

&----


*& Form f_create_delivery1

&----


  • text

----


form f_create_delivery1.

refresh t_bdcdata.

clear g_vbeln1.

*CLEAR G_VBELN.

PERFORM f_bdc_dynpro USING 'RVV50R10C'

'1000'.

PERFORM f_bdc_field USING 'BDC_CURSOR'

'ST_LEDAT-HIGH'.

PERFORM f_bdc_field USING 'BDC_OKCODE'

'=S0S_TAB2'.

PERFORM f_bdc_field USING 'ST_LEDAT-LOW'

''.

PERFORM f_bdc_field USING 'ST_LEDAT-HIGH'

''.

PERFORM f_bdc_dynpro USING 'RVV50R10C'

'1000'.

PERFORM f_bdc_field USING 'BDC_OKCODE'

'=ONLI'.

PERFORM f_bdc_field USING 'BDC_CURSOR'

'ST_VBELN-LOW'.

PERFORM f_bdc_field USING 'ST_VBELN-LOW'

g_vbeln.

PERFORM f_bdc_dynpro USING 'SAPLSLVC_FULLSCREEN'

'0500'.

PERFORM f_bdc_field USING 'BDC_OKCODE'

'=&ALL'.

PERFORM f_bdc_dynpro USING 'SAPLSLVC_FULLSCREEN'

'0500'.

PERFORM f_bdc_field USING 'BDC_OKCODE'

'=SAMD'.

perform f_bdc_dynpro using 'SAPLSHLC' '0200'.

perform f_bdc_field using 'BDC_OKCODE'

'/EEXIT'.

perform f_bdc_field using 'BDC_CURSOR'

'IOWORKFLDS-DAY03(03)'.

PERFORM f_bdc_dynpro USING 'SAPLSLVC_FULLSCREEN'

'0500'.

PERFORM f_bdc_field USING 'BDC_OKCODE'

'=&F03'.

PERFORM f_bdc_dynpro USING 'RVV50R10C'

'1000'.

PERFORM f_bdc_field USING 'BDC_OKCODE'

'/EE'.

PERFORM f_bdc_field USING 'BDC_CURSOR'

'ST_VSTEL-LOW'.

WAIT UP TO 5 SECONDS.

CALL TRANSACTION c_vl10 USING t_bdcdata MODE C_N

MESSAGES INTO t_bdcmsg.

IF sy-subrc NE 0.

MESSAGE e000 WITH 'Could not register the order document'(t16).

ENDIF.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = g_vbeln

IMPORTING

OUTPUT = g_vbeln

.

SELECT SINGLE vbeln FROM lips INTO g_vbeln1

WHERE vgbel = g_vbeln.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = g_vbeln1

IMPORTING

OUTPUT = g_vbeln1

.

IF NOT g_vbeln1 IS INITIAL.

PERFORM f_post_create1.

ELSE.

SET SCREEN 9000.

CLEAR : g_kunnr1,

g_kunnr2,

VBAK-vdatu,

t_tcdata,

g_zzjp_remarks.

ENDIF.

endform. " f_create_delivery1

&----


*& Form f_post_create1

&----


  • VL02n transaction

----


form f_post_create1.

refresh t_bdcdata.

refresh t_bdcmsg.

PERFORM f_bdc_dynpro USING 'SAPMV50A' '4004'.

PERFORM f_bdc_field USING 'BDC_CURSOR' 'LIKP-VBELN'.

PERFORM f_bdc_field USING 'LIKP-VBELN' g_vbeln1.

PERFORM f_bdc_field USING 'BDC_OKCODE' '=WABU_T'.

CALL TRANSACTION c_vl02n USING t_bdcdata MODE C_N

messages into t_bdcmsg.

IF NOT g_vbeln1 IS INITIAL.

PERFORM f_billing_docu1.

ELSE.

SET SCREEN 9000.

CLEAR : g_kunnr1,

g_kunnr2,

VBAK-vdatu,

g_zzjp_remarks,

t_tcdata.

ENDIF.

endform. " f_post_create1

----


***INCLUDE MZJPV327I01 .

----


&----


*& Module USER_COMMAND_9000 INPUT

&----


  • This Module it to process the User actions in the screen 9000 *

  • as defined individually below *

----


MODULE user_command_9000 INPUT.

CASE g_ok_code.

----


  • When user press SAVE button then data entered in the table control *

  • defined in the screen 9000 is populated to the transction VA01 *

  • ---------------------------------------------------------------------*

WHEN 'SAVE'.

LOOP AT t_tcdata.

IF t_tcdata-charg IS INITIAL.

MESSAGE s000 WITH 'BATCH NUMBER MUST BE ENTERED'(t21).

ENDIF.

PERFORM f_bdc_prg.

ENDLOOP.

  • ---------------------------------------------------------------------*

  • When user press REVE button ,To exit for the Screen 9000

----


WHEN 'REVE'.

LEAVE TO SCREEN 000.

ENDCASE.

ENDMODULE. " USER_COMMAND_9000 INPUT

&----


*& Module table_modify INPUT

&----


  • Modifiying the table control according to the internal table.

----


MODULE table_modify INPUT.

MODIFY t_tcdata INDEX t_tc-current_line.

IF sy-subrc <> 0.

INSERT t_tcdata INDEX t_tc-current_line.

ENDIF.

ENDMODULE. " table_modify INPUT

&----


*& Module exit INPUT

&----


  • Processing the Exit commands for the screen 9000 *

----


MODULE exit INPUT.

CASE g_ok_code.

&----


*& To come back form the screen 9000. *

&----


WHEN 'BACK'.

LEAVE TO SCREEN 0.

&----


*& To exit for the screen 9000. *

&----


WHEN 'EXIT'.

LEAVE PROGRAM.

&----


*& To Cancel the program from the screen 9000. *

&----


WHEN 'CANC'.

LEAVE PROGRAM.

WHEN 'REVE'.

LEAVE TO SCREEN 000.

ENDCASE.

ENDMODULE. " exit INPUT

&----


*& Module CLEAR_OKCODE INPUT

&----


  • Clearing the Ok_Code *

----


MODULE clear_okcode INPUT.

CLEAR g_ok_code.

ENDMODULE. " CLEAR_OKCODE INPUT

&----


*& Module VALIDATE_CUTS1 INPUT

&----


  • Validation for Transfer from Code (G_Kunnr1)

----


MODULE validate_cuts1 INPUT.

IF NOT g_kunnr1 IS INITIAL.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = g_kunnr1

IMPORTING

output = g_kunnr1.

SELECT SINGLE kunnr ktokd brsch FROM kna1

INTO kna1

WHERE kunnr = g_kunnr1

AND ktokd = c_ktokd

AND brsch = c_brsch.

IF sy-subrc NE 0.

MESSAGE e000 WITH 'Please enter the correct Transfer-from'(t01)

'code of special agent'(t02) .

ENDIF.

ELSE.

MESSAGE e000 WITH 'Make an entry in all required fields'(t03).

ENDIF.

ENDMODULE. " VALIDATE_CUTS1 INPUT

&----


*& Module VALIDATE_CUTS2 INPUT

&----


  • Validation for Transfer to code (G_kunnr2)

----


MODULE validate_cuts2 INPUT.

IF NOT g_kunnr2 IS INITIAL.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = g_kunnr2

IMPORTING

output = g_kunnr2.

SELECT SINGLE kunnr ktokd brsch FROM kna1

INTO kna1

WHERE kunnr = g_kunnr2

AND ktokd = c_ktokd

AND brsch = c_brsch.

IF sy-subrc NE 0.

MESSAGE e000 WITH 'Please enter the correct Transfer-to'(t04)

'code of special agent'(t05).

ENDIF.

IF g_kunnr1 = g_kunnr2.

IF sy-subrc = 0.

MESSAGE e000 WITH 'Transfer-from code and Transfer-to code'(t06)

'are the same'(t07).

ENDIF.

ENDIF.

ELSE.

MESSAGE e000 WITH 'Make an entry in all required fields'(t03).

ENDIF.

ENDMODULE. " VALIDATE_CUTS2 INPUT

&----


*& Module VALIDATE_MATNR INPUT

&----


  • Validation for Material Number

----


MODULE validate_matnr INPUT.

IF NOT t_tcdata-matnr IS INITIAL.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = t_tcdata-matnr

IMPORTING

output = t_tcdata-matnr.

SELECT SINGLE matnr FROM mvke INTO t_tcdata-matnr

WHERE matnr EQ t_tcdata-matnr

AND vkorg EQ c_vkorg

AND vtweg EQ c_vtweg

AND mvgr2 EQ c_mvgr2.

IF sy-subrc <> 0.

MESSAGE e000 WITH 'Please enter the material code'(t08)

'for which material group is Z91'(t09).

ENDIF.

ENDIF.

ENDMODULE. " VALIDATE_MATNR INPUT

&----


*& Module VALIDATE_CHARG INPUT

&----


  • Validation for Batch Number(Charg)

----


MODULE validate_charg INPUT.

IF t_tcdata-charg IS INITIAL.

MESSAGE e000 WITH 'batch number must be entered'(t10).

ELSE.

IF NOT t_tcdata-matnr IS INITIAL.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = t_tcdata-charg

IMPORTING

output = t_tcdata-charg.

  • SELECT SINGLE charg FROM mcha INTO t_tcdata-charg

  • WHERE charg = t_tcdata-charg

  • AND matnr = t_tcdata-matnr.

*

  • IF sy-subrc NE 0.

*

*

  • MESSAGE e000 WITH 'The material does not belongs to'(t11)

  • 'the specified batch'(t12).

  • ENDIF.

select single charg from mcha into t_tcdata-charg

where charg = t_tcdata-charg.

IF sy-subrc NE 0.

MESSAGE e000 WITH 'The Batch no does not exist'(t21).

ENDIF.

ENDIF.

ENDIF.

ENDMODULE. " VALIDATE_CHARG INPUT

&----


*& Module VALIDATE_KDMAT INPUT

&----


  • Validation for Integrated product code (Kdmat)

----


MODULE validate_kdmat INPUT.

IF NOT t_tcdata-kdmat IS INITIAL AND NOT t_tcdata-matnr IS INITIAL.

MESSAGE e000 WITH 'Material Code and Integrated Product Code'(t13)

'can not be entered in the same time'(t14).

ENDIF.

IF NOT t_tcdata-kdmat IS INITIAL.

select single kdmat from vbap into t_tcdata-kdmat

where kdmat = t_tcdata-kdmat.

if sy-subrc ne 0.

MESSAGE e000 WITH ' integrated product code does not exist'(t15).

endif.

endif.

  • IF NOT t_tcdata-kdmat IS INITIAL.

*

  • select single zjd_touitsumatnr from mara into t_tcdata-kdmat

  • where zjd_touitsumatnr = t_tcdata-kdmat.

*

  • if mara-zjd_touitsumatnr+3(5) = t_tcdata-kdmat.

  • if sy-subrc ne 0.

  • MESSAGE e000 WITH ' integrated product code does not exist'(t15).

  • endif.

  • endif.

  • endif.

*

if t_tcdata-kdmat is initial and t_tcdata-matnr is initial.

message e000 with

'enter either of material code or integrated product code'(t20).

endif.

ENDMODULE. " VALIDATE_KDMAT INPUT

&----


*& Module validate_date INPUT

&----


  • Validation for Transfer date

----


module validate_date input.

if VBAK-vdatu is initial.

message e000 with 'Transfer date is mandatory field'(t18).

endif.

endmodule. " validate_date INPUT

&----


*& Module validate_quan INPUT

&----


  • Validation for Quantity field

----


module validate_quan input.

if t_tcdata-kwmeng = 0 or t_tcdata-kwmeng = space.

message e000 with 'Enter the quantity'(t19).

endif.

endmodule. " validate_quan INPUT

&----


*& Module validate_remarks INPUT

&----


  • Validation for Remarks

----


module validate_remarks input.

if g_zzjp_remarks is initial.

CALL FUNCTION 'ZJD_FGT009_SINGLECHAR_CHECK'

EXPORTING

BUF = G_ZZJP_REMARKS

EXCEPTIONS

NOT_SINGLECHAR_EXEPTION = 1

OTHERS = 2

.

IF SY-SUBRC <> 0.

message e000 with

'only single byte kana-alphanumeric can be entered into remarks'(t22).

endif.

ENDIF.

endmodule. " validate_remarks INPUT

&----


*& Module VALUE_BATCH INPUT

&----


  • f4 help for Batch number

----


*MODULE VALUE_BATCH INPUT.

*

*CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'

  • EXPORTING

  • TABNAME = 'VBAP'

  • FIELDNAME = 'CHARG'

  • DYNPPROG = G_PROG

  • DYNPNR = '9000'

  • DYNPROFIELD = 'T_TCDATA-CHARG'.

*

*ENDMODULE. " VALUE_BATCH INPUT

----


  • INCLUDE MZJPV327O01 *

----


&----


*& Module STATUS_9000 OUTPUT

&----


  • Defining the module status for the screen 9000. *

  • When the end user clicks SAVE BUUTON, function code SAVE is *

  • triggered and data entered in the table control defined *

  • in the screen 9000 is populated to the transction VA01. *

  • The title bar is for the screen 9000 consists "Goods Transfer *

  • Recording Process *

----


MODULE STATUS_9000 OUTPUT.

SET PF-STATUS '9000'.

SET TITLEBAR 'ZJP_TITLE'.

DESCRIBE TABLE T_TCDATA LINES G_LINE.

T_TC-LINES = T_TC-LINES + 5.

ENDMODULE. " STATUS_9000 OUTPUT

&----


*& Include MZJPV327TOP *

&----


*& This TOP include is for declaring the global data. *

&----


PROGRAM SAPMZJPV327 MESSAGE-ID ZJPV001 .

----


  • Constants Declaration.

----


CONSTANTS : C_VA01 LIKE TSTC-TCODE VALUE 'VA01', " TCODE FOR VA01

  • C_VL01N LIKE TSTC-TCODE VALUE 'VL01N', " TCODE FOR VL01N

C_VF01 LIKE TSTC-TCODE VALUE 'VF01', " TCODE FOR VF01

c_vl10 like tstc-tcode value 'VL10', " tcode for VL10

c_vl02n like tstc-tcode value 'VL02N' ," tcode for VL02N

C_AUART(4) TYPE C VALUE 'ZJPA' , " Order Type

C_AUART1(4) TYPE C VALUE 'ZJPB', " Order Type

C_VKORG(4) TYPE C VALUE 'JP20', " Sales Organization

C_VTWEG(4) TYPE C VALUE 'TR', " Distribution Channel

C_SPART(2) TYPE C VALUE '01', " Division

C_AUGRU(6) TYPE C VALUE 'Z33', " Order reason

C_MATNR(11) VALUE 'RV45A-MABNR',

C_KDMAT(11) VALUE 'VBAP-KDMAT', " Material no Used by

" Customer

C_BSARK(4) VALUE 'Z020', " Customer Purchase

" Order type

c_bstkd(2) type c value '*' , " Purchase order no

C_KWMENG(12) VALUE 'RV45A-KWMENG', " Quantity

C_CHARG(11) VALUE 'VBAP-CHARG', " Batch No

C_MVGR2(3) VALUE 'Z91', " Material Group 2

C_KTOKD(4) TYPE C VALUE 'Z002', " Account Group

C_BRSCH(4) TYPE C VALUE 'JP03', " Industry Key

C_WERKS(10) TYPE C VALUE 'VBAP-WERKS'," Plant

c_n(1) type c value 'N'. " Mode

----


  • Tables *

----


TABLES : VBAK, " Sales Document: Header Data

KNA1, " Customer master

KNVV, " Customer master (Sales)

VBKD, " Purchase order

VBAP, " sales document : Item data

MARA. " Material master

----


  • Internal table to hold the data for formating in screen 9000.

----


DATA: BEGIN OF T_TCDATA OCCURS 0,

MATNR LIKE VBAP-MATNR,

KDMAT LIKE VBAP-KDMAT,

KWMENG(13) TYPE N,

CHARG LIKE VBAP-CHARG,

END OF T_TCDATA.

----


  • Internal table to hold BDC data. *

  • t_bdcdata : Internal table to store table field structure for Batch*

  • Input. *

  • t_bdcmsg : Collecting error messages in the SAP System *

----


DATA : T_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE,

T_BDCMSG LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

  • Internal table to Hold Customer master data

DATA : BEGIN OF T_KNA1 OCCURS 0,

KUNNR LIKE KNA1-KUNNR, " Customer No

KTOKD LIKE KNA1-KTOKD, " Account Group

BRSCH LIKE KNA1-BRSCH, " Industry Key

END OF T_KNA1.

DATA : BEGIN OF T_VBAP1 OCCURS 0,

MATNR LIKE VBAP-MATNR,

KDMAT LIKE VBAP-KDMAT,

END OF T_VBAP1.

DATA : BEGIN OF T_KDMAT OCCURS 0,

matnr like mara-matnr,

ZJD_TOUITSUMATNR LIKE MARA-ZJD_TOUITSUMATNR,

END OF T_KDMAT.

DATA : BEGIN OF T_ZJDMATNR OCCURS 0,

MATNR LIKE MARA-MATNR,

ZJD_TOUITSUMATNR LIKE MARA-ZJD_TOUITSUMATNR,

END OF T_ZJDMATNR.

DATA : BEGIN OF T_VBAP OCCURS 0,

VBELN LIKE VBAP-VBELN,

VSTEL LIKE VBAP-VSTEL,

WERKS LIKE VBAP-WERKS,

END OF T_VBAP.

  • Table Control declaration for screen 9000.

CONTROLS T_TC TYPE TABLEVIEW USING SCREEN 9000.

DATA : G_MABNR(20) TYPE C,

G_KDMAT(37) TYPE C,

G_KWMENG(16) TYPE C,

G_CHARG(20) TYPE C,

G_CTR TYPE N.

DATA : G_PROG LIKE SY-REPID.

DATA : G_KUNNR1 LIKE VBAK-KUNNR, " Variable to hold Source Customer

G_KUNNR2 LIKE VBAK-KUNNR, " Variable to hold Destination Customer

g_vdatu like vbak-vdatu, " Transfer date

G_WERKS LIKE VBAP-WERKS, " Variable to hold Plant

G_WERKS1(15) TYPE C, " Plant

G_ZZJP_REMARKS LIKE VBAK-ZZJP_REMARKS, " remarks

g_text(30) type c,

g_matnr like mara-matnr, " material number

G_OK_CODE LIKE SY-UCOMM, " Variable to hold Function codes

G_VBELN LIKE VBAP-VBELN, " variable to hold Sales Document No

G_VBELN1 LIKE LIKP-VBELN, " variable to hold Sales Document No

  • G_VSTEL LIKE VBAP-VSTEL, " Variable to Hold Shipping Point

g_remarks(30) type c, " Remarks

G_LINE TYPE I. " Variable to hold Table Control lines

Reward Points if it is helpful

Thanks

Seshu

Read only

Former Member
0 Likes
426

Hi,

What ever might be the procedure. After MM01, go the table and get the material number from MARA and keep it in one variable. Then pass this variable as input to the second tcode MM02.

You can get the document number , by using GET parameter id. Why because, there may be several material document in the table. So, this GET will pick the latest material number.

Thanks

Manju.