The shown routine ZZBDCRECXX_FB_GEN replaces BDCRECXX in a recorded ABAP. Upon executing, it will generate a function module from the recording with all variables as
parameters.
The ABAP generated by SHDB is a very useful tool for developers. However, it does not replace the recorded constants by variables.
The following routine generates a function module from the recording. All you have to do is put the coding below in an include.
Give it the name ZZBDCRECXX_FBGEN.
Then replace the include BDCRECXX in the recording with ZZBDCRECXX_FBGEN.
When you execute the ABAP, a function module in an existing function group will be created. The created function will contain the recording with all the constants replaced by variables, which show in the function module interface.
The following useful routine is written for releases up to 4.0B. In release 4.5B a similar functionality is provided. You can generate a function module from the recording transaction directly.
Before you generate the function, a function group must exist. This you have to do manually. The function group must also contain the include ZZBDCRECXX shown before, to have the declarations of the referenced FORM routines.
ZZBDCRECXX_FBGEN Replace BDCRECXX
Execute the ABAP once
Axel Angeli et.al. SAP R/3 Guide to EDI ISBN 3528157291
146
*---*
PARAMETERS: FUNCNAME LIKE RS38L-NAME DEFAULT 'Z_TESTING_BTCI_$1'.
PARAMETERS: FUGR LIKE RS38L-AREA DEFAULT 'Z_BTCI_TESTING'.
*---*
DATA: TABAP LIKE ABAPTEXT OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF XCONST OCCURS 0,
NAM LIKE DD03L-FIELDNAME, FREF LIKE DD03L-FIELDNAME, FVAL LIKE BDCDATA-FVAL, FIDX(6),
END OF XCONST.
DATA: STRL1 LIKE SY-FDPOS.
DATA: STRL2 LIKE STRL1.
DATA: IMPORT_PARAMETER LIKE RSIMP OCCURS 0 WITH HEADER LINE.
DATA: EXPORT_PARAMETER LIKE RSEXP OCCURS 0 WITH HEADER LINE.
DATA: TABLES_PARAMETER LIKE RSTBL OCCURS 0 WITH HEADER LINE.
DATA: CHANGING_PARAMETER LIKE RSCHA OCCURS 0 WITH HEADER LINE.
DATA: EXCEPTION_LIST LIKE RSEXC OCCURS 0 WITH HEADER LINE.
DATA: PARAMETER_DOCU LIKE RSFDO OCCURS 0 WITH HEADER LINE.
DATA: SHORT_TEXT LIKE TFTIT-STEXT
VALUE 'Generated BTCI for transaction ##'.
FORMAT COLOR COL_TOTAL.
WRITE: / 'Trying to generate function ', FUNCNAME.
FORMAT RESET.
ULINE.
SELECT SINGLE * FROM TLIBG WHERE AREA EQ FUGR.
IF SY-SUBRC NE 0.
MESSAGE I000(38) WITH 'Function Pool' FUGR 'does not exit'.
EXIT.
ENDIF.
MOVE 'PERFORM OPEN_GROUP.' TO TABAP.
APPEND TABAP.
*---*
XCONST-FNAM = 'INPUT_METHOD'.
XCONST-FREF = 'BDWFAP_PAR-INPUTMETHD'.
XCONST-FVAL = 'A'.
IMPORT_PARAMETER-PARAMETER = XCONST-FNAM.
IMPORT_PARAMETER-DBFIELD = XCONST-FREF.
CONCATENATE '''' XCONST-FVAL '''' INTO IMPORT_PARAMETER-DEFAULT.
IMPORT_PARAMETER-OPTIONAL = 'X'.
CASE XCONST-FIDX.
WHEN 'E'.
MOVE-CORRESPONDING IMPORT_PARAMETER TO EXPORT_PARAMETER.
APPEND EXPORT_PARAMETER.
WHEN '*'.
WHEN OTHERS.
APPEND IMPORT_PARAMETER.
ENDCASE.
* --make table parameters for obvious loop fields (fields with index) IF XCONST-FIDX CA ')*'.
MOVE-CORRESPONDING IMPORT_PARAMETER TO TABLES_PARAMETER.
TABLES_PARAMETER-DBSTRUCT = IMPORT_PARAMETER-DBFIELD.
IF XCONST-FIDX NE '*'.
WRITE: / XCONST-FNAM COLOR COL_TOTAL, (60) XCONST-FVAL.
ENDLOOP.
* SORT import_parameter BY parameter.
* DELETE ADJACENT DUPLICATES FROM import_parameter COMPARING parameter.
* SORT tables_parameter BY parameter.
* DELETE ADJACENT DUPLICATES FROM tables_parameter COMPARING parameter.
*---*
LOOP AT TABAP.
Axel Angeli et.al. SAP R/3 Guide to EDI ISBN 3528157291
147
WRITE: / TABAP COLOR COL_KEY.
ENDLOOP.
*---*
REPLACE '##' WITH XTCODE INTO SHORT_TEXT.
WRITE: / FUNCNAME COLOR COL_NEGATIVE.
WRITE: / SHORT_TEXT.
SELECT SINGLE * FROM TFDIR WHERE FUNCNAME EQ FUNCNAME.
IF SY-SUBRC EQ 0.
MESSAGE I000(38) WITH 'Function' FUNCNAME 'already exists'.
PERFORM SUCCESS_MESSAGE
USING 'Function' FUNCNAME 'already exists' SPACE ' '.
EXIT.
ENDIF.
CALL FUNCTION 'RPY_FUNCTIONMODULE_INSERT' EXPORTING
FORM BDC_TRANSACTION USING TCODE.
APPEND '*' TO TABAP.
MOVE 'PERFORM BDC_TRANSACTION_MODE USING I_TCODE INPUT_METHOD.' TO TABAP.
APPEND TABAP.
*---*
XTCODE = TCODE.
STR255 = FUNCNAME.
REPLACE '$1' WITH XTCODE INTO STR255.
CONDENSE STR255 NO-GAPS.
FUNCNAME = STR255.
*---*
XCONST-FNAM = 'I_TCODE'.
XCONST-FREF = 'SYST-TCODE'.
XCONST-FVAL = TCODE.
XCONST-FIDX = SPACE.
INSERT XCONST INDEX 1.
*---*
MOVE 'PERFORM GET_RESULTS TABLES TMESSTAB' TO TABAP.
APPEND TABAP.
MOVE ' READ TABLE RETURN_VARIABLES INDEX 1.' TO TABAP.
APPEND TABAP.
MOVE ' DOC_NUMBER = RETURN_VARIABLES-DOC_NUMBER.' TO TABAP.
APPEND TABAP.
*---*
XCONST-FNAM = 'TMESSTAB'.
XCONST-FREF = 'BDCMSGCOLL'.
XCONST-FVAL = SPACE.
XCONST-FIDX = '*'.
INSERT XCONST INDEX 1.
*---*
XCONST-FNAM = 'RETURN_VARIABLES'.
XCONST-FREF = 'BDWFRETVAR'.
XCONST-FVAL = SPACE.
XCONST-FIDX = '*'.
INSERT XCONST INDEX 1.
*---*
XCONST-FNAM = 'WORKFLOW_RESULT'.
Axel Angeli et.al. SAP R/3 Guide to EDI ISBN 3528157291
148
XCONST-FREF = 'BDWF_PARAM-RESULT'.
XCONST-FVAL = SPACE.
XCONST-FIDX = 'E'.
INSERT XCONST INDEX 1.
*---*
XCONST-FNAM = 'APPLICATION_VARIABLE'.
XCONST-FREF = 'BDWF_PARAM-APPL_VAR'.
XCONST-FIDX = 'E'.
INSERT XCONST INDEX 1.
*---*
XCONST-FNAM = 'DOC_NUMBER'.
XCONST-FREF = SPACE.
XCONST-FIDX = 'E'.
INSERT XCONST INDEX 1.
ENDFORM.
*---*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
TABAP = '*'.
FORM BDC_FIELD USING FNAM FVAL.
DATA: XFVAL LIKE BDCDATA-FVAL.
CLEAR XCONST.
CASE FNAM.
WHEN 'BDC_OKCODE' OR 'BDC_CURSOR' OR 'BDC_SUBSCR'.
CONCATENATE '''' FVAL '''' INTO XFVAL.
PERFORM ADD_BDCFIELD USING FNAM XCONST-FNAM.
ENDCASE.
ENDFORM. " BDC_FIELD
*---*
FORM ADD_BDCFIELD USING FNAM XFNAM.
CONCATENATE
CONCATENATE TABAP XFNAM '.' INTO TABAP SEPARATED BY SPACE.
APPEND TABAP.
ENDFORM. " add_bdcfield usinf fnam fval.
*---*
FORM SUCCESS_MESSAGE USING V1 V2 V3 V4 OK.
CONCATENATE V1 V2 V3 V4 INTO SY-LISEL SEPARATED BY SPACE.
REPLACE '##' WITH FUNCNAME INTO SY-LISEL.
MODIFY LINE 1.
IF OK EQ SPACE.
MODIFY LINE 1 LINE FORMAT COLOR COL_NEGATIVE.
ELSE.
MODIFY LINE 1 LINE FORMAT COLOR COL_POSITIVE.
ENDIF.
ENDFORM. "ccess_message USING v1 v2 v3 v4 ok.
Figure 91: Program ZZBDCRECXX_FBGEN found on http://www.idocs.de
The created function module should work without modification for testing at least.
However, you probably will need to modify it, e.g. by adding a loop for processing multiple entries in a table control (scroll area).
Test the function module and add eventual loops for detail processing.
Axel Angeli et.al. SAP R/3 Guide to EDI ISBN 3528157291
149
17 EDI and International Standards
With the growing importance of EDI, the fight for international standards heats up. While there are many business sectors like the automotive industry and book distribution who have used EDI for a long time and want to continue their investment, there are others who insist on a new modern standard for everybody.
The battle is still to reach its climax, but I shall estimate that the foray of the W3C for XML will succeed and make XML the EDI standard of the future.
Axel Angeli et.al. SAP R/3 Guide to EDI ISBN 3528157291