Application Development and Automation 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: 
Read only

BDC

Former Member
0 Likes
957

Hi Experts,

I have a text of around 250 chars and i am reading the text along with other fields into internal table using function module, 'ALSM_EXCEL_TO_INTERNAL_TABLE'.

The actual issue is the field length supported by structure 'ALSMEX_TABLINE' in the function module is 50 chars. So, i am unable to read the entire 250 chars into my interal table.

what is your solution for this.

Help in this regard will be greatly appreciated.

thanks.

vijay.

7 REPLIES 7
Read only

Former Member
0 Likes
880

Hi!

If you have to use the 'ALSM_EXCEL_TO_INTERNAL_TABLE' then there is no way but to read only 50 characters.

Alternatively, you could use GUI_UPLOAD to read data.

Read only

Former Member
0 Likes
880

Hi kalluri,

1. It is always better to save the excel

file as TAB Delimited file,

using excel only,

2. and then upload this text file,

using GUI_UPLOAD

regards,

amit m.

Read only

Former Member
0 Likes
880

Hi,

You can use <b>GUI_UPLOAD</b> instead of that FM.it will support 250 chars.it will read the full text into Internal table.

Regards

vijay

Read only

Former Member
0 Likes
880

Hi kalluri,

Use GUI_UPLOAD FM is good option to go ahead.

Regards,

John.

Read only

Former Member
0 Likes
880

The flat file consists of no indicators, so that i can identify as header, item , and subitem, and more over it consists of lot of spaces in between the fields.

Read only

0 Likes
880

Hi,

are you not saving the File as Tab delimited text file, that will be more easy to get the data to itab from the internal table.

and what is the field with 250chars you are uploading from flat file.how you declated your itab when you use the FM <b>ALSM_EXCEL_TO_INTERNAL_TABLE</b>

Regards

vijay

Read only

0 Likes
880

I had written a program some time back for uploading notifications. I had designed the file format to have a indicator to identify the header, line item and classification records. The file was a pipe delimited file. Please go through the code below to undestand how I read the file. Might Help.

REPORT zwam_create_notifications MESSAGE-ID vz NO STANDARD PAGE HEADING.

CONSTANTS : c_comma TYPE c VALUE '|'. "Was changed from comma to pipe

TYPES: filename(255) TYPE c,

str_line TYPE string.

TYPES: BEGIN OF nothdr,

ind,

exnum LIKE viqmel-qmnum,

ntype(2),

stext LIKE viqmel-qmtxt,

ingrp LIKE viqmel-ingrp,

gewrk LIKE riwo00-gewrk,

iwerk LIKE viqmel-iwerk,

qmnam LIKE viqmel-qmnam,

qmdat LIKE viqmel-qmdat,

qmtim LIKE viqmel-mzeit,

tplnr LIKE viqmel-tplnr,

equnr LIKE viqmel-equnr,

END OF nothdr.

TYPES: BEGIN OF nottxt,

ind,

exnum LIKE viqmel-qmnum,

ltext LIKE tline-tdline,

END OF nottxt.

TYPES: BEGIN OF notitm,

ind,

exnum LIKE viqmel-qmnum,

itmno LIKE viqmfe-fenum,

otgrp LIKE viqmfe-otgrp,

oteil LIKE viqmfe-oteil,

fegrp LIKE viqmfe-fegrp,

fecod LIKE viqmfe-fecod,

urgrp LIKE viqmur-urgrp,

urcod LIKE viqmur-urcod,

mngrp LIKE viqmma-mngrp,

mncod LIKE viqmma-mncod,

class LIKE rmclm-class,

END OF notitm.

TYPES: BEGIN OF itmchr,

ind,

exnum LIKE viqmel-qmnum,

itmno LIKE viqmfe-fenum,

type,

chrt(30),

chvl(30),

END OF itmchr.

TYPES : BEGIN OF ty_allocnum.

INCLUDE STRUCTURE bapi1003_alloc_values_num.

TYPES : END OF ty_allocnum.

TYPES : BEGIN OF ty_allocchar.

INCLUDE STRUCTURE bapi1003_alloc_values_char.

TYPES : END OF ty_allocchar.

TYPES : BEGIN OF ty_objtable.

INCLUDE STRUCTURE bapi1003_key .

TYPES : END OF ty_objtable.

TYPES : BEGIN OF ty_alloccurr.

INCLUDE STRUCTURE bapi1003_alloc_values_curr.

