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[].

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