Showing posts with label Exxova. Show all posts
Showing posts with label Exxova. Show all posts

Wednesday, May 23, 2012

workflow - how to start FI workflow

Tcode : swo1

Provide Object/Interface Type [ZPO_BO844]
click on create.



For example create one KEY filed

Key field

Friday, May 4, 2012

BDC- call transaction for the infotype 0006

*&---------------------------------------------------------------------*
*& Report ZRAJBDC006
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*


report ZRAJBDC006
no standard page heading line-size 255.

*---Type pool Declaration
type-pools : SLIS.

*---Types declarations
types: begin of TY_PA006,
PERNR type CHAR8, "Personnel number
SUBTY type CHAR4, "Subtype
BEGDA type BEGDA, "Start Date
ENDDA type ENDDA, "End Date
NAME2 TYPE NAME2, "Contact name
STRAS TYPE STRAS, "Street and House Number
LOCAT TYPE LOCAT, "2nd Address Line
PSTLZ TYPE PSTLZ, "Postal Code
ORT01 TYPE ORT01, "City
ORT02 TYPE ORT02, "District
STATE TYPE STATE, "Region
LAND1 TYPE LAND1, "Country Key
TELNR TYPE TELNR, "Telephone Number

end of TY_PA006.

data: T_FILE type standard table of TY_PA006,
WA_FILE type TY_PA006.

data: V_MSG type STRING.

*---BDC internal table and work area Declarations
data: BDCDATA like BDCDATA occurs 0 with header line,
MESSTAB like BDCMSGCOLL occurs 0 with header line,
WA_MESSTAB type BDCMSGCOLL.

*---ALV Declarations internal tables and work area
data: T_FCAT type standard table of SLIS_FIELDCAT_ALV,
T_SORT type standard table of SLIS_SORTINFO_ALV,
T_EVENTS type SLIS_T_EVENT,
FCAT_REC type SLIS_FIELDCAT_ALV,
LAYOUT_REC type SLIS_LAYOUT_ALV,
EVENTS_REC type SLIS_ALV_EVENT.

*---Declaration for Output display
types : begin of TY_TAB1,
PERNR type PERNR_D,
msgty type char01,
MSG type STRING,
end of TY_TAB1.

data : ST_TAB type standard table of TY_TAB1,
SA_TAB type TY_TAB1.

*---Constants Declarations
constants: V_UPDATE type C value 'S',
V_MODE type C value 'D'.

*---Excel declarations
data : L_INTERN type ALSMEX_TABLINE occurs 0 with header line.
data : L_INDEX type I.
data : L_START_COL type I value '1',
L_START_ROW type I value '1',
L_END_COL type I value '256',
L_END_ROW type I value '65536',
G_FILE type IBIPPARMS-PATH.

*---Selection Screen Declarations
selection-screen begin of block B1 with frame title TEXT-001.
parameters: R1 radiobutton group RB user-command PIK default 'X',
R2 radiobutton group RB .

selection-screen begin of block B2 with frame title TEXT-002.
parameters : P_FILE like IBIPPARMS-PATH modif id M1.
selection-screen end of block B2.

selection-screen begin of block B3 with frame title TEXT-003.
parameters : P_FILE1 type STRING modif id M2. "" like rlgrap-filename modif id M2.
selection-screen end of block B3.

selection-screen end of block B1.

*---AT SELECTION-SCREEN
at selection-screen on value-request for P_FILE.
call function 'F4_FILENAME'
IMPORTING
FILE_NAME = P_FILE.

at selection-screen on value-request for P_FILE1.
call function 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = 'p_file1'
IMPORTING
FILE_NAME = G_FILE.
P_FILE1 = G_FILE.


*---At Selection-screen
at selection-screen output.
if R1 = 'X'.
loop at screen.
if SCREEN-GROUP1 = 'M1'.
SCREEN-ACTIVE = 0.
SCREEN-INVISIBLE = 1.
modify screen.
endif.
endloop.
elseif R2 = 'X'.
loop at screen.
if SCREEN-GROUP1 = 'M2'.
SCREEN-ACTIVE = 0.
SCREEN-INVISIBLE = 1.
modify screen.
endif.
endloop.
endif.

