0% found this document useful (0 votes)
134 views4 pages

BDC xd01 Program

This document contains code for processing customer records from a file. It defines data structures to store the records and error messages. Validation and conversion filters are used to check for missing fields and standardize some values. Records passing the filters are transferred to SAP using BDC calls to add/update the customer master data. Any records failing validation are written to an error file.

Uploaded by

asifhussain1196
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
134 views4 pages

BDC xd01 Program

This document contains code for processing customer records from a file. It defines data structures to store the records and error messages. Validation and conversion filters are used to check for missing fields and standardize some values. Records passing the filters are transferred to SAP using BDC calls to add/update the customer master data. Any records failing validation are written to an error file.

Uploaded by

asifhussain1196
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

report ZB44TR_BDC_XD01 no standard page heading line-size 255.

include bdcrecx1.
parameters: dataset(132) lower case.
*** DO NOT CHANGE - the generated data section - DO NOT CHANGE ***
*
* If it is nessesary to change the data section use the rules:
* 1.) Each definition of a field exists of two lines
* 2.) The first line shows exactly the comment
* '* data element: ' followed with the data element
* which describes the field.
* If you don't have a data element use the
* comment without a data element name
* 3.) The second line shows the fieldname of the
* structure, the fieldname must consist of
* a fieldname and optional the character '_' and
* three numbers and the field length in brackets
* 4.) Each field must be type C.
*
*** Generated data section with specific formatting - DO NOT CHANGE ***
data: begin of record,
* data element: KTOKD
KTOKD_001(004),
* data element: NAME1_GP
NAME1_002(035),
* data element: SORTL
SORTL_003(010),
* data element: ORT01_GP
ORT01_004(035),
* data element: PSTLZ
PSTLZ_005(010),
* data element: LAND1_GP
LAND1_006(003),
* data element: SPRAS
SPRAS_007(002),
* data element: LZONE
LZONE_008(010),
*user defined for error handling
ERTEXT(100) TYPE C,
end of record.
DATA : IT_ERR LIKE TABLE OF RECORD, " TO STORE ERROR RECORDS
WA_ERR LIKE RECORD, " TO PROCESS IT_ERR
TEXT1(25) TYPE C, " FILE TO HOLD ERROR RECORDS
FLAG TYPE C, " TO INDICATE/MARK ERROR REC
COUNT TYPE I.
*** End generated data section ***
start-of-selection.
*THIS PERFORM USED THE ODS STATEMENT
perform open_dataset using dataset.
*THIS PERFORM IS CALLED ONLY IF THE PROGRAM IS RUNNING FOR "BI" MODE,
*USES FM BDC_OPEN_GROUP
perform open_group.
*THIS DO LOOP IS BECAUSE THE FILE CAN HAVE MORE THAN ONE RECORDS
do.
*THIS STATEMENT READS DATA FROM THE FILE REC BY REC AND PUTS INTO THE WA
*CREATED ABOVE
read dataset dataset into record.
*THE SY-SUBRC WILL BE MORE THAN ZERO IF THERE ARE NO MORE RECORDS FOUND
*IN THE FILE, HENCE MAKES SENSE TO EXIT THE DO LOOP
if sy-subrc <> 0. exit. endif.
* VALIDATION FILTER.
PERFORM FILTERONE.
IF FLAG = 'X'. " THE RECORD IS ERROR/BAD
CLEAR FLAG.
CONTINUE. " PICKS NEXT RECORD FROM FILE
ENDIF.
* CONVERSION FILTER.
PERFORM FILTERTWO.
*IF THE RECORD PASSES THE VALIDATION AND CONVERSION FILTERS SUCCESSFULL
*THEN MOVE IT TO GOOD TABLE (BDCDATA)
* SCREEN ONE
perform bdc_dynpro using 'SAPMF02D' '0100'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF02D-KTOKD'
record-KTOKD_001.
* SCREEN TWO
perform bdc_dynpro using 'SAPMF02D' '0110'.
perform bdc_field using 'BDC_CURSOR'
'KNA1-SPRAS'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_field using 'KNA1-NAME1'
record-NAME1_002.
perform bdc_field using 'KNA1-SORTL'
record-SORTL_003.
perform bdc_field using 'KNA1-ORT01'
record-ORT01_004.
perform bdc_field using 'KNA1-PSTLZ'
record-PSTLZ_005.
perform bdc_field using 'KNA1-LAND1'
record-LAND1_006.
perform bdc_field using 'KNA1-SPRAS'
record-SPRAS_007.
* SCREEN THREE
perform bdc_dynpro using 'SAPMF02D' '0120'.
perform bdc_field using 'BDC_CURSOR'
'KNA1-LZONE'.
perform bdc_field using 'BDC_OKCODE'
'=UPDA'.
perform bdc_field using 'KNA1-LZONE'
record-LZONE_008.
*NOW THAT ALL THE SCREENS ARE PROCESSED, CALL CORRESPONDING TRANSACTION
*AND LOAD THE GOOD DATA TABLE (BDCDATA) SO THAT SAP DOES THE POSTING
perform bdc_transaction using 'XD01'.
*ENDDO WILL TAKE BACK TO THE DO AND THE PROCESS REPEATS
enddo.
*CLOSE THE GROUP WE OPENED BEFORE THE LOOP PASS
perform close_group.
perform close_dataset using dataset.
* MOVING ERROR RECORDS BACK TO APPLICATION SERVER
TEXT1 = '.\ZB41TR_ERR'.
OPEN DATASET TEXT1 FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
LOOP AT IT_ERR INTO WA_ERR.
TRANSFER WA_ERR TO TEXT1.
WRITE : / 'ERROR RECORDS TRANSFERED'.
ENDLOOP.
CLOSE DATASET TEXT1.
*&---------------------------------------------------------------------*
*& Form FILTERONE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FILTERONE .
IF RECORD-KTOKD_001 IS INITIAL.
RECORD-ERTEXT = 'ACCOUNT GROUP MISSING'.
APPEND RECORD TO IT_ERR.
FLAG = 'X'..
ELSEIF RECORD-NAME1_002 IS INITIAL.
RECORD-ERTEXT = 'NAME MISSING'.
APPEND RECORD TO IT_ERR.
FLAG = 'X'..
ELSEIF RECORD-SORTL_003 IS INITIAL.
RECORD-ERTEXT = 'SEARCH TERM MISSING'.
APPEND RECORD TO IT_ERR.
FLAG = 'X'..
ELSEIF RECORD-ORT01_004 IS INITIAL.
RECORD-ERTEXT = 'CITY MISSING'.
APPEND RECORD TO IT_ERR.
FLAG = 'X'..
ELSEIF RECORD-PSTLZ_005 IS INITIAL.
RECORD-ERTEXT = 'POSTAL CODE MISSING'.
APPEND RECORD TO IT_ERR.
FLAG = 'X'..
ELSEIF RECORD-LAND1_006 IS INITIAL.
RECORD-ERTEXT = 'COUNTRY MISSING'.
APPEND RECORD TO IT_ERR.
FLAG = 'X'..
ELSEIF RECORD-SPRAS_007 IS INITIAL.
RECORD-ERTEXT = 'LANGUAGE MISSING'.
APPEND RECORD TO IT_ERR.
FLAG = 'X'..
ELSEIF RECORD-LZONE_008 IS INITIAL.
RECORD-ERTEXT = 'ZONE IS MISSING'.
APPEND RECORD TO IT_ERR.
FLAG = 'X'..
ENDIF.
ENDFORM. " FILTERONE
*&---------------------------------------------------------------------*
*& Form FILTERTWO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FILTERTWO .
IF RECORD-LAND1_006 = 'DE'.
RECORD-SPRAS_007 = 'DE'.
ENDIF.
ENDFORM. " FILTERTWO

You might also like