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: 

How to read specified no of charcters?

Former Member
0 Kudos

Hi

I want to read PO text in internal table.

I want to read only first 60 characters of the address field.

Specifying no of charcters in data field or using 'outputlen' in fieldcat is not giving any results.

Pls. suggest proper method or function for doing this.

Giving code for reference-

TYPES : BEGIN OF ty_final,

ebeln LIKE ekko-ebeln, "PUR DOC

bsart LIKE ekko-bsart, "DOC TYP

ernam LIKE ekko-ernam, "NANE OF THE PERSON WHO CREATED THE DOC

lifnr LIKE ekko-lifnr, "VENDOR ACCOUNT

zterm LIKE ekko-zterm, "TERMS OF PAYMENT KEY

ekgrp LIKE ekko-ekgrp, "PUR GRP

inco2 LIKE ekko-inco2, "INCOTERMS

werks LIKE ekpo-werks, "PLANT

menge LIKE ekpo-menge, "PO QTY

meins LIKE ekpo-meins, "UNIT OF QTY

netpr LIKE ekpo-netpr, "NET PRICE

peinh LIKE ekpo-peinh, "PRICE UNIT

kzwi1 LIKE ekpo-kzwi1, "TOTAL LANDED COST

bedat LIKE ekko-bedat, "DOC DATE

name1 LIKE lfa1-name1, "VENDOR NAME

lines LIKE tline-tdline,

text(60) TYPE c,

END OF ty_final.

DATA: it_text TYPE STANDARD TABLE OF mat_text,

wa_text TYPE mat_text.

DATA: wa_thead TYPE thead.

DATA: it_lines LIKE TABLE OF tline,

wa_lines TYPE tline.

DATA : it_final TYPE TABLE OF ty_final,

wa_final TYPE ty_final.

DATA : it_final1 TYPE TABLE OF ty_final,

wa_final1 TYPE ty_final.

DATA: it_fieldcat TYPE TABLE OF slis_fieldcat_alv,

wa_fieldcat TYPE slis_fieldcat_alv.

--


SCREENS--

SELECTION-SCREEN: BEGIN OF BLOCK blk1 WITH FRAME.

PARAMETER: p_ekorg LIKE ekko-ekorg OBLIGATORY,

p_ekgrp LIKE ekko-ekgrp.

SELECT-OPTIONS: s_bedat FOR ekko-bedat.

SELECTION-SCREEN: END OF BLOCK blk1.

SELECTION-SCREEN: BEGIN OF BLOCK blk2 WITH FRAME TITLE text-001.

PARAMETER: r_grid TYPE c RADIOBUTTON GROUP grp2.

PARAMETER: r_list TYPE c RADIOBUTTON GROUP grp2.

SELECTION-SCREEN: END OF BLOCK blk2.

--


START OF SELECTION--

START-OF-SELECTION.

PERFORM getdata.

PERFORM fill_alv_list.

PERFORM printdata.

&----


*& Form GETDATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM getdata .

SELECT * INTO CORRESPONDING FIELDS OF wa_final FROM ekko AS a INNER JOIN ekpo AS b

ON amandt = bmandt

AND aebeln = bebeln CLIENT SPECIFIED

WHERE a~mandt = sy-mandt

AND a~ebeln LIKE '%'

AND a~ekorg = p_ekorg

AND a~ekgrp = p_ekgrp

AND a~bedat IN s_bedat.

COLLECT wa_final INTO it_final.

CLEAR wa_final.

ENDSELECT.

LOOP AT it_final INTO wa_final.

SELECT SINGLE name1 INTO wa_final-name1 FROM lfa1 CLIENT SPECIFIED

WHERE mandt = sy-mandt

AND lifnr = wa_final-lifnr.

MODIFY it_final FROM wa_final.

CLEAR wa_final.

ENDLOOP.

LOOP AT it_final INTO wa_final.

wa_thead-tdid = 'F02'.

wa_thead-tdspras = 'EN'.

wa_thead-tdname = wa_final-ebeln.

wa_thead-tdobject = 'EKKO'.

REFRESH it_lines.

CALL FUNCTION 'READ_TEXT' "function for getting the PO header text

EXPORTING

client = sy-mandt

id = wa_thead-tdid

language = wa_thead-tdspras

name = wa_thead-tdname

object = wa_thead-tdobject

  • ARCHIVE_HANDLE = 0

  • LOCAL_CAT = ' '

  • IMPORTING

  • HEADER =

TABLES

lines = it_lines

EXCEPTIONS

id = 1

language = 2

name = 3

not_found = 4

object = 5

reference_check = 6

wrong_access_to_archive = 7

OTHERS = 8

.

LOOP AT it_lines INTO wa_lines. " WHERE tdline NE ' '.