start-of-selection.

if R2 is not initial.
*---Fetching Excel file from Desktop
field-symbols : .
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = P_FILE
I_BEGIN_COL = L_START_COL
I_BEGIN_ROW = L_START_ROW
I_END_COL = L_END_COL
I_END_ROW = L_END_ROW
TABLES
INTERN = L_INTERN
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
others = 3.

if L_INTERN[] is initial.
message I010(Z1).
exit.
else.
sort L_INTERN by ROW COL.
loop at L_INTERN.
move L_INTERN-COL to L_INDEX.
assign component L_INDEX of structure WA_FILE to .
if SY-SUBRC = 0. " Incase there are more xls columns than fields
move L_INTERN-VALUE to .
endif.
at end of ROW.
append WA_FILE to T_FILE.
clear WA_FILE.
endat.
endloop.
endif.
elseif R1 is not initial.
*---Fetching Text file from Desktop

call function 'GUI_UPLOAD'
EXPORTING
FILENAME = P_FILE1
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = T_FILE
EXCEPTIONS
FILE_OPEN_ERROR = 1
others = 2.

endif.

*---BDC Recording
loop at T_FILE into WA_FILE.

perform bdc_dynpro using 'SAPMP50A' '1000'.
perform bdc_field using 'BDC_OKCODE'
'=INS'.
perform bdc_field using 'RP50G-PERNR' "pernr
WA_FILE-PERNR.
perform bdc_field using 'RP50G-TIMR6'
'X'.
perform bdc_field using 'BDC_CURSOR'
'RP50G-SUBTY'.
perform bdc_field using 'RP50G-CHOIC'
'006'.
perform bdc_field using 'RP50G-SUBTY'
WA_FILE-SUBTY. "subtype
perform bdc_dynpro using 'MP000600' '2000'.
perform bdc_field using 'BDC_CURSOR'
'P0006-STATE'.
perform bdc_field using 'BDC_OKCODE'
'=UPD'.
perform bdc_field using 'P0006-BEGDA'
WA_FILE-BEGDA. "begda
perform bdc_field using 'P0006-ENDDA'
WA_FILE-ENDDA. "endda
perform bdc_field using 'P0006-NAME2'
WA_FILE-NAME2. "Contact Name
perform bdc_field using 'P0006-STRAS'
WA_FILE-STRAS. "Street and House Number
perform bdc_field using 'P0006-LOCAT'
WA_FILE-LOCAT. "2nd Address Line
perform bdc_field using 'P0006-PSTLZ'
WA_FILE-PSTLZ. "postalcode
perform bdc_field using 'P0006-ORT01'
WA_FILE-ORT01. "City
perform bdc_field using 'P0006-ORT02'
WA_FILE-ORT02. "District
perform bdc_field using 'P0006-STATE'
WA_FILE-STATE. "Region
perform bdc_field using 'P0006-LAND1'
WA_FILE-LAND1. "Country Key
perform bdc_field using 'P0006-TELNR'
WA_FILE-TELNR. "Telephone Number

call transaction 'PA30' using BDCDATA
mode V_MODE
update V_UPDATE
messages into MESSTAB.

loop at MESSTAB into WA_MESSTAB.
*---Formating messages
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 = V_MSG
EXCEPTIONS
NOT_FOUND = 1
others = 2.
* write:/2 WA_FILE-PERNR, 15 V_MSG.

*---ALV display
move WA_FILE-PERNR to SA_TAB-PERNR.
move WA_MESSTAB-msgtyp to SA_TAB-msgty.
move V_MSG to SA_TAB-MSG.
append SA_TAB to ST_TAB.
clear SA_TAB.

endloop.
clear: WA_FILE,WA_MESSTAB.
refresh: MESSTAB,BDCDATA.
endloop.

*&---------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form BDC_DYNPRO using PROGRAM DYNPRO.