TYPES : END OF ty_alloccurr.

DATA : wa_hdr TYPE nothdr,

wa_itm TYPE notitm,

wa_txt TYPE nottxt,

wa_chr TYPE itmchr,

it_hdr TYPE STANDARD TABLE OF nothdr,

it_itm TYPE STANDARD TABLE OF notitm,

it_txt TYPE STANDARD TABLE OF nottxt,

it_chr TYPE STANDARD TABLE OF itmchr.

DATA: BEGIN OF it_log OCCURS 0,

exnum LIKE viqmel-qmnum,

notif LIKE viqmel-qmnum,

itmno LIKE viqmfe-fenum,

msgtx(100),

END OF it_log,

BEGIN OF it_cls OCCURS 0,

exnum LIKE viqmel-qmnum,

itmno LIKE viqmfe-fenum,

class LIKE rmclm-class,

END OF it_cls,

wa_cls LIKE LINE OF it_cls,

notif_data TYPE string,

fname_str TYPE string,

ds_name TYPE string,

len TYPE i,

hdr_recs TYPE i,

log_recs TYPE i,

indicator,

faltu,

it_ipdat TYPE TABLE OF str_line WITH HEADER LINE.

DATA: i_allocvaluesnum TYPE STANDARD TABLE OF ty_allocnum WITH HEADER LINE,

i_allocvaluescurr TYPE STANDARD TABLE OF ty_alloccurr WITH HEADER LINE,

i_allocvalueschar TYPE STANDARD TABLE OF ty_allocchar WITH HEADER LINE,

i_objtable TYPE STANDARD TABLE OF ty_objtable WITH HEADER LINE.

DATA : notitem LIKE bapi2080_notitemi OCCURS 0 WITH HEADER LINE,

notifcaus LIKE bapi2080_notcausi OCCURS 0 WITH HEADER LINE,

notifactv LIKE bapi2080_notactvi OCCURS 0 WITH HEADER LINE,

notiftask LIKE bapi2080_nottaski OCCURS 0 WITH HEADER LINE,

notifpartnr LIKE bapi2080_notpartnri OCCURS 0 WITH HEADER LINE,

longtexts LIKE bapi2080_notfulltxti OCCURS 0 WITH HEADER LINE,

key_relationships LIKE bapi2080_notkeye OCCURS 0 WITH HEADER LINE,

return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,

notifheader_export LIKE bapi2080_nothdre,

external_number LIKE bapi2080_nothdre-notif_no,

notif_type LIKE bapi2080-notif_type,

notifheader LIKE bapi2080_nothdri,

task_determination LIKE bapiflag,

sender LIKE bapi_sender,

orderid LIKE bapi2080_nothdre-orderid,

p_file1 LIKE filename-fileintern.

PARAMETERS: p_file2 LIKE filename-fileintern OBLIGATORY LOWER CASE,

r_pres RADIOBUTTON GROUP rb1 DEFAULT 'X',

AT SELECTION-SCREEN.

IF sy-ucomm = 'SJOB' AND r_pres = 'X'.

MESSAGE e000 WITH 'Please place the file on the application'

'server if the program is to be'

'processed in the background' ''.

ENDIF.

START-OF-SELECTION.

PERFORM upload_file.

PERFORM read_input_data.

END-OF-SELECTION.

PERFORM create_notifications.

TOP-OF-PAGE.

PERFORM write_header.

&----


*& Form upload_file

&----


FORM upload_file .

PERFORM upload_from_application.

PERFORM upload_from_presentation.

ENDFORM. " upload_file

&----


*& Form upload_from_application

----


FORM upload_from_application .

CHECK r_appl = 'X'.

CLEAR ds_name.

p_file1 = 'ZNOTIFICATION'.

CALL FUNCTION 'FILE_GET_NAME'

EXPORTING

logical_filename = p_file1

parameter_1 = p_file2

parameter_2 = 'ipfiles'

IMPORTING

file_name = ds_name

EXCEPTIONS

file_not_found = 1

OTHERS = 2.

IF sy-subrc NE 0.

MESSAGE e102(lx) WITH p_file2.

ENDIF.

OPEN DATASET ds_name FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc > 0.

MESSAGE e105(lx) WITH ds_name.

ENDIF.

DO.

READ DATASET ds_name INTO notif_data.

IF syst-subrc GT 0.

EXIT.

ENDIF.

APPEND notif_data TO it_ipdat.

ENDDO.

