Search This Blog

Saturday, February 20, 2010

Session Method


Session Method is one of the BDC methods which is best in Maintenance.
We use Three FM's in Session Method:
BDC_OPEN_GROUP for creating SESSION OBJECT.
BDC_INSERT to insert data of the internal table.
BDC_CLOSE_GROUP to close SESSION OBJECT MEMORY from the program.

Sample code:
DATA : BEGIN OF ITAB OCCURS 0,
                 STR(255) TYPE C,
              END OF ITAB.

DATA : JTAB LIKE BDCDATA OCCURS 0 WITH HEADER LINE,
             ITAB1 LIKE MARA OCCURS 0 WITH HEADER LINE.

CALL FUNCTION 'UPLOAD'
     EXPORTING
          FILENAME = 'D:\930AM\MATDATA.TXT'
          FILETYPE = 'ASC'
     TABLES
          DATA_TAB = ITAB.


LOOP AT ITAB.
      SPLIT ITAB-STR AT ',' INTO ITAB1-MATNR ITAB1-MTART ITAB1-MBRSH ITAB1-MEINS.
      APPEND ITAB1.
ENDLOOP.


CALL FUNCTION 'BDC_OPEN_GROUP'
     EXPORTING
          CLIENT = SY-MANDT
          GROUP = 'SESS9301'
          KEEP = 'X'
          USER = SY-UNAME.

LOOP AT ITAB1.
     PERFORM PRGINFO USING 'SAPMZMPPSCR' '123'.
     PERFORM FLDINFO USING 'ITAB-MATNR' ITAB1-MATNR.
     PERFORM FLDINFO USING 'ITAB-MTART' ITAB1-MTART.
     PERFORM FLDINFO USING 'ITAB-MBRSH' ITAB1-MBRSH.
     PERFORM FLDINFO USING 'ITAB-MEINS' ITAB1-MEINS.

     CALL FUNCTION 'BDC_INSERT'
          EXPORTING
              TCODE = 'ZCT930'
          TABLES   
              DYNPROTAB = JTAB.
  ENDLOOP.

 CALL FUNCTION 'BDC_CLOSE_GROUP'.

FORM PRGINFO USING PROGRAMNAME SCRNUM.
     REFRESH JTAB.
     JTAB-PROGRAM = PROGRAMNAME.
     JTAB-DYNPRO = SCRNUM.
     JTAB-DYNBEGIN = 'X'.
     APPEND JTAB.
ENDFORM.


FORM FLDINFO USING FLDNAME FLDVAL.
     CLEAR JTAB.
     JTAB-FNAM = FLDNAME.
     JTAB-FVAL = FLDVAL.
     APPEND JTAB.
ENDFORM.

No comments:

Post a Comment