clear BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
append BDCDATA.
endform. " BDC_DYNPRO
*&---------------------------------------------------------------------*
*& Form BDC_FIELD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form BDC_FIELD using FNAM FVAL.
if FVAL <> ' '.
clear BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
append BDCDATA.
endif.
endform. " BDC_FIELD

end-of-selection.

*---Fieldcatalog
FCAT_REC-FIELDNAME = 'PERNR'.
FCAT_REC-SELTEXT_L = 'Personal Number'.
append FCAT_REC to T_FCAT.
clear FCAT_REC.

FCAT_REC-FIELDNAME = 'MSGTY'.
FCAT_REC-SELTEXT_L = 'Message Type'.
append FCAT_REC to T_FCAT.
clear FCAT_REC.

FCAT_REC-FIELDNAME = 'MSG'.
FCAT_REC-SELTEXT_L = 'Message'.
append FCAT_REC to T_FCAT.
clear FCAT_REC.

LAYOUT_REC-NO_INPUT = 'X'.
LAYOUT_REC-COLWIDTH_OPTIMIZE = 'X'.
LAYOUT_REC-INFO_FIELDNAME = 'LINE_COLOR'.

*---ALV List Display
call function 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT = LAYOUT_REC
IT_FIELDCAT = T_FCAT
TABLES
T_OUTTAB = ST_TAB[].

Thursday, May 3, 2012

BDC-Refference-Create the Selection screen to take the Excel sheet. Display the error log and the success records in ALV

report ZREE
no standard page heading line-size 255.

*---Type pool Declaration
type-pools : SLIS.

*---Types declarations
types: begin of TY_PA0022,
PERNR type CHAR8, "Personnel number
SUBTY type CHAR4, "Subtype
BEGDA type BEGDA, "Start Date
ENDDA type ENDDA, "End Date
AUSBI type CHAR6, "Education/training
INSTI type CHAR80, "Institute/location of training
SLAND type CHAR3, "Country
SLABS type CHAR2, "Certificate
ANZKL type CHAR2, "Duration of training course"
EMARK type CHAR4, "Final Grade
end of TY_PA0022.

data: T_FILE type standard table of TY_PA0022,
WA_FILE type TY_PA0022.

data: V_MSG type STRING.

*---BDC internal table and work area Declarations
data: BDCDATA like BDCDATA occurs 0 with header line,
MESSTAB like BDCMSGCOLL occurs 0 with header line,
WA_MESSTAB type BDCMSGCOLL.

*---ALV Declarations internal tables and work area
data: T_FCAT type standard table of SLIS_FIELDCAT_ALV,
T_SORT type standard table of SLIS_SORTINFO_ALV,
T_EVENTS type SLIS_T_EVENT,
FCAT_REC type SLIS_FIELDCAT_ALV,
LAYOUT_REC type SLIS_LAYOUT_ALV,
EVENTS_REC type SLIS_ALV_EVENT.

*---Declaration for Output display
types : begin of TY_TAB1,
PERNR type PERNR_D,
MSG type STRING,
end of TY_TAB1.

data : ST_TAB type standard table of TY_TAB1,
SA_TAB type TY_TAB1.

*---Constants Declarations
constants: V_UPDATE type C value 'S',
V_MODE type C value 'N'.

*---Excel declarations
data : L_INTERN type ALSMEX_TABLINE occurs 0 with header line.
data : L_INDEX type I.
data : L_START_COL type I value '1',
L_START_ROW type I value '1',
L_END_COL type I value '256',
L_END_ROW type I value '65536',
G_FILE type IBIPPARMS-PATH.

*---Selection Screen Declarations
selection-screen begin of block B1 with frame title TEXT-001.
parameters: R1 radiobutton group RB user-command PIK default 'X',
R2 radiobutton group RB .

selection-screen begin of block B2 with frame title TEXT-002.
parameters : P_FILE like IBIPPARMS-PATH modif id M1.
selection-screen end of block B2.