CLOSE DATASET ds_name.

ENDFORM. " upload_from_application

&----


*& Form upload_from_presentation

----


FORM upload_from_presentation .

CHECK r_pres = 'X'.

fname_str = p_file2.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = fname_str

filetype = 'ASC'

has_field_separator = ' '

header_length = 0

read_by_line = 'X'

dat_mode = ' '

codepage = ' '

ignore_cerr = 'X'

replacement = '#'

check_bom = ' '

TABLES

data_tab = it_ipdat

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 NE 0.

MESSAGE i000(vz) WITH 'Error uploading' 'input file.' 'Return Code' sy-subrc.

STOP.

ENDIF.

ENDFORM. " upload_from_presentation

&----


*& Form read_input_data

----


FORM read_input_data.

CLEAR : wa_hdr, wa_itm, wa_txt, wa_chr, wa_cls.

REFRESH : it_hdr, it_itm, it_txt, it_chr, it_cls.

PERFORM build_tmp_tables.

hdr_recs = LINES( it_hdr ).

IF hdr_recs EQ 0.

MESSAGE i000(vz) WITH 'No Header records' 'found in' 'the input' 'file.'.

STOP.

ENDIF.

ENDFORM. "read_input_data

&----


*& Form build_tmp_tables

----


FORM build_tmp_tables .

LOOP AT it_ipdat INTO notif_data.

len = STRLEN( notif_data ).

IF len GT 0.

indicator = notif_data+0(1).

IF indicator = 'H'.

CLEAR wa_hdr.

SPLIT notif_data AT c_comma INTO wa_hdr-ind

wa_hdr-exnum

wa_hdr-ntype

wa_hdr-stext

wa_hdr-ingrp

wa_hdr-gewrk

wa_hdr-iwerk

wa_hdr-qmnam

wa_hdr-qmdat

wa_hdr-qmtim

wa_hdr-tplnr

wa_hdr-equnr

faltu.

APPEND wa_hdr TO it_hdr.

ELSEIF indicator = 'L'.

CLEAR wa_txt.

SPLIT notif_data AT c_comma INTO wa_txt-ind

wa_txt-exnum

wa_txt-ltext

faltu.

APPEND wa_txt TO it_txt.

ELSEIF indicator = 'I'.

CLEAR wa_itm.

SPLIT notif_data AT c_comma INTO wa_itm-ind

wa_itm-exnum

wa_itm-itmno

wa_itm-otgrp

wa_itm-oteil

wa_itm-fegrp

wa_itm-fecod

wa_itm-urgrp

wa_itm-urcod

wa_itm-mngrp

wa_itm-mncod

wa_itm-class

faltu.

APPEND wa_itm TO it_itm.

MOVE-CORRESPONDING wa_itm TO wa_cls.

APPEND wa_cls TO it_cls.

ELSEIF indicator = 'C'.

CLEAR wa_chr.

SPLIT notif_data AT c_comma INTO wa_chr-ind

wa_chr-exnum

wa_chr-itmno

wa_chr-type

wa_chr-chrt

wa_chr-chvl

faltu.

APPEND wa_chr TO it_chr.

ENDIF.

ENDIF.

ENDLOOP.

ENDFORM. " build_tmp_tables

&----


*& Form create_notifications

----


FORM create_notifications .

SORT it_hdr BY exnum.

SORT it_itm BY exnum itmno.

SORT it_cls BY exnum itmno.

SORT it_chr BY exnum itmno.

LOOP AT it_hdr INTO wa_hdr.

PERFORM build_bapi_interface.

PERFORM call_bapi1.

PERFORM display_log.

ENDLOOP.

ENDFORM. " create_notifications

&----


*& Form build_bapi_interface

----


FORM build_bapi_interface .

CLEAR: notitem,

notifcaus,

notifactv,

notiftask,

notifpartnr,

longtexts,

key_relationships,

return,

notifheader_export,

external_number,

notif_type,

notifheader,

task_determination,

sender,

orderid.

REFRESH: notitem,

notifcaus,

notifactv,

notiftask,

notifpartnr,

longtexts,

key_relationships,

return.

external_number = wa_hdr-exnum.

notif_type = wa_hdr-ntype.

notifheader-refobjectkey = wa_hdr-exnum.

notifheader-equipment = wa_hdr-equnr.

notifheader-funct_loc = wa_hdr-tplnr.

notifheader-short_text = wa_hdr-stext.

