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] Extract first four characters of EDID4-SDATA field

0 Kudos

Dear ABAP Experts,

I'm facing some issues to extract iDOC Data.

EDID4-SDATA is troublesome due to its length.

Attached is the line i would like to extract from EDID4 table -> the first four characters of this field.

I can retrieve the idoc number (DOCNUM) without any problem and SEGNAM = 'ZEDKARCHIVE' always.

Can you please elaborate ABAP-Wise how this can be achieved?

capture-extract-4-first-characters-of-sdata.png

Best regards,

Shérif Baldé

8 REPLIES 8

loyd_enochs3
Participant

Pretty straightforward - basic MOVE syntax from very early ABAP training:

DATA: l_edi_sdata     TYPE edi_sdata,
      l_edi_dtint2    TYPE edi_dtint2,
      wa_sdata(2000)  TYPE c,
      wa_target       TYPE char04.

*populate L_EDI_SDATA from database, then:
  MOVE l_edi_sdata TO wa_sdata.
  MOVE wa_sdata(4) TO wa_target.
* or
  MOVE l_edi_sdata TO wa_target.   "truncation expected.

0 Kudos

Hi Loyd,

my purpose is populate L_EDI_SDATA from Database without causing any dump.

Can you please elabore on how you would do it ?

Regards,

Shérif

Sherif, the below code works for ABAP 7.31 with UNICODE active - no dump, successful read of data into WA_TARGET.

DATA: l_edi_dtint2 TYPE edi_dtint2,
      l_edi_sdata(2000) TYPE c,
      wa_target(4) TYPE c.

SELECT SINGLE dtint2 sdata FROM  edid4
   INTO (l_edi_dtint2, l_edi_sdata).
MOVE l_edi_sdata(4) TO wa_target.
WRITE / wa_target.

0 Kudos
Your second answer completely fulfills my request.

Thank you so much Loyd!

Shérif BALDE You should indicate both your code and the short dump you get so that we can help you better.

isuru_fernando24
Explorer

Hi Sherif,

Create a work area of type ZEDKARCHIVE. Then, move the SDATA field to the ZEDKARCHIVE work area. Then the work area will have all the values from SDATA filled to corresponding fields of the work area. Finally, access the first field ZEDKARCHIVE work area-field1. Then you can do further substring functions on field 1.

High-level pseudo code,

data: wa_ZEDKARCHIVE type ZEDKARCHIVE,

      lv_sdata type EDID4-sdata.


Case EDID4-segnam

when EDID4-segnam = 'ZEDKARCHIVE'.

  wa_ZEDKARCHIVE = lv_sdata

 get wa_ZEDKARCHIVE-field1 

Cheers!

Isuru

0 Kudos

Hi Isuru,

Could you please support on SDATA field extraction?

That is in fact the sticking point I'm faced with.

Regards,

Shérif

Jelena
Active Contributor
0 Kudos

Even though you're saying this is already answered I should point out that the IDoc data should be treated differently than other records. The data is stored as a "raw" string in the database because the segment and IDoc structure can be changed. In the IDoc scenario, the data itself is separated (on purpose) from its structure definition. That's why we should read the data and place it into a structure that corresponds to the segment definition. In SE11, you'll find a structure defined with the same name as the segment (ZEDKARCHIVE in this case).

I believe there are also function modules that will even do all the reading and parsing for you but don't remember the name.

Either way, please don't treat the IDoc data like plain text. It's not about "first 4 characters", you need to look for a segment field (=field in segment structure).