selection-screen begin of block B3 with frame title TEXT-003.
parameters : P_FILE1 type STRING modif id M2. "" like rlgrap-filename modif id M2.
selection-screen end of block B3.

selection-screen end of block B1.

*---AT SELECTION-SCREEN
at selection-screen on value-request for P_FILE.
call function 'F4_FILENAME'
importing
FILE_NAME = P_FILE.

at selection-screen on value-request for P_FILE1.
call function 'F4_FILENAME'
exporting
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = 'p_file1'
importing
FILE_NAME = G_FILE.
P_FILE1 = G_FILE.


*---At Selection-screen
at selection-screen output.
if R1 = 'X'.
loop at screen.
if SCREEN-GROUP1 = 'M1'.
SCREEN-ACTIVE = 0.
SCREEN-INVISIBLE = 1.
modify screen.
endif.
endloop.
elseif R2 = 'X'.
loop at screen.
if SCREEN-GROUP1 = 'M2'.
SCREEN-ACTIVE = 0.
SCREEN-INVISIBLE = 1.
modify screen.
endif.
endloop.
endif.

start-of-selection.

if R2 is not initial.
*---Fetching Excel file from Desktop
field-symbols : .
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
FILENAME = P_FILE
I_BEGIN_COL = L_START_COL
I_BEGIN_ROW = L_START_ROW
I_END_COL = L_END_COL
I_END_ROW = L_END_ROW
tables
INTERN = L_INTERN
exceptions
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
others = 3.

if L_INTERN[] is initial.
message I010(Z1).
exit.
else.
sort L_INTERN by ROW COL.
loop at L_INTERN.
move L_INTERN-COL to L_INDEX.
assign component L_INDEX of structure WA_FILE to .
if SY-SUBRC = 0. " Incase there are more xls columns than fields
move L_INTERN-VALUE to .
endif.
at end of ROW.
append WA_FILE to T_FILE.
clear WA_FILE.
endat.
endloop.
endif.
elseif R1 is not initial.
*---Fetching Text file from Desktop

call function 'GUI_UPLOAD'
exporting
FILENAME = P_FILE1
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
tables
DATA_TAB = T_FILE
exceptions
FILE_OPEN_ERROR = 1
others = 2.

endif.

*---BDC Recording
loop at T_FILE into WA_FILE.

perform BDC_DYNPRO using 'SAPMP50A' '1000'.
perform BDC_FIELD using 'BDC_OKCODE'
'=INS'.
perform BDC_FIELD using 'RP50G-PERNR'
WA_FILE-PERNR.
perform BDC_FIELD using 'RP50G-TIMR6'
'X'.
perform BDC_FIELD using 'BDC_CURSOR'
'RP50G-SUBTY'.
perform BDC_FIELD using 'RP50G-CHOIC'
'22'.
perform BDC_FIELD using 'RP50G-SUBTY'
WA_FILE-SUBTY.
perform BDC_DYNPRO using 'MP002200' '2000'.
perform BDC_FIELD using 'BDC_CURSOR'
'P0022-EMARK'.
perform BDC_FIELD using 'BDC_OKCODE'
'=UPD'.
perform BDC_FIELD using 'P0022-BEGDA'
WA_FILE-BEGDA.
perform BDC_FIELD using 'P0022-ENDDA'
WA_FILE-ENDDA.
perform BDC_FIELD using 'P0022-SLART'
'01'.
perform BDC_FIELD using 'P0022-AUSBI'
WA_FILE-AUSBI.
perform BDC_FIELD using 'P0022-INSTI'
WA_FILE-INSTI.
perform BDC_FIELD using 'P0022-SLAND'
WA_FILE-SLAND.
perform BDC_FIELD using 'P0022-SLABS'
WA_FILE-SLABS.
perform BDC_FIELD using 'P0022-ANZKL'
WA_FILE-ANZKL.
perform BDC_FIELD using 'P0022-EMARK'
WA_FILE-EMARK.
call transaction 'PA30' using BDCDATA
mode V_MODE
update V_UPDATE
messages into MESSTAB.

