2008 Feb 13 7:14 AM
2008 Feb 13 7:34 AM
hi,
When you generate the BDC (Batch Data Communication options define the processing mode for a batch input session) program with SHDB, you can remove a lot of unwanted fields by copying this customize abap include program. It allows you to execute the BDC program immediately without filling up those SAP generate fields. To run background, just run it as a background job.
* Execute BDC immediately by replacing the include BDCRECX1
*
*
***INCLUDE ZBDCRECX1.
* When you generate the program using SHDB, you can replace it
* with this if you want to execute it immediately without having
* to process it using SM35.
*
* During testing you can used the original include.
*
* For example,
* include zbdcrecx1. "After test
* include bdcrecx. "Before test
* -------------------------------------
* Declare your internal table as RECORD
* -------------------------------------
* for programs doing a data transfer by creating a batch-input session
* and
* for programs doing a data transfer by CALL TRANSACTION USING
*SELECTION-SCREEN BEGIN OF LINE.
* PARAMETERS SESSION RADIOBUTTON GROUP CTU. "create session
* SELECTION-SCREEN COMMENT 3(20) TEXT-S07 FOR FIELD SESSION.
* selection-screen position 45.
* PARAMETERS CTU RADIOBUTTON GROUP CTU DEFAULT 'X'. "call transaction
* SELECTION-SCREEN COMMENT 48(20) TEXT-S08 FOR FIELD CTU.
*SELECTION-SCREEN END OF LINE.
PARAMETERS: SESSION NO-DISPLAY,
CTU NO-DISPLAY DEFAULT 'X'.
*SELECTION-SCREEN BEGIN OF LINE.
* SELECTION-SCREEN COMMENT 3(20) TEXT-S01 FOR FIELD GROUP.
* selection-screen position 25.
* PARAMETERS GROUP(12). "group name of session
* SELECTION-SCREEN COMMENT 48(20) TEXT-S05 FOR FIELD CTUMODE.
* selection-screen position 70.
* PARAMETERS CTUMODE LIKE CTU_PARAMS-DISMODE DEFAULT 'N'.
* "A: show all dynpros
* "E: show dynpro on error only
* "N: do not display dynpro
*SELECTION-SCREEN END OF LINE.
PARAMETERS: GROUP(12) NO-DISPLAY,
CTUMODE NO-DISPLAY DEFAULT 'N'.
*SELECTION-SCREEN BEGIN OF LINE.
* SELECTION-SCREEN COMMENT 3(20) TEXT-S02 FOR FIELD USER.
* selection-screen position 25.
* PARAMETERS: USER(12) DEFAULT SY-UNAME. "user for session in batch
* SELECTION-SCREEN COMMENT 48(20) TEXT-S06 FOR FIELD CUPDATE.
* selection-screen position 70.
* PARAMETERS CUPDATE LIKE CTU_PARAMS-UPDMODE DEFAULT 'L'.
* "S: synchronously
* "A: asynchronously
* "L: local
*SELECTION-SCREEN END OF LINE.
PARAMETERS: USER(12) NO-DISPLAY DEFAULT SY-UNAME,
CUPDATE LIKE CTU_PARAMS-UPDMODE DEFAULT 'L' NO-DISPLAY.
*SELECTION-SCREEN BEGIN OF LINE.
* SELECTION-SCREEN COMMENT 3(20) TEXT-S03 FOR FIELD KEEP.
* selection-screen position 25.
* PARAMETERS: KEEP AS CHECKBOX. "' ' = delete session if finished
* "'X' = keep session if finished
* SELECTION-SCREEN COMMENT 48(20) TEXT-S09 FOR FIELD E_GROUP.
* selection-screen position 70.
* parameters E_GROUP(12). "group name of error-session
*SELECTION-SCREEN END OF LINE.
PARAMETERS: KEEP NO-DISPLAY,
E_GROUP(12) NO-DISPLAY.
*SELECTION-SCREEN BEGIN OF LINE.
* SELECTION-SCREEN COMMENT 3(20) TEXT-S04 FOR FIELD HOLDDATE.
* selection-screen position 25.
* PARAMETERS: HOLDDATE LIKE SY-DATUM.
* SELECTION-SCREEN COMMENT 51(17) TEXT-S02 FOR FIELD E_USER.
* selection-screen position 70.
* PARAMETERS: E_USER(12) DEFAULT SY-UNAME. "user for error-session
*SELECTION-SCREEN END OF LINE.
PARAMETERS: HOLDDATE LIKE SY-DATUM NO-DISPLAY,
E_USER(12) DEFAULT SY-UNAME NO-DISPLAY.
*SELECTION-SCREEN BEGIN OF LINE.
* SELECTION-SCREEN COMMENT 51(17) TEXT-S03 FOR FIELD E_KEEP.
* selection-screen position 70.
* PARAMETERS: E_KEEP AS CHECKBOX. "' ' = delete session if finished
* "'X' = keep session if finished
*SELECTION-SCREEN END OF LINE.
PARAMETERS: E_KEEP NO-DISPLAY.
*SELECTION-SCREEN BEGIN OF LINE.
* SELECTION-SCREEN COMMENT 51(17) TEXT-S04 FOR FIELD E_HDATE.
* selection-screen position 70.
* PARAMETERS: E_HDATE LIKE SY-DATUM.
*SELECTION-SCREEN END OF LINE.
*
*SELECTION-SCREEN SKIP.
PARAMETERS: E_HDATE LIKE SY-DATUM NO-DISPLAY.
*SELECTION-SCREEN BEGIN OF LINE.
* SELECTION-SCREEN COMMENT 1(33) TEXT-S10 FOR FIELD NODATA.
* PARAMETERS: NODATA DEFAULT '/' LOWER CASE. "nodata
*SELECTION-SCREEN END OF LINE.
PARAMETERS: NODATA DEFAULT '/' LOWER CASE NO-DISPLAY.
*SELECTION-SCREEN BEGIN OF LINE.
* SELECTION-SCREEN COMMENT 1(33) FOR FIELD SMALLLOG.
* PARAMETERS: SMALLLOG as checkbox. "' ' = log all transactions
* "'X' = no transaction logging
*SELECTION-SCREEN END OF LINE.
PARAMETERS: SMALLLOG NO-DISPLAY.
*----------------------------------------------------------------------*
* data definition
*----------------------------------------------------------------------*
* Batchinputdata of single transaction
DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
* messages of call transaction
DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
* error session opened (' ' or 'X')
DATA: E_GROUP_OPENED.
* message texts
TABLES: T100.
*----------------------------------------------------------------------*
* at selection screen *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
* group and user must be filled for create session
IF SESSION = 'X' AND
GROUP = SPACE OR USER = SPACE.
MESSAGE E613(MS).
ENDIF.
*----------------------------------------------------------------------*
* open dataset *
*----------------------------------------------------------------------*
FORM OPEN_DATASET USING P_DATASET.
OPEN DATASET P_DATASET IN TEXT MODE.
IF SY-SUBRC <> 0.
WRITE: / TEXT-E00, SY-SUBRC.
STOP.
ENDIF.
ENDFORM.
*----------------------------------------------------------------------*
* close dataset *
*----------------------------------------------------------------------*
FORM CLOSE_DATASET USING P_DATASET.
CLOSE DATASET P_DATASET.
ENDFORM.
*----------------------------------------------------------------------*
* create batchinput session *
* (not for call transaction using...) *
*----------------------------------------------------------------------*
FORM OPEN_GROUP.
IF SESSION = 'X'.
SKIP.
WRITE: /(20) 'Create group'(I01), GROUP.
SKIP.
* open batchinput group
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING CLIENT = SY-MANDT
GROUP = GROUP
USER = USER
KEEP = KEEP
HOLDDATE = HOLDDATE.
WRITE: /(30) 'BDC_OPEN_GROUP'(I02),
(12) 'returncode:'(I05),
SY-SUBRC.
ENDIF.
ENDFORM.
*----------------------------------------------------------------------*
* end batchinput session *
* (call transaction using...: error session) *
*----------------------------------------------------------------------*
FORM CLOSE_GROUP.
IF SESSION = 'X'.
* close batchinput group
CALL FUNCTION 'BDC_CLOSE_GROUP'.
WRITE: /(30) 'BDC_CLOSE_GROUP'(I04),
(12) 'returncode:'(I05),
SY-SUBRC.
ELSE.
IF E_GROUP_OPENED = 'X'.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
WRITE: /.
WRITE: /(30) 'Fehlermappe wurde erzeugt'(I06).
ENDIF.
ENDIF.
ENDFORM.
*----------------------------------------------------------------------*
* Start new transaction according to parameters *
*----------------------------------------------------------------------*
FORM BDC_TRANSACTION USING TCODE.
DATA: L_MSTRING(480).
DATA: L_SUBRC LIKE SY-SUBRC.
* batch input session
IF SESSION = 'X'.
CALL FUNCTION 'BDC_INSERT'
EXPORTING TCODE = TCODE
TABLES DYNPROTAB = BDCDATA.
IF SMALLLOG <> 'X'.
WRITE: / 'BDC_INSERT'(I03),
TCODE,
'returncode:'(I05),
SY-SUBRC,
'RECORD:',
SY-INDEX.
ENDIF.
* call transaction using
ELSE.
REFRESH MESSTAB.
CALL TRANSACTION TCODE USING BDCDATA
MODE CTUMODE
UPDATE CUPDATE
MESSAGES INTO MESSTAB.
L_SUBRC = SY-SUBRC.
IF SMALLLOG <> 'X'.
* WRITE: / 'CALL_TRANSACTION',
* TCODE,
* 'returncode:'(I05),
* L_SUBRC,
* 'RECORD:',
* SY-INDEX.
IF SY-SUBRC = 0.
FORMAT COLOR OFF.
WRITE:/ 'Successfully Process ', MESSTAB, RECORD.
ELSE.
FORMAT COLOR COL_NEGATIVE.
WRITE:/ 'Failed Process ', MESSTAB, RECORD.
ENDIF.
LOOP AT MESSTAB.
SELECT SINGLE * FROM T100 WHERE SPRSL = MESSTAB-MSGSPRA
AND ARBGB = MESSTAB-MSGID
AND MSGNR = MESSTAB-MSGNR.
IF SY-SUBRC = 0.
L_MSTRING = T100-TEXT.
IF L_MSTRING CS '&1'.
REPLACE '&1' WITH MESSTAB-MSGV1 INTO L_MSTRING.
REPLACE '&2' WITH MESSTAB-MSGV2 INTO L_MSTRING.
REPLACE '&3' WITH MESSTAB-MSGV3 INTO L_MSTRING.
REPLACE '&4' WITH MESSTAB-MSGV4 INTO L_MSTRING.
ELSE.
REPLACE '&' WITH MESSTAB-MSGV1 INTO L_MSTRING.
REPLACE '&' WITH MESSTAB-MSGV2 INTO L_MSTRING.
REPLACE '&' WITH MESSTAB-MSGV3 INTO L_MSTRING.
REPLACE '&' WITH MESSTAB-MSGV4 INTO L_MSTRING.
ENDIF.
CONDENSE L_MSTRING.
WRITE: / MESSTAB-MSGTYP, L_MSTRING(250).
ELSE.
WRITE: / MESSTAB.
ENDIF.
ENDLOOP.
SKIP.
ENDIF.
** Erzeugen fehlermappe ************************************************
IF L_SUBRC <> 0 AND E_GROUP <> SPACE.
IF E_GROUP_OPENED = ' '.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING CLIENT = SY-MANDT
GROUP = E_GROUP
USER = E_USER
KEEP = E_KEEP
HOLDDATE = E_HDATE.
E_GROUP_OPENED = 'X'.
ENDIF.
CALL FUNCTION 'BDC_INSERT'
EXPORTING TCODE = TCODE
TABLES DYNPROTAB = BDCDATA.
ENDIF.
ENDIF.
REFRESH BDCDATA.
ENDFORM.
*----------------------------------------------------------------------*
* 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.
IF FVAL <> NODATA.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDIF.
ENDFORM.
--- End of ABAP Program
Hope this helps, Do reward.
2008 Feb 13 10:00 AM
Recording will give you a simple way to find the screen numbers, programs and fields to update your data. Even you can write a BDC program with out using recording also.
But, you have to find the screen numbers and program names and field name mannually.
So, better to use recording before creating any BDC program.
2008 Feb 18 6:23 PM
hi,
The data from internal table is not transferred directly to database table, it has to go through transaction. You need to pass data to particular screen and to particular screen-field. Data is passed to transaction in particular format, hence there is a need for batch input structure.
The batch input structure stores the data that is to be entered into SAP system and the actions that are necessary to process the data. The batch input structure is used by all of the batch input methods. This structure is BDCDATA, which can contain the batch input data for only a single run of a transaction.
Within a BDCDATA structure, organize the data of screens in a transaction. Each screen that is processed in the course of a transaction must be identified with a BDCDATA record. This record uses the Program, Dynpro, and Dynbegin fields of the structure.
The BDCDATA structure contains the following fields:
PROGRAM: Name of module pool program associated with the screen. Set this field only for the first record for the screen.
DYNPRO: Screen Number. Set this field only in the first record for the screen.
DYNBEGIN: Indicates the first record for the screen. Set this field to X, only for the first record for the screen. (Reset to (blank) for all other records.)
FNAM: Field Name. The FNAM field is not case-sensitive.
FVAL: Value for the field named in FNAM. The FVAL field is case-sensitive. Values assigned to this field are always padded on the right, if they are less than 132 characters. Values must be in character format.
*Hence, all this data is captured when you do the recording of the transaction in SHDB, else you get the details required by this BDCDATA structure in the following way:*
Start the transaction by menu or by entering the transaction code in the command box.
(You can determine the transaction name by choosing System Status.)
Step through the transaction, entering the data will be required for processing your batch input data.
On each screen, note the program name and screen (dynpro) number.
(dynpro = dyn + pro. Dyn = screen, pro = number)
Display these by choosing System Status. The relevant fields are Program (dynpro) and Dynpro number. If pop-up windows occur during execution, you can get the program name and screen number by pressing F1 on any field or button on the screen.
The technical info pop-up shows not only the field information but also the program and screen.
For each field, check box, and radio button on each screen, press F1 (help) and then choose Technical Info.
Note the following information:
The field name for batch input, which youll find in its own box.
The length and data type of the field. You can display this information by double clicking on the Data Element field.
Find out the identification code for each function (button or menu) that you must execute to process the batch-input data (or to go to new screen).
Place the cursor on the button or menu entry while holding down the left mouse button. Then press F1.
In the pop-up window that follows, choose Technical info and note the code that is shown in the Function field.
You can also run any function that is assigned to a function key by way of the function key number. To display the list of available function keys, click on the right mouse button. Note the key number that is assigned to the functions you want to run.
Once you have program name, screen number, field name (screen field name), you can start writing the data transfer program.
So recording only makes the job less cumbersome. You can refrain from doing so too.
Hope that answered your query. Do reward points if it did.
Cheers,
Rakesh Damera
2008 Feb 18 7:48 PM
I find it easier to do it manually. You just have to execute the transaction and keep track of the technical names of the field that you use, the screens that you go through and the buttons that you press.
Rob
2024 Feb 21 5:31 AM