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: 

ABAP Code correction

susrith2021
Explorer
0 Kudos
1,013

My requirement is to download the DEBMAS IDOC as when a customer created in SAP to FTP folder (without any middleware like XI/PO/PI).

I am trying to execute a code which I taken as reference from IDOC to excel file and while I am checking syntax errors getting error ""TAB_CR" must be a character-like data object (data type C, N, D, T, or STRING)"

Please help me regards this.

*----------------------------------------------------------------------*
* Report Z_DISPLAY_IDOC_DATA *
*----------------------------------------------------------------------*
************************************************************************
* This tool reads an existing IDOC and displays the contents in a *
* spreadsheet format. The spreadsheet (MS-EXCEL) will be automatically *
* created if D_EXCEL = 'X'. *
************************************************************************
REPORT z_display_idoc_data.

DATA: idoc_control LIKE edidc,
number_of_data_records LIKE sy-dbcnt,
number_of_status_records LIKE sy-dbcnt,
int_edids LIKE edids OCCURS 0 WITH HEADER LINE,
int_edidd LIKE edidd OCCURS 0 WITH HEADER LINE.

TYPE-POOLS : ledid.

DATA: struct_type TYPE ledid_struct_type,
idoc_struct TYPE ledid_t_idoc_struct,
segments TYPE ledid_t_segment,
segment_struct TYPE ledid_t_segment_struct,
excel_tab(2000) OCCURS 0 WITH HEADER LINE.

PARAMETERS: docnum LIKE edidc-docnum OBLIGATORY, ""Idoc Number
sap_rel LIKE sy-saprl DEFAULT sy-saprl OBLIGATORY,
pi_ver LIKE edi_verrec-version DEFAULT '3' OBLIGATORY,
d_excel AS CHECKBOX DEFAULT 'X'. ""Download ?

START-OF-SELECTION.
PERFORM read_idoc.
PERFORM process_idoc.
IF d_excel = 'X'.
PERFORM download_to_excel.
ENDIF.

END-OF-SELECTION.

FORM read_idoc.
CALL FUNCTION 'IDOC_READ_COMPLETELY'
EXPORTING
document_number = docnum
IMPORTING
idoc_control = idoc_control
number_of_data_records = number_of_data_records
number_of_status_records = number_of_status_records
TABLES
int_edids = int_edids
int_edidd = int_edidd
EXCEPTIONS
document_not_exist = 1
document_number_invalid = 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.

ENDFORM. "" read_idoc

FORM process_idoc.
PERFORM read_idoc_structure.
PERFORM display_data_records.
ENDFORM. "" process_idoc

FORM display_data_records.

DATA: PE_seg_HEADER LIKE edi_sapi01,
segname LIKE edi_iapi12-segmenttyp,
prev_segname LIKE edi_iapi12-segmenttyp VALUE ' ',
pt_fields2 LIKE edi_iapi12 OCCURS 0 WITH HEADER LINE,
pt_fvalues2 LIKE edi_iapi14 OCCURS 0 WITH HEADER LINE,
byte_first TYPE i,
byte_last TYPE i,
field_val(50),
tmp_str(15),
tmp_str3(15),
seg_repeats TYPE i VALUE 0,
tmp_str2(15),
tab_cr(1) TYPE x VALUE '09',
tot_ctr TYPE i VALUE 0,
ctr TYPE i VALUE 0,
msg(40) TYPE c.

DATA: IDOC_STRUCT_wa TYPE ledid_idoc_struct.