loop at MESSTAB into WA_MESSTAB.
*---Formating messages
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 = V_MSG
exceptions
NOT_FOUND = 1
others = 2.
* write:/2 WA_FILE-PERNR, 15 V_MSG.

*---ALV display
move WA_FILE-PERNR to SA_TAB-PERNR.
move V_MSG to SA_TAB-MSG.
append SA_TAB to ST_TAB.
clear SA_TAB.

endloop.
clear: WA_FILE,WA_MESSTAB.
refresh: MESSTAB,BDCDATA.
endloop.

*&---------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form BDC_DYNPRO using PROGRAM DYNPRO.

clear BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
append BDCDATA.
endform. " BDC_DYNPRO
*&---------------------------------------------------------------------*
*& Form BDC_FIELD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form BDC_FIELD using FNAM FVAL.
if FVAL <> ' '.
clear BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
append BDCDATA.
endif.
endform. " BDC_FIELD

end-of-selection.

*---Fieldcatalog
FCAT_REC-FIELDNAME = 'PERNR'.
FCAT_REC-SELTEXT_L = 'Personal Number'.
append FCAT_REC to T_FCAT.
clear FCAT_REC.

FCAT_REC-FIELDNAME = 'MSG'.
FCAT_REC-SELTEXT_L = 'Message'.
append FCAT_REC to T_FCAT.
clear FCAT_REC.

LAYOUT_REC-NO_INPUT = 'X'.
LAYOUT_REC-COLWIDTH_OPTIMIZE = 'X'.
LAYOUT_REC-INFO_FIELDNAME = 'LINE_COLOR'.

*---ALV List Display
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT = LAYOUT_REC
IT_FIELDCAT = T_FCAT
tables
T_OUTTAB = ST_TAB[].

BDC-using session method - infotype 22

*&---------------------------------------------------------------------*
*& Report ZRAJBDC22
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZRAJBDC22.

TYPE-POOLS: SLIS.

TYPES: BEGIN OF TY_22,

PERNR type PERNR, "Personnel No
SUBTY type RP50G-SUBTY, "Sub Type
BEGDA type P0022-BEGDA, "Begin Date
ENDDA type P0022-ENDDA, "End Date
AUSBI type P0022-AUSBI, "Education/training
INSTI type P0022-INSTI, "Institute/location
SLAND type P0022-SLAND, "Country Key
SLABS type P0022-SLABS, "Certificate
ANZKL type P0022-ANZKL, "Duration of course
EMARK type P0022-EMARK, "Final Grade

END OF TY_22.

DATA : IT_22 TYPE TABLE OF TY_22,
WA_22 TYPE TY_22.


data : wa_bdcdata type bdcdata,
it_bdcdata type table of bdcdata.
* g_file type ibipparms-path.

DATA: P_RETURN TYPE BAPIRETURN1.



*------------selection-screen-------------------


DATA: d_ucomm LIKE sy-ucomm.
data : g_file type ibipparms-path.
data : g_file1 type ibipparms-path.
selection-screen begin of block b1 with frame title text-999.
PARAMETERS: p_TXT RADIOBUTTON GROUP rad1 USER-COMMAND ACT DEFAULT 'X',
p_XLS RADIOBUTTON GROUP rad1.


selection-SCREEN end of block b1.


selection-screen begin of block b2 with frame title text-998.
PARAMETERS: p_file type string MODIF ID A, "Text file
* p_file1 type RLGRAP-FILENAME MODIF ID a,
p1_file type RLGRAP-FILENAME MODIF ID b. "Xls/Csv file
* p_file2 type RLGRAP-FILENAME MODIF ID b.
selection-SCREEN end of block b2.

selection-screen begin of block b3 with frame title text-997.

PARAMETERS: p_ses TYPE char12.

selection-screen end of block b3.


AT SELECTION-SCREEN.
d_ucomm = sy-ucomm.