notifheader-reportedby = wa_hdr-qmnam.

notifheader-notif_date = wa_hdr-qmdat.

notifheader-notiftime = wa_hdr-qmtim.

notifheader-planplant = wa_hdr-iwerk.

notifheader-plangroup = wa_hdr-ingrp.

notifheader-pm_wkctr = wa_hdr-gewrk.

LOOP AT it_txt INTO wa_txt WHERE exnum = wa_hdr-exnum.

longtexts-objtype = 'QMEL'.

longtexts-format_col = '*' .

longtexts-text_line = wa_txt-ltext.

APPEND longtexts. CLEAR longtexts.

ENDLOOP.

LOOP AT it_itm INTO wa_itm WHERE exnum = wa_hdr-exnum.

IF NOT wa_itm-otgrp IS INITIAL OR NOT wa_itm-fegrp IS INITIAL.

*Object Code and Damage Code

notitem-refobjectkey = wa_hdr-exnum.

notitem-item_sort_no = wa_itm-itmno.

notitem-dl_codegrp = wa_itm-otgrp.

notitem-dl_code = wa_itm-oteil.

notitem-d_codegrp = wa_itm-fegrp.

notitem-d_code = wa_itm-fecod.

APPEND notitem.

*Cause Code

IF NOT wa_itm-urgrp IS INITIAL.

notifcaus-refobjectkey = wa_hdr-exnum.

notifcaus-cause_sort_no = wa_itm-itmno.

notifcaus-cause_codegrp = wa_itm-urgrp.

notifcaus-cause_code = wa_itm-urcod.

notifcaus-item_sort_no = wa_itm-itmno.

APPEND notifcaus. CLEAR notifcaus.

ENDIF.

*Activity Code

IF NOT wa_itm-mngrp IS INITIAL.

notifactv-refobjectkey = wa_hdr-exnum.

notifactv-act_sort_no = wa_itm-itmno.

notifactv-act_codegrp = wa_itm-mngrp.

notifactv-act_code = wa_itm-mncod.

notifactv-item_sort_no = wa_itm-itmno.

APPEND notifactv. CLEAR notifactv.

ENDIF.

ENDIF.

ENDLOOP.

ENDFORM. " build_bapi_interface

&----


*& Form call_bapi1

----


FORM call_bapi1.

CLEAR it_log. REFRESH it_log.

CALL FUNCTION 'BAPI_ALM_NOTIF_CREATE'

EXPORTING

external_number = external_number

notif_type = notif_type

notifheader = notifheader

task_determination = task_determination

sender = sender

orderid = orderid

IMPORTING

notifheader_export = notifheader_export

TABLES

notitem = notitem

notifcaus = notifcaus

notifactv = notifactv

notiftask = notiftask

notifpartnr = notifpartnr

longtexts = longtexts

key_relationships = key_relationships

return = return.

READ TABLE return WITH KEY type = 'E' BINARY SEARCH.

IF sy-subrc NE 0.

REFRESH return.

CALL FUNCTION 'BAPI_ALM_NOTIF_SAVE'

EXPORTING

number = notifheader_export-notif_no

IMPORTING

notifheader = notifheader_export

TABLES

return = return.

READ TABLE return WITH KEY type = 'E' BINARY SEARCH.

IF sy-subrc NE 0.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'.

  • it_log-exnum = wa_hdr-exnum.

  • it_log-notif = notifheader_export-notif_no.

  • it_log-msgtx = 'Notification created'.

  • APPEND it_log. CLEAR it_log.

PERFORM call_bapi2.

ELSE.

PERFORM add_bapi1_error.

ENDIF.

ELSE.

PERFORM add_bapi1_error.

ENDIF.

ENDFORM. "call_bapi1

&----


*& Form call_bapi2

----


FORM call_bapi2 .

LOOP AT it_cls INTO wa_cls WHERE exnum = wa_hdr-exnum.

REFRESH : i_allocvalueschar, i_allocvaluescurr, i_allocvaluesnum.

CLEAR : i_allocvalueschar, i_allocvaluescurr, i_allocvaluesnum.

TRANSLATE wa_cls-class TO UPPER CASE.

LOOP AT it_chr INTO wa_chr WHERE exnum = wa_cls-exnum

AND itmno = wa_cls-itmno.

TRANSLATE wa_chr-chrt TO UPPER CASE.

IF wa_chr-type = 'N'.

i_allocvaluesnum-charact = wa_chr-chrt.

