C223 BDC Program in SAP ABAP.
C223 (Maintain Production Versions)
*&---------------------------------------------------------------------*
*& Report ZCPP_PROD_VER
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zcpp_prod_ver.
DATA: lv_matnr TYPE matnr,
lv_werks(4) TYPE 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.
TYPES: BEGIN OF ty_line,
matnr(18) TYPE c,
werks(4) TYPE c,
verid(4) TYPE c,
text1(40) TYPE c,
adatu(10) TYPE c,
bdatu(10) TYPE c,
bstmi(17) TYPE c,
bstma(17) TYPE 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.
TYPES: BEGIN OF ty_header,
matnr(18) TYPE c,
werks(4) TYPE c,
END OF ty_header.
TYPES: BEGIN 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.
PARAMETERS: p_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 = lines( it_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_program) TYPE bdcdata-program
VALUE(p_screen) TYPE 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).
CLEAR: wa_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.
*& Report ZCPP_PROD_VER
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zcpp_prod_ver.
DATA: lv_matnr TYPE matnr,
lv_werks(4) TYPE 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.
TYPES: BEGIN OF ty_line,
matnr(18) TYPE c,
werks(4) TYPE c,
verid(4) TYPE c,
text1(40) TYPE c,
adatu(10) TYPE c,
bdatu(10) TYPE c,
bstmi(17) TYPE c,
bstma(17) TYPE 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.
TYPES: BEGIN OF ty_header,
matnr(18) TYPE c,
werks(4) TYPE c,
END OF ty_header.
TYPES: BEGIN 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.
PARAMETERS: p_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 = lines( it_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_program) TYPE bdcdata-program
VALUE(p_screen) TYPE 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).
CLEAR: wa_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.