AT SELECTION-SCREEN OUTPUT.
LOOP AT screen.
IF p_TXT = 'X'.
IF screen-group1 = 'B'.
screen-active = 0.
ENDIF.
ELSEIF p_XLS = 'X'.
IF screen-group1 = 'A'.
screen-active = 0.
ENDIF.
ENDIF.
MODIFY screen.
ENDLOOP.



at SELECTION-SCREEN on VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = 'p_file'
IMPORTING
FILE_NAME = g_file.
p_file = g_file.


at SELECTION-SCREEN on VALUE-REQUEST FOR p1_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = 'p1_file'
IMPORTING
FILE_NAME = g_file.
p1_file = g_file.

if p_txt = 'X'.
p_file = g_file.
endif.

if p_xls = 'X'.
p1_file = g_file.

endif.

*AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file1.
* PERFORM f_browse CHANGING p_file1.
*
*AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file2.
* PERFORM f_browse CHANGING p_file2.

*------------end of Selection-screen-------------------


START-OF-SELECTION.
*------------------------Logic for up load data from files-------------
*-----------------------CODE FOR TEXT UPLOAD--------------------------

if p_txt = 'X'.

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = P_FILE
* FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* VIRUS_SCAN_PROFILE =
* NO_AUTH_CHECK = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
DATA_TAB = it_22
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.

IF p_XLS = 'X'.

*------This logic is for executing Excel and csv file------------

data : l_intern type alsmex_tabline occurs 0 with header line.
data : l_index type i.
data : l_start_col type i value '1',
l_start_row type i value '1',
l_end_col type i value '256',
l_end_row type i value '65536'.

if p1_file is not initial.
field-symbols : .
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p1_file
i_begin_col = l_start_col
i_begin_row = l_start_row
i_end_col = l_end_col
i_end_row = l_end_row
TABLES
intern = l_intern
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
others = 3.

if l_intern[] is initial.
* message i010(z1).
exit.
else.
sort l_intern by row col.
loop at l_intern.
move l_intern-col to l_index.
assign component l_index of structure wa_22 to .
if sy-subrc = 0. " Incase there are more xls columns than fields
move l_intern-value to .
endif.
at end of row.
append wa_22 to it_22.
clear wa_22.
endat.
endloop.
endif.

endif.
endif.

*---------------end of logic for upload data-------------------------

BREAK-POINT.

*-----------------Start BDC------------------
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
* DEST = FILLER8
GROUP = p_ses
* HOLDDATE = FILLER8
KEEP = 'X'
USER = SY-UNAME
* RECORD = FILLER1
* PROG = SY-CPROG
* DCPFM = '%'
* DATFM = '%'
* IMPORTING
* QID =
EXCEPTIONS
CLIENT_INVALID = 1
DESTINATION_INVALID = 2
GROUP_INVALID = 3
GROUP_IS_LOCKED = 4
HOLDDATE_INVALID = 5
INTERNAL_ERROR = 6
QUEUE_ERROR = 7
RUNNING = 8
SYSTEM_LOCK_ERROR = 9
USER_INVALID = 10
OTHERS = 11
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

REFRESH IT_BDCdata.


*perform open_group.
LOOP AT it_22 into wa_22.

*include bdcrecx1.



*perform open_group.

perform BDC_DYNPRO using 'SAPMP50A' '1000' 'X'.
perform BDC_FIELD using 'BDC_OKCODE'
'=INS'.
perform BDC_FIELD using 'RP50G-PERNR'
WA_22-PERNR.
perform BDC_FIELD using 'RP50G-TIMR6'
'X'.
perform BDC_FIELD using 'BDC_CURSOR'
'RP50G-SUBTY'.
perform BDC_FIELD using 'RP50G-CHOIC'
'22'.
perform BDC_FIELD using 'RP50G-SUBTY'
WA_22-SUBTY.
perform BDC_DYNPRO using 'MP002200' '2000' 'X'.
perform BDC_FIELD using 'BDC_CURSOR'
'P0022-EMARK'.
perform BDC_FIELD using 'BDC_OKCODE'
'=UPD'.
perform BDC_FIELD using 'P0022-BEGDA'
WA_22-BEGDA.
perform BDC_FIELD using 'P0022-ENDDA'
WA_22-ENDDA.
perform BDC_FIELD using 'P0022-SLART'
'01'.
perform BDC_FIELD using 'P0022-AUSBI'
WA_22-AUSBI.
perform BDC_FIELD using 'P0022-INSTI'
WA_22-INSTI.
perform BDC_FIELD using 'P0022-SLAND'
WA_22-SLAND.
perform BDC_FIELD using 'P0022-SLABS'
WA_22-SLABS.
perform BDC_FIELD using 'P0022-ANZKL'
WA_22-ANZKL.
perform BDC_FIELD using 'P0022-EMARK'
WA_22-EMARK.