SORT int_edidd BY segnum.
DESCRIBE TABLE int_edidd LINES tot_ctr.
LOOP AT int_edidd.
MOVE int_edidd-segnam TO segname.
CLEAR msg.
CONCATENATE 'Reading segment ' segname
INTO msg SEPARATED BY space.
IF tot_ctr <> 0.
ctr = ( 100 * sy-tabix ) / tot_ctr.
ENDIF.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
percentage = ctr
text = msg.
ADD 1 TO seg_repeats.
CLEAR tmp_str2.
IF int_edidd-segnam <> prev_segname.
seg_repeats = 1.
CLEAR: pe_seg_header, pt_fields2, pt_fvalues2.
REFRESH: pt_fields2, pt_fvalues2.
CALL FUNCTION 'SEGMENT_READ_COMPLETE'
EXPORTING
pi_segtyp = segname
pi_release = sap_rel
pi_version = pi_ver
IMPORTING
pe_header = pe_seg_header
TABLES
pt_fields = pt_fields2
pt_fvalues = pt_fvalues2
EXCEPTIONS
segment_unknown = 1
segment_structure_unknown = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
prev_segname = int_edidd-segnam.
ENDIF.
READ TABLE idoc_struct INTO idoc_struct_wa WITH KEY
segment_type = int_edidd-segnam.
IF sy-subrc = 0.
IF idoc_struct_wa-syntax_attrib-mustfl = 'X'.
tmp_str = 'Mandatory'. ""Mandatory
ELSE.
tmp_str = 'Optional'. ""Optional
ENDIF.
IF IDOC_STRUCT_wa-segment_type_attrib-qualifier = 'X'.
tmp_str3 = 'Qualified'.
ELSE.
tmp_str3 = 'Non-Qualified'.
ENDIF.
SHIFT IDOC_STRUCT_wa-syntax_attrib-occmax
LEFT DELETING LEADING '0'.
MOVE seg_repeats TO tmp_str2.
CONDENSE: IDOC_STRUCT_wa-syntax_attrib-occmax, tmp_str2.
CONCATENATE tmp_str2 'of' IDOC_STRUCT_wa-syntax_attrib-occmax
INTO tmp_str2 SEPARATED BY space.

WRITE 😕 IDOC_STRUCT_wa-segment_type,
tmp_str,
tmp_str3,
tmp_str2,
IDOC_STRUCT_wa-syntax_attrib-hlevel,
IDOC_STRUCT_wa-segment_type_attrib-plast,
IDOC_STRUCT_wa-segment_type_attrib-descrp.
IF d_excel = 'X'.
CONCATENATE 'Segment Name' tab_cr
'Mand / Opt ' tab_cr
'Qual / non-Qual' tab_cr
'Seq of Max' tab_cr
'Level' tab_cr
'Owner' tab_cr
'Description'
INTO excel_tab.
APPEND excel_tab.
CONCATENATE IDOC_STRUCT_wa-segment_type tab_cr
tmp_str tab_cr
tmp_str3 tab_cr
tmp_str2 tab_cr
IDOC_STRUCT_wa-syntax_attrib-hlevel tab_cr
IDOC_STRUCT_wa-segment_type_attrib-plast tab_cr
IDOC_STRUCT_wa-segment_type_attrib-descrp
INTO excel_tab.
APPEND excel_tab.
CONCATENATE tab_cr
'Field Nma' tab_cr
'Type' tab_cr
'Length' tab_cr
'Byte From' tab_cr
'Byte To' tab_cr
'Description' tab_cr
'Value' tab_cr
'Qualifier Meaning'
INTO excel_tab.
APPEND excel_tab.
ENDIF.
ENDIF.
SORT pt_fields2 BY field_pos.
byte_first = 0.
LOOP AT pt_fields2.
CLEAR: field_val.
byte_last = pt_fields2-extlen.
WRITE int_edidd-sdata+byte_first(byte_last) TO
field_val LEFT-JUSTIFIED.
SHIFT pt_fields2-extlen LEFT DELETING LEADING '0'.
SHIFT pt_fields2-byte_first LEFT DELETING LEADING '0'.
SHIFT pt_fields2-byte_last LEFT DELETING LEADING '0'.
WRITE:/ ' ', pt_fields2-fieldname,
pt_fields2-datatype,
pt_fields2-extlen,
pt_fields2-byte_first ,
pt_fields2-byte_last,
pt_fields2-descrp,
field_val.
READ TABLE pt_fvalues2 WITH KEY fieldname = pt_fields2-fieldname
fldvalue_l = field_val.
ADD byte_last TO byte_first.
IF sy-subrc = 0.
WRITE : pt_fvalues2-descrp.
ELSE.
CLEAR pt_fvalues2-descrp.
ENDIF.
IF d_excel = 'X'.
CONCATENATE tab_cr pt_fields2-fieldname tab_cr
pt_fields2-datatype tab_cr
pt_fields2-extlen tab_cr
pt_fields2-byte_first tab_cr
pt_fields2-byte_last tab_cr
pt_fields2-descrp tab_cr
field_val tab_cr
pt_fvalues2-descrp
INTO excel_tab.
APPEND excel_tab.
ENDIF.
ENDLOOP.
ENDLOOP.
ENDFORM. "" display_data_records

