Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Query regarding a specific usage of 'ALSM_EXCEL_TO_INTERNAL_TABLE' FM + ALV

Former Member
0 Kudos

HI all,

I am new to ABAP and this is my first project.

I have the following requirement as a part of my object. Kindly help me with the code or atleast snippet of code. The useful responses will be rewarded with points.

An .xls file needs to be uploaded from the user's desktop at the selection screen. and run in 'test run' or 'upload run' mode.

The file has header items from row 6 and the line items from row 10. The number of line items are limited to 999 else an error needs to be thrown to the user incase the file contains from 999 line items.

Also, then there are some validations that need to be performed and then data needs to be posted to SAP using a BAPI 'BAPI_ACC_DOCUMENT_POST'.

Also, after posting, an ALV report needs to be generated displaying the header items row wise and then below it , the successful line items that were processed and then further below, row-wise the unsuccessful line items alongwith the error message for each row.

Can anyone provide some code snippets for each of the above mentioned points and some sequence of logic as well ?

Thanks a lot.

Edited by: Aniket Pallav on Dec 14, 2011 8:41 AM

7 REPLIES 7

Former Member
0 Kudos

hi

for .xls file we use this function module

<< Moderator message - Cut and paste response from http://forums.sdn.sap.com/edit!default.jspa?messageID=10708642. Plagiarism is not allowed in SCN >>

Points unassigned

thanks

chaitanya

Edited by: Rob Burbank on Dec 14, 2011 10:37 AM

Former Member
0 Kudos

Hi,

regarding Function module alsm_excel_to_internal table, the above post is useful for you and regarding bapi, check below code

this sample code will be useful i hope.

data:

obj_type like bapiache02-obj_type,

obj_key like bapiache02-obj_key,

obj_sys like bapiache02-obj_sys,

documentheader like bapiache08,

accountgl like bapiacgl08

occurs 0 with header line,

currencyamount like bapiaccr08

occurs 0 with header line,

return like bapiret2

occurs 0 with header line,

extension1 like bapiextc

occurs 0 with header line,

t_edidd like edidd occurs 0 with header line,

bapi_retn_info like bapiret2 occurs 0 with header line.

data: error_flag.

documentheader-username = sy-uname.

documentheader-header_txt = 'Test using BAPI'.

documentheader-comp_code = '1000'.

documentheader-doc_date = sy-datum.

documentheader-pstng_date = sy-datum.

documentheader-doc_type = 'SA'.

accountgl-itemno_acc = '1'.

accountgl-gl_account = '0000160100'.

accountgl-comp_code = '1000'.

accountgl-pstng_date = sy-datum.

accountgl-doc_type = 'SA'.

accountgl-profit_ctr = '0000010000'.

append accountgl.

accountgl-itemno_acc = '2'.

accountgl-gl_account = '0000160100'.

accountgl-comp_code = '1000'.

accountgl-pstng_date = sy-datum.

accountgl-doc_type = 'SA'.

accountgl-profit_ctr = '0000010000'.

append accountgl.

currencyamount-itemno_acc = '1'.

currencyamount-currency = 'GBP'.

currencyamount-amt_doccur = '100.00'.

append currencyamount.

currencyamount-itemno_acc = '2'.

currencyamount-currency = 'GBP'.

currencyamount-amt_doccur = '-100.00'.

append currencyamount.

  • call BAPI-function in this system *

call function 'BAPI_ACC_GL_POSTING_POST'

exporting

documentheader = documentheader

  • importing

  • obj_type = obj_type

  • obj_key = obj_key

  • obj_sys = obj_sys

tables

accountgl = accountgl

currencyamount = currencyamount

return = return

extension1 = extension1

exceptions

others = 1.

if sy-subrc <> 0.

message e999(re) with 'Problem occured'.

else.

loop at return.

if not return is initial.

clear bapi_retn_info.

move-corresponding return to bapi_retn_info.

if return-type = 'A' or return-type = 'E'.

error_flag = 'X'.

endif.