* CALL TRANSACTION 'PA30' USING




*perform close_group.


CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'PA30'
* POST_LOCAL = NOVBLOCAL
* PRINTING = NOPRINT
* SIMUBATCH = ' '
* CTUPARAMS = ' '
TABLES
DYNPROTAB = it_bdcdata
EXCEPTIONS
INTERNAL_ERROR = 1
NOT_OPEN = 2
QUEUE_ERROR = 3
TCODE_INVALID = 4
PRINTING_INVALID = 5
POSTING_INVALID = 6
OTHERS = 7
.
IF SY-SUBRC <> 0.
refresh it_bdcdata.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
clear wa_22.


ENDLOOP.


CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
NOT_OPEN = 1
QUEUE_ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*&---------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*

FORM BDC_DYNPRO USING p_prog
p_dyn
p_dynb.
wa_bdcdata-program = p_prog.
wa_bdcdata-dynpro = p_dyn.
wa_bdcdata-dynbegin = p_dynb.
append wa_bdcdata to it_bdcdata.
clear wa_bdcdata.
ENDFORM. " BDC_DYNPRO
*&---------------------------------------------------------------------*
*& Form BDC_FIELD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*

FORM BDC_FIELD USING p_fnam
p_fval.
wa_bdcdata-fnam = p_fnam.
wa_bdcdata-fval = p_fval.
append wa_bdcdata to it_bdcdata.
clear wa_bdcdata.
ENDFORM. " BDC_FIELD


*------------------End BDC-------------------





*&---------------------------------------------------------------------
*
*& Form f_browse
*&---------------------------------------------------------------------

form f_browse CHANGING fc_file.
DATA: lo_gui TYPE REF TO cl_gui_frontend_services,
lv_title TYPE string,
lv_folder TYPE string,
lv_dir TYPE string.

CREATE OBJECT lo_gui.
lv_title = 'Define download location'.
lv_folder = 'C:'.
CALL METHOD lo_gui->directory_browse
EXPORTING
window_title = lv_title
initial_folder = lv_folder
CHANGING
selected_folder = lv_dir.
fc_file = lv_dir.

endform. "f_browse

Wednesday, May 2, 2012

BDC Program in infotype 0006

report ZIT0006 .
* no standard page heading line-size 255.

types : begin of ty_tab,
* pernr type pernr,
* choic type choic,
BEGDA type BEGDA,
NAME2 type NAME2,
STRAS type STRAS,
LOCAT type LOCAT,
ORT01 type ORT01,
ORT02 type ORT02,
STATE type STATE,
PSTLZ type PSTLZ,
* LAND1 type LAND1,
end of ty_tab.


data : wa_tab type ty_tab,
it_tab type table of ty_tab.

data : wa_bdcdata type bdcdata,
it_bdcdata type table of bdcdata,
g_file type ibipparms-path.

parameters : p_file type string,
p_ses TYPE char12.


at SELECTION-SCREEN on VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = 'p_file'
IMPORTING
FILE_NAME = g_file.
p_file = g_file.




*include bdcrecx1.