i_allocvaluesnum-value_from = wa_chr-chvl.

APPEND i_allocvaluesnum.

ELSEIF wa_chr-type = 'C'.

i_allocvalueschar-charact = wa_chr-chrt.

i_allocvalueschar-value_neutral = wa_chr-chvl.

APPEND i_allocvalueschar.

ELSEIF wa_chr-type = 'X'.

i_allocvaluescurr-charact = wa_chr-chrt.

i_allocvaluescurr-value_from = wa_chr-chvl.

APPEND i_allocvaluescurr.

ENDIF.

AT END OF itmno.

DELETE i_allocvalueschar WHERE value_neutral IS INITIAL.

DELETE i_allocvaluesnum WHERE value_from IS INITIAL.

DELETE i_allocvaluescurr WHERE value_from IS INITIAL.

IF NOT i_allocvalueschar[] IS INITIAL OR

NOT i_allocvaluesnum[] IS INITIAL.

CLEAR i_objtable.

i_objtable-objecttable = 'QMFE'.

i_objtable-classnum = wa_cls-class.

i_objtable-classtype = '015'.

i_objtable-object = notifheader_export-notif_no.

CONCATENATE notifheader_export-notif_no wa_chr-itmno

INTO i_objtable-object.

REFRESH return.

CALL FUNCTION 'BAPI_OBJCL_CREATE'

EXPORTING

objectkeynew = i_objtable-object

objecttablenew = i_objtable-objecttable

classnumnew = i_objtable-classnum

classtypenew = i_objtable-classtype

TABLES

allocvaluesnum = i_allocvaluesnum

allocvalueschar = i_allocvalueschar

allocvaluescurr = i_allocvaluescurr

return = return.

READ TABLE return WITH KEY type = 'E' BINARY SEARCH.

IF sy-subrc NE 0.

COMMIT WORK AND WAIT.

ELSE.

PERFORM add_bapi2_error.

ENDIF.

ENDIF.

ENDAT.

ENDLOOP.

ENDLOOP.

ENDFORM. " call_bapi2

&----


*& Form display_log

----


FORM display_log .

log_recs = LINES( it_log ).

IF log_recs GT 0.

LOOP AT it_log.

WRITE:/1 it_log-exnum,

20 it_log-notif,

40 it_log-itmno,

50 it_log-msgtx.

ENDLOOP.

SKIP.

ENDIF.

ENDFORM. " display_log

&----


*& Form write_header

----


FORM write_header .

ULINE.

WRITE:/1 'External Number',

20 'SAP Notification',

40 'Item No',

50 'Message'.

ULINE.

ENDFORM. " write_header

&----


*& Form add_bapi1_error

----


FORM add_bapi1_error .

it_log-exnum = wa_hdr-exnum.

it_log-notif = notifheader_export-notif_no.

it_log-msgtx = 'Error while creating Notification'.

APPEND it_log. CLEAR it_log.

LOOP AT return.

it_log-exnum = wa_hdr-exnum.

it_log-notif = notifheader_export-notif_no.

CALL FUNCTION 'MESSAGE_TEXT_BUILD'

EXPORTING

msgid = return-id

msgnr = return-number

msgv1 = return-message_v1

msgv2 = return-message_v2

msgv3 = return-message_v3

msgv4 = return-message_v4

IMPORTING

message_text_output = it_log-msgtx.

APPEND it_log. CLEAR it_log.

ENDLOOP.

ENDFORM. " add_bapi1_error

&----


*& Form add_bapi2_error

----


FORM add_bapi2_error .

it_log-exnum = wa_hdr-exnum.

it_log-notif = notifheader_export-notif_no.

it_log-itmno = wa_chr-itmno.

it_log-msgtx = 'Error while classifying item'.

APPEND it_log. CLEAR it_log.

LOOP AT return.

it_log-exnum = wa_hdr-exnum.

it_log-notif = notifheader_export-notif_no.

it_log-itmno = wa_chr-itmno.

CALL FUNCTION 'MESSAGE_TEXT_BUILD'

EXPORTING

msgid = return-id

msgnr = return-number

msgv1 = return-message_v1

msgv2 = return-message_v2

msgv3 = return-message_v3

msgv4 = return-message_v4

IMPORTING

message_text_output = it_log-msgtx.

APPEND it_log. CLEAR it_log.

ENDLOOP.

ENDFORM. " add_bapi2_error

-Kiran

*Please reward useful answers