FORM read_idoc_structure.
DATA: idoctype TYPE ledid_idoctype.

IF NOT idoc_control-cimtyp IS INITIAL.
struct_type = 'E'. ""Extended
idoctype = idoc_control-cimtyp.
ELSE.
struct_type = 'B'. ""Basic
idoctype = idoc_control-idoctp.
ENDIF.

CALL FUNCTION 'IDOC_TYPE_COMPLETE_READ'
EXPORTING
release = sap_rel
struct_type = struct_type
idoctype = idoctype
version = pi_ver
* IMPORTING
* IDOC_TYPE = idoctype
TABLES
idoc_struct = idoc_struct
segments = segments
segment_struct = segment_struct
EXCEPTIONS
idoctype_unknown = 1
idocstruct_unknown = 2
segment_data_missing = 3
illegal_struct_type = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

ENDFORM. "" read_idoc_structure

FORM download_to_excel.
DATA: name LIKE rlgrap-filename.

SHIFT docnum LEFT DELETING LEADING '0'.
CONCATENATE docnum '-' idoc_control-idoctp '.xls'
INTO name.

CALL FUNCTION 'RH_START_EXCEL_WITH_DATA'
EXPORTING
data_name = name
data_type = 'ASC'
wait = ' '
TABLES
data_tab = excel_tab
EXCEPTIONS
no_batch = 1
excel_not_installed = 2
wrong_version = 3
internal_error = 4
invalid_type = 5
cancelled = 6
download_error = 7
OTHERS = 8.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

ENDFORM. "" download_to_excel
1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
851

You have declared TAB_CR of type X:

tab_cr(1)     TYPE x VALUE '09',

and you did:

        CONCATENATE 'Segment Name' tab_cr
                    'Mand / Opt ' tab_cr
                    'Qual / non-Qual' tab_cr
                    'Seq of Max' tab_cr
                    'Level' tab_cr
                    'Owner' tab_cr
                    'Description'
                    INTO excel_tab.

and the syntax error is:

"TAB_CR" must be a character-like data object (data type C, N, D, T, or STRING)

I guess you understand that you used the type X (byte) and CONCATENATE expects that all elements are of type character (C, N, D, T, or STRING).

You want to insert a Tabulation Character ("TAB_CR").

The most simple solution is to use a String Template (see the ABAP documentation for more information) which is of type STRING:

DATA(tab_cr2) = |\t|.
        CONCATENATE 'Segment Name' tab_cr2
                    'Mand / Opt ' tab_cr2
                    'Qual / non-Qual' tab_cr2
                    'Seq of Max' tab_cr2
                    'Level' tab_cr2
                    'Owner' tab_cr2
                    'Description'
                    INTO excel_tab.
6 REPLIES 6

Sandra_Rossi
Active Contributor
852

You have declared TAB_CR of type X:

tab_cr(1)     TYPE x VALUE '09',

and you did:

        CONCATENATE 'Segment Name' tab_cr
                    'Mand / Opt ' tab_cr
                    'Qual / non-Qual' tab_cr
                    'Seq of Max' tab_cr
                    'Level' tab_cr
                    'Owner' tab_cr
                    'Description'
                    INTO excel_tab.