append bapi_retn_info.

endif.

endloop.

if error_flag = 'X'.

message e999(re) with 'Problem occured'.

rollback work.

else.

commit work.

endif.

endif.

Former Member
0 Kudos

Okay.. thanks a lot for the above two posts..

Any idea how to have the alv reports done?

0 Kudos

Try searching for function module REUSE_ALV_LIST_DISPLAY and you will get many sample codes

0 Kudos

Hi,

REPORT ZSAMPLE_ALV.

TYPE-POOLS : SLIS.

PARAMETERS : P_EBELN TYPE EKKO-EBELN.

TYPES: BEGIN OF TY_EKPO,

EBELN TYPE EKPO-EBELN,

EBELP TYPE EKPO-EBELP,

END OF TY_EKPO.

DATA : IT_EKPO TYPE TABLE OF TY_EKPO,

WA_EKPO TYPE TY_EKPO.

DATA: IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,

WA_FCAT TYPE SLIS_FIELDCAT_ALV.

IF P_EBELN IS NOT INITIAL.

SELECT EBELN EBELP BUKRS WERKS FROM EKPO INTO CORRESPONDING FIELDS OF TABLE IT_EKPO WHERE EBELN = P_EBELN.

ENDIF.

PERFORM FIELDCAT.

PERFORM DISPLAY.

FORM FIELDCAT .

WA_FCAT-FIELDNAME = 'EBELN' .

WA_FCAT-TABNAME = 'EKPO' .

WA_FCAT-COL_POS = 1.

wa_fcat-edit = 'X'.

WA_FCAT-OUTPUTLEN = '20'.

wa_fcat-seltext_m = 'BILLING NUM' .

APPEND WA_FCAT TO IT_FCAT.

CLEAR WA_FCAT.

WA_FCAT-FIELDNAME = 'EBELP' .

WA_FCAT-TABNAME = 'EKPO' .

WA_FCAT-COL_POS = 2.

WA_FCAT-OUTPUTLEN = '20'.

wa_fcat-seltext_m = 'ITEM' .

APPEND WA_FCAT TO IT_FCAT.

CLEAR WA_FCAT.

ENDFORM. " FIELDCAT

&----


*& Form DISPLAY

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM DISPLAY .

IF IT_EKPO IS NOT INITIAL.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = SY-REPID

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

  • I_CALLBACK_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME =

  • I_BACKGROUND_ID = ' '

  • I_GRID_TITLE =

  • I_GRID_SETTINGS =

  • IS_LAYOUT = LS_LAY

IT_FIELDCAT = IT_FCAT

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = 'X'

  • IS_VARIANT =

  • IT_EVENTS =

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • I_HTML_HEIGHT_TOP = 0

  • I_HTML_HEIGHT_END = 0

  • IT_ALV_GRAPHICS =

  • IT_HYPERLINK =

  • IT_ADD_FIELDCAT =

  • IT_EXCEPT_QINFO =

  • IR_SALV_FULLSCREEN_ADAPTER =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

T_OUTTAB = IT_EKPO

  • EXCEPTIONS

  • PROGRAM_ERROR = 1

  • OTHERS = 2

.

ENDIF.

ENDFORM. " DISPLAY

Former Member
0 Kudos

Hi,

Refer below link regarding ALV reports

http://wiki.sdn.sap.com/wiki/display/ABAP/ALVeasytutorial

Thanks,

venkat.

Former Member
0 Kudos

STF!! Search the forum! For your ALV, look at SAP's demonstration programs named like BCALV, or better yet, use current methods, like SALV, and look at demo programs named like 'SALV_DEMO or SALV_TEST* In addition, a search for SALV Tutorial will bring you to Rich Heilman's excellent tutorials on the subject in SDN....

As you've probably noticed, this is not a code writing service, and I'd suggest caution...don't become a cut-and-paste plagarizer...lots of folks are willing to post code, sometimes good sometimes awful.... I would suggest you look at SAP's code and learn how to write ABAP the SAP way.