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

No comments:

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