and the syntax error is:

"TAB_CR" must be a character-like data object (data type C, N, D, T, or STRING)

I guess you understand that you used the type X (byte) and CONCATENATE expects that all elements are of type character (C, N, D, T, or STRING).

You want to insert a Tabulation Character ("TAB_CR").

The most simple solution is to use a String Template (see the ABAP documentation for more information) which is of type STRING:

DATA(tab_cr2) = |\t|.
        CONCATENATE 'Segment Name' tab_cr2
                    'Mand / Opt ' tab_cr2
                    'Qual / non-Qual' tab_cr2
                    'Seq of Max' tab_cr2
                    'Level' tab_cr2
                    'Owner' tab_cr2
                    'Description'
                    INTO excel_tab.

851

Thankyou Sandra for the help..

After making relevant changes in code I got an dump with saying.

An exception has occurred in class "CX_SY_DYN_CALL_PARAM_NOT_FOUND". This
 exception was not caught
in procedure "DOWNLOAD_TO_EXCEL" "(FORM)" or propagated by a RAISING clause.
Since the caller of the procedure could not have anticipated this
exception, the current program was terminated.
The reason for the exception occurring was:
The reason for the exception is:
Function module "RH_START_EXCEL_WITH_DATA" was called with parameter
 "DATA_NAME".
This parameter is not defined there however.

after analyzing it I found that there is something wrong in the exporting parameter "data_name" which shown in below code.

I tried giving parameter as "data_filename" then also it doesn't work for me, please correct my code.

FORM download_to_excel.
DATA: name LIKE rlgrap-filename.
SHIFT docnum LEFT DELETING LEADING '0'.
CONCATENATE docnum '-' idoc_control-idoctp '.xls'
INTO name.

CALL FUNCTION 'RH_START_EXCEL_WITH_DATA'
EXPORTING
data_name = name
data_type = 'ASC'
wait = ' '
TABLES
data_tab = excel_tab
EXCEPTIONS
no_batch = 1
excel_not_installed = 2
wrong_version = 3
internal_error = 4
invalid_type = 5
cancelled = 6
download_error = 7
OTHERS = 8.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM.

matt
Active Contributor
851

The signature of the FM is:

*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(DATA_FILENAME) TYPE STRING OPTIONAL
*" REFERENCE(DATA_PATH_FLAG) TYPE HRPATHFLAG DEFAULT 'W'
*" REFERENCE(DATA_ENVIRONMENT) TYPE HRPATHENVM OPTIONAL
*" VALUE(DATA_TABLE) TYPE TABLE OPTIONAL
*" REFERENCE(MACRO_FILENAME) TYPE STRING OPTIONAL
*" REFERENCE(MACRO_PATH_FLAG) TYPE HRPATHFLAG DEFAULT 'E'
*" REFERENCE(MACRO_ENVIRONMENT) TYPE HRPATHENVM OPTIONAL
*" REFERENCE(WAIT) TYPE FLAG DEFAULT 'X'
*" REFERENCE(DELETE_FILE) TYPE FLAG DEFAULT 'X'
*" VALUE(CODEPAGE) TYPE ABAP_ENCOD OPTIONAL
*" EXCEPTIONS
*" NO_BATCH
*" EXCEL_NOT_INSTALLED
*" INTERNAL_ERROR
*" CANCELLED
*" DOWNLOAD_ERROR
*" NO_AUTHORITY
*" FILE_NOT_DELETED
*"----------------------------------------------------------------------

You have to use those parameter names, not ones you've made up. It has no parameter called DATA_NAME or DATA_TYPE. ABAP doesn't work by magically understanding whatever you throw at it!

851
susrith2021

I guess Matthew answers your complementary question.

0 Kudos
851

Thankyou Matthew for the help.

matt
Active Contributor
851

Please add a comment to a supplied answer. Not an answer. As it says next to the edit box:

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that your answer complies with our Rules of Engagement.