Google Search - Blog...........

SAP ABAP - BDC For J3GH In ETM Module - PM.

REPORT ZETM_BDC_J3GH.

************************************************************************
*TYPE-POOLS *
************************************************************************
TYPE-POOLS TRUXS.

************************************************************************
*TYPE DECLARATION *
************************************************************************
TYPES : BEGIN OF TYPE_BDCDATA,
PROGRAM TYPE BDC_PROG,
DYNPRO TYPE BDC_DYNR,
DYNBEGIN TYPE BDC_START,
FNAM TYPE FNAM_____4,
FVAL TYPE BDC_FVAL,
END OF TYPE_BDCDATA,

BEGIN OF TYPE_DATA,
J_3GBELDAT(10),
J_3GEMPFAE TYPE J_3GEMPFAE,
EQUNR TYPE EQUNR,
END OF TYPE_DATA.

************************************************************************
*WORK AREA DECLARATION *
************************************************************************
DATA : WA_BDCDATA TYPE TYPE_BDCDATA,
WA_DATA TYPE TYPE_DATA,
WA_MESSTAB TYPE BDCMSGCOLL,
WA_RAW TYPE TRUXS_T_TEXT_DATA.

************************************************************************
*INTERNAL TABLE DECLARATION *
************************************************************************
DATA : I_BDCDATA TYPE STANDARD TABLE OF TYPE_BDCDATA,
I_DATA TYPE STANDARD TABLE OF TYPE_DATA,
I_MESSTAB TYPE STANDARD TABLE OF BDCMSGCOLL.

************************************************************************
*DATA DECLARATION *
************************************************************************
DATA : WF_MESSAGE(100),
WF_CTR(3),
WF_CTR1(4),
WF_ITR(3),
WF_FNAM TYPE FNAM_____4.

************************************************************************
*SELECTION-SCREEN DECLARATION *
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK A1 WITH FRAME TITLE TEXT-001.
PARAMETERS : P_FILE TYPE LOCALFILE OBLIGATORY,
P_MODE DEFAULT 'A'.
SELECTION-SCREEN END OF BLOCK A1.

************************************************************************
*AT SELECTION-SCREEN ON VALUE-REQUEST DECLARATION *
************************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
FIELD_NAME = 'P_FILE'
CHANGING
FILE_NAME = P_FILE .

REFRESH I_DATA[].

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
I_LINE_HEADER = 'X'
I_TAB_RAW_DATA = WA_RAW
I_FILENAME = P_FILE
TABLES
I_TAB_CONVERTED_DATA = I_DATA
.

************************************************************************
*START-OF-SELECTION *
************************************************************************
START-OF-SELECTION.

LOOP AT I_DATA INTO WA_DATA.

AT NEW J_3GEMPFAE.

CLEAR : WF_CTR, WF_CTR1, WF_ITR.

WF_ITR = 10.

PERFORM BDC_DYNPRO USING 'SAPMJ3GF' '0101'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=ENTR'.
PERFORM BDC_FIELD USING 'J_3GBELK-J_3GBLART'
'C1'.

PERFORM BDC_DYNPRO USING 'SAPMJ3GF' '0010'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'J_3GBELK-J_3GBELDAT'
WA_DATA-J_3GBELDAT.
PERFORM BDC_FIELD USING 'J_3GBELK-J_3GEMPFAE'
WA_DATA-J_3GEMPFAE.
ENDAT.

WF_CTR = WF_CTR + 1.
WF_CTR1 = WF_CTR1 + 10.

PERFORM BDC_DYNPRO USING 'SAPMJ3GF' '0010'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
CLEAR WF_FNAM.
CONCATENATE 'J_3GBELP-EQUNR(' WF_CTR ')' INTO WF_FNAM.
CONDENSE WF_FNAM NO-GAPS.
PERFORM BDC_FIELD USING WF_FNAM
WA_DATA-EQUNR.

IF WF_ITR = WF_CTR.
PERFORM BDC_DYNPRO USING 'SAPMJ3GF' '0010'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'VON_POS'
WF_CTR1.
CLEAR WF_CTR.
WF_CTR = 1.
ENDIF.

AT END OF J_3GEMPFAE.
PERFORM BDC_DYNPRO USING 'SAPMJ3GF' '0010'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=SAVE'.

CALL TRANSACTION 'J3GH' USING I_BDCDATA MODE P_MODE UPDATE 'A' MESSAGES INTO I_MESSTAB.
REFRESH I_BDCDATA[].
ENDAT.

ENDLOOP.

************************************************************************
*START-OF-SELECTION *
************************************************************************
END-OF-SELECTION.

LOOP AT I_MESSTAB INTO WA_MESSTAB.

CLEAR WF_MESSAGE.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = WA_MESSTAB-MSGID
LANG = SY-LANGU
NO = WA_MESSTAB-MSGNR
V1 = WA_MESSTAB-MSGV1
V2 = WA_MESSTAB-MSGV2
V3 = WA_MESSTAB-MSGV3
V4 = WA_MESSTAB-MSGV4
IMPORTING
MSG = WF_MESSAGE
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.

WRITE / WF_MESSAGE .
ENDLOOP.
ULINE.

*&---------------------------------------------------------------------*
*& Form BDC_FIELD
*&---------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
CLEAR WA_BDCDATA.
WA_BDCDATA-FNAM = FNAM.
WA_BDCDATA-FVAL = FVAL.
APPEND WA_BDCDATA TO I_BDCDATA.
ENDFORM. " BDC_FIELD

*&---------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&---------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO .
CLEAR WA_BDCDATA.
WA_BDCDATA-PROGRAM = PROGRAM.
WA_BDCDATA-DYNPRO = DYNPRO.
WA_BDCDATA-DYNBEGIN = 'X'.
APPEND WA_BDCDATA TO I_BDCDATA.
ENDFORM. " BDC_DYNPRO

No comments:

Post a Comment