wa_text-ebeln = wa_final-ebeln.

wa_text-lines = wa_lines-tdline.

APPEND wa_text TO it_text.

  • CLEAR wa_final.

CLEAR wa_text.

CLEAR wa_lines.

ENDLOOP.

wa_thead-tdname = ' '.

CLEAR wa_final.

ENDLOOP.

REFRESH it_final1.

LOOP AT it_text INTO wa_text.

READ TABLE it_final INTO wa_final WITH KEY ebeln = wa_text-ebeln.

MOVE-CORRESPONDING wa_final TO wa_final1.

wa_final1-lines = wa_text-lines.

  • wa_final1-text = wa_final1-lines.

  • IF ( STRLEN( wa_final1-lines ) > 60 ).

  • MOVE wa_final1-lines TO wa_final1-text.

  • string

  • ENDIF.

APPEND wa_final1 TO it_final1.

CLEAR wa_final1.

CLEAR wa_text.

CLEAR wa_final.

ENDLOOP.

ENDFORM. " GETDATA

&----


*& Form FILL_ALV_LIST

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM fill_alv_list .

PERFORM fill_fieldcat USING 'WERKS' 'WERKS' 'EKPO' ' ' ' ' ' ' ' '.

PERFORM fill_fieldcat USING 'EKGRP' 'EKGRP' 'EKKO' ' ' ' ' ' ' ' '.

PERFORM fill_fieldcat USING 'BSART' 'BSART' 'EKKO' ' ' ' ' ' ' ' '.

PERFORM fill_fieldcat USING 'EBELN' 'EBELN' 'EKKO' ' ' ' ' ' ' ''.

PERFORM fill_fieldcat USING 'BEDAT' 'BEDAT' 'EKKO' ' ' ' ' ' ' ''.

PERFORM fill_fieldcat USING 'ERNAM' 'ERNAM' 'EKKO' ' ' ' ' ' ' ''.

PERFORM fill_fieldcat USING 'NAME1' 'NAME1' 'LFA1' ' ' ' ' ' ' ''.

PERFORM fill_fieldcat USING 'KZWI1' ' ' ' ' 'Total Value' ' ' ' ' ''.

PERFORM fill_fieldcat USING 'PEINH' 'PEINH' 'EKPO' ' ' ' ' ' ' ''.

PERFORM fill_fieldcat USING 'ZTERM' ' ' ' ' 'Terms Of Payment' ' ' ' ' ''.

PERFORM fill_fieldcat USING 'INCO2' 'INCO2' 'EKPO' ' ' ' ' ' ' ''.

PERFORM fill_fieldcat USING 'LIFNR' 'LIFNR' 'EKKO' ' ' ' ' ' ' ''.

PERFORM fill_fieldcat USING 'LINES' ' ' ' ' 'PO Header' ' ' ' ' '60'.

  • PERFORM fill_fieldcat USING 'TEXT' ' ' ' ' ' TEXT' ' ' ' ' '60'.

ENDFORM. " FILL_ALV_LIST

&----


*& Form PRINTDATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM printdata .

IF ( r_grid = 'X' ).

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

it_fieldcat = it_fieldcat

TABLES

t_outtab = it_final1

EXCEPTIONS

program_error = 1

OTHERS = 2.

ENDIF.

IF ( r_list = 'X' ).

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

it_fieldcat = it_fieldcat

TABLES

t_outtab = it_final1

EXCEPTIONS

program_error = 1

OTHERS = 2.

ENDIF.

ENDFORM. " PRINTDATA

&----


*& Form fill_fieldcat

&----


  • text

----


  • -->P_0204 text

  • -->P_0205 text

  • -->P_0206 text

  • -->P_0207 text

  • -->P_0208 text

  • -->P_0209 text

----


FORM fill_fieldcat USING p_fieldname

p_reffldname

p_reftabname

p_seltext

p_cfieldname

p_qfieldname

p_outputlen

.

CLEAR wa_fieldcat.

wa_fieldcat-fieldname = p_fieldname.

wa_fieldcat-ref_fieldname = p_reffldname.

wa_fieldcat-ref_tabname = p_reftabname.

wa_fieldcat-seltext_l = p_seltext.

wa_fieldcat-seltext_s = p_seltext.

wa_fieldcat-seltext_m = p_seltext.

wa_fieldcat-outputlen = p_outputlen.

APPEND wa_fieldcat TO it_fieldcat.

ENDFORM. " fill_fieldcat

Regards

Harshada

1 REPLY 1

Former Member
0 Kudos

Hi,

After calling the FM 'READ_TEXT' , read each line of the table it_lines and concatenate the data into some variable v_data and pass v_data to the internal table.

Regards,

Krishna K.