start-of-selection.

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = p_file
* FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* VIRUS_SCAN_PROFILE =
* NO_AUTH_CHECK = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
DATA_TAB = it_tab
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
* DEST = FILLER8
GROUP = p_ses
* HOLDDATE = FILLER8
KEEP = 'X'
USER = SY-UNAME
* RECORD = FILLER1
* PROG = SY-CPROG
* DCPFM = '%'
* DATFM = '%'
* IMPORTING
* QID =
EXCEPTIONS
CLIENT_INVALID = 1
DESTINATION_INVALID = 2
GROUP_INVALID = 3
GROUP_IS_LOCKED = 4
HOLDDATE_INVALID = 5
INTERNAL_ERROR = 6
QUEUE_ERROR = 7
RUNNING = 8
SYSTEM_LOCK_ERROR = 9
USER_INVALID = 10
OTHERS = 11
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


REFRESH IT_BDCdata.
*perform open_group.

LOOP AT it_tab into wa_tab.

perform bdc_dynpro using 'SAPMP50A' '1000' 'X'.
perform bdc_field using 'BDC_OKCODE'
'=INS'.
perform bdc_field using 'RP50G-PERNR'
'9'.
perform bdc_field using 'RP50G-TIMR6'
'X'.
perform bdc_field using 'BDC_CURSOR'
'RP50G-SUBTY'.
perform bdc_field using 'RP50G-CHOIC'
'Addresses'.
perform bdc_field using 'RP50G-SUBTY'
'1'.
perform bdc_dynpro using 'MP000600' '2010' 'X'.
perform bdc_field using 'BDC_CURSOR'
'P0006-STATE'.
perform bdc_field using 'BDC_OKCODE'
'UPD'.
perform bdc_field using 'P0006-BEGDA'
wa_tab-begda.
*perform bdc_field using 'P0006-ENDDA'
* '31.12.9999'.
perform bdc_field using 'P0006-NAME2'
wa_tab-name2.
perform bdc_field using 'P0006-STRAS'
wa_tab-stras.
perform bdc_field using 'P0006-LOCAT'
wa_tab-locat.
perform bdc_field using 'P0006-ORT01'
wa_tab-ort01.
perform bdc_field using 'P0006-ORT02'
wa_tab-ort02.
perform bdc_field using 'P0006-STATE'
wa_tab-state.
perform bdc_field using 'P0006-PSTLZ'
wa_tab-pstlz.
perform bdc_field using 'P0006-LAND1'
'US'.
*perform bdc_transaction using 'PA30'.
*
*perform close_group.

CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'PA30'
* POST_LOCAL = NOVBLOCAL
* PRINTING = NOPRINT
* SIMUBATCH = ' '
* CTUPARAMS = ' '
TABLES
DYNPROTAB = it_bdcdata
EXCEPTIONS
INTERNAL_ERROR = 1
NOT_OPEN = 2
QUEUE_ERROR = 3
TCODE_INVALID = 4
PRINTING_INVALID = 5
POSTING_INVALID = 6
OTHERS = 7
.
IF SY-SUBRC <> 0.
refresh it_bdcdata.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
clear wa_tab.
endloop.

CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
NOT_OPEN = 1
QUEUE_ERROR = 2
OTHERS = 3
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*&---------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*

FORM BDC_DYNPRO USING p_prog
p_dyn
p_dynb.
wa_bdcdata-program = p_prog.
wa_bdcdata-dynpro = p_dyn.
wa_bdcdata-dynbegin = p_dynb.
append wa_bdcdata to it_bdcdata.
clear wa_bdcdata.
ENDFORM. " BDC_DYNPRO
*&---------------------------------------------------------------------*
*& Form BDC_FIELD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*

FORM BDC_FIELD USING p_fnam
p_fval.
wa_bdcdata-fnam = p_fnam.
wa_bdcdata-fval = p_fval.
append wa_bdcdata to it_bdcdata.
clear wa_bdcdata.
ENDFORM. " BDC_FIELD

Tutorials on SAP-ABAP

Adobe Interactive Forms Tutorials

Business Server Pages (BSP)

Userexits/BADIs

Web Dynpro for ABAP (Step by step procedure for web dynpro,Tutorials on Web Dynpro,)

ALV Tutorials

goodsites